revojs 0.0.35 → 0.0.37
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 +143 -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,137 @@ 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 (textContent !== hydration.textContent) hydration = parentNode.replaceChild(document.createTextNode(textContent), hydration);
|
|
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, (childScope) => {
|
|
316
|
+
const target = hydration;
|
|
317
|
+
if (name.startsWith("on")) {
|
|
318
|
+
const event = name.substring(2).toLowerCase();
|
|
319
|
+
useEvent(childScope, 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
|
+
scope.onStop(() => childScope.stop());
|
|
326
|
+
});
|
|
327
|
+
for (const [index$1, childSlot] of slot.children.entries()) await hydrate(scope, hydration, childSlot, index$1);
|
|
284
328
|
}
|
|
285
|
-
|
|
329
|
+
hydration ??= document.createComment("");
|
|
330
|
+
if (parentNode.childNodes.item(index) === null) parentNode.appendChild(toFragment(hydration));
|
|
331
|
+
return hydration;
|
|
286
332
|
};
|
|
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));
|
|
333
|
+
const renderToString = async (scope, slot) => {
|
|
334
|
+
if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") return slot.toString();
|
|
335
|
+
if (typeof slot === "function") {
|
|
336
|
+
let input = slot;
|
|
337
|
+
while (typeof input === "function") input = await input();
|
|
338
|
+
return await renderToString(scope, input);
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(slot)) {
|
|
341
|
+
let items = "";
|
|
342
|
+
for (const childSlot of slot) items += await renderToString(scope, childSlot);
|
|
343
|
+
if (items === "") return "<!---->";
|
|
344
|
+
return items;
|
|
345
|
+
}
|
|
346
|
+
if (isTemplate(slot)) {
|
|
347
|
+
const CustomElement = components.get(slot.tag);
|
|
348
|
+
const prefix = Object.entries(slot.attributes).reduce((chunks, [name, value]) => {
|
|
349
|
+
if (value && !name.startsWith("on")) chunks.push(`${name}='${toString(value)}'`);
|
|
350
|
+
return chunks;
|
|
351
|
+
}, [slot.tag]).join(" ");
|
|
352
|
+
let content = `<${prefix}>`;
|
|
353
|
+
if (CustomElement) {
|
|
354
|
+
const element = new CustomElement(slot.attributes, scope);
|
|
355
|
+
scope.onStop(() => element.scope.stop());
|
|
356
|
+
const template = await renderToString(element.scope, await element.setup());
|
|
357
|
+
if (element.shadowRoot) {
|
|
358
|
+
const shadow = {
|
|
359
|
+
tag: "template",
|
|
360
|
+
attributes: { shadowRootMode: element.shadowRoot.mode },
|
|
361
|
+
children: [template]
|
|
362
|
+
};
|
|
363
|
+
content += await renderToString(element.scope, shadow);
|
|
364
|
+
} else content += template;
|
|
352
365
|
}
|
|
366
|
+
for (const childSlot of slot.children) content += await renderToString(scope, childSlot);
|
|
367
|
+
content += `</${slot.tag}>`;
|
|
368
|
+
return content;
|
|
353
369
|
}
|
|
354
|
-
return
|
|
370
|
+
return "<!---->";
|
|
355
371
|
};
|
|
356
372
|
const defineComponent = (options) => {
|
|
357
|
-
|
|
373
|
+
class Instance {
|
|
358
374
|
static $name = options.name;
|
|
359
375
|
static $events = options.events ?? {};
|
|
360
376
|
static $attributes = options.attributes ?? {};
|
|
@@ -388,29 +404,26 @@ const defineComponent = (options) => {
|
|
|
388
404
|
if (parentNode) this.scope.parentScope = parentNode.component.scope;
|
|
389
405
|
return options.setup(this);
|
|
390
406
|
};
|
|
391
|
-
}
|
|
407
|
+
}
|
|
408
|
+
components.set(options.name, Instance);
|
|
409
|
+
return Instance;
|
|
392
410
|
};
|
|
393
411
|
const toCustomElement = (component) => {
|
|
394
412
|
return class extends HTMLElement {
|
|
395
413
|
static formAssociated = true;
|
|
414
|
+
internals;
|
|
396
415
|
component;
|
|
397
416
|
constructor() {
|
|
398
417
|
super();
|
|
418
|
+
this.internals = this.attachInternals();
|
|
399
419
|
this.component = new component(void 0, void 0, this);
|
|
400
420
|
}
|
|
401
421
|
async connectedCallback() {
|
|
402
422
|
let rootNode = this;
|
|
403
423
|
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
|
-
}
|
|
424
|
+
const options = defu(this.component.shadowRoot, { mode: "open" });
|
|
425
|
+
rootNode = this.shadowRoot ?? this.attachShadow(options);
|
|
426
|
+
if (this.component.shadowRoot.globalStyles) rootNode.adoptedStyleSheets = globalStyles;
|
|
414
427
|
}
|
|
415
428
|
for (const [name, event] of Object.entries(component.$events)) Reflect.set(this.component.events, name, (value) => {
|
|
416
429
|
if (value instanceof Event) return;
|
|
@@ -418,8 +431,8 @@ const toCustomElement = (component) => {
|
|
|
418
431
|
...event,
|
|
419
432
|
detail: value
|
|
420
433
|
}));
|
|
421
|
-
}
|
|
422
|
-
|
|
434
|
+
});
|
|
435
|
+
await hydrate(this.component.scope, rootNode, await this.component.setup(), 0);
|
|
423
436
|
this.dispatchEvent(new MountedEvent());
|
|
424
437
|
}
|
|
425
438
|
attributeChangedCallback(name, oldValue, value) {
|
|
@@ -453,7 +466,6 @@ const toCustomElement = (component) => {
|
|
|
453
466
|
};
|
|
454
467
|
};
|
|
455
468
|
const registerComponent = (component) => {
|
|
456
|
-
if (isServer()) components.set(component.$name, component);
|
|
457
469
|
if (isClient()) {
|
|
458
470
|
const previous = customElements.get(component.$name);
|
|
459
471
|
if (previous === void 0) customElements.define(component.$name, toCustomElement(component));
|
|
@@ -483,6 +495,12 @@ const preventDefault = (event) => event.preventDefault();
|
|
|
483
495
|
const stopPropagation = (event) => event.stopPropagation();
|
|
484
496
|
const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
|
|
485
497
|
const components = new Map();
|
|
498
|
+
const globalStyles = Array.from(isClient() ? document.styleSheets : []).map((style) => {
|
|
499
|
+
const sheet = new CSSStyleSheet();
|
|
500
|
+
const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
|
|
501
|
+
sheet.replaceSync(css);
|
|
502
|
+
return sheet;
|
|
503
|
+
});
|
|
486
504
|
|
|
487
505
|
//#endregion
|
|
488
506
|
//#region src/http/index.ts
|
|
@@ -757,7 +775,6 @@ const Page = defineComponent({
|
|
|
757
775
|
shadowRoot: false,
|
|
758
776
|
setup: ({ scope }) => {
|
|
759
777
|
const { route } = scope.getContext(ROUTER_CONTEXT);
|
|
760
|
-
if (route === void 0) return;
|
|
761
778
|
return () => route.value;
|
|
762
779
|
}
|
|
763
780
|
});
|
|
@@ -904,4 +921,4 @@ const markdownToSlot = (input, options) => {
|
|
|
904
921
|
};
|
|
905
922
|
|
|
906
923
|
//#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,
|
|
924
|
+
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;
|