@weapp-vite/web 1.3.36 → 1.4.0
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.
- package/README.md +144 -5
- package/dist/_virtual/_rolldown/runtime.mjs +19 -1
- package/dist/compiler/wxml/attributes.mjs +1 -1
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs +6 -3
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/interpolation.mjs +1 -2
- package/dist/compiler/wxml/interpolation.mjs.map +1 -1
- package/dist/compiler/wxml/navigation.mjs +5 -7
- package/dist/compiler/wxml/navigation.mjs.map +1 -1
- package/dist/compiler/wxml/parser.mjs +5 -5
- package/dist/compiler/wxml/parser.mjs.map +1 -1
- package/dist/compiler/wxml/renderer.mjs +13 -12
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +6 -1
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/compiler/wxml/types.d.mts +12 -0
- package/dist/compiler/wxs.mjs +5 -5
- package/dist/compiler/wxs.mjs.map +1 -1
- package/dist/css/wxss.d.mts +1 -0
- package/dist/css/wxss.mjs +110 -9
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/index.d.mts +29 -6
- package/dist/index.mjs +197 -4
- package/dist/index.mjs.map +1 -0
- package/dist/plugin/assets.d.mts +7 -0
- package/dist/plugin/assets.mjs +122 -0
- package/dist/plugin/assets.mjs.map +1 -0
- package/dist/plugin/constants.mjs +10 -1
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/dependencyScan.mjs +41 -0
- package/dist/plugin/dependencyScan.mjs.map +1 -0
- package/dist/plugin/entry.mjs +56 -7
- package/dist/plugin/entry.mjs.map +1 -1
- package/dist/plugin/files.mjs +1 -1
- package/dist/plugin/files.mjs.map +1 -1
- package/dist/plugin/index.d.mts +37 -3
- package/dist/plugin/index.mjs +245 -74
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/layout.mjs +24 -0
- package/dist/plugin/layout.mjs.map +1 -0
- package/dist/plugin/path.mjs +4 -1
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/register.mjs +48 -36
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/scan.mjs +206 -94
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/scanSfc.mjs +65 -0
- package/dist/plugin/scanSfc.mjs.map +1 -0
- package/dist/plugin/state.mjs +3 -2
- package/dist/plugin/state.mjs.map +1 -1
- package/dist/plugin/styleModule.mjs +52 -0
- package/dist/plugin/styleModule.mjs.map +1 -0
- package/dist/plugin/types.d.mts +46 -1
- package/dist/plugin/vueSfc.mjs +149 -0
- package/dist/plugin/vueSfc.mjs.map +1 -0
- package/dist/runtime/appShell/container.mjs +25 -0
- package/dist/runtime/appShell/container.mjs.map +1 -0
- package/dist/runtime/appShell/tabBar/index.mjs +192 -0
- package/dist/runtime/appShell/tabBar/index.mjs.map +1 -0
- package/dist/runtime/appShell/tabBar/style.mjs +127 -0
- package/dist/runtime/appShell/tabBar/style.mjs.map +1 -0
- package/dist/runtime/button/helpers.mjs +1 -58
- package/dist/runtime/button/helpers.mjs.map +1 -1
- package/dist/runtime/button/index.d.mts +4 -5
- package/dist/runtime/button/index.mjs +6 -28
- package/dist/runtime/button/index.mjs.map +1 -1
- package/dist/runtime/button/style.mjs +53 -28
- package/dist/runtime/button/style.mjs.map +1 -1
- package/dist/runtime/component/behavior.mjs +26 -2
- package/dist/runtime/component/behavior.mjs.map +1 -1
- package/dist/runtime/component/element.mjs +107 -31
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/observers.mjs +36 -0
- package/dist/runtime/component/observers.mjs.map +1 -0
- package/dist/runtime/component/publicInstance.mjs +48 -0
- package/dist/runtime/component/publicInstance.mjs.map +1 -0
- package/dist/runtime/component/relations.mjs +35 -0
- package/dist/runtime/component/relations.mjs.map +1 -0
- package/dist/runtime/component/slots.mjs +24 -0
- package/dist/runtime/component/slots.mjs.map +1 -0
- package/dist/runtime/component/state.mjs +13 -3
- package/dist/runtime/component/state.mjs.map +1 -1
- package/dist/runtime/component/types.d.mts +29 -4
- package/dist/runtime/component/virtualHost.mjs +83 -0
- package/dist/runtime/component/virtualHost.mjs.map +1 -0
- package/dist/runtime/host/index.d.mts +13 -0
- package/dist/runtime/host/index.mjs +47 -0
- package/dist/runtime/host/index.mjs.map +1 -0
- package/dist/runtime/host/types.d.mts +28 -0
- package/dist/runtime/hostGlobals.d.mts +9 -0
- package/dist/runtime/hostGlobals.mjs +39 -0
- package/dist/runtime/hostGlobals.mjs.map +1 -0
- package/dist/runtime/index.d.mts +21 -3
- package/dist/runtime/index.mjs +26 -4
- package/dist/runtime/index.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/dom.mjs +3 -3
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/expression.mjs +9 -9
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.mjs +6 -6
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/canvas/index.mjs +53 -0
- package/dist/runtime/nativeComponents/canvas/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/checkbox.mjs +137 -0
- package/dist/runtime/nativeComponents/checkbox.mjs.map +1 -0
- package/dist/runtime/nativeComponents/cover/index.mjs +23 -0
- package/dist/runtime/nativeComponents/cover/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/form.d.mts +7 -0
- package/dist/runtime/nativeComponents/form.mjs +50 -0
- package/dist/runtime/nativeComponents/form.mjs.map +1 -0
- package/dist/runtime/nativeComponents/formControl.mjs +61 -0
- package/dist/runtime/nativeComponents/formControl.mjs.map +1 -0
- package/dist/runtime/nativeComponents/helpers.mjs +25 -0
- package/dist/runtime/nativeComponents/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/helpers.mjs +42 -0
- package/dist/runtime/nativeComponents/icon/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/index.mjs +45 -0
- package/dist/runtime/nativeComponents/icon/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/icon/style.mjs +176 -0
- package/dist/runtime/nativeComponents/icon/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/image.d.mts +8 -0
- package/dist/runtime/nativeComponents/image.mjs +121 -0
- package/dist/runtime/nativeComponents/image.mjs.map +1 -0
- package/dist/runtime/nativeComponents/index.d.mts +11 -0
- package/dist/runtime/nativeComponents/index.mjs +83 -0
- package/dist/runtime/nativeComponents/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/input.d.mts +8 -0
- package/dist/runtime/nativeComponents/input.mjs +131 -0
- package/dist/runtime/nativeComponents/input.mjs.map +1 -0
- package/dist/runtime/nativeComponents/label.mjs +36 -0
- package/dist/runtime/nativeComponents/label.mjs.map +1 -0
- package/dist/runtime/nativeComponents/mediaRegistry.mjs +47 -0
- package/dist/runtime/nativeComponents/mediaRegistry.mjs.map +1 -0
- package/dist/runtime/nativeComponents/movable/helpers.mjs +23 -0
- package/dist/runtime/nativeComponents/movable/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/movable/index.mjs +117 -0
- package/dist/runtime/nativeComponents/movable/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/navigator.mjs +200 -0
- package/dist/runtime/nativeComponents/navigator.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/editors.mjs +74 -0
- package/dist/runtime/nativeComponents/picker/editors.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/helpers.mjs +57 -0
- package/dist/runtime/nativeComponents/picker/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/index.mjs +210 -0
- package/dist/runtime/nativeComponents/picker/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/picker/style.mjs +71 -0
- package/dist/runtime/nativeComponents/picker/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/column.mjs +134 -0
- package/dist/runtime/nativeComponents/pickerView/column.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/helpers.mjs +17 -0
- package/dist/runtime/nativeComponents/pickerView/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/index.mjs +128 -0
- package/dist/runtime/nativeComponents/pickerView/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/pickerView/style.mjs +58 -0
- package/dist/runtime/nativeComponents/pickerView/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/primitives.mjs +16 -0
- package/dist/runtime/nativeComponents/primitives.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/helpers.mjs +29 -0
- package/dist/runtime/nativeComponents/progress/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/index.mjs +130 -0
- package/dist/runtime/nativeComponents/progress/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/progress/style.mjs +40 -0
- package/dist/runtime/nativeComponents/progress/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/radio.mjs +147 -0
- package/dist/runtime/nativeComponents/radio.mjs.map +1 -0
- package/dist/runtime/nativeComponents/richText/helpers.mjs +230 -0
- package/dist/runtime/nativeComponents/richText/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/richText/index.mjs +74 -0
- package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/scrollView.d.mts +15 -0
- package/dist/runtime/nativeComponents/scrollView.mjs +79 -0
- package/dist/runtime/nativeComponents/scrollView.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/helpers.mjs +28 -0
- package/dist/runtime/nativeComponents/slider/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/index.mjs +120 -0
- package/dist/runtime/nativeComponents/slider/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/style.mjs +60 -0
- package/dist/runtime/nativeComponents/slider/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/style.mjs +41 -0
- package/dist/runtime/nativeComponents/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/helpers.mjs +52 -0
- package/dist/runtime/nativeComponents/swiper/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/index.mjs +235 -0
- package/dist/runtime/nativeComponents/swiper/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/item.mjs +14 -0
- package/dist/runtime/nativeComponents/swiper/item.mjs.map +1 -0
- package/dist/runtime/nativeComponents/swiper/style.mjs +20 -0
- package/dist/runtime/nativeComponents/swiper/style.mjs.map +1 -0
- package/dist/runtime/nativeComponents/switch.d.mts +7 -0
- package/dist/runtime/nativeComponents/switch.mjs +132 -0
- package/dist/runtime/nativeComponents/switch.mjs.map +1 -0
- package/dist/runtime/nativeComponents/textarea.d.mts +9 -0
- package/dist/runtime/nativeComponents/textarea.mjs +144 -0
- package/dist/runtime/nativeComponents/textarea.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/helpers.d.mts +12 -0
- package/dist/runtime/nativeComponents/video/helpers.mjs +21 -0
- package/dist/runtime/nativeComponents/video/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/index.mjs +124 -0
- package/dist/runtime/nativeComponents/video/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/video/style.mjs +14 -0
- package/dist/runtime/nativeComponents/video/style.mjs.map +1 -0
- package/dist/runtime/navigationBar/index.mjs +1 -3
- package/dist/runtime/navigationBar/index.mjs.map +1 -1
- package/dist/runtime/pageLayout.d.mts +9 -0
- package/dist/runtime/pageLayout.mjs +16 -0
- package/dist/runtime/pageLayout.mjs.map +1 -0
- package/dist/runtime/polyfill/animation.mjs +120 -0
- package/dist/runtime/polyfill/animation.mjs.map +1 -0
- package/dist/runtime/polyfill/appState.mjs +1 -1
- package/dist/runtime/polyfill/appState.mjs.map +1 -1
- package/dist/runtime/polyfill/async.d.mts +7 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -1
- package/dist/runtime/polyfill/canvasContext.mjs +41 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
- package/dist/runtime/polyfill/device.mjs +1 -1
- package/dist/runtime/polyfill/device.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +8 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/eventBus.mjs +56 -0
- package/dist/runtime/polyfill/eventBus.mjs.map +1 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs +5 -2
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
- package/dist/runtime/polyfill/files.mjs +10 -10
- package/dist/runtime/polyfill/files.mjs.map +1 -1
- package/dist/runtime/polyfill/font.mjs +32 -0
- package/dist/runtime/polyfill/font.mjs.map +1 -0
- package/dist/runtime/polyfill/index.d.mts +2 -2
- package/dist/runtime/polyfill/index.mjs +49 -45
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interaction.mjs +7 -6
- package/dist/runtime/polyfill/interaction.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +3 -2
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/intersectionObserver.mjs +106 -0
- package/dist/runtime/polyfill/intersectionObserver.mjs.map +1 -0
- package/dist/runtime/polyfill/locale.mjs +14 -0
- package/dist/runtime/polyfill/locale.mjs.map +1 -0
- package/dist/runtime/polyfill/locationApi.mjs +7 -4
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaActions.mjs +2 -2
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +1 -1
- package/dist/runtime/polyfill/mediaApi/info.mjs +6 -4
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +38 -4
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +6 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/network/request.mjs +2 -2
- package/dist/runtime/polyfill/network/request.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +1 -1
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +88 -0
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +44 -15
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/history.d.mts +30 -0
- package/dist/runtime/polyfill/routeRuntime/history.mjs +148 -0
- package/dist/runtime/polyfill/routeRuntime/history.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +39 -8
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +11 -1
- package/dist/runtime/polyfill/routeRuntime/options.mjs +0 -1
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/result.mjs +12 -0
- package/dist/runtime/polyfill/routeRuntime/result.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs +39 -0
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/stack.mjs +122 -0
- package/dist/runtime/polyfill/routeRuntime/stack.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +26 -17
- package/dist/runtime/polyfill/routeRuntime.mjs +121 -96
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.mjs +8 -3
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeOps.mjs +10 -6
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/selectorQuery.mjs +70 -14
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.mjs +5 -2
- package/dist/runtime/polyfill/storage.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +30 -3
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +1 -4
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +9 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +20 -9
- package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +25 -0
- package/dist/runtime/polyfill/ui.mjs +2 -6
- package/dist/runtime/polyfill/ui.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.d.mts +11 -10
- package/dist/runtime/polyfill/uiMediaApi.mjs +26 -2
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/runtime/polyfill/videoContext.mjs +4 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
- package/dist/runtime/polyfill/vkSession.mjs +4 -14
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
- package/dist/runtime/polyfill.d.mts +2 -2
- package/dist/runtime/renderContext.mjs +1 -1
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.mjs +17 -8
- package/dist/runtime/rpx.mjs.map +1 -1
- package/dist/runtime/seo/index.d.mts +31 -0
- package/dist/runtime/seo/index.mjs +94 -0
- package/dist/runtime/seo/index.mjs.map +1 -0
- package/dist/runtime/viewport/index.d.mts +12 -0
- package/dist/runtime/viewport/index.mjs +44 -0
- package/dist/runtime/viewport/index.mjs.map +1 -0
- package/dist/runtime/viewport/style.mjs +62 -0
- package/dist/runtime/viewport/style.mjs.map +1 -0
- package/dist/runtime/viewport/types.d.mts +14 -0
- package/dist/runtime/wevu.d.mts +20 -0
- package/dist/runtime/wevu.mjs +73 -0
- package/dist/runtime/wevu.mjs.map +1 -0
- package/dist/shared/nativeComponents.mjs +401 -0
- package/dist/shared/nativeComponents.mjs.map +1 -0
- package/dist/shared/tabBar.d.mts +19 -0
- package/dist/shared/tabBar.mjs +37 -0
- package/dist/shared/tabBar.mjs.map +1 -0
- package/dist/shared/wxml.mjs +3 -20
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +13 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/runtime/component/observers.ts
|
|
2
|
+
function normalizeObserverPattern(pattern) {
|
|
3
|
+
return pattern.split(",").map((item) => item.trim()).filter(Boolean);
|
|
4
|
+
}
|
|
5
|
+
function hasOwn(value, key) {
|
|
6
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
7
|
+
}
|
|
8
|
+
function resolveObservedValue(instance, pattern) {
|
|
9
|
+
if (pattern === "**") return {
|
|
10
|
+
...instance.properties,
|
|
11
|
+
...instance.data
|
|
12
|
+
};
|
|
13
|
+
const [root, ...rest] = pattern.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
14
|
+
let current = hasOwn(instance.properties, root) ? instance.properties[root] : instance.data[root];
|
|
15
|
+
for (const segment of rest) current = current?.[segment];
|
|
16
|
+
return current;
|
|
17
|
+
}
|
|
18
|
+
function matchesObserverPattern(pattern, changedKeys) {
|
|
19
|
+
if (pattern === "**") return changedKeys.length > 0;
|
|
20
|
+
return normalizeObserverPattern(pattern).some((observedKey) => {
|
|
21
|
+
if (observedKey === "**") return true;
|
|
22
|
+
return changedKeys.some((changedKey) => changedKey === observedKey || changedKey.startsWith(`${observedKey}.`) || changedKey.startsWith(`${observedKey}[`));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function runComponentObservers(component, instance, changedKeys, previousProperties = {}) {
|
|
26
|
+
if (!changedKeys.length) return;
|
|
27
|
+
for (const changedKey of changedKeys) (component.properties?.[changedKey])?.observer?.call(instance, instance.properties[changedKey], previousProperties[changedKey]);
|
|
28
|
+
for (const [pattern, observer] of Object.entries(component.observers ?? {})) {
|
|
29
|
+
if (typeof observer !== "function" || !matchesObserverPattern(pattern, changedKeys)) continue;
|
|
30
|
+
observer.call(instance, ...normalizeObserverPattern(pattern).map((item) => resolveObservedValue(instance, item)));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { runComponentObservers };
|
|
36
|
+
//# sourceMappingURL=observers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observers.mjs","names":[],"sources":["../../../src/runtime/component/observers.ts"],"sourcesContent":["import type {\n ComponentPublicInstance,\n DataRecord,\n NormalizedComponentOptions,\n} from './types'\n\nfunction normalizeObserverPattern(pattern: string) {\n return pattern.split(',').map(item => item.trim()).filter(Boolean)\n}\n\nfunction hasOwn(value: object, key: PropertyKey) {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction resolveObservedValue(instance: ComponentPublicInstance, pattern: string) {\n if (pattern === '**') {\n return {\n ...instance.properties,\n ...instance.data,\n }\n }\n\n const segments = pattern\n .replace(/\\[(\\d+)\\]/g, '.$1')\n .split('.')\n .filter(Boolean)\n const [root, ...rest] = segments as [string, ...string[]]\n let current = hasOwn(instance.properties, root)\n ? instance.properties[root]\n : instance.data[root]\n for (const segment of rest) {\n current = current?.[segment]\n }\n return current\n}\n\nfunction matchesObserverPattern(pattern: string, changedKeys: string[]) {\n if (pattern === '**') {\n return changedKeys.length > 0\n }\n return normalizeObserverPattern(pattern).some((observedKey) => {\n if (observedKey === '**') {\n return true\n }\n return changedKeys.some(changedKey => (\n changedKey === observedKey\n || changedKey.startsWith(`${observedKey}.`)\n || changedKey.startsWith(`${observedKey}[`)\n ))\n })\n}\n\nexport function runComponentObservers(\n component: NormalizedComponentOptions,\n instance: ComponentPublicInstance,\n changedKeys: string[],\n previousProperties: DataRecord = {},\n) {\n if (!changedKeys.length) {\n return\n }\n\n for (const changedKey of changedKeys) {\n const option = component.properties?.[changedKey]\n option?.observer?.call(\n instance,\n instance.properties[changedKey],\n previousProperties[changedKey],\n )\n }\n\n for (const [pattern, observer] of Object.entries(component.observers ?? {})) {\n if (typeof observer !== 'function' || !matchesObserverPattern(pattern, changedKeys)) {\n continue\n }\n observer.call(\n instance,\n ...normalizeObserverPattern(pattern).map(item => resolveObservedValue(instance, item)),\n )\n }\n}\n"],"mappings":";AAMA,SAAS,yBAAyB,SAAiB;CACjD,OAAO,QAAQ,MAAM,GAAG,CAAC,CAAC,KAAI,SAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO;AACnE;AAEA,SAAS,OAAO,OAAe,KAAkB;CAC/C,OAAO,OAAO,UAAU,eAAe,KAAK,OAAO,GAAG;AACxD;AAEA,SAAS,qBAAqB,UAAmC,SAAiB;CAChF,IAAI,YAAY,MACd,OAAO;EACL,GAAG,SAAS;EACZ,GAAG,SAAS;CACd;CAOF,MAAM,CAAC,MAAM,GAAG,QAJC,QACd,QAAQ,cAAc,KAAK,CAAC,CAC5B,MAAM,GAAG,CAAC,CACV,OAAO,OACqB;CAC/B,IAAI,UAAU,OAAO,SAAS,YAAY,IAAI,IAC1C,SAAS,WAAW,QACpB,SAAS,KAAK;CAClB,KAAK,MAAM,WAAW,MACpB,UAAU,UAAU;CAEtB,OAAO;AACT;AAEA,SAAS,uBAAuB,SAAiB,aAAuB;CACtE,IAAI,YAAY,MACd,OAAO,YAAY,SAAS;CAE9B,OAAO,yBAAyB,OAAO,CAAC,CAAC,MAAM,gBAAgB;EAC7D,IAAI,gBAAgB,MAClB,OAAO;EAET,OAAO,YAAY,MAAK,eACtB,eAAe,eACZ,WAAW,WAAW,GAAG,YAAY,EAAE,KACvC,WAAW,WAAW,GAAG,YAAY,EAAE,CAC3C;CACH,CAAC;AACH;AAEA,SAAgB,sBACd,WACA,UACA,aACA,qBAAiC,CAAC,GAClC;CACA,IAAI,CAAC,YAAY,QACf;CAGF,KAAK,MAAM,cAAc,aAEvB,CADe,UAAU,aAAa,YAChC,EAAE,UAAU,KAChB,UACA,SAAS,WAAW,aACpB,mBAAmB,WACrB;CAGF,KAAK,MAAM,CAAC,SAAS,aAAa,OAAO,QAAQ,UAAU,aAAa,CAAC,CAAC,GAAG;EAC3E,IAAI,OAAO,aAAa,cAAc,CAAC,uBAAuB,SAAS,WAAW,GAChF;EAEF,SAAS,KACP,UACA,GAAG,yBAAyB,OAAO,CAAC,CAAC,KAAI,SAAQ,qBAAqB,UAAU,IAAI,CAAC,CACvF;CACF;AACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/runtime/component/publicInstance.ts
|
|
2
|
+
const componentPublicInstanceTargets = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function resolveComponentPublicInstanceTarget(value) {
|
|
4
|
+
if (!value || typeof value !== "object") return;
|
|
5
|
+
return componentPublicInstanceTargets.get(value);
|
|
6
|
+
}
|
|
7
|
+
function createComponentPublicInstance(target, runtimePrototype, resolveComponentMethod) {
|
|
8
|
+
const runtimeMethods = /* @__PURE__ */ new Map();
|
|
9
|
+
const publicInstance = new Proxy(target, {
|
|
10
|
+
get(instance, key) {
|
|
11
|
+
if (Reflect.getOwnPropertyDescriptor(instance, key)) return Reflect.get(instance, key, instance);
|
|
12
|
+
if (Reflect.getOwnPropertyDescriptor(runtimePrototype, key)) {
|
|
13
|
+
const value = Reflect.get(instance, key, instance);
|
|
14
|
+
if (typeof value !== "function") return value;
|
|
15
|
+
const cached = runtimeMethods.get(key);
|
|
16
|
+
if (cached && cached.source === value) return cached.bound;
|
|
17
|
+
const bound = value.bind(instance);
|
|
18
|
+
runtimeMethods.set(key, {
|
|
19
|
+
source: value,
|
|
20
|
+
bound
|
|
21
|
+
});
|
|
22
|
+
return bound;
|
|
23
|
+
}
|
|
24
|
+
const componentMethod = resolveComponentMethod?.(key);
|
|
25
|
+
if (typeof componentMethod === "function") return componentMethod;
|
|
26
|
+
return typeof key === "symbol" ? Reflect.get(instance, key, instance) : void 0;
|
|
27
|
+
},
|
|
28
|
+
set(instance, key, value) {
|
|
29
|
+
if (Reflect.getOwnPropertyDescriptor(instance, key) || typeof key === "symbol") return Reflect.set(instance, key, value, instance);
|
|
30
|
+
Reflect.defineProperty(instance, key, {
|
|
31
|
+
configurable: true,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
has(instance, key) {
|
|
39
|
+
return Reflect.getOwnPropertyDescriptor(instance, key) !== void 0 || Reflect.getOwnPropertyDescriptor(runtimePrototype, key) !== void 0 || typeof resolveComponentMethod?.(key) === "function" || typeof key === "symbol" && Reflect.has(instance, key);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
componentPublicInstanceTargets.set(publicInstance, target);
|
|
43
|
+
return publicInstance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createComponentPublicInstance, resolveComponentPublicInstanceTarget };
|
|
48
|
+
//# sourceMappingURL=publicInstance.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicInstance.mjs","names":[],"sources":["../../../src/runtime/component/publicInstance.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\n\nconst componentPublicInstanceTargets = new WeakMap<object, ComponentPublicInstance>()\n\nexport function resolveComponentPublicInstanceTarget(value: unknown) {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n return componentPublicInstanceTargets.get(value)\n}\n\nexport function createComponentPublicInstance(\n target: ComponentPublicInstance,\n runtimePrototype: object,\n resolveComponentMethod?: (key: PropertyKey) => unknown,\n): ComponentPublicInstance {\n type RuntimeMethod = (...args: any[]) => unknown\n const runtimeMethods = new Map<PropertyKey, { source: RuntimeMethod, bound: RuntimeMethod }>()\n\n const publicInstance = new Proxy(target, {\n get(instance, key) {\n const ownDescriptor = Reflect.getOwnPropertyDescriptor(instance, key)\n if (ownDescriptor) {\n return Reflect.get(instance, key, instance)\n }\n const runtimeDescriptor = Reflect.getOwnPropertyDescriptor(runtimePrototype, key)\n if (runtimeDescriptor) {\n const value = Reflect.get(instance, key, instance)\n if (typeof value !== 'function') {\n return value\n }\n const cached = runtimeMethods.get(key)\n if (cached && cached.source === value) {\n return cached.bound\n }\n const bound = value.bind(instance)\n runtimeMethods.set(key, { source: value, bound })\n return bound\n }\n const componentMethod = resolveComponentMethod?.(key)\n if (typeof componentMethod === 'function') {\n return componentMethod\n }\n return typeof key === 'symbol' ? Reflect.get(instance, key, instance) : undefined\n },\n set(instance, key, value) {\n if (Reflect.getOwnPropertyDescriptor(instance, key) || typeof key === 'symbol') {\n return Reflect.set(instance, key, value, instance)\n }\n Reflect.defineProperty(instance, key, {\n configurable: true,\n enumerable: true,\n writable: true,\n value,\n })\n return true\n },\n has(instance, key) {\n return Reflect.getOwnPropertyDescriptor(instance, key) !== undefined\n || Reflect.getOwnPropertyDescriptor(runtimePrototype, key) !== undefined\n || typeof resolveComponentMethod?.(key) === 'function'\n || (typeof key === 'symbol' && Reflect.has(instance, key))\n },\n })\n componentPublicInstanceTargets.set(publicInstance, target)\n return publicInstance\n}\n"],"mappings":";AAEA,MAAM,iDAAiC,IAAI,QAAyC;AAEpF,SAAgB,qCAAqC,OAAgB;CACnE,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B;CAEF,OAAO,+BAA+B,IAAI,KAAK;AACjD;AAEA,SAAgB,8BACd,QACA,kBACA,wBACyB;CAEzB,MAAM,iCAAiB,IAAI,IAAkE;CAE7F,MAAM,iBAAiB,IAAI,MAAM,QAAQ;EACvC,IAAI,UAAU,KAAK;GAEjB,IADsB,QAAQ,yBAAyB,UAAU,GACjD,GACd,OAAO,QAAQ,IAAI,UAAU,KAAK,QAAQ;GAG5C,IAD0B,QAAQ,yBAAyB,kBAAkB,GACzD,GAAG;IACrB,MAAM,QAAQ,QAAQ,IAAI,UAAU,KAAK,QAAQ;IACjD,IAAI,OAAO,UAAU,YACnB,OAAO;IAET,MAAM,SAAS,eAAe,IAAI,GAAG;IACrC,IAAI,UAAU,OAAO,WAAW,OAC9B,OAAO,OAAO;IAEhB,MAAM,QAAQ,MAAM,KAAK,QAAQ;IACjC,eAAe,IAAI,KAAK;KAAE,QAAQ;KAAO;IAAM,CAAC;IAChD,OAAO;GACT;GACA,MAAM,kBAAkB,yBAAyB,GAAG;GACpD,IAAI,OAAO,oBAAoB,YAC7B,OAAO;GAET,OAAO,OAAO,QAAQ,WAAW,QAAQ,IAAI,UAAU,KAAK,QAAQ,IAAI;EAC1E;EACA,IAAI,UAAU,KAAK,OAAO;GACxB,IAAI,QAAQ,yBAAyB,UAAU,GAAG,KAAK,OAAO,QAAQ,UACpE,OAAO,QAAQ,IAAI,UAAU,KAAK,OAAO,QAAQ;GAEnD,QAAQ,eAAe,UAAU,KAAK;IACpC,cAAc;IACd,YAAY;IACZ,UAAU;IACV;GACF,CAAC;GACD,OAAO;EACT;EACA,IAAI,UAAU,KAAK;GACjB,OAAO,QAAQ,yBAAyB,UAAU,GAAG,MAAM,UACtD,QAAQ,yBAAyB,kBAAkB,GAAG,MAAM,UAC5D,OAAO,yBAAyB,GAAG,MAAM,cACxC,OAAO,QAAQ,YAAY,QAAQ,IAAI,UAAU,GAAG;EAC5D;CACF,CAAC;CACD,+BAA+B,IAAI,gBAAgB,MAAM;CACzD,OAAO;AACT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { slugify } from "../../shared/slugify.mjs";
|
|
2
|
+
import { posix } from "pathe";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/component/relations.ts
|
|
5
|
+
function resolveComposedParent(node) {
|
|
6
|
+
const assignedSlot = node.assignedSlot;
|
|
7
|
+
if (assignedSlot) return assignedSlot;
|
|
8
|
+
if (node.parentNode) return node.parentNode;
|
|
9
|
+
const root = node.getRootNode?.();
|
|
10
|
+
return root instanceof ShadowRoot ? root.host : void 0;
|
|
11
|
+
}
|
|
12
|
+
function resolveRelationTag(componentId, relationPath) {
|
|
13
|
+
if (!relationPath.startsWith(".")) return;
|
|
14
|
+
return slugify(posix.normalize(posix.join(posix.dirname(componentId), relationPath)), "wv-component");
|
|
15
|
+
}
|
|
16
|
+
function resolveRelationNodes(instance, componentId, relationPath, type) {
|
|
17
|
+
if (!componentId) return [];
|
|
18
|
+
const tag = resolveRelationTag(componentId, relationPath);
|
|
19
|
+
if (!tag) return [];
|
|
20
|
+
if (type === "child" || type === "descendant") {
|
|
21
|
+
const matches = Array.from(instance.querySelectorAll(tag));
|
|
22
|
+
return type === "descendant" ? matches : matches.filter((node) => resolveComposedParent(node) === instance);
|
|
23
|
+
}
|
|
24
|
+
let current = resolveComposedParent(instance);
|
|
25
|
+
while (current) {
|
|
26
|
+
if (current.tagName?.toLowerCase() === tag) return [current];
|
|
27
|
+
if (type === "parent") return [];
|
|
28
|
+
current = resolveComposedParent(current);
|
|
29
|
+
}
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolveRelationNodes };
|
|
35
|
+
//# sourceMappingURL=relations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relations.mjs","names":[],"sources":["../../../src/runtime/component/relations.ts"],"sourcesContent":["import type { ComponentPublicInstance, RelationType } from './types'\nimport { posix } from 'pathe'\nimport { slugify } from '../../shared/slugify'\n\nfunction resolveComposedParent(node: Node): Node | undefined {\n const assignedSlot = (node as Element).assignedSlot\n if (assignedSlot) {\n return assignedSlot\n }\n if (node.parentNode) {\n return node.parentNode\n }\n const root = node.getRootNode?.()\n return root instanceof ShadowRoot ? root.host : undefined\n}\n\nfunction resolveRelationTag(componentId: string, relationPath: string) {\n if (!relationPath.startsWith('.')) {\n return undefined\n }\n const targetId = posix.normalize(posix.join(posix.dirname(componentId), relationPath))\n return slugify(targetId, 'wv-component')\n}\n\nexport function resolveRelationNodes(\n instance: ComponentPublicInstance,\n componentId: string | undefined,\n relationPath: string,\n type: RelationType,\n): ComponentPublicInstance[] {\n if (!componentId) {\n return []\n }\n const tag = resolveRelationTag(componentId, relationPath)\n if (!tag) {\n return []\n }\n if (type === 'child' || type === 'descendant') {\n const matches = Array.from(instance.querySelectorAll(tag)) as ComponentPublicInstance[]\n return type === 'descendant'\n ? matches\n : matches.filter(node => resolveComposedParent(node) === instance)\n }\n\n let current = resolveComposedParent(instance)\n while (current) {\n if ((current as Element).tagName?.toLowerCase() === tag) {\n return [current as ComponentPublicInstance]\n }\n if (type === 'parent') {\n return []\n }\n current = resolveComposedParent(current)\n }\n return []\n}\n"],"mappings":";;;;AAIA,SAAS,sBAAsB,MAA8B;CAC3D,MAAM,eAAgB,KAAiB;CACvC,IAAI,cACF,OAAO;CAET,IAAI,KAAK,YACP,OAAO,KAAK;CAEd,MAAM,OAAO,KAAK,cAAc;CAChC,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;AAEA,SAAS,mBAAmB,aAAqB,cAAsB;CACrE,IAAI,CAAC,aAAa,WAAW,GAAG,GAC9B;CAGF,OAAO,QADU,MAAM,UAAU,MAAM,KAAK,MAAM,QAAQ,WAAW,GAAG,YAAY,CAC9D,GAAG,cAAc;AACzC;AAEA,SAAgB,qBACd,UACA,aACA,cACA,MAC2B;CAC3B,IAAI,CAAC,aACH,OAAO,CAAC;CAEV,MAAM,MAAM,mBAAmB,aAAa,YAAY;CACxD,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,IAAI,SAAS,WAAW,SAAS,cAAc;EAC7C,MAAM,UAAU,MAAM,KAAK,SAAS,iBAAiB,GAAG,CAAC;EACzD,OAAO,SAAS,eACZ,UACA,QAAQ,QAAO,SAAQ,sBAAsB,IAAI,MAAM,QAAQ;CACrE;CAEA,IAAI,UAAU,sBAAsB,QAAQ;CAC5C,OAAO,SAAS;EACd,IAAK,QAAoB,SAAS,YAAY,MAAM,KAClD,OAAO,CAAC,OAAkC;EAE5C,IAAI,SAAS,UACX,OAAO,CAAC;EAEV,UAAU,sBAAsB,OAAO;CACzC;CACA,OAAO,CAAC;AACV"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/runtime/component/slots.ts
|
|
2
|
+
function resolveSlotNames(value) {
|
|
3
|
+
if (Array.isArray(value)) return new Set(value.filter((name) => typeof name === "string" && name.length > 0));
|
|
4
|
+
if (!value || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
5
|
+
return new Set(Object.entries(value).filter(([, enabled]) => Boolean(enabled)).map(([name]) => name));
|
|
6
|
+
}
|
|
7
|
+
function createWebSlotsProxy(resolveValue) {
|
|
8
|
+
const hasSlot = (key) => typeof key === "string" && resolveSlotNames(resolveValue()).has(key);
|
|
9
|
+
return new Proxy(Object.create(null), {
|
|
10
|
+
get: (_target, key) => hasSlot(key) ? true : void 0,
|
|
11
|
+
has: (_target, key) => hasSlot(key),
|
|
12
|
+
ownKeys: () => Array.from(resolveSlotNames(resolveValue())),
|
|
13
|
+
getOwnPropertyDescriptor: (_target, key) => hasSlot(key) ? {
|
|
14
|
+
configurable: true,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
value: true
|
|
17
|
+
} : void 0,
|
|
18
|
+
set: () => false
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createWebSlotsProxy };
|
|
24
|
+
//# sourceMappingURL=slots.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.mjs","names":[],"sources":["../../../src/runtime/component/slots.ts"],"sourcesContent":["function resolveSlotNames(value: unknown) {\n if (Array.isArray(value)) {\n return new Set(value.filter((name): name is string => typeof name === 'string' && name.length > 0))\n }\n if (!value || typeof value !== 'object') {\n return new Set<string>()\n }\n return new Set(\n Object.entries(value)\n .filter(([, enabled]) => Boolean(enabled))\n .map(([name]) => name),\n )\n}\n\nexport function createWebSlotsProxy(resolveValue: () => unknown) {\n const hasSlot = (key: PropertyKey) => typeof key === 'string' && resolveSlotNames(resolveValue()).has(key)\n return new Proxy(Object.create(null) as Record<string, true>, {\n get: (_target, key) => hasSlot(key) ? true : undefined,\n has: (_target, key) => hasSlot(key),\n ownKeys: () => Array.from(resolveSlotNames(resolveValue())),\n getOwnPropertyDescriptor: (_target, key) => hasSlot(key)\n ? { configurable: true, enumerable: true, value: true }\n : undefined,\n set: () => false,\n })\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,OAAgB;CACxC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,IAAI,IAAI,MAAM,QAAQ,SAAyB,OAAO,SAAS,YAAY,KAAK,SAAS,CAAC,CAAC;CAEpG,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,uBAAO,IAAI,IAAY;CAEzB,OAAO,IAAI,IACT,OAAO,QAAQ,KAAK,CAAC,CAClB,QAAQ,GAAG,aAAa,QAAQ,OAAO,CAAC,CAAC,CACzC,KAAK,CAAC,UAAU,IAAI,CACzB;AACF;AAEA,SAAgB,oBAAoB,cAA6B;CAC/D,MAAM,WAAW,QAAqB,OAAO,QAAQ,YAAY,iBAAiB,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG;CACzG,OAAO,IAAI,MAAM,OAAO,OAAO,IAAI,GAA2B;EAC5D,MAAM,SAAS,QAAQ,QAAQ,GAAG,IAAI,OAAO;EAC7C,MAAM,SAAS,QAAQ,QAAQ,GAAG;EAClC,eAAe,MAAM,KAAK,iBAAiB,aAAa,CAAC,CAAC;EAC1D,2BAA2B,SAAS,QAAQ,QAAQ,GAAG,IACnD;GAAE,cAAc;GAAM,YAAY;GAAM,OAAO;EAAK,IACpD;EACJ,WAAW;CACb,CAAC;AACH"}
|
|
@@ -3,22 +3,30 @@ import { cloneValue, hyphenate } from "./utils.mjs";
|
|
|
3
3
|
import { normalizeBehaviors } from "./behavior.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/component/state.ts
|
|
6
|
+
function normalizePropertyDeclaration(declaration) {
|
|
7
|
+
if (declaration === null || typeof declaration === "function") return { type: declaration };
|
|
8
|
+
return declaration;
|
|
9
|
+
}
|
|
6
10
|
function resolveNormalizedComponent(component) {
|
|
7
11
|
const normalized = normalizeBehaviors(component);
|
|
12
|
+
const resolved = normalized.component;
|
|
8
13
|
return {
|
|
9
14
|
warnings: normalized.warnings,
|
|
10
|
-
component:
|
|
15
|
+
component: {
|
|
16
|
+
...resolved,
|
|
17
|
+
properties: Object.fromEntries(Object.entries(resolved.properties ?? {}).map(([name, declaration]) => [name, normalizePropertyDeclaration(declaration)]))
|
|
18
|
+
}
|
|
11
19
|
};
|
|
12
20
|
}
|
|
13
21
|
function createDefaultPropertyValues(propertyEntries) {
|
|
14
22
|
return propertyEntries.reduce((acc, [name, prop]) => {
|
|
15
|
-
if (hasOwn(prop, "value")) acc[name] = cloneValue(prop.value);
|
|
23
|
+
if (prop !== null && typeof prop === "object" && hasOwn(prop, "value")) acc[name] = cloneValue(prop.value);
|
|
16
24
|
else acc[name] = void 0;
|
|
17
25
|
return acc;
|
|
18
26
|
}, {});
|
|
19
27
|
}
|
|
20
28
|
function createPropertyEntries(component) {
|
|
21
|
-
return Object.entries(component.properties
|
|
29
|
+
return Object.entries(component.properties);
|
|
22
30
|
}
|
|
23
31
|
function createObservedAttributes(propertyEntries) {
|
|
24
32
|
return propertyEntries.map(([name]) => hyphenate(name));
|
|
@@ -28,6 +36,7 @@ function createComponentRuntimeState(options) {
|
|
|
28
36
|
const propertyEntries = createPropertyEntries(component);
|
|
29
37
|
return {
|
|
30
38
|
state: {
|
|
39
|
+
id: options.id,
|
|
31
40
|
templateRef: options.template,
|
|
32
41
|
styleRef: options.style ?? "",
|
|
33
42
|
componentRef: component,
|
|
@@ -45,6 +54,7 @@ function updateComponentRuntimeState(state, options) {
|
|
|
45
54
|
const { component, warnings } = resolveNormalizedComponent(options.component ?? {});
|
|
46
55
|
const propertyEntries = createPropertyEntries(component);
|
|
47
56
|
state.templateRef = options.template;
|
|
57
|
+
state.id = options.id;
|
|
48
58
|
state.styleRef = options.style ?? "";
|
|
49
59
|
state.componentRef = component;
|
|
50
60
|
state.observerInitEnabled = Boolean(options.observerInit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n PageLifeTimeHooks,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef:
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n NormalizedComponentOptions,\n PageLifeTimeHooks,\n PropertyDeclaration,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n id?: string\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef: NormalizedComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction normalizePropertyDeclaration(declaration: PropertyDeclaration): PropertyOption {\n if (declaration === null || typeof declaration === 'function') {\n return { type: declaration }\n }\n return declaration\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions) {\n const normalized = normalizeBehaviors(component)\n const resolved = normalized.component!\n return {\n warnings: normalized.warnings,\n component: {\n ...resolved,\n properties: Object.fromEntries(\n Object.entries(resolved.properties ?? {}).map(([name, declaration]) => [\n name,\n normalizePropertyDeclaration(declaration),\n ]),\n ),\n } satisfies NormalizedComponentOptions,\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (prop !== null && typeof prop === 'object' && hasOwn(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: NormalizedComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties)\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n id: options.id,\n templateRef: options.template,\n styleRef: options.style ?? '',\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.id = options.id\n state.styleRef = options.style ?? ''\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":";;;;;AA6BA,SAAS,6BAA6B,aAAkD;CACtF,IAAI,gBAAgB,QAAQ,OAAO,gBAAgB,YACjD,OAAO,EAAE,MAAM,YAAY;CAE7B,OAAO;AACT;AAEA,SAAS,2BAA2B,WAA6B;CAC/D,MAAM,aAAa,mBAAmB,SAAS;CAC/C,MAAM,WAAW,WAAW;CAC5B,OAAO;EACL,UAAU,WAAW;EACrB,WAAW;GACT,GAAG;GACH,YAAY,OAAO,YACjB,OAAO,QAAQ,SAAS,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,iBAAiB,CACrE,MACA,6BAA6B,WAAW,CAC1C,CAAC,CACH;EACF;CACF;AACF;AAEA,SAAS,4BAA4B,iBAAkC;CACrE,OAAO,gBAAgB,QAAoB,KAAK,CAAC,MAAM,UAAU;EAC/D,IAAI,SAAS,QAAQ,OAAO,SAAS,YAAY,OAAO,MAAM,OAAO,GACnE,IAAI,QAAQ,WAAW,KAAK,KAAK;OAGjC,IAAI,QAAQ;EAEd,OAAO;CACT,GAAG,CAAC,CAAC;AACP;AAEA,SAAS,sBAAsB,WAAwD;CACrF,OAAO,OAAO,QAAQ,UAAU,UAAU;AAC5C;AAEA,SAAS,yBAAyB,iBAAkC;CAClE,OAAO,gBAAgB,KAAK,CAAC,UAAU,UAAU,IAAI,CAAC;AACxD;AAEA,SAAgB,4BAA4B,SAAiC;CAC3E,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,CAAC,CAAC;CAClF,MAAM,kBAAkB,sBAAsB,SAAS;CAavD,OAAO;EACL;GAZA,IAAI,QAAQ;GACZ,aAAa,QAAQ;GACrB,UAAU,QAAQ,SAAS;GAC3B,cAAc;GACd,qBAAqB,QAAQ,QAAQ,YAAY;GACjD;GACA,oBAAoB,yBAAyB,eAAe;GAC5D,uBAAuB,4BAA4B,eAAe;GAClE,WAAW,UAAU,aAAa,CAAC;GACnC,eAAe,UAAU,iBAAiB,CAAC;EAGvC;EACJ;CACF;AACF;AAEA,SAAgB,4BAA4B,OAA8B,SAAiC;CACzG,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,CAAC,CAAC;CAClF,MAAM,kBAAkB,sBAAsB,SAAS;CACvD,MAAM,cAAc,QAAQ;CAC5B,MAAM,KAAK,QAAQ;CACnB,MAAM,WAAW,QAAQ,SAAS;CAClC,MAAM,eAAe;CACrB,MAAM,sBAAsB,QAAQ,QAAQ,YAAY;CACxD,MAAM,YAAY,UAAU,aAAa,CAAC;CAC1C,MAAM,gBAAgB,UAAU,iBAAiB,CAAC;CAClD,MAAM,kBAAkB;CACxB,MAAM,qBAAqB,yBAAyB,eAAe;CACnE,MAAM,wBAAwB,4BAA4B,eAAe;CACzE,OAAO;EACL;EACA,aAAa,UAAU,WAAW,CAAC;CACrC;AACF"}
|
|
@@ -3,9 +3,11 @@ import { TemplateRenderer } from "../template.mjs";
|
|
|
3
3
|
type DataRecord = Record<string, any>;
|
|
4
4
|
interface PropertyOption {
|
|
5
5
|
type?: StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
6
|
+
optionalTypes?: Array<StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor>;
|
|
6
7
|
value?: any;
|
|
7
8
|
observer?: (this: ComponentPublicInstance, newValue: any, oldValue: any) => void;
|
|
8
9
|
}
|
|
10
|
+
type PropertyDeclaration = PropertyOption | StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
9
11
|
interface LifeTimeHooks {
|
|
10
12
|
created?: (this: ComponentPublicInstance) => void;
|
|
11
13
|
attached?: (this: ComponentPublicInstance) => void;
|
|
@@ -17,32 +19,55 @@ interface PageLifeTimeHooks {
|
|
|
17
19
|
hide?: (this: ComponentPublicInstance) => void;
|
|
18
20
|
resize?: (this: ComponentPublicInstance) => void;
|
|
19
21
|
}
|
|
22
|
+
type RelationType = 'parent' | 'child' | 'ancestor' | 'descendant';
|
|
23
|
+
interface RelationOption {
|
|
24
|
+
type: RelationType;
|
|
25
|
+
linked?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
26
|
+
linkChanged?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
27
|
+
unlinked?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
28
|
+
}
|
|
29
|
+
interface ComponentBehaviorOptions {
|
|
30
|
+
addGlobalClass?: boolean;
|
|
31
|
+
styleIsolation?: 'isolated' | 'apply-shared' | 'shared';
|
|
32
|
+
virtualHost?: boolean;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
20
35
|
interface ComponentOptions {
|
|
21
|
-
properties?: Record<string,
|
|
36
|
+
properties?: Record<string, PropertyDeclaration>;
|
|
22
37
|
data?: DataRecord | (() => DataRecord);
|
|
23
38
|
methods?: Record<string, (this: ComponentPublicInstance, event: any) => any>;
|
|
39
|
+
observers?: Record<string, (this: ComponentPublicInstance, ...values: any[]) => void>;
|
|
24
40
|
lifetimes?: LifeTimeHooks;
|
|
25
41
|
pageLifetimes?: PageLifeTimeHooks;
|
|
42
|
+
relations?: Record<string, RelationOption>;
|
|
26
43
|
behaviors?: ComponentOptions[];
|
|
44
|
+
options?: ComponentBehaviorOptions;
|
|
27
45
|
}
|
|
28
46
|
interface DefineComponentOptions {
|
|
47
|
+
id?: string;
|
|
29
48
|
template: TemplateRenderer;
|
|
30
49
|
style?: string;
|
|
31
50
|
component?: ComponentOptions;
|
|
32
51
|
observerInit?: boolean;
|
|
33
52
|
}
|
|
53
|
+
interface TriggerEventOptions {
|
|
54
|
+
bubbles?: boolean;
|
|
55
|
+
composed?: boolean;
|
|
56
|
+
capturePhase?: boolean;
|
|
57
|
+
}
|
|
34
58
|
interface ComponentPublicInstance extends HTMLElement {
|
|
35
59
|
readonly data: DataRecord;
|
|
36
60
|
readonly properties: DataRecord;
|
|
37
|
-
setData: (patch: DataRecord) => void
|
|
38
|
-
triggerEvent: (name: string, detail?: any) => void;
|
|
61
|
+
setData: (patch: DataRecord, callback?: () => void) => void | Promise<void>;
|
|
62
|
+
triggerEvent: (name: string, detail?: any, options?: TriggerEventOptions) => void;
|
|
39
63
|
createSelectorQuery: () => any;
|
|
40
64
|
selectComponent: (selector: string) => ComponentPublicInstance | null;
|
|
41
65
|
selectAllComponents: (selector: string) => ComponentPublicInstance[];
|
|
66
|
+
getRelationNodes: (relationPath: string) => ComponentPublicInstance[];
|
|
42
67
|
}
|
|
43
68
|
type ComponentConstructor = CustomElementConstructor & {
|
|
44
69
|
__weappUpdate?: (options: DefineComponentOptions) => void;
|
|
45
70
|
};
|
|
46
71
|
//#endregion
|
|
47
|
-
export { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DataRecord, DefineComponentOptions, LifeTimeHooks, PageLifeTimeHooks, PropertyOption };
|
|
72
|
+
export { ComponentBehaviorOptions, ComponentConstructor, ComponentOptions, ComponentPublicInstance, DataRecord, DefineComponentOptions, LifeTimeHooks, PageLifeTimeHooks, PropertyDeclaration, PropertyOption, RelationOption, RelationType, TriggerEventOptions };
|
|
48
73
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region src/runtime/component/virtualHost.ts
|
|
2
|
+
function parseClassTokens(value) {
|
|
3
|
+
return new Set((value ?? "").split(/\s+/).filter(Boolean));
|
|
4
|
+
}
|
|
5
|
+
function writeTokens(element, name, tokens) {
|
|
6
|
+
const value = Array.from(tokens).join(" ");
|
|
7
|
+
if (value) {
|
|
8
|
+
if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
9
|
+
} else if (element.getAttribute(name) !== null) element.removeAttribute(name);
|
|
10
|
+
}
|
|
11
|
+
function isClassAttributeElement(value) {
|
|
12
|
+
return Boolean(value && typeof value === "object" && typeof value.getAttribute === "function" && typeof value.setAttribute === "function");
|
|
13
|
+
}
|
|
14
|
+
function resolveVirtualRootElement(root) {
|
|
15
|
+
for (const child of Array.from(root.childNodes ?? [])) {
|
|
16
|
+
if (!isClassAttributeElement(child)) continue;
|
|
17
|
+
if (child.tagName?.toLowerCase() === "style") continue;
|
|
18
|
+
return child;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 将 virtualHost 根节点的 class 暴露到 Web 自定义元素宿主。
|
|
23
|
+
*
|
|
24
|
+
* 微信的虚拟宿主不会形成样式边界,父组件可以通过 external class
|
|
25
|
+
* 和 deep 选择器命中子组件根节点。Web 仍使用 Shadow DOM 保留 slot
|
|
26
|
+
* 投影,因此需要把根节点的 class token 同步到宿主来还原该选择器语义。
|
|
27
|
+
*/
|
|
28
|
+
function syncVirtualHostClasses(host, root, ownedRuntimeTokens) {
|
|
29
|
+
const nextRuntimeTokens = parseClassTokens(resolveVirtualRootElement(root)?.getAttribute("class"));
|
|
30
|
+
const hostTokens = parseClassTokens(host.getAttribute("class"));
|
|
31
|
+
for (const token of ownedRuntimeTokens) hostTokens.delete(token);
|
|
32
|
+
ownedRuntimeTokens.clear();
|
|
33
|
+
for (const token of nextRuntimeTokens) {
|
|
34
|
+
if (!hostTokens.has(token)) ownedRuntimeTokens.add(token);
|
|
35
|
+
hostTokens.add(token);
|
|
36
|
+
}
|
|
37
|
+
writeTokens(host, "class", hostTokens);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 移除 runtime 为 virtualHost 同步的 class,并保留调用方宿主 class。
|
|
41
|
+
*/
|
|
42
|
+
function clearVirtualHostClasses(host, ownedRuntimeTokens) {
|
|
43
|
+
if (ownedRuntimeTokens.size === 0) return;
|
|
44
|
+
const hostTokens = parseClassTokens(host.getAttribute("class"));
|
|
45
|
+
for (const token of ownedRuntimeTokens) hostTokens.delete(token);
|
|
46
|
+
writeTokens(host, "class", hostTokens);
|
|
47
|
+
ownedRuntimeTokens.clear();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 清除 runtime 暴露的 CSS part,并保留组件模板声明的 part。
|
|
51
|
+
*/
|
|
52
|
+
function clearVirtualHostParts(rootElement, ownedPartTokens) {
|
|
53
|
+
if (!rootElement || ownedPartTokens.size === 0) return;
|
|
54
|
+
const partTokens = parseClassTokens(rootElement.getAttribute("part"));
|
|
55
|
+
for (const token of ownedPartTokens) partTokens.delete(token);
|
|
56
|
+
writeTokens(rootElement, "part", partTokens);
|
|
57
|
+
ownedPartTokens.clear();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 将 virtualHost 根 class 同步为 CSS part,使父组件可以跨 Shadow DOM
|
|
61
|
+
* 对子组件根节点应用 deep 样式。
|
|
62
|
+
*/
|
|
63
|
+
function syncVirtualHostParts(root, previousRootElement, ownedPartTokens) {
|
|
64
|
+
const rootElement = resolveVirtualRootElement(root);
|
|
65
|
+
if (previousRootElement && previousRootElement !== rootElement) clearVirtualHostParts(previousRootElement, ownedPartTokens);
|
|
66
|
+
if (!rootElement) {
|
|
67
|
+
ownedPartTokens.clear();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const partTokens = parseClassTokens(rootElement.getAttribute("part"));
|
|
71
|
+
for (const token of ownedPartTokens) partTokens.delete(token);
|
|
72
|
+
ownedPartTokens.clear();
|
|
73
|
+
for (const token of parseClassTokens(rootElement.getAttribute("class"))) {
|
|
74
|
+
if (!partTokens.has(token)) ownedPartTokens.add(token);
|
|
75
|
+
partTokens.add(token);
|
|
76
|
+
}
|
|
77
|
+
writeTokens(rootElement, "part", partTokens);
|
|
78
|
+
return rootElement;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { clearVirtualHostClasses, clearVirtualHostParts, syncVirtualHostClasses, syncVirtualHostParts };
|
|
83
|
+
//# sourceMappingURL=virtualHost.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtualHost.mjs","names":[],"sources":["../../../src/runtime/component/virtualHost.ts"],"sourcesContent":["export interface ClassAttributeElement {\n getAttribute: (name: string) => string | null\n removeAttribute: (name: string) => void\n setAttribute: (name: string, value: string) => void\n}\n\ninterface RenderRootLike {\n childNodes?: ArrayLike<unknown>\n}\n\nfunction parseClassTokens(value: string | null | undefined) {\n return new Set((value ?? '').split(/\\s+/).filter(Boolean))\n}\n\nfunction writeTokens(element: ClassAttributeElement, name: string, tokens: Set<string>) {\n const value = Array.from(tokens).join(' ')\n if (value) {\n if (element.getAttribute(name) !== value) {\n element.setAttribute(name, value)\n }\n }\n else if (element.getAttribute(name) !== null) {\n element.removeAttribute(name)\n }\n}\n\nfunction isClassAttributeElement(value: unknown): value is ClassAttributeElement & { tagName?: string } {\n return Boolean(\n value\n && typeof value === 'object'\n && typeof (value as ClassAttributeElement).getAttribute === 'function'\n && typeof (value as ClassAttributeElement).setAttribute === 'function',\n )\n}\n\nfunction resolveVirtualRootElement(root: RenderRootLike) {\n for (const child of Array.from(root.childNodes ?? [])) {\n if (!isClassAttributeElement(child)) {\n continue\n }\n if (child.tagName?.toLowerCase() === 'style') {\n continue\n }\n return child\n }\n return undefined\n}\n\n/**\n * 将 virtualHost 根节点的 class 暴露到 Web 自定义元素宿主。\n *\n * 微信的虚拟宿主不会形成样式边界,父组件可以通过 external class\n * 和 deep 选择器命中子组件根节点。Web 仍使用 Shadow DOM 保留 slot\n * 投影,因此需要把根节点的 class token 同步到宿主来还原该选择器语义。\n */\nexport function syncVirtualHostClasses(\n host: ClassAttributeElement,\n root: RenderRootLike,\n ownedRuntimeTokens: Set<string>,\n) {\n const rootElement = resolveVirtualRootElement(root)\n const nextRuntimeTokens = parseClassTokens(rootElement?.getAttribute('class'))\n const hostTokens = parseClassTokens(host.getAttribute('class'))\n\n for (const token of ownedRuntimeTokens) {\n hostTokens.delete(token)\n }\n ownedRuntimeTokens.clear()\n for (const token of nextRuntimeTokens) {\n if (!hostTokens.has(token)) {\n ownedRuntimeTokens.add(token)\n }\n hostTokens.add(token)\n }\n\n writeTokens(host, 'class', hostTokens)\n}\n\n/**\n * 移除 runtime 为 virtualHost 同步的 class,并保留调用方宿主 class。\n */\nexport function clearVirtualHostClasses(\n host: ClassAttributeElement,\n ownedRuntimeTokens: Set<string>,\n) {\n if (ownedRuntimeTokens.size === 0) {\n return\n }\n const hostTokens = parseClassTokens(host.getAttribute('class'))\n for (const token of ownedRuntimeTokens) {\n hostTokens.delete(token)\n }\n writeTokens(host, 'class', hostTokens)\n ownedRuntimeTokens.clear()\n}\n\n/**\n * 清除 runtime 暴露的 CSS part,并保留组件模板声明的 part。\n */\nexport function clearVirtualHostParts(\n rootElement: ClassAttributeElement | undefined,\n ownedPartTokens: Set<string>,\n) {\n if (!rootElement || ownedPartTokens.size === 0) {\n return\n }\n const partTokens = parseClassTokens(rootElement.getAttribute('part'))\n for (const token of ownedPartTokens) {\n partTokens.delete(token)\n }\n writeTokens(rootElement, 'part', partTokens)\n ownedPartTokens.clear()\n}\n\n/**\n * 将 virtualHost 根 class 同步为 CSS part,使父组件可以跨 Shadow DOM\n * 对子组件根节点应用 deep 样式。\n */\nexport function syncVirtualHostParts(\n root: RenderRootLike,\n previousRootElement: ClassAttributeElement | undefined,\n ownedPartTokens: Set<string>,\n) {\n const rootElement = resolveVirtualRootElement(root)\n if (previousRootElement && previousRootElement !== rootElement) {\n clearVirtualHostParts(previousRootElement, ownedPartTokens)\n }\n if (!rootElement) {\n ownedPartTokens.clear()\n return undefined\n }\n\n const partTokens = parseClassTokens(rootElement.getAttribute('part'))\n for (const token of ownedPartTokens) {\n partTokens.delete(token)\n }\n ownedPartTokens.clear()\n for (const token of parseClassTokens(rootElement.getAttribute('class'))) {\n if (!partTokens.has(token)) {\n ownedPartTokens.add(token)\n }\n partTokens.add(token)\n }\n writeTokens(rootElement, 'part', partTokens)\n return rootElement\n}\n"],"mappings":";AAUA,SAAS,iBAAiB,OAAkC;CAC1D,OAAO,IAAI,KAAK,SAAS,GAAE,CAAE,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC;AAC3D;AAEA,SAAS,YAAY,SAAgC,MAAc,QAAqB;CACtF,MAAM,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC,KAAK,GAAG;CACzC,IAAI,OACF;MAAI,QAAQ,aAAa,IAAI,MAAM,OACjC,QAAQ,aAAa,MAAM,KAAK;CAClC,OAEG,IAAI,QAAQ,aAAa,IAAI,MAAM,MACtC,QAAQ,gBAAgB,IAAI;AAEhC;AAEA,SAAS,wBAAwB,OAAuE;CACtG,OAAO,QACL,SACG,OAAO,UAAU,YACjB,OAAQ,MAAgC,iBAAiB,cACzD,OAAQ,MAAgC,iBAAiB,UAC9D;AACF;AAEA,SAAS,0BAA0B,MAAsB;CACvD,KAAK,MAAM,SAAS,MAAM,KAAK,KAAK,cAAc,CAAC,CAAC,GAAG;EACrD,IAAI,CAAC,wBAAwB,KAAK,GAChC;EAEF,IAAI,MAAM,SAAS,YAAY,MAAM,SACnC;EAEF,OAAO;CACT;AAEF;;;;;;;;AASA,SAAgB,uBACd,MACA,MACA,oBACA;CAEA,MAAM,oBAAoB,iBADN,0BAA0B,IACO,CAAC,EAAE,aAAa,OAAO,CAAC;CAC7E,MAAM,aAAa,iBAAiB,KAAK,aAAa,OAAO,CAAC;CAE9D,KAAK,MAAM,SAAS,oBAClB,WAAW,OAAO,KAAK;CAEzB,mBAAmB,MAAM;CACzB,KAAK,MAAM,SAAS,mBAAmB;EACrC,IAAI,CAAC,WAAW,IAAI,KAAK,GACvB,mBAAmB,IAAI,KAAK;EAE9B,WAAW,IAAI,KAAK;CACtB;CAEA,YAAY,MAAM,SAAS,UAAU;AACvC;;;;AAKA,SAAgB,wBACd,MACA,oBACA;CACA,IAAI,mBAAmB,SAAS,GAC9B;CAEF,MAAM,aAAa,iBAAiB,KAAK,aAAa,OAAO,CAAC;CAC9D,KAAK,MAAM,SAAS,oBAClB,WAAW,OAAO,KAAK;CAEzB,YAAY,MAAM,SAAS,UAAU;CACrC,mBAAmB,MAAM;AAC3B;;;;AAKA,SAAgB,sBACd,aACA,iBACA;CACA,IAAI,CAAC,eAAe,gBAAgB,SAAS,GAC3C;CAEF,MAAM,aAAa,iBAAiB,YAAY,aAAa,MAAM,CAAC;CACpE,KAAK,MAAM,SAAS,iBAClB,WAAW,OAAO,KAAK;CAEzB,YAAY,aAAa,QAAQ,UAAU;CAC3C,gBAAgB,MAAM;AACxB;;;;;AAMA,SAAgB,qBACd,MACA,qBACA,iBACA;CACA,MAAM,cAAc,0BAA0B,IAAI;CAClD,IAAI,uBAAuB,wBAAwB,aACjD,sBAAsB,qBAAqB,eAAe;CAE5D,IAAI,CAAC,aAAa;EAChB,gBAAgB,MAAM;EACtB;CACF;CAEA,MAAM,aAAa,iBAAiB,YAAY,aAAa,MAAM,CAAC;CACpE,KAAK,MAAM,SAAS,iBAClB,WAAW,OAAO,KAAK;CAEzB,gBAAgB,MAAM;CACtB,KAAK,MAAM,SAAS,iBAAiB,YAAY,aAAa,OAAO,CAAC,GAAG;EACvE,IAAI,CAAC,WAAW,IAAI,KAAK,GACvB,gBAAgB,IAAI,KAAK;EAE3B,WAAW,IAAI,KAAK;CACtB;CACA,YAAY,aAAa,QAAQ,UAAU;CAC3C,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage } from "./types.mjs";
|
|
2
|
+
//#region src/runtime/host/index.d.ts
|
|
3
|
+
declare function getWebRuntimeHost(): Readonly<WebRuntimeHost>;
|
|
4
|
+
declare function setWebRuntimeHost(host?: WebRuntimeHost): void;
|
|
5
|
+
declare function resetWebRuntimeHost(): void;
|
|
6
|
+
declare function getRuntimeFetch(): ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined;
|
|
7
|
+
declare function getRuntimeStorage(): WebRuntimeStorage | undefined;
|
|
8
|
+
declare function getRuntimeClipboard(): WebRuntimeClipboard | undefined;
|
|
9
|
+
declare function getRuntimeDialogs(): WebRuntimeDialogs;
|
|
10
|
+
declare function openRuntimeUrl(url?: string, target?: string, features?: string): unknown;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { type WebRuntimeClipboard, type WebRuntimeDialogs, type WebRuntimeHost, type WebRuntimeStorage, getRuntimeClipboard, getRuntimeDialogs, getRuntimeFetch, getRuntimeStorage, getWebRuntimeHost, openRuntimeUrl, resetWebRuntimeHost, setWebRuntimeHost };
|
|
13
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/runtime/host/index.ts
|
|
2
|
+
let runtimeHost = {};
|
|
3
|
+
function getWebRuntimeHost() {
|
|
4
|
+
return runtimeHost;
|
|
5
|
+
}
|
|
6
|
+
function setWebRuntimeHost(host) {
|
|
7
|
+
runtimeHost = host ? { ...host } : {};
|
|
8
|
+
}
|
|
9
|
+
function resetWebRuntimeHost() {
|
|
10
|
+
runtimeHost = {};
|
|
11
|
+
}
|
|
12
|
+
function getRuntimeFetch() {
|
|
13
|
+
if (typeof runtimeHost.fetch === "function") return runtimeHost.fetch;
|
|
14
|
+
const runtimeGlobal = globalThis;
|
|
15
|
+
return typeof runtimeGlobal.fetch === "function" ? runtimeGlobal.fetch : void 0;
|
|
16
|
+
}
|
|
17
|
+
function getRuntimeStorage() {
|
|
18
|
+
if (runtimeHost.storage) return runtimeHost.storage;
|
|
19
|
+
return globalThis.localStorage;
|
|
20
|
+
}
|
|
21
|
+
function getRuntimeClipboard() {
|
|
22
|
+
if (runtimeHost.clipboard) return runtimeHost.clipboard;
|
|
23
|
+
return globalThis.navigator?.clipboard;
|
|
24
|
+
}
|
|
25
|
+
function getRuntimeDialogs() {
|
|
26
|
+
if (runtimeHost.dialogs) return runtimeHost.dialogs;
|
|
27
|
+
const runtimeGlobal = globalThis;
|
|
28
|
+
return {
|
|
29
|
+
alert: runtimeGlobal.alert,
|
|
30
|
+
confirm: runtimeGlobal.confirm,
|
|
31
|
+
prompt: runtimeGlobal.prompt
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function openRuntimeUrl(url, target, features) {
|
|
35
|
+
if (typeof runtimeHost.open === "function") {
|
|
36
|
+
if (features === void 0) return runtimeHost.open(url, target);
|
|
37
|
+
return runtimeHost.open(url, target, features);
|
|
38
|
+
}
|
|
39
|
+
const runtimeGlobal = globalThis;
|
|
40
|
+
const runtimeOpen = runtimeGlobal.window?.open ?? runtimeGlobal.open;
|
|
41
|
+
if (features === void 0) return runtimeOpen?.(url, target);
|
|
42
|
+
return runtimeOpen?.(url, target, features);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { getRuntimeClipboard, getRuntimeDialogs, getRuntimeFetch, getRuntimeStorage, getWebRuntimeHost, openRuntimeUrl, resetWebRuntimeHost, setWebRuntimeHost };
|
|
47
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["runtimeGlobal"],"sources":["../../../src/runtime/host/index.ts"],"sourcesContent":["import type { WebRuntimeDialogs, WebRuntimeHost } from './types'\n\nlet runtimeHost: WebRuntimeHost = {}\n\nexport function getWebRuntimeHost(): Readonly<WebRuntimeHost> {\n return runtimeHost\n}\n\nexport function setWebRuntimeHost(host?: WebRuntimeHost): void {\n runtimeHost = host ? { ...host } : {}\n}\n\nexport function resetWebRuntimeHost(): void {\n runtimeHost = {}\n}\n\nexport function getRuntimeFetch() {\n if (typeof runtimeHost.fetch === 'function') {\n return runtimeHost.fetch\n }\n const runtimeGlobal = globalThis as { fetch?: WebRuntimeHost['fetch'] }\n return typeof runtimeGlobal.fetch === 'function' ? runtimeGlobal.fetch : undefined\n}\n\nexport function getRuntimeStorage() {\n if (runtimeHost.storage) {\n return runtimeHost.storage\n }\n const runtimeGlobal = globalThis as { localStorage?: WebRuntimeHost['storage'] }\n return runtimeGlobal.localStorage\n}\n\nexport function getRuntimeClipboard() {\n if (runtimeHost.clipboard) {\n return runtimeHost.clipboard\n }\n const runtimeGlobal = globalThis as { navigator?: { clipboard?: WebRuntimeHost['clipboard'] } }\n return runtimeGlobal.navigator?.clipboard\n}\n\nexport function getRuntimeDialogs() {\n if (runtimeHost.dialogs) {\n return runtimeHost.dialogs\n }\n const runtimeGlobal = globalThis as WebRuntimeDialogs\n return {\n alert: runtimeGlobal.alert,\n confirm: runtimeGlobal.confirm,\n prompt: runtimeGlobal.prompt,\n }\n}\n\nexport function openRuntimeUrl(url?: string, target?: string, features?: string) {\n if (typeof runtimeHost.open === 'function') {\n if (features === undefined) {\n return runtimeHost.open(url, target)\n }\n return runtimeHost.open(url, target, features)\n }\n const runtimeGlobal = globalThis as {\n open?: WebRuntimeHost['open']\n window?: { open?: WebRuntimeHost['open'] }\n }\n const runtimeOpen = runtimeGlobal.window?.open ?? runtimeGlobal.open\n if (features === undefined) {\n return runtimeOpen?.(url, target)\n }\n return runtimeOpen?.(url, target, features)\n}\n\nexport type { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage } from './types'\n"],"mappings":";AAEA,IAAI,cAA8B,CAAC;AAEnC,SAAgB,oBAA8C;CAC5D,OAAO;AACT;AAEA,SAAgB,kBAAkB,MAA6B;CAC7D,cAAc,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;AACtC;AAEA,SAAgB,sBAA4B;CAC1C,cAAc,CAAC;AACjB;AAEA,SAAgB,kBAAkB;CAChC,IAAI,OAAO,YAAY,UAAU,YAC/B,OAAO,YAAY;CAErB,MAAM,gBAAgB;CACtB,OAAO,OAAO,cAAc,UAAU,aAAa,cAAc,QAAQ;AAC3E;AAEA,SAAgB,oBAAoB;CAClC,IAAI,YAAY,SACd,OAAO,YAAY;CAGrB,OAAOA,WAAc;AACvB;AAEA,SAAgB,sBAAsB;CACpC,IAAI,YAAY,WACd,OAAO,YAAY;CAGrB,OAAOA,WAAc,WAAW;AAClC;AAEA,SAAgB,oBAAoB;CAClC,IAAI,YAAY,SACd,OAAO,YAAY;CAErB,MAAM,gBAAgB;CACtB,OAAO;EACL,OAAO,cAAc;EACrB,SAAS,cAAc;EACvB,QAAQ,cAAc;CACxB;AACF;AAEA,SAAgB,eAAe,KAAc,QAAiB,UAAmB;CAC/E,IAAI,OAAO,YAAY,SAAS,YAAY;EAC1C,IAAI,aAAa,QACf,OAAO,YAAY,KAAK,KAAK,MAAM;EAErC,OAAO,YAAY,KAAK,KAAK,QAAQ,QAAQ;CAC/C;CACA,MAAM,gBAAgB;CAItB,MAAM,cAAc,cAAc,QAAQ,QAAQ,cAAc;CAChE,IAAI,aAAa,QACf,OAAO,cAAc,KAAK,MAAM;CAElC,OAAO,cAAc,KAAK,QAAQ,QAAQ;AAC5C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/runtime/host/types.d.ts
|
|
2
|
+
interface WebRuntimeStorage {
|
|
3
|
+
readonly length: number;
|
|
4
|
+
clear: () => void;
|
|
5
|
+
getItem: (key: string) => string | null;
|
|
6
|
+
key: (index: number) => string | null;
|
|
7
|
+
removeItem: (key: string) => void;
|
|
8
|
+
setItem: (key: string, value: string) => void;
|
|
9
|
+
}
|
|
10
|
+
interface WebRuntimeClipboard {
|
|
11
|
+
readText: () => string | Promise<string>;
|
|
12
|
+
writeText: (value: string) => void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
interface WebRuntimeDialogs {
|
|
15
|
+
alert?: (message?: string) => void;
|
|
16
|
+
confirm?: (message?: string) => boolean;
|
|
17
|
+
prompt?: (message?: string, defaultValue?: string) => string | null;
|
|
18
|
+
}
|
|
19
|
+
interface WebRuntimeHost {
|
|
20
|
+
clipboard?: WebRuntimeClipboard;
|
|
21
|
+
dialogs?: WebRuntimeDialogs;
|
|
22
|
+
fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
23
|
+
open?: (url?: string, target?: string, features?: string) => unknown;
|
|
24
|
+
storage?: WebRuntimeStorage;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage };
|
|
28
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/runtime/hostGlobals.d.ts
|
|
2
|
+
type HostGlobalsTarget = Record<PropertyKey, any>;
|
|
3
|
+
/**
|
|
4
|
+
* 安装第三方库在模块求值阶段可能读取的小程序宿主全局。
|
|
5
|
+
*/
|
|
6
|
+
declare function installWebHostGlobals(target?: HostGlobalsTarget): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { installWebHostGlobals };
|
|
9
|
+
//# sourceMappingURL=hostGlobals.d.mts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { emitRuntimeWarning } from "./warning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/hostGlobals.ts
|
|
4
|
+
const IDENTITY_CONSTRUCTORS = [
|
|
5
|
+
"App",
|
|
6
|
+
"Page",
|
|
7
|
+
"Component"
|
|
8
|
+
];
|
|
9
|
+
const COMPILE_TIME_MACROS = [
|
|
10
|
+
"defineAppJson",
|
|
11
|
+
"defineComponentJson",
|
|
12
|
+
"definePageJson",
|
|
13
|
+
"definePageMeta",
|
|
14
|
+
"defineSitemapJson",
|
|
15
|
+
"defineThemeJson"
|
|
16
|
+
];
|
|
17
|
+
const PLUGIN_METHOD_RE = /^(?:add|can|choose|clear|close|create|delete|get|has|hide|is|load|navigate|off|on|open|remove|request|save|say|set|show|start|stop|update|upload)/i;
|
|
18
|
+
function createUnsupportedPlugin() {
|
|
19
|
+
return new Proxy(Object.create(null), { get(_target, property) {
|
|
20
|
+
if (property === "then") return;
|
|
21
|
+
if (typeof property === "string" && PLUGIN_METHOD_RE.test(property)) return () => void 0;
|
|
22
|
+
} });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 安装第三方库在模块求值阶段可能读取的小程序宿主全局。
|
|
26
|
+
*/
|
|
27
|
+
function installWebHostGlobals(target = globalThis) {
|
|
28
|
+
for (const name of IDENTITY_CONSTRUCTORS) if (typeof target[name] !== "function") target[name] = (options) => options;
|
|
29
|
+
for (const name of COMPILE_TIME_MACROS) if (typeof target[name] !== "function") target[name] = (options) => options;
|
|
30
|
+
if (typeof target.Behavior !== "function") target.Behavior = (options) => options;
|
|
31
|
+
if (typeof target.requirePlugin !== "function") target.requirePlugin = (pluginName) => {
|
|
32
|
+
emitRuntimeWarning(`[@weapp-vite/web] 插件 ${JSON.stringify(pluginName)} 暂无 Web 运行时实现,当前使用空代理降级。`, { key: `unsupported-plugin:${pluginName}` });
|
|
33
|
+
return createUnsupportedPlugin();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { installWebHostGlobals };
|
|
39
|
+
//# sourceMappingURL=hostGlobals.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostGlobals.mjs","names":[],"sources":["../../src/runtime/hostGlobals.ts"],"sourcesContent":["import { emitRuntimeWarning } from './warning'\n\ntype HostGlobalsTarget = Record<PropertyKey, any>\n\nconst IDENTITY_CONSTRUCTORS = ['App', 'Page', 'Component'] as const\nconst COMPILE_TIME_MACROS = [\n 'defineAppJson',\n 'defineComponentJson',\n 'definePageJson',\n 'definePageMeta',\n 'defineSitemapJson',\n 'defineThemeJson',\n] as const\n\nconst PLUGIN_METHOD_RE = /^(?:add|can|choose|clear|close|create|delete|get|has|hide|is|load|navigate|off|on|open|remove|request|save|say|set|show|start|stop|update|upload)/i\n\nfunction createUnsupportedPlugin() {\n return new Proxy(Object.create(null) as Record<PropertyKey, unknown>, {\n get(_target, property) {\n if (property === 'then') {\n return undefined\n }\n if (typeof property === 'string' && PLUGIN_METHOD_RE.test(property)) {\n return () => undefined\n }\n return undefined\n },\n })\n}\n\n/**\n * 安装第三方库在模块求值阶段可能读取的小程序宿主全局。\n */\nexport function installWebHostGlobals(target: HostGlobalsTarget = globalThis): void {\n for (const name of IDENTITY_CONSTRUCTORS) {\n if (typeof target[name] !== 'function') {\n target[name] = (options: Record<string, any>) => options\n }\n }\n for (const name of COMPILE_TIME_MACROS) {\n if (typeof target[name] !== 'function') {\n target[name] = (options: unknown) => options\n }\n }\n if (typeof target.Behavior !== 'function') {\n target.Behavior = (options: Record<string, any>) => options\n }\n if (typeof target.requirePlugin !== 'function') {\n target.requirePlugin = (pluginName: string) => {\n emitRuntimeWarning(`[@weapp-vite/web] 插件 ${JSON.stringify(pluginName)} 暂无 Web 运行时实现,当前使用空代理降级。`, {\n key: `unsupported-plugin:${pluginName}`,\n })\n return createUnsupportedPlugin()\n }\n }\n}\n"],"mappings":";;;AAIA,MAAM,wBAAwB;CAAC;CAAO;CAAQ;AAAW;AACzD,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,mBAAmB;AAEzB,SAAS,0BAA0B;CACjC,OAAO,IAAI,MAAM,OAAO,OAAO,IAAI,GAAmC,EACpE,IAAI,SAAS,UAAU;EACrB,IAAI,aAAa,QACf;EAEF,IAAI,OAAO,aAAa,YAAY,iBAAiB,KAAK,QAAQ,GAChE,aAAa;CAGjB,EACF,CAAC;AACH;;;;AAKA,SAAgB,sBAAsB,SAA4B,YAAkB;CAClF,KAAK,MAAM,QAAQ,uBACjB,IAAI,OAAO,OAAO,UAAU,YAC1B,OAAO,SAAS,YAAiC;CAGrD,KAAK,MAAM,QAAQ,qBACjB,IAAI,OAAO,OAAO,UAAU,YAC1B,OAAO,SAAS,YAAqB;CAGzC,IAAI,OAAO,OAAO,aAAa,YAC7B,OAAO,YAAY,YAAiC;CAEtD,IAAI,OAAO,OAAO,kBAAkB,YAClC,OAAO,iBAAiB,eAAuB;EAC7C,mBAAmB,wBAAwB,KAAK,UAAU,UAAU,EAAE,2BAA2B,EAC/F,KAAK,sBAAsB,aAC7B,CAAC;EACD,OAAO,wBAAwB;CACjC;AAEJ"}
|