aberdeen 1.0.5 → 1.0.6
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/dist/aberdeen.d.ts +3 -8
- package/dist/aberdeen.js +81 -77
- package/dist/aberdeen.js.map +4 -4
- package/dist/prediction.d.ts +2 -2
- package/dist/prediction.js +21 -22
- package/dist/prediction.js.map +3 -3
- package/dist/route.d.ts +2 -2
- package/dist/route.js +29 -15
- package/dist/route.js.map +3 -3
- package/dist/transitions.d.ts +14 -14
- package/dist/transitions.js +19 -6
- package/dist/transitions.js.map +3 -3
- package/dist-min/aberdeen.js +5 -5
- package/dist-min/aberdeen.js.map +4 -4
- package/dist-min/prediction.js +2 -2
- package/dist-min/prediction.js.map +3 -3
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/dist-min/transitions.js +2 -2
- package/dist-min/transitions.js.map +3 -3
- package/package.json +2 -1
- package/src/aberdeen.ts +588 -400
- package/src/helpers/reverseSortedSet.ts +187 -178
- package/src/prediction.ts +73 -55
- package/src/route.ts +115 -97
- package/src/transitions.ts +49 -37
package/dist-min/prediction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{defaultEmitHandler as W,withEmitHandler as X}from"./aberdeen.js";function S(G){let C=new Map;return X((B,z,I,J)=>{U(C,B,z,I,J)},G),C}function U(G,C,B,z,I){let J=G.get(C);if(!J)J=new Map,G.set(C,J);let K=J.get(B),L=K?K[1]:I;if(z===L)J.delete(B);else J.set(B,[z,L])}function V(G){for(let[C,B]of G)for(let[z,[I,J]]of B)W(C,z,I,J)}function Q(G,C,B=!1){for(let[z,I]of C)for(let[J,[K,L]]of I)U(G,z,J,B?L:K,B?K:L)}function R(G,C=!1){for(let[B,z]of G)for(let[I,[J,K]]of z){let L=B[I];if(L!==K)if(C)setTimeout(()=>{throw new Error(`Applying invalid patch: data ${L} is unequal to expected old data ${K} for index ${I}`)},0);else return!1}for(let[B,z]of G)for(let[I,[J,K]]of z)B[I]=J;return!0}var N=[];function Z(G){let C=S(G);return N.push(C),V(C),C}function _(G,C=[]){let B=new Map;for(let z of N)Q(B,z,!0);R(B,!0);for(let z of C){let I=N.indexOf(z);if(I>=0)N.splice(I,1)}if(G)Q(B,S(G));for(let z=0;z<N.length;z++)if(R(N[z]))Q(B,N[z]);else N.splice(z,1),z--;V(B)}export{Z as applyPrediction,_ as applyCanon};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=277071596D78B55D64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=prediction.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/prediction.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {
|
|
5
|
+
"import { defaultEmitHandler, withEmitHandler } from \"./aberdeen.js\";\nimport type { DatumType, TargetType } from \"./aberdeen.js\";\n\n/**\n * Represents a set of changes that can be applied to proxied objects.\n * This is an opaque type - its internal structure is not part of the public API.\n * @private\n */\nexport type Patch = Map<TargetType, Map<any, [DatumType, DatumType]>>;\n\nfunction recordPatch(func: () => void): Patch {\n\tconst recordingPatch = new Map();\n\twithEmitHandler((target, index, newData, oldData) => {\n\t\taddToPatch(recordingPatch, target, index, newData, oldData);\n\t}, func);\n\treturn recordingPatch;\n}\n\nfunction addToPatch(\n\tpatch: Patch,\n\tcollection: TargetType,\n\tindex: any,\n\tnewData: DatumType,\n\toldData: DatumType,\n) {\n\tlet collectionMap = patch.get(collection);\n\tif (!collectionMap) {\n\t\tcollectionMap = new Map();\n\t\tpatch.set(collection, collectionMap);\n\t}\n\tconst prev = collectionMap.get(index);\n\tconst oldData0 = prev ? prev[1] : oldData;\n\tif (newData === oldData0) collectionMap.delete(index);\n\telse collectionMap.set(index, [newData, oldData0]);\n}\n\nfunction emitPatch(patch: Patch) {\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\tdefaultEmitHandler(collection, index, newData, oldData);\n\t\t}\n\t}\n}\n\nfunction mergePatch(target: Patch, source: Patch, reverse = false) {\n\tfor (const [collection, collectionMap] of source) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\taddToPatch(\n\t\t\t\ttarget,\n\t\t\t\tcollection,\n\t\t\t\tindex,\n\t\t\t\treverse ? oldData : newData,\n\t\t\t\treverse ? newData : oldData,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction silentlyApplyPatch(patch: Patch, force = false): boolean {\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\tconst actualData = (collection as any)[index];\n\t\t\tif (actualData !== oldData) {\n\t\t\t\tif (force)\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Applying invalid patch: data ${actualData} is unequal to expected old data ${oldData} for index ${index}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}, 0);\n\t\t\t\telse return false;\n\t\t\t}\n\t\t}\n\t}\n\tfor (const [collection, collectionMap] of patch) {\n\t\tfor (const [index, [newData, oldData]] of collectionMap) {\n\t\t\t(collection as any)[index] = newData;\n\t\t}\n\t}\n\treturn true;\n}\n\nconst appliedPredictions: Array<Patch> = [];\n\n/**\n * Run the provided function, while treating all changes to Observables as predictions,\n * meaning they will be reverted when changes come back from the server (or some other\n * async source).\n * @param predictFunc The function to run. It will generally modify some Observables\n * \tto immediately reflect state (as closely as possible) that we expect the server\n * to communicate back to us later on.\n * @returns A `Patch` object. Don't modify it. This is only meant to be passed to `applyCanon`.\n */\nexport function applyPrediction(predictFunc: () => void): Patch {\n\tconst patch = recordPatch(predictFunc);\n\tappliedPredictions.push(patch);\n\temitPatch(patch);\n\treturn patch;\n}\n\n/**\n * Temporarily revert all outstanding predictions, optionally run the provided function\n * (which will generally make authoritative changes to the data based on a server response),\n * and then attempt to reapply the predictions on top of the new canonical state, dropping\n * any predictions that can no longer be applied cleanly (the data has been modified) or\n * that were specified in `dropPredictions`.\n *\n * All of this is done such that redraws are only triggered if the overall effect is an\n * actual change to an `Observable`.\n * @param canonFunc The function to run without any predictions applied. This will typically\n * make authoritative changes to the data, based on a server response.\n * @param dropPredictions An optional list of predictions (as returned by `applyPrediction`)\n * to undo. Typically, when a server response for a certain request is being handled,\n * you'd want to drop the prediction that was done for that request.\n */\nexport function applyCanon(\n\tcanonFunc?: () => void,\n\tdropPredictions: Array<Patch> = [],\n) {\n\tconst resultPatch = new Map();\n\tfor (const prediction of appliedPredictions)\n\t\tmergePatch(resultPatch, prediction, true);\n\tsilentlyApplyPatch(resultPatch, true);\n\n\tfor (const prediction of dropPredictions) {\n\t\tconst pos = appliedPredictions.indexOf(prediction);\n\t\tif (pos >= 0) appliedPredictions.splice(pos, 1);\n\t}\n\tif (canonFunc) mergePatch(resultPatch, recordPatch(canonFunc));\n\n\tfor (let idx = 0; idx < appliedPredictions.length; idx++) {\n\t\tif (silentlyApplyPatch(appliedPredictions[idx])) {\n\t\t\tmergePatch(resultPatch, appliedPredictions[idx]);\n\t\t} else {\n\t\t\tappliedPredictions.splice(idx, 1);\n\t\t\tidx--;\n\t\t}\n\t}\n\n\temitPatch(resultPatch);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAAA,6BAAS,qBAAoB,sBAU7B,SAAS,CAAW,CAAC,EAAyB,CAC7C,IAAM,EAAiB,IAAI,IAI3B,OAHA,EAAgB,CAAC,EAAQ,EAAO,EAAS,IAAY,CACpD,EAAW,EAAgB,EAAQ,EAAO,EAAS,CAAO,GACxD,CAAI,EACA,EAGR,SAAS,CAAU,CAClB,EACA,EACA,EACA,EACA,EACC,CACD,IAAI,EAAgB,EAAM,IAAI,CAAU,EACxC,IAAK,EACJ,EAAgB,IAAI,IACpB,EAAM,IAAI,EAAY,CAAa,EAEpC,IAA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AAS,CAAC,EAE7D,QAAS,EAAM,EAAG,EAAM,EAAmB,OAAQ,IAClD,GAAI,EAAmB,EAAmB,EAAI,EAC7C,EAAW,EAAa,EAAmB,EAAI,EAE/C,OAAmB,OAAO,EAAK,CAAC,EAChC,IAIF,EAAU,CAAW",
|
|
8
|
+
"debugId": "277071596D78B55D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist-min/route.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{clean as k,clone as V,getParentElement as q,immediateObserve as K,observe as z,proxy as A,runQueue as D,unproxy as N}from"./aberdeen.js";class X{path;p;hash;search;id;aux;depth=1;nav="load";mode}var B=A(new X),J={nonce:-1,depth:0};function Y(C){let F=C?.state||{},G="load";if(F.route?.nonce==null)F.route={nonce:Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),depth:1},history.replaceState(F,"");else if(J.nonce===F.route.nonce)G=F.route.depth>J.depth?"forward":"back";if(J=F.route,N(B).mode==="back"){B.depth=J.depth,$();return}let I={};for(let[M,j]of new URLSearchParams(location.search))I[M]=j;if(B.path=location.pathname,B.p=location.pathname.slice(1).split("/"),B.search=I,B.hash=location.hash,B.id=F.id,B.aux=F.aux,B.depth=J.depth,B.nav=G,C)D()}Y();window.addEventListener("popstate",Y);function Z(){let C=B.path;if(C==null&&N(B).p){_();return}if(C=`${C||"/"}`,!C.startsWith("/"))C=`/${C}`;B.path=C,B.p=C.slice(1).split("/")}K(Z);function _(){let C=B.p;if(C==null&&N(B).path){Z();return}if(!(C instanceof Array))console.error(`aberdeen route: 'p' must be a non-empty array, not ${JSON.stringify(C)}`),B.p=[""];else if(C.length===0)B.p=[""];else B.path=`/${C.join("/")}`}K(_);K(()=>{if(!B.search||typeof B.search!=="object")B.search={}});K(()=>{if(!B.id||typeof B.id!=="object")B.id={}});K(()=>{if(!B.aux||typeof B.aux!=="object")B.aux={}});K(()=>{let C=`${B.hash||""}`;if(C&&!C.startsWith("#"))C=`#${C}`;B.hash=C});function W(C,F){return location.pathname===C&&JSON.stringify(history.state.id)===JSON.stringify(F.id)}function $(){let C=B.mode,F={id:V(B.id),aux:V(B.aux),route:J},G=B.path;if(C==="back"){if(B.nav="back",!W(G,F)&&(history.state.route?.depth||0)>1){history.back();return}C="replace"}if(C)B.mode=void 0;let I=new URLSearchParams(B.search).toString(),M=(I?`${G}?${I}`:G)+B.hash;if(C==="push"||!C&&!W(G,F))J.depth++,history.pushState(F,"",M),B.nav="push",B.depth=J.depth;else history.replaceState(F,"",M)}z($);function Q(C="main"){let F=q();F.addEventListener("scroll",I),k(()=>F.removeEventListener("scroll",I));let G=N(B).aux.scroll?.name;if(G)Object.assign(F,G);function I(){if(B.mode="replace",!B.aux.scroll)B.aux.scroll={};B.aux.scroll[C]={scrollTop:F.scrollTop,scrollLeft:F.scrollLeft}}}export{B as route,Q as persistScroll,X as Route};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=6DBDC1B42BCD416964756E2164756E21
|
|
4
4
|
//# sourceMappingURL=route.js.map
|
package/dist-min/route.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/route.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {
|
|
5
|
+
"import {\n\tclean,\n\tclone,\n\tgetParentElement,\n\timmediateObserve,\n\tobserve,\n\tproxy,\n\trunQueue,\n\tunproxy,\n} 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 = 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\tnav: \"load\" | \"back\" | \"forward\" | \"push\" = \"load\";\n\t/** 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\tconst 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 (const [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\tupdateP();\n\t\treturn;\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() {\n\tconst p = route.p;\n\tif (p == null && unproxy(route).path) {\n\t\tupdatePath();\n\t\treturn;\n\t}\n\tif (!(p instanceof Array)) {\n\t\tconsole.error(\n\t\t\t`aberdeen route: 'p' must be a non-empty array, not ${JSON.stringify(p)}`,\n\t\t);\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 (\n\t\tlocation.pathname === path &&\n\t\tJSON.stringify(history.state.id) === JSON.stringify(state.id)\n\t);\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\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\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 * 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 = \"main\") {\n\tconst el = getParentElement();\n\tel.addEventListener(\"scroll\", onScroll);\n\tclean(() => el.removeEventListener(\"scroll\", onScroll));\n\n\tconst 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] = {\n\t\t\tscrollTop: el.scrollTop,\n\t\t\tscrollLeft: el.scrollLeft,\n\t\t};\n\t}\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAAA,gBACC,WACA,sBACA,sBACA,aACA,WACA,cACA,aACA,sBAQM,MAAM,CAAM,CAElB,KAEA,EAEA,KAEA,OAEA,GAEA,IAEA,MAAQ,EAMR,IAA4C,OAO5C,IACD,CAKO,IAAM,EAAQ,EAAM,IAAI,CAAO,EAElC,EAAa,CAChB,MAAO,GACP,MAAO,CACR,EAGA,SAAS,CAAoB,CAAC,EAAuB,CACpD,IAAM,EAAQ,GAAO,OAAS,CAAC,EAC3B,EAA4C,OAChD,GAAI,EAAM,OAAO,OAAS,KACzB,EAAM,MAAQ,CACb,MAAO,KAAK,MAAM,KAAK,OAAO,EAAI,OAAO,gBAAgB,EACzD,MAAO,CACR,EACA,QAAQ,aAAa,EAAO,EAAE,EACxB,QAAI,EAAW,QAAU,EAAM,MAAM,MAC3C,EAAM,EAAM,MAAM,MAAQ,EAAW,MAAQ,UAAY,OAI1D,GAFA,EAAa,EAAM,MAEf,EAAQ,CAAK,EAAE,OAAS,OAAQ,CACnC,EAAM,MAAQ,EAAW,MAEzB,EAAc,EACd,OAGD,IAAM,EAAc,CAAC,EACrB,QAAY,EAAG,KAAM,IAAI,gBAAgB,SAAS,MAAM,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GAAQ,CACxB,UAAW,EAAG,UACd,WAAY,EAAG,UAChB",
|
|
8
|
+
"debugId": "6DBDC1B42BCD416964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist-min/transitions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function q(b){let c=
|
|
1
|
+
function q(b){if(b.parentElement){let c=getComputedStyle(b.parentElement);if(c.display==="flex"&&(c.flexDirection||"").startsWith("row"))return{marginLeft:`-${b.offsetWidth/2}px`,marginRight:`-${b.offsetWidth/2}px`,transform:"scaleX(0)"}}return{marginBottom:`-${b.offsetHeight/2}px`,marginTop:`-${b.offsetHeight/2}px`,transform:"scaleY(0)"}}async function u(b){let c=q(b);Object.assign(b.style,c),b.offsetHeight,b.style.transition="margin 400ms ease-out, transform 400ms ease-out";for(let j in c)b.style[j]="";setTimeout(()=>{b.style.transition=""},400)}async function x(b){let c=q(b);b.style.transition="margin 400ms ease-out, transform 400ms ease-out",Object.assign(b.style,c),setTimeout(()=>{b.remove()},400)}export{x as shrink,u as grow};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=DC8B33339FFAA36764756E2164756E21
|
|
4
4
|
//# sourceMappingURL=transitions.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/transitions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"const FADE_TIME = 400
|
|
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): Partial<CSSStyleDeclaration> {\n\tif (el.parentElement) {\n\t\tconst parentStyle = getComputedStyle(el.parentElement);\n\t\tconst isHorizontal =\n\t\t\tparentStyle.display === \"flex\" &&\n\t\t\t(parentStyle.flexDirection || \"\").startsWith(\"row\");\n\t\tif (isHorizontal) {\n\t\t\treturn {\n\t\t\t\tmarginLeft: `-${el.offsetWidth / 2}px`,\n\t\t\t\tmarginRight: `-${el.offsetWidth / 2}px`,\n\t\t\t\ttransform: \"scaleX(0)\",\n\t\t\t};\n\t\t}\n\t}\n\treturn {\n\t\tmarginBottom: `-${el.offsetHeight / 2}px`,\n\t\tmarginTop: `-${el.offsetHeight / 2}px`,\n\t\ttransform: \"scaleY(0)\",\n\t};\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\tconst props = getGrowShrinkProps(el);\n\tObject.assign(el.style, props);\n\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 (const prop in props) el.style[prop] = \"\";\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\n\t// Remove the element after the transition is done.\n\tsetTimeout(() => {\n\t\tel.remove();\n\t}, FADE_TIME);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAGA,SAAS,CAAkB,CAAC,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAGA,SAAS,CAAkB,CAAC,EAA+C,CAC1E,GAAI,EAAG,cAAe,CACrB,IAAM,EAAc,iBAAiB,EAAG,aAAa,EAIrD,GAFC,EAAY,UAAY,SACvB,EAAY,eAAiB,IAAI,WAAW,KAAK,EAElD,MAAO,CACN,WAAY,IAAI,EAAG,YAAc,MACjC,YAAa,IAAI,EAAG,YAAc,MAClC,UAAW,WACZ,EAGF,MAAO,CACN,aAAc,IAAI,EAAG,aAAe,MACpC,UAAW,IAAI,EAAG,aAAe,MACjC,UAAW,WACZ,EAWD,eAAsB,CAAI,CAAC,EAAiB,CAC3C,IAAM,EAAQ,EAAmB,CAAE,EACnC,OAAO,OAAO,EAAG,MAAO,CAAK,EAG7B,EAAG,aAEH,EAAG,MAAM,WAtCqB,kDAuC9B,QAAW,KAAQ,EAAO,EAAG,MAAM,GAAQ,GAC3C,WAAW,IAAM,CAEhB,EAAG,MAAM,WAAa,IA3CN,GA4CL,EAWb,eAAsB,CAAM,CAAC,EAAiB,CAE7C,IAAM,EAAQ,EAAmB,CAAE,EAGnC,EAAG,MAAM,WA3DqB,kDA4D9B,OAAO,OAAO,EAAG,MAAO,CAAK,EAG7B,WAAW,IAAM,CAChB,EAAG,OAAO,GAjEM,GAkEL",
|
|
8
|
+
"debugId": "DC8B33339FFAA36764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberdeen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"author": "Frank van Viegen",
|
|
5
5
|
"main": "dist-min/aberdeen.js",
|
|
6
6
|
"devDependencies": {
|
|
7
|
+
"@biomejs/biome": "^1.9.4",
|
|
7
8
|
"@types/bun": "latest",
|
|
8
9
|
"typedoc": "^0.28.2",
|
|
9
10
|
"typescript": "^5.8.3"
|