revojs 0.0.40 → 0.0.42

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.
@@ -39,16 +39,13 @@ export type AttributeOptions<T = unknown> = {
39
39
  type: T;
40
40
  default?: Infer<T>;
41
41
  };
42
- export type ShadowRootOptions = ShadowRootInit & {
43
- globalStyles?: boolean;
44
- };
45
42
  export type Events = Record<string, EventOptions>;
46
43
  export type Attributes = Record<string, AttributeOptions>;
47
44
  export interface ComponentOptions<TEvents extends Events, TAttributes extends Attributes> {
48
45
  name: string;
49
46
  events?: TEvents;
50
47
  attributes?: TAttributes;
51
- shadowRoot?: Partial<ShadowRootOptions>;
48
+ shadowRoot?: ShadowRootInit;
52
49
  styles?: Array<string>;
53
50
  setup: (component: Component<TEvents, TAttributes>) => Slot | Promise<Slot>;
54
51
  }
@@ -56,7 +53,7 @@ export interface Component<TEvents extends Events, TAttributes extends Attribute
56
53
  readonly scope: Scope;
57
54
  readonly events: EventOutput<TEvents>;
58
55
  readonly attributes: State<AttributeOutput<TAttributes>>;
59
- readonly shadowRoot?: ShadowRootOptions;
56
+ readonly shadowRoot?: ShadowRootInit;
60
57
  setup: () => Slot | Promise<Slot>;
61
58
  }
62
59
  export interface ComponentConstructor<TEvents extends Events, TAttributes extends Attributes> {
@@ -97,7 +94,6 @@ export declare const preventDefault: (event: Event) => void;
97
94
  export declare const stopPropagation: (event: Event) => void;
98
95
  export declare const stopImmediatePropagation: (event: Event) => void;
99
96
  export declare const components: Map<string, ComponentConstructor<Events, Attributes>>;
100
- export declare const globalStyles: CSSStyleSheet[];
101
97
  export declare const HOST_CONTEXT: import("..").Descriptor<HostContext>;
102
98
  declare global {
103
99
  interface HTMLElementEventMap {
package/dist/index.js CHANGED
@@ -275,22 +275,25 @@ const hydrate = async (scope, parentNode, slot, index, previous) => {
275
275
  if (items.length) hydration = items;
276
276
  else if (previous || !(hydration instanceof Comment)) hydration = document.createComment("");
277
277
  }
278
- if (typeof slot === "function") await createCompute(scope, async (scope$1) => {
279
- let input = slot;
280
- while (typeof input === "function") input = await input();
281
- hydration = await hydrate(scope$1, parentNode, input, index, previous);
282
- if (previous && hydration !== previous) if (Array.isArray(hydration)) if (Array.isArray(previous)) {
283
- const range = toRange(previous);
284
- range.deleteContents();
285
- for (const childNode of toArray(hydration)) range.insertNode(childNode);
286
- } else parentNode.replaceChild(toFragment(hydration), previous);
287
- else if (Array.isArray(previous)) {
288
- const range = toRange(previous);
289
- range.deleteContents();
290
- range.insertNode(hydration);
291
- } else parentNode.replaceChild(hydration, previous);
292
- previous = hydration;
293
- });
278
+ if (typeof slot === "function") {
279
+ let previous$1;
280
+ await createCompute(scope, async (scope$1) => {
281
+ let input = slot;
282
+ while (typeof input === "function") input = await input();
283
+ hydration = await hydrate(scope$1, parentNode, input, index, previous$1);
284
+ if (previous$1 && hydration !== previous$1) if (Array.isArray(hydration)) if (Array.isArray(previous$1)) {
285
+ const range = toRange(previous$1);
286
+ range.deleteContents();
287
+ for (const childNode of toArray(hydration)) range.insertNode(childNode);
288
+ } else parentNode.replaceChild(toFragment(hydration), previous$1);
289
+ else if (Array.isArray(previous$1)) {
290
+ const range = toRange(previous$1);
291
+ range.deleteContents();
292
+ range.insertNode(hydration);
293
+ } else parentNode.replaceChild(hydration, previous$1);
294
+ previous$1 = hydration;
295
+ });
296
+ }
294
297
  if ((slot === null || slot === void 0) && (previous || !(hydration instanceof Comment))) hydration = document.createComment("");
295
298
  if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") {
296
299
  const textContent = slot.toString();
@@ -378,7 +381,7 @@ const defineComponent = (options) => {
378
381
  Reflect.set(attributes.value, name, fromValue(input?.[name]) ?? attribute.default, attributes.value);
379
382
  return attributes;
380
383
  }, createState({}));
381
- if (options.shadowRoot) this.shadowRoot = defu(options.shadowRoot, { mode: "open" });
384
+ this.shadowRoot = options.shadowRoot;
382
385
  }
383
386
  setup = () => options.setup(this);
384
387
  }
@@ -400,10 +403,7 @@ const toCustomElement = (Component) => {
400
403
  };
401
404
  const parentNode = findParent(this.parentNode);
402
405
  if (parentNode) this.component.scope.parentScope = parentNode.component.scope;
403
- if (this.component.shadowRoot) {
404
- rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
405
- if (this.component.shadowRoot.globalStyles) rootNode.adoptedStyleSheets = globalStyles;
406
- }
406
+ if (this.component.shadowRoot) rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
407
407
  for (const [name, event] of Object.entries(Component.$events)) Reflect.set(this.component.events, name, (value) => {
408
408
  if (value instanceof Event) return;
409
409
  this.dispatchEvent(new CustomEvent(name.substring(2).toLowerCase(), {
@@ -478,12 +478,6 @@ const preventDefault = (event) => event.preventDefault();
478
478
  const stopPropagation = (event) => event.stopPropagation();
479
479
  const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
480
480
  const components = new Map();
481
- const globalStyles = Array.from(isClient() ? document.styleSheets : []).map((style) => {
482
- const sheet = new CSSStyleSheet();
483
- const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
484
- sheet.replaceSync(css);
485
- return sheet;
486
- });
487
481
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
488
482
 
489
483
  //#endregion
@@ -904,4 +898,4 @@ const markdownToSlot = (input, options) => {
904
898
  };
905
899
 
906
900
  //#endregion
907
- export { $fetch, Compute, HOST_CONTEXT, 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, isServer, isTemplate, markdownToSlot, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useEvent, useHost, useLocale, useRouter, useRuntime };
901
+ export { $fetch, Compute, HOST_CONTEXT, 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, hydrate, isClient, isServer, isTemplate, markdownToSlot, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useEvent, useHost, useLocale, useRouter, useRuntime };
package/dist/jsx/index.js CHANGED
@@ -1,45 +1,4 @@
1
1
 
2
- //#region ../../node_modules/defu/dist/defu.mjs
3
- function isPlainObject(value) {
4
- if (value === null || typeof value !== "object") return false;
5
- const prototype = Object.getPrototypeOf(value);
6
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
7
- if (Symbol.iterator in value) return false;
8
- if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
9
- return true;
10
- }
11
- function _defu(baseObject, defaults, namespace$1 = ".", merger) {
12
- if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace$1, merger);
13
- const object = Object.assign({}, defaults);
14
- for (const key in baseObject) {
15
- if (key === "__proto__" || key === "constructor") continue;
16
- const value = baseObject[key];
17
- if (value === null || value === void 0) continue;
18
- if (merger && merger(object, key, value, namespace$1)) continue;
19
- if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
20
- else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace$1 ? `${namespace$1}.` : "") + key.toString(), merger);
21
- else object[key] = value;
22
- }
23
- return object;
24
- }
25
- function createDefu(merger) {
26
- return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
27
- }
28
- const defu = createDefu();
29
- const defuFn = createDefu((object, key, currentValue) => {
30
- if (object[key] !== void 0 && typeof currentValue === "function") {
31
- object[key] = currentValue(object[key]);
32
- return true;
33
- }
34
- });
35
- const defuArrayFn = createDefu((object, key, currentValue) => {
36
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
37
- object[key] = currentValue(object[key]);
38
- return true;
39
- }
40
- });
41
-
42
- //#endregion
43
2
  //#region src/signals/index.ts
44
3
  function defineContext(key) {
45
4
  return key;
@@ -59,13 +18,6 @@ const createElement = (input, attributes, ...children) => {
59
18
  }
60
19
  return template;
61
20
  };
62
- const isClient = () => typeof window !== "undefined";
63
- const globalStyles = Array.from(isClient() ? document.styleSheets : []).map((style) => {
64
- const sheet = new CSSStyleSheet();
65
- const css = Array.from(style.cssRules).map((rule) => rule.cssText).join(" ");
66
- sheet.replaceSync(css);
67
- return sheet;
68
- });
69
21
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
70
22
 
71
23
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",