@weapp-vite/web 1.3.37 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +16 -12
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +8 -2
- 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 +24 -6
- package/dist/index.mjs +21 -4
- 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 +55 -6
- 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 +244 -73
- 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 +6 -2
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/register.mjs +45 -33
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/scan.mjs +211 -92
- 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 +37 -1
- package/dist/plugin/vueSfc.mjs +150 -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 +36 -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/deviceApi.mjs +6 -3
- package/dist/runtime/polyfill/deviceApi.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 +33 -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 +9 -5
- 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 +11 -6
- 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 +3 -2
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +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/mediaApi/picker.mjs +16 -8
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +39 -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 +3 -2
- package/dist/runtime/polyfill/platformApi.mjs.map +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/storageAsync.mjs +4 -2
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +31 -4
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs +2 -1
- package/dist/runtime/polyfill/systemApi.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 +14 -6
|
@@ -7,17 +7,17 @@ import { parseDocument } from "htmlparser2";
|
|
|
7
7
|
const templateCache = /* @__PURE__ */ new Map();
|
|
8
8
|
function filterRenderableNode(node) {
|
|
9
9
|
if (node.type === "directive" || node.type === "comment") return false;
|
|
10
|
-
if (node.type === "text") return
|
|
10
|
+
if (node.type === "text") return node.data.trim().length > 0;
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
13
|
function getOrParseTemplate(source) {
|
|
14
14
|
let cached = templateCache.get(source);
|
|
15
15
|
if (!cached) {
|
|
16
|
-
cached =
|
|
16
|
+
cached = parseDocument(source, {
|
|
17
17
|
xmlMode: true,
|
|
18
18
|
decodeEntities: true,
|
|
19
19
|
recognizeSelfClosing: true
|
|
20
|
-
}).children
|
|
20
|
+
}).children.filter(filterRenderableNode);
|
|
21
21
|
templateCache.set(source, cached);
|
|
22
22
|
}
|
|
23
23
|
return cached;
|
|
@@ -29,7 +29,7 @@ function renderConditionalSequence(nodes, startIndex, scope, renderChildren) {
|
|
|
29
29
|
const candidate = nodes[cursor];
|
|
30
30
|
if (!isConditionalElement(candidate)) break;
|
|
31
31
|
const element = candidate;
|
|
32
|
-
const attribs = element.attribs
|
|
32
|
+
const attribs = element.attribs;
|
|
33
33
|
if (branches.length === 0 && !hasControlAttribute(attribs, "if")) break;
|
|
34
34
|
if (branches.length > 0 && !hasControlAttribute(attribs, "elif") && !hasControlAttribute(attribs, "else")) break;
|
|
35
35
|
branches.push({
|
|
@@ -64,7 +64,7 @@ function renderConditionalSequence(nodes, startIndex, scope, renderChildren) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
function renderElement(node, scope, renderChildren, options = {}) {
|
|
67
|
-
const attribs = node.attribs
|
|
67
|
+
const attribs = node.attribs;
|
|
68
68
|
if (!options.skipFor) {
|
|
69
69
|
const forExtract = extractFor(attribs);
|
|
70
70
|
if (forExtract.expr) {
|
|
@@ -93,7 +93,7 @@ function renderElement(node, scope, renderChildren, options = {}) {
|
|
|
93
93
|
return `<${normalizedTag}${attrs}>${children}</${normalizedTag}>`;
|
|
94
94
|
}
|
|
95
95
|
function renderTextNode(node, scope) {
|
|
96
|
-
const value = node.data
|
|
96
|
+
const value = node.data;
|
|
97
97
|
if (!value.trim()) return "";
|
|
98
98
|
return interpolateText(value, scope, true);
|
|
99
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n buildAttributeString,\n extractFor,\n isConditionalElement,\n stripControlAttributes,\n} from './dom'\nimport {\n createChildScope,\n createScope,\n evaluateExpression,\n interpolateText,\n normalizeList,\n} from './expression'\n\nconst templateCache = new Map<string, ChildNode[]>()\n\nfunction filterRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n buildAttributeString,\n extractFor,\n isConditionalElement,\n stripControlAttributes,\n} from './dom'\nimport {\n createChildScope,\n createScope,\n evaluateExpression,\n interpolateText,\n normalizeList,\n} from './expression'\n\nconst templateCache = new Map<string, ChildNode[]>()\n\nfunction filterRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data\n return data.trim().length > 0\n }\n return true\n}\n\nfunction getOrParseTemplate(source: string) {\n let cached = templateCache.get(source)\n if (!cached) {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n cached = document.children.filter(filterRenderableNode)\n templateCache.set(source, cached)\n }\n return cached\n}\n\nfunction renderConditionalSequence(\n nodes: ChildNode[],\n startIndex: number,\n scope: LegacyTemplateScope,\n renderChildren: (input: ChildNode[] | ChildNode | undefined, scope: LegacyTemplateScope) => string,\n) {\n const branches: Array<{ node: Element, attribs: Record<string, string> }> = []\n let cursor = startIndex\n\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const element = candidate as Element\n const attribs = element.attribs\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: element, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n\n if (!branches.length) {\n const node = nodes[startIndex]\n return {\n rendered: renderChildren(node, scope),\n endIndex: startIndex,\n }\n }\n\n for (const { node, attribs } of branches) {\n if (hasControlAttribute(attribs, 'else')) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n if (!conditionExpr) {\n continue\n }\n const condition = evaluateExpression(conditionExpr, scope)\n if (condition) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n }\n\n return {\n rendered: '',\n endIndex: startIndex + branches.length - 1,\n }\n}\n\nfunction renderElement(\n node: Element,\n scope: LegacyTemplateScope,\n renderChildren: (nodes: ChildNode[] | undefined, scope: LegacyTemplateScope) => string,\n options: RenderOptions = {},\n) {\n const attribs = node.attribs\n if (!options.skipFor) {\n const forExtract = extractFor(attribs)\n if (forExtract.expr) {\n const list = normalizeList(evaluateExpression(forExtract.expr, scope))\n if (!list.length) {\n return ''\n }\n let buffer = ''\n for (let idx = 0; idx < list.length; idx++) {\n const item = list[idx]\n const childScope = createChildScope(scope)\n childScope[forExtract.itemName] = item\n childScope[forExtract.indexName] = idx\n buffer += renderElement(node, childScope, renderChildren, {\n skipFor: true,\n overrideAttribs: forExtract.restAttribs,\n })\n }\n return buffer\n }\n }\n\n const effectiveAttribs = options.overrideAttribs ?? attribs\n const normalizedTag = normalizeTagName(node.name)\n if (normalizedTag === '#fragment') {\n return renderChildren(node.children, scope)\n }\n\n const attrs = buildAttributeString(effectiveAttribs, scope)\n const children = renderChildren(node.children, scope)\n\n if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) {\n return `<${normalizedTag}${attrs} />`\n }\n\n return `<${normalizedTag}${attrs}>${children}</${normalizedTag}>`\n}\n\nfunction renderTextNode(node: DataNode, scope: LegacyTemplateScope) {\n const value = node.data\n if (!value.trim()) {\n return ''\n }\n return interpolateText(value, scope, true)\n}\n\nfunction renderTree(\n input: ChildNode[] | ChildNode | undefined,\n scope: LegacyTemplateScope,\n): string {\n if (!input) {\n return ''\n }\n\n if (Array.isArray(input)) {\n let buffer = ''\n for (let index = 0; index < input.length; index++) {\n const node = input[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = renderConditionalSequence(input, index, scope, renderTree)\n buffer += rendered\n index = endIndex\n continue\n }\n buffer += renderTree(node, scope)\n }\n return buffer\n }\n\n const node = input\n if (node.type === 'text') {\n return renderTextNode(node as DataNode, scope)\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n return renderElement(node as Element, scope, renderTree)\n }\n if ('children' in node && node.children?.length) {\n return renderTree(node.children, scope)\n }\n return ''\n}\n\nexport function renderTemplate(nodes: ChildNode[], scope?: LegacyTemplateScope) {\n const renderScope = createScope(scope)\n return renderTree(nodes, renderScope)\n}\n\nexport function createTemplate(source: string): LegacyTemplateRenderer {\n const nodes = getOrParseTemplate(source)\n return (scope?: LegacyTemplateScope) => renderTemplate(nodes, scope)\n}\n\nexport type { LegacyTemplateRenderer, LegacyTemplateScope } from './types'\n"],"mappings":";;;;;;AA2BA,MAAM,gCAAgB,IAAI,IAAyB;AAEnD,SAAS,qBAAqB,MAAY;CACxC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AK;CACnB,IAAI,CAAC,MAAM,KAAK,GACd,OAAO;CAET,OAAO,gBAAgB,OAAO,OAAO,IAAI;AAC3C;AAEA,SAAS,WACP,OACA,OACQ;CACR,IAAI,CAAC,OACH,OAAO;CAGT,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI,SAAS;EACb,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;GACjD,MAAM,OAAO,MAAM;GACnB,IAAI,qBAAqB,IAAI,GAAG;IAC9B,MAAM,EAAE,UAAU,aAAa,0BAA0B,OAAO,OAAO,OAAO,UAAU;IACxF,UAAU;IACV,QAAQ;IACR;GACF;GACA,UAAU,WAAW,MAAM,KAAK;EAClC;EACA,OAAO;CACT;CAEA,MAAM,OAAO;CACb,IAAI,KAAK,SAAS,QAChB,OAAO,eAAe,MAAkB,KAAK;CAE/C,IAAI,KAAK,SAAS,SAAS,KAAK,SAAS,YAAY,KAAK,SAAS,SACjE,OAAO,cAAc,MAAiB,OAAO,UAAU;CAEzD,IAAI,cAAc,QAAQ,KAAK,UAAU,QACvC,OAAO,WAAW,KAAK,UAAU,KAAK;CAExC,OAAO;AACT;AAEA,SAAgB,eAAe,OAAoB,OAA6B;CAE9E,OAAO,WAAW,OADE,YAAY,KACG,CAAC;AACtC;AAEA,SAAgB,eAAe,QAAwC;CACrE,MAAM,QAAQ,mBAAmB,MAAM;CACvC,QAAQ,UAAgC,eAAe,OAAO,KAAK;AACrE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.mjs";
|
|
2
|
+
import { readBooleanAttribute, resolveContainingShadowRoot } from "../helpers.mjs";
|
|
3
|
+
import { ensureNativeComponentStyle } from "../style.mjs";
|
|
4
|
+
import { registerNativeMediaElement, unregisterNativeMediaElement } from "../mediaRegistry.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime/nativeComponents/canvas/index.ts
|
|
7
|
+
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
|
+
function resolveCanvasSize(value, fallback) {
|
|
9
|
+
const size = Number(value);
|
|
10
|
+
return Number.isInteger(size) && size > 0 ? size : fallback;
|
|
11
|
+
}
|
|
12
|
+
var WeappCanvas = class extends BaseElement {
|
|
13
|
+
static observedAttributes = [...getNativeComponentDescriptor("canvas").attributes];
|
|
14
|
+
#canvas;
|
|
15
|
+
get canvasElement() {
|
|
16
|
+
return this.#canvas;
|
|
17
|
+
}
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
ensureNativeComponentStyle(resolveContainingShadowRoot(this));
|
|
20
|
+
this.#ensureStructure();
|
|
21
|
+
this.#syncAttributes();
|
|
22
|
+
}
|
|
23
|
+
disconnectedCallback() {
|
|
24
|
+
if (this.#canvas) unregisterNativeMediaElement(this.#canvas);
|
|
25
|
+
}
|
|
26
|
+
attributeChangedCallback() {
|
|
27
|
+
this.#syncAttributes();
|
|
28
|
+
}
|
|
29
|
+
#ensureStructure() {
|
|
30
|
+
if (this.#canvas || typeof document === "undefined") return;
|
|
31
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
32
|
+
const style = document.createElement("style");
|
|
33
|
+
style.textContent = `
|
|
34
|
+
:host { position: relative; }
|
|
35
|
+
canvas { display: block; }
|
|
36
|
+
`;
|
|
37
|
+
const canvas = document.createElement("canvas");
|
|
38
|
+
root.append(style, canvas);
|
|
39
|
+
this.#canvas = canvas;
|
|
40
|
+
}
|
|
41
|
+
#syncAttributes() {
|
|
42
|
+
const canvas = this.#canvas;
|
|
43
|
+
if (!canvas) return;
|
|
44
|
+
canvas.width = resolveCanvasSize(this.getAttribute("width"), 300);
|
|
45
|
+
canvas.height = resolveCanvasSize(this.getAttribute("height"), 150);
|
|
46
|
+
canvas.style.touchAction = readBooleanAttribute(this, "disable-scroll") ? "none" : "";
|
|
47
|
+
registerNativeMediaElement("canvas", [this.getAttribute("canvas-id"), this.getAttribute("id")], canvas);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { WeappCanvas };
|
|
53
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#canvas","#ensureStructure","#syncAttributes"],"sources":["../../../../src/runtime/nativeComponents/canvas/index.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { readBooleanAttribute, resolveContainingShadowRoot } from '../helpers'\nimport { registerNativeMediaElement, unregisterNativeMediaElement } from '../mediaRegistry'\nimport { ensureNativeComponentStyle } from '../style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nfunction resolveCanvasSize(value: string | null, fallback: number) {\n const size = Number(value)\n return Number.isInteger(size) && size > 0 ? size : fallback\n}\n\nexport class WeappCanvas extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('canvas')!.attributes]\n\n #canvas?: HTMLCanvasElement\n\n get canvasElement() {\n return this.#canvas\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n this.#syncAttributes()\n }\n\n disconnectedCallback() {\n if (this.#canvas) {\n unregisterNativeMediaElement(this.#canvas)\n }\n }\n\n attributeChangedCallback() {\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#canvas || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { position: relative; }\n canvas { display: block; }\n `\n const canvas = document.createElement('canvas')\n root.append(style, canvas)\n this.#canvas = canvas\n }\n\n #syncAttributes() {\n const canvas = this.#canvas\n if (!canvas) {\n return\n }\n canvas.width = resolveCanvasSize(this.getAttribute('width'), 300)\n canvas.height = resolveCanvasSize(this.getAttribute('height'), 150)\n canvas.style.touchAction = readBooleanAttribute(this, 'disable-scroll') ? 'none' : ''\n registerNativeMediaElement('canvas', [\n this.get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|
|
|
1
|
+
import { getNativeComponentDescriptor } from "../../shared/nativeComponents.mjs";
|
|
2
|
+
import { connectFormControl, disconnectFormControl, findClosestComposedElement } from "./formControl.mjs";
|
|
3
|
+
import { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot } from "./helpers.mjs";
|
|
4
|
+
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime/nativeComponents/checkbox.ts
|
|
7
|
+
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
|
+
function collectCheckboxGroupValue(checkboxes) {
|
|
9
|
+
return Array.from(checkboxes).filter((checkbox) => checkbox.checked && !checkbox.disabled).map((checkbox) => checkbox.value);
|
|
10
|
+
}
|
|
11
|
+
var WeappCheckboxGroup = class extends BaseElement {
|
|
12
|
+
static observedAttributes = [...getNativeComponentDescriptor("checkbox-group").attributes];
|
|
13
|
+
get formControlName() {
|
|
14
|
+
return this.getAttribute("name") ?? "";
|
|
15
|
+
}
|
|
16
|
+
get formControlValue() {
|
|
17
|
+
return collectCheckboxGroupValue(this.querySelectorAll("weapp-checkbox"));
|
|
18
|
+
}
|
|
19
|
+
get formControlDisabled() {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
ensureNativeComponentStyle(resolveContainingShadowRoot(this));
|
|
24
|
+
connectFormControl(this);
|
|
25
|
+
}
|
|
26
|
+
disconnectedCallback() {
|
|
27
|
+
disconnectFormControl(this);
|
|
28
|
+
}
|
|
29
|
+
formReset() {
|
|
30
|
+
for (const checkbox of this.querySelectorAll("weapp-checkbox")) checkbox.formReset();
|
|
31
|
+
}
|
|
32
|
+
notifyCheckboxChange() {
|
|
33
|
+
dispatchMiniProgramEvent(this, "change", { value: this.formControlValue });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var WeappCheckbox = class extends BaseElement {
|
|
37
|
+
static observedAttributes = [...getNativeComponentDescriptor("checkbox").attributes];
|
|
38
|
+
#input;
|
|
39
|
+
#initialChecked = false;
|
|
40
|
+
#initialCheckedCaptured = false;
|
|
41
|
+
get value() {
|
|
42
|
+
return this.getAttribute("value") ?? "";
|
|
43
|
+
}
|
|
44
|
+
set value(value) {
|
|
45
|
+
this.setAttribute("value", value ?? "");
|
|
46
|
+
}
|
|
47
|
+
get checked() {
|
|
48
|
+
return this.#input?.checked ?? readBooleanAttribute(this, "checked");
|
|
49
|
+
}
|
|
50
|
+
set checked(value) {
|
|
51
|
+
this.toggleAttribute("checked", Boolean(value));
|
|
52
|
+
}
|
|
53
|
+
get disabled() {
|
|
54
|
+
return readBooleanAttribute(this, "disabled");
|
|
55
|
+
}
|
|
56
|
+
connectedCallback() {
|
|
57
|
+
ensureNativeComponentStyle(resolveContainingShadowRoot(this));
|
|
58
|
+
if (!this.#initialCheckedCaptured) {
|
|
59
|
+
this.#initialChecked = readBooleanAttribute(this, "checked");
|
|
60
|
+
this.#initialCheckedCaptured = true;
|
|
61
|
+
}
|
|
62
|
+
this.#ensureStructure();
|
|
63
|
+
this.#syncAttributes();
|
|
64
|
+
}
|
|
65
|
+
attributeChangedCallback() {
|
|
66
|
+
this.#syncAttributes();
|
|
67
|
+
}
|
|
68
|
+
formReset() {
|
|
69
|
+
this.setCheckedFromGroup(this.#initialChecked);
|
|
70
|
+
}
|
|
71
|
+
formActivate() {
|
|
72
|
+
if (!this.disabled) this.#input?.click();
|
|
73
|
+
}
|
|
74
|
+
setCheckedFromGroup(checked) {
|
|
75
|
+
if (this.#input) this.#input.checked = checked;
|
|
76
|
+
}
|
|
77
|
+
#ensureStructure() {
|
|
78
|
+
if (this.#input || typeof document === "undefined") return;
|
|
79
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
80
|
+
const style = document.createElement("style");
|
|
81
|
+
style.textContent = `
|
|
82
|
+
:host { --weapp-control-color: #07c160; }
|
|
83
|
+
label { display: inline-flex; align-items: center; cursor: pointer; }
|
|
84
|
+
input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
|
|
85
|
+
.control {
|
|
86
|
+
position: relative;
|
|
87
|
+
box-sizing: border-box;
|
|
88
|
+
width: 23px;
|
|
89
|
+
height: 23px;
|
|
90
|
+
flex: 0 0 23px;
|
|
91
|
+
border: 1px solid #d1d1d1;
|
|
92
|
+
border-radius: 3px;
|
|
93
|
+
background: #ffffff;
|
|
94
|
+
}
|
|
95
|
+
input:checked + .control { border-color: var(--weapp-control-color); background: var(--weapp-control-color); }
|
|
96
|
+
input:checked + .control::after {
|
|
97
|
+
position: absolute;
|
|
98
|
+
top: 3px;
|
|
99
|
+
left: 7px;
|
|
100
|
+
width: 6px;
|
|
101
|
+
height: 11px;
|
|
102
|
+
border: solid #ffffff;
|
|
103
|
+
border-width: 0 2px 2px 0;
|
|
104
|
+
content: '';
|
|
105
|
+
transform: rotate(45deg);
|
|
106
|
+
}
|
|
107
|
+
input:disabled + .control { border-color: #d8d8d8; background: #eeeeee; opacity: 0.7; }
|
|
108
|
+
.content { margin-left: 8px; }
|
|
109
|
+
`;
|
|
110
|
+
const label = document.createElement("label");
|
|
111
|
+
const input = document.createElement("input");
|
|
112
|
+
input.type = "checkbox";
|
|
113
|
+
const control = document.createElement("span");
|
|
114
|
+
control.className = "control";
|
|
115
|
+
const content = document.createElement("span");
|
|
116
|
+
content.className = "content";
|
|
117
|
+
content.append(document.createElement("slot"));
|
|
118
|
+
input.addEventListener("change", (event) => {
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
findClosestComposedElement(this, "weapp-checkbox-group")?.notifyCheckboxChange();
|
|
121
|
+
});
|
|
122
|
+
label.append(input, control, content);
|
|
123
|
+
root.append(style, label);
|
|
124
|
+
this.#input = input;
|
|
125
|
+
}
|
|
126
|
+
#syncAttributes() {
|
|
127
|
+
if (!this.#input) return;
|
|
128
|
+
this.#input.checked = readBooleanAttribute(this, "checked");
|
|
129
|
+
this.#input.disabled = this.disabled;
|
|
130
|
+
this.#input.value = this.value;
|
|
131
|
+
this.style.setProperty("--weapp-control-color", this.getAttribute("color") || "#07c160");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { WeappCheckbox, WeappCheckboxGroup, collectCheckboxGroupValue };
|
|
137
|
+
//# sourceMappingURL=checkbox.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.mjs","names":["#input","#initialCheckedCaptured","#initialChecked","#ensureStructure","#syncAttributes"],"sources":["../../../src/runtime/nativeComponents/checkbox.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../shared/nativeComponents'\nimport { connectFormControl, disconnectFormControl, findClosestComposedElement } from './formControl'\nimport { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot } from './helpers'\nimport { ensureNativeComponentStyle } from './style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nexport function collectCheckboxGroupValue(checkboxes: ArrayLike<WeappCheckbox>) {\n return Array.from(checkboxes)\n .filter(checkbox => checkbox.checked && !checkbox.disabled)\n .map(checkbox => checkbox.value)\n}\n\nexport class WeappCheckboxGroup extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('checkbox-group')!.attributes]\n\n get formControlName() {\n return this.getAttribute('name') ?? ''\n }\n\n get formControlValue() {\n return collectCheckboxGroupValue(this.querySelectorAll<WeappCheckbox>('weapp-checkbox'))\n }\n\n get formControlDisabled() {\n return false\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n connectFormControl(this)\n }\n\n disconnectedCallback() {\n disconnectFormControl(this)\n }\n\n formReset() {\n for (const checkbox of this.querySelectorAll<WeappCheckbox>('weapp-checkbox')) {\n checkbox.formReset()\n }\n }\n\n notifyCheckboxChange() {\n dispatchMiniProgramEvent(this, 'change', { value: this.formControlValue })\n }\n}\n\nexport class WeappCheckbox extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('checkbox')!.attributes]\n\n #input?: HTMLInputElement\n #initialChecked = false\n #initialCheckedCaptured = false\n\n get value() {\n return this.getAttribute('value') ?? ''\n }\n\n set value(value: string) {\n this.setAttribute('value', value ?? '')\n }\n\n get checked() {\n return this.#input?.checked ?? readBooleanAttribute(this, 'checked')\n }\n\n set checked(value: boolean) {\n this.toggleAttribute('checked', Boolean(value))\n }\n\n get disabled() {\n return readBooleanAttribute(this, 'disabled')\n }\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n if (!this.#initialCheckedCaptured) {\n this.#initialChecked = readBooleanAttribute(this, 'checked')\n this.#initialCheckedCaptured = true\n }\n this.#ensureStructure()\n this.#syncAttributes()\n }\n\n attributeChangedCallback() {\n this.#syncAttributes()\n }\n\n formReset() {\n this.setCheckedFromGroup(this.#initialChecked)\n }\n\n formActivate() {\n if (!this.disabled) {\n this.#input?.click()\n }\n }\n\n setCheckedFromGroup(checked: boolean) {\n if (this.#input) {\n this.#input.checked = checked\n }\n }\n\n #ensureStructure() {\n if (this.#input || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = `\n :host { --weapp-control-color: #07c160; }\n label { display: inline-flex; align-items: center; cursor: pointer; }\n input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }\n .control {\n position: relative;\n box-sizing: border-box;\n width: 23px;\n height: 23px;\n flex: 0 0 23px;\n border: 1px solid #d1d1d1;\n border-radius: 3px;\n background: #ffffff;\n }\n input:checked + .control { border-color: var(--weapp-control-color); background: var(--weapp-control-color); }\n input:checked + .control::after {\n position: absolute;\n top: 3px;\n left: 7px;\n width: 6px;\n height: 11px;\n border: solid #ffffff;\n border-width: 0 2px 2px 0;\n content: '';\n transform: rotate(45deg);\n }\n input:disabled + .control { border-color: #d8d8d8; background: #eeeeee; opacity: 0.7; }\n .content { margin-left: 8px; }\n `\n const label = document.createElement('label')\n const input = document.createElement('input')\n input.type = 'checkbox'\n const control = document.createElement('span')\n control.className = 'control'\n const content = document.createElement('span')\n content.className = 'content'\n content.append(document.createElement('slot'))\n input.addEventListener('change', (event) => {\n event.stopPropagation()\n const group = findClosestComposedElement(this, 'weapp-checkbox-group') as WeappCheckboxGroup | null\n group?.notifyCheckboxChange()\n })\n label.append(input, control, content)\n root.append(style, label)\n this.#input = input\n }\n\n #syncAttributes() {\n if (!this.#input) {\n return\n }\n this.#input.checked = readBooleanAttribute(this, 'checked')\n this.#input.disabled = this.disabled\n this.#input.value = this.value\n this.style.setProperty('--weapp-control-color', this.getAttribute('color') || '#07c160')\n }\n}\n"],"mappings":";;;;;;AAKA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,SAAgB,0BAA0B,YAAsC;CAC9E,OAAO,MAAM,KAAK,UAAU,CAAC,CAC1B,QAAO,aAAY,SAAS,WAAW,CAAC,SAAS,QAAQ,CAAC,CAC1D,KAAI,aAAY,SAAS,KAAK;AACnC;AAEA,IAAa,qBAAb,cAAwC,YAAY;CAClD,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,gBAAgB,CAAC,CAAE,UAAU;CAE1F,IAAI,kBAAkB;EACpB,OAAO,KAAK,aAAa,MAAM,KAAK;CACtC;CAEA,IAAI,mBAAmB;EACrB,OAAO,0BAA0B,KAAK,iBAAgC,gBAAgB,CAAC;CACzF;CAEA,IAAI,sBAAsB;EACxB,OAAO;CACT;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,mBAAmB,IAAI;CACzB;CAEA,uBAAuB;EACrB,sBAAsB,IAAI;CAC5B;CAEA,YAAY;EACV,KAAK,MAAM,YAAY,KAAK,iBAAgC,gBAAgB,GAC1E,SAAS,UAAU;CAEvB;CAEA,uBAAuB;EACrB,yBAAyB,MAAM,UAAU,EAAE,OAAO,KAAK,iBAAiB,CAAC;CAC3E;AACF;AAEA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,OAAO,qBAAqB,CAAC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AAU,SAAS,cAAc,MAAM;EAC7C,QAAQ,YAAY;EACpB,QAAQ,OAAO,SAAS,cAAc,MAAM,CAAC;EAC7C,MAAM,iBAAiB,WAAW,UAAU;GAC1C,MAAM,gBAAgB;GAEtB,AADc,2BAA2B,MAAM,sBAC3C,CAAC,EAAE,qBAAqB;EAC9B,CAAC;EACD,MAAM,OAAO,OAAO,SAAS,OAAO;EACpC,KAAK,OAAO,OAAO,KAAK;EACxB,KAAKA,SAAS;CAChB;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAKA,QACR;EAEF,KAAKA,OAAO,UAAU,qBAAqB,MAAM,SAAS;EAC1D,KAAKA,OAAO,WAAW,KAAK;EAC5B,KAAKA,OAAO,QAAQ,KAAK;EACzB,KAAK,MAAM,YAAY,yBAAyB,KAAK,aAAa,OAAO,KAAK,SAAS;CACzF;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.mjs";
|
|
2
|
+
import { WeappImage } from "../image.mjs";
|
|
3
|
+
import { WeappView } from "../primitives.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/nativeComponents/cover/index.ts
|
|
6
|
+
var WeappCoverView = class extends WeappView {
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
super.connectedCallback();
|
|
9
|
+
this.style.zIndex = "2";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var WeappCoverImage = class extends WeappImage {
|
|
13
|
+
static observedAttributes = [...getNativeComponentDescriptor("cover-image").attributes];
|
|
14
|
+
connectedCallback() {
|
|
15
|
+
super.connectedCallback();
|
|
16
|
+
this.style.position = "absolute";
|
|
17
|
+
this.style.zIndex = "2";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { WeappCoverImage, WeappCoverView };
|
|
23
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/cover/index.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { WeappImage } from '../image'\nimport { WeappView } from '../primitives'\n\nexport class WeappCoverView extends WeappView {\n connectedCallback() {\n super.connectedCallback()\n this.style.zIndex = '2'\n }\n}\n\nexport class WeappCoverImage extends WeappImage {\n static observedAttributes = [...getNativeComponentDescriptor('cover-image')!.attributes]\n\n connectedCallback() {\n super.connectedCallback()\n this.style.position = 'absolute'\n this.style.zIndex = '2'\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,oBAAoB;EAClB,MAAM,kBAAkB;EACxB,KAAK,MAAM,SAAS;CACtB;AACF;AAEA,IAAa,kBAAb,cAAqC,WAAW;CAC9C,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,aAAa,CAAC,CAAE,UAAU;CAEvF,oBAAoB;EAClB,MAAM,kBAAkB;EACxB,KAAK,MAAM,WAAW;EACtB,KAAK,MAAM,SAAS;CACtB;AACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { collectFormControlValues, resetFormControls } from "./formControl.mjs";
|
|
2
|
+
import { dispatchMiniProgramEvent, resolveContainingShadowRoot } from "./helpers.mjs";
|
|
3
|
+
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/nativeComponents/form.ts
|
|
6
|
+
const DEFAULT_FORM_CONFIG = { preventDefault: true };
|
|
7
|
+
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
|
+
let formConfig = { ...DEFAULT_FORM_CONFIG };
|
|
9
|
+
var WeappForm = class extends BaseElement {
|
|
10
|
+
#form;
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
ensureNativeComponentStyle(resolveContainingShadowRoot(this));
|
|
13
|
+
this.#ensureStructure();
|
|
14
|
+
}
|
|
15
|
+
requestSubmit() {
|
|
16
|
+
const submitEvent = new CustomEvent("submit", {
|
|
17
|
+
detail: { value: collectFormControlValues(this) },
|
|
18
|
+
bubbles: true,
|
|
19
|
+
composed: true,
|
|
20
|
+
cancelable: true
|
|
21
|
+
});
|
|
22
|
+
if (this.dispatchEvent(submitEvent) && !formConfig.preventDefault) this.#form?.submit();
|
|
23
|
+
}
|
|
24
|
+
reset() {
|
|
25
|
+
resetFormControls(this);
|
|
26
|
+
dispatchMiniProgramEvent(this, "reset", {});
|
|
27
|
+
}
|
|
28
|
+
#ensureStructure() {
|
|
29
|
+
if (this.#form || typeof document === "undefined") return;
|
|
30
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
31
|
+
const style = document.createElement("style");
|
|
32
|
+
style.textContent = ":host { display: inline; box-sizing: border-box; } form { display: block; margin: 3px 0 0; }";
|
|
33
|
+
const form = document.createElement("form");
|
|
34
|
+
form.addEventListener("submit", (event) => event.preventDefault());
|
|
35
|
+
const slot = document.createElement("slot");
|
|
36
|
+
form.append(slot);
|
|
37
|
+
root.append(style, form);
|
|
38
|
+
this.#form = form;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function setFormConfig(next) {
|
|
42
|
+
formConfig = {
|
|
43
|
+
...formConfig,
|
|
44
|
+
...next
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { WeappForm, setFormConfig };
|
|
50
|
+
//# sourceMappingURL=form.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.mjs","names":["#ensureStructure","#form"],"sources":["../../../src/runtime/nativeComponents/form.ts"],"sourcesContent":["import { collectFormControlValues, resetFormControls } from './formControl'\nimport { dispatchMiniProgramEvent, resolveContainingShadowRoot } from './helpers'\nimport { ensureNativeComponentStyle } from './style'\n\nexport interface FormConfig {\n preventDefault?: boolean\n}\n\nconst DEFAULT_FORM_CONFIG: Required<FormConfig> = {\n preventDefault: true,\n}\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\nlet formConfig: Required<FormConfig> = { ...DEFAULT_FORM_CONFIG }\n\nexport class WeappForm extends BaseElement {\n #form?: HTMLFormElement\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n }\n\n requestSubmit() {\n const submitEvent = new CustomEvent('submit', {\n detail: { value: collectFormControlValues(this) },\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n const shouldSubmit = this.dispatchEvent(submitEvent)\n if (shouldSubmit && !formConfig.preventDefault) {\n this.#form?.submit()\n }\n }\n\n reset() {\n resetFormControls(this)\n dispatchMiniProgramEvent(this, 'reset', {})\n }\n\n #ensureStructure() {\n if (this.#form || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = ':host { display: inline; box-sizing: border-box; } form { display: block; margin: 3px 0 0; }'\n const form = document.createElement('form')\n form.addEventListener('submit', event => event.preventDefault())\n const slot = document.createElement('slot')\n form.append(slot)\n root.append(style, form)\n this.#form = form\n }\n}\n\nexport function setFormConfig(next: FormConfig) {\n formConfig = {\n ...formConfig,\n ...next,\n }\n}\n"],"mappings":";;;;;AAQA,MAAM,sBAA4C,EAChD,gBAAgB,KAClB;AAEA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AACtD,IAAI,aAAmC,EAAE,GAAG,oBAAoB;AAEhE,IAAa,YAAb,cAA+B,YAAY;CACzC;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAKA,iBAAiB;CACxB;CAEA,gBAAgB;EACd,MAAM,cAAc,IAAI,YAAY,UAAU;GAC5C,QAAQ,EAAE,OAAO,yBAAyB,IAAI,EAAE;GAChD,SAAS;GACT,UAAU;GACV,YAAY;EACd,CAAC;EAED,IADqB,KAAK,cAAc,WACzB,KAAK,CAAC,WAAW,gBAC9B,KAAKC,OAAO,OAAO;CAEvB;CAEA,QAAQ;EACN,kBAAkB,IAAI;EACtB,yBAAyB,MAAM,SAAS,CAAC,CAAC;CAC5C;CAEA,mBAAmB;EACjB,IAAI,KAAKA,SAAS,OAAO,aAAa,aACpC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,MAAM,OAAO,SAAS,cAAc,MAAM;EAC1C,KAAK,iBAAiB,WAAU,UAAS,MAAM,eAAe,CAAC;EAC/D,MAAM,OAAO,SAAS,cAAc,MAAM;EAC1C,KAAK,OAAO,IAAI;EAChB,KAAK,OAAO,OAAO,IAAI;EACvB,KAAKA,QAAQ;CACf;AACF;AAEA,SAAgB,cAAc,MAAkB;CAC9C,aAAa;EACX,GAAG;EACH,GAAG;CACL;AACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/runtime/nativeComponents/formControl.ts
|
|
2
|
+
const controlsByForm = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
const formByControl = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function resolveParentAcrossShadow(element) {
|
|
5
|
+
if (element.parentElement) return element.parentElement;
|
|
6
|
+
const root = element.getRootNode();
|
|
7
|
+
return typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.host : null;
|
|
8
|
+
}
|
|
9
|
+
function findClosestComposedElement(element, selector) {
|
|
10
|
+
let current = element;
|
|
11
|
+
while (current) {
|
|
12
|
+
if (current.matches(selector)) return current;
|
|
13
|
+
current = resolveParentAcrossShadow(current);
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function disconnectFormControl(control) {
|
|
18
|
+
const form = formByControl.get(control);
|
|
19
|
+
if (!form) return;
|
|
20
|
+
controlsByForm.get(form)?.delete(control);
|
|
21
|
+
formByControl.delete(control);
|
|
22
|
+
}
|
|
23
|
+
function connectFormControl(control) {
|
|
24
|
+
disconnectFormControl(control);
|
|
25
|
+
const form = findClosestComposedElement(control, "weapp-form");
|
|
26
|
+
if (!form) return;
|
|
27
|
+
let controls = controlsByForm.get(form);
|
|
28
|
+
if (!controls) {
|
|
29
|
+
controls = /* @__PURE__ */ new Set();
|
|
30
|
+
controlsByForm.set(form, controls);
|
|
31
|
+
}
|
|
32
|
+
controls.add(control);
|
|
33
|
+
formByControl.set(control, form);
|
|
34
|
+
}
|
|
35
|
+
function collectFormControlValues(form) {
|
|
36
|
+
const values = {};
|
|
37
|
+
for (const control of controlsByForm.get(form) ?? []) {
|
|
38
|
+
if (formByControl.get(control) !== form || control.formControlDisabled) continue;
|
|
39
|
+
const name = control.formControlName.trim();
|
|
40
|
+
if (!name) continue;
|
|
41
|
+
values[name] = control.formControlValue;
|
|
42
|
+
}
|
|
43
|
+
return values;
|
|
44
|
+
}
|
|
45
|
+
function resetFormControls(form) {
|
|
46
|
+
for (const control of controlsByForm.get(form) ?? []) control.formReset();
|
|
47
|
+
}
|
|
48
|
+
function requestContainingFormAction(source, action) {
|
|
49
|
+
const form = findClosestComposedElement(source, "weapp-form");
|
|
50
|
+
if (!form) return false;
|
|
51
|
+
if (action === "submit") form.requestSubmit();
|
|
52
|
+
else form.reset();
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function isFormActivatable(value) {
|
|
56
|
+
return typeof value.formActivate === "function";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { collectFormControlValues, connectFormControl, disconnectFormControl, findClosestComposedElement, isFormActivatable, requestContainingFormAction, resetFormControls };
|
|
61
|
+
//# sourceMappingURL=formControl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formControl.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/formControl.ts"],"sourcesContent":["export interface FormControlContract extends HTMLElement {\n readonly formControlName: string\n readonly formControlValue: unknown\n readonly formControlDisabled: boolean\n formReset: () => void\n formActivate?: () => void\n}\n\nexport interface FormOwnerContract extends HTMLElement {\n requestSubmit: () => void\n reset: () => void\n}\n\nconst controlsByForm = new WeakMap<HTMLElement, Set<FormControlContract>>()\nconst formByControl = new WeakMap<FormControlContract, HTMLElement>()\n\nfunction resolveParentAcrossShadow(element: Element): Element | null {\n if (element.parentElement) {\n return element.parentElement\n }\n const root = element.getRootNode()\n return typeof ShadowRoot !== 'undefined' && root instanceof ShadowRoot\n ? root.host\n : null\n}\n\nexport function findClosestComposedElement(element: Element, selector: string) {\n let current: Element | null = element\n while (current) {\n if (current.matches(selector)) {\n return current as HTMLElement\n }\n current = resolveParentAcrossShadow(current)\n }\n return null\n}\n\nexport function disconnectFormControl(control: FormControlContract) {\n const form = formByControl.get(control)\n if (!form) {\n return\n }\n controlsByForm.get(form)?.delete(control)\n formByControl.delete(control)\n}\n\nexport function connectFormControl(control: FormControlContract) {\n disconnectFormControl(control)\n const form = findClosestComposedElement(control, 'weapp-form')\n if (!form) {\n return\n }\n let controls = controlsByForm.get(form)\n if (!controls) {\n controls = new Set()\n controlsByForm.set(form, controls)\n }\n controls.add(control)\n formByControl.set(control, form)\n}\n\nexport function collectFormControlValues(form: HTMLElement) {\n const values: Record<string, unknown> = {}\n for (const control of controlsByForm.get(form) ?? []) {\n if (formByControl.get(control) !== form || control.formControlDisabled) {\n continue\n }\n const name = control.formControlName.trim()\n if (!name) {\n continue\n }\n values[name] = control.formControlValue\n }\n return values\n}\n\nexport function resetFormControls(form: HTMLElement) {\n for (const control of controlsByForm.get(form) ?? []) {\n control.formReset()\n }\n}\n\nexport function requestContainingFormAction(source: Element, action: 'submit' | 'reset') {\n const form = findClosestComposedElement(source, 'weapp-form') as FormOwnerContract | null\n if (!form) {\n return false\n }\n if (action === 'submit') {\n form.requestSubmit()\n }\n else {\n form.reset()\n }\n return true\n}\n\nexport function isFormActivatable(value: Element): value is FormControlContract {\n return typeof (value as FormControlContract).formActivate === 'function'\n}\n"],"mappings":";AAaA,MAAM,iCAAiB,IAAI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A,SAAgB,4BAA4B,QAAiB,QAA4B;CACvF,MAAM,OAAO,2BAA2B,QAAQ,YAAY;CAC5D,IAAI,CAAC,MACH,OAAO;CAET,IAAI,WAAW,UACb,KAAK,cAAc;MAGnB,KAAK,MAAM;CAEb,OAAO;AACT;AAEA,SAAgB,kBAAkB,OAA8C;CAC9E,OAAO,OAAQ,MAA8B,iBAAiB;AAChE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/runtime/nativeComponents/helpers.ts
|
|
2
|
+
function readBooleanAttribute(element, name) {
|
|
3
|
+
const value = element.getAttribute(name);
|
|
4
|
+
return value !== null && value !== "false" && value !== "0";
|
|
5
|
+
}
|
|
6
|
+
function resolveMaxLength(value) {
|
|
7
|
+
if (value === null) return;
|
|
8
|
+
const maxlength = Number(value);
|
|
9
|
+
return Number.isInteger(maxlength) && maxlength >= 0 ? maxlength : void 0;
|
|
10
|
+
}
|
|
11
|
+
function resolveContainingShadowRoot(element) {
|
|
12
|
+
const root = element.getRootNode();
|
|
13
|
+
return typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : void 0;
|
|
14
|
+
}
|
|
15
|
+
function dispatchMiniProgramEvent(element, name, detail, options = {}) {
|
|
16
|
+
element.dispatchEvent(new CustomEvent(name, {
|
|
17
|
+
bubbles: options.bubbles ?? true,
|
|
18
|
+
composed: options.composed ?? true,
|
|
19
|
+
detail
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot, resolveMaxLength };
|
|
25
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/helpers.ts"],"sourcesContent":["export function readBooleanAttribute(element: Element, name: string) {\n const value = element.getAttribute(name)\n return value !== null && value !== 'false' && value !== '0'\n}\n\nexport function resolveMaxLength(value: string | null) {\n if (value === null) {\n return undefined\n }\n const maxlength = Number(value)\n return Number.isInteger(maxlength) && maxlength >= 0 ? maxlength : undefined\n}\n\nexport function resolveContainingShadowRoot(element: Element) {\n const root = element.getRootNode()\n return typeof ShadowRoot !== 'undefined' && root instanceof ShadowRoot ? root : undefined\n}\n\nexport function dispatchMiniProgramEvent<T>(\n element: Element,\n name: string,\n detail: T,\n options: Pick<CustomEventInit<T>, 'bubbles' | 'composed'> = {},\n) {\n element.dispatchEvent(new CustomEvent(name, {\n bubbles: options.bubbles ?? true,\n composed: options.composed ?? true,\n detail,\n }))\n}\n"],"mappings":";AAAA,SAAgB,qBAAqB,SAAkB,MAAc;CACnE,MAAM,QAAQ,QAAQ,aAAa,IAAI;CACvC,OAAO,UAAU,QAAQ,UAAU,WAAW,UAAU;AAC1D;AAEA,SAAgB,iBAAiB,OAAsB;CACrD,IAAI,UAAU,MACZ;CAEF,MAAM,YAAY,OAAO,KAAK;CAC9B,OAAO,OAAO,UAAU,SAAS,KAAK,aAAa,IAAI,YAAY;AACrE;AAEA,SAAgB,4BAA4B,SAAkB;CAC5D,MAAM,OAAO,QAAQ,YAAY;CACjC,OAAO,OAAO,eAAe,eAAe,gBAAgB,aAAa,OAAO;AAClF;AAEA,SAAgB,yBACd,SACA,MACA,QACA,UAA4D,CAAC,GAC7D;CACA,QAAQ,cAAc,IAAI,YAAY,MAAM;EAC1C,SAAS,QAAQ,WAAW;EAC5B,UAAU,QAAQ,YAAY;EAC9B;CACF,CAAC,CAAC;AACJ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/runtime/nativeComponents/icon/helpers.ts
|
|
2
|
+
const ICON_TYPES = [
|
|
3
|
+
"success",
|
|
4
|
+
"success_no_circle",
|
|
5
|
+
"info",
|
|
6
|
+
"warn",
|
|
7
|
+
"waiting",
|
|
8
|
+
"cancel",
|
|
9
|
+
"download",
|
|
10
|
+
"search",
|
|
11
|
+
"clear"
|
|
12
|
+
];
|
|
13
|
+
const iconTypes = new Set(ICON_TYPES);
|
|
14
|
+
const DEFAULT_ICON_COLORS = {
|
|
15
|
+
success: "#09bb07",
|
|
16
|
+
success_no_circle: "#09bb07",
|
|
17
|
+
info: "#10aeff",
|
|
18
|
+
warn: "#f76260",
|
|
19
|
+
waiting: "#10aeff",
|
|
20
|
+
cancel: "#f76260",
|
|
21
|
+
download: "#09bb07",
|
|
22
|
+
search: "#7a7e83",
|
|
23
|
+
clear: "#7a7e83"
|
|
24
|
+
};
|
|
25
|
+
function finiteNumber(value, fallback) {
|
|
26
|
+
const numeric = Number(value);
|
|
27
|
+
return Number.isFinite(numeric) ? numeric : fallback;
|
|
28
|
+
}
|
|
29
|
+
function resolveIconType(value) {
|
|
30
|
+
const type = String(value ?? "").trim().toLowerCase();
|
|
31
|
+
return iconTypes.has(type) ? type : "success";
|
|
32
|
+
}
|
|
33
|
+
function resolveIconSize(value) {
|
|
34
|
+
return Math.max(0, finiteNumber(value, 23));
|
|
35
|
+
}
|
|
36
|
+
function resolveIconColor(type, value) {
|
|
37
|
+
return String(value ?? "").trim() || DEFAULT_ICON_COLORS[type];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ICON_TYPES, resolveIconColor, resolveIconSize, resolveIconType };
|
|
42
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../src/runtime/nativeComponents/icon/helpers.ts"],"sourcesContent":["export const ICON_TYPES = [\n 'success',\n 'success_no_circle',\n 'info',\n 'warn',\n 'waiting',\n 'cancel',\n 'download',\n 'search',\n 'clear',\n] as const\n\nexport type IconType = typeof ICON_TYPES[number]\n\nconst iconTypes = new Set<string>(ICON_TYPES)\n\nconst DEFAULT_ICON_COLORS: Record<IconType, string> = {\n success: '#09bb07',\n success_no_circle: '#09bb07',\n info: '#10aeff',\n warn: '#f76260',\n waiting: '#10aeff',\n cancel: '#f76260',\n download: '#09bb07',\n search: '#7a7e83',\n clear: '#7a7e83',\n}\n\nfunction finiteNumber(value: unknown, fallback: number) {\n const numeric = Number(value)\n return Number.isFinite(numeric) ? numeric : fallback\n}\n\nexport function resolveIconType(value: unknown): IconType {\n const type = String(value ?? '').trim().toLowerCase()\n return iconTypes.has(type) ? type as IconType : 'success'\n}\n\nexport function resolveIconSize(value: unknown) {\n return Math.max(0, finiteNumber(value, 23))\n}\n\nexport function resolveIconColor(type: IconType, value: unknown) {\n const color = String(value ?? '').trim()\n return color || DEFAULT_ICON_COLORS[type]\n}\n"],"mappings":";AAAA,MAAa,aAAa;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,YAAY,IAAI,IAAY,UAAU;AAE5C,MAAM,sBAAgD;CACpD,SAAS;CACT,mBAAmB;CACnB,MAAM;CACN,MAAM;CACN,SAAS;CACT,QAAQ;CACR,UAAU;CACV,QAAQ;CACR,OAAO;AACT;AAEA,SAAS,aAAa,OAAgB,UAAkB;CACtD,MAAM,UAAU,OAAO,KAAK;CAC5B,OAAO,OAAO,SAAS,OAAO,IAAI,UAAU;AAC9C;AAEA,SAAgB,gBAAgB,OAA0B;CACxD,MAAM,OAAO,OAAO,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY;CACpD,OAAO,UAAU,IAAI,IAAI,IAAI,OAAmB;AAClD;AAEA,SAAgB,gBAAgB,OAAgB;CAC9C,OAAO,KAAK,IAAI,GAAG,aAAa,OAAO,EAAE,CAAC;AAC5C;AAEA,SAAgB,iBAAiB,MAAgB,OAAgB;CAE/D,OADc,OAAO,SAAS,EAAE,CAAC,CAAC,KACvB,KAAK,oBAAoB;AACtC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.mjs";
|
|
2
|
+
import { resolveContainingShadowRoot } from "../helpers.mjs";
|
|
3
|
+
import { ensureNativeComponentStyle } from "../style.mjs";
|
|
4
|
+
import { ICON_TYPES, resolveIconColor, resolveIconSize, resolveIconType } from "./helpers.mjs";
|
|
5
|
+
import { ICON_SHADOW_STYLE } from "./style.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/runtime/nativeComponents/icon/index.ts
|
|
8
|
+
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
9
|
+
var WeappIcon = class extends BaseElement {
|
|
10
|
+
static observedAttributes = [...getNativeComponentDescriptor("icon").attributes];
|
|
11
|
+
#icon;
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
ensureNativeComponentStyle(resolveContainingShadowRoot(this));
|
|
14
|
+
this.#ensureStructure();
|
|
15
|
+
this.#syncAttributes();
|
|
16
|
+
}
|
|
17
|
+
attributeChangedCallback() {
|
|
18
|
+
this.#syncAttributes();
|
|
19
|
+
}
|
|
20
|
+
#ensureStructure() {
|
|
21
|
+
if (this.#icon || typeof document === "undefined") return;
|
|
22
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
23
|
+
const style = document.createElement("style");
|
|
24
|
+
style.textContent = ICON_SHADOW_STYLE;
|
|
25
|
+
const icon = document.createElement("span");
|
|
26
|
+
icon.className = "icon";
|
|
27
|
+
icon.setAttribute("role", "img");
|
|
28
|
+
root.append(style, icon);
|
|
29
|
+
this.#icon = icon;
|
|
30
|
+
}
|
|
31
|
+
#syncAttributes() {
|
|
32
|
+
if (!this.#icon) return;
|
|
33
|
+
const type = resolveIconType(this.getAttribute("type"));
|
|
34
|
+
const size = resolveIconSize(this.getAttribute("size"));
|
|
35
|
+
const color = resolveIconColor(type, this.getAttribute("color"));
|
|
36
|
+
this.style.setProperty("--weapp-icon-size", `${size}px`);
|
|
37
|
+
this.style.setProperty("--weapp-icon-color", color);
|
|
38
|
+
this.#icon.className = `icon ${type}`;
|
|
39
|
+
this.#icon.setAttribute("aria-label", type);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { ICON_TYPES, WeappIcon, resolveIconColor, resolveIconSize, resolveIconType };
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#ensureStructure","#syncAttributes","#icon"],"sources":["../../../../src/runtime/nativeComponents/icon/index.ts"],"sourcesContent":["import { getNativeComponentDescriptor } from '../../../shared/nativeComponents'\nimport { resolveContainingShadowRoot } from '../helpers'\nimport { ensureNativeComponentStyle } from '../style'\nimport { resolveIconColor, resolveIconSize, resolveIconType } from './helpers'\nimport { ICON_SHADOW_STYLE } from './style'\n\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nexport class WeappIcon extends BaseElement {\n static observedAttributes = [...getNativeComponentDescriptor('icon')!.attributes]\n\n #icon?: HTMLSpanElement\n\n connectedCallback() {\n ensureNativeComponentStyle(resolveContainingShadowRoot(this))\n this.#ensureStructure()\n this.#syncAttributes()\n }\n\n attributeChangedCallback() {\n this.#syncAttributes()\n }\n\n #ensureStructure() {\n if (this.#icon || typeof document === 'undefined') {\n return\n }\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n const style = document.createElement('style')\n style.textContent = ICON_SHADOW_STYLE\n const icon = document.createElement('span')\n icon.className = 'icon'\n icon.setAttribute('role', 'img')\n root.append(style, icon)\n this.#icon = icon\n }\n\n #syncAttributes() {\n if (!this.#icon) {\n return\n }\n const type = resolveIconType(this.getAttribute('type'))\n const size = resolveIconSize(this.getAttribute('size'))\n const color = resolveIconColor(type, this.getAttribute('color'))\n this.style.setProperty('--weapp-icon-size', `${size}px`)\n this.style.setProperty('--weapp-icon-color', color)\n this.#icon.className = `icon ${type}`\n this.#icon.setAttribute('aria-label', type)\n }\n}\n\nexport * from './helpers'\n"],"mappings":";;;;;;;AAMA,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AAEtD,IAAa,YAAb,cAA+B,YAAY;CACzC,OAAO,qBAAqB,CAAC,GAAG,6BAA6B,MAAM,CAAC,CAAE,UAAU;CAEhF;CAEA,oBAAoB;EAClB,2BAA2B,4BAA4B,IAAI,CAAC;EAC5D,KAAKA,iBAAiB;EACtB,KAAKC,gBAAgB;CACvB;CAEA,2BAA2B;EACzB,KAAKA,gBAAgB;CACvB;CAEA,mBAAmB;EACjB,IAAI,KAAKC,SAAS,OAAO,aAAa,aACpC;EAEF,MAAM,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAClE,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,MAAM,OAAO,SAAS,cAAc,MAAM;EAC1C,KAAK,YAAY;EACjB,KAAK,aAAa,QAAQ,KAAK;EAC/B,KAAK,OAAO,OAAO,IAAI;EACvB,KAAKA,QAAQ;CACf;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAKA,OACR;EAEF,MAAM,OAAO,gBAAgB,KAAK,aAAa,MAAM,CAAC;EACtD,MAAM,OAAO,gBAAgB,KAAK,aAAa,MAAM,CAAC;EACtD,MAAM,QAAQ,iBAAiB,MAAM,KAAK,aAAa,OAAO,CAAC;EAC/D,KAAK,MAAM,YAAY,qBAAqB,GAAG,KAAK,GAAG;EACvD,KAAK,MAAM,YAAY,sBAAsB,KAAK;EAClD,KAAKA,MAAM,YAAY,QAAQ;EAC/B,KAAKA,MAAM,aAAa,cAAc,IAAI;CAC5C;AACF"}
|