@wordpress/interactivity-router 2.32.0 → 2.32.1-next.ff1cebbba.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/assets/dynamic-importmap/fetch.js +32 -43
  3. package/build/assets/dynamic-importmap/fetch.js.map +7 -1
  4. package/build/assets/dynamic-importmap/index.js +43 -73
  5. package/build/assets/dynamic-importmap/index.js.map +7 -1
  6. package/build/assets/dynamic-importmap/loader.js +139 -172
  7. package/build/assets/dynamic-importmap/loader.js.map +7 -1
  8. package/build/assets/dynamic-importmap/resolver.js +99 -112
  9. package/build/assets/dynamic-importmap/resolver.js.map +7 -1
  10. package/build/assets/script-modules.js +46 -58
  11. package/build/assets/script-modules.js.map +7 -1
  12. package/build/assets/scs.js +30 -39
  13. package/build/assets/scs.js.map +7 -1
  14. package/build/assets/styles.js +81 -171
  15. package/build/assets/styles.js.map +7 -1
  16. package/build/full-page.js +43 -36
  17. package/build/full-page.js.map +7 -1
  18. package/build/index.js +139 -265
  19. package/build/index.js.map +7 -1
  20. package/build-module/assets/dynamic-importmap/fetch.js +11 -39
  21. package/build-module/assets/dynamic-importmap/fetch.js.map +7 -1
  22. package/build-module/assets/dynamic-importmap/index.js +18 -52
  23. package/build-module/assets/dynamic-importmap/index.js.map +7 -1
  24. package/build-module/assets/dynamic-importmap/loader.js +101 -165
  25. package/build-module/assets/dynamic-importmap/loader.js.map +7 -1
  26. package/build-module/assets/dynamic-importmap/resolver.js +78 -108
  27. package/build-module/assets/dynamic-importmap/resolver.js.map +7 -1
  28. package/build-module/assets/script-modules.js +25 -49
  29. package/build-module/assets/script-modules.js.map +7 -1
  30. package/build-module/assets/scs.js +9 -35
  31. package/build-module/assets/scs.js.map +7 -1
  32. package/build-module/assets/styles.js +58 -163
  33. package/build-module/assets/styles.js.map +7 -1
  34. package/build-module/full-page.js +21 -32
  35. package/build-module/full-page.js.map +7 -1
  36. package/build-module/index.js +108 -257
  37. package/build-module/index.js.map +7 -1
  38. package/build-types/index.d.ts.map +1 -1
  39. package/package.json +12 -4
  40. package/src/index.ts +2 -3
  41. package/tsconfig.main.tsbuildinfo +1 -1
package/build/index.js CHANGED
@@ -1,21 +1,40 @@
1
- /* wp:polyfill */
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var index_exports = {};
29
+ __export(index_exports, {
30
+ actions: () => actions,
31
+ state: () => state
6
32
  });
7
- exports.state = exports.actions = void 0;
8
- var _interactivity = require("@wordpress/interactivity");
9
- var _styles = require("./assets/styles");
10
- var _scriptModules = require("./assets/script-modules");
11
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
13
- * WordPress dependencies
14
- */ /**
15
- * Internal dependencies
16
- */
33
+ module.exports = __toCommonJS(index_exports);
34
+ var import_interactivity = require("@wordpress/interactivity");
35
+ var import_styles = require("./assets/styles");
36
+ var import_script_modules = require("./assets/script-modules");
17
37
  const {
18
- directivePrefix,
19
38
  getRegionRootFragment,
20
39
  initialVdom,
21
40
  toVdom,
@@ -25,93 +44,43 @@ const {
25
44
  batch,
26
45
  routerRegions,
27
46
  cloneElement
28
- } = (0, _interactivity.privateApis)('I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.');
29
- const regionAttr = `data-${directivePrefix}-router-region`;
30
- const interactiveAttr = `data-${directivePrefix}-interactive`;
47
+ } = (0, import_interactivity.privateApis)(
48
+ "I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."
49
+ );
50
+ const regionAttr = `data-wp-router-region`;
51
+ const interactiveAttr = `data-wp-interactive`;
31
52
  const regionsSelector = `[${interactiveAttr}][${regionAttr}], [${interactiveAttr}] [${interactiveAttr}][${regionAttr}]`;
32
- // The cache of visited and prefetched pages, stylesheets and scripts.
33
- const pages = new Map();
34
-
35
- // Helper to remove domain and hash from the URL. We are only interesting in
36
- // caching the path and the query.
37
- const getPagePath = url => {
53
+ const pages = /* @__PURE__ */ new Map();
54
+ const getPagePath = (url) => {
38
55
  const u = new URL(url, window.location.href);
39
56
  return u.pathname + u.search;
40
57
  };
41
-
42
- /**
43
- * Parses the given region's directive.
44
- *
45
- * @param region Region element.
46
- * @return Data contained in the region directive value.
47
- */
48
- const parseRegionAttribute = region => {
58
+ const parseRegionAttribute = (region) => {
49
59
  const value = region.getAttribute(regionAttr);
50
60
  try {
51
- const {
52
- id,
53
- attachTo
54
- } = JSON.parse(value);
55
- return {
56
- id,
57
- attachTo
58
- };
61
+ const { id, attachTo } = JSON.parse(value);
62
+ return { id, attachTo };
59
63
  } catch (e) {
60
- return {
61
- id: value
62
- };
64
+ return { id: value };
63
65
  }
64
66
  };
65
-
66
- /**
67
- * Clones the content of the router region vDOM passed as argument.
68
- *
69
- * The function creates a new VNode instance removing all priority levels up to
70
- * the one containing the router-region directive, which should have evaluated
71
- * in advance.
72
- *
73
- * @param vdom A router region's VNode.
74
- * @return The VNode for the passed router region's content.
75
- */
76
- const cloneRouterRegionContent = vdom => {
67
+ const cloneRouterRegionContent = (vdom) => {
77
68
  if (!vdom) {
78
69
  return vdom;
79
70
  }
80
71
  const allPriorityLevels = vdom.props.priorityLevels;
81
- const routerRegionLevel = allPriorityLevels.findIndex(level => level.includes('router-region'));
72
+ const routerRegionLevel = allPriorityLevels.findIndex(
73
+ (level) => level.includes("router-region")
74
+ );
82
75
  const priorityLevels = routerRegionLevel !== -1 ? allPriorityLevels.slice(routerRegionLevel + 1) : allPriorityLevels;
83
76
  return priorityLevels.length > 0 ? cloneElement(vdom, {
84
77
  ...vdom.props,
85
78
  priorityLevels
86
79
  }) : vdom.props.element;
87
80
  };
88
-
89
- /**
90
- * IDs of router regions with an `attachTo` property pointing to the same parent
91
- * element.
92
- */
93
- const regionsToAttachByParent = new WeakMap();
94
-
95
- /**
96
- * Map of root fragments by parent element, used to render router regions with
97
- * the `attachTo` property. Those elements with the same parent are rendered
98
- * together in the corresponding root fragment.
99
- */
100
- const rootFragmentsByParent = new WeakMap();
101
-
102
- /**
103
- * Fetches and prepares a page from a given URL.
104
- *
105
- * @param url The URL of the page to fetch.
106
- * @param options Options for the fetch operation.
107
- * @param options.html Optional HTML content. If provided, the function will use
108
- * this instead of fetching from the URL.
109
- * @return A Promise that resolves to the prepared page, or false if
110
- * there was an error during fetching or preparation.
111
- */
112
- const fetchPage = async (url, {
113
- html
114
- }) => {
81
+ const regionsToAttachByParent = /* @__PURE__ */ new WeakMap();
82
+ const rootFragmentsByParent = /* @__PURE__ */ new WeakMap();
83
+ const fetchPage = async (url, { html }) => {
115
84
  try {
116
85
  if (!html) {
117
86
  const res = await window.fetch(url);
@@ -120,48 +89,20 @@ const fetchPage = async (url, {
120
89
  }
121
90
  html = await res.text();
122
91
  }
123
- const dom = new window.DOMParser().parseFromString(html, 'text/html');
92
+ const dom = new window.DOMParser().parseFromString(html, "text/html");
124
93
  return await preparePage(url, dom);
125
94
  } catch (e) {
126
95
  return false;
127
96
  }
128
97
  };
129
-
130
- /**
131
- * Processes a DOM document to extract router regions and related resources.
132
- *
133
- * This function analyzes the provided DOM document and creates a virtual DOM
134
- * representation of all HTML regions marked with a `router-region` directive.
135
- * It also extracts and preloads associated styles and scripts to prepare for
136
- * rendering the page.
137
- *
138
- * @param url The URL associated with the page, used for asset
139
- * loading and caching.
140
- * @param dom The DOM document to process.
141
- * @param vdomParams Optional parameters for virtual DOM processing.
142
- * @param vdomParams.vdom An optional existing virtual DOM cache to check for
143
- * regions. If a region exists in this cache, it will be
144
- * reused instead of creating a new vDOM representation.
145
- * @return A Promise that resolves to a {@link Page} object
146
- * containing the virtual DOM for all router regions,
147
- * preloaded styles and scripts, page title, and initial
148
- * server-rendered data.
149
- */
150
- const preparePage = async (url, dom, {
151
- vdom
152
- } = {}) => {
153
- // Remove all noscript elements as they're irrelevant when request is served via router.
154
- // This prevents browsers from extracting styles from noscript tags.
155
- dom.querySelectorAll('noscript').forEach(el => el.remove());
98
+ const preparePage = async (url, dom, { vdom } = {}) => {
99
+ dom.querySelectorAll("noscript").forEach((el) => el.remove());
156
100
  const regions = {};
157
101
  const regionsToAttach = {};
158
- dom.querySelectorAll(regionsSelector).forEach(region => {
159
- const {
160
- id,
161
- attachTo
162
- } = parseRegionAttribute(region);
102
+ dom.querySelectorAll(regionsSelector).forEach((region) => {
103
+ const { id, attachTo } = parseRegionAttribute(region);
163
104
  if (region.parentElement.closest(`[${regionAttr}]`)) {
164
- regions[id] = undefined;
105
+ regions[id] = void 0;
165
106
  } else {
166
107
  regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
167
108
  }
@@ -169,11 +110,12 @@ const preparePage = async (url, dom, {
169
110
  regionsToAttach[id] = attachTo;
170
111
  }
171
112
  });
172
- const title = dom.querySelector('title')?.innerText;
113
+ const title = dom.querySelector("title")?.innerText;
173
114
  const initialData = parseServerData(dom);
174
-
175
- // Wait for styles and modules to be ready.
176
- const [styles, scriptModules] = await Promise.all([Promise.all((0, _styles.preloadStyles)(dom, url)), Promise.all((0, _scriptModules.preloadScriptModules)(dom))]);
115
+ const [styles, scriptModules] = await Promise.all([
116
+ Promise.all((0, import_styles.preloadStyles)(dom, url)),
117
+ Promise.all((0, import_script_modules.preloadScriptModules)(dom))
118
+ ]);
177
119
  return {
178
120
  regions,
179
121
  regionsToAttach,
@@ -184,31 +126,15 @@ const preparePage = async (url, dom, {
184
126
  url
185
127
  };
186
128
  };
187
-
188
- /**
189
- * Renders a page by applying styles, populating server data, rendering regions,
190
- * and updating the document title.
191
- *
192
- * @param page The {@link Page} object to render.
193
- */
194
- const renderPage = page => {
195
- (0, _styles.applyStyles)(page.styles);
196
-
197
- // Clone regionsToAttach.
198
- const regionsToAttach = {
199
- ...page.regionsToAttach
200
- };
129
+ const renderPage = (page) => {
130
+ (0, import_styles.applyStyles)(page.styles);
131
+ const regionsToAttach = { ...page.regionsToAttach };
201
132
  batch(() => {
202
- // Update server data.
203
133
  populateServerData(page.initialData);
204
-
205
- // Reset all router regions before setting the actual values.
206
- routerRegions.forEach(signal => {
134
+ routerRegions.forEach((signal) => {
207
135
  signal.value = null;
208
136
  });
209
-
210
- //Init regions with attachTo that don't exist yet.
211
- const parentsToUpdate = new Set();
137
+ const parentsToUpdate = /* @__PURE__ */ new Set();
212
138
  for (const id in regionsToAttach) {
213
139
  const parent = document.querySelector(regionsToAttach[id]);
214
140
  if (!regionsToAttachByParent.has(parent)) {
@@ -220,32 +146,27 @@ const renderPage = page => {
220
146
  parentsToUpdate.add(parent);
221
147
  }
222
148
  }
223
-
224
- //Update all existing regions.
225
149
  for (const id in page.regions) {
226
150
  if (routerRegions.has(id)) {
227
- routerRegions.get(id).value = cloneRouterRegionContent(page.regions[id]);
151
+ routerRegions.get(id).value = cloneRouterRegionContent(
152
+ page.regions[id]
153
+ );
228
154
  }
229
155
  }
230
-
231
- // Render regions attached to the same parent in the same fragment.
232
- parentsToUpdate.forEach(parent => {
156
+ parentsToUpdate.forEach((parent) => {
233
157
  const ids = regionsToAttachByParent.get(parent);
234
- const vdoms = ids.map(id => page.regions[id]);
158
+ const vdoms = ids.map((id) => page.regions[id]);
235
159
  if (!rootFragmentsByParent.has(parent)) {
236
- const regions = vdoms.map(({
237
- props,
238
- type
239
- }) => {
240
- const elementType = typeof type === 'function' ? props.type : type;
241
-
242
- // Create an element with the obtained type where the region will be
243
- // rendered. The type should match the one of the root vnode.
160
+ const regions = vdoms.map(({ props, type }) => {
161
+ const elementType = typeof type === "function" ? props.type : type;
244
162
  const region = document.createElement(elementType);
245
163
  parent.appendChild(region);
246
164
  return region;
247
165
  });
248
- rootFragmentsByParent.set(parent, getRegionRootFragment(regions));
166
+ rootFragmentsByParent.set(
167
+ parent,
168
+ getRegionRootFragment(regions)
169
+ );
249
170
  }
250
171
  const fragment = rootFragmentsByParent.get(parent);
251
172
  render(vdoms, fragment);
@@ -255,55 +176,37 @@ const renderPage = page => {
255
176
  document.title = page.title;
256
177
  }
257
178
  };
258
-
259
- /**
260
- * Loads the given page forcing a full page reload.
261
- *
262
- * The function returns a promise that won't resolve, useful to prevent any
263
- * potential feedback indicating that the navigation has finished while the new
264
- * page is being loaded.
265
- *
266
- * @param href The page href.
267
- * @return Promise that never resolves.
268
- */
269
- const forcePageReload = href => {
179
+ const forcePageReload = (href) => {
270
180
  window.location.assign(href);
271
- return new Promise(() => {});
181
+ return new Promise(() => {
182
+ });
272
183
  };
273
-
274
- // Listen to the back and forward buttons and restore the page if it's in the
275
- // cache.
276
- window.addEventListener('popstate', async () => {
277
- const pagePath = getPagePath(window.location.href); // Remove hash.
278
- const page = pages.has(pagePath) && (await pages.get(pagePath));
184
+ window.addEventListener("popstate", async () => {
185
+ const pagePath = getPagePath(window.location.href);
186
+ const page = pages.has(pagePath) && await pages.get(pagePath);
279
187
  if (page) {
280
188
  renderPage(page);
281
- // Update the URL in the state.
282
189
  state.url = window.location.href;
283
190
  } else {
284
191
  window.location.reload();
285
192
  }
286
193
  });
287
-
288
- // Initialize the router and cache the initial page using the initial vDOM.
289
- window.document.querySelectorAll('script[type=module][src]').forEach(({
290
- src
291
- }) => (0, _scriptModules.markScriptModuleAsResolved)(src));
292
- pages.set(getPagePath(window.location.href), Promise.resolve(preparePage(getPagePath(window.location.href), document, {
293
- vdom: initialVdom
294
- })));
295
-
296
- // Variable to store the current navigation.
297
- let navigatingTo = '';
194
+ window.document.querySelectorAll("script[type=module][src]").forEach(({ src }) => (0, import_script_modules.markScriptModuleAsResolved)(src));
195
+ pages.set(
196
+ getPagePath(window.location.href),
197
+ Promise.resolve(
198
+ preparePage(getPagePath(window.location.href), document, {
199
+ vdom: initialVdom
200
+ })
201
+ )
202
+ );
203
+ let navigatingTo = "";
298
204
  let hasLoadedNavigationTextsData = false;
299
205
  const navigationTexts = {
300
- loading: 'Loading page, please wait.',
301
- loaded: 'Page Loaded.'
206
+ loading: "Loading page, please wait.",
207
+ loaded: "Page Loaded."
302
208
  };
303
- const {
304
- state,
305
- actions
306
- } = (0, _interactivity.store)('core/router', {
209
+ const { state, actions } = (0, import_interactivity.store)("core/router", {
307
210
  state: {
308
211
  url: window.location.href,
309
212
  navigation: {
@@ -331,29 +234,22 @@ const {
331
234
  * @return Promise that resolves once the navigation is completed or aborted.
332
235
  */
333
236
  *navigate(href, options = {}) {
334
- const {
335
- clientNavigationDisabled
336
- } = (0, _interactivity.getConfig)();
237
+ const { clientNavigationDisabled } = (0, import_interactivity.getConfig)();
337
238
  if (clientNavigationDisabled) {
338
239
  yield forcePageReload(href);
339
240
  }
340
241
  const pagePath = getPagePath(href);
341
- const {
342
- navigation
343
- } = state;
242
+ const { navigation } = state;
344
243
  const {
345
244
  loadingAnimation = true,
346
245
  screenReaderAnnouncement = true,
347
- timeout = 10000
246
+ timeout = 1e4
348
247
  } = options;
349
248
  navigatingTo = href;
350
249
  actions.prefetch(pagePath, options);
351
-
352
- // Create a promise that resolves when the specified timeout ends.
353
- // The timeout value is 10 seconds by default.
354
- const timeoutPromise = new Promise(resolve => setTimeout(resolve, timeout));
355
-
356
- // Don't update the navigation status immediately, wait 400 ms.
250
+ const timeoutPromise = new Promise(
251
+ (resolve) => setTimeout(resolve, timeout)
252
+ );
357
253
  const loadingTimeout = setTimeout(() => {
358
254
  if (navigatingTo !== href) {
359
255
  return;
@@ -363,42 +259,30 @@ const {
363
259
  navigation.hasFinished = false;
364
260
  }
365
261
  if (screenReaderAnnouncement) {
366
- a11ySpeak('loading');
262
+ a11ySpeak("loading");
367
263
  }
368
264
  }, 400);
369
- const page = yield Promise.race([pages.get(pagePath), timeoutPromise]);
370
-
371
- // Dismiss loading message if it hasn't been added yet.
265
+ const page = yield Promise.race([
266
+ pages.get(pagePath),
267
+ timeoutPromise
268
+ ]);
372
269
  clearTimeout(loadingTimeout);
373
-
374
- // Once the page is fetched, the destination URL could have changed
375
- // (e.g., by clicking another link in the meantime). If so, bail
376
- // out, and let the newer execution to update the HTML.
377
270
  if (navigatingTo !== href) {
378
271
  return;
379
272
  }
380
- if (page && !page.initialData?.config?.['core/router']?.clientNavigationDisabled) {
381
- yield (0, _scriptModules.importScriptModules)(page.scriptModules);
273
+ if (page && !page.initialData?.config?.["core/router"]?.clientNavigationDisabled) {
274
+ yield (0, import_script_modules.importScriptModules)(page.scriptModules);
382
275
  renderPage(page);
383
- window.history[options.replace ? 'replaceState' : 'pushState']({}, '', href);
384
-
385
- // Update the URL in the state.
276
+ window.history[options.replace ? "replaceState" : "pushState"]({}, "", href);
386
277
  state.url = href;
387
-
388
- // Update the navigation status once the the new page rendering
389
- // has been completed.
390
278
  if (loadingAnimation) {
391
279
  navigation.hasStarted = false;
392
280
  navigation.hasFinished = true;
393
281
  }
394
282
  if (screenReaderAnnouncement) {
395
- a11ySpeak('loaded');
283
+ a11ySpeak("loaded");
396
284
  }
397
-
398
- // Scroll to the anchor if exits in the link.
399
- const {
400
- hash
401
- } = new URL(href, window.location.href);
285
+ const { hash } = new URL(href, window.location.href);
402
286
  if (hash) {
403
287
  document.querySelector(hash)?.scrollIntoView();
404
288
  }
@@ -420,68 +304,58 @@ const {
420
304
  * @return Promise that resolves once the page has been fetched.
421
305
  */
422
306
  *prefetch(url, options = {}) {
423
- const {
424
- clientNavigationDisabled
425
- } = (0, _interactivity.getConfig)();
307
+ const { clientNavigationDisabled } = (0, import_interactivity.getConfig)();
426
308
  if (clientNavigationDisabled) {
427
309
  return;
428
310
  }
429
311
  const pagePath = getPagePath(url);
430
312
  if (options.force || !pages.has(pagePath)) {
431
- pages.set(pagePath, fetchPage(pagePath, {
432
- html: options.html
433
- }));
313
+ pages.set(
314
+ pagePath,
315
+ fetchPage(pagePath, { html: options.html })
316
+ );
434
317
  }
435
318
  yield pages.get(pagePath);
436
319
  }
437
320
  }
438
321
  });
439
-
440
- /**
441
- * Announces a message to screen readers.
442
- *
443
- * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing
444
- * the package on demand and should be used instead of calling `a11y.speak` directly.
445
- *
446
- * @param messageKey The message to be announced by assistive technologies.
447
- */
448
- exports.actions = actions;
449
- exports.state = state;
450
322
  function a11ySpeak(messageKey) {
451
323
  if (!hasLoadedNavigationTextsData) {
452
324
  hasLoadedNavigationTextsData = true;
453
- const content = document.getElementById('wp-script-module-data-@wordpress/interactivity-router')?.textContent;
325
+ const content = document.getElementById(
326
+ "wp-script-module-data-@wordpress/interactivity-router"
327
+ )?.textContent;
454
328
  if (content) {
455
329
  try {
456
330
  const parsed = JSON.parse(content);
457
- if (typeof parsed?.i18n?.loading === 'string') {
331
+ if (typeof parsed?.i18n?.loading === "string") {
458
332
  navigationTexts.loading = parsed.i18n.loading;
459
333
  }
460
- if (typeof parsed?.i18n?.loaded === 'string') {
334
+ if (typeof parsed?.i18n?.loaded === "string") {
461
335
  navigationTexts.loaded = parsed.i18n.loaded;
462
336
  }
463
- } catch {}
337
+ } catch {
338
+ }
464
339
  } else {
465
- // Fallback to localized strings from Interactivity API state.
466
- // @todo This block is for Core < 6.7.0. Remove when support is dropped.
467
-
468
- // @ts-expect-error
469
340
  if (state.navigation.texts?.loading) {
470
- // @ts-expect-error
471
341
  navigationTexts.loading = state.navigation.texts.loading;
472
342
  }
473
- // @ts-expect-error
474
343
  if (state.navigation.texts?.loaded) {
475
- // @ts-expect-error
476
344
  navigationTexts.loaded = state.navigation.texts.loaded;
477
345
  }
478
346
  }
479
347
  }
480
348
  const message = navigationTexts[messageKey];
481
- Promise.resolve().then(() => _interopRequireWildcard(require('@wordpress/a11y'))).then(({
482
- speak
483
- }) => speak(message),
484
- // Ignore failures to load the a11y module.
485
- () => {});
349
+ import("@wordpress/a11y").then(
350
+ ({ speak }) => speak(message),
351
+ // Ignore failures to load the a11y module.
352
+ () => {
353
+ }
354
+ );
486
355
  }
487
- //# sourceMappingURL=index.js.map
356
+ // Annotate the CommonJS export names for ESM import in node:
357
+ 0 && (module.exports = {
358
+ actions,
359
+ state
360
+ });
361
+ //# sourceMappingURL=index.js.map