@wordpress/interactivity-router 2.32.0 → 2.32.1-next.b8c8708f3.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
@@ -1,29 +1,29 @@
1
- /* wp:polyfill */
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var resolver_exports = {};
19
+ __export(resolver_exports, {
20
+ addImportMap: () => addImportMap,
21
+ resolve: () => resolve
6
22
  });
7
- exports.addImportMap = addImportMap;
8
- exports.resolve = resolve;
9
- /**
10
- * This code is derived from the following projects:
11
- *
12
- * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
13
- * 2. es-module-shims (https://github.com/guybedford/es-module-shims)
14
- *
15
- * The original implementation was created by Guy Bedford in es-module-shims,
16
- * then adapted by Mark Keller in dynamic-importmap, and further modified
17
- * for use in this project.
18
- *
19
- * Both projects are licensed under the MIT license.
20
- *
21
- * MIT License: https://opensource.org/licenses/MIT
22
- */
23
-
23
+ module.exports = __toCommonJS(resolver_exports);
24
24
  const backslashRegEx = /\\/g;
25
25
  function isURL(url) {
26
- if (url.indexOf(':') === -1) {
26
+ if (url.indexOf(":") === -1) {
27
27
  return false;
28
28
  }
29
29
  try {
@@ -34,89 +34,73 @@ function isURL(url) {
34
34
  }
35
35
  }
36
36
  function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
37
- const hIdx = parentUrl.indexOf('#'),
38
- qIdx = parentUrl.indexOf('?');
37
+ const hIdx = parentUrl.indexOf("#"), qIdx = parentUrl.indexOf("?");
39
38
  if (hIdx + qIdx > -2) {
40
- parentUrl = parentUrl.slice(0,
41
- // eslint-disable-next-line no-nested-ternary
42
- hIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx);
43
- }
44
- if (relUrl.indexOf('\\') !== -1) {
45
- relUrl = relUrl.replace(backslashRegEx, '/');
39
+ parentUrl = parentUrl.slice(
40
+ 0,
41
+ // eslint-disable-next-line no-nested-ternary
42
+ hIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx
43
+ );
46
44
  }
47
- // protocol-relative
48
- if (relUrl[0] === '/' && relUrl[1] === '/') {
49
- return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
45
+ if (relUrl.indexOf("\\") !== -1) {
46
+ relUrl = relUrl.replace(backslashRegEx, "/");
50
47
  }
51
- // relative-url
52
- else if (relUrl[0] === '.' && (relUrl[1] === '/' || relUrl[1] === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) || relUrl.length === 1 && (relUrl += '/')) || relUrl[0] === '/') {
53
- const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
54
- // Disabled, but these cases will give inconsistent results for deep backtracking
55
- //if (parentUrl[parentProtocol.length] !== '/')
56
- // throw new Error('Cannot resolve');
57
- // read pathname from parent URL
58
- // pathname taken to be part after leading "/"
48
+ if (relUrl[0] === "/" && relUrl[1] === "/") {
49
+ return parentUrl.slice(0, parentUrl.indexOf(":") + 1) + relUrl;
50
+ } else if (relUrl[0] === "." && (relUrl[1] === "/" || relUrl[1] === "." && (relUrl[2] === "/" || relUrl.length === 2 && (relUrl += "/")) || relUrl.length === 1 && (relUrl += "/")) || relUrl[0] === "/") {
51
+ const parentProtocol = parentUrl.slice(
52
+ 0,
53
+ parentUrl.indexOf(":") + 1
54
+ );
59
55
  let pathname;
60
- if (parentUrl[parentProtocol.length + 1] === '/') {
61
- // resolving to a :// so we need to read out the auth and host
62
- if (parentProtocol !== 'file:') {
56
+ if (parentUrl[parentProtocol.length + 1] === "/") {
57
+ if (parentProtocol !== "file:") {
63
58
  pathname = parentUrl.slice(parentProtocol.length + 2);
64
- pathname = pathname.slice(pathname.indexOf('/') + 1);
59
+ pathname = pathname.slice(pathname.indexOf("/") + 1);
65
60
  } else {
66
61
  pathname = parentUrl.slice(8);
67
62
  }
68
63
  } else {
69
- // resolving to :/ so pathname is the /... part
70
- pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
64
+ pathname = parentUrl.slice(
65
+ parentProtocol.length + (parentUrl[parentProtocol.length] === "/")
66
+ );
71
67
  }
72
- if (relUrl[0] === '/') {
68
+ if (relUrl[0] === "/") {
73
69
  return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
74
70
  }
75
-
76
- // join together and split for removal of .. and . segments
77
- // looping the string instead of anything fancy for perf reasons
78
- // '../../../../../z' resolved to 'x/y' is just 'z'
79
- const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
71
+ const segmented = pathname.slice(0, pathname.lastIndexOf("/") + 1) + relUrl;
80
72
  const output = [];
81
73
  let segmentIndex = -1;
82
74
  for (let i = 0; i < segmented.length; i++) {
83
- // busy reading a segment - only terminate on '/'
84
75
  if (segmentIndex !== -1) {
85
- if (segmented[i] === '/') {
76
+ if (segmented[i] === "/") {
86
77
  output.push(segmented.slice(segmentIndex, i + 1));
87
78
  segmentIndex = -1;
88
79
  }
89
80
  continue;
90
- }
91
- // new segment - check if it is relative
92
- else if (segmented[i] === '.') {
93
- // ../ segment
94
- if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
81
+ } else if (segmented[i] === ".") {
82
+ if (segmented[i + 1] === "." && (segmented[i + 2] === "/" || i + 2 === segmented.length)) {
95
83
  output.pop();
96
84
  i += 2;
97
85
  continue;
98
- }
99
- // ./ segment
100
- else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
86
+ } else if (segmented[i + 1] === "/" || i + 1 === segmented.length) {
101
87
  i += 1;
102
88
  continue;
103
89
  }
104
90
  }
105
- // it is the start of a new segment
106
- while (segmented[i] === '/') {
91
+ while (segmented[i] === "/") {
107
92
  i++;
108
93
  }
109
94
  segmentIndex = i;
110
95
  }
111
- // finish reading out the last segment
112
96
  if (segmentIndex !== -1) {
113
97
  output.push(segmented.slice(segmentIndex));
114
98
  }
115
- return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
99
+ return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join("");
116
100
  }
117
101
  }
118
102
  function resolveUrl(relUrl, parentUrl) {
119
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (isURL(relUrl) ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
103
+ return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (isURL(relUrl) ? relUrl : resolveIfNotPlainOrUrl("./" + relUrl, parentUrl));
120
104
  }
121
105
  function getMatch(path, matchObj) {
122
106
  if (matchObj[path]) {
@@ -128,7 +112,7 @@ function getMatch(path, matchObj) {
128
112
  if (segment in matchObj) {
129
113
  return segment;
130
114
  }
131
- } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
115
+ } while ((sepIndex = path.lastIndexOf("/", sepIndex - 1)) !== -1);
132
116
  }
133
117
  function applyPackages(id, packages) {
134
118
  const pkgName = getMatch(id, packages);
@@ -140,81 +124,84 @@ function applyPackages(id, packages) {
140
124
  return pkg + id.slice(pkgName.length);
141
125
  }
142
126
  }
143
- function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
144
- let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
127
+ function resolveImportMap(importMap2, resolvedOrPlain, parentUrl) {
128
+ let scopeUrl = parentUrl && getMatch(parentUrl, importMap2.scopes);
145
129
  while (scopeUrl) {
146
- const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
130
+ const packageResolution = applyPackages(
131
+ resolvedOrPlain,
132
+ importMap2.scopes[scopeUrl]
133
+ );
147
134
  if (packageResolution) {
148
135
  return packageResolution;
149
136
  }
150
- scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
137
+ scopeUrl = getMatch(
138
+ scopeUrl.slice(0, scopeUrl.lastIndexOf("/")),
139
+ importMap2.scopes
140
+ );
151
141
  }
152
- return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
142
+ return applyPackages(resolvedOrPlain, importMap2.imports) || resolvedOrPlain.indexOf(":") !== -1 && resolvedOrPlain;
153
143
  }
154
- function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
144
+ function resolveAndComposePackages(packages, outPackages, baseUrl2, parentMap) {
155
145
  for (const p in packages) {
156
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
146
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl2) || p;
157
147
  const target = packages[p];
158
- if (typeof target !== 'string') {
148
+ if (typeof target !== "string") {
159
149
  continue;
160
150
  }
161
- const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
151
+ const mapped = resolveImportMap(
152
+ parentMap,
153
+ resolveIfNotPlainOrUrl(target, baseUrl2) || target,
154
+ baseUrl2
155
+ );
162
156
  if (mapped) {
163
157
  outPackages[resolvedLhs] = mapped;
164
158
  continue;
165
159
  }
166
- // console.warn(
167
- // `Mapping "${ p }" -> "${ packages[ p ] }" does not resolve`
168
- // );
169
160
  }
170
161
  }
171
- function resolveAndComposeImportMap(json, baseUrl, parentMap) {
162
+ function resolveAndComposeImportMap(json, baseUrl2, parentMap) {
172
163
  const outMap = {
173
164
  imports: Object.assign({}, parentMap.imports),
174
165
  scopes: Object.assign({}, parentMap.scopes)
175
166
  };
176
167
  if (json.imports) {
177
- resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
168
+ resolveAndComposePackages(
169
+ json.imports,
170
+ outMap.imports,
171
+ baseUrl2,
172
+ parentMap
173
+ );
178
174
  }
179
175
  if (json.scopes) {
180
176
  for (const s in json.scopes) {
181
- const resolvedScope = resolveUrl(s, baseUrl);
182
- resolveAndComposePackages(json.scopes[s], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, parentMap);
177
+ const resolvedScope = resolveUrl(s, baseUrl2);
178
+ resolveAndComposePackages(
179
+ json.scopes[s],
180
+ outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
181
+ baseUrl2,
182
+ parentMap
183
+ );
183
184
  }
184
185
  }
185
186
  return outMap;
186
187
  }
187
- let importMap = {
188
- imports: {},
189
- scopes: {}
190
- };
191
-
192
- // TODO: check if this baseURI should change per document, and so
193
- // it need to be passed as a parameter to methods like `resolve`.
188
+ let importMap = { imports: {}, scopes: {} };
194
189
  const baseUrl = document.baseURI;
195
190
  const pageBaseUrl = baseUrl;
196
-
197
- /**
198
- * Extends the internal dynamic import map with the passed one.
199
- *
200
- * @param importMapIn Import map.
201
- * @param importMapIn.imports Imports declaration.
202
- * @param importMapIn.scopes Scopes declaration.
203
- */
204
191
  function addImportMap(importMapIn) {
205
- importMap = resolveAndComposeImportMap(importMapIn, pageBaseUrl, importMap);
192
+ importMap = resolveAndComposeImportMap(
193
+ importMapIn,
194
+ pageBaseUrl,
195
+ importMap
196
+ );
206
197
  }
207
-
208
- /**
209
- * Resolves the URL of the passed module ID against the current internal
210
- * dynamic import map.
211
- *
212
- * @param id Module ID.
213
- * @param parentUrl Parent URL, in case the module ID is relative.
214
- * @return Resolved module URL.
215
- */
216
198
  function resolve(id, parentUrl) {
217
199
  const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl);
218
200
  return resolveImportMap(importMap, urlResolved || id, parentUrl) || id;
219
201
  }
220
- //# sourceMappingURL=resolver.js.map
202
+ // Annotate the CommonJS export names for ESM import in node:
203
+ 0 && (module.exports = {
204
+ addImportMap,
205
+ resolve
206
+ });
207
+ //# sourceMappingURL=resolver.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["backslashRegEx","isURL","url","indexOf","URL","_","resolveIfNotPlainOrUrl","relUrl","parentUrl","hIdx","qIdx","slice","replace","length","parentProtocol","pathname","segmented","lastIndexOf","output","segmentIndex","i","push","pop","join","resolveUrl","getMatch","path","matchObj","sepIndex","segment","applyPackages","id","packages","pkgName","pkg","resolveImportMap","importMap","resolvedOrPlain","scopeUrl","scopes","packageResolution","imports","resolveAndComposePackages","outPackages","baseUrl","parentMap","p","resolvedLhs","target","mapped","resolveAndComposeImportMap","json","outMap","Object","assign","s","resolvedScope","document","baseURI","pageBaseUrl","addImportMap","importMapIn","resolve","urlResolved"],"sources":["@wordpress/interactivity-router/src/assets/dynamic-importmap/resolver.ts"],"sourcesContent":["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch ( _ ) {\n\t\treturn false;\n\t}\n}\n\nfunction resolveIfNotPlainOrUrl( relUrl, parentUrl ) {\n\tconst hIdx = parentUrl.indexOf( '#' ),\n\t\tqIdx = parentUrl.indexOf( '?' );\n\tif ( hIdx + qIdx > -2 ) {\n\t\tparentUrl = parentUrl.slice(\n\t\t\t0,\n\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\thIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx\n\t\t);\n\t}\n\tif ( relUrl.indexOf( '\\\\' ) !== -1 ) {\n\t\trelUrl = relUrl.replace( backslashRegEx, '/' );\n\t}\n\t// protocol-relative\n\tif ( relUrl[ 0 ] === '/' && relUrl[ 1 ] === '/' ) {\n\t\treturn parentUrl.slice( 0, parentUrl.indexOf( ':' ) + 1 ) + relUrl;\n\t}\n\t// relative-url\n\telse if (\n\t\t( relUrl[ 0 ] === '.' &&\n\t\t\t( relUrl[ 1 ] === '/' ||\n\t\t\t\t( relUrl[ 1 ] === '.' &&\n\t\t\t\t\t( relUrl[ 2 ] === '/' ||\n\t\t\t\t\t\t( relUrl.length === 2 && ( relUrl += '/' ) ) ) ) ||\n\t\t\t\t( relUrl.length === 1 && ( relUrl += '/' ) ) ) ) ||\n\t\trelUrl[ 0 ] === '/'\n\t) {\n\t\tconst parentProtocol = parentUrl.slice(\n\t\t\t0,\n\t\t\tparentUrl.indexOf( ':' ) + 1\n\t\t);\n\t\t// Disabled, but these cases will give inconsistent results for deep backtracking\n\t\t//if (parentUrl[parentProtocol.length] !== '/')\n\t\t// throw new Error('Cannot resolve');\n\t\t// read pathname from parent URL\n\t\t// pathname taken to be part after leading \"/\"\n\t\tlet pathname;\n\t\tif ( parentUrl[ parentProtocol.length + 1 ] === '/' ) {\n\t\t\t// resolving to a :// so we need to read out the auth and host\n\t\t\tif ( parentProtocol !== 'file:' ) {\n\t\t\t\tpathname = parentUrl.slice( parentProtocol.length + 2 );\n\t\t\t\tpathname = pathname.slice( pathname.indexOf( '/' ) + 1 );\n\t\t\t} else {\n\t\t\t\tpathname = parentUrl.slice( 8 );\n\t\t\t}\n\t\t} else {\n\t\t\t// resolving to :/ so pathname is the /... part\n\t\t\tpathname = parentUrl.slice(\n\t\t\t\tparentProtocol.length +\n\t\t\t\t\t( parentUrl[ parentProtocol.length ] === '/' )\n\t\t\t);\n\t\t}\n\n\t\tif ( relUrl[ 0 ] === '/' ) {\n\t\t\treturn (\n\t\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length - 1 ) +\n\t\t\t\trelUrl\n\t\t\t);\n\t\t}\n\n\t\t// join together and split for removal of .. and . segments\n\t\t// looping the string instead of anything fancy for perf reasons\n\t\t// '../../../../../z' resolved to 'x/y' is just 'z'\n\t\tconst segmented =\n\t\t\tpathname.slice( 0, pathname.lastIndexOf( '/' ) + 1 ) + relUrl;\n\n\t\tconst output = [];\n\t\tlet segmentIndex = -1;\n\t\tfor ( let i = 0; i < segmented.length; i++ ) {\n\t\t\t// busy reading a segment - only terminate on '/'\n\t\t\tif ( segmentIndex !== -1 ) {\n\t\t\t\tif ( segmented[ i ] === '/' ) {\n\t\t\t\t\toutput.push( segmented.slice( segmentIndex, i + 1 ) );\n\t\t\t\t\tsegmentIndex = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// new segment - check if it is relative\n\t\t\telse if ( segmented[ i ] === '.' ) {\n\t\t\t\t// ../ segment\n\t\t\t\tif (\n\t\t\t\t\tsegmented[ i + 1 ] === '.' &&\n\t\t\t\t\t( segmented[ i + 2 ] === '/' || i + 2 === segmented.length )\n\t\t\t\t) {\n\t\t\t\t\toutput.pop();\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// ./ segment\n\t\t\t\telse if (\n\t\t\t\t\tsegmented[ i + 1 ] === '/' ||\n\t\t\t\t\ti + 1 === segmented.length\n\t\t\t\t) {\n\t\t\t\t\ti += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// it is the start of a new segment\n\t\t\twhile ( segmented[ i ] === '/' ) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tsegmentIndex = i;\n\t\t}\n\t\t// finish reading out the last segment\n\t\tif ( segmentIndex !== -1 ) {\n\t\t\toutput.push( segmented.slice( segmentIndex ) );\n\t\t}\n\t\treturn (\n\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length ) +\n\t\t\toutput.join( '' )\n\t\t);\n\t}\n}\n\nfunction resolveUrl( relUrl, parentUrl ) {\n\treturn (\n\t\tresolveIfNotPlainOrUrl( relUrl, parentUrl ) ||\n\t\t( isURL( relUrl )\n\t\t\t? relUrl\n\t\t\t: resolveIfNotPlainOrUrl( './' + relUrl, parentUrl ) )\n\t);\n}\n\nfunction getMatch( path, matchObj ) {\n\tif ( matchObj[ path ] ) {\n\t\treturn path;\n\t}\n\tlet sepIndex = path.length;\n\tdo {\n\t\tconst segment = path.slice( 0, sepIndex + 1 );\n\t\tif ( segment in matchObj ) {\n\t\t\treturn segment;\n\t\t}\n\t} while ( ( sepIndex = path.lastIndexOf( '/', sepIndex - 1 ) ) !== -1 );\n}\n\nfunction applyPackages( id, packages ) {\n\tconst pkgName = getMatch( id, packages );\n\tif ( pkgName ) {\n\t\tconst pkg = packages[ pkgName ];\n\t\tif ( pkg === null ) {\n\t\t\treturn;\n\t\t}\n\t\treturn pkg + id.slice( pkgName.length );\n\t}\n}\n\nfunction resolveImportMap( importMap, resolvedOrPlain, parentUrl ) {\n\tlet scopeUrl = parentUrl && getMatch( parentUrl, importMap.scopes );\n\twhile ( scopeUrl ) {\n\t\tconst packageResolution = applyPackages(\n\t\t\tresolvedOrPlain,\n\t\t\timportMap.scopes[ scopeUrl ]\n\t\t);\n\t\tif ( packageResolution ) {\n\t\t\treturn packageResolution;\n\t\t}\n\t\tscopeUrl = getMatch(\n\t\t\tscopeUrl.slice( 0, scopeUrl.lastIndexOf( '/' ) ),\n\t\t\timportMap.scopes\n\t\t);\n\t}\n\treturn (\n\t\tapplyPackages( resolvedOrPlain, importMap.imports ) ||\n\t\t( resolvedOrPlain.indexOf( ':' ) !== -1 && resolvedOrPlain )\n\t);\n}\n\nfunction resolveAndComposePackages(\n\tpackages,\n\toutPackages,\n\tbaseUrl,\n\tparentMap\n) {\n\tfor ( const p in packages ) {\n\t\tconst resolvedLhs = resolveIfNotPlainOrUrl( p, baseUrl ) || p;\n\t\tconst target = packages[ p ];\n\t\tif ( typeof target !== 'string' ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst mapped = resolveImportMap(\n\t\t\tparentMap,\n\t\t\tresolveIfNotPlainOrUrl( target, baseUrl ) || target,\n\t\t\tbaseUrl\n\t\t);\n\t\tif ( mapped ) {\n\t\t\toutPackages[ resolvedLhs ] = mapped;\n\t\t\tcontinue;\n\t\t}\n\t\t// console.warn(\n\t\t// \t`Mapping \"${ p }\" -> \"${ packages[ p ] }\" does not resolve`\n\t\t// );\n\t}\n}\n\nfunction resolveAndComposeImportMap( json, baseUrl, parentMap ) {\n\tconst outMap = {\n\t\timports: Object.assign( {}, parentMap.imports ),\n\t\tscopes: Object.assign( {}, parentMap.scopes ),\n\t};\n\n\tif ( json.imports ) {\n\t\tresolveAndComposePackages(\n\t\t\tjson.imports,\n\t\t\toutMap.imports,\n\t\t\tbaseUrl,\n\t\t\tparentMap\n\t\t);\n\t}\n\n\tif ( json.scopes ) {\n\t\tfor ( const s in json.scopes ) {\n\t\t\tconst resolvedScope = resolveUrl( s, baseUrl );\n\t\t\tresolveAndComposePackages(\n\t\t\t\tjson.scopes[ s ],\n\t\t\t\toutMap.scopes[ resolvedScope ] ||\n\t\t\t\t\t( outMap.scopes[ resolvedScope ] = {} ),\n\t\t\t\tbaseUrl,\n\t\t\t\tparentMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn outMap;\n}\n\nlet importMap = { imports: {}, scopes: {} };\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `resolve`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\n/**\n * Extends the internal dynamic import map with the passed one.\n *\n * @param importMapIn Import map.\n * @param importMapIn.imports Imports declaration.\n * @param importMapIn.scopes Scopes declaration.\n */\nexport function addImportMap( importMapIn: {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, any >;\n} ) {\n\timportMap = resolveAndComposeImportMap(\n\t\timportMapIn,\n\t\tpageBaseUrl,\n\t\timportMap\n\t);\n}\n\n/**\n * Resolves the URL of the passed module ID against the current internal\n * dynamic import map.\n *\n * @param id Module ID.\n * @param parentUrl Parent URL, in case the module ID is relative.\n * @return Resolved module URL.\n */\nexport function resolve( id: string, parentUrl: string ): string {\n\tconst urlResolved = resolveIfNotPlainOrUrl( id, parentUrl );\n\treturn resolveImportMap( importMap, urlResolved || id, parentUrl ) || id;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,cAAc,GAAG,KAAK;AAE5B,SAASC,KAAKA,CAAEC,GAAW,EAAG;EAC7B,IAAKA,GAAG,CAACC,OAAO,CAAE,GAAI,CAAC,KAAK,CAAC,CAAC,EAAG;IAChC,OAAO,KAAK;EACb;EACA,IAAI;IACH,IAAIC,GAAG,CAAEF,GAAI,CAAC;IACd,OAAO,IAAI;EACZ,CAAC,CAAC,OAAQG,CAAC,EAAG;IACb,OAAO,KAAK;EACb;AACD;AAEA,SAASC,sBAAsBA,CAAEC,MAAM,EAAEC,SAAS,EAAG;EACpD,MAAMC,IAAI,GAAGD,SAAS,CAACL,OAAO,CAAE,GAAI,CAAC;IACpCO,IAAI,GAAGF,SAAS,CAACL,OAAO,CAAE,GAAI,CAAC;EAChC,IAAKM,IAAI,GAAGC,IAAI,GAAG,CAAC,CAAC,EAAG;IACvBF,SAAS,GAAGA,SAAS,CAACG,KAAK,CAC1B,CAAC;IACD;IACAF,IAAI,KAAK,CAAC,CAAC,GAAGC,IAAI,GAAGA,IAAI,KAAK,CAAC,CAAC,IAAIA,IAAI,GAAGD,IAAI,GAAGA,IAAI,GAAGC,IAC1D,CAA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AAC;IACF;EACD;EAEA,OAAOO,MAAM;AACd;AAEA,IAAIhB,SAAS,GAAG;EAAEK,OAAO,EAAE,CAAC,CAAC;EAAEF,MAAM,EAAE,CAAC;AAAE,CAAC;;AAE3C;AACA;AACA,MAAMK,OAAO,GAAGa,QAAQ,CAACC,OAAO;AAChC,MAAMC,WAAW,GAAGf,OAAO;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASgB,YAAYA,CAAEC,WAG7B,EAAG;EACHzB,SAAS,GAAGc,0BAA0B,CACrCW,WAAW,EACXF,WAAW,EACXvB,SACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS0B,OAAOA,CAAE/B,EAAU,EAAEvB,SAAiB,EAAW;EAChE,MAAMuD,WAAW,GAAGzD,sBAAsB,CAAEyB,EAAE,EAAEvB,SAAU,CAAC;EAC3D,OAAO2B,gBAAgB,CAAEC,SAAS,EAAE2B,WAAW,IAAIhC,EAAE,EAAEvB,SAAU,CAAC,IAAIuB,EAAE;AACzE","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/assets/dynamic-importmap/resolver.ts"],
4
+ "sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch ( _ ) {\n\t\treturn false;\n\t}\n}\n\nfunction resolveIfNotPlainOrUrl( relUrl, parentUrl ) {\n\tconst hIdx = parentUrl.indexOf( '#' ),\n\t\tqIdx = parentUrl.indexOf( '?' );\n\tif ( hIdx + qIdx > -2 ) {\n\t\tparentUrl = parentUrl.slice(\n\t\t\t0,\n\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\thIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx\n\t\t);\n\t}\n\tif ( relUrl.indexOf( '\\\\' ) !== -1 ) {\n\t\trelUrl = relUrl.replace( backslashRegEx, '/' );\n\t}\n\t// protocol-relative\n\tif ( relUrl[ 0 ] === '/' && relUrl[ 1 ] === '/' ) {\n\t\treturn parentUrl.slice( 0, parentUrl.indexOf( ':' ) + 1 ) + relUrl;\n\t}\n\t// relative-url\n\telse if (\n\t\t( relUrl[ 0 ] === '.' &&\n\t\t\t( relUrl[ 1 ] === '/' ||\n\t\t\t\t( relUrl[ 1 ] === '.' &&\n\t\t\t\t\t( relUrl[ 2 ] === '/' ||\n\t\t\t\t\t\t( relUrl.length === 2 && ( relUrl += '/' ) ) ) ) ||\n\t\t\t\t( relUrl.length === 1 && ( relUrl += '/' ) ) ) ) ||\n\t\trelUrl[ 0 ] === '/'\n\t) {\n\t\tconst parentProtocol = parentUrl.slice(\n\t\t\t0,\n\t\t\tparentUrl.indexOf( ':' ) + 1\n\t\t);\n\t\t// Disabled, but these cases will give inconsistent results for deep backtracking\n\t\t//if (parentUrl[parentProtocol.length] !== '/')\n\t\t// throw new Error('Cannot resolve');\n\t\t// read pathname from parent URL\n\t\t// pathname taken to be part after leading \"/\"\n\t\tlet pathname;\n\t\tif ( parentUrl[ parentProtocol.length + 1 ] === '/' ) {\n\t\t\t// resolving to a :// so we need to read out the auth and host\n\t\t\tif ( parentProtocol !== 'file:' ) {\n\t\t\t\tpathname = parentUrl.slice( parentProtocol.length + 2 );\n\t\t\t\tpathname = pathname.slice( pathname.indexOf( '/' ) + 1 );\n\t\t\t} else {\n\t\t\t\tpathname = parentUrl.slice( 8 );\n\t\t\t}\n\t\t} else {\n\t\t\t// resolving to :/ so pathname is the /... part\n\t\t\tpathname = parentUrl.slice(\n\t\t\t\tparentProtocol.length +\n\t\t\t\t\t( parentUrl[ parentProtocol.length ] === '/' )\n\t\t\t);\n\t\t}\n\n\t\tif ( relUrl[ 0 ] === '/' ) {\n\t\t\treturn (\n\t\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length - 1 ) +\n\t\t\t\trelUrl\n\t\t\t);\n\t\t}\n\n\t\t// join together and split for removal of .. and . segments\n\t\t// looping the string instead of anything fancy for perf reasons\n\t\t// '../../../../../z' resolved to 'x/y' is just 'z'\n\t\tconst segmented =\n\t\t\tpathname.slice( 0, pathname.lastIndexOf( '/' ) + 1 ) + relUrl;\n\n\t\tconst output = [];\n\t\tlet segmentIndex = -1;\n\t\tfor ( let i = 0; i < segmented.length; i++ ) {\n\t\t\t// busy reading a segment - only terminate on '/'\n\t\t\tif ( segmentIndex !== -1 ) {\n\t\t\t\tif ( segmented[ i ] === '/' ) {\n\t\t\t\t\toutput.push( segmented.slice( segmentIndex, i + 1 ) );\n\t\t\t\t\tsegmentIndex = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// new segment - check if it is relative\n\t\t\telse if ( segmented[ i ] === '.' ) {\n\t\t\t\t// ../ segment\n\t\t\t\tif (\n\t\t\t\t\tsegmented[ i + 1 ] === '.' &&\n\t\t\t\t\t( segmented[ i + 2 ] === '/' || i + 2 === segmented.length )\n\t\t\t\t) {\n\t\t\t\t\toutput.pop();\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// ./ segment\n\t\t\t\telse if (\n\t\t\t\t\tsegmented[ i + 1 ] === '/' ||\n\t\t\t\t\ti + 1 === segmented.length\n\t\t\t\t) {\n\t\t\t\t\ti += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// it is the start of a new segment\n\t\t\twhile ( segmented[ i ] === '/' ) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tsegmentIndex = i;\n\t\t}\n\t\t// finish reading out the last segment\n\t\tif ( segmentIndex !== -1 ) {\n\t\t\toutput.push( segmented.slice( segmentIndex ) );\n\t\t}\n\t\treturn (\n\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length ) +\n\t\t\toutput.join( '' )\n\t\t);\n\t}\n}\n\nfunction resolveUrl( relUrl, parentUrl ) {\n\treturn (\n\t\tresolveIfNotPlainOrUrl( relUrl, parentUrl ) ||\n\t\t( isURL( relUrl )\n\t\t\t? relUrl\n\t\t\t: resolveIfNotPlainOrUrl( './' + relUrl, parentUrl ) )\n\t);\n}\n\nfunction getMatch( path, matchObj ) {\n\tif ( matchObj[ path ] ) {\n\t\treturn path;\n\t}\n\tlet sepIndex = path.length;\n\tdo {\n\t\tconst segment = path.slice( 0, sepIndex + 1 );\n\t\tif ( segment in matchObj ) {\n\t\t\treturn segment;\n\t\t}\n\t} while ( ( sepIndex = path.lastIndexOf( '/', sepIndex - 1 ) ) !== -1 );\n}\n\nfunction applyPackages( id, packages ) {\n\tconst pkgName = getMatch( id, packages );\n\tif ( pkgName ) {\n\t\tconst pkg = packages[ pkgName ];\n\t\tif ( pkg === null ) {\n\t\t\treturn;\n\t\t}\n\t\treturn pkg + id.slice( pkgName.length );\n\t}\n}\n\nfunction resolveImportMap( importMap, resolvedOrPlain, parentUrl ) {\n\tlet scopeUrl = parentUrl && getMatch( parentUrl, importMap.scopes );\n\twhile ( scopeUrl ) {\n\t\tconst packageResolution = applyPackages(\n\t\t\tresolvedOrPlain,\n\t\t\timportMap.scopes[ scopeUrl ]\n\t\t);\n\t\tif ( packageResolution ) {\n\t\t\treturn packageResolution;\n\t\t}\n\t\tscopeUrl = getMatch(\n\t\t\tscopeUrl.slice( 0, scopeUrl.lastIndexOf( '/' ) ),\n\t\t\timportMap.scopes\n\t\t);\n\t}\n\treturn (\n\t\tapplyPackages( resolvedOrPlain, importMap.imports ) ||\n\t\t( resolvedOrPlain.indexOf( ':' ) !== -1 && resolvedOrPlain )\n\t);\n}\n\nfunction resolveAndComposePackages(\n\tpackages,\n\toutPackages,\n\tbaseUrl,\n\tparentMap\n) {\n\tfor ( const p in packages ) {\n\t\tconst resolvedLhs = resolveIfNotPlainOrUrl( p, baseUrl ) || p;\n\t\tconst target = packages[ p ];\n\t\tif ( typeof target !== 'string' ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst mapped = resolveImportMap(\n\t\t\tparentMap,\n\t\t\tresolveIfNotPlainOrUrl( target, baseUrl ) || target,\n\t\t\tbaseUrl\n\t\t);\n\t\tif ( mapped ) {\n\t\t\toutPackages[ resolvedLhs ] = mapped;\n\t\t\tcontinue;\n\t\t}\n\t\t// console.warn(\n\t\t// \t`Mapping \"${ p }\" -> \"${ packages[ p ] }\" does not resolve`\n\t\t// );\n\t}\n}\n\nfunction resolveAndComposeImportMap( json, baseUrl, parentMap ) {\n\tconst outMap = {\n\t\timports: Object.assign( {}, parentMap.imports ),\n\t\tscopes: Object.assign( {}, parentMap.scopes ),\n\t};\n\n\tif ( json.imports ) {\n\t\tresolveAndComposePackages(\n\t\t\tjson.imports,\n\t\t\toutMap.imports,\n\t\t\tbaseUrl,\n\t\t\tparentMap\n\t\t);\n\t}\n\n\tif ( json.scopes ) {\n\t\tfor ( const s in json.scopes ) {\n\t\t\tconst resolvedScope = resolveUrl( s, baseUrl );\n\t\t\tresolveAndComposePackages(\n\t\t\t\tjson.scopes[ s ],\n\t\t\t\toutMap.scopes[ resolvedScope ] ||\n\t\t\t\t\t( outMap.scopes[ resolvedScope ] = {} ),\n\t\t\t\tbaseUrl,\n\t\t\t\tparentMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn outMap;\n}\n\nlet importMap = { imports: {}, scopes: {} };\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `resolve`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\n/**\n * Extends the internal dynamic import map with the passed one.\n *\n * @param importMapIn Import map.\n * @param importMapIn.imports Imports declaration.\n * @param importMapIn.scopes Scopes declaration.\n */\nexport function addImportMap( importMapIn: {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, any >;\n} ) {\n\timportMap = resolveAndComposeImportMap(\n\t\timportMapIn,\n\t\tpageBaseUrl,\n\t\timportMap\n\t);\n}\n\n/**\n * Resolves the URL of the passed module ID against the current internal\n * dynamic import map.\n *\n * @param id Module ID.\n * @param parentUrl Parent URL, in case the module ID is relative.\n * @return Resolved module URL.\n */\nexport function resolve( id: string, parentUrl: string ): string {\n\tconst urlResolved = resolveIfNotPlainOrUrl( id, parentUrl );\n\treturn resolveImportMap( importMap, urlResolved || id, parentUrl ) || id;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,MAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,SAAU,GAAI;AACb,WAAO;AAAA,EACR;AACD;AAEA,SAAS,uBAAwB,QAAQ,WAAY;AACpD,QAAM,OAAO,UAAU,QAAS,GAAI,GACnC,OAAO,UAAU,QAAS,GAAI;AAC/B,MAAK,OAAO,OAAO,IAAK;AACvB,gBAAY,UAAU;AAAA,MACrB;AAAA;AAAA,MAEA,SAAS,KAAK,OAAO,SAAS,MAAM,OAAO,OAAO,OAAO;AAAA,IAC1D;AAAA,EACD;AACA,MAAK,OAAO,QAAS,IAAK,MAAM,IAAK;AACpC,aAAS,OAAO,QAAS,gBAAgB,GAAI;AAAA,EAC9C;AAEA,MAAK,OAAQ,CAAE,MAAM,OAAO,OAAQ,CAAE,MAAM,KAAM;AACjD,WAAO,UAAU,MAAO,GAAG,UAAU,QAAS,GAAI,IAAI,CAAE,IAAI;AAAA,EAC7D,WAGG,OAAQ,CAAE,MAAM,QACf,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ACA;AAAA,EACD;AACD;AAUO,SAAS,QAAS,IAAY,WAA4B;AAChE,QAAM,cAAc,uBAAwB,IAAI,SAAU;AAC1D,SAAO,iBAAkB,WAAW,eAAe,IAAI,SAAU,KAAK;AACvE;",
6
+ "names": ["importMap", "baseUrl"]
7
+ }
@@ -1,64 +1,52 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var script_modules_exports = {};
19
+ __export(script_modules_exports, {
20
+ importScriptModules: () => importScriptModules,
21
+ markScriptModuleAsResolved: () => markScriptModuleAsResolved,
22
+ preloadScriptModules: () => preloadScriptModules
5
23
  });
6
- exports.preloadScriptModules = exports.markScriptModuleAsResolved = exports.importScriptModules = void 0;
7
- var _dynamicImportmap = require("./dynamic-importmap");
8
- /**
9
- * Internal dependencies
10
- */
11
-
12
- /**
13
- * IDs of modules that should be resolved by the browser rather than
14
- * processed internally.
15
- */
16
- const resolvedScriptModules = new Set();
17
-
18
- /**
19
- * Marks the specified module as natively resolved.
20
- * @param url Script module URL.
21
- */
22
- const markScriptModuleAsResolved = url => {
24
+ module.exports = __toCommonJS(script_modules_exports);
25
+ var import_dynamic_importmap = require("./dynamic-importmap");
26
+ const resolvedScriptModules = /* @__PURE__ */ new Set();
27
+ const markScriptModuleAsResolved = (url) => {
23
28
  resolvedScriptModules.add(url);
24
29
  };
25
-
26
- /**
27
- * Resolves and fetches modules present in the passed document, using the
28
- * document's import map to resolve them.
29
- *
30
- * @param doc Document containing the modules to preload.
31
- * @return Array of promises that resolve to a `ScriptModuleLoad` instance.
32
- */
33
- exports.markScriptModuleAsResolved = markScriptModuleAsResolved;
34
- const preloadScriptModules = doc => {
35
- // Extract the import map from the document.
36
- const importMapElement = doc.querySelector('script#wp-importmap[type=importmap]');
37
- const importMap = importMapElement ? JSON.parse(importMapElement.text) : {
38
- imports: {},
39
- scopes: {}
40
- };
41
-
42
- // Remove imports also in the initial page's import map.
43
- // Those should be handled natively.
44
- for (const key in _dynamicImportmap.initialImportMap.imports) {
30
+ const preloadScriptModules = (doc) => {
31
+ const importMapElement = doc.querySelector(
32
+ "script#wp-importmap[type=importmap]"
33
+ );
34
+ const importMap = importMapElement ? JSON.parse(importMapElement.text) : { imports: {}, scopes: {} };
35
+ for (const key in import_dynamic_importmap.initialImportMap.imports) {
45
36
  delete importMap.imports[key];
46
37
  }
47
-
48
- // Get the URL of all modules contained in the document.
49
- const moduleUrls = [...doc.querySelectorAll('script[type=module][src]')].map(s => s.src);
50
-
51
- // Resolve and fetch those not resolved natively.
52
- return moduleUrls.filter(url => !resolvedScriptModules.has(url)).map(url => (0, _dynamicImportmap.preloadWithMap)(url, importMap));
38
+ const moduleUrls = [
39
+ ...doc.querySelectorAll(
40
+ "script[type=module][src]"
41
+ )
42
+ ].map((s) => s.src);
43
+ return moduleUrls.filter((url) => !resolvedScriptModules.has(url)).map((url) => (0, import_dynamic_importmap.preloadWithMap)(url, importMap));
53
44
  };
54
-
55
- /**
56
- * Imports modules respresented by the passed `ScriptModuleLoad` instances.
57
- *
58
- * @param modules Array of `MoudleLoad` instances.
59
- * @return Promise that resolves once all modules are imported.
60
- */
61
- exports.preloadScriptModules = preloadScriptModules;
62
- const importScriptModules = modules => Promise.all(modules.map(m => (0, _dynamicImportmap.importPreloadedModule)(m)));
63
- exports.importScriptModules = importScriptModules;
64
- //# sourceMappingURL=script-modules.js.map
45
+ const importScriptModules = (modules) => Promise.all(modules.map((m) => (0, import_dynamic_importmap.importPreloadedModule)(m)));
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ importScriptModules,
49
+ markScriptModuleAsResolved,
50
+ preloadScriptModules
51
+ });
52
+ //# sourceMappingURL=script-modules.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_dynamicImportmap","require","resolvedScriptModules","Set","markScriptModuleAsResolved","url","add","exports","preloadScriptModules","doc","importMapElement","querySelector","importMap","JSON","parse","text","imports","scopes","key","initialImportMap","moduleUrls","querySelectorAll","map","s","src","filter","has","preloadWithMap","importScriptModules","modules","Promise","all","m","importPreloadedModule"],"sources":["@wordpress/interactivity-router/src/assets/script-modules.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tinitialImportMap,\n\timportPreloadedModule,\n\tpreloadWithMap,\n\ttype ModuleLoad,\n} from './dynamic-importmap';\n\n/**\n * IDs of modules that should be resolved by the browser rather than\n * processed internally.\n */\nconst resolvedScriptModules = new Set< string >();\n\n/**\n * Marks the specified module as natively resolved.\n * @param url Script module URL.\n */\nexport const markScriptModuleAsResolved = ( url: string ) => {\n\tresolvedScriptModules.add( url );\n};\n\n/**\n * Resolves and fetches modules present in the passed document, using the\n * document's import map to resolve them.\n *\n * @param doc Document containing the modules to preload.\n * @return Array of promises that resolve to a `ScriptModuleLoad` instance.\n */\nexport const preloadScriptModules = ( doc: Document ) => {\n\t// Extract the import map from the document.\n\tconst importMapElement = doc.querySelector< HTMLScriptElement >(\n\t\t'script#wp-importmap[type=importmap]'\n\t);\n\tconst importMap = importMapElement\n\t\t? JSON.parse( importMapElement.text )\n\t\t: { imports: {}, scopes: {} };\n\n\t// Remove imports also in the initial page's import map.\n\t// Those should be handled natively.\n\tfor ( const key in initialImportMap.imports ) {\n\t\tdelete importMap.imports[ key ];\n\t}\n\n\t// Get the URL of all modules contained in the document.\n\tconst moduleUrls = [\n\t\t...doc.querySelectorAll< HTMLScriptElement >(\n\t\t\t'script[type=module][src]'\n\t\t),\n\t].map( ( s ) => s.src );\n\n\t// Resolve and fetch those not resolved natively.\n\treturn moduleUrls\n\t\t.filter( ( url ) => ! resolvedScriptModules.has( url ) )\n\t\t.map( ( url ) => preloadWithMap( url, importMap ) );\n};\n\n/**\n * Imports modules respresented by the passed `ScriptModuleLoad` instances.\n *\n * @param modules Array of `MoudleLoad` instances.\n * @return Promise that resolves once all modules are imported.\n */\nexport const importScriptModules = ( modules: ScriptModuleLoad[] ) =>\n\tPromise.all( modules.map( ( m ) => importPreloadedModule( m ) ) );\n\nexport type ScriptModuleLoad = ModuleLoad;\n"],"mappings":";;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,GAAG,IAAIC,GAAG,CAAW,CAAC;;AAEjD;AACA;AACA;AACA;AACO,MAAMC,0BAA0B,GAAKC,GAAW,IAAM;EAC5DH,qBAAqB,CAACI,GAAG,CAAED,GAAI,CAAC;AACjC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANAE,OAAA,CAAAH,0BAAA,GAAAA,0BAAA;AAOO,MAAMI,oBAAoB,GAAKC,GAAa,IAAM;EACxD;EACA,MAAMC,gBAAgB,GAAGD,GAAG,CAACE,aAAa,CACzC,qCACD,CAAC;EACD,MAAMC,SAAS,GAAGF,gBAAgB,GAC/BG,IAAI,CAACC,KAAK,CAAEJ,gBAAgB,CAACK,IAAK,CAAC,GACnC;IAAEC,OAAO,EAAE,CAAC,CAAC;IAAEC,MAAM,EAAE,CAAC;EAAE,CAAC;;EAE9B;EACA;EACA,KAAM,MAAMC,GAAG,IAAIC,kCAAgB,CAACH,OAAO,EAAG;IAC7C,OAAOJ,SAAS,CAACI,OAAO,CAAEE,GAAG,CAAE;EAChC;;EAEA;EACA,MAAME,UAAU,GAAG,CAClB,GAAGX,GAAG,CAACY,gBAAgB,CACtB,0BACD,CAAC,CACD,CAACC,GAAG,CAAIC,CAAC,IAAMA,CAAC,CAACC,GAAI,CAAC;;EAEvB;EACA,OAAOJ,UAAU,CACfK,MAAM,CAAIpB,GAAG,IAAM,CAAEH,qBAAqB,CAACwB,GAAG,CAAErB,GAAI,CAAE,CAAC,CACvDiB,GAAG,CAAIjB,GAAG,IAAM,IAAAsB,gCAAc,EAAEtB,GAAG,EAAEO,SAAU,CAAE,CAAC;AACrD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAL,OAAA,CAAAC,oBAAA,GAAAA,oBAAA;AAMO,MAAMoB,mBAAmB,GAAKC,OAA2B,IAC/DC,OAAO,CAACC,GAAG,CAAEF,OAAO,CAACP,GAAG,CAAIU,CAAC,IAAM,IAAAC,uCAAqB,EAAED,CAAE,CAAE,CAAE,CAAC;AAACzB,OAAA,CAAAqB,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/script-modules.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport {\n\tinitialImportMap,\n\timportPreloadedModule,\n\tpreloadWithMap,\n\ttype ModuleLoad,\n} from './dynamic-importmap';\n\n/**\n * IDs of modules that should be resolved by the browser rather than\n * processed internally.\n */\nconst resolvedScriptModules = new Set< string >();\n\n/**\n * Marks the specified module as natively resolved.\n * @param url Script module URL.\n */\nexport const markScriptModuleAsResolved = ( url: string ) => {\n\tresolvedScriptModules.add( url );\n};\n\n/**\n * Resolves and fetches modules present in the passed document, using the\n * document's import map to resolve them.\n *\n * @param doc Document containing the modules to preload.\n * @return Array of promises that resolve to a `ScriptModuleLoad` instance.\n */\nexport const preloadScriptModules = ( doc: Document ) => {\n\t// Extract the import map from the document.\n\tconst importMapElement = doc.querySelector< HTMLScriptElement >(\n\t\t'script#wp-importmap[type=importmap]'\n\t);\n\tconst importMap = importMapElement\n\t\t? JSON.parse( importMapElement.text )\n\t\t: { imports: {}, scopes: {} };\n\n\t// Remove imports also in the initial page's import map.\n\t// Those should be handled natively.\n\tfor ( const key in initialImportMap.imports ) {\n\t\tdelete importMap.imports[ key ];\n\t}\n\n\t// Get the URL of all modules contained in the document.\n\tconst moduleUrls = [\n\t\t...doc.querySelectorAll< HTMLScriptElement >(\n\t\t\t'script[type=module][src]'\n\t\t),\n\t].map( ( s ) => s.src );\n\n\t// Resolve and fetch those not resolved natively.\n\treturn moduleUrls\n\t\t.filter( ( url ) => ! resolvedScriptModules.has( url ) )\n\t\t.map( ( url ) => preloadWithMap( url, importMap ) );\n};\n\n/**\n * Imports modules respresented by the passed `ScriptModuleLoad` instances.\n *\n * @param modules Array of `MoudleLoad` instances.\n * @return Promise that resolves once all modules are imported.\n */\nexport const importScriptModules = ( modules: ScriptModuleLoad[] ) =>\n\tPromise.all( modules.map( ( m ) => importPreloadedModule( m ) ) );\n\nexport type ScriptModuleLoad = ModuleLoad;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,+BAKO;AAMP,MAAM,wBAAwB,oBAAI,IAAc;AAMzC,MAAM,6BAA6B,CAAE,QAAiB;AAC5D,wBAAsB,IAAK,GAAI;AAChC;AASO,MAAM,uBAAuB,CAAE,QAAmB;AAExD,QAAM,mBAAmB,IAAI;AAAA,IAC5B;AAAA,EACD;AACA,QAAM,YAAY,mBACf,KAAK,MAAO,iBAAiB,IAAK,IAClC,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE;AAI7B,aAAY,OAAO,0CAAiB,SAAU;AAC7C,WAAO,UAAU,QAAS,GAAI;AAAA,EAC/B;AAGA,QAAM,aAAa;AAAA,IAClB,GAAG,IAAI;AAAA,MACN;AAAA,IACD;AAAA,EACD,EAAE,IAAK,CAAE,MAAO,EAAE,GAAI;AAGtB,SAAO,WACL,OAAQ,CAAE,QAAS,CAAE,sBAAsB,IAAK,GAAI,CAAE,EACtD,IAAK,CAAE,YAAS,yCAAgB,KAAK,SAAU,CAAE;AACpD;AAQO,MAAM,sBAAsB,CAAE,YACpC,QAAQ,IAAK,QAAQ,IAAK,CAAE,UAAO,gDAAuB,CAAE,CAAE,CAAE;",
6
+ "names": []
7
+ }
@@ -1,56 +1,43 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var scs_exports = {};
19
+ __export(scs_exports, {
20
+ shortestCommonSupersequence: () => shortestCommonSupersequence
5
21
  });
6
- exports.shortestCommonSupersequence = shortestCommonSupersequence;
7
- /**
8
- * Calculates the Shortest Common Supersequence (SCS) of two sequences.
9
- *
10
- * A supersequence is a sequence that contains both input sequences as subsequences.
11
- * The shortest common supersequence is the shortest possible such sequence.
12
- *
13
- * This implementation uses dynamic programming with a time complexity of O(mn)
14
- * and space complexity of O(mn), where m and n are the lengths of sequences X and Y.
15
- *
16
- * @example
17
- * ```ts
18
- * const seq1 = [1, 3, 5];
19
- * const seq2 = [2, 3, 4];
20
- * const scs = shortestCommonSupersequence(seq1, seq2); // [1, 2, 3, 4, 5]
21
- * ```
22
- *
23
- * @param X The first sequence.
24
- * @param Y The second sequence.
25
- * @param isEqual Optional equality function to compare elements.
26
- * Defaults to strict equality (===).
27
- * @return The shortest common supersequence of X and Y.
28
- */
22
+ module.exports = __toCommonJS(scs_exports);
29
23
  function shortestCommonSupersequence(X, Y, isEqual = (a, b) => a === b) {
30
24
  const m = X.length;
31
25
  const n = Y.length;
32
-
33
- // Create a 2D dp table where dp[i][j] is the SCS for X[0..i-1] and Y[0..j-1].
34
- const dp = Array.from({
35
- length: m + 1
36
- }, () => Array(n + 1).fill(null));
37
-
38
- // Base cases: one of the sequences is empty.
26
+ const dp = Array.from(
27
+ { length: m + 1 },
28
+ () => Array(n + 1).fill(null)
29
+ );
39
30
  for (let i = 0; i <= m; i++) {
40
31
  dp[i][0] = X.slice(0, i);
41
32
  }
42
33
  for (let j = 0; j <= n; j++) {
43
34
  dp[0][j] = Y.slice(0, j);
44
35
  }
45
-
46
- // Fill in the dp table.
47
36
  for (let i = 1; i <= m; i++) {
48
37
  for (let j = 1; j <= n; j++) {
49
38
  if (isEqual(X[i - 1], Y[j - 1])) {
50
- // When X[i-1] equals Y[j-1], use the reference from X.
51
39
  dp[i][j] = dp[i - 1][j - 1].concat(X[i - 1]);
52
40
  } else {
53
- // Choose the shorter option between appending X[i-1] or Y[j-1].
54
41
  const option1 = dp[i - 1][j].concat(X[i - 1]);
55
42
  const option2 = dp[i][j - 1].concat(Y[j - 1]);
56
43
  dp[i][j] = option1.length <= option2.length ? option1 : option2;
@@ -59,4 +46,8 @@ function shortestCommonSupersequence(X, Y, isEqual = (a, b) => a === b) {
59
46
  }
60
47
  return dp[m][n];
61
48
  }
62
- //# sourceMappingURL=scs.js.map
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ shortestCommonSupersequence
52
+ });
53
+ //# sourceMappingURL=scs.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["shortestCommonSupersequence","X","Y","isEqual","a","b","m","length","n","dp","Array","from","fill","i","slice","j","concat","option1","option2"],"sources":["@wordpress/interactivity-router/src/assets/scs.ts"],"sourcesContent":["/**\n * Calculates the Shortest Common Supersequence (SCS) of two sequences.\n *\n * A supersequence is a sequence that contains both input sequences as subsequences.\n * The shortest common supersequence is the shortest possible such sequence.\n *\n * This implementation uses dynamic programming with a time complexity of O(mn)\n * and space complexity of O(mn), where m and n are the lengths of sequences X and Y.\n *\n * @example\n * ```ts\n * const seq1 = [1, 3, 5];\n * const seq2 = [2, 3, 4];\n * const scs = shortestCommonSupersequence(seq1, seq2); // [1, 2, 3, 4, 5]\n * ```\n *\n * @param X The first sequence.\n * @param Y The second sequence.\n * @param isEqual Optional equality function to compare elements.\n * Defaults to strict equality (===).\n * @return The shortest common supersequence of X and Y.\n */\nexport function shortestCommonSupersequence< E = unknown >(\n\tX: E[],\n\tY: E[],\n\tisEqual = ( a: E, b: E ) => a === b\n) {\n\tconst m = X.length;\n\tconst n = Y.length;\n\n\t// Create a 2D dp table where dp[i][j] is the SCS for X[0..i-1] and Y[0..j-1].\n\tconst dp: E[][][] = Array.from( { length: m + 1 }, () =>\n\t\tArray( n + 1 ).fill( null )\n\t);\n\n\t// Base cases: one of the sequences is empty.\n\tfor ( let i = 0; i <= m; i++ ) {\n\t\tdp[ i ][ 0 ] = X.slice( 0, i );\n\t}\n\tfor ( let j = 0; j <= n; j++ ) {\n\t\tdp[ 0 ][ j ] = Y.slice( 0, j );\n\t}\n\n\t// Fill in the dp table.\n\tfor ( let i = 1; i <= m; i++ ) {\n\t\tfor ( let j = 1; j <= n; j++ ) {\n\t\t\tif ( isEqual( X[ i - 1 ], Y[ j - 1 ] ) ) {\n\t\t\t\t// When X[i-1] equals Y[j-1], use the reference from X.\n\t\t\t\tdp[ i ][ j ] = dp[ i - 1 ][ j - 1 ].concat( X[ i - 1 ] );\n\t\t\t} else {\n\t\t\t\t// Choose the shorter option between appending X[i-1] or Y[j-1].\n\t\t\t\tconst option1 = dp[ i - 1 ][ j ].concat( X[ i - 1 ] );\n\t\t\t\tconst option2 = dp[ i ][ j - 1 ].concat( Y[ j - 1 ] );\n\t\t\t\tdp[ i ][ j ] =\n\t\t\t\t\toption1.length <= option2.length ? option1 : option2;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn dp[ m ][ n ];\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,2BAA2BA,CAC1CC,CAAM,EACNC,CAAM,EACNC,OAAO,GAAGA,CAAEC,CAAI,EAAEC,CAAI,KAAMD,CAAC,KAAKC,CAAC,EAClC;EACD,MAAMC,CAAC,GAAGL,CAAC,CAACM,MAAM;EAClB,MAAMC,CAAC,GAAGN,CAAC,CAACK,MAAM;;EAElB;EACA,MAAME,EAAW,GAAGC,KAAK,CAACC,IAAI,CAAE;IAAEJ,MAAM,EAAED,CAAC,GAAG;EAAE,CAAC,EAAE,MAClDI,KAAK,CAAEF,CAAC,GAAG,CAAE,CAAC,CAACI,IAAI,CAAE,IAAK,CAC3B,CAAC;;EAED;EACA,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIP,CAAC,EAAEO,CAAC,EAAE,EAAG;IAC9BJ,EAAE,CAAEI,CAAC,CAAE,CAAE,CAAC,CAAE,GAAGZ,CAAC,CAACa,KAAK,CAAE,CAAC,EAAED,CAAE,CAAC;EAC/B;EACA,KAAM,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIP,CAAC,EAAEO,CAAC,EAAE,EAAG;IAC9BN,EAAE,CAAE,CAAC,CAAE,CAAEM,CAAC,CAAE,GAAGb,CAAC,CAACY,KAAK,CAAE,CAAC,EAAEC,CAAE,CAAC;EAC/B;;EAEA;EACA,KAAM,IAAIF,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIP,CAAC,EAAEO,CAAC,EAAE,EAAG;IAC9B,KAAM,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIP,CAAC,EAAEO,CAAC,EAAE,EAAG;MAC9B,IAAKZ,OAAO,CAAEF,CAAC,CAAEY,CAAC,GAAG,CAAC,CAAE,EAAEX,CAAC,CAAEa,CAAC,GAAG,CAAC,CAAG,CAAC,EAAG;QACxC;QACAN,EAAE,CAAEI,CAAC,CAAE,CAAEE,CAAC,CAAE,GAAGN,EAAE,CAAEI,CAAC,GAAG,CAAC,CAAE,CAAEE,CAAC,GAAG,CAAC,CAAE,CAACC,MAAM,CAAEf,CAAC,CAAEY,CAAC,GAAG,CAAC,CAAG,CAAC;MACzD,CAAC,MAAM;QACN;QACA,MAAMI,OAAO,GAAGR,EAAE,CAAEI,CAAC,GAAG,CAAC,CAAE,CAAEE,CAAC,CAAE,CAACC,MAAM,CAAEf,CAAC,CAAEY,CAAC,GAAG,CAAC,CAAG,CAAC;QACrD,MAAMK,OAAO,GAAGT,EAAE,CAAEI,CAAC,CAAE,CAAEE,CAAC,GAAG,CAAC,CAAE,CAACC,MAAM,CAAEd,CAAC,CAAEa,CAAC,GAAG,CAAC,CAAG,CAAC;QACrDN,EAAE,CAAEI,CAAC,CAAE,CAAEE,CAAC,CAAE,GACXE,OAAO,CAACV,MAAM,IAAIW,OAAO,CAACX,MAAM,GAAGU,OAAO,GAAGC,OAAO;MACtD;IACD;EACD;EAEA,OAAOT,EAAE,CAAEH,CAAC,CAAE,CAAEE,CAAC,CAAE;AACpB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/scs.ts"],
4
+ "sourcesContent": ["/**\n * Calculates the Shortest Common Supersequence (SCS) of two sequences.\n *\n * A supersequence is a sequence that contains both input sequences as subsequences.\n * The shortest common supersequence is the shortest possible such sequence.\n *\n * This implementation uses dynamic programming with a time complexity of O(mn)\n * and space complexity of O(mn), where m and n are the lengths of sequences X and Y.\n *\n * @example\n * ```ts\n * const seq1 = [1, 3, 5];\n * const seq2 = [2, 3, 4];\n * const scs = shortestCommonSupersequence(seq1, seq2); // [1, 2, 3, 4, 5]\n * ```\n *\n * @param X The first sequence.\n * @param Y The second sequence.\n * @param isEqual Optional equality function to compare elements.\n * Defaults to strict equality (===).\n * @return The shortest common supersequence of X and Y.\n */\nexport function shortestCommonSupersequence< E = unknown >(\n\tX: E[],\n\tY: E[],\n\tisEqual = ( a: E, b: E ) => a === b\n) {\n\tconst m = X.length;\n\tconst n = Y.length;\n\n\t// Create a 2D dp table where dp[i][j] is the SCS for X[0..i-1] and Y[0..j-1].\n\tconst dp: E[][][] = Array.from( { length: m + 1 }, () =>\n\t\tArray( n + 1 ).fill( null )\n\t);\n\n\t// Base cases: one of the sequences is empty.\n\tfor ( let i = 0; i <= m; i++ ) {\n\t\tdp[ i ][ 0 ] = X.slice( 0, i );\n\t}\n\tfor ( let j = 0; j <= n; j++ ) {\n\t\tdp[ 0 ][ j ] = Y.slice( 0, j );\n\t}\n\n\t// Fill in the dp table.\n\tfor ( let i = 1; i <= m; i++ ) {\n\t\tfor ( let j = 1; j <= n; j++ ) {\n\t\t\tif ( isEqual( X[ i - 1 ], Y[ j - 1 ] ) ) {\n\t\t\t\t// When X[i-1] equals Y[j-1], use the reference from X.\n\t\t\t\tdp[ i ][ j ] = dp[ i - 1 ][ j - 1 ].concat( X[ i - 1 ] );\n\t\t\t} else {\n\t\t\t\t// Choose the shorter option between appending X[i-1] or Y[j-1].\n\t\t\t\tconst option1 = dp[ i - 1 ][ j ].concat( X[ i - 1 ] );\n\t\t\t\tconst option2 = dp[ i ][ j - 1 ].concat( Y[ j - 1 ] );\n\t\t\t\tdp[ i ][ j ] =\n\t\t\t\t\toption1.length <= option2.length ? option1 : option2;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn dp[ m ][ n ];\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBO,SAAS,4BACf,GACA,GACA,UAAU,CAAE,GAAM,MAAU,MAAM,GACj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