@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -32,5 +32,4 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
32
|
};
|
|
33
33
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
34
34
|
|
|
35
|
-
//#endregion
|
|
36
35
|
export { __exportAll, __reExport };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CONTROL_ATTRS, EVENT_KIND_ALIAS, EVENT_PREFIX_RE, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
|
-
import { buildExpression, parseInterpolations } from "./interpolation.mjs";
|
|
2
|
+
import { buildDatasetExpression, buildExpression, parseInterpolations } from "./interpolation.mjs";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/compiler/wxml/attributes.ts
|
|
5
5
|
function extractFor(attribs) {
|
|
6
6
|
const expr = resolveControlAttributeValue(attribs, "for");
|
|
7
7
|
const itemName = resolveControlAttributeValue(attribs, "for-item")?.trim() || "item";
|
|
@@ -84,12 +84,20 @@ function renderAttributes(attribs, scopeVar, wxsVar, options) {
|
|
|
84
84
|
}
|
|
85
85
|
const useProperty = shouldBindAsProperty(rawName) && (options?.preferProperty || options?.propertyAttributes?.includes(rawName));
|
|
86
86
|
const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName);
|
|
87
|
-
|
|
87
|
+
if (!useProperty && name.startsWith("data-")) {
|
|
88
|
+
const expr = buildDatasetExpression(rawValue ?? "", scopeVar, wxsVar);
|
|
89
|
+
buffer += ` \${bindRuntimeDataset(${JSON.stringify(name)}, ${expr})}`;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const parts = parseInterpolations(rawValue ?? "");
|
|
93
|
+
const trimmedParts = name === "style" ? parseInterpolations((rawValue ?? "").trim()) : parts;
|
|
94
|
+
const valueParts = trimmedParts.length === 1 && trimmedParts[0]?.type === "expr" ? trimmedParts : parts;
|
|
95
|
+
const rawExpr = buildExpression(valueParts, scopeVar, wxsVar);
|
|
96
|
+
const expr = name === "style" ? `__weappInlineStyle(${rawExpr})` : rawExpr;
|
|
88
97
|
buffer += ` ${useProperty ? "." : ""}${name}=\${${expr}}`;
|
|
89
98
|
}
|
|
90
99
|
return buffer;
|
|
91
100
|
}
|
|
92
101
|
|
|
93
|
-
//#endregion
|
|
94
102
|
export { extractFor, isConditionalElement, renderAttributes, resolveComponentTagName, stripControlAttributes };
|
|
95
103
|
//# sourceMappingURL=attributes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.mjs","names":[],"sources":["../../../src/compiler/wxml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\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\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: {\n skipControl?: boolean\n preferProperty?: boolean\n propertyAttributes?: readonly string[]\n },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const event = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const domEvent = aliasedEvent ?? eventInfo.rawEvent\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` \\${bindRuntimeEvent(${JSON.stringify(domEvent)}, ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)}), ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = shouldBindAsProperty(rawName)\n && (options?.preferProperty || options?.propertyAttributes?.includes(rawName))\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n const expr =
|
|
1
|
+
{"version":3,"file":"attributes.mjs","names":[],"sources":["../../../src/compiler/wxml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildDatasetExpression, buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\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\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: {\n skipControl?: boolean\n preferProperty?: boolean\n propertyAttributes?: readonly string[]\n },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const event = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const domEvent = aliasedEvent ?? eventInfo.rawEvent\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` \\${bindRuntimeEvent(${JSON.stringify(domEvent)}, ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)}), ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = shouldBindAsProperty(rawName)\n && (options?.preferProperty || options?.propertyAttributes?.includes(rawName))\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n // DOM 属性保留字符串,完整表达式的值类型由运行时单独保存。\n if (!useProperty && name.startsWith('data-')) {\n const expr = buildDatasetExpression(rawValue ?? '', scopeVar, wxsVar)\n buffer += ` \\${bindRuntimeDataset(${JSON.stringify(name)}, ${expr})}`\n continue\n }\n const parts = parseInterpolations(rawValue ?? '')\n const trimmedParts = name === 'style' ? parseInterpolations((rawValue ?? '').trim()) : parts\n const valueParts = trimmedParts.length === 1 && trimmedParts[0]?.type === 'expr' ? trimmedParts : parts\n const rawExpr = buildExpression(valueParts, scopeVar, wxsVar)\n // WXML 内联 style 不经过 postcss 链路,rpx / vw / vh 需要在运行时换算,\n // 否则浏览器会丢弃整条声明(详见 inlineStyle.ts)。\n const expr = name === 'style' ? `__weappInlineStyle(${rawExpr})` : rawExpr\n buffer += ` ${useProperty ? '.' : ''}${name}=\\${${expr}}`\n }\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uB,OAAO;EAE1F,IAAI,CAAC,eAAe,KAAK,WAAW,OAAO,GAAG;GAC5C,MAAM,OAAO,uBAAuB,YAAY,IAAI,UAAU,MAAM;GACpE,UAAU,0BAA0B,KAAK,UAAU,IAAI,EAAE,IAAI,KAAK;GAClE;EACF;EACA,MAAM,QAAQ,oBAAoB,YAAY,EAAE;EAChD,MAAM,eAAe,SAAS,UAAU,qBAAqB,YAAY,GAAE,CAAE,KAAK,CAAC,IAAI;EACvF,MAAM,aAAa,aAAa,WAAW,KAAK,aAAa,EAAE,EAAE,SAAS,SAAS,eAAe;EAClG,MAAM,UAAU,gBAAgB,YAAY,UAAU,MAAM;EAG5D,MAAM,OAAO,SAAS,UAAU,sBAAsB,QAAQ,KAAK;EACnE,UAAU,IAAI,cAAc,MAAM,KAAK,KAAK,MAAM,KAAK;CACzD;CACA,OAAO;AACT"}
|
|
@@ -4,17 +4,23 @@ import { buildNavigationBarAttrs } from "./navigation.mjs";
|
|
|
4
4
|
import { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from "./specialNodes.mjs";
|
|
5
5
|
import { prepareWxml } from "./prepare.mjs";
|
|
6
6
|
import { renderer } from "./renderer.mjs";
|
|
7
|
+
import { collectUnknownTags, formatUnknownTagWarning } from "./unknownTags.mjs";
|
|
7
8
|
import { readFileSync } from "node:fs";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
// src/compiler/wxml/compile.ts
|
|
10
11
|
const WEB_TEMPLATE_QUERY = "weapp-web-template";
|
|
11
12
|
function appendTemplateQuery(pathname) {
|
|
12
13
|
return `${pathname}${pathname.includes("?") ? "&" : "?"}${WEB_TEMPLATE_QUERY}`;
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
+
function compileTemplate(options, diagnoseUnknownTags) {
|
|
15
16
|
const dependencyContext = options.dependencyContext ?? createDependencyContext();
|
|
16
17
|
const expandDependencies = options.expandDependencies ?? !options.dependencyContext;
|
|
17
18
|
const warnings = dependencyContext.warnings;
|
|
19
|
+
const warnUnknownTags = (prepared, id) => {
|
|
20
|
+
if (!diagnoseUnknownTags) return;
|
|
21
|
+
const tags = collectUnknownTags(prepared.renderNodes, options.componentTags, prepared.templates.flatMap((template) => template.nodes));
|
|
22
|
+
if (tags.length > 0) warnings.push(formatUnknownTagWarning(tags, id));
|
|
23
|
+
};
|
|
18
24
|
const expandDependencyTree = (dependencies, importer) => {
|
|
19
25
|
for (const target of dependencies) {
|
|
20
26
|
if (dependencyContext.active.has(target)) {
|
|
@@ -39,14 +45,18 @@ function compileWxml(options) {
|
|
|
39
45
|
resolveTemplatePath: options.resolveTemplatePath,
|
|
40
46
|
resolveWxsPath: options.resolveWxsPath
|
|
41
47
|
}, dependencyContext);
|
|
42
|
-
|
|
48
|
+
warnUnknownTags(result, target);
|
|
49
|
+
collectDependencies(result, dependencyContext);
|
|
50
|
+
expandDependencyTree([...result.imports, ...result.includes].map((entry) => entry.id), target);
|
|
43
51
|
} catch (error) {
|
|
44
52
|
if (error instanceof Error && error.message) warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`);
|
|
45
53
|
}
|
|
46
54
|
dependencyContext.active.delete(target);
|
|
47
55
|
}
|
|
48
56
|
};
|
|
49
|
-
const
|
|
57
|
+
const prepared = prepareWxml(options, dependencyContext);
|
|
58
|
+
warnUnknownTags(prepared, options.id);
|
|
59
|
+
const { renderNodes: renderNodesList, navigationBarAttrs, templates, includes, imports, wxs } = prepared;
|
|
50
60
|
if (options.navigationBar && options.navigationBar.config.navigationStyle !== "custom") {
|
|
51
61
|
const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs);
|
|
52
62
|
renderNodesList.unshift({
|
|
@@ -58,7 +68,9 @@ function compileWxml(options) {
|
|
|
58
68
|
const importLines = [
|
|
59
69
|
`import { html } from 'lit'`,
|
|
60
70
|
`import { repeat } from 'lit/directives/repeat.js'`,
|
|
61
|
-
`import { bindRuntimeEvent } from '${RUNTIME_ID}'
|
|
71
|
+
`import { bindRuntimeEvent } from '${RUNTIME_ID}'`,
|
|
72
|
+
`import { bindRuntimeDataset } from '${RUNTIME_ID}'`,
|
|
73
|
+
`import { transformInlineStyleValue as __weappInlineStyle } from '${RUNTIME_ID}'`
|
|
62
74
|
];
|
|
63
75
|
const bodyLines = [];
|
|
64
76
|
const directDependencies = [];
|
|
@@ -124,7 +136,7 @@ function compileWxml(options) {
|
|
|
124
136
|
if (expandDependencies) {
|
|
125
137
|
dependencyContext.visited.add(options.id);
|
|
126
138
|
dependencyContext.active.add(options.id);
|
|
127
|
-
expandDependencyTree(
|
|
139
|
+
expandDependencyTree([...imports, ...includes].map((entry) => entry.id), options.id);
|
|
128
140
|
dependencyContext.active.delete(options.id);
|
|
129
141
|
}
|
|
130
142
|
return {
|
|
@@ -137,7 +149,13 @@ function compileWxml(options) {
|
|
|
137
149
|
warnings: warnings.length > 0 ? warnings : void 0
|
|
138
150
|
};
|
|
139
151
|
}
|
|
152
|
+
function compileWxml(options) {
|
|
153
|
+
return compileTemplate(options, true);
|
|
154
|
+
}
|
|
155
|
+
/** 依赖模块的标签诊断由入口模板按其组件注册作用域统一收集。 */
|
|
156
|
+
function compileWxmlDependency(options) {
|
|
157
|
+
return compileTemplate(options, false);
|
|
158
|
+
}
|
|
140
159
|
|
|
141
|
-
|
|
142
|
-
export { compileWxml };
|
|
160
|
+
export { compileWxml, compileWxmlDependency };
|
|
143
161
|
//# sourceMappingURL=compile.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type { WxmlCompileOptions, WxmlCompileResult } from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs } from './navigation'\nimport { prepareWxml } from './prepare'\nimport { renderer } from './renderer'\nimport { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = prepareWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n }, dependencyContext)\n expandDependencyTree(collectDependencies(result, dependencyContext), target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n const {\n renderNodes: renderNodesList,\n navigationBarAttrs,\n templates,\n includes,\n imports,\n wxs,\n } = prepareWxml(options, dependencyContext)\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,KAAK,MAAM,UAAU,cAAc;GACjC,IAAI,kBAAkB,OAAO,IAAI,MA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CAAC,KAAK,IAGhD;EACH,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;CAC7C;AACF"}
|
|
1
|
+
{"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type { WxmlCompileOptions, WxmlCompileResult } from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs } from './navigation'\nimport { prepareWxml } from './prepare'\nimport { renderer } from './renderer'\nimport { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\nimport { collectUnknownTags, formatUnknownTagWarning } from './unknownTags'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nfunction compileTemplate(options: WxmlCompileOptions, diagnoseUnknownTags: boolean): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const warnUnknownTags = (prepared: ReturnType<typeof prepareWxml>, id: string) => {\n if (!diagnoseUnknownTags) {\n return\n }\n const tags = collectUnknownTags(prepared.renderNodes, options.componentTags, prepared.templates.flatMap(template => template.nodes))\n if (tags.length > 0) {\n warnings.push(formatUnknownTagWarning(tags, id))\n }\n }\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = prepareWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n }, dependencyContext)\n warnUnknownTags(result, target)\n collectDependencies(result, dependencyContext)\n expandDependencyTree([...result.imports, ...result.includes].map(entry => entry.id), target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n const prepared = prepareWxml(options, dependencyContext)\n warnUnknownTags(prepared, options.id)\n const {\n renderNodes: renderNodesList,\n navigationBarAttrs,\n templates,\n includes,\n imports,\n wxs,\n } = prepared\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n `import { bindRuntimeDataset } from '${RUNTIME_ID}'`,\n `import { transformInlineStyleValue as __weappInlineStyle } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree([...imports, ...includes].map(entry => entry.id), options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n return compileTemplate(options, true)\n}\n\n/** 依赖模块的标签诊断由入口模板按其组件注册作用域统一收集。 */\nexport function compileWxmlDependency(options: WxmlCompileOptions): WxmlCompileResult {\n return compileTemplate(options, false)\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAS,gBAAgB,SAA6B,qBAAiD;CACrG,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,mBAAmB,UAA0C,OAAe;EAChF,IAAI,CAAC,qBACH;EAEF,MAAM,OAAO,mBAAmB,SAAS,aAAa,QAAQ,eAAe,SAAS,UAAU,SAAQ,aAAY,SAAS,KAAK,CAAC;EACnI,IAAI,KAAK,SAAS,GAChB,SAAS,KAAK,wBAAwB,MAAM,EAAE,CAAC;CAEnD;CAEA,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,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U,KAAK,uBAAuB;CAEtC,IAAI,oBAAoB;EACtB,kBAAkB,QAAQ,IAAI,QAAQ,EAAE;EACxC,kBAAkB,OAAO,IAAI,QAAQ,EAAE;EACvC,qBAAqB,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC,KAAI,UAAS,MAAM,EAAE,GAAG,QAAQ,EAAE;EACjF,kBAAkB,OAAO,OAAO,QAAQ,EAAE;CAC5C;CAIA,OAAO;EACL,MAHW;GAAC,GAAG;GAAa;GAAI,GAAG;EAAS,CAAC,CAAC,KAAK,IAGhD;EACH,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;CAC7C;AACF;AAEA,SAAgB,YAAY,SAAgD;CAC1E,OAAO,gBAAgB,SAAS,IAAI;AACtC;;AAGA,SAAgB,sBAAsB,SAAgD;CACpF,OAAO,gBAAgB,SAAS,KAAK;AACvC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compiler/wxml/dependency.ts
|
|
2
2
|
function createDependencyContext() {
|
|
3
3
|
return {
|
|
4
4
|
warnings: [],
|
|
@@ -34,6 +34,5 @@ function warnCircularTemplate(context, from, target) {
|
|
|
34
34
|
context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
//#endregion
|
|
38
37
|
export { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate };
|
|
39
38
|
//# sourceMappingURL=dependency.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compiler/wxml/interpolation.ts
|
|
2
2
|
function parseInterpolations(value) {
|
|
3
3
|
const parts = [];
|
|
4
4
|
if (!value.includes("{{")) return [{
|
|
@@ -45,6 +45,17 @@ function buildExpression(parts, scopeVar, wxsVar) {
|
|
|
45
45
|
return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`;
|
|
46
46
|
}).join(" + ")})`;
|
|
47
47
|
}
|
|
48
|
+
/** 完整表达式保留原值,混合插值逐段转为字符串,避免相邻数字执行加法。 */
|
|
49
|
+
function buildDatasetExpression(value, scopeVar, wxsVar) {
|
|
50
|
+
const trimmedParts = parseInterpolations(value.trim());
|
|
51
|
+
if (trimmedParts.length === 1 && trimmedParts[0]?.type === "expr") return buildExpression(trimmedParts, scopeVar, wxsVar);
|
|
52
|
+
const parts = parseInterpolations(value);
|
|
53
|
+
if (parts.length <= 1) return buildExpression(parts, scopeVar, wxsVar);
|
|
54
|
+
return `(${parts.map((part) => {
|
|
55
|
+
const expression = buildExpression([part], scopeVar, wxsVar);
|
|
56
|
+
return part.type === "text" ? expression : `String(${expression} ?? '')`;
|
|
57
|
+
}).join(" + ")})`;
|
|
58
|
+
}
|
|
48
59
|
function hasTopLevelColon(expression) {
|
|
49
60
|
let depth = 0;
|
|
50
61
|
let inSingleQuote = false;
|
|
@@ -136,6 +147,5 @@ function buildTemplateDataExpression(raw, scopeVar, wxsVar) {
|
|
|
136
147
|
return buildExpression(parseInterpolations(raw), scopeVar, wxsVar);
|
|
137
148
|
}
|
|
138
149
|
|
|
139
|
-
|
|
140
|
-
export { buildExpression, buildTemplateDataExpression, parseInterpolations };
|
|
150
|
+
export { buildDatasetExpression, buildExpression, buildTemplateDataExpression, parseInterpolations };
|
|
141
151
|
//# sourceMappingURL=interpolation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wxsVar)\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,OAAoC;CACtE,MAAM,QAA6B,CAAC;CACpC,IAAI,CAAC,MAAM,SAAS,IAAI,GACtB,OAAO,CAAC;EAAE,MAAM;EAAQ;CAAM,CAAC;CAEjC,IAAI,SAAS;CACb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,QAAQ,MAAM,QAAQ,MAAM,MAAM;EACxC,IAAI,UAAU,IAAI;GAChB,MAAM,KAAK;IAAE,MAAM;IAAQ,OAAO,MAAM,MAAM,MAAM;GAAE,CAAC;GACvD;EACF;EACA,IAAI,QAAQ,QACV,MAAM,KAAK;GAAE,MAAM;GAAQ,OAAO,MAAM,MAAM,QAAQ,KAAK;EAAE,CAAC;EAEhE,MAAM,MAAM,MAAM,QAAQ,MAAM,QAAQ,CAAC;EACzC,IAAI,QAAQ,IAAI;GACd,MAAM,KAAK;IAAE,MAAM;IAAQ,OAAO,MAAM,MAAM,KAAK;GAAE,CAAC;GACtD;EACF;EACA,MAAM,OAAO,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,KAAK;EAC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,MAAM;IACjB,UAAU;IACV;GACF;GACA,IAAI,SAAS,KACX,aAAa;GAEf;EACF;EAEA,IAAI,SAAS,KAAM;GACjB,gBAAgB;GAChB;EACF;EACA,IAAI,SAAS,MAAK;GAChB,gBAAgB;GAChB;EACF;EACA,IAAI,SAAS,KAAK;GAChB,aAAa;GACb;EACF;EAEA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD,SAAS;GACT;EACF;EACA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ,KAAK,IAAI,GAAG,QAAQ,CAAC;GAC7B;EACF;EAEA,IAAI,UAAU,GACZ;EAGF,IAAI,SAAS,KAAK;GAChB,sBAAsB;GACtB;EACF;EACA,IAAI,SAAS,KACX,OAAO,CAAC;CAEZ;CAEA,OAAO;AACT;AAEA,SAAS,0BAA0B,YAAoB;CACrD,MAAM,UAAU,WAAW,KAAK;CAChC,IAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAC9E,OAAO;CAET,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,4BAA4B,KAAa,UAAkB,QAAgB;CAEzF,MAAM,QAAQ,oBADE,IAAI,KACoB,CAAC;CACzC,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,EAAE,CAAC,MAAM,KAAK;EAEjC,OAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,IAAI,IAAI,KAAK,KAAK,MAAM;EACX,CAAC,GAAG,UAAU,MAAM;CACpF;CACA,OAAO,gBAAgB,oBAAoB,GAAG,GAAG,UAAU,MAAM;AACnE"}
|
|
1
|
+
{"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\n/** 完整表达式保留原值,混合插值逐段转为字符串,避免相邻数字执行加法。 */\nexport function buildDatasetExpression(value: string, scopeVar: string, wxsVar: string) {\n const trimmedParts = parseInterpolations(value.trim())\n if (trimmedParts.length === 1 && trimmedParts[0]?.type === 'expr') {\n return buildExpression(trimmedParts, scopeVar, wxsVar)\n }\n const parts = parseInterpolations(value)\n if (parts.length <= 1) {\n return buildExpression(parts, scopeVar, wxsVar)\n }\n const segments = parts.map((part) => {\n const expression = buildExpression([part], scopeVar, wxsVar)\n return part.type === 'text' ? expression : `String(${expression} ?? '')`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wxsVar)\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,OAAoC;CACtE,MAAM,QAA6B,CAAC;CACpC,IAAI,CAAC,MAAM,SAAS,IAAI,GACtB,OAAO,CA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a;GACb;EACF;EAEA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD,SAAS;GACT;EACF;EACA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ,KAAK,IAAI,GAAG,QAAQ,CAAC;GAC7B;EACF;EAEA,IAAI,UAAU,GACZ;EAGF,IAAI,SAAS,KAAK;GAChB,sBAAsB;GACtB;EACF;EACA,IAAI,SAAS,KACX,OAAO,CAAC;CAEZ;CAEA,OAAO;AACT;AAEA,SAAS,0BAA0B,YAAoB;CACrD,MAAM,UAAU,WAAW,KAAK;CAChC,IAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAC9E,OAAO;CAET,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,4BAA4B,KAAa,UAAkB,QAAgB;CAEzF,MAAM,QAAQ,oBADE,IAAI,KACoB,CAAC;CACzC,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,EAAE,CAAC,MAAM,KAAK;EAEjC,OAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,IAAI,IAAI,KAAK,KAAK,MAAM;EACX,CAAC,GAAG,UAAU,MAAM;CACpF;CACA,OAAO,gBAAgB,oBAAoB,GAAG,GAAG,UAAU,MAAM;AACnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/compiler/wxml/nativeTags.ts
|
|
2
|
+
const NATIVE_COMPONENT_NAMES = /* @__PURE__ */ new Set([
|
|
3
|
+
"ad",
|
|
4
|
+
"ad-custom",
|
|
5
|
+
"audio",
|
|
6
|
+
"block",
|
|
7
|
+
"button",
|
|
8
|
+
"camera",
|
|
9
|
+
"canvas",
|
|
10
|
+
"checkbox",
|
|
11
|
+
"checkbox-group",
|
|
12
|
+
"cover-image",
|
|
13
|
+
"cover-view",
|
|
14
|
+
"editor",
|
|
15
|
+
"form",
|
|
16
|
+
"functional-page-navigator",
|
|
17
|
+
"icon",
|
|
18
|
+
"image",
|
|
19
|
+
"import",
|
|
20
|
+
"include",
|
|
21
|
+
"input",
|
|
22
|
+
"keyboard-accessory",
|
|
23
|
+
"label",
|
|
24
|
+
"live-player",
|
|
25
|
+
"live-pusher",
|
|
26
|
+
"map",
|
|
27
|
+
"match-media",
|
|
28
|
+
"movable-area",
|
|
29
|
+
"movable-view",
|
|
30
|
+
"navigation-bar",
|
|
31
|
+
"navigator",
|
|
32
|
+
"official-account",
|
|
33
|
+
"open-data",
|
|
34
|
+
"page-container",
|
|
35
|
+
"page-meta",
|
|
36
|
+
"picker",
|
|
37
|
+
"picker-view",
|
|
38
|
+
"picker-view-column",
|
|
39
|
+
"progress",
|
|
40
|
+
"radio",
|
|
41
|
+
"radio-group",
|
|
42
|
+
"rich-text",
|
|
43
|
+
"scroll-view",
|
|
44
|
+
"share-element",
|
|
45
|
+
"slider",
|
|
46
|
+
"slot",
|
|
47
|
+
"swiper",
|
|
48
|
+
"swiper-item",
|
|
49
|
+
"switch",
|
|
50
|
+
"template",
|
|
51
|
+
"text",
|
|
52
|
+
"textarea",
|
|
53
|
+
"video",
|
|
54
|
+
"view",
|
|
55
|
+
"voip-room",
|
|
56
|
+
"web-view"
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
export { NATIVE_COMPONENT_NAMES };
|
|
60
|
+
//# sourceMappingURL=nativeTags.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeTags.mjs","names":[],"sources":["../../../src/compiler/wxml/nativeTags.ts"],"sourcesContent":["// 本文件由 components.weapp.json 生成,请运行 node packages-runtime/web/scripts/generate-native-tags.mjs。\nexport const NATIVE_COMPONENT_NAMES = new Set([\n 'ad',\n 'ad-custom',\n 'audio',\n 'block',\n 'button',\n 'camera',\n 'canvas',\n 'checkbox',\n 'checkbox-group',\n 'cover-image',\n 'cover-view',\n 'editor',\n 'form',\n 'functional-page-navigator',\n 'icon',\n 'image',\n 'import',\n 'include',\n 'input',\n 'keyboard-accessory',\n 'label',\n 'live-player',\n 'live-pusher',\n 'map',\n 'match-media',\n 'movable-area',\n 'movable-view',\n 'navigation-bar',\n 'navigator',\n 'official-account',\n 'open-data',\n 'page-container',\n 'page-meta',\n 'picker',\n 'picker-view',\n 'picker-view-column',\n 'progress',\n 'radio',\n 'radio-group',\n 'rich-text',\n 'scroll-view',\n 'share-element',\n 'slider',\n 'slot',\n 'swiper',\n 'swiper-item',\n 'switch',\n 'template',\n 'text',\n 'textarea',\n 'video',\n 'view',\n 'voip-room',\n 'web-view',\n])\n"],"mappings":";AACA,MAAa,yCAAyB,IAAI,IAAI;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compiler/wxml/navigation.ts
|
|
2
2
|
const NAVIGATION_BAR_ATTRS = /* @__PURE__ */ new Set([
|
|
3
3
|
"title",
|
|
4
4
|
"background-color",
|
|
@@ -78,6 +78,5 @@ function buildNavigationBarAttrs(config, overrides) {
|
|
|
78
78
|
return attrs;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
//#endregion
|
|
82
81
|
export { buildNavigationBarAttrs, extractNavigationBarFromPageMeta };
|
|
83
82
|
//# sourceMappingURL=navigation.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseDocument } from "htmlparser2";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/compiler/wxml/parser.ts
|
|
4
4
|
function isRenderableNode(node) {
|
|
5
5
|
if (node.type === "directive" || node.type === "comment") return false;
|
|
6
6
|
if (node.type === "text") return node.data.trim().length > 0;
|
|
@@ -36,6 +36,5 @@ function parseWxml(source) {
|
|
|
36
36
|
}).children.filter(isRenderableNode).map((node) => convertNode(node)).filter((node) => Boolean(node));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
//#endregion
|
|
40
39
|
export { parseWxml };
|
|
41
40
|
//# sourceMappingURL=parser.mjs.map
|
|
@@ -2,7 +2,7 @@ import { extractNavigationBarFromPageMeta } from "./navigation.mjs";
|
|
|
2
2
|
import { parseWxml } from "./parser.mjs";
|
|
3
3
|
import { collectSpecialNodes } from "./specialNodes.mjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/compiler/wxml/prepare.ts
|
|
6
6
|
/** 共享模板分析阶段,依赖扫描复用其结果而不生成渲染代码。 */
|
|
7
7
|
function prepareWxml(options, dependencyContext) {
|
|
8
8
|
const warnings = dependencyContext.warnings;
|
|
@@ -38,6 +38,5 @@ function prepareWxml(options, dependencyContext) {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//#endregion
|
|
42
41
|
export { prepareWxml };
|
|
43
42
|
//# sourceMappingURL=prepare.mjs.map
|
|
@@ -3,7 +3,7 @@ import { SELF_CLOSING_TAGS, hasControlAttribute, normalizeTagName, resolveContro
|
|
|
3
3
|
import { buildExpression, buildTemplateDataExpression, parseInterpolations } from "./interpolation.mjs";
|
|
4
4
|
import { extractFor, isConditionalElement, renderAttributes, resolveComponentTagName, stripControlAttributes } from "./attributes.mjs";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/compiler/wxml/renderer.ts
|
|
7
7
|
var Renderer = class {
|
|
8
8
|
renderNodes(nodes, scopeVar, wxsVar, componentTags) {
|
|
9
9
|
const parts = [];
|
|
@@ -113,6 +113,5 @@ var Renderer = class {
|
|
|
113
113
|
};
|
|
114
114
|
const renderer = new Renderer();
|
|
115
115
|
|
|
116
|
-
//#endregion
|
|
117
116
|
export { Renderer, renderer };
|
|
118
117
|
//# sourceMappingURL=renderer.mjs.map
|
|
@@ -2,7 +2,7 @@ import { isKnownUnsupportedNativeComponent } from "../../shared/nativeComponents
|
|
|
2
2
|
import { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from "../../shared/wxml.mjs";
|
|
3
3
|
import { dirname, relative } from "pathe";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/compiler/wxml/specialNodes.ts
|
|
6
6
|
function shouldMarkWxsImport(pathname) {
|
|
7
7
|
const lower = pathname.toLowerCase();
|
|
8
8
|
if (lower.endsWith(".wxs") || lower.endsWith(".wxs.ts") || lower.endsWith(".wxs.js")) return false;
|
|
@@ -86,6 +86,5 @@ function toRelativeImport(from, target) {
|
|
|
86
86
|
return `./${rel}`;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
//#endregion
|
|
90
89
|
export { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport };
|
|
91
90
|
//# sourceMappingURL=specialNodes.mjs.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/compiler/wxml/types.d.ts
|
|
2
1
|
export interface NavigationBarConfig {
|
|
3
2
|
title?: string;
|
|
4
3
|
backgroundColor?: string;
|
|
@@ -7,5 +6,4 @@ export interface NavigationBarConfig {
|
|
|
7
6
|
loading?: boolean;
|
|
8
7
|
navigationStyle?: string;
|
|
9
8
|
}
|
|
10
|
-
//#endregion
|
|
11
9
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isKnownUnsupportedNativeComponent, resolveNativeComponentWebTag } from "../../shared/nativeComponents.mjs";
|
|
2
|
+
import { NATIVE_COMPONENT_NAMES } from "./nativeTags.mjs";
|
|
3
|
+
import { isHTMLTag, isMathMLTag, isSVGTag } from "@vue/shared";
|
|
4
|
+
|
|
5
|
+
// src/compiler/wxml/unknownTags.ts
|
|
6
|
+
const CONTROL_TAGS = /* @__PURE__ */ new Set(["wxs"]);
|
|
7
|
+
function isKnownTag(name, componentTags) {
|
|
8
|
+
const normalized = name.toLowerCase();
|
|
9
|
+
const isRegistered = (tag) => componentTags && Object.hasOwn(componentTags, tag) && typeof componentTags[tag] === "string" && Boolean(componentTags[tag]);
|
|
10
|
+
if (!normalized || isRegistered(name) || isRegistered(normalized)) return true;
|
|
11
|
+
return CONTROL_TAGS.has(normalized) || NATIVE_COMPONENT_NAMES.has(normalized) || isHTMLTag(normalized) || isSVGTag(name) || isMathMLTag(normalized) || Boolean(resolveNativeComponentWebTag(normalized)) || isKnownUnsupportedNativeComponent(normalized);
|
|
12
|
+
}
|
|
13
|
+
function collectFromNodes(nodes, unknown, componentTags) {
|
|
14
|
+
for (const node of nodes ?? []) {
|
|
15
|
+
if (node.type !== "element") continue;
|
|
16
|
+
const name = node.name ?? "";
|
|
17
|
+
if (name && !isKnownTag(name, componentTags)) unknown.add(name);
|
|
18
|
+
collectFromNodes(node.children, unknown, componentTags);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** 收集用户模板中可能拼写错误或尚未注册的标签,不改变渲染结果。 */
|
|
22
|
+
function collectUnknownTags(nodes, componentTags, extraNodes = []) {
|
|
23
|
+
const unknown = /* @__PURE__ */ new Set();
|
|
24
|
+
collectFromNodes(nodes, unknown, componentTags);
|
|
25
|
+
collectFromNodes(extraNodes, unknown, componentTags);
|
|
26
|
+
return [...unknown];
|
|
27
|
+
}
|
|
28
|
+
function formatUnknownTagWarning(tags, filename) {
|
|
29
|
+
return `[web] 模板中使用了未知标签${filename ? ` (${filename})` : ""}:${tags.map((tag) => `<${tag}>`).join("、")}。这些标签可能尚未在 usingComponents 中注册或存在拼写错误,请检查组件注册和标签名称。`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { collectUnknownTags, formatUnknownTagWarning };
|
|
33
|
+
//# sourceMappingURL=unknownTags.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknownTags.mjs","names":[],"sources":["../../../src/compiler/wxml/unknownTags.ts"],"sourcesContent":["import type { RenderNode } from './types'\nimport { isHTMLTag, isMathMLTag, isSVGTag } from '@vue/shared'\nimport { isKnownUnsupportedNativeComponent, resolveNativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_NAMES } from './nativeTags'\n\nconst CONTROL_TAGS = new Set(['wxs'])\n\nfunction isKnownTag(name: string, componentTags?: Record<string, string>) {\n const normalized = name.toLowerCase()\n const isRegistered = (tag: string) => componentTags\n && Object.hasOwn(componentTags, tag)\n && typeof componentTags[tag] === 'string'\n && Boolean(componentTags[tag])\n if (!normalized || isRegistered(name) || isRegistered(normalized)) {\n return true\n }\n return CONTROL_TAGS.has(normalized)\n || NATIVE_COMPONENT_NAMES.has(normalized)\n || isHTMLTag(normalized)\n || isSVGTag(name)\n || isMathMLTag(normalized)\n || Boolean(resolveNativeComponentWebTag(normalized))\n || isKnownUnsupportedNativeComponent(normalized)\n}\n\nfunction collectFromNodes(nodes: RenderNode[] | undefined, unknown: Set<string>, componentTags?: Record<string, string>) {\n for (const node of nodes ?? []) {\n if (node.type !== 'element') {\n continue\n }\n const name = node.name ?? ''\n if (name && !isKnownTag(name, componentTags)) {\n unknown.add(name)\n }\n collectFromNodes(node.children, unknown, componentTags)\n }\n}\n\n/** 收集用户模板中可能拼写错误或尚未注册的标签,不改变渲染结果。 */\nexport function collectUnknownTags(\n nodes: RenderNode[] | undefined,\n componentTags?: Record<string, string>,\n extraNodes: RenderNode[] = [],\n) {\n const unknown = new Set<string>()\n collectFromNodes(nodes, unknown, componentTags)\n collectFromNodes(extraNodes, unknown, componentTags)\n return [...unknown]\n}\n\nexport function formatUnknownTagWarning(tags: string[], filename?: string) {\n const location = filename ? ` (${filename})` : ''\n const list = tags.map(tag => `<${tag}>`).join('、')\n return `[web] 模板中使用了未知标签${location}:${list}。`\n + '这些标签可能尚未在 usingComponents 中注册或存在拼写错误,请检查组件注册和标签名称。'\n}\n"],"mappings":";;;;;AAKA,MAAM,+BAAe,IAAI,IAAI,CAAC,KAAK,CAAC;AAEpC,SAAS,WAAW,MAAc,eAAwC;CACxE,MAAM,aAAa,KAAK,YAAY;CACpC,MAAM,gBAAgB,QAAgB,iBACjC,OAAO,OAAO,eAAe,GAAG,KAChC,OAAO,cAAc,SAAS,YAC9B,QAAQ,cAAc,IAAI;CAC/B,IAAI,CAAC,cAAc,aAAa,IAAI,KAAK,aAAa,UAAU,GAC9D,OAAO;CAET,OAAO,aAAa,IAAI,UAAU,KAC7B,uBAAuB,IAAI,UAAU,KACrC,UAAU,UAAU,KACpB,SAAS,IAAI,KACb,YAAY,UAAU,KACtB,QAAQ,6BAA6B,UAAU,CAAC,KAChD,kCAAkC,UAAU;AACnD;AAEA,SAAS,iBAAiB,OAAiC,SAAsB,eAAwC;CACvH,KAAK,MAAM,QAAQ,SAAS,CAAC,GAAG;EAC9B,IAAI,KAAK,SAAS,WAChB;EAEF,MAAM,OAAO,KAAK,QAAQ;EAC1B,IAAI,QAAQ,CAAC,WAAW,MAAM,aAAa,GACzC,QAAQ,IAAI,IAAI;EAElB,iBAAiB,KAAK,UAAU,SAAS,aAAa;CACxD;AACF;;AAGA,SAAgB,mBACd,OACA,eACA,aAA2B,CAAC,GAC5B;CACA,MAAM,0BAAU,IAAI,IAAY;CAChC,iBAAiB,OAAO,SAAS,aAAa;CAC9C,iBAAiB,YAAY,SAAS,aAAa;CACnD,OAAO,CAAC,GAAG,OAAO;AACpB;AAEA,SAAgB,wBAAwB,MAAgB,UAAmB;CAGzE,OAAO,mBAFU,WAAW,KAAK,SAAS,KAAK,GAEZ,GADtB,KAAK,KAAI,QAAO,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,GACL,EAAE;AAE7C"}
|
package/dist/compiler/wxs.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compiler/wxs.ts
|
|
2
2
|
const REQUIRE_RE = /require\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
3
3
|
function normalizePath(p) {
|
|
4
4
|
return p.replace(/\\/g, "/");
|
|
@@ -78,6 +78,5 @@ function transformWxsToEsm(code, id, options) {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
//#endregion
|
|
82
81
|
export { transformWxsToEsm };
|
|
83
82
|
//# sourceMappingURL=wxs.mjs.map
|
package/dist/css/wxss.d.mts
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
|
+
import { WxssTransformOptions } from "../shared/styleUnits/options.mjs";
|
|
1
2
|
import postcss from "postcss";
|
|
2
|
-
//#region src/css/wxss.d.ts
|
|
3
|
-
export interface WxssTransformOptions {
|
|
4
|
-
/**
|
|
5
|
-
* 1rpx 对应的 CSS 像素数。
|
|
6
|
-
* 默认值近似于 750rpx 设计稿在 375px 屏幕上的换算。
|
|
7
|
-
*/
|
|
8
|
-
pxPerRpx?: number;
|
|
9
|
-
/**
|
|
10
|
-
* rpx 换算的设计宽度。传入后会把 rpx 转为
|
|
11
|
-
* `calc(var(--rpx) * N)` 以实现响应式缩放。
|
|
12
|
-
*/
|
|
13
|
-
designWidth?: number;
|
|
14
|
-
/**
|
|
15
|
-
* 用于存储运行时 rpx 大小的 CSS 变量名。
|
|
16
|
-
* @default "--rpx"
|
|
17
|
-
*/
|
|
18
|
-
rpxVar?: string;
|
|
19
|
-
}
|
|
20
3
|
export interface WxssTransformResult {
|
|
21
4
|
css: string;
|
|
22
5
|
}
|
|
23
6
|
export declare function transformWxssToCss(source: string, options?: WxssTransformOptions): WxssTransformResult;
|
|
24
|
-
|
|
7
|
+
export type { WxssTransformOptions };
|
|
25
8
|
//# sourceMappingURL=wxss.d.mts.map
|
package/dist/css/wxss.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { resolveNativeComponentWebTag } from "../shared/nativeComponents.mjs";
|
|
2
|
+
import { resolveStyleUnitOptions } from "../shared/styleUnits/options.mjs";
|
|
3
|
+
import { transformStyleValue } from "../shared/styleUnits/value.mjs";
|
|
2
4
|
import postcss from "postcss";
|
|
3
5
|
import selectorParser from "postcss-selector-parser";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
const RPX_RE = /(-?(?:\d+(?:\.\d+)?|\.\d+))rpx/gi;
|
|
7
|
-
const SAFE_AREA_ENV_RE = /env\(\s*safe-area-inset-(top|right|bottom|left)(?:\s*,[^)]*)?\)/gi;
|
|
7
|
+
// src/css/wxss.ts
|
|
8
8
|
const PAGE_HOST_SELECTOR = selectorParser().astSync(":host(:where([data-weapp-page-active]))").nodes[0].nodes[0];
|
|
9
9
|
function isDeepPseudo(pseudo) {
|
|
10
10
|
return pseudo.value === ":deep" || pseudo.value === "::v-deep";
|
|
@@ -86,18 +86,12 @@ function transformWxssSelector(selector) {
|
|
|
86
86
|
return output.join(",\n");
|
|
87
87
|
}
|
|
88
88
|
function transformWxssRoot(root, options) {
|
|
89
|
-
const
|
|
90
|
-
const useVariable = options?.pxPerRpx === void 0 || typeof options.designWidth === "number" && Number.isFinite(options.designWidth);
|
|
91
|
-
const ratio = options?.pxPerRpx ?? .5;
|
|
89
|
+
const unitOptions = resolveStyleUnitOptions(options);
|
|
92
90
|
root.walkRules((rule) => {
|
|
93
91
|
if (rule.selector) rule.selector = transformWxssSelector(rule.selector);
|
|
94
92
|
});
|
|
95
93
|
root.walkDecls((declaration) => {
|
|
96
|
-
declaration.value = declaration.value
|
|
97
|
-
const numeric = Number.parseFloat(value);
|
|
98
|
-
if (useVariable) return `calc(var(${rpxVar}) * ${numeric})`;
|
|
99
|
-
return `${Math.round(numeric * ratio * 1e3) / 1e3}px`;
|
|
100
|
-
});
|
|
94
|
+
declaration.value = transformStyleValue(declaration.value, unitOptions);
|
|
101
95
|
});
|
|
102
96
|
}
|
|
103
97
|
function createWxssPostcssPlugin(options) {
|
|
@@ -114,6 +108,5 @@ function transformWxssToCss(source, options) {
|
|
|
114
108
|
return { css: root.toString() };
|
|
115
109
|
}
|
|
116
110
|
|
|
117
|
-
//#endregion
|
|
118
111
|
export { createWxssPostcssPlugin, transformWxssToCss };
|
|
119
112
|
//# sourceMappingURL=wxss.mjs.map
|