@potok-web-framework/core 0.1.0 → 0.3.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.
Files changed (94) hide show
  1. package/dist/block.d.ts +17 -0
  2. package/dist/bootstrap-app.d.ts +8 -0
  3. package/dist/client-only.d.ts +3 -0
  4. package/dist/client.mjs +133 -0
  5. package/dist/constants-BOAOReQ3.mjs +26 -0
  6. package/dist/constants.d.ts +2 -0
  7. package/dist/context.d.ts +12 -0
  8. package/dist/detect-child.d.ts +6 -0
  9. package/dist/error-boundary.d.ts +5 -0
  10. package/dist/exports/client.d.ts +1 -0
  11. package/dist/exports/hmr.d.ts +1 -0
  12. package/dist/exports/index.d.ts +14 -0
  13. package/dist/exports/jsx-runtime.d.ts +4 -0
  14. package/dist/exports/server.d.ts +1 -0
  15. package/dist/fragment-BahmURhz.mjs +17 -0
  16. package/dist/fragment.d.ts +4 -0
  17. package/dist/hmr/hmr-dev.d.ts +9 -0
  18. package/dist/hmr/register-component.d.ts +2 -0
  19. package/dist/hmr/registered-component.d.ts +23 -0
  20. package/dist/hmr/registry.d.ts +12 -0
  21. package/dist/hmr/types.d.ts +4 -0
  22. package/dist/hmr/utils.d.ts +3 -0
  23. package/dist/hmr.mjs +42 -0
  24. package/dist/html-element-Cm0RtMkT.mjs +42 -0
  25. package/dist/html-element.d.ts +6 -0
  26. package/dist/index.mjs +199 -0
  27. package/dist/jsx-runtime.mjs +10 -0
  28. package/dist/jsx-types.d.ts +11 -0
  29. package/dist/lazy.d.ts +7 -0
  30. package/dist/lib-context-reader.d.ts +5 -0
  31. package/dist/lib-scripts.d.ts +2 -0
  32. package/dist/lifecycle-4vjEuXGy.mjs +57 -0
  33. package/dist/lifecycle.d.ts +8 -0
  34. package/dist/list.d.ts +9 -0
  35. package/dist/portal-CbcYOHLv.mjs +44 -0
  36. package/dist/portal.d.ts +10 -0
  37. package/dist/prop-types.d.ts +939 -0
  38. package/dist/ref.d.ts +6 -0
  39. package/dist/render-to-dom.d.ts +8 -0
  40. package/dist/render-to-string.d.ts +2 -0
  41. package/dist/server-node.d.ts +10 -0
  42. package/dist/server.mjs +1192 -0
  43. package/dist/show.d.ts +6 -0
  44. package/dist/signals.d.ts +32 -0
  45. package/dist/store.d.ts +26 -0
  46. package/dist/text.d.ts +5 -0
  47. package/dist/types.d.ts +39 -0
  48. package/dist/utils-CAe_kbSH.mjs +345 -0
  49. package/dist/utils.d.ts +11 -0
  50. package/package.json +9 -3
  51. package/CHANGELOG.md +0 -7
  52. package/bun.lock +0 -25
  53. package/src/block.ts +0 -102
  54. package/src/bootstrap-app.ts +0 -115
  55. package/src/client-only.ts +0 -17
  56. package/src/constants.ts +0 -27
  57. package/src/context.ts +0 -85
  58. package/src/detect-child.ts +0 -21
  59. package/src/error-boundary.ts +0 -51
  60. package/src/exports/client.ts +0 -1
  61. package/src/exports/hmr.ts +0 -1
  62. package/src/exports/index.ts +0 -21
  63. package/src/exports/jsx-runtime.ts +0 -4
  64. package/src/exports/server.ts +0 -1
  65. package/src/fragment.ts +0 -28
  66. package/src/global.dev.d.ts +0 -12
  67. package/src/hmr/hmr-dev.ts +0 -10
  68. package/src/hmr/register-component.ts +0 -109
  69. package/src/hmr/registered-component.ts +0 -59
  70. package/src/hmr/registry.ts +0 -78
  71. package/src/hmr/types.ts +0 -6
  72. package/src/hmr/utils.ts +0 -20
  73. package/src/html-element.ts +0 -95
  74. package/src/jsx-types.ts +0 -13
  75. package/src/lazy.ts +0 -44
  76. package/src/lib-context-reader.ts +0 -33
  77. package/src/lib-scripts.ts +0 -8
  78. package/src/lifecycle.ts +0 -44
  79. package/src/list.ts +0 -175
  80. package/src/portal.ts +0 -101
  81. package/src/prop-types.ts +0 -1165
  82. package/src/ref.ts +0 -11
  83. package/src/render-to-dom.ts +0 -325
  84. package/src/render-to-string.ts +0 -65
  85. package/src/server-node.ts +0 -98
  86. package/src/show.ts +0 -46
  87. package/src/signals.ts +0 -323
  88. package/src/store.ts +0 -68
  89. package/src/text.ts +0 -35
  90. package/src/types.ts +0 -69
  91. package/src/utils.ts +0 -118
  92. package/tests/signals.test.ts +0 -403
  93. package/tsconfig.json +0 -17
  94. package/vite.config.ts +0 -21
@@ -0,0 +1,17 @@
1
+ import { Effect } from './signals';
2
+ import { LibContext, LibHtmlElementNode, LibNode, LibProps } from './types';
3
+ export declare abstract class LibBlock {
4
+ node: LibNode | null;
5
+ abstract context: LibContext;
6
+ abstract props: LibProps;
7
+ effects: Effect[];
8
+ children: (LibBlock | null)[];
9
+ get nearestParentElement(): LibHtmlElementNode | null;
10
+ get previousBlock(): LibBlock | null;
11
+ get nearestPreviousNode(): LibNode | null;
12
+ get previousNode(): LibNode | null;
13
+ addEffect(effect: Effect): void;
14
+ unmountChildren(): void;
15
+ insertNode(): void;
16
+ unmount(): void;
17
+ }
@@ -0,0 +1,8 @@
1
+ import { PotokElement } from './types';
2
+ type App = (request: Request) => PotokElement;
3
+ type BootstrapAppOptions = {
4
+ app: App;
5
+ port?: number;
6
+ };
7
+ export declare function bootstrapApp(options: BootstrapAppOptions): void;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import { PotokElement, WithChildren } from './types';
2
+ export type ClientOnlyProps = WithChildren<{}>;
3
+ export declare function ClientOnly(props: ClientOnlyProps): PotokElement;
@@ -0,0 +1,133 @@
1
+ import { a as objectKeys, c as createEffect, l as createSignal, p as untrack, u as deepTrack } from "./utils-CAe_kbSH.mjs";
2
+ import { n as HTML_ELEMENT_STYLE_PX_PROPERTIES } from "./constants-BOAOReQ3.mjs";
3
+ function renderToDOM(o) {
4
+ let s = o.root ?? document, c = /* @__PURE__ */ new Map(), l = createSignal({
5
+ portals: {},
6
+ listeners: {},
7
+ isHydrating: o.needToHydrate ?? !1
8
+ });
9
+ function u(e) {
10
+ let t = e.replace(/^on([A-Z])/, (e, t) => t.toLowerCase());
11
+ document.addEventListener(t, (t) => {
12
+ let n = !1, r = t.target, i = t.stopPropagation.bind(t), a = t.stopImmediatePropagation.bind(t);
13
+ for (t.stopPropagation = () => {
14
+ n = !0, i();
15
+ }, t.stopImmediatePropagation = () => {
16
+ n = !0, a();
17
+ }; r;) {
18
+ let i = l.listeners[e]?.get(r);
19
+ if (i && (Object.defineProperty(t, "currentTarget", {
20
+ configurable: !0,
21
+ enumerable: !0,
22
+ get: () => r
23
+ }), i(t), n)) break;
24
+ r = r.parentElement;
25
+ }
26
+ });
27
+ }
28
+ let d = /* @__PURE__ */ new Set();
29
+ createEffect(() => {
30
+ deepTrack(l.listeners, 1), untrack(() => {
31
+ objectKeys(l.listeners).forEach((e) => {
32
+ d.has(e) || (u(e), d.add(e));
33
+ });
34
+ });
35
+ }, !0);
36
+ let f = (e, t, n) => e.insertBefore(t, n ? n.nextSibling : e.firstChild), p = (e) => e instanceof HTMLElement;
37
+ if (!o.needToHydrate) for (; s.firstChild;) s.removeChild(s.firstChild);
38
+ o.app()({
39
+ parentBlock: null,
40
+ index: 0,
41
+ portals: l.portals,
42
+ contexts: {},
43
+ listeners: l.listeners,
44
+ isServer: !1,
45
+ promises: [],
46
+ get isHydrating() {
47
+ return l.isHydrating;
48
+ },
49
+ insertNode(e, t, n) {
50
+ if (l.isHydrating) {
51
+ if (e === null) c.set(t, document.querySelector("html"));
52
+ else {
53
+ let r = c.get(e);
54
+ if (!r) throw Error("Ошибка гидрации");
55
+ let i = null;
56
+ if (n) {
57
+ let e = c.get(n);
58
+ if (!e) throw Error("Ошибка гидрации");
59
+ i = e.nextSibling;
60
+ } else i = r.firstChild;
61
+ for (;;) {
62
+ if (!i) throw Error("Ошибка гидрации");
63
+ if (t.type === "text" && String(t.props.text) === i.textContent || t.type === "html-element" && p(i) && t.props.tag === i.tagName.toLowerCase()) {
64
+ c.set(t, i);
65
+ break;
66
+ } else {
67
+ let e = i;
68
+ i = i.nextSibling, e.parentElement?.removeChild(e);
69
+ }
70
+ }
71
+ }
72
+ return;
73
+ }
74
+ e && !c.has(e) && c.set(e, document.createElement(e.props.tag));
75
+ let r = e ? c.get(e) : s, i = (n && c.get(n)) ?? null;
76
+ if (t.type === "text") {
77
+ let e = document.createTextNode(String(t.props.text));
78
+ c.set(t, e), this.updateTextNode(t), f(r, e, i);
79
+ } else if (t.type === "html-element") {
80
+ c.has(t) || c.set(t, document.createElement(t.props.tag));
81
+ for (let [e, n] of Object.entries(Object.getOwnPropertyDescriptors(t.props))) {
82
+ if ([
83
+ "tag",
84
+ "children",
85
+ "ref"
86
+ ].includes(e)) continue;
87
+ let r = n.get?.() ?? n.value;
88
+ this.updateHtmlElementNodeProp(t, e, r);
89
+ }
90
+ let e = c.get(t);
91
+ f(r, e, i), t.props.ref && (t.props.ref.element = e);
92
+ } else throw Error("Неверный тип ноды");
93
+ },
94
+ updateTextNode(e) {
95
+ let t = e.props.text, n = c.get(e);
96
+ n && (n.textContent = String(t));
97
+ },
98
+ updateHtmlElementNodeProp(e, t, n) {
99
+ let r = c.get(e);
100
+ if (!r) return;
101
+ let i = r;
102
+ if (((e) => e.startsWith("on"))(t)) {
103
+ n ? (this.listeners[t] ??= /* @__PURE__ */ new Map(), this.listeners[t].set(i, n)) : this.listeners[t]?.delete(i);
104
+ return;
105
+ }
106
+ if (t.startsWith("aria")) {
107
+ let e = t.toLowerCase().replace("aria", "aria-");
108
+ n ? i.setAttribute(e, n) : i.removeAttribute(e);
109
+ return;
110
+ }
111
+ if (t === "className") {
112
+ n ? i.className = n : i.removeAttribute("class");
113
+ return;
114
+ }
115
+ if (t === "style") {
116
+ n ? Object.keys(n).forEach((e) => {
117
+ let t = n[e];
118
+ if (t !== void 0) {
119
+ let n = String(HTML_ELEMENT_STYLE_PX_PROPERTIES.has(e) && typeof t == "number" ? `${t}px` : t);
120
+ i.style.setProperty(e, n);
121
+ } else i.style.removeProperty(e);
122
+ }) : i.removeAttribute("style");
123
+ return;
124
+ }
125
+ n == null ? i.removeAttribute(t) : i.setAttribute(t, String(n));
126
+ },
127
+ removeNode(e) {
128
+ let t = c.get(e);
129
+ t && (c.delete(e), p(t) ? t.remove() : t.parentElement?.removeChild(t));
130
+ }
131
+ }), o.needToHydrate && (l.isHydrating = !1);
132
+ }
133
+ export { renderToDOM };
@@ -0,0 +1,26 @@
1
+ const HTML_ELEMENT_STYLE_PX_PROPERTIES = new Set([
2
+ "width",
3
+ "height",
4
+ "top",
5
+ "left",
6
+ "right",
7
+ "bottom",
8
+ "margin",
9
+ "marginTop",
10
+ "marginBottom",
11
+ "marginLeft",
12
+ "marginRight",
13
+ "padding",
14
+ "paddingTop",
15
+ "paddingBottom",
16
+ "paddingLeft",
17
+ "paddingRight",
18
+ "fontSize",
19
+ "borderWidth",
20
+ "borderRadius",
21
+ "maxWidth",
22
+ "minWidth",
23
+ "maxHeight",
24
+ "minHeight"
25
+ ]), CLIENT_ENTRY_FILE_NAME = "client";
26
+ export { HTML_ELEMENT_STYLE_PX_PROPERTIES as n, CLIENT_ENTRY_FILE_NAME as t };
@@ -0,0 +1,2 @@
1
+ export declare const HTML_ELEMENT_STYLE_PX_PROPERTIES: Set<string>;
2
+ export declare const CLIENT_ENTRY_FILE_NAME = "client";
@@ -0,0 +1,12 @@
1
+ import { MaybeArray, PotokElement, WithChildren } from './types';
2
+ type ContextProviderProps<Value extends Record<string, unknown>> = WithChildren<{
3
+ value: Value;
4
+ }>;
5
+ type ContextConsumerProps<Value extends Record<string, unknown>> = {
6
+ children: MaybeArray<(value: Value) => PotokElement>;
7
+ };
8
+ export declare function createContext<Value extends Record<string, unknown>>(): {
9
+ provider(props: ContextProviderProps<Value>): PotokElement;
10
+ reader(props: ContextConsumerProps<Value>): PotokElement;
11
+ };
12
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Child } from './types';
2
+ type DetectChildProps = {
3
+ readonly value: Child;
4
+ };
5
+ export declare function detectChild(props: DetectChildProps): Child;
6
+ export {};
@@ -0,0 +1,5 @@
1
+ import { PotokElement, WithChildren } from './types';
2
+ export type ErrorBoundaryProps = WithChildren<{
3
+ onError?: (error: Error) => void;
4
+ }>;
5
+ export declare function ErrorBoundary(props: ErrorBoundaryProps): PotokElement;
@@ -0,0 +1 @@
1
+ export { renderToDOM } from '../render-to-dom';
@@ -0,0 +1 @@
1
+ export { registerComponent } from '../hmr/register-component';
@@ -0,0 +1,14 @@
1
+ export { ClientOnly } from '../client-only';
2
+ export { ErrorBoundary } from '../error-boundary';
3
+ export { Lazy } from '../lazy';
4
+ export { LibContextReader } from '../lib-context-reader';
5
+ export { LibScripts } from '../lib-scripts';
6
+ export { Lifecycle } from '../lifecycle';
7
+ export { List } from '../list';
8
+ export { PortalIn, PortalOut } from '../portal';
9
+ export { createElementReference } from '../ref';
10
+ export { Show } from '../show';
11
+ export { createSignal, createEffect, batch, untrack, deepTrack, getSignal, } from '../signals';
12
+ export { createStore } from '../store';
13
+ export type { PotokElement, WithChildren } from '../types';
14
+ export type * from '../jsx-types.ts';
@@ -0,0 +1,4 @@
1
+ export { fragment } from '../fragment';
2
+ export { htmlElement } from '../html-element';
3
+ export { text } from '../text';
4
+ export { detectChild } from '../detect-child';
@@ -0,0 +1 @@
1
+ export { bootstrapApp } from '../bootstrap-app';
@@ -0,0 +1,17 @@
1
+ import { _ as LibBlock, i as normalizeChildren, n as mergeContext } from "./utils-CAe_kbSH.mjs";
2
+ var FragmentClass = class extends LibBlock {
3
+ constructor(e, n) {
4
+ super(), this.props = e, this.context = n, normalizeChildren(e.children).forEach((e, t) => {
5
+ this.children.push(e(mergeContext(n, {
6
+ parentBlock: this,
7
+ index: t
8
+ })));
9
+ });
10
+ }
11
+ };
12
+ function fragment(e) {
13
+ return function(t) {
14
+ return new FragmentClass(e, t);
15
+ };
16
+ }
17
+ export { fragment as t };
@@ -0,0 +1,4 @@
1
+ import { PotokElement, WithChildren } from './types';
2
+ type FragmentProps = WithChildren<{}>;
3
+ export declare function fragment(props: FragmentProps): PotokElement;
4
+ export {};
@@ -0,0 +1,9 @@
1
+ import { CachedInstanceState } from './registered-component';
2
+ import { HMRRegistry } from './registry';
3
+ export declare const HMR_DEV: {
4
+ registry: HMRRegistry;
5
+ currentInstance: {
6
+ states: CachedInstanceState[];
7
+ stateIndex: number;
8
+ } | null;
9
+ };
@@ -0,0 +1,2 @@
1
+ import { Component, ComponentProps, PotokElement } from '../types';
2
+ export declare function registerComponent<Props extends ComponentProps>(component: (props: Props) => PotokElement, moduleId: string, componentId: string): Component<Props>;
@@ -0,0 +1,23 @@
1
+ import { Component, PotokElement } from '../types';
2
+ import { HMRSubscriber } from './types';
3
+ export type CachedInstanceState = {
4
+ current: unknown;
5
+ initial: unknown;
6
+ };
7
+ type CachedInstance = {
8
+ isRemovable: boolean;
9
+ element: PotokElement;
10
+ states: CachedInstanceState[];
11
+ };
12
+ export declare class RegisteredComponent {
13
+ component: Component<any>;
14
+ subscribers: Set<HMRSubscriber>;
15
+ private cachedInstances;
16
+ constructor(component: Component<any>);
17
+ getCachedInstance(instanceId: string): CachedInstance | undefined;
18
+ addCachedInstance(instanceId: string, element: PotokElement, states: CachedInstanceState[]): void;
19
+ markInstanceAsRemovable(instanceId: string): void;
20
+ unmarkInstanceAsRemovable(instanceId: string): void;
21
+ removeCachedInstance(instanceId: string): void;
22
+ }
23
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Component } from '../types';
2
+ import { ComponentId, HMRSubscriber, ModudeId } from './types';
3
+ import { RegisteredComponent } from './registered-component';
4
+ export declare class HMRRegistry {
5
+ private components;
6
+ private getModuleComponentsMap;
7
+ addComponent(moduleId: ModudeId, componentId: ComponentId, component: Component<any>): RegisteredComponent;
8
+ getRegisteredComponent(moduleId: ModudeId, componentId: ComponentId): RegisteredComponent | undefined;
9
+ subscribeToComponent(moduleId: ModudeId, componentId: ComponentId, subscriber: HMRSubscriber): () => void;
10
+ unsubscribeFromComponent(moduleId: ModudeId, componentId: ComponentId, subscriber: HMRSubscriber): void;
11
+ notifyComponentUpdate(moduleId: ModudeId, componentId: ComponentId): void;
12
+ }
@@ -0,0 +1,4 @@
1
+ import { RegisteredComponent } from './registered-component';
2
+ export type HMRSubscriber = (component: RegisteredComponent | undefined) => void;
3
+ export type ModudeId = string;
4
+ export type ComponentId = string;
@@ -0,0 +1,3 @@
1
+ import { LibContext } from '../types';
2
+ export declare function isWindowDefined(): boolean;
3
+ export declare function getComponentInstanceId(context: LibContext): string;
package/dist/hmr.mjs ADDED
@@ -0,0 +1,42 @@
1
+ import { g as HMR_DEV, h as isWindowDefined, l as createSignal, m as getComponentInstanceId } from "./utils-CAe_kbSH.mjs";
2
+ import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-4vjEuXGy.mjs";
3
+ import { t as fragment } from "./fragment-BahmURhz.mjs";
4
+ function registerComponent(o, s, c) {
5
+ if (!isWindowDefined()) return o;
6
+ let l = HMR_DEV.registry.addComponent(s, c, o);
7
+ HMR_DEV.registry.notifyComponentUpdate(s, c);
8
+ function u(e, t, n = !1) {
9
+ let r = getComponentInstanceId(t), i = l.getCachedInstance(r);
10
+ if (!n && i) return i.element;
11
+ HMR_DEV.currentInstance = {
12
+ states: i ? i.states : [],
13
+ stateIndex: 0
14
+ };
15
+ let a = l.component(e);
16
+ return l.addCachedInstance(r, a, HMR_DEV.currentInstance.states), HMR_DEV.currentInstance = null, a;
17
+ }
18
+ return (e) => LibContextReader({ children(r) {
19
+ let o = createSignal({ element: u(e, r) }), d = getComponentInstanceId(r);
20
+ return Lifecycle({
21
+ onMounted() {
22
+ let t = HMR_DEV.registry.subscribeToComponent(s, c, () => {
23
+ o.element = null, o.element = u(e, r, !0);
24
+ });
25
+ return l.unmarkInstanceAsRemovable(d), () => {
26
+ t(), l.markInstanceAsRemovable(d), setTimeout(() => {
27
+ l.getCachedInstance(d)?.isRemovable && l.removeCachedInstance(d);
28
+ });
29
+ };
30
+ },
31
+ children: [Show({
32
+ get when() {
33
+ return o.element !== null;
34
+ },
35
+ children: [fragment({ get children() {
36
+ return [o.element];
37
+ } })]
38
+ })]
39
+ });
40
+ } });
41
+ }
42
+ export { registerComponent };
@@ -0,0 +1,42 @@
1
+ import { _ as LibBlock, a as objectKeys, c as createEffect, i as normalizeChildren, n as mergeContext, t as extractListenersFromProps } from "./utils-CAe_kbSH.mjs";
2
+ var LibHTMLElement = class extends LibBlock {
3
+ constructor(e, t) {
4
+ super(), this.props = e, this.context = t;
5
+ let a = {
6
+ type: "html-element",
7
+ context: t,
8
+ props: e
9
+ };
10
+ this.node = a;
11
+ let o = Object.getOwnPropertyDescriptors(e);
12
+ for (let [e, r] of Object.entries(o)) {
13
+ if ([
14
+ "tag",
15
+ "children",
16
+ "ref"
17
+ ].includes(e)) continue;
18
+ r.value && t.updateHtmlElementNodeProp(a, e, r.value);
19
+ let i = r.get;
20
+ i && this.addEffect(createEffect(() => {
21
+ t.updateHtmlElementNodeProp(a, e, i());
22
+ }, !0));
23
+ }
24
+ t.isHydrating && this.insertNode(), normalizeChildren(e.children).forEach((e, n) => {
25
+ this.children.push(e(mergeContext(t, {
26
+ parentBlock: this,
27
+ index: n
28
+ })));
29
+ }), t.isHydrating || this.insertNode();
30
+ }
31
+ unmount() {
32
+ this.node && objectKeys(extractListenersFromProps(this.props)).forEach((e) => {
33
+ this.context.listeners[e]?.delete(this.node);
34
+ }), this.props.ref && (this.props.ref.element = null), super.unmount();
35
+ }
36
+ };
37
+ function htmlElement(e) {
38
+ return function(t) {
39
+ return new LibHTMLElement(e, t);
40
+ };
41
+ }
42
+ export { htmlElement as t };
@@ -0,0 +1,6 @@
1
+ import { LibHTMLElementTagNameMap } from './prop-types';
2
+ import { PotokElement } from './types';
3
+ export type LibHTMLElementProps<Tag extends keyof LibHTMLElementTagNameMap> = {
4
+ tag: Tag;
5
+ } & LibHTMLElementTagNameMap[Tag];
6
+ export declare function htmlElement<Tag extends keyof LibHTMLElementTagNameMap>(props: LibHTMLElementProps<Tag>): PotokElement;
package/dist/index.mjs ADDED
@@ -0,0 +1,199 @@
1
+ import { _ as LibBlock, c as createEffect, d as getSignal, f as isSignal, i as normalizeChildren, l as createSignal, n as mergeContext, p as untrack, r as normalizeArray, s as batch, u as deepTrack } from "./utils-CAe_kbSH.mjs";
2
+ import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-4vjEuXGy.mjs";
3
+ import { t as fragment } from "./fragment-BahmURhz.mjs";
4
+ import { n as PortalOut, t as PortalIn } from "./portal-CbcYOHLv.mjs";
5
+ function ClientOnly(e) {
6
+ return LibContextReader({ children: (t) => Show({
7
+ get when() {
8
+ return !t.isServer && !t.isHydrating;
9
+ },
10
+ children: e.children
11
+ }) });
12
+ }
13
+ var ErrorBoundaryClass = class extends LibBlock {
14
+ constructor(e, t) {
15
+ super(), this.props = e, this.context = t;
16
+ try {
17
+ normalizeChildren(e.children).forEach((e, n) => {
18
+ this.children.push(e(mergeContext(t, {
19
+ parentBlock: this,
20
+ index: n
21
+ })));
22
+ });
23
+ } catch (t) {
24
+ e.onError?.(this.buildError(t));
25
+ }
26
+ }
27
+ unmount() {
28
+ try {
29
+ super.unmount();
30
+ } catch (e) {
31
+ this.props.onError?.(this.buildError(e));
32
+ }
33
+ }
34
+ buildError(e) {
35
+ return e instanceof Error ? e : Error(typeof e == "string" ? e : "Unknown error");
36
+ }
37
+ };
38
+ function ErrorBoundary(e) {
39
+ return function(t) {
40
+ return new ErrorBoundaryClass(e, t);
41
+ };
42
+ }
43
+ function Lazy(e) {
44
+ return LibContextReader({ children: (t) => {
45
+ let n = createSignal({ block: null });
46
+ return t.promises.push(e.import().then((t) => {
47
+ n.block = e.resolve(t);
48
+ })), fragment({ children: [Show({
49
+ get when() {
50
+ return n.block !== null;
51
+ },
52
+ children: [n.block]
53
+ }), Show({
54
+ get when() {
55
+ return n.block === null;
56
+ },
57
+ children: [e.fallback]
58
+ })] });
59
+ } });
60
+ }
61
+ function LibScripts() {
62
+ return PortalOut({ name: "lib-scripts" });
63
+ }
64
+ var ListClass = class extends LibBlock {
65
+ signals = [];
66
+ constructor(e, i) {
67
+ super(), this.props = e, this.context = i;
68
+ let c = [];
69
+ this.addEffect(createEffect(() => {
70
+ let t = e.items;
71
+ isSignal(t) && deepTrack(t, 1), untrack(() => {
72
+ this.diff(c, t).forEach((t) => {
73
+ if (t.type === "add") {
74
+ let r = createSignal({
75
+ item: t.item,
76
+ index: t.index
77
+ });
78
+ this.children.splice(t.index, 0, null), this.signals.splice(t.index, 0, getSignal(r));
79
+ let s = e.render(r)(mergeContext(i, {
80
+ parentBlock: this,
81
+ get index() {
82
+ return r.index;
83
+ }
84
+ }));
85
+ this.children[t.index] = s;
86
+ } else if (t.type === "replace") this.signals[t.index].proxy.item = t.newItem;
87
+ else if (t.type === "delete") {
88
+ let e = this.children[t.index];
89
+ this.children.splice(t.index, 1), this.signals.splice(t.index, 1), e?.unmount();
90
+ }
91
+ }), this.signals.forEach((e, t) => {
92
+ e.value.index !== t && (e.proxy.index = t);
93
+ }), c = [...t];
94
+ });
95
+ }, !0));
96
+ }
97
+ diff(e, t) {
98
+ let n = [];
99
+ for (let r = 0; r <= e.length; r++) {
100
+ n.push([r]);
101
+ for (let i = 1; i <= t.length; i++) if (r === 0) n[r].push(i);
102
+ else {
103
+ let a = n[r - 1][i] + 1, o = n[r][i - 1] + 1, s = n[r - 1][i - 1] + (e[r - 1] === t[i - 1] ? 0 : 1);
104
+ n[r].push(Math.min(a, o, s));
105
+ }
106
+ }
107
+ let r = [], i = t.length, a = e.length;
108
+ for (; i > 0 || a > 0;) {
109
+ let o = a > 0 ? n[a - 1][i] : Infinity, s = i > 0 ? n[a][i - 1] : Infinity, c = a > 0 && i > 0 ? n[a - 1][i - 1] : Infinity, l = Math.min(o, s, c);
110
+ l === c ? (e[a - 1] !== t[i - 1] && r.push({
111
+ type: "replace",
112
+ index: a - 1,
113
+ oldItem: e[a - 1],
114
+ newItem: t[i - 1]
115
+ }), i--, a--) : l === o ? (r.push({
116
+ type: "delete",
117
+ index: a - 1
118
+ }), a--) : (r.push({
119
+ type: "add",
120
+ index: a,
121
+ item: t[i - 1]
122
+ }), i--);
123
+ }
124
+ return r;
125
+ }
126
+ unmount() {
127
+ super.unmount(), this.signals = [];
128
+ }
129
+ };
130
+ function List(e) {
131
+ return function(t) {
132
+ return new ListClass(e, t);
133
+ };
134
+ }
135
+ function createElementReference() {
136
+ return createSignal({ element: null });
137
+ }
138
+ var ContextProvider = class extends LibBlock {
139
+ constructor(e, t, n) {
140
+ super(), this.props = e, this.context = n, normalizeChildren(e.children).forEach((r, i) => {
141
+ this.children.push(r(mergeContext(n, {
142
+ parentBlock: this,
143
+ index: i,
144
+ contexts: { [t]: e.value }
145
+ })));
146
+ });
147
+ }
148
+ }, ContextConsumer = class extends LibBlock {
149
+ constructor(e, t, n) {
150
+ super(), this.props = e, this.context = n;
151
+ let r = n.contexts[t];
152
+ if (!r) throw Error("Контекст не найден");
153
+ normalizeArray(e.children).forEach((e, t) => {
154
+ this.children.push(e(r)(mergeContext(n, {
155
+ parentBlock: this,
156
+ index: t
157
+ })));
158
+ });
159
+ }
160
+ };
161
+ function createContext() {
162
+ let e = Symbol("context");
163
+ return {
164
+ provider(t) {
165
+ return function(n) {
166
+ return new ContextProvider(t, e, n);
167
+ };
168
+ },
169
+ reader(t) {
170
+ return function(n) {
171
+ return new ContextConsumer(t, e, n);
172
+ };
173
+ }
174
+ };
175
+ }
176
+ function createStore() {
177
+ return function(e) {
178
+ let t = createContext();
179
+ return {
180
+ provider(n) {
181
+ let r = createSignal(e.state({ props: n })), i = e.actions({
182
+ props: n,
183
+ state: r
184
+ }), o = Object.entries(i).reduce((e, [t, n]) => (e[t] = (...e) => batch(() => n.apply(i, e)), e), {});
185
+ return t.provider({
186
+ value: {
187
+ state: r,
188
+ actions: o
189
+ },
190
+ children: n.children
191
+ });
192
+ },
193
+ reader(e) {
194
+ return t.reader({ children: (t) => e.children(t) });
195
+ }
196
+ };
197
+ };
198
+ }
199
+ export { ClientOnly, ErrorBoundary, Lazy, LibContextReader, LibScripts, Lifecycle, List, PortalIn, PortalOut, Show, batch, createEffect, createElementReference, createSignal, createStore, deepTrack, getSignal, untrack };
@@ -0,0 +1,10 @@
1
+ import { o as text } from "./utils-CAe_kbSH.mjs";
2
+ import { t as fragment } from "./fragment-BahmURhz.mjs";
3
+ import { t as htmlElement } from "./html-element-Cm0RtMkT.mjs";
4
+ function detectChild(e) {
5
+ let t = e.value, n = typeof t;
6
+ return n === "string" || n === "number" || n === "boolean" ? text({ get text() {
7
+ return e.value;
8
+ } }) : t;
9
+ }
10
+ export { detectChild, fragment, htmlElement, text };
@@ -0,0 +1,11 @@
1
+ import { LibHTMLElementTagNameMap } from './prop-types';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements extends LibHTMLElementTagNameMap {
5
+ }
6
+ interface ElementChildrenAttribute {
7
+ children: {};
8
+ }
9
+ }
10
+ }
11
+ export {};
package/dist/lazy.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { PotokElement } from './types';
2
+ export type LazyProps<Module> = {
3
+ import: () => Promise<Module>;
4
+ resolve: (module: Module) => PotokElement;
5
+ fallback?: PotokElement;
6
+ };
7
+ export declare function Lazy<Module>(props: LazyProps<Module>): PotokElement;