@pyreon/preact-compat 0.5.6 → 0.6.0

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.
@@ -5386,7 +5386,7 @@ var drawChart = (function (exports) {
5386
5386
  </script>
5387
5387
  <script>
5388
5388
  /*<!--*/
5389
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src/index.ts","uid":"17fbe9f7-1"}]}],"isRoot":true},"nodeParts":{"17fbe9f7-1":{"renderedLength":2842,"gzipLength":1179,"brotliLength":0,"metaUid":"17fbe9f7-0"}},"nodeMetas":{"17fbe9f7-0":{"id":"/src/index.ts","moduleParts":{"index.js":"17fbe9f7-1"},"imported":[{"uid":"17fbe9f7-2"},{"uid":"17fbe9f7-3"},{"uid":"17fbe9f7-4"}],"importedBy":[],"isEntry":true},"17fbe9f7-2":{"id":"@pyreon/core","moduleParts":{},"imported":[],"importedBy":[{"uid":"17fbe9f7-0"}]},"17fbe9f7-3":{"id":"@pyreon/reactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"17fbe9f7-0"}]},"17fbe9f7-4":{"id":"@pyreon/runtime-dom","moduleParts":{},"imported":[],"importedBy":[{"uid":"17fbe9f7-0"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
5389
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src/index.ts","uid":"e7c3b550-1"}]}],"isRoot":true},"nodeParts":{"e7c3b550-1":{"renderedLength":2789,"gzipLength":1150,"brotliLength":0,"metaUid":"e7c3b550-0"}},"nodeMetas":{"e7c3b550-0":{"id":"/src/index.ts","moduleParts":{"index.js":"e7c3b550-1"},"imported":[{"uid":"e7c3b550-2"},{"uid":"e7c3b550-3"},{"uid":"e7c3b550-4"}],"importedBy":[],"isEntry":true},"e7c3b550-2":{"id":"@pyreon/core","moduleParts":{},"imported":[],"importedBy":[{"uid":"e7c3b550-0"}]},"e7c3b550-3":{"id":"@pyreon/reactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"e7c3b550-0"}]},"e7c3b550-4":{"id":"@pyreon/runtime-dom","moduleParts":{},"imported":[],"importedBy":[{"uid":"e7c3b550-0"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
5390
5390
 
5391
5391
  const run = () => {
5392
5392
  const width = window.innerWidth;
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Fragment, createContext as createContext$1, createRef, h as pyreonH, onUnmount, popContext, pushContext, useContext } from "@pyreon/core";
1
+ import { Fragment, createContext as createContext$1, createRef, h as pyreonH, provide, useContext } from "@pyreon/core";
2
2
  import { batch, signal } from "@pyreon/reactivity";
3
3
  import { hydrateRoot, mount } from "@pyreon/runtime-dom";
4
4
 
@@ -25,8 +25,7 @@ function hydrate(vnode, container) {
25
25
  function createContext(defaultValue) {
26
26
  const ctx = createContext$1(defaultValue);
27
27
  const Provider = ((props) => {
28
- pushContext(new Map([[ctx.id, props.value]]));
29
- onUnmount(() => popContext());
28
+ provide(ctx, props.value);
30
29
  return props.children;
31
30
  });
32
31
  return {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["pyreonCreateContext"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @pyreon/preact-compat\n *\n * Preact-compatible API shim that runs on Pyreon's reactive engine.\n *\n * Provides the core Preact API surface: h, Fragment, render, hydrate,\n * Component class, createContext, createRef, cloneElement, toChildArray,\n * isValidElement, and the options hook object.\n *\n * For hooks, import from \"@pyreon/preact-compat/hooks\".\n * For signals, import from \"@pyreon/preact-compat/signals\".\n */\n\nimport type { ComponentFn, Props, VNode, VNodeChild } from \"@pyreon/core\"\nimport {\n createRef,\n Fragment,\n onUnmount,\n popContext,\n pushContext,\n createContext as pyreonCreateContext,\n h as pyreonH,\n useContext,\n} from \"@pyreon/core\"\nimport { batch, signal } from \"@pyreon/reactivity\"\nimport { hydrateRoot, mount } from \"@pyreon/runtime-dom\"\n\n// ─── Core JSX ────────────────────────────────────────────────────────────────\n\n/** Preact's hyperscript function — maps directly to Pyreon's h() */\nexport { pyreonH as h }\n\n/** Alias: Preact also exports createElement */\nexport const createElement = pyreonH\n\nexport { Fragment }\n\n// ─── Render / Hydrate ────────────────────────────────────────────────────────\n\n/**\n * Preact's `render(vnode, container)`.\n * Maps to Pyreon's `mount(vnode, container)`.\n */\nexport function render(vnode: VNodeChild, container: Element): void {\n mount(vnode, container)\n}\n\n/**\n * Preact's `hydrate(vnode, container)`.\n * Maps to Pyreon's `hydrateRoot(container, vnode)`.\n */\nexport function hydrate(vnode: VNodeChild, container: Element): void {\n hydrateRoot(container, vnode as VNode)\n}\n\n// ─── Context ─────────────────────────────────────────────────────────────────\n\nexport interface PreactContext<T> {\n readonly id: symbol\n readonly defaultValue: T\n Provider: ComponentFn<{ value: T; children?: VNodeChild }>\n}\n\n/**\n * Preact-compatible createContext — returns a context with a `.Provider` component.\n */\nexport function createContext<T>(defaultValue: T): PreactContext<T> {\n const ctx = pyreonCreateContext<T>(defaultValue)\n const Provider = ((props: { value: T; children?: VNodeChild }) => {\n pushContext(new Map([[ctx.id, props.value]]))\n onUnmount(() => popContext())\n return props.children as VNode | null\n }) as ComponentFn<{ value: T; children?: VNodeChild }>\n return { ...ctx, Provider }\n}\n\nexport { useContext }\n\n// ─── Refs ────────────────────────────────────────────────────────────────────\n\nexport { createRef }\n\n// ─── Component class ─────────────────────────────────────────────────────────\n\n/**\n * Preact-compatible class-based Component.\n *\n * Wraps Pyreon's signal-based reactivity so `setState` triggers re-renders.\n * Usage: `class MyComp extends Component { render() { ... } }`\n */\nexport class Component<\n P extends Props = Props,\n S extends Record<string, unknown> = Record<string, unknown>,\n> {\n props: P\n state: S\n private _stateSignal: ReturnType<typeof signal<S>>\n\n constructor(props: P) {\n this.props = props\n this.state = {} as S\n this._stateSignal = signal<S>(this.state)\n }\n\n /**\n * Update state — accepts a partial state object or an updater function.\n * Merges into existing state (shallow merge, like Preact/React).\n */\n setState(partial: Partial<S> | ((prev: S) => Partial<S>)): void {\n batch(() => {\n const current = this._stateSignal()\n const update =\n typeof partial === \"function\" ? (partial as (prev: S) => Partial<S>)(current) : partial\n const next = { ...current, ...update } as S\n this.state = next\n this._stateSignal.set(next)\n })\n }\n\n /**\n * Force a re-render. In Pyreon this triggers the state signal to re-fire.\n */\n forceUpdate(): void {\n this._stateSignal.set({ ...this.state })\n }\n\n /**\n * Override in subclass to return VNode tree.\n */\n render(): VNodeChild {\n return null\n }\n}\n\n// ─── cloneElement ────────────────────────────────────────────────────────────\n\n/**\n * Clone a VNode with merged props (like Preact's cloneElement).\n */\nexport function cloneElement(vnode: VNode, props?: Props, ...children: VNodeChild[]): VNode {\n const mergedProps = { ...vnode.props, ...(props ?? {}) }\n const mergedChildren = children.length > 0 ? children : vnode.children\n return {\n type: vnode.type,\n props: mergedProps,\n children: mergedChildren,\n key: (props?.key as string | number | null) ?? vnode.key,\n }\n}\n\n// ─── toChildArray ────────────────────────────────────────────────────────────\n\n/**\n * Flatten children into a flat array, filtering out null/undefined/boolean.\n * Matches Preact's `toChildArray` utility.\n */\ntype NestedChildren = VNodeChild | NestedChildren[]\n\nexport function toChildArray(children: NestedChildren): VNodeChild[] {\n const result: VNodeChild[] = []\n flatten(children, result)\n return result\n}\n\nfunction flatten(value: NestedChildren, out: VNodeChild[]): void {\n if (value == null || typeof value === \"boolean\") return\n if (Array.isArray(value)) {\n for (const child of value) {\n flatten(child, out)\n }\n } else {\n out.push(value as VNodeChild)\n }\n}\n\n// ─── isValidElement ──────────────────────────────────────────────────────────\n\n/**\n * Check if a value is a VNode (like Preact's isValidElement).\n */\nexport function isValidElement(x: unknown): x is VNode {\n return (\n x !== null &&\n typeof x === \"object\" &&\n \"type\" in (x as Record<string, unknown>) &&\n \"props\" in (x as Record<string, unknown>) &&\n \"children\" in (x as Record<string, unknown>)\n )\n}\n\n// ─── options ─────────────────────────────────────────────────────────────────\n\n/**\n * Preact's plugin/hook system. Exposed as an empty object for compatibility\n * with libraries that check for `options._hook`, `options.vnode`, etc.\n */\nexport const options: Record<string, unknown> = {}\n"],"mappings":";;;;;;AAiCA,MAAa,gBAAgB;;;;;AAU7B,SAAgB,OAAO,OAAmB,WAA0B;AAClE,OAAM,OAAO,UAAU;;;;;;AAOzB,SAAgB,QAAQ,OAAmB,WAA0B;AACnE,aAAY,WAAW,MAAe;;;;;AAcxC,SAAgB,cAAiB,cAAmC;CAClE,MAAM,MAAMA,gBAAuB,aAAa;CAChD,MAAM,aAAa,UAA+C;AAChE,cAAY,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,MAAM,CAAC,CAAC,CAAC;AAC7C,kBAAgB,YAAY,CAAC;AAC7B,SAAO,MAAM;;AAEf,QAAO;EAAE,GAAG;EAAK;EAAU;;;;;;;;AAiB7B,IAAa,YAAb,MAGE;CACA;CACA;CACA,AAAQ;CAER,YAAY,OAAU;AACpB,OAAK,QAAQ;AACb,OAAK,QAAQ,EAAE;AACf,OAAK,eAAe,OAAU,KAAK,MAAM;;;;;;CAO3C,SAAS,SAAuD;AAC9D,cAAY;GACV,MAAM,UAAU,KAAK,cAAc;GACnC,MAAM,SACJ,OAAO,YAAY,aAAc,QAAoC,QAAQ,GAAG;GAClF,MAAM,OAAO;IAAE,GAAG;IAAS,GAAG;IAAQ;AACtC,QAAK,QAAQ;AACb,QAAK,aAAa,IAAI,KAAK;IAC3B;;;;;CAMJ,cAAoB;AAClB,OAAK,aAAa,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;;;;;CAM1C,SAAqB;AACnB,SAAO;;;;;;AASX,SAAgB,aAAa,OAAc,OAAe,GAAG,UAA+B;CAC1F,MAAM,cAAc;EAAE,GAAG,MAAM;EAAO,GAAI,SAAS,EAAE;EAAG;CACxD,MAAM,iBAAiB,SAAS,SAAS,IAAI,WAAW,MAAM;AAC9D,QAAO;EACL,MAAM,MAAM;EACZ,OAAO;EACP,UAAU;EACV,KAAM,OAAO,OAAkC,MAAM;EACtD;;AAWH,SAAgB,aAAa,UAAwC;CACnE,MAAM,SAAuB,EAAE;AAC/B,SAAQ,UAAU,OAAO;AACzB,QAAO;;AAGT,SAAS,QAAQ,OAAuB,KAAyB;AAC/D,KAAI,SAAS,QAAQ,OAAO,UAAU,UAAW;AACjD,KAAI,MAAM,QAAQ,MAAM,CACtB,MAAK,MAAM,SAAS,MAClB,SAAQ,OAAO,IAAI;KAGrB,KAAI,KAAK,MAAoB;;;;;AASjC,SAAgB,eAAe,GAAwB;AACrD,QACE,MAAM,QACN,OAAO,MAAM,YACb,UAAW,KACX,WAAY,KACZ,cAAe;;;;;;AAUnB,MAAa,UAAmC,EAAE"}
1
+ {"version":3,"file":"index.js","names":["pyreonCreateContext"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @pyreon/preact-compat\n *\n * Preact-compatible API shim that runs on Pyreon's reactive engine.\n *\n * Provides the core Preact API surface: h, Fragment, render, hydrate,\n * Component class, createContext, createRef, cloneElement, toChildArray,\n * isValidElement, and the options hook object.\n *\n * For hooks, import from \"@pyreon/preact-compat/hooks\".\n * For signals, import from \"@pyreon/preact-compat/signals\".\n */\n\nimport type { ComponentFn, Props, VNode, VNodeChild } from \"@pyreon/core\"\nimport {\n createRef,\n Fragment,\n provide,\n createContext as pyreonCreateContext,\n h as pyreonH,\n useContext,\n} from \"@pyreon/core\"\nimport { batch, signal } from \"@pyreon/reactivity\"\nimport { hydrateRoot, mount } from \"@pyreon/runtime-dom\"\n\n// ─── Core JSX ────────────────────────────────────────────────────────────────\n\n/** Preact's hyperscript function — maps directly to Pyreon's h() */\nexport { pyreonH as h }\n\n/** Alias: Preact also exports createElement */\nexport const createElement = pyreonH\n\nexport { Fragment }\n\n// ─── Render / Hydrate ────────────────────────────────────────────────────────\n\n/**\n * Preact's `render(vnode, container)`.\n * Maps to Pyreon's `mount(vnode, container)`.\n */\nexport function render(vnode: VNodeChild, container: Element): void {\n mount(vnode, container)\n}\n\n/**\n * Preact's `hydrate(vnode, container)`.\n * Maps to Pyreon's `hydrateRoot(container, vnode)`.\n */\nexport function hydrate(vnode: VNodeChild, container: Element): void {\n hydrateRoot(container, vnode as VNode)\n}\n\n// ─── Context ─────────────────────────────────────────────────────────────────\n\nexport interface PreactContext<T> {\n readonly id: symbol\n readonly defaultValue: T\n Provider: ComponentFn<{ value: T; children?: VNodeChild }>\n}\n\n/**\n * Preact-compatible createContext — returns a context with a `.Provider` component.\n */\nexport function createContext<T>(defaultValue: T): PreactContext<T> {\n const ctx = pyreonCreateContext<T>(defaultValue)\n const Provider = ((props: { value: T; children?: VNodeChild }) => {\n provide(ctx, props.value)\n return props.children\n }) as ComponentFn<{ value: T; children?: VNodeChild }>\n return { ...ctx, Provider }\n}\n\nexport { useContext }\n\n// ─── Refs ────────────────────────────────────────────────────────────────────\n\nexport { createRef }\n\n// ─── Component class ─────────────────────────────────────────────────────────\n\n/**\n * Preact-compatible class-based Component.\n *\n * Wraps Pyreon's signal-based reactivity so `setState` triggers re-renders.\n * Usage: `class MyComp extends Component { render() { ... } }`\n */\nexport class Component<\n P extends Props = Props,\n S extends Record<string, unknown> = Record<string, unknown>,\n> {\n props: P\n state: S\n private _stateSignal: ReturnType<typeof signal<S>>\n\n constructor(props: P) {\n this.props = props\n this.state = {} as S\n this._stateSignal = signal<S>(this.state)\n }\n\n /**\n * Update state — accepts a partial state object or an updater function.\n * Merges into existing state (shallow merge, like Preact/React).\n */\n setState(partial: Partial<S> | ((prev: S) => Partial<S>)): void {\n batch(() => {\n const current = this._stateSignal()\n const update =\n typeof partial === \"function\" ? (partial as (prev: S) => Partial<S>)(current) : partial\n const next = { ...current, ...update } as S\n this.state = next\n this._stateSignal.set(next)\n })\n }\n\n /**\n * Force a re-render. In Pyreon this triggers the state signal to re-fire.\n */\n forceUpdate(): void {\n this._stateSignal.set({ ...this.state })\n }\n\n /**\n * Override in subclass to return VNode tree.\n */\n render(): VNodeChild {\n return null\n }\n}\n\n// ─── cloneElement ────────────────────────────────────────────────────────────\n\n/**\n * Clone a VNode with merged props (like Preact's cloneElement).\n */\nexport function cloneElement(vnode: VNode, props?: Props, ...children: VNodeChild[]): VNode {\n const mergedProps = { ...vnode.props, ...(props ?? {}) }\n const mergedChildren = children.length > 0 ? children : vnode.children\n return {\n type: vnode.type,\n props: mergedProps,\n children: mergedChildren,\n key: (props?.key as string | number | null) ?? vnode.key,\n }\n}\n\n// ─── toChildArray ────────────────────────────────────────────────────────────\n\n/**\n * Flatten children into a flat array, filtering out null/undefined/boolean.\n * Matches Preact's `toChildArray` utility.\n */\ntype NestedChildren = VNodeChild | NestedChildren[]\n\nexport function toChildArray(children: NestedChildren): VNodeChild[] {\n const result: VNodeChild[] = []\n flatten(children, result)\n return result\n}\n\nfunction flatten(value: NestedChildren, out: VNodeChild[]): void {\n if (value == null || typeof value === \"boolean\") return\n if (Array.isArray(value)) {\n for (const child of value) {\n flatten(child, out)\n }\n } else {\n out.push(value as VNodeChild)\n }\n}\n\n// ─── isValidElement ──────────────────────────────────────────────────────────\n\n/**\n * Check if a value is a VNode (like Preact's isValidElement).\n */\nexport function isValidElement(x: unknown): x is VNode {\n return (\n x !== null &&\n typeof x === \"object\" &&\n \"type\" in (x as Record<string, unknown>) &&\n \"props\" in (x as Record<string, unknown>) &&\n \"children\" in (x as Record<string, unknown>)\n )\n}\n\n// ─── options ─────────────────────────────────────────────────────────────────\n\n/**\n * Preact's plugin/hook system. Exposed as an empty object for compatibility\n * with libraries that check for `options._hook`, `options.vnode`, etc.\n */\nexport const options: Record<string, unknown> = {}\n"],"mappings":";;;;;;AA+BA,MAAa,gBAAgB;;;;;AAU7B,SAAgB,OAAO,OAAmB,WAA0B;AAClE,OAAM,OAAO,UAAU;;;;;;AAOzB,SAAgB,QAAQ,OAAmB,WAA0B;AACnE,aAAY,WAAW,MAAe;;;;;AAcxC,SAAgB,cAAiB,cAAmC;CAClE,MAAM,MAAMA,gBAAuB,aAAa;CAChD,MAAM,aAAa,UAA+C;AA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AE"}
@@ -1,178 +1,47 @@
1
- import { onErrorCaptured, useContext } from "@pyreon/core";
2
- function getCurrentCtx() {
3
- return _currentCtx;
4
- }
5
- function getHookIndex() {
6
- return _hookIndex++;
7
- }
8
-
9
- //#endregion
10
- //#region src/hooks.ts
11
- function requireCtx() {
12
- const ctx = getCurrentCtx();
13
- if (!ctx) throw new Error("Hook called outside of a component render");
14
- return ctx;
15
- }
16
- function depsChanged(a, b) {
17
- if (a === void 0 || b === void 0) return true;
18
- if (a.length !== b.length) return true;
19
- for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return true;
20
- return false;
21
- }
22
- /**
23
- * Preact-compatible `useState` — returns `[value, setter]`.
24
- * Triggers a component re-render when the setter is called.
25
- */
26
- function useState(initial) {
27
- const ctx = requireCtx();
28
- const idx = getHookIndex();
29
- if (ctx.hooks.length <= idx) ctx.hooks.push(typeof initial === "function" ? initial() : initial);
30
- const value = ctx.hooks[idx];
31
- const setter = v => {
32
- const current = ctx.hooks[idx];
33
- const next = typeof v === "function" ? v(current) : v;
34
- if (Object.is(current, next)) return;
35
- ctx.hooks[idx] = next;
36
- ctx.scheduleRerender();
37
- };
38
- return [value, setter];
39
- }
40
- /**
41
- * Preact-compatible `useEffect` — runs after render when deps change.
42
- * Returns cleanup on unmount and before re-running.
43
- */
44
- function useEffect(fn, deps) {
45
- const ctx = requireCtx();
46
- const idx = getHookIndex();
47
- if (ctx.hooks.length <= idx) {
48
- const entry = {
49
- fn,
50
- deps,
51
- cleanup: void 0
52
- };
53
- ctx.hooks.push(entry);
54
- ctx.pendingEffects.push(entry);
55
- } else {
56
- const entry = ctx.hooks[idx];
57
- if (depsChanged(entry.deps, deps)) {
58
- entry.fn = fn;
59
- entry.deps = deps;
60
- ctx.pendingEffects.push(entry);
61
- }
62
- }
63
- }
64
- /**
65
- * Preact-compatible `useLayoutEffect` — runs synchronously after DOM mutations.
66
- */
67
- function useLayoutEffect(fn, deps) {
68
- const ctx = requireCtx();
69
- const idx = getHookIndex();
70
- if (ctx.hooks.length <= idx) {
71
- const entry = {
72
- fn,
73
- deps,
74
- cleanup: void 0
75
- };
76
- ctx.hooks.push(entry);
77
- ctx.pendingLayoutEffects.push(entry);
78
- } else {
79
- const entry = ctx.hooks[idx];
80
- if (depsChanged(entry.deps, deps)) {
81
- entry.fn = fn;
82
- entry.deps = deps;
83
- ctx.pendingLayoutEffects.push(entry);
84
- }
85
- }
86
- }
87
- /**
88
- * Preact-compatible `useMemo` — returns the cached value, recomputed when deps change.
89
- */
90
- function useMemo(fn, deps) {
91
- const ctx = requireCtx();
92
- const idx = getHookIndex();
93
- if (ctx.hooks.length <= idx) {
94
- const value = fn();
95
- ctx.hooks.push({
96
- value,
97
- deps
98
- });
99
- return value;
100
- }
101
- const entry = ctx.hooks[idx];
102
- if (depsChanged(entry.deps, deps)) {
103
- entry.value = fn();
104
- entry.deps = deps;
105
- }
106
- return entry.value;
107
- }
108
- /**
109
- * Preact-compatible `useCallback` — returns the cached function when deps haven't changed.
110
- */
111
- function useCallback(fn, deps) {
112
- return useMemo(() => fn, deps);
113
- }
114
- /**
115
- * Preact-compatible `useRef` — returns `{ current }` persisted across re-renders.
116
- */
117
- function useRef(initial) {
118
- const ctx = requireCtx();
119
- const idx = getHookIndex();
120
- if (ctx.hooks.length <= idx) {
121
- const ref = {
122
- current: initial !== void 0 ? initial : null
123
- };
124
- ctx.hooks.push(ref);
125
- }
126
- return ctx.hooks[idx];
127
- }
128
- /**
129
- * Preact-compatible `useReducer` — returns `[state, dispatch]`.
130
- */
131
- function useReducer(reducer, initial) {
132
- const ctx = requireCtx();
133
- const idx = getHookIndex();
134
- if (ctx.hooks.length <= idx) ctx.hooks.push(typeof initial === "function" ? initial() : initial);
135
- const state = ctx.hooks[idx];
136
- const dispatch = action => {
137
- const current = ctx.hooks[idx];
138
- const next = reducer(current, action);
139
- if (Object.is(current, next)) return;
140
- ctx.hooks[idx] = next;
141
- ctx.scheduleRerender();
142
- };
143
- return [state, dispatch];
144
- }
145
- /**
146
- * Preact-compatible `useId` — returns a stable unique string per hook call.
147
- */
148
- function useId() {
149
- const ctx = requireCtx();
150
- const idx = getHookIndex();
151
- if (ctx.hooks.length <= idx) ctx.hooks.push(`:r${(_idCounter++).toString(36)}:`);
152
- return ctx.hooks[idx];
153
- }
154
- /**
155
- * Preact-compatible `memo` — wraps a component to skip re-render when props
156
- * are shallowly equal.
157
- */
158
- function memo(component, areEqual) {
159
- const compare = areEqual ?? ((a, b) => {
160
- const keysA = Object.keys(a);
161
- const keysB = Object.keys(b);
162
- if (keysA.length !== keysB.length) return false;
163
- for (const k of keysA) if (!Object.is(a[k], b[k])) return false;
164
- return true;
165
- });
166
- let prevProps = null;
167
- let prevResult = null;
168
- return props => {
169
- if (prevProps !== null && compare(prevProps, props)) return prevResult;
170
- prevProps = props;
171
- prevResult = component(props);
172
- return prevResult;
173
- };
174
- }
1
+ import { VNodeChild, onErrorCaptured, useContext } from "@pyreon/core";
175
2
 
3
+ //#region src/hooks.d.ts
4
+ /**
5
+ * Preact-compatible `useState` — returns `[value, setter]`.
6
+ * Triggers a component re-render when the setter is called.
7
+ */
8
+ declare function useState<T>(initial: T | (() => T)): [T, (v: T | ((prev: T) => T)) => void];
9
+ /**
10
+ * Preact-compatible `useEffect` — runs after render when deps change.
11
+ * Returns cleanup on unmount and before re-running.
12
+ */
13
+ declare function useEffect(fn: () => (() => void) | void, deps?: unknown[]): void;
14
+ /**
15
+ * Preact-compatible `useLayoutEffect` — runs synchronously after DOM mutations.
16
+ */
17
+ declare function useLayoutEffect(fn: () => (() => void) | void, deps?: unknown[]): void;
18
+ /**
19
+ * Preact-compatible `useMemo` — returns the cached value, recomputed when deps change.
20
+ */
21
+ declare function useMemo<T>(fn: () => T, deps: unknown[]): T;
22
+ /**
23
+ * Preact-compatible `useCallback` — returns the cached function when deps haven't changed.
24
+ */
25
+ declare function useCallback<T extends (...args: never[]) => unknown>(fn: T, deps: unknown[]): T;
26
+ /**
27
+ * Preact-compatible `useRef` — returns `{ current }` persisted across re-renders.
28
+ */
29
+ declare function useRef<T>(initial?: T): {
30
+ current: T | null;
31
+ };
32
+ /**
33
+ * Preact-compatible `useReducer` — returns `[state, dispatch]`.
34
+ */
35
+ declare function useReducer<S, A>(reducer: (state: S, action: A) => S, initial: S | (() => S)): [S, (action: A) => void];
36
+ /**
37
+ * Preact-compatible `useId` — returns a stable unique string per hook call.
38
+ */
39
+ declare function useId(): string;
40
+ /**
41
+ * Preact-compatible `memo` — wraps a component to skip re-render when props
42
+ * are shallowly equal.
43
+ */
44
+ declare function memo<P extends Record<string, unknown>>(component: (props: P) => VNodeChild, areEqual?: (prevProps: P, nextProps: P) => boolean): (props: P) => VNodeChild;
176
45
  //#endregion
177
46
  export { memo, useCallback, useContext, useEffect, onErrorCaptured as useErrorBoundary, useId, useLayoutEffect, useMemo, useReducer, useRef, useState };
178
- //# sourceMappingURL=hooks.d.ts.map
47
+ //# sourceMappingURL=hooks2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","names":[],"sources":["../../../src/jsx-runtime.ts","../../../src/hooks.ts"],"mappings":";AAwCA,SAAgB,aAAA,CAAA,EAAsC;EACpD,OAAO,WAAA;;AAGT,SAAgB,YAAA,CAAA,EAAuB;EACrC,OAAO,UAAA,EAAA;;;;;AC1BT,SAAS,UAAA,CAAA,EAAa;EACpB,MAAM,GAAA,GAAM,aAAA,CAAA,CAAe;EAC3B,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,2CAAA,CAA4C;EACtE,OAAO,GAAA;;AAGT,SAAS,WAAA,CAAY,CAAA,EAA0B,CAAA,EAAmC;EAChF,IAAI,CAAA,KAAM,KAAA,CAAA,IAAa,CAAA,KAAM,KAAA,CAAA,EAAW,OAAO,IAAA;EAC/C,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,IAAA;EAClC,KAAK,IAAI,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,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C,OAAA,CAAQ,KAAA,EAAO,UAAA,EAAY,SAAA,EAAW,OAAA;AAAA,UAMrC,aAAA;EAAA,SACN,EAAA;EAAA,SACA,YAAA,EAAc,CAAA;EACvB,QAAA,EAAU,WAAA;IAAc,KAAA,EAAO,CAAA;IAAG,QAAA,GAAW,UAAA;EAAA;AAAA;;;;iBAM/B,aAAA,GAAA,CAAiB,YAAA,EAAc,CAAA,GAAI,aAAA,CAAc,CAAA;;;;;;;cAuBpD,SAAA,WACD,KAAA,GAAQ,KAAA,YACR,MAAA,oBAA0B,MAAA;EAEpC,KAAA,EAAO,CAAA;EACP,KAAA,EAAO,CAAA;EAAA,QACC,YAAA;cAEI,KAAA,EAAO,CAAA;EA/B8B;;;;EAyCjD,QAAA,CAAS,OAAA,EAAS,OAAA,CAAQ,CAAA,MAAO,IAAA,EAAM,CAAA,KAAM,OAAA,CAAQ,CAAA;EAzCtB;;;EAuD/B,WAAA,CAAA;EAvDgE;AAuBlE;;EAuCE,MAAA,CAAA,GAAU,UAAA;AAAA;;;;iBAUI,YAAA,CAAa,KAAA,EAAO,KAAA,EAAO,KAAA,GAAQ,KAAA,KAAU,QAAA,EAAU,UAAA,KAAe,KAAA;;;;;KAiBjF,cAAA,GAAiB,UAAA,GAAa,cAAA;AAAA,iBAEnB,YAAA,CAAa,QAAA,EAAU,cAAA,GAAiB,UAAA;;;;iBAsBxC,cAAA,CAAe,CAAA,YAAa,CAAA,IAAK,KAAA;;;;;cAgBpC,OAAA,EAAS,MAAA"}
@@ -1,87 +1,10 @@
1
- import { Fragment, h } from "@pyreon/core";
2
- import { signal } from "@pyreon/reactivity";
1
+ import { ComponentFn, Fragment, Props, VNode, VNodeChild } from "@pyreon/core";
3
2
 
4
- //#region src/jsx-runtime.ts
5
-
6
- function beginRender(ctx) {
7
- _currentCtx = ctx;
8
- _hookIndex = 0;
9
- ctx.pendingEffects = [];
10
- ctx.pendingLayoutEffects = [];
11
- }
12
- function endRender() {
13
- _currentCtx = null;
14
- _hookIndex = 0;
15
- }
16
- function runLayoutEffects(entries) {
17
- for (const entry of entries) {
18
- if (entry.cleanup) entry.cleanup();
19
- const cleanup = entry.fn();
20
- entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
21
- }
22
- }
23
- function scheduleEffects(ctx, entries) {
24
- if (entries.length === 0) return;
25
- queueMicrotask(() => {
26
- for (const entry of entries) {
27
- if (ctx.unmounted) return;
28
- if (entry.cleanup) entry.cleanup();
29
- const cleanup = entry.fn();
30
- entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
31
- }
32
- });
33
- }
34
- function wrapCompatComponent(preactComponent) {
35
- let wrapped = _wrapperCache.get(preactComponent);
36
- if (wrapped) return wrapped;
37
- wrapped = props => {
38
- const ctx = {
39
- hooks: [],
40
- scheduleRerender: () => {},
41
- pendingEffects: [],
42
- pendingLayoutEffects: [],
43
- unmounted: false
44
- };
45
- const version = signal(0);
46
- let updateScheduled = false;
47
- ctx.scheduleRerender = () => {
48
- if (ctx.unmounted || updateScheduled) return;
49
- updateScheduled = true;
50
- queueMicrotask(() => {
51
- updateScheduled = false;
52
- if (!ctx.unmounted) version.set(version.peek() + 1);
53
- });
54
- };
55
- return () => {
56
- version();
57
- beginRender(ctx);
58
- const result = preactComponent(props);
59
- const layoutEffects = ctx.pendingLayoutEffects;
60
- const effects = ctx.pendingEffects;
61
- endRender();
62
- runLayoutEffects(layoutEffects);
63
- scheduleEffects(ctx, effects);
64
- return result;
65
- };
66
- };
67
- _wrapperCache.set(preactComponent, wrapped);
68
- return wrapped;
69
- }
70
- function jsx(type, props, key) {
71
- const {
72
- children,
73
- ...rest
74
- } = props;
75
- const propsWithKey = key != null ? {
76
- ...rest,
77
- key
78
- } : rest;
79
- if (typeof type === "function") return h(wrapCompatComponent(type), children !== void 0 ? {
80
- ...propsWithKey,
81
- children
82
- } : propsWithKey);
83
- return h(type, propsWithKey, ...(children === void 0 ? [] : Array.isArray(children) ? children : [children]));
84
- }
3
+ //#region src/jsx-runtime.d.ts
4
+ declare function jsx(type: string | ComponentFn | symbol, props: Props & {
5
+ children?: VNodeChild | VNodeChild[];
6
+ }, key?: string | number | null): VNode;
7
+ declare const jsxs: typeof jsx;
85
8
  //#endregion
86
9
  export { Fragment, jsx, jsxs };
87
- //# sourceMappingURL=jsx-runtime.d.ts.map
10
+ //# sourceMappingURL=jsx-runtime2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-runtime.d.ts","names":[],"sources":["../../../src/jsx-runtime.ts"],"mappings":";;;;;AAgDA,SAAgB,WAAA,CAAY,GAAA,EAA0B;EACpD,WAAA,GAAc,GAAA;EACd,UAAA,GAAa,CAAA;EACb,GAAA,CAAI,cAAA,GAAiB,EAAE;EACvB,GAAA,CAAI,oBAAA,GAAuB,EAAE;;AAG/B,SAAgB,SAAA,CAAA,EAAkB;EAChC,WAAA,GAAc,IAAA;EACd,UAAA,GAAa,CAAA;;AAKf,SAAS,gBAAA,CAAiB,OAAA,EAA8B;EACtD,KAAK,MAAM,KAAA,IAAS,OAAA,EAAS;IAC3B,IAAI,KAAA,CAAM,OAAA,EAAS,KAAA,CAAM,OAAA,CAAA,CAAS;IAClC,MAAM,OAAA,GAAU,KAAA,CAAM,EAAA,CAAA,CAAI;IAC1B,KAAA,CAAM,OAAA,GAAU,OAAO,OAAA,KAAY,UAAA,GAAa,OAAA,GAAU,KAAA,CAAA;;;AAI9D,SAAS,eAAA,CAAgB,GAAA,EAAoB,OAAA,EAA8B;EACzE,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,EAAG;EAC1B,cAAA,CAAA,MAAqB;IACnB,KAAK,MAAM,KAAA,IAAS,OAAA,EAAS;MAC3B,IAAI,GAAA,CAAI,SAAA,EAAW;MACnB,IAAI,KAAA,CAAM,OAAA,EAAS,KAAA,CAAM,OAAA,CAAA,CAAS;MAClC,MAAM,OAAA,GAAU,KAAA,CAAM,EAAA,CAAA,CAAI;MAC1B,KAAA,CAAM,OAAA,GAAU,OAAO,OAAA,KAAY,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AAE,QAAA;IAAU,GAAG;EAAA,CAAA,GAAS,KAAA;EAC9B,MAAM,YAAA,GAAgB,GAAA,IAAO,IAAA,GAAO;IAAE,GAAG,IAAA;IAAM;GAAK,GAAG,IAAA;EAEvD,IAAI,OAAO,IAAA,KAAS,UAAA,EAIlB,OAAO,CAAA,CAFS,mBAAA,CAAoB,IAAA,CAAK,EAClB,QAAA,KAAa,KAAA,CAAA,GAAY;IAAE,GAAG,YAAA;IAAc;GAAU,GAAG,YAAA,CAC/C;EAMnC,OAAO,CAAA,CAAE,IAAA,EAAM,YAAA,EAAc,IAFV,QAAA,KAAa,KAAA,CAAA,GAAY,EAAE,GAAG,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,GAAG,QAAA,GAAW,CAAC,QAAA,CAAS,EAEnC"}
1
+ {"version":3,"file":"jsx-runtime2.d.ts","names":[],"sources":["../../../src/jsx-runtime.ts"],"mappings":";;;iBA2IgB,GAAA,CACd,IAAA,WAAe,WAAA,WACf,KAAA,EAAO,KAAA;EAAU,QAAA,GAAW,UAAA,GAAa,UAAA;AAAA,GACzC,GAAA,4BACC,KAAA;AAAA,cAiBU,IAAA,SAAI,GAAA"}
@@ -1,57 +1,35 @@
1
- import { batch as pyreonBatch, computed as computed$1, effect as effect$1, signal as signal$1 } from "@pyreon/reactivity";
1
+ import { batch as pyreonBatch } from "@pyreon/reactivity";
2
2
 
3
- //#region src/signals.ts
4
- /**
5
- * Create a Preact-style signal with `.value` accessor.
6
- *
7
- * @example
8
- * const count = signal(0)
9
- * count.value++ // write
10
- * console.log(count.value) // read (tracked)
11
- */
12
- function signal(initial) {
13
- const s = signal$1(initial);
14
- return {
15
- get value() {
16
- return s();
17
- },
18
- set value(v) {
19
- s.set(v);
20
- },
21
- peek() {
22
- return s.peek();
23
- }
24
- };
3
+ //#region src/signals.d.ts
4
+ interface ReadonlySignal<T> {
5
+ readonly value: T;
6
+ peek(): T;
25
7
  }
26
- /**
27
- * Create a Preact-style computed with `.value` accessor.
28
- *
29
- * @example
30
- * const doubled = computed(() => count.value * 2)
31
- * console.log(doubled.value)
32
- */
33
- function computed(fn) {
34
- const c = computed$1(fn);
35
- return {
36
- get value() {
37
- return c();
38
- },
39
- peek() {
40
- return c();
41
- }
42
- };
8
+ interface WritableSignal<T> extends ReadonlySignal<T> {
9
+ value: T;
43
10
  }
44
11
  /**
45
- * Run a side-effect that auto-tracks signal reads.
46
- * Returns a dispose function.
47
- */
48
- function effect(fn) {
49
- const e = effect$1(fn);
50
- return () => {
51
- e.dispose();
52
- };
53
- }
54
-
12
+ * Create a Preact-style signal with `.value` accessor.
13
+ *
14
+ * @example
15
+ * const count = signal(0)
16
+ * count.value++ // write
17
+ * console.log(count.value) // read (tracked)
18
+ */
19
+ declare function signal<T>(initial: T): WritableSignal<T>;
20
+ /**
21
+ * Create a Preact-style computed with `.value` accessor.
22
+ *
23
+ * @example
24
+ * const doubled = computed(() => count.value * 2)
25
+ * console.log(doubled.value)
26
+ */
27
+ declare function computed<T>(fn: () => T): ReadonlySignal<T>;
28
+ /**
29
+ * Run a side-effect that auto-tracks signal reads.
30
+ * Returns a dispose function.
31
+ */
32
+ declare function effect(fn: () => void | (() => void)): () => void;
55
33
  //#endregion
56
- export { pyreonBatch as batch, computed, effect, signal };
57
- //# sourceMappingURL=signals.d.ts.map
34
+ export { ReadonlySignal, WritableSignal, pyreonBatch as batch, computed, effect, signal };
35
+ //# sourceMappingURL=signals2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.d.ts","names":["pyreonSignal","pyreonComputed","pyreonEffect"],"sources":["../../../src/signals.ts"],"mappings":";;;;;;;;;;;AAkCA,SAAgB,MAAA,CAAU,OAAA,EAA+B;EACvD,MAAM,CAAA,GAAIA,QAAAA,CAAgB,OAAA,CAAQ;EAClC,OAAO;IACL,IAAI,KAAA,CAAA,EAAW;MACb,OAAO,CAAA,CAAA,CAAG;;IAEZ,IAAI,KAAA,CAAM,CAAA,EAAM;MACd,CAAA,CAAE,GAAA,CAAI,CAAA,CAAE;;IAEV,IAAA,CAAA,EAAU;MACR,OAAO,CAAA,CAAE,IAAA,CAAA,CAAM;;GAElB;;;;;;;;;AAYH,SAAgB,QAAA,CAAY,EAAA,EAAgC;EAC1D,MAAM,CAAA,GAAIC,UAAAA,CAAe,EAAA,CAAG;EAC5B,OAAO;IACL,IAAI,KAAA,CAAA,EAAW;MACb,OAAO,CAAA,CAAA,CAAG;;IAEZ,IAAA,CAAA,EAAU;MAER,OAAO,CAAA,CAAA,CAAG;;GAEb;;;;;;AAUH,SAAgB,MAAA,CAAO,EAAA,EAA2C;EAEhE,MAAM,CAAA,GAAYC,QAAAA,CAAa,EAAA,CAAG;EAClC,OAAA,MAAa;IACX,CAAA,CAAE,OAAA,CAAA,CAAS"}
1
+ {"version":3,"file":"signals2.d.ts","names":[],"sources":["../../../src/signals.ts"],"mappings":";;;UAiBiB,cAAA;EAAA,SACN,KAAA,EAAO,CAAA;EAChB,IAAA,IAAQ,CAAA;AAAA;AAAA,UAGO,cAAA,YAA0B,cAAA,CAAe,CAAA;EACxD,KAAA,EAAO,CAAA;AAAA;AADT;;;;;;;;AAAA,iBAYgB,MAAA,GAAA,CAAU,OAAA,EAAS,CAAA,GAAI,cAAA,CAAe,CAAA;;;;;;;AAAtD;iBAwBgB,QAAA,GAAA,CAAY,EAAA,QAAU,CAAA,GAAI,cAAA,CAAe,CAAA;;;;;iBAoBzC,MAAA,CAAO,EAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyreon/preact-compat",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "Preact-compatible API shim for Pyreon — write Preact-style code that runs on Pyreon's reactive engine",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -59,9 +59,9 @@
59
59
  "prepublishOnly": "bun run build"
60
60
  },
61
61
  "dependencies": {
62
- "@pyreon/core": "^0.5.6",
63
- "@pyreon/reactivity": "^0.5.6",
64
- "@pyreon/runtime-dom": "^0.5.6"
62
+ "@pyreon/core": "^0.6.0",
63
+ "@pyreon/reactivity": "^0.6.0",
64
+ "@pyreon/runtime-dom": "^0.6.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@happy-dom/global-registrator": "^20.8.3",
package/src/index.ts CHANGED
@@ -15,9 +15,7 @@ import type { ComponentFn, Props, VNode, VNodeChild } from "@pyreon/core"
15
15
  import {
16
16
  createRef,
17
17
  Fragment,
18
- onUnmount,
19
- popContext,
20
- pushContext,
18
+ provide,
21
19
  createContext as pyreonCreateContext,
22
20
  h as pyreonH,
23
21
  useContext,
@@ -67,9 +65,8 @@ export interface PreactContext<T> {
67
65
  export function createContext<T>(defaultValue: T): PreactContext<T> {
68
66
  const ctx = pyreonCreateContext<T>(defaultValue)
69
67
  const Provider = ((props: { value: T; children?: VNodeChild }) => {
70
- pushContext(new Map([[ctx.id, props.value]]))
71
- onUnmount(() => popContext())
72
- return props.children as VNode | null
68
+ provide(ctx, props.value)
69
+ return props.children
73
70
  }) as ComponentFn<{ value: T; children?: VNodeChild }>
74
71
  return { ...ctx, Provider }
75
72
  }