@mpcore/simulator 1.3.5-dev.20261117.1 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +5 -3
  2. package/dist/index.mjs +275 -126
  3. package/package.json +7 -7
package/README.md CHANGED
@@ -76,13 +76,15 @@ Node/browser 宿主提供 `BeforeAppRoute`、`BeforePageUnload`、`AppRoute`、`
76
76
 
77
77
  Node/browser 的原生 tap 到达未禁用的 `button form-type="submit"` 时,在 tap 回调之后提交最近的参与表单。提交目标、字段值与方法所有者在回调前固定;组件销毁、重渲染或同路由重建不会把提交转交给新实例。`tap()` 等待 tap 与 submit 的异步处理,继续传递结果或错误。普通插槽按声明归属参与;跨私有组件边界的按钮需要 `wx://form-field-button`,原生字段分组需要 `wx://form-field-group`。WXML 按 XML 节点结构解析,不应用 HTML 对嵌套 `form` 的隐式修复。
78
78
 
79
+ `checked` / `disabled` 在序列化前保留原始绑定值,裸属性为 true,空值或缺失绑定为 false。禁用按钮不派发 tap 或 submit。保留的 tap 句柄在激活前按节点身份重新定位到当前渲染树,节点已移除时拒绝分发,不能调用旧回调。
80
+
79
81
  后续监听器同步抛错时,测试句柄仍观察并等待此前已启动的异步处理。只有该同步错误时原样抛出;异步处理也失败时,抛出包含全部已收集失败的 `AggregateError`,并以原同步错误作为 `cause`,避免遗留未处理的 Promise 拒绝。
80
82
 
81
- `submit.detail.value` 来自参与表单的具名原生控件当前渲染绑定,包含 input/textarea、switch、slider、picker、radio-group 与 checkbox-group;picker 数组保留原始绑定类型,不从逗号字符串猜测值。此能力不补齐未绑定输入的宿主状态、`wx://form-field` 自定义值导出、reset 或真实 `formId` 上报,也不把任意页面数据当作原生字段值。
83
+ `submit.detail.value` 来自参与表单的具名原生控件当前渲染绑定,包含 input/textarea、switch、slider、picker、radio-group 与 checkbox-group;picker 数组保留原始绑定类型,不从逗号字符串猜测值。参与的 `wx://form-field` 组件按自己的当前 name/value 收集,保留对象、false、0 和 null,并在 tap 回调前克隆值。私有组件内部字段仍被隔离。此能力不补齐未绑定输入的宿主状态、reset 或真实 `formId` 上报,也不把任意页面数据当作原生字段值。
82
84
 
83
- `rich-text` 的结构化 `nodes` 与 HTML 字符串通过 `@weapp-core/shared/rich-text` 的共同安全规则生成实际渲染子树,支持更新和清空。内容不会再次解释为 WXML 表达式、事件或自定义组件;外部内容不能伪造 `data-sim-*` 元数据。通用 `text()`、快照和序列化观察同一份渲染内容,`attr('nodes')` 仍是既有字符串属性,不是结构化属性 API。富文本内部不获得 WXML 声明作用域;需要检查内部渲染节点时使用 XPath,而不是放宽声明作用域内的 CSS 查询。
85
+ `rich-text` 的结构化 `nodes` 与 HTML 字符串通过 `@weapp-core/shared/rich-text` 的 `normalizeNativeRichTextNodes` 生成实际渲染子树,支持更新和清空。仅保留微信原生支持的节点和逐标签属性,未知节点及子树被移除;文本实体仅解码一次,内容不会再次解释为 WXML 表达式、事件或自定义组件,也不能伪造 `data-sim-*` 元数据。`normalizeRichTextNodes` 保持独立的 Web 规范化策略,不携带原生策略及其额外解码代码。通用 `text()`、快照和序列化观察同一份渲染内容,`attr('nodes')` 仍是既有字符串属性,不是结构化属性 API。富文本内部不获得 WXML 声明作用域;需要检查内部渲染节点时使用 XPath,而不是放宽声明作用域内的 CSS 查询。
84
86
 
85
- 浏览器预览取消富文本链接的普通/辅助点击导航和 HTML 表单默认提交;业务 tap 与原生表单动作仍由模拟器分发,不能让浏览器额外导航或再次提交。
87
+ 浏览器预览取消富文本链接的普通/辅助点击导航和 HTML 表单默认提交;富文本链接与表单按钮的中键按下阶段也取消 Windows 自动滚动等宿主默认动作,不影响主键按下。业务 tap 与原生表单动作仍由模拟器分发,不能让浏览器额外导航或再次提交。
86
88
 
87
89
  上述能力属于模拟器模型,不代表真实微信 IDE 或设备验收。
88
90
 
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { TemplateLexicalError, compileDialect, createParser, decodeAttribute, ex
7
7
  import postcss from "postcss";
8
8
  import valueParser from "postcss-value-parser";
9
9
  import { weapp } from "@weapp-vite/wxml/presets";
10
- import { normalizeRichTextNodes } from "@weapp-core/shared/rich-text";
10
+ import { normalizeNativeRichTextNodes } from "@weapp-core/shared/rich-text";
11
11
  import { selectAll } from "css-select";
12
12
  import { AttributeAction, SelectorType, parse as parse$1 } from "css-what";
13
13
  import * as fontoxpath from "fontoxpath";
@@ -2237,6 +2237,7 @@ function mergeRecord(...records) {
2237
2237
  return Object.assign({}, ...records.filter(Boolean));
2238
2238
  }
2239
2239
  // src/runtime/componentInstance/observers.ts
2240
+ const observerRunStates = /* @__PURE__ */ new WeakMap();
2240
2241
  function runPropertyObservers(definition, instance, changedKeys, previousProperties) {
2241
2242
  const propOptions = definition.properties;
2242
2243
  if (!propOptions || typeof propOptions !== "object" || Array.isArray(propOptions)) return;
@@ -2282,7 +2283,7 @@ function matchObserverPattern(pattern, changedKeys) {
2282
2283
  });
2283
2284
  });
2284
2285
  }
2285
- function runComponentObservers(definition, instance, changedKeys, previousProperties = {}) {
2286
+ function runComponentObserversOnce(definition, instance, changedKeys, previousProperties = {}, includePropertyObservers = true) {
2286
2287
  if (changedKeys.length === 0) return;
2287
2288
  const observers = definition.observers;
2288
2289
  if (observers && typeof observers === "object" && !Array.isArray(observers)) for (const [pattern, handler] of Object.entries(observers)) {
@@ -2290,7 +2291,41 @@ function runComponentObservers(definition, instance, changedKeys, previousProper
2290
2291
  const args = normalizeObserverPattern(pattern).map((item) => resolveObservedValue(instance, item));
2291
2292
  handler.call(instance, ...args);
2292
2293
  }
2293
- runPropertyObservers(definition, instance, changedKeys, previousProperties);
2294
+ if (includePropertyObservers) runPropertyObservers(definition, instance, changedKeys, previousProperties);
2295
+ }
2296
+ function runComponentObservers(definition, instance, changedKeys, previousProperties = {}) {
2297
+ if (changedKeys.length === 0) return;
2298
+ const state = observerRunStates.get(instance) ?? {
2299
+ running: false,
2300
+ pending: []
2301
+ };
2302
+ observerRunStates.set(instance, state);
2303
+ if (state.running) {
2304
+ runPropertyObservers(definition, instance, changedKeys, previousProperties);
2305
+ state.pending.push({
2306
+ changedKeys: [...changedKeys],
2307
+ previousProperties,
2308
+ includePropertyObservers: false
2309
+ });
2310
+ return;
2311
+ }
2312
+ state.pending.push({
2313
+ changedKeys: [...changedKeys],
2314
+ previousProperties,
2315
+ includePropertyObservers: true
2316
+ });
2317
+ state.running = true;
2318
+ try {
2319
+ while (state.pending.length > 0) {
2320
+ const next = state.pending.shift();
2321
+ runComponentObserversOnce(definition, instance, next.changedKeys, next.previousProperties, next.includePropertyObservers);
2322
+ }
2323
+ } catch (error) {
2324
+ state.pending.length = 0;
2325
+ throw error;
2326
+ } finally {
2327
+ state.running = false;
2328
+ }
2294
2329
  }
2295
2330
  // src/runtime/componentInstance/lifetimes.ts
2296
2331
  function mergeComponentLifetimes(behaviors, definition) {
@@ -2332,27 +2367,45 @@ function flattenBehaviors(definition) {
2332
2367
  }
2333
2368
  return flattened;
2334
2369
  }
2370
+ function applyBehaviorDefinitionFilters(definition, behaviors) {
2371
+ if (!behaviors.some((behavior) => typeof behavior.definitionFilter === "function")) return definition;
2372
+ const filteredDefinition = {
2373
+ ...definition,
2374
+ ...definition.observers && typeof definition.observers === "object" && !Array.isArray(definition.observers) ? { observers: { ...definition.observers } } : {}
2375
+ };
2376
+ for (const behavior of behaviors) if (typeof behavior.definitionFilter === "function") behavior.definitionFilter(filteredDefinition);
2377
+ return filteredDefinition;
2378
+ }
2335
2379
  function resolveComponentPropertyDefinitions(definition, behaviors = flattenBehaviors(definition)) {
2336
2380
  return behaviors.length === 0 ? definition.properties ?? {} : mergeRecord(...behaviors.map((item) => item.properties), definition.properties);
2337
2381
  }
2382
+ const RESERVED_COMPONENT_HOST_PROPERTIES = /* @__PURE__ */ new Set([
2383
+ "id",
2384
+ "class",
2385
+ "slot"
2386
+ ]);
2387
+ function isReservedComponentHostProperty(key) {
2388
+ return RESERVED_COMPONENT_HOST_PROPERTIES.has(key);
2389
+ }
2338
2390
  function normalizeComponentDefinition(definition) {
2339
2391
  const behaviors = flattenBehaviors(definition);
2340
2392
  if (behaviors.length === 0) return definition;
2393
+ const filteredDefinition = applyBehaviorDefinitionFilters(definition, behaviors);
2341
2394
  const mergedDataEntries = behaviors.map((item) => item.data).filter(Boolean);
2342
2395
  const mergedDefinition = {
2343
- ...mergeRecord(...behaviors, definition),
2344
- methods: mergeRecord(...behaviors.map((item) => item.methods), definition.methods),
2345
- observers: mergeRecord(...behaviors.map((item) => item.observers), definition.observers),
2346
- pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes), definition.pageLifetimes),
2347
- properties: resolveComponentPropertyDefinitions(definition, behaviors),
2348
- relations: mergeRecord(...behaviors.map((item) => item.relations), definition.relations),
2349
- lifetimes: mergeComponentLifetimes(behaviors, definition)
2350
- };
2351
- if (mergedDataEntries.length > 0 || definition.data) mergedDefinition.data = function mergedComponentData() {
2396
+ ...mergeRecord(...behaviors, filteredDefinition),
2397
+ methods: mergeRecord(...behaviors.map((item) => item.methods), filteredDefinition.methods),
2398
+ observers: mergeRecord(...behaviors.map((item) => item.observers), filteredDefinition.observers),
2399
+ pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes), filteredDefinition.pageLifetimes),
2400
+ properties: resolveComponentPropertyDefinitions(filteredDefinition, behaviors),
2401
+ relations: mergeRecord(...behaviors.map((item) => item.relations), filteredDefinition.relations),
2402
+ lifetimes: mergeComponentLifetimes(behaviors, filteredDefinition)
2403
+ };
2404
+ if (mergedDataEntries.length > 0 || filteredDefinition.data) mergedDefinition.data = function mergedComponentData() {
2352
2405
  return mergeRecord(mergeRecord(...mergedDataEntries.map((entry) => {
2353
2406
  if (typeof entry === "function") return entry.call(this);
2354
2407
  return entry;
2355
- })), typeof definition.data === "function" ? definition.data.call(this) : definition.data);
2408
+ })), typeof filteredDefinition.data === "function" ? filteredDefinition.data.call(this) : filteredDefinition.data);
2356
2409
  };
2357
2410
  return mergedDefinition;
2358
2411
  }
@@ -3122,6 +3175,36 @@ function resolveEventBindingPhases(attributes, eventName, includeCapture = true)
3122
3175
  }
3123
3176
  return bindings;
3124
3177
  }
3178
+ // src/view/nativeBoolean.ts
3179
+ const nativeBooleanValues = /* @__PURE__ */ new WeakMap();
3180
+ /** 保留原始布尔属性值,避免 null/undefined 在属性序列化后退化为裸属性。 */
3181
+ function setNativeBooleanValue(node, name, value, valueless = false) {
3182
+ if (name !== "checked" && name !== "disabled") return;
3183
+ let values = nativeBooleanValues.get(node);
3184
+ if (!values) {
3185
+ values = /* @__PURE__ */ new Map();
3186
+ nativeBooleanValues.set(node, values);
3187
+ }
3188
+ values.set(name, {
3189
+ value,
3190
+ valueless
3191
+ });
3192
+ }
3193
+ function getNativeBooleanValue(node, name) {
3194
+ const attributes = node.attribs;
3195
+ if (!attributes || !Object.hasOwn(attributes, name)) return false;
3196
+ const snapshot = node.nativeBooleanValues;
3197
+ const stored = nativeBooleanValues.get(node)?.get(name) ?? snapshot?.get(name);
3198
+ if (stored) {
3199
+ if (stored.valueless) return true;
3200
+ return stored.value !== void 0 && stored.value !== null && stored.value !== false && stored.value !== 0 && stored.value !== "" && stored.value !== "false" && stored.value !== "0";
3201
+ }
3202
+ const value = attributes[name];
3203
+ return value !== "false" && value !== "0";
3204
+ }
3205
+ function getNativeBooleanSnapshot(node) {
3206
+ return nativeBooleanValues.get(node);
3207
+ }
3125
3208
  // src/view/nodeDataset.ts
3126
3209
  const DATASET_NAME_RE = /-([a-z])/g;
3127
3210
  function isDatasetAttribute(attributeName) {
@@ -3182,7 +3265,8 @@ function mergeComponentEventRoot(root, host) {
3182
3265
  const entry = eventNodes.get(root);
3183
3266
  if (entry.target === root) entry.target = {
3184
3267
  attribs: root.attribs,
3185
- dataset: root.dataset
3268
+ dataset: root.dataset,
3269
+ nativeBooleanValues: getNativeBooleanSnapshot(root)
3186
3270
  };
3187
3271
  entry.hosts ??= [];
3188
3272
  entry.hosts.push(host);
@@ -4061,6 +4145,52 @@ function getNativeBindingCommit(node, previous) {
4061
4145
  }
4062
4146
  };
4063
4147
  }
4148
+ // src/testing/sessionHandle/shared.ts
4149
+ const LEADING_SLASH_RE$5 = /^\/+/;
4150
+ const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
4151
+ const DEFAULT_WAIT_INTERVAL$1 = 10;
4152
+ function normalizeRoute$1(route) {
4153
+ return route.replace(LEADING_SLASH_RE$5, "");
4154
+ }
4155
+ function resolvePageScopeId$1(scopeId) {
4156
+ const pagePathIndex = scopeId.indexOf("/page/");
4157
+ return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
4158
+ }
4159
+ function normalizeNonEmptyInput(value, label) {
4160
+ const normalizedValue = value.trim();
4161
+ if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
4162
+ return normalizedValue;
4163
+ }
4164
+ function cloneProtocolValue(value) {
4165
+ if (!value || typeof value !== "object") return value;
4166
+ return JSON.parse(JSON.stringify(value));
4167
+ }
4168
+ async function waitForDelay(ms = 0) {
4169
+ if (ms <= 0) return;
4170
+ await new Promise((resolve) => setTimeout(resolve, ms));
4171
+ }
4172
+ async function pollUntil$2(check, errorMessage, options = {}) {
4173
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
4174
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
4175
+ const deadline = Date.now() + timeout;
4176
+ while (true) {
4177
+ const result = await check();
4178
+ if (result != null) return result;
4179
+ if (Date.now() >= deadline) throw new Error(errorMessage);
4180
+ await waitForDelay(interval);
4181
+ }
4182
+ }
4183
+ async function runWithTimeout(operation, timeout, message) {
4184
+ if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
4185
+ let timer;
4186
+ try {
4187
+ return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
4188
+ timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
4189
+ })]);
4190
+ } finally {
4191
+ if (timer) clearTimeout(timer);
4192
+ }
4193
+ }
4064
4194
  // src/view/nodeEvents.ts
4065
4195
  /** 正确字段优先;复制触点,避免处理器修改调用者持有的数据。 */
4066
4196
  function readTouchEventPayload(event) {
@@ -4138,9 +4268,33 @@ function participates(scopeId, formScopes, behavior, resolveComponent) {
4138
4268
  }
4139
4269
  return true;
4140
4270
  }
4141
- function checked(attributes, name) {
4142
- const value = attributes?.[name];
4143
- return value !== void 0 && value !== "false" && value !== "0";
4271
+ function participatesFormField(scopeId, formScopes, resolveComponent) {
4272
+ const visited = /* @__PURE__ */ new Set();
4273
+ while (!formScopes.has(scopeId)) {
4274
+ if (!scopeId || visited.has(scopeId)) return false;
4275
+ visited.add(scopeId);
4276
+ const component = resolveComponent?.(scopeId);
4277
+ if (!component || !includesBehavior(component.definition, "wx://form-field") && !includesBehavior(component.definition, "wx://form-field-group")) return false;
4278
+ scopeId = component.ownerScopeId;
4279
+ }
4280
+ return true;
4281
+ }
4282
+ function resolveFormFieldComponent(scopeId, resolveComponent) {
4283
+ const visited = /* @__PURE__ */ new Set();
4284
+ let current = scopeId;
4285
+ while (current && !visited.has(current)) {
4286
+ visited.add(current);
4287
+ const component = resolveComponent?.(current);
4288
+ if (!component) return;
4289
+ if (includesBehavior(component.definition, "wx://form-field")) return {
4290
+ scopeId: current,
4291
+ component
4292
+ };
4293
+ current = component.ownerScopeId;
4294
+ }
4295
+ }
4296
+ function checked(node, name) {
4297
+ return getNativeBooleanValue(node, name);
4144
4298
  }
4145
4299
  function choiceValues(group, pageScope, resolveComponent) {
4146
4300
  const values = [];
@@ -4150,7 +4304,7 @@ function choiceValues(group, pageScope, resolveComponent) {
4150
4304
  if (node.name === "form" || node.name === "radio-group" || node.name === "checkbox-group") return;
4151
4305
  if (node.name === choice) {
4152
4306
  const owner = nativeOwner(node);
4153
- if (checked(owner.target.attribs, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
4307
+ if (checked(owner.target, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
4154
4308
  }
4155
4309
  for (const child of node.children ?? []) visit(child);
4156
4310
  };
@@ -4163,6 +4317,12 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4163
4317
  if (node.name === "form") return;
4164
4318
  const owner = nativeOwner(node);
4165
4319
  const attributes = owner.target.attribs;
4320
+ const field = resolveFormFieldComponent(owner.scopeId, resolveComponent);
4321
+ const componentName = field?.component.name;
4322
+ if (typeof componentName === "string" && componentName && node.attribs?.["data-sim-component"] && field && participatesFormField(field.scopeId, scopes, resolveComponent)) {
4323
+ values[componentName] = cloneProtocolValue(field.component.value);
4324
+ return;
4325
+ }
4166
4326
  const name = attributes?.name;
4167
4327
  if (attributes && name && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) switch (node.name) {
4168
4328
  case "input":
@@ -4170,7 +4330,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4170
4330
  values[name] = attributes.value ?? "";
4171
4331
  break;
4172
4332
  case "switch":
4173
- values[name] = checked(attributes, "checked");
4333
+ values[name] = checked(owner.target, "checked");
4174
4334
  break;
4175
4335
  case "slider":
4176
4336
  values[name] = Number(attributes.value ?? 0);
@@ -4196,7 +4356,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4196
4356
  /** 先固定提交目标、字段值和方法所有者,再允许 tap 回调改变组件树。 */
4197
4357
  function prepareNativeFormSubmit(button, pageScope, event, resolveMethod, resolveComponent) {
4198
4358
  const owner = nativeOwner(button);
4199
- if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target.attribs, "disabled")) return;
4359
+ if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target, "disabled")) return;
4200
4360
  let form = button.parent;
4201
4361
  while (form && form.name !== "form") form = form.parent;
4202
4362
  if (!form) return;
@@ -4218,7 +4378,6 @@ function materializeNode(node) {
4218
4378
  type: "text",
4219
4379
  data: node.text
4220
4380
  };
4221
- for (const name of Object.keys(node.attrs)) if (name.startsWith("data-sim-")) delete node.attrs[name];
4222
4381
  return {
4223
4382
  type: "tag",
4224
4383
  name: node.name,
@@ -4228,7 +4387,7 @@ function materializeNode(node) {
4228
4387
  }
4229
4388
  /** 富文本直接成为已渲染节点,不能再进入 WXML 表达式或组件处理流程。 */
4230
4389
  function renderRichTextNodes(value) {
4231
- return normalizeRichTextNodes(value).map(materializeNode);
4390
+ return normalizeNativeRichTextNodes(value).map(materializeNode);
4232
4391
  }
4233
4392
  // src/view/templateIncludes.ts
4234
4393
  /** 展开 include 的可渲染内容,并保留嵌套引用的来源文件。 */
@@ -4326,7 +4485,7 @@ function parseWxsTemplateDocument(templateSource) {
4326
4485
  return parseSharedWxsDocument(templateSource);
4327
4486
  }
4328
4487
  // src/browser/render/shared.ts
4329
- const LEADING_SLASH_RE$5 = /^\/+/;
4488
+ const LEADING_SLASH_RE$4 = /^\/+/;
4330
4489
  const EVENT_BINDING_ATTRS$1 = [
4331
4490
  "bindtap",
4332
4491
  "bind:tap",
@@ -4406,7 +4565,7 @@ function serializeDomNode$2(node) {
4406
4565
  if (node.type === "root") return (node.children ?? []).map(serializeDomNode$2).join("");
4407
4566
  const tagName = node.name ?? "";
4408
4567
  if (!tagName) return (node.children ?? []).map(serializeDomNode$2).join("");
4409
- return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute$2(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$2).join("")}</${tagName}>`;
4568
+ return `<${tagName}${Object.entries(node.attribs ?? {}).filter(([key]) => key !== "disabled" && key !== "checked" || getNativeBooleanValue(node, key)).map(([key, value]) => ` ${key}="${escapeAttribute$2(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$2).join("")}</${tagName}>`;
4410
4569
  }
4411
4570
  function isTagNode$1(node) {
4412
4571
  return node.type === "tag" && typeof node.name === "string";
@@ -4435,6 +4594,7 @@ function applyNodeBindings$1(node, scope, richText = false) {
4435
4594
  continue;
4436
4595
  }
4437
4596
  const resolvedValue = resolveNativeAttributeValue(node, key, scope, (source) => typeof value === "string" ? resolveAttributeValue$1(value, source) : value);
4597
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
4438
4598
  if (key === "value") setNativePickerValue(node, resolvedValue);
4439
4599
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
4440
4600
  node.attribs[key] = String(resolvedValue ?? "");
@@ -4483,7 +4643,7 @@ function resolveUsingComponent$1(context, ownerJsonPath, ownerFilePath, alias) {
4483
4643
  if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return;
4484
4644
  const rawPath = usingComponents[alias];
4485
4645
  if (typeof rawPath !== "string") return;
4486
- return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => readBrowserVirtualFile(context.files, candidate) !== void 0)).replace(LEADING_SLASH_RE$5, "");
4646
+ return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => readBrowserVirtualFile(context.files, candidate) !== void 0)).replace(LEADING_SLASH_RE$4, "");
4487
4647
  } catch {
4488
4648
  return;
4489
4649
  }
@@ -4502,8 +4662,8 @@ function resolveComponentGenerics$1(context, hostNode, ownerJsonPath, ownerFileP
4502
4662
  }
4503
4663
  const defaultPath = typeof definition === "object" && definition !== null ? definition.default : void 0;
4504
4664
  if (typeof defaultPath !== "string" || !defaultPath) continue;
4505
- const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$5, "") : normalize(join(dirname(componentFilePath), defaultPath));
4506
- resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$5, ""));
4665
+ const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$4, "") : normalize(join(dirname(componentFilePath), defaultPath));
4666
+ resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$4, ""));
4507
4667
  }
4508
4668
  return resolved.size > 0 ? resolved : void 0;
4509
4669
  }
@@ -4535,7 +4695,7 @@ function resolveComponentProperties$1(clonedNode, scope, definition) {
4535
4695
  const bindingExpressions = {};
4536
4696
  const declaredProperties = resolveComponentPropertyDefinitions(definition);
4537
4697
  for (const [key, value] of Object.entries(clonedNode.attribs ?? {})) {
4538
- if (key.startsWith("bind") || key.startsWith("generic:")) continue;
4698
+ if (key.startsWith("bind") || key.startsWith("generic:") || key.startsWith("wx:") || isReservedComponentHostProperty(key)) continue;
4539
4699
  const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
4540
4700
  const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
4541
4701
  if (isMustacheOnly$2(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
@@ -4787,7 +4947,7 @@ function reconcileBrowserPageTree(context, page, bindingsOnly = false) {
4787
4947
  for (;;) {
4788
4948
  bindAttachmentBindingScope(context, page);
4789
4949
  if (page.__lastChangedKeys__) context.changedPageKeys = page.__lastChangedKeys__;
4790
- const route = page.route.replace(LEADING_SLASH_RE$5, "");
4950
+ const route = page.route.replace(LEADING_SLASH_RE$4, "");
4791
4951
  const resourcePath = context.project.routes.find((item) => item.route === route)?.resourcePath ?? route;
4792
4952
  const templatePath = join(context.project.miniprogramRootPath, `${resourcePath}.wxml`);
4793
4953
  const document = parseTemplateDocument$1(readTemplateSource$1(context.files, templatePath, context.templateSource));
@@ -5205,11 +5365,11 @@ function assignByPath(target, path, value) {
5205
5365
  const normalizedLeafSegment = isArrayIndexSegment(leafSegment) ? Number(leafSegment) : leafSegment;
5206
5366
  current[normalizedLeafSegment] = value;
5207
5367
  }
5208
- function normalizeRoute$1(route) {
5368
+ function normalizeRoute(route) {
5209
5369
  return route.replace(LEADING_ROUTE_SLASH_RE, "");
5210
5370
  }
5211
5371
  function createPageInstance(route, definition, options = {}, pageState = {}) {
5212
- const normalizedRoute = normalizeRoute$1(route);
5372
+ const normalizedRoute = normalizeRoute(route);
5213
5373
  const data = {
5214
5374
  ...resolveInitialData(definition),
5215
5375
  ...isComponentPageDefinition(definition) ? resolveInitialProperties(definition, {}) : {}
@@ -7279,7 +7439,7 @@ function createValueEventDetail(value, detail) {
7279
7439
  ...detail ?? {}
7280
7440
  };
7281
7441
  }
7282
- function resolvePageScopeId$1(scopeId) {
7442
+ function resolvePageScopeId(scopeId) {
7283
7443
  if (!scopeId) return null;
7284
7444
  const pagePathIndex = scopeId.indexOf("/page/");
7285
7445
  return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
@@ -7304,7 +7464,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7304
7464
  if (!scope || !this.interactions) return nodes;
7305
7465
  return nodes.filter((node) => {
7306
7466
  const nodeScope = node.attribs?.["data-sim-scope"];
7307
- return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId$1(nodeScope)) === scope;
7467
+ return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId(nodeScope)) === scope;
7308
7468
  });
7309
7469
  }
7310
7470
  async $(selector) {
@@ -7341,7 +7501,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7341
7501
  async pageScope() {
7342
7502
  this.assertActive();
7343
7503
  if (!this.interactions) throw new Error("Node interactions are not available for this headless testing node.");
7344
- return this.interactions.createScopeHandle(resolvePageScopeId$1(this.node.attribs?.["data-sim-scope"] ?? null));
7504
+ return this.interactions.createScopeHandle(resolvePageScopeId(this.node.attribs?.["data-sim-scope"] ?? null));
7345
7505
  }
7346
7506
  async page() {
7347
7507
  this.assertActive();
@@ -7434,7 +7594,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7434
7594
  }
7435
7595
  };
7436
7596
  // src/view/render.ts
7437
- const LEADING_SLASH_RE$4 = /^\/+/;
7597
+ const LEADING_SLASH_RE$3 = /^\/+/;
7438
7598
  const TEMPLATE_INTERPOLATION_RE = /\{\{([^{}]+)\}\}/g;
7439
7599
  function resolveRawValueByPath$1(source, expression) {
7440
7600
  const normalized = expression.trim();
@@ -7473,6 +7633,7 @@ function interpolateDomTree(root, data) {
7473
7633
  let dataset;
7474
7634
  for (const [key, value] of Object.entries(node.attribs)) {
7475
7635
  const resolvedValue = isMustacheOnly$1(value) ? resolveRawValueByPath$1(data, value.trim().slice(2, -2)) : interpolateTemplate$1(value, data);
7636
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
7476
7637
  if (key === "value") setNativePickerValue(node, resolvedValue);
7477
7638
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
7478
7639
  node.attribs[key] = String(resolvedValue ?? "");
@@ -7500,7 +7661,7 @@ function serializeDomNode$1(node) {
7500
7661
  return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute$1(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$1).join("")}</${tagName}>`;
7501
7662
  }
7502
7663
  function renderPageTree(project, page) {
7503
- const route = page.route.replace(LEADING_SLASH_RE$4, "");
7664
+ const route = page.route.replace(LEADING_SLASH_RE$3, "");
7504
7665
  const templatePath = path.resolve(project.miniprogramRootPath, `${route}.wxml`);
7505
7666
  const templateSource = project.artifactSource.readText(templatePath);
7506
7667
  if (templateSource == null) throw new Error(`Missing template in headless runtime: ${templatePath}`);
@@ -7796,6 +7957,21 @@ function coordinate(value) {
7796
7957
  function nodeKey(node) {
7797
7958
  return node.attribs?.["data-sim-node"] ?? "";
7798
7959
  }
7960
+ /** 按稳定渲染键把保留的测试节点句柄映射到当前树;有键但已移除时返回 undefined。 */
7961
+ function resolveNativeNode(root, node) {
7962
+ const key = nodeKey(node);
7963
+ if (!key) return node;
7964
+ let match;
7965
+ const visit = (current) => {
7966
+ if (current.attribs?.["data-sim-node"] === key) {
7967
+ match = current;
7968
+ return;
7969
+ }
7970
+ for (const child of current.children ?? []) if (!match) visit(child);
7971
+ };
7972
+ visit(root);
7973
+ return match;
7974
+ }
7799
7975
  /** 原生滚动位置独立于绑定值;未改变的绑定不能覆盖用户滚动。 */
7800
7976
  function syncNativeScrollViews(page, root, emit) {
7801
7977
  let states = pageScrollViews.get(page);
@@ -7897,6 +8073,14 @@ function dispatchNativeNodeEvent(page, node, eventName, event, wx, resolveMethod
7897
8073
  const origin = getNativeNodeOwner(node)?.target ?? node;
7898
8074
  let handlers;
7899
8075
  let handled = false;
8076
+ let eligibility = node;
8077
+ while (eligibility) {
8078
+ if (eligibility.name === "button") {
8079
+ if (getNativeBooleanValue(getNativeNodeOwner(eligibility)?.target ?? eligibility, "disabled")) return true;
8080
+ break;
8081
+ }
8082
+ eligibility = eligibility.parent;
8083
+ }
7900
8084
  const collectHandler = (scopeId, target, binding) => {
7901
8085
  if (binding.method) {
7902
8086
  const call = resolveMethod(scopeId, binding.method);
@@ -8860,14 +9044,14 @@ function createHeadlessVideoContext(driver, videoId, scope) {
8860
9044
  };
8861
9045
  }
8862
9046
  // src/browser/session.ts
8863
- const LEADING_SLASH_RE$3 = /^\/+/;
9047
+ const LEADING_SLASH_RE$2 = /^\/+/;
8864
9048
  const PAGE_STACK_LIMIT$1 = 10;
8865
9049
  const WHITESPACE_RE$1 = /\s+/;
8866
9050
  const DATA_ATTR_SELECTOR_RE$1 = /^\[data-([^=\]]+)="([^"]*)"\]$/;
8867
9051
  const COMPOUND_SELECTOR_PART_RE$1 = /#[\w-]+|\.[\w-]+|\[data-[^=\]]+="[^"]*"\]|[A-Za-z][\w-]*/g;
8868
9052
  const DATASET_KEY_RE$1 = /-([a-z])/g;
8869
9053
  function stripLeadingSlash$1(route) {
8870
- return route.replace(LEADING_SLASH_RE$3, "");
9054
+ return route.replace(LEADING_SLASH_RE$2, "");
8871
9055
  }
8872
9056
  function normalizeQuery$1(queryString) {
8873
9057
  const query = new URLSearchParams(queryString);
@@ -8919,9 +9103,9 @@ function readJsonObject$2(files, filePath) {
8919
9103
  }
8920
9104
  function resolveNavigationPath$1(targetPath, baseRoute) {
8921
9105
  if (!targetPath) throw new Error("Navigation url must include a pathname in browser simulator runtime.");
8922
- if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$3, "");
9106
+ if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$2, "");
8923
9107
  if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
8924
- return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$3, "");
9108
+ return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$2, "");
8925
9109
  }
8926
9110
  var BrowserHeadlessSession = class {
8927
9111
  files;
@@ -9504,15 +9688,20 @@ var BrowserHeadlessSession = class {
9504
9688
  }
9505
9689
  dispatchNativeNodeEvent(node, eventName, event, onHandlerResult) {
9506
9690
  const current = this.requireCurrentPage("dispatchNativeNodeEvent()");
9507
- if (eventName === "tap") this.renderCurrentPage();
9508
- return dispatchNativeNodeEvent(current, node, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
9691
+ const rendered = eventName === "tap" ? this.renderCurrentPage() : void 0;
9692
+ const currentNode = rendered ? resolveNativeNode(rendered.root, node) : node;
9693
+ if (!currentNode) throw new Error("Native testing node is no longer present in the current page.");
9694
+ const handled = dispatchNativeNodeEvent(current, currentNode, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
9509
9695
  const instance = this.componentCache.get(scopeId);
9510
9696
  const scope = this.componentScopes.get(scopeId);
9511
9697
  return instance?.__definition__ && scope ? {
9512
9698
  definition: instance.__definition__,
9513
- ownerScopeId: scope.ownerScopeId ?? null
9699
+ ownerScopeId: scope.ownerScopeId ?? null,
9700
+ name: typeof instance.properties?.name === "string" ? instance.properties.name : void 0,
9701
+ value: instance.properties && Object.hasOwn(instance.properties, "value") ? instance.properties.value : void 0
9514
9702
  } : void 0;
9515
9703
  });
9704
+ return eventName === "tap" && Boolean(node.attribs?.["data-sim-node"]) ? true : handled;
9516
9705
  }
9517
9706
  requestRender(callback) {
9518
9707
  this.assertActive();
@@ -10248,7 +10437,7 @@ function getRuntimeWxsLoader(owner, artifactSource) {
10248
10437
  return loader.load;
10249
10438
  }
10250
10439
  // src/runtime/render/shared.ts
10251
- const LEADING_SLASH_RE$2 = /^\/+/;
10440
+ const LEADING_SLASH_RE$1 = /^\/+/;
10252
10441
  const EVENT_BINDING_ATTRS = [
10253
10442
  "bindtap",
10254
10443
  "bind:tap",
@@ -10357,6 +10546,7 @@ function applyNodeBindings(node, scope, richText = false) {
10357
10546
  continue;
10358
10547
  }
10359
10548
  const resolvedValue = resolveNativeAttributeValue(node, key, scope, (source) => typeof value === "string" ? resolveAttributeValue(value, source) : value);
10549
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
10360
10550
  if (key === "value") setNativePickerValue(node, resolvedValue);
10361
10551
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
10362
10552
  node.attribs[key] = String(resolvedValue ?? "");
@@ -10412,7 +10602,7 @@ function resolveOwnerComponent(context, ownerJsonPath, ownerFilePath, alias) {
10412
10602
  if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return;
10413
10603
  const rawPath = usingComponents[alias];
10414
10604
  if (typeof rawPath !== "string") return;
10415
- return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$2, "");
10605
+ return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$1, "");
10416
10606
  } catch {
10417
10607
  return;
10418
10608
  }
@@ -10460,8 +10650,8 @@ function resolveComponentGenerics(context, hostNode, ownerJsonPath, ownerFilePat
10460
10650
  }
10461
10651
  const defaultPath = typeof definition === "object" && definition !== null ? definition.default : void 0;
10462
10652
  if (typeof defaultPath !== "string" || !defaultPath) continue;
10463
- const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$2, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
10464
- resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$2, ""));
10653
+ const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$1, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
10654
+ resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$1, ""));
10465
10655
  }
10466
10656
  return resolved.size > 0 ? resolved : void 0;
10467
10657
  }
@@ -10493,7 +10683,7 @@ function resolveComponentProperties(clonedNode, scope, definition) {
10493
10683
  const bindingExpressions = {};
10494
10684
  const declaredProperties = resolveComponentPropertyDefinitions(definition);
10495
10685
  for (const [key, value] of Object.entries(clonedNode.attribs ?? {})) {
10496
- if (key.startsWith("bind") || key.startsWith("generic:")) continue;
10686
+ if (key.startsWith("bind") || key.startsWith("generic:") || key.startsWith("wx:") || isReservedComponentHostProperty(key)) continue;
10497
10687
  const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
10498
10688
  const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
10499
10689
  if (isMustacheOnly(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
@@ -10748,7 +10938,7 @@ function reconcileRuntimePageTree(context, page, bindingsOnly = false) {
10748
10938
  for (;;) {
10749
10939
  bindAttachmentBindingScope(context, page);
10750
10940
  if (page.__lastChangedKeys__) context.changedPageKeys = page.__lastChangedKeys__;
10751
- const route = page.route.replace(LEADING_SLASH_RE$2, "");
10941
+ const route = page.route.replace(LEADING_SLASH_RE$1, "");
10752
10942
  const resourcePath = context.project.routes.find((item) => item.route === route)?.resourcePath ?? route;
10753
10943
  const templatePath = path.resolve(context.project.miniprogramRootPath, `${resourcePath}.wxml`);
10754
10944
  const document = parseTemplateDocument(readTemplateSource(context.artifactSource, templatePath));
@@ -10988,14 +11178,14 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, optio
10988
11178
  return loader;
10989
11179
  }
10990
11180
  // src/runtime/session.ts
10991
- const LEADING_SLASH_RE$1 = /^\/+/;
11181
+ const LEADING_SLASH_RE = /^\/+/;
10992
11182
  const PAGE_STACK_LIMIT = 10;
10993
11183
  const WHITESPACE_RE = /\s+/;
10994
11184
  const DATA_ATTR_SELECTOR_RE = /^\[data-([^=\]]+)="([^"]*)"\]$/;
10995
11185
  const COMPOUND_SELECTOR_PART_RE = /#[\w-]+|\.[\w-]+|\[data-[^=\]]+="[^"]*"\]|[A-Za-z][\w-]*/g;
10996
11186
  const DATASET_KEY_RE = /-([a-z])/g;
10997
11187
  function stripLeadingSlash(route) {
10998
- return route.replace(LEADING_SLASH_RE$1, "");
11188
+ return route.replace(LEADING_SLASH_RE, "");
10999
11189
  }
11000
11190
  function normalizeQuery(queryString) {
11001
11191
  const query = new URLSearchParams(queryString);
@@ -11046,9 +11236,9 @@ function readJsonObject(project, filePath) {
11046
11236
  }
11047
11237
  function resolveNavigationPath(targetPath, baseRoute) {
11048
11238
  if (!targetPath) throw new Error("Navigation url must include a pathname in headless runtime.");
11049
- if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE$1, "");
11239
+ if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE, "");
11050
11240
  if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
11051
- return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$1, "");
11241
+ return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE, "");
11052
11242
  }
11053
11243
  var HeadlessSession = class {
11054
11244
  project;
@@ -11389,15 +11579,20 @@ var HeadlessSession = class {
11389
11579
  }
11390
11580
  dispatchNativeNodeEvent(node, eventName, event, onHandlerResult) {
11391
11581
  const current = this.requireCurrentPage("dispatchNativeNodeEvent()");
11392
- if (eventName === "tap") this.renderCurrentPage();
11393
- return dispatchNativeNodeEvent(current, node, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
11582
+ const rendered = eventName === "tap" ? this.renderCurrentPage() : void 0;
11583
+ const currentNode = rendered ? resolveNativeNode(rendered.root, node) : node;
11584
+ if (!currentNode) throw new Error("Native testing node is no longer present in the current page.");
11585
+ const handled = dispatchNativeNodeEvent(current, currentNode, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
11394
11586
  const instance = this.componentCache.get(scopeId);
11395
11587
  const scope = this.componentScopes.get(scopeId);
11396
11588
  return instance?.__definition__ && scope ? {
11397
11589
  definition: instance.__definition__,
11398
- ownerScopeId: scope.ownerScopeId ?? null
11590
+ ownerScopeId: scope.ownerScopeId ?? null,
11591
+ name: typeof instance.properties?.name === "string" ? instance.properties.name : void 0,
11592
+ value: instance.properties && Object.hasOwn(instance.properties, "value") ? instance.properties.value : void 0
11399
11593
  } : void 0;
11400
11594
  });
11595
+ return eventName === "tap" && Boolean(node.attribs?.["data-sim-node"]) ? true : handled;
11401
11596
  }
11402
11597
  requestRender(callback) {
11403
11598
  this.assertActive();
@@ -12268,16 +12463,16 @@ function resolveTestingPagePath(route) {
12268
12463
  return route.replace(PRIVATE_PLUGIN_ROUTE_RE, "__plugin__/$1/$2");
12269
12464
  }
12270
12465
  // src/testing/pageWait.ts
12271
- const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
12272
- const DEFAULT_WAIT_INTERVAL$1 = 10;
12466
+ const DEFAULT_WAIT_TIMEOUT = 1e3;
12467
+ const DEFAULT_WAIT_INTERVAL = 10;
12273
12468
  function normalizeInput(value, label) {
12274
12469
  const normalized = value.trim();
12275
12470
  if (!normalized) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
12276
12471
  return normalized;
12277
12472
  }
12278
- async function pollUntil$2(access, check, errorMessage, options) {
12279
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
12280
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
12473
+ async function pollUntil$1(access, check, errorMessage, options) {
12474
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
12475
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
12281
12476
  const deadline = Date.now() + timeout;
12282
12477
  while (true) {
12283
12478
  const result = await check();
@@ -12289,34 +12484,34 @@ async function pollUntil$2(access, check, errorMessage, options) {
12289
12484
  async function waitForPageSelector(access, selector, options = {}) {
12290
12485
  const normalizedSelector = normalizeInput(selector, "Selector");
12291
12486
  if (options.state === "detached") {
12292
- 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);
12487
+ 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);
12293
12488
  return null;
12294
12489
  }
12295
- return await pollUntil$2(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
12490
+ return await pollUntil$1(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
12296
12491
  }
12297
12492
  async function waitForPageComponent(access, selector, options = {}) {
12298
12493
  const normalizedSelector = normalizeInput(selector, "Selector");
12299
- return await pollUntil$2(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12494
+ return await pollUntil$1(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12300
12495
  }
12301
12496
  async function waitForPageComponents(access, selector, count = 1, options = {}) {
12302
12497
  const normalizedSelector = normalizeInput(selector, "Selector");
12303
12498
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12304
- return await pollUntil$2(access, async () => {
12499
+ return await pollUntil$1(access, async () => {
12305
12500
  const components = await access.selectComponents(normalizedSelector);
12306
12501
  return components.length >= normalizedCount ? components : null;
12307
12502
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
12308
12503
  }
12309
12504
  async function waitForPageText(access, text, options = {}) {
12310
12505
  const normalizedText = normalizeInput(text, "Text");
12311
- return await pollUntil$2(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
12506
+ return await pollUntil$1(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
12312
12507
  }
12313
12508
  async function waitForPageTextGone(access, text, options = {}) {
12314
12509
  const normalizedText = normalizeInput(text, "Text");
12315
- 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);
12510
+ 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);
12316
12511
  }
12317
12512
  async function waitForPageData(access, path, matcher, hasMatcher, options = {}) {
12318
12513
  const normalizedPath = normalizeInput(path, "Data path");
12319
- return await pollUntil$2(access, async () => {
12514
+ return await pollUntil$1(access, async () => {
12320
12515
  const value = await access.data(normalizedPath);
12321
12516
  if (typeof matcher === "function") return matcher(value) ? value : null;
12322
12517
  if (hasMatcher) return Object.is(value, matcher) ? value : null;
@@ -12336,7 +12531,7 @@ function matchesDataset(node, expected) {
12336
12531
  const dataset = node.dataset ?? {};
12337
12532
  return Object.entries(expected).every(([key, value]) => String(dataset[key] ?? "") === String(value));
12338
12533
  }
12339
- async function pollUntil$1(access, check, errorMessage, options) {
12534
+ async function pollUntil(access, check, errorMessage, options) {
12340
12535
  const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_RENDERED_WAIT_TIMEOUT)) : DEFAULT_RENDERED_WAIT_TIMEOUT;
12341
12536
  const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_RENDERED_WAIT_INTERVAL)) : DEFAULT_RENDERED_WAIT_INTERVAL;
12342
12537
  const deadline = Date.now() + timeout;
@@ -12375,7 +12570,7 @@ async function waitForRenderedPage(access, options = {}) {
12375
12570
  access.assertActive();
12376
12571
  if (options.selector) {
12377
12572
  const selector = normalizeSelector(options.selector);
12378
- return await pollUntil$1(access, async () => {
12573
+ return await pollUntil(access, async () => {
12379
12574
  const nodes = await readRenderedNodes(access, selector, options);
12380
12575
  return nodes.some((node) => matchesDataset(node, options.dataset)) ? JSON.stringify({
12381
12576
  nodes,
@@ -12383,7 +12578,7 @@ async function waitForRenderedPage(access, options = {}) {
12383
12578
  }) : null;
12384
12579
  }, `Timed out waiting page rendered: selector=${selector} dataset=${JSON.stringify(options.dataset ?? {})}`, options);
12385
12580
  }
12386
- return await pollUntil$1(access, async () => {
12581
+ return await pollUntil(access, async () => {
12387
12582
  const wxml = await access.wxml();
12388
12583
  const normalizedWxml = wxml.trim();
12389
12584
  if (options.predicate?.(wxml)) return wxml;
@@ -12392,52 +12587,6 @@ async function waitForRenderedPage(access, options = {}) {
12392
12587
  return null;
12393
12588
  }, 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);
12394
12589
  }
12395
- // src/testing/sessionHandle/shared.ts
12396
- const LEADING_SLASH_RE = /^\/+/;
12397
- const DEFAULT_WAIT_TIMEOUT = 1e3;
12398
- const DEFAULT_WAIT_INTERVAL = 10;
12399
- function normalizeRoute(route) {
12400
- return route.replace(LEADING_SLASH_RE, "");
12401
- }
12402
- function resolvePageScopeId(scopeId) {
12403
- const pagePathIndex = scopeId.indexOf("/page/");
12404
- return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
12405
- }
12406
- function normalizeNonEmptyInput(value, label) {
12407
- const normalizedValue = value.trim();
12408
- if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
12409
- return normalizedValue;
12410
- }
12411
- function cloneProtocolValue(value) {
12412
- if (!value || typeof value !== "object") return value;
12413
- return JSON.parse(JSON.stringify(value));
12414
- }
12415
- async function waitForDelay(ms = 0) {
12416
- if (ms <= 0) return;
12417
- await new Promise((resolve) => setTimeout(resolve, ms));
12418
- }
12419
- async function pollUntil(check, errorMessage, options = {}) {
12420
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
12421
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
12422
- const deadline = Date.now() + timeout;
12423
- while (true) {
12424
- const result = await check();
12425
- if (result != null) return result;
12426
- if (Date.now() >= deadline) throw new Error(errorMessage);
12427
- await waitForDelay(interval);
12428
- }
12429
- }
12430
- async function runWithTimeout(operation, timeout, message) {
12431
- if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
12432
- let timer;
12433
- try {
12434
- return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
12435
- timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
12436
- })]);
12437
- } finally {
12438
- if (timer) clearTimeout(timer);
12439
- }
12440
- }
12441
12590
  // src/testing/pageHandle.ts
12442
12591
  var HeadlessTestingPageHandle = class {
12443
12592
  project;
@@ -12775,13 +12924,13 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
12775
12924
  return currentPage ? new HeadlessTestingPageHandle(this.project, currentPage, this.session) : null;
12776
12925
  }
12777
12926
  async pageScope() {
12778
- return new HeadlessTestingScopeHandle(resolvePageScopeId(this.scopeId), this.project, this.session);
12927
+ return new HeadlessTestingScopeHandle(resolvePageScopeId$1(this.scopeId), this.project, this.session);
12779
12928
  }
12780
12929
  async ownerComponent() {
12781
12930
  return this.createScopeHandle(this.session.selectOwnerComponent(this.scopeId));
12782
12931
  }
12783
12932
  async waitForOwnerComponent(options = {}) {
12784
- return await pollUntil(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
12933
+ return await pollUntil$2(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
12785
12934
  }
12786
12935
  async selectComponent(selector) {
12787
12936
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
@@ -12794,12 +12943,12 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
12794
12943
  }
12795
12944
  async waitForComponent(selector, options = {}) {
12796
12945
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12797
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12946
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12798
12947
  }
12799
12948
  async waitForComponents(selector, count = 1, options = {}) {
12800
12949
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12801
12950
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12802
- return await pollUntil(async () => {
12951
+ return await pollUntil$2(async () => {
12803
12952
  const components = await this.selectAllComponents(normalizedSelector);
12804
12953
  return components.length >= normalizedCount ? components : null;
12805
12954
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -12902,12 +13051,12 @@ var HeadlessTestingSessionHandle = class {
12902
13051
  }
12903
13052
  async waitForComponent(selector, options = {}) {
12904
13053
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12905
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
13054
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12906
13055
  }
12907
13056
  async waitForComponents(selector, count = 1, options = {}) {
12908
13057
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12909
13058
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12910
- return await pollUntil(async () => {
13059
+ return await pollUntil$2(async () => {
12911
13060
  const components = await this.selectAllComponents(normalizedSelector);
12912
13061
  return components.length >= normalizedCount ? components : null;
12913
13062
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -12943,14 +13092,14 @@ var HeadlessTestingSessionHandle = class {
12943
13092
  async waitForCurrentPage(route, options = {}) {
12944
13093
  const normalizedRoute = route?.trim();
12945
13094
  if (normalizedRoute != null && !normalizedRoute) throw new Error("Route must be a non-empty string in headless testing runtime.");
12946
- return await pollUntil(async () => {
13095
+ return await pollUntil$2(async () => {
12947
13096
  const currentPageInstance = this.session.getCurrentPages().at(-1);
12948
13097
  if (!currentPageInstance) return null;
12949
13098
  const current = new HeadlessTestingPageHandle(this.project, currentPageInstance, this.session);
12950
13099
  if (!normalizedRoute) return current;
12951
- if (normalizeRoute(current.path) === resolveTestingPagePath(normalizeRoute(normalizedRoute))) return current;
13100
+ if (normalizeRoute$1(current.path) === resolveTestingPagePath(normalizeRoute$1(normalizedRoute))) return current;
12952
13101
  return null;
12953
- }, normalizedRoute ? `Timed out waiting for current page "${normalizeRoute(normalizedRoute)}" in headless testing runtime.` : "Timed out waiting for a current page in headless testing runtime.", options);
13102
+ }, normalizedRoute ? `Timed out waiting for current page "${normalizeRoute$1(normalizedRoute)}" in headless testing runtime.` : "Timed out waiting for a current page in headless testing runtime.", options);
12954
13103
  }
12955
13104
  async pageScrollTo(scrollTop) {
12956
13105
  this.session.pageScrollTo({ scrollTop });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpcore/simulator",
3
3
  "type": "module",
4
- "version": "1.3.5-dev.20261117.1",
4
+ "version": "1.3.6-dev.20261119.1",
5
5
  "description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -44,9 +44,9 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/parser": "^8.1.2",
47
- "@weapp-core/constants": "0.6.1-dev.20261117.1",
48
- "@weapp-core/shared": "3.5.1-dev.20261117.1",
49
- "@weapp-vite/wxml": "0.0.3-dev.20261117.1",
47
+ "@weapp-core/constants": "0.6.2-dev.20261119.1",
48
+ "@weapp-core/shared": "3.5.2-dev.20261119.1",
49
+ "@weapp-vite/wxml": "0.0.4-dev.20261119.1",
50
50
  "css-select": "^7.0.0",
51
51
  "css-what": "^8.0.0",
52
52
  "fontoxpath": "^3.34.0",
@@ -64,9 +64,9 @@
64
64
  },
65
65
  "repoctlSnapshot": {
66
66
  "kind": "nightly",
67
- "commit": "1218da39b57ef783727d51ad86b2eecde20c375a",
68
- "buildId": "44017370760-1",
69
- "identityKey": "308bcda13e3bd3f6b91c0a3c717e48c6f2dcd2caee9b39cdf00c077ef771f58a",
67
+ "commit": "29a77f1e58e5686dbbfceefa78673afa59d2a1ef",
68
+ "buildId": "44450884003-1",
69
+ "identityKey": "0c330c88d6a9536155ce29b9033403e7ca04e00c3d490aa29ff68859371758e7",
70
70
  "tag": "snapshot-nightly"
71
71
  },
72
72
  "scripts": {