@weapp-vite/web 1.3.15 → 1.3.16

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 (242) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +18 -0
  2. package/dist/compiler/wxml/attributes.mjs +93 -0
  3. package/dist/compiler/wxml/attributes.mjs.map +1 -0
  4. package/dist/compiler/wxml/compile.mjs +158 -0
  5. package/dist/compiler/wxml/compile.mjs.map +1 -0
  6. package/dist/compiler/wxml/dependency.mjs +31 -0
  7. package/dist/compiler/wxml/dependency.mjs.map +1 -0
  8. package/dist/compiler/wxml/interpolation.mjs +142 -0
  9. package/dist/compiler/wxml/interpolation.mjs.map +1 -0
  10. package/dist/compiler/wxml/navigation.mjs +85 -0
  11. package/dist/compiler/wxml/navigation.mjs.map +1 -0
  12. package/dist/compiler/wxml/parser.mjs +41 -0
  13. package/dist/compiler/wxml/parser.mjs.map +1 -0
  14. package/dist/compiler/wxml/renderer.mjs +114 -0
  15. package/dist/compiler/wxml/renderer.mjs.map +1 -0
  16. package/dist/compiler/wxml/specialNodes.mjs +84 -0
  17. package/dist/compiler/wxml/specialNodes.mjs.map +1 -0
  18. package/dist/compiler/wxs.mjs +83 -0
  19. package/dist/compiler/wxs.mjs.map +1 -0
  20. package/dist/css/wxss.d.mts +25 -0
  21. package/dist/css/wxss.mjs +17 -0
  22. package/dist/css/wxss.mjs.map +1 -0
  23. package/dist/index.d.mts +18 -2
  24. package/dist/index.mjs +18 -3
  25. package/dist/plugin/constants.mjs +43 -0
  26. package/dist/plugin/constants.mjs.map +1 -0
  27. package/dist/plugin/entry.mjs +29 -0
  28. package/dist/plugin/entry.mjs.map +1 -0
  29. package/dist/plugin/files.mjs +58 -0
  30. package/dist/plugin/files.mjs.map +1 -0
  31. package/dist/plugin/index.d.mts +33 -0
  32. package/dist/plugin/index.mjs +188 -0
  33. package/dist/plugin/index.mjs.map +1 -0
  34. package/dist/plugin/navigation.mjs +20 -0
  35. package/dist/plugin/navigation.mjs.map +1 -0
  36. package/dist/plugin/path.mjs +85 -0
  37. package/dist/plugin/path.mjs.map +1 -0
  38. package/dist/plugin/register.mjs +83 -0
  39. package/dist/plugin/register.mjs.map +1 -0
  40. package/dist/plugin/scan.mjs +195 -0
  41. package/dist/plugin/scan.mjs.map +1 -0
  42. package/dist/plugin/scanConfig.mjs +45 -0
  43. package/dist/plugin/scanConfig.mjs.map +1 -0
  44. package/dist/plugin/state.mjs +22 -0
  45. package/dist/plugin/state.mjs.map +1 -0
  46. package/dist/plugin/types.d.mts +46 -0
  47. package/dist/plugin.d.mts +3 -2
  48. package/dist/plugin.mjs +3 -2
  49. package/dist/runtime/button/helpers.mjs +92 -0
  50. package/dist/runtime/button/helpers.mjs.map +1 -0
  51. package/dist/runtime/button/index.d.mts +9 -0
  52. package/dist/runtime/button/index.mjs +198 -0
  53. package/dist/runtime/button/index.mjs.map +1 -0
  54. package/dist/runtime/button/style.mjs +168 -0
  55. package/dist/runtime/button/style.mjs.map +1 -0
  56. package/dist/runtime/component/behavior.mjs +98 -0
  57. package/dist/runtime/component/behavior.mjs.map +1 -0
  58. package/dist/runtime/component/constants.mjs +8 -0
  59. package/dist/runtime/component/constants.mjs.map +1 -0
  60. package/dist/runtime/component/dom.mjs +26 -0
  61. package/dist/runtime/component/dom.mjs.map +1 -0
  62. package/dist/runtime/component/element.mjs +208 -0
  63. package/dist/runtime/component/element.mjs.map +1 -0
  64. package/dist/runtime/component/events.mjs +48 -0
  65. package/dist/runtime/component/events.mjs.map +1 -0
  66. package/dist/runtime/component/index.d.mts +7 -0
  67. package/dist/runtime/component/index.mjs +44 -0
  68. package/dist/runtime/component/index.mjs.map +1 -0
  69. package/dist/runtime/component/state.mjs +63 -0
  70. package/dist/runtime/component/state.mjs.map +1 -0
  71. package/dist/runtime/component/types.d.mts +49 -0
  72. package/dist/runtime/component/utils.mjs +39 -0
  73. package/dist/runtime/component/utils.mjs.map +1 -0
  74. package/dist/runtime/execution.d.mts +7 -0
  75. package/dist/runtime/execution.mjs +37 -0
  76. package/dist/runtime/execution.mjs.map +1 -0
  77. package/dist/runtime/index.d.mts +16 -2
  78. package/dist/runtime/index.mjs +16 -2
  79. package/dist/runtime/legacyTemplate/dom.mjs +131 -0
  80. package/dist/runtime/legacyTemplate/dom.mjs.map +1 -0
  81. package/dist/runtime/legacyTemplate/expression.mjs +113 -0
  82. package/dist/runtime/legacyTemplate/expression.mjs.map +1 -0
  83. package/dist/runtime/legacyTemplate/index.d.mts +9 -0
  84. package/dist/runtime/legacyTemplate/index.mjs +131 -0
  85. package/dist/runtime/legacyTemplate/index.mjs.map +1 -0
  86. package/dist/runtime/legacyTemplate/types.d.mts +6 -0
  87. package/dist/runtime/navigationBar/index.d.mts +10 -0
  88. package/dist/runtime/navigationBar/index.mjs +162 -0
  89. package/dist/runtime/navigationBar/index.mjs.map +1 -0
  90. package/dist/runtime/navigationBar/style.mjs +108 -0
  91. package/dist/runtime/navigationBar/style.mjs.map +1 -0
  92. package/dist/runtime/polyfill/ad.mjs +150 -0
  93. package/dist/runtime/polyfill/ad.mjs.map +1 -0
  94. package/dist/runtime/polyfill/appState.mjs +31 -0
  95. package/dist/runtime/polyfill/appState.mjs.map +1 -0
  96. package/dist/runtime/polyfill/async.mjs +31 -0
  97. package/dist/runtime/polyfill/async.mjs.map +1 -0
  98. package/dist/runtime/polyfill/auth.mjs +120 -0
  99. package/dist/runtime/polyfill/auth.mjs.map +1 -0
  100. package/dist/runtime/polyfill/authApi.mjs +101 -0
  101. package/dist/runtime/polyfill/authApi.mjs.map +1 -0
  102. package/dist/runtime/polyfill/background.mjs +31 -0
  103. package/dist/runtime/polyfill/background.mjs.map +1 -0
  104. package/dist/runtime/polyfill/canvasContext.mjs +115 -0
  105. package/dist/runtime/polyfill/canvasContext.mjs.map +1 -0
  106. package/dist/runtime/polyfill/capability.mjs +17 -0
  107. package/dist/runtime/polyfill/capability.mjs.map +1 -0
  108. package/dist/runtime/polyfill/cloud.mjs +39 -0
  109. package/dist/runtime/polyfill/cloud.mjs.map +1 -0
  110. package/dist/runtime/polyfill/device.mjs +44 -0
  111. package/dist/runtime/polyfill/device.mjs.map +1 -0
  112. package/dist/runtime/polyfill/deviceApi.mjs +31 -0
  113. package/dist/runtime/polyfill/deviceApi.mjs.map +1 -0
  114. package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +102 -0
  115. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +144 -0
  116. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -0
  117. package/dist/runtime/polyfill/filePicker.mjs +158 -0
  118. package/dist/runtime/polyfill/filePicker.mjs.map +1 -0
  119. package/dist/runtime/polyfill/fileSystemManager.mjs +45 -0
  120. package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -0
  121. package/dist/runtime/polyfill/files.mjs +118 -0
  122. package/dist/runtime/polyfill/files.mjs.map +1 -0
  123. package/dist/runtime/polyfill/index.d.mts +40 -0
  124. package/dist/runtime/polyfill/index.mjs +99 -0
  125. package/dist/runtime/polyfill/index.mjs.map +1 -0
  126. package/dist/runtime/polyfill/interaction.mjs +38 -0
  127. package/dist/runtime/polyfill/interaction.mjs.map +1 -0
  128. package/dist/runtime/polyfill/interactionApi.mjs +54 -0
  129. package/dist/runtime/polyfill/interactionApi.mjs.map +1 -0
  130. package/dist/runtime/polyfill/location.mjs +106 -0
  131. package/dist/runtime/polyfill/location.mjs.map +1 -0
  132. package/dist/runtime/polyfill/locationApi.mjs +120 -0
  133. package/dist/runtime/polyfill/locationApi.mjs.map +1 -0
  134. package/dist/runtime/polyfill/mediaActions.mjs +52 -0
  135. package/dist/runtime/polyfill/mediaActions.mjs.map +1 -0
  136. package/dist/runtime/polyfill/mediaApi/file.mjs +63 -0
  137. package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -0
  138. package/dist/runtime/polyfill/mediaApi/info.mjs +59 -0
  139. package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -0
  140. package/dist/runtime/polyfill/mediaApi/picker.mjs +82 -0
  141. package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -0
  142. package/dist/runtime/polyfill/mediaApi/preview.mjs +39 -0
  143. package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -0
  144. package/dist/runtime/polyfill/mediaApi/process.mjs +46 -0
  145. package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -0
  146. package/dist/runtime/polyfill/mediaInfo.mjs +136 -0
  147. package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -0
  148. package/dist/runtime/polyfill/mediaPicker.mjs +213 -0
  149. package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -0
  150. package/dist/runtime/polyfill/mediaProcess.mjs +65 -0
  151. package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -0
  152. package/dist/runtime/polyfill/menuApi.mjs +70 -0
  153. package/dist/runtime/polyfill/menuApi.mjs.map +1 -0
  154. package/dist/runtime/polyfill/navigationBarRuntime.mjs +65 -0
  155. package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -0
  156. package/dist/runtime/polyfill/network/request.mjs +162 -0
  157. package/dist/runtime/polyfill/network/request.mjs.map +1 -0
  158. package/dist/runtime/polyfill/network/requestBridge.mjs +49 -0
  159. package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -0
  160. package/dist/runtime/polyfill/network/status.mjs +55 -0
  161. package/dist/runtime/polyfill/network/status.mjs.map +1 -0
  162. package/dist/runtime/polyfill/platformApi.mjs +33 -0
  163. package/dist/runtime/polyfill/platformApi.mjs.map +1 -0
  164. package/dist/runtime/polyfill/platformRuntime.mjs +120 -0
  165. package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -0
  166. package/dist/runtime/polyfill/routeRuntime/dom.mjs +36 -0
  167. package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -0
  168. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +83 -0
  169. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -0
  170. package/dist/runtime/polyfill/routeRuntime/options.d.mts +33 -0
  171. package/dist/runtime/polyfill/routeRuntime/options.mjs +76 -0
  172. package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -0
  173. package/dist/runtime/polyfill/routeRuntime/url.mjs +35 -0
  174. package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -0
  175. package/dist/runtime/polyfill/routeRuntime.d.mts +43 -0
  176. package/dist/runtime/polyfill/routeRuntime.mjs +202 -0
  177. package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -0
  178. package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +26 -0
  179. package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -0
  180. package/dist/runtime/polyfill/runtimeDataApi.d.mts +79 -0
  181. package/dist/runtime/polyfill/runtimeDataApi.mjs +134 -0
  182. package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -0
  183. package/dist/runtime/polyfill/runtimeInfra.mjs +40 -0
  184. package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -0
  185. package/dist/runtime/polyfill/runtimeOps.mjs +62 -0
  186. package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -0
  187. package/dist/runtime/polyfill/selectorQuery.mjs +204 -0
  188. package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -0
  189. package/dist/runtime/polyfill/storage.mjs +103 -0
  190. package/dist/runtime/polyfill/storage.mjs.map +1 -0
  191. package/dist/runtime/polyfill/storageAsync.mjs +62 -0
  192. package/dist/runtime/polyfill/storageAsync.mjs.map +1 -0
  193. package/dist/runtime/polyfill/subscribe.mjs +30 -0
  194. package/dist/runtime/polyfill/subscribe.mjs.map +1 -0
  195. package/dist/runtime/polyfill/system.mjs +111 -0
  196. package/dist/runtime/polyfill/system.mjs.map +1 -0
  197. package/dist/runtime/polyfill/systemApi.mjs +65 -0
  198. package/dist/runtime/polyfill/systemApi.mjs.map +1 -0
  199. package/dist/runtime/polyfill/types/base.d.mts +12 -0
  200. package/dist/runtime/polyfill/types/common.d.mts +126 -0
  201. package/dist/runtime/polyfill/types/locationRuntime.d.mts +151 -0
  202. package/dist/runtime/polyfill/types/mediaAuth.d.mts +152 -0
  203. package/dist/runtime/polyfill/types/platformRuntime.d.mts +141 -0
  204. package/dist/runtime/polyfill/types/systemAuth.d.mts +122 -0
  205. package/dist/runtime/polyfill/ui.mjs +135 -0
  206. package/dist/runtime/polyfill/ui.mjs.map +1 -0
  207. package/dist/runtime/polyfill/uiFeedback.mjs +35 -0
  208. package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -0
  209. package/dist/runtime/polyfill/uiMediaApi.d.mts +172 -0
  210. package/dist/runtime/polyfill/uiMediaApi.mjs +162 -0
  211. package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -0
  212. package/dist/runtime/polyfill/videoContext.mjs +56 -0
  213. package/dist/runtime/polyfill/videoContext.mjs.map +1 -0
  214. package/dist/runtime/polyfill/vkSession.mjs +58 -0
  215. package/dist/runtime/polyfill/vkSession.mjs.map +1 -0
  216. package/dist/runtime/polyfill/windowResize.mjs +39 -0
  217. package/dist/runtime/polyfill/windowResize.mjs.map +1 -0
  218. package/dist/runtime/polyfill/worker.mjs +77 -0
  219. package/dist/runtime/polyfill/worker.mjs.map +1 -0
  220. package/dist/runtime/polyfill.d.mts +5 -0
  221. package/dist/runtime/renderContext.d.mts +21 -0
  222. package/dist/runtime/renderContext.mjs +147 -0
  223. package/dist/runtime/renderContext.mjs.map +1 -0
  224. package/dist/runtime/rpx.d.mts +9 -0
  225. package/dist/runtime/rpx.mjs +27 -0
  226. package/dist/runtime/rpx.mjs.map +1 -0
  227. package/dist/runtime/style.d.mts +6 -0
  228. package/dist/runtime/style.mjs +37 -0
  229. package/dist/runtime/style.mjs.map +1 -0
  230. package/dist/runtime/template.d.mts +10 -0
  231. package/dist/runtime/warning.d.mts +10 -0
  232. package/dist/runtime/warning.mjs +43 -0
  233. package/dist/runtime/warning.mjs.map +1 -0
  234. package/dist/{slugify-B4l45KNs.mjs → shared/slugify.mjs} +3 -1
  235. package/dist/shared/slugify.mjs.map +1 -0
  236. package/dist/shared/wxml.mjs +64 -0
  237. package/dist/shared/wxml.mjs.map +1 -0
  238. package/package.json +1 -1
  239. package/dist/index-w9xxIH-l.d.mts +0 -1229
  240. package/dist/plugin-BARxSPO8.mjs +0 -1567
  241. package/dist/plugin-DP2iPVmw.d.mts +0 -96
  242. package/dist/runtime-D6j2_x_N.mjs +0 -6251
@@ -0,0 +1,168 @@
1
+ import { injectStyle } from "../style.mjs";
2
+
3
+ //#region src/runtime/button/style.ts
4
+ const BUTTON_STYLE_ID = "weapp-web-button-style";
5
+ const styleTargets = /* @__PURE__ */ new WeakSet();
6
+ let sharedSheet;
7
+ const BUTTON_STYLE = `
8
+ weapp-button {
9
+ display: block;
10
+ width: 100%;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ weapp-button.weapp-btn--mini {
15
+ display: inline-block;
16
+ width: auto;
17
+ }
18
+
19
+ weapp-button .weapp-btn {
20
+ appearance: none;
21
+ -webkit-appearance: none;
22
+ box-sizing: border-box;
23
+ width: 100%;
24
+ border-radius: 5px;
25
+ border: 1px solid #d9d9d9;
26
+ padding: 0 16px;
27
+ height: 44px;
28
+ line-height: 44px;
29
+ font-size: 17px;
30
+ font-weight: 400;
31
+ background-color: #f8f8f8;
32
+ color: #000000;
33
+ cursor: pointer;
34
+ outline: none;
35
+ user-select: none;
36
+ -webkit-tap-highlight-color: transparent;
37
+ }
38
+
39
+ weapp-button.weapp-btn--primary .weapp-btn {
40
+ background-color: #07c160;
41
+ border-color: #07c160;
42
+ color: #ffffff;
43
+ }
44
+
45
+ weapp-button.weapp-btn--warn .weapp-btn {
46
+ background-color: #e64340;
47
+ border-color: #e64340;
48
+ color: #ffffff;
49
+ }
50
+
51
+ weapp-button.weapp-btn--plain .weapp-btn {
52
+ background-color: transparent;
53
+ }
54
+
55
+ weapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {
56
+ border-color: #b2b2b2;
57
+ color: #353535;
58
+ }
59
+
60
+ weapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {
61
+ border-color: #07c160;
62
+ color: #07c160;
63
+ }
64
+
65
+ weapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {
66
+ border-color: #e64340;
67
+ color: #e64340;
68
+ }
69
+
70
+ weapp-button.weapp-btn--loading .weapp-btn,
71
+ weapp-button.weapp-btn--disabled .weapp-btn {
72
+ background-color: #f7f7f7;
73
+ border-color: #d9d9d9;
74
+ color: #9b9b9b;
75
+ cursor: not-allowed;
76
+ }
77
+
78
+ weapp-button.button-hover .weapp-btn {
79
+ background-color: #ededed;
80
+ border-color: #d2d2d2;
81
+ }
82
+
83
+ weapp-button.button-hover.weapp-btn--primary .weapp-btn {
84
+ background-color: #06ad56;
85
+ border-color: #06ad56;
86
+ }
87
+
88
+ weapp-button.button-hover.weapp-btn--warn .weapp-btn {
89
+ background-color: #d93c37;
90
+ border-color: #d93c37;
91
+ }
92
+
93
+ weapp-button.button-hover.weapp-btn--plain .weapp-btn {
94
+ background-color: rgba(0, 0, 0, 0.06);
95
+ }
96
+
97
+ weapp-button.weapp-btn--mini .weapp-btn {
98
+ height: 32px;
99
+ line-height: 32px;
100
+ font-size: 13px;
101
+ padding: 0 12px;
102
+ border-radius: 4px;
103
+ }
104
+
105
+ weapp-button .weapp-btn__content {
106
+ display: inline-flex;
107
+ align-items: center;
108
+ justify-content: center;
109
+ gap: 6px;
110
+ width: 100%;
111
+ }
112
+
113
+ weapp-button .weapp-btn__loading {
114
+ width: 14px;
115
+ height: 14px;
116
+ border-radius: 50%;
117
+ border: 2px solid currentColor;
118
+ border-top-color: transparent;
119
+ animation: weapp-btn-spin 0.8s linear infinite;
120
+ }
121
+
122
+ weapp-button .weapp-btn__loading[hidden] {
123
+ display: none;
124
+ }
125
+
126
+ @keyframes weapp-btn-spin {
127
+ from { transform: rotate(0deg); }
128
+ to { transform: rotate(360deg); }
129
+ }
130
+ `;
131
+ function resolveAdoptedStyleSheets(root) {
132
+ const doc = root.ownerDocument ?? document;
133
+ if (!doc || typeof doc.createElement !== "function") return;
134
+ if (!("adoptedStyleSheets" in doc)) return;
135
+ if (!sharedSheet && "replaceSync" in CSSStyleSheet.prototype) {
136
+ const sheet = new CSSStyleSheet();
137
+ sheet.replaceSync(BUTTON_STYLE);
138
+ sharedSheet = sheet;
139
+ }
140
+ return sharedSheet;
141
+ }
142
+ function ensureButtonStyle(root) {
143
+ if (typeof document === "undefined") return;
144
+ if (root && styleTargets.has(root)) return;
145
+ if (!root) {
146
+ const target = document.head;
147
+ if (!target || styleTargets.has(target)) return;
148
+ injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID);
149
+ styleTargets.add(target);
150
+ return;
151
+ }
152
+ const sheet = resolveAdoptedStyleSheets(root);
153
+ if (sheet) {
154
+ const existing = root.adoptedStyleSheets ?? [];
155
+ if (!existing.includes(sheet)) root.adoptedStyleSheets = [...existing, sheet];
156
+ styleTargets.add(root);
157
+ return;
158
+ }
159
+ const style = document.createElement("style");
160
+ style.id = BUTTON_STYLE_ID;
161
+ style.textContent = BUTTON_STYLE;
162
+ root.appendChild(style);
163
+ styleTargets.add(root);
164
+ }
165
+
166
+ //#endregion
167
+ export { ensureButtonStyle };
168
+ //# sourceMappingURL=style.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/button/style.ts"],"sourcesContent":["import { injectStyle } from '../style'\n\nconst BUTTON_STYLE_ID = 'weapp-web-button-style'\nconst styleTargets = new WeakSet<ParentNode>()\nlet sharedSheet: CSSStyleSheet | undefined\n\nconst BUTTON_STYLE = `\nweapp-button {\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\nweapp-button.weapp-btn--mini {\n display: inline-block;\n width: auto;\n}\n\nweapp-button .weapp-btn {\n appearance: none;\n -webkit-appearance: none;\n box-sizing: border-box;\n width: 100%;\n border-radius: 5px;\n border: 1px solid #d9d9d9;\n padding: 0 16px;\n height: 44px;\n line-height: 44px;\n font-size: 17px;\n font-weight: 400;\n background-color: #f8f8f8;\n color: #000000;\n cursor: pointer;\n outline: none;\n user-select: none;\n -webkit-tap-highlight-color: transparent;\n}\n\nweapp-button.weapp-btn--primary .weapp-btn {\n background-color: #07c160;\n border-color: #07c160;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--warn .weapp-btn {\n background-color: #e64340;\n border-color: #e64340;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--plain .weapp-btn {\n background-color: transparent;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {\n border-color: #b2b2b2;\n color: #353535;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {\n border-color: #07c160;\n color: #07c160;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {\n border-color: #e64340;\n color: #e64340;\n}\n\nweapp-button.weapp-btn--loading .weapp-btn,\nweapp-button.weapp-btn--disabled .weapp-btn {\n background-color: #f7f7f7;\n border-color: #d9d9d9;\n color: #9b9b9b;\n cursor: not-allowed;\n}\n\nweapp-button.button-hover .weapp-btn {\n background-color: #ededed;\n border-color: #d2d2d2;\n}\n\nweapp-button.button-hover.weapp-btn--primary .weapp-btn {\n background-color: #06ad56;\n border-color: #06ad56;\n}\n\nweapp-button.button-hover.weapp-btn--warn .weapp-btn {\n background-color: #d93c37;\n border-color: #d93c37;\n}\n\nweapp-button.button-hover.weapp-btn--plain .weapp-btn {\n background-color: rgba(0, 0, 0, 0.06);\n}\n\nweapp-button.weapp-btn--mini .weapp-btn {\n height: 32px;\n line-height: 32px;\n font-size: 13px;\n padding: 0 12px;\n border-radius: 4px;\n}\n\nweapp-button .weapp-btn__content {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n width: 100%;\n}\n\nweapp-button .weapp-btn__loading {\n width: 14px;\n height: 14px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-btn-spin 0.8s linear infinite;\n}\n\nweapp-button .weapp-btn__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-btn-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n\nfunction resolveAdoptedStyleSheets(root: ShadowRoot) {\n const doc = root.ownerDocument ?? document\n if (!doc || typeof doc.createElement !== 'function') {\n return undefined\n }\n if (!('adoptedStyleSheets' in doc)) {\n return undefined\n }\n if (!sharedSheet && 'replaceSync' in CSSStyleSheet.prototype) {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(BUTTON_STYLE)\n sharedSheet = sheet\n }\n return sharedSheet\n}\n\nexport function ensureButtonStyle(root?: ShadowRoot) {\n if (typeof document === 'undefined') {\n return\n }\n if (root && styleTargets.has(root)) {\n return\n }\n if (!root) {\n const target = document.head\n if (!target || styleTargets.has(target)) {\n return\n }\n injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID)\n styleTargets.add(target)\n return\n }\n const sheet = resolveAdoptedStyleSheets(root)\n if (sheet) {\n const existing = root.adoptedStyleSheets ?? []\n if (!existing.includes(sheet)) {\n root.adoptedStyleSheets = [...existing, sheet]\n }\n styleTargets.add(root)\n return\n }\n const style = document.createElement('style')\n style.id = BUTTON_STYLE_ID\n style.textContent = BUTTON_STYLE\n root.appendChild(style)\n styleTargets.add(root)\n}\n"],"mappings":";;;AAEA,MAAM,kBAAkB;AACxB,MAAM,+BAAe,IAAI,SAAqB;AAC9C,IAAI;AAEJ,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HrB,SAAS,0BAA0B,MAAkB;CACnD,MAAM,MAAM,KAAK,iBAAiB;AAClC,KAAI,CAAC,OAAO,OAAO,IAAI,kBAAkB,WACvC;AAEF,KAAI,EAAE,wBAAwB,KAC5B;AAEF,KAAI,CAAC,eAAe,iBAAiB,cAAc,WAAW;EAC5D,MAAM,QAAQ,IAAI,eAAe;AACjC,QAAM,YAAY,aAAa;AAC/B,gBAAc;;AAEhB,QAAO;;AAGT,SAAgB,kBAAkB,MAAmB;AACnD,KAAI,OAAO,aAAa,YACtB;AAEF,KAAI,QAAQ,aAAa,IAAI,KAAK,CAChC;AAEF,KAAI,CAAC,MAAM;EACT,MAAM,SAAS,SAAS;AACxB,MAAI,CAAC,UAAU,aAAa,IAAI,OAAO,CACrC;AAEF,cAAY,cAAc,gBAAgB;AAC1C,eAAa,IAAI,OAAO;AACxB;;CAEF,MAAM,QAAQ,0BAA0B,KAAK;AAC7C,KAAI,OAAO;EACT,MAAM,WAAW,KAAK,sBAAsB,EAAE;AAC9C,MAAI,CAAC,SAAS,SAAS,MAAM,CAC3B,MAAK,qBAAqB,CAAC,GAAG,UAAU,MAAM;AAEhD,eAAa,IAAI,KAAK;AACtB;;CAEF,MAAM,QAAQ,SAAS,cAAc,QAAQ;AAC7C,OAAM,KAAK;AACX,OAAM,cAAc;AACpB,MAAK,YAAY,MAAM;AACvB,cAAa,IAAI,KAAK"}
@@ -0,0 +1,98 @@
1
+ //#region src/runtime/component/behavior.ts
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ function mergeLifetimes(target, source) {
6
+ if (!source) return;
7
+ for (const key of [
8
+ "created",
9
+ "attached",
10
+ "ready",
11
+ "detached"
12
+ ]) {
13
+ const next = source[key];
14
+ if (!next) continue;
15
+ const current = target[key];
16
+ target[key] = current ? function merged() {
17
+ current.call(this);
18
+ next.call(this);
19
+ } : next;
20
+ }
21
+ }
22
+ function mergePageLifetimes(target, source) {
23
+ if (!source) return;
24
+ for (const key of [
25
+ "show",
26
+ "hide",
27
+ "resize"
28
+ ]) {
29
+ const next = source[key];
30
+ if (!next) continue;
31
+ const current = target[key];
32
+ target[key] = current ? function merged() {
33
+ current.call(this);
34
+ next.call(this);
35
+ } : next;
36
+ }
37
+ }
38
+ function normalizeBehaviors(component) {
39
+ if (!component) return {
40
+ component: void 0,
41
+ warnings: []
42
+ };
43
+ const warnings = [];
44
+ const visited = /* @__PURE__ */ new Set();
45
+ const merged = {};
46
+ const mergeComponent = (source) => {
47
+ if (source.properties) merged.properties = {
48
+ ...merged.properties ?? {},
49
+ ...source.properties
50
+ };
51
+ if (source.data) {
52
+ const nextData = typeof source.data === "function" ? source.data() : source.data;
53
+ if (isPlainObject(nextData)) merged.data = {
54
+ ...merged.data ?? {},
55
+ ...nextData
56
+ };
57
+ }
58
+ if (source.methods) merged.methods = {
59
+ ...merged.methods ?? {},
60
+ ...source.methods
61
+ };
62
+ if (source.lifetimes) {
63
+ merged.lifetimes = merged.lifetimes ?? {};
64
+ mergeLifetimes(merged.lifetimes, source.lifetimes);
65
+ }
66
+ if (source.pageLifetimes) {
67
+ merged.pageLifetimes = merged.pageLifetimes ?? {};
68
+ mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes);
69
+ }
70
+ };
71
+ const walk = (source) => {
72
+ if (visited.has(source)) {
73
+ warnings.push("[@weapp-vite/web] behaviors 存在循环引用,已跳过。");
74
+ return;
75
+ }
76
+ visited.add(source);
77
+ const behaviors = source.behaviors ?? [];
78
+ if (Array.isArray(behaviors)) for (const behavior of behaviors) {
79
+ if (!behavior || !isPlainObject(behavior)) {
80
+ warnings.push("[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。");
81
+ continue;
82
+ }
83
+ walk(behavior);
84
+ mergeComponent(behavior);
85
+ }
86
+ else if (behaviors) warnings.push("[@weapp-vite/web] behaviors 仅支持数组,已忽略。");
87
+ };
88
+ walk(component);
89
+ mergeComponent(component);
90
+ return {
91
+ component: merged,
92
+ warnings
93
+ };
94
+ }
95
+
96
+ //#endregion
97
+ export { normalizeBehaviors };
98
+ //# sourceMappingURL=behavior.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.mjs","names":[],"sources":["../../../src/runtime/component/behavior.ts"],"sourcesContent":["import type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n LifeTimeHooks,\n PageLifeTimeHooks,\n} from './types'\n\nfunction isPlainObject(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction mergeLifetimes(target: LifeTimeHooks, source?: LifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof LifeTimeHooks> = ['created', 'attached', 'ready', 'detached']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nfunction mergePageLifetimes(target: PageLifeTimeHooks, source?: PageLifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof PageLifeTimeHooks> = ['show', 'hide', 'resize']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nexport function normalizeBehaviors(component: ComponentOptions | undefined) {\n if (!component) {\n return { component: undefined, warnings: [] as string[] }\n }\n const warnings: string[] = []\n const visited = new Set<ComponentOptions>()\n const merged: ComponentOptions = {}\n\n const mergeComponent = (source: ComponentOptions) => {\n if (source.properties) {\n merged.properties = { ...(merged.properties ?? {}), ...source.properties }\n }\n if (source.data) {\n const nextData = typeof source.data === 'function'\n ? source.data()\n : source.data\n if (isPlainObject(nextData)) {\n merged.data = { ...((merged.data as DataRecord) ?? {}), ...nextData }\n }\n }\n if (source.methods) {\n merged.methods = { ...(merged.methods ?? {}), ...source.methods }\n }\n if (source.lifetimes) {\n merged.lifetimes = merged.lifetimes ?? {}\n mergeLifetimes(merged.lifetimes, source.lifetimes)\n }\n if (source.pageLifetimes) {\n merged.pageLifetimes = merged.pageLifetimes ?? {}\n mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes)\n }\n }\n\n const walk = (source: ComponentOptions) => {\n if (visited.has(source)) {\n warnings.push('[@weapp-vite/web] behaviors 存在循环引用,已跳过。')\n return\n }\n visited.add(source)\n const behaviors = source.behaviors ?? []\n if (Array.isArray(behaviors)) {\n for (const behavior of behaviors) {\n if (!behavior || !isPlainObject(behavior)) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。')\n continue\n }\n walk(behavior as ComponentOptions)\n mergeComponent(behavior as ComponentOptions)\n }\n }\n else if (behaviors) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持数组,已忽略。')\n }\n }\n\n walk(component)\n mergeComponent(component)\n\n return {\n component: merged,\n warnings,\n }\n}\n"],"mappings":";AAQA,SAAS,cAAc,OAA8C;AACnE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG7E,SAAS,eAAe,QAAuB,QAAwB;AACrE,KAAI,CAAC,OACH;AAGF,MAAK,MAAM,OAD8B;EAAC;EAAW;EAAY;EAAS;EAAW,EAC7D;EACtB,MAAM,OAAO,OAAO;AACpB,MAAI,CAAC,KACH;EAEF,MAAM,UAAU,OAAO;AACvB,SAAO,OAAO,UACV,SAAS,SAAsC;AAC/C,WAAQ,KAAK,KAAK;AAClB,QAAK,KAAK,KAAK;MAEf;;;AAIR,SAAS,mBAAmB,QAA2B,QAA4B;AACjF,KAAI,CAAC,OACH;AAGF,MAAK,MAAM,OADkC;EAAC;EAAQ;EAAQ;EAAS,EAC/C;EACtB,MAAM,OAAO,OAAO;AACpB,MAAI,CAAC,KACH;EAEF,MAAM,UAAU,OAAO;AACvB,SAAO,OAAO,UACV,SAAS,SAAsC;AAC/C,WAAQ,KAAK,KAAK;AAClB,QAAK,KAAK,KAAK;MAEf;;;AAIR,SAAgB,mBAAmB,WAAyC;AAC1E,KAAI,CAAC,UACH,QAAO;EAAE,WAAW;EAAW,UAAU,EAAE;EAAc;CAE3D,MAAM,WAAqB,EAAE;CAC7B,MAAM,0BAAU,IAAI,KAAuB;CAC3C,MAAM,SAA2B,EAAE;CAEnC,MAAM,kBAAkB,WAA6B;AACnD,MAAI,OAAO,WACT,QAAO,aAAa;GAAE,GAAI,OAAO,cAAc,EAAE;GAAG,GAAG,OAAO;GAAY;AAE5E,MAAI,OAAO,MAAM;GACf,MAAM,WAAW,OAAO,OAAO,SAAS,aACpC,OAAO,MAAM,GACb,OAAO;AACX,OAAI,cAAc,SAAS,CACzB,QAAO,OAAO;IAAE,GAAK,OAAO,QAAuB,EAAE;IAAG,GAAG;IAAU;;AAGzE,MAAI,OAAO,QACT,QAAO,UAAU;GAAE,GAAI,OAAO,WAAW,EAAE;GAAG,GAAG,OAAO;GAAS;AAEnE,MAAI,OAAO,WAAW;AACpB,UAAO,YAAY,OAAO,aAAa,EAAE;AACzC,kBAAe,OAAO,WAAW,OAAO,UAAU;;AAEpD,MAAI,OAAO,eAAe;AACxB,UAAO,gBAAgB,OAAO,iBAAiB,EAAE;AACjD,sBAAmB,OAAO,eAAe,OAAO,cAAc;;;CAIlE,MAAM,QAAQ,WAA6B;AACzC,MAAI,QAAQ,IAAI,OAAO,EAAE;AACvB,YAAS,KAAK,0CAA0C;AACxD;;AAEF,UAAQ,IAAI,OAAO;EACnB,MAAM,YAAY,OAAO,aAAa,EAAE;AACxC,MAAI,MAAM,QAAQ,UAAU,CAC1B,MAAK,MAAM,YAAY,WAAW;AAChC,OAAI,CAAC,YAAY,CAAC,cAAc,SAAS,EAAE;AACzC,aAAS,KAAK,8CAA8C;AAC5D;;AAEF,QAAK,SAA6B;AAClC,kBAAe,SAA6B;;WAGvC,UACP,UAAS,KAAK,yCAAyC;;AAI3D,MAAK,UAAU;AACf,gBAAe,UAAU;AAEzB,QAAO;EACL,WAAW;EACX;EACD"}
@@ -0,0 +1,8 @@
1
+ //#region src/runtime/component/constants.ts
2
+ const supportsLit = typeof document !== "undefined" && typeof document.createComment === "function" && typeof document.createTreeWalker === "function";
3
+ const FallbackElement = class {};
4
+ const EVENT_FLAG_ATTRIBUTE_PREFIX = "data-wx-on-flags-";
5
+
6
+ //#endregion
7
+ export { EVENT_FLAG_ATTRIBUTE_PREFIX, FallbackElement, supportsLit };
8
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/runtime/component/constants.ts"],"sourcesContent":["export const supportsLit = typeof document !== 'undefined'\n && typeof document.createComment === 'function'\n && typeof document.createTreeWalker === 'function'\n\nexport const FallbackElement = class {}\n\nexport const EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-wx-on-flags-'\n"],"mappings":";AAAA,MAAa,cAAc,OAAO,aAAa,eAC1C,OAAO,SAAS,kBAAkB,cAClC,OAAO,SAAS,qBAAqB;AAE1C,MAAa,kBAAkB,MAAM;AAErC,MAAa,8BAA8B"}
@@ -0,0 +1,26 @@
1
+ //#region src/runtime/component/dom.ts
2
+ function resolveQueryRoot(instance) {
3
+ return instance.renderRoot ?? instance.shadowRoot ?? instance;
4
+ }
5
+ function resolveRenderRoot(instance) {
6
+ return instance.renderRoot ?? instance.shadowRoot ?? instance;
7
+ }
8
+ function createScopedSelectorQuery(instance) {
9
+ const query = globalThis.wx?.createSelectorQuery?.();
10
+ if (query && typeof query.in === "function") return query.in(instance);
11
+ return query;
12
+ }
13
+ function selectRuntimeComponent(instance, selector) {
14
+ const root = resolveQueryRoot(instance);
15
+ if (!selector || typeof root.querySelector !== "function") return null;
16
+ return root.querySelector(selector);
17
+ }
18
+ function selectRuntimeComponents(instance, selector) {
19
+ const root = resolveQueryRoot(instance);
20
+ if (!selector || typeof root.querySelectorAll !== "function") return [];
21
+ return Array.from(root.querySelectorAll(selector));
22
+ }
23
+
24
+ //#endregion
25
+ export { createScopedSelectorQuery, resolveRenderRoot, selectRuntimeComponent, selectRuntimeComponents };
26
+ //# sourceMappingURL=dom.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/component/dom.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\n\ntype QueryRoot = ParentNode & {\n querySelector?: ParentNode['querySelector']\n querySelectorAll?: ParentNode['querySelectorAll']\n}\n\nexport function resolveQueryRoot(instance: ComponentPublicInstance & { renderRoot?: ParentNode }): QueryRoot {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as QueryRoot\n}\n\nexport function resolveRenderRoot(instance: ComponentPublicInstance & { renderRoot?: HTMLElement | ShadowRoot }) {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as HTMLElement | ShadowRoot\n}\n\nexport function createScopedSelectorQuery(instance: ComponentPublicInstance) {\n const runtime = globalThis as {\n wx?: {\n createSelectorQuery?: () => {\n in?: (context: unknown) => unknown\n }\n }\n }\n const query = runtime.wx?.createSelectorQuery?.()\n if (query && typeof query.in === 'function') {\n return query.in(instance)\n }\n return query\n}\n\nexport function selectRuntimeComponent(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelector !== 'function') {\n return null\n }\n return root.querySelector(selector) as ComponentPublicInstance | null\n}\n\nexport function selectRuntimeComponents(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelectorAll !== 'function') {\n return []\n }\n return Array.from(root.querySelectorAll(selector)) as ComponentPublicInstance[]\n}\n"],"mappings":";AAOA,SAAgB,iBAAiB,UAA4E;AAC3G,QAAQ,SAAS,cAAc,SAAS,cAAc;;AAGxD,SAAgB,kBAAkB,UAA+E;AAC/G,QAAQ,SAAS,cAAc,SAAS,cAAc;;AAGxD,SAAgB,0BAA0B,UAAmC;CAQ3E,MAAM,QAPU,WAOM,IAAI,uBAAuB;AACjD,KAAI,SAAS,OAAO,MAAM,OAAO,WAC/B,QAAO,MAAM,GAAG,SAAS;AAE3B,QAAO;;AAGT,SAAgB,uBAAuB,UAAiE,UAAkB;CACxH,MAAM,OAAO,iBAAiB,SAAS;AACvC,KAAI,CAAC,YAAY,OAAO,KAAK,kBAAkB,WAC7C,QAAO;AAET,QAAO,KAAK,cAAc,SAAS;;AAGrC,SAAgB,wBAAwB,UAAiE,UAAkB;CACzH,MAAM,OAAO,iBAAiB,SAAS;AACvC,KAAI,CAAC,YAAY,OAAO,KAAK,qBAAqB,WAChD,QAAO,EAAE;AAEX,QAAO,MAAM,KAAK,KAAK,iBAAiB,SAAS,CAAC"}
@@ -0,0 +1,208 @@
1
+ import { supportsLit } from "./constants.mjs";
2
+ import { createRenderContext } from "../renderContext.mjs";
3
+ import { createScopedSelectorQuery, resolveRenderRoot, selectRuntimeComponent, selectRuntimeComponents } from "./dom.mjs";
4
+ import { bindRuntimeEvents } from "./events.mjs";
5
+ import { cloneValue, coerceValue, toCamelCase } from "./utils.mjs";
6
+ import { html } from "lit";
7
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
8
+
9
+ //#region src/runtime/component/element.ts
10
+ function createComponentElementClass({ BaseElement, runtimeState, instances }) {
11
+ class WeappWebComponent extends BaseElement {
12
+ static observedAttributes = runtimeState.observedAttributes;
13
+ #state;
14
+ #properties;
15
+ #methods;
16
+ #isMounted = false;
17
+ #renderContext = createRenderContext(this, {});
18
+ #usesLegacyTemplate = false;
19
+ #readyFired = false;
20
+ #observerInitDone = false;
21
+ #observedKeys = /* @__PURE__ */ new Set();
22
+ data;
23
+ properties;
24
+ constructor() {
25
+ super();
26
+ const dataOption = typeof runtimeState.componentRef.data === "function" ? runtimeState.componentRef.data() : runtimeState.componentRef.data ?? {};
27
+ this.#properties = { ...runtimeState.defaultPropertyValues };
28
+ this.#state = {
29
+ ...cloneValue(this.#properties),
30
+ ...cloneValue(dataOption)
31
+ };
32
+ this.#methods = {};
33
+ this.#syncMethods(runtimeState.componentRef.methods ?? {});
34
+ Object.defineProperties(this, {
35
+ data: {
36
+ configurable: true,
37
+ enumerable: true,
38
+ get: () => this.#state
39
+ },
40
+ properties: {
41
+ configurable: true,
42
+ enumerable: true,
43
+ get: () => this.#properties
44
+ }
45
+ });
46
+ for (const [propName] of runtimeState.propertyEntries) Object.defineProperty(this, propName, {
47
+ configurable: true,
48
+ enumerable: true,
49
+ get: () => this.#state[propName],
50
+ set: (value) => this.#setProperty(propName, value)
51
+ });
52
+ if (!supportsLit) {
53
+ const host = this;
54
+ if (!host.shadowRoot && typeof host.attachShadow === "function") host.attachShadow({ mode: "open" });
55
+ this.renderRoot = host.shadowRoot ?? host;
56
+ }
57
+ instances.add(this);
58
+ runtimeState.lifetimes.created?.call(this);
59
+ }
60
+ setData(patch) {
61
+ this.#applyDataPatch(patch);
62
+ }
63
+ triggerEvent(name, detail) {
64
+ this.dispatchEvent(new CustomEvent(name, {
65
+ detail,
66
+ bubbles: true,
67
+ composed: true
68
+ }));
69
+ }
70
+ createSelectorQuery() {
71
+ return createScopedSelectorQuery(this);
72
+ }
73
+ selectComponent(selector) {
74
+ return selectRuntimeComponent(this, selector);
75
+ }
76
+ selectAllComponents(selector) {
77
+ return selectRuntimeComponents(this, selector);
78
+ }
79
+ connectedCallback() {
80
+ const superConnected = BaseElement.prototype.connectedCallback;
81
+ if (supportsLit && typeof superConnected === "function") superConnected.call(this);
82
+ this.#applyAttributes();
83
+ if (runtimeState.observerInitEnabled) this.#runInitialObservers();
84
+ runtimeState.lifetimes.attached?.call(this);
85
+ this.#isMounted = true;
86
+ if (!supportsLit) this.#renderLegacy();
87
+ }
88
+ disconnectedCallback() {
89
+ const superDisconnected = BaseElement.prototype.disconnectedCallback;
90
+ if (supportsLit && typeof superDisconnected === "function") superDisconnected.call(this);
91
+ this.#isMounted = false;
92
+ instances.delete(this);
93
+ runtimeState.lifetimes.detached?.call(this);
94
+ }
95
+ attributeChangedCallback(attrName, oldValue, newValue) {
96
+ const superAttributeChanged = BaseElement.prototype.attributeChangedCallback;
97
+ if (supportsLit && typeof superAttributeChanged === "function") superAttributeChanged.call(this, attrName, oldValue, newValue);
98
+ const propName = toCamelCase(attrName);
99
+ if (!Object.hasOwn(this.#properties, propName)) return;
100
+ const propOption = runtimeState.componentRef.properties?.[propName];
101
+ this.#setProperty(propName, coerceValue(newValue, propOption?.type));
102
+ }
103
+ firstUpdated() {
104
+ runtimeState.lifetimes.ready?.call(this);
105
+ this.#readyFired = true;
106
+ }
107
+ updated() {
108
+ if (this.#usesLegacyTemplate) bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this);
109
+ }
110
+ render() {
111
+ const result = runtimeState.templateRef(this.#state, this.#renderContext);
112
+ const styleMarkup = runtimeState.styleRef ? html`<style>${runtimeState.styleRef}</style>` : null;
113
+ if (typeof result === "string") {
114
+ this.#usesLegacyTemplate = true;
115
+ return html`${styleMarkup}${unsafeHTML(result)}`;
116
+ }
117
+ this.#usesLegacyTemplate = false;
118
+ if (styleMarkup) return html`${styleMarkup}${result}`;
119
+ return result;
120
+ }
121
+ requestUpdate(name, oldValue, options) {
122
+ const superRequestUpdate = BaseElement.prototype.requestUpdate;
123
+ if (supportsLit && typeof superRequestUpdate === "function") return superRequestUpdate.call(this, name, oldValue, options);
124
+ if (this.#isMounted) this.#renderLegacy();
125
+ }
126
+ #applyAttributes() {
127
+ if (!this.attributes || typeof this.attributes[Symbol.iterator] !== "function") return;
128
+ for (const attr of this.attributes) this.attributeChangedCallback(attr.name, null, attr.value);
129
+ }
130
+ #applyDataPatch(patch) {
131
+ if (!patch || typeof patch !== "object") return;
132
+ let changed = false;
133
+ for (const [key, value] of Object.entries(patch)) {
134
+ if (this.#state[key] === value) continue;
135
+ const oldValue = this.#state[key];
136
+ this.#state[key] = value;
137
+ if (Object.hasOwn(this.#properties, key)) {
138
+ this.#properties[key] = value;
139
+ const propOption = runtimeState.componentRef.properties?.[key];
140
+ if (propOption?.observer) {
141
+ propOption.observer.call(this, value, oldValue);
142
+ this.#observedKeys.add(key);
143
+ }
144
+ }
145
+ changed = true;
146
+ }
147
+ if (changed) this.requestUpdate();
148
+ }
149
+ #setProperty(name, value) {
150
+ const propOption = runtimeState.componentRef.properties?.[name];
151
+ const coerced = coerceValue(value, propOption?.type);
152
+ const oldValue = this.#properties[name];
153
+ if (oldValue === coerced) return;
154
+ this.#properties[name] = coerced;
155
+ this.#state[name] = coerced;
156
+ if (this.#isMounted) this.requestUpdate();
157
+ if (propOption?.observer) {
158
+ propOption.observer.call(this, coerced, oldValue);
159
+ this.#observedKeys.add(name);
160
+ }
161
+ }
162
+ #runInitialObservers() {
163
+ if (this.#observerInitDone) return;
164
+ this.#observerInitDone = true;
165
+ for (const [propName, propOption] of runtimeState.propertyEntries) {
166
+ if (!propOption.observer || this.#observedKeys.has(propName)) continue;
167
+ const value = this.#state[propName];
168
+ propOption.observer.call(this, value, void 0);
169
+ this.#observedKeys.add(propName);
170
+ }
171
+ }
172
+ #syncMethods(nextMethods) {
173
+ const resolved = nextMethods ?? {};
174
+ const bound = {};
175
+ for (const [name, fn] of Object.entries(resolved)) if (typeof fn === "function") bound[name] = fn.bind(this);
176
+ for (const key of Object.keys(this.#methods)) if (!(key in bound)) delete this.#methods[key];
177
+ for (const [key, fn] of Object.entries(bound)) this.#methods[key] = fn;
178
+ this.#renderContext = createRenderContext(this, this.#methods);
179
+ }
180
+ __weappSync(nextMethods) {
181
+ this.#syncMethods(nextMethods);
182
+ this.requestUpdate();
183
+ }
184
+ __weappInvokePageLifetime(type) {
185
+ const hook = runtimeState.pageLifetimes[type];
186
+ if (typeof hook === "function") hook.call(this);
187
+ }
188
+ #renderLegacy() {
189
+ const result = runtimeState.templateRef(this.#state, this.#renderContext);
190
+ const root = resolveRenderRoot(this);
191
+ const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : "";
192
+ if (typeof result === "string") {
193
+ root.innerHTML = `${styleMarkup}${result}`;
194
+ bindRuntimeEvents(root, this.#methods, this);
195
+ } else if (result == null) root.innerHTML = styleMarkup;
196
+ else root.innerHTML = `${styleMarkup}${String(result)}`;
197
+ if (!this.#readyFired) {
198
+ runtimeState.lifetimes.ready?.call(this);
199
+ this.#readyFired = true;
200
+ }
201
+ }
202
+ }
203
+ return WeappWebComponent;
204
+ }
205
+
206
+ //#endregion
207
+ export { createComponentElementClass };
208
+ //# sourceMappingURL=element.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.mjs","names":["#properties","#state","#methods","#syncMethods","#setProperty","#applyDataPatch","#applyAttributes","#runInitialObservers","#isMounted","#renderLegacy","#readyFired","#usesLegacyTemplate","#renderContext","#observedKeys","#observerInitDone"],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n DataRecord,\n PageLifeTimeHooks,\n} from './types'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createRenderContext } from '../renderContext'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { cloneValue, coerceValue, toCamelCase } from './utils'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n class WeappWebComponent extends BaseElement implements WeappComponentInstance {\n static observedAttributes = runtimeState.observedAttributes\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any>\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = typeof runtimeState.componentRef.data === 'function'\n ? (runtimeState.componentRef.data as () => DataRecord)()\n : (runtimeState.componentRef.data ?? {})\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n this.#methods = {}\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this)\n }\n\n setData(patch: DataRecord) {\n this.#applyDataPatch(patch)\n }\n\n triggerEvent(name: string, detail?: any) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n connectedCallback() {\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this)\n this.#isMounted = true\n if (!supportsLit) {\n this.#renderLegacy()\n }\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!Object.hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n\n updated() {\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const styleMarkup = runtimeState.styleRef\n ? html`<style>${runtimeState.styleRef}</style>`\n : null\n if (typeof result === 'string') {\n this.#usesLegacyTemplate = true\n return html`${styleMarkup}${unsafeHTML(result)}`\n }\n this.#usesLegacyTemplate = false\n if (styleMarkup) {\n return html`${styleMarkup}${result as any}`\n }\n return result\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return\n }\n let changed = false\n for (const [key, value] of Object.entries(patch)) {\n if (this.#state[key] === value) {\n continue\n }\n const oldValue = this.#state[key]\n this.#state[key] = value\n if (Object.hasOwn(this.#properties, key)) {\n this.#properties[key] = value\n const propOption = runtimeState.componentRef.properties?.[key]\n if (propOption?.observer) {\n propOption.observer.call(this, value, oldValue)\n this.#observedKeys.add(key)\n }\n }\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n }\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n if (propOption?.observer) {\n propOption.observer.call(this, coerced, oldValue)\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this)\n }\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n this.#methods[key] = fn\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : ''\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":"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"}
@@ -0,0 +1,48 @@
1
+ import { EVENT_FLAG_ATTRIBUTE_PREFIX } from "./constants.mjs";
2
+
3
+ //#region src/runtime/component/events.ts
4
+ function parseEventFlags(value) {
5
+ if (!value) return {
6
+ catch: false,
7
+ capture: false
8
+ };
9
+ const tokens = value.split(",").map((token) => token.trim()).filter(Boolean);
10
+ const tokenSet = new Set(tokens);
11
+ return {
12
+ catch: tokenSet.has("catch"),
13
+ capture: tokenSet.has("capture")
14
+ };
15
+ }
16
+ function bindRuntimeEvents(root, methods, instance) {
17
+ if (typeof document === "undefined") return;
18
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
19
+ while (walker.nextNode()) {
20
+ const element = walker.currentNode;
21
+ for (const attribute of element.getAttributeNames()) {
22
+ if (!attribute.startsWith("data-wx-on-") || attribute.startsWith("data-wx-on-flags-")) continue;
23
+ const handlerName = element.getAttribute(attribute);
24
+ if (!handlerName) continue;
25
+ const handler = methods[handlerName];
26
+ if (!handler) continue;
27
+ const eventName = attribute.slice(11);
28
+ const flags = parseEventFlags(element.getAttribute(`${EVENT_FLAG_ATTRIBUTE_PREFIX}${eventName}`));
29
+ element.addEventListener(eventName, (nativeEvent) => {
30
+ if (flags.catch) nativeEvent.stopPropagation();
31
+ const dataset = { ...element.dataset };
32
+ const syntheticEvent = {
33
+ type: eventName,
34
+ timeStamp: nativeEvent.timeStamp,
35
+ detail: nativeEvent.detail ?? nativeEvent.data ?? void 0,
36
+ target: { dataset },
37
+ currentTarget: { dataset },
38
+ originalEvent: nativeEvent
39
+ };
40
+ handler.call(instance, syntheticEvent);
41
+ }, flags.capture);
42
+ }
43
+ }
44
+ }
45
+
46
+ //#endregion
47
+ export { bindRuntimeEvents };
48
+ //# sourceMappingURL=events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { EVENT_FLAG_ATTRIBUTE_PREFIX } from './constants'\n\nfunction parseEventFlags(value: string | null) {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n for (const attribute of element.getAttributeNames()) {\n if (!attribute.startsWith('data-wx-on-') || attribute.startsWith(EVENT_FLAG_ATTRIBUTE_PREFIX)) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const eventName = attribute.slice('data-wx-on-'.length)\n const flags = parseEventFlags(element.getAttribute(`${EVENT_FLAG_ATTRIBUTE_PREFIX}${eventName}`))\n element.addEventListener(eventName, (nativeEvent) => {\n if (flags.catch) {\n nativeEvent.stopPropagation()\n }\n const dataset = { ...element.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,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }, flags.capture)\n }\n }\n}\n"],"mappings":";;;AAGA,SAAS,gBAAgB,OAAsB;AAC7C,KAAI,CAAC,MACH,QAAO;EAAE,OAAO;EAAO,SAAS;EAAO;CAEzC,MAAM,SAAS,MAAM,MAAM,IAAI,CAAC,KAAI,UAAS,MAAM,MAAM,CAAC,CAAC,OAAO,QAAQ;CAC1E,MAAM,WAAW,IAAI,IAAI,OAAO;AAChC,QAAO;EACL,OAAO,SAAS,IAAI,QAAQ;EAC5B,SAAS,SAAS,IAAI,UAAU;EACjC;;AAGH,SAAgB,kBACd,MACA,SACA,UACA;AACA,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,SAAS,SAAS,iBAAiB,MAAM,WAAW,aAAa;AACvE,QAAO,OAAO,UAAU,EAAE;EACxB,MAAM,UAAU,OAAO;AACvB,OAAK,MAAM,aAAa,QAAQ,mBAAmB,EAAE;AACnD,OAAI,CAAC,UAAU,WAAW,cAAc,IAAI,UAAU,+BAAuC,CAC3F;GAEF,MAAM,cAAc,QAAQ,aAAa,UAAU;AACnD,OAAI,CAAC,YACH;GAEF,MAAM,UAAU,QAAQ;AACxB,OAAI,CAAC,QACH;GAEF,MAAM,YAAY,UAAU,MAAM,GAAqB;GACvD,MAAM,QAAQ,gBAAgB,QAAQ,aAAa,GAAG,8BAA8B,YAAY,CAAC;AACjG,WAAQ,iBAAiB,YAAY,gBAAgB;AACnD,QAAI,MAAM,MACR,aAAY,iBAAiB;IAE/B,MAAM,UAAU,EAAE,GAAG,QAAQ,SAAS;IACtC,MAAM,iBAAiB;KACrB,MAAM;KACN,WAAW,YAAY;KACvB,QAAS,YAA4B,UAAW,YAA2B,QAAQ;KACnF,QAAQ,EACN,SACD;KACD,eAAe,EACb,SACD;KACD,eAAe;KAChB;AACD,YAAQ,KAAK,UAAU,eAAe;MACrC,MAAM,QAAQ"}
@@ -0,0 +1,7 @@
1
+ import { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DefineComponentOptions, PropertyOption } from "./types.mjs";
2
+
3
+ //#region src/runtime/component/index.d.ts
4
+ declare function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor;
5
+ //#endregion
6
+ export { defineComponent };
7
+ //# sourceMappingURL=index.d.mts.map