@rindo/core 1.17.4 → 2.5.2

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 (164) hide show
  1. package/LICENSE.md +27 -27
  2. package/bin/cli.ts +20 -0
  3. package/bin/rindo +51 -56
  4. package/cli/index.cjs +1263 -0
  5. package/cli/index.d.ts +1 -1
  6. package/cli/index.js +1232 -495
  7. package/cli/package.json +9 -4
  8. package/compiler/lib.d.ts +24 -0
  9. package/compiler/lib.dom.d.ts +20230 -0
  10. package/compiler/lib.dom.iterable.d.ts +351 -0
  11. package/compiler/lib.es2015.collection.d.ts +89 -0
  12. package/compiler/lib.es2015.core.d.ts +517 -0
  13. package/compiler/lib.es2015.d.ts +30 -0
  14. package/compiler/lib.es2015.generator.d.ts +79 -0
  15. package/compiler/lib.es2015.iterable.d.ts +505 -0
  16. package/compiler/lib.es2015.promise.d.ts +150 -0
  17. package/compiler/lib.es2015.proxy.d.ts +41 -0
  18. package/compiler/lib.es2015.reflect.d.ts +123 -0
  19. package/compiler/lib.es2015.symbol.d.ts +48 -0
  20. package/compiler/lib.es2015.symbol.wellknown.d.ts +324 -0
  21. package/compiler/lib.es2016.array.include.d.ts +118 -0
  22. package/compiler/lib.es2016.d.ts +22 -0
  23. package/compiler/lib.es2016.full.d.ts +25 -0
  24. package/compiler/lib.es2017.d.ts +26 -0
  25. package/compiler/lib.es2017.full.d.ts +25 -0
  26. package/compiler/lib.es2017.intl.d.ts +32 -0
  27. package/compiler/lib.es2017.object.d.ts +51 -0
  28. package/compiler/lib.es2017.sharedmemory.d.ts +137 -0
  29. package/compiler/lib.es2017.string.d.ts +47 -0
  30. package/compiler/lib.es2017.typedarrays.d.ts +55 -0
  31. package/compiler/lib.es2018.asyncgenerator.d.ts +79 -0
  32. package/compiler/lib.es2018.asynciterable.d.ts +45 -0
  33. package/compiler/lib.es2018.d.ts +26 -0
  34. package/compiler/lib.es2018.full.d.ts +25 -0
  35. package/compiler/lib.es2018.intl.d.ts +61 -0
  36. package/compiler/lib.es2018.promise.d.ts +32 -0
  37. package/compiler/lib.es2018.regexp.d.ts +39 -0
  38. package/compiler/lib.es2019.array.d.ts +85 -0
  39. package/compiler/lib.es2019.d.ts +25 -0
  40. package/compiler/lib.es2019.full.d.ts +25 -0
  41. package/compiler/lib.es2019.object.d.ts +35 -0
  42. package/compiler/lib.es2019.string.d.ts +33 -0
  43. package/compiler/lib.es2019.symbol.d.ts +26 -0
  44. package/compiler/lib.es2020.bigint.d.ts +728 -0
  45. package/compiler/lib.es2020.d.ts +27 -0
  46. package/compiler/lib.es2020.full.d.ts +25 -0
  47. package/compiler/lib.es2020.intl.d.ts +310 -0
  48. package/compiler/lib.es2020.promise.d.ts +50 -0
  49. package/compiler/lib.es2020.sharedmemory.d.ts +99 -0
  50. package/compiler/lib.es2020.string.d.ts +30 -0
  51. package/compiler/lib.es2020.symbol.wellknown.d.ts +39 -0
  52. package/compiler/lib.es5.d.ts +4435 -0
  53. package/compiler/lib.es6.d.ts +25 -0
  54. package/compiler/lib.esnext.d.ts +25 -0
  55. package/compiler/lib.esnext.full.d.ts +25 -0
  56. package/compiler/lib.esnext.intl.d.ts +32 -0
  57. package/compiler/lib.esnext.promise.d.ts +43 -0
  58. package/compiler/lib.esnext.string.d.ts +35 -0
  59. package/compiler/lib.esnext.weakref.d.ts +75 -0
  60. package/compiler/lib.scripthost.d.ts +327 -0
  61. package/compiler/lib.webworker.d.ts +6042 -0
  62. package/compiler/lib.webworker.importscripts.d.ts +26 -0
  63. package/compiler/lib.webworker.iterable.d.ts +166 -0
  64. package/compiler/package.json +3 -3
  65. package/compiler/rindo.d.ts +0 -16
  66. package/compiler/rindo.js +42738 -40541
  67. package/compiler/rindo.min.js +2 -15
  68. package/dependencies.json +73 -50
  69. package/dev-server/client/index.js +33 -10
  70. package/dev-server/client/package.json +3 -3
  71. package/dev-server/connector.html +3 -3
  72. package/dev-server/index.d.ts +3 -6
  73. package/dev-server/index.js +256 -252
  74. package/dev-server/package.json +3 -3
  75. package/dev-server/server-process.js +1738 -0
  76. package/dev-server/server-worker-thread.js +39 -0
  77. package/dev-server/templates/initial-load.html +160 -160
  78. package/dev-server/ws.js +1 -1
  79. package/internal/app-data/{index.cjs.js → index.cjs} +7 -5
  80. package/internal/app-data/index.d.ts +1 -0
  81. package/internal/app-data/index.js +7 -6
  82. package/internal/app-data/package.json +11 -5
  83. package/internal/client/css-shim.js +2 -2
  84. package/internal/client/dom.js +1 -1
  85. package/internal/client/index.js +193 -119
  86. package/internal/client/package.json +4 -3
  87. package/internal/client/{patch.js → patch-browser.js} +8 -24
  88. package/internal/client/patch-esm.js +23 -0
  89. package/internal/client/polyfills/css-shim.js +1 -1
  90. package/internal/client/polyfills/index.js +34 -34
  91. package/internal/client/shadow-css.js +9 -3
  92. package/internal/hydrate/index.js +305 -281
  93. package/internal/hydrate/package.json +2 -2
  94. package/internal/hydrate/runner.d.ts +24 -12
  95. package/internal/hydrate/runner.js +153 -124
  96. package/internal/hydrate/shadow-css.js +24 -24
  97. package/internal/package.json +5 -4
  98. package/internal/rindo-core/index.cjs +1 -0
  99. package/internal/rindo-core/index.d.ts +51 -2
  100. package/internal/rindo-core/index.js +15 -1
  101. package/internal/rindo-ext-modules.d.ts +41 -39
  102. package/internal/rindo-private.d.ts +93 -148
  103. package/internal/rindo-public-compiler.d.ts +231 -155
  104. package/internal/rindo-public-runtime.d.ts +42 -39
  105. package/internal/testing/index.js +144 -121
  106. package/internal/testing/package.json +2 -2
  107. package/internal/testing/shadow-css.js +24 -24
  108. package/mock-doc/index.cjs +4610 -0
  109. package/mock-doc/index.d.ts +12 -1
  110. package/mock-doc/index.js +177 -67
  111. package/mock-doc/package.json +11 -5
  112. package/package.json +132 -133
  113. package/readme.md +21 -95
  114. package/screenshot/compare/build/app.js +33 -33
  115. package/screenshot/compare/build/p-f4745c2f.entry.js +1 -1
  116. package/screenshot/connector-base.d.ts +1 -1
  117. package/screenshot/connector-local.d.ts +1 -1
  118. package/screenshot/index.js +63 -46
  119. package/screenshot/package.json +10 -3
  120. package/screenshot/pixel-match.js +54 -57
  121. package/screenshot/screenshot-compare.d.ts +1 -1
  122. package/screenshot/screenshot-fs.d.ts +1 -1
  123. package/sys/deno/index.js +1785 -0
  124. package/sys/deno/node-compat.js +2654 -0
  125. package/sys/deno/worker.js +44 -0
  126. package/sys/node/autoprefixer.js +8 -1
  127. package/sys/node/glob.js +1 -1
  128. package/sys/node/graceful-fs.js +1 -1
  129. package/sys/node/index.d.ts +1 -1
  130. package/sys/node/index.js +689 -705
  131. package/sys/node/node-fetch.js +1 -1
  132. package/sys/node/package.json +3 -3
  133. package/sys/node/prompts.js +1 -1
  134. package/sys/node/worker.js +38 -19
  135. package/testing/index.d.ts +3 -3
  136. package/testing/index.js +863 -749
  137. package/testing/jest/jest-config.d.ts +2 -89
  138. package/testing/jest/jest-environment.d.ts +1 -1
  139. package/testing/jest/jest-runner.d.ts +1 -1
  140. package/testing/jest/jest-screenshot.d.ts +1 -1
  141. package/testing/jest-preset.js +32 -32
  142. package/testing/matchers/events.d.ts +1 -1
  143. package/testing/matchers/screenshot.d.ts +1 -1
  144. package/testing/mock-fetch.d.ts +1 -1
  145. package/testing/mocks.d.ts +1 -1
  146. package/testing/package.json +3 -3
  147. package/testing/puppeteer/index.d.ts +1 -1
  148. package/testing/puppeteer/puppeteer-browser.d.ts +2 -2
  149. package/testing/puppeteer/puppeteer-declarations.d.ts +11 -11
  150. package/testing/puppeteer/puppeteer-element.d.ts +3 -3
  151. package/testing/puppeteer/puppeteer-emulate.d.ts +1 -1
  152. package/testing/puppeteer/puppeteer-events.d.ts +3 -3
  153. package/testing/puppeteer/puppeteer-page.d.ts +1 -1
  154. package/testing/puppeteer/puppeteer-screenshot.d.ts +2 -2
  155. package/testing/reset-build-conditionals.d.ts +1 -1
  156. package/testing/spec-page.d.ts +1 -1
  157. package/testing/test-transpile.d.ts +1 -1
  158. package/testing/testing-logger.d.ts +1 -1
  159. package/testing/testing-utils.d.ts +1 -1
  160. package/testing/testing.d.ts +1 -1
  161. package/cli/index.cjs.js +0 -524
  162. package/dev-server/content-type-db.json +0 -1
  163. package/dev-server/server-worker.js +0 -1570
  164. package/mock-doc/index.cjs.js +0 -4500
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rindo/core/internal/hydrate",
3
- "version": "0.0.0-dev.20221104122636",
3
+ "version": "2.5.2",
4
4
  "description": "Rindo internal hydrate platform to be imported by the Rindo Compiler. Breaking changes can and will happen at any time.",
5
- "main": "index.js",
5
+ "main": "./index.js",
6
6
  "private": true
7
7
  }
@@ -2,24 +2,29 @@
2
2
 
3
3
  export declare function createWindowFromHtml(templateHtml: string, uniqueId: string): any;
4
4
  export interface HydrateDocumentOptions {
5
+ /**
6
+ * Build ID that will be added to `<html data-rindo-build="BUILD_ID">`. By default
7
+ * a random ID will be generated
8
+ */
9
+ buildId?: string;
5
10
  /**
6
11
  * Sets the `href` attribute on the `<link rel="canonical">`
7
12
  * tag within the `<head>`. If the value is not defined it will
8
13
  * ensure a canonical link tag is no included in the `<head>`.
9
14
  */
10
15
  canonicalUrl?: string;
11
- /**
12
- * Constrain `setTimeout()` to 1ms, but still async. Also
13
- * only allows `setInterval()` to fire once, also constrained to 1ms.
14
- * Defaults to `true`.
15
- */
16
- constrainTimeouts?: boolean;
17
16
  /**
18
17
  * Include the HTML comments and attributes used by the clientside
19
18
  * JavaScript to read the structure of the HTML and rebuild each
20
19
  * component. Defaults to `true`.
21
20
  */
22
21
  clientHydrateAnnotations?: boolean;
22
+ /**
23
+ * Constrain `setTimeout()` to 1ms, but still async. Also
24
+ * only allows `setInterval()` to fire once, also constrained to 1ms.
25
+ * Defaults to `true`.
26
+ */
27
+ constrainTimeouts?: boolean;
23
28
  /**
24
29
  * Sets `document.cookie`
25
30
  */
@@ -156,6 +161,7 @@ export interface Diagnostic {
156
161
  }[];
157
162
  }
158
163
  export interface HydrateResults {
164
+ buildId: string;
159
165
  diagnostics: Diagnostic[];
160
166
  url: string;
161
167
  host: string;
@@ -168,9 +174,10 @@ export interface HydrateResults {
168
174
  html: string;
169
175
  components: HydrateComponent[];
170
176
  anchors: HydrateAnchorElement[];
171
- styles: HydrateStyleElement[];
172
- scripts: HydrateScriptElement[];
173
177
  imgs: HydrateImgElement[];
178
+ scripts: HydrateScriptElement[];
179
+ styles: HydrateStyleElement[];
180
+ staticData: HydrateStaticData[];
174
181
  title: string;
175
182
  hydratedCount: number;
176
183
  httpStatus: number;
@@ -188,15 +195,20 @@ export interface HydrateAnchorElement extends HydrateElement {
188
195
  href?: string;
189
196
  target?: string;
190
197
  }
191
- export interface HydrateStyleElement extends HydrateElement {
192
- href?: string;
198
+ export interface HydrateImgElement extends HydrateElement {
199
+ src?: string;
193
200
  }
194
201
  export interface HydrateScriptElement extends HydrateElement {
195
202
  src?: string;
196
203
  type?: string;
197
204
  }
198
- export interface HydrateImgElement extends HydrateElement {
199
- src?: string;
205
+ export interface HydrateStyleElement extends HydrateElement {
206
+ href?: string;
207
+ }
208
+ export interface HydrateStaticData {
209
+ id: string;
210
+ type: string;
211
+ content: string;
200
212
  }
201
213
  export declare function renderToString(html: string | any, options?: SerializeDocumentOptions): Promise<HydrateResults>;
202
214
  export declare function hydrateDocument(doc: any | string, options?: HydrateDocumentOptions): Promise<HydrateResults>;
@@ -26,8 +26,9 @@ function mapValidTags(e) {
26
26
  }
27
27
 
28
28
  function generateHydrateResults(e) {
29
- "string" != typeof e.url && (e.url = "https://hydrate-rindojs.web.app/");
29
+ "string" != typeof e.url && (e.url = "https://hydrate-rindojs.web.app/"), "string" != typeof e.buildId && (e.buildId = createHydrateBuildId());
30
30
  const t = {
31
+ buildId: e.buildId,
31
32
  diagnostics: [],
32
33
  url: e.url,
33
34
  host: null,
@@ -44,6 +45,7 @@ function generateHydrateResults(e) {
44
45
  components: [],
45
46
  imgs: [],
46
47
  scripts: [],
48
+ staticData: [],
47
49
  styles: [],
48
50
  title: null
49
51
  };
@@ -85,6 +87,45 @@ function runtimeLog(e, t, r) {
85
87
  global.console[t].apply(global.console, [ `[ ${e} ${t} ] `, ...r ]);
86
88
  }
87
89
 
90
+ function inspectElement(e, t, r) {
91
+ const s = t.children;
92
+ for (let t = 0, n = s.length; t < n; t++) {
93
+ const n = s[t], o = n.nodeName.toLowerCase();
94
+ if (o.includes("-")) {
95
+ const t = e.components.find((e => e.tag === o));
96
+ null != t && (t.count++, r > t.depth && (t.depth = r));
97
+ } else switch (o) {
98
+ case "a":
99
+ const t = collectAttributes(n);
100
+ t.href = n.href, "string" == typeof t.href && (e.anchors.some((e => e.href === t.href)) || e.anchors.push(t));
101
+ break;
102
+
103
+ case "img":
104
+ const r = collectAttributes(n);
105
+ r.src = n.src, "string" == typeof r.src && (e.imgs.some((e => e.src === r.src)) || e.imgs.push(r));
106
+ break;
107
+
108
+ case "link":
109
+ const s = collectAttributes(n);
110
+ s.href = n.href, "string" == typeof s.rel && "stylesheet" === s.rel.toLowerCase() && "string" == typeof s.href && (e.styles.some((e => e.link === s.href)) || (delete s.rel,
111
+ delete s.type, e.styles.push(s)));
112
+ break;
113
+
114
+ case "script":
115
+ const o = collectAttributes(n);
116
+ if (n.hasAttribute("src")) o.src = n.src, "string" == typeof o.src && (e.scripts.some((e => e.src === o.src)) || e.scripts.push(o)); else {
117
+ const t = n.getAttribute("data-rindo-static");
118
+ t && e.staticData.push({
119
+ id: t,
120
+ type: n.getAttribute("type"),
121
+ content: n.textContent
122
+ });
123
+ }
124
+ }
125
+ inspectElement(e, n, ++r);
126
+ }
127
+ }
128
+
88
129
  function collectAttributes(e) {
89
130
  const t = {}, r = e.attributes;
90
131
  for (let e = 0, s = r.length; e < s; e++) {
@@ -127,86 +168,98 @@ function getRootNode(e) {
127
168
 
128
169
  function renderToString(e, t) {
129
170
  const r = normalizeHydrateOptions(t);
130
- return r.serializeToHtml = !0, new Promise(t => {
131
- const s = generateHydrateResults(r);
132
- if (hasError(s.diagnostics)) t(s); else if ("string" == typeof e) try {
133
- r.destroyWindow = !0, r.destroyDocument = !0, render(new MockWindow(e), r, s, t);
171
+ return r.serializeToHtml = !0, new Promise((t => {
172
+ let s;
173
+ const n = generateHydrateResults(r);
174
+ if (hasError(n.diagnostics)) t(n); else if ("string" == typeof e) try {
175
+ r.destroyWindow = !0, r.destroyDocument = !0, s = new MockWindow(e), render(s, r, n, t);
134
176
  } catch (e) {
135
- renderCatchError(s, e), t(s);
177
+ s && s.close && s.close(), s = null, renderCatchError(n, e), t(n);
136
178
  } else if (isValidDocument(e)) try {
137
- r.destroyDocument = !1, render(patchDomImplementation(e, r), r, s, t);
179
+ r.destroyDocument = !1, s = patchDomImplementation(e, r), render(s, r, n, t);
138
180
  } catch (e) {
139
- renderCatchError(s, e), t(s);
140
- } else renderBuildError(s, 'Invalid html or document. Must be either a valid "html" string, or DOM "document".'),
141
- t(s);
142
- });
181
+ s && s.close && s.close(), s = null, renderCatchError(n, e), t(n);
182
+ } else renderBuildError(n, 'Invalid html or document. Must be either a valid "html" string, or DOM "document".'),
183
+ t(n);
184
+ }));
143
185
  }
144
186
 
145
187
  function hydrateDocument(e, t) {
146
188
  const r = normalizeHydrateOptions(t);
147
- return r.serializeToHtml = !1, new Promise(t => {
148
- const s = generateHydrateResults(r);
149
- if (hasError(s.diagnostics)) t(s); else if ("string" == typeof e) try {
150
- r.destroyWindow = !0, r.destroyDocument = !0, render(new MockWindow(e), r, s, t);
189
+ return r.serializeToHtml = !1, new Promise((t => {
190
+ let s;
191
+ const n = generateHydrateResults(r);
192
+ if (hasError(n.diagnostics)) t(n); else if ("string" == typeof e) try {
193
+ r.destroyWindow = !0, r.destroyDocument = !0, s = new MockWindow(e), render(s, r, n, t);
151
194
  } catch (e) {
152
- renderCatchError(s, e), t(s);
195
+ s && s.close && s.close(), s = null, renderCatchError(n, e), t(n);
153
196
  } else if (isValidDocument(e)) try {
154
- r.destroyDocument = !1, render(patchDomImplementation(e, r), r, s, t);
197
+ r.destroyDocument = !1, s = patchDomImplementation(e, r), render(s, r, n, t);
155
198
  } catch (e) {
156
- renderCatchError(s, e), t(s);
157
- } else renderBuildError(s, 'Invalid html or document. Must be either a valid "html" string, or DOM "document".'),
158
- t(s);
159
- });
199
+ s && s.close && s.close(), s = null, renderCatchError(n, e), t(n);
200
+ } else renderBuildError(n, 'Invalid html or document. Must be either a valid "html" string, or DOM "document".'),
201
+ t(n);
202
+ }));
160
203
  }
161
204
 
162
205
  function render(e, t, r, s) {
163
- if (process.__rindoErrors || (process.__rindoErrors = !0, process.on("unhandledRejection", e => {
206
+ if (process.__rindoErrors || (process.__rindoErrors = !0, process.on("unhandledRejection", (e => {
164
207
  console.log("unhandledRejection", e);
165
- })), function n(e, t, r) {
208
+ }))), function n(e, t, r, s) {
166
209
  try {
167
- e.location.href = t.url;
210
+ e.location.href = r.url;
168
211
  } catch (e) {
169
- renderCatchError(r, e);
212
+ renderCatchError(s, e);
170
213
  }
171
- if ("string" == typeof t.userAgent) try {
172
- e.navigator.userAgent = t.userAgent;
214
+ if ("string" == typeof r.userAgent) try {
215
+ e.navigator.userAgent = r.userAgent;
173
216
  } catch (e) {}
174
- if ("string" == typeof t.cookie) try {
175
- e.document.cookie = t.cookie;
217
+ if ("string" == typeof r.cookie) try {
218
+ t.cookie = r.cookie;
176
219
  } catch (e) {}
177
- if ("string" == typeof t.referrer) try {
178
- e.document.referrer = t.referrer;
220
+ if ("string" == typeof r.referrer) try {
221
+ t.referrer = r.referrer;
179
222
  } catch (e) {}
180
- if ("string" == typeof t.direction) try {
181
- e.document.documentElement.setAttribute("dir", t.direction);
223
+ if ("string" == typeof r.direction) try {
224
+ t.documentElement.setAttribute("dir", r.direction);
182
225
  } catch (e) {}
183
- if ("string" == typeof t.language) try {
184
- e.document.documentElement.setAttribute("lang", t.language);
226
+ if ("string" == typeof r.language) try {
227
+ t.documentElement.setAttribute("lang", r.language);
228
+ } catch (e) {}
229
+ if ("string" == typeof r.buildId) try {
230
+ t.documentElement.setAttribute("data-rindo-build", r.buildId);
185
231
  } catch (e) {}
186
232
  try {
187
233
  e.customElements = null;
188
234
  } catch (e) {}
189
- return t.constrainTimeouts && constrainTimeouts(e), function s(e, t, r) {
235
+ return r.constrainTimeouts && constrainTimeouts(e), function n(e, t, r) {
190
236
  try {
191
237
  const s = e.location.pathname;
192
238
  e.console.error = (...e) => {
193
- renderCatchError(r, [ ...e ].join(", ")), t.runtimeLogging && runtimeLog(s, "error", e);
239
+ const n = e.reduce(((e, t) => {
240
+ if (t) {
241
+ if (null != t.stack) return e + " " + String(t.stack);
242
+ if (null != t.message) return e + " " + String(t.message);
243
+ }
244
+ return String(t);
245
+ }), "").trim();
246
+ "" !== n && (renderCatchError(r, n), t.runtimeLogging && runtimeLog(s, "error", [ n ]));
194
247
  }, e.console.debug = (...e) => {
195
248
  renderBuildDiagnostic(r, "debug", "Hydrate Debug", [ ...e ].join(", ")), t.runtimeLogging && runtimeLog(s, "debug", e);
196
- }, t.runtimeLogging && [ "log", "warn", "assert", "info", "trace" ].forEach(t => {
249
+ }, t.runtimeLogging && [ "log", "warn", "assert", "info", "trace" ].forEach((t => {
197
250
  e.console[t] = (...e) => {
198
251
  runtimeLog(s, t, e);
199
252
  };
200
- });
253
+ }));
201
254
  } catch (e) {
202
255
  renderCatchError(r, e);
203
256
  }
204
- }(e, t, r), e;
205
- }(e, t, r), "function" == typeof t.beforeHydrate) try {
257
+ }(e, r, s), e;
258
+ }(e, e.document, t, r), "function" == typeof t.beforeHydrate) try {
206
259
  const n = t.beforeHydrate(e.document);
207
- isPromise(n) ? n.then(() => {
260
+ isPromise(n) ? n.then((() => {
208
261
  hydrateFactory(e, t, r, afterHydrate, s);
209
- }) : hydrateFactory(e, t, r, afterHydrate, s);
262
+ })) : hydrateFactory(e, t, r, afterHydrate, s);
210
263
  } catch (n) {
211
264
  renderCatchError(r, n), finalizeHydrate(e, e.document, t, r, s);
212
265
  } else hydrateFactory(e, t, r, afterHydrate, s);
@@ -215,9 +268,9 @@ function render(e, t, r, s) {
215
268
  function afterHydrate(e, t, r, s) {
216
269
  if ("function" == typeof t.afterHydrate) try {
217
270
  const n = t.afterHydrate(e.document);
218
- isPromise(n) ? n.then(() => {
271
+ isPromise(n) ? n.then((() => {
219
272
  finalizeHydrate(e, e.document, t, r, s);
220
- }) : finalizeHydrate(e, e.document, t, r, s);
273
+ })) : finalizeHydrate(e, e.document, t, r, s);
221
274
  } catch (n) {
222
275
  renderCatchError(r, n), finalizeHydrate(e, e.document, t, r, s);
223
276
  } else finalizeHydrate(e, e.document, t, r, s);
@@ -225,37 +278,7 @@ function afterHydrate(e, t, r, s) {
225
278
 
226
279
  function finalizeHydrate(e, t, r, s, n) {
227
280
  try {
228
- if (function e(t, r, s) {
229
- const n = r.children;
230
- for (let r = 0, o = n.length; r < o; r++) {
231
- const o = n[r], i = o.nodeName.toLowerCase();
232
- if (i.includes("-")) {
233
- const e = t.components.find(e => e.tag === i);
234
- null != e && (e.count++, s > e.depth && (e.depth = s));
235
- } else switch (i) {
236
- case "a":
237
- const e = collectAttributes(o);
238
- e.href = o.href, "string" == typeof e.href && (t.anchors.some(t => t.href === e.href) || t.anchors.push(e));
239
- break;
240
-
241
- case "img":
242
- const r = collectAttributes(o);
243
- r.src = o.src, "string" == typeof r.src && (t.imgs.some(e => e.src === r.src) || t.imgs.push(r));
244
- break;
245
-
246
- case "link":
247
- const s = collectAttributes(o);
248
- s.href = o.href, "string" == typeof s.rel && "stylesheet" === s.rel.toLowerCase() && "string" == typeof s.href && (t.styles.some(e => e.link === s.href) || (delete s.rel,
249
- delete s.type, t.styles.push(s)));
250
- break;
251
-
252
- case "script":
253
- const n = collectAttributes(o);
254
- n.src = o.src, "string" == typeof n.src && (t.scripts.some(e => e.src === n.src) || t.scripts.push(n));
255
- }
256
- e(t, o, ++s);
257
- }
258
- }(s, t.documentElement, 0), !1 !== r.removeUnusedStyles) try {
281
+ if (inspectElement(s, t.documentElement, 0), !1 !== r.removeUnusedStyles) try {
259
282
  ((e, t) => {
260
283
  try {
261
284
  const r = e.head.querySelectorAll("style[data-styles]"), s = r.length;
@@ -295,13 +318,7 @@ function finalizeHydrate(e, t, r, s, n) {
295
318
  } catch (e) {
296
319
  renderCatchError(s, e);
297
320
  }
298
- s.title = t.title, r.removeScripts && function e(t) {
299
- const r = t.children;
300
- for (let t = r.length - 1; t >= 0; t--) {
301
- const s = r[t];
302
- e(s), ("SCRIPT" === s.nodeName || "LINK" === s.nodeName && "modulepreload" === s.getAttribute("rel")) && s.remove();
303
- }
304
- }(t.documentElement);
321
+ s.title = t.title, r.removeScripts && removeScripts(t.documentElement);
305
322
  try {
306
323
  ((e, t) => {
307
324
  let r = e.head.querySelector('link[rel="canonical"]');
@@ -332,7 +349,7 @@ function finalizeHydrate(e, t, r, s, n) {
332
349
  renderCatchError(s, e);
333
350
  }
334
351
  if (r.destroyWindow) try {
335
- r.destroyDocument || (e.document = null, t.defaultView = null), e.close();
352
+ r.destroyDocument || (e.document = null, t.defaultView = null), e.close && e.close();
336
353
  } catch (e) {
337
354
  renderCatchError(s, e);
338
355
  }
@@ -356,12 +373,23 @@ function isValidDocument(e) {
356
373
  return null != e && 9 === e.nodeType && null != e.documentElement && 1 === e.documentElement.nodeType && null != e.body && 1 === e.body.nodeType;
357
374
  }
358
375
 
376
+ function removeScripts(e) {
377
+ const t = e.children;
378
+ for (let e = t.length - 1; e >= 0; e--) {
379
+ const r = t[e];
380
+ removeScripts(r), ("SCRIPT" === r.nodeName || "LINK" === r.nodeName && "modulepreload" === r.getAttribute("rel")) && r.remove();
381
+ }
382
+ }
383
+
359
384
  import { MockWindow, cloneWindow, constrainTimeouts, patchWindow, serializeNodeToHtml } from "@rindo/core/mock-doc";
360
385
 
361
386
  import { hydrateFactory } from "@rindo/core/hydrate-factory";
362
387
 
363
- const templateWindows = new Map, IS_NODE_ENV = !("undefined" == typeof global || "function" != typeof require || !global.process || "string" != typeof __filename || global.origin && "string" == typeof global.origin), isPromise = (global.process.platform,
364
- IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && ("object" == typeof e || "function" == typeof e) && "function" == typeof e.then), hasError = e => null != e && 0 !== e.length && e.some(e => "error" === e.level && "runtime" !== e.type), shouldIgnoreError = e => e === TASK_CANCELED_MSG, TASK_CANCELED_MSG = "task canceled", SKIP_ATTRS = new Set([ "s-id", "c-id" ]), collectUsedSelectors = (e, t) => {
388
+ const templateWindows = new Map, createHydrateBuildId = () => {
389
+ let e = "abcdefghijklmnopqrstuvwxyz", t = "";
390
+ for (;t.length < 8; ) t += e[Math.floor(Math.random() * e.length)], 1 === t.length && (e += "0123456789");
391
+ return t;
392
+ }, isPromise = e => !!e && ("object" == typeof e || "function" == typeof e) && "function" == typeof e.then, hasError = e => null != e && 0 !== e.length && e.some((e => "error" === e.level && "runtime" !== e.type)), shouldIgnoreError = e => e === TASK_CANCELED_MSG, TASK_CANCELED_MSG = "task canceled", SKIP_ATTRS = new Set([ "s-id", "c-id" ]), collectUsedSelectors = (e, t) => {
365
393
  if (null != t && 1 === t.nodeType) {
366
394
  const r = t.children, s = t.nodeName.toLowerCase();
367
395
  e.tags.add(s);
@@ -387,7 +415,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
387
415
  line: r,
388
416
  column: s
389
417
  };
390
- return t => (t.position = new A(e), m(), t);
418
+ return t => (t.position = new z(e), m(), t);
391
419
  }, a = o => {
392
420
  const i = e.split("\n"), a = {
393
421
  level: "error",
@@ -432,7 +460,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
432
460
  }, d = () => {
433
461
  let t;
434
462
  const r = [];
435
- for (m(), h(r); e.length && "}" !== e.charAt(0) && (t = w() || z()); ) !1 !== t && (r.push(t),
463
+ for (m(), h(r); e.length && "}" !== e.charAt(0) && (t = w() || A()); ) !1 !== t && (r.push(t),
436
464
  h(r));
437
465
  return r;
438
466
  }, m = () => u(/^\s*/), h = e => {
@@ -447,7 +475,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
447
475
  if (r += 2, "" === e.charAt(r - 1)) return a("End of comment missing");
448
476
  const n = e.slice(2, r - 2);
449
477
  return s += 2, o(n), e = e.slice(r), s += 2, t({
450
- type: "comment",
478
+ type: 1,
451
479
  comment: n
452
480
  });
453
481
  }, f = () => {
@@ -463,7 +491,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
463
491
  if (!t) return null;
464
492
  if (t = trim(t[0]), !u(/^:\s*/)) return a("property missing ':'");
465
493
  const r = u(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/), s = e({
466
- type: "declaration",
494
+ type: 4,
467
495
  property: t.replace(commentre, ""),
468
496
  value: r ? trim(r[0]).replace(commentre, "") : ""
469
497
  });
@@ -479,21 +507,21 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
479
507
  const t = [], r = i();
480
508
  for (;e = u(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/); ) t.push(e[1]), u(/^,\s*/);
481
509
  return t.length ? r({
482
- type: "keyframe",
510
+ type: 9,
483
511
  values: t,
484
512
  declarations: y()
485
513
  }) : null;
486
- }, S = e => {
487
- const t = new RegExp("^@" + e + "\\s*([^;]+);");
514
+ }, S = (e, t) => {
515
+ const r = new RegExp("^@" + e + "\\s*([^;]+);");
488
516
  return () => {
489
- const r = i(), s = u(t);
490
- if (!s) return null;
491
- const n = {
492
- type: e
517
+ const s = i(), n = u(r);
518
+ if (!n) return null;
519
+ const o = {
520
+ type: t
493
521
  };
494
- return n[e] = s[1].trim(), r(n);
522
+ return o[e] = n[1].trim(), s(o);
495
523
  };
496
- }, E = S("import"), b = S("charset"), T = S("namespace"), w = () => "@" !== e[0] ? null : (() => {
524
+ }, E = S("import", 7), b = S("charset", 0), T = S("namespace", 11), w = () => "@" !== e[0] ? null : (() => {
497
525
  const e = i();
498
526
  let t = u(/^@([-\w]+)?keyframes\s*/);
499
527
  if (!t) return null;
@@ -504,7 +532,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
504
532
  let n, o = h();
505
533
  for (;n = C(); ) o.push(n), o = o.concat(h());
506
534
  return c() ? e({
507
- type: "keyframes",
535
+ type: 8,
508
536
  name: s,
509
537
  vendor: r,
510
538
  keyframes: o
@@ -516,14 +544,14 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
516
544
  if (!l()) return a("@media missing '{'");
517
545
  const s = h().concat(d());
518
546
  return c() ? e({
519
- type: "media",
547
+ type: 10,
520
548
  media: r,
521
549
  rules: s
522
550
  }) : a("@media missing '}'");
523
551
  })() || (() => {
524
552
  const e = i(), t = u(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
525
553
  return t ? e({
526
- type: "custom-media",
554
+ type: 2,
527
555
  name: trim(t[1]),
528
556
  media: trim(t[2])
529
557
  }) : null;
@@ -534,7 +562,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
534
562
  if (!l()) return a("@supports missing '{'");
535
563
  const s = h().concat(d());
536
564
  return c() ? e({
537
- type: "supports",
565
+ type: 15,
538
566
  supports: r,
539
567
  rules: s
540
568
  }) : a("@supports missing '}'");
@@ -545,7 +573,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
545
573
  if (!l()) return a("@document missing '{'");
546
574
  const n = h().concat(d());
547
575
  return c() ? e({
548
- type: "document",
576
+ type: 3,
549
577
  document: s,
550
578
  vendor: r,
551
579
  rules: n
@@ -558,7 +586,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
558
586
  let r, s = h();
559
587
  for (;r = g(); ) s.push(r), s = s.concat(h());
560
588
  return c() ? e({
561
- type: "page",
589
+ type: 12,
562
590
  selectors: t,
563
591
  declarations: s
564
592
  }) : a("@page missing '}'");
@@ -568,7 +596,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
568
596
  if (!l()) return a("@host missing '{'");
569
597
  const t = h().concat(d());
570
598
  return c() ? e({
571
- type: "host",
599
+ type: 6,
572
600
  rules: t
573
601
  }) : a("@host missing '}'");
574
602
  })() || (() => {
@@ -578,18 +606,18 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
578
606
  let t, r = h();
579
607
  for (;t = g(); ) r.push(t), r = r.concat(h());
580
608
  return c() ? e({
581
- type: "font-face",
609
+ type: 5,
582
610
  declarations: r
583
611
  }) : a("@font-face missing '}'");
584
- })(), z = () => {
612
+ })(), A = () => {
585
613
  const e = i(), t = f();
586
614
  return t ? (h(), e({
587
- type: "rule",
615
+ type: 13,
588
616
  selectors: t,
589
617
  declarations: y()
590
618
  })) : a("selector missing");
591
619
  };
592
- class A {
620
+ class z {
593
621
  constructor(e) {
594
622
  this.start = e, this.end = {
595
623
  line: r,
@@ -597,18 +625,19 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
597
625
  }, this.source = t;
598
626
  }
599
627
  }
600
- return A.prototype.content = e, Object.assign({
601
- diagnostics: n
602
- }, addParent((() => {
603
- const e = d();
604
- return {
605
- type: "stylesheet",
606
- stylesheet: {
607
- source: t,
608
- rules: e
609
- }
610
- };
611
- })()));
628
+ return z.prototype.content = e, {
629
+ diagnostics: n,
630
+ ...addParent((() => {
631
+ const e = d();
632
+ return {
633
+ type: 14,
634
+ stylesheet: {
635
+ source: t,
636
+ rules: e
637
+ }
638
+ };
639
+ })())
640
+ };
612
641
  }, trim = e => e ? e.trim() : "", addParent = (e, t) => {
613
642
  const r = e && "string" == typeof e.type, s = r ? e : t;
614
643
  for (const t in e) {
@@ -628,7 +657,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
628
657
  const t = (e = e.replace(/\./g, " .").replace(/\#/g, " #").replace(/\[/g, " [").replace(/\>/g, " > ").replace(/\+/g, " + ").replace(/\~/g, " ~ ").replace(/\*/g, " * ").replace(/\:not\((.*?)\)/g, " ")).split(" ");
629
658
  for (let e = 0, r = t.length; e < r; e++) t[e] = t[e].split(":")[0], 0 !== t[e].length && ("." === t[e].charAt(0) ? SELECTORS.classNames.push(t[e].substr(1)) : "#" === t[e].charAt(0) ? SELECTORS.ids.push(t[e].substr(1)) : "[" === t[e].charAt(0) ? (t[e] = t[e].substr(1).split("=")[0].split("]")[0].trim(),
630
659
  SELECTORS.attrs.push(t[e].toLowerCase())) : /[a-z]/g.test(t[e].charAt(0)) && SELECTORS.tags.push(t[e].toLowerCase()));
631
- return SELECTORS.classNames = SELECTORS.classNames.sort((e, t) => e.length < t.length ? -1 : e.length > t.length ? 1 : 0),
660
+ return SELECTORS.classNames = SELECTORS.classNames.sort(((e, t) => e.length < t.length ? -1 : e.length > t.length ? 1 : 0)),
632
661
  SELECTORS;
633
662
  }, SELECTORS = {
634
663
  all: [],
@@ -638,7 +667,7 @@ IS_NODE_ENV && global.process.platform, process.cwd, process.exit, e => !!e && (
638
667
  attrs: []
639
668
  }, serializeCssVisitNode = (e, t, r, s) => {
640
669
  const n = t.type;
641
- return "declaration" === n ? serializeCssDeclaration(t, r, s) : "rule" === n ? serializeCssRule(e, t) : "comment" === n ? "!" === t.comment[0] ? `/*${t.comment}*/` : "" : "media" === n ? serializeCssMedia(e, t) : "keyframes" === n ? serializeCssKeyframes(e, t) : "keyframe" === n ? serializeCssKeyframe(e, t) : "font-face" === n ? serializeCssFontFace(e, t) : "supports" === n ? serializeCssSupports(e, t) : "import" === n ? "@import " + t.import + ";" : "charset" === n ? "@charset " + t.charset + ";" : "page" === n ? serializeCssPage(e, t) : "host" === n ? "@host{" + serializeCssMapVisit(e, t.rules) + "}" : "custom-media" === n ? "@custom-media " + t.name + " " + t.media + ";" : "document" === n ? serializeCssDocument(e, t) : "namespace" === n ? "@namespace " + t.namespace + ";" : "";
670
+ return 4 === n ? serializeCssDeclaration(t, r, s) : 13 === n ? serializeCssRule(e, t) : 1 === n ? "!" === t.comment[0] ? `/*${t.comment}*/` : "" : 10 === n ? serializeCssMedia(e, t) : 8 === n ? serializeCssKeyframes(e, t) : 9 === n ? serializeCssKeyframe(e, t) : 5 === n ? serializeCssFontFace(e, t) : 15 === n ? serializeCssSupports(e, t) : 7 === n ? "@import " + t.import + ";" : 0 === n ? "@charset " + t.charset + ";" : 12 === n ? serializeCssPage(e, t) : 6 === n ? "@host{" + serializeCssMapVisit(e, t.rules) + "}" : 2 === n ? "@custom-media " + t.name + " " + t.media + ";" : 3 === n ? serializeCssDocument(e, t) : 11 === n ? "@namespace " + t.namespace + ";" : "";
642
671
  }, serializeCssRule = (e, t) => {
643
672
  const r = t.declarations, s = e.usedSelectors, n = t.selectors.slice();
644
673
  if (null == r || 0 === r.length) return "";