@pyreon/preact-compat 0.4.0 → 0.5.1

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.
@@ -0,0 +1,87 @@
1
+ import { Fragment, h } from "@pyreon/core";
2
+ import { signal } from "@pyreon/reactivity";
3
+
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
+ }
85
+ //#endregion
86
+ export { Fragment, jsx, jsxs };
87
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +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,EA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AI,cAAA;MACpB,SAAA,CAAA,CAAW;MAEX,gBAAA,CAAiB,aAAA,CAAc;MAC/B,eAAA,CAAgB,GAAA,EAAK,OAAA,CAAQ;MAE7B,OAAO,MAAA;;;EAIX,aAAA,CAAc,GAAA,CAAI,eAAA,EAAiB,OAAA,CAAQ;EAC3C,OAAO,OAAA;;AAKT,SAAgB,GAAA,CACd,IAAA,EACA,KAAA,EACA,GAAA,EACO;EACP,MAAM;IAAE,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"}
@@ -0,0 +1,10 @@
1
+ import { ComponentFn, Fragment, Props, VNode, VNodeChild } from "@pyreon/core";
2
+
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;
8
+ //#endregion
9
+ export { Fragment, jsx, jsxs };
10
+ //# sourceMappingURL=jsx-runtime2.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,57 @@
1
+ import { batch as pyreonBatch, computed as computed$1, effect as effect$1, signal as signal$1 } from "@pyreon/reactivity";
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
+ };
25
+ }
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
+ };
43
+ }
44
+ /**
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
+
55
+ //#endregion
56
+ export { pyreonBatch as batch, computed, effect, signal };
57
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,35 @@
1
+ import { batch as pyreonBatch } from "@pyreon/reactivity";
2
+
3
+ //#region src/signals.d.ts
4
+ interface ReadonlySignal<T> {
5
+ readonly value: T;
6
+ peek(): T;
7
+ }
8
+ interface WritableSignal<T> extends ReadonlySignal<T> {
9
+ value: T;
10
+ }
11
+ /**
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;
33
+ //#endregion
34
+ export { ReadonlySignal, WritableSignal, pyreonBatch as batch, computed, effect, signal };
35
+ //# sourceMappingURL=signals2.d.ts.map
@@ -0,0 +1 @@
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.4.0",
3
+ "version": "0.5.1",
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.4.0",
63
- "@pyreon/reactivity": "^0.4.0",
64
- "@pyreon/runtime-dom": "^0.4.0"
62
+ "@pyreon/core": "^0.5.1",
63
+ "@pyreon/reactivity": "^0.5.1",
64
+ "@pyreon/runtime-dom": "^0.5.1"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@happy-dom/global-registrator": "^20.8.3",
@@ -0,0 +1 @@
1
+ export { Fragment, jsx, jsxs } from "./jsx-runtime"