@weapp-vite/web 1.6.0 → 2.0.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 (63) hide show
  1. package/README.md +22 -0
  2. package/dist/compiler/wxml/compile.mjs +9 -33
  3. package/dist/compiler/wxml/compile.mjs.map +1 -1
  4. package/dist/compiler/wxml/dependency.mjs +9 -1
  5. package/dist/compiler/wxml/dependency.mjs.map +1 -1
  6. package/dist/compiler/wxml/prepare.mjs +43 -0
  7. package/dist/compiler/wxml/prepare.mjs.map +1 -0
  8. package/dist/css/wxss.mjs +2 -1
  9. package/dist/css/wxss.mjs.map +1 -1
  10. package/dist/plugin/assets.d.mts +1 -0
  11. package/dist/plugin/constants.mjs +4 -2
  12. package/dist/plugin/constants.mjs.map +1 -1
  13. package/dist/plugin/hostTypes.d.mts +75 -0
  14. package/dist/plugin/index.d.mts +2 -74
  15. package/dist/plugin/index.mjs +28 -16
  16. package/dist/plugin/index.mjs.map +1 -1
  17. package/dist/plugin/sfcHmr.mjs +38 -0
  18. package/dist/plugin/sfcHmr.mjs.map +1 -0
  19. package/dist/plugin/vueSfc.mjs +12 -9
  20. package/dist/plugin/vueSfc.mjs.map +1 -1
  21. package/dist/runtime/appStyle.mjs +25 -0
  22. package/dist/runtime/appStyle.mjs.map +1 -0
  23. package/dist/runtime/component/element.mjs +39 -19
  24. package/dist/runtime/component/element.mjs.map +1 -1
  25. package/dist/runtime/component/events.mjs +34 -3
  26. package/dist/runtime/component/events.mjs.map +1 -1
  27. package/dist/runtime/component/publicInstance.mjs +7 -3
  28. package/dist/runtime/component/publicInstance.mjs.map +1 -1
  29. package/dist/runtime/component/state.mjs +7 -0
  30. package/dist/runtime/component/state.mjs.map +1 -1
  31. package/dist/runtime/component/types.d.mts +2 -0
  32. package/dist/runtime/component/utils.mjs +23 -3
  33. package/dist/runtime/component/utils.mjs.map +1 -1
  34. package/dist/runtime/componentEvents.mjs +37 -0
  35. package/dist/runtime/componentEvents.mjs.map +1 -0
  36. package/dist/runtime/eventBinding.d.mts +1 -0
  37. package/dist/runtime/eventBinding.mjs +5 -2
  38. package/dist/runtime/eventBinding.mjs.map +1 -1
  39. package/dist/runtime/hostGlobals.d.mts +1 -0
  40. package/dist/runtime/legacyTemplate/dom.mjs +2 -7
  41. package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
  42. package/dist/runtime/nativeComponents/canvas/index.mjs +12 -3
  43. package/dist/runtime/nativeComponents/canvas/index.mjs.map +1 -1
  44. package/dist/runtime/nativeComponents/index.mjs +0 -1
  45. package/dist/runtime/nativeComponents/index.mjs.map +1 -1
  46. package/dist/runtime/nativeComponents/richText/index.mjs +2 -2
  47. package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -1
  48. package/dist/runtime/pageLayout.d.mts +1 -0
  49. package/dist/runtime/polyfill/index.mjs +1 -1
  50. package/dist/runtime/polyfill/routeRuntime/options.d.mts +1 -0
  51. package/dist/runtime/polyfill/routeRuntime.d.mts +1 -1
  52. package/dist/runtime/polyfill/routeRuntime.mjs +5 -1
  53. package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
  54. package/dist/runtime/renderContext.mjs +3 -2
  55. package/dist/runtime/renderContext.mjs.map +1 -1
  56. package/dist/runtime/wevu.d.mts +1 -0
  57. package/dist/runtime/wevu.mjs +2 -0
  58. package/dist/runtime/wevu.mjs.map +1 -1
  59. package/dist/shared/wxml.mjs +5 -1
  60. package/dist/shared/wxml.mjs.map +1 -1
  61. package/package.json +15 -13
  62. package/dist/runtime/nativeComponents/richText/helpers.mjs +0 -230
  63. package/dist/runtime/nativeComponents/richText/helpers.mjs.map +0 -1
@@ -23,7 +23,9 @@ var WeappCanvas = class extends BaseElement {
23
23
  disconnectedCallback() {
24
24
  if (this.#canvas) unregisterNativeMediaElement(this.#canvas);
25
25
  }
26
- attributeChangedCallback() {
26
+ attributeChangedCallback(name, previous, current) {
27
+ if (previous === current) return;
28
+ if (name === "width" || name === "height") this.#syncSize(name);
27
29
  this.#syncAttributes();
28
30
  }
29
31
  #ensureStructure() {
@@ -37,12 +39,19 @@ var WeappCanvas = class extends BaseElement {
37
39
  const canvas = document.createElement("canvas");
38
40
  root.append(style, canvas);
39
41
  this.#canvas = canvas;
42
+ this.#syncSize();
43
+ }
44
+ #syncSize(dimension) {
45
+ const canvas = this.#canvas;
46
+ if (!canvas) return;
47
+ for (const name of dimension ? [dimension] : ["width", "height"]) {
48
+ const size = resolveCanvasSize(this.getAttribute(name), name === "width" ? 300 : 150);
49
+ if (canvas[name] !== size) canvas[name] = size;
50
+ }
40
51
  }
41
52
  #syncAttributes() {
42
53
  const canvas = this.#canvas;
43
54
  if (!canvas) return;
44
- canvas.width = resolveCanvasSize(this.getAttribute("width"), 300);
45
- canvas.height = resolveCanvasSize(this.getAttribute("height"), 150);
46
55
  canvas.style.touchAction = readBooleanAttribute(this, "disable-scroll") ? "none" : "";
47
56
  registerNativeMediaElement("canvas", [this.getAttribute("canvas-id"), this.getAttribute("id")], canvas);
48
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/canvas/index.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { registerNativeMediaElement, unregisterNativeMediaElement } from '../mediaRegistry'\nimport { ensureNativeComponentStyle } from '../style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction resolveCanvasSize(value: string | null, fallback: number) {\n const size = Number(value)\n return Number.isInteger(size) && size > 0 ? size : fallback\n}\n\nexport class WeappCanvas extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('canvas')!.attributes]\n\n #canvas?: HTMLCanvasElement\n\n get canvasElement() {\n return this.#canvas\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n this.#syncAttributes()\n }\n\n disconnectedCallback() {\n if (this.#canvas) {\n unregisterNativeMediaElement(this.#canvas)\n }\n }\n\n attributeChangedCallback() {\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#canvas || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { position: relative; }\n canvas { display: block; }\n `\n const canvas = document.createElement('canvas')\n root.append(style, canvas)\n this.#canvas = canvas\n }\n\n #syncAttributes() {\n const canvas = this.#canvas\n if (!canvas) {\n return\n }\n canvas.width = resolveCanvasSize(this.getAttribute('width'), 300)\n canvas.height = resolveCanvasSize(this.getAttribute('height'), 150)\n canvas.style.touchAction = readBooleanAttribute(this, 'disable-scroll') ? 'none' : ''\n registerNativeMediaElement('canvas', [\n this.getAttribute('canvas-id'),\n this.getAttribute('id'),\n ], canvas)\n }\n}\n"],"mappings":";;;;;;AAKA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAS,kBAAkB,OAAsB,UAAkB;CACjE,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,OAAO,UAAU,IAAI,KAAK,OAAO,IAAI,OAAO;AACrD;AAEA,IAAa,cAAb,cAAiC,YAAY;CAC3C,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,QAAQ,CAAC,CAAE,UAAU;CAElF;CAEA,IAAI,gBAAgB;EAClB,OAAO,KAAK;CACd;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;CACvB;CAEA,uBAAuB;EACrB,IAAI,KAAK,SACP,6BAA6B,KAAK,OAAO;CAE7C;CAEA,2BAA2B;EACzB,KAAK,gBAAgB;CACvB;CAEA,mBAAmB;EACjB,IAAI,KAAK,WAAW,OAAO,aAAa,aACtC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;;;;EAIpB,MAAM,SAAS,SAAS,cAAc,QAAQ;EAC9C,KAAK,OAAO,OAAO,MAAM;EACzB,KAAK,UAAU;CACjB;CAEA,kBAAkB;EAChB,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QACH;EAEF,OAAO,QAAQ,kBAAkB,KAAK,aAAa,OAAO,GAAG,GAAG;EAChE,OAAO,SAAS,kBAAkB,KAAK,aAAa,QAAQ,GAAG,GAAG;EAClE,OAAO,MAAM,cAAc,qBAAqB,MAAM,gBAAgB,IAAI,SAAS;EACnF,2BAA2B,UAAU,CACnC,KAAK,aAAa,WAAW,GAC7B,KAAK,aAAa,IAAI,CACxB,GAAG,MAAM;CACX;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/canvas/index.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { registerNativeMediaElement, unregisterNativeMediaElement } from '../mediaRegistry'\nimport { ensureNativeComponentStyle } from '../style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction resolveCanvasSize(value: string | null, fallback: number) {\n const size = Number(value)\n return Number.isInteger(size) && size > 0 ? size : fallback\n}\n\nexport class WeappCanvas extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('canvas')!.attributes]\n\n #canvas?: HTMLCanvasElement\n\n get canvasElement() {\n return this.#canvas\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n this.#syncAttributes()\n }\n\n disconnectedCallback() {\n if (this.#canvas) {\n unregisterNativeMediaElement(this.#canvas)\n }\n }\n\n attributeChangedCallback(name: string, previous: string | null, current: string | null) {\n if (previous === current) {\n return\n }\n if (name === 'width' || name === 'height') {\n this.#syncSize(name)\n }\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#canvas || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { position: relative; }\n canvas { display: block; }\n `\n const canvas = document.createElement('canvas')\n root.append(style, canvas)\n this.#canvas = canvas\n this.#syncSize()\n }\n\n #syncSize(dimension?: 'width' | 'height') {\n const canvas = this.#canvas\n if (!canvas) {\n return\n }\n // 相同尺寸赋值也会清空位图和绘图状态;尺寸只归对应宿主属性的实际变化所有。\n for (const name of dimension ? [dimension] : ['width', 'height'] as const) {\n const size = resolveCanvasSize(this.getAttribute(name), name === 'width' ? 300 : 150)\n if (canvas[name] !== size) {\n canvas[name] = size\n }\n }\n }\n\n #syncAttributes() {\n const canvas = this.#canvas\n if (!canvas) {\n return\n }\n canvas.style.touchAction = readBooleanAttribute(this, 'disable-scroll') ? 'none' : ''\n registerNativeMediaElement('canvas', [\n this.getAttribute('canvas-id'),\n this.getAttribute('id'),\n ], canvas)\n }\n}\n"],"mappings":";;;;;;AAKA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAS,kBAAkB,OAAsB,UAAkB;CACjE,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,OAAO,UAAU,IAAI,KAAK,OAAO,IAAI,OAAO;AACrD;AAEA,IAAa,cAAb,cAAiC,YAAY;CAC3C,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,QAAQ,CAAC,CAAE,UAAU;CAElF;CAEA,IAAI,gBAAgB;EAClB,OAAO,KAAK;CACd;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;CACvB;CAEA,uBAAuB;EACrB,IAAI,KAAK,SACP,6BAA6B,KAAK,OAAO;CAE7C;CAEA,yBAAyB,MAAc,UAAyB,SAAwB;EACtF,IAAI,aAAa,SACf;EAEF,IAAI,SAAS,WAAW,SAAS,UAC/B,KAAK,UAAU,IAAI;EAErB,KAAK,gBAAgB;CACvB;CAEA,mBAAmB;EACjB,IAAI,KAAK,WAAW,OAAO,aAAa,aACtC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;;;;EAIpB,MAAM,SAAS,SAAS,cAAc,QAAQ;EAC9C,KAAK,OAAO,OAAO,MAAM;EACzB,KAAK,UAAU;EACf,KAAK,UAAU;CACjB;CAEA,UAAU,WAAgC;EACxC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QACH;EAGF,KAAK,MAAM,QAAQ,YAAY,CAAC,SAAS,IAAI,CAAC,SAAS,QAAQ,GAAY;GACzE,MAAM,OAAO,kBAAkB,KAAK,aAAa,IAAI,GAAG,SAAS,UAAU,MAAM,GAAG;GACpF,IAAI,OAAO,UAAU,MACnB,OAAO,QAAQ;EAEnB;CACF;CAEA,kBAAkB;EAChB,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QACH;EAEF,OAAO,MAAM,cAAc,qBAAqB,MAAM,gBAAgB,IAAI,SAAS;EACnF,2BAA2B,UAAU,CACnC,KAAK,aAAa,WAAW,GAC7B,KAAK,aAAa,IAAI,CACxB,GAAG,MAAM;CACX;AACF"}
@@ -23,7 +23,6 @@ import { WeappPickerView } from "./pickerView/index.mjs";
23
23
  import { createProgressActiveEndDetail, resolveProgressAnimationDuration, resolveProgressConfig } from "./progress/helpers.mjs";
24
24
  import { WeappProgress } from "./progress/index.mjs";
25
25
  import { WeappRadio, WeappRadioGroup, collectRadioGroupValue } from "./radio.mjs";
26
- import { normalizeRichTextNodes, sanitizeRichTextAttributes, sanitizeRichTextStyle } from "./richText/helpers.mjs";
27
26
  import { WeappRichText } from "./richText/index.mjs";
28
27
  import { WeappScrollView, createScrollEventDetail } from "./scrollView.mjs";
29
28
  import { createSliderEventDetail, resolveSliderConfig } from "./slider/helpers.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport {\n normalizeRichTextNodes,\n sanitizeRichTextAttributes,\n sanitizeRichTextStyle,\n} from './richText/helpers'\nexport { createScrollEventDetail } from './scrollView'\nexport { createSliderEventDetail, resolveSliderConfig } from './slider/helpers'\nexport { NATIVE_COMPONENT_STYLE } from './style'\nexport {\n createSwiperChangeDetail,\n resolveSwiperIndex,\n resolveSwiperNumber,\n resolveSwipeTarget,\n} from './swiper/helpers'\nexport { createSwitchEventDetail } from './switch'\nexport { createTextareaLineChangeDetail } from './textarea'\nexport {\n createVideoProgressDetail,\n createVideoTimeUpdateDetail,\n resolveVideoObjectFit,\n} from './video/helpers'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,eAAe;CACnB,cAAc;CACd,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,cAAc;CACd,eAAe;CACf,wBAAwB;CACxB,kBAAkB;CAClB,qBAAqB;CACrB,eAAe;CACf,gBAAgB;CAChB,gBAAgB;CAChB,qBAAqB;CACrB,4BAA4B;CAC5B,gBAAgB;CAChB,cAAc;CACd,kBAAkB;CAClB,mBAAmB;CACnB,qBAAqB;CACrB,mBAAmB;CACnB,gBAAgB;CAChB,qBAAqB;CACrB,gBAAgB;CAChB,eAAe;CACf,oBAAoB;CACpB,qBAAqB;CACrB,sBAAsB;CACtB,sBAAsB;AACxB;AAEA,SAAgB,gCAAgC;CAC9C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,KAAK,MAAM,cAAc,8BAA8B;EACrD,IAAI,eAAe,IAAI,WAAW,MAAM,GACtC;EAEF,MAAM,cAAc,aAAa,WAAW;EAC5C,eAAe,OAAO,WAAW,QAAQ,WAAW;CACtD;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport { createScrollEventDetail } from './scrollView'\nexport { createSliderEventDetail, resolveSliderConfig } from './slider/helpers'\nexport { NATIVE_COMPONENT_STYLE } from './style'\nexport {\n createSwiperChangeDetail,\n resolveSwiperIndex,\n resolveSwiperNumber,\n resolveSwipeTarget,\n} from './swiper/helpers'\nexport { createSwitchEventDetail } from './switch'\nexport { createTextareaLineChangeDetail } from './textarea'\nexport {\n createVideoProgressDetail,\n createVideoTimeUpdateDetail,\n resolveVideoObjectFit,\n} from './video/helpers'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,eAAe;CACnB,cAAc;CACd,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,cAAc;CACd,eAAe;CACf,wBAAwB;CACxB,kBAAkB;CAClB,qBAAqB;CACrB,eAAe;CACf,gBAAgB;CAChB,gBAAgB;CAChB,qBAAqB;CACrB,4BAA4B;CAC5B,gBAAgB;CAChB,cAAc;CACd,kBAAkB;CAClB,mBAAmB;CACnB,qBAAqB;CACrB,mBAAmB;CACnB,gBAAgB;CAChB,qBAAqB;CACrB,gBAAgB;CAChB,eAAe;CACf,oBAAoB;CACpB,qBAAqB;CACrB,sBAAsB;CACtB,sBAAsB;AACxB;AAEA,SAAgB,gCAAgC;CAC9C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,KAAK,MAAM,cAAc,8BAA8B;EACrD,IAAI,eAAe,IAAI,WAAW,MAAM,GACtC;EAEF,MAAM,cAAc,aAAa,WAAW;EAC5C,eAAe,OAAO,WAAW,QAAQ,WAAW;CACtD;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.mjs";
2
2
  import { readBooleanAttribute, resolveContainingShadowRoot } from "../helpers.mjs";
3
3
  import { ensureNativeComponentStyle } from "../style.mjs";
4
- import { normalizeRichTextNodes, sanitizeRichTextAttributes, sanitizeRichTextStyle } from "./helpers.mjs";
4
+ import { normalizeRichTextNodes } from "@weapp-core/shared/rich-text";
5
5
 
6
6
  //#region src/runtime/nativeComponents/richText/index.ts
7
7
  const BaseElement = globalThis.HTMLElement ?? class {};
@@ -70,5 +70,5 @@ var WeappRichText = class extends BaseElement {
70
70
  };
71
71
 
72
72
  //#endregion
73
- export { WeappRichText, normalizeRichTextNodes, sanitizeRichTextAttributes, sanitizeRichTextStyle };
73
+ export { WeappRichText };
74
74
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/richText/index.ts"],"sourcesContent":["import type { SafeRichTextNode } from './helpers'\nimport { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { ensureNativeComponentStyle } from '../style'\nimport { normalizeRichTextNodes } from './helpers'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction createRichTextDomNode(node: SafeRichTextNode): globalThis.Node {\n if (node.type === 'text') {\n return document.createTextNode(node.text)\n }\n const element = document.createElement(node.name)\n for (const [name, value] of Object.entries(node.attrs)) {\n element.setAttribute(name, value)\n }\n element.append(...node.children.map(createRichTextDomNode))\n return element\n}\n\nexport class WeappRichText extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('rich-text')!.attributes]\n\n #content?: HTMLDivElement\n #nodes: unknown = ''\n\n get nodes() {\n return this.#nodes\n }\n\n set nodes(value: unknown) {\n if (Object.is(this.#nodes, value)) {\n return\n }\n this.#nodes = value\n this.#renderNodes()\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n if (this.#nodes === '') {\n this.#nodes = this.getAttribute('nodes') ?? ''\n }\n this.#syncAttributes()\n this.#renderNodes()\n }\n\n attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {\n if (name === 'nodes') {\n this.#nodes = newValue ?? ''\n this.#renderNodes()\n return\n }\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#content || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { overflow-wrap: break-word; }\n .content { display: block; min-width: 0; }\n img { max-width: 100%; }\n `\n const content = document.createElement('div')\n content.className = 'content'\n content.addEventListener('click', (event) => {\n const target = event.target\n if (target instanceof Element && target.closest('a')) {\n event.preventDefault()\n }\n })\n root.append(style, content)\n this.#content = content\n }\n\n #syncAttributes() {\n if (!this.#content) {\n return\n }\n const space = this.getAttribute('space')\n this.#content.style.whiteSpace = space === 'nbsp' || space === 'ensp' || space === 'emsp'\n ? 'pre-wrap'\n : 'normal'\n this.#content.style.userSelect = readBooleanAttribute(this, 'user-select') ? 'text' : ''\n }\n\n #renderNodes() {\n if (!this.#content || typeof document === 'undefined') {\n return\n }\n this.#content.replaceChildren(...normalizeRichTextNodes(this.#nodes).map(createRichTextDomNode))\n }\n}\n\nexport * from './helpers'\n"],"mappings":";;;;;;AAMA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAS,sBAAsB,MAAyC;CACtE,IAAI,KAAK,SAAS,QAChB,OAAO,SAAS,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,SAAS,cAAc,KAAK,IAAI;CAChD,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,KAAK,GACnD,QAAQ,aAAa,MAAM,KAAK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,UAAU,UAAU,SAC/E,aACA;EACJ,KAAK,SAAS,MAAM,aAAa,qBAAqB,MAAM,aAAa,IAAI,SAAS;CACxF;CAEA,eAAe;EACb,IAAI,CAAC,KAAK,YAAY,OAAO,aAAa,aACxC;EAEF,KAAK,SAAS,gBAAgB,GAAG,uBAAuB,KAAK,MAAM,CAAC,CAAC,IAAI,qBAAqB,CAAC;CACjG;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/richText/index.ts"],"sourcesContent":["import type { SafeRichTextNode } from '@weapp-core/shared/rich-text'\nimport { normalizeRichTextNodes } from '@weapp-core/shared/rich-text'\nimport { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { ensureNativeComponentStyle } from '../style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction createRichTextDomNode(node: SafeRichTextNode): globalThis.Node {\n if (node.type === 'text') {\n return document.createTextNode(node.text)\n }\n const element = document.createElement(node.name)\n for (const [name, value] of Object.entries(node.attrs)) {\n element.setAttribute(name, value)\n }\n element.append(...node.children.map(createRichTextDomNode))\n return element\n}\n\nexport class WeappRichText extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('rich-text')!.attributes]\n\n #content?: HTMLDivElement\n #nodes: unknown = ''\n\n get nodes() {\n return this.#nodes\n }\n\n set nodes(value: unknown) {\n if (Object.is(this.#nodes, value)) {\n return\n }\n this.#nodes = value\n this.#renderNodes()\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n if (this.#nodes === '') {\n this.#nodes = this.getAttribute('nodes') ?? ''\n }\n this.#syncAttributes()\n this.#renderNodes()\n }\n\n attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {\n if (name === 'nodes') {\n this.#nodes = newValue ?? ''\n this.#renderNodes()\n return\n }\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#content || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { overflow-wrap: break-word; }\n .content { display: block; min-width: 0; }\n img { max-width: 100%; }\n `\n const content = document.createElement('div')\n content.className = 'content'\n content.addEventListener('click', (event) => {\n const target = event.target\n if (target instanceof Element && target.closest('a')) {\n event.preventDefault()\n }\n })\n root.append(style, content)\n this.#content = content\n }\n\n #syncAttributes() {\n if (!this.#content) {\n return\n }\n const space = this.getAttribute('space')\n this.#content.style.whiteSpace = space === 'nbsp' || space === 'ensp' || space === 'emsp'\n ? 'pre-wrap'\n : 'normal'\n this.#content.style.userSelect = readBooleanAttribute(this, 'user-select') ? 'text' : ''\n }\n\n #renderNodes() {\n if (!this.#content || typeof document === 'undefined') {\n return\n }\n this.#content.replaceChildren(...normalizeRichTextNodes(this.#nodes).map(createRichTextDomNode))\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAS,sBAAsB,MAAyC;CACtE,IAAI,KAAK,SAAS,QAChB,OAAO,SAAS,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,SAAS,cAAc,KAAK,IAAI;CAChD,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,KAAK,GACnD,QAAQ,aAAa,MAAM,KAAK;CAElC,QAAQ,OAAO,GAAG,KAAK,SAAS,IAAI,qBAAqB,CAAC;CAC1D,OAAO;AACT;AAEA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,WAAW,CAAC,CAAE,UAAU;CAErF;CACA,SAAkB;CAElB,IAAI,QAAQ;EACV,OAAO,KAAK;CACd;CAEA,IAAI,MAAM,OAAgB;EACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,KAAK,GAC9B;EAEF,KAAK,SAAS;EACd,KAAK,aAAa;CACpB;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAK,iBAAiB;EACtB,IAAI,KAAK,WAAW,IAClB,KAAK,SAAS,KAAK,aAAa,OAAO,KAAK;EAE9C,KAAK,gBAAgB;EACrB,KAAK,aAAa;CACpB;CAEA,yBAAyB,MAAc,WAA0B,UAAyB;EACxF,IAAI,SAAS,SAAS;GACpB,KAAK,SAAS,YAAY;GAC1B,KAAK,aAAa;GAClB;EACF;EACA,KAAK,gBAAgB;CACvB;CAEA,mBAAmB;EACjB,IAAI,KAAK,YAAY,OAAO,aAAa,aACvC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;;;;;EAKpB,MAAM,UAAU,SAAS,cAAc,KAAK;EAC5C,QAAQ,YAAY;EACpB,QAAQ,iBAAiB,UAAU,UAAU;GAC3C,MAAM,SAAS,MAAM;GACrB,IAAI,kBAAkB,WAAW,OAAO,QAAQ,GAAG,GACjD,MAAM,eAAe;EAEzB,CAAC;EACD,KAAK,OAAO,OAAO,OAAO;EAC1B,KAAK,WAAW;CAClB;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAK,UACR;EAEF,MAAM,QAAQ,KAAK,aAAa,OAAO;EACvC,KAAK,SAAS,MAAM,aAAa,UAAU,UAAU,UAAU,UAAU,UAAU,SAC/E,aACA;EACJ,KAAK,SAAS,MAAM,aAAa,qBAAqB,MAAM,aAAa,IAAI,SAAS;CACxF;CAEA,eAAe;EACb,IAAI,CAAC,KAAK,YAAY,OAAO,aAAa,aACxC;EAEF,KAAK,SAAS,gBAAgB,GAAG,uBAAuB,KAAK,MAAM,CAAC,CAAC,IAAI,qBAAqB,CAAC;CACjG;AACF"}
@@ -5,4 +5,5 @@ type ResolveTypedPageLayoutProps<Name extends string> = Name extends keyof WevuP
5
5
  export declare function setPageLayout(layout: false): void;
6
6
  export declare function setPageLayout<Name extends ResolveTypedPageLayoutName>(layout: Name, props?: ResolveTypedPageLayoutProps<Name>): void;
7
7
  //#endregion
8
+ export {};
8
9
  //# sourceMappingURL=pageLayout.d.mts.map
@@ -16,8 +16,8 @@ import { clearStorage, clearStorageSync, createCanvasContext, createIntersection
16
16
  import { offAppRoute, offAppRouteDone, offBeforeAppRoute, offBeforePageUnload, onAppRoute, onAppRouteDone, onBeforeAppRoute, onBeforePageUnload } from "./routeRuntime/events.mjs";
17
17
  import { getAppInstance, getCurrentPagesInternal, getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, offAppHide, offAppShow, onAppHide, onAppShow, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./routeRuntime.mjs";
18
18
  import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, hideTabBarRedDot, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, removeTabBarBadge, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, setTabBarBadge, setTabBarItem, setTabBarStyle, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showTabBarRedDot, showToast, uiMediaApi_exports, updateShareMenu } from "./uiMediaApi.mjs";
19
- import { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared/platforms/runtime";
20
19
  import { WEVU_PAGE_SCROLL_EVENT_CONTRACT_KEY, WEVU_PAGE_SCROLL_RESTORATION_OWNER_KEY, WEVU_ROUTE_EVENT_CONTRACT_KEY } from "@weapp-core/constants";
20
+ import { getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared/platforms/runtime";
21
21
 
22
22
  //#region src/runtime/polyfill/index.ts
23
23
  const MINI_PROGRAM_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys();
@@ -45,4 +45,5 @@ export interface NavigateBackOptions extends MiniProgramAsyncOptions<MiniProgram
45
45
  export type PageRawOptions = ComponentOptions & PageHooks & Record<string, unknown>;
46
46
  export type ComponentRawOptions = ComponentOptions & Record<string, unknown>;
47
47
  //#endregion
48
+ export {};
48
49
  //# sourceMappingURL=options.d.mts.map
@@ -30,7 +30,7 @@ export declare function initializePageRoutes(ids: string[], options?: {
30
30
  }): void;
31
31
  export declare function registerPage<T extends PageRawOptions | undefined>(options: T, meta: RegisterMeta): T;
32
32
  export declare function registerComponent<T extends ComponentRawOptions | undefined>(options: T, meta: RegisterMeta): T;
33
- export declare function registerApp<T extends AppRuntime | undefined>(options: T, _meta?: RegisterMeta): T;
33
+ export declare function registerApp<T extends AppRuntime | undefined>(options: T, meta?: RegisterMeta): T;
34
34
  export declare function offAppHide(callback?: AppHideCallback): void;
35
35
  export declare function offAppShow(callback?: AppShowCallback): void;
36
36
  export declare function onAppHide(callback: AppHideCallback): void;
@@ -2,6 +2,7 @@ import { slugify } from "../../shared/slugify.mjs";
2
2
  import { setRuntimeWarningOptions } from "../warning.mjs";
3
3
  import { configureTabBar, getTabBarPagePaths, syncTabBarRoute } from "../appShell/tabBar/index.mjs";
4
4
  import { configureWebSeo, setupWebResourceHints, syncWebDocumentHead } from "../seo/index.mjs";
5
+ import { setAppStyle } from "../appStyle.mjs";
5
6
  import { setButtonFormConfig } from "../button/index.mjs";
6
7
  import { setRuntimeExecutionMode } from "../execution.mjs";
7
8
  import { defineComponent } from "../component/index.mjs";
@@ -136,6 +137,7 @@ function registerPage(options, meta) {
136
137
  const component = augmentPageComponentOptions(normalized.component, existing);
137
138
  defineComponent(tag, {
138
139
  id: meta.id,
140
+ kind: "page",
139
141
  template,
140
142
  style: meta.style,
141
143
  component
@@ -151,6 +153,7 @@ function registerPage(options, meta) {
151
153
  const component = augmentPageComponentOptions(normalized.component, record);
152
154
  defineComponent(tag, {
153
155
  id: meta.id,
156
+ kind: "page",
154
157
  template,
155
158
  style: meta.style,
156
159
  component
@@ -184,7 +187,8 @@ function registerComponent(options, meta) {
184
187
  componentRegistry.set(meta.id, { tag });
185
188
  return options;
186
189
  }
187
- function registerApp(options, _meta) {
190
+ function registerApp(options, meta) {
191
+ setAppStyle(meta?.style ?? "");
188
192
  return appLifecycle.register(options);
189
193
  }
190
194
  function offAppHide(callback) {
@@ -1 +1 @@
1
- {"version":3,"file":"routeRuntime.mjs","names":[],"sources":["../../../src/runtime/polyfill/routeRuntime.ts"],"sourcesContent":["import type { WebTabBarConfig } from '../../shared/tabBar'\nimport type { ButtonFormConfig } from '../button'\nimport type { ComponentPublicInstance } from '../component'\nimport type { NavigationBarMetrics } from '../navigationBar'\nimport type { WebResourceHintsConfig, WebSeoConfig } from '../seo'\nimport type { WebViewportConfig } from '../viewport'\nimport type { WebRouteHistoryState, WebRouteTarget, WebRoutingConfig } from './routeRuntime/history'\nimport type { AppHideCallback, AppRuntime, AppShowCallback, ComponentRawOptions, ComponentRecord, NavigateBackOptions, PageRawOptions, PageRecord, RegisterMeta, RouteOptions } from './routeRuntime/options'\nimport { slugify } from '../../shared/slugify'\nimport {\n configureTabBar,\n getTabBarPagePaths,\n syncTabBarRoute,\n} from '../appShell/tabBar'\nimport { setButtonFormConfig } from '../button'\nimport { defineComponent } from '../component'\nimport { setRuntimeExecutionMode } from '../execution'\nimport { ensureNativeComponentsDefined } from '../nativeComponents'\nimport { ensureNavigationBarDefined, setNavigationBarMetrics } from '../navigationBar'\nimport { setupRpx } from '../rpx'\nimport { configureWebSeo, setupWebResourceHints, syncWebDocumentHead } from '../seo'\nimport { setupWebViewport } from '../viewport'\nimport { setRuntimeWarningOptions } from '../warning'\nimport { resolveCurrentPages } from './appState'\nimport { AppLifecycleRuntime } from './routeRuntime/appLifecycle'\nimport { getEntryWebviewId } from './routeRuntime/events'\nimport {\n configureWebRouting,\n getWebHistoryStack,\n readWebRouteTarget,\n syncWebRouting,\n} from './routeRuntime/history'\nimport {\n augmentPageComponentOptions,\n dispatchPageLifetimeToComponents,\n} from './routeRuntime/lifecycle'\nimport {\n normalizeComponentOptions,\n normalizePageOptions,\n} from './routeRuntime/options'\nimport { resolveRouteAction } from './routeRuntime/result'\nimport { PageStackRuntime } from './routeRuntime/stack'\nimport { parsePageUrl } from './routeRuntime/url'\n\nconst pageRegistry = new Map<string, PageRecord>()\nconst componentRegistry = new Map<string, ComponentRecord>()\nlet pageOrder: string[] = []\nlet pageResizeBridgeBound = false\n\nlet pageStack: PageStackRuntime\nconst appLifecycle = new AppLifecycleRuntime(\n () => pageStack?.entries[pageStack.entries.length - 1],\n)\npageStack = new PageStackRuntime(pageRegistry, entry => appLifecycle.ensureLaunched(entry))\n\nfunction syncCurrentWebDocument() {\n const current = pageStack.entries[pageStack.entries.length - 1]\n syncWebDocumentHead({\n route: current?.id,\n title: current ? pageRegistry.get(current.id)?.navigationBar?.title : undefined,\n })\n}\n\nfunction syncCurrentWebRoute(operation: 'push' | 'replace') {\n syncWebRouting(pageStack.entries, operation)\n syncCurrentWebDocument()\n}\n\nfunction reconcileWebRoute(target: WebRouteTarget | undefined, state: WebRouteHistoryState | undefined) {\n const currentEntries = pageStack.entries\n const historyStack = getWebHistoryStack(state)\n if (historyStack?.length) {\n if (historyStack.some(entry => !pageRegistry.has(entry.id))) {\n return\n }\n const sharedLength = Math.min(historyStack.length, currentEntries.length)\n const samePrefix = historyStack.slice(0, sharedLength).every((entry, index) => {\n const current = currentEntries[index]!\n return entry.id === current.id\n && (entry.webviewId === undefined || entry.webviewId === getEntryWebviewId(current))\n && Object.keys(entry.query).length === Object.keys(current.query).length\n && Object.entries(entry.query).every(([key, value]) => current.query[key] === value)\n })\n if (samePrefix && historyStack.length === currentEntries.length) {\n return\n }\n if (samePrefix && historyStack.length < currentEntries.length) {\n pageStack.back(currentEntries.length - historyStack.length)\n }\n else if (samePrefix && historyStack.length > currentEntries.length) {\n const added = historyStack.slice(currentEntries.length)\n if (added.length === 1) {\n pageStack.push(added[0]!.id, { ...added[0]!.query })\n }\n else {\n pageStack.forward(added)\n }\n }\n else {\n const last = historyStack[historyStack.length - 1]!\n if (getTabBarPagePaths().has(last.id)) {\n pageStack.switchTab(last.id, { ...last.query })\n }\n else {\n pageStack.relaunch(last.id, { ...last.query })\n }\n }\n syncWebRouting(pageStack.entries, 'replace')\n syncTabBarRoute(pageStack.entries[pageStack.entries.length - 1]?.id ?? '')\n syncCurrentWebDocument()\n return\n }\n if (target && pageRegistry.has(target.id)) {\n const current = currentEntries[currentEntries.length - 1]\n if (current?.id === target.id\n && Object.keys(current.query).length === Object.keys(target.query).length\n && Object.entries(target.query).every(([key, value]) => current.query[key] === value)) {\n return\n }\n if (getTabBarPagePaths().has(target.id)) {\n pageStack.switchTab(target.id, { ...target.query })\n }\n else {\n pageStack.relaunch(target.id, { ...target.query })\n }\n syncWebRouting(pageStack.entries, 'replace')\n syncTabBarRoute(target.id)\n syncCurrentWebDocument()\n }\n}\n\nfunction performSwitchTab(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const previousLength = pageStack.entries.length\n const previousEntry = pageStack.entries[previousLength - 1]\n const succeeded = pageStack.switchTab(id, query)\n if (succeeded && (pageStack.entries.length !== previousLength || pageStack.entries.at(-1) !== previousEntry)) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('push')\n }\n return resolveRouteAction('switchTab', options, succeeded, 'not a tabBar page')\n}\n\nfunction bindPageResizeBridge() {\n if (pageResizeBridgeBound || typeof window === 'undefined') {\n return\n }\n if (typeof window.addEventListener !== 'function') {\n return\n }\n pageResizeBridgeBound = true\n window.addEventListener('resize', () => {\n const pages = resolveCurrentPages<ComponentPublicInstance>(pageStack.entries)\n const current = pages[pages.length - 1]\n if (!current) {\n return\n }\n dispatchPageLifetimeToComponents(current, 'resize')\n })\n}\n\nexport function initializePageRoutes(\n ids: string[],\n options?: {\n rpx?: { designWidth?: number, varName?: string }\n navigationBar?: NavigationBarMetrics\n form?: ButtonFormConfig\n tabBar?: WebTabBarConfig\n runtime?: {\n executionMode?: 'compat' | 'safe' | 'strict'\n warnings?: {\n level?: 'off' | 'warn' | 'error'\n dedupe?: boolean\n }\n viewport?: WebViewportConfig\n routing?: WebRoutingConfig\n seo?: WebSeoConfig\n resourceHints?: WebResourceHintsConfig\n }\n },\n) {\n setRuntimeExecutionMode(options?.runtime?.executionMode)\n setRuntimeWarningOptions(options?.runtime?.warnings)\n setupWebViewport(options?.runtime?.viewport)\n configureWebSeo(options?.runtime?.seo)\n setupWebResourceHints(options?.runtime?.resourceHints)\n configureWebRouting(options?.runtime?.routing, ids, reconcileWebRoute)\n appLifecycle.bindVisibility()\n ensureNativeComponentsDefined()\n pageOrder = Array.from(new Set(ids))\n configureTabBar(options?.tabBar, url => performSwitchTab({ url }))\n pageStack.configureTabPages(getTabBarPagePaths())\n if (!pageOrder.length) {\n return\n }\n bindPageResizeBridge()\n if (options?.rpx) {\n setupRpx(options.rpx)\n }\n if (options?.navigationBar) {\n setNavigationBarMetrics(options.navigationBar)\n }\n if (options?.form) {\n setButtonFormConfig(options.form)\n }\n if (!pageStack.entries.length) {\n const initialTarget = readWebRouteTarget(pageOrder)\n const initialId = initialTarget?.id ?? pageOrder[0]\n const initialQuery = initialTarget?.query ?? {}\n if (pageStack.push(initialId, initialQuery, 'appLaunch')) {\n syncTabBarRoute(initialId)\n syncCurrentWebRoute('replace')\n }\n }\n}\n\nexport function registerPage<T extends PageRawOptions | undefined>(options: T, meta: RegisterMeta): T {\n ensureNativeComponentsDefined()\n ensureNavigationBarDefined()\n const tag = slugify(meta.id, 'wv-page')\n const template = meta.template ?? (() => '')\n const normalized = normalizePageOptions(options)\n const existing = pageRegistry.get(meta.id)\n if (existing) {\n existing.hooks = normalized.hooks\n existing.navigationBar = meta.navigationBar\n const component = augmentPageComponentOptions(normalized.component, existing)\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n return options\n }\n const record: PageRecord = {\n tag,\n hooks: normalized.hooks,\n instances: new Set(),\n navigationBar: meta.navigationBar,\n }\n const component = augmentPageComponentOptions(normalized.component, record)\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n pageRegistry.set(meta.id, record)\n return options\n}\n\nexport function getCurrentPageInstance(): ComponentPublicInstance | undefined {\n return pageStack.entries[pageStack.entries.length - 1]?.instance\n}\n\nexport function registerComponent<T extends ComponentRawOptions | undefined>(options: T, meta: RegisterMeta): T {\n ensureNativeComponentsDefined()\n const tag = slugify(meta.id, 'wv-component')\n const template = meta.template ?? (() => '')\n const component = normalizeComponentOptions(options)\n if (componentRegistry.has(meta.id)) {\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n return options\n }\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n componentRegistry.set(meta.id, { tag })\n return options\n}\n\nexport function registerApp<T extends AppRuntime | undefined>(options: T, _meta?: RegisterMeta): T {\n return appLifecycle.register(options)\n}\n\nexport function offAppHide(callback?: AppHideCallback) {\n appLifecycle.offAppHide(callback)\n}\n\nexport function offAppShow(callback?: AppShowCallback) {\n appLifecycle.offAppShow(callback)\n}\n\nexport function onAppHide(callback: AppHideCallback) {\n appLifecycle.onAppHide(callback)\n}\n\nexport function onAppShow(callback: AppShowCallback) {\n appLifecycle.onAppShow(callback)\n}\n\nexport function navigateTo(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.push(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('push')\n }\n return resolveRouteAction('navigateTo', options, succeeded)\n}\n\nexport function redirectTo(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.replace(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('redirectTo', options, succeeded)\n}\n\nexport function reLaunch(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.relaunch(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('reLaunch', options, succeeded)\n}\n\nexport function switchTab(options: RouteOptions) {\n return performSwitchTab(options)\n}\n\nexport function navigateBack(options?: NavigateBackOptions) {\n const succeeded = pageStack.back(options?.delta)\n if (succeeded) {\n syncTabBarRoute(pageStack.entries[pageStack.entries.length - 1]?.id ?? '')\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('navigateBack', options, succeeded)\n}\n\nexport function getCurrentPagesInternal() {\n return resolveCurrentPages<ComponentPublicInstance>(pageStack.entries)\n}\n\nexport function getAppInstance() {\n return appLifecycle.instance\n}\n\nexport function getLaunchOptionsSync() {\n return appLifecycle.getLaunchOptions()\n}\n\nexport function getEnterOptionsSync() {\n return appLifecycle.getEnterOptions()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,+BAAe,IAAI,IAAwB;AACjD,MAAM,oCAAoB,IAAI,IAA6B;AAC3D,IAAI,YAAsB,CAAC;AAC3B,IAAI,wBAAwB;AAE5B,IAAI;AACJ,MAAM,eAAe,IAAI,0BACjB,WAAW,QAAQ,UAAU,QAAQ,SAAS,EACtD;AACA,YAAY,IAAI,iBAAiB,eAAc,UAAS,aAAa,eAAe,KAAK,CAAC;AAE1F,SAAS,yBAAyB;CAChC,MAAM,UAAU,UAAU,QAAQ,UAAU,QAAQ,SAAS;CAC7D,oBAAoB;EAClB,OAAO,SAAS;EAChB,OAAO,UAAU,aAAa,IAAI,QAAQ,EAAE,CAAC,EAAE,eAAe,QAAQ;CACxE,CAAC;AACH;AAEA,SAAS,oBAAoB,WAA+B;CAC1D,eAAe,UAAU,SAAS,SAAS;CAC3C,uBAAuB;AACzB;AAEA,SAAS,kBAAkB,QAAoC,OAAyC;CACtG,MAAM,iBAAiB,UAAU;CACjC,MAAM,eAAe,mBAAmB,KAAK;CAC7C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AAK,IAAI,KAAK;CAC1C,IAAI,WAAW;EACb,gBAAgB,EAAE;EAClB,oBAAoB,MAAM;CAC5B;CACA,OAAO,mBAAmB,cAAc,SAAS,SAAS;AAC5D;AAEA,SAAgB,WAAW,SAAuB;CAChD,MAAM,EAAE,IAAI,UAAU,aAAa,SAAS,OAAO,EAAE;CACrD,MAAM,YAAY,UAAU,QAAQ,IAAI,KAAK;CAC7C,IAAI,WAAW;EACb,gBAAgB,EAAE;EAClB,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,cAAc,SAAS,SAAS;AAC5D;AAEA,SAAgB,SAAS,SAAuB;CAC9C,MAAM,EAAE,IAAI,UAAU,aAAa,SAAS,OAAO,EAAE;CACrD,MAAM,YAAY,UAAU,SAAS,IAAI,KAAK;CAC9C,IAAI,WAAW;EACb,gBAAgB,EAAE;EAClB,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,YAAY,SAAS,SAAS;AAC1D;AAEA,SAAgB,UAAU,SAAuB;CAC/C,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,aAAa,SAA+B;CAC1D,MAAM,YAAY,UAAU,KAAK,SAAS,KAAK;CAC/C,IAAI,WAAW;EACb,gBAAgB,UAAU,QAAQ,UAAU,QAAQ,SAAS,EAAE,EAAE,MAAM,EAAE;EACzE,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,gBAAgB,SAAS,SAAS;AAC9D;AAEA,SAAgB,0BAA0B;CACxC,OAAO,oBAA6C,UAAU,OAAO;AACvE;AAEA,SAAgB,iBAAiB;CAC/B,OAAO,aAAa;AACtB;AAEA,SAAgB,uBAAuB;CACrC,OAAO,aAAa,iBAAiB;AACvC;AAEA,SAAgB,sBAAsB;CACpC,OAAO,aAAa,gBAAgB;AACtC"}
1
+ {"version":3,"file":"routeRuntime.mjs","names":[],"sources":["../../../src/runtime/polyfill/routeRuntime.ts"],"sourcesContent":["import type { WebTabBarConfig } from '../../shared/tabBar'\nimport type { ButtonFormConfig } from '../button'\nimport type { ComponentPublicInstance } from '../component'\nimport type { NavigationBarMetrics } from '../navigationBar'\nimport type { WebResourceHintsConfig, WebSeoConfig } from '../seo'\nimport type { WebViewportConfig } from '../viewport'\nimport type { WebRouteHistoryState, WebRouteTarget, WebRoutingConfig } from './routeRuntime/history'\nimport type { AppHideCallback, AppRuntime, AppShowCallback, ComponentRawOptions, ComponentRecord, NavigateBackOptions, PageRawOptions, PageRecord, RegisterMeta, RouteOptions } from './routeRuntime/options'\nimport { slugify } from '../../shared/slugify'\nimport {\n configureTabBar,\n getTabBarPagePaths,\n syncTabBarRoute,\n} from '../appShell/tabBar'\nimport { setAppStyle } from '../appStyle'\nimport { setButtonFormConfig } from '../button'\nimport { defineComponent } from '../component'\nimport { setRuntimeExecutionMode } from '../execution'\nimport { ensureNativeComponentsDefined } from '../nativeComponents'\nimport { ensureNavigationBarDefined, setNavigationBarMetrics } from '../navigationBar'\nimport { setupRpx } from '../rpx'\nimport { configureWebSeo, setupWebResourceHints, syncWebDocumentHead } from '../seo'\nimport { setupWebViewport } from '../viewport'\nimport { setRuntimeWarningOptions } from '../warning'\nimport { resolveCurrentPages } from './appState'\nimport { AppLifecycleRuntime } from './routeRuntime/appLifecycle'\nimport { getEntryWebviewId } from './routeRuntime/events'\nimport {\n configureWebRouting,\n getWebHistoryStack,\n readWebRouteTarget,\n syncWebRouting,\n} from './routeRuntime/history'\nimport {\n augmentPageComponentOptions,\n dispatchPageLifetimeToComponents,\n} from './routeRuntime/lifecycle'\nimport {\n normalizeComponentOptions,\n normalizePageOptions,\n} from './routeRuntime/options'\nimport { resolveRouteAction } from './routeRuntime/result'\nimport { PageStackRuntime } from './routeRuntime/stack'\nimport { parsePageUrl } from './routeRuntime/url'\n\nconst pageRegistry = new Map<string, PageRecord>()\nconst componentRegistry = new Map<string, ComponentRecord>()\nlet pageOrder: string[] = []\nlet pageResizeBridgeBound = false\n\nlet pageStack: PageStackRuntime\nconst appLifecycle = new AppLifecycleRuntime(\n () => pageStack?.entries[pageStack.entries.length - 1],\n)\npageStack = new PageStackRuntime(pageRegistry, entry => appLifecycle.ensureLaunched(entry))\n\nfunction syncCurrentWebDocument() {\n const current = pageStack.entries[pageStack.entries.length - 1]\n syncWebDocumentHead({\n route: current?.id,\n title: current ? pageRegistry.get(current.id)?.navigationBar?.title : undefined,\n })\n}\n\nfunction syncCurrentWebRoute(operation: 'push' | 'replace') {\n syncWebRouting(pageStack.entries, operation)\n syncCurrentWebDocument()\n}\n\nfunction reconcileWebRoute(target: WebRouteTarget | undefined, state: WebRouteHistoryState | undefined) {\n const currentEntries = pageStack.entries\n const historyStack = getWebHistoryStack(state)\n if (historyStack?.length) {\n if (historyStack.some(entry => !pageRegistry.has(entry.id))) {\n return\n }\n const sharedLength = Math.min(historyStack.length, currentEntries.length)\n const samePrefix = historyStack.slice(0, sharedLength).every((entry, index) => {\n const current = currentEntries[index]!\n return entry.id === current.id\n && (entry.webviewId === undefined || entry.webviewId === getEntryWebviewId(current))\n && Object.keys(entry.query).length === Object.keys(current.query).length\n && Object.entries(entry.query).every(([key, value]) => current.query[key] === value)\n })\n if (samePrefix && historyStack.length === currentEntries.length) {\n return\n }\n if (samePrefix && historyStack.length < currentEntries.length) {\n pageStack.back(currentEntries.length - historyStack.length)\n }\n else if (samePrefix && historyStack.length > currentEntries.length) {\n const added = historyStack.slice(currentEntries.length)\n if (added.length === 1) {\n pageStack.push(added[0]!.id, { ...added[0]!.query })\n }\n else {\n pageStack.forward(added)\n }\n }\n else {\n const last = historyStack[historyStack.length - 1]!\n if (getTabBarPagePaths().has(last.id)) {\n pageStack.switchTab(last.id, { ...last.query })\n }\n else {\n pageStack.relaunch(last.id, { ...last.query })\n }\n }\n syncWebRouting(pageStack.entries, 'replace')\n syncTabBarRoute(pageStack.entries[pageStack.entries.length - 1]?.id ?? '')\n syncCurrentWebDocument()\n return\n }\n if (target && pageRegistry.has(target.id)) {\n const current = currentEntries[currentEntries.length - 1]\n if (current?.id === target.id\n && Object.keys(current.query).length === Object.keys(target.query).length\n && Object.entries(target.query).every(([key, value]) => current.query[key] === value)) {\n return\n }\n if (getTabBarPagePaths().has(target.id)) {\n pageStack.switchTab(target.id, { ...target.query })\n }\n else {\n pageStack.relaunch(target.id, { ...target.query })\n }\n syncWebRouting(pageStack.entries, 'replace')\n syncTabBarRoute(target.id)\n syncCurrentWebDocument()\n }\n}\n\nfunction performSwitchTab(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const previousLength = pageStack.entries.length\n const previousEntry = pageStack.entries[previousLength - 1]\n const succeeded = pageStack.switchTab(id, query)\n if (succeeded && (pageStack.entries.length !== previousLength || pageStack.entries.at(-1) !== previousEntry)) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('push')\n }\n return resolveRouteAction('switchTab', options, succeeded, 'not a tabBar page')\n}\n\nfunction bindPageResizeBridge() {\n if (pageResizeBridgeBound || typeof window === 'undefined') {\n return\n }\n if (typeof window.addEventListener !== 'function') {\n return\n }\n pageResizeBridgeBound = true\n window.addEventListener('resize', () => {\n const pages = resolveCurrentPages<ComponentPublicInstance>(pageStack.entries)\n const current = pages[pages.length - 1]\n if (!current) {\n return\n }\n dispatchPageLifetimeToComponents(current, 'resize')\n })\n}\n\nexport function initializePageRoutes(\n ids: string[],\n options?: {\n rpx?: { designWidth?: number, varName?: string }\n navigationBar?: NavigationBarMetrics\n form?: ButtonFormConfig\n tabBar?: WebTabBarConfig\n runtime?: {\n executionMode?: 'compat' | 'safe' | 'strict'\n warnings?: {\n level?: 'off' | 'warn' | 'error'\n dedupe?: boolean\n }\n viewport?: WebViewportConfig\n routing?: WebRoutingConfig\n seo?: WebSeoConfig\n resourceHints?: WebResourceHintsConfig\n }\n },\n) {\n setRuntimeExecutionMode(options?.runtime?.executionMode)\n setRuntimeWarningOptions(options?.runtime?.warnings)\n setupWebViewport(options?.runtime?.viewport)\n configureWebSeo(options?.runtime?.seo)\n setupWebResourceHints(options?.runtime?.resourceHints)\n configureWebRouting(options?.runtime?.routing, ids, reconcileWebRoute)\n appLifecycle.bindVisibility()\n ensureNativeComponentsDefined()\n pageOrder = Array.from(new Set(ids))\n configureTabBar(options?.tabBar, url => performSwitchTab({ url }))\n pageStack.configureTabPages(getTabBarPagePaths())\n if (!pageOrder.length) {\n return\n }\n bindPageResizeBridge()\n if (options?.rpx) {\n setupRpx(options.rpx)\n }\n if (options?.navigationBar) {\n setNavigationBarMetrics(options.navigationBar)\n }\n if (options?.form) {\n setButtonFormConfig(options.form)\n }\n if (!pageStack.entries.length) {\n const initialTarget = readWebRouteTarget(pageOrder)\n const initialId = initialTarget?.id ?? pageOrder[0]\n const initialQuery = initialTarget?.query ?? {}\n if (pageStack.push(initialId, initialQuery, 'appLaunch')) {\n syncTabBarRoute(initialId)\n syncCurrentWebRoute('replace')\n }\n }\n}\n\nexport function registerPage<T extends PageRawOptions | undefined>(options: T, meta: RegisterMeta): T {\n ensureNativeComponentsDefined()\n ensureNavigationBarDefined()\n const tag = slugify(meta.id, 'wv-page')\n const template = meta.template ?? (() => '')\n const normalized = normalizePageOptions(options)\n const existing = pageRegistry.get(meta.id)\n if (existing) {\n existing.hooks = normalized.hooks\n existing.navigationBar = meta.navigationBar\n const component = augmentPageComponentOptions(normalized.component, existing)\n defineComponent(tag, {\n id: meta.id,\n kind: 'page',\n template,\n style: meta.style,\n component,\n })\n return options\n }\n const record: PageRecord = {\n tag,\n hooks: normalized.hooks,\n instances: new Set(),\n navigationBar: meta.navigationBar,\n }\n const component = augmentPageComponentOptions(normalized.component, record)\n defineComponent(tag, {\n id: meta.id,\n kind: 'page',\n template,\n style: meta.style,\n component,\n })\n pageRegistry.set(meta.id, record)\n return options\n}\n\nexport function getCurrentPageInstance(): ComponentPublicInstance | undefined {\n return pageStack.entries[pageStack.entries.length - 1]?.instance\n}\n\nexport function registerComponent<T extends ComponentRawOptions | undefined>(options: T, meta: RegisterMeta): T {\n ensureNativeComponentsDefined()\n const tag = slugify(meta.id, 'wv-component')\n const template = meta.template ?? (() => '')\n const component = normalizeComponentOptions(options)\n if (componentRegistry.has(meta.id)) {\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n return options\n }\n defineComponent(tag, {\n id: meta.id,\n template,\n style: meta.style,\n component,\n })\n componentRegistry.set(meta.id, { tag })\n return options\n}\n\nexport function registerApp<T extends AppRuntime | undefined>(options: T, meta?: RegisterMeta): T {\n setAppStyle(meta?.style ?? '')\n return appLifecycle.register(options)\n}\n\nexport function offAppHide(callback?: AppHideCallback) {\n appLifecycle.offAppHide(callback)\n}\n\nexport function offAppShow(callback?: AppShowCallback) {\n appLifecycle.offAppShow(callback)\n}\n\nexport function onAppHide(callback: AppHideCallback) {\n appLifecycle.onAppHide(callback)\n}\n\nexport function onAppShow(callback: AppShowCallback) {\n appLifecycle.onAppShow(callback)\n}\n\nexport function navigateTo(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.push(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('push')\n }\n return resolveRouteAction('navigateTo', options, succeeded)\n}\n\nexport function redirectTo(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.replace(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('redirectTo', options, succeeded)\n}\n\nexport function reLaunch(options: RouteOptions) {\n const { id, query } = parsePageUrl(options?.url ?? '')\n const succeeded = pageStack.relaunch(id, query)\n if (succeeded) {\n syncTabBarRoute(id)\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('reLaunch', options, succeeded)\n}\n\nexport function switchTab(options: RouteOptions) {\n return performSwitchTab(options)\n}\n\nexport function navigateBack(options?: NavigateBackOptions) {\n const succeeded = pageStack.back(options?.delta)\n if (succeeded) {\n syncTabBarRoute(pageStack.entries[pageStack.entries.length - 1]?.id ?? '')\n syncCurrentWebRoute('replace')\n }\n return resolveRouteAction('navigateBack', options, succeeded)\n}\n\nexport function getCurrentPagesInternal() {\n return resolveCurrentPages<ComponentPublicInstance>(pageStack.entries)\n}\n\nexport function getAppInstance() {\n return appLifecycle.instance\n}\n\nexport function getLaunchOptionsSync() {\n return appLifecycle.getLaunchOptions()\n}\n\nexport function getEnterOptionsSync() {\n return appLifecycle.getEnterOptions()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,+BAAe,IAAI,IAAwB;AACjD,MAAM,oCAAoB,IAAI,IAA6B;AAC3D,IAAI,YAAsB,CAAC;AAC3B,IAAI,wBAAwB;AAE5B,IAAI;AACJ,MAAM,eAAe,IAAI,0BACjB,WAAW,QAAQ,UAAU,QAAQ,SAAS,EACtD;AACA,YAAY,IAAI,iBAAiB,eAAc,UAAS,aAAa,eAAe,KAAK,CAAC;AAE1F,SAAS,yBAAyB;CAChC,MAAM,UAAU,UAAU,QAAQ,UAAU,QAAQ,SAAS;CAC7D,oBAAoB;EAClB,OAAO,SAAS;EAChB,OAAO,UAAU,aAAa,IAAI,QAAQ,EAAE,CAAC,EAAE,eAAe,QAAQ;CACxE,CAAC;AACH;AAEA,SAAS,oBAAoB,WAA+B;CAC1D,eAAe,UAAU,SAAS,SAAS;CAC3C,uBAAuB;AACzB;AAEA,SAAS,kBAAkB,QAAoC,OAAyC;CACtG,MAAM,iBAAiB,UAAU;CACjC,MAAM,eAAe,mBAAmB,KAAK;CAC7C,IAAI,cAAc,QAAQ;EACxB,IAAI,aAAa,MAAK,UAAS,CAAC,aAAa,IAAI,MAAM,EAAE,CAAC,GACxD;EAEF,MAAM,eAAe,KAAK,IAAI,aAAa,QAAQ,eAAe,MAAM;EACxE,MAAM,aAAa,aAAa,MAAM,GAAG,YAAY,CAAC,CAAC,OAAO,OAAO,UAAU;GAC7E,MAAM,UAAU,eAAe;GAC/B,OAAO,MAAM,OAAO,QAAQ,OACtB,MAAM,cAAc,UAAa,MAAM,cAAc,kBAAkB,OAAO,MAC/E,OAAO,K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EAClB,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,cAAc,SAAS,SAAS;AAC5D;AAEA,SAAgB,SAAS,SAAuB;CAC9C,MAAM,EAAE,IAAI,UAAU,aAAa,SAAS,OAAO,EAAE;CACrD,MAAM,YAAY,UAAU,SAAS,IAAI,KAAK;CAC9C,IAAI,WAAW;EACb,gBAAgB,EAAE;EAClB,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,YAAY,SAAS,SAAS;AAC1D;AAEA,SAAgB,UAAU,SAAuB;CAC/C,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,aAAa,SAA+B;CAC1D,MAAM,YAAY,UAAU,KAAK,SAAS,KAAK;CAC/C,IAAI,WAAW;EACb,gBAAgB,UAAU,QAAQ,UAAU,QAAQ,SAAS,EAAE,EAAE,MAAM,EAAE;EACzE,oBAAoB,SAAS;CAC/B;CACA,OAAO,mBAAmB,gBAAgB,SAAS,SAAS;AAC9D;AAEA,SAAgB,0BAA0B;CACxC,OAAO,oBAA6C,UAAU,OAAO;AACvE;AAEA,SAAgB,iBAAiB;CAC/B,OAAO,aAAa;AACtB;AAEA,SAAgB,uBAAuB;CACrC,OAAO,aAAa,iBAAiB;AACvC;AAEA,SAAgB,sBAAsB;CACpC,OAAO,aAAa,gBAAgB;AACtC"}
@@ -1,4 +1,5 @@
1
1
  import { emitRuntimeWarning } from "./warning.mjs";
2
+ import { nameRuntimeEventHandler } from "./componentEvents.mjs";
2
3
  import { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from "./execution.mjs";
3
4
  import { invokeMiniProgramEventHandler } from "./inputHandlerResult.mjs";
4
5
 
@@ -69,7 +70,7 @@ function normalizeKey(rawKey, item, index, scope) {
69
70
  function createEventHandler(instance, methods, eventName, handlerRef, flags) {
70
71
  const handler = typeof handlerRef === "function" ? handlerRef : methods[handlerRef] ?? instance[handlerRef];
71
72
  if (typeof handler !== "function") return () => {};
72
- return (nativeEvent) => {
73
+ return nameRuntimeEventHandler((nativeEvent) => {
73
74
  if (flags?.catch) nativeEvent.stopPropagation();
74
75
  const target = nativeEvent.target;
75
76
  const dataset = nativeEvent.currentTarget?.dataset ?? {};
@@ -82,7 +83,7 @@ function createEventHandler(instance, methods, eventName, handlerRef, flags) {
82
83
  originalEvent: nativeEvent
83
84
  };
84
85
  invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent);
85
- };
86
+ }, eventName);
86
87
  }
87
88
  function createWxsModule(code, id, requireMap) {
88
89
  const module = { exports: {} };
@@ -1 +1 @@
1
- {"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/runtime/renderContext.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './component'\nimport type { TemplateScope } from './template'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from './execution'\nimport { invokeMiniProgramEventHandler } from './inputHandlerResult'\nimport { emitRuntimeWarning } from './warning'\n\nexport interface RenderContext {\n instance: ComponentPublicInstance\n eval: (expression: string, scope: TemplateScope, wxs?: Record<string, any>) => any\n createScope: (parent: TemplateScope, locals?: Record<string, any>) => TemplateScope\n mergeScope: (parent: TemplateScope, data?: any) => TemplateScope\n normalizeList: (value: any) => any[]\n key: (rawKey: string, item: any, index: number, scope: TemplateScope, wxs?: Record<string, any>) => any\n renderTemplate: (templates: Record<string, any>, name: any, scope: TemplateScope, ctx: RenderContext) => any\n event: (eventName: string, handlerName: any, scope: TemplateScope, wxs?: Record<string, any>, flags?: { catch?: boolean, capture?: boolean }) => (event: Event) => void\n createWxsModule: (code: string, id: string, requireMap?: Record<string, any>) => Record<string, any>\n}\n\nconst expressionCache = new Map<string, (scope: TemplateScope) => any>()\nconst MUSTACHE_PREFIX_RE = /^\\{\\{\\s*/\nconst MUSTACHE_SUFFIX_RE = /\\s*\\}\\}$/\nconst SIMPLE_KEY_PATH_RE = /[.[()]/\n\nfunction createScope(initial?: TemplateScope): TemplateScope {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nfunction createChildScope(parent: TemplateScope, locals?: Record<string, any>): TemplateScope {\n return Object.assign(Object.create(parent), locals ?? {})\n}\n\nfunction evaluateExpression(expression: string, scope: TemplateScope): any {\n if (!expression) {\n return undefined\n }\n const trimmed = expression.trim()\n if (!trimmed) {\n return undefined\n }\n let evaluator = expressionCache.get(trimmed)\n if (!evaluator) {\n try {\n // eslint-disable-next-line no-new-func -- dynamic expressions are required for template evaluation\n evaluator = new Function('scope', `with(scope){ return (${trimmed}); }`) as (scope: TemplateScope) => any\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-expression-parse:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式解析错误 \"${trimmed}\": ${reason}`,\n )\n evaluator = () => undefined\n }\n else {\n throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 \"${trimmed}\": ${reason}`)\n }\n }\n expressionCache.set(trimmed, evaluator)\n }\n try {\n return evaluator?.(scope)\n }\n catch (error) {\n const mode = getRuntimeExecutionMode()\n if (mode === 'strict') {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 \"${trimmed}\": ${reason}`)\n }\n if (mode === 'safe') {\n const reason = error instanceof Error ? error.message : String(error)\n warnRuntimeExecutionOnce(\n `safe-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nfunction normalizeList(value: any): any[] {\n if (Array.isArray(value)) {\n return value\n }\n if (value == null) {\n return []\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n const length = Math.max(0, Math.floor(value))\n return Array.from({ length }, (_, index) => index)\n }\n if (typeof value === 'object') {\n return Object.values(value)\n }\n return []\n}\n\nfunction normalizeKey(rawKey: string, item: any, index: number, scope: TemplateScope): any {\n const key = rawKey?.trim()\n if (!key) {\n if (item != null && (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean')) {\n return item\n }\n return index\n }\n if (key === '*this') {\n return item\n }\n if (key.includes('{{') && key.includes('}}')) {\n const expr = key.replace(MUSTACHE_PREFIX_RE, '').replace(MUSTACHE_SUFFIX_RE, '')\n return evaluateExpression(expr, scope)\n }\n if (!SIMPLE_KEY_PATH_RE.test(key) && item && typeof item === 'object' && key in item) {\n return (item as Record<string, any>)[key]\n }\n return evaluateExpression(key, scope)\n}\n\nfunction createEventHandler(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n eventName: string,\n handlerRef: string | ((event: any) => any),\n flags?: { catch?: boolean },\n) {\n const handler = typeof handlerRef === 'function'\n ? handlerRef\n : methods[handlerRef] ?? (instance as Record<string, any>)[handlerRef]\n if (typeof handler !== 'function') {\n return () => {}\n }\n return (nativeEvent: Event) => {\n if (flags?.catch) {\n nativeEvent.stopPropagation()\n }\n const target = nativeEvent.target as HTMLElement | null\n const currentTarget = nativeEvent.currentTarget as HTMLElement | null\n const dataset = currentTarget?.dataset ?? {}\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset: target?.dataset ?? dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent)\n }\n}\n\nfunction createWxsModule(code: string, id: string, requireMap?: Record<string, any>) {\n const module = { exports: {} as Record<string, any> }\n const exports = module.exports\n const getRegExp = (pattern: string, flags?: string) => new RegExp(pattern, flags)\n const getDate = (value?: string | number | Date) => (value == null ? new Date() : new Date(value))\n const require = (request: string) => requireMap?.[request]\n try {\n // eslint-disable-next-line no-new-func -- run in isolated module scope\n const runner = new Function('module', 'exports', 'require', 'getRegExp', 'getDate', code)\n runner(module, exports, require, getRegExp, getDate)\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-wxs-runtime:${id}`,\n `[@weapp-vite/web] safe 模式下忽略 WXS 执行错误: ${id} ${reason}`,\n )\n return {}\n }\n throw new Error(`[@weapp-vite/web] WXS 执行失败: ${id} ${reason}`)\n }\n return module.exports\n}\n\nexport function createRenderContext(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n): RenderContext {\n const warnMissingTemplate = (name: string) => {\n emitRuntimeWarning(`[@weapp-vite/web] 未找到模板: ${name}`, {\n key: `template-missing:${name}`,\n context: 'runtime:template',\n })\n }\n\n return {\n instance,\n eval: (expression, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return evaluateExpression(expression, renderScope)\n },\n createScope: (parent, locals) => createChildScope(parent, locals),\n mergeScope: (parent, data) => {\n const baseScope = parent ?? createScope()\n if (!data || typeof data !== 'object') {\n return baseScope\n }\n return createChildScope(baseScope, data as Record<string, any>)\n },\n normalizeList,\n key: (rawKey, item, index, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return normalizeKey(rawKey, item, index, renderScope)\n },\n renderTemplate: (templates, name, scope, ctx) => {\n const resolvedName = typeof name === 'string' ? name : String(name)\n const template = templates?.[resolvedName]\n if (typeof template !== 'function') {\n warnMissingTemplate(resolvedName)\n return ''\n }\n return template(scope, ctx)\n },\n event: (eventName, handlerName, _scope, _wxs, flags) => {\n if (typeof handlerName === 'function') {\n return createEventHandler(instance, methods, eventName, handlerName, flags)\n }\n const resolvedHandler = String(handlerName ?? '')\n return createEventHandler(instance, methods, eventName, resolvedHandler, flags)\n },\n createWxsModule,\n }\n}\n\nexport { createChildScope, createScope, evaluateExpression }\n"],"mappings":";;;;;AAkBA,MAAM,kCAAkB,IAAI,IAA2C;AACvE,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MA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a,QAAQ,MAAM,OADd,MAAM,iBAAiB,WAAW,GAAG,IAAI,SACT;EACtD;EACA,iBAAiB,WAAW,MAAM,OAAO,QAAQ;GAC/C,MAAM,eAAe,OAAO,SAAS,WAAW,OAAO,OAAO,IAAI;GAClE,MAAM,WAAW,YAAY;GAC7B,IAAI,OAAO,aAAa,YAAY;IAClC,oBAAoB,YAAY;IAChC,OAAO;GACT;GACA,OAAO,SAAS,OAAO,GAAG;EAC5B;EACA,QAAQ,WAAW,aAAa,QAAQ,MAAM,UAAU;GACtD,IAAI,OAAO,gBAAgB,YACzB,OAAO,mBAAmB,UAAU,SAAS,WAAW,aAAa,KAAK;GAG5E,OAAO,mBAAmB,UAAU,SAAS,WADrB,OAAO,eAAe,EACwB,GAAG,KAAK;EAChF;EACA;CACF;AACF"}
1
+ {"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/runtime/renderContext.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './component'\nimport type { TemplateScope } from './template'\nimport { nameRuntimeEventHandler } from './componentEvents'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from './execution'\nimport { invokeMiniProgramEventHandler } from './inputHandlerResult'\nimport { emitRuntimeWarning } from './warning'\n\nexport interface RenderContext {\n instance: ComponentPublicInstance\n eval: (expression: string, scope: TemplateScope, wxs?: Record<string, any>) => any\n createScope: (parent: TemplateScope, locals?: Record<string, any>) => TemplateScope\n mergeScope: (parent: TemplateScope, data?: any) => TemplateScope\n normalizeList: (value: any) => any[]\n key: (rawKey: string, item: any, index: number, scope: TemplateScope, wxs?: Record<string, any>) => any\n renderTemplate: (templates: Record<string, any>, name: any, scope: TemplateScope, ctx: RenderContext) => any\n event: (eventName: string, handlerName: any, scope: TemplateScope, wxs?: Record<string, any>, flags?: { catch?: boolean, capture?: boolean }) => (event: Event) => void\n createWxsModule: (code: string, id: string, requireMap?: Record<string, any>) => Record<string, any>\n}\n\nconst expressionCache = new Map<string, (scope: TemplateScope) => any>()\nconst MUSTACHE_PREFIX_RE = /^\\{\\{\\s*/\nconst MUSTACHE_SUFFIX_RE = /\\s*\\}\\}$/\nconst SIMPLE_KEY_PATH_RE = /[.[()]/\n\nfunction createScope(initial?: TemplateScope): TemplateScope {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nfunction createChildScope(parent: TemplateScope, locals?: Record<string, any>): TemplateScope {\n return Object.assign(Object.create(parent), locals ?? {})\n}\n\nfunction evaluateExpression(expression: string, scope: TemplateScope): any {\n if (!expression) {\n return undefined\n }\n const trimmed = expression.trim()\n if (!trimmed) {\n return undefined\n }\n let evaluator = expressionCache.get(trimmed)\n if (!evaluator) {\n try {\n // eslint-disable-next-line no-new-func -- dynamic expressions are required for template evaluation\n evaluator = new Function('scope', `with(scope){ return (${trimmed}); }`) as (scope: TemplateScope) => any\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-expression-parse:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式解析错误 \"${trimmed}\": ${reason}`,\n )\n evaluator = () => undefined\n }\n else {\n throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 \"${trimmed}\": ${reason}`)\n }\n }\n expressionCache.set(trimmed, evaluator)\n }\n try {\n return evaluator?.(scope)\n }\n catch (error) {\n const mode = getRuntimeExecutionMode()\n if (mode === 'strict') {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 \"${trimmed}\": ${reason}`)\n }\n if (mode === 'safe') {\n const reason = error instanceof Error ? error.message : String(error)\n warnRuntimeExecutionOnce(\n `safe-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nfunction normalizeList(value: any): any[] {\n if (Array.isArray(value)) {\n return value\n }\n if (value == null) {\n return []\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n const length = Math.max(0, Math.floor(value))\n return Array.from({ length }, (_, index) => index)\n }\n if (typeof value === 'object') {\n return Object.values(value)\n }\n return []\n}\n\nfunction normalizeKey(rawKey: string, item: any, index: number, scope: TemplateScope): any {\n const key = rawKey?.trim()\n if (!key) {\n if (item != null && (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean')) {\n return item\n }\n return index\n }\n if (key === '*this') {\n return item\n }\n if (key.includes('{{') && key.includes('}}')) {\n const expr = key.replace(MUSTACHE_PREFIX_RE, '').replace(MUSTACHE_SUFFIX_RE, '')\n return evaluateExpression(expr, scope)\n }\n if (!SIMPLE_KEY_PATH_RE.test(key) && item && typeof item === 'object' && key in item) {\n return (item as Record<string, any>)[key]\n }\n return evaluateExpression(key, scope)\n}\n\nfunction createEventHandler(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n eventName: string,\n handlerRef: string | ((event: any) => any),\n flags?: { catch?: boolean },\n) {\n const handler = typeof handlerRef === 'function'\n ? handlerRef\n : methods[handlerRef] ?? (instance as Record<string, any>)[handlerRef]\n if (typeof handler !== 'function') {\n return () => {}\n }\n return nameRuntimeEventHandler((nativeEvent: Event) => {\n if (flags?.catch) {\n nativeEvent.stopPropagation()\n }\n const target = nativeEvent.target as HTMLElement | null\n const currentTarget = nativeEvent.currentTarget as HTMLElement | null\n const dataset = currentTarget?.dataset ?? {}\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset: target?.dataset ?? dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent)\n }, eventName)\n}\n\nfunction createWxsModule(code: string, id: string, requireMap?: Record<string, any>) {\n const module = { exports: {} as Record<string, any> }\n const exports = module.exports\n const getRegExp = (pattern: string, flags?: string) => new RegExp(pattern, flags)\n const getDate = (value?: string | number | Date) => (value == null ? new Date() : new Date(value))\n const require = (request: string) => requireMap?.[request]\n try {\n // eslint-disable-next-line no-new-func -- run in isolated module scope\n const runner = new Function('module', 'exports', 'require', 'getRegExp', 'getDate', code)\n runner(module, exports, require, getRegExp, getDate)\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-wxs-runtime:${id}`,\n `[@weapp-vite/web] safe 模式下忽略 WXS 执行错误: ${id} ${reason}`,\n )\n return {}\n }\n throw new Error(`[@weapp-vite/web] WXS 执行失败: ${id} ${reason}`)\n }\n return module.exports\n}\n\nexport function createRenderContext(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n): RenderContext {\n const warnMissingTemplate = (name: string) => {\n emitRuntimeWarning(`[@weapp-vite/web] 未找到模板: ${name}`, {\n key: `template-missing:${name}`,\n context: 'runtime:template',\n })\n }\n\n return {\n instance,\n eval: (expression, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return evaluateExpression(expression, renderScope)\n },\n createScope: (parent, locals) => createChildScope(parent, locals),\n mergeScope: (parent, data) => {\n const baseScope = parent ?? createScope()\n if (!data || typeof data !== 'object') {\n return baseScope\n }\n return createChildScope(baseScope, data as Record<string, any>)\n },\n normalizeList,\n key: (rawKey, item, index, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return normalizeKey(rawKey, item, index, renderScope)\n },\n renderTemplate: (templates, name, scope, ctx) => {\n const resolvedName = typeof name === 'string' ? name : String(name)\n const template = templates?.[resolvedName]\n if (typeof template !== 'function') {\n warnMissingTemplate(resolvedName)\n return ''\n }\n return template(scope, ctx)\n },\n event: (eventName, handlerName, _scope, _wxs, flags) => {\n if (typeof handlerName === 'function') {\n return createEventHandler(instance, methods, eventName, handlerName, flags)\n }\n const resolvedHandler = String(handlerName ?? '')\n return createEventHandler(instance, methods, eventName, resolvedHandler, flags)\n },\n createWxsModule,\n }\n}\n\nexport { createChildScope, createScope, evaluateExpression }\n"],"mappings":";;;;;;AAmBA,MAAM,kCAAkB,IAAI,IAA2C;AACvE,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAE3B,SAAS,YAAY,SAAwC;CAC3D,OAAO,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,WAAW,CAAC,CAAC;AACzD;AAEA,SAAS,iBAAiB,QAAuB,QAA6C;CAC5F,OAAO,OAAO,OAAO,OAAO,OAAO,MAAM,GAAG,UAAU,CAAC,CAAC;AAC1D;AAEA,SAAS,mBAAmB,YAAoB,OAA2B;CACzE,IAAI,CAAC,YACH;CAEF,MAAM,UAAU,WAAW,KAAK;CAChC,IAAI,CAAC,SACH;CAEF,IAAI,YAAY,gBAAgB,IAAI,OAAO;CAC3C,IAAI,CAAC,WAAW;EACd,IAAI;GAEF,YAAY,IAAI,SAAS,SAAS,wBAAwB,QAAQ,KAAK;EACzE,SACO,OAAO;GACZ,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAEpE,IADa,wBACN,MAAM,QAAQ;IACnB,yBACE,yBAAyB,WACzB,wCAAwC,QAAQ,KAAK,QACvD;IACA,kBAAkB;GACpB,OAEE,MAAM,IAAI,YAAY,8BAA8B,QAAQ,KAAK,QAAQ;EAE7E;EACA,gBAAgB,IAAI,SAAS,SAAS;CACxC;CACA,IAAI;EACF,OAAO,YAAY,KAAK;CAC1B,SACO,OAAO;EACZ,MAAM,OAAO,wBAAwB;EACrC,IAAI,SAAS,UAAU;GACrB,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GACpE,MAAM,IAAI,MAAM,wCAAwC,QAAQ,KAAK,QAAQ;EAC/E;EACA,IAAI,SAAS,QAAQ;GACnB,MAAM,SAAS,iBAAiB,QAAQ,MAA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AAa,QAAQ,SAAS;GAC5B,MAAM,YAAY,UAAU,YAAY;GACxC,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC3B,OAAO;GAET,OAAO,iBAAiB,WAAW,IAA2B;EAChE;EACA;EACA,MAAM,QAAQ,MAAM,OAAO,OAAO,QAAQ;GACxC,MAAM,YAAY,SAAS,YAAY;GAEvC,OAAO,aAAa,QAAQ,MAAM,OADd,MAAM,iBAAiB,WAAW,GAAG,IAAI,SACT;EACtD;EACA,iBAAiB,WAAW,MAAM,OAAO,QAAQ;GAC/C,MAAM,eAAe,OAAO,SAAS,WAAW,OAAO,OAAO,IAAI;GAClE,MAAM,WAAW,YAAY;GAC7B,IAAI,OAAO,aAAa,YAAY;IAClC,oBAAoB,YAAY;IAChC,OAAO;GACT;GACA,OAAO,SAAS,OAAO,GAAG;EAC5B;EACA,QAAQ,WAAW,aAAa,QAAQ,MAAM,UAAU;GACtD,IAAI,OAAO,gBAAgB,YACzB,OAAO,mBAAmB,UAAU,SAAS,WAAW,aAAa,KAAK;GAG5E,OAAO,mBAAmB,UAAU,SAAS,WADrB,OAAO,eAAe,EACwB,GAAG,KAAK;EAChF;EACA;CACF;AACF"}
@@ -20,4 +20,5 @@ export declare function registerWebWevuComponentFactory<TArgs extends unknown[],
20
20
  */
21
21
  export declare function installWebModuleRegistration(meta: WevuRegisterMeta, target?: Record<string, any>): () => void;
22
22
  //#endregion
23
+ export {};
23
24
  //# sourceMappingURL=wevu.d.mts.map
@@ -1,3 +1,4 @@
1
+ import { setAppStyle } from "./appStyle.mjs";
1
2
  import { registerApp, registerComponent, registerPage } from "./polyfill/routeRuntime.mjs";
2
3
  import { createApp, createWevuComponent, takePendingRuntimeAppRegistration } from "wevu/internal-runtime";
3
4
 
@@ -26,6 +27,7 @@ function withRuntimeConstructor(name, constructor, run) {
26
27
  * 将 Wevu App 注册过程接入 Web 页面栈。
27
28
  */
28
29
  function registerWebWevuApp(options, meta) {
30
+ setAppStyle(meta.style ?? "");
29
31
  const pendingRegistration = takePendingRuntimeAppRegistration();
30
32
  withRuntimeConstructor("App", (definition) => registerApp(definition, meta), () => {
31
33
  if (pendingRegistration) {
@@ -1 +1 @@
1
- {"version":3,"file":"wevu.mjs","names":[],"sources":["../../src/runtime/wevu.ts"],"sourcesContent":["import type { RegisterMeta } from './polyfill/routeRuntime/options'\nimport { createApp, createWevuComponent, takePendingRuntimeAppRegistration } from 'wevu/internal-runtime'\nimport { registerApp, registerComponent, registerPage } from './polyfill/routeRuntime'\n\ninterface WevuRegisterMeta extends RegisterMeta {\n kind: 'app' | 'page' | 'component'\n}\n\ntype RuntimeConstructorName = 'App' | 'Page' | 'Component'\n\nfunction createRuntimeConstructor(meta: WevuRegisterMeta, name: RuntimeConstructorName) {\n return (definition: Record<string, any>) => {\n if (name === 'App') {\n registerApp(definition, meta)\n }\n else if (name === 'Page' || meta.kind === 'page') {\n registerPage(definition, meta)\n }\n else {\n registerComponent(definition, meta)\n }\n return definition\n }\n}\n\nfunction withRuntimeConstructor<T>(\n name: 'App' | 'Component',\n constructor: (options: Record<string, any>) => unknown,\n run: () => T,\n) {\n const target = globalThis as Record<string, any>\n const hadOwn = Object.prototype.hasOwnProperty.call(target, name)\n const previous = target[name]\n target[name] = constructor\n try {\n return run()\n }\n finally {\n if (hadOwn) {\n target[name] = previous\n }\n else {\n delete target[name]\n }\n }\n}\n\n/**\n * 将 Wevu App 注册过程接入 Web 页面栈。\n */\nexport function registerWebWevuApp(options: Record<string, any>, meta: WevuRegisterMeta): void {\n const pendingRegistration = takePendingRuntimeAppRegistration()\n withRuntimeConstructor('App', definition => registerApp(definition, meta), () => {\n if (pendingRegistration) {\n pendingRegistration.register()\n return pendingRegistration.app\n }\n return createApp(options)\n })\n}\n\n/**\n * 将 Wevu 页面或组件注册过程接入 Web 自定义元素。\n */\nexport function registerWebWevuComponent(options: Record<string, any>, meta: WevuRegisterMeta): void {\n // Web 依赖 prop 构造器解码 DOM 属性,不使用小程序宿主的 nullable transport 降级。\n withRuntimeConstructor('Component', (definition) => {\n return meta.kind === 'page'\n ? registerPage(definition, meta)\n : registerComponent(definition, meta)\n }, () => createWevuComponent({ ...options, allowNullPropInput: false }))\n}\n\n/**\n * 保留公开 Wevu 工厂行为,并使用当前模块元数据完成 Web 注册。\n */\nexport function registerWebWevuComponentFactory<TArgs extends unknown[], TResult>(\n factory: (...args: TArgs) => TResult,\n meta: WevuRegisterMeta,\n ...args: TArgs\n): TResult {\n return withRuntimeConstructor('Component', (definition) => {\n return meta.kind === 'page'\n ? registerPage(definition, meta)\n : registerComponent(definition, meta)\n }, () => factory(...args))\n}\n\n/**\n * 在原生模块同步求值期间安装带页面元数据的宿主注册函数。\n */\nexport function installWebModuleRegistration(\n meta: WevuRegisterMeta,\n target: Record<string, any> = globalThis,\n): () => void {\n const names: RuntimeConstructorName[] = meta.kind === 'app'\n ? ['App']\n : meta.kind === 'page'\n ? ['Page', 'Component']\n : ['Component']\n const previous = names.map(name => ({\n hadOwn: Object.prototype.hasOwnProperty.call(target, name),\n name,\n value: target[name],\n }))\n const installed = new Map<RuntimeConstructorName, (definition: Record<string, any>) => Record<string, any>>()\n\n for (const name of names) {\n const constructor = createRuntimeConstructor(meta, name)\n installed.set(name, constructor)\n target[name] = constructor\n }\n\n return () => {\n for (const entry of previous) {\n if (target[entry.name] !== installed.get(entry.name)) {\n continue\n }\n if (entry.hadOwn) {\n target[entry.name] = entry.value\n }\n else {\n delete target[entry.name]\n }\n }\n }\n}\n"],"mappings":";;;;AAUA,SAAS,yBAAyB,MAAwB,MAA8B;CACtF,QAAQ,eAAoC;EAC1C,IAAI,SAAS,OACX,YAAY,YAAY,IAAI;OAEzB,IAAI,SAAS,UAAU,KAAK,SAAS,QACxC,aAAa,YAAY,IAAI;OAG7B,kBAAkB,YAAY,IAAI;EAEpC,OAAO;CACT;AACF;AAEA,SAAS,uBACP,MACA,aACA,KACA;CACA,MAAM,SAAS;CACf,MAAM,SAAS,OAAO,UAAU,eAAe,KAAK,QAAQ,IAAI;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AK,MAAM,SAAS,UAAU;GAC5B,IAAI,OAAO,MAAM,UAAU,UAAU,IAAI,MAAM,IAAI,GACjD;GAEF,IAAI,MAAM,QACR,OAAO,MAAM,QAAQ,MAAM;QAG3B,OAAO,OAAO,MAAM;EAExB;CACF;AACF"}
1
+ {"version":3,"file":"wevu.mjs","names":[],"sources":["../../src/runtime/wevu.ts"],"sourcesContent":["import type { RegisterMeta } from './polyfill/routeRuntime/options'\nimport { createApp, createWevuComponent, takePendingRuntimeAppRegistration } from 'wevu/internal-runtime'\nimport { setAppStyle } from './appStyle'\nimport { registerApp, registerComponent, registerPage } from './polyfill/routeRuntime'\n\ninterface WevuRegisterMeta extends RegisterMeta {\n kind: 'app' | 'page' | 'component'\n}\n\ntype RuntimeConstructorName = 'App' | 'Page' | 'Component'\n\nfunction createRuntimeConstructor(meta: WevuRegisterMeta, name: RuntimeConstructorName) {\n return (definition: Record<string, any>) => {\n if (name === 'App') {\n registerApp(definition, meta)\n }\n else if (name === 'Page' || meta.kind === 'page') {\n registerPage(definition, meta)\n }\n else {\n registerComponent(definition, meta)\n }\n return definition\n }\n}\n\nfunction withRuntimeConstructor<T>(\n name: 'App' | 'Component',\n constructor: (options: Record<string, any>) => unknown,\n run: () => T,\n) {\n const target = globalThis as Record<string, any>\n const hadOwn = Object.prototype.hasOwnProperty.call(target, name)\n const previous = target[name]\n target[name] = constructor\n try {\n return run()\n }\n finally {\n if (hadOwn) {\n target[name] = previous\n }\n else {\n delete target[name]\n }\n }\n}\n\n/**\n * 将 Wevu App 注册过程接入 Web 页面栈。\n */\nexport function registerWebWevuApp(options: Record<string, any>, meta: WevuRegisterMeta): void {\n // App 生命周期只注册一次,但每次模块求值都应发布最新样式。\n setAppStyle(meta.style ?? '')\n const pendingRegistration = takePendingRuntimeAppRegistration()\n withRuntimeConstructor('App', definition => registerApp(definition, meta), () => {\n if (pendingRegistration) {\n pendingRegistration.register()\n return pendingRegistration.app\n }\n return createApp(options)\n })\n}\n\n/**\n * 将 Wevu 页面或组件注册过程接入 Web 自定义元素。\n */\nexport function registerWebWevuComponent(options: Record<string, any>, meta: WevuRegisterMeta): void {\n // Web 依赖 prop 构造器解码 DOM 属性,不使用小程序宿主的 nullable transport 降级。\n withRuntimeConstructor('Component', (definition) => {\n return meta.kind === 'page'\n ? registerPage(definition, meta)\n : registerComponent(definition, meta)\n }, () => createWevuComponent({ ...options, allowNullPropInput: false }))\n}\n\n/**\n * 保留公开 Wevu 工厂行为,并使用当前模块元数据完成 Web 注册。\n */\nexport function registerWebWevuComponentFactory<TArgs extends unknown[], TResult>(\n factory: (...args: TArgs) => TResult,\n meta: WevuRegisterMeta,\n ...args: TArgs\n): TResult {\n return withRuntimeConstructor('Component', (definition) => {\n return meta.kind === 'page'\n ? registerPage(definition, meta)\n : registerComponent(definition, meta)\n }, () => factory(...args))\n}\n\n/**\n * 在原生模块同步求值期间安装带页面元数据的宿主注册函数。\n */\nexport function installWebModuleRegistration(\n meta: WevuRegisterMeta,\n target: Record<string, any> = globalThis,\n): () => void {\n const names: RuntimeConstructorName[] = meta.kind === 'app'\n ? ['App']\n : meta.kind === 'page'\n ? ['Page', 'Component']\n : ['Component']\n const previous = names.map(name => ({\n hadOwn: Object.prototype.hasOwnProperty.call(target, name),\n name,\n value: target[name],\n }))\n const installed = new Map<RuntimeConstructorName, (definition: Record<string, any>) => Record<string, any>>()\n\n for (const name of names) {\n const constructor = createRuntimeConstructor(meta, name)\n installed.set(name, constructor)\n target[name] = constructor\n }\n\n return () => {\n for (const entry of previous) {\n if (target[entry.name] !== installed.get(entry.name)) {\n continue\n }\n if (entry.hadOwn) {\n target[entry.name] = entry.value\n }\n else {\n delete target[entry.name]\n }\n }\n }\n}\n"],"mappings":";;;;;AAWA,SAAS,yBAAyB,MAAwB,MAA8B;CACtF,QAAQ,eAAoC;EAC1C,IAAI,SAAS,OACX,YAAY,YAAY,IAAI;OAEzB,IAAI,SAAS,UAAU,KAAK,SAAS,QACxC,aAAa,YAAY,IAAI;OAG7B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;CACF,MAAM,4BAAY,IAAI,IAAsF;CAE5G,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,cAAc,yBAAyB,MAAM,IAAI;EACvD,UAAU,IAAI,MAAM,WAAW;EAC/B,OAAO,QAAQ;CACjB;CAEA,aAAa;EACX,KAAK,MAAM,SAAS,UAAU;GAC5B,IAAI,OAAO,MAAM,UAAU,UAAU,IAAI,MAAM,IAAI,GACjD;GAEF,IAAI,MAAM,QACR,OAAO,MAAM,QAAQ,MAAM;QAG3B,OAAO,OAAO,MAAM;EAExB;CACF;AACF"}
@@ -16,7 +16,11 @@ const TEMPLATE_IMPORT_TAG_NAMES = Array.from(/* @__PURE__ */ new Set(["import",
16
16
  const TEMPLATE_INCLUDE_TAG_NAMES = Array.from(/* @__PURE__ */ new Set(["include", ...CONTROL_ATTR_PREFIXES.map((prefix) => `${prefix}-include`)]));
17
17
  const CONTROL_ATTRS = /* @__PURE__ */ new Set([...CONTROL_ATTR_PREFIXES.flatMap((prefix) => CONTROL_ATTR_SUFFIXES.map((suffix) => `${prefix}:${suffix}`))]);
18
18
  const EVENT_PREFIX_RE = /^(?:bind|catch|mut-bind|capture-bind|capture-catch)([\w-]+)$/;
19
- const EVENT_KIND_ALIAS = { tap: "click" };
19
+ const EVENT_KIND_ALIAS = {
20
+ tap: "click",
21
+ longtap: "contextmenu",
22
+ longpress: "contextmenu"
23
+ };
20
24
  const SELF_CLOSING_TAGS = /* @__PURE__ */ new Set([
21
25
  "area",
22
26
  "base",
@@ -1 +1 @@
1
- {"version":3,"file":"wxml.mjs","names":[],"sources":["../../src/shared/wxml.ts"],"sourcesContent":["import { getSupportedMiniProgramDirectivePrefixes } from '@weapp-core/shared/platforms/runtime'\nimport { resolveNativeComponentWebTag } from './nativeComponents'\n\nconst CONTROL_ATTR_SUFFIXES = [\n 'if',\n 'elif',\n 'else',\n 'for',\n 'for-item',\n 'for-index',\n 'key',\n] as const\n\nexport type ControlAttrSuffix = typeof CONTROL_ATTR_SUFFIXES[number]\n\nexport const CONTROL_ATTR_PREFIXES = [...getSupportedMiniProgramDirectivePrefixes()]\n\nexport const TEMPLATE_IMPORT_TAG_NAMES = Array.from(new Set([\n 'import',\n ...CONTROL_ATTR_PREFIXES.map(prefix => `${prefix}-import`),\n]))\n\nexport const TEMPLATE_INCLUDE_TAG_NAMES = Array.from(new Set([\n 'include',\n ...CONTROL_ATTR_PREFIXES.map(prefix => `${prefix}-include`),\n]))\n\nexport const CONTROL_ATTRS = new Set([\n ...CONTROL_ATTR_PREFIXES.flatMap(prefix => CONTROL_ATTR_SUFFIXES.map(suffix => `${prefix}:${suffix}`)),\n])\n\nexport const EVENT_PREFIX_RE = /^(?:bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nexport const EVENT_KIND_ALIAS: Record<string, string> = {\n tap: 'click',\n}\n\nexport const SELF_CLOSING_TAGS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'image',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nexport function resolveControlAttributeName(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): string | undefined {\n for (const prefix of CONTROL_ATTR_PREFIXES) {\n const name = `${prefix}:${suffix}`\n if (name in attribs) {\n return name\n }\n }\n return undefined\n}\n\nexport function resolveControlAttributeValue(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): string | undefined {\n const name = resolveControlAttributeName(attribs, suffix)\n return name ? attribs[name] : undefined\n}\n\nexport function hasControlAttribute(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): boolean {\n return resolveControlAttributeName(attribs, suffix) !== undefined\n}\n\nexport function normalizeTagName(name: string) {\n const nativeComponentTag = resolveNativeComponentWebTag(name)\n if (nativeComponentTag) {\n return nativeComponentTag\n }\n switch (name) {\n case 'block':\n return '#fragment'\n case 'slot':\n return 'slot'\n default:\n return name || 'div'\n }\n}\n\nexport function normalizeAttributeName(name: string) {\n if (name === 'class' || name === 'style' || name.startsWith('data-')) {\n return name\n }\n return name.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)\n}\n"],"mappings":";;;;AAGA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAa,wBAAwB,CAAC,GAAG,yCAAyC,CAAC;AAEnF,MAAa,4BAA4B,MAAM,qBAAK,IAAI,IAAI,CAC1D,UACA,GAAG,sBAAsB,KAAI,WAAU,GAAG,OAAO,QAAQ,CAC3D,CAAC,CAAC;AAEF,MAAa,6BAA6B,MAAM,qBAAK,IAAI,IAAI,CAC3D,WACA,GAAG,sBAAsB,KAAI,WAAU,GAAG,OAAO,SAAS,CAC5D,CAAC,CAAC;AAEF,MAAa,gCAAgB,IAAI,IAAI,CACnC,GAAG,sBAAsB,SAAQ,WAAU,sBAAsB,KAAI,WAAU,GAAG,OAAO,GAAG,QAAQ,CAAC,CACvG,CAAC;AAED,MAAa,kBAAkB;AAC/B,MAAa,mBAA2C,EACtD,KAAK,QACP;AAEA,MAAa,oCAAoB,IAAI,IAAI;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,4BACd,SACA,QACoB;CACpB,KAAK,MAAM,UAAU,uBAAuB;EAC1C,MAAM,OAAO,GAAG,OAAO,GAAG;EAC1B,IAAI,QAAQ,SACV,OAAO;CAEX;AAEF;AAEA,SAAgB,6BACd,SACA,QACoB;CACpB,MAAM,OAAO,4BAA4B,SAAS,MAAM;CACxD,OAAO,OAAO,QAAQ,QAAQ;AAChC;AAEA,SAAgB,oBACd,SACA,QACS;CACT,OAAO,4BAA4B,SAAS,MAAM,MAAM;AAC1D;AAEA,SAAgB,iBAAiB,MAAc;CAC7C,MAAM,qBAAqB,6BAA6B,IAAI;CAC5D,IAAI,oBACF,OAAO;CAET,QAAQ,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO,QAAQ;CACnB;AACF;AAEA,SAAgB,uBAAuB,MAAc;CACnD,IAAI,SAAS,WAAW,SAAS,WAAW,KAAK,WAAW,OAAO,GACjE,OAAO;CAET,OAAO,KAAK,QAAQ,WAAU,UAAS,IAAI,MAAM,YAAY,GAAG;AAClE"}
1
+ {"version":3,"file":"wxml.mjs","names":[],"sources":["../../src/shared/wxml.ts"],"sourcesContent":["import { getSupportedMiniProgramDirectivePrefixes } from '@weapp-core/shared/platforms/runtime'\nimport { resolveNativeComponentWebTag } from './nativeComponents'\n\nconst CONTROL_ATTR_SUFFIXES = [\n 'if',\n 'elif',\n 'else',\n 'for',\n 'for-item',\n 'for-index',\n 'key',\n] as const\n\nexport type ControlAttrSuffix = typeof CONTROL_ATTR_SUFFIXES[number]\n\nexport const CONTROL_ATTR_PREFIXES = [...getSupportedMiniProgramDirectivePrefixes()]\n\nexport const TEMPLATE_IMPORT_TAG_NAMES = Array.from(new Set([\n 'import',\n ...CONTROL_ATTR_PREFIXES.map(prefix => `${prefix}-import`),\n]))\n\nexport const TEMPLATE_INCLUDE_TAG_NAMES = Array.from(new Set([\n 'include',\n ...CONTROL_ATTR_PREFIXES.map(prefix => `${prefix}-include`),\n]))\n\nexport const CONTROL_ATTRS = new Set([\n ...CONTROL_ATTR_PREFIXES.flatMap(prefix => CONTROL_ATTR_SUFFIXES.map(suffix => `${prefix}:${suffix}`)),\n])\n\nexport const EVENT_PREFIX_RE = /^(?:bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nexport const EVENT_KIND_ALIAS: Record<string, string> = {\n tap: 'click',\n longtap: 'contextmenu',\n longpress: 'contextmenu',\n}\n\nexport const SELF_CLOSING_TAGS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'image',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nexport function resolveControlAttributeName(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): string | undefined {\n for (const prefix of CONTROL_ATTR_PREFIXES) {\n const name = `${prefix}:${suffix}`\n if (name in attribs) {\n return name\n }\n }\n return undefined\n}\n\nexport function resolveControlAttributeValue(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): string | undefined {\n const name = resolveControlAttributeName(attribs, suffix)\n return name ? attribs[name] : undefined\n}\n\nexport function hasControlAttribute(\n attribs: Record<string, string>,\n suffix: ControlAttrSuffix,\n): boolean {\n return resolveControlAttributeName(attribs, suffix) !== undefined\n}\n\nexport function normalizeTagName(name: string) {\n const nativeComponentTag = resolveNativeComponentWebTag(name)\n if (nativeComponentTag) {\n return nativeComponentTag\n }\n switch (name) {\n case 'block':\n return '#fragment'\n case 'slot':\n return 'slot'\n default:\n return name || 'div'\n }\n}\n\nexport function normalizeAttributeName(name: string) {\n if (name === 'class' || name === 'style' || name.startsWith('data-')) {\n return name\n }\n return name.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)\n}\n"],"mappings":";;;;AAGA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAa,wBAAwB,CAAC,GAAG,yCAAyC,CAAC;AAEnF,MAAa,4BAA4B,MAAM,qBAAK,IAAI,IAAI,CAC1D,UACA,GAAG,sBAAsB,KAAI,WAAU,GAAG,OAAO,QAAQ,CAC3D,CAAC,CAAC;AAEF,MAAa,6BAA6B,MAAM,qBAAK,IAAI,IAAI,CAC3D,WACA,GAAG,sBAAsB,KAAI,WAAU,GAAG,OAAO,SAAS,CAC5D,CAAC,CAAC;AAEF,MAAa,gCAAgB,IAAI,IAAI,CACnC,GAAG,sBAAsB,SAAQ,WAAU,sBAAsB,KAAI,WAAU,GAAG,OAAO,GAAG,QAAQ,CAAC,CACvG,CAAC;AAED,MAAa,kBAAkB;AAC/B,MAAa,mBAA2C;CACtD,KAAK;CACL,SAAS;CACT,WAAW;AACb;AAEA,MAAa,oCAAoB,IAAI,IAAI;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,4BACd,SACA,QACoB;CACpB,KAAK,MAAM,UAAU,uBAAuB;EAC1C,MAAM,OAAO,GAAG,OAAO,GAAG;EAC1B,IAAI,QAAQ,SACV,OAAO;CAEX;AAEF;AAEA,SAAgB,6BACd,SACA,QACoB;CACpB,MAAM,OAAO,4BAA4B,SAAS,MAAM;CACxD,OAAO,OAAO,QAAQ,QAAQ;AAChC;AAEA,SAAgB,oBACd,SACA,QACS;CACT,OAAO,4BAA4B,SAAS,MAAM,MAAM;AAC1D;AAEA,SAAgB,iBAAiB,MAAc;CAC7C,MAAM,qBAAqB,6BAA6B,IAAI;CAC5D,IAAI,oBACF,OAAO;CAET,QAAQ,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO,QAAQ;CACnB;AACF;AAEA,SAAgB,uBAAuB,MAAc;CACnD,IAAI,SAAS,WAAW,SAAS,WAAW,KAAK,WAAW,OAAO,GACjE,OAAO;CAET,OAAO,KAAK,QAAQ,WAAU,UAAS,IAAI,MAAM,YAAY,GAAG;AAClE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-vite/web",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "2.0.1",
5
5
  "description": "Experimental web runtime for weapp-vite templates",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "dist"
53
53
  ],
54
54
  "engines": {
55
- "node": "^20.19.0 || >=22.12.0"
55
+ "node": "^22.18.0 || ^24.11.0 || >=26.0.0"
56
56
  },
57
57
  "tsd": {
58
58
  "compilerOptions": {
@@ -62,25 +62,26 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@babel/parser": "^8.0.6",
66
- "@babel/traverse": "^8.0.6",
65
+ "@babel/parser": "^8.0.7",
66
+ "@babel/traverse": "^8.0.7",
67
67
  "@babel/types": "^8.0.6",
68
- "@weapp-core/constants": "0.3.0",
69
- "@weapp-core/shared": "3.2.7",
68
+ "@weapp-core/constants": "0.4.0",
69
+ "@weapp-core/shared": "3.3.0",
70
70
  "domhandler": "^6.0.1",
71
71
  "esbuild": "^0.28.2",
72
72
  "htmlparser2": "^12.0.0",
73
73
  "lit": "^3.3.3",
74
- "magic-string": "^1.4.2",
74
+ "magic-string": "^1.4.3",
75
75
  "pathe": "^2.0.3",
76
- "postcss": "^8.5.28",
76
+ "postcss": "^8.5.30",
77
77
  "postcss-selector-parser": "^7.1.6",
78
- "rolldown": "1.2.11",
79
- "rolldown-require": "2.0.34",
80
- "wevu": "7.4.0"
78
+ "rolldown": "1.2.14",
79
+ "rolldown-require": "2.0.36",
80
+ "vite": "8.3.4",
81
+ "wevu": "7.6.0"
81
82
  },
82
83
  "devDependencies": {
83
- "happy-dom": "^20.14.5"
84
+ "happy-dom": "^21.0.3"
84
85
  },
85
86
  "publishConfig": {
86
87
  "access": "public",
@@ -93,7 +94,8 @@
93
94
  "test": "vitest run",
94
95
  "test:coverage": "cross-env WEAPP_VITE_WEB_COVERAGE_STRICT=1 vitest run --coverage",
95
96
  "test:dev": "vitest",
96
- "test:types": "pnpm build && tsd",
97
+ "test:types": "pnpm build && pnpm run test:types:check",
98
+ "test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
97
99
  "typecheck": "tsc --noEmit"
98
100
  }
99
101
  }