@bgub/fig-reconciler 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Ben Gubler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @bgub/fig-reconciler
2
+
3
+ Fig host-config reconciler.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @bgub/fig-reconciler
9
+ ```
10
+
11
+ Fig packages are ESM-only and require Node `^20.19.0 || >=22.12.0` for Node runtime entry
12
+ points.
@@ -0,0 +1,69 @@
1
+ import { DependencyList, ElementType, FigContext, Props } from "@bgub/fig";
2
+ import { DataStoreEntrySnapshot } from "@bgub/fig/internal";
3
+ //#region src/devtools.d.ts
4
+ type FigDevtoolsFiberKind = "root" | "host" | "text" | "function" | "fragment" | "assets" | "context-provider" | "suspense" | "error-boundary" | "portal" | "activity" | "view-transition";
5
+ type FigDevtoolsHookKind = "state" | "action-state" | "id" | "deferred-value" | "external-store" | "memo" | "transition" | "stable-event" | "reactive" | "before-paint" | "before-layout";
6
+ type FigDevtoolsEffectPhase = "reactive" | "before-paint" | "before-layout";
7
+ type FigDevtoolsWorkLabel = "sync" | "input" | "default" | "gesture" | "transition" | "retry" | "idle" | "offscreen" | "deferred" | "selective-hydration";
8
+ interface FigDevtoolsHookSnapshot {
9
+ id: number;
10
+ kind: FigDevtoolsHookKind;
11
+ state?: unknown;
12
+ deps?: DependencyList | null;
13
+ phase?: FigDevtoolsEffectPhase;
14
+ active?: boolean;
15
+ }
16
+ interface FigDevtoolsFiberSnapshot {
17
+ id: number;
18
+ parentId: number | null;
19
+ name: string;
20
+ kind: FigDevtoolsFiberKind;
21
+ key: string | number | null;
22
+ index: number;
23
+ props: Props;
24
+ pendingWork: FigDevtoolsWorkLabel[];
25
+ childWork: FigDevtoolsWorkLabel[];
26
+ hooks: FigDevtoolsHookSnapshot[];
27
+ contextDependencies: string[];
28
+ host?: FigDevtoolsHostSnapshot;
29
+ capturedError?: unknown;
30
+ componentStack?: string;
31
+ children: FigDevtoolsFiberSnapshot[];
32
+ }
33
+ interface FigDevtoolsHostSnapshot {
34
+ kind: "element" | "text";
35
+ tagName?: string;
36
+ attributes?: Record<string, string>;
37
+ text?: string;
38
+ }
39
+ interface FigDevtoolsRootSnapshot {
40
+ id: number;
41
+ rendererId: number;
42
+ committedAt: number;
43
+ dataResources: DataStoreEntrySnapshot[];
44
+ pendingWork: FigDevtoolsWorkLabel[];
45
+ suspendedWork: FigDevtoolsWorkLabel[];
46
+ pingedWork: FigDevtoolsWorkLabel[];
47
+ expiredWork: FigDevtoolsWorkLabel[];
48
+ tree: FigDevtoolsFiberSnapshot;
49
+ }
50
+ interface FigDevtoolsElementInspection {
51
+ rootId: number;
52
+ fiberId: number;
53
+ }
54
+ interface FigDevtoolsCommitInspection {
55
+ inspectElement(target: unknown): FigDevtoolsElementInspection | null;
56
+ elementForFiber(fiberId: number): unknown;
57
+ }
58
+ interface FigDevtoolsRendererInfo {
59
+ name: string;
60
+ packageName: string;
61
+ }
62
+ interface FigDevtoolsGlobalHook {
63
+ inject(renderer: FigDevtoolsRendererInfo): number;
64
+ onCommitRoot(rendererId: number, snapshot: FigDevtoolsRootSnapshot, inspection?: FigDevtoolsCommitInspection): void;
65
+ }
66
+ declare function devtoolsTypeName(type: ElementType | FigContext<unknown> | null, fallback: string): string;
67
+ declare function getFigDevtoolsGlobalHook(): FigDevtoolsGlobalHook | null;
68
+ //#endregion
69
+ export { FigDevtoolsCommitInspection, FigDevtoolsEffectPhase, FigDevtoolsElementInspection, FigDevtoolsFiberKind, FigDevtoolsFiberSnapshot, FigDevtoolsGlobalHook, FigDevtoolsHookKind, FigDevtoolsHookSnapshot, FigDevtoolsHostSnapshot, FigDevtoolsRendererInfo, FigDevtoolsRootSnapshot, FigDevtoolsWorkLabel, devtoolsTypeName, getFigDevtoolsGlobalHook };
@@ -0,0 +1,22 @@
1
+ import { Fragment } from "@bgub/fig";
2
+ //#region src/devtools.ts
3
+ function devtoolsTypeName(type, fallback) {
4
+ if (typeof type === "string") return type;
5
+ if (type === Fragment) return "Fragment";
6
+ if (typeof type !== "function") return fallback;
7
+ const namedType = type;
8
+ if (typeof namedType.displayName === "string" && namedType.displayName !== "") return namedType.displayName;
9
+ if (typeof namedType.name === "string" && namedType.name !== "") return namedType.name;
10
+ return fallback;
11
+ }
12
+ function getFigDevtoolsGlobalHook() {
13
+ const hook = globalThis.__FIG_DEVTOOLS_GLOBAL_HOOK__;
14
+ if (typeof hook !== "object" || hook === null || !("inject" in hook) || !("onCommitRoot" in hook)) return null;
15
+ const candidate = hook;
16
+ if (typeof candidate.inject !== "function" || typeof candidate.onCommitRoot !== "function") return null;
17
+ return candidate;
18
+ }
19
+ //#endregion
20
+ export { devtoolsTypeName, getFigDevtoolsGlobalHook };
21
+
22
+ //# sourceMappingURL=devtools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools.js","names":["globalWithHook"],"sources":["../src/devtools.ts"],"sourcesContent":["import {\n type DependencyList,\n type ElementType,\n type FigContext,\n Fragment,\n type Props,\n} from \"@bgub/fig\";\nimport type { DataStoreEntrySnapshot } from \"@bgub/fig/internal\";\n\nexport type FigDevtoolsFiberKind =\n | \"root\"\n | \"host\"\n | \"text\"\n | \"function\"\n | \"fragment\"\n | \"assets\"\n | \"context-provider\"\n | \"suspense\"\n | \"error-boundary\"\n | \"portal\"\n | \"activity\"\n | \"view-transition\";\n\nexport type FigDevtoolsHookKind =\n | \"state\"\n | \"action-state\"\n | \"id\"\n | \"deferred-value\"\n | \"external-store\"\n | \"memo\"\n | \"transition\"\n | \"stable-event\"\n | \"reactive\"\n | \"before-paint\"\n | \"before-layout\";\n\nexport type FigDevtoolsEffectPhase =\n | \"reactive\"\n | \"before-paint\"\n | \"before-layout\";\n\nexport type FigDevtoolsWorkLabel =\n | \"sync\"\n | \"input\"\n | \"default\"\n | \"gesture\"\n | \"transition\"\n | \"retry\"\n | \"idle\"\n | \"offscreen\"\n | \"deferred\"\n | \"selective-hydration\";\n\nexport interface FigDevtoolsHookSnapshot {\n id: number;\n kind: FigDevtoolsHookKind;\n state?: unknown;\n deps?: DependencyList | null;\n phase?: FigDevtoolsEffectPhase;\n active?: boolean;\n}\n\nexport interface FigDevtoolsFiberSnapshot {\n id: number;\n parentId: number | null;\n name: string;\n kind: FigDevtoolsFiberKind;\n key: string | number | null;\n index: number;\n props: Props;\n pendingWork: FigDevtoolsWorkLabel[];\n childWork: FigDevtoolsWorkLabel[];\n hooks: FigDevtoolsHookSnapshot[];\n contextDependencies: string[];\n host?: FigDevtoolsHostSnapshot;\n capturedError?: unknown;\n componentStack?: string;\n children: FigDevtoolsFiberSnapshot[];\n}\n\nexport interface FigDevtoolsHostSnapshot {\n kind: \"element\" | \"text\";\n tagName?: string;\n attributes?: Record<string, string>;\n text?: string;\n}\n\nexport interface FigDevtoolsRootSnapshot {\n id: number;\n rendererId: number;\n committedAt: number;\n dataResources: DataStoreEntrySnapshot[];\n pendingWork: FigDevtoolsWorkLabel[];\n suspendedWork: FigDevtoolsWorkLabel[];\n pingedWork: FigDevtoolsWorkLabel[];\n expiredWork: FigDevtoolsWorkLabel[];\n tree: FigDevtoolsFiberSnapshot;\n}\n\nexport interface FigDevtoolsElementInspection {\n rootId: number;\n fiberId: number;\n}\n\nexport interface FigDevtoolsCommitInspection {\n inspectElement(target: unknown): FigDevtoolsElementInspection | null;\n elementForFiber(fiberId: number): unknown;\n}\n\nexport interface FigDevtoolsRendererInfo {\n name: string;\n packageName: string;\n}\n\nexport interface FigDevtoolsGlobalHook {\n inject(renderer: FigDevtoolsRendererInfo): number;\n onCommitRoot(\n rendererId: number,\n snapshot: FigDevtoolsRootSnapshot,\n inspection?: FigDevtoolsCommitInspection,\n ): void;\n}\n\nexport function devtoolsTypeName(\n type: ElementType | FigContext<unknown> | null,\n fallback: string,\n): string {\n if (typeof type === \"string\") return type;\n if (type === Fragment) return \"Fragment\";\n if (typeof type !== \"function\") return fallback;\n\n const namedType = type as {\n displayName?: unknown;\n name?: unknown;\n };\n\n if (typeof namedType.displayName === \"string\" && namedType.displayName !== \"\")\n return namedType.displayName;\n if (typeof namedType.name === \"string\" && namedType.name !== \"\")\n return namedType.name;\n\n return fallback;\n}\n\nexport function getFigDevtoolsGlobalHook(): FigDevtoolsGlobalHook | null {\n const globalWithHook = globalThis as typeof globalThis & {\n __FIG_DEVTOOLS_GLOBAL_HOOK__?: unknown;\n };\n const hook = globalWithHook.__FIG_DEVTOOLS_GLOBAL_HOOK__;\n\n if (\n typeof hook !== \"object\" ||\n hook === null ||\n !(\"inject\" in hook) ||\n !(\"onCommitRoot\" in hook)\n ) {\n return null;\n }\n\n const candidate = hook as Partial<FigDevtoolsGlobalHook>;\n if (\n typeof candidate.inject !== \"function\" ||\n typeof candidate.onCommitRoot !== \"function\"\n ) {\n return null;\n }\n\n return candidate as FigDevtoolsGlobalHook;\n}\n"],"mappings":";;AA2HA,SAAgB,iBACd,MACA,UACQ;CACR,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI,SAAS,UAAU,OAAO;CAC9B,IAAI,OAAO,SAAS,YAAY,OAAO;CAEvC,MAAM,YAAY;CAKlB,IAAI,OAAO,UAAU,gBAAgB,YAAY,UAAU,gBAAgB,IACzE,OAAO,UAAU;CACnB,IAAI,OAAO,UAAU,SAAS,YAAY,UAAU,SAAS,IAC3D,OAAO,UAAU;CAEnB,OAAO;AACT;AAEA,SAAgB,2BAAyD;CAIvE,MAAM,OAAOA,WAAe;CAE5B,IACE,OAAO,SAAS,YAChB,SAAS,QACT,EAAE,YAAY,SACd,EAAE,kBAAkB,OAEpB,OAAO;CAGT,MAAM,YAAY;CAClB,IACE,OAAO,UAAU,WAAW,cAC5B,OAAO,UAAU,iBAAiB,YAElC,OAAO;CAGT,OAAO;AACT"}
@@ -0,0 +1,125 @@
1
+ import { RefreshUpdate } from "./refresh.js";
2
+ import { DataResourceKeyInput, ErrorInfo, FigDataHydrationEntry, FigDataStoreHandle, FigNode, Props } from "@bgub/fig";
3
+ //#region src/scheduler.d.ts
4
+ declare function act<T>(callback: () => T | PromiseLike<T>): Promise<Awaited<T>>;
5
+ //#endregion
6
+ //#region src/index.d.ts
7
+ type EventPriority = "default" | "continuous" | "discrete";
8
+ declare function runWithEventPriority<T>(priority: EventPriority, callback: () => T): T;
9
+ type HostNode<Instance, TextInstance> = Instance | TextInstance;
10
+ type Parent<Container, Instance> = Container | Instance;
11
+ interface DehydratedSuspenseError {
12
+ digest?: string;
13
+ message?: string;
14
+ }
15
+ interface DehydratedSuspenseBoundary<Instance = unknown, TextInstance = unknown> {
16
+ error?: DehydratedSuspenseError | null;
17
+ id: string | null;
18
+ start: HostNode<Instance, TextInstance>;
19
+ end: HostNode<Instance, TextInstance>;
20
+ status: "completed" | "pending" | "client-rendered";
21
+ forceClientRender: boolean;
22
+ }
23
+ type ViewTransitionCommitResult = false | "committed" | "deferred";
24
+ interface ViewTransitionSurfaceMeasurement {
25
+ absolutelyPositioned: boolean;
26
+ height: number;
27
+ inViewport: boolean;
28
+ width: number;
29
+ x: number;
30
+ y: number;
31
+ }
32
+ interface ViewTransitionMutationResult {
33
+ canceledNames: string[];
34
+ cancelRootSnapshot: boolean;
35
+ }
36
+ interface ViewTransitionHostConfig<Container, Instance> {
37
+ commit(this: void, container: Container, prepareSnapshot: () => void, mutate: () => ViewTransitionMutationResult, cleanup: () => void): ViewTransitionCommitResult;
38
+ apply(this: void, instance: Instance, name: string, className: string | null): void;
39
+ restore(this: void, instance: Instance, props: Props): void;
40
+ measure?(this: void, instance: Instance): ViewTransitionSurfaceMeasurement | null;
41
+ suspend?(this: void, container: Container, onFinished: () => void): boolean;
42
+ }
43
+ interface HostConfig<Container, Instance, TextInstance> {
44
+ createInstance(type: string, props: Props, parent: Parent<Container, Instance>): Instance;
45
+ createTextInstance(text: string): TextInstance;
46
+ validateInstanceNesting?(type: string, props: Props, ancestors: readonly string[]): void;
47
+ validateTextNesting?(text: string, ancestors: readonly string[]): void;
48
+ containerType?(container: Parent<Container, Instance>): string | null;
49
+ appendInitialChild?(parent: Instance, child: HostNode<Instance, TextInstance>): void;
50
+ finalizeInitialInstance?(instance: Instance, props: Props): void;
51
+ setTextContent?(instance: Instance, text: string): void;
52
+ getFirstHydratableChild?(parent: Parent<Container, Instance>, props?: Props): HostNode<Instance, TextInstance> | null;
53
+ getNextHydratableSibling?(node: HostNode<Instance, TextInstance>): HostNode<Instance, TextInstance> | null;
54
+ canHydrateInstance?(node: HostNode<Instance, TextInstance>, type: string, props: Props): boolean;
55
+ canHydrateTextInstance?(node: HostNode<Instance, TextInstance>, text: string, suppressHydrationWarning?: boolean): boolean;
56
+ isHoistedInstance?(type: string, props: Props): boolean;
57
+ commitHoistedInstance?(instance: Instance): Instance | void;
58
+ removeHoistedInstance?(instance: Instance): void;
59
+ updateHoistedInstance?(instance: Instance, previousProps: Props, nextProps: Props): Instance;
60
+ shouldCommitUpdate?(type: string, previousProps: Props, nextProps: Props): boolean;
61
+ clearContainer?(container: Container): void;
62
+ insertBefore(parent: Parent<Container, Instance>, child: HostNode<Instance, TextInstance>, before: HostNode<Instance, TextInstance> | null): void;
63
+ removeChild(parent: Parent<Container, Instance>, child: HostNode<Instance, TextInstance>): void;
64
+ commitUpdate(instance: Instance, previousProps: Props, nextProps: Props): void;
65
+ commitHydratedInstance?(instance: Instance, nextProps: Props): void;
66
+ getActivityBoundary?(node: HostNode<Instance, TextInstance>): Instance | null;
67
+ getFirstActivityHydratable?(boundary: Instance): HostNode<Instance, TextInstance> | null;
68
+ commitHydratedActivityBoundary?(boundary: Instance): void;
69
+ hideInstance?(instance: Instance): void;
70
+ unhideInstance?(instance: Instance, props: Props): void;
71
+ hideTextInstance?(instance: TextInstance): void;
72
+ unhideTextInstance?(instance: TextInstance, text: string): void;
73
+ getSuspenseBoundary?(node: HostNode<Instance, TextInstance>): DehydratedSuspenseBoundary<Instance, TextInstance> | null;
74
+ getEnclosingSuspenseBoundaryStart?(target: unknown): HostNode<Instance, TextInstance> | null;
75
+ isTargetWithinSuspenseBoundary?(target: unknown, boundary: DehydratedSuspenseBoundary<Instance, TextInstance>): boolean;
76
+ registerSuspenseBoundaryRetry?(boundary: DehydratedSuspenseBoundary<Instance, TextInstance>, retry: () => void): void;
77
+ commitHydratedSuspenseBoundary?(boundary: DehydratedSuspenseBoundary<Instance, TextInstance>): void;
78
+ completeRootHydration?(container: Container): void;
79
+ removeDehydratedSuspenseBoundary?(boundary: DehydratedSuspenseBoundary<Instance, TextInstance>): void;
80
+ preparePortalContainer?(container: Parent<Container, Instance>, root: Container, logicalParent: Parent<Container, Instance>): void;
81
+ removePortalContainer?(container: Parent<Container, Instance>): void;
82
+ viewTransition?: ViewTransitionHostConfig<Container, Instance>;
83
+ commitTextUpdate(text: TextInstance, value: string): void;
84
+ }
85
+ type HostRenderConfig<Container, Instance, TextInstance> = Pick<HostConfig<Container, Instance, TextInstance>, "createInstance" | "createTextInstance" | "appendInitialChild" | "finalizeInitialInstance" | "setTextContent" | "insertBefore" | "removeChild" | "commitUpdate" | "commitTextUpdate" | "shouldCommitUpdate" | "clearContainer">;
86
+ type HostValidationConfig<Container, Instance, TextInstance> = Pick<HostConfig<Container, Instance, TextInstance>, "validateInstanceNesting" | "validateTextNesting" | "containerType">;
87
+ type HostHydrationConfig<Container, Instance, TextInstance> = Required<Pick<HostConfig<Container, Instance, TextInstance>, "getFirstHydratableChild" | "getNextHydratableSibling" | "canHydrateInstance" | "canHydrateTextInstance" | "clearContainer">> & Pick<HostConfig<Container, Instance, TextInstance>, "commitHydratedInstance">;
88
+ type HostActivityConfig<Container, Instance, TextInstance> = Required<Pick<HostConfig<Container, Instance, TextInstance>, "getActivityBoundary" | "getFirstActivityHydratable" | "commitHydratedActivityBoundary" | "hideInstance" | "unhideInstance" | "hideTextInstance" | "unhideTextInstance">>;
89
+ type HostSuspenseHydrationConfig<Container, Instance, TextInstance> = Required<Pick<HostConfig<Container, Instance, TextInstance>, "getSuspenseBoundary" | "getEnclosingSuspenseBoundaryStart" | "isTargetWithinSuspenseBoundary" | "registerSuspenseBoundaryRetry" | "commitHydratedSuspenseBoundary" | "completeRootHydration" | "removeDehydratedSuspenseBoundary">>;
90
+ type HostPortalConfig<Container, Instance, TextInstance> = Required<Pick<HostConfig<Container, Instance, TextInstance>, "preparePortalContainer" | "removePortalContainer">>;
91
+ type HostHoistedAssetConfig<Container, Instance, TextInstance> = Required<Pick<HostConfig<Container, Instance, TextInstance>, "isHoistedInstance" | "commitHoistedInstance" | "removeHoistedInstance" | "updateHoistedInstance">>;
92
+ interface FigRoot {
93
+ data: FigDataStoreHandle;
94
+ render(children: FigNode): void;
95
+ unmount(): void;
96
+ }
97
+ interface FigRootOptions {
98
+ dataPartition?: DataResourceKeyInput;
99
+ initialData?: readonly FigDataHydrationEntry[];
100
+ identifierPrefix?: string;
101
+ devtools?: boolean;
102
+ onRecoverableError?: (error: unknown, info: RecoverableErrorInfo) => void;
103
+ onUncaughtError?: (error: unknown, info: ErrorInfo) => void;
104
+ }
105
+ interface RecoverableErrorInfo extends ErrorInfo {
106
+ actual?: string;
107
+ boundaryId?: string;
108
+ componentStack: string;
109
+ digest?: string;
110
+ expected?: string;
111
+ recovery: "root" | "suspense";
112
+ source: "hydration" | "server";
113
+ }
114
+ type HydrationTargetResult = "none" | "hydrated" | "blocked";
115
+ interface FigRenderer<Container> {
116
+ batchedUpdates<T>(this: void, callback: () => T): T;
117
+ createRoot(this: void, container: Container, options?: FigRootOptions): FigRoot;
118
+ hydrateRoot(this: void, container: Container, children: FigNode, options?: FigRootOptions): FigRoot;
119
+ hydrateTarget(this: void, container: Container, target: unknown, priority?: EventPriority): HydrationTargetResult;
120
+ flushSync<T>(this: void, callback: () => T): T;
121
+ scheduleRefresh(this: void, update: RefreshUpdate): void;
122
+ }
123
+ declare function createRenderer<Container, Instance, TextInstance>(host: HostConfig<Container, Instance, TextInstance>): FigRenderer<Container>;
124
+ //#endregion
125
+ export { DehydratedSuspenseBoundary, DehydratedSuspenseError, EventPriority, FigRenderer, FigRoot, FigRootOptions, HostActivityConfig, HostConfig, HostHoistedAssetConfig, HostHydrationConfig, HostPortalConfig, HostRenderConfig, HostSuspenseHydrationConfig, HostValidationConfig, HydrationTargetResult, RecoverableErrorInfo, type RefreshUpdate, ViewTransitionCommitResult, ViewTransitionHostConfig, ViewTransitionMutationResult, ViewTransitionSurfaceMeasurement, act, createRenderer, runWithEventPriority };