@fluixi/web-components 0.0.0-stage → 1.0.0-alpha.100
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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/context.cjs +162 -0
- package/dist/context.d.ts +65 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +192 -0
- package/dist/context.mjs +141 -0
- package/dist/element.cjs +847 -0
- package/dist/element.d.ts +213 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +681 -0
- package/dist/element.mjs +835 -0
- package/dist/events.cjs +35 -0
- package/dist/events.d.ts +24 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +20 -0
- package/dist/events.mjs +14 -0
- package/dist/focus.cjs +156 -0
- package/dist/focus.d.ts +34 -0
- package/dist/focus.d.ts.map +1 -0
- package/dist/focus.js +185 -0
- package/dist/focus.mjs +135 -0
- package/dist/form.cjs +145 -0
- package/dist/form.d.ts +33 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +113 -0
- package/dist/form.mjs +125 -0
- package/dist/index.cjs +1202 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.mjs +1188 -0
- package/dist/props.cjs +114 -0
- package/dist/props.d.ts +93 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +99 -0
- package/dist/props.mjs +93 -0
- package/dist/registry.cjs +77 -0
- package/dist/registry.d.ts +26 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +91 -0
- package/dist/registry.mjs +56 -0
- package/dist/styles.cjs +59 -0
- package/dist/styles.d.ts +17 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +53 -0
- package/dist/styles.mjs +38 -0
- package/dist/targets.cjs +42 -0
- package/dist/targets.d.ts +26 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/targets.js +35 -0
- package/dist/targets.mjs +21 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.mjs +0 -0
- package/package.json +53 -3
package/dist/element.cjs
ADDED
|
@@ -0,0 +1,847 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
|
|
28
|
+
// src/element.ts
|
|
29
|
+
var element_exports = {};
|
|
30
|
+
__export(element_exports, {
|
|
31
|
+
HTMLReactiveElement: () => HTMLReactiveElement,
|
|
32
|
+
createElementClass: () => createElementClass,
|
|
33
|
+
defineElement: () => defineElement,
|
|
34
|
+
typedElement: () => typedElement
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(element_exports);
|
|
37
|
+
var import_signal3 = require("@fluixi/reactive/signal");
|
|
38
|
+
var import_dom2 = require("@fluixi/dom");
|
|
39
|
+
|
|
40
|
+
// src/props.ts
|
|
41
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
42
|
+
function createPropStates(schema) {
|
|
43
|
+
const states = {};
|
|
44
|
+
for (const [name, declaration] of Object.entries(schema)) {
|
|
45
|
+
const value = (0, import_signal.signal)(declaration.initial, { equals: declaration.equals, name });
|
|
46
|
+
states[name] = {
|
|
47
|
+
read: value,
|
|
48
|
+
// `.set` reads a function argument as an updater and calls it. A property holding
|
|
49
|
+
// a callback is ordinary for a custom element, so it is wrapped: the value
|
|
50
|
+
// arrives as the return of an updater that ignores the previous one.
|
|
51
|
+
write: (next) => void (typeof next === "function" ? value.set(() => next) : value.set(next)),
|
|
52
|
+
declaration,
|
|
53
|
+
attribute: declaration.attribute === "" ? name.toLowerCase() : declaration.attribute
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return states;
|
|
57
|
+
}
|
|
58
|
+
function observedFrom(schema) {
|
|
59
|
+
return Object.entries(schema).map(([name, d]) => d.attribute === "" ? name.toLowerCase() : d.attribute).filter((a) => a !== false);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/registry.ts
|
|
63
|
+
var import_dom = require("@fluixi/dom");
|
|
64
|
+
var defined = /* @__PURE__ */ new Map();
|
|
65
|
+
function registry() {
|
|
66
|
+
return typeof customElements === "undefined" ? null : customElements;
|
|
67
|
+
}
|
|
68
|
+
function defineCustomElement(name, constructor, options = {}) {
|
|
69
|
+
if ((0, import_dom.isServer)() && typeof HTMLElement !== "undefined") return constructor;
|
|
70
|
+
const registered = defined.get(name);
|
|
71
|
+
if (registered) return registered;
|
|
72
|
+
const ce = registry();
|
|
73
|
+
if (!ce) return constructor;
|
|
74
|
+
const existing = ce.get(name);
|
|
75
|
+
if (existing) {
|
|
76
|
+
defined.set(name, existing);
|
|
77
|
+
return existing;
|
|
78
|
+
}
|
|
79
|
+
ce.define(name, constructor, options.extends ? { extends: options.extends } : void 0);
|
|
80
|
+
defined.set(name, constructor);
|
|
81
|
+
return constructor;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/events.ts
|
|
85
|
+
function createDispatch(host) {
|
|
86
|
+
return (type, detail, init = {}) => host.dispatchEvent(
|
|
87
|
+
new CustomEvent(type, {
|
|
88
|
+
bubbles: init.bubbles ?? true,
|
|
89
|
+
composed: init.composed ?? true,
|
|
90
|
+
cancelable: init.cancelable ?? false,
|
|
91
|
+
detail
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/targets.ts
|
|
97
|
+
function selector(name) {
|
|
98
|
+
const escaped = typeof CSS !== "undefined" && CSS.escape ? CSS.escape(name) : name;
|
|
99
|
+
return `[data-target="${escaped}"]`;
|
|
100
|
+
}
|
|
101
|
+
function createTargets(root2) {
|
|
102
|
+
return {
|
|
103
|
+
get: (name) => root2().querySelector(selector(name)),
|
|
104
|
+
all: (name) => Array.from(root2().querySelectorAll(selector(name))),
|
|
105
|
+
require: (name) => {
|
|
106
|
+
const found = root2().querySelector(selector(name));
|
|
107
|
+
if (found) return found;
|
|
108
|
+
throw new Error(
|
|
109
|
+
`[fluixi] no element with data-target="${name}" in this component. Add it to the markup, or use targets.get() if its absence is expected.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/styles.ts
|
|
116
|
+
var sheets = /* @__PURE__ */ new Map();
|
|
117
|
+
var resolved = /* @__PURE__ */ new WeakMap();
|
|
118
|
+
function flatten(styles, out) {
|
|
119
|
+
if (!styles) return out;
|
|
120
|
+
if (typeof styles === "string" || !Array.isArray(styles)) out.push(styles);
|
|
121
|
+
else for (const entry of styles) flatten(entry, out);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
function sheetFor(css) {
|
|
125
|
+
let sheet = sheets.get(css);
|
|
126
|
+
if (!sheet) {
|
|
127
|
+
sheet = new CSSStyleSheet();
|
|
128
|
+
sheet.replaceSync(css);
|
|
129
|
+
sheets.set(css, sheet);
|
|
130
|
+
}
|
|
131
|
+
return sheet;
|
|
132
|
+
}
|
|
133
|
+
function canAdopt(root2) {
|
|
134
|
+
return typeof CSSStyleSheet !== "undefined" && "replaceSync" in CSSStyleSheet.prototype && "adoptedStyleSheets" in root2;
|
|
135
|
+
}
|
|
136
|
+
function applyStyles(root2, owner, styles) {
|
|
137
|
+
let list = resolved.get(owner);
|
|
138
|
+
if (!list) resolved.set(owner, list = flatten(styles, []));
|
|
139
|
+
if (!list.length) return;
|
|
140
|
+
if (canAdopt(root2)) {
|
|
141
|
+
root2.adoptedStyleSheets = [...root2.adoptedStyleSheets, ...list.map((s) => typeof s === "string" ? sheetFor(s) : s)];
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
for (const entry of list) {
|
|
145
|
+
const style = document.createElement("style");
|
|
146
|
+
style.textContent = typeof entry === "string" ? entry : Array.from(entry.cssRules, (rule) => rule.cssText).join("\n");
|
|
147
|
+
root2.appendChild(style);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/context.ts
|
|
152
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
153
|
+
var ContextRequestEvent = class extends Event {
|
|
154
|
+
constructor(context, contextTarget, callback, subscribe) {
|
|
155
|
+
super("context-request", { bubbles: true, composed: true });
|
|
156
|
+
this.context = context;
|
|
157
|
+
this.contextTarget = contextTarget;
|
|
158
|
+
this.callback = callback;
|
|
159
|
+
this.subscribe = subscribe;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var ContextProviderEvent = class extends Event {
|
|
163
|
+
constructor(context, contextTarget) {
|
|
164
|
+
super("context-provider", { bubbles: true, composed: true });
|
|
165
|
+
this.context = context;
|
|
166
|
+
this.contextTarget = contextTarget;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var ContextOwnerEvent = class extends Event {
|
|
170
|
+
constructor(element) {
|
|
171
|
+
super("fluixi-context-owner");
|
|
172
|
+
this.element = element;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function announceOwner(element) {
|
|
176
|
+
element.ownerDocument.dispatchEvent(new ContextOwnerEvent(element));
|
|
177
|
+
}
|
|
178
|
+
function matches(key, context) {
|
|
179
|
+
return key === context || typeof key === "object" && key !== null && key.id === context.id;
|
|
180
|
+
}
|
|
181
|
+
function describe(context) {
|
|
182
|
+
return context.id.description ?? "context";
|
|
183
|
+
}
|
|
184
|
+
function provideContext(host, context, value) {
|
|
185
|
+
const read = typeof value === "function" ? value : () => value;
|
|
186
|
+
const subscribers = /* @__PURE__ */ new Map();
|
|
187
|
+
const onRequest = (event) => {
|
|
188
|
+
const request = event;
|
|
189
|
+
if (!matches(request.context, context) || request.contextTarget === host) return;
|
|
190
|
+
event.stopImmediatePropagation();
|
|
191
|
+
if (!request.subscribe) {
|
|
192
|
+
request.callback((0, import_signal2.untrack)(read));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const unsubscribe = () => void subscribers.delete(request.callback);
|
|
196
|
+
subscribers.set(request.callback, unsubscribe);
|
|
197
|
+
request.callback((0, import_signal2.untrack)(read), unsubscribe);
|
|
198
|
+
};
|
|
199
|
+
const dom = typeof host.addEventListener === "function";
|
|
200
|
+
if (dom) host.addEventListener("context-request", onRequest);
|
|
201
|
+
const owner = (0, import_signal2.getOwner)();
|
|
202
|
+
let first = true;
|
|
203
|
+
const stopTracking = (0, import_signal2.effect)(
|
|
204
|
+
() => {
|
|
205
|
+
const next = read();
|
|
206
|
+
if (owner) (owner.contexts ??= /* @__PURE__ */ new Map()).set(context.id, next);
|
|
207
|
+
if (first) {
|
|
208
|
+
first = false;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
for (const [callback, unsubscribe] of subscribers) callback(next, unsubscribe);
|
|
212
|
+
},
|
|
213
|
+
void 0,
|
|
214
|
+
{ name: `provide ${describe(context)}` }
|
|
215
|
+
);
|
|
216
|
+
if (dom) {
|
|
217
|
+
queueMicrotask(() => {
|
|
218
|
+
if (!stopped) host.dispatchEvent(new ContextProviderEvent(context, host));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
let stopped = false;
|
|
222
|
+
const stop = () => {
|
|
223
|
+
if (stopped) return;
|
|
224
|
+
stopped = true;
|
|
225
|
+
if (dom) host.removeEventListener("context-request", onRequest);
|
|
226
|
+
stopTracking();
|
|
227
|
+
subscribers.clear();
|
|
228
|
+
};
|
|
229
|
+
(0, import_signal2.onCleanup)(stop);
|
|
230
|
+
return stop;
|
|
231
|
+
}
|
|
232
|
+
function consumeContext(host, context, options = {}) {
|
|
233
|
+
const subscribe = options.subscribe ?? true;
|
|
234
|
+
const owner = (0, import_signal2.getOwner)();
|
|
235
|
+
const fromTree = () => (0, import_signal2.runWithOwner)(owner, () => (0, import_signal2.useContext)(context));
|
|
236
|
+
const value = (0, import_signal2.signal)(fromTree(), { name: describe(context) });
|
|
237
|
+
if (typeof host.dispatchEvent !== "function") return () => value();
|
|
238
|
+
let answered = false;
|
|
239
|
+
let unsubscribe;
|
|
240
|
+
const ask = () => {
|
|
241
|
+
host.dispatchEvent(
|
|
242
|
+
new ContextRequestEvent(
|
|
243
|
+
context,
|
|
244
|
+
host,
|
|
245
|
+
(next, stop) => {
|
|
246
|
+
answered = true;
|
|
247
|
+
if (stop) unsubscribe = stop;
|
|
248
|
+
value.set(() => next);
|
|
249
|
+
},
|
|
250
|
+
subscribe
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
const doc = host.ownerDocument;
|
|
255
|
+
const onProvider = (event) => {
|
|
256
|
+
const announced = event;
|
|
257
|
+
if (answered || !matches(announced.context, context)) return;
|
|
258
|
+
if (containsComposed(announced.contextTarget, host)) ask();
|
|
259
|
+
};
|
|
260
|
+
const onOwner = (event) => {
|
|
261
|
+
if (answered || !containsComposed(event.element, host)) return;
|
|
262
|
+
const next = fromTree();
|
|
263
|
+
value.set(() => next);
|
|
264
|
+
};
|
|
265
|
+
ask();
|
|
266
|
+
if (!answered) {
|
|
267
|
+
doc.addEventListener("context-provider", onProvider);
|
|
268
|
+
doc.addEventListener("fluixi-context-owner", onOwner);
|
|
269
|
+
}
|
|
270
|
+
(0, import_signal2.onCleanup)(() => {
|
|
271
|
+
unsubscribe?.();
|
|
272
|
+
doc.removeEventListener("context-provider", onProvider);
|
|
273
|
+
doc.removeEventListener("fluixi-context-owner", onOwner);
|
|
274
|
+
});
|
|
275
|
+
return () => value();
|
|
276
|
+
}
|
|
277
|
+
function containsComposed(container, node) {
|
|
278
|
+
let at = node;
|
|
279
|
+
while (at) {
|
|
280
|
+
if (at === container) return true;
|
|
281
|
+
at = at.parentNode ?? (at instanceof ShadowRoot ? at.host : null);
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/element.ts
|
|
287
|
+
var OWNER_KEY = /* @__PURE__ */ Symbol.for("fluixi.owner");
|
|
288
|
+
var SERVER_PROPS = /* @__PURE__ */ Symbol.for("fluixi.serverProps");
|
|
289
|
+
var ELEMENT_RENDERER = /* @__PURE__ */ Symbol.for("fluixi.serverElementRenderer");
|
|
290
|
+
var RENDER_ON_SERVER = /* @__PURE__ */ Symbol.for("fluixi.renderOnServer");
|
|
291
|
+
var OWNS_CONTENT = /* @__PURE__ */ Symbol.for("fluixi.ownsContent");
|
|
292
|
+
var SSR_ATTRIBUTE = "data-fx-ssr";
|
|
293
|
+
var SSR_PROPS_ATTRIBUTE = "data-fx-props";
|
|
294
|
+
function isPlainData(value, seen = /* @__PURE__ */ new Set()) {
|
|
295
|
+
if (value === null) return true;
|
|
296
|
+
switch (typeof value) {
|
|
297
|
+
case "string":
|
|
298
|
+
case "number":
|
|
299
|
+
case "boolean":
|
|
300
|
+
return true;
|
|
301
|
+
case "object":
|
|
302
|
+
break;
|
|
303
|
+
default:
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
const object = value;
|
|
307
|
+
if (seen.has(object)) return false;
|
|
308
|
+
seen.add(object);
|
|
309
|
+
const proto = Object.getPrototypeOf(object);
|
|
310
|
+
if (Array.isArray(object)) return object.every((item) => isPlainData(item, seen));
|
|
311
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
312
|
+
return Object.values(object).every((item) => isPlainData(item, seen));
|
|
313
|
+
}
|
|
314
|
+
var BaseElement = typeof HTMLElement === "undefined" ? class {
|
|
315
|
+
} : HTMLElement;
|
|
316
|
+
if (typeof HTMLElement === "undefined" && typeof globalThis.customElements === "undefined") {
|
|
317
|
+
const defined2 = /* @__PURE__ */ new Map();
|
|
318
|
+
globalThis.customElements = {
|
|
319
|
+
define: (name, constructor) => void defined2.set(name, constructor),
|
|
320
|
+
get: (name) => defined2.get(name),
|
|
321
|
+
getName: (constructor) => [...defined2].find(([, c]) => c === constructor)?.[0] ?? null,
|
|
322
|
+
upgrade: () => {
|
|
323
|
+
},
|
|
324
|
+
// Never resolves: nothing is ever upgraded on a server.
|
|
325
|
+
whenDefined: () => new Promise(() => {
|
|
326
|
+
})
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
var prepared = /* @__PURE__ */ new WeakSet();
|
|
330
|
+
function shadowInit(shadow) {
|
|
331
|
+
if (shadow === true) return { mode: "open" };
|
|
332
|
+
if (typeof shadow === "string") return { mode: shadow };
|
|
333
|
+
return { mode: "open", ...shadow };
|
|
334
|
+
}
|
|
335
|
+
function schemaOf(constructor) {
|
|
336
|
+
const chain = [];
|
|
337
|
+
for (let c = constructor; c && c !== HTMLReactiveElement; c = Object.getPrototypeOf(c)) {
|
|
338
|
+
if (Object.prototype.hasOwnProperty.call(c, "props")) chain.unshift(c.props ?? {});
|
|
339
|
+
}
|
|
340
|
+
return Object.assign({}, ...chain);
|
|
341
|
+
}
|
|
342
|
+
function prepare(constructor) {
|
|
343
|
+
if (prepared.has(constructor)) return;
|
|
344
|
+
prepared.add(constructor);
|
|
345
|
+
const observed = constructor.observedAttributes ?? [];
|
|
346
|
+
const missing = observedFrom(schemaOf(constructor)).filter((a) => !observed.includes(a));
|
|
347
|
+
if (missing.length) {
|
|
348
|
+
console.warn(
|
|
349
|
+
`[fluixi] ${constructor.name}.observedAttributes leaves out ${missing.join(", ")}, so those props no longer follow their attributes. A class or mixin that adds its own should return [...super.observedAttributes, ...].`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
for (const name of Object.keys(schemaOf(constructor))) {
|
|
353
|
+
Object.defineProperty(constructor.prototype, name, {
|
|
354
|
+
configurable: true,
|
|
355
|
+
enumerable: true,
|
|
356
|
+
get() {
|
|
357
|
+
return stateOf(this, name).read();
|
|
358
|
+
},
|
|
359
|
+
set(value) {
|
|
360
|
+
writeFromOutside(this, name, value);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
var stateOf;
|
|
366
|
+
var writeFromOutside;
|
|
367
|
+
var _deferred, _HTMLReactiveElement_instances, writeFromOutside_fn, _statesCache, _carried, _dispose, _root, _authored, _built, _waiting, _waited, _handed, _hydrating, _pendingDispose, _reflecting, _internals, _scope, _targets, _dispatch, _creator, _rootOwner, states_fn, reactiveScope_fn, adoptOwnProps_fn, _HTMLReactiveElement_static, renderOnServer_fn, build_fn, startReflecting_fn, shouldWaitForHost_fn, waitForHost_fn, adoptOwner_fn, teardown_fn;
|
|
368
|
+
var _HTMLReactiveElement = class _HTMLReactiveElement extends BaseElement {
|
|
369
|
+
constructor() {
|
|
370
|
+
super();
|
|
371
|
+
__privateAdd(this, _HTMLReactiveElement_instances);
|
|
372
|
+
/**
|
|
373
|
+
* Props written while the app hydrates around an element already built, applied once it is
|
|
374
|
+
* done. The page hydrates inside a batch whose effects run before hydration ends: an update
|
|
375
|
+
* run there builds the element's new content while server nodes are still being claimed,
|
|
376
|
+
* and its templates claimed the page's nodes as their own (the page's frame moved into the
|
|
377
|
+
* element). Until then the element shows what it adopted from the server.
|
|
378
|
+
*/
|
|
379
|
+
__privateAdd(this, _deferred, null);
|
|
380
|
+
__privateAdd(this, _statesCache, null);
|
|
381
|
+
/** Prop values kept across a real removal, for the signals the next scope re-creates. */
|
|
382
|
+
__privateAdd(this, _carried, null);
|
|
383
|
+
__privateAdd(this, _dispose, null);
|
|
384
|
+
__privateAdd(this, _root, this);
|
|
385
|
+
__privateAdd(this, _authored, []);
|
|
386
|
+
__privateAdd(this, _built, false);
|
|
387
|
+
/** Server-rendered and waiting for the app to hand over an owner; cancels the wait. */
|
|
388
|
+
__privateAdd(this, _waiting, null);
|
|
389
|
+
/** The wait ran once; whatever it found, the next build goes ahead. */
|
|
390
|
+
__privateAdd(this, _waited, false);
|
|
391
|
+
/**
|
|
392
|
+
* A template or hydration handed the owner over. An upgrade reads whatever owner happens to be
|
|
393
|
+
* current (a module evaluating inside a route preload), which is not this element's host.
|
|
394
|
+
*/
|
|
395
|
+
__privateAdd(this, _handed, false);
|
|
396
|
+
/** The first build adopts content the server rendered. */
|
|
397
|
+
__privateAdd(this, _hydrating, false);
|
|
398
|
+
/**
|
|
399
|
+
* Disposal is deferred because `disconnectedCallback` cannot tell a removal from a move.
|
|
400
|
+
* Appending an already-parented node fires disconnect then connect in the same task, and
|
|
401
|
+
* tearing the scope down in between would rebuild the subtree on every reorder, which a
|
|
402
|
+
* keyed list does constantly.
|
|
403
|
+
*/
|
|
404
|
+
__privateAdd(this, _pendingDispose, null);
|
|
405
|
+
/** Suppresses the attribute callback a reflect triggers, so it does not loop. */
|
|
406
|
+
__privateAdd(this, _reflecting, /* @__PURE__ */ new Set());
|
|
407
|
+
__privateAdd(this, _internals, null);
|
|
408
|
+
/**
|
|
409
|
+
* What the devtools graph groups this element's signals under. Opened when the element
|
|
410
|
+
* first needs one, closed when it is really removed.
|
|
411
|
+
*/
|
|
412
|
+
__privateAdd(this, _scope, null);
|
|
413
|
+
__privateAdd(this, _targets, null);
|
|
414
|
+
__privateAdd(this, _dispatch, null);
|
|
415
|
+
/** The owner the element was created under, for context: a Fluixi template, or none. */
|
|
416
|
+
__privateAdd(this, _creator, (0, import_signal3.getOwner)());
|
|
417
|
+
/** The owner `render()` runs under, while built. Its parent is the creator. */
|
|
418
|
+
__privateAdd(this, _rootOwner, null);
|
|
419
|
+
prepare(new.target);
|
|
420
|
+
const handed = Object.getOwnPropertyDescriptor(this, OWNER_KEY);
|
|
421
|
+
if (handed) {
|
|
422
|
+
delete this[OWNER_KEY];
|
|
423
|
+
__privateSet(this, _creator, handed.value ?? __privateGet(this, _creator));
|
|
424
|
+
__privateSet(this, _handed, handed.value != null);
|
|
425
|
+
}
|
|
426
|
+
__privateMethod(this, _HTMLReactiveElement_instances, adoptOwnProps_fn).call(this);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* The attributes of every declared prop. A mixin in between that observes its own
|
|
430
|
+
* extends this with `super.observedAttributes`; a subclass need not touch it.
|
|
431
|
+
*/
|
|
432
|
+
static get observedAttributes() {
|
|
433
|
+
prepare(this);
|
|
434
|
+
return observedFrom(schemaOf(this));
|
|
435
|
+
}
|
|
436
|
+
connectedCallback() {
|
|
437
|
+
Object.getPrototypeOf(_HTMLReactiveElement.prototype).connectedCallback?.call(this);
|
|
438
|
+
if (__privateGet(this, _pendingDispose) !== null) {
|
|
439
|
+
clearTimeout(__privateGet(this, _pendingDispose));
|
|
440
|
+
__privateSet(this, _pendingDispose, null);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
__privateMethod(this, _HTMLReactiveElement_instances, adoptOwnProps_fn).call(this, true);
|
|
444
|
+
if (!__privateGet(this, _built) && !__privateGet(this, _waiting)) __privateMethod(this, _HTMLReactiveElement_instances, build_fn).call(this);
|
|
445
|
+
}
|
|
446
|
+
disconnectedCallback() {
|
|
447
|
+
Object.getPrototypeOf(_HTMLReactiveElement.prototype).disconnectedCallback?.call(this);
|
|
448
|
+
if (!__privateGet(this, _built) || __privateGet(this, _pendingDispose) !== null) return;
|
|
449
|
+
__privateSet(this, _pendingDispose, setTimeout(() => {
|
|
450
|
+
__privateSet(this, _pendingDispose, null);
|
|
451
|
+
__privateMethod(this, _HTMLReactiveElement_instances, teardown_fn).call(this);
|
|
452
|
+
}, 0));
|
|
453
|
+
}
|
|
454
|
+
/** Another document, the same scope: nothing reactive depends on which document holds the node. */
|
|
455
|
+
adoptedCallback() {
|
|
456
|
+
Object.getPrototypeOf(_HTMLReactiveElement.prototype).adoptedCallback?.call(this);
|
|
457
|
+
}
|
|
458
|
+
attributeChangedCallback(name, previous, value) {
|
|
459
|
+
Object.getPrototypeOf(_HTMLReactiveElement.prototype).attributeChangedCallback?.call(
|
|
460
|
+
this,
|
|
461
|
+
name,
|
|
462
|
+
previous,
|
|
463
|
+
value
|
|
464
|
+
);
|
|
465
|
+
if (__privateGet(this, _reflecting).has(name)) return;
|
|
466
|
+
for (const [prop, state] of Object.entries(__privateMethod(this, _HTMLReactiveElement_instances, states_fn).call(this))) {
|
|
467
|
+
if (state.attribute !== name) continue;
|
|
468
|
+
__privateMethod(this, _HTMLReactiveElement_instances, writeFromOutside_fn).call(this, prop, value, () => state.write(state.declaration.fromAttribute(value)));
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* What the element shows. Runs once, on the first connect, inside the element's reactive
|
|
474
|
+
* scope; bindings keep it current after that. It is never re-run, so read a prop inside a
|
|
475
|
+
* binding (`() => this.step`), not in the body, to follow it.
|
|
476
|
+
*/
|
|
477
|
+
render() {
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Give `context` to the elements inside this one, and to `useContext` in the components it
|
|
482
|
+
* renders. A value or an accessor; subscribed consumers follow the accessor. Call in `render()`.
|
|
483
|
+
*/
|
|
484
|
+
provide(context, value) {
|
|
485
|
+
provideContext(this, context, value);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* The nearest value of `context` above this element, as an accessor: an element providing
|
|
489
|
+
* it, else the Fluixi app the element was rendered in, else the default. Call in `render()`.
|
|
490
|
+
*/
|
|
491
|
+
consume(context, options) {
|
|
492
|
+
return consumeContext(this, context, options);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Dispatch a `CustomEvent`, bubbling and composed by default. False when cancelled.
|
|
496
|
+
*
|
|
497
|
+
* The name goes out lowercased: a JSX handler listens for the name after `on`, lowercased,
|
|
498
|
+
* so `emit('signOut')` reaches `onSignOut`, and a listener added by hand uses `signout`.
|
|
499
|
+
*/
|
|
500
|
+
emit(type, detail, init) {
|
|
501
|
+
__privateGet(this, _dispatch) ?? __privateSet(this, _dispatch, createDispatch(this));
|
|
502
|
+
return __privateGet(this, _dispatch).call(this, type.toLowerCase(), detail, init);
|
|
503
|
+
}
|
|
504
|
+
/** Elements inside this one, by `data-target`, scoped to its render root. */
|
|
505
|
+
get targets() {
|
|
506
|
+
return __privateGet(this, _targets) ?? __privateSet(this, _targets, createTargets(() => __privateGet(this, _root)));
|
|
507
|
+
}
|
|
508
|
+
/** Where `render()` output goes: the shadow root, or the element itself in light DOM. */
|
|
509
|
+
get renderRoot() {
|
|
510
|
+
return __privateGet(this, _root);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* The children the author wrote between the tags, in light DOM. Empty under shadow DOM,
|
|
514
|
+
* where the browser projects them through `<slot>` and they were never the element's to place.
|
|
515
|
+
*/
|
|
516
|
+
get authoredChildren() {
|
|
517
|
+
return __privateGet(this, _authored);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The element's `ElementInternals`, attached on first use: ARIA defaults, custom states,
|
|
521
|
+
* and with `static formAssociated = true`, taking part in a `<form>`.
|
|
522
|
+
*/
|
|
523
|
+
get internals() {
|
|
524
|
+
return __privateGet(this, _internals) ?? __privateSet(this, _internals, this.attachInternals());
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Render a light DOM element's content into its server node, under the page's owner so its
|
|
528
|
+
* context and resources are the page's. Props come from what @fluixi/dom recorded on the
|
|
529
|
+
* node; the ones with no attribute form ride along as JSON for the client. Shadow DOM
|
|
530
|
+
* elements are left to the client until declarative shadow roots are emitted.
|
|
531
|
+
*/
|
|
532
|
+
static [RENDER_ON_SERVER](node) {
|
|
533
|
+
var _a;
|
|
534
|
+
__privateMethod(_a = _HTMLReactiveElement, _HTMLReactiveElement_static, renderOnServer_fn).call(_a, this, node);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
_deferred = new WeakMap();
|
|
538
|
+
_HTMLReactiveElement_instances = new WeakSet();
|
|
539
|
+
writeFromOutside_fn = function(name, value, apply = () => stateOf(this, name).write(value)) {
|
|
540
|
+
if (!__privateGet(this, _built) || !(0, import_dom2.isAppHydrationPending)()) {
|
|
541
|
+
apply();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (!__privateGet(this, _deferred)) {
|
|
545
|
+
__privateSet(this, _deferred, /* @__PURE__ */ new Map());
|
|
546
|
+
(0, import_dom2.whenAppHydrated)(() => {
|
|
547
|
+
const pending = __privateGet(this, _deferred);
|
|
548
|
+
__privateSet(this, _deferred, null);
|
|
549
|
+
for (const write of pending?.values() ?? []) write();
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
__privateGet(this, _deferred).set(name, apply);
|
|
553
|
+
};
|
|
554
|
+
_statesCache = new WeakMap();
|
|
555
|
+
_carried = new WeakMap();
|
|
556
|
+
_dispose = new WeakMap();
|
|
557
|
+
_root = new WeakMap();
|
|
558
|
+
_authored = new WeakMap();
|
|
559
|
+
_built = new WeakMap();
|
|
560
|
+
_waiting = new WeakMap();
|
|
561
|
+
_waited = new WeakMap();
|
|
562
|
+
_handed = new WeakMap();
|
|
563
|
+
_hydrating = new WeakMap();
|
|
564
|
+
_pendingDispose = new WeakMap();
|
|
565
|
+
_reflecting = new WeakMap();
|
|
566
|
+
_internals = new WeakMap();
|
|
567
|
+
_scope = new WeakMap();
|
|
568
|
+
_targets = new WeakMap();
|
|
569
|
+
_dispatch = new WeakMap();
|
|
570
|
+
_creator = new WeakMap();
|
|
571
|
+
_rootOwner = new WeakMap();
|
|
572
|
+
states_fn = function() {
|
|
573
|
+
if (__privateGet(this, _statesCache)) return __privateGet(this, _statesCache);
|
|
574
|
+
const states = (0, import_signal3.withReactiveScope)(__privateMethod(this, _HTMLReactiveElement_instances, reactiveScope_fn).call(this), () => createPropStates(schemaOf(this.constructor)));
|
|
575
|
+
if (__privateGet(this, _carried)) {
|
|
576
|
+
for (const [name, value] of Object.entries(__privateGet(this, _carried))) states[name]?.write(value);
|
|
577
|
+
__privateSet(this, _carried, null);
|
|
578
|
+
}
|
|
579
|
+
return __privateSet(this, _statesCache, states);
|
|
580
|
+
};
|
|
581
|
+
reactiveScope_fn = function() {
|
|
582
|
+
return __privateGet(this, _scope) ?? __privateSet(this, _scope, (0, import_signal3.openReactiveScope)({
|
|
583
|
+
kind: "element",
|
|
584
|
+
name: `<${this.localName}>`,
|
|
585
|
+
target: this,
|
|
586
|
+
// The class, since the line that opened the scope is this package's, not the app's.
|
|
587
|
+
detail: this.constructor.name
|
|
588
|
+
}));
|
|
589
|
+
};
|
|
590
|
+
adoptOwnProps_fn = function(warn = false) {
|
|
591
|
+
for (const name of Object.keys(schemaOf(this.constructor))) {
|
|
592
|
+
if (!Object.prototype.hasOwnProperty.call(this, name)) continue;
|
|
593
|
+
const value = this[name];
|
|
594
|
+
delete this[name];
|
|
595
|
+
if (warn) {
|
|
596
|
+
console.warn(
|
|
597
|
+
`[fluixi] <${this.localName}> has a class field named "${name}", which hides the declared prop. Declare it only in static props, and set a default there.`
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
__privateMethod(this, _HTMLReactiveElement_instances, states_fn).call(this)[name].write(value);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
_HTMLReactiveElement_static = new WeakSet();
|
|
604
|
+
renderOnServer_fn = function(constructor, node) {
|
|
605
|
+
var _a;
|
|
606
|
+
if (constructor.shadow !== void 0 && constructor.shadow !== false) return;
|
|
607
|
+
const element = new constructor();
|
|
608
|
+
const recorded = node[SERVER_PROPS] ?? {};
|
|
609
|
+
const carried = {};
|
|
610
|
+
for (const [name, state] of Object.entries(__privateMethod(_a = element, _HTMLReactiveElement_instances, states_fn).call(_a))) {
|
|
611
|
+
if (name in recorded) {
|
|
612
|
+
const value = recorded[name];
|
|
613
|
+
state.write(value);
|
|
614
|
+
if (value !== null && typeof value === "object" && isPlainData(value)) carried[name] = value;
|
|
615
|
+
} else if (state.attribute !== false) {
|
|
616
|
+
const attribute = node.getAttribute(state.attribute);
|
|
617
|
+
if (attribute !== null) state.write(state.declaration.fromAttribute(attribute));
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
__privateSet(element, _authored, [...node.childNodes]);
|
|
621
|
+
for (const child of __privateGet(element, _authored)) node.removeChild(child);
|
|
622
|
+
__privateSet(element, _root, node);
|
|
623
|
+
__privateSet(element, _built, true);
|
|
624
|
+
const scope = `${node.getAttribute(import_dom2.HYDRATION_KEY) ?? ""}~`;
|
|
625
|
+
const createdIn = node[OWNER_KEY] ?? null;
|
|
626
|
+
(0, import_signal3.runWithOwner)(
|
|
627
|
+
createdIn,
|
|
628
|
+
() => (0, import_signal3.root)(() => {
|
|
629
|
+
(0, import_dom2.setKeyScope)(scope);
|
|
630
|
+
(0, import_dom2.insert)(node, element.render());
|
|
631
|
+
})
|
|
632
|
+
);
|
|
633
|
+
node.setAttribute(SSR_ATTRIBUTE, "");
|
|
634
|
+
if (Object.keys(carried).length) {
|
|
635
|
+
try {
|
|
636
|
+
node.setAttribute(SSR_PROPS_ATTRIBUTE, JSON.stringify(carried));
|
|
637
|
+
} catch {
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
build_fn = function() {
|
|
642
|
+
if (__privateMethod(this, _HTMLReactiveElement_instances, shouldWaitForHost_fn).call(this)) return __privateMethod(this, _HTMLReactiveElement_instances, waitForHost_fn).call(this);
|
|
643
|
+
__privateSet(this, _built, true);
|
|
644
|
+
const constructor = this.constructor;
|
|
645
|
+
const shadow = constructor.shadow;
|
|
646
|
+
if (shadow !== void 0 && shadow !== false) {
|
|
647
|
+
__privateSet(this, _root, this.shadowRoot ?? this.attachShadow(shadowInit(shadow)));
|
|
648
|
+
applyStyles(__privateGet(this, _root), constructor, constructor.styles);
|
|
649
|
+
} else if (this.hasAttribute(SSR_ATTRIBUTE)) {
|
|
650
|
+
__privateSet(this, _hydrating, true);
|
|
651
|
+
const json = this.getAttribute(SSR_PROPS_ATTRIBUTE);
|
|
652
|
+
if (json) {
|
|
653
|
+
try {
|
|
654
|
+
const states = __privateMethod(this, _HTMLReactiveElement_instances, states_fn).call(this);
|
|
655
|
+
for (const [name, value] of Object.entries(JSON.parse(json))) states[name]?.write(value);
|
|
656
|
+
} catch {
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
this.removeAttribute(SSR_ATTRIBUTE);
|
|
660
|
+
this.removeAttribute(SSR_PROPS_ATTRIBUTE);
|
|
661
|
+
this[OWNS_CONTENT] = true;
|
|
662
|
+
__privateSet(this, _root, this);
|
|
663
|
+
} else {
|
|
664
|
+
__privateSet(this, _authored, Array.from(this.childNodes));
|
|
665
|
+
for (const node of __privateGet(this, _authored)) node.remove();
|
|
666
|
+
__privateSet(this, _root, this);
|
|
667
|
+
}
|
|
668
|
+
const creator = __privateGet(this, _creator) ?? (0, import_signal3.getOwner)();
|
|
669
|
+
(0, import_signal3.runWithOwner)(null, () => (0, import_signal3.withReactiveScope)(
|
|
670
|
+
__privateMethod(this, _HTMLReactiveElement_instances, reactiveScope_fn).call(this),
|
|
671
|
+
() => (0, import_signal3.root)((dispose) => {
|
|
672
|
+
const own = (0, import_signal3.getOwner)();
|
|
673
|
+
__privateSet(this, _rootOwner, own);
|
|
674
|
+
if (own && creator) own.parent = creator;
|
|
675
|
+
__privateSet(this, _dispose, dispose);
|
|
676
|
+
__privateMethod(this, _HTMLReactiveElement_instances, startReflecting_fn).call(this);
|
|
677
|
+
if (__privateGet(this, _hydrating)) {
|
|
678
|
+
(0, import_dom2.setKeyScope)(`${this.getAttribute(import_dom2.HYDRATION_KEY) ?? ""}~`);
|
|
679
|
+
(0, import_dom2.hydrateChildren)(this, () => this.render());
|
|
680
|
+
} else (0, import_dom2.insert)(__privateGet(this, _root), this.render());
|
|
681
|
+
__privateSet(this, _hydrating, false);
|
|
682
|
+
})
|
|
683
|
+
));
|
|
684
|
+
const shown = (node) => node.nodeType === 1 || node.nodeType === 3 && node.textContent?.trim();
|
|
685
|
+
if (__privateGet(this, _root) === this && __privateGet(this, _authored).some((node) => shown(node) && !node.isConnected)) {
|
|
686
|
+
console.warn(
|
|
687
|
+
`[fluixi] <${this.localName}> has children between its tags that its render() does not place, so they are not shown. Place this.authoredChildren in render(), or use shadow DOM with a <slot>.`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
startReflecting_fn = function() {
|
|
692
|
+
for (const state of Object.values(__privateMethod(this, _HTMLReactiveElement_instances, states_fn).call(this))) {
|
|
693
|
+
const attribute = state.attribute;
|
|
694
|
+
if (attribute === false || !state.declaration.reflect) continue;
|
|
695
|
+
(0, import_signal3.effect)(() => {
|
|
696
|
+
const next = state.declaration.toAttribute(state.read());
|
|
697
|
+
__privateGet(this, _reflecting).add(attribute);
|
|
698
|
+
try {
|
|
699
|
+
if (next === null) this.removeAttribute(attribute);
|
|
700
|
+
else this.setAttribute(attribute, next);
|
|
701
|
+
} finally {
|
|
702
|
+
__privateGet(this, _reflecting).delete(attribute);
|
|
703
|
+
}
|
|
704
|
+
}, void 0, { name: `reflect ${attribute}` });
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* Hydration found this element after it had already rendered, as a server-rendered one does:
|
|
709
|
+
* link the render to the app now, so what it provides reaches the element. Consumers that
|
|
710
|
+
* found nothing are told to look again.
|
|
711
|
+
*/
|
|
712
|
+
/**
|
|
713
|
+
* Rendered by the server inside an app, and upgraded before that app hydrated: nothing
|
|
714
|
+
* above it yet, so a context read in its first render would find nothing. Light DOM only;
|
|
715
|
+
* a shadow root is built by the client.
|
|
716
|
+
*/
|
|
717
|
+
shouldWaitForHost_fn = function() {
|
|
718
|
+
const shadow = this.constructor.shadow;
|
|
719
|
+
return !__privateGet(this, _waited) && !__privateGet(this, _handed) && (shadow === void 0 || shadow === false) && this.hasAttribute(SSR_ATTRIBUTE);
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* Wait a microtask, so an entry module that imported this element has called `startClient`.
|
|
723
|
+
* Then build when the app hands over an owner, or when its hydration ends without reaching
|
|
724
|
+
* this element. No app hydrating (a static page, another framework): build now.
|
|
725
|
+
*/
|
|
726
|
+
waitForHost_fn = function() {
|
|
727
|
+
let cancelled = false;
|
|
728
|
+
let stop = () => {
|
|
729
|
+
};
|
|
730
|
+
__privateSet(this, _waiting, () => {
|
|
731
|
+
cancelled = true;
|
|
732
|
+
stop();
|
|
733
|
+
});
|
|
734
|
+
const resume = () => {
|
|
735
|
+
if (cancelled) return;
|
|
736
|
+
__privateSet(this, _waiting, null);
|
|
737
|
+
__privateSet(this, _waited, true);
|
|
738
|
+
if (!__privateGet(this, _built) && this.isConnected) __privateMethod(this, _HTMLReactiveElement_instances, build_fn).call(this);
|
|
739
|
+
};
|
|
740
|
+
queueMicrotask(() => {
|
|
741
|
+
if (cancelled) return;
|
|
742
|
+
if ((0, import_dom2.isAppHydrationPending)()) stop = (0, import_dom2.whenAppHydrated)(resume);
|
|
743
|
+
else resume();
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
adoptOwner_fn = function(owner) {
|
|
747
|
+
if (!owner || __privateGet(this, _handed)) return;
|
|
748
|
+
__privateSet(this, _handed, true);
|
|
749
|
+
__privateSet(this, _creator, owner);
|
|
750
|
+
if (__privateGet(this, _waiting)) {
|
|
751
|
+
__privateGet(this, _waiting).call(this);
|
|
752
|
+
__privateSet(this, _waiting, null);
|
|
753
|
+
if (this.isConnected) __privateMethod(this, _HTMLReactiveElement_instances, build_fn).call(this);
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (!__privateGet(this, _rootOwner)) return;
|
|
757
|
+
__privateGet(this, _rootOwner).parent = owner;
|
|
758
|
+
announceOwner(this);
|
|
759
|
+
};
|
|
760
|
+
teardown_fn = function() {
|
|
761
|
+
var _a;
|
|
762
|
+
(_a = __privateGet(this, _dispose)) == null ? void 0 : _a.call(this);
|
|
763
|
+
__privateSet(this, _dispose, null);
|
|
764
|
+
__privateSet(this, _rootOwner, null);
|
|
765
|
+
__privateSet(this, _built, false);
|
|
766
|
+
if (__privateGet(this, _scope)) (0, import_signal3.closeReactiveScope)(__privateGet(this, _scope));
|
|
767
|
+
__privateSet(this, _scope, null);
|
|
768
|
+
if (__privateGet(this, _statesCache)) {
|
|
769
|
+
__privateSet(this, _carried, Object.fromEntries(Object.entries(__privateGet(this, _statesCache)).map(([name, state]) => [name, state.read()])));
|
|
770
|
+
__privateSet(this, _statesCache, null);
|
|
771
|
+
}
|
|
772
|
+
if (__privateGet(this, _root) === this) {
|
|
773
|
+
this.textContent = "";
|
|
774
|
+
for (const node of __privateGet(this, _authored)) this.appendChild(node);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
__privateAdd(_HTMLReactiveElement, _HTMLReactiveElement_static);
|
|
778
|
+
(() => {
|
|
779
|
+
Object.defineProperty(_HTMLReactiveElement.prototype, OWNER_KEY, {
|
|
780
|
+
configurable: true,
|
|
781
|
+
get() {
|
|
782
|
+
return __privateGet(this, _creator);
|
|
783
|
+
},
|
|
784
|
+
set(owner) {
|
|
785
|
+
__privateMethod(this, _HTMLReactiveElement_instances, adoptOwner_fn).call(this, owner);
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
if (typeof HTMLElement === "undefined") {
|
|
789
|
+
globalThis[ELEMENT_RENDERER] ??= (node) => {
|
|
790
|
+
const registry2 = globalThis.customElements;
|
|
791
|
+
const constructor = registry2?.get(node.localName);
|
|
792
|
+
constructor?.[RENDER_ON_SERVER]?.(node);
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
stateOf = (element, name) => {
|
|
796
|
+
var _a;
|
|
797
|
+
const state = __privateMethod(_a = element, _HTMLReactiveElement_instances, states_fn).call(_a)[name];
|
|
798
|
+
if (!state) throw new Error(`[fluixi] ${name} is not a declared prop of <${element.localName}>`);
|
|
799
|
+
return state;
|
|
800
|
+
};
|
|
801
|
+
writeFromOutside = (element, name, value) => {
|
|
802
|
+
var _a;
|
|
803
|
+
return __privateMethod(_a = element, _HTMLReactiveElement_instances, writeFromOutside_fn).call(_a, name, value);
|
|
804
|
+
};
|
|
805
|
+
})();
|
|
806
|
+
var HTMLReactiveElement = _HTMLReactiveElement;
|
|
807
|
+
function typedElement(props) {
|
|
808
|
+
class Typed extends HTMLReactiveElement {
|
|
809
|
+
}
|
|
810
|
+
Typed.props = props;
|
|
811
|
+
return Typed;
|
|
812
|
+
}
|
|
813
|
+
function createElementClass(setup, options = {}) {
|
|
814
|
+
let Base = HTMLReactiveElement;
|
|
815
|
+
for (const mixin of options.mixins ?? []) Base = mixin(Base);
|
|
816
|
+
class SetupElement extends Base {
|
|
817
|
+
render() {
|
|
818
|
+
const accessors = {};
|
|
819
|
+
for (const name of Object.keys(schemaOf(this.constructor))) {
|
|
820
|
+
accessors[name] = () => this[name];
|
|
821
|
+
}
|
|
822
|
+
return setup({
|
|
823
|
+
el: this,
|
|
824
|
+
props: accessors,
|
|
825
|
+
set: (name, value) => {
|
|
826
|
+
this[name] = value;
|
|
827
|
+
},
|
|
828
|
+
dispatch: (type, detail, init) => this.emit(type, detail, init),
|
|
829
|
+
targets: this.targets,
|
|
830
|
+
children: () => [...this.authoredChildren],
|
|
831
|
+
provide: (context, value) => this.provide(context, value),
|
|
832
|
+
consume: (context, options2) => this.consume(context, options2)
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
SetupElement.props = options.props ?? {};
|
|
837
|
+
SetupElement.shadow = options.shadow;
|
|
838
|
+
SetupElement.styles = options.styles;
|
|
839
|
+
return SetupElement;
|
|
840
|
+
}
|
|
841
|
+
function defineElement(name, setup, options = {}) {
|
|
842
|
+
const constructor = createElementClass(setup, options);
|
|
843
|
+
const className = name.replace(/(^|-)([a-z0-9])/g, (_, _dash, ch) => ch.toUpperCase());
|
|
844
|
+
Object.defineProperty(constructor, "name", { value: className, configurable: true });
|
|
845
|
+
if ((0, import_dom2.isServer)()) return constructor;
|
|
846
|
+
return defineCustomElement(name, constructor, options.define);
|
|
847
|
+
}
|