@weapp-vite/web 1.3.14 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/compiler/wxml/attributes.mjs +93 -0
- package/dist/compiler/wxml/attributes.mjs.map +1 -0
- package/dist/compiler/wxml/compile.mjs +158 -0
- package/dist/compiler/wxml/compile.mjs.map +1 -0
- package/dist/compiler/wxml/dependency.mjs +31 -0
- package/dist/compiler/wxml/dependency.mjs.map +1 -0
- package/dist/compiler/wxml/interpolation.mjs +142 -0
- package/dist/compiler/wxml/interpolation.mjs.map +1 -0
- package/dist/compiler/wxml/navigation.mjs +85 -0
- package/dist/compiler/wxml/navigation.mjs.map +1 -0
- package/dist/compiler/wxml/parser.mjs +41 -0
- package/dist/compiler/wxml/parser.mjs.map +1 -0
- package/dist/compiler/wxml/renderer.mjs +114 -0
- package/dist/compiler/wxml/renderer.mjs.map +1 -0
- package/dist/compiler/wxml/specialNodes.mjs +84 -0
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -0
- package/dist/compiler/wxs.mjs +83 -0
- package/dist/compiler/wxs.mjs.map +1 -0
- package/dist/css/wxss.d.mts +25 -0
- package/dist/css/wxss.mjs +17 -0
- package/dist/css/wxss.mjs.map +1 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +18 -3
- package/dist/plugin/constants.mjs +43 -0
- package/dist/plugin/constants.mjs.map +1 -0
- package/dist/plugin/entry.mjs +29 -0
- package/dist/plugin/entry.mjs.map +1 -0
- package/dist/plugin/files.mjs +58 -0
- package/dist/plugin/files.mjs.map +1 -0
- package/dist/plugin/index.d.mts +33 -0
- package/dist/plugin/index.mjs +188 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/plugin/navigation.mjs +20 -0
- package/dist/plugin/navigation.mjs.map +1 -0
- package/dist/plugin/path.mjs +85 -0
- package/dist/plugin/path.mjs.map +1 -0
- package/dist/plugin/register.mjs +83 -0
- package/dist/plugin/register.mjs.map +1 -0
- package/dist/plugin/scan.mjs +195 -0
- package/dist/plugin/scan.mjs.map +1 -0
- package/dist/plugin/scanConfig.mjs +45 -0
- package/dist/plugin/scanConfig.mjs.map +1 -0
- package/dist/plugin/state.mjs +22 -0
- package/dist/plugin/state.mjs.map +1 -0
- package/dist/plugin/types.d.mts +46 -0
- package/dist/plugin.d.mts +3 -2
- package/dist/plugin.mjs +3 -2
- package/dist/runtime/button/helpers.mjs +92 -0
- package/dist/runtime/button/helpers.mjs.map +1 -0
- package/dist/runtime/button/index.d.mts +9 -0
- package/dist/runtime/button/index.mjs +198 -0
- package/dist/runtime/button/index.mjs.map +1 -0
- package/dist/runtime/button/style.mjs +168 -0
- package/dist/runtime/button/style.mjs.map +1 -0
- package/dist/runtime/component/behavior.mjs +98 -0
- package/dist/runtime/component/behavior.mjs.map +1 -0
- package/dist/runtime/component/constants.mjs +8 -0
- package/dist/runtime/component/constants.mjs.map +1 -0
- package/dist/runtime/component/dom.mjs +26 -0
- package/dist/runtime/component/dom.mjs.map +1 -0
- package/dist/runtime/component/element.mjs +208 -0
- package/dist/runtime/component/element.mjs.map +1 -0
- package/dist/runtime/component/events.mjs +48 -0
- package/dist/runtime/component/events.mjs.map +1 -0
- package/dist/runtime/component/index.d.mts +7 -0
- package/dist/runtime/component/index.mjs +44 -0
- package/dist/runtime/component/index.mjs.map +1 -0
- package/dist/runtime/component/state.mjs +63 -0
- package/dist/runtime/component/state.mjs.map +1 -0
- package/dist/runtime/component/types.d.mts +49 -0
- package/dist/runtime/component/utils.mjs +39 -0
- package/dist/runtime/component/utils.mjs.map +1 -0
- package/dist/runtime/execution.d.mts +7 -0
- package/dist/runtime/execution.mjs +37 -0
- package/dist/runtime/execution.mjs.map +1 -0
- package/dist/runtime/index.d.mts +16 -2
- package/dist/runtime/index.mjs +16 -2
- package/dist/runtime/legacyTemplate/dom.mjs +131 -0
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/expression.mjs +113 -0
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/index.d.mts +9 -0
- package/dist/runtime/legacyTemplate/index.mjs +131 -0
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/types.d.mts +6 -0
- package/dist/runtime/navigationBar/index.d.mts +10 -0
- package/dist/runtime/navigationBar/index.mjs +162 -0
- package/dist/runtime/navigationBar/index.mjs.map +1 -0
- package/dist/runtime/navigationBar/style.mjs +108 -0
- package/dist/runtime/navigationBar/style.mjs.map +1 -0
- package/dist/runtime/polyfill/ad.mjs +150 -0
- package/dist/runtime/polyfill/ad.mjs.map +1 -0
- package/dist/runtime/polyfill/appState.mjs +31 -0
- package/dist/runtime/polyfill/appState.mjs.map +1 -0
- package/dist/runtime/polyfill/async.mjs +31 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -0
- package/dist/runtime/polyfill/auth.mjs +120 -0
- package/dist/runtime/polyfill/auth.mjs.map +1 -0
- package/dist/runtime/polyfill/authApi.mjs +101 -0
- package/dist/runtime/polyfill/authApi.mjs.map +1 -0
- package/dist/runtime/polyfill/background.mjs +31 -0
- package/dist/runtime/polyfill/background.mjs.map +1 -0
- package/dist/runtime/polyfill/canvasContext.mjs +115 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -0
- package/dist/runtime/polyfill/capability.mjs +17 -0
- package/dist/runtime/polyfill/capability.mjs.map +1 -0
- package/dist/runtime/polyfill/cloud.mjs +39 -0
- package/dist/runtime/polyfill/cloud.mjs.map +1 -0
- package/dist/runtime/polyfill/device.mjs +44 -0
- package/dist/runtime/polyfill/device.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceApi.mjs +31 -0
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +102 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +144 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/filePicker.mjs +158 -0
- package/dist/runtime/polyfill/filePicker.mjs.map +1 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs +45 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -0
- package/dist/runtime/polyfill/files.mjs +118 -0
- package/dist/runtime/polyfill/files.mjs.map +1 -0
- package/dist/runtime/polyfill/index.d.mts +40 -0
- package/dist/runtime/polyfill/index.mjs +99 -0
- package/dist/runtime/polyfill/index.mjs.map +1 -0
- package/dist/runtime/polyfill/interaction.mjs +38 -0
- package/dist/runtime/polyfill/interaction.mjs.map +1 -0
- package/dist/runtime/polyfill/interactionApi.mjs +54 -0
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -0
- package/dist/runtime/polyfill/location.mjs +106 -0
- package/dist/runtime/polyfill/location.mjs.map +1 -0
- package/dist/runtime/polyfill/locationApi.mjs +120 -0
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaActions.mjs +52 -0
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs +63 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs +59 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs +82 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs +39 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs +46 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaInfo.mjs +136 -0
- package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaPicker.mjs +213 -0
- package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaProcess.mjs +65 -0
- package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -0
- package/dist/runtime/polyfill/menuApi.mjs +70 -0
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +65 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/network/request.mjs +162 -0
- package/dist/runtime/polyfill/network/request.mjs.map +1 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs +49 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -0
- package/dist/runtime/polyfill/network/status.mjs +55 -0
- package/dist/runtime/polyfill/network/status.mjs.map +1 -0
- package/dist/runtime/polyfill/platformApi.mjs +33 -0
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -0
- package/dist/runtime/polyfill/platformRuntime.mjs +120 -0
- package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +36 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +83 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +33 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs +76 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs +35 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +43 -0
- package/dist/runtime/polyfill/routeRuntime.mjs +202 -0
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +26 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +79 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs +134 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs +40 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeOps.mjs +62 -0
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -0
- package/dist/runtime/polyfill/selectorQuery.mjs +204 -0
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -0
- package/dist/runtime/polyfill/storage.mjs +103 -0
- package/dist/runtime/polyfill/storage.mjs.map +1 -0
- package/dist/runtime/polyfill/storageAsync.mjs +62 -0
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -0
- package/dist/runtime/polyfill/subscribe.mjs +30 -0
- package/dist/runtime/polyfill/subscribe.mjs.map +1 -0
- package/dist/runtime/polyfill/system.mjs +111 -0
- package/dist/runtime/polyfill/system.mjs.map +1 -0
- package/dist/runtime/polyfill/systemApi.mjs +65 -0
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/types/base.d.mts +12 -0
- package/dist/runtime/polyfill/types/common.d.mts +126 -0
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +151 -0
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +152 -0
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +141 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +122 -0
- package/dist/runtime/polyfill/ui.mjs +135 -0
- package/dist/runtime/polyfill/ui.mjs.map +1 -0
- package/dist/runtime/polyfill/uiFeedback.mjs +35 -0
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -0
- package/dist/runtime/polyfill/uiMediaApi.d.mts +172 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs +162 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -0
- package/dist/runtime/polyfill/videoContext.mjs +56 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -0
- package/dist/runtime/polyfill/vkSession.mjs +58 -0
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -0
- package/dist/runtime/polyfill/windowResize.mjs +39 -0
- package/dist/runtime/polyfill/windowResize.mjs.map +1 -0
- package/dist/runtime/polyfill/worker.mjs +77 -0
- package/dist/runtime/polyfill/worker.mjs.map +1 -0
- package/dist/runtime/polyfill.d.mts +5 -0
- package/dist/runtime/renderContext.d.mts +21 -0
- package/dist/runtime/renderContext.mjs +147 -0
- package/dist/runtime/renderContext.mjs.map +1 -0
- package/dist/runtime/rpx.d.mts +9 -0
- package/dist/runtime/rpx.mjs +27 -0
- package/dist/runtime/rpx.mjs.map +1 -0
- package/dist/runtime/style.d.mts +6 -0
- package/dist/runtime/style.mjs +37 -0
- package/dist/runtime/style.mjs.map +1 -0
- package/dist/runtime/template.d.mts +10 -0
- package/dist/runtime/warning.d.mts +10 -0
- package/dist/runtime/warning.mjs +43 -0
- package/dist/runtime/warning.mjs.map +1 -0
- package/dist/{slugify-B4l45KNs.mjs → shared/slugify.mjs} +3 -1
- package/dist/shared/slugify.mjs.map +1 -0
- package/dist/shared/wxml.mjs +64 -0
- package/dist/shared/wxml.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/index-w9xxIH-l.d.mts +0 -1229
- package/dist/plugin-BARxSPO8.mjs +0 -1567
- package/dist/plugin-DP2iPVmw.d.mts +0 -96
- package/dist/runtime-D6j2_x_N.mjs +0 -6251
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { emitRuntimeWarning } from "../warning.mjs";
|
|
2
|
+
import { FallbackElement, supportsLit } from "./constants.mjs";
|
|
3
|
+
import { createComponentElementClass } from "./element.mjs";
|
|
4
|
+
import { createComponentRuntimeState, updateComponentRuntimeState } from "./state.mjs";
|
|
5
|
+
import { LitElement } from "lit";
|
|
6
|
+
|
|
7
|
+
//#region src/runtime/component/index.ts
|
|
8
|
+
function emitBehaviorWarnings(warnings) {
|
|
9
|
+
for (const warning of warnings) emitRuntimeWarning(warning, {
|
|
10
|
+
key: `component-behaviors:${warning}`,
|
|
11
|
+
context: "runtime:component"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function defineComponent(tagName, options) {
|
|
15
|
+
if (!options || typeof options !== "object") throw new TypeError("[@weapp-vite/web] defineComponent 需要提供配置对象。");
|
|
16
|
+
const existing = customElements.get(tagName);
|
|
17
|
+
if (existing) {
|
|
18
|
+
existing.__weappUpdate?.(options);
|
|
19
|
+
return existing;
|
|
20
|
+
}
|
|
21
|
+
if (!options.template) throw new Error("[@weapp-vite/web] defineComponent 需要提供模板渲染函数。");
|
|
22
|
+
const BaseElement = supportsLit ? LitElement : globalThis.HTMLElement ?? FallbackElement;
|
|
23
|
+
const { state: runtimeState, warnings } = createComponentRuntimeState(options);
|
|
24
|
+
emitBehaviorWarnings(warnings);
|
|
25
|
+
const instances = /* @__PURE__ */ new Set();
|
|
26
|
+
const WeappWebComponent = createComponentElementClass({
|
|
27
|
+
BaseElement,
|
|
28
|
+
runtimeState,
|
|
29
|
+
instances
|
|
30
|
+
});
|
|
31
|
+
const updateComponent = (nextOptions) => {
|
|
32
|
+
if (!nextOptions?.template) return;
|
|
33
|
+
const { warnings: nextWarnings, nextMethods } = updateComponentRuntimeState(runtimeState, nextOptions);
|
|
34
|
+
emitBehaviorWarnings(nextWarnings);
|
|
35
|
+
for (const instance of instances) instance.__weappSync(nextMethods);
|
|
36
|
+
};
|
|
37
|
+
WeappWebComponent.__weappUpdate = updateComponent;
|
|
38
|
+
customElements.define(tagName, WeappWebComponent);
|
|
39
|
+
return WeappWebComponent;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { defineComponent };
|
|
44
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/component/index.ts"],"sourcesContent":["import type { WeappComponentInstance } from './element'\nimport type { ComponentConstructor, DefineComponentOptions } from './types'\nimport { LitElement } from 'lit'\nimport { emitRuntimeWarning } from '../warning'\nimport { FallbackElement, supportsLit } from './constants'\nimport { createComponentElementClass } from './element'\nimport { createComponentRuntimeState, updateComponentRuntimeState } from './state'\n\nfunction emitBehaviorWarnings(warnings: string[]): void {\n for (const warning of warnings) {\n emitRuntimeWarning(warning, {\n key: `component-behaviors:${warning}`,\n context: 'runtime:component',\n })\n }\n}\n\nexport function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor {\n if (!options || typeof options !== 'object') {\n throw new TypeError('[@weapp-vite/web] defineComponent 需要提供配置对象。')\n }\n\n const existing = customElements.get(tagName) as ComponentConstructor | undefined\n if (existing) {\n existing.__weappUpdate?.(options)\n return existing\n }\n\n if (!options.template) {\n throw new Error('[@weapp-vite/web] defineComponent 需要提供模板渲染函数。')\n }\n\n const BaseElement = (supportsLit ? LitElement : (globalThis.HTMLElement ?? FallbackElement)) as typeof HTMLElement\n const { state: runtimeState, warnings } = createComponentRuntimeState(options)\n emitBehaviorWarnings(warnings)\n\n const instances = new Set<WeappComponentInstance>()\n const WeappWebComponent = createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n })\n\n const updateComponent = (nextOptions: DefineComponentOptions) => {\n if (!nextOptions?.template) {\n return\n }\n const { warnings: nextWarnings, nextMethods } = updateComponentRuntimeState(runtimeState, nextOptions)\n emitBehaviorWarnings(nextWarnings)\n for (const instance of instances) {\n instance.__weappSync(nextMethods)\n }\n }\n\n ;(WeappWebComponent as ComponentConstructor).__weappUpdate = updateComponent\n\n customElements.define(tagName, WeappWebComponent)\n return WeappWebComponent\n}\n\nexport type {\n ComponentOptions,\n ComponentPublicInstance,\n DefineComponentOptions,\n PropertyOption,\n} from './types'\n"],"mappings":";;;;;;;AAQA,SAAS,qBAAqB,UAA0B;AACtD,MAAK,MAAM,WAAW,SACpB,oBAAmB,SAAS;EAC1B,KAAK,uBAAuB;EAC5B,SAAS;EACV,CAAC;;AAIN,SAAgB,gBAAgB,SAAiB,SAAuD;AACtG,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,OAAM,IAAI,UAAU,8CAA8C;CAGpE,MAAM,WAAW,eAAe,IAAI,QAAQ;AAC5C,KAAI,UAAU;AACZ,WAAS,gBAAgB,QAAQ;AACjC,SAAO;;AAGT,KAAI,CAAC,QAAQ,SACX,OAAM,IAAI,MAAM,gDAAgD;CAGlE,MAAM,cAAe,cAAc,aAAc,WAAW,eAAe;CAC3E,MAAM,EAAE,OAAO,cAAc,aAAa,4BAA4B,QAAQ;AAC9E,sBAAqB,SAAS;CAE9B,MAAM,4BAAY,IAAI,KAA6B;CACnD,MAAM,oBAAoB,4BAA4B;EACpD;EACA;EACA;EACD,CAAC;CAEF,MAAM,mBAAmB,gBAAwC;AAC/D,MAAI,CAAC,aAAa,SAChB;EAEF,MAAM,EAAE,UAAU,cAAc,gBAAgB,4BAA4B,cAAc,YAAY;AACtG,uBAAqB,aAAa;AAClC,OAAK,MAAM,YAAY,UACrB,UAAS,YAAY,YAAY;;AAIpC,CAAC,kBAA2C,gBAAgB;AAE7D,gBAAe,OAAO,SAAS,kBAAkB;AACjD,QAAO"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { cloneValue, hyphenate } from "./utils.mjs";
|
|
2
|
+
import { normalizeBehaviors } from "./behavior.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/component/state.ts
|
|
5
|
+
function resolveNormalizedComponent(component) {
|
|
6
|
+
const normalized = normalizeBehaviors(component);
|
|
7
|
+
return {
|
|
8
|
+
warnings: normalized.warnings,
|
|
9
|
+
component: normalized.component ?? component ?? {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createDefaultPropertyValues(propertyEntries) {
|
|
13
|
+
return propertyEntries.reduce((acc, [name, prop]) => {
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(prop, "value")) acc[name] = cloneValue(prop.value);
|
|
15
|
+
else acc[name] = void 0;
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
function createPropertyEntries(component) {
|
|
20
|
+
return Object.entries(component.properties ?? {});
|
|
21
|
+
}
|
|
22
|
+
function createObservedAttributes(propertyEntries) {
|
|
23
|
+
return propertyEntries.map(([name]) => hyphenate(name));
|
|
24
|
+
}
|
|
25
|
+
function createComponentRuntimeState(options) {
|
|
26
|
+
const { component, warnings } = resolveNormalizedComponent(options.component ?? {});
|
|
27
|
+
const propertyEntries = createPropertyEntries(component);
|
|
28
|
+
return {
|
|
29
|
+
state: {
|
|
30
|
+
templateRef: options.template,
|
|
31
|
+
styleRef: options.style ?? "",
|
|
32
|
+
componentRef: component,
|
|
33
|
+
observerInitEnabled: Boolean(options.observerInit),
|
|
34
|
+
propertyEntries,
|
|
35
|
+
observedAttributes: createObservedAttributes(propertyEntries),
|
|
36
|
+
defaultPropertyValues: createDefaultPropertyValues(propertyEntries),
|
|
37
|
+
lifetimes: component.lifetimes ?? {},
|
|
38
|
+
pageLifetimes: component.pageLifetimes ?? {}
|
|
39
|
+
},
|
|
40
|
+
warnings
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function updateComponentRuntimeState(state, options) {
|
|
44
|
+
const { component, warnings } = resolveNormalizedComponent(options.component ?? {});
|
|
45
|
+
const propertyEntries = createPropertyEntries(component);
|
|
46
|
+
state.templateRef = options.template;
|
|
47
|
+
state.styleRef = options.style ?? "";
|
|
48
|
+
state.componentRef = component;
|
|
49
|
+
state.observerInitEnabled = Boolean(options.observerInit);
|
|
50
|
+
state.lifetimes = component.lifetimes ?? {};
|
|
51
|
+
state.pageLifetimes = component.pageLifetimes ?? {};
|
|
52
|
+
state.propertyEntries = propertyEntries;
|
|
53
|
+
state.observedAttributes = createObservedAttributes(propertyEntries);
|
|
54
|
+
state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries);
|
|
55
|
+
return {
|
|
56
|
+
warnings,
|
|
57
|
+
nextMethods: component.methods ?? {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createComponentRuntimeState, updateComponentRuntimeState };
|
|
63
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n PageLifeTimeHooks,\n PropertyOption,\n} from './types'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef: ComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions | undefined) {\n const normalized = normalizeBehaviors(component)\n return {\n warnings: normalized.warnings,\n component: normalized.component ?? component ?? {},\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (Object.prototype.hasOwnProperty.call(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: ComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties ?? {})\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n templateRef: options.template,\n styleRef: options.style ?? '',\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.styleRef = options.style ?? ''\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":";;;;AAyBA,SAAS,2BAA2B,WAAyC;CAC3E,MAAM,aAAa,mBAAmB,UAAU;AAChD,QAAO;EACL,UAAU,WAAW;EACrB,WAAW,WAAW,aAAa,aAAa,EAAE;EACnD;;AAGH,SAAS,4BAA4B,iBAAkC;AACrE,QAAO,gBAAgB,QAAoB,KAAK,CAAC,MAAM,UAAU;AAC/D,MAAI,OAAO,UAAU,eAAe,KAAK,MAAM,QAAQ,CACrD,KAAI,QAAQ,WAAW,KAAK,MAAM;MAGlC,KAAI,QAAQ;AAEd,SAAO;IACN,EAAE,CAAC;;AAGR,SAAS,sBAAsB,WAA8C;AAC3E,QAAO,OAAO,QAAQ,UAAU,cAAc,EAAE,CAAC;;AAGnD,SAAS,yBAAyB,iBAAkC;AAClE,QAAO,gBAAgB,KAAK,CAAC,UAAU,UAAU,KAAK,CAAC;;AAGzD,SAAgB,4BAA4B,SAAiC;CAC3E,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,EAAE,CAAC;CACnF,MAAM,kBAAkB,sBAAsB,UAAU;AAYxD,QAAO;EACL,OAZmC;GACnC,aAAa,QAAQ;GACrB,UAAU,QAAQ,SAAS;GAC3B,cAAc;GACd,qBAAqB,QAAQ,QAAQ,aAAa;GAClD;GACA,oBAAoB,yBAAyB,gBAAgB;GAC7D,uBAAuB,4BAA4B,gBAAgB;GACnE,WAAW,UAAU,aAAa,EAAE;GACpC,eAAe,UAAU,iBAAiB,EAAE;GAC7C;EAGC;EACD;;AAGH,SAAgB,4BAA4B,OAA8B,SAAiC;CACzG,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,EAAE,CAAC;CACnF,MAAM,kBAAkB,sBAAsB,UAAU;AACxD,OAAM,cAAc,QAAQ;AAC5B,OAAM,WAAW,QAAQ,SAAS;AAClC,OAAM,eAAe;AACrB,OAAM,sBAAsB,QAAQ,QAAQ,aAAa;AACzD,OAAM,YAAY,UAAU,aAAa,EAAE;AAC3C,OAAM,gBAAgB,UAAU,iBAAiB,EAAE;AACnD,OAAM,kBAAkB;AACxB,OAAM,qBAAqB,yBAAyB,gBAAgB;AACpE,OAAM,wBAAwB,4BAA4B,gBAAgB;AAC1E,QAAO;EACL;EACA,aAAa,UAAU,WAAW,EAAE;EACrC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TemplateRenderer } from "../template.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/component/types.d.ts
|
|
4
|
+
type DataRecord = Record<string, any>;
|
|
5
|
+
interface PropertyOption {
|
|
6
|
+
type?: StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
7
|
+
value?: any;
|
|
8
|
+
observer?: (this: ComponentPublicInstance, newValue: any, oldValue: any) => void;
|
|
9
|
+
}
|
|
10
|
+
interface LifeTimeHooks {
|
|
11
|
+
created?: (this: ComponentPublicInstance) => void;
|
|
12
|
+
attached?: (this: ComponentPublicInstance) => void;
|
|
13
|
+
ready?: (this: ComponentPublicInstance) => void;
|
|
14
|
+
detached?: (this: ComponentPublicInstance) => void;
|
|
15
|
+
}
|
|
16
|
+
interface PageLifeTimeHooks {
|
|
17
|
+
show?: (this: ComponentPublicInstance) => void;
|
|
18
|
+
hide?: (this: ComponentPublicInstance) => void;
|
|
19
|
+
resize?: (this: ComponentPublicInstance) => void;
|
|
20
|
+
}
|
|
21
|
+
interface ComponentOptions {
|
|
22
|
+
properties?: Record<string, PropertyOption>;
|
|
23
|
+
data?: DataRecord | (() => DataRecord);
|
|
24
|
+
methods?: Record<string, (this: ComponentPublicInstance, event: any) => any>;
|
|
25
|
+
lifetimes?: LifeTimeHooks;
|
|
26
|
+
pageLifetimes?: PageLifeTimeHooks;
|
|
27
|
+
behaviors?: ComponentOptions[];
|
|
28
|
+
}
|
|
29
|
+
interface DefineComponentOptions {
|
|
30
|
+
template: TemplateRenderer;
|
|
31
|
+
style?: string;
|
|
32
|
+
component?: ComponentOptions;
|
|
33
|
+
observerInit?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface ComponentPublicInstance extends HTMLElement {
|
|
36
|
+
readonly data: DataRecord;
|
|
37
|
+
readonly properties: DataRecord;
|
|
38
|
+
setData: (patch: DataRecord) => void;
|
|
39
|
+
triggerEvent: (name: string, detail?: any) => void;
|
|
40
|
+
createSelectorQuery: () => any;
|
|
41
|
+
selectComponent: (selector: string) => ComponentPublicInstance | null;
|
|
42
|
+
selectAllComponents: (selector: string) => ComponentPublicInstance[];
|
|
43
|
+
}
|
|
44
|
+
type ComponentConstructor = CustomElementConstructor & {
|
|
45
|
+
__weappUpdate?: (options: DefineComponentOptions) => void;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DefineComponentOptions, PropertyOption };
|
|
49
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/runtime/component/utils.ts
|
|
2
|
+
function hyphenate(name) {
|
|
3
|
+
return name.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
|
|
4
|
+
}
|
|
5
|
+
function toCamelCase(name) {
|
|
6
|
+
return name.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
7
|
+
}
|
|
8
|
+
function cloneValue(value) {
|
|
9
|
+
if (Array.isArray(value)) return value.slice();
|
|
10
|
+
if (value && typeof value === "object") return { ...value };
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function coerceValue(value, type) {
|
|
14
|
+
if (type === Boolean) {
|
|
15
|
+
if (value === "" || value === true) return true;
|
|
16
|
+
if (value === void 0 || value === null || value === false) return false;
|
|
17
|
+
if (typeof value === "string") return value !== "false";
|
|
18
|
+
return Boolean(value);
|
|
19
|
+
}
|
|
20
|
+
if (type === Number) {
|
|
21
|
+
if (value === void 0 || value === null) return value;
|
|
22
|
+
const numeric = Number(value);
|
|
23
|
+
return Number.isNaN(numeric) ? value : numeric;
|
|
24
|
+
}
|
|
25
|
+
if (type === Object || type === Array) {
|
|
26
|
+
if (value === void 0 || value === null) return value;
|
|
27
|
+
if (typeof value === "string") try {
|
|
28
|
+
return JSON.parse(value);
|
|
29
|
+
} catch {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { cloneValue, coerceValue, hyphenate, toCamelCase };
|
|
39
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/runtime/component/utils.ts"],"sourcesContent":["import type { PropertyOption } from './types'\n\nexport function hyphenate(name: string) {\n return name.replace(/([A-Z])/g, (_, char: string) => `-${char.toLowerCase()}`)\n}\n\nexport function toCamelCase(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function cloneValue(value: any) {\n if (Array.isArray(value)) {\n return value.slice()\n }\n if (value && typeof value === 'object') {\n return { ...value }\n }\n return value\n}\n\nexport function coerceValue(value: any, type?: PropertyOption['type']) {\n if (type === Boolean) {\n if (value === '' || value === true) {\n return true\n }\n if (value === undefined || value === null || value === false) {\n return false\n }\n if (typeof value === 'string') {\n return value !== 'false'\n }\n return Boolean(value)\n }\n\n if (type === Number) {\n if (value === undefined || value === null) {\n return value\n }\n const numeric = Number(value)\n return Number.isNaN(numeric) ? value : numeric\n }\n\n if (type === Object || type === Array) {\n if (value === undefined || value === null) {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n }\n return value\n }\n\n return value\n}\n"],"mappings":";AAEA,SAAgB,UAAU,MAAc;AACtC,QAAO,KAAK,QAAQ,aAAa,GAAG,SAAiB,IAAI,KAAK,aAAa,GAAG;;AAGhF,SAAgB,YAAY,MAAc;AACxC,QAAO,KAAK,QAAQ,cAAc,GAAG,SAAiB,KAAK,aAAa,CAAC;;AAG3E,SAAgB,WAAW,OAAY;AACrC,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,OAAO;AAEtB,KAAI,SAAS,OAAO,UAAU,SAC5B,QAAO,EAAE,GAAG,OAAO;AAErB,QAAO;;AAGT,SAAgB,YAAY,OAAY,MAA+B;AACrE,KAAI,SAAS,SAAS;AACpB,MAAI,UAAU,MAAM,UAAU,KAC5B,QAAO;AAET,MAAI,UAAU,UAAa,UAAU,QAAQ,UAAU,MACrD,QAAO;AAET,MAAI,OAAO,UAAU,SACnB,QAAO,UAAU;AAEnB,SAAO,QAAQ,MAAM;;AAGvB,KAAI,SAAS,QAAQ;AACnB,MAAI,UAAU,UAAa,UAAU,KACnC,QAAO;EAET,MAAM,UAAU,OAAO,MAAM;AAC7B,SAAO,OAAO,MAAM,QAAQ,GAAG,QAAQ;;AAGzC,KAAI,SAAS,UAAU,SAAS,OAAO;AACrC,MAAI,UAAU,UAAa,UAAU,KACnC,QAAO;AAET,MAAI,OAAO,UAAU,SACnB,KAAI;AACF,UAAO,KAAK,MAAM,MAAM;UAEpB;AACJ,UAAO;;AAGX,SAAO;;AAGT,QAAO"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/runtime/execution.d.ts
|
|
2
|
+
type RuntimeExecutionMode = 'compat' | 'safe' | 'strict';
|
|
3
|
+
declare function getRuntimeExecutionMode(): RuntimeExecutionMode;
|
|
4
|
+
declare function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getRuntimeExecutionMode, setRuntimeExecutionMode };
|
|
7
|
+
//# sourceMappingURL=execution.d.mts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { emitRuntimeWarning } from "./warning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/execution.ts
|
|
4
|
+
let currentRuntimeExecutionMode = "compat";
|
|
5
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
6
|
+
function isRuntimeExecutionMode(value) {
|
|
7
|
+
return value === "compat" || value === "safe" || value === "strict";
|
|
8
|
+
}
|
|
9
|
+
function getRuntimeExecutionMode() {
|
|
10
|
+
return currentRuntimeExecutionMode;
|
|
11
|
+
}
|
|
12
|
+
function warnRuntimeExecutionOnce(key, message) {
|
|
13
|
+
if (warnedMessages.has(key)) return;
|
|
14
|
+
warnedMessages.add(key);
|
|
15
|
+
emitRuntimeWarning(message, {
|
|
16
|
+
key: `execution:${key}`,
|
|
17
|
+
context: "runtime:execution"
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function setRuntimeExecutionMode(mode) {
|
|
21
|
+
if (mode === void 0) {
|
|
22
|
+
currentRuntimeExecutionMode = "compat";
|
|
23
|
+
warnedMessages.clear();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (isRuntimeExecutionMode(mode)) {
|
|
27
|
+
currentRuntimeExecutionMode = mode;
|
|
28
|
+
warnedMessages.clear();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
warnRuntimeExecutionOnce(`invalid-runtime-mode:${String(mode)}`, `[@weapp-vite/web] 未知 executionMode "${String(mode)}",已回退到 compat。`);
|
|
32
|
+
currentRuntimeExecutionMode = "compat";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { getRuntimeExecutionMode, setRuntimeExecutionMode, warnRuntimeExecutionOnce };
|
|
37
|
+
//# sourceMappingURL=execution.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.mjs","names":[],"sources":["../../src/runtime/execution.ts"],"sourcesContent":["import { emitRuntimeWarning } from './warning'\n\nexport type RuntimeExecutionMode = 'compat' | 'safe' | 'strict'\n\nlet currentRuntimeExecutionMode: RuntimeExecutionMode = 'compat'\nconst warnedMessages = new Set<string>()\n\nfunction isRuntimeExecutionMode(value: unknown): value is RuntimeExecutionMode {\n return value === 'compat' || value === 'safe' || value === 'strict'\n}\n\nexport function getRuntimeExecutionMode(): RuntimeExecutionMode {\n return currentRuntimeExecutionMode\n}\n\nexport function warnRuntimeExecutionOnce(key: string, message: string): void {\n if (warnedMessages.has(key)) {\n return\n }\n warnedMessages.add(key)\n emitRuntimeWarning(message, {\n key: `execution:${key}`,\n context: 'runtime:execution',\n })\n}\n\nexport function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void {\n if (mode === undefined) {\n currentRuntimeExecutionMode = 'compat'\n warnedMessages.clear()\n return\n }\n if (isRuntimeExecutionMode(mode)) {\n currentRuntimeExecutionMode = mode\n warnedMessages.clear()\n return\n }\n warnRuntimeExecutionOnce(\n `invalid-runtime-mode:${String(mode)}`,\n `[@weapp-vite/web] 未知 executionMode \"${String(mode)}\",已回退到 compat。`,\n )\n currentRuntimeExecutionMode = 'compat'\n}\n"],"mappings":";;;AAIA,IAAI,8BAAoD;AACxD,MAAM,iCAAiB,IAAI,KAAa;AAExC,SAAS,uBAAuB,OAA+C;AAC7E,QAAO,UAAU,YAAY,UAAU,UAAU,UAAU;;AAG7D,SAAgB,0BAAgD;AAC9D,QAAO;;AAGT,SAAgB,yBAAyB,KAAa,SAAuB;AAC3E,KAAI,eAAe,IAAI,IAAI,CACzB;AAEF,gBAAe,IAAI,IAAI;AACvB,oBAAmB,SAAS;EAC1B,KAAK,aAAa;EAClB,SAAS;EACV,CAAC;;AAGJ,SAAgB,wBAAwB,MAA4C;AAClF,KAAI,SAAS,QAAW;AACtB,gCAA8B;AAC9B,iBAAe,OAAO;AACtB;;AAEF,KAAI,uBAAuB,KAAK,EAAE;AAChC,gCAA8B;AAC9B,iBAAe,OAAO;AACtB;;AAEF,0BACE,wBAAwB,OAAO,KAAK,IACpC,uCAAuC,OAAO,KAAK,CAAC,gBACrD;AACD,+BAA8B"}
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ButtonFormConfig, ensureButtonDefined, setButtonFormConfig } from "./button/index.mjs";
|
|
2
|
+
import { RenderContext, createRenderContext } from "./renderContext.mjs";
|
|
3
|
+
import { createTemplate, renderTemplate } from "./legacyTemplate/index.mjs";
|
|
4
|
+
import { TemplateRenderer, TemplateScope } from "./template.mjs";
|
|
5
|
+
import { defineComponent } from "./component/index.mjs";
|
|
6
|
+
import { getRuntimeExecutionMode, setRuntimeExecutionMode } from "./execution.mjs";
|
|
7
|
+
import { NavigationBarMetrics, setNavigationBarMetrics } from "./navigationBar/index.mjs";
|
|
8
|
+
import { authorize, checkSession, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort } from "./polyfill/deviceAuthSystemApi.mjs";
|
|
9
|
+
import { getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./polyfill/routeRuntime.mjs";
|
|
10
|
+
import { clearStorage, clearStorageSync, createCanvasContext, createSelectorQuery, createVKSession, createVideoContext, createWorker, downloadFile, exitMiniProgram, getFileSystemManager, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, hideKeyboard, loadSubPackage, navigateToMiniProgram, nextTick, pageScrollTo, preloadSubpackage, removeStorage, removeStorageSync, request, setStorage, setStorageSync, startPullDownRefresh, stopPullDownRefresh, uploadFile } from "./polyfill/runtimeDataApi.mjs";
|
|
11
|
+
import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showToast, updateShareMenu } from "./polyfill/uiMediaApi.mjs";
|
|
12
|
+
import { canIUse, createInterstitialAd, createRewardedVideoAd, getExtConfig, getExtConfigSync, getLogManager, getUpdateManager, hideNavigationBarLoading, reportAnalytics, setBackgroundColor, setBackgroundTextStyle, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading } from "./polyfill/index.mjs";
|
|
13
|
+
import { RpxConfig, setupRpx } from "./rpx.mjs";
|
|
14
|
+
import { injectStyle, removeStyle } from "./style.mjs";
|
|
15
|
+
import { RuntimeWarningLevel, RuntimeWarningOptions, setRuntimeWarningOptions } from "./warning.mjs";
|
|
16
|
+
export { type ButtonFormConfig, type NavigationBarMetrics, type RenderContext, type RpxConfig, type RuntimeWarningLevel, type RuntimeWarningOptions, type TemplateRenderer, type TemplateScope, authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, createCanvasContext, createInterstitialAd, createRenderContext, createRewardedVideoAd, createSelectorQuery, createTemplate, createVKSession, createVideoContext, createWorker, defineComponent, downloadFile, ensureButtonDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeExecutionMode, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, initializePageRoutes, injectStyle, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, removeStorage, removeStorageSync, removeStyle, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setupRpx, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, updateShareMenu, uploadFile, vibrateShort };
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { injectStyle, removeStyle } from "./style.mjs";
|
|
2
|
+
import { ensureButtonDefined, setButtonFormConfig } from "./button/index.mjs";
|
|
3
|
+
import { setRuntimeWarningOptions } from "./warning.mjs";
|
|
4
|
+
import { getRuntimeExecutionMode, setRuntimeExecutionMode } from "./execution.mjs";
|
|
5
|
+
import { createRenderContext } from "./renderContext.mjs";
|
|
6
|
+
import { defineComponent } from "./component/index.mjs";
|
|
7
|
+
import { setNavigationBarMetrics } from "./navigationBar/index.mjs";
|
|
8
|
+
import { authorize, checkSession, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort } from "./polyfill/deviceAuthSystemApi.mjs";
|
|
9
|
+
import { setupRpx } from "./rpx.mjs";
|
|
10
|
+
import { getEnterOptionsSync, getLaunchOptionsSync, initializePageRoutes, navigateBack, navigateTo, reLaunch, redirectTo, registerApp, registerComponent, registerPage, switchTab } from "./polyfill/routeRuntime.mjs";
|
|
11
|
+
import { clearStorage, clearStorageSync, createCanvasContext, createSelectorQuery, createVKSession, createVideoContext, createWorker, downloadFile, exitMiniProgram, getFileSystemManager, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, hideKeyboard, loadSubPackage, navigateToMiniProgram, nextTick, pageScrollTo, preloadSubpackage, removeStorage, removeStorageSync, request, setStorage, setStorageSync, startPullDownRefresh, stopPullDownRefresh, uploadFile } from "./polyfill/runtimeDataApi.mjs";
|
|
12
|
+
import { chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, compressImage, compressVideo, getClipboardData, getImageInfo, getVideoInfo, hideLoading, hideTabBar, makePhoneCall, openCustomerServiceChat, openDocument, openLocation, openVideoEditor, previewImage, previewMedia, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setClipboardData, showActionSheet, showLoading, showModal, showShareMenu, showTabBar, showToast, updateShareMenu } from "./polyfill/uiMediaApi.mjs";
|
|
13
|
+
import { canIUse, createInterstitialAd, createRewardedVideoAd, getExtConfig, getExtConfigSync, getLogManager, getUpdateManager, hideNavigationBarLoading, reportAnalytics, setBackgroundColor, setBackgroundTextStyle, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading } from "./polyfill/index.mjs";
|
|
14
|
+
import { createTemplate, renderTemplate } from "./legacyTemplate/index.mjs";
|
|
15
|
+
|
|
16
|
+
export { authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, createCanvasContext, createInterstitialAd, createRenderContext, createRewardedVideoAd, createSelectorQuery, createTemplate, createVKSession, createVideoContext, createWorker, defineComponent, downloadFile, ensureButtonDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeExecutionMode, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, initializePageRoutes, injectStyle, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, removeStorage, removeStorageSync, removeStyle, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setupRpx, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, updateShareMenu, uploadFile, vibrateShort };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { escapeAttribute, resolveAttributeValue } from "./expression.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/legacyTemplate/dom.ts
|
|
4
|
+
const CONTROL_ATTRS = new Set([
|
|
5
|
+
"wx:if",
|
|
6
|
+
"wx:elif",
|
|
7
|
+
"wx:else",
|
|
8
|
+
"wx:for",
|
|
9
|
+
"wx:for-item",
|
|
10
|
+
"wx:for-index",
|
|
11
|
+
"wx:key"
|
|
12
|
+
]);
|
|
13
|
+
const EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\w-]+)$/;
|
|
14
|
+
const EVENT_KIND_ALIAS = {
|
|
15
|
+
tap: "click",
|
|
16
|
+
longtap: "contextmenu",
|
|
17
|
+
longpress: "contextmenu"
|
|
18
|
+
};
|
|
19
|
+
const EVENT_PREFIX_FLAGS = {
|
|
20
|
+
"bind": {},
|
|
21
|
+
"catch": { catch: true },
|
|
22
|
+
"mut-bind": {},
|
|
23
|
+
"capture-bind": { capture: true },
|
|
24
|
+
"capture-catch": {
|
|
25
|
+
capture: true,
|
|
26
|
+
catch: true
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const SELF_CLOSING_TAGS = new Set([
|
|
30
|
+
"area",
|
|
31
|
+
"base",
|
|
32
|
+
"br",
|
|
33
|
+
"col",
|
|
34
|
+
"embed",
|
|
35
|
+
"hr",
|
|
36
|
+
"img",
|
|
37
|
+
"image",
|
|
38
|
+
"input",
|
|
39
|
+
"link",
|
|
40
|
+
"meta",
|
|
41
|
+
"param",
|
|
42
|
+
"source",
|
|
43
|
+
"track",
|
|
44
|
+
"wbr"
|
|
45
|
+
]);
|
|
46
|
+
function normalizeTagName(name) {
|
|
47
|
+
switch (name) {
|
|
48
|
+
case "view":
|
|
49
|
+
case "cover-view":
|
|
50
|
+
case "navigator":
|
|
51
|
+
case "scroll-view":
|
|
52
|
+
case "swiper":
|
|
53
|
+
case "swiper-item":
|
|
54
|
+
case "movable-area":
|
|
55
|
+
case "movable-view":
|
|
56
|
+
case "cover-image": return "div";
|
|
57
|
+
case "text":
|
|
58
|
+
case "icon": return "span";
|
|
59
|
+
case "image": return "img";
|
|
60
|
+
case "button": return "weapp-button";
|
|
61
|
+
case "input": return "input";
|
|
62
|
+
case "textarea": return "textarea";
|
|
63
|
+
case "form": return "form";
|
|
64
|
+
case "label": return "label";
|
|
65
|
+
case "picker":
|
|
66
|
+
case "picker-view": return "select";
|
|
67
|
+
case "block": return "#fragment";
|
|
68
|
+
case "slot": return "slot";
|
|
69
|
+
default: return name || "div";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function normalizeAttributeName(name) {
|
|
73
|
+
if (name === "class" || name === "style" || name.startsWith("data-")) return name;
|
|
74
|
+
if (name === "hover-class") return "data-hover-class";
|
|
75
|
+
return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
76
|
+
}
|
|
77
|
+
function extractFor(attribs) {
|
|
78
|
+
const expr = attribs["wx:for"];
|
|
79
|
+
const restAttribs = {};
|
|
80
|
+
const itemName = attribs["wx:for-item"]?.trim() || "item";
|
|
81
|
+
let indexName = attribs["wx:for-index"]?.trim() || "index";
|
|
82
|
+
for (const [key, val] of Object.entries(attribs)) {
|
|
83
|
+
if (key === "wx:for" || key === "wx:for-item" || key === "wx:for-index" || key === "wx:key") continue;
|
|
84
|
+
restAttribs[key] = val;
|
|
85
|
+
}
|
|
86
|
+
if (itemName === indexName) indexName = `${indexName}Index`;
|
|
87
|
+
return {
|
|
88
|
+
expr,
|
|
89
|
+
itemName,
|
|
90
|
+
indexName,
|
|
91
|
+
restAttribs
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function buildAttributeString(attribs, scope) {
|
|
95
|
+
let result = "";
|
|
96
|
+
for (const [name, rawValue] of Object.entries(attribs)) {
|
|
97
|
+
if (CONTROL_ATTRS.has(name)) continue;
|
|
98
|
+
const eventMatch = EVENT_PREFIX_RE.exec(name);
|
|
99
|
+
if (eventMatch) {
|
|
100
|
+
const [, prefix, rawEvent] = eventMatch;
|
|
101
|
+
const event = rawEvent.toLowerCase();
|
|
102
|
+
const handlerName = resolveAttributeValue(rawValue, scope).trim();
|
|
103
|
+
if (!handlerName) continue;
|
|
104
|
+
const runtimeEvent = EVENT_KIND_ALIAS[event] ?? event;
|
|
105
|
+
const flags = EVENT_PREFIX_FLAGS[prefix] ?? {};
|
|
106
|
+
result += ` data-wx-on-${runtimeEvent}="${escapeAttribute(handlerName)}"`;
|
|
107
|
+
const flagTokens = [flags.capture ? "capture" : "", flags.catch ? "catch" : ""].filter(Boolean);
|
|
108
|
+
if (flagTokens.length) result += ` data-wx-on-flags-${runtimeEvent}="${flagTokens.join(",")}"`;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const value = resolveAttributeValue(rawValue, scope);
|
|
112
|
+
if (value === "") continue;
|
|
113
|
+
const normalizedName = normalizeAttributeName(name);
|
|
114
|
+
result += ` ${normalizedName}="${escapeAttribute(value)}"`;
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
function stripControlAttributes(attribs) {
|
|
119
|
+
const result = {};
|
|
120
|
+
for (const [name, value] of Object.entries(attribs)) if (!CONTROL_ATTRS.has(name)) result[name] = value;
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
function isConditionalElement(node) {
|
|
124
|
+
if (node.type !== "tag") return false;
|
|
125
|
+
const attribs = node.attribs ?? {};
|
|
126
|
+
return "wx:if" in attribs || "wx:elif" in attribs || "wx:else" in attribs;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
export { SELF_CLOSING_TAGS, buildAttributeString, extractFor, isConditionalElement, normalizeTagName, stripControlAttributes };
|
|
131
|
+
//# sourceMappingURL=dom.mjs.map
|
|
@@ -0,0 +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 { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst CONTROL_ATTRS = new Set([\n 'wx:if',\n 'wx:elif',\n 'wx:else',\n 'wx:for',\n 'wx:for-item',\n 'wx:for-index',\n 'wx:key',\n])\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_KIND_ALIAS: Record<string, string> = {\n tap: 'click',\n longtap: 'contextmenu',\n longpress: 'contextmenu',\n}\n\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\nexport const SELF_CLOSING_TAGS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'image',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nexport function normalizeTagName(name: string) {\n switch (name) {\n case 'view':\n case 'cover-view':\n case 'navigator':\n case 'scroll-view':\n case 'swiper':\n case 'swiper-item':\n case 'movable-area':\n case 'movable-view':\n case 'cover-image':\n return 'div'\n case 'text':\n case 'icon':\n return 'span'\n case 'image':\n return 'img'\n case 'button':\n return 'weapp-button'\n case 'input':\n return 'input'\n case 'textarea':\n return 'textarea'\n case 'form':\n return 'form'\n case 'label':\n return 'label'\n case 'picker':\n case 'picker-view':\n return 'select'\n case 'block':\n return '#fragment'\n case 'slot':\n return 'slot'\n default:\n return name || 'div'\n }\n}\n\nfunction normalizeAttributeName(name: string) {\n if (name === 'class' || name === 'style' || name.startsWith('data-')) {\n return name\n }\n if (name === 'hover-class') {\n return 'data-hover-class'\n }\n return name.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = attribs['wx:for']\n const restAttribs: Record<string, string> = {}\n const itemName = attribs['wx:for-item']?.trim() || 'item'\n let indexName = attribs['wx:for-index']?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (key === 'wx:for' || key === 'wx:for-item' || key === 'wx:for-index' || key === 'wx: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 eventMatch = EVENT_PREFIX_RE.exec(name)\n if (eventMatch) {\n const [, prefix, rawEvent] = eventMatch\n const event = rawEvent.toLowerCase()\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const runtimeEvent = EVENT_KIND_ALIAS[event] ?? event\n const flags = EVENT_PREFIX_FLAGS[prefix] ?? {}\n result += ` data-wx-on-${runtimeEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` data-wx-on-flags-${runtimeEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const value = resolveAttributeValue(rawValue, scope)\n if (value === '') {\n continue\n }\n const normalizedName = normalizeAttributeName(name)\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 'wx:if' in attribs || 'wx:elif' in attribs || 'wx:else' in attribs\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from "../execution.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/legacyTemplate/expression.ts
|
|
4
|
+
const expressionCache = /* @__PURE__ */ new Map();
|
|
5
|
+
function createScope(initial) {
|
|
6
|
+
return Object.assign(Object.create(null), initial ?? {});
|
|
7
|
+
}
|
|
8
|
+
function createChildScope(parent) {
|
|
9
|
+
return Object.assign(Object.create(parent), {});
|
|
10
|
+
}
|
|
11
|
+
function normalizeList(value) {
|
|
12
|
+
if (Array.isArray(value)) return value;
|
|
13
|
+
if (value == null) return [];
|
|
14
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
15
|
+
const length = Math.max(0, Math.floor(value));
|
|
16
|
+
return Array.from({ length }, (_, index) => index);
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "object") return Object.values(value);
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
function escapeHtml(value) {
|
|
22
|
+
return value.replace(/[&<>"']/g, (match) => {
|
|
23
|
+
switch (match) {
|
|
24
|
+
case "&": return "&";
|
|
25
|
+
case "<": return "<";
|
|
26
|
+
case ">": return ">";
|
|
27
|
+
case "\"": return """;
|
|
28
|
+
case "'": return "'";
|
|
29
|
+
default: return match;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function escapeAttribute(value) {
|
|
34
|
+
return escapeHtml(value);
|
|
35
|
+
}
|
|
36
|
+
function toDisplayString(value) {
|
|
37
|
+
if (value == null) return "";
|
|
38
|
+
if (typeof value === "object") {
|
|
39
|
+
if (value instanceof Date) return value.toISOString();
|
|
40
|
+
try {
|
|
41
|
+
return JSON.stringify(value);
|
|
42
|
+
} catch {
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return String(value);
|
|
47
|
+
}
|
|
48
|
+
function unwrapExpression(expression) {
|
|
49
|
+
const trimmed = expression.trim();
|
|
50
|
+
if (trimmed.startsWith("{{") && trimmed.endsWith("}}")) return trimmed.slice(2, -2).trim();
|
|
51
|
+
return trimmed;
|
|
52
|
+
}
|
|
53
|
+
function evaluateExpression(expression, scope) {
|
|
54
|
+
if (!expression) return;
|
|
55
|
+
const trimmed = unwrapExpression(expression);
|
|
56
|
+
if (!trimmed) return;
|
|
57
|
+
let evaluator = expressionCache.get(trimmed);
|
|
58
|
+
if (!evaluator) {
|
|
59
|
+
try {
|
|
60
|
+
evaluator = new Function("scope", `with(scope){ return (${trimmed}); }`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
63
|
+
if (getRuntimeExecutionMode() === "safe") {
|
|
64
|
+
warnRuntimeExecutionOnce(`safe-legacy-expression-parse:${trimmed}`, `[@weapp-vite/web] safe 模式下忽略表达式解析错误 "${trimmed}": ${reason}`);
|
|
65
|
+
evaluator = () => void 0;
|
|
66
|
+
} else throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 "${trimmed}": ${reason}`);
|
|
67
|
+
}
|
|
68
|
+
if (evaluator) expressionCache.set(trimmed, evaluator);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return evaluator?.(scope);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const mode = getRuntimeExecutionMode();
|
|
74
|
+
if (mode === "strict") {
|
|
75
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
76
|
+
throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 "${trimmed}": ${reason}`);
|
|
77
|
+
}
|
|
78
|
+
if (mode === "safe") {
|
|
79
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
80
|
+
warnRuntimeExecutionOnce(`safe-legacy-expression-runtime:${trimmed}`, `[@weapp-vite/web] safe 模式下忽略表达式执行错误 "${trimmed}": ${reason}`);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function interpolateText(source, scope, escapeResult) {
|
|
86
|
+
if (!source.includes("{{")) return escapeResult ? escapeHtml(source) : source;
|
|
87
|
+
let cursor = 0;
|
|
88
|
+
let buffer = "";
|
|
89
|
+
while (cursor < source.length) {
|
|
90
|
+
const start = source.indexOf("{{", cursor);
|
|
91
|
+
if (start === -1) {
|
|
92
|
+
buffer += source.slice(cursor);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
buffer += source.slice(cursor, start);
|
|
96
|
+
const end = source.indexOf("}}", start + 2);
|
|
97
|
+
if (end === -1) {
|
|
98
|
+
buffer += source.slice(start);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const evaluated = toDisplayString(evaluateExpression(source.slice(start + 2, end).trim(), scope));
|
|
102
|
+
buffer += evaluated;
|
|
103
|
+
cursor = end + 2;
|
|
104
|
+
}
|
|
105
|
+
return escapeResult ? escapeHtml(buffer) : buffer;
|
|
106
|
+
}
|
|
107
|
+
function resolveAttributeValue(value, scope) {
|
|
108
|
+
return interpolateText(value ?? "", scope, false);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { createChildScope, createScope, escapeAttribute, evaluateExpression, interpolateText, normalizeList, resolveAttributeValue };
|
|
113
|
+
//# sourceMappingURL=expression.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/expression.ts"],"sourcesContent":["import type { LegacyTemplateScope } from './types'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from '../execution'\n\nconst expressionCache = new Map<string, (scope: LegacyTemplateScope) => any>()\n\nexport function createScope(initial?: LegacyTemplateScope) {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nexport function createChildScope(parent: LegacyTemplateScope) {\n return Object.assign(Object.create(parent), {})\n}\n\nexport function normalizeList(value: any): any[] {\n if (Array.isArray(value)) {\n return value\n }\n if (value == null) {\n return []\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n const length = Math.max(0, Math.floor(value))\n return Array.from({ length }, (_, index) => index)\n }\n if (typeof value === 'object') {\n return Object.values(value)\n }\n return []\n}\n\nexport function escapeHtml(value: string) {\n return value.replace(/[&<>\"']/g, (match) => {\n switch (match) {\n case '&':\n return '&'\n case '<':\n return '<'\n case '>':\n return '>'\n case '\"':\n return '"'\n case '\\'':\n return '''\n default:\n return match\n }\n })\n}\n\nexport function escapeAttribute(value: string) {\n return escapeHtml(value)\n}\n\nfunction toDisplayString(value: any) {\n if (value == null) {\n return ''\n }\n if (typeof value === 'object') {\n if (value instanceof Date) {\n return value.toISOString()\n }\n try {\n return JSON.stringify(value)\n }\n catch {\n return String(value)\n }\n }\n return String(value)\n}\n\nfunction unwrapExpression(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{{') && trimmed.endsWith('}}')) {\n return trimmed.slice(2, -2).trim()\n }\n return trimmed\n}\n\nexport function evaluateExpression(expression: string, scope: LegacyTemplateScope) {\n if (!expression) {\n return undefined\n }\n const trimmed = unwrapExpression(expression)\n if (!trimmed) {\n return undefined\n }\n let evaluator = expressionCache.get(trimmed)\n if (!evaluator) {\n try {\n // eslint-disable-next-line no-new-func -- dynamic expressions are required for template evaluation\n evaluator = new Function('scope', `with(scope){ return (${trimmed}); }`) as (scope: LegacyTemplateScope) => any\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-parse:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式解析错误 \"${trimmed}\": ${reason}`,\n )\n evaluator = () => undefined\n }\n else {\n throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 \"${trimmed}\": ${reason}`)\n }\n }\n if (evaluator) {\n expressionCache.set(trimmed, evaluator)\n }\n }\n try {\n return evaluator?.(scope)\n }\n catch (error) {\n const mode = getRuntimeExecutionMode()\n if (mode === 'strict') {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 \"${trimmed}\": ${reason}`)\n }\n if (mode === 'safe') {\n const reason = error instanceof Error ? error.message : String(error)\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nexport function interpolateText(source: string, scope: LegacyTemplateScope, escapeResult: boolean) {\n if (!source.includes('{{')) {\n return escapeResult ? escapeHtml(source) : source\n }\n\n let cursor = 0\n let buffer = ''\n\n while (cursor < source.length) {\n const start = source.indexOf('{{', cursor)\n if (start === -1) {\n buffer += source.slice(cursor)\n break\n }\n\n buffer += source.slice(cursor, start)\n\n const end = source.indexOf('}}', start + 2)\n if (end === -1) {\n buffer += source.slice(start)\n break\n }\n\n const expression = source.slice(start + 2, end).trim()\n const evaluated = toDisplayString(evaluateExpression(expression, scope))\n buffer += evaluated\n cursor = end + 2\n }\n\n return escapeResult ? escapeHtml(buffer) : buffer\n}\n\nexport function resolveAttributeValue(value: string, scope: LegacyTemplateScope) {\n return interpolateText(value ?? '', scope, false)\n}\n"],"mappings":";;;AAGA,MAAM,kCAAkB,IAAI,KAAkD;AAE9E,SAAgB,YAAY,SAA+B;AACzD,QAAO,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,WAAW,EAAE,CAAC;;AAG1D,SAAgB,iBAAiB,QAA6B;AAC5D,QAAO,OAAO,OAAO,OAAO,OAAO,OAAO,EAAE,EAAE,CAAC;;AAGjD,SAAgB,cAAc,OAAmB;AAC/C,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO;AAET,KAAI,SAAS,KACX,QAAO,EAAE;AAEX,KAAI,OAAO,UAAU,YAAY,OAAO,SAAS,MAAM,EAAE;EACvD,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,CAAC;AAC7C,SAAO,MAAM,KAAK,EAAE,QAAQ,GAAG,GAAG,UAAU,MAAM;;AAEpD,KAAI,OAAO,UAAU,SACnB,QAAO,OAAO,OAAO,MAAM;AAE7B,QAAO,EAAE;;AAGX,SAAgB,WAAW,OAAe;AACxC,QAAO,MAAM,QAAQ,aAAa,UAAU;AAC1C,UAAQ,OAAR;GACE,KAAK,IACH,QAAO;GACT,KAAK,IACH,QAAO;GACT,KAAK,IACH,QAAO;GACT,KAAK,KACH,QAAO;GACT,KAAK,IACH,QAAO;GACT,QACE,QAAO;;GAEX;;AAGJ,SAAgB,gBAAgB,OAAe;AAC7C,QAAO,WAAW,MAAM;;AAG1B,SAAS,gBAAgB,OAAY;AACnC,KAAI,SAAS,KACX,QAAO;AAET,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,iBAAiB,KACnB,QAAO,MAAM,aAAa;AAE5B,MAAI;AACF,UAAO,KAAK,UAAU,MAAM;UAExB;AACJ,UAAO,OAAO,MAAM;;;AAGxB,QAAO,OAAO,MAAM;;AAGtB,SAAS,iBAAiB,YAAoB;CAC5C,MAAM,UAAU,WAAW,MAAM;AACjC,KAAI,QAAQ,WAAW,KAAK,IAAI,QAAQ,SAAS,KAAK,CACpD,QAAO,QAAQ,MAAM,GAAG,GAAG,CAAC,MAAM;AAEpC,QAAO;;AAGT,SAAgB,mBAAmB,YAAoB,OAA4B;AACjF,KAAI,CAAC,WACH;CAEF,MAAM,UAAU,iBAAiB,WAAW;AAC5C,KAAI,CAAC,QACH;CAEF,IAAI,YAAY,gBAAgB,IAAI,QAAQ;AAC5C,KAAI,CAAC,WAAW;AACd,MAAI;AAEF,eAAY,IAAI,SAAS,SAAS,wBAAwB,QAAQ,MAAM;WAEnE,OAAO;GACZ,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAErE,OADa,yBAAyB,KACzB,QAAQ;AACnB,6BACE,gCAAgC,WAChC,wCAAwC,QAAQ,KAAK,SACtD;AACD,sBAAkB;SAGlB,OAAM,IAAI,YAAY,8BAA8B,QAAQ,KAAK,SAAS;;AAG9E,MAAI,UACF,iBAAgB,IAAI,SAAS,UAAU;;AAG3C,KAAI;AACF,SAAO,YAAY,MAAM;UAEpB,OAAO;EACZ,MAAM,OAAO,yBAAyB;AACtC,MAAI,SAAS,UAAU;GACrB,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACrE,SAAM,IAAI,MAAM,wCAAwC,QAAQ,KAAK,SAAS;;AAEhF,MAAI,SAAS,QAAQ;GACnB,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACrE,4BACE,kCAAkC,WAClC,wCAAwC,QAAQ,KAAK,SACtD;;AAEH;;;AAIJ,SAAgB,gBAAgB,QAAgB,OAA4B,cAAuB;AACjG,KAAI,CAAC,OAAO,SAAS,KAAK,CACxB,QAAO,eAAe,WAAW,OAAO,GAAG;CAG7C,IAAI,SAAS;CACb,IAAI,SAAS;AAEb,QAAO,SAAS,OAAO,QAAQ;EAC7B,MAAM,QAAQ,OAAO,QAAQ,MAAM,OAAO;AAC1C,MAAI,UAAU,IAAI;AAChB,aAAU,OAAO,MAAM,OAAO;AAC9B;;AAGF,YAAU,OAAO,MAAM,QAAQ,MAAM;EAErC,MAAM,MAAM,OAAO,QAAQ,MAAM,QAAQ,EAAE;AAC3C,MAAI,QAAQ,IAAI;AACd,aAAU,OAAO,MAAM,MAAM;AAC7B;;EAIF,MAAM,YAAY,gBAAgB,mBADf,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EACW,MAAM,CAAC;AACxE,YAAU;AACV,WAAS,MAAM;;AAGjB,QAAO,eAAe,WAAW,OAAO,GAAG;;AAG7C,SAAgB,sBAAsB,OAAe,OAA4B;AAC/E,QAAO,gBAAgB,SAAS,IAAI,OAAO,MAAM"}
|