@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,198 @@
|
|
|
1
|
+
import { collectFormValues, getHoverClass, isDisabled, isInternalNode, normalizeType, parseNumber, toBoolean } from "./helpers.mjs";
|
|
2
|
+
import { ensureButtonStyle } from "./style.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/button/index.ts
|
|
5
|
+
const DEFAULT_FORM_CONFIG = { preventDefault: true };
|
|
6
|
+
const NAV_BUTTON_TAG = "weapp-button";
|
|
7
|
+
const BaseElement = globalThis.HTMLElement ?? class {};
|
|
8
|
+
let formConfig = { ...DEFAULT_FORM_CONFIG };
|
|
9
|
+
var WeappButton = class extends BaseElement {
|
|
10
|
+
static observedAttributes = [
|
|
11
|
+
"type",
|
|
12
|
+
"plain",
|
|
13
|
+
"size",
|
|
14
|
+
"loading",
|
|
15
|
+
"disabled",
|
|
16
|
+
"hover-class",
|
|
17
|
+
"hover-start-time",
|
|
18
|
+
"hover-stay-time",
|
|
19
|
+
"form-type",
|
|
20
|
+
"open-type"
|
|
21
|
+
];
|
|
22
|
+
#button;
|
|
23
|
+
#content;
|
|
24
|
+
#text;
|
|
25
|
+
#loading;
|
|
26
|
+
#hoverTimer;
|
|
27
|
+
#hoverRemoveTimer;
|
|
28
|
+
#lastTouchTime = 0;
|
|
29
|
+
#observer;
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
const root = this.getRootNode();
|
|
32
|
+
if (root instanceof ShadowRoot) ensureButtonStyle(root);
|
|
33
|
+
else ensureButtonStyle();
|
|
34
|
+
this.#ensureStructure();
|
|
35
|
+
this.#applyState();
|
|
36
|
+
this.#bindEvents();
|
|
37
|
+
}
|
|
38
|
+
disconnectedCallback() {
|
|
39
|
+
this.#clearHoverTimers();
|
|
40
|
+
this.#observer?.disconnect();
|
|
41
|
+
this.#observer = void 0;
|
|
42
|
+
}
|
|
43
|
+
attributeChangedCallback() {
|
|
44
|
+
this.#applyState();
|
|
45
|
+
}
|
|
46
|
+
#ensureStructure() {
|
|
47
|
+
if (this.#button) return;
|
|
48
|
+
const button = document.createElement("button");
|
|
49
|
+
button.type = "button";
|
|
50
|
+
button.className = "weapp-btn";
|
|
51
|
+
button.dataset.weappInternal = "true";
|
|
52
|
+
const content = document.createElement("span");
|
|
53
|
+
content.className = "weapp-btn__content";
|
|
54
|
+
content.dataset.weappInternal = "true";
|
|
55
|
+
const loading = document.createElement("span");
|
|
56
|
+
loading.className = "weapp-btn__loading";
|
|
57
|
+
loading.dataset.weappInternal = "true";
|
|
58
|
+
loading.setAttribute("hidden", "");
|
|
59
|
+
const text = document.createElement("span");
|
|
60
|
+
text.className = "weapp-btn__text";
|
|
61
|
+
text.dataset.weappInternal = "true";
|
|
62
|
+
content.append(loading, text);
|
|
63
|
+
button.append(content);
|
|
64
|
+
const existing = [...this.childNodes].filter((node) => !isInternalNode(node));
|
|
65
|
+
for (const node of existing) text.appendChild(node);
|
|
66
|
+
this.appendChild(button);
|
|
67
|
+
this.#button = button;
|
|
68
|
+
this.#content = content;
|
|
69
|
+
this.#text = text;
|
|
70
|
+
this.#loading = loading;
|
|
71
|
+
if (typeof MutationObserver !== "undefined") {
|
|
72
|
+
this.#observer = new MutationObserver((records) => {
|
|
73
|
+
if (!this.#text) return;
|
|
74
|
+
for (const record of records) for (const node of [...record.addedNodes]) {
|
|
75
|
+
if (isInternalNode(node)) continue;
|
|
76
|
+
if (node === this.#button) continue;
|
|
77
|
+
this.#text.appendChild(node);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.#observer.observe(this, { childList: true });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
#applyState() {
|
|
84
|
+
if (!this.#button || !this.#loading) return;
|
|
85
|
+
const type = normalizeType(this.getAttribute("type"));
|
|
86
|
+
const plain = toBoolean(this.getAttribute("plain"));
|
|
87
|
+
const size = (this.getAttribute("size") ?? "default").toLowerCase();
|
|
88
|
+
const loading = toBoolean(this.getAttribute("loading"));
|
|
89
|
+
const disabled = toBoolean(this.getAttribute("disabled"));
|
|
90
|
+
const openType = this.getAttribute("open-type");
|
|
91
|
+
this.classList.toggle("weapp-btn--primary", type === "primary");
|
|
92
|
+
this.classList.toggle("weapp-btn--warn", type === "warn");
|
|
93
|
+
this.classList.toggle("weapp-btn--default", type === "default");
|
|
94
|
+
this.classList.toggle("weapp-btn--plain", plain);
|
|
95
|
+
this.classList.toggle("weapp-btn--mini", size === "mini");
|
|
96
|
+
this.classList.toggle("weapp-btn--loading", loading);
|
|
97
|
+
this.classList.toggle("weapp-btn--disabled", disabled);
|
|
98
|
+
if (openType) {
|
|
99
|
+
const openTypeClass = `weapp-btn--open-type-${openType}`;
|
|
100
|
+
for (const className of [...this.classList]) if (className.startsWith("weapp-btn--open-type-") && className !== openTypeClass) this.classList.remove(className);
|
|
101
|
+
this.classList.add(openTypeClass);
|
|
102
|
+
} else for (const className of [...this.classList]) if (className.startsWith("weapp-btn--open-type-")) this.classList.remove(className);
|
|
103
|
+
const locked = disabled || loading;
|
|
104
|
+
this.#button.disabled = locked;
|
|
105
|
+
if (locked) this.#button.setAttribute("aria-disabled", "true");
|
|
106
|
+
else this.#button.removeAttribute("aria-disabled");
|
|
107
|
+
this.#loading.toggleAttribute("hidden", !loading);
|
|
108
|
+
}
|
|
109
|
+
#bindEvents() {
|
|
110
|
+
if (this.__weappButtonBound) return;
|
|
111
|
+
this.__weappButtonBound = true;
|
|
112
|
+
this.addEventListener("click", this.#handleClickCapture, true);
|
|
113
|
+
this.addEventListener("click", this.#handleClick);
|
|
114
|
+
this.addEventListener("touchstart", this.#handlePressStart, { passive: true });
|
|
115
|
+
this.addEventListener("mousedown", this.#handlePressStart);
|
|
116
|
+
this.addEventListener("touchend", this.#handlePressEnd);
|
|
117
|
+
this.addEventListener("touchcancel", this.#handlePressEnd);
|
|
118
|
+
this.addEventListener("mouseup", this.#handlePressEnd);
|
|
119
|
+
this.addEventListener("mouseleave", this.#handlePressEnd);
|
|
120
|
+
}
|
|
121
|
+
#handleClickCapture = (event) => {
|
|
122
|
+
if (isDisabled(this)) {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
event.stopImmediatePropagation();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
#handleClick = (event) => {
|
|
128
|
+
if (isDisabled(this)) return;
|
|
129
|
+
const formType = this.getAttribute("form-type");
|
|
130
|
+
if (!formType) return;
|
|
131
|
+
const form = this.closest("form");
|
|
132
|
+
if (!form) return;
|
|
133
|
+
if (formType === "submit") {
|
|
134
|
+
const detail = { value: collectFormValues(form) };
|
|
135
|
+
const submitEvent = new CustomEvent("submit", {
|
|
136
|
+
detail,
|
|
137
|
+
bubbles: true,
|
|
138
|
+
cancelable: true
|
|
139
|
+
});
|
|
140
|
+
if (form.dispatchEvent(submitEvent) && !formConfig.preventDefault) form.submit();
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (formType === "reset") {
|
|
145
|
+
form.reset();
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
#handlePressStart = (event) => {
|
|
150
|
+
if (isDisabled(this)) return;
|
|
151
|
+
const hoverClass = getHoverClass(this);
|
|
152
|
+
if (!hoverClass) return;
|
|
153
|
+
if (event.type === "touchstart") this.#lastTouchTime = Date.now();
|
|
154
|
+
if (event.type === "mousedown" && Date.now() - this.#lastTouchTime < 400) return;
|
|
155
|
+
const startTime = parseNumber(this.getAttribute("hover-start-time"), 20);
|
|
156
|
+
this.#clearHoverTimers();
|
|
157
|
+
this.#hoverTimer = globalThis.setTimeout(() => {
|
|
158
|
+
this.classList.add(hoverClass);
|
|
159
|
+
}, startTime);
|
|
160
|
+
};
|
|
161
|
+
#handlePressEnd = (event) => {
|
|
162
|
+
const hoverClass = getHoverClass(this);
|
|
163
|
+
if (!hoverClass) return;
|
|
164
|
+
if (event.type === "mouseup" && Date.now() - this.#lastTouchTime < 400) return;
|
|
165
|
+
const stayTime = parseNumber(this.getAttribute("hover-stay-time"), 70);
|
|
166
|
+
if (this.#hoverTimer) {
|
|
167
|
+
clearTimeout(this.#hoverTimer);
|
|
168
|
+
this.#hoverTimer = void 0;
|
|
169
|
+
}
|
|
170
|
+
if (this.classList.contains(hoverClass)) this.#hoverRemoveTimer = globalThis.setTimeout(() => {
|
|
171
|
+
this.classList.remove(hoverClass);
|
|
172
|
+
}, stayTime);
|
|
173
|
+
};
|
|
174
|
+
#clearHoverTimers() {
|
|
175
|
+
if (this.#hoverTimer) {
|
|
176
|
+
clearTimeout(this.#hoverTimer);
|
|
177
|
+
this.#hoverTimer = void 0;
|
|
178
|
+
}
|
|
179
|
+
if (this.#hoverRemoveTimer) {
|
|
180
|
+
clearTimeout(this.#hoverRemoveTimer);
|
|
181
|
+
this.#hoverRemoveTimer = void 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
function ensureButtonDefined() {
|
|
186
|
+
if (typeof customElements === "undefined") return;
|
|
187
|
+
if (!customElements.get(NAV_BUTTON_TAG)) customElements.define(NAV_BUTTON_TAG, WeappButton);
|
|
188
|
+
}
|
|
189
|
+
function setButtonFormConfig(next) {
|
|
190
|
+
formConfig = {
|
|
191
|
+
...formConfig,
|
|
192
|
+
...next
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
export { ensureButtonDefined, setButtonFormConfig };
|
|
198
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#ensureStructure","#applyState","#bindEvents","#clearHoverTimers","#observer","#button","#content","#text","#loading","#handleClickCapture","#handleClick","#handlePressStart","#handlePressEnd","#lastTouchTime","#hoverTimer","#hoverRemoveTimer"],"sources":["../../../src/runtime/button/index.ts"],"sourcesContent":["import {\n collectFormValues,\n DEFAULT_HOVER_START,\n DEFAULT_HOVER_STAY,\n getHoverClass,\n isDisabled,\n isInternalNode,\n normalizeType,\n parseNumber,\n toBoolean,\n} from './helpers'\nimport { ensureButtonStyle } from './style'\n\ninterface ButtonFormConfig {\n preventDefault?: boolean\n}\n\nconst DEFAULT_FORM_CONFIG: Required<ButtonFormConfig> = {\n preventDefault: true,\n}\n\nconst NAV_BUTTON_TAG = 'weapp-button'\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nlet formConfig: Required<ButtonFormConfig> = { ...DEFAULT_FORM_CONFIG }\n\nclass WeappButton extends BaseElement {\n static observedAttributes = [\n 'type',\n 'plain',\n 'size',\n 'loading',\n 'disabled',\n 'hover-class',\n 'hover-start-time',\n 'hover-stay-time',\n 'form-type',\n 'open-type',\n ]\n\n #button?: HTMLButtonElement\n #content?: HTMLSpanElement\n #text?: HTMLSpanElement\n #loading?: HTMLSpanElement\n #hoverTimer?: ReturnType<typeof globalThis.setTimeout>\n #hoverRemoveTimer?: ReturnType<typeof globalThis.setTimeout>\n #lastTouchTime = 0\n #observer?: MutationObserver\n\n connectedCallback() {\n const root = this.getRootNode()\n if (root instanceof ShadowRoot) {\n ensureButtonStyle(root)\n }\n else {\n ensureButtonStyle()\n }\n this.#ensureStructure()\n this.#applyState()\n this.#bindEvents()\n }\n\n disconnectedCallback() {\n this.#clearHoverTimers()\n this.#observer?.disconnect()\n this.#observer = undefined\n }\n\n attributeChangedCallback() {\n this.#applyState()\n }\n\n #ensureStructure() {\n if (this.#button) {\n return\n }\n const button = document.createElement('button')\n button.type = 'button'\n button.className = 'weapp-btn'\n button.dataset.weappInternal = 'true'\n const content = document.createElement('span')\n content.className = 'weapp-btn__content'\n content.dataset.weappInternal = 'true'\n const loading = document.createElement('span')\n loading.className = 'weapp-btn__loading'\n loading.dataset.weappInternal = 'true'\n loading.setAttribute('hidden', '')\n const text = document.createElement('span')\n text.className = 'weapp-btn__text'\n text.dataset.weappInternal = 'true'\n content.append(loading, text)\n button.append(content)\n\n const existing = [...this.childNodes].filter(node => !isInternalNode(node))\n for (const node of existing) {\n text.appendChild(node)\n }\n this.appendChild(button)\n\n this.#button = button\n this.#content = content\n this.#text = text\n this.#loading = loading\n\n if (typeof MutationObserver !== 'undefined') {\n this.#observer = new MutationObserver((records) => {\n if (!this.#text) {\n return\n }\n for (const record of records) {\n for (const node of [...record.addedNodes]) {\n if (isInternalNode(node)) {\n continue\n }\n if (node === this.#button) {\n continue\n }\n this.#text.appendChild(node)\n }\n }\n })\n this.#observer.observe(this, { childList: true })\n }\n }\n\n #applyState() {\n if (!this.#button || !this.#loading) {\n return\n }\n const type = normalizeType(this.getAttribute('type'))\n const plain = toBoolean(this.getAttribute('plain'))\n const size = (this.getAttribute('size') ?? 'default').toLowerCase()\n const loading = toBoolean(this.getAttribute('loading'))\n const disabled = toBoolean(this.getAttribute('disabled'))\n const openType = this.getAttribute('open-type')\n\n this.classList.toggle('weapp-btn--primary', type === 'primary')\n this.classList.toggle('weapp-btn--warn', type === 'warn')\n this.classList.toggle('weapp-btn--default', type === 'default')\n this.classList.toggle('weapp-btn--plain', plain)\n this.classList.toggle('weapp-btn--mini', size === 'mini')\n this.classList.toggle('weapp-btn--loading', loading)\n this.classList.toggle('weapp-btn--disabled', disabled)\n\n if (openType) {\n const openTypeClass = `weapp-btn--open-type-${openType}`\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-') && className !== openTypeClass) {\n this.classList.remove(className)\n }\n }\n this.classList.add(openTypeClass)\n }\n else {\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-')) {\n this.classList.remove(className)\n }\n }\n }\n\n const locked = disabled || loading\n this.#button.disabled = locked\n if (locked) {\n this.#button.setAttribute('aria-disabled', 'true')\n }\n else {\n this.#button.removeAttribute('aria-disabled')\n }\n this.#loading.toggleAttribute('hidden', !loading)\n }\n\n #bindEvents() {\n if ((this as any).__weappButtonBound) {\n return\n }\n ;(this as any).__weappButtonBound = true\n this.addEventListener('click', this.#handleClickCapture, true)\n this.addEventListener('click', this.#handleClick)\n this.addEventListener('touchstart', this.#handlePressStart, { passive: true })\n this.addEventListener('mousedown', this.#handlePressStart)\n this.addEventListener('touchend', this.#handlePressEnd)\n this.addEventListener('touchcancel', this.#handlePressEnd)\n this.addEventListener('mouseup', this.#handlePressEnd)\n this.addEventListener('mouseleave', this.#handlePressEnd)\n }\n\n #handleClickCapture = (event: Event) => {\n if (isDisabled(this)) {\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n }\n\n #handleClick = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const formType = this.getAttribute('form-type')\n if (!formType) {\n return\n }\n const form = this.closest('form') as HTMLFormElement | null\n if (!form) {\n return\n }\n if (formType === 'submit') {\n const detail = { value: collectFormValues(form) }\n const submitEvent = new CustomEvent('submit', {\n detail,\n bubbles: true,\n cancelable: true,\n })\n const shouldSubmit = form.dispatchEvent(submitEvent)\n if (shouldSubmit && !formConfig.preventDefault) {\n form.submit()\n }\n event.preventDefault()\n return\n }\n if (formType === 'reset') {\n form.reset()\n event.preventDefault()\n }\n }\n\n #handlePressStart = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'touchstart') {\n this.#lastTouchTime = Date.now()\n }\n if (event.type === 'mousedown' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const startTime = parseNumber(this.getAttribute('hover-start-time'), DEFAULT_HOVER_START)\n this.#clearHoverTimers()\n this.#hoverTimer = globalThis.setTimeout(() => {\n this.classList.add(hoverClass)\n }, startTime)\n }\n\n #handlePressEnd = (event: Event) => {\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'mouseup' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const stayTime = parseNumber(this.getAttribute('hover-stay-time'), DEFAULT_HOVER_STAY)\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.classList.contains(hoverClass)) {\n this.#hoverRemoveTimer = globalThis.setTimeout(() => {\n this.classList.remove(hoverClass)\n }, stayTime)\n }\n }\n\n #clearHoverTimers() {\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.#hoverRemoveTimer) {\n clearTimeout(this.#hoverRemoveTimer)\n this.#hoverRemoveTimer = undefined\n }\n }\n}\n\nexport function ensureButtonDefined(): void {\n if (typeof customElements === 'undefined') {\n return\n }\n if (!customElements.get(NAV_BUTTON_TAG)) {\n customElements.define(NAV_BUTTON_TAG, WeappButton)\n }\n}\n\nexport function setButtonFormConfig(next: ButtonFormConfig): void {\n formConfig = {\n ...formConfig,\n ...next,\n }\n}\n\nexport type { ButtonFormConfig }\n"],"mappings":";;;;AAiBA,MAAM,sBAAkD,EACtD,gBAAgB,MACjB;AAED,MAAM,iBAAiB;AACvB,MAAM,cAAe,WAAW,eAAe,MAAM;AAErD,IAAI,aAAyC,EAAE,GAAG,qBAAqB;AAEvE,IAAM,cAAN,cAA0B,YAAY;CACpC,OAAO,qBAAqB;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CAED;CACA;CACA;CACA;CACA;CACA;CACA,iBAAiB;CACjB;CAEA,oBAAoB;EAClB,MAAM,OAAO,KAAK,aAAa;AAC/B,MAAI,gBAAgB,WAClB,mBAAkB,KAAK;MAGvB,oBAAmB;AAErB,QAAKA,iBAAkB;AACvB,QAAKC,YAAa;AAClB,QAAKC,YAAa;;CAGpB,uBAAuB;AACrB,QAAKC,kBAAmB;AACxB,QAAKC,UAAW,YAAY;AAC5B,QAAKA,WAAY;;CAGnB,2BAA2B;AACzB,QAAKH,YAAa;;CAGpB,mBAAmB;AACjB,MAAI,MAAKI,OACP;EAEF,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,OAAO;AACd,SAAO,YAAY;AACnB,SAAO,QAAQ,gBAAgB;EAC/B,MAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,UAAQ,YAAY;AACpB,UAAQ,QAAQ,gBAAgB;EAChC,MAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,UAAQ,YAAY;AACpB,UAAQ,QAAQ,gBAAgB;AAChC,UAAQ,aAAa,UAAU,GAAG;EAClC,MAAM,OAAO,SAAS,cAAc,OAAO;AAC3C,OAAK,YAAY;AACjB,OAAK,QAAQ,gBAAgB;AAC7B,UAAQ,OAAO,SAAS,KAAK;AAC7B,SAAO,OAAO,QAAQ;EAEtB,MAAM,WAAW,CAAC,GAAG,KAAK,WAAW,CAAC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YAC5B;AAEF,KAAI,CAAC,eAAe,IAAI,eAAe,CACrC,gBAAe,OAAO,gBAAgB,YAAY;;AAItD,SAAgB,oBAAoB,MAA8B;AAChE,cAAa;EACX,GAAG;EACH,GAAG;EACJ"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { injectStyle } from "../style.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/button/style.ts
|
|
4
|
+
const BUTTON_STYLE_ID = "weapp-web-button-style";
|
|
5
|
+
const styleTargets = /* @__PURE__ */ new WeakSet();
|
|
6
|
+
let sharedSheet;
|
|
7
|
+
const BUTTON_STYLE = `
|
|
8
|
+
weapp-button {
|
|
9
|
+
display: block;
|
|
10
|
+
width: 100%;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
weapp-button.weapp-btn--mini {
|
|
15
|
+
display: inline-block;
|
|
16
|
+
width: auto;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
weapp-button .weapp-btn {
|
|
20
|
+
appearance: none;
|
|
21
|
+
-webkit-appearance: none;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
width: 100%;
|
|
24
|
+
border-radius: 5px;
|
|
25
|
+
border: 1px solid #d9d9d9;
|
|
26
|
+
padding: 0 16px;
|
|
27
|
+
height: 44px;
|
|
28
|
+
line-height: 44px;
|
|
29
|
+
font-size: 17px;
|
|
30
|
+
font-weight: 400;
|
|
31
|
+
background-color: #f8f8f8;
|
|
32
|
+
color: #000000;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
outline: none;
|
|
35
|
+
user-select: none;
|
|
36
|
+
-webkit-tap-highlight-color: transparent;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
weapp-button.weapp-btn--primary .weapp-btn {
|
|
40
|
+
background-color: #07c160;
|
|
41
|
+
border-color: #07c160;
|
|
42
|
+
color: #ffffff;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
weapp-button.weapp-btn--warn .weapp-btn {
|
|
46
|
+
background-color: #e64340;
|
|
47
|
+
border-color: #e64340;
|
|
48
|
+
color: #ffffff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
weapp-button.weapp-btn--plain .weapp-btn {
|
|
52
|
+
background-color: transparent;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
weapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {
|
|
56
|
+
border-color: #b2b2b2;
|
|
57
|
+
color: #353535;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
weapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {
|
|
61
|
+
border-color: #07c160;
|
|
62
|
+
color: #07c160;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
weapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {
|
|
66
|
+
border-color: #e64340;
|
|
67
|
+
color: #e64340;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
weapp-button.weapp-btn--loading .weapp-btn,
|
|
71
|
+
weapp-button.weapp-btn--disabled .weapp-btn {
|
|
72
|
+
background-color: #f7f7f7;
|
|
73
|
+
border-color: #d9d9d9;
|
|
74
|
+
color: #9b9b9b;
|
|
75
|
+
cursor: not-allowed;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
weapp-button.button-hover .weapp-btn {
|
|
79
|
+
background-color: #ededed;
|
|
80
|
+
border-color: #d2d2d2;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
weapp-button.button-hover.weapp-btn--primary .weapp-btn {
|
|
84
|
+
background-color: #06ad56;
|
|
85
|
+
border-color: #06ad56;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
weapp-button.button-hover.weapp-btn--warn .weapp-btn {
|
|
89
|
+
background-color: #d93c37;
|
|
90
|
+
border-color: #d93c37;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
weapp-button.button-hover.weapp-btn--plain .weapp-btn {
|
|
94
|
+
background-color: rgba(0, 0, 0, 0.06);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
weapp-button.weapp-btn--mini .weapp-btn {
|
|
98
|
+
height: 32px;
|
|
99
|
+
line-height: 32px;
|
|
100
|
+
font-size: 13px;
|
|
101
|
+
padding: 0 12px;
|
|
102
|
+
border-radius: 4px;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
weapp-button .weapp-btn__content {
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
gap: 6px;
|
|
110
|
+
width: 100%;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
weapp-button .weapp-btn__loading {
|
|
114
|
+
width: 14px;
|
|
115
|
+
height: 14px;
|
|
116
|
+
border-radius: 50%;
|
|
117
|
+
border: 2px solid currentColor;
|
|
118
|
+
border-top-color: transparent;
|
|
119
|
+
animation: weapp-btn-spin 0.8s linear infinite;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
weapp-button .weapp-btn__loading[hidden] {
|
|
123
|
+
display: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@keyframes weapp-btn-spin {
|
|
127
|
+
from { transform: rotate(0deg); }
|
|
128
|
+
to { transform: rotate(360deg); }
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
function resolveAdoptedStyleSheets(root) {
|
|
132
|
+
const doc = root.ownerDocument ?? document;
|
|
133
|
+
if (!doc || typeof doc.createElement !== "function") return;
|
|
134
|
+
if (!("adoptedStyleSheets" in doc)) return;
|
|
135
|
+
if (!sharedSheet && "replaceSync" in CSSStyleSheet.prototype) {
|
|
136
|
+
const sheet = new CSSStyleSheet();
|
|
137
|
+
sheet.replaceSync(BUTTON_STYLE);
|
|
138
|
+
sharedSheet = sheet;
|
|
139
|
+
}
|
|
140
|
+
return sharedSheet;
|
|
141
|
+
}
|
|
142
|
+
function ensureButtonStyle(root) {
|
|
143
|
+
if (typeof document === "undefined") return;
|
|
144
|
+
if (root && styleTargets.has(root)) return;
|
|
145
|
+
if (!root) {
|
|
146
|
+
const target = document.head;
|
|
147
|
+
if (!target || styleTargets.has(target)) return;
|
|
148
|
+
injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID);
|
|
149
|
+
styleTargets.add(target);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const sheet = resolveAdoptedStyleSheets(root);
|
|
153
|
+
if (sheet) {
|
|
154
|
+
const existing = root.adoptedStyleSheets ?? [];
|
|
155
|
+
if (!existing.includes(sheet)) root.adoptedStyleSheets = [...existing, sheet];
|
|
156
|
+
styleTargets.add(root);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const style = document.createElement("style");
|
|
160
|
+
style.id = BUTTON_STYLE_ID;
|
|
161
|
+
style.textContent = BUTTON_STYLE;
|
|
162
|
+
root.appendChild(style);
|
|
163
|
+
styleTargets.add(root);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
export { ensureButtonStyle };
|
|
168
|
+
//# sourceMappingURL=style.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/button/style.ts"],"sourcesContent":["import { injectStyle } from '../style'\n\nconst BUTTON_STYLE_ID = 'weapp-web-button-style'\nconst styleTargets = new WeakSet<ParentNode>()\nlet sharedSheet: CSSStyleSheet | undefined\n\nconst BUTTON_STYLE = `\nweapp-button {\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\nweapp-button.weapp-btn--mini {\n display: inline-block;\n width: auto;\n}\n\nweapp-button .weapp-btn {\n appearance: none;\n -webkit-appearance: none;\n box-sizing: border-box;\n width: 100%;\n border-radius: 5px;\n border: 1px solid #d9d9d9;\n padding: 0 16px;\n height: 44px;\n line-height: 44px;\n font-size: 17px;\n font-weight: 400;\n background-color: #f8f8f8;\n color: #000000;\n cursor: pointer;\n outline: none;\n user-select: none;\n -webkit-tap-highlight-color: transparent;\n}\n\nweapp-button.weapp-btn--primary .weapp-btn {\n background-color: #07c160;\n border-color: #07c160;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--warn .weapp-btn {\n background-color: #e64340;\n border-color: #e64340;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--plain .weapp-btn {\n background-color: transparent;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {\n border-color: #b2b2b2;\n color: #353535;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {\n border-color: #07c160;\n color: #07c160;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {\n border-color: #e64340;\n color: #e64340;\n}\n\nweapp-button.weapp-btn--loading .weapp-btn,\nweapp-button.weapp-btn--disabled .weapp-btn {\n background-color: #f7f7f7;\n border-color: #d9d9d9;\n color: #9b9b9b;\n cursor: not-allowed;\n}\n\nweapp-button.button-hover .weapp-btn {\n background-color: #ededed;\n border-color: #d2d2d2;\n}\n\nweapp-button.button-hover.weapp-btn--primary .weapp-btn {\n background-color: #06ad56;\n border-color: #06ad56;\n}\n\nweapp-button.button-hover.weapp-btn--warn .weapp-btn {\n background-color: #d93c37;\n border-color: #d93c37;\n}\n\nweapp-button.button-hover.weapp-btn--plain .weapp-btn {\n background-color: rgba(0, 0, 0, 0.06);\n}\n\nweapp-button.weapp-btn--mini .weapp-btn {\n height: 32px;\n line-height: 32px;\n font-size: 13px;\n padding: 0 12px;\n border-radius: 4px;\n}\n\nweapp-button .weapp-btn__content {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n width: 100%;\n}\n\nweapp-button .weapp-btn__loading {\n width: 14px;\n height: 14px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-btn-spin 0.8s linear infinite;\n}\n\nweapp-button .weapp-btn__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-btn-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n\nfunction resolveAdoptedStyleSheets(root: ShadowRoot) {\n const doc = root.ownerDocument ?? document\n if (!doc || typeof doc.createElement !== 'function') {\n return undefined\n }\n if (!('adoptedStyleSheets' in doc)) {\n return undefined\n }\n if (!sharedSheet && 'replaceSync' in CSSStyleSheet.prototype) {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(BUTTON_STYLE)\n sharedSheet = sheet\n }\n return sharedSheet\n}\n\nexport function ensureButtonStyle(root?: ShadowRoot) {\n if (typeof document === 'undefined') {\n return\n }\n if (root && styleTargets.has(root)) {\n return\n }\n if (!root) {\n const target = document.head\n if (!target || styleTargets.has(target)) {\n return\n }\n injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID)\n styleTargets.add(target)\n return\n }\n const sheet = resolveAdoptedStyleSheets(root)\n if (sheet) {\n const existing = root.adoptedStyleSheets ?? []\n if (!existing.includes(sheet)) {\n root.adoptedStyleSheets = [...existing, sheet]\n }\n styleTargets.add(root)\n return\n }\n const style = document.createElement('style')\n style.id = BUTTON_STYLE_ID\n style.textContent = BUTTON_STYLE\n root.appendChild(style)\n styleTargets.add(root)\n}\n"],"mappings":";;;AAEA,MAAM,kBAAkB;AACxB,MAAM,+BAAe,IAAI,SAAqB;AAC9C,IAAI;AAEJ,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HrB,SAAS,0BAA0B,MAAkB;CACnD,MAAM,MAAM,KAAK,iBAAiB;AAClC,KAAI,CAAC,OAAO,OAAO,IAAI,kBAAkB,WACvC;AAEF,KAAI,EAAE,wBAAwB,KAC5B;AAEF,KAAI,CAAC,eAAe,iBAAiB,cAAc,WAAW;EAC5D,MAAM,QAAQ,IAAI,eAAe;AACjC,QAAM,YAAY,aAAa;AAC/B,gBAAc;;AAEhB,QAAO;;AAGT,SAAgB,kBAAkB,MAAmB;AACnD,KAAI,OAAO,aAAa,YACtB;AAEF,KAAI,QAAQ,aAAa,IAAI,KAAK,CAChC;AAEF,KAAI,CAAC,MAAM;EACT,MAAM,SAAS,SAAS;AACxB,MAAI,CAAC,UAAU,aAAa,IAAI,OAAO,CACrC;AAEF,cAAY,cAAc,gBAAgB;AAC1C,eAAa,IAAI,OAAO;AACxB;;CAEF,MAAM,QAAQ,0BAA0B,KAAK;AAC7C,KAAI,OAAO;EACT,MAAM,WAAW,KAAK,sBAAsB,EAAE;AAC9C,MAAI,CAAC,SAAS,SAAS,MAAM,CAC3B,MAAK,qBAAqB,CAAC,GAAG,UAAU,MAAM;AAEhD,eAAa,IAAI,KAAK;AACtB;;CAEF,MAAM,QAAQ,SAAS,cAAc,QAAQ;AAC7C,OAAM,KAAK;AACX,OAAM,cAAc;AACpB,MAAK,YAAY,MAAM;AACvB,cAAa,IAAI,KAAK"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region src/runtime/component/behavior.ts
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function mergeLifetimes(target, source) {
|
|
6
|
+
if (!source) return;
|
|
7
|
+
for (const key of [
|
|
8
|
+
"created",
|
|
9
|
+
"attached",
|
|
10
|
+
"ready",
|
|
11
|
+
"detached"
|
|
12
|
+
]) {
|
|
13
|
+
const next = source[key];
|
|
14
|
+
if (!next) continue;
|
|
15
|
+
const current = target[key];
|
|
16
|
+
target[key] = current ? function merged() {
|
|
17
|
+
current.call(this);
|
|
18
|
+
next.call(this);
|
|
19
|
+
} : next;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function mergePageLifetimes(target, source) {
|
|
23
|
+
if (!source) return;
|
|
24
|
+
for (const key of [
|
|
25
|
+
"show",
|
|
26
|
+
"hide",
|
|
27
|
+
"resize"
|
|
28
|
+
]) {
|
|
29
|
+
const next = source[key];
|
|
30
|
+
if (!next) continue;
|
|
31
|
+
const current = target[key];
|
|
32
|
+
target[key] = current ? function merged() {
|
|
33
|
+
current.call(this);
|
|
34
|
+
next.call(this);
|
|
35
|
+
} : next;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function normalizeBehaviors(component) {
|
|
39
|
+
if (!component) return {
|
|
40
|
+
component: void 0,
|
|
41
|
+
warnings: []
|
|
42
|
+
};
|
|
43
|
+
const warnings = [];
|
|
44
|
+
const visited = /* @__PURE__ */ new Set();
|
|
45
|
+
const merged = {};
|
|
46
|
+
const mergeComponent = (source) => {
|
|
47
|
+
if (source.properties) merged.properties = {
|
|
48
|
+
...merged.properties ?? {},
|
|
49
|
+
...source.properties
|
|
50
|
+
};
|
|
51
|
+
if (source.data) {
|
|
52
|
+
const nextData = typeof source.data === "function" ? source.data() : source.data;
|
|
53
|
+
if (isPlainObject(nextData)) merged.data = {
|
|
54
|
+
...merged.data ?? {},
|
|
55
|
+
...nextData
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (source.methods) merged.methods = {
|
|
59
|
+
...merged.methods ?? {},
|
|
60
|
+
...source.methods
|
|
61
|
+
};
|
|
62
|
+
if (source.lifetimes) {
|
|
63
|
+
merged.lifetimes = merged.lifetimes ?? {};
|
|
64
|
+
mergeLifetimes(merged.lifetimes, source.lifetimes);
|
|
65
|
+
}
|
|
66
|
+
if (source.pageLifetimes) {
|
|
67
|
+
merged.pageLifetimes = merged.pageLifetimes ?? {};
|
|
68
|
+
mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const walk = (source) => {
|
|
72
|
+
if (visited.has(source)) {
|
|
73
|
+
warnings.push("[@weapp-vite/web] behaviors 存在循环引用,已跳过。");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
visited.add(source);
|
|
77
|
+
const behaviors = source.behaviors ?? [];
|
|
78
|
+
if (Array.isArray(behaviors)) for (const behavior of behaviors) {
|
|
79
|
+
if (!behavior || !isPlainObject(behavior)) {
|
|
80
|
+
warnings.push("[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。");
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
walk(behavior);
|
|
84
|
+
mergeComponent(behavior);
|
|
85
|
+
}
|
|
86
|
+
else if (behaviors) warnings.push("[@weapp-vite/web] behaviors 仅支持数组,已忽略。");
|
|
87
|
+
};
|
|
88
|
+
walk(component);
|
|
89
|
+
mergeComponent(component);
|
|
90
|
+
return {
|
|
91
|
+
component: merged,
|
|
92
|
+
warnings
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { normalizeBehaviors };
|
|
98
|
+
//# sourceMappingURL=behavior.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavior.mjs","names":[],"sources":["../../../src/runtime/component/behavior.ts"],"sourcesContent":["import type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n LifeTimeHooks,\n PageLifeTimeHooks,\n} from './types'\n\nfunction isPlainObject(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction mergeLifetimes(target: LifeTimeHooks, source?: LifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof LifeTimeHooks> = ['created', 'attached', 'ready', 'detached']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nfunction mergePageLifetimes(target: PageLifeTimeHooks, source?: PageLifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof PageLifeTimeHooks> = ['show', 'hide', 'resize']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nexport function normalizeBehaviors(component: ComponentOptions | undefined) {\n if (!component) {\n return { component: undefined, warnings: [] as string[] }\n }\n const warnings: string[] = []\n const visited = new Set<ComponentOptions>()\n const merged: ComponentOptions = {}\n\n const mergeComponent = (source: ComponentOptions) => {\n if (source.properties) {\n merged.properties = { ...(merged.properties ?? {}), ...source.properties }\n }\n if (source.data) {\n const nextData = typeof source.data === 'function'\n ? source.data()\n : source.data\n if (isPlainObject(nextData)) {\n merged.data = { ...((merged.data as DataRecord) ?? {}), ...nextData }\n }\n }\n if (source.methods) {\n merged.methods = { ...(merged.methods ?? {}), ...source.methods }\n }\n if (source.lifetimes) {\n merged.lifetimes = merged.lifetimes ?? {}\n mergeLifetimes(merged.lifetimes, source.lifetimes)\n }\n if (source.pageLifetimes) {\n merged.pageLifetimes = merged.pageLifetimes ?? {}\n mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes)\n }\n }\n\n const walk = (source: ComponentOptions) => {\n if (visited.has(source)) {\n warnings.push('[@weapp-vite/web] behaviors 存在循环引用,已跳过。')\n return\n }\n visited.add(source)\n const behaviors = source.behaviors ?? []\n if (Array.isArray(behaviors)) {\n for (const behavior of behaviors) {\n if (!behavior || !isPlainObject(behavior)) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。')\n continue\n }\n walk(behavior as ComponentOptions)\n mergeComponent(behavior as ComponentOptions)\n }\n }\n else if (behaviors) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持数组,已忽略。')\n }\n }\n\n walk(component)\n mergeComponent(component)\n\n return {\n component: merged,\n warnings,\n }\n}\n"],"mappings":";AAQA,SAAS,cAAc,OAA8C;AACnE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG7E,SAAS,eAAe,QAAuB,QAAwB;AACrE,KAAI,CAAC,OACH;AAGF,MAAK,MAAM,OAD8B;EAAC;EAAW;EAAY;EAAS;EAAW,EAC7D;EACtB,M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AAQ,WAA6B;AACzC,MAAI,QAAQ,IAAI,OAAO,EAAE;AACvB,YAAS,KAAK,0CAA0C;AACxD;;AAEF,UAAQ,IAAI,OAAO;EACnB,MAAM,YAAY,OAAO,aAAa,EAAE;AACxC,MAAI,MAAM,QAAQ,UAAU,CAC1B,MAAK,MAAM,YAAY,WAAW;AAChC,OAAI,CAAC,YAAY,CAAC,cAAc,SAAS,EAAE;AACzC,aAAS,KAAK,8CAA8C;AAC5D;;AAEF,QAAK,SAA6B;AAClC,kBAAe,SAA6B;;WAGvC,UACP,UAAS,KAAK,yCAAyC;;AAI3D,MAAK,UAAU;AACf,gBAAe,UAAU;AAEzB,QAAO;EACL,WAAW;EACX;EACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/runtime/component/constants.ts
|
|
2
|
+
const supportsLit = typeof document !== "undefined" && typeof document.createComment === "function" && typeof document.createTreeWalker === "function";
|
|
3
|
+
const FallbackElement = class {};
|
|
4
|
+
const MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX = "data-mp-on-";
|
|
5
|
+
const MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX = "data-mp-on-flags-";
|
|
6
|
+
const WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX = "data-wx-on-";
|
|
7
|
+
const WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = "data-wx-on-flags-";
|
|
8
|
+
const EVENT_ATTRIBUTE_PREFIXES = [MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX];
|
|
9
|
+
const EVENT_FLAG_ATTRIBUTE_PREFIXES = [MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX];
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES, FallbackElement, MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, supportsLit };
|
|
13
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/runtime/component/constants.ts"],"sourcesContent":["export const supportsLit = typeof document !== 'undefined'\n && typeof document.createComment === 'function'\n && typeof document.createTreeWalker === 'function'\n\nexport const FallbackElement = class {}\n\nexport const MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX = 'data-mp-on-'\nexport const MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-mp-on-flags-'\n\nexport const WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX = 'data-wx-on-'\nexport const WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-wx-on-flags-'\n\nexport const LEGACY_EVENT_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX\nexport const LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX\n\nexport const EVENT_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX,\n] as const\n\nexport const EVENT_FLAG_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX,\n] as const\n"],"mappings":";AAAA,MAAa,cAAc,OAAO,aAAa,eAC1C,OAAO,SAAS,kBAAkB,cAClC,OAAO,SAAS,qBAAqB;AAE1C,MAAa,kBAAkB,MAAM;AAErC,MAAa,sCAAsC;AACnD,MAAa,2CAA2C;AAExD,MAAa,uCAAuC;AACpD,MAAa,4CAA4C;AAKzD,MAAa,2BAA2B,CACtC,qCACA,qCACD;AAED,MAAa,gCAAgC,CAC3C,0CACA,0CACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getMiniProgramRuntimeGlobalKeys } from "@weapp-core/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/component/dom.ts
|
|
4
|
+
const MINI_PROGRAM_RUNTIME_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys();
|
|
5
|
+
function resolveQueryRoot(instance) {
|
|
6
|
+
return instance.renderRoot ?? instance.shadowRoot ?? instance;
|
|
7
|
+
}
|
|
8
|
+
function resolveRenderRoot(instance) {
|
|
9
|
+
return instance.renderRoot ?? instance.shadowRoot ?? instance;
|
|
10
|
+
}
|
|
11
|
+
function createScopedSelectorQuery(instance) {
|
|
12
|
+
const runtime = globalThis;
|
|
13
|
+
for (const globalKey of MINI_PROGRAM_RUNTIME_GLOBAL_KEYS) {
|
|
14
|
+
const query = runtime[globalKey]?.createSelectorQuery?.();
|
|
15
|
+
if (query && typeof query.in === "function") return query.in(instance);
|
|
16
|
+
if (query) return query;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function selectRuntimeComponent(instance, selector) {
|
|
20
|
+
const root = resolveQueryRoot(instance);
|
|
21
|
+
if (!selector || typeof root.querySelector !== "function") return null;
|
|
22
|
+
return root.querySelector(selector);
|
|
23
|
+
}
|
|
24
|
+
function selectRuntimeComponents(instance, selector) {
|
|
25
|
+
const root = resolveQueryRoot(instance);
|
|
26
|
+
if (!selector || typeof root.querySelectorAll !== "function") return [];
|
|
27
|
+
return Array.from(root.querySelectorAll(selector));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createScopedSelectorQuery, resolveRenderRoot, selectRuntimeComponent, selectRuntimeComponents };
|
|
32
|
+
//# sourceMappingURL=dom.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/component/dom.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { getMiniProgramRuntimeGlobalKeys } from '@weapp-core/shared'\n\ntype QueryRoot = ParentNode & {\n querySelector?: ParentNode['querySelector']\n querySelectorAll?: ParentNode['querySelectorAll']\n}\n\nconst MINI_PROGRAM_RUNTIME_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys()\n\nexport function resolveQueryRoot(instance: ComponentPublicInstance & { renderRoot?: ParentNode }): QueryRoot {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as QueryRoot\n}\n\nexport function resolveRenderRoot(instance: ComponentPublicInstance & { renderRoot?: HTMLElement | ShadowRoot }) {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as HTMLElement | ShadowRoot\n}\n\nexport function createScopedSelectorQuery(instance: ComponentPublicInstance) {\n const runtime = globalThis as Record<string, {\n createSelectorQuery?: () => {\n in?: (context: unknown) => unknown\n }\n } | undefined>\n for (const globalKey of MINI_PROGRAM_RUNTIME_GLOBAL_KEYS) {\n const query = runtime[globalKey]?.createSelectorQuery?.()\n if (query && typeof query.in === 'function') {\n return query.in(instance)\n }\n if (query) {\n return query\n }\n }\n return undefined\n}\n\nexport function selectRuntimeComponent(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelector !== 'function') {\n return null\n }\n return root.querySelector(selector) as ComponentPublicInstance | null\n}\n\nexport function selectRuntimeComponents(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelectorAll !== 'function') {\n return []\n }\n return Array.from(root.querySelectorAll(selector)) as ComponentPublicInstance[]\n}\n"],"mappings":";;;AAQA,MAAM,mCAAmC,iCAAiC;AAE1E,SAAgB,iBAAiB,UAA4E;AAC3G,QAAQ,SAAS,cAAc,SAAS,cAAc;;AAGxD,SAAgB,kBAAkB,UAA+E;AAC/G,QAAQ,SAAS,cAAc,SAAS,cAAc;;AAGxD,SAAgB,0BAA0B,UAAmC;CAC3E,MAAM,UAAU;AAKhB,MAAK,MAAM,aAAa,kCAAkC;EACxD,MAAM,QAAQ,QAAQ,YAAY,uBAAuB;AACzD,MAAI,SAAS,OAAO,MAAM,OAAO,WAC/B,QAAO,MAAM,GAAG,SAAS;AAE3B,MAAI,MACF,QAAO;;;AAMb,SAAgB,uBAAuB,UAAiE,UAAkB;CACxH,MAAM,OAAO,iBAAiB,SAAS;AACvC,KAAI,CAAC,YAAY,OAAO,KAAK,kBAAkB,WAC7C,QAAO;AAET,QAAO,KAAK,cAAc,SAAS;;AAGrC,SAAgB,wBAAwB,UAAiE,UAAkB;CACzH,MAAM,OAAO,iBAAiB,SAAS;AACvC,KAAI,CAAC,YAAY,OAAO,KAAK,qBAAqB,WAChD,QAAO,EAAE;AAEX,QAAO,MAAM,KAAK,KAAK,iBAAiB,SAAS,CAAC"}
|