@zeus-js/runtime-dom 0.1.0-beta.2 → 0.1.0-beta.4
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/runtime-dom.cjs.js +279 -38
- package/dist/runtime-dom.cjs.prod.js +278 -38
- package/dist/runtime-dom.d.ts +128 -20
- package/dist/runtime-dom.esm-browser.js +274 -97
- package/dist/runtime-dom.esm-browser.prod.js +1 -1
- package/dist/runtime-dom.esm-bundler.js +274 -96
- package/dist/runtime-dom.global.js +278 -97
- package/dist/runtime-dom.global.prod.js +1 -1
- package/package.json +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* runtime-dom v0.1.0-beta.
|
|
2
|
+
* runtime-dom v0.1.0-beta.4
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -168,7 +168,7 @@ function useContext(context, fallback) {
|
|
|
168
168
|
const ZEUS_CONTEXT_REQUEST = "zeus:context-request";
|
|
169
169
|
/**
|
|
170
170
|
* Creates a transparent DOM element that acts as a context boundary.
|
|
171
|
-
* Native custom elements inside it can use `
|
|
171
|
+
* Native custom elements inside it can use `resolveDOMContext` to receive
|
|
172
172
|
* context values via the DOM event protocol.
|
|
173
173
|
*/
|
|
174
174
|
function createDOMContextBoundary(context, value, children) {
|
|
@@ -180,7 +180,7 @@ function createDOMContextBoundary(context, value, children) {
|
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Registers a context value on a DOM target so that any descendant custom
|
|
183
|
-
* element can pick it up via `
|
|
183
|
+
* element can pick it up via `resolveDOMContext`.
|
|
184
184
|
*/
|
|
185
185
|
function provideDOMContext(target, context, value) {
|
|
186
186
|
const handler = (event) => {
|
|
@@ -198,7 +198,7 @@ function provideDOMContext(target, context, value) {
|
|
|
198
198
|
/**
|
|
199
199
|
* Internal precise DOM context resolver.
|
|
200
200
|
*
|
|
201
|
-
*
|
|
201
|
+
* The result distinguishes:
|
|
202
202
|
* - found: false, value: undefined
|
|
203
203
|
* - found: true, value: undefined
|
|
204
204
|
*/
|
|
@@ -227,16 +227,6 @@ function resolveDOMContext(host, context) {
|
|
|
227
227
|
value
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Public compatibility API.
|
|
232
|
-
*
|
|
233
|
-
* Returns the resolved value if found, otherwise undefined.
|
|
234
|
-
* If you need to distinguish "not found" from "found undefined",
|
|
235
|
-
* use resolveDOMContext().
|
|
236
|
-
*/
|
|
237
|
-
function requestDOMContext(host, context) {
|
|
238
|
-
return resolveDOMContext(host, context).value;
|
|
239
|
-
}
|
|
240
230
|
function resolveValue$3(value) {
|
|
241
231
|
return typeof value === "function" ? value() : value !== null && value !== void 0 ? value : null;
|
|
242
232
|
}
|
|
@@ -627,68 +617,42 @@ function mountFor(parent, marker, each, key, render) {
|
|
|
627
617
|
mountFor$1(parent, marker, each, key, render);
|
|
628
618
|
}
|
|
629
619
|
//#endregion
|
|
630
|
-
//#region
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
653
|
-
function toPropertyKey(t) {
|
|
654
|
-
var i = toPrimitive(t, "string");
|
|
655
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
656
|
-
}
|
|
657
|
-
//#endregion
|
|
658
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
659
|
-
function _defineProperty(e, r, t) {
|
|
660
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
661
|
-
value: t,
|
|
662
|
-
enumerable: !0,
|
|
663
|
-
configurable: !0,
|
|
664
|
-
writable: !0
|
|
665
|
-
}) : e[r] = t, e;
|
|
620
|
+
//#region packages/core/runtime-dom/src/defineElement.ts
|
|
621
|
+
const ZEUS_ELEMENT_DEFINITION = Symbol.for("zeus.element.definition");
|
|
622
|
+
function prop(input, options = {}) {
|
|
623
|
+
var _options$reflect, _options$default;
|
|
624
|
+
if (Array.isArray(input)) return {
|
|
625
|
+
type: String,
|
|
626
|
+
values: input,
|
|
627
|
+
attr: options.attr,
|
|
628
|
+
reflect: options.reflect,
|
|
629
|
+
default: options.default,
|
|
630
|
+
serialize: options.serialize,
|
|
631
|
+
deserialize: options.deserialize
|
|
632
|
+
};
|
|
633
|
+
const type = input;
|
|
634
|
+
return {
|
|
635
|
+
type,
|
|
636
|
+
attr: options.attr,
|
|
637
|
+
reflect: type === Boolean ? (_options$reflect = options.reflect) !== null && _options$reflect !== void 0 ? _options$reflect : true : options.reflect,
|
|
638
|
+
default: type === Boolean ? (_options$default = options.default) !== null && _options$default !== void 0 ? _options$default : false : options.default,
|
|
639
|
+
serialize: options.serialize,
|
|
640
|
+
deserialize: options.deserialize
|
|
641
|
+
};
|
|
666
642
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
function _objectSpread2(e) {
|
|
680
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
681
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
682
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
683
|
-
_defineProperty(e, r, t[r]);
|
|
684
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
685
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
return e;
|
|
643
|
+
function event(input) {
|
|
644
|
+
if (typeof input === "string") return {
|
|
645
|
+
__zeusEvent: true,
|
|
646
|
+
name: input
|
|
647
|
+
};
|
|
648
|
+
return {
|
|
649
|
+
__zeusEvent: true,
|
|
650
|
+
name: input === null || input === void 0 ? void 0 : input.name,
|
|
651
|
+
bubbles: input === null || input === void 0 ? void 0 : input.bubbles,
|
|
652
|
+
composed: input === null || input === void 0 ? void 0 : input.composed,
|
|
653
|
+
cancelable: input === null || input === void 0 ? void 0 : input.cancelable
|
|
654
|
+
};
|
|
689
655
|
}
|
|
690
|
-
//#endregion
|
|
691
|
-
//#region packages/core/runtime-dom/src/defineElement.ts
|
|
692
656
|
function createPropStore(defs) {
|
|
693
657
|
const slots = /* @__PURE__ */ new Map();
|
|
694
658
|
const props = {};
|
|
@@ -728,6 +692,12 @@ function createPropStore(defs) {
|
|
|
728
692
|
function defineElement(tagName, options, setup) {
|
|
729
693
|
var _options$props;
|
|
730
694
|
const propDefs = normalizePropDefinitions((_options$props = options.props) !== null && _options$props !== void 0 ? _options$props : {});
|
|
695
|
+
const definition = {
|
|
696
|
+
tagName,
|
|
697
|
+
options,
|
|
698
|
+
setup,
|
|
699
|
+
propDefs
|
|
700
|
+
};
|
|
731
701
|
const observedAttributes = propDefs.filter((def) => def.attr !== false).map((def) => def.attr);
|
|
732
702
|
class ZeusElement extends HTMLElement {
|
|
733
703
|
static get observedAttributes() {
|
|
@@ -742,6 +712,13 @@ function defineElement(tagName, options, setup) {
|
|
|
742
712
|
this.props = this.propStore.props;
|
|
743
713
|
applyPropDefaults(this.propStore, propDefs);
|
|
744
714
|
definePropAccessors(this, this.propStore, propDefs);
|
|
715
|
+
if (options.formAssociated) this.internals = attachElementInternals(this);
|
|
716
|
+
this.setupContext = {
|
|
717
|
+
host: this,
|
|
718
|
+
internals: this.internals,
|
|
719
|
+
emit: createEmitApi(this, options.emits),
|
|
720
|
+
expose: createExpose(this)
|
|
721
|
+
};
|
|
745
722
|
}
|
|
746
723
|
connectedCallback() {
|
|
747
724
|
var _options$shadow, _options$consumes;
|
|
@@ -765,17 +742,10 @@ function defineElement(tagName, options, setup) {
|
|
|
765
742
|
mode,
|
|
766
743
|
lightChildren: this.lightChildren
|
|
767
744
|
};
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
bubbles: true,
|
|
773
|
-
composed: true,
|
|
774
|
-
cancelable: true
|
|
775
|
-
}, eventOptions), {}, { detail })));
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
this.dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => setup(this.props, setupContext))), target, { owner });
|
|
745
|
+
this.dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => {
|
|
746
|
+
syncFormValue(this.props, this.setupContext, options.form);
|
|
747
|
+
return setup(this.props, this.setupContext);
|
|
748
|
+
})), target, { owner });
|
|
779
749
|
mountStyles(target, options.styles);
|
|
780
750
|
}
|
|
781
751
|
disconnectedCallback() {
|
|
@@ -783,6 +753,22 @@ function defineElement(tagName, options, setup) {
|
|
|
783
753
|
(_this$dispose = this.dispose) === null || _this$dispose === void 0 || _this$dispose.call(this);
|
|
784
754
|
this.dispose = void 0;
|
|
785
755
|
}
|
|
756
|
+
formAssociatedCallback(form) {
|
|
757
|
+
var _options$form, _options$form$associa;
|
|
758
|
+
(_options$form = options.form) === null || _options$form === void 0 || (_options$form$associa = _options$form.associated) === null || _options$form$associa === void 0 || _options$form$associa.call(_options$form, form, this.props, this.setupContext);
|
|
759
|
+
}
|
|
760
|
+
formDisabledCallback(disabled) {
|
|
761
|
+
var _options$form2, _options$form2$disabl;
|
|
762
|
+
(_options$form2 = options.form) === null || _options$form2 === void 0 || (_options$form2$disabl = _options$form2.disabled) === null || _options$form2$disabl === void 0 || _options$form2$disabl.call(_options$form2, disabled, this.props, this.setupContext);
|
|
763
|
+
}
|
|
764
|
+
formResetCallback() {
|
|
765
|
+
var _options$form3, _options$form3$reset;
|
|
766
|
+
(_options$form3 = options.form) === null || _options$form3 === void 0 || (_options$form3$reset = _options$form3.reset) === null || _options$form3$reset === void 0 || _options$form3$reset.call(_options$form3, this.props, this.setupContext);
|
|
767
|
+
}
|
|
768
|
+
formStateRestoreCallback(state, mode) {
|
|
769
|
+
var _options$form4, _options$form4$stateR;
|
|
770
|
+
(_options$form4 = options.form) === null || _options$form4 === void 0 || (_options$form4$stateR = _options$form4.stateRestore) === null || _options$form4$stateR === void 0 || _options$form4$stateR.call(_options$form4, state, mode, this.props, this.setupContext);
|
|
771
|
+
}
|
|
786
772
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
787
773
|
if (oldValue === newValue || this.reflecting) return;
|
|
788
774
|
const def = propDefs.find((item) => item.attr === name);
|
|
@@ -818,24 +804,131 @@ function defineElement(tagName, options, setup) {
|
|
|
818
804
|
}
|
|
819
805
|
}
|
|
820
806
|
}
|
|
807
|
+
ZeusElement.formAssociated = Boolean(options.formAssociated);
|
|
821
808
|
if (!customElements.get(tagName)) customElements.define(tagName, ZeusElement);
|
|
809
|
+
Object.defineProperty(ZeusElement, ZEUS_ELEMENT_DEFINITION, {
|
|
810
|
+
value: definition,
|
|
811
|
+
configurable: false
|
|
812
|
+
});
|
|
822
813
|
return ZeusElement;
|
|
823
814
|
}
|
|
815
|
+
function getElementDefinition(ctor) {
|
|
816
|
+
const definition = ctor[ZEUS_ELEMENT_DEFINITION];
|
|
817
|
+
if (!definition) throw new Error("[zeus] Element definition metadata not found.");
|
|
818
|
+
return definition;
|
|
819
|
+
}
|
|
820
|
+
function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new Map(), mountState = {}) {
|
|
821
|
+
var _options$shadow2, _mountState$lightChil, _options$consumes2, _mountState$target, _mountState$internals;
|
|
822
|
+
const { options, setup, propDefs } = getElementDefinition(ctor);
|
|
823
|
+
const propStore = createPropStore(propDefs);
|
|
824
|
+
applyPropDefaults(propStore, propDefs);
|
|
825
|
+
for (const def of propDefs) {
|
|
826
|
+
var _mountState$attribute;
|
|
827
|
+
if (def.attr !== false && ((_mountState$attribute = mountState.attributeProps) === null || _mountState$attribute === void 0 ? void 0 : _mountState$attribute.has(def.key))) {
|
|
828
|
+
propStore.set(def.key, castAttributeValue(host.getAttribute(def.attr), def));
|
|
829
|
+
initialValues.set(def.key, propStore.get(def.key));
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
if (initialValues.has(def.key)) {
|
|
833
|
+
propStore.set(def.key, initialValues.get(def.key));
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Sync real definition defaults (e.g. factory defaults like `default: () => []`)
|
|
838
|
+
* back to the lazy host value map so that `element.propName` returns the
|
|
839
|
+
* correct default value rather than undefined.
|
|
840
|
+
*/
|
|
841
|
+
initialValues.set(def.key, propStore.get(def.key));
|
|
842
|
+
}
|
|
843
|
+
for (const def of propDefs) {
|
|
844
|
+
var _mountState$attribute2;
|
|
845
|
+
if (def.reflect && def.serialize && !((_mountState$attribute2 = mountState.attributeProps) === null || _mountState$attribute2 === void 0 ? void 0 : _mountState$attribute2.has(def.key))) reflectExternalProp(host, def, propStore.get(def.key), mountState.reflectingAttrs);
|
|
846
|
+
}
|
|
847
|
+
const shadow = (_options$shadow2 = options.shadow) !== null && _options$shadow2 !== void 0 ? _options$shadow2 : false;
|
|
848
|
+
const mode = shadow ? "shadow" : "light";
|
|
849
|
+
if (mode === "light" && !mountState.capturedLightChildren) {
|
|
850
|
+
mountState.lightChildren = Array.from(host.childNodes);
|
|
851
|
+
mountState.capturedLightChildren = true;
|
|
852
|
+
}
|
|
853
|
+
const lightChildren = (_mountState$lightChil = mountState.lightChildren) !== null && _mountState$lightChil !== void 0 ? _mountState$lightChil : [];
|
|
854
|
+
const owner = createOwner();
|
|
855
|
+
for (const context of (_options$consumes2 = options.consumes) !== null && _options$consumes2 !== void 0 ? _options$consumes2 : []) {
|
|
856
|
+
const resolved = resolveDOMContext(host, context);
|
|
857
|
+
if (resolved.found) owner.provides.set(context.id, resolved.value);
|
|
858
|
+
else if (context.hasDefaultValue) owner.provides.set(context.id, context.defaultValue);
|
|
859
|
+
}
|
|
860
|
+
const target = (_mountState$target = mountState.target) !== null && _mountState$target !== void 0 ? _mountState$target : mountState.target = resolveExternalRenderTarget(host, shadow);
|
|
861
|
+
const hostContext = {
|
|
862
|
+
host,
|
|
863
|
+
mode,
|
|
864
|
+
lightChildren
|
|
865
|
+
};
|
|
866
|
+
const setupContext = {
|
|
867
|
+
host,
|
|
868
|
+
internals: (_mountState$internals = mountState.internals) !== null && _mountState$internals !== void 0 ? _mountState$internals : options.formAssociated ? attachElementInternals(host) : void 0,
|
|
869
|
+
emit: createEmitApi(host, options.emits),
|
|
870
|
+
expose: createExpose(host)
|
|
871
|
+
};
|
|
872
|
+
mountState.internals = setupContext.internals;
|
|
873
|
+
const dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => {
|
|
874
|
+
syncFormValue(propStore.props, setupContext, options.form);
|
|
875
|
+
return setup(propStore.props, setupContext);
|
|
876
|
+
})), target, { owner });
|
|
877
|
+
mountStyles(target, options.styles);
|
|
878
|
+
return {
|
|
879
|
+
propertyChanged(name, _oldValue, newValue) {
|
|
880
|
+
var _mountState$attribute3;
|
|
881
|
+
const def = propDefs.find((item) => item.key === name);
|
|
882
|
+
const fromAttribute = Boolean((def === null || def === void 0 ? void 0 : def.attr) !== false && ((_mountState$attribute3 = mountState.attributeProps) === null || _mountState$attribute3 === void 0 ? void 0 : _mountState$attribute3.has(name)));
|
|
883
|
+
const value = fromAttribute && def ? castAttributeValue(typeof newValue === "string" ? newValue : null, def) : newValue;
|
|
884
|
+
propStore.set(name, value);
|
|
885
|
+
initialValues.set(name, value);
|
|
886
|
+
if ((def === null || def === void 0 ? void 0 : def.reflect) && !fromAttribute) reflectExternalProp(host, def, value, mountState.reflectingAttrs);
|
|
887
|
+
},
|
|
888
|
+
formAssociated(form) {
|
|
889
|
+
var _options$form5, _options$form5$associ;
|
|
890
|
+
(_options$form5 = options.form) === null || _options$form5 === void 0 || (_options$form5$associ = _options$form5.associated) === null || _options$form5$associ === void 0 || _options$form5$associ.call(_options$form5, form, propStore.props, setupContext);
|
|
891
|
+
},
|
|
892
|
+
formDisabled(disabled) {
|
|
893
|
+
var _options$form6, _options$form6$disabl;
|
|
894
|
+
(_options$form6 = options.form) === null || _options$form6 === void 0 || (_options$form6$disabl = _options$form6.disabled) === null || _options$form6$disabl === void 0 || _options$form6$disabl.call(_options$form6, disabled, propStore.props, setupContext);
|
|
895
|
+
},
|
|
896
|
+
formReset() {
|
|
897
|
+
var _options$form7, _options$form7$reset;
|
|
898
|
+
(_options$form7 = options.form) === null || _options$form7 === void 0 || (_options$form7$reset = _options$form7.reset) === null || _options$form7$reset === void 0 || _options$form7$reset.call(_options$form7, propStore.props, setupContext);
|
|
899
|
+
},
|
|
900
|
+
formStateRestore(state, mode) {
|
|
901
|
+
var _options$form8, _options$form8$stateR;
|
|
902
|
+
(_options$form8 = options.form) === null || _options$form8 === void 0 || (_options$form8$stateR = _options$form8.stateRestore) === null || _options$form8$stateR === void 0 || _options$form8$stateR.call(_options$form8, state, mode, propStore.props, setupContext);
|
|
903
|
+
},
|
|
904
|
+
dispose() {
|
|
905
|
+
dispose();
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
}
|
|
824
909
|
function normalizePropDefinitions(props) {
|
|
825
910
|
return Object.keys(props).map((key) => {
|
|
911
|
+
const propKey = String(key);
|
|
826
912
|
const input = props[key];
|
|
827
|
-
if (typeof input === "function")
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
913
|
+
if (typeof input === "function") {
|
|
914
|
+
const type = input;
|
|
915
|
+
return {
|
|
916
|
+
key: propKey,
|
|
917
|
+
attr: isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false,
|
|
918
|
+
type,
|
|
919
|
+
reflect: false
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
const type = input === null || input === void 0 ? void 0 : input.type;
|
|
923
|
+
const defaultAttr = isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false;
|
|
833
924
|
return {
|
|
834
|
-
key,
|
|
835
|
-
attr: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ?
|
|
836
|
-
type
|
|
925
|
+
key: propKey,
|
|
926
|
+
attr: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? defaultAttr : input.attr,
|
|
927
|
+
type,
|
|
837
928
|
reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
|
|
838
|
-
default: input === null || input === void 0 ? void 0 : input.default
|
|
929
|
+
default: input === null || input === void 0 ? void 0 : input.default,
|
|
930
|
+
serialize: input === null || input === void 0 ? void 0 : input.serialize,
|
|
931
|
+
deserialize: input === null || input === void 0 ? void 0 : input.deserialize
|
|
839
932
|
};
|
|
840
933
|
});
|
|
841
934
|
}
|
|
@@ -871,6 +964,7 @@ function definePropAccessors(element, store, defs) {
|
|
|
871
964
|
}
|
|
872
965
|
}
|
|
873
966
|
function castAttributeValue(value, def) {
|
|
967
|
+
if (def.deserialize) return def.deserialize(value);
|
|
874
968
|
if (def.type === Boolean) return value !== null;
|
|
875
969
|
if (value === null) return;
|
|
876
970
|
if (def.type === Number) return Number(value);
|
|
@@ -880,10 +974,17 @@ function castAttributeValue(value, def) {
|
|
|
880
974
|
console.warn(`[Zeus custom-element] Failed to parse JSON attribute "${def.attr}".`);
|
|
881
975
|
return def.type === Array ? [] : {};
|
|
882
976
|
}
|
|
977
|
+
if (def.type === Function) return;
|
|
883
978
|
return value;
|
|
884
979
|
}
|
|
885
980
|
function reflectPropToAttribute(element, def, value) {
|
|
886
981
|
if (def.attr === false) return;
|
|
982
|
+
if (def.serialize) {
|
|
983
|
+
const serialized = def.serialize(value);
|
|
984
|
+
if (serialized == null) element.removeAttribute(def.attr);
|
|
985
|
+
else element.setAttribute(def.attr, serialized);
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
887
988
|
if (def.type === Boolean) {
|
|
888
989
|
if (value) element.setAttribute(def.attr, "");
|
|
889
990
|
else element.removeAttribute(def.attr);
|
|
@@ -897,8 +998,85 @@ function reflectPropToAttribute(element, def, value) {
|
|
|
897
998
|
element.setAttribute(def.attr, JSON.stringify(value));
|
|
898
999
|
return;
|
|
899
1000
|
}
|
|
1001
|
+
if (def.type === Function) return;
|
|
900
1002
|
element.setAttribute(def.attr, String(value));
|
|
901
1003
|
}
|
|
1004
|
+
function reflectExternalProp(element, def, value, reflectingAttrs) {
|
|
1005
|
+
if (def.attr === false) return;
|
|
1006
|
+
const attrName = def.attr.toLowerCase();
|
|
1007
|
+
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.add(attrName);
|
|
1008
|
+
try {
|
|
1009
|
+
reflectPropToAttribute(element, def, value);
|
|
1010
|
+
} finally {
|
|
1011
|
+
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.delete(attrName);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function syncFormValue(props, context, form) {
|
|
1015
|
+
const valueResolver = form === null || form === void 0 ? void 0 : form.value;
|
|
1016
|
+
const stateResolver = form === null || form === void 0 ? void 0 : form.state;
|
|
1017
|
+
if (!context.internals || valueResolver === void 0) return;
|
|
1018
|
+
effect(() => {
|
|
1019
|
+
const value = resolveFormValue(props, valueResolver);
|
|
1020
|
+
const state = stateResolver === void 0 ? void 0 : resolveFormValue(props, stateResolver);
|
|
1021
|
+
context.internals.setFormValue(value, state);
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
function resolveFormValue(props, resolver) {
|
|
1025
|
+
if (typeof resolver === "function") {
|
|
1026
|
+
var _resolver;
|
|
1027
|
+
return (_resolver = resolver(props)) !== null && _resolver !== void 0 ? _resolver : null;
|
|
1028
|
+
}
|
|
1029
|
+
const value = props[resolver];
|
|
1030
|
+
return value == null ? null : value;
|
|
1031
|
+
}
|
|
1032
|
+
function attachElementInternals(host) {
|
|
1033
|
+
const attachInternals = host.attachInternals;
|
|
1034
|
+
if (typeof attachInternals !== "function") return;
|
|
1035
|
+
try {
|
|
1036
|
+
return attachInternals.call(host);
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
console.warn("[Zeus custom-element] Failed to attach ElementInternals.", error);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function createEmitApi(host, emits) {
|
|
1043
|
+
const emit = {};
|
|
1044
|
+
const dispatch = (name, detail, options) => {
|
|
1045
|
+
var _definition$name, _ref, _options$bubbles, _ref2, _options$composed, _ref3, _options$cancelable;
|
|
1046
|
+
const definition = emits === null || emits === void 0 ? void 0 : emits[name];
|
|
1047
|
+
return host.dispatchEvent(new CustomEvent((_definition$name = definition === null || definition === void 0 ? void 0 : definition.name) !== null && _definition$name !== void 0 ? _definition$name : toKebabCase(name), {
|
|
1048
|
+
bubbles: (_ref = (_options$bubbles = options === null || options === void 0 ? void 0 : options.bubbles) !== null && _options$bubbles !== void 0 ? _options$bubbles : definition === null || definition === void 0 ? void 0 : definition.bubbles) !== null && _ref !== void 0 ? _ref : true,
|
|
1049
|
+
composed: (_ref2 = (_options$composed = options === null || options === void 0 ? void 0 : options.composed) !== null && _options$composed !== void 0 ? _options$composed : definition === null || definition === void 0 ? void 0 : definition.composed) !== null && _ref2 !== void 0 ? _ref2 : true,
|
|
1050
|
+
cancelable: (_ref3 = (_options$cancelable = options === null || options === void 0 ? void 0 : options.cancelable) !== null && _options$cancelable !== void 0 ? _options$cancelable : definition === null || definition === void 0 ? void 0 : definition.cancelable) !== null && _ref3 !== void 0 ? _ref3 : false,
|
|
1051
|
+
detail
|
|
1052
|
+
}));
|
|
1053
|
+
};
|
|
1054
|
+
if (emits) for (const key of Object.keys(emits)) Object.defineProperty(emit, key, {
|
|
1055
|
+
configurable: true,
|
|
1056
|
+
enumerable: true,
|
|
1057
|
+
value(detail, options) {
|
|
1058
|
+
return dispatch(key, detail, options);
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
return emit;
|
|
1062
|
+
}
|
|
1063
|
+
function createExpose(host) {
|
|
1064
|
+
return (methods) => {
|
|
1065
|
+
for (const key of Object.keys(methods)) Object.defineProperty(host, key, {
|
|
1066
|
+
configurable: true,
|
|
1067
|
+
enumerable: false,
|
|
1068
|
+
value: methods[key]
|
|
1069
|
+
});
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
function isAttributeBackedConstructor(type) {
|
|
1073
|
+
return type === String || type === Number || type === Boolean;
|
|
1074
|
+
}
|
|
1075
|
+
function resolveExternalRenderTarget(host, shadow) {
|
|
1076
|
+
var _host$shadowRoot;
|
|
1077
|
+
if (!shadow) return host;
|
|
1078
|
+
return (_host$shadowRoot = host.shadowRoot) !== null && _host$shadowRoot !== void 0 ? _host$shadowRoot : host.attachShadow(typeof shadow === "object" ? shadow : { mode: "open" });
|
|
1079
|
+
}
|
|
902
1080
|
function mountStyles(target, styles) {
|
|
903
1081
|
if (!styles) return;
|
|
904
1082
|
const list = Array.isArray(styles) ? styles : [styles];
|
|
@@ -1035,4 +1213,4 @@ function normalizeHostAttrName(name) {
|
|
|
1035
1213
|
}
|
|
1036
1214
|
}
|
|
1037
1215
|
//#endregion
|
|
1038
|
-
export { For, Host, Show, Slot, ZEUS_CONTEXT_REQUEST, bindAttr, bindClass, bindEvent, bindProp, bindRef, bindStyle, bindText, bindTextContent, captureCurrentHostContext, child, createComponent, createContext, createDOMContextBoundary, createOwner, createSlot, defineElement, delegateEvents, getCurrentHostContext, getCurrentOwner, inject, insert, insertTracked, marker, mountDynamic, mountFor, mountShow, normalizeClass, provide, provideDOMContext, removeNodes, render,
|
|
1216
|
+
export { For, Host, Show, Slot, ZEUS_CONTEXT_REQUEST, ZEUS_ELEMENT_DEFINITION, bindAttr, bindClass, bindEvent, bindProp, bindRef, bindStyle, bindText, bindTextContent, captureCurrentHostContext, child, createComponent, createContext, createDOMContextBoundary, createOwner, createSlot, defineElement, delegateEvents, event, getCurrentHostContext, getCurrentOwner, getElementDefinition, inject, insert, insertTracked, marker, mountDynamic, mountElementDefinition, mountFor, mountShow, normalizeClass, prop, provide, provideDOMContext, removeNodes, render, resolveDOMContext, resolveValue, runWithOwner, setAttr, setRef, template, useContext, withCapturedHostContext, withHostContext };
|