@zeus-js/web-c-runtime 0.1.0-beta.7 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web-c-runtime.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type: ZeusPropType;
|
|
6
|
-
reflect?: boolean;
|
|
1
|
+
import { CustomElementPropSchema, CustomElementPropType } from '@zeus-js/runtime-dom';
|
|
2
|
+
|
|
3
|
+
export type ZeusPropType = CustomElementPropType;
|
|
4
|
+
export interface ZeusPropMeta extends CustomElementPropSchema {
|
|
7
5
|
default?: unknown;
|
|
8
|
-
serialize?: boolean;
|
|
9
|
-
deserialize?: boolean;
|
|
10
6
|
}
|
|
11
7
|
export interface ZeusLazyComponentMeta {
|
|
12
8
|
tagName: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* web-c-runtime v0.1.0-beta.
|
|
2
|
+
* web-c-runtime v0.1.0-beta.9
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
6
|
+
import { coerceCustomElementAttribute, findCustomElementPropByAttribute, getCustomElementAttributeName, getCustomElementObservedAttributes, reflectCustomElementProperty } from "@zeus-js/runtime-dom";
|
|
6
7
|
//#region packages/web-c/web-c-runtime/src/form-callbacks.ts
|
|
7
8
|
function invokeFormCallback(hostRef, callback) {
|
|
8
9
|
switch (callback.type) {
|
|
@@ -87,7 +88,7 @@ function setPropValue(hostRef, prop, value) {
|
|
|
87
88
|
if (Object.is(oldValue, value)) return;
|
|
88
89
|
hostRef.values.set(prop.name, value);
|
|
89
90
|
hostRef.attributeProps.delete(prop.name);
|
|
90
|
-
if (prop.reflect
|
|
91
|
+
if (prop.reflect) reflectCustomElementProperty(hostRef.host, prop, value, hostRef.reflectingAttrs);
|
|
91
92
|
if (hostRef.loaded) {
|
|
92
93
|
var _hostRef$instance, _hostRef$instance$pro;
|
|
93
94
|
(_hostRef$instance = hostRef.instance) === null || _hostRef$instance === void 0 || (_hostRef$instance$pro = _hostRef$instance.propertyChanged) === null || _hostRef$instance$pro === void 0 || _hostRef$instance$pro.call(_hostRef$instance, prop.name, oldValue, value);
|
|
@@ -96,10 +97,10 @@ function setPropValue(hostRef, prop, value) {
|
|
|
96
97
|
function syncAttributeToProperty(hostRef, attrName, _oldValue, newValue) {
|
|
97
98
|
const normalizedAttrName = normalizeAttrName(attrName);
|
|
98
99
|
if (hostRef.reflectingAttrs.has(normalizedAttrName)) return;
|
|
99
|
-
const prop =
|
|
100
|
+
const prop = findCustomElementPropByAttribute(hostRef.meta.props, normalizedAttrName);
|
|
100
101
|
if (!prop) return;
|
|
101
102
|
const oldPropValue = getPropValue(hostRef, prop);
|
|
102
|
-
const newPropValue =
|
|
103
|
+
const newPropValue = coerceCustomElementAttribute(prop, newValue);
|
|
103
104
|
if (Object.is(oldPropValue, newPropValue)) return;
|
|
104
105
|
hostRef.values.set(prop.name, newPropValue);
|
|
105
106
|
hostRef.attributeProps.add(prop.name);
|
|
@@ -112,9 +113,9 @@ function applyInitialValues(hostRef) {
|
|
|
112
113
|
const host = hostRef.host;
|
|
113
114
|
for (const prop of hostRef.meta.props) {
|
|
114
115
|
if (hostRef.values.has(prop.name)) continue;
|
|
115
|
-
const attrName =
|
|
116
|
+
const attrName = getCustomElementAttributeName(prop);
|
|
116
117
|
if (attrName && host.hasAttribute(attrName)) {
|
|
117
|
-
hostRef.values.set(prop.name,
|
|
118
|
+
hostRef.values.set(prop.name, coerceCustomElementAttribute(prop, host.getAttribute(attrName)));
|
|
118
119
|
hostRef.attributeProps.add(prop.name);
|
|
119
120
|
continue;
|
|
120
121
|
}
|
|
@@ -122,12 +123,7 @@ function applyInitialValues(hostRef) {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
function getObservedAttributes(props) {
|
|
125
|
-
|
|
126
|
-
for (const prop of props) {
|
|
127
|
-
const attrName = getAttrName(prop);
|
|
128
|
-
if (attrName) attrs.push(attrName);
|
|
129
|
-
}
|
|
130
|
-
return attrs;
|
|
126
|
+
return getCustomElementObservedAttributes(props);
|
|
131
127
|
}
|
|
132
128
|
/**
|
|
133
129
|
* Upgrades properties that were written on an element instance before its
|
|
@@ -147,56 +143,9 @@ function upgradePreDefinedProperties(host, hostRef) {
|
|
|
147
143
|
setPropValue(hostRef, prop, value);
|
|
148
144
|
}
|
|
149
145
|
}
|
|
150
|
-
function findPropByAttrName(hostRef, attrName) {
|
|
151
|
-
return hostRef.meta.props.find((prop) => {
|
|
152
|
-
return getAttrName(prop) === attrName;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function getAttrName(prop) {
|
|
156
|
-
var _prop$attrName;
|
|
157
|
-
if (prop.attrName === false) return;
|
|
158
|
-
if (!isAttributeBackedType(prop.type) && !prop.deserialize) return;
|
|
159
|
-
return normalizeAttrName((_prop$attrName = prop.attrName) !== null && _prop$attrName !== void 0 ? _prop$attrName : toKebabCase(prop.name));
|
|
160
|
-
}
|
|
161
|
-
function isAttributeBackedType(type) {
|
|
162
|
-
return type === "string" || type === "number" || type === "boolean";
|
|
163
|
-
}
|
|
164
146
|
function normalizeAttrName(value) {
|
|
165
147
|
return value.toLowerCase();
|
|
166
148
|
}
|
|
167
|
-
function parseAttributeValue(prop, value) {
|
|
168
|
-
if (prop.deserialize) return value;
|
|
169
|
-
switch (prop.type) {
|
|
170
|
-
case "boolean": return value !== null;
|
|
171
|
-
case "number":
|
|
172
|
-
if (value === null) return;
|
|
173
|
-
return Number(value);
|
|
174
|
-
case "string": return value !== null && value !== void 0 ? value : void 0;
|
|
175
|
-
default: return value;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
function reflectPropertyToAttribute(hostRef, prop, value) {
|
|
179
|
-
const host = hostRef.host;
|
|
180
|
-
const attrName = getAttrName(prop);
|
|
181
|
-
if (!attrName) return;
|
|
182
|
-
hostRef.reflectingAttrs.add(attrName);
|
|
183
|
-
try {
|
|
184
|
-
if (prop.type === "boolean") {
|
|
185
|
-
host.toggleAttribute(attrName, Boolean(value));
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (value === null || value === void 0 || value === false) {
|
|
189
|
-
host.removeAttribute(attrName);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (prop.type === "string" || prop.type === "number") host.setAttribute(attrName, String(value));
|
|
193
|
-
} finally {
|
|
194
|
-
hostRef.reflectingAttrs.delete(attrName);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function toKebabCase(value) {
|
|
198
|
-
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
199
|
-
}
|
|
200
149
|
//#endregion
|
|
201
150
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/asyncToGenerator.js
|
|
202
151
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeus-js/web-c-runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.9",
|
|
5
5
|
"description": "Zeus Web-C lazy-loading runtime",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@zeus-js/runtime-dom": "0.1.0-beta.9"
|
|
30
|
+
},
|
|
28
31
|
"author": "Baicie",
|
|
29
32
|
"buildOptions": {
|
|
30
33
|
"name": "ZeusWebCRuntime",
|