aberdeen 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/README.md +138 -96
- package/dist/aberdeen.d.ts +652 -528
- package/dist/aberdeen.js +1144 -1957
- package/dist/aberdeen.js.map +11 -1
- package/dist/helpers/reverseSortedSet.d.ts +91 -0
- package/dist/prediction.d.ts +7 -3
- package/dist/prediction.js +77 -93
- package/dist/prediction.js.map +10 -1
- package/dist/route.d.ts +36 -19
- package/dist/route.js +131 -158
- package/dist/route.js.map +10 -1
- package/dist/transitions.js +30 -70
- package/dist/transitions.js.map +10 -1
- package/dist-min/aberdeen.js +7 -2
- package/dist-min/aberdeen.js.map +11 -1
- package/dist-min/prediction.js +4 -2
- package/dist-min/prediction.js.map +10 -1
- package/dist-min/route.js +4 -2
- package/dist-min/route.js.map +10 -1
- package/dist-min/transitions.js +4 -2
- package/dist-min/transitions.js.map +10 -1
- package/package.json +20 -23
- package/src/aberdeen.ts +1933 -1814
- package/src/helpers/reverseSortedSet.ts +188 -0
- package/src/prediction.ts +14 -9
- package/src/route.ts +81 -64
- package/src/transitions.ts +1 -14
- package/dist-min/aberdeen.d.ts +0 -601
- package/dist-min/prediction.d.ts +0 -29
- package/dist-min/route.d.ts +0 -30
- package/dist-min/transitions.d.ts +0 -18
package/dist/route.js.map
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/route.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {getParentElement, runQueue, clean, proxy, observe, immediateObserve, unproxy, clone} from './aberdeen.js'\n\n/**\n * The class for the singleton `route` object.\n * \n */\n\nexport class Route {\n\t/** The current path of the URL split into components. For instance `/` or `/users/123/feed`. Updates will be reflected in the URL and will *push* a new entry to the browser history. */\n\tpath!: string\n\t/** Array containing the path segments. For instance `[]` or `['users', 123, 'feed']`. Updates will be reflected in the URL and will *push* a new entry to the browser history. Also, the values of `p` and `path` will be synced. */\n\tp!: string[]\n\t/** An observable object containing search parameters (a split up query string). For instance `{order: \"date\", title: \"something\"}` or just `{}`. By default, updates will be reflected in the URL, replacing the current history state. */\n\thash!: string\n\t/** A part of the browser history *state* that is considered part of the page *identify*, meaning changes will (by default) cause a history push, and when going *back*, it must match. */\n\tsearch!: Record<string, string>\n\t/** The `hash` interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\"}`. */\n\tid!: Record<string, any>\n\t/** The auxiliary part of the browser history *state*, not considered part of the page *identity*. Changes will be reflected in the browser history using a replace. */\n\taux!: Record<string, any>\n\t/** The navigation depth of the current session. Starts at 1. Writing to this property has no effect. */\n\tdepth: number = 1\n\t/** The navigation action that got us to this page. Writing to this property has no effect.\n - `\"load\"`: An initial page load.\n - `\"back\"` or `\"forward\"`: When we navigated backwards or forwards in the stack.\n - `\"push\"`: When we added a new page on top of the stack. \n */\n nav: 'load' | 'back' | 'forward' | 'push' = 'load'\n /** As described above, this library takes a best guess about whether pushing an item to the browser history makes sense or not. When `mode` is... \n \t - `\"push\"`: Force creation of a new browser history entry. \n \t - `\"replace\"`: Update the current history entry, even when updates to other keys would normally cause a *push*.\n \t - `\"back\"`: Unwind the history (like repeatedly pressing the *back* button) until we find a page that matches the given `path` and `id` (or that is the first page in our stack), and then *replace* that state by the full given state.\n The `mode` key can be written to `route` but will be immediately and silently removed.\n */\n\tmode: 'push' | 'replace' | 'back' | undefined\n}\n\n/**\n * The singleton {@link Route} object reflecting the current URL and browser history state. You can make changes to it to affect the URL and browser history. See {@link Route} for details.\n */\nexport const route = proxy(new Route())\n\nlet stateRoute = {\n\tnonce: -1,\n\tdepth: 0,\n}\n\n// Reflect changes to the browser URL (back/forward navigation) in the `route` and `stack`.\nfunction handleLocationUpdate(event?: PopStateEvent) {\n\tlet state = event?.state || {}\n\tlet nav: 'load' | 'back' | 'forward' | 'push' = 'load'\n\tif (state.route?.nonce == null) {\n\t\tstate.route = {\n\t\t\tnonce: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),\n\t\t\tdepth: 1,\n\t\t} \n\t\thistory.replaceState(state, '')\n\t} else if (stateRoute.nonce === state.route.nonce) {\n\t\tnav = state.route.depth > stateRoute.depth ? 'forward' : 'back'\n\t}\n\tstateRoute = state.route\n\n\tif (unproxy(route).mode === 'back') {\n\t\troute.depth = stateRoute.depth\n\t\t// We are still in the process of searching for a page in our navigation history..\n\t\tupdateHistory()\n\t\treturn\n\t}\n\n\tconst search: any= {}\n\tfor(let [k, v] of new URLSearchParams(location.search)) {\n\t\tsearch[k] = v\n\t}\n\n\troute.path = location.pathname\n\troute.p = location.pathname.slice(1).split('/')\n\troute.search = search\n\troute.hash = location.hash\n\troute.id = state.id\n\troute.aux = state.aux\n\troute.depth = stateRoute.depth\n\troute.nav = nav\n\n\t// Forward or back event. Redraw synchronously, because we can!\n\tif (event) runQueue();\n}\nhandleLocationUpdate()\nwindow.addEventListener(\"popstate\", handleLocationUpdate);\n\n// These immediate-mode observers will rewrite the data in `route` to its canonical form.\n// We want to to this immediately, so that user-code running immediately after a user-code\n// initiated `set` will see the canonical form (instead of doing a rerender shortly after,\n// or crashing due to non-canonical data).\nfunction updatePath(): void {\n\tlet path = route.path\n\tif (path == null && unproxy(route).p) {\n\t\treturn updateP()\n\t} \n\tpath = ''+(path || '/')\n\tif (!path.startsWith('/')) path = '/'+path\n\troute.path = path\n\troute.p = path.slice(1).split('/')\n}\nimmediateObserve(updatePath)\n\nfunction updateP(): void {\n\tconst p = route.p\n\tif (p == null && unproxy(route).path) {\n\t\treturn updatePath()\n\t}\n\tif (!(p instanceof Array)) {\n\t\tconsole.error(`aberdeen route: 'p' must be a non-empty array, not ${JSON.stringify(p)}`)\n\t\troute.p = [''] // This will cause a recursive call this observer.\n\t} else if (p.length == 0) {\n\t\troute.p = [''] // This will cause a recursive call this observer.\n\t} else {\n\t\troute.path = '/' + p.join('/')\n\t}\n}\nimmediateObserve(updateP)\n\nimmediateObserve(() => {\n\tif (!route.search || typeof route.search !== 'object') route.search = {}\n})\n\nimmediateObserve(() => {\n\tif (!route.id || typeof route.id !== 'object') route.id = {}\n})\n\nimmediateObserve(() => {\n\tif (!route.aux || typeof route.aux !== 'object') route.aux = {}\n})\n\nimmediateObserve(() => {\n\tlet hash = ''+(route.hash || '')\n\tif (hash && !hash.startsWith('#')) hash = '#'+hash\n\troute.hash = hash\n})\n\nfunction isSamePage(path: string, state: any): boolean {\n\treturn location.pathname === path && JSON.stringify(history.state.id) === JSON.stringify(state.id)\n}\n\nfunction updateHistory() {\n\t// Get and delete mode without triggering anything.\n\tlet mode = route.mode\n\tconst state = {\n\t\tid: clone(route.id),\n\t\taux: clone(route.aux),\n\t\troute: stateRoute,\n\t}\n\t\n\t// Construct the URL.\n\tconst path = route.path\n\n\t// Change browser state, according to `mode`.\n\tif (mode === 'back') {\n\t\troute.nav = 'back'\n\t\tif (!isSamePage(path, state) && (history.state.route?.depth||0) > 1) {\n\t\t\thistory.back()\n\t\t\treturn\n\t\t}\n\t\tmode = 'replace'\n\t\t// We'll replace the state async, to give the history.go the time to take affect first.\n\t\t//setTimeout(() => history.replaceState(state, '', url), 0)\n\t}\n\n\tif (mode) route.mode = undefined\n\tconst search = new URLSearchParams(route.search).toString()\n\tconst url = (search ? path+'?'+search : path) + route.hash\n\t\t\n\tif (mode === 'push' || (!mode && !isSamePage(path, state))) {\n\t\tstateRoute.depth++ // stateRoute === state.route\n\t\thistory.pushState(state, '', url)\n\t\troute.nav = 'push'\n\t\troute.depth = stateRoute.depth\n\t} else {\n\t\t// Default to `push` when the URL changed or top-level state keys changed.\n\t\thistory.replaceState(state, '', url)\n\t}\n}\n\n// This deferred-mode observer will update the URL and history based on `route` changes.\nobserve(updateHistory)\n\n\n/**\n * Restore and store the vertical and horizontal scroll position for\n * the parent element to the page state.\n * \n * @param {string} name - A unique (within this page) name for this\n * scrollable element. Defaults to 'main'.\n * \n * The scroll position will be persisted in `route.aux.scroll.<name>`.\n */\nexport function persistScroll(name: string = 'main') {\n\tconst el = getParentElement()\n\tel.addEventListener('scroll', onScroll)\n\tclean(() => el.removeEventListener('scroll', onScroll))\n\n\tlet restore = unproxy(route).aux.scroll?.name\n\tif (restore) {\n\t\tObject.assign(el, restore)\n\t}\n\n\tfunction onScroll() {\n\t\troute.mode = 'replace'\n\t\tif (!route.aux.scroll) route.aux.scroll = {}\n\t\troute.aux.scroll[name] = {scrollTop: el.scrollTop, scrollLeft: el.scrollLeft}\n\t}\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "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",
|
|
8
|
+
"debugId": "917712AC1764DFEF64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/transitions.js
CHANGED
|
@@ -1,74 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { DOM_READ_PHASE, DOM_WRITE_PHASE } from './aberdeen.js';
|
|
11
|
-
const FADE_TIME = 400;
|
|
12
|
-
const GROW_SHRINK_TRANSITION = `margin ${FADE_TIME}ms ease-out, transform ${FADE_TIME}ms ease-out`;
|
|
1
|
+
// src/transitions.ts
|
|
2
|
+
var FADE_TIME = 400;
|
|
3
|
+
var GROW_SHRINK_TRANSITION = `margin ${FADE_TIME}ms ease-out, transform ${FADE_TIME}ms ease-out`;
|
|
13
4
|
function getGrowShrinkProps(el) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{ marginLeft: `-${el.offsetWidth / 2}px`, marginRight: `-${el.offsetWidth / 2}px`, transform: "scaleX(0)" } :
|
|
18
|
-
{ marginBottom: `-${el.offsetHeight / 2}px`, marginTop: `-${el.offsetHeight / 2}px`, transform: "scaleY(0)" };
|
|
5
|
+
const parentStyle = el.parentElement ? getComputedStyle(el.parentElement) : {};
|
|
6
|
+
const isHorizontal = parentStyle.display === "flex" && (parentStyle.flexDirection || "").startsWith("row");
|
|
7
|
+
return isHorizontal ? { marginLeft: `-${el.offsetWidth / 2}px`, marginRight: `-${el.offsetWidth / 2}px`, transform: "scaleX(0)" } : { marginBottom: `-${el.offsetHeight / 2}px`, marginTop: `-${el.offsetHeight / 2}px`, transform: "scaleY(0)" };
|
|
19
8
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Wait until all DOM updates have been done. Then get info from the computed layout.
|
|
31
|
-
yield DOM_READ_PHASE;
|
|
32
|
-
let props = getGrowShrinkProps(el);
|
|
33
|
-
// In the write phase, make the element size 0 using transforms and negative margins.
|
|
34
|
-
yield DOM_WRITE_PHASE;
|
|
35
|
-
Object.assign(el.style, props);
|
|
36
|
-
// Await read phase, to combine multiple transitions into a single browser layout
|
|
37
|
-
yield DOM_READ_PHASE;
|
|
38
|
-
// Make sure the layouting has been performed, to cause transitions to trigger
|
|
39
|
-
el.offsetHeight;
|
|
40
|
-
// In the next write phase, do the transitions
|
|
41
|
-
yield DOM_WRITE_PHASE;
|
|
42
|
-
el.style.transition = GROW_SHRINK_TRANSITION;
|
|
43
|
-
for (let prop in props)
|
|
44
|
-
el.style[prop] = '';
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
// Disable transitions.
|
|
47
|
-
el.style.transition = '';
|
|
48
|
-
}, FADE_TIME);
|
|
49
|
-
});
|
|
9
|
+
async function grow(el) {
|
|
10
|
+
let props = getGrowShrinkProps(el);
|
|
11
|
+
Object.assign(el.style, props);
|
|
12
|
+
el.offsetHeight;
|
|
13
|
+
el.style.transition = GROW_SHRINK_TRANSITION;
|
|
14
|
+
for (let prop in props)
|
|
15
|
+
el.style[prop] = "";
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
el.style.transition = "";
|
|
18
|
+
}, FADE_TIME);
|
|
50
19
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*/
|
|
59
|
-
export function shrink(el) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
// Wait until all DOM updates have been done. Then get info from the computed layout.
|
|
62
|
-
yield DOM_READ_PHASE;
|
|
63
|
-
const props = getGrowShrinkProps(el);
|
|
64
|
-
// Batch starting transitions in the write phase.
|
|
65
|
-
yield DOM_WRITE_PHASE;
|
|
66
|
-
el.style.transition = GROW_SHRINK_TRANSITION;
|
|
67
|
-
Object.assign(el.style, props);
|
|
68
|
-
// Remove the element after the transition is done.
|
|
69
|
-
setTimeout(() => {
|
|
70
|
-
el.remove();
|
|
71
|
-
}, FADE_TIME);
|
|
72
|
-
});
|
|
20
|
+
async function shrink(el) {
|
|
21
|
+
const props = getGrowShrinkProps(el);
|
|
22
|
+
el.style.transition = GROW_SHRINK_TRANSITION;
|
|
23
|
+
Object.assign(el.style, props);
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
el.remove();
|
|
26
|
+
}, FADE_TIME);
|
|
73
27
|
}
|
|
74
|
-
|
|
28
|
+
export {
|
|
29
|
+
shrink,
|
|
30
|
+
grow
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//# debugId=ADD871168A635CB264756E2164756E21
|
|
34
|
+
//# sourceMappingURL=transitions.js.map
|
package/dist/transitions.js.map
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/transitions.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"const FADE_TIME = 400\nconst GROW_SHRINK_TRANSITION = `margin ${FADE_TIME}ms ease-out, transform ${FADE_TIME}ms ease-out`\n\nfunction getGrowShrinkProps(el: HTMLElement) {\n\tconst parentStyle: any = el.parentElement ? getComputedStyle(el.parentElement) : {}\n\tconst isHorizontal = parentStyle.display === 'flex' && (parentStyle.flexDirection||'').startsWith('row')\n\treturn isHorizontal ?\n\t\t{marginLeft: `-${el.offsetWidth/2}px`, marginRight: `-${el.offsetWidth/2}px`, transform: \"scaleX(0)\"} :\n\t\t{marginBottom: `-${el.offsetHeight/2}px`, marginTop: `-${el.offsetHeight/2}px`, transform: \"scaleY(0)\"}\n\n}\n\n/** Do a grow transition for the given element. This is meant to be used as a\n* handler for the `create` property.\n*\n* @param el The element to transition.\n*\n* The transition doesn't look great for table elements, and may have problems\n* for other specific cases as well.\n*/\nexport async function grow(el: HTMLElement) {\n\tlet props = getGrowShrinkProps(el)\n\tObject.assign(el.style, props)\n\t\n\t// Make sure the layouting has been performed, to cause transitions to trigger\n\tel.offsetHeight\n\n\tel.style.transition = GROW_SHRINK_TRANSITION\n\tfor(let prop in props) el.style[prop as any] = ''\n\tsetTimeout(() => {\n\t\t// Disable transitions.\n\t\tel.style.transition = ''\n\t}, FADE_TIME)\n}\n\n/** Do a shrink transition for the given element, and remove it from the DOM\n* afterwards. This is meant to be used as a handler for the `destroy` property.\n*\n* @param el The element to transition and remove.\n*\n* The transition doesn't look great for table elements, and may have problems\n* for other specific cases as well.\n*/\nexport async function shrink(el: HTMLElement) {\n\t// Get original layout info\n\tconst props = getGrowShrinkProps(el)\n\n\t// Batch starting transitions in the write phase.\n\tel.style.transition = GROW_SHRINK_TRANSITION\n\tObject.assign(el.style, props)\n\t\n\t// Remove the element after the transition is done.\n\tsetTimeout(() => {\n\t\tel.remove()\n\t}, FADE_TIME)\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAAA,IAAM,YAAY;AAClB,IAAM,yBAAyB,UAAU,mCAAmC;AAE5E,SAAS,kBAAkB,CAAC,IAAiB;AAAA,EAC5C,MAAM,cAAmB,GAAG,gBAAgB,iBAAiB,GAAG,aAAa,IAAI,CAAC;AAAA,EAClF,MAAM,eAAe,YAAY,YAAY,WAAW,YAAY,iBAAe,IAAI,WAAW,KAAK;AAAA,EACvG,OAAO,eACN,EAAC,YAAY,IAAI,GAAG,cAAY,OAAO,aAAa,IAAI,GAAG,cAAY,OAAO,WAAW,YAAW,IACpG,EAAC,cAAc,IAAI,GAAG,eAAa,OAAO,WAAW,IAAI,GAAG,eAAa,OAAO,WAAW,YAAW;AAAA;AAYxG,eAAsB,IAAI,CAAC,IAAiB;AAAA,EAC3C,IAAI,QAAQ,mBAAmB,EAAE;AAAA,EACjC,OAAO,OAAO,GAAG,OAAO,KAAK;AAAA,EAG7B,GAAG;AAAA,EAEH,GAAG,MAAM,aAAa;AAAA,EACtB,SAAQ,QAAQ;AAAA,IAAO,GAAG,MAAM,QAAe;AAAA,EAC/C,WAAW,MAAM;AAAA,IAEhB,GAAG,MAAM,aAAa;AAAA,KACpB,SAAS;AAAA;AAWb,eAAsB,MAAM,CAAC,IAAiB;AAAA,EAE7C,MAAM,QAAQ,mBAAmB,EAAE;AAAA,EAGnC,GAAG,MAAM,aAAa;AAAA,EACtB,OAAO,OAAO,GAAG,OAAO,KAAK;AAAA,EAG7B,WAAW,MAAM;AAAA,IAChB,GAAG,OAAO;AAAA,KACR,SAAS;AAAA;",
|
|
8
|
+
"debugId": "ADD871168A635CB264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist-min/aberdeen.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
var t=this&&this.t||function(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{l(n.next(t))}catch(t){o(t)}}function h(t){try{l(n.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,h)}l((n=n.apply(t,e||[])).next())}))};let e=[],i=0,n=new Set,r=!0,o=0,s=!1;function h(t){if(!n.has(t)){if(o>42)throw new Error("Too many recursive updates from observes");e.length?t.i<e[e.length-1].i&&(r=!1):setTimeout(runQueue,0),e.push(t),n.add(t)}}export function runQueue(){for(s=!0;i<e.length;){r||(e.splice(0,i),i=0,e.sort(((t,e)=>t.i-e.i)),r=!0);let t=e.length;for(;i<t&&r;){let t=e[i++];n.delete(t),t.o()}o++}i=0,e.length=0,o=0,s=!1}let l=[],u=!1;export const DOM_READ_PHASE={then:function(t){return u?t():(l.length||h(c),l.push(t)),this}};export const DOM_WRITE_PHASE={then:function(t){return u?(l.length||h(c),l.push(t)):t(),this}};const c={i:99999,o:function(){let t=l;l=[],u=!u;for(let e of t)try{e()}catch(t){console.error(t)}}};function f(t){if("string"==typeof t)return t+"";{let e=function(t,e){let i="";for(;t>0;)i+=String.fromCharCode(e?65535-t%65533:2+t%65533),t=Math.floor(t/65533);return i}(Math.abs(Math.round(t)),t<0);return String.fromCharCode(128+(t>0?e.length:-e.length))+e}}class a{constructor(t,e,i){this.h=t,this.l=e,this.i=i,this.u=[],this.p=!1}v(t=void 0){let e,i=this;for(;(e=i.l)&&e!==t;){if(e instanceof Node)return e;let t=e.m();if(t)return t;i=e}}m(){if(this._)return this._ instanceof Node?this._:this._.m()||this._.v(this.l)}O(t){let e=this.m()||this.v();this.h.insertBefore(t,e?e.nextSibling:this.h.firstChild),this._=t}S(){if(this.h){let t=this.m();if(t){let e=this.v();for(e=e?e.nextSibling:this.h.firstChild,this._=void 0;;){if(!e)return z(1);const i=e;e=i.nextSibling||void 0;let n=M.get(i);if(n&&i instanceof Element?!0!==n&&("function"==typeof n?n(i):N(i,n),M.set(i,!0)):this.h.removeChild(i),i===t)break}}}this.C()}C(){this.p=!0;for(let t of this.u)t.C(this);this.u.length=0}$(t,e,i){h(this)}}class d extends a{constructor(t,e,i,n){super(t,e,i),n&&(this.M=n)}M(){z(14)}o(){b&&z(2),this.p||(this.S(),this.p=!1,this.N())}N(){let t=b;b=this;try{this.M()}catch(t){U(t,!0)}b=t}T(){s?(s=!1,this.N(),s=!0):this.N(),b.u.push(this)}}class w extends d{constructor(t,e,i,n,r){super(t,e,i),this.j=n,this.A=r}M(){I(this.h,this.j,this.A.get())}}let p=new Set;class v extends d{$(t,e,i){p.add(this)}}let b,m=!1;function y(){if(!m)for(let t=0;p.size;t++){if(t>42)throw p.clear(),new Error("Too many recursive updates from immediate-mode observes");m=!0;let e=p;p=new Set;let i=b;b=void 0;try{for(const t of e)t.o()}finally{b=i,m=!1}}}class _{constructor(t,e,i){this.scope=t,this.collection=e,this.triggerCount=i,this.count=e.I(),e.J(x,this),t.u.push(this)}$(t,e,i){void 0===e?!this.triggerCount&&--this.count||h(this.scope):void 0===i&&(!this.triggerCount&&this.count++||h(this.scope))}C(){this.collection.R(x,this)}}class g extends a{constructor(t,e,i,n,r,o){super(t,e,i),this.P=[],this.D=new Map,this.H=new Set,this.k=new Set,this.q=n,this.M=r,this.U=o}$(t,e,i){void 0===i?this.k.has(t)?this.k.delete(t):(this.H.add(t),h(this)):void 0===e&&(this.H.has(t)?this.H.delete(t):(this.k.add(t),h(this)))}o(){if(this.p)return;let t=this.k;this.k=new Set,t.forEach((t=>{this.W(t)})),t=this.H,this.H=new Set,t.forEach((t=>{this.F(t)}))}C(){super.C(),this.q.G.delete(this);for(const[t,e]of this.D)e.C();this.P.length=0,this.D.clear()}B(){if(!b)return z(3);let t=b;this.q.L(this),b=t}F(t){let e=new O(this.h,void 0,this.i+1,this,t);this.D.set(t,e),e.N()}W(t){let e=this.D.get(t);if(!e)return z(6);e.S(),this.D.delete(t),this.K(e)}V(t){let e=this.P,i=0,n=e.length;if(!n||t>e[n-1].X)return n;for(;i<n;){let r=i+n>>1;e[r].X<t?i=r+1:n=r}return i}Y(t){let e=this.V(t.X);this.P.splice(e,0,t);let i=this.P[e+1];i?(t.l=i.l,i.l=t):(t.l=this._||this.l,this._=t)}K(t){if(""===t.X)return;let e=this.V(t.X);for(;;){if(this.P[e]===t){if(this.P.splice(e,1),e<this.P.length){let i=this.P[e];if(!i)return z(8);if(i.l!==t)return z(13);i.l=t.l}else{if(t!==this._)return z(12);this._=t.l===this.l?void 0:t.l}return}if(++e>=this.P.length||this.P[e].X!==t.X)return z(5)}}}class O extends a{constructor(t,e,i,n,r){super(t,e,i),this.X="",this.Z=n,this.tt=r}o(){b&&z(4),this.p||(this.S(),this.p=!1,this.N())}N(){let t=b;b=this;let e,i=new Store(this.Z.q,this.tt);try{e=this.Z.U(i)}catch(t){U(t,!1)}let n=this.X,r=null==e?"":(o=e)instanceof Array?o.map(f).join(""):f(o);var o;if(""!==n&&n!==r&&this.Z.K(this),this.X=r,""!==r){r!==n&&this.Z.Y(this);try{this.Z.M(i)}catch(t){U(t,!0)}}b=t}}const x={};export class ObsCollection{constructor(){this.G=new Map}J(t,e){let i=this.G.get(t);if(i){if(i.has(e))return!1;i.add(e)}else this.G.set(t,new Set([e]));return!0}R(t,e){this.G.get(t).delete(e)}emitChange(t,e,i){let n=this.G.get(t);n&&n.forEach((n=>n.$(t,e,i))),n=this.G.get(x),n&&n.forEach((n=>n.$(t,e,i)))}C(t){this.R(x,t)}et(t,e,i){const n=this.rawGet(t);if(!(n instanceof ObsCollection)||e instanceof Store||!n.it(e,i)){let i=k(e);i!==n&&(this.rawSet(t,i),this.emitChange(t,i,n))}}}class S extends ObsCollection{constructor(){super(...arguments),this.nt=[]}rt(){return"array"}ot(t){b&&this.J(x,b)&&b.u.push(this);let e=[];for(let i=0;i<this.nt.length;i++){let n=this.nt[i];e.push(n instanceof ObsCollection?t?n.ot(t-1):new Store(this,i):n)}return e}rawGet(t){return this.nt[t]}rawSet(t,e){if(t!==(0|t)||t<0||t>999999)throw new Error(`Invalid array index ${JSON.stringify(t)}`);for(this.nt[t]=e;this.nt.length>0&&void 0===this.nt[this.nt.length-1];)this.nt.pop()}it(t,e){if(!(t instanceof Array))return!1;for(let i=0;i<t.length;i++)this.et(i,t[i],e);if(this.nt.length>t.length){for(let e=t.length;e<this.nt.length;e++){let t=this.nt[e];void 0!==t&&this.emitChange(e,void 0,t)}this.nt.length=t.length}return!0}L(t){for(let e=0;e<this.nt.length;e++)void 0!==this.nt[e]&&t.F(e)}st(t){if("number"==typeof t)return t;if("string"==typeof t){let e=0|t;if(t.length&&e==t)return t}throw new Error(`Invalid array index ${JSON.stringify(t)}`)}I(){return this.nt.length}}class E extends ObsCollection{constructor(){super(...arguments),this.data=new Map}rt(){return"map"}ot(t){b&&this.J(x,b)&&b.u.push(this);let e=new Map;return this.data.forEach(((i,n)=>{e.set(n,i instanceof ObsCollection?t?i.ot(t-1):new Store(this,n):i)})),e}rawGet(t){return this.data.get(t)}rawSet(t,e){void 0===e?this.data.delete(t):this.data.set(t,e)}it(t,e){return t instanceof Map&&(t.forEach(((t,i)=>{this.et(i,t,e)})),e&&this.data.forEach(((e,i)=>{t.has(i)||this.et(i,void 0,!1)})),!0)}L(t){this.data.forEach(((e,i)=>{t.F(i)}))}st(t){return t}I(){return this.data.size}}class C extends E{rt(){return"object"}ot(t){b&&this.J(x,b)&&b.u.push(this);let e={};return this.data.forEach(((i,n)=>{e[n]=i instanceof ObsCollection?t?i.ot(t-1):new Store(this,n):i})),e}it(t,e){if(!t||t.constructor!==Object)return!1;for(let i in t)this.et(i,t[i],e);return e&&this.data.forEach(((e,i)=>{t.hasOwnProperty(i)||this.et(i,void 0,!1)})),!0}st(t){let e=typeof t;if("string"===e)return t;if("number"===e)return""+t;throw new Error(`Invalid object index ${JSON.stringify(t)}`)}I(){let t=0;for(let e of this.data)t++;return t}}export class Store{constructor(t=void 0,e=void 0){const i=function(...t){const e=new Store(i.q,i.ht);return(t.length||i.lt)&&(e.lt=i.lt?i.lt.concat(t):t),e};if(Object.setPrototypeOf(i,Store.prototype),void 0===e)i.q=new S,i.ht=0,void 0!==t&&i.q.rawSet(0,k(t));else{if(!(t instanceof ObsCollection))throw new Error("1st parameter should be an ObsCollection if the 2nd is also given");i.q=t,i.ht=e}return i}index(){return this.ht}C(t){this.q.R(this.ht,t)}get(t=0){let e=this.ut();return e instanceof ObsCollection?e.ot(t-1):e}peek(t=0){let e=b;b=void 0;let i=this.get(t);return b=e,i}getTyped(t,e=0){let i=this.ut(),n=i instanceof ObsCollection?i.rt():null===i?"null":typeof i;if(n!==t)throw new TypeError(`Expecting ${t} but got ${n}`);return i instanceof ObsCollection?i.ot(e-1):i}getNumber(){return this.getTyped("number")}getString(){return this.getTyped("string")}getBoolean(){return this.getTyped("boolean")}getFunction(){return this.getTyped("function")}getArray(t=0){return this.getTyped("array",t)}getObject(t=0){return this.getTyped("object",t)}getMap(t=0){return this.getTyped("map",t)}getOr(t){let e=this.ut();if(void 0===e)return t;let i=typeof t;"object"===i&&(t instanceof Map?i="map":t instanceof Array?i="array":null===t&&(i="null"));let n=e instanceof ObsCollection?e.rt():null===e?"null":typeof e;if(n!==i)throw new TypeError(`Expecting ${i} but got ${n}`);return e instanceof ObsCollection?e.ot(-1):e}isEmpty(){let t=this.ut();if(t instanceof ObsCollection){if(b){return!new _(b,t,!1).count}return!t.I()}if(void 0===t)return!0;throw new Error(`isEmpty() expects a collection or undefined, but got ${JSON.stringify(t)}`)}count(){let t=this.ut();if(t instanceof ObsCollection){if(b){return new _(b,t,!0).count}return t.I()}if(void 0===t)return 0;throw new Error(`count() expects a collection or undefined, but got ${JSON.stringify(t)}`)}getType(){let t=this.ut();return t instanceof ObsCollection?t.rt():null===t?"null":typeof t}if(t,e){const i=new Store;return observe((()=>{const n=this.get()?t:e;i.set(n)})),i}set(t){return this.ct(!0),this.q.et(this.ht,t,!0),y(),this}ct(t){if(!this.lt)return!0;let e=this.q,i=this.ht;for(let n=0;n<this.lt.length;n++){!t&&b&&e.J(i,b)&&b.u.push(this);let r=e.rawGet(i);if(!(r instanceof ObsCollection)){if(void 0!==r)throw new Error(`While resolving ${JSON.stringify(this.lt)}, found ${JSON.stringify(r)} at index ${n} instead of a collection.`);if(!t)return!1;r=new C,e.rawSet(i,r),e.emitChange(i,r,void 0)}e=r;const o=this.lt[n];i=e.st(o)}return this.q=e,this.ht=i,delete this.lt,!0}merge(t){return this.ct(!0),this.q.et(this.ht,t,!1),y(),this}delete(){return this.ct(!0),this.q.et(this.ht,void 0,!0),y(),this}push(t){this.ct(!0);let e=this.q.rawGet(this.ht);if(void 0===e)e=new S,this.q.et(this.ht,e,!0);else if(!(e instanceof S))throw new TypeError("push() is only allowed for an array or undefined (which would become an array)");let i=k(t),n=e.nt.length;return e.nt.push(i),e.emitChange(n,i,void 0),y(),n}modify(t){return this.set(t(this.peek())),this}ut(){if(this.ct(!1))return b&&this.q.J(this.ht,b)&&b.u.push(this),this.q.rawGet(this.ht)}onEach(t,e=q){if(!b)return void H(void 0,(()=>this.onEach(t,e)),d);let i=this.ut();if(i instanceof ObsCollection){let n=new g(b.h,b._||b.l,b.i+1,i,t,e);i.J(x,n),b.u.push(n),b._=n,n.B()}else if(void 0!==i)throw new Error("onEach() attempted on a value that is neither a collection nor undefined")}derive(t){let e=new Store;return observe((()=>{e.set(t(this.get()))})),e}map(t){let e=new Store;return observe((()=>{let i=this.getType();e.set("array"===i?[]:"object"===i?{}:new Map),this.onEach((i=>{let n=t(i);if(void 0!==n){let t=i.index();const r=e(t);r.set(n),clean((()=>{r.delete()}))}}))})),e}multiMap(t){let e=new Store(new Map);return this.onEach((i=>{let n=t(i),r=[];if(n.constructor===Object)for(let t in n){const i=e(t);i.set(n[t]),r.push(i)}else{if(!(n instanceof Map))return;n.forEach(((t,i)=>{const n=e(i);n.set(t),r.push(n)}))}r.length&&clean((()=>{for(let t of r)t.delete()}))})),e}dump(){let t=this.getType();return"array"===t||"object"===t||"map"===t?($({text:`<${t}>`}),$("ul",(()=>{this.onEach((t=>{$("li:"+JSON.stringify(t.index())+": ",(()=>{t.dump()}))}))}))):$({text:JSON.stringify(this.get())}),this}}let M=new WeakMap;function N(t,e){t.classList.add(e),setTimeout((()=>t.remove()),2e3)}function T(t,e){t===b.h?b.O(e):t.appendChild(e)}function j(t,e,i){if(null==i)return;if(!(i instanceof Store))throw new Error(`Unexpect bind-argument: ${JSON.parse(i)}`);const n=t;let r,o,s=n.getAttribute("type"),h=i.peek();"checkbox"===s?(void 0===h&&i.set(n.checked),r=t=>n.checked=t,o=()=>i.set(n.checked)):"radio"===s?(void 0===h&&n.checked&&i.set(n.value),r=t=>n.checked=t===n.value,o=()=>{n.checked&&i.set(n.value)}):(o=()=>i.set("number"===s||"range"===s?""===n.value?null:+n.value:n.value),void 0===h&&o(),r=t=>{n.value!==t&&(n.value=t)}),observe((()=>{r(i.get())})),n.addEventListener("input",o),clean((()=>{n.removeEventListener("input",o)}))}const A={create:function(e,i){s&&("function"==typeof i?i(e):(e.classList.add(i),function(){t(this,void 0,void 0,(function*(){yield DOM_READ_PHASE,e.offsetHeight,yield DOM_WRITE_PHASE,e.classList.remove(i)}))}()))},destroy:function(t,e){M.set(t,e)},html:function(t,e){if(!e)return;let i=document.createElement(t.tagName);for(i.innerHTML=""+e;i.firstChild;)T(t,i.firstChild)},text:function(t,e){null!=e&&T(t,document.createTextNode(e))},element:function(t,e){if(null!=e){if(!(e instanceof Node))throw new Error(`Unexpect element-argument: ${JSON.parse(e)}`);T(t,e)}}};export function $(...t){if(!b||!b.h)throw new W(!0);let e=b.h;for(let i of t)if(null!=i&&!1!==i)if("string"==typeof i){let t,n;const r=i.indexOf(":");if(r>=0){if(t=i.substring(r+1),0===r){T(e,document.createTextNode(t));continue}i=i.substring(0,r)}const o=i.indexOf(".");if(o>=0&&(n=i.substring(o+1).replaceAll("."," "),i=i.substring(0,o)),i.indexOf(" ")>=0)throw new Error(`Tag '${i}' cannot contain space`);const s=document.createElement(i||"div");n&&(s.className=n),t&&(s.textContent=t),T(e,s),e=s}else if("object"==typeof i){if(i.constructor!==Object)throw new Error(`Unexpected argument: ${i}`);for(const t in i){const n=i[t];if("bind"===t)j(e,0,n);else if(n instanceof Store){new w(e,e.lastChild,b.i+1,t,n).T()}else I(e,t,n)}}else{if("function"!=typeof i)throw new Error(`Unexpected argument: ${JSON.stringify(i)}`);if(e===b.h)H(void 0,t[0],d);else{new d(e,e.lastChild,b.i+1,i).T()}}}function I(t,e,i){if("."===e[0]){const n=e.substring(1).split(".");i?t.classList.add(...n):t.classList.remove(...n)}else if("$"===e[0]){const n=e.substring(1);t.style[n]=null==i||!1===i?"":""+i}else e in A?A[e](t,i):"function"==typeof i?(t.addEventListener(e,i),clean((()=>t.removeEventListener(e,i)))):!0===i||!1===i||"value"===e||"selectedIndex"===e?t[e]=i:t.setAttribute(e,i)}function J(t){return console.error("Error while in Aberdeen render:",t),!0}let R=J;export function setErrorHandler(t){R=t||J}export function getParentElement(){if(!b||!b.h)throw new W(!0);return b.h}export function clean(t){if(!b)throw new W(!1);b.u.push({C:t})}export function observe(t){return H(void 0,t,d)}export function immediateObserve(t){return H(void 0,t,v)}export function mount(t,e){for(let e of D.values())if(t===e.h)throw new Error("Only a single mount per parent element");return H(t,e,d)}let P=0;const D=new Map;function H(t,e,i){let n;if(t||!b?n=new i(t,void 0,0,e):(n=new i(b.h,b._||b.l,b.i+1,e),b._=n),n.N(),!b)return D.set(++P,n),P;b.u.push(n)}export function unmount(t){if(null==t){for(let t of D.values())t.S();D.clear()}else{let e=D.get(t);if(!e)throw new Error("No such mount "+t);D.delete(t),e.S()}}export function peek(t){let e=b;b=void 0;try{return t()}finally{b=e}}function k(t){if(t instanceof Store)return t.ut();if("object"==typeof t&&t){if(t instanceof Map){let e=new E;return t.forEach(((t,i)=>{let n=k(t);void 0!==n&&e.rawSet(i,n)})),e}if(t instanceof Array){let e=new S;for(let i=0;i<t.length;i++){let n=k(t[i]);void 0!==n&&e.rawSet(i,n)}return e}if(t.constructor===Object){let e=new C;for(let i in t){let n=k(t[i]);void 0!==n&&e.rawSet(i,n)}return e}return t}return t}function q(t){return t.index()}function z(t){throw new Error("Aberdeen internal error "+t)}function U(t,e){try{!1===R(t)&&(e=!1)}catch(t){}e&&(null==b?void 0:b.h)&&$(".aberdeen-error:Error")}class W extends Error{constructor(t){super(`Operation not permitted outside of ${t?"a mount":"an observe"}() scope`)}}export function withEmitHandler(t,e){const i=ObsCollection.prototype.emitChange;ObsCollection.prototype.emitChange=t;try{e()}finally{ObsCollection.prototype.emitChange=i}}String.prototype.replaceAll||(String.prototype.replaceAll=function(t,e){return this.split(t).join(e)});
|
|
2
|
-
|
|
1
|
+
class N{keyProp;tail;symbols;constructor(z){this.keyProp=z;this.tail={},this.symbols=[Symbol(0)]}add(z){if(this.symbols[0]in z)return!1;let F=1+(Math.clz32(Math.random()*4294967295)>>2);for(let W=this.symbols.length;W<F;W++)this.symbols.push(Symbol(W));let J=this.keyProp,X=z[J],Z,U=this.tail;for(let W=this.symbols.length-1;W>=0;W--){let j=this.symbols[W];while((Z=U[j])&&Z[J]>X)U=Z;if(W<F)z[j]=U[j],U[j]=z}return!0}has(z){return this.symbols[0]in z}fetchLast(){let z=this.tail[this.symbols[0]];if(z)return this.remove(z),z}isEmpty(){return this.tail[this.symbols[0]]===void 0}get(z){let F=this.keyProp,J=this.tail,X;for(let Z=this.symbols.length-1;Z>=0;Z--){let U=this.symbols[Z];while((X=J[U])&&X[F]>z)J=X}return J[this.symbols[0]]?.[F]===z?J[this.symbols[0]]:void 0}*[Symbol.iterator](){let z=this.symbols[0],F=this.tail[z];while(F)yield F,F=F[z]}prev(z){return z[this.symbols[0]]}remove(z){if(!(this.symbols[0]in z))return!1;let F=this.keyProp,J=z[F],X,Z=this.tail;for(let U=this.symbols.length-1;U>=0;U--){let W=this.symbols[U];while((X=Z[W])&&X[F]>=J&&X!==z)Z=X;if(X===z)Z[W]=X[W],delete X[W]}return X===z}clear(){let z=this.symbols[0],F=this.tail;while(F){let J=F[z];for(let X of this.symbols){if(!(X in F))break;delete F[X]}F=J}this.tail={}}}var B,_=0,G;function f(z){if(!B)B=new N("prio"),setTimeout(Kz,0);else if(!(_&1)){if(_++,_>98)throw new Error("Too many recursive updates from observes")}B.add(z)}function Kz(){let z=Date.now();while(B){let F=B.fetchLast();if(!F)break;if(_&1)_++;F.queueRun()}if(B=void 0,_=0,z=Date.now()-z,z>1)console.debug(`Aberdeen queue took ${z}ms`)}function l(z){if(typeof z==="string")return z+"\x01";let F="",J=Math.abs(Math.round(z)),X=z<0;while(J>0)F+=String.fromCharCode(X?65534-J%65533:2+J%65533),J=Math.floor(J/65533);return String.fromCharCode(128+(X?-F.length:F.length))+F}function Cz(z){let F="";for(let J=0;J<z.length;J++)F+=String.fromCodePoint(65535-z.charCodeAt(J));return F}var Gz=0;class d{prio=--Gz;remove(){let z=this.getLastNode();if(z)E(z,this.getPrecedingNode());this.delete()}}class C extends d{cleaners;constructor(z=[]){super();this.cleaners=z}lastChild;redraw(){}getLastNode(){return T(this.lastChild)}delete(){for(let z of this.cleaners)if(typeof z==="function")z();else z.delete(this);this.cleaners.length=0,B?.remove(this),this.lastChild=void 0}queueRun(){this.remove(),G=this,this.redraw(),G=void 0}getInsertAfterNode(){return this.getLastNode()||this.getPrecedingNode()}onChange(z,F,J){f(this)}getChildPrevSibling(){return this.lastChild}}class P extends C{parentElement;prevSibling;constructor(z,F=!1){super(F?q.cleaners:[]);this.parentElement=z;if(z===q.parentElement)this.prevSibling=q.getChildPrevSibling(),q.lastChild=this;if(!F)q.cleaners.push(this)}getPrecedingNode(){return T(this.prevSibling)}getChildPrevSibling(){return this.lastChild||this.prevSibling}}class b extends P{renderer;constructor(z,F){super(z);this.renderer=F;this.redraw()}redraw(){let z=q;q=this;try{this.renderer()}catch(F){c(F,!0)}q=z}}class r extends C{parentElement=document.body;getPrecedingNode(){return}}class t extends C{parentElement;renderer;constructor(z,F){super();this.parentElement=z;this.renderer=F;this.redraw(),q.cleaners.push(this)}redraw(){b.prototype.redraw.call(this)}getPrecedingNode(){return}delete(){E(this.getLastNode(),this.getPrecedingNode()),super.delete()}remove(){this.delete()}}function E(z,F){while(z&&z!==F){let J=z.previousSibling,X=S.get(z);if(X&&z instanceof Element){if(X!==!0){if(typeof X==="function")X(z);else Az(z,X);S.set(z,!0)}}else z.remove();z=J}}function T(z){if(!z||z instanceof Node)return z;return z.getLastNode()||z.getPrecedingNode()}class e extends P{renderer;result=A({value:void 0});constructor(z,F){super(z);this.renderer=F;this.redraw()}redraw(){let z=q;q=this;try{this.result.value=this.renderer()}catch(F){c(F,!0)}q=z}}class zz extends P{key;target;constructor(z,F,J){super(z);this.key=F;this.target=J;this.redraw()}redraw(){let z=q;q=this,jz(this.key,this.target.value),q=z}}var M=new N("prio");class Fz extends b{onChange(z,F,J){M.add(this)}}var v=!1;function w(){for(let z=0;!M.isEmpty()&&!v;z++){if(z>42)throw M.clear(),new Error("Too many immediate-mode recursive updates");v=!0;let F=M;M=new N("prio");try{for(let J of F)J.queueRun()}finally{v=!1}}}class Jz extends d{renderer;makeSortKey;parentElement=q.parentElement;prevSibling;target;byIndex=new Map;sortedSet=new N("sortKey");changedIndexes=new Set;constructor(z,F,J){super();this.renderer=F;this.makeSortKey=J;let X=this.target=z[$]||z;if(V(X,Q,this),this.prevSibling=q.getChildPrevSibling(),q.lastChild=this,q.cleaners.push(this),X instanceof Array){for(let Z=0;Z<X.length;Z++)if(X[Z]!==void 0)new h(this,Z,!1)}else for(let Z in X)if(X[Z]!==void 0)new h(this,Z,!1)}getPrecedingNode(){return T(this.prevSibling)}onChange(z,F,J){if(!(this.target instanceof Array)||typeof z==="number")this.changedIndexes.add(z);f(this)}queueRun(){let z=this.changedIndexes;this.changedIndexes=new Set;for(let F of z){let J=this.byIndex.get(F);if(J)J.remove();if(this.target[F]===void 0)this.byIndex.delete(F);else new h(this,F,!0)}G=void 0}delete(){for(let z of this.byIndex.values())z.delete();this.byIndex.clear(),setTimeout(()=>{this.sortedSet.clear()},1)}getLastNode(){for(let z of this.sortedSet){let F=z.getActualLastNode();if(F)return F}}}class h extends C{parent;itemIndex;sortKey;parentElement;constructor(z,F,J){super();this.parent=z;this.itemIndex=F;if(this.parentElement=z.parentElement,this.parent.byIndex.set(this.itemIndex,this),this.lastChild=this,J)G=this;this.redraw()}getPrecedingNode(){this.parent.sortedSet.add(this);let z=this.parent.sortedSet.prev(this);if(z)return T(z.lastChild);return this.parent.getPrecedingNode()}getLastNode(){return this.getPrecedingNode()}getActualLastNode(){let z=this.lastChild;while(z&&z!==this){if(z instanceof Node)return z;let F=z.getLastNode();if(F)return F;z=z.getPrecedingNode()}}queueRun(){if(q!==R)a(4);if(this.sortKey!==void 0){let z=this.getActualLastNode();if(z)E(z,this.getPrecedingNode())}this.delete(),this.lastChild=this,G=this,this.redraw(),G=void 0}redraw(){let z=A(this.parent.target[this.itemIndex]),F=q;q=this;let J;try{if(this.parent.makeSortKey){let X=this.parent.makeSortKey(z,this.itemIndex);if(X!=null)J=X instanceof Array?X.map(l).join(""):X}else J=this.itemIndex;if(typeof J==="number")J=l(J);if(this.sortKey!==J)this.parent.sortedSet.remove(this),this.sortKey=J;if(J!=null)this.parent.renderer(z,this.itemIndex)}catch(X){c(X,J!=null)}q=F}getInsertAfterNode(){if(this.sortKey==null)a(1);return T(this.lastChild)}remove(){if(this.sortKey!==void 0){let z=this.getActualLastNode();if(z)E(z,this.getPrecedingNode());this.parent.sortedSet.remove(this),this.sortKey=void 0}this.delete()}}function L(z){let F=q.parentElement,J=q.getInsertAfterNode();F.insertBefore(z,J?J.nextSibling:F.firstChild),q.lastChild=z}var R=new r,q=R,Q=Symbol("any"),$=Symbol("target"),y=new WeakMap,D=0;function V(z,F,J=q){if(J===R||D)return;let X=y.get(z);if(!X)y.set(z,X=new Map);if(F!==Q&&X.get(Q)?.has(J))return;let Z=X.get(F);if(!Z)X.set(F,Z=new Set);if(Z.has(J))return;if(Z.add(J),J===q)q.cleaners.push(Z);else q.cleaners.push(function(){Z.delete(J)})}function x(z,F,J){if(!z||typeof z!=="object")throw new Error("onEach requires an object");z=z[$]||z,new Jz(z,F,J)}function Xz(z){for(let F in z)return!1;return!0}function Pz(z){let F=z[$]||z,J=q;if(F instanceof Array)return V(F,"length",function(X,Z,U){if(!Z!==!U)f(J)}),!F.length;else{let X=Xz(F);return V(F,Q,function(Z,U,W){if(X?W===void 0:U===void 0)f(J)}),X}}function Rz(z){if(z instanceof Array)return Wz(z,"length");let F=z[$]||z,J=0;for(let Z in F)if(F[Z]!==void 0)J++;let X=Zz(J);return V(F,Q,function(Z,U,W){if(W===U);else if(W===void 0)X.value=++J;else if(U===void 0)X.value=--J}),X}function Vz(z,F,J,X){if(J===X&&J!==void 0)return;let Z=y.get(z);if(Z===void 0)return;for(let U of[F,Q]){let W=Z.get(U);if(W)for(let j of W)if(typeof j==="function")j(F,J,X);else j.onChange(F,J,X)}}var K=Vz,Qz={get(z,F){if(F===$)return z;return V(z,F),A(z[F])},set(z,F,J){if(typeof J==="object"&&J)J=J[$]||J;let X=z[F];if(J!==X)z[F]=J,K(z,F,J,X),w();return!0},deleteProperty(z,F){let J=z[F];return delete z[F],K(z,F,void 0,J),w(),!0},has(z,F){let J=F in z;return V(z,F),J},ownKeys(z){return V(z,Q),Reflect.ownKeys(z)}};function u(z,F,J){if(typeof J==="object"&&J)J=J[$]||J;let X=z[F];if(J!==X){let Z=z.length;if(F==="length"){z.length=J;for(let U=J;U<Z;U++)K(z,U,void 0,z[U])}else{let U=parseInt(F);if(U.toString()===F)F=U;z[F]=J,K(z,F,J,X)}if(z.length!==Z)K(z,"length",z.length,Z);w()}return!0}var Bz={get(z,F){if(F===$)return z;let J=F;if(typeof F!=="symbol"){let X=parseInt(F);if(X.toString()===F)J=X}return V(z,J),A(z[F])},set:u,deleteProperty(z,F){return u(z,F,void 0)}},s=new WeakMap;function A(z){if(typeof z!=="object"||!z||z[$]!==void 0)return z;let F=s.get(z);if(F)return F;return F=new Proxy(z,z instanceof Array?Bz:Qz),s.set(z,F),F}function Zz(z){return A(typeof z==="object"&&z!==null?z:{value:z})}function Uz(z){return z?z[$]||z:z}var S=new WeakMap;function Az(z,F){let J=F.split(".").filter((X)=>X);z.classList.add(...J),setTimeout(()=>z.remove(),2000)}function hz(z,F,J=0){k(z,F,J),w()}var g=1,Nz=2,p=32,O=64;function Oz(z,F=0){let J=Object.create(Object.getPrototypeOf(z));return k(J,z,F),J}function k(z,F,J){let X=z[$];if(X)z=X,J|=O;if(X=F[$],X){if(F=X,q!==R&&!D)J|=p}if(J&p)V(F,Q);if(F instanceof Array){if(!(z instanceof Array))throw new Error("Cannot copy array into object");let Z=z.length,U=F.length;for(let W=0;W<U;W++)n(z,F,W,J);if(U!==Z)if(J&O){for(let W=U;W<Z;W++){let j=z[W];z[W]=void 0,K(z,W,void 0,j)}z.length=U,K(z,"length",U,Z)}else z.length=U}else{for(let Z in F)n(z,F,Z,J);if(!(J&g)){for(let Z in z)if(!(Z in F)){let U=z[Z];if(delete z[Z],J&O&&U!==void 0)K(z,Z,void 0,U)}}}}function n(z,F,J,X){let Z=z[J],U=F[J];if(U!==Z){if(U&&Z&&typeof U==="object"&&typeof Z==="object"&&(U.constructor===Z.constructor||X&g&&Z instanceof Array)){k(Z,U,X);return}if(!(X&Nz)&&U&&typeof U==="object"){let j=Object.create(Object.getPrototypeOf(U));k(j,U,0),U=j}let W=z[J];if(X&g&&U==null)delete z[J];else z[J]=U;if(X&O)K(z,J,U,W)}}var Yz={get(z,F){if(F===$)return Wz(Uz(z.proxy),z.index);if(F==="value")return z.proxy[z.index]},set(z,F,J){if(F==="value")return z.proxy[z.index]=J,!0;return!1}};function Wz(z,F){return new Proxy({proxy:z,index:F},Yz)}function _z(z,F){let J=z,X,Z,U=J.getAttribute("type"),W=Uz(F).value;if(U==="checkbox"){if(W===void 0)F.value=J.checked;X=()=>J.checked=F.value,Z=()=>F.value=J.checked}else if(U==="radio"){if(W===void 0&&J.checked)F.value=J.value;X=()=>J.checked=F.value===J.value,Z=()=>{if(J.checked)F.value=J.value}}else{if(Z=()=>F.value=U==="number"||U==="range"?J.value===""?null:+J.value:J.value,W===void 0)Z();X=()=>J.value=F.value}Iz(X),J.addEventListener("input",Z),I(()=>{J.removeEventListener("input",Z)})}var o={create:function(z){let F=q.parentElement;if(q!==G)return;if(typeof z==="function")z(F);else{let J=z.split(".").filter((X)=>X);F.classList.add(...J),async function(){F.offsetHeight,F.classList.remove(...J)}()}},destroy:function(z){let F=q.parentElement;S.set(F,z)},html:function(z){let F=document.createElement(q.parentElement.tagName);F.innerHTML=""+z;while(F.firstChild)L(F.firstChild)},text:function(z){L(document.createTextNode(z))},element:function(z){if(!(z instanceof Node))throw new Error(`Unexpected element-argument: ${JSON.parse(z)}`);L(z)}};function Y(...z){let F,J;for(let X of z){if(X==null||X===!1)continue;if(typeof X==="string"){let Z,U,W=X.indexOf(":");if(W>=0)Z=X.substring(W+1),X=X.substring(0,W);let j=X.indexOf(".");if(j>=0)U=X.substring(j+1),X=X.substring(0,j);if(X===""){if(Z)L(document.createTextNode(Z));if(U){let H=q.parentElement;if(H.classList.add(...U.split(".")),!F)I(()=>H.classList.remove(...U.split(".")))}}else if(X.indexOf(" ")>=0){J=`Tag '${X}' cannot contain space`;break}else{let H=document.createElement(X);if(U)H.className=U.replaceAll("."," ");if(Z)H.textContent=Z;if(L(H),!F)F=q;let m=new P(H,!0);if(m.lastChild=H.lastChild||void 0,G===q)G=m;q=m}}else if(typeof X==="object"){if(X.constructor!==Object){J=`Unexpected argument: ${X}`;break}for(let Z in X){let U=X[Z];jz(Z,U)}}else if(typeof X==="function")new b(q.parentElement,X);else{J=`Unexpected argument: ${X}`;break}}if(F)q=F;if(J)throw new Error(J)}var qz=0;function fz(z,F=!1){let J=F?"":".AbdStl"+ ++qz,X=i(z,J);if(X)Y("style:"+X);return J}function i(z,F){let J="",X="";for(let Z in z){let U=z[Z];for(let W of Z.split(/, ?/g))if(U&&typeof U==="object")if(W.startsWith("@"))X+=W+`{
|
|
2
|
+
`+i(U,F)+`}
|
|
3
|
+
`;else X+=i(U,W.includes("&")?W.replace(/&/g,F):F+" "+W);else J+=W.replace(/[A-Z]/g,(j)=>"-"+j.toLowerCase())+":"+U+";"}if(J)X=(F.trimStart()||"*")+"{"+J+`}
|
|
4
|
+
`+X;return X}function jz(z,F){let J=q.parentElement;if(typeof F==="object"&&F!==null&&F[$])if(z==="bind")_z(J,F);else new zz(J,z,F);else if(z[0]==="."){let X=z.substring(1).split(".");if(F)J.classList.add(...X);else J.classList.remove(...X)}else if(z[0]==="$"){let X=z.substring(1);if(F==null||F===!1)J.style[X]="";else J.style[X]=""+F}else if(F==null);else if(z in o)o[z](F);else if(typeof F==="function")J.addEventListener(z,F),I(()=>J.removeEventListener(z,F));else if(F===!0||F===!1||z==="value"||z==="selectedIndex")J[z]=F;else J.setAttribute(z,F)}function Hz(z){return console.error("Error while in Aberdeen render:",z),!0}var $z=Hz;function Ez(z){$z=z||Hz}function wz(){return q.parentElement}function I(z){q.cleaners.push(z)}function Iz(z){return new e(q.parentElement,z).result}function Dz(z){new Fz(q.parentElement,z)}function kz(z,F){new t(z,F)}function bz(){R.remove(),qz=0}function xz(z){D++;try{return z()}finally{D--}}function mz(z,F){let J=A(z instanceof Array?[]:{});return x(z,(X,Z)=>{let U=F(X,Z);if(U!==void 0)J[Z]=U,I(()=>{delete J[Z]})}),J}function vz(z,F){let J=A({});return x(z,(X,Z)=>{let U=F(X,Z);if(U){for(let W in U)J[W]=U[W];I(()=>{for(let W in U)delete J[W]})}}),J}function yz(z,F){let J={},X=Zz(J);return x(z,(Z,U)=>{let W=F(Z,U);if(W!=null){let j=W instanceof Array?W:[W];if(j.length){for(let H of j)if(J[H])X[H][U]=Z;else X[H]={[U]:Z};I(()=>{for(let H of j)if(delete X[H][U],Xz(J[H]))delete X[H]})}}}),X}function Mz(z){if(z&&typeof z==="object")Y({text:z instanceof Array?"<array>":"<object>"}),Y("ul",()=>{x(z,(F,J)=>{Y("li:"+JSON.stringify(J)+": ",()=>{Mz(F)})})});else Y({text:JSON.stringify(z)});return z}function a(z){throw new Error("Aberdeen internal error "+z)}function c(z,F){try{if($z(z)===!1)F=!1}catch(J){console.error(J)}try{if(F)Y("div.aberdeen-error:Error")}catch{}}function Sz(z,F){let J=K;K=z;try{F()}finally{K=J}}if(!String.prototype.replaceAll)String.prototype.replaceAll=function(z,F){return this.split(z).join(F)};export{Sz as withEmitHandler,Uz as unproxy,bz as unmountAll,Ez as setErrorHandler,Kz as runQueue,Wz as ref,Zz as proxy,xz as peek,yz as partition,x as onEach,Iz as observe,vz as multiMap,kz as mount,mz as map,Pz as isEmpty,Cz as invertString,fz as insertCss,Dz as immediateObserve,wz as getParentElement,Mz as dump,Vz as defaultEmitHandler,Rz as count,hz as copy,Oz as clone,I as clean,Nz as SHALLOW,g as MERGE,Y as $};
|
|
5
|
+
|
|
6
|
+
//# debugId=F44758EEED34538E64756E2164756E21
|
|
7
|
+
//# sourceMappingURL=aberdeen.js.map
|