revojs 0.0.35 → 0.0.36
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/html/index.d.ts +17 -9
- package/dist/index.js +142 -126
- package/dist/jsx/index.js +8 -6
- package/dist/router/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type TypeOf<T> = {
|
|
|
5
5
|
};
|
|
6
6
|
export type Infer<T> = T extends TypeOf<infer U> ? U : unknown;
|
|
7
7
|
export type Slot = unknown | Template | Array<Slot> | (() => Slot);
|
|
8
|
+
export type Hydration = Comment | Text | Element | Array<Hydration>;
|
|
8
9
|
export type EventListener<T extends Event> = ((event: T) => void) | Array<(event: T) => void>;
|
|
9
10
|
export type Template = {
|
|
10
11
|
tag: string;
|
|
@@ -63,6 +64,7 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
|
|
|
63
64
|
new (input?: Input<TEvents, TAttributes>, scope?: Scope, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
|
|
64
65
|
}
|
|
65
66
|
export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
|
|
67
|
+
readonly internals: ElementInternals;
|
|
66
68
|
readonly component: Component<TEvents, TAttributes>;
|
|
67
69
|
}
|
|
68
70
|
export interface CustomElementConstructor<TEvents extends Events, TAttributes extends Attributes> {
|
|
@@ -71,18 +73,23 @@ export interface CustomElementConstructor<TEvents extends Events, TAttributes ex
|
|
|
71
73
|
export declare class MountedEvent extends Event {
|
|
72
74
|
constructor();
|
|
73
75
|
}
|
|
74
|
-
export declare const isTemplate: (value
|
|
76
|
+
export declare const isTemplate: (value?: any) => value is Template;
|
|
75
77
|
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
76
78
|
export declare const toString: (slot: Slot) => string;
|
|
77
|
-
export declare const
|
|
79
|
+
export declare const isTextNode: (hydration?: Hydration) => hydration is Text;
|
|
80
|
+
export declare const isCommentNode: (hydration?: Hydration) => hydration is Comment;
|
|
81
|
+
export declare const isElementNode: (hydration?: Hydration, tagName?: string) => hydration is Element;
|
|
82
|
+
export declare const toArray: (hydration: Hydration) => Array<Node>;
|
|
83
|
+
export declare const toRange: (hydration: Hydration) => Range;
|
|
84
|
+
export declare const toFragment: (hydration: Hydration) => DocumentFragment;
|
|
85
|
+
export declare const hydrate: (scope: Scope, parentNode: Node, slot: Slot, index: number, previous?: Hydration) => Promise<Hydration>;
|
|
78
86
|
export declare const renderToString: (scope: Scope, slot: Slot) => Promise<string>;
|
|
79
|
-
export declare const
|
|
80
|
-
export declare const
|
|
81
|
-
export declare const
|
|
82
|
-
export declare
|
|
83
|
-
export declare function useEvent<T extends keyof
|
|
84
|
-
export declare function useEvent<T extends keyof
|
|
85
|
-
export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: HTMLElement | undefined, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
87
|
+
export declare const defineComponent: <TEvents extends Events, TAttributes extends Attributes>(options: ComponentOptions<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
|
|
88
|
+
export declare const toCustomElement: <TEvents extends Events, TAttributes extends Attributes>(component: ComponentConstructor<TEvents, TAttributes>) => CustomElementConstructor<TEvents, TAttributes>;
|
|
89
|
+
export declare const registerComponent: <TEvents extends Events, TAttributes extends Attributes>(component: ComponentConstructor<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
|
|
90
|
+
export declare function useEvent<T extends keyof ElementEventMap>(scope: Scope, target: EventTarget | undefined | null, event: T, input: EventListener<ElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
91
|
+
export declare function useEvent<T extends keyof WindowEventMap>(scope: Scope, target: Window | undefined | null, event: T, input: EventListener<WindowEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
92
|
+
export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: HTMLElement | undefined | null, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
86
93
|
export declare const getCustomElement: (node: Node | null) => CustomElement<Events, Attributes> | undefined;
|
|
87
94
|
export declare const isClient: () => boolean;
|
|
88
95
|
export declare const isServer: () => boolean;
|
|
@@ -90,6 +97,7 @@ export declare const preventDefault: (event: Event) => void;
|
|
|
90
97
|
export declare const stopPropagation: (event: Event) => void;
|
|
91
98
|
export declare const stopImmediatePropagation: (event: Event) => void;
|
|
92
99
|
export declare const components: Map<string, ComponentConstructor<Events, Attributes>>;
|
|
100
|
+
export declare const globalStyles: CSSStyleSheet[];
|
|
93
101
|
declare global {
|
|
94
102
|
interface HTMLElementEventMap {
|
|
95
103
|
mounted: MountedEvent;
|
package/dist/index.js
CHANGED
|
@@ -219,19 +219,14 @@ var MountedEvent = class extends Event {
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
const isTemplate = (value) => {
|
|
222
|
-
return "tag" in value && "attributes" in value && "children" in value;
|
|
222
|
+
return typeof value === "object" && "tag" in value && "attributes" in value && "children" in value;
|
|
223
223
|
};
|
|
224
224
|
const createElement = (input, attributes, ...children) => {
|
|
225
|
-
|
|
225
|
+
return {
|
|
226
226
|
tag: typeof input === "function" ? input.$name : input,
|
|
227
227
|
attributes: attributes ?? {},
|
|
228
228
|
children
|
|
229
229
|
};
|
|
230
|
-
if (typeof input === "function") {
|
|
231
|
-
const classes = template.attributes["class"];
|
|
232
|
-
template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
|
|
233
|
-
}
|
|
234
|
-
return template;
|
|
235
230
|
};
|
|
236
231
|
const toString = (slot) => {
|
|
237
232
|
switch (typeof slot) {
|
|
@@ -245,116 +240,136 @@ const toString = (slot) => {
|
|
|
245
240
|
default: return "";
|
|
246
241
|
}
|
|
247
242
|
};
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
243
|
+
const isTextNode = (hydration) => {
|
|
244
|
+
if (Array.isArray(hydration)) return false;
|
|
245
|
+
return hydration?.nodeType === Node.TEXT_NODE;
|
|
246
|
+
};
|
|
247
|
+
const isCommentNode = (hydration) => {
|
|
248
|
+
if (Array.isArray(hydration)) return false;
|
|
249
|
+
return hydration?.nodeType === Node.COMMENT_NODE;
|
|
250
|
+
};
|
|
251
|
+
const isElementNode = (hydration, tagName) => {
|
|
252
|
+
if (Array.isArray(hydration)) return false;
|
|
253
|
+
return hydration?.nodeType === Node.ELEMENT_NODE && hydration.nodeName.toUpperCase() === tagName?.toUpperCase();
|
|
254
|
+
};
|
|
255
|
+
const toArray = (hydration) => {
|
|
256
|
+
if (Array.isArray(hydration)) return hydration.reduce((items, child) => items.concat(toArray(child)), new Array());
|
|
257
|
+
else return [hydration];
|
|
258
|
+
};
|
|
259
|
+
const toRange = (hydration) => {
|
|
260
|
+
const items = toArray(hydration);
|
|
261
|
+
const range = document.createRange();
|
|
262
|
+
const firstNode = items.at(0);
|
|
263
|
+
if (firstNode) range.setStartBefore(firstNode);
|
|
264
|
+
const lastNode = items.at(-1);
|
|
265
|
+
if (lastNode) range.setEndAfter(lastNode);
|
|
266
|
+
return range;
|
|
267
|
+
};
|
|
268
|
+
const toFragment = (hydration) => {
|
|
269
|
+
return toArray(hydration).reduce((fragment, node) => {
|
|
270
|
+
fragment.appendChild(node);
|
|
271
|
+
return fragment;
|
|
272
|
+
}, document.createDocumentFragment());
|
|
273
|
+
};
|
|
274
|
+
const hydrate = async (scope, parentNode, slot, index, previous) => {
|
|
275
|
+
let hydration = parentNode.childNodes.item(index);
|
|
276
|
+
if (Array.isArray(slot)) {
|
|
277
|
+
const items = new Array();
|
|
278
|
+
for (const [index$1, childSlot] of slot.entries()) items.push(await hydrate(scope, parentNode, childSlot, index$1));
|
|
279
|
+
if (items.length) hydration = items;
|
|
280
|
+
else if (isCommentNode(hydration) === false) hydration = document.createComment("");
|
|
281
|
+
}
|
|
282
|
+
if (typeof slot === "function") {
|
|
283
|
+
let previous$1;
|
|
284
|
+
await createCompute(scope, async (scope$1) => {
|
|
285
|
+
let input = slot;
|
|
286
|
+
while (typeof input === "function") input = await input();
|
|
287
|
+
hydration = await hydrate(scope$1, parentNode, input, index, previous$1);
|
|
288
|
+
if (previous$1 && hydration !== previous$1) if (Array.isArray(hydration)) if (Array.isArray(previous$1)) {
|
|
289
|
+
const range = toRange(previous$1);
|
|
290
|
+
range.deleteContents();
|
|
291
|
+
for (const childNode of toArray(hydration)) range.insertNode(childNode);
|
|
292
|
+
} else parentNode.replaceChild(toFragment(hydration), previous$1);
|
|
293
|
+
else if (Array.isArray(previous$1)) {
|
|
294
|
+
const range = toRange(previous$1);
|
|
295
|
+
range.deleteContents();
|
|
296
|
+
range.insertNode(hydration);
|
|
297
|
+
} else parentNode.replaceChild(hydration, previous$1);
|
|
298
|
+
previous$1 = hydration;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (slot === null || slot === void 0) {
|
|
302
|
+
if (isCommentNode(hydration) === false) hydration = document.createComment("");
|
|
303
|
+
}
|
|
304
|
+
if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") {
|
|
305
|
+
const textContent = slot.toString();
|
|
306
|
+
if (isTextNode(hydration)) {
|
|
307
|
+
if (previous) hydration.textContent = textContent;
|
|
308
|
+
else if (hydration.textContent !== textContent) parentNode.insertBefore(hydration.splitText(textContent.length), hydration.nextSibling);
|
|
309
|
+
} else hydration = document.createTextNode(textContent);
|
|
310
|
+
}
|
|
311
|
+
if (isTemplate(slot)) {
|
|
312
|
+
const Component = components.get(slot.tag);
|
|
313
|
+
if (Component) registerComponent(Component);
|
|
314
|
+
if (isElementNode(hydration, slot.tag) === false) hydration = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
315
|
+
for (const [name, value] of Object.entries(slot.attributes)) createCompute(scope, (scope$1) => {
|
|
316
|
+
const target = hydration;
|
|
317
|
+
if (name.startsWith("on")) {
|
|
318
|
+
const event = name.substring(2).toLowerCase();
|
|
319
|
+
useEvent(scope$1, target, event, value);
|
|
320
|
+
} else {
|
|
321
|
+
const set = toString(value);
|
|
322
|
+
if (set === "" || set === "false") return target.removeAttribute(name);
|
|
323
|
+
return target.setAttribute(name, set);
|
|
281
324
|
}
|
|
282
|
-
|
|
283
|
-
|
|
325
|
+
});
|
|
326
|
+
for (const [index$1, childSlot] of slot.children.entries()) await hydrate(scope, hydration, childSlot, index$1);
|
|
284
327
|
}
|
|
285
|
-
|
|
328
|
+
hydration ??= document.createComment("");
|
|
329
|
+
if (parentNode.childNodes.item(index) === null) parentNode.appendChild(toFragment(hydration));
|
|
330
|
+
return hydration;
|
|
286
331
|
};
|
|
287
|
-
const
|
|
288
|
-
if (slot)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
parentNode?.appendChild(next);
|
|
320
|
-
}
|
|
321
|
-
} else node?.parentNode?.replaceChild(next, node);
|
|
322
|
-
node = next;
|
|
323
|
-
});
|
|
324
|
-
if (Array.isArray(node)) return toFragment(node);
|
|
325
|
-
return node ?? document.createComment("");
|
|
326
|
-
}
|
|
327
|
-
if (typeof slot === "object") {
|
|
328
|
-
if (Array.isArray(slot)) {
|
|
329
|
-
if (slot.length) {
|
|
330
|
-
const children = await Promise.all(slot.map((child) => renderToNode(scope, child)));
|
|
331
|
-
return toFragment(children);
|
|
332
|
-
}
|
|
333
|
-
return document.createDocumentFragment();
|
|
334
|
-
}
|
|
335
|
-
if (isTemplate(slot)) {
|
|
336
|
-
const element = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
337
|
-
for (const name in slot.attributes) {
|
|
338
|
-
const value = slot.attributes[name];
|
|
339
|
-
if (name.startsWith("on")) {
|
|
340
|
-
const event = name.substring(2).toLowerCase();
|
|
341
|
-
useEvent(scope, element, event, value);
|
|
342
|
-
} else createCompute(scope, () => {
|
|
343
|
-
const set = toString(value);
|
|
344
|
-
if (set === "" || set === "false") return element.removeAttribute(name);
|
|
345
|
-
return element.setAttribute(name, set);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
element.replaceChildren(await renderToNode(scope, slot.children));
|
|
349
|
-
return element;
|
|
350
|
-
}
|
|
351
|
-
return document.createTextNode(JSON.stringify(slot));
|
|
332
|
+
const renderToString = async (scope, slot) => {
|
|
333
|
+
if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") return slot.toString();
|
|
334
|
+
if (typeof slot === "function") {
|
|
335
|
+
let input = slot;
|
|
336
|
+
while (typeof input === "function") input = await input();
|
|
337
|
+
return await renderToString(scope, input);
|
|
338
|
+
}
|
|
339
|
+
if (Array.isArray(slot)) {
|
|
340
|
+
let items = "";
|
|
341
|
+
for (const childSlot of slot) items += await renderToString(scope, childSlot);
|
|
342
|
+
if (items === "") return "<!---->";
|
|
343
|
+
return items;
|
|
344
|
+
}
|
|
345
|
+
if (isTemplate(slot)) {
|
|
346
|
+
const CustomElement = components.get(slot.tag);
|
|
347
|
+
const prefix = Object.entries(slot.attributes).reduce((chunks, [name, value]) => {
|
|
348
|
+
if (value && !name.startsWith("on")) chunks.push(`${name}='${toString(value)}'`);
|
|
349
|
+
return chunks;
|
|
350
|
+
}, [slot.tag]).join(" ");
|
|
351
|
+
let content = `<${prefix}>`;
|
|
352
|
+
if (CustomElement) {
|
|
353
|
+
const element = new CustomElement(slot.attributes, scope);
|
|
354
|
+
scope.onStop(() => element.scope.stop());
|
|
355
|
+
const template = await renderToString(element.scope, await element.setup());
|
|
356
|
+
if (element.shadowRoot) {
|
|
357
|
+
const shadow = {
|
|
358
|
+
tag: "template",
|
|
359
|
+
attributes: { shadowRootMode: element.shadowRoot.mode },
|
|
360
|
+
children: [template]
|
|
361
|
+
};
|
|
362
|
+
content += await renderToString(element.scope, shadow);
|
|
363
|
+
} else content += template;
|
|
352
364
|
}
|
|
365
|
+
for (const childSlot of slot.children) content += await renderToString(scope, childSlot);
|
|
366
|
+
content += `</${slot.tag}>`;
|
|
367
|
+
return content;
|
|
353
368
|
}
|
|
354
|
-
return
|
|
369
|
+
return "<!---->";
|
|
355
370
|
};
|
|
356
371
|
const defineComponent = (options) => {
|
|
357
|
-
|
|
372
|
+
class Instance {
|
|
358
373
|
static $name = options.name;
|
|
359
374
|
static $events = options.events ?? {};
|
|
360
375
|
static $attributes = options.attributes ?? {};
|
|
@@ -388,29 +403,26 @@ const defineComponent = (options) => {
|
|
|
388
403
|
if (parentNode) this.scope.parentScope = parentNode.component.scope;
|
|
389
404
|
return options.setup(this);
|
|
390
405
|
};
|
|
391
|
-
}
|
|
406
|
+
}
|
|
407
|
+
components.set(options.name, Instance);
|
|
408
|
+
return Instance;
|
|
392
409
|
};
|
|
393
410
|
const toCustomElement = (component) => {
|
|
394
411
|
return class extends HTMLElement {
|
|
395
412
|
static formAssociated = true;
|
|
413
|
+
internals;
|
|
396
414
|
component;
|
|
397
415
|
constructor() {
|
|
398
416
|
super();
|
|
417
|
+
this.internals = this.attachInternals();
|
|
399
418
|
this.component = new component(void 0, void 0, this);
|
|
400
419
|
}
|
|
401
420
|
async connectedCallback() {
|
|
402
421
|
let rootNode = this;
|
|
403
422
|
if (this.component.shadowRoot) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const sheet = new CSSStyleSheet();
|
|
408
|
-
const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
|
|
409
|
-
sheet.replaceSync(css);
|
|
410
|
-
return sheet;
|
|
411
|
-
});
|
|
412
|
-
rootNode.adoptedStyleSheets.push(...globalStyles);
|
|
413
|
-
}
|
|
423
|
+
const options = defu(this.component.shadowRoot, { mode: "open" });
|
|
424
|
+
rootNode = this.shadowRoot ?? this.attachShadow(options);
|
|
425
|
+
if (this.component.shadowRoot.globalStyles) rootNode.adoptedStyleSheets = globalStyles;
|
|
414
426
|
}
|
|
415
427
|
for (const [name, event] of Object.entries(component.$events)) Reflect.set(this.component.events, name, (value) => {
|
|
416
428
|
if (value instanceof Event) return;
|
|
@@ -418,8 +430,8 @@ const toCustomElement = (component) => {
|
|
|
418
430
|
...event,
|
|
419
431
|
detail: value
|
|
420
432
|
}));
|
|
421
|
-
}
|
|
422
|
-
|
|
433
|
+
});
|
|
434
|
+
await hydrate(this.component.scope, rootNode, await this.component.setup(), 0);
|
|
423
435
|
this.dispatchEvent(new MountedEvent());
|
|
424
436
|
}
|
|
425
437
|
attributeChangedCallback(name, oldValue, value) {
|
|
@@ -453,7 +465,6 @@ const toCustomElement = (component) => {
|
|
|
453
465
|
};
|
|
454
466
|
};
|
|
455
467
|
const registerComponent = (component) => {
|
|
456
|
-
if (isServer()) components.set(component.$name, component);
|
|
457
468
|
if (isClient()) {
|
|
458
469
|
const previous = customElements.get(component.$name);
|
|
459
470
|
if (previous === void 0) customElements.define(component.$name, toCustomElement(component));
|
|
@@ -483,6 +494,12 @@ const preventDefault = (event) => event.preventDefault();
|
|
|
483
494
|
const stopPropagation = (event) => event.stopPropagation();
|
|
484
495
|
const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
|
|
485
496
|
const components = new Map();
|
|
497
|
+
const globalStyles = Array.from(isClient() ? document.styleSheets : []).map((style) => {
|
|
498
|
+
const sheet = new CSSStyleSheet();
|
|
499
|
+
const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
|
|
500
|
+
sheet.replaceSync(css);
|
|
501
|
+
return sheet;
|
|
502
|
+
});
|
|
486
503
|
|
|
487
504
|
//#endregion
|
|
488
505
|
//#region src/http/index.ts
|
|
@@ -757,7 +774,6 @@ const Page = defineComponent({
|
|
|
757
774
|
shadowRoot: false,
|
|
758
775
|
setup: ({ scope }) => {
|
|
759
776
|
const { route } = scope.getContext(ROUTER_CONTEXT);
|
|
760
|
-
if (route === void 0) return;
|
|
761
777
|
return () => route.value;
|
|
762
778
|
}
|
|
763
779
|
});
|
|
@@ -904,4 +920,4 @@ const markdownToSlot = (input, options) => {
|
|
|
904
920
|
};
|
|
905
921
|
|
|
906
922
|
//#endregion
|
|
907
|
-
export { $fetch, Compute, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createEvent, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, preventDefault, registerComponent,
|
|
923
|
+
export { $fetch, Compute, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createEvent, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, globalStyles, hydrate, isClient, isCommentNode, isElementNode, isServer, isTemplate, isTextNode, markdownToSlot, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useEvent, useLocale, useRouter, useRuntime };
|
package/dist/jsx/index.js
CHANGED
|
@@ -42,17 +42,19 @@ const defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/html/index.ts
|
|
44
44
|
const createElement = (input, attributes, ...children) => {
|
|
45
|
-
|
|
45
|
+
return {
|
|
46
46
|
tag: typeof input === "function" ? input.$name : input,
|
|
47
47
|
attributes: attributes ?? {},
|
|
48
48
|
children
|
|
49
49
|
};
|
|
50
|
-
if (typeof input === "function") {
|
|
51
|
-
const classes = template.attributes["class"];
|
|
52
|
-
template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
|
|
53
|
-
}
|
|
54
|
-
return template;
|
|
55
50
|
};
|
|
51
|
+
const isClient = () => typeof window !== "undefined";
|
|
52
|
+
const globalStyles = Array.from(isClient() ? document.styleSheets : []).map((style) => {
|
|
53
|
+
const sheet = new CSSStyleSheet();
|
|
54
|
+
const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
|
|
55
|
+
sheet.replaceSync(css);
|
|
56
|
+
return sheet;
|
|
57
|
+
});
|
|
56
58
|
|
|
57
59
|
//#endregion
|
|
58
60
|
//#region src/jsx/index.ts
|
package/dist/router/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare const useRouter: <T extends RouterContext>(scope: Scope, context?
|
|
|
36
36
|
navigate: (path: string) => void;
|
|
37
37
|
anchorNavigate: (event: Event) => void;
|
|
38
38
|
};
|
|
39
|
-
export declare const Page: ComponentConstructor<
|
|
39
|
+
export declare const Page: ComponentConstructor<Events, Attributes>;
|
|
40
40
|
declare global {
|
|
41
41
|
interface ElementEventMap {
|
|
42
42
|
navigate: NavigateEvent;
|