@weapp-vite/web 1.3.14 → 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 +2 -2
  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,56 @@
1
+ //#region src/runtime/polyfill/videoContext.ts
2
+ function resolveVideoElementById(videoId) {
3
+ if (typeof document === "undefined") return;
4
+ const normalized = String(videoId ?? "").trim();
5
+ if (!normalized) return;
6
+ const fromId = document.getElementById(normalized);
7
+ if (fromId && "play" in fromId && "pause" in fromId) return fromId;
8
+ const escaped = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(normalized) : normalized.replace(/"/g, "\\\"");
9
+ const fromQuery = document.querySelector(`video#${escaped}`);
10
+ if (fromQuery && "play" in fromQuery && "pause" in fromQuery) return fromQuery;
11
+ }
12
+ function createVideoContextBridge(videoId) {
13
+ const getVideo = () => resolveVideoElementById(videoId);
14
+ return {
15
+ play() {
16
+ getVideo()?.play?.();
17
+ },
18
+ pause() {
19
+ getVideo()?.pause?.();
20
+ },
21
+ stop() {
22
+ const video = getVideo();
23
+ if (!video) return;
24
+ video.pause?.();
25
+ try {
26
+ video.currentTime = 0;
27
+ } catch {}
28
+ },
29
+ seek(position) {
30
+ if (!Number.isFinite(position)) return;
31
+ const video = getVideo();
32
+ if (!video) return;
33
+ try {
34
+ video.currentTime = Math.max(0, position);
35
+ } catch {}
36
+ },
37
+ playbackRate(rate) {
38
+ if (!Number.isFinite(rate) || rate <= 0) return;
39
+ const video = getVideo();
40
+ if (!video) return;
41
+ try {
42
+ video.playbackRate = rate;
43
+ } catch {}
44
+ },
45
+ requestFullScreen() {
46
+ getVideo()?.requestFullscreen?.();
47
+ },
48
+ exitFullScreen() {
49
+ document.exitFullscreen?.();
50
+ }
51
+ };
52
+ }
53
+
54
+ //#endregion
55
+ export { createVideoContextBridge };
56
+ //# sourceMappingURL=videoContext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"videoContext.mjs","names":[],"sources":["../../../src/runtime/polyfill/videoContext.ts"],"sourcesContent":["import type { VideoContext } from './types/platformRuntime'\n\nfunction resolveVideoElementById(videoId: string) {\n if (typeof document === 'undefined') {\n return undefined\n }\n const normalized = String(videoId ?? '').trim()\n if (!normalized) {\n return undefined\n }\n const fromId = document.getElementById(normalized)\n if (fromId && 'play' in fromId && 'pause' in fromId) {\n return fromId as unknown as HTMLVideoElement\n }\n const escaped = typeof CSS !== 'undefined' && typeof CSS.escape === 'function'\n ? CSS.escape(normalized)\n : normalized.replace(/\"/g, '\\\\\"')\n const fromQuery = document.querySelector(`video#${escaped}`)\n if (fromQuery && 'play' in fromQuery && 'pause' in fromQuery) {\n return fromQuery as HTMLVideoElement\n }\n return undefined\n}\n\nexport function createVideoContextBridge(videoId: string): VideoContext {\n const getVideo = () => resolveVideoElementById(videoId)\n return {\n play() {\n getVideo()?.play?.()\n },\n pause() {\n getVideo()?.pause?.()\n },\n stop() {\n const video = getVideo()\n if (!video) {\n return\n }\n video.pause?.()\n try {\n video.currentTime = 0\n }\n catch {\n // ignore browsers that block currentTime mutation\n }\n },\n seek(position: number) {\n if (!Number.isFinite(position)) {\n return\n }\n const video = getVideo()\n if (!video) {\n return\n }\n try {\n video.currentTime = Math.max(0, position)\n }\n catch {\n // ignore browsers that block currentTime mutation\n }\n },\n playbackRate(rate: number) {\n if (!Number.isFinite(rate) || rate <= 0) {\n return\n }\n const video = getVideo()\n if (!video) {\n return\n }\n try {\n video.playbackRate = rate\n }\n catch {\n // ignore unsupported playbackRate mutation\n }\n },\n requestFullScreen() {\n const video = getVideo() as (HTMLVideoElement & { requestFullscreen?: () => Promise<void> | void }) | undefined\n video?.requestFullscreen?.()\n },\n exitFullScreen() {\n const runtimeDocument = document as { exitFullscreen?: () => Promise<void> | void }\n runtimeDocument.exitFullscreen?.()\n },\n }\n}\n"],"mappings":";AAEA,SAAS,wBAAwB,SAAiB;AAChD,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,aAAa,OAAO,WAAW,GAAG,CAAC,MAAM;AAC/C,KAAI,CAAC,WACH;CAEF,MAAM,SAAS,SAAS,eAAe,WAAW;AAClD,KAAI,UAAU,UAAU,UAAU,WAAW,OAC3C,QAAO;CAET,MAAM,UAAU,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,aAChE,IAAI,OAAO,WAAW,GACtB,WAAW,QAAQ,MAAM,OAAM;CACnC,MAAM,YAAY,SAAS,cAAc,SAAS,UAAU;AAC5D,KAAI,aAAa,UAAU,aAAa,WAAW,UACjD,QAAO;;AAKX,SAAgB,yBAAyB,SAA+B;CACtE,MAAM,iBAAiB,wBAAwB,QAAQ;AACvD,QAAO;EACL,OAAO;AACL,aAAU,EAAE,QAAQ;;EAEtB,QAAQ;AACN,aAAU,EAAE,SAAS;;EAEvB,OAAO;GACL,MAAM,QAAQ,UAAU;AACxB,OAAI,CAAC,MACH;AAEF,SAAM,SAAS;AACf,OAAI;AACF,UAAM,cAAc;WAEhB;;EAIR,KAAK,UAAkB;AACrB,OAAI,CAAC,OAAO,SAAS,SAAS,CAC5B;GAEF,MAAM,QAAQ,UAAU;AACxB,OAAI,CAAC,MACH;AAEF,OAAI;AACF,UAAM,cAAc,KAAK,IAAI,GAAG,SAAS;WAErC;;EAIR,aAAa,MAAc;AACzB,OAAI,CAAC,OAAO,SAAS,KAAK,IAAI,QAAQ,EACpC;GAEF,MAAM,QAAQ,UAAU;AACxB,OAAI,CAAC,MACH;AAEF,OAAI;AACF,UAAM,eAAe;WAEjB;;EAIR,oBAAoB;AAElB,GADc,UAAU,EACjB,qBAAqB;;EAE9B,iBAAiB;AAEf,GADwB,SACR,kBAAkB;;EAErC"}
@@ -0,0 +1,58 @@
1
+ //#region src/runtime/polyfill/vkSession.ts
2
+ function createVkSessionBridge() {
3
+ let destroyed = false;
4
+ const listeners = /* @__PURE__ */ new Map();
5
+ const ensureAvailable = (action) => {
6
+ if (destroyed) throw new TypeError(`createVKSession:fail session is destroyed (${action})`);
7
+ };
8
+ return {
9
+ start() {
10
+ try {
11
+ ensureAvailable("start");
12
+ } catch (error) {
13
+ const message = error instanceof Error ? error.message : String(error);
14
+ return Promise.reject(new TypeError(message));
15
+ }
16
+ return Promise.resolve({ errMsg: "vkSession.start:ok" });
17
+ },
18
+ stop() {
19
+ try {
20
+ ensureAvailable("stop");
21
+ } catch (error) {
22
+ const message = error instanceof Error ? error.message : String(error);
23
+ return Promise.reject(new TypeError(message));
24
+ }
25
+ return Promise.resolve({ errMsg: "vkSession.stop:ok" });
26
+ },
27
+ destroy() {
28
+ destroyed = true;
29
+ listeners.clear();
30
+ },
31
+ on(eventName, callback) {
32
+ if (typeof eventName !== "string" || typeof callback !== "function") return;
33
+ const key = eventName.trim();
34
+ if (!key) return;
35
+ const list = listeners.get(key) ?? /* @__PURE__ */ new Set();
36
+ list.add(callback);
37
+ listeners.set(key, list);
38
+ },
39
+ off(eventName, callback) {
40
+ if (typeof eventName !== "string" || !eventName.trim()) {
41
+ listeners.clear();
42
+ return;
43
+ }
44
+ const list = listeners.get(eventName.trim());
45
+ if (!list) return;
46
+ if (typeof callback !== "function") {
47
+ listeners.delete(eventName.trim());
48
+ return;
49
+ }
50
+ list.delete(callback);
51
+ if (list.size === 0) listeners.delete(eventName.trim());
52
+ }
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ export { createVkSessionBridge };
58
+ //# sourceMappingURL=vkSession.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vkSession.mjs","names":[],"sources":["../../../src/runtime/polyfill/vkSession.ts"],"sourcesContent":["interface VkSession {\n start: () => Promise<{ errMsg: string }>\n stop: () => Promise<{ errMsg: string }>\n destroy: () => void\n on: (eventName: string, callback: (payload: unknown) => void) => void\n off: (eventName?: string, callback?: (payload: unknown) => void) => void\n}\n\nexport function createVkSessionBridge(): VkSession {\n let destroyed = false\n const listeners = new Map<string, Set<(payload: unknown) => void>>()\n\n const ensureAvailable = (action: string) => {\n if (destroyed) {\n throw new TypeError(`createVKSession:fail session is destroyed (${action})`)\n }\n }\n\n return {\n start() {\n try {\n ensureAvailable('start')\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n return Promise.reject(new TypeError(message))\n }\n return Promise.resolve({ errMsg: 'vkSession.start:ok' })\n },\n stop() {\n try {\n ensureAvailable('stop')\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n return Promise.reject(new TypeError(message))\n }\n return Promise.resolve({ errMsg: 'vkSession.stop:ok' })\n },\n destroy() {\n destroyed = true\n listeners.clear()\n },\n on(eventName: string, callback: (payload: unknown) => void) {\n if (typeof eventName !== 'string' || typeof callback !== 'function') {\n return\n }\n const key = eventName.trim()\n if (!key) {\n return\n }\n const list = listeners.get(key) ?? new Set<(payload: unknown) => void>()\n list.add(callback)\n listeners.set(key, list)\n },\n off(eventName?: string, callback?: (payload: unknown) => void) {\n if (typeof eventName !== 'string' || !eventName.trim()) {\n listeners.clear()\n return\n }\n const list = listeners.get(eventName.trim())\n if (!list) {\n return\n }\n if (typeof callback !== 'function') {\n listeners.delete(eventName.trim())\n return\n }\n list.delete(callback)\n if (list.size === 0) {\n listeners.delete(eventName.trim())\n }\n },\n }\n}\n"],"mappings":";AAQA,SAAgB,wBAAmC;CACjD,IAAI,YAAY;CAChB,MAAM,4BAAY,IAAI,KAA8C;CAEpE,MAAM,mBAAmB,WAAmB;AAC1C,MAAI,UACF,OAAM,IAAI,UAAU,8CAA8C,OAAO,GAAG;;AAIhF,QAAO;EACL,QAAQ;AACN,OAAI;AACF,oBAAgB,QAAQ;YAEnB,OAAO;IACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,WAAO,QAAQ,OAAO,IAAI,UAAU,QAAQ,CAAC;;AAE/C,UAAO,QAAQ,QAAQ,EAAE,QAAQ,sBAAsB,CAAC;;EAE1D,OAAO;AACL,OAAI;AACF,oBAAgB,OAAO;YAElB,OAAO;IACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,WAAO,QAAQ,OAAO,IAAI,UAAU,QAAQ,CAAC;;AAE/C,UAAO,QAAQ,QAAQ,EAAE,QAAQ,qBAAqB,CAAC;;EAEzD,UAAU;AACR,eAAY;AACZ,aAAU,OAAO;;EAEnB,GAAG,WAAmB,UAAsC;AAC1D,OAAI,OAAO,cAAc,YAAY,OAAO,aAAa,WACvD;GAEF,MAAM,MAAM,UAAU,MAAM;AAC5B,OAAI,CAAC,IACH;GAEF,MAAM,OAAO,UAAU,IAAI,IAAI,oBAAI,IAAI,KAAiC;AACxE,QAAK,IAAI,SAAS;AAClB,aAAU,IAAI,KAAK,KAAK;;EAE1B,IAAI,WAAoB,UAAuC;AAC7D,OAAI,OAAO,cAAc,YAAY,CAAC,UAAU,MAAM,EAAE;AACtD,cAAU,OAAO;AACjB;;GAEF,MAAM,OAAO,UAAU,IAAI,UAAU,MAAM,CAAC;AAC5C,OAAI,CAAC,KACH;AAEF,OAAI,OAAO,aAAa,YAAY;AAClC,cAAU,OAAO,UAAU,MAAM,CAAC;AAClC;;AAEF,QAAK,OAAO,SAAS;AACrB,OAAI,KAAK,SAAS,EAChB,WAAU,OAAO,UAAU,MAAM,CAAC;;EAGvC"}
@@ -0,0 +1,39 @@
1
+ //#region src/runtime/polyfill/windowResize.ts
2
+ const windowResizeCallbacks = /* @__PURE__ */ new Set();
3
+ let windowResizeBridgeBound = false;
4
+ function readWindowResizeResult(getWindowInfo) {
5
+ const windowInfo = getWindowInfo();
6
+ return {
7
+ size: {
8
+ windowWidth: windowInfo.windowWidth,
9
+ windowHeight: windowInfo.windowHeight
10
+ },
11
+ windowWidth: windowInfo.windowWidth,
12
+ windowHeight: windowInfo.windowHeight
13
+ };
14
+ }
15
+ function notifyWindowResize(getWindowInfo) {
16
+ if (windowResizeCallbacks.size === 0) return;
17
+ const result = readWindowResizeResult(getWindowInfo);
18
+ for (const callback of windowResizeCallbacks) callback(result);
19
+ }
20
+ function bindWindowResizeBridge(getWindowInfo) {
21
+ if (windowResizeBridgeBound) return;
22
+ windowResizeBridgeBound = true;
23
+ (typeof window !== "undefined" ? window : globalThis).addEventListener?.("resize", () => notifyWindowResize(getWindowInfo));
24
+ }
25
+ function addWindowResizeCallback(callback, getWindowInfo) {
26
+ bindWindowResizeBridge(getWindowInfo);
27
+ windowResizeCallbacks.add(callback);
28
+ }
29
+ function removeWindowResizeCallback(callback) {
30
+ if (typeof callback !== "function") {
31
+ windowResizeCallbacks.clear();
32
+ return;
33
+ }
34
+ windowResizeCallbacks.delete(callback);
35
+ }
36
+
37
+ //#endregion
38
+ export { addWindowResizeCallback, removeWindowResizeCallback };
39
+ //# sourceMappingURL=windowResize.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowResize.mjs","names":[],"sources":["../../../src/runtime/polyfill/windowResize.ts"],"sourcesContent":["interface WindowResizeSnapshot {\n size: {\n windowWidth: number\n windowHeight: number\n }\n windowWidth: number\n windowHeight: number\n}\n\nconst windowResizeCallbacks = new Set<(result: WindowResizeSnapshot) => void>()\nlet windowResizeBridgeBound = false\n\nfunction readWindowResizeResult(getWindowInfo: () => { windowWidth: number, windowHeight: number }) {\n const windowInfo = getWindowInfo()\n return {\n size: {\n windowWidth: windowInfo.windowWidth,\n windowHeight: windowInfo.windowHeight,\n },\n windowWidth: windowInfo.windowWidth,\n windowHeight: windowInfo.windowHeight,\n }\n}\n\nfunction notifyWindowResize(getWindowInfo: () => { windowWidth: number, windowHeight: number }) {\n if (windowResizeCallbacks.size === 0) {\n return\n }\n const result = readWindowResizeResult(getWindowInfo)\n for (const callback of windowResizeCallbacks) {\n callback(result)\n }\n}\n\nfunction bindWindowResizeBridge(getWindowInfo: () => { windowWidth: number, windowHeight: number }) {\n if (windowResizeBridgeBound) {\n return\n }\n windowResizeBridgeBound = true\n const runtimeTarget = (typeof window !== 'undefined'\n ? window\n : globalThis) as {\n addEventListener?: (type: string, listener: () => void) => void\n }\n runtimeTarget.addEventListener?.('resize', () => notifyWindowResize(getWindowInfo))\n}\n\nexport function addWindowResizeCallback(\n callback: (result: WindowResizeSnapshot) => void,\n getWindowInfo: () => { windowWidth: number, windowHeight: number },\n) {\n bindWindowResizeBridge(getWindowInfo)\n windowResizeCallbacks.add(callback)\n}\n\nexport function removeWindowResizeCallback(callback?: (result: WindowResizeSnapshot) => void) {\n if (typeof callback !== 'function') {\n windowResizeCallbacks.clear()\n return\n }\n windowResizeCallbacks.delete(callback)\n}\n"],"mappings":";AASA,MAAM,wCAAwB,IAAI,KAA6C;AAC/E,IAAI,0BAA0B;AAE9B,SAAS,uBAAuB,eAAoE;CAClG,MAAM,aAAa,eAAe;AAClC,QAAO;EACL,MAAM;GACJ,aAAa,WAAW;GACxB,cAAc,WAAW;GAC1B;EACD,aAAa,WAAW;EACxB,cAAc,WAAW;EAC1B;;AAGH,SAAS,mBAAmB,eAAoE;AAC9F,KAAI,sBAAsB,SAAS,EACjC;CAEF,MAAM,SAAS,uBAAuB,cAAc;AACpD,MAAK,MAAM,YAAY,sBACrB,UAAS,OAAO;;AAIpB,SAAS,uBAAuB,eAAoE;AAClG,KAAI,wBACF;AAEF,2BAA0B;AAM1B,EALuB,OAAO,WAAW,cACrC,SACA,YAGU,mBAAmB,gBAAgB,mBAAmB,cAAc,CAAC;;AAGrF,SAAgB,wBACd,UACA,eACA;AACA,wBAAuB,cAAc;AACrC,uBAAsB,IAAI,SAAS;;AAGrC,SAAgB,2BAA2B,UAAmD;AAC5F,KAAI,OAAO,aAAa,YAAY;AAClC,wBAAsB,OAAO;AAC7B;;AAEF,uBAAsB,OAAO,SAAS"}
@@ -0,0 +1,77 @@
1
+ //#region src/runtime/polyfill/worker.ts
2
+ function resolveWorkerPath(path) {
3
+ const normalized = typeof path === "string" ? path.trim() : "";
4
+ if (!normalized) throw new TypeError("createWorker:fail invalid scriptPath");
5
+ try {
6
+ const base = (typeof location !== "undefined" ? location : void 0)?.href;
7
+ if (base) return new URL(normalized, base).toString();
8
+ } catch {}
9
+ return normalized;
10
+ }
11
+ function createWorkerBridge(path) {
12
+ const WorkerCtor = globalThis.Worker;
13
+ if (typeof WorkerCtor !== "function") throw new TypeError("createWorker:fail Worker is unavailable");
14
+ const scriptPath = resolveWorkerPath(path);
15
+ let nativeWorker;
16
+ try {
17
+ nativeWorker = new WorkerCtor(scriptPath);
18
+ } catch (error) {
19
+ const message = error instanceof Error ? error.message : String(error);
20
+ throw new TypeError(`createWorker:fail ${message}`);
21
+ }
22
+ const messageCallbacks = /* @__PURE__ */ new Set();
23
+ const errorCallbacks = /* @__PURE__ */ new Set();
24
+ const handleMessage = (event) => {
25
+ for (const callback of messageCallbacks) callback({ data: event?.data });
26
+ };
27
+ const handleError = (event) => {
28
+ const payload = {
29
+ message: event?.message ?? "unknown error",
30
+ filename: event?.filename,
31
+ lineno: event?.lineno,
32
+ colno: event?.colno
33
+ };
34
+ for (const callback of errorCallbacks) callback(payload);
35
+ };
36
+ if (typeof nativeWorker.addEventListener === "function") {
37
+ nativeWorker.addEventListener("message", handleMessage);
38
+ nativeWorker.addEventListener("error", handleError);
39
+ } else {
40
+ nativeWorker.onmessage = handleMessage;
41
+ nativeWorker.onerror = handleError;
42
+ }
43
+ return {
44
+ postMessage(data) {
45
+ nativeWorker.postMessage(data);
46
+ },
47
+ terminate() {
48
+ nativeWorker.terminate();
49
+ messageCallbacks.clear();
50
+ errorCallbacks.clear();
51
+ },
52
+ onMessage(callback) {
53
+ if (typeof callback === "function") messageCallbacks.add(callback);
54
+ },
55
+ offMessage(callback) {
56
+ if (typeof callback !== "function") {
57
+ messageCallbacks.clear();
58
+ return;
59
+ }
60
+ messageCallbacks.delete(callback);
61
+ },
62
+ onError(callback) {
63
+ if (typeof callback === "function") errorCallbacks.add(callback);
64
+ },
65
+ offError(callback) {
66
+ if (typeof callback !== "function") {
67
+ errorCallbacks.clear();
68
+ return;
69
+ }
70
+ errorCallbacks.delete(callback);
71
+ }
72
+ };
73
+ }
74
+
75
+ //#endregion
76
+ export { createWorkerBridge };
77
+ //# sourceMappingURL=worker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.mjs","names":[],"sources":["../../../src/runtime/polyfill/worker.ts"],"sourcesContent":["type WorkerMessageCallback = (result: { data: unknown }) => void\ntype WorkerErrorCallback = (error: {\n message: string\n filename?: string\n lineno?: number\n colno?: number\n}) => void\n\nfunction resolveWorkerPath(path: unknown) {\n const normalized = typeof path === 'string' ? path.trim() : ''\n if (!normalized) {\n throw new TypeError('createWorker:fail invalid scriptPath')\n }\n try {\n const runtimeLocation = (typeof location !== 'undefined' ? location : undefined) as { href?: string } | undefined\n const base = runtimeLocation?.href\n if (base) {\n return new URL(normalized, base).toString()\n }\n }\n catch {\n // fallback to raw path\n }\n return normalized\n}\n\nexport function createWorkerBridge(path: string) {\n const WorkerCtor = (globalThis as { Worker?: typeof Worker }).Worker\n if (typeof WorkerCtor !== 'function') {\n throw new TypeError('createWorker:fail Worker is unavailable')\n }\n const scriptPath = resolveWorkerPath(path)\n\n let nativeWorker: Worker\n try {\n nativeWorker = new WorkerCtor(scriptPath)\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new TypeError(`createWorker:fail ${message}`)\n }\n\n const messageCallbacks = new Set<WorkerMessageCallback>()\n const errorCallbacks = new Set<WorkerErrorCallback>()\n\n const handleMessage = (event: MessageEvent<unknown>) => {\n for (const callback of messageCallbacks) {\n callback({ data: event?.data })\n }\n }\n const handleError = (event: ErrorEvent) => {\n const payload = {\n message: event?.message ?? 'unknown error',\n filename: event?.filename,\n lineno: event?.lineno,\n colno: event?.colno,\n }\n for (const callback of errorCallbacks) {\n callback(payload)\n }\n }\n\n if (typeof nativeWorker.addEventListener === 'function') {\n nativeWorker.addEventListener('message', handleMessage as EventListener)\n nativeWorker.addEventListener('error', handleError as EventListener)\n }\n else {\n nativeWorker.onmessage = handleMessage as ((this: AbstractWorker, ev: MessageEvent) => any)\n nativeWorker.onerror = handleError as ((this: AbstractWorker, ev: ErrorEvent) => any)\n }\n\n return {\n postMessage(data: unknown) {\n nativeWorker.postMessage(data)\n },\n terminate() {\n nativeWorker.terminate()\n messageCallbacks.clear()\n errorCallbacks.clear()\n },\n onMessage(callback: WorkerMessageCallback) {\n if (typeof callback === 'function') {\n messageCallbacks.add(callback)\n }\n },\n offMessage(callback?: WorkerMessageCallback) {\n if (typeof callback !== 'function') {\n messageCallbacks.clear()\n return\n }\n messageCallbacks.delete(callback)\n },\n onError(callback: WorkerErrorCallback) {\n if (typeof callback === 'function') {\n errorCallbacks.add(callback)\n }\n },\n offError(callback?: WorkerErrorCallback) {\n if (typeof callback !== 'function') {\n errorCallbacks.clear()\n return\n }\n errorCallbacks.delete(callback)\n },\n }\n}\n"],"mappings":";AAQA,SAAS,kBAAkB,MAAe;CACxC,MAAM,aAAa,OAAO,SAAS,WAAW,KAAK,MAAM,GAAG;AAC5D,KAAI,CAAC,WACH,OAAM,IAAI,UAAU,uCAAuC;AAE7D,KAAI;EAEF,MAAM,QADmB,OAAO,aAAa,cAAc,WAAW,SACxC;AAC9B,MAAI,KACF,QAAO,IAAI,IAAI,YAAY,KAAK,CAAC,UAAU;SAGzC;AAGN,QAAO;;AAGT,SAAgB,mBAAmB,MAAc;CAC/C,MAAM,aAAc,WAA0C;AAC9D,KAAI,OAAO,eAAe,WACxB,OAAM,IAAI,UAAU,0CAA0C;CAEhE,MAAM,aAAa,kBAAkB,KAAK;CAE1C,IAAI;AACJ,KAAI;AACF,iBAAe,IAAI,WAAW,WAAW;UAEpC,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,QAAM,IAAI,UAAU,qBAAqB,UAAU;;CAGrD,MAAM,mCAAmB,IAAI,KAA4B;CACzD,MAAM,iCAAiB,IAAI,KAA0B;CAErD,MAAM,iBAAiB,UAAiC;AACtD,OAAK,MAAM,YAAY,iBACrB,UAAS,EAAE,MAAM,OAAO,MAAM,CAAC;;CAGnC,MAAM,eAAe,UAAsB;EACzC,MAAM,UAAU;GACd,SAAS,OAAO,WAAW;GAC3B,UAAU,OAAO;GACjB,QAAQ,OAAO;GACf,OAAO,OAAO;GACf;AACD,OAAK,MAAM,YAAY,eACrB,UAAS,QAAQ;;AAIrB,KAAI,OAAO,aAAa,qBAAqB,YAAY;AACvD,eAAa,iBAAiB,WAAW,cAA+B;AACxE,eAAa,iBAAiB,SAAS,YAA6B;QAEjE;AACH,eAAa,YAAY;AACzB,eAAa,UAAU;;AAGzB,QAAO;EACL,YAAY,MAAe;AACzB,gBAAa,YAAY,KAAK;;EAEhC,YAAY;AACV,gBAAa,WAAW;AACxB,oBAAiB,OAAO;AACxB,kBAAe,OAAO;;EAExB,UAAU,UAAiC;AACzC,OAAI,OAAO,aAAa,WACtB,kBAAiB,IAAI,SAAS;;EAGlC,WAAW,UAAkC;AAC3C,OAAI,OAAO,aAAa,YAAY;AAClC,qBAAiB,OAAO;AACxB;;AAEF,oBAAiB,OAAO,SAAS;;EAEnC,QAAQ,UAA+B;AACrC,OAAI,OAAO,aAAa,WACtB,gBAAe,IAAI,SAAS;;EAGhC,SAAS,UAAgC;AACvC,OAAI,OAAO,aAAa,YAAY;AAClC,mBAAe,OAAO;AACtB;;AAEF,kBAAe,OAAO,SAAS;;EAElC"}
@@ -0,0 +1,5 @@
1
+ import { authorize, checkSession, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort } from "./polyfill/deviceAuthSystemApi.mjs";
2
+ import { getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./polyfill/routeRuntime.mjs";
3
+ import { clearStorage, clearStorageSync, createCanvasContext, createSelectorQuery, createVKSession, createVideoContext, createWorker, downloadFile, exitMiniProgram, getFileSystemManager, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, hideKeyboard, loadSubPackage, navigateToMiniProgram, nextTick, pageScrollTo, preloadSubpackage, removeStorage, removeStorageSync, request, setStorage, setStorageSync, startPullDownRefresh, stopPullDownRefresh, uploadFile } from "./polyfill/runtimeDataApi.mjs";
4
+ import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showToast, updateShareMenu } from "./polyfill/uiMediaApi.mjs";
5
+ import { canIUse, createInterstitialAd, createRewardedVideoAd, getExtConfig, getExtConfigSync, getLogManager, getUpdateManager, hideNavigationBarLoading, reportAnalytics, setBackgroundColor, setBackgroundTextStyle, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading } from "./polyfill/index.mjs";
@@ -0,0 +1,21 @@
1
+ import { TemplateScope } from "./template.mjs";
2
+ import { ComponentPublicInstance } from "./component/types.mjs";
3
+ //#region src/runtime/renderContext.d.ts
4
+ interface RenderContext {
5
+ instance: ComponentPublicInstance;
6
+ eval: (expression: string, scope: TemplateScope, wxs?: Record<string, any>) => any;
7
+ createScope: (parent: TemplateScope, locals?: Record<string, any>) => TemplateScope;
8
+ mergeScope: (parent: TemplateScope, data?: any) => TemplateScope;
9
+ normalizeList: (value: any) => any[];
10
+ key: (rawKey: string, item: any, index: number, scope: TemplateScope, wxs?: Record<string, any>) => any;
11
+ renderTemplate: (templates: Record<string, any>, name: any, scope: TemplateScope, ctx: RenderContext) => any;
12
+ event: (eventName: string, handlerName: any, scope: TemplateScope, wxs?: Record<string, any>, flags?: {
13
+ catch?: boolean;
14
+ capture?: boolean;
15
+ }) => (event: Event) => void;
16
+ createWxsModule: (code: string, id: string, requireMap?: Record<string, any>) => Record<string, any>;
17
+ }
18
+ declare function createRenderContext(instance: ComponentPublicInstance, methods: Record<string, (event: any) => any>): RenderContext;
19
+ //#endregion
20
+ export { RenderContext, createRenderContext };
21
+ //# sourceMappingURL=renderContext.d.mts.map
@@ -0,0 +1,147 @@
1
+ import { emitRuntimeWarning } from "./warning.mjs";
2
+ import { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from "./execution.mjs";
3
+
4
+ //#region src/runtime/renderContext.ts
5
+ const expressionCache = /* @__PURE__ */ new Map();
6
+ const MUSTACHE_PREFIX_RE = /^\{\{\s*/;
7
+ const MUSTACHE_SUFFIX_RE = /\s*\}\}$/;
8
+ const SIMPLE_KEY_PATH_RE = /[.[()]/;
9
+ function createScope(initial) {
10
+ return Object.assign(Object.create(null), initial ?? {});
11
+ }
12
+ function createChildScope(parent, locals) {
13
+ return Object.assign(Object.create(parent), locals ?? {});
14
+ }
15
+ function evaluateExpression(expression, scope) {
16
+ if (!expression) return;
17
+ const trimmed = expression.trim();
18
+ if (!trimmed) return;
19
+ let evaluator = expressionCache.get(trimmed);
20
+ if (!evaluator) {
21
+ try {
22
+ evaluator = new Function("scope", `with(scope){ return (${trimmed}); }`);
23
+ } catch (error) {
24
+ const reason = error instanceof Error ? error.message : String(error);
25
+ if (getRuntimeExecutionMode() === "safe") {
26
+ warnRuntimeExecutionOnce(`safe-expression-parse:${trimmed}`, `[@weapp-vite/web] safe 模式下忽略表达式解析错误 "${trimmed}": ${reason}`);
27
+ evaluator = () => void 0;
28
+ } else throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 "${trimmed}": ${reason}`);
29
+ }
30
+ if (evaluator) expressionCache.set(trimmed, evaluator);
31
+ }
32
+ try {
33
+ return evaluator?.(scope);
34
+ } catch (error) {
35
+ const mode = getRuntimeExecutionMode();
36
+ if (mode === "strict") {
37
+ const reason = error instanceof Error ? error.message : String(error);
38
+ throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 "${trimmed}": ${reason}`);
39
+ }
40
+ if (mode === "safe") {
41
+ const reason = error instanceof Error ? error.message : String(error);
42
+ warnRuntimeExecutionOnce(`safe-expression-runtime:${trimmed}`, `[@weapp-vite/web] safe 模式下忽略表达式执行错误 "${trimmed}": ${reason}`);
43
+ }
44
+ return;
45
+ }
46
+ }
47
+ function normalizeList(value) {
48
+ if (Array.isArray(value)) return value;
49
+ if (value == null) return [];
50
+ if (typeof value === "number" && Number.isFinite(value)) {
51
+ const length = Math.max(0, Math.floor(value));
52
+ return Array.from({ length }, (_, index) => index);
53
+ }
54
+ if (typeof value === "object") return Object.values(value);
55
+ return [];
56
+ }
57
+ function normalizeKey(rawKey, item, index, scope) {
58
+ const key = rawKey?.trim();
59
+ if (!key) {
60
+ if (item != null && (typeof item === "string" || typeof item === "number" || typeof item === "boolean")) return item;
61
+ return index;
62
+ }
63
+ if (key === "*this") return item;
64
+ if (key.includes("{{") && key.includes("}}")) return evaluateExpression(key.replace(MUSTACHE_PREFIX_RE, "").replace(MUSTACHE_SUFFIX_RE, ""), scope);
65
+ if (!SIMPLE_KEY_PATH_RE.test(key) && item && typeof item === "object" && key in item) return item[key];
66
+ return evaluateExpression(key, scope);
67
+ }
68
+ function createEventHandler(instance, methods, eventName, handlerRef, flags) {
69
+ const handler = typeof handlerRef === "function" ? handlerRef : methods[handlerRef] ?? instance[handlerRef];
70
+ if (typeof handler !== "function") return () => {};
71
+ return (nativeEvent) => {
72
+ if (flags?.catch) nativeEvent.stopPropagation();
73
+ const target = nativeEvent.target;
74
+ const dataset = nativeEvent.currentTarget?.dataset ?? {};
75
+ const syntheticEvent = {
76
+ type: eventName,
77
+ timeStamp: nativeEvent.timeStamp,
78
+ detail: nativeEvent.detail ?? nativeEvent.data ?? void 0,
79
+ target: { dataset: target?.dataset ?? dataset },
80
+ currentTarget: { dataset },
81
+ originalEvent: nativeEvent
82
+ };
83
+ handler.call(instance, syntheticEvent);
84
+ };
85
+ }
86
+ function createWxsModule(code, id, requireMap) {
87
+ const module = { exports: {} };
88
+ const exports = module.exports;
89
+ const getRegExp = (pattern, flags) => new RegExp(pattern, flags);
90
+ const getDate = (value) => value == null ? /* @__PURE__ */ new Date() : new Date(value);
91
+ const require = (request) => requireMap?.[request];
92
+ try {
93
+ new Function("module", "exports", "require", "getRegExp", "getDate", code)(module, exports, require, getRegExp, getDate);
94
+ } catch (error) {
95
+ const reason = error instanceof Error ? error.message : String(error);
96
+ if (getRuntimeExecutionMode() === "safe") {
97
+ warnRuntimeExecutionOnce(`safe-wxs-runtime:${id}`, `[@weapp-vite/web] safe 模式下忽略 WXS 执行错误: ${id} ${reason}`);
98
+ return {};
99
+ }
100
+ throw new Error(`[@weapp-vite/web] WXS 执行失败: ${id} ${reason}`);
101
+ }
102
+ return module.exports;
103
+ }
104
+ function createRenderContext(instance, methods) {
105
+ const warnMissingTemplate = (name) => {
106
+ emitRuntimeWarning(`[@weapp-vite/web] 未找到模板: ${name}`, {
107
+ key: `template-missing:${name}`,
108
+ context: "runtime:template"
109
+ });
110
+ };
111
+ return {
112
+ instance,
113
+ eval: (expression, scope, wxs) => {
114
+ const baseScope = scope ?? createScope();
115
+ return evaluateExpression(expression, wxs ? createChildScope(baseScope, wxs) : baseScope);
116
+ },
117
+ createScope: (parent, locals) => createChildScope(parent, locals),
118
+ mergeScope: (parent, data) => {
119
+ const baseScope = parent ?? createScope();
120
+ if (!data || typeof data !== "object") return baseScope;
121
+ return createChildScope(baseScope, data);
122
+ },
123
+ normalizeList,
124
+ key: (rawKey, item, index, scope, wxs) => {
125
+ const baseScope = scope ?? createScope();
126
+ return normalizeKey(rawKey, item, index, wxs ? createChildScope(baseScope, wxs) : baseScope);
127
+ },
128
+ renderTemplate: (templates, name, scope, ctx) => {
129
+ const resolvedName = typeof name === "string" ? name : String(name);
130
+ const template = templates?.[resolvedName];
131
+ if (typeof template !== "function") {
132
+ warnMissingTemplate(resolvedName);
133
+ return "";
134
+ }
135
+ return template(scope, ctx);
136
+ },
137
+ event: (eventName, handlerName, _scope, _wxs, flags) => {
138
+ if (typeof handlerName === "function") return createEventHandler(instance, methods, eventName, handlerName, flags);
139
+ return createEventHandler(instance, methods, eventName, String(handlerName ?? ""), flags);
140
+ },
141
+ createWxsModule
142
+ };
143
+ }
144
+
145
+ //#endregion
146
+ export { createRenderContext };
147
+ //# sourceMappingURL=renderContext.mjs.map
@@ -0,0 +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 { 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 if (evaluator) {\n expressionCache.set(trimmed, evaluator)\n }\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 handler.call(instance, syntheticEvent)\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":"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"}
@@ -0,0 +1,9 @@
1
+ //#region src/runtime/rpx.d.ts
2
+ interface RpxConfig {
3
+ designWidth?: number;
4
+ varName?: string;
5
+ }
6
+ declare function setupRpx(config?: RpxConfig): void;
7
+ //#endregion
8
+ export { RpxConfig, setupRpx };
9
+ //# sourceMappingURL=rpx.d.mts.map
@@ -0,0 +1,27 @@
1
+ //#region src/runtime/rpx.ts
2
+ const DEFAULT_DESIGN_WIDTH = 750;
3
+ const DEFAULT_VAR_NAME = "--rpx";
4
+ let initialized = false;
5
+ function computeRpx(designWidth) {
6
+ if (typeof window === "undefined") return 0;
7
+ return (document.documentElement?.clientWidth ?? window.innerWidth) / designWidth;
8
+ }
9
+ function setupRpx(config) {
10
+ if (typeof document === "undefined") return;
11
+ const designWidth = config?.designWidth ?? DEFAULT_DESIGN_WIDTH;
12
+ const varName = config?.varName ?? DEFAULT_VAR_NAME;
13
+ const root = document.documentElement;
14
+ const apply = () => {
15
+ const value = computeRpx(designWidth);
16
+ root.style.setProperty(varName, `${value}px`);
17
+ };
18
+ apply();
19
+ if (!initialized) {
20
+ initialized = true;
21
+ window.addEventListener("resize", apply);
22
+ }
23
+ }
24
+
25
+ //#endregion
26
+ export { setupRpx };
27
+ //# sourceMappingURL=rpx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpx.mjs","names":[],"sources":["../../src/runtime/rpx.ts"],"sourcesContent":["export interface RpxConfig {\n designWidth?: number\n varName?: string\n}\n\nconst DEFAULT_DESIGN_WIDTH = 750\nconst DEFAULT_VAR_NAME = '--rpx'\nlet initialized = false\n\nfunction computeRpx(designWidth: number) {\n if (typeof window === 'undefined') {\n return 0\n }\n const width = document.documentElement?.clientWidth ?? window.innerWidth\n return width / designWidth\n}\n\nexport function setupRpx(config?: RpxConfig) {\n if (typeof document === 'undefined') {\n return\n }\n const designWidth = config?.designWidth ?? DEFAULT_DESIGN_WIDTH\n const varName = config?.varName ?? DEFAULT_VAR_NAME\n const root = document.documentElement\n const apply = () => {\n const value = computeRpx(designWidth)\n root.style.setProperty(varName, `${value}px`)\n }\n apply()\n if (!initialized) {\n initialized = true\n window.addEventListener('resize', apply)\n }\n}\n"],"mappings":";AAKA,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AACzB,IAAI,cAAc;AAElB,SAAS,WAAW,aAAqB;AACvC,KAAI,OAAO,WAAW,YACpB,QAAO;AAGT,SADc,SAAS,iBAAiB,eAAe,OAAO,cAC/C;;AAGjB,SAAgB,SAAS,QAAoB;AAC3C,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,SAAS;CACtB,MAAM,cAAc;EAClB,MAAM,QAAQ,WAAW,YAAY;AACrC,OAAK,MAAM,YAAY,SAAS,GAAG,MAAM,IAAI;;AAE/C,QAAO;AACP,KAAI,CAAC,aAAa;AAChB,gBAAc;AACd,SAAO,iBAAiB,UAAU,MAAM"}
@@ -0,0 +1,6 @@
1
+ //#region src/runtime/style.d.ts
2
+ declare function removeStyle(id: string): void;
3
+ declare function injectStyle(css: string, id?: string): () => void;
4
+ //#endregion
5
+ export { injectStyle, removeStyle };
6
+ //# sourceMappingURL=style.d.mts.map
@@ -0,0 +1,37 @@
1
+ //#region src/runtime/style.ts
2
+ const injected = /* @__PURE__ */ new Map();
3
+ function createStyleId(css) {
4
+ let hash = 2166136261;
5
+ for (let i = 0; i < css.length; i++) {
6
+ hash ^= css.charCodeAt(i);
7
+ hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
8
+ }
9
+ return `weapp-web-style-${(hash >>> 0).toString(36)}`;
10
+ }
11
+ function removeStyle(id) {
12
+ if (typeof document === "undefined") return;
13
+ const style = injected.get(id);
14
+ if (style) {
15
+ style.remove();
16
+ injected.delete(id);
17
+ }
18
+ }
19
+ function injectStyle(css, id) {
20
+ if (typeof document === "undefined") return () => {};
21
+ const styleId = id ?? createStyleId(css);
22
+ const existing = injected.get(styleId);
23
+ if (existing) {
24
+ existing.textContent = css;
25
+ return () => removeStyle(styleId);
26
+ }
27
+ const style = document.createElement("style");
28
+ style.id = styleId;
29
+ style.textContent = css;
30
+ document.head.append(style);
31
+ injected.set(styleId, style);
32
+ return () => removeStyle(styleId);
33
+ }
34
+
35
+ //#endregion
36
+ export { injectStyle, removeStyle };
37
+ //# sourceMappingURL=style.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.mjs","names":[],"sources":["../../src/runtime/style.ts"],"sourcesContent":["const injected = new Map<string, HTMLStyleElement>()\n\nfunction createStyleId(css: string) {\n let hash = 2166136261\n for (let i = 0; i < css.length; i++) {\n hash ^= css.charCodeAt(i)\n hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)\n }\n return `weapp-web-style-${(hash >>> 0).toString(36)}`\n}\n\nexport function removeStyle(id: string) {\n if (typeof document === 'undefined') {\n return\n }\n const style = injected.get(id)\n if (style) {\n style.remove()\n injected.delete(id)\n }\n}\n\nexport function injectStyle(css: string, id?: string) {\n if (typeof document === 'undefined') {\n return () => {}\n }\n const styleId = id ?? createStyleId(css)\n const existing = injected.get(styleId)\n if (existing) {\n existing.textContent = css\n return () => removeStyle(styleId)\n }\n const style = document.createElement('style')\n style.id = styleId\n style.textContent = css\n document.head.append(style)\n injected.set(styleId, style)\n return () => removeStyle(styleId)\n}\n"],"mappings":";AAAA,MAAM,2BAAW,IAAI,KAA+B;AAEpD,SAAS,cAAc,KAAa;CAClC,IAAI,OAAO;AACX,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAQ,IAAI,WAAW,EAAE;AACzB,WAAS,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ;;AAE3E,QAAO,oBAAoB,SAAS,GAAG,SAAS,GAAG;;AAGrD,SAAgB,YAAY,IAAY;AACtC,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,QAAQ,SAAS,IAAI,GAAG;AAC9B,KAAI,OAAO;AACT,QAAM,QAAQ;AACd,WAAS,OAAO,GAAG;;;AAIvB,SAAgB,YAAY,KAAa,IAAa;AACpD,KAAI,OAAO,aAAa,YACtB,cAAa;CAEf,MAAM,UAAU,MAAM,cAAc,IAAI;CACxC,MAAM,WAAW,SAAS,IAAI,QAAQ;AACtC,KAAI,UAAU;AACZ,WAAS,cAAc;AACvB,eAAa,YAAY,QAAQ;;CAEnC,MAAM,QAAQ,SAAS,cAAc,QAAQ;AAC7C,OAAM,KAAK;AACX,OAAM,cAAc;AACpB,UAAS,KAAK,OAAO,MAAM;AAC3B,UAAS,IAAI,SAAS,MAAM;AAC5B,cAAa,YAAY,QAAQ"}
@@ -0,0 +1,10 @@
1
+ import { RenderContext } from "./renderContext.mjs";
2
+ import { createTemplate, renderTemplate } from "./legacyTemplate/index.mjs";
3
+ import { TemplateResult } from "lit";
4
+
5
+ //#region src/runtime/template.d.ts
6
+ type TemplateScope = Record<string, any>;
7
+ type TemplateRenderer = (scope: TemplateScope, ctx: RenderContext) => TemplateResult | string | unknown;
8
+ //#endregion
9
+ export { TemplateRenderer, TemplateScope };
10
+ //# sourceMappingURL=template.d.mts.map
@@ -0,0 +1,10 @@
1
+ //#region src/runtime/warning.d.ts
2
+ type RuntimeWarningLevel = 'off' | 'warn' | 'error';
3
+ interface RuntimeWarningOptions {
4
+ level?: RuntimeWarningLevel;
5
+ dedupe?: boolean;
6
+ }
7
+ declare function setRuntimeWarningOptions(options?: RuntimeWarningOptions): void;
8
+ //#endregion
9
+ export { RuntimeWarningLevel, RuntimeWarningOptions, setRuntimeWarningOptions };
10
+ //# sourceMappingURL=warning.d.mts.map
@@ -0,0 +1,43 @@
1
+ //#region src/runtime/warning.ts
2
+ const defaultWarningOptions = {
3
+ level: "warn",
4
+ dedupe: true
5
+ };
6
+ let runtimeWarningOptions = { ...defaultWarningOptions };
7
+ const warnedKeys = /* @__PURE__ */ new Set();
8
+ function withContext(message, context) {
9
+ if (!context) return message;
10
+ if (message.startsWith("[@weapp-vite/web]")) return message.replace("[@weapp-vite/web]", `[@weapp-vite/web][${context}]`);
11
+ return `[@weapp-vite/web][${context}] ${message}`;
12
+ }
13
+ function getConsole() {
14
+ return globalThis.console;
15
+ }
16
+ function setRuntimeWarningOptions(options) {
17
+ runtimeWarningOptions = {
18
+ ...defaultWarningOptions,
19
+ ...options ?? {}
20
+ };
21
+ warnedKeys.clear();
22
+ }
23
+ function emitRuntimeWarning(message, options = {}) {
24
+ const level = options.level ?? runtimeWarningOptions.level;
25
+ if (level === "off") return;
26
+ const key = options.key;
27
+ if (runtimeWarningOptions.dedupe && key) {
28
+ if (warnedKeys.has(key)) return;
29
+ warnedKeys.add(key);
30
+ }
31
+ const logger = getConsole();
32
+ if (!logger) return;
33
+ const normalized = withContext(message, options.context);
34
+ if (level === "error" && typeof logger.error === "function") {
35
+ logger.error(normalized);
36
+ return;
37
+ }
38
+ if (typeof logger.warn === "function") logger.warn(normalized);
39
+ }
40
+
41
+ //#endregion
42
+ export { emitRuntimeWarning, setRuntimeWarningOptions };
43
+ //# sourceMappingURL=warning.mjs.map