revojs 0.0.59 → 0.0.61

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/index.js CHANGED
@@ -111,19 +111,13 @@ var Scope = class extends EventTarget {
111
111
  context;
112
112
  constructor(parentScope) {
113
113
  super();
114
- this.context = new Map();
115
- this.setParentScope(parentScope);
116
- }
117
- getParentScope() {
118
- return this.parentScope;
119
- }
120
- setParentScope(parentScope) {
121
114
  this.parentScope = parentScope;
122
- return this.parentScope?.onStop(() => this.stop());
115
+ this.parentScope?.onStop(() => this.stop());
116
+ this.context = /* @__PURE__ */ new Map();
123
117
  }
124
118
  getContext(input) {
125
119
  let scope = this;
126
- const seen = new Set();
120
+ const seen = /* @__PURE__ */ new Set();
127
121
  while (scope && !seen.has(scope)) {
128
122
  seen.add(scope);
129
123
  if (scope.context.has(input)) return scope.context.get(input);
@@ -156,11 +150,17 @@ var Handler = class Handler {
156
150
  get(target, key) {
157
151
  const compute = activeCompute;
158
152
  if (compute) {
159
- const computes = targets.get(target) ?? new Map();
160
- const set = computes.get(key) ?? new Set();
153
+ const computes = targets.get(target) ?? /* @__PURE__ */ new Map();
154
+ const set = computes.get(key) ?? /* @__PURE__ */ new Set();
161
155
  computes.set(key, set.add(compute));
162
156
  targets.set(target, computes);
163
- compute.getParentScope()?.onStop(() => set.delete(compute));
157
+ compute.parentScope?.onStop(() => {
158
+ set.delete(compute);
159
+ if (set.size === 0) {
160
+ computes.delete(key);
161
+ if (computes.size === 0) targets.delete(target);
162
+ }
163
+ });
164
164
  }
165
165
  const value = Reflect.get(target, key);
166
166
  if (value) {
@@ -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
@@ -416,7 +416,7 @@ const toCustomElement = (Component) => {
416
416
  return findParentScope(node.parentNode);
417
417
  }
418
418
  };
419
- this.component.scope.setParentScope(findParentScope(this.parentNode));
419
+ this.component.scope.parentScope = findParentScope(this.parentNode);
420
420
  if (this.component.shadowRoot) rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
421
421
  for (const [name, event] of Object.entries(Component.$events)) Reflect.set(this.component.events, name, (value) => {
422
422
  if (value instanceof Event) return;
@@ -485,7 +485,7 @@ const isServer = () => typeof window === "undefined";
485
485
  const preventDefault = (event) => event.preventDefault();
486
486
  const stopPropagation = (event) => event.stopPropagation();
487
487
  const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
488
- const components = new Map();
488
+ const components = /* @__PURE__ */ new Map();
489
489
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
490
490
 
491
491
  //#endregion
@@ -859,10 +859,15 @@ const useLocale = (scope, context) => {
859
859
  const $ = (key) => {
860
860
  return () => messages.value?.[key] ?? key;
861
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
+ };
862
866
  return {
863
867
  locale,
864
868
  messages,
865
- $
869
+ $,
870
+ date
866
871
  };
867
872
  };
868
873
 
@@ -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-plDYfDhw.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-plDYfDhw.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
 
4
4
  //#region src/presets/cloudflare.ts
@@ -9,19 +9,13 @@ var Scope = class extends EventTarget {
9
9
  context;
10
10
  constructor(parentScope) {
11
11
  super();
12
- this.context = new Map();
13
- this.setParentScope(parentScope);
14
- }
15
- getParentScope() {
16
- return this.parentScope;
17
- }
18
- setParentScope(parentScope) {
19
12
  this.parentScope = parentScope;
20
- return this.parentScope?.onStop(() => this.stop());
13
+ this.parentScope?.onStop(() => this.stop());
14
+ this.context = /* @__PURE__ */ new Map();
21
15
  }
22
16
  getContext(input) {
23
17
  let scope = this;
24
- const seen = new Set();
18
+ const seen = /* @__PURE__ */ new Set();
25
19
  while (scope && !seen.has(scope)) {
26
20
  seen.add(scope);
27
21
  if (scope.context.has(input)) return scope.context.get(input);
@@ -10,11 +10,9 @@ export declare class StopEvent extends Event {
10
10
  constructor();
11
11
  }
12
12
  export declare class Scope extends EventTarget {
13
- private parentScope?;
13
+ parentScope?: Scope;
14
14
  readonly context: Map<string, unknown>;
15
15
  constructor(parentScope?: Scope);
16
- getParentScope(): Scope | undefined;
17
- setParentScope(parentScope?: Scope): void | undefined;
18
16
  getContext<T>(input: Descriptor<T>): T;
19
17
  setContext<T>(input: Descriptor<T>, value: T): void;
20
18
  onStop(input: (event: StopEvent) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
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
  }