@wordpress/interactivity-router 2.39.1-next.v.202602091733.0 → 2.40.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 CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.40.0 (2026-02-18)
6
+
7
+ ### Deprecations
8
+
9
+ - Move `state.navigation.hasStarted` and `state.navigation.hasFinished` to a private store and deprecate direct access from the public `core/router` store. ([#70882](https://github.com/WordPress/gutenberg/pull/70882))
10
+
11
+ ### Bug Fixes
12
+
13
+ - Update cached styles for re-fetched pages. ([#75097](https://github.com/WordPress/gutenberg/pull/75097))
14
+
5
15
  ## 2.39.0 (2026-01-29)
6
16
 
7
17
  ### Bug Fixes
@@ -37,8 +47,7 @@
37
47
 
38
48
  - Preserve `media` attribute on intial style sheets after client-side navigation. ([70668](https://github.com/WordPress/gutenberg/pull/70668))
39
49
 
40
- - Ignores `<noscript>` elements while preparing DOM. ([70905](https://github.com/WordPress/gutenberg/pull/70905))
41
-
50
+ - Ignores `<noscript>` elements while preparing DOM. ([70905](https://github.com/WordPress/gutenberg/pull/70905))
42
51
 
43
52
  ## 2.26.0 (2025-06-25)
44
53
 
package/README.md CHANGED
@@ -45,15 +45,6 @@ When loaded, this package [adds the following state and actions](https://github.
45
45
  const { state, actions } = store( 'core/router', {
46
46
  state: {
47
47
  url: window.location.href,
48
- navigation: {
49
- hasStarted: false,
50
- hasFinished: false,
51
- texts: {
52
- loading: '',
53
- loaded: '',
54
- },
55
- message: '',
56
- },
57
48
  },
58
49
  actions: {
59
50
  *navigate(href, options) {...},
@@ -157,7 +148,6 @@ prefetch( url: string, options: PrefetchOptions = {} )
157
148
  ### State
158
149
 
159
150
  `state.url` is a reactive property synchronized with the current URL.
160
- Properties under `state.navigation` are meant for loading bar animations.
161
151
 
162
152
  ## Installation
163
153
 
@@ -117,24 +117,16 @@ var prepareStylePromise = (element) => {
117
117
  stylePromiseCache.set(element, promise);
118
118
  return promise;
119
119
  };
120
- var styleSheetCache = /* @__PURE__ */ new Map();
121
- var preloadStyles = (doc, url) => {
122
- if (!styleSheetCache.has(url)) {
123
- const currentStyleElements = Array.from(
124
- window.document.querySelectorAll(
125
- "style,link[rel=stylesheet]"
126
- )
127
- );
128
- const newStyleElements = Array.from(
129
- doc.querySelectorAll("style,link[rel=stylesheet]")
130
- );
131
- const stylePromises = updateStylesWithSCS(
132
- currentStyleElements,
133
- newStyleElements
134
- );
135
- styleSheetCache.set(url, stylePromises);
136
- }
137
- return styleSheetCache.get(url);
120
+ var preloadStyles = (doc) => {
121
+ const currentStyleElements = Array.from(
122
+ window.document.querySelectorAll(
123
+ "style,link[rel=stylesheet]"
124
+ )
125
+ );
126
+ const newStyleElements = Array.from(
127
+ doc.querySelectorAll("style,link[rel=stylesheet]")
128
+ );
129
+ return updateStylesWithSCS(currentStyleElements, newStyleElements);
138
130
  };
139
131
  var applyStyles = (styles) => {
140
132
  window.document.querySelectorAll("style,link[rel=stylesheet]").forEach((el) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/assets/styles.ts"],
4
- "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\t// Only update mediaText when necessary.\n\t\t\t\t\tif ( el.sheet.media.mediaText === 'preload' ) {\n\t\t\t\t\t\tconst { originalMedia = 'all' } = el.dataset;\n\t\t\t\t\t\tel.sheet.media.mediaText = originalMedia;\n\t\t\t\t\t}\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA4C;AAY5C,IAAM,gBAAgB,CAAE,GAAiB,MACxC,EAAE,YAAa,CAAE;AAmBX,IAAM,iBAAiB,CAAE,YAAyC;AACxE,YAAU,QAAQ,UAAW,IAAK;AAClC,QAAM,QAAQ,QAAQ;AACtB,QAAM,EAAE,cAAc,IAAI,QAAQ;AAElC,MAAK,UAAU,WAAY;AAC1B,YAAQ,QAAQ,iBAAiB;AACjC,YAAQ,gBAAiB,qBAAsB;AAAA,EAChD,WAAY,CAAE,QAAQ,OAAQ;AAC7B,YAAQ,QAAQ;AAAA,EACjB;AACA,SAAO;AACR;AAuBO,SAAS,oBACf,GACA,GACA,SAAkB,OAAO,SAAS,M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,MAAM,MAAM,cAAc,WAAY;AAC7C,gBAAM,EAAE,gBAAgB,MAAM,IAAI,GAAG;AACrC,aAAG,MAAM,MAAM,YAAY;AAAA,QAC5B;AACA,WAAG,MAAM,WAAW;AAAA,MACrB,OAAO;AACN,WAAG,MAAM,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,EACD,CAAE;AACJ;",
4
+ "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 * 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 * Note that this function alters the passed document, as it can transfer\n * nodes from it to the global document.\n *\n * @param doc Document instance.\n * @return A list of promises for each style element in the passed document.\n */\nexport const preloadStyles = ( doc: Document ): Promise< StyleElement >[] => {\n\tconst currentStyleElements = Array.from(\n\t\twindow.document.querySelectorAll< StyleElement >(\n\t\t\t'style,link[rel=stylesheet]'\n\t\t)\n\t);\n\tconst newStyleElements = Array.from(\n\t\tdoc.querySelectorAll< StyleElement >( 'style,link[rel=stylesheet]' )\n\t);\n\n\t// Set styles in order.\n\treturn updateStylesWithSCS( currentStyleElements, newStyleElements );\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\t// Only update mediaText when necessary.\n\t\t\t\t\tif ( el.sheet.media.mediaText === 'preload' ) {\n\t\t\t\t\t\tconst { originalMedia = 'all' } = el.dataset;\n\t\t\t\t\t\tel.sheet.media.mediaText = originalMedia;\n\t\t\t\t\t}\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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C9B,IAAI,iBAAkC,4BAA6B;AAAA,EACpE;AAGA,SAAO,oBAAqB,sBAAsB,gBAAiB;AACpE;AAWO,IAAM,cAAc,CAAE,WAA4B;AACxD,SAAO,SACL,iBAAkB,4BAA6B,EAC/C,QAAS,CAAE,OAA4C;AACvD,QAAK,GAAG,OAAQ;AACf,UAAK,OAAO,SAAU,EAAG,GAAI;AAE5B,YAAK,GAAG,MAAM,MAAM,cAAc,WAAY;AAC7C,gBAAM,EAAE,gBAAgB,MAAM,IAAI,GAAG;AACrC,aAAG,MAAM,MAAM,YAAY;AAAA,QAC5B;AACA,WAAG,MAAM,WAAW;AAAA,MACrB,OAAO;AACN,WAAG,MAAM,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,EACD,CAAE;AACJ;",
6
6
  "names": ["promise"]
7
7
  }
package/build/index.cjs CHANGED
@@ -46,7 +46,8 @@ var {
46
46
  batch,
47
47
  routerRegions,
48
48
  h: createElement,
49
- navigationSignal
49
+ navigationSignal,
50
+ warn
50
51
  } = (0, import_interactivity.privateApis)(
51
52
  "I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."
52
53
  );
@@ -117,7 +118,7 @@ var preparePage = async (url, dom, { vdom } = {}) => {
117
118
  const title = dom.querySelector("title")?.innerText;
118
119
  const initialData = parseServerData(dom);
119
120
  const [styles, scriptModules] = await Promise.all([
120
- Promise.all((0, import_styles.preloadStyles)(dom, url)),
121
+ Promise.all((0, import_styles.preloadStyles)(dom)),
121
122
  Promise.all((0, import_script_modules.preloadScriptModules)(dom))
122
123
  ]);
123
124
  return {
@@ -219,12 +220,27 @@ var navigationTexts = {
219
220
  loading: "Loading page, please wait.",
220
221
  loaded: "Page Loaded."
221
222
  };
223
+ var { state: privateState } = (0, import_interactivity.store)(
224
+ "core/router/private",
225
+ {
226
+ state: {
227
+ navigation: {
228
+ hasStarted: false,
229
+ hasFinished: false
230
+ }
231
+ }
232
+ },
233
+ { lock: true }
234
+ );
222
235
  var { state, actions } = (0, import_interactivity.store)("core/router", {
223
236
  state: {
224
- url: window.location.href,
225
- navigation: {
226
- hasStarted: false,
227
- hasFinished: false
237
+ get navigation() {
238
+ if (globalThis.SCRIPT_DEBUG) {
239
+ warn(
240
+ `The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`
241
+ );
242
+ }
243
+ return privateState.navigation;
228
244
  }
229
245
  },
230
246
  actions: {
@@ -252,7 +268,7 @@ var { state, actions } = (0, import_interactivity.store)("core/router", {
252
268
  yield forcePageReload(href);
253
269
  }
254
270
  const pagePath = getPagePath(href);
255
- const { navigation } = state;
271
+ const { navigation } = privateState;
256
272
  const {
257
273
  loadingAnimation = true,
258
274
  screenReaderAnnouncement = true,
@@ -334,6 +350,7 @@ var { state, actions } = (0, import_interactivity.store)("core/router", {
334
350
  }
335
351
  }
336
352
  });
353
+ state.url = state.url || window.location.href;
337
354
  function a11ySpeak(messageKey) {
338
355
  if (!hasLoadedNavigationTextsData) {
339
356
  hasLoadedNavigationTextsData = true;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "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\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\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-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\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 * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\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\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\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\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, 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\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\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// Creates 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// Doesn'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// Dismisses 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\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\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\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAA8C;AAK9C,oBAA8D;AAC9D,4BAKO;AAEP,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH;AACD,QAAI;AAAA,EACH;AACD;AAEA,IAAM,aAAa;AACnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,IAAK,eAAgB,KAAM,UAAW,OAAQ,eAAgB,MAAO,eAAgB,KAAM,UAAW;AAqC9H,IAAM,QAAQ,oBAAI,IAAuC;AAIzD,IAAM,cAAc,CAAE,QAAiB;AACtC,QAAM,IAAI,IAAI,IAAK,KAAK,OAAO,SAAS,IAAK;AAC7C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": ["/**\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\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\twarn,\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-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\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 * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\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\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\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 ) ),\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\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, 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\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\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\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\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 } = privateState;\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// Creates 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// Doesn'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// Dismisses 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\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\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\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// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAA8C;AAK9C,oBAA8D;AAC9D,4BAKO;AAEP,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH;AAAA,EACA;AACD,QAAI;AAAA,EACH;AACD;AAEA,IAAM,aAAa;AACnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,IAAK,eAAgB,KAAM,UAAW,OAAQ,eAAgB,MAAO,eAAgB,KAAM,UAAW;AAqC9H,IAAM,QAAQ,oBAAI,IAAuC;AAIzD,IAAM,cAAc,CAAE,QAAiB;AACtC,QAAM,IAAI,IAAI,IAAK,KAAK,OAAO,SAAS,IAAK;AAC7C,SAAO,EAAE,WAAW,EAAE;AACvB;AAQA,IAAM,uBAAuB,CAAE,WAAqB;AACnD,QAAM,QAAQ,OAAO,aAAc,UAAW;AAC9C,MAAI;AACH,UAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAO,KAAM;AAC3C,WAAO,EAAE,IAAI,SAAS;AAAA,EACvB,SAAU,GAAI;AACb,WAAO,EAAE,IAAI,MAAM;AAAA,EACpB;AACD;AAYA,IAAM,2BAA2B,CAAE,SAAe;AACjD,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AACA,QAAM,oBAAgC,KAAK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C,UAAK,0BAA2B;AAC/B;AAAA,MACD;AAEA,YAAM,WAAW,YAAa,GAAI;AAClC,UAAK,QAAQ,SAAS,CAAE,MAAM,IAAK,QAAS,GAAI;AAC/C,cAAM;AAAA,UACL;AAAA,UACA,UAAW,UAAU,EAAE,MAAM,QAAQ,KAAK,CAAE;AAAA,QAC7C;AAAA,MACD;AAEA,YAAM,MAAM,IAAK,QAAS;AAAA,IAC3B;AAAA,EACD;AACD,CAAE;AAGF,MAAM,MAAM,MAAM,OAAO,OAAO,SAAS;AAUzC,SAAS,UAAW,YAA2C;AAC9D,MAAK,CAAE,8BAA+B;AACrC,mCAA+B;AAC/B,UAAM,UAAU,SAAS;AAAA,MACxB;AAAA,IACD,GAAG;AACH,QAAK,SAAU;AACd,UAAI;AACH,cAAM,SAAS,KAAK,MAAO,OAAQ;AACnC,YAAK,OAAO,QAAQ,MAAM,YAAY,UAAW;AAChD,0BAAgB,UAAU,OAAO,KAAK;AAAA,QACvC;AACA,YAAK,OAAO,QAAQ,MAAM,WAAW,UAAW;AAC/C,0BAAgB,SAAS,OAAO,KAAK;AAAA,QACtC;AAAA,MACD,QAAQ;AAAA,MAAC;AAAA,IACV,OAAO;AAKN,UAAK,MAAM,WAAW,OAAO,SAAU;AAEtC,wBAAgB,UAAU,MAAM,WAAW,MAAM;AAAA,MAClD;AAEA,UAAK,MAAM,WAAW,OAAO,QAAS;AAErC,wBAAgB,SAAS,MAAM,WAAW,MAAM;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,gBAAiB,UAAW;AAE5C,SAAQ,iBAAkB,EAAE;AAAA,IAC3B,CAAE,EAAE,MAAM,MAAO,MAAO,OAAQ;AAAA;AAAA,IAEhC,MAAM;AAAA,IAAC;AAAA,EACR;AACD;",
6
6
  "names": []
7
7
  }
@@ -91,24 +91,16 @@ var prepareStylePromise = (element) => {
91
91
  stylePromiseCache.set(element, promise);
92
92
  return promise;
93
93
  };
94
- var styleSheetCache = /* @__PURE__ */ new Map();
95
- var preloadStyles = (doc, url) => {
96
- if (!styleSheetCache.has(url)) {
97
- const currentStyleElements = Array.from(
98
- window.document.querySelectorAll(
99
- "style,link[rel=stylesheet]"
100
- )
101
- );
102
- const newStyleElements = Array.from(
103
- doc.querySelectorAll("style,link[rel=stylesheet]")
104
- );
105
- const stylePromises = updateStylesWithSCS(
106
- currentStyleElements,
107
- newStyleElements
108
- );
109
- styleSheetCache.set(url, stylePromises);
110
- }
111
- return styleSheetCache.get(url);
94
+ var preloadStyles = (doc) => {
95
+ const currentStyleElements = Array.from(
96
+ window.document.querySelectorAll(
97
+ "style,link[rel=stylesheet]"
98
+ )
99
+ );
100
+ const newStyleElements = Array.from(
101
+ doc.querySelectorAll("style,link[rel=stylesheet]")
102
+ );
103
+ return updateStylesWithSCS(currentStyleElements, newStyleElements);
112
104
  };
113
105
  var applyStyles = (styles) => {
114
106
  window.document.querySelectorAll("style,link[rel=stylesheet]").forEach((el) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/assets/styles.ts"],
4
- "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\t// Only update mediaText when necessary.\n\t\t\t\t\tif ( el.sheet.media.mediaText === 'preload' ) {\n\t\t\t\t\t\tconst { originalMedia = 'all' } = el.dataset;\n\t\t\t\t\t\tel.sheet.media.mediaText = originalMedia;\n\t\t\t\t\t}\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"],
5
- "mappings": ";AAGA,SAAS,mCAAmC;AAY5C,IAAM,gBAAgB,CAAE,GAAiB,MACxC,EAAE,YAAa,CAAE;AAmBX,IAAM,iBAAiB,CAAE,YAAyC;AACxE,YAAU,QAAQ,UAAW,IAAK;AAClC,QAAM,QAAQ,QAAQ;AACtB,QAAM,EAAE,cAAc,IAAI,QAAQ;AAElC,MAAK,UAAU,WAAY;AAC1B,YAAQ,QAAQ,iBAAiB;AACjC,YAAQ,gBAAiB,qBAAsB;AAAA,EAChD,WAAY,CAAE,QAAQ,OAAQ;AAC7B,YAAQ,QAAQ;AAAA,EACjB;AACA,SAAO;AACR;AAuBO,SAAS,oBACf,GACA,GACA,SAAkB,OAAO,SAAS,MACjC;AACD,MAAK,EAAE,WAAW,GAAI;AACrB,WAAO,EAAE,IAAK,CAAE,YAAa;AAC5B,YAAM,UAAU,oBAAqB,OAAQ;AAC7C,aAAO,YAAa,OAAQ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M,WAAW;AAAA,MACrB,OAAO;AACN,WAAG,MAAM,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,EACD,CAAE;AACJ;",
4
+ "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 * 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 * Note that this function alters the passed document, as it can transfer\n * nodes from it to the global document.\n *\n * @param doc Document instance.\n * @return A list of promises for each style element in the passed document.\n */\nexport const preloadStyles = ( doc: Document ): Promise< StyleElement >[] => {\n\tconst currentStyleElements = Array.from(\n\t\twindow.document.querySelectorAll< StyleElement >(\n\t\t\t'style,link[rel=stylesheet]'\n\t\t)\n\t);\n\tconst newStyleElements = Array.from(\n\t\tdoc.querySelectorAll< StyleElement >( 'style,link[rel=stylesheet]' )\n\t);\n\n\t// Set styles in order.\n\treturn updateStylesWithSCS( currentStyleElements, newStyleElements );\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\t// Only update mediaText when necessary.\n\t\t\t\t\tif ( el.sheet.media.mediaText === 'preload' ) {\n\t\t\t\t\t\tconst { originalMedia = 'all' } = el.dataset;\n\t\t\t\t\t\tel.sheet.media.mediaText = originalMedia;\n\t\t\t\t\t}\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"],
5
+ "mappings": ";AAGA,SAAS,mCAAmC;AAY5C,IAAM,gBAAgB,CAAE,GAAiB,MACxC,EAAE,YAAa,CAAE;AAmBX,IAAM,iBAAiB,CAAE,YAAyC;AACxE,YAAU,QAAQ,UAAW,IAAK;AAClC,QAAM,QAAQ,QAAQ;AACtB,QAAM,EAAE,cA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AAQ;AACf,UAAK,OAAO,SAAU,EAAG,GAAI;AAE5B,YAAK,GAAG,MAAM,MAAM,cAAc,WAAY;AAC7C,gBAAM,EAAE,gBAAgB,MAAM,IAAI,GAAG;AACrC,aAAG,MAAM,MAAM,YAAY;AAAA,QAC5B;AACA,WAAG,MAAM,WAAW;AAAA,MACrB,OAAO;AACN,WAAG,MAAM,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,EACD,CAAE;AACJ;",
6
6
  "names": ["promise"]
7
7
  }
@@ -16,7 +16,8 @@ var {
16
16
  batch,
17
17
  routerRegions,
18
18
  h: createElement,
19
- navigationSignal
19
+ navigationSignal,
20
+ warn
20
21
  } = privateApis(
21
22
  "I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."
22
23
  );
@@ -87,7 +88,7 @@ var preparePage = async (url, dom, { vdom } = {}) => {
87
88
  const title = dom.querySelector("title")?.innerText;
88
89
  const initialData = parseServerData(dom);
89
90
  const [styles, scriptModules] = await Promise.all([
90
- Promise.all(preloadStyles(dom, url)),
91
+ Promise.all(preloadStyles(dom)),
91
92
  Promise.all(preloadScriptModules(dom))
92
93
  ]);
93
94
  return {
@@ -189,12 +190,27 @@ var navigationTexts = {
189
190
  loading: "Loading page, please wait.",
190
191
  loaded: "Page Loaded."
191
192
  };
193
+ var { state: privateState } = store(
194
+ "core/router/private",
195
+ {
196
+ state: {
197
+ navigation: {
198
+ hasStarted: false,
199
+ hasFinished: false
200
+ }
201
+ }
202
+ },
203
+ { lock: true }
204
+ );
192
205
  var { state, actions } = store("core/router", {
193
206
  state: {
194
- url: window.location.href,
195
- navigation: {
196
- hasStarted: false,
197
- hasFinished: false
207
+ get navigation() {
208
+ if (globalThis.SCRIPT_DEBUG) {
209
+ warn(
210
+ `The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`
211
+ );
212
+ }
213
+ return privateState.navigation;
198
214
  }
199
215
  },
200
216
  actions: {
@@ -222,7 +238,7 @@ var { state, actions } = store("core/router", {
222
238
  yield forcePageReload(href);
223
239
  }
224
240
  const pagePath = getPagePath(href);
225
- const { navigation } = state;
241
+ const { navigation } = privateState;
226
242
  const {
227
243
  loadingAnimation = true,
228
244
  screenReaderAnnouncement = true,
@@ -304,6 +320,7 @@ var { state, actions } = store("core/router", {
304
320
  }
305
321
  }
306
322
  });
323
+ state.url = state.url || window.location.href;
307
324
  function a11ySpeak(messageKey) {
308
325
  if (!hasLoadedNavigationTextsData) {
309
326
  hasLoadedNavigationTextsData = true;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "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\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\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-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\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 * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\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\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\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\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, 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\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\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// Creates 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// Doesn'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// Dismisses 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\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\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\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"],
5
- "mappings": ";AAGA,SAAS,OAAO,aAAa,iBAAiB;AAK9C,SAAS,eAAe,mBAAsC;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAEP,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH;AACD,IAAI;AAAA,EACH;AACD;AAEA,IAAM,aAAa;AACnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,IAAK,eAAgB,KAAM,UAAW,OAAQ,eAAgB,MAAO,eAAgB,KAAM,UAAW;AAqC9H,IAAM,QAAQ,oBAAI,IAAuC;AAIzD,IAAM,cAAc,CAAE,QAAiB;AACtC,QAAM,IAAI,IAAI,IAAK,KAAK,OAAO,SAAS,IAAK;AAC7C,SAAO,EAAE,WAAW,EAAE;AACvB;AAQA,IAAM,uBAAuB,CAAE,WAAqB;AACnD,QAAM,QAAQ,OAAO,aAAc,UAAW;AAC9C,MAAI;AACH,UAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAO,KAAM;AAC3C,WAAO,EAAE,IAAI,SAAS;AAAA,EACvB,SAAU,GAAI;AACb,WAAO,EAAE,IAAI,MAAM;AAAA,EACpB;AACD;AAYA,IAAM,2BAA2B,CAAE,SAAe;AACjD,MAA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W,UAAU,EAAE,MAAM,QAAQ,KAAK,CAAE;AAAA,QAC7C;AAAA,MACD;AAEA,YAAM,MAAM,IAAK,QAAS;AAAA,IAC3B;AAAA,EACD;AACD,CAAE;AAUF,SAAS,UAAW,YAA2C;AAC9D,MAAK,CAAE,8BAA+B;AACrC,mCAA+B;AAC/B,UAAM,UAAU,SAAS;AAAA,MACxB;AAAA,IACD,GAAG;AACH,QAAK,SAAU;AACd,UAAI;AACH,cAAM,SAAS,KAAK,MAAO,OAAQ;AACnC,YAAK,OAAO,QAAQ,MAAM,YAAY,UAAW;AAChD,0BAAgB,UAAU,OAAO,KAAK;AAAA,QACvC;AACA,YAAK,OAAO,QAAQ,MAAM,WAAW,UAAW;AAC/C,0BAAgB,SAAS,OAAO,KAAK;AAAA,QACtC;AAAA,MACD,QAAQ;AAAA,MAAC;AAAA,IACV,OAAO;AAKN,UAAK,MAAM,WAAW,OAAO,SAAU;AAEtC,wBAAgB,UAAU,MAAM,WAAW,MAAM;AAAA,MAClD;AAEA,UAAK,MAAM,WAAW,OAAO,QAAS;AAErC,wBAAgB,SAAS,MAAM,WAAW,MAAM;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,gBAAiB,UAAW;AAE5C,SAAQ,iBAAkB,EAAE;AAAA,IAC3B,CAAE,EAAE,MAAM,MAAO,MAAO,OAAQ;AAAA;AAAA,IAEhC,MAAM;AAAA,IAAC;AAAA,EACR;AACD;",
4
+ "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\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\twarn,\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-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\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 * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\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\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\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 ) ),\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\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, 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\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\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\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\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 } = privateState;\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// Creates 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// Doesn'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// Dismisses 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\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\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\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// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\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"],
5
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;AAUzC,SAAS,UAAW,YAA2C;AAC9D,MAAK,CAAE,8BAA+B;AACrC,mCAA+B;AAC/B,UAAM,UAAU,SAAS;AAAA,MACxB;AAAA,IACD,GAAG;AACH,QAAK,SAAU;AACd,UAAI;AACH,cAAM,SAAS,KAAK,MAAO,OAAQ;AACnC,YAAK,OAAO,QAAQ,MAAM,YAAY,UAAW;AAChD,0BAAgB,UAAU,OAAO,KAAK;AAAA,QACvC;AACA,YAAK,OAAO,QAAQ,MAAM,WAAW,UAAW;AAC/C,0BAAgB,SAAS,OAAO,KAAK;AAAA,QACtC;AAAA,MACD,QAAQ;AAAA,MAAC;AAAA,IACV,OAAO;AAKN,UAAK,MAAM,WAAW,OAAO,SAAU;AAEtC,wBAAgB,UAAU,MAAM,WAAW,MAAM;AAAA,MAClD;AAEA,UAAK,MAAM,WAAW,OAAO,QAAS;AAErC,wBAAgB,SAAS,MAAM,WAAW,MAAM;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,gBAAiB,UAAW;AAE5C,SAAQ,iBAAkB,EAAE;AAAA,IAC3B,CAAE,EAAE,MAAM,MAAO,MAAO,OAAQ;AAAA;AAAA,IAEhC,MAAM;AAAA,IAAC;AAAA,EACR;AACD;",
6
6
  "names": []
7
7
  }
@@ -51,11 +51,13 @@ export declare function updateStylesWithSCS(X: StyleElement[], Y: StyleElement[]
51
51
  * make them effectively disabled until they are applied with the
52
52
  * {@link applyStyles|`applyStyles`} function.
53
53
  *
54
+ * Note that this function alters the passed document, as it can transfer
55
+ * nodes from it to the global document.
56
+ *
54
57
  * @param doc Document instance.
55
- * @param url URL for the passed document.
56
58
  * @return A list of promises for each style element in the passed document.
57
59
  */
58
- export declare const preloadStyles: (doc: Document, url: string) => Promise<StyleElement>[];
60
+ export declare const preloadStyles: (doc: Document) => Promise<StyleElement>[];
59
61
  /**
60
62
  * Traverses all style elements in the DOM, enabling only those included
61
63
  * in the passed list and disabling the others.
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/assets/styles.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAa9D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,GAAK,SAAS,YAAY,KAAI,YAYxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAClC,CAAC,EAAE,YAAY,EAAE,EACjB,CAAC,EAAE,YAAY,EAAE,EACjB,MAAM,GAAE,OAA8B,SAqDtC;AAiFD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GACzB,KAAK,QAAQ,EACb,KAAK,MAAM,KACT,OAAO,CAAE,YAAY,CAAE,EAoBzB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAK,QAAQ,YAAY,EAAE,SAiBlD,CAAC"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/assets/styles.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAa9D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,GAAK,SAAS,YAAY,KAAI,YAYxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAClC,CAAC,EAAE,YAAY,EAAE,EACjB,CAAC,EAAE,YAAY,EAAE,EACjB,MAAM,GAAE,OAA8B,SAqDtC;AAuED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAK,KAAK,QAAQ,KAAI,OAAO,CAAE,YAAY,CAAE,EAYtE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAK,QAAQ,YAAY,EAAE,SAiBlD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings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,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAM,OAAO,CAAE,IAAI,CAAE;CA0KtE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/interactivity-router",
3
- "version": "2.39.1-next.v.202602091733.0+daa0b19c4",
3
+ "version": "2.40.0",
4
4
  "description": "Package that exposes state and actions from the `core/router` store, part of the Interactivity API.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -46,12 +46,12 @@
46
46
  },
47
47
  "types": "build-types",
48
48
  "dependencies": {
49
- "@wordpress/a11y": "^4.39.1-next.v.202602091733.0+daa0b19c4",
50
- "@wordpress/interactivity": "^6.39.1-next.v.202602091733.0+daa0b19c4",
49
+ "@wordpress/a11y": "^4.40.0",
50
+ "@wordpress/interactivity": "^6.40.0",
51
51
  "es-module-lexer": "^1.5.4"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "74f59922b25e30904319373dda91bf8e81f3544e"
56
+ "gitHead": "376124aa10dbc2cc0c81c964ec00b99fcfee5382"
57
57
  }
@@ -195,16 +195,6 @@ const prepareStylePromise = (
195
195
  return promise;
196
196
  };
197
197
 
198
- /**
199
- * Cache of style promise lists per URL.
200
- *
201
- * It contains the list of style elements associated to the page with the
202
- * passed URL. The original order is preserved to respect the CSS cascade.
203
- *
204
- * Each included promise resolves when the associated style element is ready.
205
- */
206
- const styleSheetCache = new Map< string, Promise< StyleElement >[] >();
207
-
208
198
  /**
209
199
  * Prepares all style elements contained in the passed document.
210
200
  *
@@ -217,33 +207,24 @@ const styleSheetCache = new Map< string, Promise< StyleElement >[] >();
217
207
  * make them effectively disabled until they are applied with the
218
208
  * {@link applyStyles|`applyStyles`} function.
219
209
  *
210
+ * Note that this function alters the passed document, as it can transfer
211
+ * nodes from it to the global document.
212
+ *
220
213
  * @param doc Document instance.
221
- * @param url URL for the passed document.
222
214
  * @return A list of promises for each style element in the passed document.
223
215
  */
224
- export const preloadStyles = (
225
- doc: Document,
226
- url: string
227
- ): Promise< StyleElement >[] => {
228
- if ( ! styleSheetCache.has( url ) ) {
229
- const currentStyleElements = Array.from(
230
- window.document.querySelectorAll< StyleElement >(
231
- 'style,link[rel=stylesheet]'
232
- )
233
- );
234
- const newStyleElements = Array.from(
235
- doc.querySelectorAll< StyleElement >( 'style,link[rel=stylesheet]' )
236
- );
237
-
238
- // Set styles in order.
239
- const stylePromises = updateStylesWithSCS(
240
- currentStyleElements,
241
- newStyleElements
242
- );
216
+ export const preloadStyles = ( doc: Document ): Promise< StyleElement >[] => {
217
+ const currentStyleElements = Array.from(
218
+ window.document.querySelectorAll< StyleElement >(
219
+ 'style,link[rel=stylesheet]'
220
+ )
221
+ );
222
+ const newStyleElements = Array.from(
223
+ doc.querySelectorAll< StyleElement >( 'style,link[rel=stylesheet]' )
224
+ );
243
225
 
244
- styleSheetCache.set( url, stylePromises );
245
- }
246
- return styleSheetCache.get( url );
226
+ // Set styles in order.
227
+ return updateStylesWithSCS( currentStyleElements, newStyleElements );
247
228
  };
248
229
 
249
230
  /**
@@ -78,7 +78,7 @@ describe( 'Router styles management', () => {
78
78
 
79
79
  describe( 'updateStylesWithSCS', () => {
80
80
  it( 'should append all elements when X is empty in the correct order', () => {
81
- const X = [];
81
+ const X: HTMLStyleElement[] = [];
82
82
  const Y = [
83
83
  createStyleElement( 'style1' ),
84
84
  createLinkElement( 'link1' ),
@@ -514,25 +514,22 @@ describe( 'Router styles management', () => {
514
514
 
515
515
  // Tests for preloadStyles function.
516
516
  describe( 'preloadStyles', () => {
517
- it( 'should use cached promises for the same URL', () => {
517
+ it( 'should return cached promises for the same HTML', () => {
518
518
  // Create a test document.
519
519
  const doc = document.implementation.createHTMLDocument();
520
520
  const style = doc.createElement( 'style' );
521
521
  doc.head.appendChild( style );
522
522
 
523
+ // NOTE: preloadStyles() modifies the passed document. That's why
524
+ // the document is cloned beforehand.
525
+
523
526
  // First call should update the DOM.
524
- const firstResult = preloadStyles(
525
- doc,
526
- 'https://example.com/test'
527
- );
527
+ const firstResult = preloadStyles( doc.cloneNode() as Document );
528
528
  expect( firstResult ).toBeTruthy();
529
529
 
530
530
  // Second call should return the same promises.
531
- const secondResult = preloadStyles(
532
- doc,
533
- 'https://example.com/test'
534
- );
535
- expect( secondResult ).toBe( firstResult );
531
+ const secondResult = preloadStyles( doc.cloneNode() as Document );
532
+ expect( secondResult ).toEqual( firstResult );
536
533
  } );
537
534
 
538
535
  it( 'should extract style elements from the provided document', () => {
@@ -546,7 +543,7 @@ describe( 'Router styles management', () => {
546
543
  doc.head.appendChild( style1 );
547
544
  doc.head.appendChild( style2 );
548
545
 
549
- preloadStyles( doc, 'https://example.com/another-test-page' );
546
+ preloadStyles( doc );
550
547
 
551
548
  // Check that styles were extracted and added to the document.
552
549
  const addedStyle1 = document.querySelector( '#test-style-1' );
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ const {
25
25
  routerRegions,
26
26
  h: createElement,
27
27
  navigationSignal,
28
+ warn,
28
29
  } = privateApis(
29
30
  'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'
30
31
  );
@@ -220,7 +221,7 @@ const preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {
220
221
 
221
222
  // Wait for styles and modules to be ready.
222
223
  const [ styles, scriptModules ] = await Promise.all( [
223
- Promise.all( preloadStyles( dom, url ) ),
224
+ Promise.all( preloadStyles( dom ) ),
224
225
  Promise.all( preloadScriptModules( dom ) ),
225
226
  ] );
226
227
 
@@ -394,12 +395,28 @@ interface Store {
394
395
  };
395
396
  }
396
397
 
398
+ const { state: privateState } = store(
399
+ 'core/router/private',
400
+ {
401
+ state: {
402
+ navigation: {
403
+ hasStarted: false,
404
+ hasFinished: false,
405
+ },
406
+ },
407
+ },
408
+ { lock: true }
409
+ );
410
+
397
411
  export const { state, actions } = store< Store >( 'core/router', {
398
412
  state: {
399
- url: window.location.href,
400
- navigation: {
401
- hasStarted: false,
402
- hasFinished: false,
413
+ get navigation() {
414
+ if ( globalThis.SCRIPT_DEBUG ) {
415
+ warn(
416
+ `The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`
417
+ );
418
+ }
419
+ return privateState.navigation;
403
420
  },
404
421
  },
405
422
  actions: {
@@ -428,7 +445,7 @@ export const { state, actions } = store< Store >( 'core/router', {
428
445
  }
429
446
 
430
447
  const pagePath = getPagePath( href );
431
- const { navigation } = state;
448
+ const { navigation } = privateState;
432
449
  const {
433
450
  loadingAnimation = true,
434
451
  screenReaderAnnouncement = true,
@@ -546,6 +563,9 @@ export const { state, actions } = store< Store >( 'core/router', {
546
563
  },
547
564
  } );
548
565
 
566
+ // Initialize the URL in the state if it hasn't been set yet in the server.
567
+ state.url = state.url || window.location.href;
568
+
549
569
  /**
550
570
  * Announces a message to screen readers.
551
571
  *