app.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. ;(function(){
  2. /**
  3. * Require the given path.
  4. *
  5. * @param {String} path
  6. * @return {Object} exports
  7. * @api public
  8. */
  9. function require(path, parent, orig) {
  10. var resolved = require.resolve(path);
  11. // lookup failed
  12. if (null == resolved) {
  13. orig = orig || path;
  14. parent = parent || 'root';
  15. var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
  16. err.path = orig;
  17. err.parent = parent;
  18. err.require = true;
  19. throw err;
  20. }
  21. var module = require.modules[resolved];
  22. // perform real require()
  23. // by invoking the module's
  24. // registered function
  25. if (!module.exports) {
  26. module.exports = {};
  27. module.client = module.component = true;
  28. module.call(this, module.exports, require.relative(resolved), module);
  29. }
  30. return module.exports;
  31. }
  32. /**
  33. * Registered modules.
  34. */
  35. require.modules = {};
  36. /**
  37. * Registered aliases.
  38. */
  39. require.aliases = {};
  40. /**
  41. * Resolve `path`.
  42. *
  43. * Lookup:
  44. *
  45. * - PATH/index.js
  46. * - PATH.js
  47. * - PATH
  48. *
  49. * @param {String} path
  50. * @return {String} path or null
  51. * @api private
  52. */
  53. require.resolve = function(path) {
  54. if (path.charAt(0) === '/') path = path.slice(1);
  55. var paths = [
  56. path,
  57. path + '.js',
  58. path + '.json',
  59. path + '/index.js',
  60. path + '/index.json'
  61. ];
  62. for (var i = 0; i < paths.length; i++) {
  63. var path = paths[i];
  64. if (require.modules.hasOwnProperty(path)) return path;
  65. if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
  66. }
  67. };
  68. /**
  69. * Normalize `path` relative to the current path.
  70. *
  71. * @param {String} curr
  72. * @param {String} path
  73. * @return {String}
  74. * @api private
  75. */
  76. require.normalize = function(curr, path) {
  77. var segs = [];
  78. if ('.' != path.charAt(0)) return path;
  79. curr = curr.split('/');
  80. path = path.split('/');
  81. for (var i = 0; i < path.length; ++i) {
  82. if ('..' == path[i]) {
  83. curr.pop();
  84. } else if ('.' != path[i] && '' != path[i]) {
  85. segs.push(path[i]);
  86. }
  87. }
  88. return curr.concat(segs).join('/');
  89. };
  90. /**
  91. * Register module at `path` with callback `definition`.
  92. *
  93. * @param {String} path
  94. * @param {Function} definition
  95. * @api private
  96. */
  97. require.register = function(path, definition) {
  98. require.modules[path] = definition;
  99. };
  100. /**
  101. * Alias a module definition.
  102. *
  103. * @param {String} from
  104. * @param {String} to
  105. * @api private
  106. */
  107. require.alias = function(from, to) {
  108. if (!require.modules.hasOwnProperty(from)) {
  109. throw new Error('Failed to alias "' + from + '", it does not exist');
  110. }
  111. require.aliases[to] = from;
  112. };
  113. /**
  114. * Return a require function relative to the `parent` path.
  115. *
  116. * @param {String} parent
  117. * @return {Function}
  118. * @api private
  119. */
  120. require.relative = function(parent) {
  121. var p = require.normalize(parent, '..');
  122. /**
  123. * lastIndexOf helper.
  124. */
  125. function lastIndexOf(arr, obj) {
  126. var i = arr.length;
  127. while (i--) {
  128. if (arr[i] === obj) return i;
  129. }
  130. return -1;
  131. }
  132. /**
  133. * The relative require() itself.
  134. */
  135. function localRequire(path) {
  136. var resolved = localRequire.resolve(path);
  137. return require(resolved, parent, path);
  138. }
  139. /**
  140. * Resolve relative to the parent.
  141. */
  142. localRequire.resolve = function(path) {
  143. var c = path.charAt(0);
  144. if ('/' == c) return path.slice(1);
  145. if ('.' == c) return require.normalize(p, path);
  146. // resolve deps by returning
  147. // the dep in the nearest "deps"
  148. // directory
  149. var segs = parent.split('/');
  150. var i = lastIndexOf(segs, 'deps') + 1;
  151. if (!i) i = 0;
  152. path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
  153. return path;
  154. };
  155. /**
  156. * Check if module is defined at `path`.
  157. */
  158. localRequire.exists = function(path) {
  159. return require.modules.hasOwnProperty(localRequire.resolve(path));
  160. };
  161. return localRequire;
  162. };
  163. require.register("store/dist/store2.js", function(exports, require, module){
  164. /*! store2 - v2.14.2 - 2022-07-18
  165. * Copyright (c) 2022 Nathan Bubna; Licensed (MIT OR GPL-3.0) */
  166. ;(function(window, define) {
  167. var _ = {
  168. version: "2.14.2",
  169. areas: {},
  170. apis: {},
  171. nsdelim: '.',
  172. // utilities
  173. inherit: function(api, o) {
  174. for (var p in api) {
  175. if (!o.hasOwnProperty(p)) {
  176. Object.defineProperty(o, p, Object.getOwnPropertyDescriptor(api, p));
  177. }
  178. }
  179. return o;
  180. },
  181. stringify: function(d, fn) {
  182. return d === undefined || typeof d === "function" ? d+'' : JSON.stringify(d,fn||_.replace);
  183. },
  184. parse: function(s, fn) {
  185. // if it doesn't parse, return as is
  186. try{ return JSON.parse(s,fn||_.revive); }catch(e){ return s; }
  187. },
  188. // extension hooks
  189. fn: function(name, fn) {
  190. _.storeAPI[name] = fn;
  191. for (var api in _.apis) {
  192. _.apis[api][name] = fn;
  193. }
  194. },
  195. get: function(area, key){ return area.getItem(key); },
  196. set: function(area, key, string){ area.setItem(key, string); },
  197. remove: function(area, key){ area.removeItem(key); },
  198. key: function(area, i){ return area.key(i); },
  199. length: function(area){ return area.length; },
  200. clear: function(area){ area.clear(); },
  201. // core functions
  202. Store: function(id, area, namespace) {
  203. var store = _.inherit(_.storeAPI, function(key, data, overwrite) {
  204. if (arguments.length === 0){ return store.getAll(); }
  205. if (typeof data === "function"){ return store.transact(key, data, overwrite); }// fn=data, alt=overwrite
  206. if (data !== undefined){ return store.set(key, data, overwrite); }
  207. if (typeof key === "string" || typeof key === "number"){ return store.get(key); }
  208. if (typeof key === "function"){ return store.each(key); }
  209. if (!key){ return store.clear(); }
  210. return store.setAll(key, data);// overwrite=data, data=key
  211. });
  212. store._id = id;
  213. try {
  214. var testKey = '__store2_test';
  215. area.setItem(testKey, 'ok');
  216. store._area = area;
  217. area.removeItem(testKey);
  218. } catch (e) {
  219. store._area = _.storage('fake');
  220. }
  221. store._ns = namespace || '';
  222. if (!_.areas[id]) {
  223. _.areas[id] = store._area;
  224. }
  225. if (!_.apis[store._ns+store._id]) {
  226. _.apis[store._ns+store._id] = store;
  227. }
  228. return store;
  229. },
  230. storeAPI: {
  231. // admin functions
  232. area: function(id, area) {
  233. var store = this[id];
  234. if (!store || !store.area) {
  235. store = _.Store(id, area, this._ns);//new area-specific api in this namespace
  236. if (!this[id]){ this[id] = store; }
  237. }
  238. return store;
  239. },
  240. namespace: function(namespace, singleArea, delim) {
  241. delim = delim || this._delim || _.nsdelim;
  242. if (!namespace){
  243. return this._ns ? this._ns.substring(0,this._ns.length-delim.length) : '';
  244. }
  245. var ns = namespace, store = this[ns];
  246. if (!store || !store.namespace) {
  247. store = _.Store(this._id, this._area, this._ns+ns+delim);//new namespaced api
  248. store._delim = delim;
  249. if (!this[ns]){ this[ns] = store; }
  250. if (!singleArea) {
  251. for (var name in _.areas) {
  252. store.area(name, _.areas[name]);
  253. }
  254. }
  255. }
  256. return store;
  257. },
  258. isFake: function(force) {
  259. if (force) {
  260. this._real = this._area;
  261. this._area = _.storage('fake');
  262. } else if (force === false) {
  263. this._area = this._real || this._area;
  264. }
  265. return this._area.name === 'fake';
  266. },
  267. toString: function() {
  268. return 'store'+(this._ns?'.'+this.namespace():'')+'['+this._id+']';
  269. },
  270. // storage functions
  271. has: function(key) {
  272. if (this._area.has) {
  273. return this._area.has(this._in(key));//extension hook
  274. }
  275. return !!(this._in(key) in this._area);
  276. },
  277. size: function(){ return this.keys().length; },
  278. each: function(fn, fill) {// fill is used by keys(fillList) and getAll(fillList))
  279. for (var i=0, m=_.length(this._area); i<m; i++) {
  280. var key = this._out(_.key(this._area, i));
  281. if (key !== undefined) {
  282. if (fn.call(this, key, this.get(key), fill) === false) {
  283. break;
  284. }
  285. }
  286. if (m > _.length(this._area)) { m--; i--; }// in case of removeItem
  287. }
  288. return fill || this;
  289. },
  290. keys: function(fillList) {
  291. return this.each(function(k, v, list){ list.push(k); }, fillList || []);
  292. },
  293. get: function(key, alt) {
  294. var s = _.get(this._area, this._in(key)),
  295. fn;
  296. if (typeof alt === "function") {
  297. fn = alt;
  298. alt = null;
  299. }
  300. return s !== null ? _.parse(s, fn) :
  301. alt != null ? alt : s;
  302. },
  303. getAll: function(fillObj) {
  304. return this.each(function(k, v, all){ all[k] = v; }, fillObj || {});
  305. },
  306. transact: function(key, fn, alt) {
  307. var val = this.get(key, alt),
  308. ret = fn(val);
  309. this.set(key, ret === undefined ? val : ret);
  310. return this;
  311. },
  312. set: function(key, data, overwrite) {
  313. var d = this.get(key),
  314. replacer;
  315. if (d != null && overwrite === false) {
  316. return data;
  317. }
  318. if (typeof overwrite === "function") {
  319. replacer = overwrite;
  320. overwrite = undefined;
  321. }
  322. return _.set(this._area, this._in(key), _.stringify(data, replacer), overwrite) || d;
  323. },
  324. setAll: function(data, overwrite) {
  325. var changed, val;
  326. for (var key in data) {
  327. val = data[key];
  328. if (this.set(key, val, overwrite) !== val) {
  329. changed = true;
  330. }
  331. }
  332. return changed;
  333. },
  334. add: function(key, data, replacer) {
  335. var d = this.get(key);
  336. if (d instanceof Array) {
  337. data = d.concat(data);
  338. } else if (d !== null) {
  339. var type = typeof d;
  340. if (type === typeof data && type === 'object') {
  341. for (var k in data) {
  342. d[k] = data[k];
  343. }
  344. data = d;
  345. } else {
  346. data = d + data;
  347. }
  348. }
  349. _.set(this._area, this._in(key), _.stringify(data, replacer));
  350. return data;
  351. },
  352. remove: function(key, alt) {
  353. var d = this.get(key, alt);
  354. _.remove(this._area, this._in(key));
  355. return d;
  356. },
  357. clear: function() {
  358. if (!this._ns) {
  359. _.clear(this._area);
  360. } else {
  361. this.each(function(k){ _.remove(this._area, this._in(k)); }, 1);
  362. }
  363. return this;
  364. },
  365. clearAll: function() {
  366. var area = this._area;
  367. for (var id in _.areas) {
  368. if (_.areas.hasOwnProperty(id)) {
  369. this._area = _.areas[id];
  370. this.clear();
  371. }
  372. }
  373. this._area = area;
  374. return this;
  375. },
  376. // internal use functions
  377. _in: function(k) {
  378. if (typeof k !== "string"){ k = _.stringify(k); }
  379. return this._ns ? this._ns + k : k;
  380. },
  381. _out: function(k) {
  382. return this._ns ?
  383. k && k.indexOf(this._ns) === 0 ?
  384. k.substring(this._ns.length) :
  385. undefined : // so each() knows to skip it
  386. k;
  387. }
  388. },// end _.storeAPI
  389. storage: function(name) {
  390. return _.inherit(_.storageAPI, { items: {}, name: name });
  391. },
  392. storageAPI: {
  393. length: 0,
  394. has: function(k){ return this.items.hasOwnProperty(k); },
  395. key: function(i) {
  396. var c = 0;
  397. for (var k in this.items){
  398. if (this.has(k) && i === c++) {
  399. return k;
  400. }
  401. }
  402. },
  403. setItem: function(k, v) {
  404. if (!this.has(k)) {
  405. this.length++;
  406. }
  407. this.items[k] = v;
  408. },
  409. removeItem: function(k) {
  410. if (this.has(k)) {
  411. delete this.items[k];
  412. this.length--;
  413. }
  414. },
  415. getItem: function(k){ return this.has(k) ? this.items[k] : null; },
  416. clear: function(){ for (var k in this.items){ this.removeItem(k); } }
  417. }// end _.storageAPI
  418. };
  419. var store =
  420. // safely set this up (throws error in IE10/32bit mode for local files)
  421. _.Store("local", (function(){try{ return localStorage; }catch(e){}})());
  422. store.local = store;// for completeness
  423. store._ = _;// for extenders and debuggers...
  424. // safely setup store.session (throws exception in FF for file:/// urls)
  425. store.area("session", (function(){try{ return sessionStorage; }catch(e){}})());
  426. store.area("page", _.storage("page"));
  427. if (typeof define === 'function' && define.amd !== undefined) {
  428. define('store2', [], function () {
  429. return store;
  430. });
  431. } else if (typeof module !== 'undefined' && module.exports) {
  432. module.exports = store;
  433. } else {
  434. // expose the primary store fn to the global object and save conflicts
  435. if (window.store){ _.conflict = window.store; }
  436. window.store = store;
  437. }
  438. })(this, this && this.define);
  439. });
  440. require.register("store/src/store.on.js", function(exports, require, module){
  441. /**
  442. * Copyright (c) 2013 ESHA Research
  443. * Dual licensed under the MIT and GPL licenses:
  444. * http://www.opensource.org/licenses/mit-license.php
  445. * http://www.gnu.org/licenses/gpl.html
  446. *
  447. * Makes it easy to watch for storage events by enhancing the events and
  448. * allowing binding to particular keys and/or namespaces.
  449. *
  450. * // listen to particular key storage events (yes, this is namespace sensitive)
  451. * store.on('foo', function listenToFoo(e){ console.log('foo was changed:', e); });
  452. * store.off('foo', listenToFoo);
  453. *
  454. * // listen to all storage events (also namespace sensitive)
  455. * store.on(function storageEvent(e){ console.log('web storage:', e); });
  456. * store.off(storageEvent);
  457. *
  458. * Status: BETA - useful, if you aren't using IE8 or worse
  459. */
  460. ;(function(window, _) {
  461. _.on = function(key, fn) {
  462. if (!fn) { fn = key; key = ''; }// no key === all keys
  463. var s = this,
  464. listener = function(e) {
  465. var k = s._out(e.key);// undefined if key is not in the namespace
  466. if ((k && (k === key ||// match key if listener has one
  467. (!key && k !== '_-bad-_'))) &&// match catch-all, except internal test
  468. (!e.storageArea || e.storageArea === s._area)) {// match area, if available
  469. return fn.call(s, _.event.call(s, k, e));
  470. }
  471. };
  472. window.addEventListener("storage", fn[key+'-listener']=listener, false);
  473. return this;
  474. };
  475. _.off = function(key, fn) {
  476. if (!fn) { fn = key; key = ''; }// no key === all keys
  477. window.removeEventListener("storage", fn[key+'-listener']);
  478. return this;
  479. };
  480. _.once = function(key, fn) {
  481. if (!fn) { fn = key; key = ''; }
  482. var s = this, listener;
  483. return s.on(key, listener = function() {
  484. s.off(key, listener);
  485. return fn.apply(this, arguments);
  486. });
  487. };
  488. _.event = function(k, e) {
  489. var event = {
  490. key: k,
  491. namespace: this.namespace(),
  492. newValue: _.parse(e.newValue),
  493. oldValue: _.parse(e.oldValue),
  494. url: e.url || e.uri,
  495. storageArea: e.storageArea,
  496. source: e.source,
  497. timeStamp: e.timeStamp,
  498. originalEvent: e
  499. };
  500. if (_.cache) {
  501. var min = _.expires(e.newValue || e.oldValue);
  502. if (min) {
  503. event.expires = _.when(min);
  504. }
  505. }
  506. return event;
  507. };
  508. // store2 policy is to not throw errors on old browsers
  509. var old = !window.addEventListener ? function(){} : null;
  510. _.fn('on', old || _.on);
  511. _.fn('off', old || _.off);
  512. _.fn('once', old || _.once);
  513. })(window, window.store._);
  514. });
  515. require.register("store/src/store.cache.js", function(exports, require, module){
  516. /**
  517. * Copyright (c) 2013 ESHA Research
  518. * Dual licensed under the MIT and GPL licenses:
  519. * http://www.opensource.org/licenses/mit-license.php
  520. * http://www.gnu.org/licenses/gpl.html
  521. *
  522. * Allows use of a number as 'overwrite' param on set calls to give time in seconds after
  523. * which the value should not be retrievable again (an expiration time).
  524. *
  525. * Status: BETA - useful, needs testing
  526. */
  527. ;(function(_) {
  528. var prefix = 'exp@',
  529. suffix = ';',
  530. parse = _.parse,
  531. _get = _.get,
  532. _set = _.set;
  533. _.parse = function(s, fn) {
  534. if (s && s.indexOf(prefix) === 0) {
  535. s = s.substring(s.indexOf(suffix)+1);
  536. }
  537. return parse(s, fn);
  538. };
  539. _.expires = function(s) {
  540. if (s && s.indexOf(prefix) === 0) {
  541. return parseInt(s.substring(prefix.length, s.indexOf(suffix)), 10);
  542. }
  543. return false;
  544. };
  545. _.when = function(sec) {// if sec, return sec->date, else date->sec
  546. var now = Math.floor((new Date().getTime())/1000);
  547. return sec ? new Date((now+sec)*1000) : now;
  548. };
  549. _.cache = function(area, key) {
  550. var s = _get(area, key),
  551. sec = _.expires(s);
  552. if (sec && _.when() >= sec) {
  553. return area.removeItem(key);
  554. }
  555. return s;
  556. };
  557. _.get = function(area, key) {
  558. var s = _.cache(area, key);
  559. return s === undefined ? null : s;
  560. };
  561. _.set = function(area, key, string, sec) {
  562. try {
  563. if (sec) {
  564. string = prefix + (_.when()+sec) + suffix + string;
  565. }
  566. _set(area, key, string);
  567. } catch (e) {
  568. if (e.name === 'QUOTA_EXCEEDED_ERR' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
  569. var changed = false;
  570. for (var i=0,m=area.length; i<m; i++) {
  571. if (_.cache(area, key) === undefined) {
  572. changed = true;
  573. }
  574. }
  575. if (changed) {
  576. return _.set.apply(this, arguments);
  577. }
  578. }
  579. throw e;
  580. }
  581. };
  582. })(window.store._, undefined);
  583. });
  584. require.register("store/src/store.measure.js", function(exports, require, module){
  585. /**
  586. * Copyright (c) 2013 ESHA Research
  587. * Dual licensed under the MIT and GPL licenses:
  588. * http://www.opensource.org/licenses/mit-license.php
  589. * http://www.gnu.org/licenses/gpl.html
  590. *
  591. * store.remainingSpace();// returns remainingSpace value (if browser supports it)
  592. * store.charsUsed();// returns length of all data when stringified
  593. * store.charsLeft([true]);// tests how many more chars we can fit (crash threat!)
  594. * store.charsTotal([true]);// charsUsed + charsLeft, duh.
  595. *
  596. * TODO: byte/string conversions
  597. *
  598. * Status: ALPHA - changing API *and* crash threats :)
  599. */
  600. ;(function(store, _) {
  601. function put(area, s) {
  602. try {
  603. area.setItem("__test__", s);
  604. return true;
  605. } catch (e) {}
  606. }
  607. _.fn('remainingSpace', function() {
  608. return this._area.remainingSpace;
  609. });
  610. _.fn('charsUsed', function() {
  611. return _.stringify(this.getAll()).length - 2;
  612. });
  613. _.fn('charsLeft', function(test) {
  614. if (this.isFake()){ return; }
  615. if (arguments.length === 0) {
  616. test = window.confirm('Calling store.charsLeft() may crash some browsers!');
  617. }
  618. if (test) {
  619. var s = 's ', add = s;
  620. // grow add for speed
  621. while (put(store._area, s)) {
  622. s += add;
  623. if (add.length < 50000) {
  624. add = s;
  625. }
  626. }
  627. // shrink add for accuracy
  628. while (add.length > 2) {
  629. s = s.substring(0, s.length - (add.length/2));
  630. while (put(store._area, s)) {
  631. s += add;
  632. }
  633. add = add.substring(add.length/2);
  634. }
  635. _.remove(store._area, "__test__");
  636. return s.length + 8;
  637. }
  638. });
  639. _.fn('charsTotal', function(test) {
  640. return store.charsUsed() + store.charsLeft(test);
  641. });
  642. })(window.store, window.store._);
  643. });
  644. require.register("store/src/store.old.js", function(exports, require, module){
  645. /**
  646. * Copyright (c) 2013 ESHA Research
  647. * Dual licensed under the MIT and GPL licenses:
  648. * http://www.opensource.org/licenses/mit-license.php
  649. * http://www.gnu.org/licenses/gpl.html
  650. *
  651. * If fake (non-persistent) storage for users stuck in the dark ages
  652. * does not satisfy you, this will replace it with the a reasonable imitator for their
  653. * pathetic, incompetent browser. Note that the session replacement here is potentially
  654. * insecure as it uses window.name without any fancy protections.
  655. *
  656. * Status: BETA - unsupported, useful, needs testing & refining
  657. */
  658. ;(function(window, document, store, _) {
  659. function addUpdateFn(area, name, update) {
  660. var old = area[name];
  661. area[name] = function() {
  662. var ret = old.apply(this, arguments);
  663. update.apply(this, arguments);
  664. return ret;
  665. };
  666. }
  667. function create(name, items, update) {
  668. var length = 0;
  669. for (var k in items) {
  670. if (items.hasOwnProperty(k)) {
  671. length++;
  672. }
  673. }
  674. var area = _.inherit(_.storageAPI, { items:items, length:length, name:name });
  675. if (update) {
  676. addUpdateFn(area, 'setItem', update);
  677. addUpdateFn(area, 'removeItem', update);
  678. }
  679. return area;
  680. }
  681. if (store.isFake()) {
  682. var area;
  683. if (document.documentElement.addBehavior) {// IE userData
  684. var el = document.createElement('div'),
  685. sn = 'localStorage',
  686. body = document.body,
  687. wrap = function wrap(fn) {
  688. return function() {
  689. body.appendChild(el);
  690. el.addBehavior('#default#userData');
  691. el.load(sn);
  692. var ret = fn.apply(store._area, arguments);
  693. el.save(sn);
  694. body.removeChild(el);
  695. return ret;
  696. };
  697. },
  698. has = function has(key){
  699. return el.getAttribute(key) !== null;
  700. },
  701. UserDataStorage = function UserDataStorage(){};
  702. UserDataStorage.prototype = {
  703. length: (wrap(function(){
  704. return el.XMLDocument.documentElement.attributes.length;
  705. }))(),
  706. has: wrap(has),
  707. key: wrap(function(i) {
  708. return el.XMLDocument.documentElement.attributes[i];
  709. }),
  710. setItem: wrap(function(k, v) {
  711. if (!has(k)) {
  712. this.length++;
  713. }
  714. el.setAttribute(k, v);
  715. }),
  716. removeItem: wrap(function(k) {
  717. if (has(k)) {
  718. el.removeAttribute(k);
  719. this.length--;
  720. }
  721. }),
  722. getItem: wrap(function(k){ return el.getAttribute(k); }),
  723. clear: wrap(function() {
  724. var all = el.XMLDocument.documentElement.attributes;
  725. for (var i=0, a; !!(a = all[i]); i++) {
  726. el.removeAttribute(a.name);
  727. }
  728. this.length = 0;
  729. })
  730. };
  731. area = new UserDataStorage();
  732. } else if ('globalStorage' in window && window.globalStorage) {// FF globalStorage
  733. area = create('global', window.globalStorage[window.location.hostname]);
  734. } else {// cookie
  735. var date = new Date(),
  736. key = 'store.local',
  737. items = {},
  738. cookies = document.cookie.split(';');
  739. date.setTime(date.getTime()+(5*365*24*60*60*1000));//5 years out
  740. date = date.toGMTString();
  741. for (var i=0,m=cookies.length; i<m; i++) {
  742. var c = cookies[i];
  743. while (c.charAt(0) === ' ') {
  744. c = c.substring(1, c.length);
  745. }
  746. if (c.indexOf(key) === 0) {
  747. items = JSON.parse(c.substring(key.length+1));
  748. }
  749. }
  750. area = create('cookie', items, function() {
  751. document.cookie = key+"="+JSON.stringify(this.items)+"; expires="+date+"; path=/";
  752. });
  753. }
  754. // replace local's fake storage
  755. store._area = _.areas.local = area;
  756. }
  757. if (store.session.isFake()) {
  758. var sItems = window.name ? JSON.parse(window.name)[document.domain]||{} : {};
  759. store.session._area = _.areas.session =
  760. create('windowName', sItems, function() {
  761. var o = {};
  762. o[document.domain] = this.items;
  763. window.name = JSON.stringify(o);
  764. });
  765. }
  766. })(window, document, window.store, window.store._);
  767. });
  768. require.register("store/src/store.overflow.js", function(exports, require, module){
  769. /**
  770. * Copyright (c) 2013 ESHA Research
  771. * Dual licensed under the MIT and GPL licenses:
  772. * http://www.opensource.org/licenses/mit-license.php
  773. * http://www.gnu.org/licenses/gpl.html
  774. *
  775. * When quota is reached on a storage area, this shifts incoming values to
  776. * fake storage, so they last only as long as the page does. This is useful
  777. * because it is more burdensome for localStorage to recover from quota errors
  778. * than incomplete caches. In other words, it is wiser to rely on store.js
  779. * never complaining than never missing data. You should already be checking
  780. * the integrity of cached data on every page load.
  781. *
  782. * Status: BETA
  783. */
  784. ;(function(store, _) {
  785. var _set = _.set,
  786. _get = _.get,
  787. _remove = _.remove,
  788. _key = _.key,
  789. _length = _.length,
  790. _clear = _.clear;
  791. _.overflow = function(area, create) {
  792. var name = area === _.areas.local ? '+local+' :
  793. area === _.areas.session ? '+session+' : false;
  794. if (name) {
  795. var overflow = _.areas[name];
  796. if (create && !overflow) {
  797. overflow = store.area(name)._area;// area() copies to _.areas
  798. } else if (create === false) {
  799. delete _.areas[name];
  800. delete store[name];
  801. }
  802. return overflow;
  803. }
  804. };
  805. _.set = function(area, key, string) {
  806. try {
  807. _set.apply(this, arguments);
  808. } catch (e) {
  809. if (e.name === 'QUOTA_EXCEEDED_ERR' ||
  810. e.name === 'NS_ERROR_DOM_QUOTA_REACHED' ||
  811. e.toString().indexOf("QUOTA_EXCEEDED_ERR") !== -1 ||
  812. e.toString().indexOf("QuotaExceededError") !== -1) {
  813. // the e.toString is needed for IE9 / IE10, cos name is empty there
  814. return _.set(_.overflow(area, true), key, string);
  815. }
  816. throw e;
  817. }
  818. };
  819. _.get = function(area, key) {
  820. var overflow = _.overflow(area);
  821. return (overflow && _get.call(this, overflow, key)) ||
  822. _get.apply(this, arguments);
  823. };
  824. _.remove = function(area, key) {
  825. var overflow = _.overflow(area);
  826. if (overflow){ _remove.call(this, overflow, key); }
  827. _remove.apply(this, arguments);
  828. };
  829. _.key = function(area, i) {
  830. var overflow = _.overflow(area);
  831. if (overflow) {
  832. var l = _length.call(this, area);
  833. if (i >= l) {
  834. i = i - l;// make i overflow-relative
  835. for (var j=0, m=_length.call(this, overflow); j<m; j++) {
  836. if (j === i) {// j is overflow index
  837. return _key.call(this, overflow, j);
  838. }
  839. }
  840. }
  841. }
  842. return _key.apply(this, arguments);
  843. };
  844. _.length = function(area) {
  845. var length = _length(area),
  846. overflow = _.overflow(area);
  847. return overflow ? length + _length(overflow) : length;
  848. };
  849. _.clear = function(area) {
  850. _.overflow(area, false);
  851. _clear.apply(this, arguments);
  852. };
  853. })(window.store, window.store._);
  854. });
  855. require.register("store/src/store.quota.js", function(exports, require, module){
  856. /**
  857. * Copyright (c) 2013 ESHA Research
  858. * Dual licensed under the MIT and GPL licenses:
  859. * http://www.opensource.org/licenses/mit-license.php
  860. * http://www.gnu.org/licenses/gpl.html
  861. *
  862. * Bind handlers to quota errors:
  863. * store.quota(function(e, area, key, str) {
  864. * console.log(e, area, key, str);
  865. * });
  866. * If a handler returns true other handlers are not called and
  867. * the error is suppressed.
  868. *
  869. * Think quota errors will never happen to you? Think again:
  870. * http://spin.atomicobject.com/2013/01/23/ios-private-browsing-localstorage/
  871. * (this affects sessionStorage too)
  872. *
  873. * Status: ALPHA - API could use unbind feature
  874. */
  875. ;(function(store, _) {
  876. store.quota = function(fn) {
  877. store.quota.fns.push(fn);
  878. };
  879. store.quota.fns = [];
  880. var _set = _.set;
  881. _.set = function(area, key, str) {
  882. try {
  883. _set.apply(this, arguments);
  884. } catch (e) {
  885. if (e.name === 'QUOTA_EXCEEDED_ERR' ||
  886. e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
  887. var fns = store.quota.fns;
  888. for (var i=0,m=fns.length; i<m; i++) {
  889. if (true === fns[i].call(this, e, area, key, str)) {
  890. return;
  891. }
  892. }
  893. }
  894. throw e;
  895. }
  896. };
  897. })(window.store, window.store._);
  898. });
  899. require.register("store/src/store.array.js", function(exports, require, module){
  900. /**
  901. * Copyright (c) 2017 ESHA Research
  902. * Dual licensed under the MIT and GPL licenses:
  903. * http://www.opensource.org/licenses/mit-license.php
  904. * http://www.gnu.org/licenses/gpl.html
  905. *
  906. * Adds shortcut for safely applying all available Array functions to stored values. If there is no
  907. * value, the functions will act as if upon an empty one. If there is a non, array value, it is put
  908. * into an array before the function is applied. If the function results in an empty array, the
  909. * key/value is removed from the storage, otherwise the array is restored.
  910. *
  911. * store.push('array', 'a', 1, true);// == store.set('array', (store.get('array')||[]).push('a', 1, true]));
  912. * store.indexOf('array', true);// === store.get('array').indexOf(true)
  913. *
  914. * This will add all functions of Array.prototype that are specific to the Array interface and have no
  915. * conflict with existing store functions.
  916. *
  917. * Status: BETA - useful, but adds more functions than reasonable
  918. */
  919. ;(function(_, Array) {
  920. // expose internals on the underscore to allow extensibility
  921. _.array = function(fnName, key, args) {
  922. var value = this.get(key, []),
  923. array = Array.isArray(value) ? value : [value],
  924. ret = array[fnName].apply(array, args);
  925. if (array.length > 0) {
  926. this.set(key, array.length > 1 ? array : array[0]);
  927. } else {
  928. this.remove(key);
  929. }
  930. return ret;
  931. };
  932. _.arrayFn = function(fnName) {
  933. return function(key) {
  934. return this.array(fnName, key,
  935. arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null);
  936. };
  937. };
  938. // add function(s) to the store interface
  939. _.fn('array', _.array);
  940. Object.getOwnPropertyNames(Array.prototype).forEach(function(name) {
  941. // add Array interface functions w/o existing conflicts
  942. if (typeof Array.prototype[name] === "function") {
  943. if (!(name in _.storeAPI)) {
  944. _.fn(name, _.array[name] = _.arrayFn(name));
  945. }
  946. }
  947. });
  948. })(window.store._, window.Array);
  949. });
  950. require.register("store/src/store.onlyreal.js", function(exports, require, module){
  951. /**
  952. * Copyright (c) 2015 ESHA Research
  953. * Dual licensed under the MIT and GPL licenses:
  954. * http://www.opensource.org/licenses/mit-license.php
  955. * http://www.gnu.org/licenses/gpl.html
  956. *
  957. * Store nothing when storage is not supported.
  958. *
  959. * Status: ALPHA - due to being of doubtful propriety
  960. */
  961. ;(function(_) {
  962. var _set = _.set;
  963. _.set = function(area) {
  964. return area.name === 'fake' ? undefined : _set.apply(this, arguments);
  965. };
  966. })(window.store._);
  967. });
  968. require.register("store/src/store.dot.js", function(exports, require, module){
  969. /**
  970. * Copyright (c) 2017 ESHA Research
  971. * Dual licensed under the MIT and GPL licenses:
  972. * http://www.opensource.org/licenses/mit-license.php
  973. * http://www.gnu.org/licenses/gpl.html
  974. *
  975. * Adds getters and setters for existing keys (and newly set() ones) to enable dot access to stored properties.
  976. *
  977. * store.dot('foo','bar');// makes store aware of keys (could also do store.set('foo',''))
  978. * store.foo = { is: true };// == store.set('foo', { is: true });
  979. * console.log(store.foo.is);// logs 'true'
  980. *
  981. * This will not create accessors that conflict with existing properties of the store object.
  982. *
  983. * Status: ALPHA - good, but ```store.foo.is=false``` won't persist while looking like it would
  984. */
  985. ;(function(_, Object, Array) {
  986. // expose internals on the underscore to allow extensibility
  987. _.dot = function(key) {
  988. var keys = !key ? this.keys() :
  989. Array.isArray(key) ? key :
  990. Array.prototype.slice.call(arguments),
  991. target = this;
  992. keys.forEach(function(key) {
  993. _.dot.define(target, key);
  994. });
  995. return this;
  996. };
  997. _.dot.define = function(target, key) {
  998. if (!(key in target)) {
  999. Object.defineProperty(target, key, {
  1000. enumerable: true,
  1001. get: function(){ return this.get(key); },
  1002. set: function(value){ this.set(key, value); }
  1003. });
  1004. }
  1005. };
  1006. // add function(s) to the store interface
  1007. _.fn('dot', _.dot);
  1008. })(window.store._, window.Object, window.Array);
  1009. });
  1010. require.register("store/src/store.deep.js", function(exports, require, module){
  1011. /**
  1012. * Copyright (c) 2017 ESHA Research
  1013. * Dual licensed under the MIT and GPL licenses:
  1014. * http://www.opensource.org/licenses/mit-license.php
  1015. * http://www.gnu.org/licenses/gpl.html
  1016. *
  1017. * Allows retrieval of values from within a stored object.
  1018. *
  1019. * store.set('foo', { is: { not: { quite: false }}});
  1020. * console.log(store.get('foo.is.not.quite'));// logs false
  1021. *
  1022. * Status: ALPHA - currently only supports get, inefficient, uses eval
  1023. */
  1024. ;(function(_) {
  1025. // save original core accessor
  1026. var _get = _.get;
  1027. // replace with enhanced version
  1028. _.get = function(area, key, kid) {
  1029. var s = _get(area, key);
  1030. if (s == null) {
  1031. var parts = _.split(key);
  1032. if (parts) {
  1033. key = parts[0];
  1034. kid = kid ? parts[1] + '.' + kid : parts[1];
  1035. return _.get(area, parts[0], kid);
  1036. }
  1037. } else if (kid) {
  1038. var val = _.parse(s);
  1039. /*jshint evil:true */
  1040. val = eval("val."+kid);
  1041. s = _.stringify(val);
  1042. }
  1043. return s;
  1044. };
  1045. // expose internals on the underscore to allow extensibility
  1046. _.split = function(key) {
  1047. var dot = key.lastIndexOf('.');
  1048. if (dot > 0) {
  1049. var kid = key.substring(dot+1, key.length);
  1050. key = key.substring(0, dot);
  1051. return [key, kid];
  1052. }
  1053. };
  1054. })(window.store._);
  1055. });
  1056. require.register("store/src/store.dom.js", function(exports, require, module){
  1057. /**
  1058. * Copyright (c) 2017 ESHA Research
  1059. * Dual licensed under the MIT and GPL licenses:
  1060. * http://www.opensource.org/licenses/mit-license.php
  1061. * http://www.gnu.org/licenses/gpl.html
  1062. *
  1063. * Declarative, persistent DOM content.
  1064. *
  1065. * <input store name="whatever">
  1066. * <div store="somekey" store-area="session" contenteditable>Some content</div>
  1067. *
  1068. * Status: BETA - uses store, doesn't extend it, deserves standalone project
  1069. */
  1070. ;(function(document, store, _, Array) {
  1071. // expose internal functions on store._.dom for extensibility
  1072. var DOM = _.dom = function() {
  1073. var nodes = document.querySelectorAll(DOM.selector),
  1074. array = Array.prototype.slice.call(nodes);
  1075. for (var i=0; i<array.length; i++) {
  1076. DOM.node(array[i], i);
  1077. }
  1078. return array;
  1079. };
  1080. DOM.selector = '[store],[store-area]';
  1081. DOM.event = 'input';// beforeunload is tempting
  1082. DOM.node = function(node, i) {
  1083. var key = DOM.key(node, i),
  1084. area = DOM.area(node),
  1085. value = area(key);
  1086. if (value == null) {
  1087. value = DOM.get(node);
  1088. } else {
  1089. DOM.set(node, value);
  1090. }
  1091. if (!node.storeListener) {
  1092. node.addEventListener(DOM.event, function() {
  1093. area(key, DOM.get(node));
  1094. });
  1095. node.storeListener = true;
  1096. }
  1097. };
  1098. DOM.area = function(node) {
  1099. return store[node.getAttribute('store-area') || 'local'];
  1100. };
  1101. // prefer store attribute value, then name attribute, use nodeName+index as last resort
  1102. DOM.key = function(node, i) {
  1103. return node.getAttribute('store') ||
  1104. node.getAttribute('name') ||
  1105. ('dom.'+node.nodeName.toLowerCase() + (i||''));
  1106. };
  1107. // both get and set should prefer value property to innerHTML
  1108. DOM.get = function(node) {
  1109. return node.value || node.innerHTML;
  1110. };
  1111. DOM.set = function(node, value) {
  1112. if ('value' in node) {
  1113. node.value = value;
  1114. } else {
  1115. node.innerHTML = typeof value === "string" ? value : _.stringify(value);
  1116. }
  1117. };
  1118. // initialize
  1119. document.addEventListener('DOMContentLoaded', DOM);
  1120. })(document, window.store, window.store._, Array);
  1121. });
  1122. require.register("store/src/store.async.js", function(exports, require, module){
  1123. /**
  1124. * Copyright (c) 2019 ESHA Research
  1125. * Dual licensed under the MIT and GPL licenses:
  1126. * http://www.opensource.org/licenses/mit-license.php
  1127. * http://www.gnu.org/licenses/gpl.html
  1128. *
  1129. * Adds an 'async' duplicate on all store APIs that
  1130. * performs storage-related operations asynchronously and returns
  1131. * a promise.
  1132. *
  1133. * Status: BETA - works great, but lacks justification for existence
  1134. */
  1135. ;(function(window, _) {
  1136. var dontPromisify = ['async', 'area', 'namespace', 'isFake', 'toString'];
  1137. _.promisify = function(api) {
  1138. var async = api.async = _.Store(api._id, api._area, api._ns);
  1139. async._async = true;
  1140. Object.keys(api).forEach(function(name) {
  1141. if (name.charAt(0) !== '_' && dontPromisify.indexOf(name) < 0) {
  1142. var fn = api[name];
  1143. if (typeof fn === "function") {
  1144. async[name] = _.promiseFn(name, fn, api);
  1145. }
  1146. }
  1147. });
  1148. return async;
  1149. };
  1150. _.promiseFn = function(name, fn, self) {
  1151. return function promised() {
  1152. var args = arguments;
  1153. return new Promise(function(resolve, reject) {
  1154. setTimeout(function() {
  1155. try {
  1156. resolve(fn.apply(self, args));
  1157. } catch (e) {
  1158. reject(e);
  1159. }
  1160. }, 0);
  1161. });
  1162. };
  1163. };
  1164. // promisify existing apis
  1165. for (var apiName in _.apis) {
  1166. _.promisify(_.apis[apiName]);
  1167. }
  1168. // ensure future apis are promisified
  1169. Object.defineProperty(_.storeAPI, 'async', {
  1170. enumerable: true,
  1171. configurable: true,
  1172. get: function() {
  1173. var async = _.promisify(this);
  1174. // overwrite getter to avoid re-promisifying
  1175. Object.defineProperty(this, 'async', {
  1176. enumerable: true,
  1177. value: async
  1178. });
  1179. return async;
  1180. }
  1181. });
  1182. })(window, window.store._);
  1183. });
  1184. require.alias("store/dist/store2.js", "store/index.js");
  1185. if (typeof exports == "object") {
  1186. module.exports = require("store");
  1187. } else if (typeof define == "function" && define.amd) {
  1188. define(function(){ return require("store"); });
  1189. } else {
  1190. this["store"] = require("store");
  1191. }})();