@wordpress/interactivity-router 2.25.0 → 2.26.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/CHANGELOG.md +17 -0
- package/README.md +22 -0
- package/build/assets/dynamic-importmap/fetch.js +60 -0
- package/build/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build/assets/dynamic-importmap/index.js +91 -0
- package/build/assets/dynamic-importmap/index.js.map +1 -0
- package/build/assets/dynamic-importmap/loader.js +286 -0
- package/build/assets/dynamic-importmap/loader.js.map +1 -0
- package/build/assets/dynamic-importmap/resolver.js +220 -0
- package/build/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build/assets/script-modules.js +64 -0
- package/build/assets/script-modules.js.map +1 -0
- package/build/assets/scs.js +62 -0
- package/build/assets/scs.js.map +1 -0
- package/build/assets/styles.js +246 -0
- package/build/assets/styles.js.map +1 -0
- package/build/full-page.js +43 -0
- package/build/full-page.js.map +1 -0
- package/build/index.js +140 -38
- package/build/index.js.map +1 -1
- package/build-module/assets/dynamic-importmap/fetch.js +54 -0
- package/build-module/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build-module/assets/dynamic-importmap/index.js +72 -0
- package/build-module/assets/dynamic-importmap/index.js.map +1 -0
- package/build-module/assets/dynamic-importmap/loader.js +279 -0
- package/build-module/assets/dynamic-importmap/loader.js.map +1 -0
- package/build-module/assets/dynamic-importmap/resolver.js +213 -0
- package/build-module/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build-module/assets/script-modules.js +55 -0
- package/build-module/assets/script-modules.js.map +1 -0
- package/build-module/assets/scs.js +56 -0
- package/build-module/assets/scs.js.map +1 -0
- package/build-module/assets/styles.js +235 -0
- package/build-module/assets/styles.js.map +1 -0
- package/build-module/full-page.js +39 -0
- package/build-module/full-page.js.map +1 -0
- package/build-module/index.js +142 -38
- package/build-module/index.js.map +1 -1
- package/build-types/assets/dynamic-importmap/fetch.d.ts +30 -0
- package/build-types/assets/dynamic-importmap/fetch.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/index.d.ts +42 -0
- package/build-types/assets/dynamic-importmap/index.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts +68 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts +35 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts.map +1 -0
- package/build-types/assets/script-modules.d.ts +26 -0
- package/build-types/assets/script-modules.d.ts.map +1 -0
- package/build-types/assets/scs.d.ts +24 -0
- package/build-types/assets/scs.d.ts.map +1 -0
- package/build-types/assets/styles.d.ts +69 -0
- package/build-types/assets/styles.d.ts.map +1 -0
- package/build-types/full-page.d.ts +3 -0
- package/build-types/full-page.d.ts.map +1 -0
- package/build-types/index.d.ts +4 -5
- package/build-types/index.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/assets/dynamic-importmap/fetch.ts +58 -0
- package/src/assets/dynamic-importmap/index.ts +87 -0
- package/src/assets/dynamic-importmap/loader.ts +366 -0
- package/src/assets/dynamic-importmap/resolver.ts +292 -0
- package/src/assets/script-modules.ts +69 -0
- package/src/assets/scs.ts +61 -0
- package/src/assets/styles.ts +272 -0
- package/src/assets/test/scs.test.ts +367 -0
- package/src/assets/test/styles.test.ts +758 -0
- package/src/full-page.ts +53 -0
- package/src/index.ts +165 -45
- package/tsconfig.full-page.json +12 -0
- package/tsconfig.full-page.tsbuildinfo +1 -0
- package/tsconfig.json +9 -4
- package/tsconfig.main.json +21 -0
- package/tsconfig.main.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_scs","require","areNodesEqual","a","b","isEqualNode","normalizeMedia","element","cloneNode","media","originalMedia","dataset","removeAttribute","exports","updateStylesWithSCS","X","Y","parent","window","document","head","length","map","promise","prepareStylePromise","appendChild","xNormalized","yNormalized","scs","shortestCommonSupersequence","xLength","yLength","promises","last","xIndex","yIndex","scsElement","xElement","yElement","xNormEl","yNormEl","push","before","after","stylePromiseCache","WeakMap","has","get","contains","Promise","resolve","set","hasAttribute","HTMLStyleElement","reject","addEventListener","event","href","target","Error","styleSheetCache","Map","preloadStyles","doc","url","currentStyleElements","Array","from","querySelectorAll","newStyleElements","stylePromises","applyStyles","styles","forEach","el","sheet","includes","mediaText","disabled"],"sources":["@wordpress/interactivity-router/src/assets/styles.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { shortestCommonSupersequence } from './scs';\n\nexport type StyleElement = HTMLLinkElement | HTMLStyleElement;\n\n/**\n * Compares the passed style or link elements to check if they can be\n * considered equal.\n *\n * @param a `<style>` or `<link>` element.\n * @param b `<style>` or `<link>` element.\n * @return Whether they are considered equal.\n */\nconst areNodesEqual = ( a: StyleElement, b: StyleElement ): boolean =>\n\ta.isEqualNode( b );\n\n/**\n * Normalizes the passed style or link element, reverting the changes\n * made by {@link prepareStylePromise|`prepareStylePromise`} to the\n * `data-original-media` and `media`.\n *\n * @example\n * The following elements should be normalized to the same element:\n * ```html\n * <link rel=\"stylesheet\" src=\"./assets/styles.css\">\n * <link rel=\"stylesheet\" src=\"./assets/styles.css\" media=\"all\">\n * <link rel=\"stylesheet\" src=\"./assets/styles.css\" media=\"preload\">\n * <link rel=\"stylesheet\" src=\"./assets/styles.css\" media=\"preload\" data-original-media=\"all\">\n * ```\n *\n * @param element `<style>` or `<link>` element.\n * @return Normalized node.\n */\nexport const normalizeMedia = ( element: StyleElement ): StyleElement => {\n\telement = element.cloneNode( true ) as StyleElement;\n\tconst media = element.media;\n\tconst { originalMedia } = element.dataset;\n\n\tif ( media === 'preload' ) {\n\t\telement.media = originalMedia || 'all';\n\t\telement.removeAttribute( 'data-original-media' );\n\t} else if ( ! element.media ) {\n\t\telement.media = 'all';\n\t}\n\treturn element;\n};\n\n/**\n * Adds the minimum style elements from Y around those in X using a\n * shortest common supersequence algorithm, returning a list of\n * promises for all the elements in Y.\n *\n * If X is empty, it appends all elements in Y to the passed parent\n * element or to `document.head` instead.\n *\n * The returned promises resolve once the corresponding style element\n * is loaded and ready. Those elements that are also in X return a\n * cached promise.\n *\n * The algorithm ensures that the final style elements present in the\n * document (or the passed `parent` element) are in the correct order\n * and they are included in either X or Y.\n *\n * @param X Base list of style elements.\n * @param Y List of style elements.\n * @param parent Optional parent element to append to the new style elements.\n * @return List of promises that resolve once the elements in Y are ready.\n */\nexport function updateStylesWithSCS(\n\tX: StyleElement[],\n\tY: StyleElement[],\n\tparent: Element = window.document.head\n) {\n\tif ( X.length === 0 ) {\n\t\treturn Y.map( ( element ) => {\n\t\t\tconst promise = prepareStylePromise( element );\n\t\t\tparent.appendChild( element );\n\t\t\treturn promise;\n\t\t} );\n\t}\n\n\t// Create normalized arrays for comparison.\n\tconst xNormalized = X.map( normalizeMedia );\n\tconst yNormalized = Y.map( normalizeMedia );\n\n\t// The `scs` array contains normalized elements.\n\tconst scs = shortestCommonSupersequence(\n\t\txNormalized,\n\t\tyNormalized,\n\t\tareNodesEqual\n\t);\n\tconst xLength = X.length;\n\tconst yLength = Y.length;\n\tconst promises = [];\n\tlet last = X[ xLength - 1 ];\n\tlet xIndex = 0;\n\tlet yIndex = 0;\n\n\tfor ( const scsElement of scs ) {\n\t\t// Actual elements that will end up in the DOM.\n\t\tconst xElement = X[ xIndex ];\n\t\tconst yElement = Y[ yIndex ];\n\t\t// Normalized elements for comparison.\n\t\tconst xNormEl = xNormalized[ xIndex ];\n\t\tconst yNormEl = yNormalized[ yIndex ];\n\t\tif ( xIndex < xLength && areNodesEqual( xNormEl, scsElement ) ) {\n\t\t\tif ( yIndex < yLength && areNodesEqual( yNormEl, scsElement ) ) {\n\t\t\t\tpromises.push( prepareStylePromise( xElement ) );\n\t\t\t\tyIndex++;\n\t\t\t}\n\t\t\txIndex++;\n\t\t} else {\n\t\t\tpromises.push( prepareStylePromise( yElement ) );\n\t\t\tif ( xIndex < xLength ) {\n\t\t\t\txElement.before( yElement );\n\t\t\t} else {\n\t\t\t\tlast.after( yElement );\n\t\t\t\tlast = yElement;\n\t\t\t}\n\t\t\tyIndex++;\n\t\t}\n\t}\n\n\treturn promises;\n}\n\n/**\n * Cache of promises per style elements.\n *\n * Each style element has their own associated `Promise` that resolves\n * once the element has been loaded and is ready.\n */\nconst stylePromiseCache = new WeakMap<\n\tStyleElement,\n\tPromise< StyleElement >\n>();\n\n/**\n * Prepares and returns the corresponding `Promise` for the passed style\n * element.\n *\n * It returns the cached promise if it exists. Otherwise, constructs\n * a `Promise` that resolves once the element has finished loading.\n *\n * For those elements that are not in the DOM yet, this function\n * injects a `media=\"preload\"` attribute to the passed element so the\n * style is loaded without applying any styles to the document.\n *\n * @param element Style element.\n * @return The associated `Promise` to the passed element.\n */\nconst prepareStylePromise = (\n\telement: StyleElement\n): Promise< StyleElement > => {\n\tif ( stylePromiseCache.has( element ) ) {\n\t\treturn stylePromiseCache.get( element );\n\t}\n\n\t// When the element exists in the main document and its media attribute\n\t// is not \"preload\", that means the element comes from the initial page.\n\t// The `media` attribute doesn't need to be handled in this case.\n\tif ( window.document.contains( element ) && element.media !== 'preload' ) {\n\t\tconst promise = Promise.resolve( element );\n\t\tstylePromiseCache.set( element, promise );\n\t\treturn promise;\n\t}\n\n\tif ( element.hasAttribute( 'media' ) && element.media !== 'all' ) {\n\t\telement.dataset.originalMedia = element.media;\n\t}\n\n\telement.media = 'preload';\n\n\tif ( element instanceof HTMLStyleElement ) {\n\t\tconst promise = Promise.resolve( element );\n\t\tstylePromiseCache.set( element, promise );\n\t\treturn promise;\n\t}\n\n\tconst promise = new Promise< HTMLLinkElement >( ( resolve, reject ) => {\n\t\telement.addEventListener( 'load', () => resolve( element ) );\n\t\telement.addEventListener( 'error', ( event ) => {\n\t\t\tconst { href } = event.target as HTMLLinkElement;\n\t\t\treject(\n\t\t\t\tError(\n\t\t\t\t\t`The style sheet with the following URL failed to load: ${ href }`\n\t\t\t\t)\n\t\t\t);\n\t\t} );\n\t} );\n\n\tstylePromiseCache.set( element, promise );\n\treturn promise;\n};\n\n/**\n * Cache of style promise lists per URL.\n *\n * It contains the list of style elements associated to the page with the\n * passed URL. The original order is preserved to respect the CSS cascade.\n *\n * Each included promise resolves when the associated style element is ready.\n */\nconst styleSheetCache = new Map< string, Promise< StyleElement >[] >();\n\n/**\n * Prepares all style elements contained in the passed document.\n *\n * This function calls {@link updateStylesWithSCS|`updateStylesWithSCS`}\n * to insert only the minimum amount of style elements into the DOM, so\n * those present in the passed document end up in the DOM while the order\n * is respected.\n *\n * New appended style elements contain a `media=preload` attribute to\n * make them effectively disabled until they are applied with the\n * {@link applyStyles|`applyStyles`} function.\n *\n * @param doc Document instance.\n * @param url URL for the passed document.\n * @return A list of promises for each style element in the passed document.\n */\nexport const preloadStyles = (\n\tdoc: Document,\n\turl: string\n): Promise< StyleElement >[] => {\n\tif ( ! styleSheetCache.has( url ) ) {\n\t\tconst currentStyleElements = Array.from(\n\t\t\twindow.document.querySelectorAll< StyleElement >(\n\t\t\t\t'style,link[rel=stylesheet]'\n\t\t\t)\n\t\t);\n\t\tconst newStyleElements = Array.from(\n\t\t\tdoc.querySelectorAll< StyleElement >( 'style,link[rel=stylesheet]' )\n\t\t);\n\n\t\t// Set styles in order.\n\t\tconst stylePromises = updateStylesWithSCS(\n\t\t\tcurrentStyleElements,\n\t\t\tnewStyleElements\n\t\t);\n\n\t\tstyleSheetCache.set( url, stylePromises );\n\t}\n\treturn styleSheetCache.get( url );\n};\n\n/**\n * Traverses all style elements in the DOM, enabling only those included\n * in the passed list and disabling the others.\n *\n * If the style element has the `data-original-media` attribute, the\n * original `media` value is restored.\n *\n * @param styles List of style elements to apply.\n */\nexport const applyStyles = ( styles: StyleElement[] ) => {\n\twindow.document\n\t\t.querySelectorAll( 'style,link[rel=stylesheet]' )\n\t\t.forEach( ( el: HTMLLinkElement | HTMLStyleElement ) => {\n\t\t\tif ( el.sheet ) {\n\t\t\t\tif ( styles.includes( el ) ) {\n\t\t\t\t\tconst { originalMedia = 'all' } = el.dataset;\n\t\t\t\t\tel.sheet.media.mediaText = originalMedia;\n\t\t\t\t\tel.sheet.disabled = false;\n\t\t\t\t} else {\n\t\t\t\t\tel.sheet.disabled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAGA,CAAEC,CAAe,EAAEC,CAAe,KACvDD,CAAC,CAACE,WAAW,CAAED,CAAE,CAAC;;AAEnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,cAAc,GAAKC,OAAqB,IAAoB;EACxEA,OAAO,GAAGA,OAAO,CAACC,SAAS,CAAE,IAAK,CAAiB;EACnD,MAAMC,KAAK,GAAGF,OAAO,CAACE,KAAK;EAC3B,MAAM;IAAEC;EAAc,CAAC,GAAGH,OAAO,CAACI,OAAO;EAEzC,IAAKF,KAAK,KAAK,SAAS,EAAG;IAC1BF,OAAO,CAACE,KAAK,GAAGC,aAAa,IAAI,KAAK;IACtCH,OAAO,CAACK,eAAe,CAAE,qBAAsB,CAAC;EACjD,CAAC,MAAM,IAAK,CAAEL,OAAO,CAACE,KAAK,EAAG;IAC7BF,OAAO,CAACE,KAAK,GAAG,KAAK;EACtB;EACA,OAAOF,OAAO;AACf,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AApBAM,OAAA,CAAAP,cAAA,GAAAA,cAAA;AAqBO,SAASQ,mBAAmBA,CAClCC,CAAiB,EACjBC,CAAiB,EACjBC,MAAe,GAAGC,MAAM,CAACC,QAAQ,CAACC,IAAI,EACrC;EACD,IAAKL,CAAC,CAACM,MAAM,KAAK,CAAC,EAAG;IACrB,OAAOL,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AAC;EAC1C;EACA,OAAOV,eAAe,CAACb,GAAG,CAAEiB,GAAI,CAAC;AAClC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARAnD,OAAA,CAAAiD,aAAA,GAAAA,aAAA;AASO,MAAMS,WAAW,GAAKC,MAAsB,IAAM;EACxDtD,MAAM,CAACC,QAAQ,CACbiD,gBAAgB,CAAE,4BAA6B,CAAC,CAChDK,OAAO,CAAIC,EAAsC,IAAM;IACvD,IAAKA,EAAE,CAACC,KAAK,EAAG;MACf,IAAKH,MAAM,CAACI,QAAQ,CAAEF,EAAG,CAAC,EAAG;QAC5B,MAAM;UAAEhE,aAAa,GAAG;QAAM,CAAC,GAAGgE,EAAE,CAAC/D,OAAO;QAC5C+D,EAAE,CAACC,KAAK,CAAClE,KAAK,CAACoE,SAAS,GAAGnE,aAAa;QACxCgE,EAAE,CAACC,KAAK,CAACG,QAAQ,GAAG,KAAK;MAC1B,CAAC,MAAM;QACNJ,EAAE,CAACC,KAAK,CAACG,QAAQ,GAAG,IAAI;MACzB;IACD;EACD,CAAE,CAAC;AACL,CAAC;AAACjE,OAAA,CAAA0D,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* wp:polyfill */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
5
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
6
|
+
// Check if the link is valid for client-side navigation.
|
|
7
|
+
const isValidLink = ref => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === '_self') && ref.origin === window.location.origin && !ref.pathname.startsWith('/wp-admin') && !ref.pathname.startsWith('/wp-login.php') && !ref.getAttribute('href').startsWith('#') && !new URL(ref.href).searchParams.has('_wpnonce');
|
|
8
|
+
|
|
9
|
+
// Check if the event is valid for client-side navigation.
|
|
10
|
+
const isValidEvent = event => event && event.button === 0 &&
|
|
11
|
+
// Left clicks only.
|
|
12
|
+
!event.metaKey &&
|
|
13
|
+
// Open in new tab (Mac).
|
|
14
|
+
!event.ctrlKey &&
|
|
15
|
+
// Open in new tab (Windows).
|
|
16
|
+
!event.altKey &&
|
|
17
|
+
// Download.
|
|
18
|
+
!event.shiftKey && !event.defaultPrevented;
|
|
19
|
+
|
|
20
|
+
// Navigate on click.
|
|
21
|
+
document.addEventListener('click', async event => {
|
|
22
|
+
const ref = event.target.closest('a');
|
|
23
|
+
if (isValidLink(ref) && isValidEvent(event)) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
const {
|
|
26
|
+
actions
|
|
27
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@wordpress/interactivity-router')));
|
|
28
|
+
actions.navigate(ref.href);
|
|
29
|
+
}
|
|
30
|
+
}, true);
|
|
31
|
+
// Prefetch on hover.
|
|
32
|
+
document.addEventListener('mouseenter', async event => {
|
|
33
|
+
if (event.target?.nodeName === 'A') {
|
|
34
|
+
const ref = event.target.closest('a');
|
|
35
|
+
if (isValidLink(ref) && isValidEvent(event)) {
|
|
36
|
+
const {
|
|
37
|
+
actions
|
|
38
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@wordpress/interactivity-router')));
|
|
39
|
+
actions.prefetch(ref.href);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, true);
|
|
43
|
+
//# sourceMappingURL=full-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isValidLink","ref","window","HTMLAnchorElement","href","target","origin","location","pathname","startsWith","getAttribute","URL","searchParams","has","isValidEvent","event","button","metaKey","ctrlKey","altKey","shiftKey","defaultPrevented","document","addEventListener","closest","preventDefault","actions","Promise","resolve","then","_interopRequireWildcard","require","navigate","nodeName","prefetch"],"sources":["@wordpress/interactivity-router/src/full-page.ts"],"sourcesContent":["// Check if the link is valid for client-side navigation.\nconst isValidLink = ( ref: HTMLAnchorElement ) =>\n\tref &&\n\tref instanceof window.HTMLAnchorElement &&\n\tref.href &&\n\t( ! ref.target || ref.target === '_self' ) &&\n\tref.origin === window.location.origin &&\n\t! ref.pathname.startsWith( '/wp-admin' ) &&\n\t! ref.pathname.startsWith( '/wp-login.php' ) &&\n\t! ref.getAttribute( 'href' ).startsWith( '#' ) &&\n\t! new URL( ref.href ).searchParams.has( '_wpnonce' );\n\n// Check if the event is valid for client-side navigation.\nconst isValidEvent = ( event: MouseEvent ) =>\n\tevent &&\n\tevent.button === 0 && // Left clicks only.\n\t! event.metaKey && // Open in new tab (Mac).\n\t! event.ctrlKey && // Open in new tab (Windows).\n\t! event.altKey && // Download.\n\t! event.shiftKey &&\n\t! event.defaultPrevented;\n\n// Navigate on click.\ndocument.addEventListener(\n\t'click',\n\tasync ( event ) => {\n\t\tconst ref = ( event.target as Element ).closest( 'a' );\n\t\tif ( isValidLink( ref ) && isValidEvent( event ) ) {\n\t\t\tevent.preventDefault();\n\t\t\tconst { actions } = await import(\n\t\t\t\t'@wordpress/interactivity-router'\n\t\t\t);\n\t\t\tactions.navigate( ref.href );\n\t\t}\n\t},\n\ttrue\n);\n// Prefetch on hover.\ndocument.addEventListener(\n\t'mouseenter',\n\tasync ( event ) => {\n\t\tif ( ( event.target as Element )?.nodeName === 'A' ) {\n\t\t\tconst ref = ( event.target as Element ).closest( 'a' );\n\t\t\tif ( isValidLink( ref ) && isValidEvent( event ) ) {\n\t\t\t\tconst { actions } = await import(\n\t\t\t\t\t'@wordpress/interactivity-router'\n\t\t\t\t);\n\t\t\t\tactions.prefetch( ref.href );\n\t\t\t}\n\t\t}\n\t},\n\ttrue\n);\n"],"mappings":";;;;;AAAA;AACA,MAAMA,WAAW,GAAKC,GAAsB,IAC3CA,GAAG,IACHA,GAAG,YAAYC,MAAM,CAACC,iBAAiB,IACvCF,GAAG,CAACG,IAAI,KACN,CAAEH,GAAG,CAACI,MAAM,IAAIJ,GAAG,CAACI,MAAM,KAAK,OAAO,CAAE,IAC1CJ,GAAG,CAACK,MAAM,KAAKJ,MAAM,CAACK,QAAQ,CAACD,MAAM,IACrC,CAAEL,GAAG,CAACO,QAAQ,CAACC,UAAU,CAAE,WAAY,CAAC,IACxC,CAAER,GAAG,CAACO,QAAQ,CAACC,UAAU,CAAE,eAAgB,CAAC,IAC5C,CAAER,GAAG,CAACS,YAAY,CAAE,MAAO,CAAC,CAACD,UAAU,CAAE,GAAI,CAAC,IAC9C,CAAE,IAAIE,GAAG,CAAEV,GAAG,CAACG,IAAK,CAAC,CAACQ,YAAY,CAACC,GAAG,CAAE,UAAW,CAAC;;AAErD;AACA,MAAMC,YAAY,GAAKC,KAAiB,IACvCA,KAAK,IACLA,KAAK,CAACC,MAAM,KAAK,CAAC;AAAI;AACtB,CAAED,KAAK,CAACE,OAAO;AAAI;AACnB,CAAEF,KAAK,CAACG,OAAO;AAAI;AACnB,CAAEH,KAAK,CAACI,MAAM;AAAI;AAClB,CAAEJ,KAAK,CAACK,QAAQ,IAChB,CAAEL,KAAK,CAACM,gBAAgB;;AAEzB;AACAC,QAAQ,CAACC,gBAAgB,CACxB,OAAO,EACP,MAAQR,KAAK,IAAM;EAClB,MAAMd,GAAG,GAAKc,KAAK,CAACV,MAAM,CAAcmB,OAAO,CAAE,GAAI,CAAC;EACtD,IAAKxB,WAAW,CAAEC,GAAI,CAAC,IAAIa,YAAY,CAAEC,KAAM,CAAC,EAAG;IAClDA,KAAK,CAACU,cAAc,CAAC,CAAC;IACtB,MAAM;MAAEC;IAAQ,CAAC,GAAG,MAAAC,OAAA,CAAAC,OAAA,GAAAC,IAAA,OAAAC,uBAAA,CAAAC,OAAA,CACnB,iCAAiC,GACjC;IACDL,OAAO,CAACM,QAAQ,CAAE/B,GAAG,CAACG,IAAK,CAAC;EAC7B;AACD,CAAC,EACD,IACD,CAAC;AACD;AACAkB,QAAQ,CAACC,gBAAgB,CACxB,YAAY,EACZ,MAAQR,KAAK,IAAM;EAClB,IAAOA,KAAK,CAACV,MAAM,EAAe4B,QAAQ,KAAK,GAAG,EAAG;IACpD,MAAMhC,GAAG,GAAKc,KAAK,CAACV,MAAM,CAAcmB,OAAO,CAAE,GAAI,CAAC;IACtD,IAAKxB,WAAW,CAAEC,GAAI,CAAC,IAAIa,YAAY,CAAEC,KAAM,CAAC,EAAG;MAClD,MAAM;QAAEW;MAAQ,CAAC,GAAG,MAAAC,OAAA,CAAAC,OAAA,GAAAC,IAAA,OAAAC,uBAAA,CAAAC,OAAA,CACnB,iCAAiC,GACjC;MACDL,OAAO,CAACQ,QAAQ,CAAEjC,GAAG,CAACG,IAAK,CAAC;IAC7B;EACD;AACD,CAAC,EACD,IACD,CAAC","ignoreList":[]}
|
package/build/index.js
CHANGED
|
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.state = exports.actions = void 0;
|
|
8
8
|
var _interactivity = require("@wordpress/interactivity");
|
|
9
|
+
var _styles = require("./assets/styles");
|
|
10
|
+
var _scriptModules = require("./assets/script-modules");
|
|
9
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
|
|
11
13
|
* WordPress dependencies
|
|
14
|
+
*/ /**
|
|
15
|
+
* Internal dependencies
|
|
12
16
|
*/
|
|
13
17
|
const {
|
|
14
18
|
directivePrefix,
|
|
@@ -20,10 +24,9 @@ const {
|
|
|
20
24
|
populateServerData,
|
|
21
25
|
batch
|
|
22
26
|
} = (0, _interactivity.privateApis)('I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
+
const regionAttr = `data-${directivePrefix}-router-region`;
|
|
28
|
+
const interactiveAttr = `data-${directivePrefix}-interactive`;
|
|
29
|
+
const regionsSelector = `[${interactiveAttr}][${regionAttr}]:not([${interactiveAttr}] [${interactiveAttr}])`;
|
|
27
30
|
// The cache of visited and prefetched pages, stylesheets and scripts.
|
|
28
31
|
const pages = new Map();
|
|
29
32
|
|
|
@@ -34,7 +37,40 @@ const getPagePath = url => {
|
|
|
34
37
|
return u.pathname + u.search;
|
|
35
38
|
};
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Parses the given region's directive.
|
|
42
|
+
*
|
|
43
|
+
* @param region Region element.
|
|
44
|
+
* @return Data contained in the region directive value.
|
|
45
|
+
*/
|
|
46
|
+
const parseRegionAttribute = region => {
|
|
47
|
+
const value = region.getAttribute(regionAttr);
|
|
48
|
+
try {
|
|
49
|
+
const {
|
|
50
|
+
id,
|
|
51
|
+
attachTo
|
|
52
|
+
} = JSON.parse(value);
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
attachTo
|
|
56
|
+
};
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return {
|
|
59
|
+
id: value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Fetches and prepares a page from a given URL.
|
|
66
|
+
*
|
|
67
|
+
* @param url The URL of the page to fetch.
|
|
68
|
+
* @param options Options for the fetch operation.
|
|
69
|
+
* @param options.html Optional HTML content. If provided, the function will use
|
|
70
|
+
* this instead of fetching from the URL.
|
|
71
|
+
* @return A Promise that resolves to the prepared page, or false if
|
|
72
|
+
* there was an error during fetching or preparation.
|
|
73
|
+
*/
|
|
38
74
|
const fetchPage = async (url, {
|
|
39
75
|
html
|
|
40
76
|
}) => {
|
|
@@ -47,56 +83,115 @@ const fetchPage = async (url, {
|
|
|
47
83
|
html = await res.text();
|
|
48
84
|
}
|
|
49
85
|
const dom = new window.DOMParser().parseFromString(html, 'text/html');
|
|
50
|
-
return
|
|
86
|
+
return await preparePage(url, dom);
|
|
51
87
|
} catch (e) {
|
|
52
88
|
return false;
|
|
53
89
|
}
|
|
54
90
|
};
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Processes a DOM document to extract router regions and related resources.
|
|
94
|
+
*
|
|
95
|
+
* This function analyzes the provided DOM document and creates a virtual DOM
|
|
96
|
+
* representation of all HTML regions marked with a `router-region` directive.
|
|
97
|
+
* It also extracts and preloads associated styles and scripts to prepare for
|
|
98
|
+
* rendering the page.
|
|
99
|
+
*
|
|
100
|
+
* @param url The URL associated with the page, used for asset
|
|
101
|
+
* loading and caching.
|
|
102
|
+
* @param dom The DOM document to process.
|
|
103
|
+
* @param vdomParams Optional parameters for virtual DOM processing.
|
|
104
|
+
* @param vdomParams.vdom An optional existing virtual DOM cache to check for
|
|
105
|
+
* regions. If a region exists in this cache, it will be
|
|
106
|
+
* reused instead of creating a new vDOM representation.
|
|
107
|
+
* @return A Promise that resolves to a {@link Page} object
|
|
108
|
+
* containing the virtual DOM for all router regions,
|
|
109
|
+
* preloaded styles and scripts, page title, and initial
|
|
110
|
+
* server-rendered data.
|
|
111
|
+
*/
|
|
112
|
+
const preparePage = async (url, dom, {
|
|
59
113
|
vdom
|
|
60
114
|
} = {}) => {
|
|
61
|
-
const regions = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
115
|
+
const regions = {};
|
|
116
|
+
const regionsToAttach = {};
|
|
117
|
+
dom.querySelectorAll(regionsSelector).forEach(region => {
|
|
118
|
+
const {
|
|
119
|
+
id,
|
|
120
|
+
attachTo
|
|
121
|
+
} = parseRegionAttribute(region);
|
|
122
|
+
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
123
|
+
if (attachTo) {
|
|
124
|
+
regionsToAttach[id] = attachTo;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
71
127
|
const title = dom.querySelector('title')?.innerText;
|
|
72
128
|
const initialData = parseServerData(dom);
|
|
129
|
+
|
|
130
|
+
// Wait for styles and modules to be ready.
|
|
131
|
+
const [styles, scriptModules] = await Promise.all([Promise.all((0, _styles.preloadStyles)(dom, url)), Promise.all((0, _scriptModules.preloadScriptModules)(dom))]);
|
|
73
132
|
return {
|
|
74
133
|
regions,
|
|
134
|
+
regionsToAttach,
|
|
135
|
+
styles,
|
|
136
|
+
scriptModules,
|
|
75
137
|
title,
|
|
76
|
-
initialData
|
|
138
|
+
initialData,
|
|
139
|
+
url
|
|
77
140
|
};
|
|
78
141
|
};
|
|
79
142
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Renders a page by applying styles, populating server data, rendering regions,
|
|
145
|
+
* and updating the document title.
|
|
146
|
+
*
|
|
147
|
+
* @param page The {@link Page} object to render.
|
|
148
|
+
*/
|
|
149
|
+
const renderPage = page => {
|
|
150
|
+
(0, _styles.applyStyles)(page.styles);
|
|
151
|
+
|
|
152
|
+
// Clone regionsToAttach.
|
|
153
|
+
const regionsToAttach = {
|
|
154
|
+
...page.regionsToAttach
|
|
155
|
+
};
|
|
156
|
+
batch(() => {
|
|
157
|
+
populateServerData(page.initialData);
|
|
158
|
+
document.querySelectorAll(regionsSelector).forEach(region => {
|
|
159
|
+
const {
|
|
160
|
+
id
|
|
161
|
+
} = parseRegionAttribute(region);
|
|
162
|
+
const fragment = getRegionRootFragment(region);
|
|
163
|
+
render(page.regions[id], fragment);
|
|
164
|
+
// If this is an attached region, remove it from the list.
|
|
165
|
+
delete regionsToAttach[id];
|
|
91
166
|
});
|
|
92
|
-
|
|
167
|
+
|
|
168
|
+
// Render unattached regions.
|
|
169
|
+
for (const id in regionsToAttach) {
|
|
170
|
+
const parent = document.querySelector(regionsToAttach[id]);
|
|
171
|
+
|
|
172
|
+
// Get the type from the vnode. If wrapped with Directives, get the
|
|
173
|
+
// original type from `props.type`.
|
|
174
|
+
const {
|
|
175
|
+
props,
|
|
176
|
+
type
|
|
177
|
+
} = page.regions[id];
|
|
178
|
+
const elementType = typeof type === 'function' ? props.type : type;
|
|
179
|
+
|
|
180
|
+
// Create an element with the obtained type where the region will be
|
|
181
|
+
// rendered. The type should match the one of the root vnode.
|
|
182
|
+
const region = document.createElement(elementType);
|
|
183
|
+
parent.appendChild(region);
|
|
184
|
+
const fragment = getRegionRootFragment(region);
|
|
185
|
+
render(page.regions[id], fragment);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
93
188
|
if (page.title) {
|
|
94
189
|
document.title = page.title;
|
|
95
190
|
}
|
|
96
191
|
};
|
|
97
192
|
|
|
98
193
|
/**
|
|
99
|
-
*
|
|
194
|
+
* Loads the given page forcing a full page reload.
|
|
100
195
|
*
|
|
101
196
|
* The function returns a promise that won't resolve, useful to prevent any
|
|
102
197
|
* potential feedback indicating that the navigation has finished while the new
|
|
@@ -116,7 +211,7 @@ window.addEventListener('popstate', async () => {
|
|
|
116
211
|
const pagePath = getPagePath(window.location.href); // Remove hash.
|
|
117
212
|
const page = pages.has(pagePath) && (await pages.get(pagePath));
|
|
118
213
|
if (page) {
|
|
119
|
-
|
|
214
|
+
renderPage(page);
|
|
120
215
|
// Update the URL in the state.
|
|
121
216
|
state.url = window.location.href;
|
|
122
217
|
} else {
|
|
@@ -125,7 +220,10 @@ window.addEventListener('popstate', async () => {
|
|
|
125
220
|
});
|
|
126
221
|
|
|
127
222
|
// Initialize the router and cache the initial page using the initial vDOM.
|
|
128
|
-
|
|
223
|
+
window.document.querySelectorAll('script[type=module][src]').forEach(({
|
|
224
|
+
src
|
|
225
|
+
}) => (0, _scriptModules.markScriptModuleAsResolved)(src));
|
|
226
|
+
pages.set(getPagePath(window.location.href), Promise.resolve(preparePage(getPagePath(window.location.href), document, {
|
|
129
227
|
vdom: initialVdom
|
|
130
228
|
})));
|
|
131
229
|
|
|
@@ -214,7 +312,8 @@ const {
|
|
|
214
312
|
return;
|
|
215
313
|
}
|
|
216
314
|
if (page && !page.initialData?.config?.['core/router']?.clientNavigationDisabled) {
|
|
217
|
-
yield
|
|
315
|
+
yield (0, _scriptModules.importScriptModules)(page.scriptModules);
|
|
316
|
+
renderPage(page);
|
|
218
317
|
window.history[options.replace ? 'replaceState' : 'pushState']({}, '', href);
|
|
219
318
|
|
|
220
319
|
// Update the URL in the state.
|
|
@@ -251,8 +350,10 @@ const {
|
|
|
251
350
|
* @param [options] Options object.
|
|
252
351
|
* @param [options.force] Force fetching the URL again.
|
|
253
352
|
* @param [options.html] HTML string to be used instead of fetching the requested URL.
|
|
353
|
+
*
|
|
354
|
+
* @return Promise that resolves once the page has been fetched.
|
|
254
355
|
*/
|
|
255
|
-
prefetch(url, options = {}) {
|
|
356
|
+
*prefetch(url, options = {}) {
|
|
256
357
|
const {
|
|
257
358
|
clientNavigationDisabled
|
|
258
359
|
} = (0, _interactivity.getConfig)();
|
|
@@ -265,6 +366,7 @@ const {
|
|
|
265
366
|
html: options.html
|
|
266
367
|
}));
|
|
267
368
|
}
|
|
369
|
+
yield pages.get(pagePath);
|
|
268
370
|
}
|
|
269
371
|
}
|
|
270
372
|
});
|
|
@@ -273,7 +375,7 @@ const {
|
|
|
273
375
|
* Announces a message to screen readers.
|
|
274
376
|
*
|
|
275
377
|
* This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing
|
|
276
|
-
* the package on demand and should be used instead of calling `
|
|
378
|
+
* the package on demand and should be used instead of calling `a11y.speak` directly.
|
|
277
379
|
*
|
|
278
380
|
* @param messageKey The message to be announced by assistive technologies.
|
|
279
381
|
*/
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_interactivity","require","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","privateApis","navigationMode","pages","Map","getPagePath","url","URL","window","location","href","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","vdom","regions","body","undefined","attrName","querySelectorAll","forEach","region","id","getAttribute","title","querySelector","innerText","initialData","renderRegions","page","document","fragment","forcePageReload","assign","Promise","addEventListener","pagePath","state","reload","resolve","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","store","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","getConfig","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","history","replace","hash","scrollIntoView","force","exports","messageKey","content","getElementById","textContent","parsed","JSON","parse","i18n","texts","message","then","speak"],"sources":["@wordpress/interactivity-router/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\nconst {\n\tdirectivePrefix,\n\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\ninterface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\ninterface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: typeof initialVdom;\n}\n\ninterface Page {\n\tregions: Record< string, any >;\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype RegionsToVdom = ( dom: Document, params?: VdomParams ) => Promise< Page >;\n\n// Check if the navigation mode is full page or region based. The only supported\n// mode for now is 'regionBased'.\nconst navigationMode: 'regionBased' = 'regionBased';\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom: RegionsToVdom = async ( dom, { vdom } = {} ) => {\n\tconst regions = { body: undefined };\n\tif ( navigationMode === 'regionBased' ) {\n\t\tconst attrName = `data-${ directivePrefix }-router-region`;\n\t\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\t\tconst id = region.getAttribute( attrName );\n\t\t\tregions[ id ] = vdom?.has( region )\n\t\t\t\t? vdom.get( region )\n\t\t\t\t: toVdom( region );\n\t\t} );\n\t}\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\treturn { regions, title, initialData };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = async ( page: Page ) => {\n\tif ( navigationMode === 'regionBased' ) {\n\t\tconst attrName = `data-${ directivePrefix }-router-region`;\n\t\tbatch( () => {\n\t\t\tpopulateServerData( page.initialData );\n\t\t\tdocument\n\t\t\t\t.querySelectorAll( `[${ attrName }]` )\n\t\t\t\t.forEach( ( region ) => {\n\t\t\t\t\tconst id = region.getAttribute( attrName );\n\t\t\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\t\t\trender( page.regions[ id ], fragment );\n\t\t\t\t} );\n\t\t} );\n\t}\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Load the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tawait renderRegions( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\npages.set(\n\tgetPagePath( window.location.href ),\n\tPromise.resolve( regionsToVdom( document, { vdom: initialVdom } ) )\n);\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: ( href: string, options?: NavigateOptions ) => void;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => void;\n\t};\n}\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise< void >( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = true;\n\t\t\t\t\tnavigation.hasFinished = false;\n\t\t\t\t}\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loading' );\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield renderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t */\n\t\tprefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t},\n} );\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `ally.speak` direacly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAAyE,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAI,wBAAAJ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAM,OAAA,EAAAN,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAI,GA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c,CACtC,uDACD,CAAC,EAAEC,WAAW;IACd,IAAKF,OAAO,EAAG;MACd,IAAI;QACH,MAAMG,MAAM,GAAGC,IAAI,CAACC,KAAK,CAAEL,OAAQ,CAAC;QACpC,IAAK,OAAOG,MAAM,EAAEG,IAAI,EAAEnC,OAAO,KAAK,QAAQ,EAAG;UAChDD,eAAe,CAACC,OAAO,GAAGgC,MAAM,CAACG,IAAI,CAACnC,OAAO;QAC9C;QACA,IAAK,OAAOgC,MAAM,EAAEG,IAAI,EAAElC,MAAM,KAAK,QAAQ,EAAG;UAC/CF,eAAe,CAACE,MAAM,GAAG+B,MAAM,CAACG,IAAI,CAAClC,MAAM;QAC5C;MACD,CAAC,CAAC,MAAM,CAAC;IACV,CAAC,MAAM;MACN;MACA;;MAEA;MACA,IAAKP,KAAK,CAACU,UAAU,CAACgC,KAAK,EAAEpC,OAAO,EAAG;QACtC;QACAD,eAAe,CAACC,OAAO,GAAGN,KAAK,CAACU,UAAU,CAACgC,KAAK,CAACpC,OAAO;MACzD;MACA;MACA,IAAKN,KAAK,CAACU,UAAU,CAACgC,KAAK,EAAEnC,MAAM,EAAG;QACrC;QACAF,eAAe,CAACE,MAAM,GAAGP,KAAK,CAACU,UAAU,CAACgC,KAAK,CAACnC,MAAM;MACvD;IACD;EACD;EAEA,MAAMoC,OAAO,GAAGtC,eAAe,CAAE6B,UAAU,CAAE;EAE7CrC,OAAA,CAAAK,OAAA,GAAA0C,IAAA,OAAAjH,uBAAA,CAAAN,OAAA,CAAQ,iBAAiB,IAAGuH,IAAI,CAC/B,CAAE;IAAEC;EAAM,CAAC,KAAMA,KAAK,CAAEF,OAAQ,CAAC;EACjC;EACA,MAAM,CAAC,CACR,CAAC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_interactivity","require","_styles","_scriptModules","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","privateApis","regionAttr","interactiveAttr","regionsSelector","pages","Map","getPagePath","url","URL","window","location","href","pathname","search","parseRegionAttribute","region","value","getAttribute","id","attachTo","JSON","parse","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","preparePage","vdom","regions","regionsToAttach","querySelectorAll","forEach","title","querySelector","innerText","initialData","styles","scriptModules","Promise","all","preloadStyles","preloadScriptModules","renderPage","page","applyStyles","document","fragment","parent","props","type","elementType","createElement","appendChild","forcePageReload","assign","addEventListener","pagePath","state","reload","src","markScriptModuleAsResolved","resolve","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","store","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","getConfig","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","importScriptModules","history","replace","hash","scrollIntoView","force","exports","messageKey","content","getElementById","textContent","parsed","i18n","texts","message","then","speak"],"sources":["@wordpress/interactivity-router/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tdirectivePrefix,\n\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-${ directivePrefix }-router-region`;\nconst interactiveAttr = `data-${ directivePrefix }-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }]:not([${ interactiveAttr }] [${ interactiveAttr }])`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: typeof initialVdom;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch ( e ) {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\t\tregions[ id ] = vdom?.has( region )\n\t\t\t? vdom.get( region )\n\t\t\t: toVdom( region );\n\t\tif ( attachTo ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom, url ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\tpopulateServerData( page.initialData );\n\t\tdocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\t\tconst { id } = parseRegionAttribute( region );\n\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\trender( page.regions[ id ], fragment );\n\t\t\t// If this is an attached region, remove it from the list.\n\t\t\tdelete regionsToAttach[ id ];\n\t\t} );\n\n\t\t// Render unattached regions.\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\n\t\t\t// Get the type from the vnode. If wrapped with Directives, get the\n\t\t\t// original type from `props.type`.\n\t\t\tconst { props, type } = page.regions[ id ];\n\t\t\tconst elementType = typeof type === 'function' ? props.type : type;\n\n\t\t\t// Create an element with the obtained type where the region will be\n\t\t\t// rendered. The type should match the one of the root vnode.\n\t\t\tconst region = document.createElement( elementType );\n\t\t\tparent.appendChild( region );\n\n\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\trender( page.regions[ id ], fragment );\n\t\t}\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\trenderPage( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\npages.set(\n\tgetPagePath( window.location.href ),\n\tPromise.resolve(\n\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\tvdom: initialVdom,\n\t\t} )\n\t)\n);\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise< void >( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = true;\n\t\t\t\t\tnavigation.hasFinished = false;\n\t\t\t\t}\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loading' );\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\t\t\t\trenderPage( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAKiC,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAA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M,EAAEC,IAAI,EAAElC,OAAO,KAAK,QAAQ,EAAG;UAChDD,eAAe,CAACC,OAAO,GAAGiC,MAAM,CAACC,IAAI,CAAClC,OAAO;QAC9C;QACA,IAAK,OAAOiC,MAAM,EAAEC,IAAI,EAAEjC,MAAM,KAAK,QAAQ,EAAG;UAC/CF,eAAe,CAACE,MAAM,GAAGgC,MAAM,CAACC,IAAI,CAACjC,MAAM;QAC5C;MACD,CAAC,CAAC,MAAM,CAAC;IACV,CAAC,MAAM;MACN;MACA;;MAEA;MACA,IAAKT,KAAK,CAACY,UAAU,CAAC+B,KAAK,EAAEnC,OAAO,EAAG;QACtC;QACAD,eAAe,CAACC,OAAO,GAAGR,KAAK,CAACY,UAAU,CAAC+B,KAAK,CAACnC,OAAO;MACzD;MACA;MACA,IAAKR,KAAK,CAACY,UAAU,CAAC+B,KAAK,EAAElC,MAAM,EAAG;QACrC;QACAF,eAAe,CAACE,MAAM,GAAGT,KAAK,CAACY,UAAU,CAAC+B,KAAK,CAAClC,MAAM;MACvD;IACD;EACD;EAEA,MAAMmC,OAAO,GAAGrC,eAAe,CAAE8B,UAAU,CAAE;EAE7CxD,OAAA,CAAAuB,OAAA,GAAAyC,IAAA,OAAAnI,uBAAA,CAAAR,OAAA,CAAQ,iBAAiB,IAAG2I,IAAI,CAC/B,CAAE;IAAEC;EAAM,CAAC,KAAMA,KAAK,CAAEF,OAAQ,CAAC;EACjC;EACA,MAAM,CAAC,CACR,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is derived from the following projects:
|
|
3
|
+
*
|
|
4
|
+
* 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
|
|
5
|
+
* 2. es-module-shims (https://github.com/guybedford/es-module-shims)
|
|
6
|
+
*
|
|
7
|
+
* The original implementation was created by Guy Bedford in es-module-shims,
|
|
8
|
+
* then adapted by Mark Keller in dynamic-importmap, and further modified
|
|
9
|
+
* for use in this project.
|
|
10
|
+
*
|
|
11
|
+
* Both projects are licensed under the MIT license.
|
|
12
|
+
*
|
|
13
|
+
* MIT License: https://opensource.org/licenses/MIT
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const fetching = (url, parent) => {
|
|
21
|
+
return ` fetching ${url}${parent ? ` from ${parent}` : ''}`;
|
|
22
|
+
};
|
|
23
|
+
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Fetches the passed module URL and return the corresponding `ModuleLoad`
|
|
27
|
+
* instance. If the passed URL does not point to a JS file, the function
|
|
28
|
+
* throws and error.
|
|
29
|
+
*
|
|
30
|
+
* @param url Module URL.
|
|
31
|
+
* @param fetchOpts Fetch init options.
|
|
32
|
+
* @param parent Parent module URL referencing this URL (if any).
|
|
33
|
+
* @return Promise with a `ModuleLoad` instance.
|
|
34
|
+
*/
|
|
35
|
+
export async function fetchModule(url, fetchOpts, parent) {
|
|
36
|
+
let res;
|
|
37
|
+
try {
|
|
38
|
+
res = await fetch(url, fetchOpts);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw Error(`Network error${fetching(url, parent)}.`);
|
|
41
|
+
}
|
|
42
|
+
if (!res.ok) {
|
|
43
|
+
throw Error(`Error ${res.status}${fetching(url, parent)}.`);
|
|
44
|
+
}
|
|
45
|
+
const contentType = res.headers.get('content-type');
|
|
46
|
+
if (!jsContentType.test(contentType)) {
|
|
47
|
+
throw Error(`Bad Content-Type "${contentType}"${fetching(url, parent)}.`);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
responseUrl: res.url,
|
|
51
|
+
source: await res.text()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fetching","url","parent","jsContentType","fetchModule","fetchOpts","res","fetch","e","Error","ok","status","contentType","headers","get","test","responseUrl","source","text"],"sources":["@wordpress/interactivity-router/src/assets/dynamic-importmap/fetch.ts"],"sourcesContent":["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { type ModuleLoad } from './loader';\n\nconst fetching = ( url: string, parent?: string ) => {\n\treturn ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;\n};\n\nconst jsContentType = /^(text|application)\\/(x-)?javascript(;|$)/;\n\n/**\n * Fetches the passed module URL and return the corresponding `ModuleLoad`\n * instance. If the passed URL does not point to a JS file, the function\n * throws and error.\n *\n * @param url Module URL.\n * @param fetchOpts Fetch init options.\n * @param parent Parent module URL referencing this URL (if any).\n * @return Promise with a `ModuleLoad` instance.\n */\nexport async function fetchModule(\n\turl: string,\n\tfetchOpts: RequestInit,\n\tparent: string\n): Promise< ModuleLoad > {\n\tlet res: Response;\n\ttry {\n\t\tres = await fetch( url, fetchOpts );\n\t} catch ( e ) {\n\t\tthrow Error( `Network error${ fetching( url, parent ) }.` );\n\t}\n\tif ( ! res.ok ) {\n\t\tthrow Error( `Error ${ res.status }${ fetching( url, parent ) }.` );\n\t}\n\tconst contentType = res.headers.get( 'content-type' );\n\tif ( ! jsContentType.test( contentType ) ) {\n\t\tthrow Error(\n\t\t\t`Bad Content-Type \"${ contentType }\"${ fetching( url, parent ) }.`\n\t\t);\n\t}\n\treturn { responseUrl: res.url, source: await res.text() };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA,MAAMA,QAAQ,GAAGA,CAAEC,GAAW,EAAEC,MAAe,KAAM;EACpD,OAAO,aAAcD,GAAG,GAAKC,MAAM,GAAG,SAAUA,MAAM,EAAG,GAAG,EAAE,EAAG;AAClE,CAAC;AAED,MAAMC,aAAa,GAAG,2CAA2C;;AAEjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,WAAWA,CAChCH,GAAW,EACXI,SAAsB,EACtBH,MAAc,EACU;EACxB,IAAII,GAAa;EACjB,IAAI;IACHA,GAAG,GAAG,MAAMC,KAAK,CAAEN,GAAG,EAAEI,SAAU,CAAC;EACpC,CAAC,CAAC,OAAQG,CAAC,EAAG;IACb,MAAMC,KAAK,CAAE,gBAAiBT,QAAQ,CAAEC,GAAG,EAAEC,MAAO,CAAC,GAAK,CAAC;EAC5D;EACA,IAAK,CAAEI,GAAG,CAACI,EAAE,EAAG;IACf,MAAMD,KAAK,CAAE,SAAUH,GAAG,CAACK,MAAM,GAAKX,QAAQ,CAAEC,GAAG,EAAEC,MAAO,CAAC,GAAK,CAAC;EACpE;EACA,MAAMU,WAAW,GAAGN,GAAG,CAACO,OAAO,CAACC,GAAG,CAAE,cAAe,CAAC;EACrD,IAAK,CAAEX,aAAa,CAACY,IAAI,CAAEH,WAAY,CAAC,EAAG;IAC1C,MAAMH,KAAK,CACV,qBAAsBG,WAAW,IAAMZ,QAAQ,CAAEC,GAAG,EAAEC,MAAO,CAAC,GAC/D,CAAC;EACF;EACA,OAAO;IAAEc,WAAW,EAAEV,GAAG,CAACL,GAAG;IAAEgB,MAAM,EAAE,MAAMX,GAAG,CAACY,IAAI,CAAC;EAAE,CAAC;AAC1D","ignoreList":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is derived from the following projects:
|
|
3
|
+
*
|
|
4
|
+
* 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
|
|
5
|
+
* 2. es-module-shims (https://github.com/guybedford/es-module-shims)
|
|
6
|
+
*
|
|
7
|
+
* The original implementation was created by Guy Bedford in es-module-shims,
|
|
8
|
+
* then adapted by Mark Keller in dynamic-importmap, and further modified
|
|
9
|
+
* for use in this project.
|
|
10
|
+
*
|
|
11
|
+
* Both projects are licensed under the MIT license.
|
|
12
|
+
*
|
|
13
|
+
* MIT License: https://opensource.org/licenses/MIT
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import { addImportMap, resolve } from './resolver';
|
|
20
|
+
import { initPromise, topLevelLoad, preloadModule } from './loader';
|
|
21
|
+
// TODO: check if this baseURI should change per document, and so
|
|
22
|
+
// it need to be passed as a parameter to methods like `importWithMap`
|
|
23
|
+
// and `preloadWithMap`.
|
|
24
|
+
const baseUrl = document.baseURI;
|
|
25
|
+
const pageBaseUrl = baseUrl;
|
|
26
|
+
Object.defineProperty(self, 'wpInteractivityRouterImport', {
|
|
27
|
+
value: importShim,
|
|
28
|
+
writable: false,
|
|
29
|
+
enumerable: false,
|
|
30
|
+
configurable: false
|
|
31
|
+
});
|
|
32
|
+
async function importShim(id) {
|
|
33
|
+
await initPromise;
|
|
34
|
+
return topLevelLoad(resolve(id, pageBaseUrl), {
|
|
35
|
+
credentials: 'same-origin'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Imports the module with the passed ID.
|
|
41
|
+
*
|
|
42
|
+
* The module is resolved against the internal dynamic import map,
|
|
43
|
+
* extended with the passed import map.
|
|
44
|
+
*
|
|
45
|
+
* @param id Module ID.
|
|
46
|
+
* @param importMapIn Import map.
|
|
47
|
+
* @return Resolved module.
|
|
48
|
+
*/
|
|
49
|
+
export async function importWithMap(id, importMapIn) {
|
|
50
|
+
addImportMap(importMapIn);
|
|
51
|
+
return importShim(id);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Preloads the module with the passed ID along with its dependencies.
|
|
56
|
+
*
|
|
57
|
+
* The module is resolved against the internal dynamic import map,
|
|
58
|
+
* extended with the passed import map.
|
|
59
|
+
*
|
|
60
|
+
* @param id Module ID.
|
|
61
|
+
* @param importMapIn Import map.
|
|
62
|
+
* @return Resolved `ModuleLoad` instance.
|
|
63
|
+
*/
|
|
64
|
+
export async function preloadWithMap(id, importMapIn) {
|
|
65
|
+
addImportMap(importMapIn);
|
|
66
|
+
await initPromise;
|
|
67
|
+
return preloadModule(resolve(id, pageBaseUrl), {
|
|
68
|
+
credentials: 'same-origin'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export { initialImportMap, importPreloadedModule } from './loader';
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["addImportMap","resolve","initPromise","topLevelLoad","preloadModule","baseUrl","document","baseURI","pageBaseUrl","Object","defineProperty","self","value","importShim","writable","enumerable","configurable","id","credentials","importWithMap","importMapIn","preloadWithMap","initialImportMap","importPreloadedModule"],"sources":["@wordpress/interactivity-router/src/assets/dynamic-importmap/index.ts"],"sourcesContent":["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { addImportMap, resolve } from './resolver';\nimport { initPromise, topLevelLoad, preloadModule } from './loader';\n\ntype ImportMap = {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, Record< string, string > >;\n};\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `importWithMap`\n// and `preloadWithMap`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\nObject.defineProperty( self, 'wpInteractivityRouterImport', {\n\tvalue: importShim,\n\twritable: false,\n\tenumerable: false,\n\tconfigurable: false,\n} );\n\nasync function importShim< Module = unknown >( id: string ) {\n\tawait initPromise;\n\treturn topLevelLoad< Module >( resolve( id, pageBaseUrl ), {\n\t\tcredentials: 'same-origin',\n\t} );\n}\n\n/**\n * Imports the module with the passed ID.\n *\n * The module is resolved against the internal dynamic import map,\n * extended with the passed import map.\n *\n * @param id Module ID.\n * @param importMapIn Import map.\n * @return Resolved module.\n */\nexport async function importWithMap< Module = unknown >(\n\tid: string,\n\timportMapIn: ImportMap\n) {\n\taddImportMap( importMapIn );\n\treturn importShim< Module >( id );\n}\n\n/**\n * Preloads the module with the passed ID along with its dependencies.\n *\n * The module is resolved against the internal dynamic import map,\n * extended with the passed import map.\n *\n * @param id Module ID.\n * @param importMapIn Import map.\n * @return Resolved `ModuleLoad` instance.\n */\nexport async function preloadWithMap( id: string, importMapIn: ImportMap ) {\n\taddImportMap( importMapIn );\n\tawait initPromise;\n\treturn preloadModule( resolve( id, pageBaseUrl ), {\n\t\tcredentials: 'same-origin',\n\t} );\n}\n\nexport {\n\tinitialImportMap,\n\timportPreloadedModule,\n\ttype ModuleLoad,\n} from './loader';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,OAAO,QAAQ,YAAY;AAClD,SAASC,WAAW,EAAEC,YAAY,EAAEC,aAAa,QAAQ,UAAU;AAOnE;AACA;AACA;AACA,MAAMC,OAAO,GAAGC,QAAQ,CAACC,OAAO;AAChC,MAAMC,WAAW,GAAGH,OAAO;AAE3BI,MAAM,CAACC,cAAc,CAAEC,IAAI,EAAE,6BAA6B,EAAE;EAC3DC,KAAK,EAAEC,UAAU;EACjBC,QAAQ,EAAE,KAAK;EACfC,UAAU,EAAE,KAAK;EACjBC,YAAY,EAAE;AACf,CAAE,CAAC;AAEH,eAAeH,UAAUA,CAAsBI,EAAU,EAAG;EAC3D,MAAMf,WAAW;EACjB,OAAOC,YAAY,CAAYF,OAAO,CAAEgB,EAAE,EAAET,WAAY,CAAC,EAAE;IAC1DU,WAAW,EAAE;EACd,CAAE,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CAClCF,EAAU,EACVG,WAAsB,EACrB;EACDpB,YAAY,CAAEoB,WAAY,CAAC;EAC3B,OAAOP,UAAU,CAAYI,EAAG,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeI,cAAcA,CAAEJ,EAAU,EAAEG,WAAsB,EAAG;EAC1EpB,YAAY,CAAEoB,WAAY,CAAC;EAC3B,MAAMlB,WAAW;EACjB,OAAOE,aAAa,CAAEH,OAAO,CAAEgB,EAAE,EAAET,WAAY,CAAC,EAAE;IACjDU,WAAW,EAAE;EACd,CAAE,CAAC;AACJ;AAEA,SACCI,gBAAgB,EAChBC,qBAAqB,QAEf,UAAU","ignoreList":[]}
|