@weapp-vite/web 1.3.15 → 1.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- 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 +85 -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 +13 -0
- package/dist/runtime/component/constants.mjs.map +1 -0
- package/dist/runtime/component/dom.mjs +32 -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 +49 -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 +76 -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 +132 -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 +20 -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 +110 -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 +66 -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 +83 -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,208 @@
|
|
|
1
|
+
import { supportsLit } from "./constants.mjs";
|
|
2
|
+
import { createRenderContext } from "../renderContext.mjs";
|
|
3
|
+
import { createScopedSelectorQuery, resolveRenderRoot, selectRuntimeComponent, selectRuntimeComponents } from "./dom.mjs";
|
|
4
|
+
import { bindRuntimeEvents } from "./events.mjs";
|
|
5
|
+
import { cloneValue, coerceValue, toCamelCase } from "./utils.mjs";
|
|
6
|
+
import { html } from "lit";
|
|
7
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
8
|
+
|
|
9
|
+
//#region src/runtime/component/element.ts
|
|
10
|
+
function createComponentElementClass({ BaseElement, runtimeState, instances }) {
|
|
11
|
+
class WeappWebComponent extends BaseElement {
|
|
12
|
+
static observedAttributes = runtimeState.observedAttributes;
|
|
13
|
+
#state;
|
|
14
|
+
#properties;
|
|
15
|
+
#methods;
|
|
16
|
+
#isMounted = false;
|
|
17
|
+
#renderContext = createRenderContext(this, {});
|
|
18
|
+
#usesLegacyTemplate = false;
|
|
19
|
+
#readyFired = false;
|
|
20
|
+
#observerInitDone = false;
|
|
21
|
+
#observedKeys = /* @__PURE__ */ new Set();
|
|
22
|
+
data;
|
|
23
|
+
properties;
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
const dataOption = typeof runtimeState.componentRef.data === "function" ? runtimeState.componentRef.data() : runtimeState.componentRef.data ?? {};
|
|
27
|
+
this.#properties = { ...runtimeState.defaultPropertyValues };
|
|
28
|
+
this.#state = {
|
|
29
|
+
...cloneValue(this.#properties),
|
|
30
|
+
...cloneValue(dataOption)
|
|
31
|
+
};
|
|
32
|
+
this.#methods = {};
|
|
33
|
+
this.#syncMethods(runtimeState.componentRef.methods ?? {});
|
|
34
|
+
Object.defineProperties(this, {
|
|
35
|
+
data: {
|
|
36
|
+
configurable: true,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: () => this.#state
|
|
39
|
+
},
|
|
40
|
+
properties: {
|
|
41
|
+
configurable: true,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: () => this.#properties
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
for (const [propName] of runtimeState.propertyEntries) Object.defineProperty(this, propName, {
|
|
47
|
+
configurable: true,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: () => this.#state[propName],
|
|
50
|
+
set: (value) => this.#setProperty(propName, value)
|
|
51
|
+
});
|
|
52
|
+
if (!supportsLit) {
|
|
53
|
+
const host = this;
|
|
54
|
+
if (!host.shadowRoot && typeof host.attachShadow === "function") host.attachShadow({ mode: "open" });
|
|
55
|
+
this.renderRoot = host.shadowRoot ?? host;
|
|
56
|
+
}
|
|
57
|
+
instances.add(this);
|
|
58
|
+
runtimeState.lifetimes.created?.call(this);
|
|
59
|
+
}
|
|
60
|
+
setData(patch) {
|
|
61
|
+
this.#applyDataPatch(patch);
|
|
62
|
+
}
|
|
63
|
+
triggerEvent(name, detail) {
|
|
64
|
+
this.dispatchEvent(new CustomEvent(name, {
|
|
65
|
+
detail,
|
|
66
|
+
bubbles: true,
|
|
67
|
+
composed: true
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
createSelectorQuery() {
|
|
71
|
+
return createScopedSelectorQuery(this);
|
|
72
|
+
}
|
|
73
|
+
selectComponent(selector) {
|
|
74
|
+
return selectRuntimeComponent(this, selector);
|
|
75
|
+
}
|
|
76
|
+
selectAllComponents(selector) {
|
|
77
|
+
return selectRuntimeComponents(this, selector);
|
|
78
|
+
}
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
const superConnected = BaseElement.prototype.connectedCallback;
|
|
81
|
+
if (supportsLit && typeof superConnected === "function") superConnected.call(this);
|
|
82
|
+
this.#applyAttributes();
|
|
83
|
+
if (runtimeState.observerInitEnabled) this.#runInitialObservers();
|
|
84
|
+
runtimeState.lifetimes.attached?.call(this);
|
|
85
|
+
this.#isMounted = true;
|
|
86
|
+
if (!supportsLit) this.#renderLegacy();
|
|
87
|
+
}
|
|
88
|
+
disconnectedCallback() {
|
|
89
|
+
const superDisconnected = BaseElement.prototype.disconnectedCallback;
|
|
90
|
+
if (supportsLit && typeof superDisconnected === "function") superDisconnected.call(this);
|
|
91
|
+
this.#isMounted = false;
|
|
92
|
+
instances.delete(this);
|
|
93
|
+
runtimeState.lifetimes.detached?.call(this);
|
|
94
|
+
}
|
|
95
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
|
96
|
+
const superAttributeChanged = BaseElement.prototype.attributeChangedCallback;
|
|
97
|
+
if (supportsLit && typeof superAttributeChanged === "function") superAttributeChanged.call(this, attrName, oldValue, newValue);
|
|
98
|
+
const propName = toCamelCase(attrName);
|
|
99
|
+
if (!Object.hasOwn(this.#properties, propName)) return;
|
|
100
|
+
const propOption = runtimeState.componentRef.properties?.[propName];
|
|
101
|
+
this.#setProperty(propName, coerceValue(newValue, propOption?.type));
|
|
102
|
+
}
|
|
103
|
+
firstUpdated() {
|
|
104
|
+
runtimeState.lifetimes.ready?.call(this);
|
|
105
|
+
this.#readyFired = true;
|
|
106
|
+
}
|
|
107
|
+
updated() {
|
|
108
|
+
if (this.#usesLegacyTemplate) bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this);
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
const result = runtimeState.templateRef(this.#state, this.#renderContext);
|
|
112
|
+
const styleMarkup = runtimeState.styleRef ? html`<style>${runtimeState.styleRef}</style>` : null;
|
|
113
|
+
if (typeof result === "string") {
|
|
114
|
+
this.#usesLegacyTemplate = true;
|
|
115
|
+
return html`${styleMarkup}${unsafeHTML(result)}`;
|
|
116
|
+
}
|
|
117
|
+
this.#usesLegacyTemplate = false;
|
|
118
|
+
if (styleMarkup) return html`${styleMarkup}${result}`;
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
requestUpdate(name, oldValue, options) {
|
|
122
|
+
const superRequestUpdate = BaseElement.prototype.requestUpdate;
|
|
123
|
+
if (supportsLit && typeof superRequestUpdate === "function") return superRequestUpdate.call(this, name, oldValue, options);
|
|
124
|
+
if (this.#isMounted) this.#renderLegacy();
|
|
125
|
+
}
|
|
126
|
+
#applyAttributes() {
|
|
127
|
+
if (!this.attributes || typeof this.attributes[Symbol.iterator] !== "function") return;
|
|
128
|
+
for (const attr of this.attributes) this.attributeChangedCallback(attr.name, null, attr.value);
|
|
129
|
+
}
|
|
130
|
+
#applyDataPatch(patch) {
|
|
131
|
+
if (!patch || typeof patch !== "object") return;
|
|
132
|
+
let changed = false;
|
|
133
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
134
|
+
if (this.#state[key] === value) continue;
|
|
135
|
+
const oldValue = this.#state[key];
|
|
136
|
+
this.#state[key] = value;
|
|
137
|
+
if (Object.hasOwn(this.#properties, key)) {
|
|
138
|
+
this.#properties[key] = value;
|
|
139
|
+
const propOption = runtimeState.componentRef.properties?.[key];
|
|
140
|
+
if (propOption?.observer) {
|
|
141
|
+
propOption.observer.call(this, value, oldValue);
|
|
142
|
+
this.#observedKeys.add(key);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
changed = true;
|
|
146
|
+
}
|
|
147
|
+
if (changed) this.requestUpdate();
|
|
148
|
+
}
|
|
149
|
+
#setProperty(name, value) {
|
|
150
|
+
const propOption = runtimeState.componentRef.properties?.[name];
|
|
151
|
+
const coerced = coerceValue(value, propOption?.type);
|
|
152
|
+
const oldValue = this.#properties[name];
|
|
153
|
+
if (oldValue === coerced) return;
|
|
154
|
+
this.#properties[name] = coerced;
|
|
155
|
+
this.#state[name] = coerced;
|
|
156
|
+
if (this.#isMounted) this.requestUpdate();
|
|
157
|
+
if (propOption?.observer) {
|
|
158
|
+
propOption.observer.call(this, coerced, oldValue);
|
|
159
|
+
this.#observedKeys.add(name);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
#runInitialObservers() {
|
|
163
|
+
if (this.#observerInitDone) return;
|
|
164
|
+
this.#observerInitDone = true;
|
|
165
|
+
for (const [propName, propOption] of runtimeState.propertyEntries) {
|
|
166
|
+
if (!propOption.observer || this.#observedKeys.has(propName)) continue;
|
|
167
|
+
const value = this.#state[propName];
|
|
168
|
+
propOption.observer.call(this, value, void 0);
|
|
169
|
+
this.#observedKeys.add(propName);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
#syncMethods(nextMethods) {
|
|
173
|
+
const resolved = nextMethods ?? {};
|
|
174
|
+
const bound = {};
|
|
175
|
+
for (const [name, fn] of Object.entries(resolved)) if (typeof fn === "function") bound[name] = fn.bind(this);
|
|
176
|
+
for (const key of Object.keys(this.#methods)) if (!(key in bound)) delete this.#methods[key];
|
|
177
|
+
for (const [key, fn] of Object.entries(bound)) this.#methods[key] = fn;
|
|
178
|
+
this.#renderContext = createRenderContext(this, this.#methods);
|
|
179
|
+
}
|
|
180
|
+
__weappSync(nextMethods) {
|
|
181
|
+
this.#syncMethods(nextMethods);
|
|
182
|
+
this.requestUpdate();
|
|
183
|
+
}
|
|
184
|
+
__weappInvokePageLifetime(type) {
|
|
185
|
+
const hook = runtimeState.pageLifetimes[type];
|
|
186
|
+
if (typeof hook === "function") hook.call(this);
|
|
187
|
+
}
|
|
188
|
+
#renderLegacy() {
|
|
189
|
+
const result = runtimeState.templateRef(this.#state, this.#renderContext);
|
|
190
|
+
const root = resolveRenderRoot(this);
|
|
191
|
+
const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : "";
|
|
192
|
+
if (typeof result === "string") {
|
|
193
|
+
root.innerHTML = `${styleMarkup}${result}`;
|
|
194
|
+
bindRuntimeEvents(root, this.#methods, this);
|
|
195
|
+
} else if (result == null) root.innerHTML = styleMarkup;
|
|
196
|
+
else root.innerHTML = `${styleMarkup}${String(result)}`;
|
|
197
|
+
if (!this.#readyFired) {
|
|
198
|
+
runtimeState.lifetimes.ready?.call(this);
|
|
199
|
+
this.#readyFired = true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return WeappWebComponent;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
export { createComponentElementClass };
|
|
208
|
+
//# sourceMappingURL=element.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.mjs","names":["#properties","#state","#methods","#syncMethods","#setProperty","#applyDataPatch","#applyAttributes","#runInitialObservers","#isMounted","#renderLegacy","#readyFired","#usesLegacyTemplate","#renderContext","#observedKeys","#observerInitDone"],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n DataRecord,\n PageLifeTimeHooks,\n} from './types'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createRenderContext } from '../renderContext'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { cloneValue, coerceValue, toCamelCase } from './utils'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n class WeappWebComponent extends BaseElement implements WeappComponentInstance {\n static observedAttributes = runtimeState.observedAttributes\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any>\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = typeof runtimeState.componentRef.data === 'function'\n ? (runtimeState.componentRef.data as () => DataRecord)()\n : (runtimeState.componentRef.data ?? {})\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n this.#methods = {}\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this)\n }\n\n setData(patch: DataRecord) {\n this.#applyDataPatch(patch)\n }\n\n triggerEvent(name: string, detail?: any) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n connectedCallback() {\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this)\n this.#isMounted = true\n if (!supportsLit) {\n this.#renderLegacy()\n }\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!Object.hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n\n updated() {\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const styleMarkup = runtimeState.styleRef\n ? html`<style>${runtimeState.styleRef}</style>`\n : null\n if (typeof result === 'string') {\n this.#usesLegacyTemplate = true\n return html`${styleMarkup}${unsafeHTML(result)}`\n }\n this.#usesLegacyTemplate = false\n if (styleMarkup) {\n return html`${styleMarkup}${result as any}`\n }\n return result\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return\n }\n let changed = false\n for (const [key, value] of Object.entries(patch)) {\n if (this.#state[key] === value) {\n continue\n }\n const oldValue = this.#state[key]\n this.#state[key] = value\n if (Object.hasOwn(this.#properties, key)) {\n this.#properties[key] = value\n const propOption = runtimeState.componentRef.properties?.[key]\n if (propOption?.observer) {\n propOption.observer.call(this, value, oldValue)\n this.#observedKeys.add(key)\n }\n }\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n }\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n if (propOption?.observer) {\n propOption.observer.call(this, coerced, oldValue)\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this)\n }\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n this.#methods[key] = fn\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : ''\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,4BAA4B,EAC1C,aACA,cACA,aACiE;CACjE,MAAM,0BAA0B,YAA8C;EAC5E,OAAO,qBAAqB,aAAa;EAEzC;EACA;EACA;EACA,aAAa;EACb,i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AEnD,UAAU,KACjB,MAAK,YAAY;OAGjB,MAAK,YAAY,GAAG,cAAc,OAAO,OAAO;AAElD,OAAI,CAAC,MAAKQ,YAAa;AACrB,iBAAa,UAAU,OAAO,KAAK,KAAK;AACxC,UAAKA,aAAc;;;;AAKzB,QAAO"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES } from "./constants.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/component/events.ts
|
|
4
|
+
function parseEventFlags(value) {
|
|
5
|
+
if (!value) return {
|
|
6
|
+
catch: false,
|
|
7
|
+
capture: false
|
|
8
|
+
};
|
|
9
|
+
const tokens = value.split(",").map((token) => token.trim()).filter(Boolean);
|
|
10
|
+
const tokenSet = new Set(tokens);
|
|
11
|
+
return {
|
|
12
|
+
catch: tokenSet.has("catch"),
|
|
13
|
+
capture: tokenSet.has("capture")
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function bindRuntimeEvents(root, methods, instance) {
|
|
17
|
+
if (typeof document === "undefined") return;
|
|
18
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
|
|
19
|
+
while (walker.nextNode()) {
|
|
20
|
+
const element = walker.currentNode;
|
|
21
|
+
for (const attribute of element.getAttributeNames()) {
|
|
22
|
+
const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find((prefix) => attribute.startsWith(prefix));
|
|
23
|
+
if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some((prefix) => attribute.startsWith(prefix))) continue;
|
|
24
|
+
const handlerName = element.getAttribute(attribute);
|
|
25
|
+
if (!handlerName) continue;
|
|
26
|
+
const handler = methods[handlerName];
|
|
27
|
+
if (!handler) continue;
|
|
28
|
+
const eventName = attribute.slice(matchedPrefix.length);
|
|
29
|
+
const flags = parseEventFlags(EVENT_FLAG_ATTRIBUTE_PREFIXES.map((prefix) => element.getAttribute(`${prefix}${eventName}`)).find((value) => value !== null) ?? null);
|
|
30
|
+
element.addEventListener(eventName, (nativeEvent) => {
|
|
31
|
+
if (flags.catch) nativeEvent.stopPropagation();
|
|
32
|
+
const dataset = { ...element.dataset };
|
|
33
|
+
const syntheticEvent = {
|
|
34
|
+
type: eventName,
|
|
35
|
+
timeStamp: nativeEvent.timeStamp,
|
|
36
|
+
detail: nativeEvent.detail ?? nativeEvent.data ?? void 0,
|
|
37
|
+
target: { dataset },
|
|
38
|
+
currentTarget: { dataset },
|
|
39
|
+
originalEvent: nativeEvent
|
|
40
|
+
};
|
|
41
|
+
handler.call(instance, syntheticEvent);
|
|
42
|
+
}, flags.capture);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { bindRuntimeEvents };
|
|
49
|
+
//# sourceMappingURL=events.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport {\n EVENT_ATTRIBUTE_PREFIXES,\n EVENT_FLAG_ATTRIBUTE_PREFIXES,\n} from './constants'\n\nfunction parseEventFlags(value: string | null) {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n for (const attribute of element.getAttributeNames()) {\n const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find(prefix => attribute.startsWith(prefix))\n if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some(prefix => attribute.startsWith(prefix))) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const eventName = attribute.slice(matchedPrefix.length)\n const flagAttributeValue = EVENT_FLAG_ATTRIBUTE_PREFIXES\n .map(prefix => element.getAttribute(`${prefix}${eventName}`))\n .find(value => value !== null) ?? null\n const flags = parseEventFlags(flagAttributeValue)\n element.addEventListener(eventName, (nativeEvent) => {\n if (flags.catch) {\n nativeEvent.stopPropagation()\n }\n const dataset = { ...element.dataset }\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }, flags.capture)\n }\n }\n}\n"],"mappings":";;;AAMA,SAAS,gBAAgB,OAAsB;AAC7C,KAAI,CAAC,MACH,QAAO;EAAE,OAAO;EAAO,SAAS;EAAO;CAEzC,MAAM,SAAS,MAAM,MAAM,IAAI,CAAC,KAAI,UAAS,MAAM,MAAM,CAAC,CAAC,OAAO,QAAQ;CAC1E,MAAM,WAAW,IAAI,IAAI,OAAO;AAChC,QAAO;EACL,OAAO,SAAS,IAAI,QAAQ;EAC5B,SAAS,SAAS,IAAI,UAAU;EACjC;;AAGH,SAAgB,kBACd,MACA,SACA,UACA;AACA,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,SAAS,SAAS,iBAAiB,MAAM,WAAW,aAAa;AACvE,QAAO,OAAO,UAAU,EAAE;EACxB,MAAM,UAAU,OAAO;AACvB,OAAK,MAAM,aAAa,QAAQ,mBAAmB,EAAE;GACnD,MAAM,gBAAgB,yBAAyB,MAAK,WAAU,UAAU,WAAW,OAAO,CAAC;AAC3F,OAAI,CAAC,iBAAiB,8BAA8B,MAAK,WAAU,UAAU,WAAW,OAAO,CAAC,CAC9F;GAEF,MAAM,cAAc,QAAQ,aAAa,UAAU;AACnD,OAAI,CAAC,YACH;GAEF,MAAM,UAAU,QAAQ;AACxB,OAAI,CAAC,QACH;GAEF,MAAM,YAAY,UAAU,MAAM,cAAc,OAAO;GAIvD,MAAM,QAAQ,gBAHa,8BACxB,KAAI,WAAU,QAAQ,aAAa,GAAG,SAAS,YAAY,CAAC,CAC5D,MAAK,UAAS,UAAU,KAAK,IAAI,KACa;AACjD,WAAQ,iBAAiB,YAAY,gBAAgB;AACnD,QAAI,MAAM,MACR,aAAY,iBAAiB;IAE/B,MAAM,UAAU,EAAE,GAAG,QAAQ,SAAS;IACtC,MAAM,iBAAiB;KACrB,MAAM;KACN,WAAW,YAAY;KACvB,QAAS,YAA4B,UAAW,YAA2B,QAAQ;KACnF,QAAQ,EACN,SACD;KACD,eAAe,EACb,SACD;KACD,eAAe;KAChB;AACD,YAAQ,KAAK,UAAU,eAAe;MACrC,MAAM,QAAQ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DefineComponentOptions, PropertyOption } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/component/index.d.ts
|
|
4
|
+
declare function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { defineComponent };
|
|
7
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -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 };
|