@weapp-vite/miniprogram-automator 1.5.5-dev.20261117.1 → 1.5.6-dev.20261119.1

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.
@@ -199,6 +199,7 @@ function mergeRecord(...records) {
199
199
  return Object.assign({}, ...records.filter(Boolean));
200
200
  }
201
201
  // ../../mpcore/packages/simulator/src/runtime/componentInstance/observers.ts
202
+ const observerRunStates = /* @__PURE__ */ new WeakMap();
202
203
  function runPropertyObservers(definition, instance, changedKeys, previousProperties) {
203
204
  const propOptions = definition.properties;
204
205
  if (!propOptions || typeof propOptions !== "object" || Array.isArray(propOptions)) return;
@@ -244,7 +245,7 @@ function matchObserverPattern(pattern, changedKeys) {
244
245
  });
245
246
  });
246
247
  }
247
- function runComponentObservers(definition, instance, changedKeys, previousProperties = {}) {
248
+ function runComponentObserversOnce(definition, instance, changedKeys, previousProperties = {}, includePropertyObservers = true) {
248
249
  if (changedKeys.length === 0) return;
249
250
  const observers = definition.observers;
250
251
  if (observers && typeof observers === "object" && !Array.isArray(observers)) for (const [pattern, handler] of Object.entries(observers)) {
@@ -252,7 +253,41 @@ function runComponentObservers(definition, instance, changedKeys, previousProper
252
253
  const args = normalizeObserverPattern(pattern).map((item) => resolveObservedValue(instance, item));
253
254
  handler.call(instance, ...args);
254
255
  }
255
- runPropertyObservers(definition, instance, changedKeys, previousProperties);
256
+ if (includePropertyObservers) runPropertyObservers(definition, instance, changedKeys, previousProperties);
257
+ }
258
+ function runComponentObservers(definition, instance, changedKeys, previousProperties = {}) {
259
+ if (changedKeys.length === 0) return;
260
+ const state = observerRunStates.get(instance) ?? {
261
+ running: false,
262
+ pending: []
263
+ };
264
+ observerRunStates.set(instance, state);
265
+ if (state.running) {
266
+ runPropertyObservers(definition, instance, changedKeys, previousProperties);
267
+ state.pending.push({
268
+ changedKeys: [...changedKeys],
269
+ previousProperties,
270
+ includePropertyObservers: false
271
+ });
272
+ return;
273
+ }
274
+ state.pending.push({
275
+ changedKeys: [...changedKeys],
276
+ previousProperties,
277
+ includePropertyObservers: true
278
+ });
279
+ state.running = true;
280
+ try {
281
+ while (state.pending.length > 0) {
282
+ const next = state.pending.shift();
283
+ runComponentObserversOnce(definition, instance, next.changedKeys, next.previousProperties, next.includePropertyObservers);
284
+ }
285
+ } catch (error) {
286
+ state.pending.length = 0;
287
+ throw error;
288
+ } finally {
289
+ state.running = false;
290
+ }
256
291
  }
257
292
  // ../../mpcore/packages/simulator/src/runtime/componentInstance/lifetimes.ts
258
293
  function mergeComponentLifetimes(behaviors, definition) {
@@ -294,27 +329,45 @@ function flattenBehaviors(definition) {
294
329
  }
295
330
  return flattened;
296
331
  }
332
+ function applyBehaviorDefinitionFilters(definition, behaviors) {
333
+ if (!behaviors.some((behavior) => typeof behavior.definitionFilter === "function")) return definition;
334
+ const filteredDefinition = {
335
+ ...definition,
336
+ ...definition.observers && typeof definition.observers === "object" && !Array.isArray(definition.observers) ? { observers: { ...definition.observers } } : {}
337
+ };
338
+ for (const behavior of behaviors) if (typeof behavior.definitionFilter === "function") behavior.definitionFilter(filteredDefinition);
339
+ return filteredDefinition;
340
+ }
297
341
  function resolveComponentPropertyDefinitions(definition, behaviors = flattenBehaviors(definition)) {
298
342
  return behaviors.length === 0 ? definition.properties ?? {} : mergeRecord(...behaviors.map((item) => item.properties), definition.properties);
299
343
  }
344
+ const RESERVED_COMPONENT_HOST_PROPERTIES = /* @__PURE__ */ new Set([
345
+ "id",
346
+ "class",
347
+ "slot"
348
+ ]);
349
+ function isReservedComponentHostProperty(key) {
350
+ return RESERVED_COMPONENT_HOST_PROPERTIES.has(key);
351
+ }
300
352
  function normalizeComponentDefinition(definition) {
301
353
  const behaviors = flattenBehaviors(definition);
302
354
  if (behaviors.length === 0) return definition;
355
+ const filteredDefinition = applyBehaviorDefinitionFilters(definition, behaviors);
303
356
  const mergedDataEntries = behaviors.map((item) => item.data).filter(Boolean);
304
357
  const mergedDefinition = {
305
- ...mergeRecord(...behaviors, definition),
306
- methods: mergeRecord(...behaviors.map((item) => item.methods), definition.methods),
307
- observers: mergeRecord(...behaviors.map((item) => item.observers), definition.observers),
308
- pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes), definition.pageLifetimes),
309
- properties: resolveComponentPropertyDefinitions(definition, behaviors),
310
- relations: mergeRecord(...behaviors.map((item) => item.relations), definition.relations),
311
- lifetimes: mergeComponentLifetimes(behaviors, definition)
358
+ ...mergeRecord(...behaviors, filteredDefinition),
359
+ methods: mergeRecord(...behaviors.map((item) => item.methods), filteredDefinition.methods),
360
+ observers: mergeRecord(...behaviors.map((item) => item.observers), filteredDefinition.observers),
361
+ pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes), filteredDefinition.pageLifetimes),
362
+ properties: resolveComponentPropertyDefinitions(filteredDefinition, behaviors),
363
+ relations: mergeRecord(...behaviors.map((item) => item.relations), filteredDefinition.relations),
364
+ lifetimes: mergeComponentLifetimes(behaviors, filteredDefinition)
312
365
  };
313
- if (mergedDataEntries.length > 0 || definition.data) mergedDefinition.data = function mergedComponentData() {
366
+ if (mergedDataEntries.length > 0 || filteredDefinition.data) mergedDefinition.data = function mergedComponentData() {
314
367
  return mergeRecord(mergeRecord(...mergedDataEntries.map((entry) => {
315
368
  if (typeof entry === "function") return entry.call(this);
316
369
  return entry;
317
- })), typeof definition.data === "function" ? definition.data.call(this) : definition.data);
370
+ })), typeof filteredDefinition.data === "function" ? filteredDefinition.data.call(this) : filteredDefinition.data);
318
371
  };
319
372
  return mergedDefinition;
320
373
  }
@@ -1318,6 +1371,36 @@ function resolveEventBindingPhases(attributes, eventName, includeCapture = true)
1318
1371
  }
1319
1372
  return bindings;
1320
1373
  }
1374
+ // ../../mpcore/packages/simulator/src/view/nativeBoolean.ts
1375
+ const nativeBooleanValues = /* @__PURE__ */ new WeakMap();
1376
+ /** 保留原始布尔属性值,避免 null/undefined 在属性序列化后退化为裸属性。 */
1377
+ function setNativeBooleanValue(node, name, value, valueless = false) {
1378
+ if (name !== "checked" && name !== "disabled") return;
1379
+ let values = nativeBooleanValues.get(node);
1380
+ if (!values) {
1381
+ values = /* @__PURE__ */ new Map();
1382
+ nativeBooleanValues.set(node, values);
1383
+ }
1384
+ values.set(name, {
1385
+ value,
1386
+ valueless
1387
+ });
1388
+ }
1389
+ function getNativeBooleanValue(node, name) {
1390
+ const attributes = node.attribs;
1391
+ if (!attributes || !Object.hasOwn(attributes, name)) return false;
1392
+ const snapshot = node.nativeBooleanValues;
1393
+ const stored = nativeBooleanValues.get(node)?.get(name) ?? snapshot?.get(name);
1394
+ if (stored) {
1395
+ if (stored.valueless) return true;
1396
+ return stored.value !== void 0 && stored.value !== null && stored.value !== false && stored.value !== 0 && stored.value !== "" && stored.value !== "false" && stored.value !== "0";
1397
+ }
1398
+ const value = attributes[name];
1399
+ return value !== "false" && value !== "0";
1400
+ }
1401
+ function getNativeBooleanSnapshot(node) {
1402
+ return nativeBooleanValues.get(node);
1403
+ }
1321
1404
  // ../../mpcore/packages/simulator/src/view/nodeDataset.ts
1322
1405
  const DATASET_NAME_RE = /-([a-z])/g;
1323
1406
  function isDatasetAttribute(attributeName) {
@@ -1378,7 +1461,8 @@ function mergeComponentEventRoot(root, host) {
1378
1461
  const entry = eventNodes.get(root);
1379
1462
  if (entry.target === root) entry.target = {
1380
1463
  attribs: root.attribs,
1381
- dataset: root.dataset
1464
+ dataset: root.dataset,
1465
+ nativeBooleanValues: getNativeBooleanSnapshot(root)
1382
1466
  };
1383
1467
  entry.hosts ??= [];
1384
1468
  entry.hosts.push(host);
@@ -13996,15 +14080,15 @@ const NUMERIC_CONSUMED_SHIFT = 21;
13996
14080
  const NUMERIC_CODE_POINT_MASK = 2097151;
13997
14081
  const NUMERIC_CONSUMED_OVERFLOW = 2047;
13998
14082
  /** Full length, including `&`, when the packed consumed field overflows. */
13999
- let longNumericConsumed = 0;
14083
+ let longNumericConsumed$1 = 0;
14000
14084
  /**
14001
14085
  * Recover the consumed count before the next numeric parse can overwrite
14002
14086
  * `longNumericConsumed`. This avoids allocating a tuple for each reference.
14003
14087
  * @param packed Packed result of `parseNumericEntity`.
14004
14088
  */
14005
- function unpackConsumed(packed) {
14089
+ function unpackConsumed$1(packed) {
14006
14090
  const consumed = packed >>> NUMERIC_CONSUMED_SHIFT;
14007
- return consumed === NUMERIC_CONSUMED_OVERFLOW ? longNumericConsumed : consumed;
14091
+ return consumed === NUMERIC_CONSUMED_OVERFLOW ? longNumericConsumed$1 : consumed;
14008
14092
  }
14009
14093
  /** ASCII digit values; 0xff marks characters outside the hexadecimal range. */
14010
14094
  const numericDigits = /* #__PURE__ */ (() => {
@@ -14026,7 +14110,7 @@ const numericDigits = /* #__PURE__ */ (() => {
14026
14110
  * @param offset Index right after the `#`.
14027
14111
  * @param isStrict Whether a terminating semicolon is required.
14028
14112
  */
14029
- function parseNumericEntity(input, offset, isStrict) {
14113
+ function parseNumericEntity$1(input, offset, isStrict) {
14030
14114
  const inputLength = input.length;
14031
14115
  let index = offset;
14032
14116
  let codePoint = 0;
@@ -14061,7 +14145,7 @@ function parseNumericEntity(input, offset, isStrict) {
14061
14145
  if (index < inputLength && input.charCodeAt(index) === CHAR_SEMI) consumed += 1;
14062
14146
  else if (isStrict) return 0;
14063
14147
  if (consumed >= NUMERIC_CONSUMED_OVERFLOW) {
14064
- longNumericConsumed = consumed;
14148
+ longNumericConsumed$1 = consumed;
14065
14149
  consumed = NUMERIC_CONSUMED_OVERFLOW;
14066
14150
  }
14067
14151
  return consumed << NUMERIC_CONSUMED_SHIFT | codePoint;
@@ -14084,8 +14168,8 @@ function decodeXML(xmlString) {
14084
14168
  let value = "";
14085
14169
  const c1 = xmlString.charCodeAt(start);
14086
14170
  if (c1 === CHAR_NUM) {
14087
- const packed = parseNumericEntity(xmlString, start + 1, true);
14088
- consumed = unpackConsumed(packed);
14171
+ const packed = parseNumericEntity$1(xmlString, start + 1, true);
14172
+ consumed = unpackConsumed$1(packed);
14089
14173
  if (consumed !== 0) {
14090
14174
  const codePoint = packed & NUMERIC_CODE_POINT_MASK;
14091
14175
  value = codePoint - 1 >>> 0 < 55295 ? String.fromCharCode(codePoint) : String.fromCodePoint(replaceCodePointXML$1(codePoint));
@@ -16094,6 +16178,52 @@ function getNativeBindingCommit(node, previous) {
16094
16178
  }
16095
16179
  };
16096
16180
  }
16181
+ // ../../mpcore/packages/simulator/src/testing/sessionHandle/shared.ts
16182
+ const LEADING_SLASH_RE$4 = /^\/+/;
16183
+ const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
16184
+ const DEFAULT_WAIT_INTERVAL$1 = 10;
16185
+ function normalizeRoute(route) {
16186
+ return route.replace(LEADING_SLASH_RE$4, "");
16187
+ }
16188
+ function resolvePageScopeId$1(scopeId) {
16189
+ const pagePathIndex = scopeId.indexOf("/page/");
16190
+ return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
16191
+ }
16192
+ function normalizeNonEmptyInput(value, label) {
16193
+ const normalizedValue = value.trim();
16194
+ if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
16195
+ return normalizedValue;
16196
+ }
16197
+ function cloneProtocolValue(value) {
16198
+ if (!value || typeof value !== "object") return value;
16199
+ return JSON.parse(JSON.stringify(value));
16200
+ }
16201
+ async function waitForDelay(ms = 0) {
16202
+ if (ms <= 0) return;
16203
+ await new Promise((resolve) => setTimeout(resolve, ms));
16204
+ }
16205
+ async function pollUntil$2(check, errorMessage, options = {}) {
16206
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
16207
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
16208
+ const deadline = Date.now() + timeout;
16209
+ while (true) {
16210
+ const result = await check();
16211
+ if (result != null) return result;
16212
+ if (Date.now() >= deadline) throw new Error(errorMessage);
16213
+ await waitForDelay(interval);
16214
+ }
16215
+ }
16216
+ async function runWithTimeout(operation, timeout, message) {
16217
+ if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
16218
+ let timer;
16219
+ try {
16220
+ return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
16221
+ timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
16222
+ })]);
16223
+ } finally {
16224
+ if (timer) clearTimeout(timer);
16225
+ }
16226
+ }
16097
16227
  // ../../mpcore/packages/simulator/src/view/nodeEvents.ts
16098
16228
  /** 正确字段优先;复制触点,避免处理器修改调用者持有的数据。 */
16099
16229
  function readTouchEventPayload(event) {
@@ -16168,9 +16298,33 @@ function participates(scopeId, formScopes, behavior, resolveComponent) {
16168
16298
  }
16169
16299
  return true;
16170
16300
  }
16171
- function checked(attributes, name) {
16172
- const value = attributes?.[name];
16173
- return value !== void 0 && value !== "false" && value !== "0";
16301
+ function participatesFormField(scopeId, formScopes, resolveComponent) {
16302
+ const visited = /* @__PURE__ */ new Set();
16303
+ while (!formScopes.has(scopeId)) {
16304
+ if (!scopeId || visited.has(scopeId)) return false;
16305
+ visited.add(scopeId);
16306
+ const component = resolveComponent?.(scopeId);
16307
+ if (!component || !includesBehavior(component.definition, "wx://form-field") && !includesBehavior(component.definition, "wx://form-field-group")) return false;
16308
+ scopeId = component.ownerScopeId;
16309
+ }
16310
+ return true;
16311
+ }
16312
+ function resolveFormFieldComponent(scopeId, resolveComponent) {
16313
+ const visited = /* @__PURE__ */ new Set();
16314
+ let current = scopeId;
16315
+ while (current && !visited.has(current)) {
16316
+ visited.add(current);
16317
+ const component = resolveComponent?.(current);
16318
+ if (!component) return;
16319
+ if (includesBehavior(component.definition, "wx://form-field")) return {
16320
+ scopeId: current,
16321
+ component
16322
+ };
16323
+ current = component.ownerScopeId;
16324
+ }
16325
+ }
16326
+ function checked(node, name) {
16327
+ return getNativeBooleanValue(node, name);
16174
16328
  }
16175
16329
  function choiceValues(group, pageScope, resolveComponent) {
16176
16330
  const values = [];
@@ -16180,7 +16334,7 @@ function choiceValues(group, pageScope, resolveComponent) {
16180
16334
  if (node.name === "form" || node.name === "radio-group" || node.name === "checkbox-group") return;
16181
16335
  if (node.name === choice) {
16182
16336
  const owner = nativeOwner(node);
16183
- if (checked(owner.target.attribs, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
16337
+ if (checked(owner.target, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
16184
16338
  }
16185
16339
  for (const child of node.children ?? []) visit(child);
16186
16340
  };
@@ -16193,6 +16347,12 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
16193
16347
  if (node.name === "form") return;
16194
16348
  const owner = nativeOwner(node);
16195
16349
  const attributes = owner.target.attribs;
16350
+ const field = resolveFormFieldComponent(owner.scopeId, resolveComponent);
16351
+ const componentName = field?.component.name;
16352
+ if (typeof componentName === "string" && componentName && node.attribs?.["data-sim-component"] && field && participatesFormField(field.scopeId, scopes, resolveComponent)) {
16353
+ values[componentName] = cloneProtocolValue(field.component.value);
16354
+ return;
16355
+ }
16196
16356
  const name = attributes?.name;
16197
16357
  if (attributes && name && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) switch (node.name) {
16198
16358
  case "input":
@@ -16200,7 +16360,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
16200
16360
  values[name] = attributes.value ?? "";
16201
16361
  break;
16202
16362
  case "switch":
16203
- values[name] = checked(attributes, "checked");
16363
+ values[name] = checked(owner.target, "checked");
16204
16364
  break;
16205
16365
  case "slider":
16206
16366
  values[name] = Number(attributes.value ?? 0);
@@ -16226,7 +16386,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
16226
16386
  /** 先固定提交目标、字段值和方法所有者,再允许 tap 回调改变组件树。 */
16227
16387
  function prepareNativeFormSubmit(button, pageScope, event, resolveMethod, resolveComponent) {
16228
16388
  const owner = nativeOwner(button);
16229
- if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target.attribs, "disabled")) return;
16389
+ if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target, "disabled")) return;
16230
16390
  let form = button.parent;
16231
16391
  while (form && form.name !== "form") form = form.parent;
16232
16392
  if (!form) return;
@@ -16242,6 +16402,145 @@ function prepareNativeFormSubmit(button, pageScope, event, resolveMethod, resolv
16242
16402
  })
16243
16403
  };
16244
16404
  }
16405
+ // ../../@weapp-core/shared/dist/rich-text-shared.js
16406
+ const ALLOWED_TAGS = /* @__PURE__ */ new Set([
16407
+ "a",
16408
+ "abbr",
16409
+ "address",
16410
+ "article",
16411
+ "aside",
16412
+ "b",
16413
+ "bdi",
16414
+ "bdo",
16415
+ "big",
16416
+ "blockquote",
16417
+ "br",
16418
+ "caption",
16419
+ "center",
16420
+ "cite",
16421
+ "code",
16422
+ "col",
16423
+ "colgroup",
16424
+ "dd",
16425
+ "del",
16426
+ "div",
16427
+ "dl",
16428
+ "dt",
16429
+ "em",
16430
+ "fieldset",
16431
+ "font",
16432
+ "h1",
16433
+ "h2",
16434
+ "h3",
16435
+ "h4",
16436
+ "h5",
16437
+ "h6",
16438
+ "header",
16439
+ "hr",
16440
+ "i",
16441
+ "img",
16442
+ "ins",
16443
+ "label",
16444
+ "legend",
16445
+ "li",
16446
+ "mark",
16447
+ "ol",
16448
+ "p",
16449
+ "pre",
16450
+ "q",
16451
+ "rt",
16452
+ "ruby",
16453
+ "s",
16454
+ "section",
16455
+ "small",
16456
+ "span",
16457
+ "strong",
16458
+ "sub",
16459
+ "sup",
16460
+ "table",
16461
+ "tbody",
16462
+ "td",
16463
+ "tfoot",
16464
+ "th",
16465
+ "thead",
16466
+ "tr",
16467
+ "tt",
16468
+ "u",
16469
+ "ul"
16470
+ ]);
16471
+ const ALLOWED_STYLE_PROPERTIES = /* @__PURE__ */ new Set([
16472
+ "background",
16473
+ "background-color",
16474
+ "border",
16475
+ "border-bottom",
16476
+ "border-color",
16477
+ "border-left",
16478
+ "border-radius",
16479
+ "border-right",
16480
+ "border-style",
16481
+ "border-top",
16482
+ "border-width",
16483
+ "color",
16484
+ "display",
16485
+ "font-family",
16486
+ "font-size",
16487
+ "font-style",
16488
+ "font-weight",
16489
+ "height",
16490
+ "letter-spacing",
16491
+ "line-height",
16492
+ "margin",
16493
+ "margin-bottom",
16494
+ "margin-left",
16495
+ "margin-right",
16496
+ "margin-top",
16497
+ "max-height",
16498
+ "max-width",
16499
+ "min-height",
16500
+ "min-width",
16501
+ "opacity",
16502
+ "overflow",
16503
+ "padding",
16504
+ "padding-bottom",
16505
+ "padding-left",
16506
+ "padding-right",
16507
+ "padding-top",
16508
+ "text-align",
16509
+ "text-decoration",
16510
+ "text-indent",
16511
+ "text-overflow",
16512
+ "text-transform",
16513
+ "vertical-align",
16514
+ "white-space",
16515
+ "width",
16516
+ "word-break",
16517
+ "word-wrap"
16518
+ ]);
16519
+ function isRecord(value) {
16520
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
16521
+ }
16522
+ function isSafeUrl(value, attribute) {
16523
+ const normalized = Array.from(value).filter((character) => character.charCodeAt(0) > 32).join("").toLowerCase();
16524
+ if (!normalized || normalized.startsWith("#") || normalized.startsWith("/") || normalized.startsWith("./") || normalized.startsWith("../")) return true;
16525
+ if (/^(?:https?:|mailto:|tel:)/.test(normalized)) return true;
16526
+ return attribute === "src" && /^data:image\/(?:gif|jpe?g|png|webp);base64,/.test(normalized);
16527
+ }
16528
+ function isSafeStyleValue(value) {
16529
+ const normalized = value.toLowerCase().replace(/\s+/g, "");
16530
+ return !normalized.includes("url(") && !normalized.includes("expression(") && !normalized.includes("javascript:") && !normalized.includes("behavior:") && !normalized.includes("-moz-binding");
16531
+ }
16532
+ function sanitizeRichTextStyle(value) {
16533
+ const source = isRecord(value) ? Object.entries(value).map(([property, propertyValue]) => `${property}:${String(propertyValue)}`).join(";") : String(value ?? "");
16534
+ const declarations = [];
16535
+ for (const declaration of source.split(";")) {
16536
+ const separator = declaration.indexOf(":");
16537
+ if (separator <= 0) continue;
16538
+ const property = declaration.slice(0, separator).trim().toLowerCase();
16539
+ const propertyValue = declaration.slice(separator + 1).trim();
16540
+ if (ALLOWED_STYLE_PROPERTIES.has(property) && propertyValue && isSafeStyleValue(propertyValue)) declarations.push(`${property}: ${propertyValue}`);
16541
+ }
16542
+ return declarations.join("; ");
16543
+ }
16245
16544
  // ../../node_modules/.pnpm/entities@8.1.0/node_modules/entities/dist/decode-codepoint.js
16246
16545
  /**
16247
16546
  * C1 Unicode control character reference replacements (code points 128–159).
@@ -16310,6 +16609,19 @@ function replaceCodePoint(codePoint) {
16310
16609
  function replaceCodePointXML(codePoint) {
16311
16610
  return isInvalidCodePoint(codePoint) ? 65533 : codePoint;
16312
16611
  }
16612
+ /**
16613
+ * Convert the code point of a decoded numeric entity to a string, replacing
16614
+ * invalid values.
16615
+ *
16616
+ * Fast path for plain BMP code points: [1..0x7F] and [0xA0..0xD7FF] pass
16617
+ * `replaceCodePoint` unchanged (no NUL, C1 remap, surrogate, or out-of-range
16618
+ * handling) and fit a single charCode. 0xd760 = 0xD800 (the first surrogate)
16619
+ * - 0xA0.
16620
+ * @param codePoint Unicode code point to convert.
16621
+ */
16622
+ function codePointToString(codePoint) {
16623
+ return codePoint - 1 >>> 0 < 127 || codePoint - 160 >>> 0 < 55136 ? String.fromCharCode(codePoint) : String.fromCodePoint(replaceCodePoint(codePoint));
16624
+ }
16313
16625
  // ../../node_modules/.pnpm/entities@8.1.0/node_modules/entities/dist/internal/decode-shared.js
16314
16626
  const BASE91_INVERSE = /* #__PURE__ */ (() => {
16315
16627
  const table = /* @__PURE__ */ new Uint8Array(127);
@@ -16546,6 +16858,31 @@ var CharCodes$1;
16546
16858
  })(CharCodes$1 || (CharCodes$1 = {}));
16547
16859
  /** Bit that needs to be set to convert an upper case ASCII character to lower case */
16548
16860
  const TO_LOWER_BIT = 32;
16861
+ const CONSUMED_SHIFT = 21;
16862
+ const CODE_POINT_MASK = 2097151;
16863
+ /**
16864
+ * Reserved consumed field for counts of at least 2047 characters after `&`.
16865
+ * The true count is in `longNumericConsumed`.
16866
+ */
16867
+ const CONSUMED_OVERFLOW = 2047;
16868
+ /**
16869
+ * Side channel for numeric entities of at least 2048 characters including
16870
+ * `&`. Set by `parseNumericEntity` when its consumed count reaches the
16871
+ * reserved value `CONSUMED_OVERFLOW`; callers read the true count from here.
16872
+ * A module-level slot avoids a tuple allocation on the hot path.
16873
+ */
16874
+ let longNumericConsumed = 0;
16875
+ /**
16876
+ * Extract the consumed count from a `parseNumericEntity` packed result,
16877
+ * recovering the true length from `longNumericConsumed` when the packed
16878
+ * field contains the sentinel. Read it before the next `parseNumericEntity`
16879
+ * call, which may overwrite the side channel. This helper owns that protocol.
16880
+ * @param packed Packed result of `parseNumericEntity`.
16881
+ */
16882
+ function unpackConsumed(packed) {
16883
+ const consumed = packed >>> CONSUMED_SHIFT;
16884
+ return consumed === CONSUMED_OVERFLOW ? longNumericConsumed : consumed;
16885
+ }
16549
16886
  /**
16550
16887
  * Unsigned subtraction trick: (code - lo) >>> 0 wraps negatives to large
16551
16888
  * values, so a single `<=` covers the entire [lo..hi] range check.
@@ -16958,6 +17295,202 @@ function determineBranch(decodeTree, current, nodeIndex, char) {
16958
17295
  }
16959
17296
  return -1;
16960
17297
  }
17298
+ /**
17299
+ * Read the decoded value from a trie node.
17300
+ * @param decodeTree The trie.
17301
+ * @param nodeIndex The index of the node.
17302
+ * @param valueLength The length of the value (1, 2, or 3).
17303
+ * @returns The decoded string.
17304
+ */
17305
+ function readTrieValue(decodeTree, nodeIndex, valueLength) {
17306
+ if (valueLength === 1) return String.fromCharCode(decodeTree[nodeIndex] & BinTrieFlags.VALUE_MASK);
17307
+ if (valueLength === 2) return String.fromCharCode(decodeTree[nodeIndex + 1]);
17308
+ return String.fromCharCode(decodeTree[nodeIndex + 1], decodeTree[nodeIndex + 2]);
17309
+ }
17310
+ /**
17311
+ * Parse a numeric entity (`&#DDD;` or `&#xHHH;`).
17312
+ *
17313
+ * Encodes the result as `(consumed << CONSUMED_SHIFT) | codepoint` (see
17314
+ * the packing comment at the top of the file; overlong entities spill
17315
+ * their length into `longNumericConsumed`). Returns 0 when no digits were
17316
+ * found.
17317
+ *
17318
+ * This is the sync counterpart of the streaming
17319
+ * `EntityDecoder#stateNumericDecimal` / `#stateNumericHex`. Digit parsing
17320
+ * matches those methods; only this packed result needs a value clamp.
17321
+ * @param input The input string.
17322
+ * @param numberStart Index of the `#` character.
17323
+ * @param inputLength Cached `input.length`.
17324
+ */
17325
+ function parseNumericEntity(input, numberStart, inputLength) {
17326
+ let offset = numberStart + 1;
17327
+ let cp = 0;
17328
+ let digitStart = offset;
17329
+ if (offset < inputLength && (input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes$1.LOWER_X) {
17330
+ offset += 1;
17331
+ digitStart = offset;
17332
+ while (offset < inputLength) {
17333
+ const char = input.charCodeAt(offset);
17334
+ if (isNumber(char)) cp = cp * 16 + (char - CharCodes$1.ZERO);
17335
+ else if (isHexadecimalCharacter(char)) cp = cp * 16 + ((char | TO_LOWER_BIT) - CharCodes$1.LOWER_A + 10);
17336
+ else break;
17337
+ offset += 1;
17338
+ }
17339
+ } else while (offset < inputLength) {
17340
+ const digit = input.charCodeAt(offset) - CharCodes$1.ZERO;
17341
+ if (digit >>> 0 > 9) break;
17342
+ cp = cp * 10 + digit;
17343
+ offset += 1;
17344
+ }
17345
+ if (offset === digitStart) return 0;
17346
+ if (offset < inputLength && input.charCodeAt(offset) === CharCodes$1.SEMI) offset += 1;
17347
+ if (cp > 1114111) cp = 1114112;
17348
+ let consumed = offset - numberStart;
17349
+ if (consumed >= CONSUMED_OVERFLOW) {
17350
+ longNumericConsumed = consumed;
17351
+ consumed = CONSUMED_OVERFLOW;
17352
+ }
17353
+ return consumed << CONSUMED_SHIFT | cp;
17354
+ }
17355
+ /**
17356
+ * Decode all entities in `input` using the HTML trie.
17357
+ *
17358
+ * Hard-wired to `htmlDecodeTree`: the inline root navigation below assumes
17359
+ * the HTML root's jump-table shape, so this must not be generalized to
17360
+ * other tries (the XML trie's dictionary root would silently match no
17361
+ * entities — `decodeXML` has its own hand-coded fast path instead).
17362
+ * @param input The string to decode.
17363
+ * @param isStrict Only match semicolon-terminated entities.
17364
+ * @param isAttribute Whether to apply attribute-specific parsing rules (disallowing certain non-semicolon terminators).
17365
+ * @returns The decoded string.
17366
+ */
17367
+ function decodeWithTrie(input, isStrict, isAttribute) {
17368
+ const decodeTree = htmlDecodeTree;
17369
+ let offset = input.indexOf("&");
17370
+ if (offset < 0) return input;
17371
+ const inputLength = input.length;
17372
+ let chunkStart = 0;
17373
+ let result = "";
17374
+ const root = decodeTree[0];
17375
+ const rootJumpOffset = root & BinTrieFlags.JUMP_TABLE;
17376
+ const rootBranchCount = (root & BinTrieFlags.BRANCH_LENGTH) >> 7;
17377
+ do {
17378
+ const entityStart = offset + 1;
17379
+ const firstChar = input.charCodeAt(entityStart);
17380
+ let consumed;
17381
+ let value;
17382
+ if (firstChar === CharCodes$1.NUM) {
17383
+ const packed = parseNumericEntity(input, entityStart, inputLength);
17384
+ consumed = unpackConsumed(packed);
17385
+ if (isStrict && consumed > 0 && input.charCodeAt(entityStart + consumed - 1) !== CharCodes$1.SEMI) consumed = 0;
17386
+ value = consumed === 0 ? "" : codePointToString(packed & CODE_POINT_MASK);
17387
+ } else if (isAlpha(firstChar)) {
17388
+ consumed = 0;
17389
+ value = "";
17390
+ const rootSlotIndex = firstChar - rootJumpOffset;
17391
+ let nodeIndex;
17392
+ if (rootSlotIndex >>> 0 < rootBranchCount) {
17393
+ const stored = decodeTree[1 + rootSlotIndex];
17394
+ nodeIndex = stored === 0 ? -1 : rootBranchCount + stored & 65535;
17395
+ } else nodeIndex = -1;
17396
+ let bestNodeIndex = 0;
17397
+ let bestValueLength = 0;
17398
+ let current = nodeIndex < 0 ? 0 : decodeTree[nodeIndex];
17399
+ let index = entityStart + 1;
17400
+ trie: while (index < inputLength) {
17401
+ while ((current & (BinTrieFlags.VALUE_LENGTH | BinTrieFlags.FLAG13)) === 0 && (current & BinTrieFlags.JUMP_TABLE) !== 0) {
17402
+ const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
17403
+ const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
17404
+ if (branchCount === 0) {
17405
+ if (input.charCodeAt(index) !== jumpOffset) break trie;
17406
+ nodeIndex += 1;
17407
+ } else {
17408
+ const slot = input.charCodeAt(index) - jumpOffset;
17409
+ if (slot >>> 0 >= branchCount) break trie;
17410
+ const stored = decodeTree[nodeIndex + 1 + slot];
17411
+ if (stored === 0) break trie;
17412
+ nodeIndex = nodeIndex + branchCount + stored & 65535;
17413
+ }
17414
+ current = decodeTree[nodeIndex];
17415
+ index += 1;
17416
+ if (index >= inputLength) break trie;
17417
+ }
17418
+ if ((current & (BinTrieFlags.VALUE_LENGTH | BinTrieFlags.FLAG13)) === BinTrieFlags.FLAG13) {
17419
+ const runLength = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
17420
+ if (input.charCodeAt(index) !== (current & BinTrieFlags.JUMP_TABLE)) break;
17421
+ index += 1;
17422
+ const remaining = runLength - 1;
17423
+ let wordIndex = nodeIndex + 1;
17424
+ let charIndexInPacked = 0;
17425
+ for (; charIndexInPacked + 1 < remaining; charIndexInPacked += 2) {
17426
+ const packed = decodeTree[wordIndex];
17427
+ if (input.charCodeAt(index) !== (packed & 255)) break trie;
17428
+ index += 1;
17429
+ if (input.charCodeAt(index) !== (packed >> 8 & 255)) break trie;
17430
+ index += 1;
17431
+ wordIndex += 1;
17432
+ }
17433
+ if (charIndexInPacked < remaining) {
17434
+ if (input.charCodeAt(index) !== (decodeTree[wordIndex] & 255)) break;
17435
+ index += 1;
17436
+ }
17437
+ nodeIndex += 1 + (runLength >> 1);
17438
+ current = decodeTree[nodeIndex];
17439
+ continue;
17440
+ }
17441
+ const valueLength = current >>> 14;
17442
+ const char = input.charCodeAt(index);
17443
+ if (valueLength !== 0) {
17444
+ if (char === CharCodes$1.SEMI) {
17445
+ consumed = index - entityStart + 1;
17446
+ value = valueLength === 1 ? String.fromCharCode(current & BinTrieFlags.VALUE_MASK) : readTrieValue(decodeTree, nodeIndex, valueLength);
17447
+ break;
17448
+ }
17449
+ if (!isStrict && (current & BinTrieFlags.FLAG13) === 0) {
17450
+ consumed = index - entityStart;
17451
+ bestNodeIndex = nodeIndex;
17452
+ bestValueLength = valueLength;
17453
+ }
17454
+ if (valueLength === 1) break;
17455
+ }
17456
+ const next = determineBranch(decodeTree, current, nodeIndex + (valueLength || 1), char);
17457
+ if (next < 0) break;
17458
+ nodeIndex = next;
17459
+ current = decodeTree[nodeIndex];
17460
+ index += 1;
17461
+ }
17462
+ if (value === "") {
17463
+ const finalVL = current >>> 14;
17464
+ if (finalVL !== 0 && !isStrict && (current & BinTrieFlags.FLAG13) === 0) {
17465
+ consumed = index - entityStart;
17466
+ bestNodeIndex = nodeIndex;
17467
+ bestValueLength = finalVL;
17468
+ }
17469
+ if (consumed > 0) value = readTrieValue(decodeTree, bestNodeIndex, bestValueLength);
17470
+ }
17471
+ } else {
17472
+ consumed = 0;
17473
+ value = "";
17474
+ }
17475
+ if (consumed === 0 || isAttribute && firstChar !== CharCodes$1.NUM && input.charCodeAt(entityStart + consumed - 1) !== CharCodes$1.SEMI && entityStart + consumed < inputLength && isEntityInAttributeInvalidEnd(input.charCodeAt(entityStart + consumed))) offset = entityStart;
17476
+ else {
17477
+ if (chunkStart < offset) result += input.slice(chunkStart, offset);
17478
+ result += value;
17479
+ offset = chunkStart = entityStart + consumed;
17480
+ }
17481
+ if (input.charCodeAt(offset) !== CharCodes$1.AMP) offset = input.indexOf("&", offset);
17482
+ } while (offset >= 0);
17483
+ return result + input.slice(chunkStart);
17484
+ }
17485
+ /**
17486
+ * Decodes an HTML string.
17487
+ * @param htmlString The string to decode.
17488
+ * @param mode The decoding mode.
17489
+ * @returns The decoded string.
17490
+ */
17491
+ function decodeHTML(htmlString, mode = DecodingMode.Legacy) {
17492
+ return decodeWithTrie(htmlString, mode === DecodingMode.Strict, mode === DecodingMode.Attribute);
17493
+ }
16961
17494
  // ../../node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/Tokenizer.js
16962
17495
  var CharCodes;
16963
17496
  (function(CharCodes) {
@@ -19992,202 +20525,73 @@ function parseDocument(data, options) {
19992
20525
  new Parser(handler, options).end(data);
19993
20526
  return handler.root;
19994
20527
  }
19995
- // ../../@weapp-core/shared/dist/rich-text.js
19996
- const ALLOWED_TAGS = /* @__PURE__ */ new Set([
19997
- "a",
19998
- "abbr",
19999
- "address",
20000
- "article",
20001
- "aside",
20002
- "b",
20003
- "bdi",
20004
- "bdo",
20005
- "big",
20006
- "blockquote",
20007
- "br",
20008
- "caption",
20009
- "center",
20010
- "cite",
20011
- "code",
20012
- "col",
20013
- "colgroup",
20014
- "dd",
20015
- "del",
20016
- "div",
20017
- "dl",
20018
- "dt",
20019
- "em",
20020
- "fieldset",
20021
- "font",
20022
- "h1",
20023
- "h2",
20024
- "h3",
20025
- "h4",
20026
- "h5",
20027
- "h6",
20028
- "header",
20029
- "hr",
20030
- "i",
20031
- "img",
20032
- "ins",
20033
- "label",
20034
- "legend",
20035
- "li",
20036
- "mark",
20037
- "ol",
20038
- "p",
20039
- "pre",
20040
- "q",
20041
- "rt",
20042
- "ruby",
20043
- "s",
20044
- "section",
20045
- "small",
20046
- "span",
20047
- "strong",
20048
- "sub",
20049
- "sup",
20050
- "table",
20051
- "tbody",
20052
- "td",
20053
- "tfoot",
20054
- "th",
20055
- "thead",
20056
- "tr",
20057
- "tt",
20058
- "u",
20059
- "ul"
20060
- ]);
20061
- const ALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
20062
- "abbr",
20063
- "align",
20064
- "alt",
20065
- "axis",
20066
- "bgcolor",
20067
- "border",
20068
- "cellpadding",
20069
- "cellspacing",
20070
- "class",
20071
- "colspan",
20072
- "dir",
20073
- "height",
20074
- "href",
20075
- "id",
20076
- "lang",
20077
- "rowspan",
20078
- "scope",
20079
- "span",
20080
- "start",
20081
- "style",
20082
- "summary",
20083
- "target",
20084
- "title",
20085
- "type",
20086
- "valign",
20087
- "width"
20528
+ // ../../@weapp-core/shared/dist/rich-text-native.js
20529
+ const NATIVE_ALLOWED_TAGS = /* @__PURE__ */ new Set([
20530
+ ...ALLOWED_TAGS,
20531
+ "footer",
20532
+ "nav"
20088
20533
  ]);
20089
- const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src"]);
20090
- const ALLOWED_STYLE_PROPERTIES = /* @__PURE__ */ new Set([
20091
- "background",
20092
- "background-color",
20093
- "border",
20094
- "border-bottom",
20095
- "border-color",
20096
- "border-left",
20097
- "border-radius",
20098
- "border-right",
20099
- "border-style",
20100
- "border-top",
20101
- "border-width",
20102
- "color",
20103
- "display",
20104
- "font-family",
20105
- "font-size",
20106
- "font-style",
20107
- "font-weight",
20108
- "height",
20109
- "letter-spacing",
20110
- "line-height",
20111
- "margin",
20112
- "margin-bottom",
20113
- "margin-left",
20114
- "margin-right",
20115
- "margin-top",
20116
- "max-height",
20117
- "max-width",
20118
- "min-height",
20119
- "min-width",
20120
- "opacity",
20121
- "overflow",
20122
- "padding",
20123
- "padding-bottom",
20124
- "padding-left",
20125
- "padding-right",
20126
- "padding-top",
20127
- "text-align",
20128
- "text-decoration",
20129
- "text-indent",
20130
- "text-overflow",
20131
- "text-transform",
20132
- "vertical-align",
20133
- "white-space",
20134
- "width",
20135
- "word-break",
20136
- "word-wrap"
20137
- ]);
20138
- function isRecord(value) {
20139
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
20140
- }
20141
- function isSafeUrl(value, attribute) {
20142
- const normalized = Array.from(value).filter((character) => character.charCodeAt(0) > 32).join("").toLowerCase();
20143
- if (!normalized || normalized.startsWith("#") || normalized.startsWith("/") || normalized.startsWith("./") || normalized.startsWith("../")) return true;
20144
- if (/^(?:https?:|mailto:|tel:)/.test(normalized)) return true;
20145
- return attribute === "src" && /^data:image\/(?:gif|jpe?g|png|webp);base64,/.test(normalized);
20146
- }
20147
- function isSafeStyleValue(value) {
20148
- const normalized = value.toLowerCase().replace(/\s+/g, "");
20149
- return !normalized.includes("url(") && !normalized.includes("expression(") && !normalized.includes("javascript:") && !normalized.includes("behavior:") && !normalized.includes("-moz-binding");
20150
- }
20151
- function sanitizeRichTextStyle(value) {
20152
- const source = isRecord(value) ? Object.entries(value).map(([property, propertyValue]) => `${property}:${String(propertyValue)}`).join(";") : String(value ?? "");
20153
- const declarations = [];
20154
- for (const declaration of source.split(";")) {
20155
- const separator = declaration.indexOf(":");
20156
- if (separator <= 0) continue;
20157
- const property = declaration.slice(0, separator).trim().toLowerCase();
20158
- const propertyValue = declaration.slice(separator + 1).trim();
20159
- if (ALLOWED_STYLE_PROPERTIES.has(property) && propertyValue && isSafeStyleValue(propertyValue)) declarations.push(`${property}: ${propertyValue}`);
20160
- }
20161
- return declarations.join("; ");
20162
- }
20163
- function sanitizeRichTextAttributes(value, tagName) {
20534
+ const NATIVE_TAG_ATTRIBUTES = {
20535
+ bdo: ["dir"],
20536
+ col: ["span", "width"],
20537
+ colgroup: ["span", "width"],
20538
+ img: [
20539
+ "alt",
20540
+ "src",
20541
+ "height",
20542
+ "width"
20543
+ ],
20544
+ ol: ["start", "type"],
20545
+ table: ["width"],
20546
+ td: [
20547
+ "colspan",
20548
+ "height",
20549
+ "rowspan",
20550
+ "width"
20551
+ ],
20552
+ th: [
20553
+ "colspan",
20554
+ "height",
20555
+ "rowspan",
20556
+ "width"
20557
+ ],
20558
+ tr: [
20559
+ "colspan",
20560
+ "height",
20561
+ "rowspan",
20562
+ "width"
20563
+ ]
20564
+ };
20565
+ function sanitizeNativeRichTextAttributes(value, tagName) {
20164
20566
  if (!isRecord(value)) return {};
20165
20567
  const attributes = {};
20568
+ const nativeAttributes = Object.prototype.hasOwnProperty.call(NATIVE_TAG_ATTRIBUTES, tagName) ? NATIVE_TAG_ATTRIBUTES[tagName] : void 0;
20166
20569
  for (const [rawName, rawValue] of Object.entries(value)) {
20167
20570
  const name = rawName.trim().toLowerCase();
20168
20571
  if (name.startsWith("on") || name === "srcdoc") continue;
20169
- if (!ALLOWED_ATTRIBUTES.has(name) && name !== "src" && !name.startsWith("aria-") && !name.startsWith("data-")) continue;
20572
+ if (name !== "class" && name !== "style" && !nativeAttributes?.includes(name)) continue;
20170
20573
  if (name === "src" && tagName !== "img") continue;
20171
20574
  const serialized = name === "style" ? sanitizeRichTextStyle(rawValue) : String(rawValue ?? "");
20172
- if (!serialized || URL_ATTRIBUTES.has(name) && !isSafeUrl(serialized, name)) continue;
20575
+ if (!serialized || name === "src" && !isSafeUrl(serialized, name)) continue;
20576
+ if (name === "src" && !/^(?:https?:)?\/\//i.test(serialized.trim())) continue;
20173
20577
  attributes[name] = serialized;
20174
20578
  }
20175
- if (tagName === "a") attributes.rel = "noopener noreferrer";
20176
20579
  return attributes;
20177
20580
  }
20178
20581
  function convertSourceNode(value) {
20179
20582
  if (!isRecord(value)) return [];
20180
- if (value.type === "text" || !value.name && typeof value.text === "string") return [{
20583
+ if (value.type === "text") return typeof value.text === "string" ? [{
20181
20584
  type: "text",
20182
- text: String(value.text ?? "")
20183
- }];
20585
+ text: decodeHTML(value.text)
20586
+ }] : [];
20587
+ if (value.type !== void 0 && value.type !== "node" || typeof value.name !== "string") return [];
20588
+ const name = value.name.toLowerCase();
20589
+ if (!NATIVE_ALLOWED_TAGS.has(name)) return [];
20184
20590
  const children = Array.isArray(value.children) ? value.children.flatMap(convertSourceNode) : [];
20185
- const name = String(value.name ?? "").toLowerCase();
20186
- if (!ALLOWED_TAGS.has(name)) return children;
20187
20591
  return [{
20188
20592
  type: "element",
20189
20593
  name,
20190
- attrs: sanitizeRichTextAttributes(value.attrs, name),
20594
+ attrs: sanitizeNativeRichTextAttributes(value.attrs, name),
20191
20595
  children
20192
20596
  }];
20193
20597
  }
@@ -20198,17 +20602,17 @@ function convertParsedNode(node) {
20198
20602
  }];
20199
20603
  if (node.type !== "tag") return [];
20200
20604
  const element = node;
20201
- const children = element.children.flatMap(convertParsedNode);
20202
20605
  const name = element.name.toLowerCase();
20203
- if (!ALLOWED_TAGS.has(name)) return children;
20606
+ if (!NATIVE_ALLOWED_TAGS.has(name)) return [];
20607
+ const children = element.children.flatMap(convertParsedNode);
20204
20608
  return [{
20205
20609
  type: "element",
20206
20610
  name,
20207
- attrs: sanitizeRichTextAttributes(element.attribs, name),
20611
+ attrs: sanitizeNativeRichTextAttributes(element.attribs, name),
20208
20612
  children
20209
20613
  }];
20210
20614
  }
20211
- function normalizeRichTextNodes(value) {
20615
+ function normalizeNativeRichTextNodes(value) {
20212
20616
  if (typeof value === "string") return parseDocument(value, {
20213
20617
  decodeEntities: true,
20214
20618
  lowerCaseAttributeNames: true,
@@ -20222,7 +20626,6 @@ function materializeNode(node) {
20222
20626
  type: "text",
20223
20627
  data: node.text
20224
20628
  };
20225
- for (const name of Object.keys(node.attrs)) if (name.startsWith("data-sim-")) delete node.attrs[name];
20226
20629
  return {
20227
20630
  type: "tag",
20228
20631
  name: node.name,
@@ -20232,7 +20635,7 @@ function materializeNode(node) {
20232
20635
  }
20233
20636
  /** 富文本直接成为已渲染节点,不能再进入 WXML 表达式或组件处理流程。 */
20234
20637
  function renderRichTextNodes(value) {
20235
- return normalizeRichTextNodes(value).map(materializeNode);
20638
+ return normalizeNativeRichTextNodes(value).map(materializeNode);
20236
20639
  }
20237
20640
  // ../../mpcore/packages/simulator/src/view/templateIncludes.ts
20238
20641
  /** 展开 include 的可渲染内容,并保留嵌套引用的来源文件。 */
@@ -20330,7 +20733,7 @@ function parseWxsTemplateDocument(templateSource) {
20330
20733
  return parseSharedWxsDocument(templateSource);
20331
20734
  }
20332
20735
  // ../../mpcore/packages/simulator/src/runtime/render/shared.ts
20333
- const LEADING_SLASH_RE$4 = /^\/+/;
20736
+ const LEADING_SLASH_RE$3 = /^\/+/;
20334
20737
  const EVENT_BINDING_ATTRS = [
20335
20738
  "bindtap",
20336
20739
  "bind:tap",
@@ -20439,6 +20842,7 @@ function applyNodeBindings(node, scope, richText = false) {
20439
20842
  continue;
20440
20843
  }
20441
20844
  const resolvedValue = resolveNativeAttributeValue(node, key, scope, (source) => typeof value === "string" ? resolveAttributeValue(value, source) : value);
20845
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
20442
20846
  if (key === "value") setNativePickerValue(node, resolvedValue);
20443
20847
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
20444
20848
  node.attribs[key] = String(resolvedValue ?? "");
@@ -20494,7 +20898,7 @@ function resolveOwnerComponent(context, ownerJsonPath, ownerFilePath, alias) {
20494
20898
  if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return;
20495
20899
  const rawPath = usingComponents[alias];
20496
20900
  if (typeof rawPath !== "string") return;
20497
- return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$4, "");
20901
+ return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$3, "");
20498
20902
  } catch {
20499
20903
  return;
20500
20904
  }
@@ -20542,8 +20946,8 @@ function resolveComponentGenerics(context, hostNode, ownerJsonPath, ownerFilePat
20542
20946
  }
20543
20947
  const defaultPath = typeof definition === "object" && definition !== null ? definition.default : void 0;
20544
20948
  if (typeof defaultPath !== "string" || !defaultPath) continue;
20545
- const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$4, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
20546
- resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$4, ""));
20949
+ const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$3, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
20950
+ resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$3, ""));
20547
20951
  }
20548
20952
  return resolved.size > 0 ? resolved : void 0;
20549
20953
  }
@@ -20575,7 +20979,7 @@ function resolveComponentProperties(clonedNode, scope, definition) {
20575
20979
  const bindingExpressions = {};
20576
20980
  const declaredProperties = resolveComponentPropertyDefinitions(definition);
20577
20981
  for (const [key, value] of Object.entries(clonedNode.attribs ?? {})) {
20578
- if (key.startsWith("bind") || key.startsWith("generic:")) continue;
20982
+ if (key.startsWith("bind") || key.startsWith("generic:") || key.startsWith("wx:") || isReservedComponentHostProperty(key)) continue;
20579
20983
  const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
20580
20984
  const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
20581
20985
  if (isMustacheOnly$1(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
@@ -20830,7 +21234,7 @@ function reconcileRuntimePageTree(context, page, bindingsOnly = false) {
20830
21234
  for (;;) {
20831
21235
  bindAttachmentBindingScope(context, page);
20832
21236
  if (page.__lastChangedKeys__) context.changedPageKeys = page.__lastChangedKeys__;
20833
- const route = page.route.replace(LEADING_SLASH_RE$4, "");
21237
+ const route = page.route.replace(LEADING_SLASH_RE$3, "");
20834
21238
  const resourcePath = context.project.routes.find((item) => item.route === route)?.resourcePath ?? route;
20835
21239
  const templatePath = path.resolve(context.project.miniprogramRootPath, `${resourcePath}.wxml`);
20836
21240
  const document = parseTemplateDocument(readTemplateSource(context.artifactSource, templatePath));
@@ -21942,11 +22346,11 @@ var RuntimeRenderQueue = class {
21942
22346
  }
21943
22347
  };
21944
22348
  // ../../mpcore/packages/simulator/src/project/resolveRoutes.ts
21945
- const LEADING_SLASH_RE$3 = /^\/+/;
22349
+ const LEADING_SLASH_RE$2 = /^\/+/;
21946
22350
  const TRAILING_SLASH_RE$1 = /\/+$/;
21947
22351
  const DUPLICATE_SLASH_RE = /\/{2,}/g;
21948
22352
  function normalizeSegment(value) {
21949
- return value.replace(LEADING_SLASH_RE$3, "").replace(TRAILING_SLASH_RE$1, "");
22353
+ return value.replace(LEADING_SLASH_RE$2, "").replace(TRAILING_SLASH_RE$1, "");
21950
22354
  }
21951
22355
  function pushRoute(records, seen, record) {
21952
22356
  if (!record.route || seen.has(record.route)) return;
@@ -41447,7 +41851,7 @@ function createValueEventDetail(value, detail) {
41447
41851
  ...detail ?? {}
41448
41852
  };
41449
41853
  }
41450
- function resolvePageScopeId$1(scopeId) {
41854
+ function resolvePageScopeId(scopeId) {
41451
41855
  if (!scopeId) return null;
41452
41856
  const pagePathIndex = scopeId.indexOf("/page/");
41453
41857
  return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
@@ -41472,7 +41876,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
41472
41876
  if (!scope || !this.interactions) return nodes;
41473
41877
  return nodes.filter((node) => {
41474
41878
  const nodeScope = node.attribs?.["data-sim-scope"];
41475
- return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId$1(nodeScope)) === scope;
41879
+ return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId(nodeScope)) === scope;
41476
41880
  });
41477
41881
  }
41478
41882
  async $(selector) {
@@ -41509,7 +41913,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
41509
41913
  async pageScope() {
41510
41914
  this.assertActive();
41511
41915
  if (!this.interactions) throw new Error("Node interactions are not available for this headless testing node.");
41512
- return this.interactions.createScopeHandle(resolvePageScopeId$1(this.node.attribs?.["data-sim-scope"] ?? null));
41916
+ return this.interactions.createScopeHandle(resolvePageScopeId(this.node.attribs?.["data-sim-scope"] ?? null));
41513
41917
  }
41514
41918
  async page() {
41515
41919
  this.assertActive();
@@ -41602,7 +42006,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
41602
42006
  }
41603
42007
  };
41604
42008
  // ../../mpcore/packages/simulator/src/view/render.ts
41605
- const LEADING_SLASH_RE$2 = /^\/+/;
42009
+ const LEADING_SLASH_RE$1 = /^\/+/;
41606
42010
  const TEMPLATE_INTERPOLATION_RE = /\{\{([^{}]+)\}\}/g;
41607
42011
  function resolveRawValueByPath(source, expression) {
41608
42012
  const normalized = expression.trim();
@@ -41641,6 +42045,7 @@ function interpolateDomTree(root, data) {
41641
42045
  let dataset;
41642
42046
  for (const [key, value] of Object.entries(node.attribs)) {
41643
42047
  const resolvedValue = isMustacheOnly(value) ? resolveRawValueByPath(data, value.trim().slice(2, -2)) : interpolateTemplate(value, data);
42048
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
41644
42049
  if (key === "value") setNativePickerValue(node, resolvedValue);
41645
42050
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
41646
42051
  node.attribs[key] = String(resolvedValue ?? "");
@@ -41668,7 +42073,7 @@ function serializeDomNode(node) {
41668
42073
  return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode).join("")}</${tagName}>`;
41669
42074
  }
41670
42075
  function renderPageTree(project, page) {
41671
- const route = page.route.replace(LEADING_SLASH_RE$2, "");
42076
+ const route = page.route.replace(LEADING_SLASH_RE$1, "");
41672
42077
  const templatePath = path.resolve(project.miniprogramRootPath, `${route}.wxml`);
41673
42078
  const templateSource = project.artifactSource.readText(templatePath);
41674
42079
  if (templateSource == null) throw new Error(`Missing template in headless runtime: ${templatePath}`);
@@ -41964,6 +42369,21 @@ function coordinate(value) {
41964
42369
  function nodeKey(node) {
41965
42370
  return node.attribs?.["data-sim-node"] ?? "";
41966
42371
  }
42372
+ /** 按稳定渲染键把保留的测试节点句柄映射到当前树;有键但已移除时返回 undefined。 */
42373
+ function resolveNativeNode(root, node) {
42374
+ const key = nodeKey(node);
42375
+ if (!key) return node;
42376
+ let match;
42377
+ const visit = (current) => {
42378
+ if (current.attribs?.["data-sim-node"] === key) {
42379
+ match = current;
42380
+ return;
42381
+ }
42382
+ for (const child of current.children ?? []) if (!match) visit(child);
42383
+ };
42384
+ visit(root);
42385
+ return match;
42386
+ }
41967
42387
  /** 原生滚动位置独立于绑定值;未改变的绑定不能覆盖用户滚动。 */
41968
42388
  function syncNativeScrollViews(page, root, emit) {
41969
42389
  let states = pageScrollViews.get(page);
@@ -42065,6 +42485,14 @@ function dispatchNativeNodeEvent(page, node, eventName, event, wx, resolveMethod
42065
42485
  const origin = getNativeNodeOwner(node)?.target ?? node;
42066
42486
  let handlers;
42067
42487
  let handled = false;
42488
+ let eligibility = node;
42489
+ while (eligibility) {
42490
+ if (eligibility.name === "button") {
42491
+ if (getNativeBooleanValue(getNativeNodeOwner(eligibility)?.target ?? eligibility, "disabled")) return true;
42492
+ break;
42493
+ }
42494
+ eligibility = eligibility.parent;
42495
+ }
42068
42496
  const collectHandler = (scopeId, target, binding) => {
42069
42497
  if (binding.method) {
42070
42498
  const call = resolveMethod(scopeId, binding.method);
@@ -45685,14 +46113,14 @@ function createHeadlessWxState(scheduler = nativeScheduler, options = {}) {
45685
46113
  };
45686
46114
  }
45687
46115
  // ../../mpcore/packages/simulator/src/runtime/session.ts
45688
- const LEADING_SLASH_RE$1 = /^\/+/;
46116
+ const LEADING_SLASH_RE = /^\/+/;
45689
46117
  const PAGE_STACK_LIMIT = 10;
45690
46118
  const WHITESPACE_RE = /\s+/;
45691
46119
  const DATA_ATTR_SELECTOR_RE = /^\[data-([^=\]]+)="([^"]*)"\]$/;
45692
46120
  const COMPOUND_SELECTOR_PART_RE = /#[\w-]+|\.[\w-]+|\[data-[^=\]]+="[^"]*"\]|[A-Za-z][\w-]*/g;
45693
46121
  const DATASET_KEY_RE = /-([a-z])/g;
45694
46122
  function stripLeadingSlash(route) {
45695
- return route.replace(LEADING_SLASH_RE$1, "");
46123
+ return route.replace(LEADING_SLASH_RE, "");
45696
46124
  }
45697
46125
  function normalizeQuery(queryString) {
45698
46126
  const query = new URLSearchParams(queryString);
@@ -45743,9 +46171,9 @@ function readJsonObject(project, filePath) {
45743
46171
  }
45744
46172
  function resolveNavigationPath(targetPath, baseRoute) {
45745
46173
  if (!targetPath) throw new Error("Navigation url must include a pathname in headless runtime.");
45746
- if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE$1, "");
46174
+ if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE, "");
45747
46175
  if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
45748
- return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$1, "");
46176
+ return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE, "");
45749
46177
  }
45750
46178
  var HeadlessSession = class {
45751
46179
  project;
@@ -46086,15 +46514,20 @@ var HeadlessSession = class {
46086
46514
  }
46087
46515
  dispatchNativeNodeEvent(node, eventName, event, onHandlerResult) {
46088
46516
  const current = this.requireCurrentPage("dispatchNativeNodeEvent()");
46089
- if (eventName === "tap") this.renderCurrentPage();
46090
- return dispatchNativeNodeEvent(current, node, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
46517
+ const rendered = eventName === "tap" ? this.renderCurrentPage() : void 0;
46518
+ const currentNode = rendered ? resolveNativeNode(rendered.root, node) : node;
46519
+ if (!currentNode) throw new Error("Native testing node is no longer present in the current page.");
46520
+ const handled = dispatchNativeNodeEvent(current, currentNode, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
46091
46521
  const instance = this.componentCache.get(scopeId);
46092
46522
  const scope = this.componentScopes.get(scopeId);
46093
46523
  return instance?.__definition__ && scope ? {
46094
46524
  definition: instance.__definition__,
46095
- ownerScopeId: scope.ownerScopeId ?? null
46525
+ ownerScopeId: scope.ownerScopeId ?? null,
46526
+ name: typeof instance.properties?.name === "string" ? instance.properties.name : void 0,
46527
+ value: instance.properties && Object.hasOwn(instance.properties, "value") ? instance.properties.value : void 0
46096
46528
  } : void 0;
46097
46529
  });
46530
+ return eventName === "tap" && Boolean(node.attribs?.["data-sim-node"]) ? true : handled;
46098
46531
  }
46099
46532
  requestRender(callback) {
46100
46533
  this.assertActive();
@@ -46965,16 +47398,16 @@ function resolveTestingPagePath(route) {
46965
47398
  return route.replace(PRIVATE_PLUGIN_ROUTE_RE, "__plugin__/$1/$2");
46966
47399
  }
46967
47400
  // ../../mpcore/packages/simulator/src/testing/pageWait.ts
46968
- const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
46969
- const DEFAULT_WAIT_INTERVAL$1 = 10;
47401
+ const DEFAULT_WAIT_TIMEOUT = 1e3;
47402
+ const DEFAULT_WAIT_INTERVAL = 10;
46970
47403
  function normalizeInput(value, label) {
46971
47404
  const normalized = value.trim();
46972
47405
  if (!normalized) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
46973
47406
  return normalized;
46974
47407
  }
46975
- async function pollUntil$2(access, check, errorMessage, options) {
46976
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
46977
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
47408
+ async function pollUntil$1(access, check, errorMessage, options) {
47409
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
47410
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
46978
47411
  const deadline = Date.now() + timeout;
46979
47412
  while (true) {
46980
47413
  const result = await check();
@@ -46986,34 +47419,34 @@ async function pollUntil$2(access, check, errorMessage, options) {
46986
47419
  async function waitForPageSelector(access, selector, options = {}) {
46987
47420
  const normalizedSelector = normalizeInput(selector, "Selector");
46988
47421
  if (options.state === "detached") {
46989
- await pollUntil$2(access, async () => await access.findOne(normalizedSelector) ? null : true, `Timed out waiting for selector "${normalizedSelector}" to become detached in headless testing runtime.`, options);
47422
+ await pollUntil$1(access, async () => await access.findOne(normalizedSelector) ? null : true, `Timed out waiting for selector "${normalizedSelector}" to become detached in headless testing runtime.`, options);
46990
47423
  return null;
46991
47424
  }
46992
- return await pollUntil$2(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
47425
+ return await pollUntil$1(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
46993
47426
  }
46994
47427
  async function waitForPageComponent(access, selector, options = {}) {
46995
47428
  const normalizedSelector = normalizeInput(selector, "Selector");
46996
- return await pollUntil$2(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
47429
+ return await pollUntil$1(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
46997
47430
  }
46998
47431
  async function waitForPageComponents(access, selector, count = 1, options = {}) {
46999
47432
  const normalizedSelector = normalizeInput(selector, "Selector");
47000
47433
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
47001
- return await pollUntil$2(access, async () => {
47434
+ return await pollUntil$1(access, async () => {
47002
47435
  const components = await access.selectComponents(normalizedSelector);
47003
47436
  return components.length >= normalizedCount ? components : null;
47004
47437
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
47005
47438
  }
47006
47439
  async function waitForPageText(access, text, options = {}) {
47007
47440
  const normalizedText = normalizeInput(text, "Text");
47008
- return await pollUntil$2(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
47441
+ return await pollUntil$1(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
47009
47442
  }
47010
47443
  async function waitForPageTextGone(access, text, options = {}) {
47011
47444
  const normalizedText = normalizeInput(text, "Text");
47012
- await pollUntil$2(access, async () => (await access.wxml()).includes(normalizedText) ? null : true, `Timed out waiting for text "${normalizedText}" to disappear in headless testing runtime.`, options);
47445
+ await pollUntil$1(access, async () => (await access.wxml()).includes(normalizedText) ? null : true, `Timed out waiting for text "${normalizedText}" to disappear in headless testing runtime.`, options);
47013
47446
  }
47014
47447
  async function waitForPageData(access, path, matcher, hasMatcher, options = {}) {
47015
47448
  const normalizedPath = normalizeInput(path, "Data path");
47016
- return await pollUntil$2(access, async () => {
47449
+ return await pollUntil$1(access, async () => {
47017
47450
  const value = await access.data(normalizedPath);
47018
47451
  if (typeof matcher === "function") return matcher(value) ? value : null;
47019
47452
  if (hasMatcher) return Object.is(value, matcher) ? value : null;
@@ -47033,7 +47466,7 @@ function matchesDataset(node, expected) {
47033
47466
  const dataset = node.dataset ?? {};
47034
47467
  return Object.entries(expected).every(([key, value]) => String(dataset[key] ?? "") === String(value));
47035
47468
  }
47036
- async function pollUntil$1(access, check, errorMessage, options) {
47469
+ async function pollUntil(access, check, errorMessage, options) {
47037
47470
  const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_RENDERED_WAIT_TIMEOUT)) : DEFAULT_RENDERED_WAIT_TIMEOUT;
47038
47471
  const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_RENDERED_WAIT_INTERVAL)) : DEFAULT_RENDERED_WAIT_INTERVAL;
47039
47472
  const deadline = Date.now() + timeout;
@@ -47072,7 +47505,7 @@ async function waitForRenderedPage(access, options = {}) {
47072
47505
  access.assertActive();
47073
47506
  if (options.selector) {
47074
47507
  const selector = normalizeSelector(options.selector);
47075
- return await pollUntil$1(access, async () => {
47508
+ return await pollUntil(access, async () => {
47076
47509
  const nodes = await readRenderedNodes(access, selector, options);
47077
47510
  return nodes.some((node) => matchesDataset(node, options.dataset)) ? JSON.stringify({
47078
47511
  nodes,
@@ -47080,7 +47513,7 @@ async function waitForRenderedPage(access, options = {}) {
47080
47513
  }) : null;
47081
47514
  }, `Timed out waiting page rendered: selector=${selector} dataset=${JSON.stringify(options.dataset ?? {})}`, options);
47082
47515
  }
47083
- return await pollUntil$1(access, async () => {
47516
+ return await pollUntil(access, async () => {
47084
47517
  const wxml = await access.wxml();
47085
47518
  const normalizedWxml = wxml.trim();
47086
47519
  if (options.predicate?.(wxml)) return wxml;
@@ -47089,52 +47522,6 @@ async function waitForRenderedPage(access, options = {}) {
47089
47522
  return null;
47090
47523
  }, options.text ? `Timed out waiting page rendered: text=${options.text}` : options.predicate ? "Timed out waiting page rendered: predicate=true" : "Timed out waiting page rendered: non-empty wxml", options);
47091
47524
  }
47092
- // ../../mpcore/packages/simulator/src/testing/sessionHandle/shared.ts
47093
- const LEADING_SLASH_RE = /^\/+/;
47094
- const DEFAULT_WAIT_TIMEOUT = 1e3;
47095
- const DEFAULT_WAIT_INTERVAL = 10;
47096
- function normalizeRoute(route) {
47097
- return route.replace(LEADING_SLASH_RE, "");
47098
- }
47099
- function resolvePageScopeId(scopeId) {
47100
- const pagePathIndex = scopeId.indexOf("/page/");
47101
- return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
47102
- }
47103
- function normalizeNonEmptyInput(value, label) {
47104
- const normalizedValue = value.trim();
47105
- if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
47106
- return normalizedValue;
47107
- }
47108
- function cloneProtocolValue(value) {
47109
- if (!value || typeof value !== "object") return value;
47110
- return JSON.parse(JSON.stringify(value));
47111
- }
47112
- async function waitForDelay(ms = 0) {
47113
- if (ms <= 0) return;
47114
- await new Promise((resolve) => setTimeout(resolve, ms));
47115
- }
47116
- async function pollUntil(check, errorMessage, options = {}) {
47117
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
47118
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
47119
- const deadline = Date.now() + timeout;
47120
- while (true) {
47121
- const result = await check();
47122
- if (result != null) return result;
47123
- if (Date.now() >= deadline) throw new Error(errorMessage);
47124
- await waitForDelay(interval);
47125
- }
47126
- }
47127
- async function runWithTimeout(operation, timeout, message) {
47128
- if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
47129
- let timer;
47130
- try {
47131
- return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
47132
- timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
47133
- })]);
47134
- } finally {
47135
- if (timer) clearTimeout(timer);
47136
- }
47137
- }
47138
47525
  // ../../mpcore/packages/simulator/src/testing/pageHandle.ts
47139
47526
  var HeadlessTestingPageHandle = class {
47140
47527
  project;
@@ -47472,13 +47859,13 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
47472
47859
  return currentPage ? new HeadlessTestingPageHandle(this.project, currentPage, this.session) : null;
47473
47860
  }
47474
47861
  async pageScope() {
47475
- return new HeadlessTestingScopeHandle(resolvePageScopeId(this.scopeId), this.project, this.session);
47862
+ return new HeadlessTestingScopeHandle(resolvePageScopeId$1(this.scopeId), this.project, this.session);
47476
47863
  }
47477
47864
  async ownerComponent() {
47478
47865
  return this.createScopeHandle(this.session.selectOwnerComponent(this.scopeId));
47479
47866
  }
47480
47867
  async waitForOwnerComponent(options = {}) {
47481
- return await pollUntil(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
47868
+ return await pollUntil$2(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
47482
47869
  }
47483
47870
  async selectComponent(selector) {
47484
47871
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
@@ -47491,12 +47878,12 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
47491
47878
  }
47492
47879
  async waitForComponent(selector, options = {}) {
47493
47880
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
47494
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
47881
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
47495
47882
  }
47496
47883
  async waitForComponents(selector, count = 1, options = {}) {
47497
47884
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
47498
47885
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
47499
- return await pollUntil(async () => {
47886
+ return await pollUntil$2(async () => {
47500
47887
  const components = await this.selectAllComponents(normalizedSelector);
47501
47888
  return components.length >= normalizedCount ? components : null;
47502
47889
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -47599,12 +47986,12 @@ var HeadlessTestingSessionHandle = class {
47599
47986
  }
47600
47987
  async waitForComponent(selector, options = {}) {
47601
47988
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
47602
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
47989
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
47603
47990
  }
47604
47991
  async waitForComponents(selector, count = 1, options = {}) {
47605
47992
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
47606
47993
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
47607
- return await pollUntil(async () => {
47994
+ return await pollUntil$2(async () => {
47608
47995
  const components = await this.selectAllComponents(normalizedSelector);
47609
47996
  return components.length >= normalizedCount ? components : null;
47610
47997
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -47640,7 +48027,7 @@ var HeadlessTestingSessionHandle = class {
47640
48027
  async waitForCurrentPage(route, options = {}) {
47641
48028
  const normalizedRoute = route?.trim();
47642
48029
  if (normalizedRoute != null && !normalizedRoute) throw new Error("Route must be a non-empty string in headless testing runtime.");
47643
- return await pollUntil(async () => {
48030
+ return await pollUntil$2(async () => {
47644
48031
  const currentPageInstance = this.session.getCurrentPages().at(-1);
47645
48032
  if (!currentPageInstance) return null;
47646
48033
  const current = new HeadlessTestingPageHandle(this.project, currentPageInstance, this.session);