@weapp-vite/web 2.0.1 → 2.1.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/dist/_virtual/_rolldown/runtime.mjs +1 -2
- package/dist/compiler/wxml/attributes.mjs +12 -4
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs +26 -8
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/dependency.mjs +1 -2
- package/dist/compiler/wxml/interpolation.mjs +13 -3
- package/dist/compiler/wxml/interpolation.mjs.map +1 -1
- package/dist/compiler/wxml/nativeTags.mjs +60 -0
- package/dist/compiler/wxml/nativeTags.mjs.map +1 -0
- package/dist/compiler/wxml/navigation.mjs +1 -2
- package/dist/compiler/wxml/parser.mjs +1 -2
- package/dist/compiler/wxml/prepare.mjs +1 -2
- package/dist/compiler/wxml/renderer.mjs +1 -2
- package/dist/compiler/wxml/specialNodes.mjs +1 -2
- package/dist/compiler/wxml/types.d.mts +0 -2
- package/dist/compiler/wxml/unknownTags.mjs +33 -0
- package/dist/compiler/wxml/unknownTags.mjs.map +1 -0
- package/dist/compiler/wxs.mjs +1 -2
- package/dist/css/wxss.d.mts +2 -19
- package/dist/css/wxss.mjs +5 -12
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/index.d.mts +8 -3
- package/dist/index.mjs +8 -5
- package/dist/plugin/assets.d.mts +0 -2
- package/dist/plugin/assets.mjs +1 -2
- package/dist/plugin/constants.mjs +1 -2
- package/dist/plugin/dependencyScan.mjs +1 -2
- package/dist/plugin/entry.mjs +6 -4
- package/dist/plugin/entry.mjs.map +1 -1
- package/dist/plugin/files.mjs +1 -2
- package/dist/plugin/hostTypes.d.mts +0 -2
- package/dist/plugin/index.d.mts +0 -2
- package/dist/plugin/index.mjs +5 -5
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/layout.mjs +1 -2
- package/dist/plugin/navigation.mjs +1 -2
- package/dist/plugin/packageResolution.mjs +1 -2
- package/dist/plugin/path.mjs +1 -2
- package/dist/plugin/register.mjs +1 -2
- package/dist/plugin/scan.mjs +1 -2
- package/dist/plugin/scanConfig.mjs +1 -2
- package/dist/plugin/scanSfc.mjs +1 -2
- package/dist/plugin/sfcHmr.mjs +1 -2
- package/dist/plugin/state.mjs +1 -2
- package/dist/plugin/styleModule.mjs +1 -2
- package/dist/plugin/types.d.mts +2 -3
- package/dist/plugin/vueSfc.mjs +1 -2
- package/dist/runtime/appShell/container.mjs +1 -2
- package/dist/runtime/appShell/tabBar/index.mjs +1 -2
- package/dist/runtime/appShell/tabBar/style.mjs +1 -2
- package/dist/runtime/appStyle.mjs +1 -2
- package/dist/runtime/button/helpers.mjs +1 -2
- package/dist/runtime/button/index.d.mts +0 -2
- package/dist/runtime/button/index.mjs +1 -2
- package/dist/runtime/button/style.mjs +1 -2
- package/dist/runtime/component/behavior.mjs +1 -2
- package/dist/runtime/component/constants.mjs +1 -2
- package/dist/runtime/component/dom.mjs +1 -2
- package/dist/runtime/component/element.mjs +9 -2
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/events.mjs +4 -4
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/component/index.d.mts +0 -2
- package/dist/runtime/component/index.mjs +1 -2
- package/dist/runtime/component/observers.mjs +1 -2
- package/dist/runtime/component/publicInstance.mjs +1 -2
- package/dist/runtime/component/relations.mjs +1 -2
- package/dist/runtime/component/slots.mjs +1 -2
- package/dist/runtime/component/state.mjs +1 -2
- package/dist/runtime/component/types.d.mts +0 -2
- package/dist/runtime/component/utils.mjs +1 -2
- package/dist/runtime/component/virtualHost.mjs +1 -2
- package/dist/runtime/componentEvents.mjs +1 -2
- package/dist/runtime/dataset.mjs +49 -0
- package/dist/runtime/dataset.mjs.map +1 -0
- package/dist/runtime/datasetBinding.d.mts +13 -0
- package/dist/runtime/datasetBinding.mjs +40 -0
- package/dist/runtime/datasetBinding.mjs.map +1 -0
- package/dist/runtime/eventBinding.d.mts +0 -2
- package/dist/runtime/eventBinding.mjs +1 -2
- package/dist/runtime/execution.d.mts +0 -2
- package/dist/runtime/execution.mjs +1 -2
- package/dist/runtime/host/index.d.mts +0 -2
- package/dist/runtime/host/index.mjs +1 -2
- package/dist/runtime/host/types.d.mts +0 -2
- package/dist/runtime/hostGlobals.d.mts +0 -2
- package/dist/runtime/hostGlobals.mjs +1 -2
- package/dist/runtime/index.d.mts +8 -3
- package/dist/runtime/index.mjs +9 -7
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/runtime/inlineStyle.d.mts +5 -0
- package/dist/runtime/inlineStyle.mjs +21 -0
- package/dist/runtime/inlineStyle.mjs.map +1 -0
- package/dist/runtime/inputHandlerResult.mjs +1 -2
- package/dist/runtime/legacyTemplate/dataset.mjs +53 -0
- package/dist/runtime/legacyTemplate/dataset.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/dom.mjs +20 -5
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/expression.mjs +1 -2
- package/dist/runtime/legacyTemplate/index.d.mts +0 -2
- package/dist/runtime/legacyTemplate/index.mjs +23 -16
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/types.d.mts +0 -2
- package/dist/runtime/nativeComponents/canvas/index.mjs +1 -2
- package/dist/runtime/nativeComponents/checkbox.mjs +1 -2
- package/dist/runtime/nativeComponents/cover/index.mjs +1 -2
- package/dist/runtime/nativeComponents/form.d.mts +0 -2
- package/dist/runtime/nativeComponents/form.mjs +1 -2
- package/dist/runtime/nativeComponents/formControl.mjs +1 -2
- package/dist/runtime/nativeComponents/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/icon/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/icon/index.mjs +1 -2
- package/dist/runtime/nativeComponents/icon/style.mjs +1 -2
- package/dist/runtime/nativeComponents/image.d.mts +0 -2
- package/dist/runtime/nativeComponents/image.mjs +1 -2
- package/dist/runtime/nativeComponents/index.d.mts +1 -3
- package/dist/runtime/nativeComponents/index.mjs +3 -3
- package/dist/runtime/nativeComponents/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/input.d.mts +0 -2
- package/dist/runtime/nativeComponents/input.mjs +1 -2
- package/dist/runtime/nativeComponents/label.mjs +1 -2
- package/dist/runtime/nativeComponents/mediaRegistry.mjs +1 -2
- package/dist/runtime/nativeComponents/movable/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/movable/index.mjs +1 -2
- package/dist/runtime/nativeComponents/navigator.mjs +1 -2
- package/dist/runtime/nativeComponents/picker/editors.mjs +1 -2
- package/dist/runtime/nativeComponents/picker/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/picker/index.mjs +1 -2
- package/dist/runtime/nativeComponents/picker/style.mjs +1 -2
- package/dist/runtime/nativeComponents/pickerView/column.mjs +1 -2
- package/dist/runtime/nativeComponents/pickerView/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/pickerView/index.mjs +1 -2
- package/dist/runtime/nativeComponents/pickerView/style.mjs +1 -2
- package/dist/runtime/nativeComponents/primitives.mjs +1 -2
- package/dist/runtime/nativeComponents/progress/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/progress/index.mjs +1 -2
- package/dist/runtime/nativeComponents/progress/style.mjs +1 -2
- package/dist/runtime/nativeComponents/radio.mjs +1 -2
- package/dist/runtime/nativeComponents/richText/index.mjs +1 -2
- package/dist/runtime/nativeComponents/scrollView/boundaries.mjs +62 -0
- package/dist/runtime/nativeComponents/scrollView/boundaries.mjs.map +1 -0
- package/dist/runtime/nativeComponents/{scrollView.d.mts → scrollView/helpers.d.mts} +4 -5
- package/dist/runtime/nativeComponents/scrollView/helpers.mjs +14 -0
- package/dist/runtime/nativeComponents/scrollView/helpers.mjs.map +1 -0
- package/dist/runtime/nativeComponents/scrollView/index.mjs +193 -0
- package/dist/runtime/nativeComponents/scrollView/index.mjs.map +1 -0
- package/dist/runtime/nativeComponents/scrollView/position.mjs +43 -0
- package/dist/runtime/nativeComponents/scrollView/position.mjs.map +1 -0
- package/dist/runtime/nativeComponents/slider/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/slider/index.mjs +1 -2
- package/dist/runtime/nativeComponents/slider/style.mjs +1 -2
- package/dist/runtime/nativeComponents/style.mjs +1 -2
- package/dist/runtime/nativeComponents/swiper/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/swiper/index.mjs +1 -2
- package/dist/runtime/nativeComponents/swiper/item.mjs +1 -2
- package/dist/runtime/nativeComponents/swiper/style.mjs +1 -2
- package/dist/runtime/nativeComponents/switch.d.mts +0 -2
- package/dist/runtime/nativeComponents/switch.mjs +1 -2
- package/dist/runtime/nativeComponents/textarea.d.mts +0 -2
- package/dist/runtime/nativeComponents/textarea.mjs +1 -2
- package/dist/runtime/nativeComponents/video/helpers.d.mts +0 -2
- package/dist/runtime/nativeComponents/video/helpers.mjs +1 -2
- package/dist/runtime/nativeComponents/video/index.mjs +1 -2
- package/dist/runtime/nativeComponents/video/style.mjs +1 -2
- package/dist/runtime/navigationBar/index.d.mts +0 -2
- package/dist/runtime/navigationBar/index.mjs +1 -2
- package/dist/runtime/navigationBar/style.mjs +1 -2
- package/dist/runtime/pageLayout.d.mts +0 -2
- package/dist/runtime/pageLayout.mjs +1 -2
- package/dist/runtime/polyfill/ad.mjs +1 -2
- package/dist/runtime/polyfill/animation.mjs +1 -2
- package/dist/runtime/polyfill/appState.mjs +1 -2
- package/dist/runtime/polyfill/async.d.mts +0 -2
- package/dist/runtime/polyfill/async.mjs +1 -2
- package/dist/runtime/polyfill/auth.mjs +1 -2
- package/dist/runtime/polyfill/authApi.mjs +1 -2
- package/dist/runtime/polyfill/background.mjs +1 -2
- package/dist/runtime/polyfill/canvasContext.mjs +1 -2
- package/dist/runtime/polyfill/capability.mjs +1 -2
- package/dist/runtime/polyfill/cloud.mjs +1 -2
- package/dist/runtime/polyfill/device.mjs +1 -2
- package/dist/runtime/polyfill/deviceApi.mjs +1 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +0 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +1 -2
- package/dist/runtime/polyfill/eventBus.mjs +1 -2
- package/dist/runtime/polyfill/filePicker.mjs +1 -2
- package/dist/runtime/polyfill/fileSystemManager.mjs +1 -2
- package/dist/runtime/polyfill/files.mjs +1 -2
- package/dist/runtime/polyfill/font.mjs +1 -2
- package/dist/runtime/polyfill/index.d.mts +4 -4
- package/dist/runtime/polyfill/index.mjs +11 -4
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interaction.mjs +1 -2
- package/dist/runtime/polyfill/interactionApi.mjs +1 -2
- package/dist/runtime/polyfill/intersectionObserver.mjs +4 -4
- package/dist/runtime/polyfill/intersectionObserver.mjs.map +1 -1
- package/dist/runtime/polyfill/lifecycleEvents.d.mts +12 -0
- package/dist/runtime/polyfill/lifecycleEvents.mjs +67 -0
- package/dist/runtime/polyfill/lifecycleEvents.mjs.map +1 -0
- package/dist/runtime/polyfill/locale.mjs +1 -2
- package/dist/runtime/polyfill/location.mjs +1 -2
- package/dist/runtime/polyfill/locationApi.mjs +1 -2
- package/dist/runtime/polyfill/mediaActions.mjs +1 -2
- package/dist/runtime/polyfill/mediaApi/file.mjs +1 -2
- package/dist/runtime/polyfill/mediaApi/info.mjs +1 -2
- package/dist/runtime/polyfill/mediaApi/picker.mjs +1 -2
- package/dist/runtime/polyfill/mediaApi/preview.mjs +1 -2
- package/dist/runtime/polyfill/mediaApi/process.mjs +1 -2
- package/dist/runtime/polyfill/mediaInfo.mjs +1 -2
- package/dist/runtime/polyfill/mediaPicker.mjs +1 -2
- package/dist/runtime/polyfill/mediaProcess.mjs +1 -2
- package/dist/runtime/polyfill/menuApi.mjs +5 -3
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +1 -2
- package/dist/runtime/polyfill/network/request.mjs +1 -2
- package/dist/runtime/polyfill/network/requestBridge.mjs +1 -2
- package/dist/runtime/polyfill/network/status.mjs +1 -2
- package/dist/runtime/polyfill/platformApi.mjs +1 -2
- package/dist/runtime/polyfill/platformRuntime.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/events.d.mts +0 -2
- package/dist/runtime/polyfill/routeRuntime/events.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/history.d.mts +0 -2
- package/dist/runtime/polyfill/routeRuntime/history.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +0 -2
- package/dist/runtime/polyfill/routeRuntime/options.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/result.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs +37 -6
- package/dist/runtime/polyfill/routeRuntime/scroll.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/stack.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime/url.mjs +1 -2
- package/dist/runtime/polyfill/routeRuntime.d.mts +2 -2
- package/dist/runtime/polyfill/routeRuntime.mjs +14 -5
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +1 -2
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +0 -2
- package/dist/runtime/polyfill/runtimeDataApi.mjs +1 -2
- package/dist/runtime/polyfill/runtimeInfra.mjs +1 -2
- package/dist/runtime/polyfill/runtimeOps.mjs +1 -2
- package/dist/runtime/polyfill/selectorQuery.mjs +3 -3
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.mjs +1 -2
- package/dist/runtime/polyfill/storageAsync.mjs +1 -2
- package/dist/runtime/polyfill/subscribe.mjs +1 -2
- package/dist/runtime/polyfill/system.mjs +1 -2
- package/dist/runtime/polyfill/systemApi.mjs +1 -2
- package/dist/runtime/polyfill/types/base.d.mts +0 -2
- package/dist/runtime/polyfill/types/common.d.mts +0 -2
- package/dist/runtime/polyfill/types/lifecycle.d.mts +12 -0
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +0 -2
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +0 -2
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +0 -2
- package/dist/runtime/polyfill/types/systemAuth.d.mts +0 -2
- package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +0 -2
- package/dist/runtime/polyfill/ui.mjs +1 -2
- package/dist/runtime/polyfill/uiFeedback.mjs +19 -5
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.d.mts +8 -2
- package/dist/runtime/polyfill/uiMediaApi.mjs +20 -5
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/runtime/polyfill/videoContext.mjs +1 -2
- package/dist/runtime/polyfill/vkSession.mjs +1 -2
- package/dist/runtime/polyfill/windowResize.mjs +1 -2
- package/dist/runtime/polyfill/worker.mjs +1 -2
- package/dist/runtime/polyfill.d.mts +4 -2
- package/dist/runtime/renderContext.d.mts +0 -2
- package/dist/runtime/renderContext.mjs +5 -4
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.d.mts +0 -2
- package/dist/runtime/rpx.mjs +6 -6
- package/dist/runtime/rpx.mjs.map +1 -1
- package/dist/runtime/seo/index.d.mts +0 -2
- package/dist/runtime/seo/index.mjs +1 -2
- package/dist/runtime/style.d.mts +0 -2
- package/dist/runtime/style.mjs +1 -2
- package/dist/runtime/template.d.mts +0 -2
- package/dist/runtime/utils/object.mjs +1 -2
- package/dist/runtime/viewport/index.d.mts +0 -2
- package/dist/runtime/viewport/index.mjs +1 -2
- package/dist/runtime/viewport/style.mjs +2 -2
- package/dist/runtime/viewport/style.mjs.map +1 -1
- package/dist/runtime/viewport/types.d.mts +0 -2
- package/dist/runtime/warning.d.mts +0 -2
- package/dist/runtime/warning.mjs +1 -2
- package/dist/runtime/wevu.d.mts +0 -2
- package/dist/runtime/wevu.mjs +1 -2
- package/dist/shared/nativeComponents.mjs +10 -3
- package/dist/shared/nativeComponents.mjs.map +1 -1
- package/dist/shared/slugify.mjs +1 -2
- package/dist/shared/styleUnits/options.d.mts +24 -0
- package/dist/shared/styleUnits/options.mjs +13 -0
- package/dist/shared/styleUnits/options.mjs.map +1 -0
- package/dist/shared/styleUnits/value.mjs +63 -0
- package/dist/shared/styleUnits/value.mjs.map +1 -0
- package/dist/shared/tabBar.d.mts +0 -2
- package/dist/shared/tabBar.mjs +1 -2
- package/dist/shared/wxml.mjs +1 -2
- package/package.json +15 -13
- package/dist/runtime/nativeComponents/scrollView.mjs +0 -88
- package/dist/runtime/nativeComponents/scrollView.mjs.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { clearRuntimeDataset, storeRuntimeDataset } from "../dataset.mjs";
|
|
2
|
+
import { WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX } from "@weapp-core/constants";
|
|
3
|
+
|
|
4
|
+
// src/runtime/legacyTemplate/dataset.ts
|
|
5
|
+
const commits = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
/** 每次渲染只收集当前组件的值,提交前仍由旧一轮绑定负责读取。 */
|
|
7
|
+
function resetLegacyDatasetRender(context) {
|
|
8
|
+
const commit = commits.get(context);
|
|
9
|
+
if (commit) commit.values = [];
|
|
10
|
+
}
|
|
11
|
+
function recordLegacyDatasetRender(context, values) {
|
|
12
|
+
const commit = commits.get(context) ?? {
|
|
13
|
+
values,
|
|
14
|
+
bound: []
|
|
15
|
+
};
|
|
16
|
+
commit.values = values;
|
|
17
|
+
commits.set(context, commit);
|
|
18
|
+
}
|
|
19
|
+
function createLegacyDatasetAnchor(values, dataset) {
|
|
20
|
+
const index = values.push(dataset) - 1;
|
|
21
|
+
return `<!--${WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX}${index}-->`;
|
|
22
|
+
}
|
|
23
|
+
/** 释放本组件提交过的绑定;重复调用不影响其他组件或同一元素的其他属性。 */
|
|
24
|
+
function releaseLegacyDatasetBindings(context) {
|
|
25
|
+
const commit = commits.get(context);
|
|
26
|
+
if (!commit) return;
|
|
27
|
+
for (const { element, attributes } of commit.bound) for (const attribute of attributes) clearRuntimeDataset(element, attribute);
|
|
28
|
+
commit.bound = [];
|
|
29
|
+
}
|
|
30
|
+
/** HTML 字符串相同也重新提交值,避免相同字符串化结果遮蔽新对象。 */
|
|
31
|
+
function commitLegacyDatasetBindings(root, context) {
|
|
32
|
+
const commit = commits.get(context);
|
|
33
|
+
if (!commit) return;
|
|
34
|
+
releaseLegacyDatasetBindings(context);
|
|
35
|
+
if (commit.values.length === 0) return;
|
|
36
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
37
|
+
while (walker.nextNode()) {
|
|
38
|
+
const comment = walker.currentNode;
|
|
39
|
+
if (!comment.data.startsWith(WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX)) continue;
|
|
40
|
+
const index = comment.data.slice(WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX.length);
|
|
41
|
+
const values = /^\d+$/.test(index) ? commit.values[Number(index)] : void 0;
|
|
42
|
+
const element = comment.nextSibling;
|
|
43
|
+
if (!values || element?.nodeType !== Node.ELEMENT_NODE) continue;
|
|
44
|
+
for (const [attribute, value] of values) storeRuntimeDataset(element, attribute, value);
|
|
45
|
+
commit.bound.push({
|
|
46
|
+
element,
|
|
47
|
+
attributes: [...values.keys()]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { commitLegacyDatasetBindings, createLegacyDatasetAnchor, recordLegacyDatasetRender, releaseLegacyDatasetBindings, resetLegacyDatasetRender };
|
|
53
|
+
//# sourceMappingURL=dataset.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dataset.ts"],"sourcesContent":["import { WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX } from '@weapp-core/constants'\nimport { clearRuntimeDataset, storeRuntimeDataset } from '../dataset'\n\nexport type LegacyDatasetValues = Array<Map<string, unknown>>\n\ninterface LegacyDatasetCommit {\n values: LegacyDatasetValues\n bound: Array<{ element: Element, attributes: string[] }>\n}\n\nconst commits = new WeakMap<object, LegacyDatasetCommit>()\n\n/** 每次渲染只收集当前组件的值,提交前仍由旧一轮绑定负责读取。 */\nexport function resetLegacyDatasetRender(context: object) {\n const commit = commits.get(context)\n if (commit) {\n commit.values = []\n }\n}\n\nexport function recordLegacyDatasetRender(context: object, values: LegacyDatasetValues) {\n const commit = commits.get(context) ?? { values, bound: [] }\n commit.values = values\n commits.set(context, commit)\n}\n\nexport function createLegacyDatasetAnchor(values: LegacyDatasetValues, dataset: Map<string, unknown>) {\n const index = values.push(dataset) - 1\n return `<!--${WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX}${index}-->`\n}\n\n/** 释放本组件提交过的绑定;重复调用不影响其他组件或同一元素的其他属性。 */\nexport function releaseLegacyDatasetBindings(context: object) {\n const commit = commits.get(context)\n if (!commit) {\n return\n }\n for (const { element, attributes } of commit.bound) {\n for (const attribute of attributes) {\n clearRuntimeDataset(element, attribute)\n }\n }\n commit.bound = []\n}\n\n/** HTML 字符串相同也重新提交值,避免相同字符串化结果遮蔽新对象。 */\nexport function commitLegacyDatasetBindings(root: HTMLElement | ShadowRoot, context: object) {\n const commit = commits.get(context)\n if (!commit) {\n return\n }\n releaseLegacyDatasetBindings(context)\n if (commit.values.length === 0) {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT)\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment\n if (!comment.data.startsWith(WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX)) {\n continue\n }\n const index = comment.data.slice(WEAPP_VITE_WEB_LEGACY_DATASET_COMMENT_PREFIX.length)\n const values = /^\\d+$/.test(index) ? commit.values[Number(index)] : undefined\n const element = comment.nextSibling\n if (!values || element?.nodeType !== Node.ELEMENT_NODE) {\n continue\n }\n for (const [attribute, value] of values) {\n storeRuntimeDataset(element as Element, attribute, value)\n }\n commit.bound.push({ element: element as Element, attributes: [...values.keys()] })\n }\n}\n"],"mappings":";;;;AAUA,MAAM,0BAAU,IAAI,QAAqC;;AAGzD,SAAgB,yBAAyB,SAAiB;CACxD,MAAM,SAAS,QAAQ,IAAI,OAAO;CAClC,IAAI,QACF,OAAO,SAAS,CAAC;AAErB;AAEA,SAAgB,0BAA0B,SAAiB,QAA6B;CACtF,MAAM,SAAS,QAAQ,IAAI,OAAO,KAAK;EAAE;EAAQ,OAAO,CAAC;CAAE;CAC3D,OAAO,SAAS;CAChB,QAAQ,IAAI,SAAS,MAAM;AAC7B;AAEA,SAAgB,0BAA0B,QAA6B,SAA+B;CACpG,MAAM,QAAQ,OAAO,KAAK,OAAO,IAAI;CACrC,OAAO,OAAO,+CAA+C,MAAM;AACrE;;AAGA,SAAgB,6BAA6B,SAAiB;CAC5D,MAAM,SAAS,QAAQ,IAAI,OAAO;CAClC,IAAI,CAAC,QACH;CAEF,KAAK,MAAM,EAAE,SAAS,gBAAgB,OAAO,OAC3C,KAAK,MAAM,aAAa,YACtB,oBAAoB,SAAS,SAAS;CAG1C,OAAO,QAAQ,CAAC;AAClB;;AAGA,SAAgB,4BAA4B,MAAgC,SAAiB;CAC3F,MAAM,SAAS,QAAQ,IAAI,OAAO;CAClC,IAAI,CAAC,QACH;CAEF,6BAA6B,OAAO;CACpC,IAAI,OAAO,OAAO,WAAW,GAC3B;CAEF,MAAM,SAAS,SAAS,iBAAiB,MAAM,WAAW,YAAY;CACtE,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,IAAI,CAAC,QAAQ,KAAK,WAAW,4CAA4C,GACvE;EAEF,MAAM,QAAQ,QAAQ,KAAK,MAAM,6CAA6C,MAAM;EACpF,MAAM,SAAS,QAAQ,KAAK,KAAK,IAAI,OAAO,OAAO,OAAO,KAAK,KAAK;EACpE,MAAM,UAAU,QAAQ;EACxB,IAAI,CAAC,UAAU,SAAS,aAAa,KAAK,cACxC;EAEF,KAAK,MAAM,CAAC,WAAW,UAAU,QAC/B,oBAAoB,SAAoB,WAAW,KAAK;EAE1D,OAAO,MAAM,KAAK;GAAW;GAAoB,YAAY,CAAC,GAAG,OAAO,KAAK,CAAC;EAAE,CAAC;CACnF;AACF"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CONTROL_ATTRS, EVENT_KIND_ALIAS, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
2
|
import { MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, encodeEventAttributeName } from "../component/constants.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { transformInlineStyleValue } from "../inlineStyle.mjs";
|
|
4
|
+
import { escapeAttribute, evaluateExpression, resolveAttributeValue } from "./expression.mjs";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// src/runtime/legacyTemplate/dom.ts
|
|
6
7
|
const EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\w-]+)$/;
|
|
7
8
|
const EVENT_PREFIX_FLAGS = {
|
|
8
9
|
"bind": {},
|
|
@@ -49,7 +50,7 @@ function extractFor(attribs) {
|
|
|
49
50
|
restAttribs
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
function buildAttributeString(attribs, scope) {
|
|
53
|
+
function buildAttributeString(attribs, scope, dataset) {
|
|
53
54
|
let result = "";
|
|
54
55
|
for (const [name, rawValue] of Object.entries(attribs)) {
|
|
55
56
|
if (CONTROL_ATTRS.has(name)) continue;
|
|
@@ -66,9 +67,24 @@ function buildAttributeString(attribs, scope) {
|
|
|
66
67
|
if (flagTokens.length) result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${encodedEvent}="${flagTokens.join(",")}"`;
|
|
67
68
|
continue;
|
|
68
69
|
}
|
|
70
|
+
const normalizedName = normalizeAttributeName(name);
|
|
71
|
+
if (normalizedName.startsWith("data-")) {
|
|
72
|
+
const trimmed = rawValue.trim();
|
|
73
|
+
const expression = /^\{\{((?:(?!\}\})[\s\S])*)\}\}$/.exec(trimmed);
|
|
74
|
+
const value = expression ? evaluateExpression(expression[1], scope) : rawValue.replace(/\{\{([\s\S]*?)\}\}/g, (_, source) => String(evaluateExpression(source, scope) ?? ""));
|
|
75
|
+
dataset?.set(normalizedName, value);
|
|
76
|
+
result += ` ${normalizedName}="${escapeAttribute(String(value ?? ""))}"`;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (normalizedName === "style") {
|
|
80
|
+
const expression = /^\{\{((?:(?!\}\})[\s\S])*)\}\}$/.exec(rawValue.trim());
|
|
81
|
+
const rawStyle = expression ? evaluateExpression(expression[1], scope) : resolveAttributeValue(rawValue, scope);
|
|
82
|
+
const style = transformInlineStyleValue(rawStyle);
|
|
83
|
+
if (style != null && style !== "") result += ` style="${escapeAttribute(String(style))}"`;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
69
86
|
const value = resolveAttributeValue(rawValue, scope);
|
|
70
87
|
if (value === "") continue;
|
|
71
|
-
const normalizedName = normalizeAttributeName(name);
|
|
72
88
|
result += ` ${normalizedName}="${escapeAttribute(value)}"`;
|
|
73
89
|
}
|
|
74
90
|
return result;
|
|
@@ -84,6 +100,5 @@ function isConditionalElement(node) {
|
|
|
84
100
|
return hasControlAttribute(attribs, "if") || hasControlAttribute(attribs, "elif") || hasControlAttribute(attribs, "else");
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
//#endregion
|
|
88
103
|
export { buildAttributeString, extractFor, isConditionalElement, stripControlAttributes };
|
|
89
104
|
//# sourceMappingURL=dom.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n encodeEventAttributeName,\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_PREFIX_FLAGS: Record<string, { catch?: boolean, capture?: boolean }> = {\n 'bind': {},\n 'catch': { catch: true },\n 'mut-bind': {},\n 'capture-bind': { capture: true },\n 'capture-catch': { capture: true, catch: true },\n}\n\nfunction parseEventAttribute(name: string) {\n const separatorIndex = name.indexOf(':')\n if (separatorIndex >= 0) {\n const prefix = name.slice(0, separatorIndex)\n const rawEvent = name.slice(separatorIndex + 1)\n if (rawEvent && prefix in EVENT_PREFIX_FLAGS) {\n return { prefix, rawEvent }\n }\n return undefined\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: match[1]!, rawEvent: match[2]! }\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const restAttribs: Record<string, string> = {}\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(key)) {\n continue\n }\n restAttribs[key] = val\n }\n\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n\n return {\n expr,\n itemName,\n indexName,\n restAttribs,\n }\n}\n\nexport function buildAttributeString(\n attribs: Record<string, string>,\n scope: LegacyTemplateScope,\n) {\n let result = ''\n for (const [name, rawValue] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n\n const eventInfo = parseEventAttribute(name)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const runtimeEvent = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const encodedEvent = encodeEventAttributeName(runtimeEvent)\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const flags = EVENT_PREFIX_FLAGS[eventInfo.prefix]!\n result += ` ${MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX}${encodedEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${encodedEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const value =
|
|
1
|
+
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n encodeEventAttributeName,\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { transformInlineStyleValue } from '../inlineStyle'\nimport { escapeAttribute, evaluateExpression, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_PREFIX_FLAGS: Record<string, { catch?: boolean, capture?: boolean }> = {\n 'bind': {},\n 'catch': { catch: true },\n 'mut-bind': {},\n 'capture-bind': { capture: true },\n 'capture-catch': { capture: true, catch: true },\n}\n\nfunction parseEventAttribute(name: string) {\n const separatorIndex = name.indexOf(':')\n if (separatorIndex >= 0) {\n const prefix = name.slice(0, separatorIndex)\n const rawEvent = name.slice(separatorIndex + 1)\n if (rawEvent && prefix in EVENT_PREFIX_FLAGS) {\n return { prefix, rawEvent }\n }\n return undefined\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: match[1]!, rawEvent: match[2]! }\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const restAttribs: Record<string, string> = {}\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(key)) {\n continue\n }\n restAttribs[key] = val\n }\n\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n\n return {\n expr,\n itemName,\n indexName,\n restAttribs,\n }\n}\n\nexport function buildAttributeString(\n attribs: Record<string, string>,\n scope: LegacyTemplateScope,\n dataset?: Map<string, unknown>,\n) {\n let result = ''\n for (const [name, rawValue] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n\n const eventInfo = parseEventAttribute(name)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const runtimeEvent = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const encodedEvent = encodeEventAttributeName(runtimeEvent)\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const flags = EVENT_PREFIX_FLAGS[eventInfo.prefix]!\n result += ` ${MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX}${encodedEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${encodedEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const normalizedName = normalizeAttributeName(name)\n if (normalizedName.startsWith('data-')) {\n const trimmed = rawValue.trim()\n const expression = /^\\{\\{((?:(?!\\}\\})[\\s\\S])*)\\}\\}$/.exec(trimmed)\n const value: unknown = expression\n ? evaluateExpression(expression[1]!, scope)\n : rawValue.replace(/\\{\\{([\\s\\S]*?)\\}\\}/g, (_, source: string) => String(evaluateExpression(source, scope) ?? ''))\n dataset?.set(normalizedName, value)\n result += ` ${normalizedName}=\"${escapeAttribute(String(value ?? ''))}\"`\n continue\n }\n if (normalizedName === 'style') {\n const expression = /^\\{\\{((?:(?!\\}\\})[\\s\\S])*)\\}\\}$/.exec(rawValue.trim())\n const rawStyle: unknown = expression\n ? evaluateExpression(expression[1]!, scope)\n : resolveAttributeValue(rawValue, scope)\n const style = transformInlineStyleValue(rawStyle)\n if (style != null && style !== '') {\n result += ` style=\"${escapeAttribute(String(style))}\"`\n }\n continue\n }\n const value = resolveAttributeValue(rawValue, scope)\n if (value === '') {\n continue\n }\n result += ` ${normalizedName}=\"${escapeAttribute(value)}\"`\n }\n return result\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nexport function isConditionalElement(node: Node): node is Element {\n if (node.type !== 'tag') {\n return false\n }\n const attribs = (node as Element).attribs\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n"],"mappings":";;;;;;AAiBA,MAAM,kBAAkB;AACxB,MAAM,qBAA6E;CACjF,QAAQ,CAAC;CACT,SAAS,EAAE,OAAO,KAAK;CACvB,YAAY,CAAC;CACb,gBAAgB,EAAE,SAAS,KAAK;CAChC,iBAAiB;EAAE,SAAS;EAAM,OAAO;CAAK;AAChD;AAEA,SAAS,oBAAoB,MAAc;CACzC,MAAM,iBAAiB,KAAK,QAAQ,GAAG;CACvC,IAAI,kBAAkB,GAAG;EACvB,MAAM,SAAS,KAAK,MAAM,GAAG,cAAc;EAC3C,MAAM,WAAW,KAAK,MAAM,iBAAiB,CAAC;EAC9C,IAAI,YAAY,UAAU,oBACxB,OAAO;GAAE;GAAQ;EAAS;EAE5B;CACF;CACA,MAAM,QAAQ,gBAAgB,KAAK,IAAI;CACvC,IAAI,CAAC,OACH;CAEF,OAAO;EAAE,QAAQ,MAAM;EAAK,UAAU,MAAM;CAAI;AAClD;AAEA,SAAgB,WAAW,SAAmD;CAC5E,MAAM,OAAO,6BAA6B,SAAS,KAAK;CACxD,MAAM,cAAsC,CAAC;CAC7C,MAAM,WAAW,6BAA6B,SAAS,UAAU,CAAC,EAAE,KAAK,KAAK;CAC9E,IAAI,YAAY,6BAA6B,SAAS,WAAW,CAAC,EAAE,KAAK,KAAK;CAE9E,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,OAAO,GAAG;EAChD,IAAI,cAAc,IAAI,GAAG,GACvB;EAEF,YAAY,OAAO;CACrB;CAEA,IAAI,aAAa,WACf,YAAY,GAAG,UAAU;CAG3B,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAEA,SAAgB,qBACd,SACA,OACA,SACA;CACA,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,OAAO,GAAG;EACtD,IAAI,cAAc,IAAI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M,QAAQ,sBAAsB,UAAU,KAAK;EACnD,IAAI,UAAU,IACZ;EAEF,UAAU,IAAI,eAAe,IAAI,gBAAgB,KAAK,EAAE;CAC1D;CACA,OAAO;AACT;AAEA,SAAgB,uBAAuB,SAAiC;CACtE,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,CAAC,cAAc,IAAI,IAAI,GACzB,OAAO,QAAQ;CAGnB,OAAO;AACT;AAEA,SAAgB,qBAAqB,MAA6B;CAChE,IAAI,KAAK,SAAS,OAChB,OAAO;CAET,MAAM,UAAW,KAAiB;CAClC,OAAO,oBAAoB,SAAS,IAAI,KACnC,oBAAoB,SAAS,MAAM,KACnC,oBAAoB,SAAS,MAAM;AAC1C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from "../execution.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/runtime/legacyTemplate/expression.ts
|
|
4
4
|
const expressionCache = /* @__PURE__ */ new Map();
|
|
5
5
|
function createScope(initial) {
|
|
6
6
|
return Object.assign(Object.create(null), initial ?? {});
|
|
@@ -108,6 +108,5 @@ function resolveAttributeValue(value, scope) {
|
|
|
108
108
|
return interpolateText(value ?? "", scope, false);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
//#endregion
|
|
112
111
|
export { createChildScope, createScope, escapeAttribute, escapeHtml, evaluateExpression, interpolateText, normalizeList, resolveAttributeValue };
|
|
113
112
|
//# sourceMappingURL=expression.mjs.map
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { LegacyTemplateRenderer, LegacyTemplateScope } from "./types.mjs";
|
|
2
2
|
import { ChildNode } from "domhandler";
|
|
3
|
-
//#region src/runtime/legacyTemplate/index.d.ts
|
|
4
3
|
export declare function renderTemplate(nodes: ChildNode[], scope?: LegacyTemplateScope): string;
|
|
5
4
|
export declare function createTemplate(source: string): LegacyTemplateRenderer;
|
|
6
|
-
//#endregion
|
|
7
5
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { SELF_CLOSING_TAGS, hasControlAttribute, normalizeTagName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
|
+
import { createLegacyDatasetAnchor, recordLegacyDatasetRender } from "./dataset.mjs";
|
|
2
3
|
import { createChildScope, createScope, evaluateExpression, interpolateText, normalizeList } from "./expression.mjs";
|
|
3
4
|
import { buildAttributeString, extractFor, isConditionalElement, stripControlAttributes } from "./dom.mjs";
|
|
4
5
|
import { parseDocument } from "htmlparser2";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
// src/runtime/legacyTemplate/index.ts
|
|
7
8
|
const templateCache = /* @__PURE__ */ new Map();
|
|
8
9
|
function filterRenderableNode(node) {
|
|
9
10
|
if (node.type === "directive" || node.type === "comment") return false;
|
|
@@ -22,7 +23,7 @@ function getOrParseTemplate(source) {
|
|
|
22
23
|
}
|
|
23
24
|
return cached;
|
|
24
25
|
}
|
|
25
|
-
function renderConditionalSequence(nodes, startIndex, scope, renderChildren) {
|
|
26
|
+
function renderConditionalSequence(nodes, startIndex, scope, renderChildren, datasets) {
|
|
26
27
|
const branches = [];
|
|
27
28
|
let cursor = startIndex;
|
|
28
29
|
while (cursor < nodes.length) {
|
|
@@ -48,13 +49,13 @@ function renderConditionalSequence(nodes, startIndex, scope, renderChildren) {
|
|
|
48
49
|
}
|
|
49
50
|
for (const { node, attribs } of branches) {
|
|
50
51
|
if (hasControlAttribute(attribs, "else")) return {
|
|
51
|
-
rendered: renderElement(node, scope, renderChildren, { overrideAttribs: stripControlAttributes(attribs) }),
|
|
52
|
+
rendered: renderElement(node, scope, renderChildren, { overrideAttribs: stripControlAttributes(attribs) }, datasets),
|
|
52
53
|
endIndex: startIndex + branches.length - 1
|
|
53
54
|
};
|
|
54
55
|
const conditionExpr = resolveControlAttributeValue(attribs, "if") ?? resolveControlAttributeValue(attribs, "elif");
|
|
55
56
|
if (!conditionExpr) continue;
|
|
56
57
|
if (evaluateExpression(conditionExpr, scope)) return {
|
|
57
|
-
rendered: renderElement(node, scope, renderChildren, { overrideAttribs: stripControlAttributes(attribs) }),
|
|
58
|
+
rendered: renderElement(node, scope, renderChildren, { overrideAttribs: stripControlAttributes(attribs) }, datasets),
|
|
58
59
|
endIndex: startIndex + branches.length - 1
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -63,7 +64,7 @@ function renderConditionalSequence(nodes, startIndex, scope, renderChildren) {
|
|
|
63
64
|
endIndex: startIndex + branches.length - 1
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
|
-
function renderElement(node, scope, renderChildren, options = {}) {
|
|
67
|
+
function renderElement(node, scope, renderChildren, options = {}, datasets) {
|
|
67
68
|
const attribs = node.attribs;
|
|
68
69
|
if (!options.skipFor) {
|
|
69
70
|
const forExtract = extractFor(attribs);
|
|
@@ -79,7 +80,7 @@ function renderElement(node, scope, renderChildren, options = {}) {
|
|
|
79
80
|
buffer += renderElement(node, childScope, renderChildren, {
|
|
80
81
|
skipFor: true,
|
|
81
82
|
overrideAttribs: forExtract.restAttribs
|
|
82
|
-
});
|
|
83
|
+
}, datasets);
|
|
83
84
|
}
|
|
84
85
|
return buffer;
|
|
85
86
|
}
|
|
@@ -87,36 +88,38 @@ function renderElement(node, scope, renderChildren, options = {}) {
|
|
|
87
88
|
const effectiveAttribs = options.overrideAttribs ?? attribs;
|
|
88
89
|
const normalizedTag = normalizeTagName(node.name);
|
|
89
90
|
if (normalizedTag === "#fragment") return renderChildren(node.children, scope);
|
|
90
|
-
const
|
|
91
|
+
const dataset = datasets ? /* @__PURE__ */ new Map() : void 0;
|
|
92
|
+
const attrs = buildAttributeString(effectiveAttribs, scope, dataset);
|
|
93
|
+
const anchor = dataset?.size && datasets ? createLegacyDatasetAnchor(datasets, dataset) : "";
|
|
91
94
|
const children = renderChildren(node.children, scope);
|
|
92
|
-
if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) return
|
|
93
|
-
return
|
|
95
|
+
if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) return `${anchor}<${normalizedTag}${attrs} />`;
|
|
96
|
+
return `${anchor}<${normalizedTag}${attrs}>${children}</${normalizedTag}>`;
|
|
94
97
|
}
|
|
95
98
|
function renderTextNode(node, scope) {
|
|
96
99
|
const value = node.data;
|
|
97
100
|
if (!value.trim()) return "";
|
|
98
101
|
return interpolateText(value, scope, true);
|
|
99
102
|
}
|
|
100
|
-
function renderTree(input, scope) {
|
|
103
|
+
function renderTree(input, scope, datasets) {
|
|
101
104
|
if (!input) return "";
|
|
102
105
|
if (Array.isArray(input)) {
|
|
103
106
|
let buffer = "";
|
|
104
107
|
for (let index = 0; index < input.length; index++) {
|
|
105
108
|
const node = input[index];
|
|
106
109
|
if (isConditionalElement(node)) {
|
|
107
|
-
const { rendered, endIndex } = renderConditionalSequence(input, index, scope, renderTree);
|
|
110
|
+
const { rendered, endIndex } = renderConditionalSequence(input, index, scope, (nodes, childScope) => renderTree(nodes, childScope, datasets), datasets);
|
|
108
111
|
buffer += rendered;
|
|
109
112
|
index = endIndex;
|
|
110
113
|
continue;
|
|
111
114
|
}
|
|
112
|
-
buffer += renderTree(node, scope);
|
|
115
|
+
buffer += renderTree(node, scope, datasets);
|
|
113
116
|
}
|
|
114
117
|
return buffer;
|
|
115
118
|
}
|
|
116
119
|
const node = input;
|
|
117
120
|
if (node.type === "text") return renderTextNode(node, scope);
|
|
118
|
-
if (node.type === "tag" || node.type === "script" || node.type === "style") return renderElement(node, scope, renderTree);
|
|
119
|
-
if ("children" in node && node.children?.length) return renderTree(node.children, scope);
|
|
121
|
+
if (node.type === "tag" || node.type === "script" || node.type === "style") return renderElement(node, scope, (nodes, childScope) => renderTree(nodes, childScope, datasets), {}, datasets);
|
|
122
|
+
if ("children" in node && node.children?.length) return renderTree(node.children, scope, datasets);
|
|
120
123
|
return "";
|
|
121
124
|
}
|
|
122
125
|
function renderTemplate(nodes, scope) {
|
|
@@ -124,9 +127,13 @@ function renderTemplate(nodes, scope) {
|
|
|
124
127
|
}
|
|
125
128
|
function createTemplate(source) {
|
|
126
129
|
const nodes = getOrParseTemplate(source);
|
|
127
|
-
return (scope) =>
|
|
130
|
+
return (scope, context) => {
|
|
131
|
+
const datasets = context ? [] : void 0;
|
|
132
|
+
const result = renderTree(nodes, createScope(scope), datasets);
|
|
133
|
+
if (context && datasets) recordLegacyDatasetRender(context, datasets);
|
|
134
|
+
return result;
|
|
135
|
+
};
|
|
128
136
|
}
|
|
129
137
|
|
|
130
|
-
//#endregion
|
|
131
138
|
export { createTemplate, renderTemplate };
|
|
132
139
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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\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,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,WAC7C,OAAO;CAET,IAAI,KAAK,SAAS,QAEhB,OADc,KAAkB,KACpB,KAAK,CAAC,CAAC,SAAS;CAE9B,OAAO;AACT;AAEA,SAAS,mBAAmB,QAAgB;CAC1C,IAAI,SAAS,cAAc,IAAI,MAAM;CACrC,IAAI,CAAC,QAAQ;EAMX,SALiB,cAAc,QAAQ;GACrC,SAAS;GACT,gBAAgB;GAChB,sBAAsB;EACxB,CACgB,CAAC,CAAC,SAAS,OAAO,oBAAoB;EACtD,cAAc,IAAI,QAAQ,MAAM;CAClC;CACA,OAAO;AACT;AAEA,SAAS,0BACP,OACA,YACA,OACA,gBACA;CACA,MAAM,WAAsE,CAAC;CAC7E,IAAI,SAAS;CAEb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,YAAY,MAAM;EACxB,IAAI,CAAC,qBAAqB,SAAS,GACjC;EAEF,MAAM,UAAU;EAChB,MAAM,UAAU,QAAQ;EACxB,IAAI,SAAS,WAAW,KAAK,CAAC,oBAAoB,SAAS,IAAI,GAC7D;EAEF,IAAI,SAAS,SAAS,KAAK,CAAC,oBAAoB,SAAS,MAAM,KAAK,CAAC,oBAAoB,SAAS,MAAM,GACtG;EAEF,SAAS,KAAK;GAAE,MAAM;GAAS;EAAQ,CAAC;EACxC,UAAU;EACV,IAAI,oBAAoB,SAAS,MAAM,GACrC;CAEJ;CAEA,IAAI,CAAC,SAAS,QAAQ;EACpB,MAAM,OAAO,MAAM;EACnB,OAAO;GACL,UAAU,eAAe,MAAM,KAAK;GACpC,UAAU;EACZ;CACF;CAEA,KAAK,MAAM,EAAE,MAAM,aAA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AK;CAEpD,IAAI,kBAAkB,IAAI,aAAa,KAAK,CAAC,UAC3C,OAAO,IAAI,gBAAgB,MAAM;CAGnC,OAAO,IAAI,gBAAgB,MAAM,GAAG,SAAS,IAAI,cAAc;AACjE;AAEA,SAAS,eAAe,MAAgB,OAA4B;CAClE,MAAM,QAAQ,KAAK;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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type { LegacyDatasetValues } from './dataset'\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 { createLegacyDatasetAnchor, recordLegacyDatasetRender } from './dataset'\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 datasets?: LegacyDatasetValues,\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 datasets,\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 datasets,\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 datasets?: LegacyDatasetValues,\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 }, datasets)\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 dataset = datasets ? new Map<string, unknown>() : undefined\n const attrs = buildAttributeString(effectiveAttribs, scope, dataset)\n const anchor = dataset?.size && datasets ? createLegacyDatasetAnchor(datasets, dataset) : ''\n const children = renderChildren(node.children, scope)\n\n if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) {\n return `${anchor}<${normalizedTag}${attrs} />`\n }\n\n return `${anchor}<${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 datasets?: LegacyDatasetValues,\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, (nodes, childScope) => renderTree(nodes, childScope, datasets), datasets)\n buffer += rendered\n index = endIndex\n continue\n }\n buffer += renderTree(node, scope, datasets)\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, (nodes, childScope) => renderTree(nodes, childScope, datasets), {}, datasets)\n }\n if ('children' in node && node.children?.length) {\n return renderTree(node.children, scope, datasets)\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, context?: object) => {\n const datasets: LegacyDatasetValues | undefined = context ? [] : undefined\n const result = renderTree(nodes, createScope(scope), datasets)\n if (context && datasets) {\n recordLegacyDatasetRender(context, datasets)\n }\n return result\n }\n}\n\nexport type { LegacyTemplateRenderer, LegacyTemplateScope } from './types'\n"],"mappings":";;;;;;;AA6BA,MAAM,g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qB;EACxD,MAAM,WAA4C,UAAU,CAAC,IAAI;EACjE,MAAM,SAAS,WAAW,OAAO,YAAY,KAAK,GAAG,QAAQ;EAC7D,IAAI,WAAW,UACb,0BAA0B,SAAS,QAAQ;EAE7C,OAAO;CACT;AACF"}
|
|
@@ -3,7 +3,7 @@ import { readBooleanAttribute, resolveContainingShadowRoot } from "../helpers.mj
|
|
|
3
3
|
import { ensureNativeComponentStyle } from "../style.mjs";
|
|
4
4
|
import { registerNativeMediaElement, unregisterNativeMediaElement } from "../mediaRegistry.mjs";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/runtime/nativeComponents/canvas/index.ts
|
|
7
7
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
8
|
function resolveCanvasSize(value, fallback) {
|
|
9
9
|
const size = Number(value);
|
|
@@ -57,6 +57,5 @@ var WeappCanvas = class extends BaseElement {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
//#endregion
|
|
61
60
|
export { WeappCanvas };
|
|
62
61
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -3,7 +3,7 @@ import { connectFormControl, disconnectFormControl, findClosestComposedElement }
|
|
|
3
3
|
import { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot } from "./helpers.mjs";
|
|
4
4
|
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/runtime/nativeComponents/checkbox.ts
|
|
7
7
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
8
|
function collectCheckboxGroupValue(checkboxes) {
|
|
9
9
|
return Array.from(checkboxes).filter((checkbox) => checkbox.checked && !checkbox.disabled).map((checkbox) => checkbox.value);
|
|
@@ -132,6 +132,5 @@ var WeappCheckbox = class extends BaseElement {
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
//#endregion
|
|
136
135
|
export { WeappCheckbox, WeappCheckboxGroup, collectCheckboxGroupValue };
|
|
137
136
|
//# sourceMappingURL=checkbox.mjs.map
|
|
@@ -2,7 +2,7 @@ import { getNativeComponentDescriptor } from "../../../shared/nativeComponents.m
|
|
|
2
2
|
import { WeappImage } from "../image.mjs";
|
|
3
3
|
import { WeappView } from "../primitives.mjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/runtime/nativeComponents/cover/index.ts
|
|
6
6
|
var WeappCoverView = class extends WeappView {
|
|
7
7
|
connectedCallback() {
|
|
8
8
|
super.connectedCallback();
|
|
@@ -18,6 +18,5 @@ var WeappCoverImage = class extends WeappImage {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
//#endregion
|
|
22
21
|
export { WeappCoverImage, WeappCoverView };
|
|
23
22
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -2,7 +2,7 @@ import { collectFormControlValues, resetFormControls } from "./formControl.mjs";
|
|
|
2
2
|
import { dispatchMiniProgramEvent, resolveContainingShadowRoot } from "./helpers.mjs";
|
|
3
3
|
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/runtime/nativeComponents/form.ts
|
|
6
6
|
const DEFAULT_FORM_CONFIG = { preventDefault: true };
|
|
7
7
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
8
|
let formConfig = { ...DEFAULT_FORM_CONFIG };
|
|
@@ -45,6 +45,5 @@ function setFormConfig(next) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
//#endregion
|
|
49
48
|
export { WeappForm, setFormConfig };
|
|
50
49
|
//# sourceMappingURL=form.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/runtime/nativeComponents/formControl.ts
|
|
2
2
|
const controlsByForm = /* @__PURE__ */ new WeakMap();
|
|
3
3
|
const formByControl = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
function resolveParentAcrossShadow(element) {
|
|
@@ -56,6 +56,5 @@ function isFormActivatable(value) {
|
|
|
56
56
|
return typeof value.formActivate === "function";
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
//#endregion
|
|
60
59
|
export { collectFormControlValues, connectFormControl, disconnectFormControl, findClosestComposedElement, isFormActivatable, requestContainingFormAction, resetFormControls };
|
|
61
60
|
//# sourceMappingURL=formControl.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/runtime/nativeComponents/helpers.ts
|
|
2
2
|
function readBooleanAttribute(element, name) {
|
|
3
3
|
const value = element.getAttribute(name);
|
|
4
4
|
return value !== null && value !== "false" && value !== "0";
|
|
@@ -20,6 +20,5 @@ function dispatchMiniProgramEvent(element, name, detail, options = {}) {
|
|
|
20
20
|
}));
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
//#endregion
|
|
24
23
|
export { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot, resolveMaxLength };
|
|
25
24
|
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/runtime/nativeComponents/icon/helpers.ts
|
|
2
2
|
const ICON_TYPES = [
|
|
3
3
|
"success",
|
|
4
4
|
"success_no_circle",
|
|
@@ -37,6 +37,5 @@ function resolveIconColor(type, value) {
|
|
|
37
37
|
return String(value ?? "").trim() || DEFAULT_ICON_COLORS[type];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
//#endregion
|
|
41
40
|
export { ICON_TYPES, resolveIconColor, resolveIconSize, resolveIconType };
|
|
42
41
|
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -4,7 +4,7 @@ import { ensureNativeComponentStyle } from "../style.mjs";
|
|
|
4
4
|
import { ICON_TYPES, resolveIconColor, resolveIconSize, resolveIconType } from "./helpers.mjs";
|
|
5
5
|
import { ICON_SHADOW_STYLE } from "./style.mjs";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/runtime/nativeComponents/icon/index.ts
|
|
8
8
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
9
9
|
var WeappIcon = class extends BaseElement {
|
|
10
10
|
static observedAttributes = [...getNativeComponentDescriptor("icon").attributes];
|
|
@@ -40,6 +40,5 @@ var WeappIcon = class extends BaseElement {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
//#endregion
|
|
44
43
|
export { ICON_TYPES, WeappIcon, resolveIconColor, resolveIconSize, resolveIconType };
|
|
45
44
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/runtime/nativeComponents/icon/style.ts
|
|
2
2
|
const ICON_SHADOW_STYLE = `
|
|
3
3
|
:host {
|
|
4
4
|
width: var(--weapp-icon-size);
|
|
@@ -171,6 +171,5 @@ const ICON_SHADOW_STYLE = `
|
|
|
171
171
|
}
|
|
172
172
|
`;
|
|
173
173
|
|
|
174
|
-
//#endregion
|
|
175
174
|
export { ICON_SHADOW_STYLE };
|
|
176
175
|
//# sourceMappingURL=style.mjs.map
|
|
@@ -2,7 +2,7 @@ import { getNativeComponentDescriptor } from "../../shared/nativeComponents.mjs"
|
|
|
2
2
|
import { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadowRoot } from "./helpers.mjs";
|
|
3
3
|
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/runtime/nativeComponents/image.ts
|
|
6
6
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
7
7
|
const IMAGE_MODE_STYLES = {
|
|
8
8
|
"scaleToFill": {
|
|
@@ -116,6 +116,5 @@ var WeappImage = class extends BaseElement {
|
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
//#endregion
|
|
120
119
|
export { WeappImage, resolveImageModeStyle };
|
|
121
120
|
//# sourceMappingURL=image.mjs.map
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { resolveImageModeStyle } from "./image.mjs";
|
|
2
2
|
import { createInputEventDetail } from "./input.mjs";
|
|
3
|
-
import { createScrollEventDetail } from "./scrollView.mjs";
|
|
3
|
+
import { createScrollEventDetail } from "./scrollView/helpers.mjs";
|
|
4
4
|
import { createSwitchEventDetail } from "./switch.mjs";
|
|
5
5
|
import { createTextareaLineChangeDetail } from "./textarea.mjs";
|
|
6
6
|
import { createVideoProgressDetail, createVideoTimeUpdateDetail, resolveVideoObjectFit } from "./video/helpers.mjs";
|
|
7
|
-
//#region src/runtime/nativeComponents/index.d.ts
|
|
8
7
|
export declare function ensureNativeComponentsDefined(): void;
|
|
9
|
-
//#endregion
|
|
10
8
|
export { createInputEventDetail, createScrollEventDetail, createSwitchEventDetail, createTextareaLineChangeDetail, createVideoProgressDetail, createVideoTimeUpdateDetail, resolveImageModeStyle, resolveVideoObjectFit };
|
|
11
9
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -24,7 +24,8 @@ import { createProgressActiveEndDetail, resolveProgressAnimationDuration, resolv
|
|
|
24
24
|
import { WeappProgress } from "./progress/index.mjs";
|
|
25
25
|
import { WeappRadio, WeappRadioGroup, collectRadioGroupValue } from "./radio.mjs";
|
|
26
26
|
import { WeappRichText } from "./richText/index.mjs";
|
|
27
|
-
import {
|
|
27
|
+
import { createScrollEventDetail } from "./scrollView/helpers.mjs";
|
|
28
|
+
import { WeappScrollView } from "./scrollView/index.mjs";
|
|
28
29
|
import { createSliderEventDetail, resolveSliderConfig } from "./slider/helpers.mjs";
|
|
29
30
|
import { WeappSlider } from "./slider/index.mjs";
|
|
30
31
|
import { createSwiperChangeDetail, resolveSwipeTarget, resolveSwiperIndex, resolveSwiperNumber } from "./swiper/helpers.mjs";
|
|
@@ -35,7 +36,7 @@ import { WeappTextarea, createTextareaLineChangeDetail } from "./textarea.mjs";
|
|
|
35
36
|
import { createVideoProgressDetail, createVideoTimeUpdateDetail, resolveVideoObjectFit } from "./video/helpers.mjs";
|
|
36
37
|
import { WeappVideo } from "./video/index.mjs";
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
// src/runtime/nativeComponents/index.ts
|
|
39
40
|
const constructors = {
|
|
40
41
|
"weapp-view": WeappView,
|
|
41
42
|
"weapp-text": WeappText,
|
|
@@ -77,6 +78,5 @@ function ensureNativeComponentsDefined() {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
//#endregion
|
|
81
81
|
export { createInputEventDetail, createScrollEventDetail, createSwitchEventDetail, createTextareaLineChangeDetail, createVideoProgressDetail, createVideoTimeUpdateDetail, ensureNativeComponentsDefined, resolveImageModeStyle, resolveVideoObjectFit };
|
|
82
82
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport { createScrollEventDetail } from './scrollView'\nexport { createSliderEventDetail, resolveSliderConfig } from './slider/helpers'\nexport { NATIVE_COMPONENT_STYLE } from './style'\nexport {\n createSwiperChangeDetail,\n resolveSwiperIndex,\n resolveSwiperNumber,\n resolveSwipeTarget,\n} from './swiper/helpers'\nexport { createSwitchEventDetail } from './switch'\nexport { createTextareaLineChangeDetail } from './textarea'\nexport {\n createVideoProgressDetail,\n createVideoTimeUpdateDetail,\n resolveVideoObjectFit,\n} from './video/helpers'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/nativeComponents/index.ts"],"sourcesContent":["import type { NativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_DESCRIPTORS } from '../../shared/nativeComponents'\nimport { WeappButton } from '../button'\nimport { WeappCanvas } from './canvas'\nimport { WeappCheckbox, WeappCheckboxGroup } from './checkbox'\nimport { WeappCoverImage, WeappCoverView } from './cover'\nimport { WeappForm } from './form'\nimport { WeappIcon } from './icon'\nimport { WeappImage } from './image'\nimport { WeappInput } from './input'\nimport { WeappLabel } from './label'\nimport { WeappMovableArea, WeappMovableView } from './movable'\nimport { WeappNavigator } from './navigator'\nimport { WeappPicker } from './picker'\nimport { WeappPickerView, WeappPickerViewColumn } from './pickerView'\nimport { WeappText, WeappView } from './primitives'\nimport { WeappProgress } from './progress'\nimport { WeappRadio, WeappRadioGroup } from './radio'\nimport { WeappRichText } from './richText'\nimport { WeappScrollView } from './scrollView'\nimport { WeappSlider } from './slider'\nimport { WeappSwiper } from './swiper'\nimport { WeappSwiperItem } from './swiper/item'\nimport { WeappSwitch } from './switch'\nimport { WeappTextarea } from './textarea'\nimport { WeappVideo } from './video'\n\nconst constructors = {\n 'weapp-view': WeappView,\n 'weapp-text': WeappText,\n 'weapp-image': WeappImage,\n 'weapp-button': WeappButton,\n 'weapp-input': WeappInput,\n 'weapp-textarea': WeappTextarea,\n 'weapp-form': WeappForm,\n 'weapp-label': WeappLabel,\n 'weapp-checkbox-group': WeappCheckboxGroup,\n 'weapp-checkbox': WeappCheckbox,\n 'weapp-radio-group': WeappRadioGroup,\n 'weapp-radio': WeappRadio,\n 'weapp-switch': WeappSwitch,\n 'weapp-picker': WeappPicker,\n 'weapp-picker-view': WeappPickerView,\n 'weapp-picker-view-column': WeappPickerViewColumn,\n 'weapp-slider': WeappSlider,\n 'weapp-icon': WeappIcon,\n 'weapp-progress': WeappProgress,\n 'weapp-rich-text': WeappRichText,\n 'weapp-scroll-view': WeappScrollView,\n 'weapp-navigator': WeappNavigator,\n 'weapp-swiper': WeappSwiper,\n 'weapp-swiper-item': WeappSwiperItem,\n 'weapp-canvas': WeappCanvas,\n 'weapp-video': WeappVideo,\n 'weapp-cover-view': WeappCoverView,\n 'weapp-cover-image': WeappCoverImage,\n 'weapp-movable-area': WeappMovableArea,\n 'weapp-movable-view': WeappMovableView,\n} satisfies Record<NativeComponentWebTag, CustomElementConstructor>\n\nexport function ensureNativeComponentsDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n for (const descriptor of NATIVE_COMPONENT_DESCRIPTORS) {\n if (customElements.get(descriptor.webTag)) {\n continue\n }\n const constructor = constructors[descriptor.webTag]\n customElements.define(descriptor.webTag, constructor)\n }\n}\n\nexport { collectCheckboxGroupValue } from './checkbox'\nexport { collectFormControlValues } from './formControl'\nexport { resolveIconColor, resolveIconSize, resolveIconType } from './icon/helpers'\nexport { resolveImageModeStyle } from './image'\nexport { createInputEventDetail } from './input'\nexport { clampMovablePosition, resolveMovableDirection } from './movable/helpers'\nexport {\n createPickerChangeDetail,\n normalizePickerIndexes,\n resolvePickerColumns,\n resolvePickerMode,\n} from './picker/helpers'\nexport { normalizePickerViewValue } from './pickerView/helpers'\nexport {\n createProgressActiveEndDetail,\n resolveProgressAnimationDuration,\n resolveProgressConfig,\n} from './progress/helpers'\nexport { collectRadioGroupValue } from './radio'\nexport { createScrollEventDetail } from './scrollView'\nexport { createSliderEventDetail, resolveSliderConfig } from './slider/helpers'\nexport { NATIVE_COMPONENT_STYLE } from './style'\nexport {\n createSwiperChangeDetail,\n resolveSwiperIndex,\n resolveSwiperNumber,\n resolveSwipeTarget,\n} from './swiper/helpers'\nexport { createSwitchEventDetail } from './switch'\nexport { createTextareaLineChangeDetail } from './textarea'\nexport {\n createVideoProgressDetail,\n createVideoTimeUpdateDetail,\n resolveVideoObjectFit,\n} from './video/helpers'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,eAAe;CACnB,cAAc;CACd,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,cAAc;CACd,eAAe;CACf,wBAAwB;CACxB,kBAAkB;CAClB,qBAAqB;CACrB,eAAe;CACf,gBAAgB;CAChB,gBAAgB;CAChB,qBAAqB;CACrB,4BAA4B;CAC5B,gBAAgB;CAChB,cAAc;CACd,kBAAkB;CAClB,mBAAmB;CACnB,qBAAqB;CACrB,mBAAmB;CACnB,gBAAgB;CAChB,qBAAqB;CACrB,gBAAgB;CAChB,eAAe;CACf,oBAAoB;CACpB,qBAAqB;CACrB,sBAAsB;CACtB,sBAAsB;AACxB;AAEA,SAAgB,gCAAgC;CAC9C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,KAAK,MAAM,cAAc,8BAA8B;EACrD,IAAI,eAAe,IAAI,WAAW,MAAM,GACtC;EAEF,MAAM,cAAc,aAAa,WAAW;EAC5C,eAAe,OAAO,WAAW,QAAQ,WAAW;CACtD;AACF"}
|
|
@@ -4,7 +4,7 @@ import { dispatchMiniProgramEvent, readBooleanAttribute, resolveContainingShadow
|
|
|
4
4
|
import { ensureNativeComponentStyle } from "./style.mjs";
|
|
5
5
|
import { dispatchNativeInputEvent } from "../inputHandlerResult.mjs";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/runtime/nativeComponents/input.ts
|
|
8
8
|
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
9
9
|
function resolveInputType(element) {
|
|
10
10
|
if (readBooleanAttribute(element, "password")) return "password";
|
|
@@ -128,6 +128,5 @@ var WeappInput = class extends BaseElement {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
//#endregion
|
|
132
131
|
export { WeappInput, createInputEventDetail };
|
|
133
132
|
//# sourceMappingURL=input.mjs.map
|