revojs 0.0.58 → 0.0.60

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.
@@ -74,6 +74,7 @@ export declare class MountedEvent extends Event {
74
74
  }
75
75
  export declare const isTemplate: <T>(value?: T) => value is Template & T;
76
76
  export declare const isCustomElement: <T>(value?: T) => value is CustomElement<Events, Attributes> & T;
77
+ export declare const isComponent: <T>(value?: T) => value is ComponentConstructor<Events, Attributes> & T;
77
78
  export declare const useHost: (scope: Scope) => HostContext;
78
79
  export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
79
80
  export declare const toString: (slot: Slot) => string;
package/dist/index.js CHANGED
@@ -111,7 +111,7 @@ var Scope = class extends EventTarget {
111
111
  context;
112
112
  constructor(parentScope) {
113
113
  super();
114
- this.context = new Map();
114
+ this.context = /* @__PURE__ */ new Map();
115
115
  this.setParentScope(parentScope);
116
116
  }
117
117
  getParentScope() {
@@ -123,7 +123,7 @@ var Scope = class extends EventTarget {
123
123
  }
124
124
  getContext(input) {
125
125
  let scope = this;
126
- const seen = new Set();
126
+ const seen = /* @__PURE__ */ new Set();
127
127
  while (scope && !seen.has(scope)) {
128
128
  seen.add(scope);
129
129
  if (scope.context.has(input)) return scope.context.get(input);
@@ -156,8 +156,8 @@ var Handler = class Handler {
156
156
  get(target, key) {
157
157
  const compute = activeCompute;
158
158
  if (compute) {
159
- const computes = targets.get(target) ?? new Map();
160
- const set = computes.get(key) ?? new Set();
159
+ const computes = targets.get(target) ?? /* @__PURE__ */ new Map();
160
+ const set = computes.get(key) ?? /* @__PURE__ */ new Set();
161
161
  computes.set(key, set.add(compute));
162
162
  targets.set(target, computes);
163
163
  compute.getParentScope()?.onStop(() => set.delete(compute));
@@ -208,7 +208,7 @@ function defineContext(key) {
208
208
  return key;
209
209
  }
210
210
  let activeCompute;
211
- const targets = new WeakMap();
211
+ const targets = /* @__PURE__ */ new WeakMap();
212
212
 
213
213
  //#endregion
214
214
  //#region src/html/index.ts
@@ -223,20 +223,34 @@ const isTemplate = (value) => {
223
223
  const isCustomElement = (value) => {
224
224
  return !!value && typeof value === "object" && "component" in value;
225
225
  };
226
+ const isComponent = (value) => {
227
+ return !!value && typeof value === "function" && "$name" in value;
228
+ };
226
229
  const useHost = (scope) => {
227
230
  return scope.getContext(HOST_CONTEXT);
228
231
  };
229
232
  const createElement = (input, attributes, ...children) => {
230
- const template = {
231
- tag: typeof input === "function" ? input.$name : input,
233
+ if (isComponent(input)) {
234
+ const template = {
235
+ tag: input.$name,
236
+ attributes: attributes ?? {},
237
+ children
238
+ };
239
+ if (input.$styles.length) {
240
+ const classes = template.attributes["class"];
241
+ template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
242
+ }
243
+ return template;
244
+ }
245
+ if (typeof input === "string") return {
246
+ tag: input,
232
247
  attributes: attributes ?? {},
233
248
  children
234
249
  };
235
- if (typeof input === "function" && input.$styles.length) {
236
- const classes = template.attributes["class"];
237
- template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
238
- }
239
- return template;
250
+ return input?.({
251
+ ...attributes,
252
+ children
253
+ });
240
254
  };
241
255
  const toString = (slot) => {
242
256
  switch (typeof slot) {
@@ -471,7 +485,7 @@ const isServer = () => typeof window === "undefined";
471
485
  const preventDefault = (event) => event.preventDefault();
472
486
  const stopPropagation = (event) => event.stopPropagation();
473
487
  const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
474
- const components = new Map();
488
+ const components = /* @__PURE__ */ new Map();
475
489
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
476
490
 
477
491
  //#endregion
@@ -845,12 +859,17 @@ const useLocale = (scope, context) => {
845
859
  const $ = (key) => {
846
860
  return () => messages.value?.[key] ?? key;
847
861
  };
862
+ const date = (date$1, options) => {
863
+ const format = new Intl.DateTimeFormat(locale.value, options);
864
+ if (date$1) return format.format(date$1);
865
+ };
848
866
  return {
849
867
  locale,
850
868
  messages,
851
- $
869
+ $,
870
+ date
852
871
  };
853
872
  };
854
873
 
855
874
  //#endregion
856
- export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isCustomElement, isRoute, isServer, isTemplate, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
875
+ export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
@@ -1,4 +1,7 @@
1
1
  import { type EventListener, type Slot } from "../html";
2
+ export type Fragment = {
3
+ children: Array<Slot>;
4
+ };
2
5
  export type EventAttributes = {
3
6
  onScroll?: EventListener<Event>;
4
7
  onScrollCapture?: EventListener<Event>;
@@ -365,3 +368,4 @@ export declare namespace JSX {
365
368
  export declare const svgElements: Set<string>;
366
369
  export declare const namespace: (tag: string) => "http://www.w3.org/1999/xhtml" | "http://www.w3.org/2000/svg";
367
370
  export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
371
+ export declare const fragment: ({ children }: Fragment) => unknown[];
package/dist/jsx/index.js CHANGED
@@ -5,17 +5,31 @@ function defineContext(key) {
5
5
 
6
6
  //#endregion
7
7
  //#region src/html/index.ts
8
+ const isComponent = (value) => {
9
+ return !!value && typeof value === "function" && "$name" in value;
10
+ };
8
11
  const createElement = (input, attributes, ...children) => {
9
- const template = {
10
- tag: typeof input === "function" ? input.$name : input,
12
+ if (isComponent(input)) {
13
+ const template = {
14
+ tag: input.$name,
15
+ attributes: attributes ?? {},
16
+ children
17
+ };
18
+ if (input.$styles.length) {
19
+ const classes = template.attributes["class"];
20
+ template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
21
+ }
22
+ return template;
23
+ }
24
+ if (typeof input === "string") return {
25
+ tag: input,
11
26
  attributes: attributes ?? {},
12
27
  children
13
28
  };
14
- if (typeof input === "function" && input.$styles.length) {
15
- const classes = template.attributes["class"];
16
- template.attributes["class"] = (classes ? [classes, ...input.$styles] : input.$styles).join(" ");
17
- }
18
- return template;
29
+ return input?.({
30
+ ...attributes,
31
+ children
32
+ });
19
33
  };
20
34
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
21
35
 
@@ -104,6 +118,7 @@ const namespace = (tag) => {
104
118
  return svgElements.has(tag) ? "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml";
105
119
  };
106
120
  const h = createElement;
121
+ const fragment = ({ children }) => children;
107
122
 
108
123
  //#endregion
109
- export { h, namespace, svgElements };
124
+ export { fragment, h, namespace, svgElements };
@@ -17,10 +17,12 @@ export declare const createLocale: <T extends LocaleOptions>(options: T) => {
17
17
  locale: State<string | undefined>;
18
18
  messages: State<Record<string, string> | undefined>;
19
19
  $: (key: never) => () => string | number | symbol;
20
+ date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
20
21
  }>;
21
22
  };
22
23
  export declare const useLocale: <T extends LocaleContext>(scope: Scope, context?: Descriptor<T>) => {
23
24
  locale: State<string | undefined>;
24
25
  messages: State<Record<string, string> | undefined>;
25
26
  $: (key: keyof T["options"]["locales"][keyof T["options"]["locales"]]) => () => string | number | symbol;
27
+ date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
26
28
  };
@@ -1,4 +1,4 @@
1
- import { RUNTIME_CONTEXT, Scope } from "./runtime-BWvA8m4e.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-6tWe5NVu.js";
2
2
  import { serve } from "bun";
3
3
  import { runtime } from "#virtual/runtime";
4
4
 
@@ -1,4 +1,4 @@
1
- import { RUNTIME_CONTEXT, Scope } from "./runtime-BWvA8m4e.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-6tWe5NVu.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
 
4
4
  //#region src/presets/cloudflare.ts
@@ -9,7 +9,7 @@ var Scope = class extends EventTarget {
9
9
  context;
10
10
  constructor(parentScope) {
11
11
  super();
12
- this.context = new Map();
12
+ this.context = /* @__PURE__ */ new Map();
13
13
  this.setParentScope(parentScope);
14
14
  }
15
15
  getParentScope() {
@@ -21,7 +21,7 @@ var Scope = class extends EventTarget {
21
21
  }
22
22
  getContext(input) {
23
23
  let scope = this;
24
- const seen = new Set();
24
+ const seen = /* @__PURE__ */ new Set();
25
25
  while (scope && !seen.has(scope)) {
26
26
  seen.add(scope);
27
27
  if (scope.context.has(input)) return scope.context.get(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.58",
3
+ "version": "0.0.60",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@revojs/tsconfig": "*",
43
43
  "@revojs/rolldown": "*",
44
- "@types/bun": "^1.2.2",
45
- "rolldown": "^1.0.0-beta.1"
44
+ "@types/bun": "^1.2.17",
45
+ "rolldown": "^1.0.0-beta.19"
46
46
  }
47
47
  }