@stencil/core 4.28.2-dev.1742303553.90ea840 → 4.28.2-dev.1742318817.ddf403c

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Stencil Hydrate Runner v4.28.2-dev.1742303553.90ea840 | MIT Licensed | https://stenciljs.com
2
+ Stencil Hydrate Runner v4.28.2-dev.1742318817.ddf403c | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  var __defProp = Object.defineProperty;
5
5
  var __export = (target, all) => {
@@ -14234,1808 +14234,1816 @@ import { BUILD as BUILD24 } from "@stencil/core/internal/app-data";
14234
14234
  // src/runtime/client-hydrate.ts
14235
14235
  import { BUILD as BUILD12 } from "@stencil/core/internal/app-data";
14236
14236
 
14237
- // src/runtime/dom-extras.ts
14238
- import { BUILD as BUILD9 } from "@stencil/core/internal/app-data";
14239
-
14240
- // src/runtime/slot-polyfill-utils.ts
14241
- import { BUILD as BUILD8 } from "@stencil/core/internal/app-data";
14242
-
14243
- // src/runtime/profile.ts
14244
- import { BUILD as BUILD10 } from "@stencil/core/internal/app-data";
14245
-
14246
- // src/runtime/vdom/h.ts
14247
- import { BUILD as BUILD11 } from "@stencil/core/internal/app-data";
14248
-
14249
- // src/runtime/initialize-component.ts
14250
- import { BUILD as BUILD23 } from "@stencil/core/internal/app-data";
14251
-
14252
- // src/utils/shadow-css.ts
14253
- /**
14254
- * @license
14255
- * Copyright Google Inc. All Rights Reserved.
14256
- *
14257
- * Use of this source code is governed by an MIT-style license that can be
14258
- * found in the LICENSE file at https://angular.io/license
14259
- *
14260
- * This file is a port of shadowCSS from `webcomponents.js` to TypeScript.
14261
- * https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js
14262
- * https://github.com/angular/angular/blob/master/packages/compiler/src/shadow_css.ts
14263
- */
14264
- var _polyfillHost = "-shadowcsshost";
14265
- var _polyfillSlotted = "-shadowcssslotted";
14266
- var _polyfillHostContext = "-shadowcsscontext";
14267
- var _parenSuffix = ")(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)";
14268
- var _cssColonHostRe = new RegExp("(" + _polyfillHost + _parenSuffix, "gim");
14269
- var _cssColonHostContextRe = new RegExp("(" + _polyfillHostContext + _parenSuffix, "gim");
14270
- var _cssColonSlottedRe = new RegExp("(" + _polyfillSlotted + _parenSuffix, "gim");
14271
- var _polyfillHostNoCombinator = _polyfillHost + "-no-combinator";
14272
- var createSupportsRuleRe = (selector) => new RegExp(`((?<!(^@supports(.*)))|(?<={.*))(${selector}\\b)`, "gim");
14273
- var _colonSlottedRe = createSupportsRuleRe("::slotted");
14274
- var _colonHostRe = createSupportsRuleRe(":host");
14275
- var _colonHostContextRe = createSupportsRuleRe(":host-context");
14276
-
14277
- // src/runtime/mode.ts
14278
- var setMode = (handler) => modeResolutionChain.push(handler);
14279
-
14280
- // src/runtime/proxy-component.ts
14281
- import { BUILD as BUILD22 } from "@stencil/core/internal/app-data";
14282
-
14283
- // src/runtime/set-value.ts
14284
- import { BUILD as BUILD21 } from "@stencil/core/internal/app-data";
14285
-
14286
- // src/runtime/parse-property-value.ts
14287
- import { BUILD as BUILD13 } from "@stencil/core/internal/app-data";
14288
-
14289
- // src/runtime/update-component.ts
14290
- import { BUILD as BUILD20, NAMESPACE } from "@stencil/core/internal/app-data";
14291
-
14292
- // src/runtime/event-emitter.ts
14293
- import { BUILD as BUILD15 } from "@stencil/core/internal/app-data";
14294
-
14295
- // src/runtime/element.ts
14296
- import { BUILD as BUILD14 } from "@stencil/core/internal/app-data";
14297
-
14298
- // src/runtime/styles.ts
14299
- import { BUILD as BUILD16 } from "@stencil/core/internal/app-data";
14300
-
14301
- // src/runtime/vdom/vdom-render.ts
14302
- import { BUILD as BUILD19 } from "@stencil/core/internal/app-data";
14303
-
14304
- // src/runtime/vdom/update-element.ts
14305
- import { BUILD as BUILD18 } from "@stencil/core/internal/app-data";
14306
-
14307
- // src/runtime/vdom/set-accessor.ts
14308
- import { BUILD as BUILD17 } from "@stencil/core/internal/app-data";
14309
- var CAPTURE_EVENT_SUFFIX = "Capture";
14310
- var CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + "$");
14311
-
14312
- // src/runtime/disconnected-callback.ts
14313
- import { BUILD as BUILD25 } from "@stencil/core/internal/app-data";
14314
-
14315
- // src/runtime/bootstrap-lazy.ts
14316
- import { BUILD as BUILD27 } from "@stencil/core/internal/app-data";
14317
-
14318
- // src/runtime/host-listener.ts
14319
- import { BUILD as BUILD28 } from "@stencil/core/internal/app-data";
14320
-
14321
- // src/compiler/html/canonical-link.ts
14322
- var updateCanonicalLink = (doc, href) => {
14323
- var _a2;
14324
- let canonicalLinkElm = doc.head.querySelector('link[rel="canonical"]');
14325
- if (typeof href === "string") {
14326
- if (canonicalLinkElm == null) {
14327
- canonicalLinkElm = doc.createElement("link");
14328
- canonicalLinkElm.setAttribute("rel", "canonical");
14329
- doc.head.appendChild(canonicalLinkElm);
14330
- }
14331
- canonicalLinkElm.setAttribute("href", href);
14332
- } else {
14333
- if (canonicalLinkElm != null) {
14334
- const existingHref = canonicalLinkElm.getAttribute("href");
14335
- if (!existingHref) {
14336
- (_a2 = canonicalLinkElm.parentNode) == null ? void 0 : _a2.removeChild(canonicalLinkElm);
14337
- }
14237
+ // src/hydrate/runner/serialize.ts
14238
+ var PrimitiveType = /* @__PURE__ */ ((PrimitiveType2) => {
14239
+ PrimitiveType2["Undefined"] = "undefined";
14240
+ PrimitiveType2["Null"] = "null";
14241
+ PrimitiveType2["String"] = "string";
14242
+ PrimitiveType2["Number"] = "number";
14243
+ PrimitiveType2["SpecialNumber"] = "number";
14244
+ PrimitiveType2["Boolean"] = "boolean";
14245
+ PrimitiveType2["BigInt"] = "bigint";
14246
+ return PrimitiveType2;
14247
+ })(PrimitiveType || {});
14248
+ var NonPrimitiveType = /* @__PURE__ */ ((NonPrimitiveType2) => {
14249
+ NonPrimitiveType2["Array"] = "array";
14250
+ NonPrimitiveType2["Date"] = "date";
14251
+ NonPrimitiveType2["Map"] = "map";
14252
+ NonPrimitiveType2["Object"] = "object";
14253
+ NonPrimitiveType2["RegularExpression"] = "regexp";
14254
+ NonPrimitiveType2["Set"] = "set";
14255
+ NonPrimitiveType2["Channel"] = "channel";
14256
+ NonPrimitiveType2["Symbol"] = "symbol";
14257
+ return NonPrimitiveType2;
14258
+ })(NonPrimitiveType || {});
14259
+ var TYPE_CONSTANT = "type";
14260
+ var VALUE_CONSTANT = "value";
14261
+ var SERIALIZED_PREFIX = "serialized:";
14262
+ var SERIALIZABLE_TYPES = ["string", "boolean", "undefined", "number"];
14263
+ function serializeProperty(value) {
14264
+ if (SERIALIZABLE_TYPES.includes(typeof value) && value !== Infinity && value !== -Infinity && !isNaN(value)) {
14265
+ return value;
14266
+ }
14267
+ const arg = LocalValue.getArgument(value);
14268
+ return SERIALIZED_PREFIX + btoa(JSON.stringify(arg));
14269
+ }
14270
+ function deserializeProperty(value) {
14271
+ if (typeof value !== "string" || !value.startsWith(SERIALIZED_PREFIX)) {
14272
+ return value;
14273
+ }
14274
+ return RemoteValue.fromLocalValue(JSON.parse(atob(value.slice(SERIALIZED_PREFIX.length))));
14275
+ }
14276
+ var LocalValue = class _LocalValue {
14277
+ constructor(type, value) {
14278
+ if (type === "undefined" /* Undefined */ || type === "null" /* Null */) {
14279
+ this.type = type;
14280
+ } else {
14281
+ this.type = type;
14282
+ this.value = value;
14338
14283
  }
14339
14284
  }
14340
- };
14341
-
14342
- // src/compiler/html/relocate-meta-charset.ts
14343
- var relocateMetaCharset = (doc) => {
14344
- const head = doc.head;
14345
- let charsetElm = head.querySelector("meta[charset]");
14346
- if (charsetElm == null) {
14347
- charsetElm = doc.createElement("meta");
14348
- charsetElm.setAttribute("charset", "utf-8");
14349
- } else {
14350
- charsetElm.remove();
14285
+ /**
14286
+ * Creates a new LocalValue object with a string value.
14287
+ *
14288
+ * @param {string} value - The string value to be stored in the LocalValue object.
14289
+ * @returns {LocalValue} - The created LocalValue object.
14290
+ */
14291
+ static createStringValue(value) {
14292
+ return new _LocalValue("string" /* String */, value);
14351
14293
  }
14352
- head.insertBefore(charsetElm, head.firstChild);
14353
- };
14354
-
14355
- // src/compiler/style/css-parser/parse-css.ts
14356
- var parseCss = (css, filePath) => {
14357
- let lineno = 1;
14358
- let column = 1;
14359
- const diagnostics = [];
14360
- const updatePosition = (str) => {
14361
- const lines = str.match(/\n/g);
14362
- if (lines) lineno += lines.length;
14363
- const i = str.lastIndexOf("\n");
14364
- column = ~i ? str.length - i : column + str.length;
14365
- };
14366
- const position = () => {
14367
- const start = { line: lineno, column };
14368
- return (node) => {
14369
- node.position = new ParsePosition(start);
14370
- whitespace();
14371
- return node;
14372
- };
14373
- };
14374
- const error = (msg) => {
14375
- const srcLines = css.split("\n");
14376
- const d = {
14377
- level: "error",
14378
- type: "css",
14379
- language: "css",
14380
- header: "CSS Parse",
14381
- messageText: msg,
14382
- absFilePath: filePath,
14383
- lines: [
14384
- {
14385
- lineIndex: lineno - 1,
14386
- lineNumber: lineno,
14387
- errorCharStart: column,
14388
- text: css[lineno - 1]
14389
- }
14390
- ]
14391
- };
14392
- if (lineno > 1) {
14393
- const previousLine = {
14394
- lineIndex: lineno - 1,
14395
- lineNumber: lineno - 1,
14396
- text: css[lineno - 2],
14397
- errorCharStart: -1,
14398
- errorLength: -1
14399
- };
14400
- d.lines.unshift(previousLine);
14294
+ /**
14295
+ * Creates a new LocalValue object with a number value.
14296
+ *
14297
+ * @param {number} value - The number value.
14298
+ * @returns {LocalValue} - The created LocalValue object.
14299
+ */
14300
+ static createNumberValue(value) {
14301
+ return new _LocalValue("number" /* Number */, value);
14302
+ }
14303
+ /**
14304
+ * Creates a new LocalValue object with a special number value.
14305
+ *
14306
+ * @param {number} value - The value of the special number.
14307
+ * @returns {LocalValue} - The created LocalValue object.
14308
+ */
14309
+ static createSpecialNumberValue(value) {
14310
+ if (Number.isNaN(value)) {
14311
+ return new _LocalValue("number" /* SpecialNumber */, "NaN");
14401
14312
  }
14402
- if (lineno + 2 < srcLines.length) {
14403
- const nextLine = {
14404
- lineIndex: lineno,
14405
- lineNumber: lineno + 1,
14406
- text: srcLines[lineno],
14407
- errorCharStart: -1,
14408
- errorLength: -1
14409
- };
14410
- d.lines.push(nextLine);
14313
+ if (Object.is(value, -0)) {
14314
+ return new _LocalValue("number" /* SpecialNumber */, "-0");
14411
14315
  }
14412
- diagnostics.push(d);
14413
- return null;
14414
- };
14415
- const stylesheet = () => {
14416
- const rulesList = rules();
14417
- return {
14418
- type: 14 /* StyleSheet */,
14419
- stylesheet: {
14420
- source: filePath,
14421
- rules: rulesList
14422
- }
14423
- };
14424
- };
14425
- const open = () => match(/^{\s*/);
14426
- const close = () => match(/^}/);
14427
- const match = (re) => {
14428
- const m = re.exec(css);
14429
- if (!m) return;
14430
- const str = m[0];
14431
- updatePosition(str);
14432
- css = css.slice(str.length);
14433
- return m;
14434
- };
14435
- const rules = () => {
14436
- let node;
14437
- const rules2 = [];
14438
- whitespace();
14439
- comments(rules2);
14440
- while (css.length && css.charAt(0) !== "}" && (node = atrule() || rule())) {
14441
- rules2.push(node);
14442
- comments(rules2);
14443
- }
14444
- return rules2;
14445
- };
14446
- const whitespace = () => match(/^\s*/);
14447
- const comments = (rules2) => {
14448
- let c;
14449
- rules2 = rules2 || [];
14450
- while (c = comment()) {
14451
- rules2.push(c);
14316
+ if (value === Infinity) {
14317
+ return new _LocalValue("number" /* SpecialNumber */, "Infinity");
14452
14318
  }
14453
- return rules2;
14454
- };
14455
- const comment = () => {
14456
- const pos = position();
14457
- if ("/" !== css.charAt(0) || "*" !== css.charAt(1)) return null;
14458
- let i = 2;
14459
- while ("" !== css.charAt(i) && ("*" !== css.charAt(i) || "/" !== css.charAt(i + 1))) ++i;
14460
- i += 2;
14461
- if ("" === css.charAt(i - 1)) {
14462
- return error("End of comment missing");
14319
+ if (value === -Infinity) {
14320
+ return new _LocalValue("number" /* SpecialNumber */, "-Infinity");
14463
14321
  }
14464
- const comment2 = css.slice(2, i - 2);
14465
- column += 2;
14466
- updatePosition(comment2);
14467
- css = css.slice(i);
14468
- column += 2;
14469
- return pos({
14470
- type: 1 /* Comment */,
14471
- comment: comment2
14472
- });
14473
- };
14474
- const selector = () => {
14475
- const m = match(/^([^{]+)/);
14476
- if (!m) return null;
14477
- return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, "").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m2) {
14478
- return m2.replace(/,/g, "\u200C");
14479
- }).split(/\s*(?![^(]*\)),\s*/).map(function(s) {
14480
- return s.replace(/\u200C/g, ",");
14322
+ return new _LocalValue("number" /* SpecialNumber */, value);
14323
+ }
14324
+ /**
14325
+ * Creates a new LocalValue object with an undefined value.
14326
+ * @returns {LocalValue} - The created LocalValue object.
14327
+ */
14328
+ static createUndefinedValue() {
14329
+ return new _LocalValue("undefined" /* Undefined */);
14330
+ }
14331
+ /**
14332
+ * Creates a new LocalValue object with a null value.
14333
+ * @returns {LocalValue} - The created LocalValue object.
14334
+ */
14335
+ static createNullValue() {
14336
+ return new _LocalValue("null" /* Null */);
14337
+ }
14338
+ /**
14339
+ * Creates a new LocalValue object with a boolean value.
14340
+ *
14341
+ * @param {boolean} value - The boolean value.
14342
+ * @returns {LocalValue} - The created LocalValue object.
14343
+ */
14344
+ static createBooleanValue(value) {
14345
+ return new _LocalValue("boolean" /* Boolean */, value);
14346
+ }
14347
+ /**
14348
+ * Creates a new LocalValue object with a BigInt value.
14349
+ *
14350
+ * @param {BigInt} value - The BigInt value.
14351
+ * @returns {LocalValue} - The created LocalValue object.
14352
+ */
14353
+ static createBigIntValue(value) {
14354
+ return new _LocalValue("bigint" /* BigInt */, value.toString());
14355
+ }
14356
+ /**
14357
+ * Creates a new LocalValue object with an array.
14358
+ *
14359
+ * @param {Array} value - The array.
14360
+ * @returns {LocalValue} - The created LocalValue object.
14361
+ */
14362
+ static createArrayValue(value) {
14363
+ return new _LocalValue("array" /* Array */, value);
14364
+ }
14365
+ /**
14366
+ * Creates a new LocalValue object with date value.
14367
+ *
14368
+ * @param {string} value - The date.
14369
+ * @returns {LocalValue} - The created LocalValue object.
14370
+ */
14371
+ static createDateValue(value) {
14372
+ return new _LocalValue("date" /* Date */, value);
14373
+ }
14374
+ /**
14375
+ * Creates a new LocalValue object of map value.
14376
+ * @param {Map} map - The map.
14377
+ * @returns {LocalValue} - The created LocalValue object.
14378
+ */
14379
+ static createMapValue(map2) {
14380
+ const value = [];
14381
+ Array.from(map2.entries()).forEach(([key, val]) => {
14382
+ value.push([_LocalValue.getArgument(key), _LocalValue.getArgument(val)]);
14481
14383
  });
14482
- };
14483
- const declaration = () => {
14484
- const pos = position();
14485
- let prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
14486
- if (!prop) return null;
14487
- prop = trim(prop[0]);
14488
- if (!match(/^:\s*/)) return error(`property missing ':'`);
14489
- const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
14490
- const ret = pos({
14491
- type: 4 /* Declaration */,
14492
- property: prop.replace(commentre, ""),
14493
- value: val ? trim(val[0]).replace(commentre, "") : ""
14384
+ return new _LocalValue("map" /* Map */, value);
14385
+ }
14386
+ /**
14387
+ * Creates a new LocalValue object from the passed object.
14388
+ *
14389
+ * @param object the object to create a LocalValue from
14390
+ * @returns {LocalValue} - The created LocalValue object.
14391
+ */
14392
+ static createObjectValue(object) {
14393
+ const value = [];
14394
+ Object.entries(object).forEach(([key, val]) => {
14395
+ value.push([key, _LocalValue.getArgument(val)]);
14494
14396
  });
14495
- match(/^[;\s]*/);
14496
- return ret;
14497
- };
14498
- const declarations = () => {
14499
- const decls = [];
14500
- if (!open()) return error(`missing '{'`);
14501
- comments(decls);
14502
- let decl;
14503
- while (decl = declaration()) {
14504
- decls.push(decl);
14505
- comments(decls);
14506
- }
14507
- if (!close()) return error(`missing '}'`);
14508
- return decls;
14509
- };
14510
- const keyframe = () => {
14511
- let m;
14512
- const values = [];
14513
- const pos = position();
14514
- while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
14515
- values.push(m[1]);
14516
- match(/^,\s*/);
14397
+ return new _LocalValue("object" /* Object */, value);
14398
+ }
14399
+ /**
14400
+ * Creates a new LocalValue object of regular expression value.
14401
+ *
14402
+ * @param {string} value - The value of the regular expression.
14403
+ * @returns {LocalValue} - The created LocalValue object.
14404
+ */
14405
+ static createRegularExpressionValue(value) {
14406
+ return new _LocalValue("regexp" /* RegularExpression */, value);
14407
+ }
14408
+ /**
14409
+ * Creates a new LocalValue object with the specified value.
14410
+ * @param {Set} value - The value to be set.
14411
+ * @returns {LocalValue} - The created LocalValue object.
14412
+ */
14413
+ static createSetValue(value) {
14414
+ return new _LocalValue("set" /* Set */, value);
14415
+ }
14416
+ /**
14417
+ * Creates a new LocalValue object with the given channel value
14418
+ *
14419
+ * @param {ChannelValue} value - The channel value.
14420
+ * @returns {LocalValue} - The created LocalValue object.
14421
+ */
14422
+ static createChannelValue(value) {
14423
+ return new _LocalValue("channel" /* Channel */, value);
14424
+ }
14425
+ /**
14426
+ * Creates a new LocalValue object with a Symbol value.
14427
+ *
14428
+ * @param {Symbol} symbol - The Symbol value
14429
+ * @returns {LocalValue} - The created LocalValue object
14430
+ */
14431
+ static createSymbolValue(symbol) {
14432
+ const description = symbol.description || "Symbol()";
14433
+ return new _LocalValue("symbol" /* Symbol */, description);
14434
+ }
14435
+ static getArgument(argument) {
14436
+ const type = typeof argument;
14437
+ switch (type) {
14438
+ case "string" /* String */:
14439
+ return _LocalValue.createStringValue(argument);
14440
+ case "number" /* Number */:
14441
+ if (Number.isNaN(argument) || Object.is(argument, -0) || !Number.isFinite(argument)) {
14442
+ return _LocalValue.createSpecialNumberValue(argument);
14443
+ }
14444
+ return _LocalValue.createNumberValue(argument);
14445
+ case "boolean" /* Boolean */:
14446
+ return _LocalValue.createBooleanValue(argument);
14447
+ case "bigint" /* BigInt */:
14448
+ return _LocalValue.createBigIntValue(argument);
14449
+ case "undefined" /* Undefined */:
14450
+ return _LocalValue.createUndefinedValue();
14451
+ case "symbol" /* Symbol */:
14452
+ return _LocalValue.createSymbolValue(argument);
14453
+ case "object" /* Object */:
14454
+ if (argument === null) {
14455
+ return _LocalValue.createNullValue();
14456
+ }
14457
+ if (argument instanceof Date) {
14458
+ return _LocalValue.createDateValue(argument);
14459
+ }
14460
+ if (argument instanceof Map) {
14461
+ const map2 = [];
14462
+ argument.forEach((value, key) => {
14463
+ const objectKey = typeof key === "string" ? key : _LocalValue.getArgument(key);
14464
+ const objectValue = _LocalValue.getArgument(value);
14465
+ map2.push([objectKey, objectValue]);
14466
+ });
14467
+ return _LocalValue.createMapValue(argument);
14468
+ }
14469
+ if (argument instanceof Set) {
14470
+ const set = [];
14471
+ argument.forEach((value) => {
14472
+ set.push(_LocalValue.getArgument(value));
14473
+ });
14474
+ return _LocalValue.createSetValue(set);
14475
+ }
14476
+ if (argument instanceof Array) {
14477
+ const arr = [];
14478
+ argument.forEach((value) => {
14479
+ arr.push(_LocalValue.getArgument(value));
14480
+ });
14481
+ return _LocalValue.createArrayValue(arr);
14482
+ }
14483
+ if (argument instanceof RegExp) {
14484
+ return _LocalValue.createRegularExpressionValue({
14485
+ pattern: argument.source,
14486
+ flags: argument.flags
14487
+ });
14488
+ }
14489
+ return _LocalValue.createObjectValue(argument);
14517
14490
  }
14518
- if (!values.length) return null;
14519
- return pos({
14520
- type: 9 /* KeyFrame */,
14521
- values,
14522
- declarations: declarations()
14523
- });
14524
- };
14525
- const atkeyframes = () => {
14526
- const pos = position();
14527
- let m = match(/^@([-\w]+)?keyframes\s*/);
14528
- if (!m) return null;
14529
- const vendor = m[1];
14530
- m = match(/^([-\w]+)\s*/);
14531
- if (!m) return error(`@keyframes missing name`);
14532
- const name = m[1];
14533
- if (!open()) return error(`@keyframes missing '{'`);
14534
- let frame;
14535
- let frames = comments();
14536
- while (frame = keyframe()) {
14537
- frames.push(frame);
14538
- frames = frames.concat(comments());
14539
- }
14540
- if (!close()) return error(`@keyframes missing '}'`);
14541
- return pos({
14542
- type: 8 /* KeyFrames */,
14543
- name,
14544
- vendor,
14545
- keyframes: frames
14546
- });
14547
- };
14548
- const atsupports = () => {
14549
- const pos = position();
14550
- const m = match(/^@supports *([^{]+)/);
14551
- if (!m) return null;
14552
- const supports = trim(m[1]);
14553
- if (!open()) return error(`@supports missing '{'`);
14554
- const style = comments().concat(rules());
14555
- if (!close()) return error(`@supports missing '}'`);
14556
- return pos({
14557
- type: 15 /* Supports */,
14558
- supports,
14559
- rules: style
14560
- });
14561
- };
14562
- const athost = () => {
14563
- const pos = position();
14564
- const m = match(/^@host\s*/);
14565
- if (!m) return null;
14566
- if (!open()) return error(`@host missing '{'`);
14567
- const style = comments().concat(rules());
14568
- if (!close()) return error(`@host missing '}'`);
14569
- return pos({
14570
- type: 6 /* Host */,
14571
- rules: style
14572
- });
14573
- };
14574
- const atmedia = () => {
14575
- const pos = position();
14576
- const m = match(/^@media *([^{]+)/);
14577
- if (!m) return null;
14578
- const media = trim(m[1]);
14579
- if (!open()) return error(`@media missing '{'`);
14580
- const style = comments().concat(rules());
14581
- if (!close()) return error(`@media missing '}'`);
14582
- return pos({
14583
- type: 10 /* Media */,
14584
- media,
14585
- rules: style
14586
- });
14587
- };
14588
- const atcustommedia = () => {
14589
- const pos = position();
14590
- const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
14591
- if (!m) return null;
14592
- return pos({
14593
- type: 2 /* CustomMedia */,
14594
- name: trim(m[1]),
14595
- media: trim(m[2])
14596
- });
14597
- };
14598
- const atpage = () => {
14599
- const pos = position();
14600
- const m = match(/^@page */);
14601
- if (!m) return null;
14602
- const sel = selector() || [];
14603
- if (!open()) return error(`@page missing '{'`);
14604
- let decls = comments();
14605
- let decl;
14606
- while (decl = declaration()) {
14607
- decls.push(decl);
14608
- decls = decls.concat(comments());
14609
- }
14610
- if (!close()) return error(`@page missing '}'`);
14611
- return pos({
14612
- type: 12 /* Page */,
14613
- selectors: sel,
14614
- declarations: decls
14615
- });
14616
- };
14617
- const atdocument = () => {
14618
- const pos = position();
14619
- const m = match(/^@([-\w]+)?document *([^{]+)/);
14620
- if (!m) return null;
14621
- const vendor = trim(m[1]);
14622
- const doc = trim(m[2]);
14623
- if (!open()) return error(`@document missing '{'`);
14624
- const style = comments().concat(rules());
14625
- if (!close()) return error(`@document missing '}'`);
14626
- return pos({
14627
- type: 3 /* Document */,
14628
- document: doc,
14629
- vendor,
14630
- rules: style
14631
- });
14632
- };
14633
- const atfontface = () => {
14634
- const pos = position();
14635
- const m = match(/^@font-face\s*/);
14636
- if (!m) return null;
14637
- if (!open()) return error(`@font-face missing '{'`);
14638
- let decls = comments();
14639
- let decl;
14640
- while (decl = declaration()) {
14641
- decls.push(decl);
14642
- decls = decls.concat(comments());
14643
- }
14644
- if (!close()) return error(`@font-face missing '}'`);
14645
- return pos({
14646
- type: 5 /* FontFace */,
14647
- declarations: decls
14648
- });
14649
- };
14650
- const compileAtrule = (nodeName, nodeType) => {
14651
- const re = new RegExp("^@" + nodeName + "\\s*([^;]+);");
14652
- return () => {
14653
- const pos = position();
14654
- const m = match(re);
14655
- if (!m) return null;
14656
- const node = {
14657
- type: nodeType
14658
- };
14659
- node[nodeName] = m[1].trim();
14660
- return pos(node);
14491
+ throw new Error(`Unsupported type: ${type}`);
14492
+ }
14493
+ asMap() {
14494
+ return {
14495
+ [TYPE_CONSTANT]: this.type,
14496
+ ...!(this.type === "null" /* Null */ || this.type === "undefined" /* Undefined */) ? { [VALUE_CONSTANT]: this.value } : {}
14661
14497
  };
14662
- };
14663
- const atimport = compileAtrule("import", 7 /* Import */);
14664
- const atcharset = compileAtrule("charset", 0 /* Charset */);
14665
- const atnamespace = compileAtrule("namespace", 11 /* Namespace */);
14666
- const atrule = () => {
14667
- if (css[0] !== "@") return null;
14668
- return atkeyframes() || atmedia() || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface();
14669
- };
14670
- const rule = () => {
14671
- const pos = position();
14672
- const sel = selector();
14673
- if (!sel) return error("selector missing");
14674
- comments();
14675
- return pos({
14676
- type: 13 /* Rule */,
14677
- selectors: sel,
14678
- declarations: declarations()
14679
- });
14680
- };
14681
- class ParsePosition {
14682
- constructor(start) {
14683
- this.start = start;
14684
- this.end = { line: lineno, column };
14685
- this.source = filePath;
14686
- }
14687
14498
  }
14688
- ParsePosition.prototype.content = css;
14689
- return {
14690
- diagnostics,
14691
- ...addParent(stylesheet())
14692
- };
14693
14499
  };
14694
- var trim = (str) => str ? str.trim() : "";
14695
- var addParent = (obj, parent) => {
14696
- const isNode = obj && typeof obj.type === "string";
14697
- const childParent = isNode ? obj : parent;
14698
- for (const k in obj) {
14699
- const value = obj[k];
14700
- if (Array.isArray(value)) {
14701
- value.forEach(function(v) {
14702
- addParent(v, childParent);
14703
- });
14704
- } else if (value && typeof value === "object") {
14705
- addParent(value, childParent);
14500
+ var RemoteValue = class _RemoteValue {
14501
+ /**
14502
+ * Deserializes a LocalValue serialized object back to its original JavaScript representation
14503
+ *
14504
+ * @param serialized The serialized LocalValue object
14505
+ * @returns The original JavaScript value/object
14506
+ */
14507
+ static fromLocalValue(serialized) {
14508
+ const type = serialized[TYPE_CONSTANT];
14509
+ const value = VALUE_CONSTANT in serialized ? serialized[VALUE_CONSTANT] : void 0;
14510
+ switch (type) {
14511
+ case "string" /* String */:
14512
+ return value;
14513
+ case "boolean" /* Boolean */:
14514
+ return value;
14515
+ case "bigint" /* BigInt */:
14516
+ return BigInt(value);
14517
+ case "undefined" /* Undefined */:
14518
+ return void 0;
14519
+ case "null" /* Null */:
14520
+ return null;
14521
+ case "number" /* Number */:
14522
+ if (value === "NaN") return NaN;
14523
+ if (value === "-0") return -0;
14524
+ if (value === "Infinity") return Infinity;
14525
+ if (value === "-Infinity") return -Infinity;
14526
+ return value;
14527
+ case "array" /* Array */:
14528
+ return value.map((item) => _RemoteValue.fromLocalValue(item));
14529
+ case "date" /* Date */:
14530
+ return new Date(value);
14531
+ case "map" /* Map */:
14532
+ const map2 = /* @__PURE__ */ new Map();
14533
+ for (const [key, val] of value) {
14534
+ const deserializedKey = typeof key === "object" && key !== null ? _RemoteValue.fromLocalValue(key) : key;
14535
+ const deserializedValue = _RemoteValue.fromLocalValue(val);
14536
+ map2.set(deserializedKey, deserializedValue);
14537
+ }
14538
+ return map2;
14539
+ case "object" /* Object */:
14540
+ const obj = {};
14541
+ for (const [key, val] of value) {
14542
+ obj[key] = _RemoteValue.fromLocalValue(val);
14543
+ }
14544
+ return obj;
14545
+ case "regexp" /* RegularExpression */:
14546
+ const { pattern, flags } = value;
14547
+ return new RegExp(pattern, flags);
14548
+ case "set" /* Set */:
14549
+ const set = /* @__PURE__ */ new Set();
14550
+ for (const item of value) {
14551
+ set.add(_RemoteValue.fromLocalValue(item));
14552
+ }
14553
+ return set;
14554
+ case "symbol" /* Symbol */:
14555
+ return Symbol(value);
14556
+ default:
14557
+ throw new Error(`Unsupported type: ${type}`);
14706
14558
  }
14707
14559
  }
14708
- if (isNode) {
14709
- Object.defineProperty(obj, "parent", {
14710
- configurable: true,
14711
- writable: true,
14712
- enumerable: false,
14713
- value: parent || null
14714
- });
14715
- }
14716
- return obj;
14717
- };
14718
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
14719
-
14720
- // src/compiler/style/css-parser/get-css-selectors.ts
14721
- var getCssSelectors = (sel) => {
14722
- SELECTORS.all.length = SELECTORS.tags.length = SELECTORS.classNames.length = SELECTORS.ids.length = SELECTORS.attrs.length = 0;
14723
- sel = sel.replace(/\./g, " .").replace(/\#/g, " #").replace(/\[/g, " [").replace(/\>/g, " > ").replace(/\+/g, " + ").replace(/\~/g, " ~ ").replace(/\*/g, " * ").replace(/\:not\((.*?)\)/g, " ");
14724
- const items = sel.split(" ");
14725
- for (let i = 0, l = items.length; i < l; i++) {
14726
- items[i] = items[i].split(":")[0];
14727
- if (items[i].length === 0) continue;
14728
- if (items[i].charAt(0) === ".") {
14729
- SELECTORS.classNames.push(items[i].slice(1));
14730
- } else if (items[i].charAt(0) === "#") {
14731
- SELECTORS.ids.push(items[i].slice(1));
14732
- } else if (items[i].charAt(0) === "[") {
14733
- items[i] = items[i].slice(1).split("=")[0].split("]")[0].trim();
14734
- SELECTORS.attrs.push(items[i].toLowerCase());
14735
- } else if (/[a-z]/g.test(items[i].charAt(0))) {
14736
- SELECTORS.tags.push(items[i].toLowerCase());
14560
+ /**
14561
+ * Utility method to deserialize multiple LocalValues at once
14562
+ *
14563
+ * @param serializedValues Array of serialized LocalValue objects
14564
+ * @returns Array of deserialized JavaScript values
14565
+ */
14566
+ static fromLocalValueArray(serializedValues) {
14567
+ return serializedValues.map((value) => _RemoteValue.fromLocalValue(value));
14568
+ }
14569
+ /**
14570
+ * Verifies if the given object matches the structure of a serialized LocalValue
14571
+ *
14572
+ * @param obj Object to verify
14573
+ * @returns boolean indicating if the object has LocalValue structure
14574
+ */
14575
+ static isLocalValueObject(obj) {
14576
+ if (typeof obj !== "object" || obj === null) {
14577
+ return false;
14578
+ }
14579
+ if (!obj.hasOwnProperty(TYPE_CONSTANT)) {
14580
+ return false;
14581
+ }
14582
+ const type = obj[TYPE_CONSTANT];
14583
+ const hasTypeProperty = Object.values({ ...PrimitiveType, ...NonPrimitiveType }).includes(type);
14584
+ if (!hasTypeProperty) {
14585
+ return false;
14586
+ }
14587
+ if (type !== "null" /* Null */ && type !== "undefined" /* Undefined */) {
14588
+ return obj.hasOwnProperty(VALUE_CONSTANT);
14737
14589
  }
14590
+ return true;
14738
14591
  }
14739
- SELECTORS.classNames = SELECTORS.classNames.sort((a, b) => {
14740
- if (a.length < b.length) return -1;
14741
- if (a.length > b.length) return 1;
14742
- return 0;
14743
- });
14744
- return SELECTORS;
14745
- };
14746
- var SELECTORS = {
14747
- all: [],
14748
- tags: [],
14749
- classNames: [],
14750
- ids: [],
14751
- attrs: []
14752
14592
  };
14753
14593
 
14754
- // src/compiler/style/css-parser/serialize-css.ts
14755
- var serializeCss = (stylesheet, serializeOpts) => {
14756
- const usedSelectors = serializeOpts.usedSelectors || null;
14757
- const opts = {
14758
- usedSelectors: usedSelectors || null,
14759
- hasUsedAttrs: !!usedSelectors && usedSelectors.attrs.size > 0,
14760
- hasUsedClassNames: !!usedSelectors && usedSelectors.classNames.size > 0,
14761
- hasUsedIds: !!usedSelectors && usedSelectors.ids.size > 0,
14762
- hasUsedTags: !!usedSelectors && usedSelectors.tags.size > 0
14763
- };
14764
- const rules = stylesheet.rules;
14765
- if (!rules) {
14766
- return "";
14767
- }
14768
- const rulesLen = rules.length;
14769
- const out = [];
14770
- for (let i = 0; i < rulesLen; i++) {
14771
- out.push(serializeCssVisitNode(opts, rules[i], i, rulesLen));
14772
- }
14773
- return out.join("");
14774
- };
14775
- var serializeCssVisitNode = (opts, node, index, len) => {
14594
+ // src/runtime/dom-extras.ts
14595
+ import { BUILD as BUILD9 } from "@stencil/core/internal/app-data";
14596
+
14597
+ // src/runtime/slot-polyfill-utils.ts
14598
+ import { BUILD as BUILD8 } from "@stencil/core/internal/app-data";
14599
+
14600
+ // src/runtime/profile.ts
14601
+ import { BUILD as BUILD10 } from "@stencil/core/internal/app-data";
14602
+
14603
+ // src/runtime/vdom/h.ts
14604
+ import { BUILD as BUILD11 } from "@stencil/core/internal/app-data";
14605
+
14606
+ // src/runtime/initialize-component.ts
14607
+ import { BUILD as BUILD23 } from "@stencil/core/internal/app-data";
14608
+
14609
+ // src/utils/shadow-css.ts
14610
+ /**
14611
+ * @license
14612
+ * Copyright Google Inc. All Rights Reserved.
14613
+ *
14614
+ * Use of this source code is governed by an MIT-style license that can be
14615
+ * found in the LICENSE file at https://angular.io/license
14616
+ *
14617
+ * This file is a port of shadowCSS from `webcomponents.js` to TypeScript.
14618
+ * https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js
14619
+ * https://github.com/angular/angular/blob/master/packages/compiler/src/shadow_css.ts
14620
+ */
14621
+ var _polyfillHost = "-shadowcsshost";
14622
+ var _polyfillSlotted = "-shadowcssslotted";
14623
+ var _polyfillHostContext = "-shadowcsscontext";
14624
+ var _parenSuffix = ")(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)";
14625
+ var _cssColonHostRe = new RegExp("(" + _polyfillHost + _parenSuffix, "gim");
14626
+ var _cssColonHostContextRe = new RegExp("(" + _polyfillHostContext + _parenSuffix, "gim");
14627
+ var _cssColonSlottedRe = new RegExp("(" + _polyfillSlotted + _parenSuffix, "gim");
14628
+ var _polyfillHostNoCombinator = _polyfillHost + "-no-combinator";
14629
+ var createSupportsRuleRe = (selector) => new RegExp(`((?<!(^@supports(.*)))|(?<={.*))(${selector}\\b)`, "gim");
14630
+ var _colonSlottedRe = createSupportsRuleRe("::slotted");
14631
+ var _colonHostRe = createSupportsRuleRe(":host");
14632
+ var _colonHostContextRe = createSupportsRuleRe(":host-context");
14633
+
14634
+ // src/runtime/mode.ts
14635
+ var setMode = (handler) => modeResolutionChain.push(handler);
14636
+
14637
+ // src/runtime/proxy-component.ts
14638
+ import { BUILD as BUILD22 } from "@stencil/core/internal/app-data";
14639
+
14640
+ // src/runtime/set-value.ts
14641
+ import { BUILD as BUILD21 } from "@stencil/core/internal/app-data";
14642
+
14643
+ // src/runtime/parse-property-value.ts
14644
+ import { BUILD as BUILD13 } from "@stencil/core/internal/app-data";
14645
+
14646
+ // src/runtime/update-component.ts
14647
+ import { BUILD as BUILD20, NAMESPACE } from "@stencil/core/internal/app-data";
14648
+
14649
+ // src/runtime/event-emitter.ts
14650
+ import { BUILD as BUILD15 } from "@stencil/core/internal/app-data";
14651
+
14652
+ // src/runtime/element.ts
14653
+ import { BUILD as BUILD14 } from "@stencil/core/internal/app-data";
14654
+
14655
+ // src/runtime/styles.ts
14656
+ import { BUILD as BUILD16 } from "@stencil/core/internal/app-data";
14657
+
14658
+ // src/runtime/vdom/vdom-render.ts
14659
+ import { BUILD as BUILD19 } from "@stencil/core/internal/app-data";
14660
+
14661
+ // src/runtime/vdom/update-element.ts
14662
+ import { BUILD as BUILD18 } from "@stencil/core/internal/app-data";
14663
+
14664
+ // src/runtime/vdom/set-accessor.ts
14665
+ import { BUILD as BUILD17 } from "@stencil/core/internal/app-data";
14666
+ var CAPTURE_EVENT_SUFFIX = "Capture";
14667
+ var CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + "$");
14668
+
14669
+ // src/runtime/disconnected-callback.ts
14670
+ import { BUILD as BUILD25 } from "@stencil/core/internal/app-data";
14671
+
14672
+ // src/runtime/bootstrap-lazy.ts
14673
+ import { BUILD as BUILD27 } from "@stencil/core/internal/app-data";
14674
+
14675
+ // src/runtime/host-listener.ts
14676
+ import { BUILD as BUILD28 } from "@stencil/core/internal/app-data";
14677
+
14678
+ // src/compiler/html/canonical-link.ts
14679
+ var updateCanonicalLink = (doc, href) => {
14776
14680
  var _a2;
14777
- const nodeType = node.type;
14778
- if (nodeType === 4 /* Declaration */) {
14779
- return serializeCssDeclaration(node, index, len);
14780
- }
14781
- if (nodeType === 13 /* Rule */) {
14782
- return serializeCssRule(opts, node);
14783
- }
14784
- if (nodeType === 1 /* Comment */) {
14785
- if (((_a2 = node.comment) == null ? void 0 : _a2[0]) === "!") {
14786
- return `/*${node.comment}*/`;
14787
- } else {
14788
- return "";
14681
+ let canonicalLinkElm = doc.head.querySelector('link[rel="canonical"]');
14682
+ if (typeof href === "string") {
14683
+ if (canonicalLinkElm == null) {
14684
+ canonicalLinkElm = doc.createElement("link");
14685
+ canonicalLinkElm.setAttribute("rel", "canonical");
14686
+ doc.head.appendChild(canonicalLinkElm);
14687
+ }
14688
+ canonicalLinkElm.setAttribute("href", href);
14689
+ } else {
14690
+ if (canonicalLinkElm != null) {
14691
+ const existingHref = canonicalLinkElm.getAttribute("href");
14692
+ if (!existingHref) {
14693
+ (_a2 = canonicalLinkElm.parentNode) == null ? void 0 : _a2.removeChild(canonicalLinkElm);
14694
+ }
14789
14695
  }
14790
14696
  }
14791
- if (nodeType === 10 /* Media */) {
14792
- return serializeCssMedia(opts, node);
14793
- }
14794
- if (nodeType === 8 /* KeyFrames */) {
14795
- return serializeCssKeyframes(opts, node);
14796
- }
14797
- if (nodeType === 9 /* KeyFrame */) {
14798
- return serializeCssKeyframe(opts, node);
14799
- }
14800
- if (nodeType === 5 /* FontFace */) {
14801
- return serializeCssFontFace(opts, node);
14802
- }
14803
- if (nodeType === 15 /* Supports */) {
14804
- return serializeCssSupports(opts, node);
14805
- }
14806
- if (nodeType === 7 /* Import */) {
14807
- return "@import " + node.import + ";";
14808
- }
14809
- if (nodeType === 0 /* Charset */) {
14810
- return "@charset " + node.charset + ";";
14811
- }
14812
- if (nodeType === 12 /* Page */) {
14813
- return serializeCssPage(opts, node);
14814
- }
14815
- if (nodeType === 6 /* Host */) {
14816
- return "@host{" + serializeCssMapVisit(opts, node.rules) + "}";
14817
- }
14818
- if (nodeType === 2 /* CustomMedia */) {
14819
- return "@custom-media " + node.name + " " + node.media + ";";
14820
- }
14821
- if (nodeType === 3 /* Document */) {
14822
- return serializeCssDocument(opts, node);
14823
- }
14824
- if (nodeType === 11 /* Namespace */) {
14825
- return "@namespace " + node.namespace + ";";
14826
- }
14827
- return "";
14828
14697
  };
14829
- var serializeCssRule = (opts, node) => {
14830
- var _a2, _b;
14831
- const decls = node.declarations;
14832
- const usedSelectors = opts.usedSelectors;
14833
- const selectors = (_b = (_a2 = node.selectors) == null ? void 0 : _a2.slice()) != null ? _b : [];
14834
- if (decls == null || decls.length === 0) {
14835
- return "";
14698
+
14699
+ // src/compiler/html/relocate-meta-charset.ts
14700
+ var relocateMetaCharset = (doc) => {
14701
+ const head = doc.head;
14702
+ let charsetElm = head.querySelector("meta[charset]");
14703
+ if (charsetElm == null) {
14704
+ charsetElm = doc.createElement("meta");
14705
+ charsetElm.setAttribute("charset", "utf-8");
14706
+ } else {
14707
+ charsetElm.remove();
14836
14708
  }
14837
- if (usedSelectors) {
14838
- let i;
14839
- let j;
14840
- let include = true;
14841
- for (i = selectors.length - 1; i >= 0; i--) {
14842
- const sel = getCssSelectors(selectors[i]);
14843
- include = true;
14844
- let jlen = sel.classNames.length;
14845
- if (jlen > 0 && opts.hasUsedClassNames) {
14846
- for (j = 0; j < jlen; j++) {
14847
- if (!usedSelectors.classNames.has(sel.classNames[j])) {
14848
- include = false;
14849
- break;
14850
- }
14851
- }
14852
- }
14853
- if (include && opts.hasUsedTags) {
14854
- jlen = sel.tags.length;
14855
- if (jlen > 0) {
14856
- for (j = 0; j < jlen; j++) {
14857
- if (!usedSelectors.tags.has(sel.tags[j])) {
14858
- include = false;
14859
- break;
14860
- }
14861
- }
14862
- }
14863
- }
14864
- if (include && opts.hasUsedAttrs) {
14865
- jlen = sel.attrs.length;
14866
- if (jlen > 0) {
14867
- for (j = 0; j < jlen; j++) {
14868
- if (!usedSelectors.attrs.has(sel.attrs[j])) {
14869
- include = false;
14870
- break;
14871
- }
14872
- }
14873
- }
14874
- }
14875
- if (include && opts.hasUsedIds) {
14876
- jlen = sel.ids.length;
14877
- if (jlen > 0) {
14878
- for (j = 0; j < jlen; j++) {
14879
- if (!usedSelectors.ids.has(sel.ids[j])) {
14880
- include = false;
14881
- break;
14882
- }
14883
- }
14709
+ head.insertBefore(charsetElm, head.firstChild);
14710
+ };
14711
+
14712
+ // src/compiler/style/css-parser/parse-css.ts
14713
+ var parseCss = (css, filePath) => {
14714
+ let lineno = 1;
14715
+ let column = 1;
14716
+ const diagnostics = [];
14717
+ const updatePosition = (str) => {
14718
+ const lines = str.match(/\n/g);
14719
+ if (lines) lineno += lines.length;
14720
+ const i = str.lastIndexOf("\n");
14721
+ column = ~i ? str.length - i : column + str.length;
14722
+ };
14723
+ const position = () => {
14724
+ const start = { line: lineno, column };
14725
+ return (node) => {
14726
+ node.position = new ParsePosition(start);
14727
+ whitespace();
14728
+ return node;
14729
+ };
14730
+ };
14731
+ const error = (msg) => {
14732
+ const srcLines = css.split("\n");
14733
+ const d = {
14734
+ level: "error",
14735
+ type: "css",
14736
+ language: "css",
14737
+ header: "CSS Parse",
14738
+ messageText: msg,
14739
+ absFilePath: filePath,
14740
+ lines: [
14741
+ {
14742
+ lineIndex: lineno - 1,
14743
+ lineNumber: lineno,
14744
+ errorCharStart: column,
14745
+ text: css[lineno - 1]
14884
14746
  }
14885
- }
14886
- if (!include) {
14887
- selectors.splice(i, 1);
14888
- }
14747
+ ]
14748
+ };
14749
+ if (lineno > 1) {
14750
+ const previousLine = {
14751
+ lineIndex: lineno - 1,
14752
+ lineNumber: lineno - 1,
14753
+ text: css[lineno - 2],
14754
+ errorCharStart: -1,
14755
+ errorLength: -1
14756
+ };
14757
+ d.lines.unshift(previousLine);
14889
14758
  }
14890
- }
14891
- if (selectors.length === 0) {
14892
- return "";
14893
- }
14894
- const cleanedSelectors = [];
14895
- let cleanedSelector = "";
14896
- if (node.selectors) {
14897
- for (const selector of node.selectors) {
14898
- cleanedSelector = removeSelectorWhitespace(selector);
14899
- if (!cleanedSelectors.includes(cleanedSelector)) {
14900
- cleanedSelectors.push(cleanedSelector);
14759
+ if (lineno + 2 < srcLines.length) {
14760
+ const nextLine = {
14761
+ lineIndex: lineno,
14762
+ lineNumber: lineno + 1,
14763
+ text: srcLines[lineno],
14764
+ errorCharStart: -1,
14765
+ errorLength: -1
14766
+ };
14767
+ d.lines.push(nextLine);
14768
+ }
14769
+ diagnostics.push(d);
14770
+ return null;
14771
+ };
14772
+ const stylesheet = () => {
14773
+ const rulesList = rules();
14774
+ return {
14775
+ type: 14 /* StyleSheet */,
14776
+ stylesheet: {
14777
+ source: filePath,
14778
+ rules: rulesList
14901
14779
  }
14780
+ };
14781
+ };
14782
+ const open = () => match(/^{\s*/);
14783
+ const close = () => match(/^}/);
14784
+ const match = (re) => {
14785
+ const m = re.exec(css);
14786
+ if (!m) return;
14787
+ const str = m[0];
14788
+ updatePosition(str);
14789
+ css = css.slice(str.length);
14790
+ return m;
14791
+ };
14792
+ const rules = () => {
14793
+ let node;
14794
+ const rules2 = [];
14795
+ whitespace();
14796
+ comments(rules2);
14797
+ while (css.length && css.charAt(0) !== "}" && (node = atrule() || rule())) {
14798
+ rules2.push(node);
14799
+ comments(rules2);
14902
14800
  }
14903
- }
14904
- return `${cleanedSelectors}{${serializeCssMapVisit(opts, decls)}}`;
14905
- };
14906
- var serializeCssDeclaration = (node, index, len) => {
14907
- if (node.value === "") {
14908
- return "";
14909
- }
14910
- if (len - 1 === index) {
14911
- return node.property + ":" + node.value;
14912
- }
14913
- return node.property + ":" + node.value + ";";
14914
- };
14915
- var serializeCssMedia = (opts, node) => {
14916
- const mediaCss = serializeCssMapVisit(opts, node.rules);
14917
- if (mediaCss === "") {
14918
- return "";
14919
- }
14920
- return "@media " + removeMediaWhitespace(node.media) + "{" + mediaCss + "}";
14921
- };
14922
- var serializeCssKeyframes = (opts, node) => {
14923
- const keyframesCss = serializeCssMapVisit(opts, node.keyframes);
14924
- if (keyframesCss === "") {
14925
- return "";
14926
- }
14927
- return "@" + (node.vendor || "") + "keyframes " + node.name + "{" + keyframesCss + "}";
14928
- };
14929
- var serializeCssKeyframe = (opts, node) => {
14930
- var _a2, _b;
14931
- return ((_b = (_a2 = node.values) == null ? void 0 : _a2.join(",")) != null ? _b : "") + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
14932
- };
14933
- var serializeCssFontFace = (opts, node) => {
14934
- const fontCss = serializeCssMapVisit(opts, node.declarations);
14935
- if (fontCss === "") {
14936
- return "";
14937
- }
14938
- return "@font-face{" + fontCss + "}";
14939
- };
14940
- var serializeCssSupports = (opts, node) => {
14941
- const supportsCss = serializeCssMapVisit(opts, node.rules);
14942
- if (supportsCss === "") {
14943
- return "";
14944
- }
14945
- return "@supports " + node.supports + "{" + supportsCss + "}";
14946
- };
14947
- var serializeCssPage = (opts, node) => {
14948
- var _a2, _b;
14949
- const sel = (_b = (_a2 = node.selectors) == null ? void 0 : _a2.join(", ")) != null ? _b : "";
14950
- return "@page " + sel + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
14951
- };
14952
- var serializeCssDocument = (opts, node) => {
14953
- const documentCss = serializeCssMapVisit(opts, node.rules);
14954
- const doc = "@" + (node.vendor || "") + "document " + node.document;
14955
- if (documentCss === "") {
14956
- return "";
14957
- }
14958
- return doc + "{" + documentCss + "}";
14959
- };
14960
- var serializeCssMapVisit = (opts, nodes) => {
14961
- let rtn = "";
14962
- if (nodes) {
14963
- for (let i = 0, len = nodes.length; i < len; i++) {
14964
- rtn += serializeCssVisitNode(opts, nodes[i], i, len);
14801
+ return rules2;
14802
+ };
14803
+ const whitespace = () => match(/^\s*/);
14804
+ const comments = (rules2) => {
14805
+ let c;
14806
+ rules2 = rules2 || [];
14807
+ while (c = comment()) {
14808
+ rules2.push(c);
14965
14809
  }
14966
- }
14967
- return rtn;
14968
- };
14969
- var removeSelectorWhitespace = (selector) => {
14970
- let rtn = "";
14971
- let char = "";
14972
- let inAttr = false;
14973
- selector = selector.trim();
14974
- for (let i = 0, l = selector.length; i < l; i++) {
14975
- char = selector[i];
14976
- if (char === "[" && rtn[rtn.length - 1] !== "\\") {
14977
- inAttr = true;
14978
- } else if (char === "]" && rtn[rtn.length - 1] !== "\\") {
14979
- inAttr = false;
14810
+ return rules2;
14811
+ };
14812
+ const comment = () => {
14813
+ const pos = position();
14814
+ if ("/" !== css.charAt(0) || "*" !== css.charAt(1)) return null;
14815
+ let i = 2;
14816
+ while ("" !== css.charAt(i) && ("*" !== css.charAt(i) || "/" !== css.charAt(i + 1))) ++i;
14817
+ i += 2;
14818
+ if ("" === css.charAt(i - 1)) {
14819
+ return error("End of comment missing");
14980
14820
  }
14981
- if (!inAttr && CSS_WS_REG.test(char)) {
14982
- if (CSS_NEXT_CHAR_REG.test(selector[i + 1])) {
14983
- continue;
14984
- }
14985
- if (CSS_PREV_CHAR_REG.test(rtn[rtn.length - 1])) {
14986
- continue;
14987
- }
14988
- rtn += " ";
14989
- } else {
14990
- rtn += char;
14821
+ const comment2 = css.slice(2, i - 2);
14822
+ column += 2;
14823
+ updatePosition(comment2);
14824
+ css = css.slice(i);
14825
+ column += 2;
14826
+ return pos({
14827
+ type: 1 /* Comment */,
14828
+ comment: comment2
14829
+ });
14830
+ };
14831
+ const selector = () => {
14832
+ const m = match(/^([^{]+)/);
14833
+ if (!m) return null;
14834
+ return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, "").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m2) {
14835
+ return m2.replace(/,/g, "\u200C");
14836
+ }).split(/\s*(?![^(]*\)),\s*/).map(function(s) {
14837
+ return s.replace(/\u200C/g, ",");
14838
+ });
14839
+ };
14840
+ const declaration = () => {
14841
+ const pos = position();
14842
+ let prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
14843
+ if (!prop) return null;
14844
+ prop = trim(prop[0]);
14845
+ if (!match(/^:\s*/)) return error(`property missing ':'`);
14846
+ const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
14847
+ const ret = pos({
14848
+ type: 4 /* Declaration */,
14849
+ property: prop.replace(commentre, ""),
14850
+ value: val ? trim(val[0]).replace(commentre, "") : ""
14851
+ });
14852
+ match(/^[;\s]*/);
14853
+ return ret;
14854
+ };
14855
+ const declarations = () => {
14856
+ const decls = [];
14857
+ if (!open()) return error(`missing '{'`);
14858
+ comments(decls);
14859
+ let decl;
14860
+ while (decl = declaration()) {
14861
+ decls.push(decl);
14862
+ comments(decls);
14991
14863
  }
14992
- }
14993
- return rtn;
14994
- };
14995
- var removeMediaWhitespace = (media) => {
14996
- var _a2;
14997
- let rtn = "";
14998
- let char = "";
14999
- media = (_a2 = media == null ? void 0 : media.trim()) != null ? _a2 : "";
15000
- for (let i = 0, l = media.length; i < l; i++) {
15001
- char = media[i];
15002
- if (CSS_WS_REG.test(char)) {
15003
- if (CSS_WS_REG.test(rtn[rtn.length - 1])) {
15004
- continue;
15005
- }
15006
- rtn += " ";
15007
- } else {
15008
- rtn += char;
14864
+ if (!close()) return error(`missing '}'`);
14865
+ return decls;
14866
+ };
14867
+ const keyframe = () => {
14868
+ let m;
14869
+ const values = [];
14870
+ const pos = position();
14871
+ while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
14872
+ values.push(m[1]);
14873
+ match(/^,\s*/);
15009
14874
  }
15010
- }
15011
- return rtn;
15012
- };
15013
- var CSS_WS_REG = /\s/;
15014
- var CSS_NEXT_CHAR_REG = /[>\(\)\~\,\+\s]/;
15015
- var CSS_PREV_CHAR_REG = /[>\(\~\,\+]/;
15016
-
15017
- // src/compiler/style/css-parser/used-selectors.ts
15018
- var getUsedSelectors = (elm) => {
15019
- const usedSelectors = {
15020
- attrs: /* @__PURE__ */ new Set(),
15021
- classNames: /* @__PURE__ */ new Set(),
15022
- ids: /* @__PURE__ */ new Set(),
15023
- tags: /* @__PURE__ */ new Set()
14875
+ if (!values.length) return null;
14876
+ return pos({
14877
+ type: 9 /* KeyFrame */,
14878
+ values,
14879
+ declarations: declarations()
14880
+ });
14881
+ };
14882
+ const atkeyframes = () => {
14883
+ const pos = position();
14884
+ let m = match(/^@([-\w]+)?keyframes\s*/);
14885
+ if (!m) return null;
14886
+ const vendor = m[1];
14887
+ m = match(/^([-\w]+)\s*/);
14888
+ if (!m) return error(`@keyframes missing name`);
14889
+ const name = m[1];
14890
+ if (!open()) return error(`@keyframes missing '{'`);
14891
+ let frame;
14892
+ let frames = comments();
14893
+ while (frame = keyframe()) {
14894
+ frames.push(frame);
14895
+ frames = frames.concat(comments());
14896
+ }
14897
+ if (!close()) return error(`@keyframes missing '}'`);
14898
+ return pos({
14899
+ type: 8 /* KeyFrames */,
14900
+ name,
14901
+ vendor,
14902
+ keyframes: frames
14903
+ });
14904
+ };
14905
+ const atsupports = () => {
14906
+ const pos = position();
14907
+ const m = match(/^@supports *([^{]+)/);
14908
+ if (!m) return null;
14909
+ const supports = trim(m[1]);
14910
+ if (!open()) return error(`@supports missing '{'`);
14911
+ const style = comments().concat(rules());
14912
+ if (!close()) return error(`@supports missing '}'`);
14913
+ return pos({
14914
+ type: 15 /* Supports */,
14915
+ supports,
14916
+ rules: style
14917
+ });
14918
+ };
14919
+ const athost = () => {
14920
+ const pos = position();
14921
+ const m = match(/^@host\s*/);
14922
+ if (!m) return null;
14923
+ if (!open()) return error(`@host missing '{'`);
14924
+ const style = comments().concat(rules());
14925
+ if (!close()) return error(`@host missing '}'`);
14926
+ return pos({
14927
+ type: 6 /* Host */,
14928
+ rules: style
14929
+ });
14930
+ };
14931
+ const atmedia = () => {
14932
+ const pos = position();
14933
+ const m = match(/^@media *([^{]+)/);
14934
+ if (!m) return null;
14935
+ const media = trim(m[1]);
14936
+ if (!open()) return error(`@media missing '{'`);
14937
+ const style = comments().concat(rules());
14938
+ if (!close()) return error(`@media missing '}'`);
14939
+ return pos({
14940
+ type: 10 /* Media */,
14941
+ media,
14942
+ rules: style
14943
+ });
14944
+ };
14945
+ const atcustommedia = () => {
14946
+ const pos = position();
14947
+ const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
14948
+ if (!m) return null;
14949
+ return pos({
14950
+ type: 2 /* CustomMedia */,
14951
+ name: trim(m[1]),
14952
+ media: trim(m[2])
14953
+ });
14954
+ };
14955
+ const atpage = () => {
14956
+ const pos = position();
14957
+ const m = match(/^@page */);
14958
+ if (!m) return null;
14959
+ const sel = selector() || [];
14960
+ if (!open()) return error(`@page missing '{'`);
14961
+ let decls = comments();
14962
+ let decl;
14963
+ while (decl = declaration()) {
14964
+ decls.push(decl);
14965
+ decls = decls.concat(comments());
14966
+ }
14967
+ if (!close()) return error(`@page missing '}'`);
14968
+ return pos({
14969
+ type: 12 /* Page */,
14970
+ selectors: sel,
14971
+ declarations: decls
14972
+ });
14973
+ };
14974
+ const atdocument = () => {
14975
+ const pos = position();
14976
+ const m = match(/^@([-\w]+)?document *([^{]+)/);
14977
+ if (!m) return null;
14978
+ const vendor = trim(m[1]);
14979
+ const doc = trim(m[2]);
14980
+ if (!open()) return error(`@document missing '{'`);
14981
+ const style = comments().concat(rules());
14982
+ if (!close()) return error(`@document missing '}'`);
14983
+ return pos({
14984
+ type: 3 /* Document */,
14985
+ document: doc,
14986
+ vendor,
14987
+ rules: style
14988
+ });
14989
+ };
14990
+ const atfontface = () => {
14991
+ const pos = position();
14992
+ const m = match(/^@font-face\s*/);
14993
+ if (!m) return null;
14994
+ if (!open()) return error(`@font-face missing '{'`);
14995
+ let decls = comments();
14996
+ let decl;
14997
+ while (decl = declaration()) {
14998
+ decls.push(decl);
14999
+ decls = decls.concat(comments());
15000
+ }
15001
+ if (!close()) return error(`@font-face missing '}'`);
15002
+ return pos({
15003
+ type: 5 /* FontFace */,
15004
+ declarations: decls
15005
+ });
15006
+ };
15007
+ const compileAtrule = (nodeName, nodeType) => {
15008
+ const re = new RegExp("^@" + nodeName + "\\s*([^;]+);");
15009
+ return () => {
15010
+ const pos = position();
15011
+ const m = match(re);
15012
+ if (!m) return null;
15013
+ const node = {
15014
+ type: nodeType
15015
+ };
15016
+ node[nodeName] = m[1].trim();
15017
+ return pos(node);
15018
+ };
15019
+ };
15020
+ const atimport = compileAtrule("import", 7 /* Import */);
15021
+ const atcharset = compileAtrule("charset", 0 /* Charset */);
15022
+ const atnamespace = compileAtrule("namespace", 11 /* Namespace */);
15023
+ const atrule = () => {
15024
+ if (css[0] !== "@") return null;
15025
+ return atkeyframes() || atmedia() || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface();
15026
+ };
15027
+ const rule = () => {
15028
+ const pos = position();
15029
+ const sel = selector();
15030
+ if (!sel) return error("selector missing");
15031
+ comments();
15032
+ return pos({
15033
+ type: 13 /* Rule */,
15034
+ selectors: sel,
15035
+ declarations: declarations()
15036
+ });
15024
15037
  };
15025
- collectUsedSelectors(usedSelectors, elm);
15026
- return usedSelectors;
15027
- };
15028
- var collectUsedSelectors = (usedSelectors, elm) => {
15029
- if (elm != null && elm.nodeType === 1) {
15030
- const children = elm.children;
15031
- const tagName = elm.nodeName.toLowerCase();
15032
- usedSelectors.tags.add(tagName);
15033
- const attributes = elm.attributes;
15034
- for (let i = 0, l = attributes.length; i < l; i++) {
15035
- const attr = attributes.item(i);
15036
- const attrName = attr.name.toLowerCase();
15037
- usedSelectors.attrs.add(attrName);
15038
- if (attrName === "class") {
15039
- const classList = elm.classList;
15040
- for (let i2 = 0, l2 = classList.length; i2 < l2; i2++) {
15041
- usedSelectors.classNames.add(classList.item(i2));
15042
- }
15043
- } else if (attrName === "id") {
15044
- usedSelectors.ids.add(attr.value);
15045
- }
15046
- }
15047
- if (children) {
15048
- for (let i = 0, l = children.length; i < l; i++) {
15049
- collectUsedSelectors(usedSelectors, children[i]);
15050
- }
15051
- }
15052
- }
15053
- };
15054
-
15055
- // src/compiler/html/remove-unused-styles.ts
15056
- var removeUnusedStyles = (doc, diagnostics) => {
15057
- try {
15058
- const styleElms = doc.head.querySelectorAll(`style[data-styles]`);
15059
- const styleLen = styleElms.length;
15060
- if (styleLen > 0) {
15061
- const usedSelectors = getUsedSelectors(doc.documentElement);
15062
- for (let i = 0; i < styleLen; i++) {
15063
- removeUnusedStyleText(usedSelectors, diagnostics, styleElms[i]);
15064
- }
15038
+ class ParsePosition {
15039
+ constructor(start) {
15040
+ this.start = start;
15041
+ this.end = { line: lineno, column };
15042
+ this.source = filePath;
15065
15043
  }
15066
- } catch (e) {
15067
- catchError(diagnostics, e);
15068
15044
  }
15045
+ ParsePosition.prototype.content = css;
15046
+ return {
15047
+ diagnostics,
15048
+ ...addParent(stylesheet())
15049
+ };
15069
15050
  };
15070
- var removeUnusedStyleText = (usedSelectors, diagnostics, styleElm) => {
15071
- try {
15072
- const parseResults = parseCss(styleElm.innerHTML);
15073
- diagnostics.push(...parseResults.diagnostics);
15074
- if (hasError(diagnostics)) {
15075
- return;
15076
- }
15077
- try {
15078
- styleElm.innerHTML = serializeCss(parseResults.stylesheet, {
15079
- usedSelectors
15080
- });
15081
- } catch (e) {
15082
- diagnostics.push({
15083
- level: "warn",
15084
- type: "css",
15085
- header: "CSS Stringify",
15086
- messageText: e,
15087
- lines: []
15051
+ var trim = (str) => str ? str.trim() : "";
15052
+ var addParent = (obj, parent) => {
15053
+ const isNode = obj && typeof obj.type === "string";
15054
+ const childParent = isNode ? obj : parent;
15055
+ for (const k in obj) {
15056
+ const value = obj[k];
15057
+ if (Array.isArray(value)) {
15058
+ value.forEach(function(v) {
15059
+ addParent(v, childParent);
15088
15060
  });
15061
+ } else if (value && typeof value === "object") {
15062
+ addParent(value, childParent);
15089
15063
  }
15090
- } catch (e) {
15091
- diagnostics.push({
15092
- level: "warn",
15093
- type: "css",
15094
- header: "CSS Parse",
15095
- messageText: e,
15096
- lines: []
15064
+ }
15065
+ if (isNode) {
15066
+ Object.defineProperty(obj, "parent", {
15067
+ configurable: true,
15068
+ writable: true,
15069
+ enumerable: false,
15070
+ value: parent || null
15097
15071
  });
15098
15072
  }
15073
+ return obj;
15099
15074
  };
15075
+ var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
15100
15076
 
15101
- // src/hydrate/runner/inspect-element.ts
15102
- function inspectElement(results, elm, depth) {
15103
- const children = [...Array.from(elm.children), ...Array.from(elm.shadowRoot ? elm.shadowRoot.children : [])];
15104
- for (let i = 0, ii = children.length; i < ii; i++) {
15105
- const childElm = children[i];
15106
- const tagName = childElm.nodeName.toLowerCase();
15107
- if (tagName.includes("-")) {
15108
- const cmp = results.components.find((c) => c.tag === tagName);
15109
- if (cmp != null) {
15110
- cmp.count++;
15111
- if (depth > cmp.depth) {
15112
- cmp.depth = depth;
15113
- }
15114
- }
15115
- } else {
15116
- switch (tagName) {
15117
- case "a":
15118
- const anchor = collectAttributes(childElm);
15119
- anchor.href = childElm.href;
15120
- if (typeof anchor.href === "string") {
15121
- if (!results.anchors.some((a) => a.href === anchor.href)) {
15122
- results.anchors.push(anchor);
15123
- }
15124
- }
15125
- break;
15126
- case "img":
15127
- const img = collectAttributes(childElm);
15128
- img.src = childElm.src;
15129
- if (typeof img.src === "string") {
15130
- if (!results.imgs.some((a) => a.src === img.src)) {
15131
- results.imgs.push(img);
15132
- }
15133
- }
15134
- break;
15135
- case "link":
15136
- const link = collectAttributes(childElm);
15137
- link.href = childElm.href;
15138
- if (typeof link.rel === "string" && link.rel.toLowerCase() === "stylesheet") {
15139
- if (typeof link.href === "string") {
15140
- if (!results.styles.some((s) => s.link === link.href)) {
15141
- delete link.rel;
15142
- delete link.type;
15143
- results.styles.push(link);
15144
- }
15145
- }
15146
- }
15147
- break;
15148
- case "script":
15149
- const script = collectAttributes(childElm);
15150
- if (childElm.hasAttribute("src")) {
15151
- script.src = childElm.src;
15152
- if (typeof script.src === "string") {
15153
- if (!results.scripts.some((s) => s.src === script.src)) {
15154
- results.scripts.push(script);
15155
- }
15156
- }
15157
- } else {
15158
- const staticDataKey = childElm.getAttribute("data-stencil-static");
15159
- if (staticDataKey) {
15160
- results.staticData.push({
15161
- id: staticDataKey,
15162
- type: childElm.getAttribute("type"),
15163
- content: childElm.textContent
15164
- });
15165
- }
15166
- }
15167
- break;
15168
- }
15169
- }
15170
- depth++;
15171
- inspectElement(results, childElm, depth);
15172
- }
15173
- }
15174
- function collectAttributes(node) {
15175
- const parsedElm = {};
15176
- const attrs = node.attributes;
15177
- for (let i = 0, ii = attrs.length; i < ii; i++) {
15178
- const attr = attrs.item(i);
15179
- const attrName = attr.nodeName.toLowerCase();
15180
- if (SKIP_ATTRS.has(attrName)) {
15181
- continue;
15182
- }
15183
- const attrValue = attr.nodeValue;
15184
- if (attrName === "class" && attrValue === "") {
15185
- continue;
15077
+ // src/compiler/style/css-parser/get-css-selectors.ts
15078
+ var getCssSelectors = (sel) => {
15079
+ SELECTORS.all.length = SELECTORS.tags.length = SELECTORS.classNames.length = SELECTORS.ids.length = SELECTORS.attrs.length = 0;
15080
+ sel = sel.replace(/\./g, " .").replace(/\#/g, " #").replace(/\[/g, " [").replace(/\>/g, " > ").replace(/\+/g, " + ").replace(/\~/g, " ~ ").replace(/\*/g, " * ").replace(/\:not\((.*?)\)/g, " ");
15081
+ const items = sel.split(" ");
15082
+ for (let i = 0, l = items.length; i < l; i++) {
15083
+ items[i] = items[i].split(":")[0];
15084
+ if (items[i].length === 0) continue;
15085
+ if (items[i].charAt(0) === ".") {
15086
+ SELECTORS.classNames.push(items[i].slice(1));
15087
+ } else if (items[i].charAt(0) === "#") {
15088
+ SELECTORS.ids.push(items[i].slice(1));
15089
+ } else if (items[i].charAt(0) === "[") {
15090
+ items[i] = items[i].slice(1).split("=")[0].split("]")[0].trim();
15091
+ SELECTORS.attrs.push(items[i].toLowerCase());
15092
+ } else if (/[a-z]/g.test(items[i].charAt(0))) {
15093
+ SELECTORS.tags.push(items[i].toLowerCase());
15186
15094
  }
15187
- parsedElm[attrName] = attrValue;
15188
15095
  }
15189
- return parsedElm;
15190
- }
15191
- var SKIP_ATTRS = /* @__PURE__ */ new Set(["s-id", "c-id"]);
15096
+ SELECTORS.classNames = SELECTORS.classNames.sort((a, b) => {
15097
+ if (a.length < b.length) return -1;
15098
+ if (a.length > b.length) return 1;
15099
+ return 0;
15100
+ });
15101
+ return SELECTORS;
15102
+ };
15103
+ var SELECTORS = {
15104
+ all: [],
15105
+ tags: [],
15106
+ classNames: [],
15107
+ ids: [],
15108
+ attrs: []
15109
+ };
15192
15110
 
15193
- // src/hydrate/runner/patch-dom-implementation.ts
15194
- function patchDomImplementation(doc, opts) {
15195
- let win2;
15196
- if (doc.defaultView != null) {
15197
- opts.destroyWindow = true;
15198
- patchWindow(doc.defaultView);
15199
- win2 = doc.defaultView;
15200
- } else {
15201
- opts.destroyWindow = true;
15202
- opts.destroyDocument = false;
15203
- win2 = new MockWindow(false);
15204
- }
15205
- if (win2.document !== doc) {
15206
- win2.document = doc;
15207
- }
15208
- if (doc.defaultView !== win2) {
15209
- doc.defaultView = win2;
15111
+ // src/compiler/style/css-parser/serialize-css.ts
15112
+ var serializeCss = (stylesheet, serializeOpts) => {
15113
+ const usedSelectors = serializeOpts.usedSelectors || null;
15114
+ const opts = {
15115
+ usedSelectors: usedSelectors || null,
15116
+ hasUsedAttrs: !!usedSelectors && usedSelectors.attrs.size > 0,
15117
+ hasUsedClassNames: !!usedSelectors && usedSelectors.classNames.size > 0,
15118
+ hasUsedIds: !!usedSelectors && usedSelectors.ids.size > 0,
15119
+ hasUsedTags: !!usedSelectors && usedSelectors.tags.size > 0
15120
+ };
15121
+ const rules = stylesheet.rules;
15122
+ if (!rules) {
15123
+ return "";
15210
15124
  }
15211
- const HTMLElement2 = doc.documentElement.constructor.prototype;
15212
- if (typeof HTMLElement2.getRootNode !== "function") {
15213
- const elm = doc.createElement("unknown-element");
15214
- const HTMLUnknownElement = elm.constructor.prototype;
15215
- HTMLUnknownElement.getRootNode = getRootNode;
15125
+ const rulesLen = rules.length;
15126
+ const out = [];
15127
+ for (let i = 0; i < rulesLen; i++) {
15128
+ out.push(serializeCssVisitNode(opts, rules[i], i, rulesLen));
15216
15129
  }
15217
- if (typeof doc.createEvent === "function") {
15218
- const CustomEvent2 = doc.createEvent("CustomEvent").constructor;
15219
- if (win2.CustomEvent !== CustomEvent2) {
15220
- win2.CustomEvent = CustomEvent2;
15221
- }
15130
+ return out.join("");
15131
+ };
15132
+ var serializeCssVisitNode = (opts, node, index, len) => {
15133
+ var _a2;
15134
+ const nodeType = node.type;
15135
+ if (nodeType === 4 /* Declaration */) {
15136
+ return serializeCssDeclaration(node, index, len);
15222
15137
  }
15223
- try {
15224
- win2.__stencil_baseURI = doc.baseURI;
15225
- } catch (e) {
15226
- Object.defineProperty(doc, "baseURI", {
15227
- get() {
15228
- const baseElm = doc.querySelector("base[href]");
15229
- if (baseElm) {
15230
- return new URL(baseElm.getAttribute("href"), win2.location.href).href;
15231
- }
15232
- return win2.location.href;
15233
- }
15234
- });
15138
+ if (nodeType === 13 /* Rule */) {
15139
+ return serializeCssRule(opts, node);
15235
15140
  }
15236
- return win2;
15237
- }
15238
- function getRootNode(opts) {
15239
- const isComposed = opts != null && opts.composed === true;
15240
- let node = this;
15241
- while (node.parentNode != null) {
15242
- node = node.parentNode;
15243
- if (isComposed === true && node.parentNode == null && node.host != null) {
15244
- node = node.host;
15141
+ if (nodeType === 1 /* Comment */) {
15142
+ if (((_a2 = node.comment) == null ? void 0 : _a2[0]) === "!") {
15143
+ return `/*${node.comment}*/`;
15144
+ } else {
15145
+ return "";
15245
15146
  }
15246
15147
  }
15247
- return node;
15248
- }
15249
-
15250
- // src/hydrate/runner/render-utils.ts
15251
- function normalizeHydrateOptions(inputOpts) {
15252
- const outputOpts = Object.assign(
15253
- {
15254
- serializeToHtml: false,
15255
- destroyWindow: false,
15256
- destroyDocument: false
15257
- },
15258
- inputOpts || {}
15259
- );
15260
- if (typeof outputOpts.clientHydrateAnnotations !== "boolean") {
15261
- outputOpts.clientHydrateAnnotations = true;
15148
+ if (nodeType === 10 /* Media */) {
15149
+ return serializeCssMedia(opts, node);
15262
15150
  }
15263
- if (typeof outputOpts.constrainTimeouts !== "boolean") {
15264
- outputOpts.constrainTimeouts = true;
15151
+ if (nodeType === 8 /* KeyFrames */) {
15152
+ return serializeCssKeyframes(opts, node);
15265
15153
  }
15266
- if (typeof outputOpts.maxHydrateCount !== "number") {
15267
- outputOpts.maxHydrateCount = 300;
15154
+ if (nodeType === 9 /* KeyFrame */) {
15155
+ return serializeCssKeyframe(opts, node);
15268
15156
  }
15269
- if (typeof outputOpts.runtimeLogging !== "boolean") {
15270
- outputOpts.runtimeLogging = false;
15157
+ if (nodeType === 5 /* FontFace */) {
15158
+ return serializeCssFontFace(opts, node);
15271
15159
  }
15272
- if (typeof outputOpts.timeout !== "number") {
15273
- outputOpts.timeout = 15e3;
15160
+ if (nodeType === 15 /* Supports */) {
15161
+ return serializeCssSupports(opts, node);
15274
15162
  }
15275
- if (Array.isArray(outputOpts.excludeComponents)) {
15276
- outputOpts.excludeComponents = outputOpts.excludeComponents.filter(filterValidTags).map(mapValidTags);
15277
- } else {
15278
- outputOpts.excludeComponents = [];
15163
+ if (nodeType === 7 /* Import */) {
15164
+ return "@import " + node.import + ";";
15279
15165
  }
15280
- if (Array.isArray(outputOpts.staticComponents)) {
15281
- outputOpts.staticComponents = outputOpts.staticComponents.filter(filterValidTags).map(mapValidTags);
15282
- } else {
15283
- outputOpts.staticComponents = [];
15166
+ if (nodeType === 0 /* Charset */) {
15167
+ return "@charset " + node.charset + ";";
15284
15168
  }
15285
- return outputOpts;
15286
- }
15287
- function filterValidTags(tag) {
15288
- return typeof tag === "string" && tag.includes("-");
15289
- }
15290
- function mapValidTags(tag) {
15291
- return tag.trim().toLowerCase();
15292
- }
15293
- function generateHydrateResults(opts) {
15294
- if (typeof opts.url !== "string") {
15295
- opts.url = `https://hydrate.stenciljs.com/`;
15169
+ if (nodeType === 12 /* Page */) {
15170
+ return serializeCssPage(opts, node);
15296
15171
  }
15297
- if (typeof opts.buildId !== "string") {
15298
- opts.buildId = createHydrateBuildId();
15172
+ if (nodeType === 6 /* Host */) {
15173
+ return "@host{" + serializeCssMapVisit(opts, node.rules) + "}";
15299
15174
  }
15300
- const results = {
15301
- buildId: opts.buildId,
15302
- diagnostics: [],
15303
- url: opts.url,
15304
- host: null,
15305
- hostname: null,
15306
- href: null,
15307
- pathname: null,
15308
- port: null,
15309
- search: null,
15310
- hash: null,
15311
- html: null,
15312
- httpStatus: null,
15313
- hydratedCount: 0,
15314
- anchors: [],
15315
- components: [],
15316
- imgs: [],
15317
- scripts: [],
15318
- staticData: [],
15319
- styles: [],
15320
- title: null
15321
- };
15322
- try {
15323
- const url = new URL(opts.url, `https://hydrate.stenciljs.com/`);
15324
- results.url = url.href;
15325
- results.host = url.host;
15326
- results.hostname = url.hostname;
15327
- results.href = url.href;
15328
- results.port = url.port;
15329
- results.pathname = url.pathname;
15330
- results.search = url.search;
15331
- results.hash = url.hash;
15332
- } catch (e) {
15333
- renderCatchError(results, e);
15175
+ if (nodeType === 2 /* CustomMedia */) {
15176
+ return "@custom-media " + node.name + " " + node.media + ";";
15334
15177
  }
15335
- return results;
15336
- }
15337
- var createHydrateBuildId = () => {
15338
- let chars = "abcdefghijklmnopqrstuvwxyz";
15339
- let buildId = "";
15340
- while (buildId.length < 8) {
15341
- const char = chars[Math.floor(Math.random() * chars.length)];
15342
- buildId += char;
15343
- if (buildId.length === 1) {
15344
- chars += "0123456789";
15345
- }
15178
+ if (nodeType === 3 /* Document */) {
15179
+ return serializeCssDocument(opts, node);
15346
15180
  }
15347
- return buildId;
15181
+ if (nodeType === 11 /* Namespace */) {
15182
+ return "@namespace " + node.namespace + ";";
15183
+ }
15184
+ return "";
15348
15185
  };
15349
- function renderBuildDiagnostic(results, level, header, msg) {
15350
- const diagnostic = {
15351
- level,
15352
- type: "build",
15353
- header,
15354
- messageText: msg,
15355
- relFilePath: void 0,
15356
- absFilePath: void 0,
15357
- lines: []
15358
- };
15359
- if (results.pathname) {
15360
- if (results.pathname !== "/") {
15361
- diagnostic.header += ": " + results.pathname;
15362
- }
15363
- } else if (results.url) {
15364
- diagnostic.header += ": " + results.url;
15186
+ var serializeCssRule = (opts, node) => {
15187
+ var _a2, _b;
15188
+ const decls = node.declarations;
15189
+ const usedSelectors = opts.usedSelectors;
15190
+ const selectors = (_b = (_a2 = node.selectors) == null ? void 0 : _a2.slice()) != null ? _b : [];
15191
+ if (decls == null || decls.length === 0) {
15192
+ return "";
15365
15193
  }
15366
- results.diagnostics.push(diagnostic);
15367
- return diagnostic;
15368
- }
15369
- function renderBuildError(results, msg) {
15370
- return renderBuildDiagnostic(results, "error", "Hydrate Error", msg || "");
15371
- }
15372
- function renderCatchError(results, err2) {
15373
- const diagnostic = renderBuildError(results);
15374
- if (err2 != null) {
15375
- if (err2.stack != null) {
15376
- diagnostic.messageText = err2.stack.toString();
15377
- } else {
15378
- if (err2.message != null) {
15379
- diagnostic.messageText = err2.message.toString();
15380
- } else {
15381
- diagnostic.messageText = err2.toString();
15194
+ if (usedSelectors) {
15195
+ let i;
15196
+ let j;
15197
+ let include = true;
15198
+ for (i = selectors.length - 1; i >= 0; i--) {
15199
+ const sel = getCssSelectors(selectors[i]);
15200
+ include = true;
15201
+ let jlen = sel.classNames.length;
15202
+ if (jlen > 0 && opts.hasUsedClassNames) {
15203
+ for (j = 0; j < jlen; j++) {
15204
+ if (!usedSelectors.classNames.has(sel.classNames[j])) {
15205
+ include = false;
15206
+ break;
15207
+ }
15208
+ }
15382
15209
  }
15383
- }
15384
- }
15385
- return diagnostic;
15386
- }
15387
-
15388
- // src/hydrate/runner/runtime-log.ts
15389
- function runtimeLogging(win2, opts, results) {
15390
- try {
15391
- const pathname = win2.location.pathname;
15392
- win2.console.error = (...msgs) => {
15393
- const errMsg = msgs.reduce((errMsg2, m) => {
15394
- if (m) {
15395
- if (m.stack != null) {
15396
- return errMsg2 + " " + String(m.stack);
15397
- } else {
15398
- if (m.message != null) {
15399
- return errMsg2 + " " + String(m.message);
15210
+ if (include && opts.hasUsedTags) {
15211
+ jlen = sel.tags.length;
15212
+ if (jlen > 0) {
15213
+ for (j = 0; j < jlen; j++) {
15214
+ if (!usedSelectors.tags.has(sel.tags[j])) {
15215
+ include = false;
15216
+ break;
15217
+ }
15218
+ }
15219
+ }
15220
+ }
15221
+ if (include && opts.hasUsedAttrs) {
15222
+ jlen = sel.attrs.length;
15223
+ if (jlen > 0) {
15224
+ for (j = 0; j < jlen; j++) {
15225
+ if (!usedSelectors.attrs.has(sel.attrs[j])) {
15226
+ include = false;
15227
+ break;
15228
+ }
15229
+ }
15230
+ }
15231
+ }
15232
+ if (include && opts.hasUsedIds) {
15233
+ jlen = sel.ids.length;
15234
+ if (jlen > 0) {
15235
+ for (j = 0; j < jlen; j++) {
15236
+ if (!usedSelectors.ids.has(sel.ids[j])) {
15237
+ include = false;
15238
+ break;
15400
15239
  }
15401
15240
  }
15402
15241
  }
15403
- return String(m);
15404
- }, "").trim();
15405
- if (errMsg !== "") {
15406
- renderCatchError(results, errMsg);
15407
- if (opts.runtimeLogging) {
15408
- runtimeLog(pathname, "error", [errMsg]);
15409
- }
15410
15242
  }
15411
- };
15412
- win2.console.debug = (...msgs) => {
15413
- renderBuildDiagnostic(results, "debug", "Hydrate Debug", [...msgs].join(", "));
15414
- if (opts.runtimeLogging) {
15415
- runtimeLog(pathname, "debug", msgs);
15243
+ if (!include) {
15244
+ selectors.splice(i, 1);
15416
15245
  }
15417
- };
15418
- if (opts.runtimeLogging) {
15419
- ["log", "warn", "assert", "info", "trace"].forEach((type) => {
15420
- win2.console[type] = (...msgs) => {
15421
- runtimeLog(pathname, type, msgs);
15422
- };
15423
- });
15424
15246
  }
15425
- } catch (e) {
15426
- renderCatchError(results, e);
15427
15247
  }
15428
- }
15429
- function runtimeLog(pathname, type, msgs) {
15430
- global.console[type].apply(global.console, [`[ ${pathname} ${type} ] `, ...msgs]);
15431
- }
15432
-
15433
- // src/hydrate/runner/window-initialize.ts
15434
- var docData = {
15435
- hostIds: 0,
15436
- rootLevelIds: 0,
15437
- staticComponents: /* @__PURE__ */ new Set()
15438
- };
15439
- function initializeWindow(win2, doc, opts, results) {
15440
- if (typeof opts.url === "string") {
15441
- try {
15442
- win2.location.href = opts.url;
15443
- } catch (e) {
15444
- }
15248
+ if (selectors.length === 0) {
15249
+ return "";
15445
15250
  }
15446
- if (typeof opts.userAgent === "string") {
15447
- try {
15448
- win2.navigator.userAgent = opts.userAgent;
15449
- } catch (e) {
15251
+ const cleanedSelectors = [];
15252
+ let cleanedSelector = "";
15253
+ if (node.selectors) {
15254
+ for (const selector of node.selectors) {
15255
+ cleanedSelector = removeSelectorWhitespace(selector);
15256
+ if (!cleanedSelectors.includes(cleanedSelector)) {
15257
+ cleanedSelectors.push(cleanedSelector);
15258
+ }
15450
15259
  }
15451
15260
  }
15452
- if (typeof opts.cookie === "string") {
15453
- try {
15454
- doc.cookie = opts.cookie;
15455
- } catch (e) {
15456
- }
15261
+ return `${cleanedSelectors}{${serializeCssMapVisit(opts, decls)}}`;
15262
+ };
15263
+ var serializeCssDeclaration = (node, index, len) => {
15264
+ if (node.value === "") {
15265
+ return "";
15457
15266
  }
15458
- if (typeof opts.referrer === "string") {
15459
- try {
15460
- doc.referrer = opts.referrer;
15461
- } catch (e) {
15462
- }
15267
+ if (len - 1 === index) {
15268
+ return node.property + ":" + node.value;
15463
15269
  }
15464
- if (typeof opts.direction === "string") {
15465
- try {
15466
- doc.documentElement.setAttribute("dir", opts.direction);
15467
- } catch (e) {
15468
- }
15270
+ return node.property + ":" + node.value + ";";
15271
+ };
15272
+ var serializeCssMedia = (opts, node) => {
15273
+ const mediaCss = serializeCssMapVisit(opts, node.rules);
15274
+ if (mediaCss === "") {
15275
+ return "";
15469
15276
  }
15470
- if (typeof opts.language === "string") {
15471
- try {
15472
- doc.documentElement.setAttribute("lang", opts.language);
15473
- } catch (e) {
15474
- }
15277
+ return "@media " + removeMediaWhitespace(node.media) + "{" + mediaCss + "}";
15278
+ };
15279
+ var serializeCssKeyframes = (opts, node) => {
15280
+ const keyframesCss = serializeCssMapVisit(opts, node.keyframes);
15281
+ if (keyframesCss === "") {
15282
+ return "";
15475
15283
  }
15476
- if (typeof opts.buildId === "string") {
15477
- try {
15478
- doc.documentElement.setAttribute("data-stencil-build", opts.buildId);
15479
- } catch (e) {
15480
- }
15284
+ return "@" + (node.vendor || "") + "keyframes " + node.name + "{" + keyframesCss + "}";
15285
+ };
15286
+ var serializeCssKeyframe = (opts, node) => {
15287
+ var _a2, _b;
15288
+ return ((_b = (_a2 = node.values) == null ? void 0 : _a2.join(",")) != null ? _b : "") + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
15289
+ };
15290
+ var serializeCssFontFace = (opts, node) => {
15291
+ const fontCss = serializeCssMapVisit(opts, node.declarations);
15292
+ if (fontCss === "") {
15293
+ return "";
15481
15294
  }
15482
- try {
15483
- win2.customElements = null;
15484
- } catch (e) {
15295
+ return "@font-face{" + fontCss + "}";
15296
+ };
15297
+ var serializeCssSupports = (opts, node) => {
15298
+ const supportsCss = serializeCssMapVisit(opts, node.rules);
15299
+ if (supportsCss === "") {
15300
+ return "";
15485
15301
  }
15486
- if (opts.constrainTimeouts) {
15487
- constrainTimeouts(win2);
15302
+ return "@supports " + node.supports + "{" + supportsCss + "}";
15303
+ };
15304
+ var serializeCssPage = (opts, node) => {
15305
+ var _a2, _b;
15306
+ const sel = (_b = (_a2 = node.selectors) == null ? void 0 : _a2.join(", ")) != null ? _b : "";
15307
+ return "@page " + sel + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
15308
+ };
15309
+ var serializeCssDocument = (opts, node) => {
15310
+ const documentCss = serializeCssMapVisit(opts, node.rules);
15311
+ const doc = "@" + (node.vendor || "") + "document " + node.document;
15312
+ if (documentCss === "") {
15313
+ return "";
15488
15314
  }
15489
- runtimeLogging(win2, opts, results);
15490
- doc[STENCIL_DOC_DATA] = docData;
15491
- return win2;
15492
- }
15493
-
15494
- // src/hydrate/runner/render.ts
15495
- var NOOP = () => {
15315
+ return doc + "{" + documentCss + "}";
15496
15316
  };
15497
- function streamToString(html, option) {
15498
- return renderToString(html, option, true);
15499
- }
15500
- function renderToString(html, options, asStream) {
15501
- const opts = normalizeHydrateOptions(options);
15502
- opts.serializeToHtml = true;
15503
- opts.fullDocument = typeof opts.fullDocument === "boolean" ? opts.fullDocument : true;
15504
- opts.serializeShadowRoot = typeof opts.serializeShadowRoot === "undefined" ? "declarative-shadow-dom" : opts.serializeShadowRoot;
15505
- opts.constrainTimeouts = false;
15506
- return hydrateDocument(html, opts, asStream);
15507
- }
15508
- function hydrateDocument(doc, options, asStream) {
15509
- const opts = normalizeHydrateOptions(options);
15510
- let win2 = null;
15511
- const results = generateHydrateResults(opts);
15512
- if (hasError(results.diagnostics)) {
15513
- return Promise.resolve(results);
15317
+ var serializeCssMapVisit = (opts, nodes) => {
15318
+ let rtn = "";
15319
+ if (nodes) {
15320
+ for (let i = 0, len = nodes.length; i < len; i++) {
15321
+ rtn += serializeCssVisitNode(opts, nodes[i], i, len);
15322
+ }
15514
15323
  }
15515
- if (typeof doc === "string") {
15516
- try {
15517
- opts.destroyWindow = true;
15518
- opts.destroyDocument = true;
15519
- win2 = new MockWindow(doc);
15520
- if (!asStream) {
15521
- return render(win2, opts, results).then(() => results);
15324
+ return rtn;
15325
+ };
15326
+ var removeSelectorWhitespace = (selector) => {
15327
+ let rtn = "";
15328
+ let char = "";
15329
+ let inAttr = false;
15330
+ selector = selector.trim();
15331
+ for (let i = 0, l = selector.length; i < l; i++) {
15332
+ char = selector[i];
15333
+ if (char === "[" && rtn[rtn.length - 1] !== "\\") {
15334
+ inAttr = true;
15335
+ } else if (char === "]" && rtn[rtn.length - 1] !== "\\") {
15336
+ inAttr = false;
15337
+ }
15338
+ if (!inAttr && CSS_WS_REG.test(char)) {
15339
+ if (CSS_NEXT_CHAR_REG.test(selector[i + 1])) {
15340
+ continue;
15522
15341
  }
15523
- return renderStream(win2, opts, results);
15524
- } catch (e) {
15525
- if (win2 && win2.close) {
15526
- win2.close();
15342
+ if (CSS_PREV_CHAR_REG.test(rtn[rtn.length - 1])) {
15343
+ continue;
15527
15344
  }
15528
- win2 = null;
15529
- renderCatchError(results, e);
15530
- return Promise.resolve(results);
15345
+ rtn += " ";
15346
+ } else {
15347
+ rtn += char;
15531
15348
  }
15532
15349
  }
15533
- if (isValidDocument(doc)) {
15534
- try {
15535
- opts.destroyDocument = false;
15536
- win2 = patchDomImplementation(doc, opts);
15537
- if (!asStream) {
15538
- return render(win2, opts, results).then(() => results);
15350
+ return rtn;
15351
+ };
15352
+ var removeMediaWhitespace = (media) => {
15353
+ var _a2;
15354
+ let rtn = "";
15355
+ let char = "";
15356
+ media = (_a2 = media == null ? void 0 : media.trim()) != null ? _a2 : "";
15357
+ for (let i = 0, l = media.length; i < l; i++) {
15358
+ char = media[i];
15359
+ if (CSS_WS_REG.test(char)) {
15360
+ if (CSS_WS_REG.test(rtn[rtn.length - 1])) {
15361
+ continue;
15362
+ }
15363
+ rtn += " ";
15364
+ } else {
15365
+ rtn += char;
15366
+ }
15367
+ }
15368
+ return rtn;
15369
+ };
15370
+ var CSS_WS_REG = /\s/;
15371
+ var CSS_NEXT_CHAR_REG = /[>\(\)\~\,\+\s]/;
15372
+ var CSS_PREV_CHAR_REG = /[>\(\~\,\+]/;
15373
+
15374
+ // src/compiler/style/css-parser/used-selectors.ts
15375
+ var getUsedSelectors = (elm) => {
15376
+ const usedSelectors = {
15377
+ attrs: /* @__PURE__ */ new Set(),
15378
+ classNames: /* @__PURE__ */ new Set(),
15379
+ ids: /* @__PURE__ */ new Set(),
15380
+ tags: /* @__PURE__ */ new Set()
15381
+ };
15382
+ collectUsedSelectors(usedSelectors, elm);
15383
+ return usedSelectors;
15384
+ };
15385
+ var collectUsedSelectors = (usedSelectors, elm) => {
15386
+ if (elm != null && elm.nodeType === 1) {
15387
+ const children = elm.children;
15388
+ const tagName = elm.nodeName.toLowerCase();
15389
+ usedSelectors.tags.add(tagName);
15390
+ const attributes = elm.attributes;
15391
+ for (let i = 0, l = attributes.length; i < l; i++) {
15392
+ const attr = attributes.item(i);
15393
+ const attrName = attr.name.toLowerCase();
15394
+ usedSelectors.attrs.add(attrName);
15395
+ if (attrName === "class") {
15396
+ const classList = elm.classList;
15397
+ for (let i2 = 0, l2 = classList.length; i2 < l2; i2++) {
15398
+ usedSelectors.classNames.add(classList.item(i2));
15399
+ }
15400
+ } else if (attrName === "id") {
15401
+ usedSelectors.ids.add(attr.value);
15539
15402
  }
15540
- return renderStream(win2, opts, results);
15541
- } catch (e) {
15542
- if (win2 && win2.close) {
15543
- win2.close();
15403
+ }
15404
+ if (children) {
15405
+ for (let i = 0, l = children.length; i < l; i++) {
15406
+ collectUsedSelectors(usedSelectors, children[i]);
15544
15407
  }
15545
- win2 = null;
15546
- renderCatchError(results, e);
15547
- return Promise.resolve(results);
15548
15408
  }
15549
15409
  }
15550
- renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15551
- return Promise.resolve(results);
15552
- }
15553
- async function render(win2, opts, results) {
15554
- if ("process" in globalThis && typeof process.on === "function" && !process.__stencilErrors) {
15555
- process.__stencilErrors = true;
15556
- process.on("unhandledRejection", (e) => {
15557
- console.log("unhandledRejection", e);
15558
- });
15559
- }
15560
- initializeWindow(win2, win2.document, opts, results);
15561
- const beforeHydrateFn = typeof opts.beforeHydrate === "function" ? opts.beforeHydrate : NOOP;
15410
+ };
15411
+
15412
+ // src/compiler/html/remove-unused-styles.ts
15413
+ var removeUnusedStyles = (doc, diagnostics) => {
15562
15414
  try {
15563
- await Promise.resolve(beforeHydrateFn(win2.document));
15564
- return new Promise((resolve) => {
15565
- if (Array.isArray(opts.modes)) {
15566
- modeResolutionChain.length = 0;
15567
- opts.modes.forEach((mode) => setMode(mode));
15415
+ const styleElms = doc.head.querySelectorAll(`style[data-styles]`);
15416
+ const styleLen = styleElms.length;
15417
+ if (styleLen > 0) {
15418
+ const usedSelectors = getUsedSelectors(doc.documentElement);
15419
+ for (let i = 0; i < styleLen; i++) {
15420
+ removeUnusedStyleText(usedSelectors, diagnostics, styleElms[i]);
15568
15421
  }
15569
- return hydrateFactory(win2, opts, results, afterHydrate, resolve);
15570
- });
15571
- } catch (e) {
15572
- renderCatchError(results, e);
15573
- return finalizeHydrate(win2, win2.document, opts, results);
15574
- }
15575
- }
15576
- function renderStream(win2, opts, results) {
15577
- async function* processRender() {
15578
- const renderResult = await render(win2, opts, results);
15579
- yield renderResult.html;
15580
- }
15581
- return Readable.from(processRender());
15582
- }
15583
- async function afterHydrate(win2, opts, results, resolve) {
15584
- const afterHydrateFn = typeof opts.afterHydrate === "function" ? opts.afterHydrate : NOOP;
15585
- try {
15586
- await Promise.resolve(afterHydrateFn(win2.document));
15587
- return resolve(finalizeHydrate(win2, win2.document, opts, results));
15422
+ }
15588
15423
  } catch (e) {
15589
- renderCatchError(results, e);
15590
- return resolve(finalizeHydrate(win2, win2.document, opts, results));
15424
+ catchError(diagnostics, e);
15591
15425
  }
15592
- }
15593
- function finalizeHydrate(win2, doc, opts, results) {
15426
+ };
15427
+ var removeUnusedStyleText = (usedSelectors, diagnostics, styleElm) => {
15594
15428
  try {
15595
- inspectElement(results, doc.documentElement, 0);
15596
- if (opts.removeUnusedStyles !== false) {
15597
- try {
15598
- removeUnusedStyles(doc, results.diagnostics);
15599
- } catch (e) {
15600
- renderCatchError(results, e);
15601
- }
15602
- }
15603
- if (typeof opts.title === "string") {
15604
- try {
15605
- doc.title = opts.title;
15606
- } catch (e) {
15607
- renderCatchError(results, e);
15608
- }
15609
- }
15610
- results.title = doc.title;
15611
- if (opts.removeScripts) {
15612
- removeScripts(doc.documentElement);
15613
- }
15614
- try {
15615
- updateCanonicalLink(doc, opts.canonicalUrl);
15616
- } catch (e) {
15617
- renderCatchError(results, e);
15429
+ const parseResults = parseCss(styleElm.innerHTML);
15430
+ diagnostics.push(...parseResults.diagnostics);
15431
+ if (hasError(diagnostics)) {
15432
+ return;
15618
15433
  }
15619
15434
  try {
15620
- relocateMetaCharset(doc);
15435
+ styleElm.innerHTML = serializeCss(parseResults.stylesheet, {
15436
+ usedSelectors
15437
+ });
15621
15438
  } catch (e) {
15439
+ diagnostics.push({
15440
+ level: "warn",
15441
+ type: "css",
15442
+ header: "CSS Stringify",
15443
+ messageText: e,
15444
+ lines: []
15445
+ });
15622
15446
  }
15623
- if (!hasError(results.diagnostics)) {
15624
- results.httpStatus = 200;
15625
- }
15626
- try {
15627
- const metaStatus = doc.head.querySelector('meta[http-equiv="status"]');
15628
- if (metaStatus != null) {
15629
- const metaStatusContent = metaStatus.getAttribute("content");
15630
- if (metaStatusContent && metaStatusContent.length > 0) {
15631
- results.httpStatus = parseInt(metaStatusContent, 10);
15447
+ } catch (e) {
15448
+ diagnostics.push({
15449
+ level: "warn",
15450
+ type: "css",
15451
+ header: "CSS Parse",
15452
+ messageText: e,
15453
+ lines: []
15454
+ });
15455
+ }
15456
+ };
15457
+
15458
+ // src/hydrate/runner/inspect-element.ts
15459
+ function inspectElement(results, elm, depth) {
15460
+ const children = [...Array.from(elm.children), ...Array.from(elm.shadowRoot ? elm.shadowRoot.children : [])];
15461
+ for (let i = 0, ii = children.length; i < ii; i++) {
15462
+ const childElm = children[i];
15463
+ const tagName = childElm.nodeName.toLowerCase();
15464
+ if (tagName.includes("-")) {
15465
+ const cmp = results.components.find((c) => c.tag === tagName);
15466
+ if (cmp != null) {
15467
+ cmp.count++;
15468
+ if (depth > cmp.depth) {
15469
+ cmp.depth = depth;
15632
15470
  }
15633
15471
  }
15634
- } catch (e) {
15472
+ } else {
15473
+ switch (tagName) {
15474
+ case "a":
15475
+ const anchor = collectAttributes(childElm);
15476
+ anchor.href = childElm.href;
15477
+ if (typeof anchor.href === "string") {
15478
+ if (!results.anchors.some((a) => a.href === anchor.href)) {
15479
+ results.anchors.push(anchor);
15480
+ }
15481
+ }
15482
+ break;
15483
+ case "img":
15484
+ const img = collectAttributes(childElm);
15485
+ img.src = childElm.src;
15486
+ if (typeof img.src === "string") {
15487
+ if (!results.imgs.some((a) => a.src === img.src)) {
15488
+ results.imgs.push(img);
15489
+ }
15490
+ }
15491
+ break;
15492
+ case "link":
15493
+ const link = collectAttributes(childElm);
15494
+ link.href = childElm.href;
15495
+ if (typeof link.rel === "string" && link.rel.toLowerCase() === "stylesheet") {
15496
+ if (typeof link.href === "string") {
15497
+ if (!results.styles.some((s) => s.link === link.href)) {
15498
+ delete link.rel;
15499
+ delete link.type;
15500
+ results.styles.push(link);
15501
+ }
15502
+ }
15503
+ }
15504
+ break;
15505
+ case "script":
15506
+ const script = collectAttributes(childElm);
15507
+ if (childElm.hasAttribute("src")) {
15508
+ script.src = childElm.src;
15509
+ if (typeof script.src === "string") {
15510
+ if (!results.scripts.some((s) => s.src === script.src)) {
15511
+ results.scripts.push(script);
15512
+ }
15513
+ }
15514
+ } else {
15515
+ const staticDataKey = childElm.getAttribute("data-stencil-static");
15516
+ if (staticDataKey) {
15517
+ results.staticData.push({
15518
+ id: staticDataKey,
15519
+ type: childElm.getAttribute("type"),
15520
+ content: childElm.textContent
15521
+ });
15522
+ }
15523
+ }
15524
+ break;
15525
+ }
15635
15526
  }
15636
- if (opts.clientHydrateAnnotations) {
15637
- doc.documentElement.classList.add("hydrated");
15527
+ depth++;
15528
+ inspectElement(results, childElm, depth);
15529
+ }
15530
+ }
15531
+ function collectAttributes(node) {
15532
+ const parsedElm = {};
15533
+ const attrs = node.attributes;
15534
+ for (let i = 0, ii = attrs.length; i < ii; i++) {
15535
+ const attr = attrs.item(i);
15536
+ const attrName = attr.nodeName.toLowerCase();
15537
+ if (SKIP_ATTRS.has(attrName)) {
15538
+ continue;
15638
15539
  }
15639
- if (opts.serializeToHtml) {
15640
- results.html = serializeDocumentToString(doc, opts);
15540
+ const attrValue = attr.nodeValue;
15541
+ if (attrName === "class" && attrValue === "") {
15542
+ continue;
15641
15543
  }
15642
- } catch (e) {
15643
- renderCatchError(results, e);
15544
+ parsedElm[attrName] = attrValue;
15644
15545
  }
15645
- destroyWindow(win2, doc, opts, results);
15646
- return results;
15546
+ return parsedElm;
15647
15547
  }
15648
- function destroyWindow(win2, doc, opts, results) {
15649
- if (!opts.destroyWindow) {
15650
- return;
15548
+ var SKIP_ATTRS = /* @__PURE__ */ new Set(["s-id", "c-id"]);
15549
+
15550
+ // src/hydrate/runner/patch-dom-implementation.ts
15551
+ function patchDomImplementation(doc, opts) {
15552
+ let win2;
15553
+ if (doc.defaultView != null) {
15554
+ opts.destroyWindow = true;
15555
+ patchWindow(doc.defaultView);
15556
+ win2 = doc.defaultView;
15557
+ } else {
15558
+ opts.destroyWindow = true;
15559
+ opts.destroyDocument = false;
15560
+ win2 = new MockWindow(false);
15651
15561
  }
15652
- try {
15653
- if (!opts.destroyDocument) {
15654
- win2.document = null;
15655
- doc.defaultView = null;
15656
- }
15657
- if (win2.close) {
15658
- win2.close();
15562
+ if (win2.document !== doc) {
15563
+ win2.document = doc;
15564
+ }
15565
+ if (doc.defaultView !== win2) {
15566
+ doc.defaultView = win2;
15567
+ }
15568
+ const HTMLElement2 = doc.documentElement.constructor.prototype;
15569
+ if (typeof HTMLElement2.getRootNode !== "function") {
15570
+ const elm = doc.createElement("unknown-element");
15571
+ const HTMLUnknownElement = elm.constructor.prototype;
15572
+ HTMLUnknownElement.getRootNode = getRootNode;
15573
+ }
15574
+ if (typeof doc.createEvent === "function") {
15575
+ const CustomEvent2 = doc.createEvent("CustomEvent").constructor;
15576
+ if (win2.CustomEvent !== CustomEvent2) {
15577
+ win2.CustomEvent = CustomEvent2;
15659
15578
  }
15579
+ }
15580
+ try {
15581
+ win2.__stencil_baseURI = doc.baseURI;
15660
15582
  } catch (e) {
15661
- renderCatchError(results, e);
15583
+ Object.defineProperty(doc, "baseURI", {
15584
+ get() {
15585
+ const baseElm = doc.querySelector("base[href]");
15586
+ if (baseElm) {
15587
+ return new URL(baseElm.getAttribute("href"), win2.location.href).href;
15588
+ }
15589
+ return win2.location.href;
15590
+ }
15591
+ });
15662
15592
  }
15593
+ return win2;
15663
15594
  }
15664
- function serializeDocumentToString(doc, opts) {
15665
- return serializeNodeToHtml(doc, {
15666
- approximateLineWidth: opts.approximateLineWidth,
15667
- outerHtml: false,
15668
- prettyHtml: opts.prettyHtml,
15669
- removeAttributeQuotes: opts.removeAttributeQuotes,
15670
- removeBooleanAttributeQuotes: opts.removeBooleanAttributeQuotes,
15671
- removeEmptyAttributes: opts.removeEmptyAttributes,
15672
- removeHtmlComments: opts.removeHtmlComments,
15673
- serializeShadowRoot: opts.serializeShadowRoot,
15674
- fullDocument: opts.fullDocument
15675
- });
15676
- }
15677
- function isValidDocument(doc) {
15678
- return doc != null && doc.nodeType === 9 && doc.documentElement != null && doc.documentElement.nodeType === 1 && doc.body != null && doc.body.nodeType === 1;
15679
- }
15680
- function removeScripts(elm) {
15681
- const children = elm.children;
15682
- for (let i = children.length - 1; i >= 0; i--) {
15683
- const child = children[i];
15684
- removeScripts(child);
15685
- if (child.nodeName === "SCRIPT" || child.nodeName === "LINK" && child.getAttribute("rel") === "modulepreload") {
15686
- child.remove();
15595
+ function getRootNode(opts) {
15596
+ const isComposed = opts != null && opts.composed === true;
15597
+ let node = this;
15598
+ while (node.parentNode != null) {
15599
+ node = node.parentNode;
15600
+ if (isComposed === true && node.parentNode == null && node.host != null) {
15601
+ node = node.host;
15687
15602
  }
15688
15603
  }
15604
+ return node;
15689
15605
  }
15690
15606
 
15691
- // src/hydrate/runner/serialize.ts
15692
- var PrimitiveType = /* @__PURE__ */ ((PrimitiveType2) => {
15693
- PrimitiveType2["Undefined"] = "undefined";
15694
- PrimitiveType2["Null"] = "null";
15695
- PrimitiveType2["String"] = "string";
15696
- PrimitiveType2["Number"] = "number";
15697
- PrimitiveType2["SpecialNumber"] = "number";
15698
- PrimitiveType2["Boolean"] = "boolean";
15699
- PrimitiveType2["BigInt"] = "bigint";
15700
- return PrimitiveType2;
15701
- })(PrimitiveType || {});
15702
- var NonPrimitiveType = /* @__PURE__ */ ((NonPrimitiveType2) => {
15703
- NonPrimitiveType2["Array"] = "array";
15704
- NonPrimitiveType2["Date"] = "date";
15705
- NonPrimitiveType2["Map"] = "map";
15706
- NonPrimitiveType2["Object"] = "object";
15707
- NonPrimitiveType2["RegularExpression"] = "regexp";
15708
- NonPrimitiveType2["Set"] = "set";
15709
- NonPrimitiveType2["Channel"] = "channel";
15710
- NonPrimitiveType2["Symbol"] = "symbol";
15711
- return NonPrimitiveType2;
15712
- })(NonPrimitiveType || {});
15713
- var TYPE_CONSTANT = "type";
15714
- var VALUE_CONSTANT = "value";
15715
- function serializeProperty(value) {
15716
- const arg = LocalValue.getArgument(value);
15717
- return JSON.stringify(arg);
15607
+ // src/hydrate/runner/render-utils.ts
15608
+ function normalizeHydrateOptions(inputOpts) {
15609
+ const outputOpts = Object.assign(
15610
+ {
15611
+ serializeToHtml: false,
15612
+ destroyWindow: false,
15613
+ destroyDocument: false
15614
+ },
15615
+ inputOpts || {}
15616
+ );
15617
+ if (typeof outputOpts.clientHydrateAnnotations !== "boolean") {
15618
+ outputOpts.clientHydrateAnnotations = true;
15619
+ }
15620
+ if (typeof outputOpts.constrainTimeouts !== "boolean") {
15621
+ outputOpts.constrainTimeouts = true;
15622
+ }
15623
+ if (typeof outputOpts.maxHydrateCount !== "number") {
15624
+ outputOpts.maxHydrateCount = 300;
15625
+ }
15626
+ if (typeof outputOpts.runtimeLogging !== "boolean") {
15627
+ outputOpts.runtimeLogging = false;
15628
+ }
15629
+ if (typeof outputOpts.timeout !== "number") {
15630
+ outputOpts.timeout = 15e3;
15631
+ }
15632
+ if (Array.isArray(outputOpts.excludeComponents)) {
15633
+ outputOpts.excludeComponents = outputOpts.excludeComponents.filter(filterValidTags).map(mapValidTags);
15634
+ } else {
15635
+ outputOpts.excludeComponents = [];
15636
+ }
15637
+ if (Array.isArray(outputOpts.staticComponents)) {
15638
+ outputOpts.staticComponents = outputOpts.staticComponents.filter(filterValidTags).map(mapValidTags);
15639
+ } else {
15640
+ outputOpts.staticComponents = [];
15641
+ }
15642
+ return outputOpts;
15718
15643
  }
15719
- function deserializeProperty(value) {
15720
- return RemoteValue.fromLocalValue(value);
15644
+ function filterValidTags(tag) {
15645
+ return typeof tag === "string" && tag.includes("-");
15721
15646
  }
15722
- var LocalValue = class _LocalValue {
15723
- constructor(type, value) {
15724
- if (type === "undefined" /* Undefined */ || type === "null" /* Null */) {
15725
- this.type = type;
15726
- } else {
15727
- this.type = type;
15728
- this.value = value;
15729
- }
15647
+ function mapValidTags(tag) {
15648
+ return tag.trim().toLowerCase();
15649
+ }
15650
+ function generateHydrateResults(opts) {
15651
+ if (typeof opts.url !== "string") {
15652
+ opts.url = `https://hydrate.stenciljs.com/`;
15730
15653
  }
15731
- /**
15732
- * Creates a new LocalValue object with a string value.
15733
- *
15734
- * @param {string} value - The string value to be stored in the LocalValue object.
15735
- * @returns {LocalValue} - The created LocalValue object.
15736
- */
15737
- static createStringValue(value) {
15738
- return new _LocalValue("string" /* String */, value);
15654
+ if (typeof opts.buildId !== "string") {
15655
+ opts.buildId = createHydrateBuildId();
15739
15656
  }
15740
- /**
15741
- * Creates a new LocalValue object with a number value.
15742
- *
15743
- * @param {number} value - The number value.
15744
- * @returns {LocalValue} - The created LocalValue object.
15745
- */
15746
- static createNumberValue(value) {
15747
- return new _LocalValue("number" /* Number */, value);
15657
+ const results = {
15658
+ buildId: opts.buildId,
15659
+ diagnostics: [],
15660
+ url: opts.url,
15661
+ host: null,
15662
+ hostname: null,
15663
+ href: null,
15664
+ pathname: null,
15665
+ port: null,
15666
+ search: null,
15667
+ hash: null,
15668
+ html: null,
15669
+ httpStatus: null,
15670
+ hydratedCount: 0,
15671
+ anchors: [],
15672
+ components: [],
15673
+ imgs: [],
15674
+ scripts: [],
15675
+ staticData: [],
15676
+ styles: [],
15677
+ title: null
15678
+ };
15679
+ try {
15680
+ const url = new URL(opts.url, `https://hydrate.stenciljs.com/`);
15681
+ results.url = url.href;
15682
+ results.host = url.host;
15683
+ results.hostname = url.hostname;
15684
+ results.href = url.href;
15685
+ results.port = url.port;
15686
+ results.pathname = url.pathname;
15687
+ results.search = url.search;
15688
+ results.hash = url.hash;
15689
+ } catch (e) {
15690
+ renderCatchError(results, e);
15748
15691
  }
15749
- /**
15750
- * Creates a new LocalValue object with a special number value.
15751
- *
15752
- * @param {number} value - The value of the special number.
15753
- * @returns {LocalValue} - The created LocalValue object.
15754
- */
15755
- static createSpecialNumberValue(value) {
15756
- if (Number.isNaN(value)) {
15757
- return new _LocalValue("number" /* SpecialNumber */, "NaN");
15692
+ return results;
15693
+ }
15694
+ var createHydrateBuildId = () => {
15695
+ let chars = "abcdefghijklmnopqrstuvwxyz";
15696
+ let buildId = "";
15697
+ while (buildId.length < 8) {
15698
+ const char = chars[Math.floor(Math.random() * chars.length)];
15699
+ buildId += char;
15700
+ if (buildId.length === 1) {
15701
+ chars += "0123456789";
15758
15702
  }
15759
- if (Object.is(value, -0)) {
15760
- return new _LocalValue("number" /* SpecialNumber */, "-0");
15703
+ }
15704
+ return buildId;
15705
+ };
15706
+ function renderBuildDiagnostic(results, level, header, msg) {
15707
+ const diagnostic = {
15708
+ level,
15709
+ type: "build",
15710
+ header,
15711
+ messageText: msg,
15712
+ relFilePath: void 0,
15713
+ absFilePath: void 0,
15714
+ lines: []
15715
+ };
15716
+ if (results.pathname) {
15717
+ if (results.pathname !== "/") {
15718
+ diagnostic.header += ": " + results.pathname;
15761
15719
  }
15762
- if (value === Infinity) {
15763
- return new _LocalValue("number" /* SpecialNumber */, "Infinity");
15720
+ } else if (results.url) {
15721
+ diagnostic.header += ": " + results.url;
15722
+ }
15723
+ results.diagnostics.push(diagnostic);
15724
+ return diagnostic;
15725
+ }
15726
+ function renderBuildError(results, msg) {
15727
+ return renderBuildDiagnostic(results, "error", "Hydrate Error", msg || "");
15728
+ }
15729
+ function renderCatchError(results, err2) {
15730
+ const diagnostic = renderBuildError(results);
15731
+ if (err2 != null) {
15732
+ if (err2.stack != null) {
15733
+ diagnostic.messageText = err2.stack.toString();
15734
+ } else {
15735
+ if (err2.message != null) {
15736
+ diagnostic.messageText = err2.message.toString();
15737
+ } else {
15738
+ diagnostic.messageText = err2.toString();
15739
+ }
15764
15740
  }
15765
- if (value === -Infinity) {
15766
- return new _LocalValue("number" /* SpecialNumber */, "-Infinity");
15741
+ }
15742
+ return diagnostic;
15743
+ }
15744
+
15745
+ // src/hydrate/runner/runtime-log.ts
15746
+ function runtimeLogging(win2, opts, results) {
15747
+ try {
15748
+ const pathname = win2.location.pathname;
15749
+ win2.console.error = (...msgs) => {
15750
+ const errMsg = msgs.reduce((errMsg2, m) => {
15751
+ if (m) {
15752
+ if (m.stack != null) {
15753
+ return errMsg2 + " " + String(m.stack);
15754
+ } else {
15755
+ if (m.message != null) {
15756
+ return errMsg2 + " " + String(m.message);
15757
+ }
15758
+ }
15759
+ }
15760
+ return String(m);
15761
+ }, "").trim();
15762
+ if (errMsg !== "") {
15763
+ renderCatchError(results, errMsg);
15764
+ if (opts.runtimeLogging) {
15765
+ runtimeLog(pathname, "error", [errMsg]);
15766
+ }
15767
+ }
15768
+ };
15769
+ win2.console.debug = (...msgs) => {
15770
+ renderBuildDiagnostic(results, "debug", "Hydrate Debug", [...msgs].join(", "));
15771
+ if (opts.runtimeLogging) {
15772
+ runtimeLog(pathname, "debug", msgs);
15773
+ }
15774
+ };
15775
+ if (opts.runtimeLogging) {
15776
+ ["log", "warn", "assert", "info", "trace"].forEach((type) => {
15777
+ win2.console[type] = (...msgs) => {
15778
+ runtimeLog(pathname, type, msgs);
15779
+ };
15780
+ });
15767
15781
  }
15768
- return new _LocalValue("number" /* SpecialNumber */, value);
15769
- }
15770
- /**
15771
- * Creates a new LocalValue object with an undefined value.
15772
- * @returns {LocalValue} - The created LocalValue object.
15773
- */
15774
- static createUndefinedValue() {
15775
- return new _LocalValue("undefined" /* Undefined */);
15776
- }
15777
- /**
15778
- * Creates a new LocalValue object with a null value.
15779
- * @returns {LocalValue} - The created LocalValue object.
15780
- */
15781
- static createNullValue() {
15782
- return new _LocalValue("null" /* Null */);
15782
+ } catch (e) {
15783
+ renderCatchError(results, e);
15783
15784
  }
15784
- /**
15785
- * Creates a new LocalValue object with a boolean value.
15786
- *
15787
- * @param {boolean} value - The boolean value.
15788
- * @returns {LocalValue} - The created LocalValue object.
15789
- */
15790
- static createBooleanValue(value) {
15791
- return new _LocalValue("boolean" /* Boolean */, value);
15785
+ }
15786
+ function runtimeLog(pathname, type, msgs) {
15787
+ global.console[type].apply(global.console, [`[ ${pathname} ${type} ] `, ...msgs]);
15788
+ }
15789
+
15790
+ // src/hydrate/runner/window-initialize.ts
15791
+ var docData = {
15792
+ hostIds: 0,
15793
+ rootLevelIds: 0,
15794
+ staticComponents: /* @__PURE__ */ new Set()
15795
+ };
15796
+ function initializeWindow(win2, doc, opts, results) {
15797
+ if (typeof opts.url === "string") {
15798
+ try {
15799
+ win2.location.href = opts.url;
15800
+ } catch (e) {
15801
+ }
15792
15802
  }
15793
- /**
15794
- * Creates a new LocalValue object with a BigInt value.
15795
- *
15796
- * @param {BigInt} value - The BigInt value.
15797
- * @returns {LocalValue} - The created LocalValue object.
15798
- */
15799
- static createBigIntValue(value) {
15800
- return new _LocalValue("bigint" /* BigInt */, value);
15803
+ if (typeof opts.userAgent === "string") {
15804
+ try {
15805
+ win2.navigator.userAgent = opts.userAgent;
15806
+ } catch (e) {
15807
+ }
15801
15808
  }
15802
- /**
15803
- * Creates a new LocalValue object with an array.
15804
- *
15805
- * @param {Array} value - The array.
15806
- * @returns {LocalValue} - The created LocalValue object.
15807
- */
15808
- static createArrayValue(value) {
15809
- return new _LocalValue("array" /* Array */, value);
15809
+ if (typeof opts.cookie === "string") {
15810
+ try {
15811
+ doc.cookie = opts.cookie;
15812
+ } catch (e) {
15813
+ }
15810
15814
  }
15811
- /**
15812
- * Creates a new LocalValue object with date value.
15813
- *
15814
- * @param {string} value - The date.
15815
- * @returns {LocalValue} - The created LocalValue object.
15816
- */
15817
- static createDateValue(value) {
15818
- return new _LocalValue("date" /* Date */, value);
15815
+ if (typeof opts.referrer === "string") {
15816
+ try {
15817
+ doc.referrer = opts.referrer;
15818
+ } catch (e) {
15819
+ }
15819
15820
  }
15820
- /**
15821
- * Creates a new LocalValue object of map value.
15822
- * @param {Map} map - The map.
15823
- * @returns {LocalValue} - The created LocalValue object.
15824
- */
15825
- static createMapValue(map2) {
15826
- const value = [];
15827
- Array.from(map2.entries()).forEach(([key, val]) => {
15828
- value.push([_LocalValue.getArgument(key), _LocalValue.getArgument(val)]);
15829
- });
15830
- return new _LocalValue("map" /* Map */, value);
15821
+ if (typeof opts.direction === "string") {
15822
+ try {
15823
+ doc.documentElement.setAttribute("dir", opts.direction);
15824
+ } catch (e) {
15825
+ }
15831
15826
  }
15832
- /**
15833
- * Creates a new LocalValue object from the passed object.
15834
- *
15835
- * @param object the object to create a LocalValue from
15836
- * @returns {LocalValue} - The created LocalValue object.
15837
- */
15838
- static createObjectValue(object) {
15839
- const value = [];
15840
- Object.entries(object).forEach(([key, val]) => {
15841
- value.push([key, _LocalValue.getArgument(val)]);
15842
- });
15843
- return new _LocalValue("object" /* Object */, value);
15827
+ if (typeof opts.language === "string") {
15828
+ try {
15829
+ doc.documentElement.setAttribute("lang", opts.language);
15830
+ } catch (e) {
15831
+ }
15844
15832
  }
15845
- /**
15846
- * Creates a new LocalValue object of regular expression value.
15847
- *
15848
- * @param {string} value - The value of the regular expression.
15849
- * @returns {LocalValue} - The created LocalValue object.
15850
- */
15851
- static createRegularExpressionValue(value) {
15852
- return new _LocalValue("regexp" /* RegularExpression */, value);
15833
+ if (typeof opts.buildId === "string") {
15834
+ try {
15835
+ doc.documentElement.setAttribute("data-stencil-build", opts.buildId);
15836
+ } catch (e) {
15837
+ }
15853
15838
  }
15854
- /**
15855
- * Creates a new LocalValue object with the specified value.
15856
- * @param {Set} value - The value to be set.
15857
- * @returns {LocalValue} - The created LocalValue object.
15858
- */
15859
- static createSetValue(value) {
15860
- return new _LocalValue("set" /* Set */, value);
15839
+ try {
15840
+ win2.customElements = null;
15841
+ } catch (e) {
15861
15842
  }
15862
- /**
15863
- * Creates a new LocalValue object with the given channel value
15864
- *
15865
- * @param {ChannelValue} value - The channel value.
15866
- * @returns {LocalValue} - The created LocalValue object.
15867
- */
15868
- static createChannelValue(value) {
15869
- return new _LocalValue("channel" /* Channel */, value);
15843
+ if (opts.constrainTimeouts) {
15844
+ constrainTimeouts(win2);
15870
15845
  }
15871
- /**
15872
- * Creates a new LocalValue object with a Symbol value.
15873
- *
15874
- * @param {Symbol} symbol - The Symbol value
15875
- * @returns {LocalValue} - The created LocalValue object
15876
- */
15877
- static createSymbolValue(symbol) {
15878
- const description = symbol.description || "Symbol()";
15879
- return new _LocalValue("symbol" /* Symbol */, description);
15846
+ runtimeLogging(win2, opts, results);
15847
+ doc[STENCIL_DOC_DATA] = docData;
15848
+ return win2;
15849
+ }
15850
+
15851
+ // src/hydrate/runner/render.ts
15852
+ var NOOP = () => {
15853
+ };
15854
+ function streamToString(html, option) {
15855
+ return renderToString(html, option, true);
15856
+ }
15857
+ function renderToString(html, options, asStream) {
15858
+ const opts = normalizeHydrateOptions(options);
15859
+ opts.serializeToHtml = true;
15860
+ opts.fullDocument = typeof opts.fullDocument === "boolean" ? opts.fullDocument : true;
15861
+ opts.serializeShadowRoot = typeof opts.serializeShadowRoot === "undefined" ? "declarative-shadow-dom" : opts.serializeShadowRoot;
15862
+ opts.constrainTimeouts = false;
15863
+ return hydrateDocument(html, opts, asStream);
15864
+ }
15865
+ function hydrateDocument(doc, options, asStream) {
15866
+ const opts = normalizeHydrateOptions(options);
15867
+ let win2 = null;
15868
+ const results = generateHydrateResults(opts);
15869
+ if (hasError(results.diagnostics)) {
15870
+ return Promise.resolve(results);
15880
15871
  }
15881
- static getArgument(argument) {
15882
- const type = typeof argument;
15883
- switch (type) {
15884
- case "string" /* String */:
15885
- return _LocalValue.createStringValue(argument);
15886
- case "number" /* Number */:
15887
- if (Number.isNaN(argument) || Object.is(argument, -0) || !Number.isFinite(argument)) {
15888
- return _LocalValue.createSpecialNumberValue(argument);
15889
- }
15890
- return _LocalValue.createNumberValue(argument);
15891
- case "boolean" /* Boolean */:
15892
- return _LocalValue.createBooleanValue(argument);
15893
- case "bigint" /* BigInt */:
15894
- return _LocalValue.createBigIntValue(argument);
15895
- case "undefined" /* Undefined */:
15896
- return _LocalValue.createUndefinedValue();
15897
- case "symbol" /* Symbol */:
15898
- return _LocalValue.createSymbolValue(argument);
15899
- case "object" /* Object */:
15900
- if (argument === null) {
15901
- return _LocalValue.createNullValue();
15902
- }
15903
- if (argument instanceof Date) {
15904
- return _LocalValue.createDateValue(argument);
15905
- }
15906
- if (argument instanceof Map) {
15907
- const map2 = [];
15908
- argument.forEach((value, key) => {
15909
- const objectKey = typeof key === "string" ? key : _LocalValue.getArgument(key);
15910
- const objectValue = _LocalValue.getArgument(value);
15911
- map2.push([objectKey, objectValue]);
15912
- });
15913
- return _LocalValue.createMapValue(argument);
15914
- }
15915
- if (argument instanceof Set) {
15916
- const set = [];
15917
- argument.forEach((value) => {
15918
- set.push(_LocalValue.getArgument(value));
15919
- });
15920
- return _LocalValue.createSetValue(set);
15921
- }
15922
- if (argument instanceof Array) {
15923
- const arr = [];
15924
- argument.forEach((value) => {
15925
- arr.push(_LocalValue.getArgument(value));
15926
- });
15927
- return _LocalValue.createArrayValue(arr);
15928
- }
15929
- if (argument instanceof RegExp) {
15930
- return _LocalValue.createRegularExpressionValue({
15931
- pattern: argument.source,
15932
- flags: argument.flags
15933
- });
15934
- }
15935
- return _LocalValue.createObjectValue(argument);
15872
+ if (typeof doc === "string") {
15873
+ try {
15874
+ opts.destroyWindow = true;
15875
+ opts.destroyDocument = true;
15876
+ win2 = new MockWindow(doc);
15877
+ if (!asStream) {
15878
+ return render(win2, opts, results).then(() => results);
15879
+ }
15880
+ return renderStream(win2, opts, results);
15881
+ } catch (e) {
15882
+ if (win2 && win2.close) {
15883
+ win2.close();
15884
+ }
15885
+ win2 = null;
15886
+ renderCatchError(results, e);
15887
+ return Promise.resolve(results);
15936
15888
  }
15937
- throw new Error(`Unsupported type: ${type}`);
15938
15889
  }
15939
- asMap() {
15940
- return {
15941
- [TYPE_CONSTANT]: this.type,
15942
- ...!(this.type === "null" /* Null */ || this.type === "undefined" /* Undefined */) ? { [VALUE_CONSTANT]: this.value } : {}
15943
- };
15890
+ if (isValidDocument(doc)) {
15891
+ try {
15892
+ opts.destroyDocument = false;
15893
+ win2 = patchDomImplementation(doc, opts);
15894
+ if (!asStream) {
15895
+ return render(win2, opts, results).then(() => results);
15896
+ }
15897
+ return renderStream(win2, opts, results);
15898
+ } catch (e) {
15899
+ if (win2 && win2.close) {
15900
+ win2.close();
15901
+ }
15902
+ win2 = null;
15903
+ renderCatchError(results, e);
15904
+ return Promise.resolve(results);
15905
+ }
15944
15906
  }
15945
- };
15946
- var RemoteValue = class _RemoteValue {
15947
- /**
15948
- * Deserializes a LocalValue serialized object back to its original JavaScript representation
15949
- *
15950
- * @param serialized The serialized LocalValue object
15951
- * @returns The original JavaScript value/object
15952
- */
15953
- static fromLocalValue(serialized) {
15954
- const type = serialized[TYPE_CONSTANT];
15955
- const value = VALUE_CONSTANT in serialized ? serialized[VALUE_CONSTANT] : void 0;
15956
- switch (type) {
15957
- case "string" /* String */:
15958
- return value;
15959
- case "boolean" /* Boolean */:
15960
- return value;
15961
- case "bigint" /* BigInt */:
15962
- return BigInt(value);
15963
- case "undefined" /* Undefined */:
15964
- return void 0;
15965
- case "null" /* Null */:
15966
- return null;
15967
- case "number" /* Number */:
15968
- if (value === "NaN") return NaN;
15969
- if (value === "-0") return -0;
15970
- if (value === "Infinity") return Infinity;
15971
- if (value === "-Infinity") return -Infinity;
15972
- return value;
15973
- case "array" /* Array */:
15974
- return value.map((item) => _RemoteValue.fromLocalValue(item));
15975
- case "date" /* Date */:
15976
- return new Date(value);
15977
- case "map" /* Map */:
15978
- const map2 = /* @__PURE__ */ new Map();
15979
- for (const [key, val] of value) {
15980
- const deserializedKey = typeof key === "object" && key !== null ? _RemoteValue.fromLocalValue(key) : key;
15981
- const deserializedValue = _RemoteValue.fromLocalValue(val);
15982
- map2.set(deserializedKey, deserializedValue);
15983
- }
15984
- return map2;
15985
- case "object" /* Object */:
15986
- const obj = {};
15987
- for (const [key, val] of value) {
15988
- obj[key] = _RemoteValue.fromLocalValue(val);
15989
- }
15990
- return obj;
15991
- case "regexp" /* RegularExpression */:
15992
- const { pattern, flags } = value;
15993
- return new RegExp(pattern, flags);
15994
- case "set" /* Set */:
15995
- const set = /* @__PURE__ */ new Set();
15996
- for (const item of value) {
15997
- set.add(_RemoteValue.fromLocalValue(item));
15907
+ renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15908
+ return Promise.resolve(results);
15909
+ }
15910
+ async function render(win2, opts, results) {
15911
+ if ("process" in globalThis && typeof process.on === "function" && !process.__stencilErrors) {
15912
+ process.__stencilErrors = true;
15913
+ process.on("unhandledRejection", (e) => {
15914
+ console.log("unhandledRejection", e);
15915
+ });
15916
+ }
15917
+ initializeWindow(win2, win2.document, opts, results);
15918
+ const beforeHydrateFn = typeof opts.beforeHydrate === "function" ? opts.beforeHydrate : NOOP;
15919
+ try {
15920
+ await Promise.resolve(beforeHydrateFn(win2.document));
15921
+ return new Promise((resolve) => {
15922
+ if (Array.isArray(opts.modes)) {
15923
+ modeResolutionChain.length = 0;
15924
+ opts.modes.forEach((mode) => setMode(mode));
15925
+ }
15926
+ return hydrateFactory(win2, opts, results, afterHydrate, resolve);
15927
+ });
15928
+ } catch (e) {
15929
+ renderCatchError(results, e);
15930
+ return finalizeHydrate(win2, win2.document, opts, results);
15931
+ }
15932
+ }
15933
+ function renderStream(win2, opts, results) {
15934
+ async function* processRender() {
15935
+ const renderResult = await render(win2, opts, results);
15936
+ yield renderResult.html;
15937
+ }
15938
+ return Readable.from(processRender());
15939
+ }
15940
+ async function afterHydrate(win2, opts, results, resolve) {
15941
+ const afterHydrateFn = typeof opts.afterHydrate === "function" ? opts.afterHydrate : NOOP;
15942
+ try {
15943
+ await Promise.resolve(afterHydrateFn(win2.document));
15944
+ return resolve(finalizeHydrate(win2, win2.document, opts, results));
15945
+ } catch (e) {
15946
+ renderCatchError(results, e);
15947
+ return resolve(finalizeHydrate(win2, win2.document, opts, results));
15948
+ }
15949
+ }
15950
+ function finalizeHydrate(win2, doc, opts, results) {
15951
+ try {
15952
+ inspectElement(results, doc.documentElement, 0);
15953
+ if (opts.removeUnusedStyles !== false) {
15954
+ try {
15955
+ removeUnusedStyles(doc, results.diagnostics);
15956
+ } catch (e) {
15957
+ renderCatchError(results, e);
15958
+ }
15959
+ }
15960
+ if (typeof opts.title === "string") {
15961
+ try {
15962
+ doc.title = opts.title;
15963
+ } catch (e) {
15964
+ renderCatchError(results, e);
15965
+ }
15966
+ }
15967
+ results.title = doc.title;
15968
+ if (opts.removeScripts) {
15969
+ removeScripts(doc.documentElement);
15970
+ }
15971
+ try {
15972
+ updateCanonicalLink(doc, opts.canonicalUrl);
15973
+ } catch (e) {
15974
+ renderCatchError(results, e);
15975
+ }
15976
+ try {
15977
+ relocateMetaCharset(doc);
15978
+ } catch (e) {
15979
+ }
15980
+ if (!hasError(results.diagnostics)) {
15981
+ results.httpStatus = 200;
15982
+ }
15983
+ try {
15984
+ const metaStatus = doc.head.querySelector('meta[http-equiv="status"]');
15985
+ if (metaStatus != null) {
15986
+ const metaStatusContent = metaStatus.getAttribute("content");
15987
+ if (metaStatusContent && metaStatusContent.length > 0) {
15988
+ results.httpStatus = parseInt(metaStatusContent, 10);
15998
15989
  }
15999
- return set;
16000
- case "symbol" /* Symbol */:
16001
- return Symbol(value);
16002
- default:
16003
- throw new Error(`Unsupported type: ${type}`);
15990
+ }
15991
+ } catch (e) {
15992
+ }
15993
+ if (opts.clientHydrateAnnotations) {
15994
+ doc.documentElement.classList.add("hydrated");
15995
+ }
15996
+ if (opts.serializeToHtml) {
15997
+ results.html = serializeDocumentToString(doc, opts);
16004
15998
  }
15999
+ } catch (e) {
16000
+ renderCatchError(results, e);
16005
16001
  }
16006
- /**
16007
- * Utility method to deserialize multiple LocalValues at once
16008
- *
16009
- * @param serializedValues Array of serialized LocalValue objects
16010
- * @returns Array of deserialized JavaScript values
16011
- */
16012
- static fromLocalValueArray(serializedValues) {
16013
- return serializedValues.map((value) => _RemoteValue.fromLocalValue(value));
16002
+ destroyWindow(win2, doc, opts, results);
16003
+ return results;
16004
+ }
16005
+ function destroyWindow(win2, doc, opts, results) {
16006
+ if (!opts.destroyWindow) {
16007
+ return;
16014
16008
  }
16015
- /**
16016
- * Verifies if the given object matches the structure of a serialized LocalValue
16017
- *
16018
- * @param obj Object to verify
16019
- * @returns boolean indicating if the object has LocalValue structure
16020
- */
16021
- static isLocalValueObject(obj) {
16022
- if (typeof obj !== "object" || obj === null) {
16023
- return false;
16024
- }
16025
- if (!obj.hasOwnProperty(TYPE_CONSTANT)) {
16026
- return false;
16009
+ try {
16010
+ if (!opts.destroyDocument) {
16011
+ win2.document = null;
16012
+ doc.defaultView = null;
16027
16013
  }
16028
- const type = obj[TYPE_CONSTANT];
16029
- const hasTypeProperty = Object.values({ ...PrimitiveType, ...NonPrimitiveType }).includes(type);
16030
- if (!hasTypeProperty) {
16031
- return false;
16014
+ if (win2.close) {
16015
+ win2.close();
16032
16016
  }
16033
- if (type !== "null" /* Null */ && type !== "undefined" /* Undefined */) {
16034
- return obj.hasOwnProperty(VALUE_CONSTANT);
16017
+ } catch (e) {
16018
+ renderCatchError(results, e);
16019
+ }
16020
+ }
16021
+ function serializeDocumentToString(doc, opts) {
16022
+ return serializeNodeToHtml(doc, {
16023
+ approximateLineWidth: opts.approximateLineWidth,
16024
+ outerHtml: false,
16025
+ prettyHtml: opts.prettyHtml,
16026
+ removeAttributeQuotes: opts.removeAttributeQuotes,
16027
+ removeBooleanAttributeQuotes: opts.removeBooleanAttributeQuotes,
16028
+ removeEmptyAttributes: opts.removeEmptyAttributes,
16029
+ removeHtmlComments: opts.removeHtmlComments,
16030
+ serializeShadowRoot: opts.serializeShadowRoot,
16031
+ fullDocument: opts.fullDocument
16032
+ });
16033
+ }
16034
+ function isValidDocument(doc) {
16035
+ return doc != null && doc.nodeType === 9 && doc.documentElement != null && doc.documentElement.nodeType === 1 && doc.body != null && doc.body.nodeType === 1;
16036
+ }
16037
+ function removeScripts(elm) {
16038
+ const children = elm.children;
16039
+ for (let i = children.length - 1; i >= 0; i--) {
16040
+ const child = children[i];
16041
+ removeScripts(child);
16042
+ if (child.nodeName === "SCRIPT" || child.nodeName === "LINK" && child.getAttribute("rel") === "modulepreload") {
16043
+ child.remove();
16035
16044
  }
16036
- return true;
16037
16045
  }
16038
- };
16046
+ }
16039
16047
  export {
16040
16048
  createWindowFromHtml,
16041
16049
  deserializeProperty,