@bgub/fig 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.
@@ -0,0 +1,275 @@
1
+ import { g as createElement, n as Assets } from "./element-Bh_k9c3N.js";
2
+ //#region src/context.ts
3
+ const FigContextSymbol = Symbol.for("fig.context");
4
+ function createContext(defaultValue) {
5
+ return Object.assign((props) => props.children, {
6
+ $$typeof: FigContextSymbol,
7
+ defaultValue
8
+ });
9
+ }
10
+ function isContext(value) {
11
+ return typeof value === "function" && value.$$typeof === FigContextSymbol;
12
+ }
13
+ //#endregion
14
+ //#region src/resource.ts
15
+ function assets(value, children) {
16
+ return createElement(Assets, { assets: value }, children);
17
+ }
18
+ function stylesheet(href, options = {}) {
19
+ return {
20
+ ...options,
21
+ href,
22
+ kind: "stylesheet"
23
+ };
24
+ }
25
+ function preload(href, as, options = {}) {
26
+ return {
27
+ ...options,
28
+ as,
29
+ href,
30
+ kind: "preload"
31
+ };
32
+ }
33
+ function modulepreload(href, options = {}) {
34
+ return {
35
+ ...options,
36
+ href,
37
+ kind: "modulepreload"
38
+ };
39
+ }
40
+ function script(src, options = {}) {
41
+ return {
42
+ ...options,
43
+ kind: "script",
44
+ src
45
+ };
46
+ }
47
+ function font(href, type, options = {}) {
48
+ return {
49
+ ...options,
50
+ href,
51
+ kind: "font",
52
+ type
53
+ };
54
+ }
55
+ function preconnect(href, options = {}) {
56
+ return {
57
+ ...options,
58
+ href,
59
+ kind: "preconnect"
60
+ };
61
+ }
62
+ function title(value) {
63
+ return {
64
+ kind: "title",
65
+ value
66
+ };
67
+ }
68
+ function meta(options) {
69
+ return {
70
+ ...options,
71
+ kind: "meta"
72
+ };
73
+ }
74
+ function isFigAssetResource(value) {
75
+ if (typeof value !== "object" || value === null) return false;
76
+ switch (value.kind) {
77
+ case "stylesheet":
78
+ case "preload":
79
+ case "modulepreload":
80
+ case "script":
81
+ case "font":
82
+ case "preconnect":
83
+ case "title":
84
+ case "meta": return true;
85
+ default: return false;
86
+ }
87
+ }
88
+ function clientReferenceAssets(reference) {
89
+ const value = reference.assets;
90
+ if (value === void 0) return [];
91
+ const list = typeof value === "function" ? value() : value;
92
+ if (isFigAssetResource(list)) return [list];
93
+ return Array.isArray(list) ? list : [];
94
+ }
95
+ function assetResourceKey(resource) {
96
+ if (resource.kind === "title") return "title";
97
+ if (resource.kind === "font" && resource.key !== void 0) return `preload:${resource.key}`;
98
+ if (resource.key !== void 0) return `${resource.kind}:${resource.key}`;
99
+ switch (resource.kind) {
100
+ case "stylesheet": return `stylesheet:${resource.href}`;
101
+ case "preload": return `preload:${resource.as}:${resource.href}`;
102
+ case "modulepreload": return `modulepreload:${resource.href}`;
103
+ case "script": return `script:${resource.src}`;
104
+ case "font": return `preload:font:${resource.href}`;
105
+ case "preconnect": return `preconnect:${resource.href}`;
106
+ case "meta": return metaResourceKey(resource);
107
+ }
108
+ }
109
+ function assetResourceDestination(resource) {
110
+ return resource.kind === "title" || resource.kind === "meta" ? "head" : "stream";
111
+ }
112
+ function assetResourceFromHostProps(type, props) {
113
+ return resourceFromHost(type, (name) => props[name], props.children);
114
+ }
115
+ function assetResourceFromHostAttributes(type, getAttribute) {
116
+ return resourceFromHost(type, getAttribute);
117
+ }
118
+ function assetResourceHostAttributes(resource) {
119
+ const pairs = [];
120
+ switch (resource.kind) {
121
+ case "stylesheet":
122
+ pairs.push(["rel", "stylesheet"], ["href", resource.href], ["data-fig-resource-key", resource.key], ["data-precedence", resource.precedence], ["media", resource.media], ["crossorigin", resource.crossOrigin]);
123
+ break;
124
+ case "preload":
125
+ pairs.push(["rel", "preload"], ["href", resource.href], ["as", resource.as], ["data-fig-resource-key", resource.key], ["type", resource.type], ["crossorigin", resource.crossOrigin], ["fetchpriority", resource.fetchPriority]);
126
+ break;
127
+ case "modulepreload":
128
+ pairs.push(["rel", "modulepreload"], ["href", resource.href], ["data-fig-resource-key", resource.key], ["crossorigin", resource.crossOrigin], ["fetchpriority", resource.fetchPriority]);
129
+ break;
130
+ case "font":
131
+ pairs.push(["rel", "preload"], ["href", resource.href], ["as", "font"], ["data-fig-resource-key", resource.key], ["type", resource.type], ["crossorigin", resource.crossOrigin ?? "anonymous"], ["fetchpriority", resource.fetchPriority]);
132
+ break;
133
+ case "preconnect":
134
+ pairs.push(["rel", "preconnect"], ["href", resource.href], ["data-fig-resource-key", resource.key], ["crossorigin", resource.crossOrigin]);
135
+ break;
136
+ case "script":
137
+ pairs.push(["src", resource.src], ["type", resource.module === true ? "module" : void 0], ["data-fig-resource-key", resource.key], ["async", resource.async ?? resource.defer !== true ? true : void 0], ["defer", resource.defer === true ? true : void 0], ["crossorigin", resource.crossOrigin]);
138
+ break;
139
+ case "title":
140
+ case "meta": break;
141
+ }
142
+ return pairs.filter((pair) => pair[1] !== void 0);
143
+ }
144
+ function resourceFromHost(type, prop, children) {
145
+ const withKey = (resource) => {
146
+ const key = readProp(prop, "data-fig-resource-key");
147
+ return key === void 0 ? resource : {
148
+ ...resource,
149
+ key
150
+ };
151
+ };
152
+ switch (type.toLowerCase()) {
153
+ case "title": return withKey({
154
+ kind: "title",
155
+ value: textResourceValue(children)
156
+ });
157
+ case "meta":
158
+ if (readProp(prop, "itemProp", "itemprop") !== void 0) return null;
159
+ return withKey({
160
+ charset: readProp(prop, "charset", "charSet"),
161
+ content: readProp(prop, "content"),
162
+ httpEquiv: readProp(prop, "httpEquiv", "http-equiv"),
163
+ kind: "meta",
164
+ name: readProp(prop, "name"),
165
+ property: readProp(prop, "property")
166
+ });
167
+ case "link": return withNullableKey(linkResourceFromHost(prop), withKey);
168
+ case "script": {
169
+ const src = readProp(prop, "src");
170
+ if (src === void 0) return null;
171
+ return withKey({
172
+ async: prop("async") === true ? true : prop("async") === false ? false : void 0,
173
+ crossOrigin: readCrossOrigin(prop),
174
+ defer: prop("defer") === true,
175
+ kind: "script",
176
+ module: prop("module") === true || prop("type") === "module",
177
+ src
178
+ });
179
+ }
180
+ default: return null;
181
+ }
182
+ }
183
+ function withNullableKey(resource, withKey) {
184
+ return resource === null ? null : withKey(resource);
185
+ }
186
+ function linkResourceFromHost(prop) {
187
+ const rel = readProp(prop, "rel")?.toLowerCase();
188
+ const href = readProp(prop, "href");
189
+ if (rel === void 0 || href === void 0 || readProp(prop, "itemProp", "itemprop") !== void 0) return null;
190
+ if (rel === "stylesheet") return {
191
+ blocking: prop("blocking") === "none" ? "none" : void 0,
192
+ crossOrigin: readCrossOrigin(prop),
193
+ href,
194
+ kind: "stylesheet",
195
+ media: readProp(prop, "media"),
196
+ precedence: readProp(prop, "precedence", "data-precedence")
197
+ };
198
+ if (rel === "modulepreload") return {
199
+ crossOrigin: readCrossOrigin(prop),
200
+ fetchPriority: fetchPriorityProp(readProp(prop, "fetchPriority", "fetchpriority")),
201
+ href,
202
+ kind: "modulepreload"
203
+ };
204
+ if (rel === "preload") {
205
+ const as = readProp(prop, "as");
206
+ if (as === void 0) return null;
207
+ return {
208
+ as,
209
+ crossOrigin: readCrossOrigin(prop),
210
+ fetchPriority: fetchPriorityProp(readProp(prop, "fetchPriority", "fetchpriority")),
211
+ href,
212
+ kind: "preload",
213
+ type: readProp(prop, "type")
214
+ };
215
+ }
216
+ if (rel === "preconnect") return {
217
+ crossOrigin: readCrossOrigin(prop),
218
+ href,
219
+ kind: "preconnect"
220
+ };
221
+ return null;
222
+ }
223
+ function readProp(prop, ...names) {
224
+ for (const name of names) {
225
+ const value = stringProp(prop(name));
226
+ if (value !== void 0) return value;
227
+ }
228
+ }
229
+ function stringProp(value) {
230
+ if (value === void 0 || value === null || value === false) return void 0;
231
+ if (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || value === true) return String(value);
232
+ throw new Error("Resource host props must be serializable during server render.");
233
+ }
234
+ function readCrossOrigin(prop) {
235
+ return crossOriginProp(readProp(prop, "crossOrigin", "crossorigin"));
236
+ }
237
+ function crossOriginProp(value) {
238
+ return value === "anonymous" || value === "use-credentials" || value === "" ? value : void 0;
239
+ }
240
+ function fetchPriorityProp(value) {
241
+ return value === "high" || value === "low" || value === "auto" ? value : void 0;
242
+ }
243
+ function textResourceValue(node) {
244
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
245
+ if (typeof node === "string" || typeof node === "number") return String(node);
246
+ if (Array.isArray(node)) return node.map(textResourceValue).join("");
247
+ throw new Error("<title> can only contain text during server render.");
248
+ }
249
+ function metaResourceKey(resource) {
250
+ if (resource.charset !== void 0) return `meta:charset:${resource.charset}`;
251
+ if (resource.name !== void 0) return `meta:name:${resource.name}`;
252
+ if (resource.property !== void 0) return `meta:property:${resource.property}`;
253
+ if (resource.httpEquiv !== void 0) return `meta:http-equiv:${resource.httpEquiv}`;
254
+ return `meta:${resource.content ?? ""}`;
255
+ }
256
+ //#endregion
257
+ //#region src/transition.ts
258
+ let transitionHandler = (callback) => callback();
259
+ /**
260
+ * Runs state updates scheduled by `callback` at transition priority. If
261
+ * `callback` returns a thenable, updates after an `await` remain in the
262
+ * transition priority scope until it settles.
263
+ */
264
+ function transition(callback) {
265
+ return transitionHandler(callback);
266
+ }
267
+ function setTransitionHandler(handler) {
268
+ const previous = transitionHandler;
269
+ transitionHandler = handler;
270
+ return previous;
271
+ }
272
+ //#endregion
273
+ export { stylesheet as _, assetResourceFromHostProps as a, createContext as b, assets as c, isFigAssetResource as d, meta as f, script as g, preload as h, assetResourceFromHostAttributes as i, clientReferenceAssets as l, preconnect as m, transition as n, assetResourceHostAttributes as o, modulepreload as p, assetResourceDestination as r, assetResourceKey as s, setTransitionHandler as t, font as u, title as v, isContext as x, FigContextSymbol as y };
274
+
275
+ //# sourceMappingURL=transition-DEqcImne.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition-DEqcImne.js","names":[],"sources":["../src/context.ts","../src/resource.ts","../src/transition.ts"],"sourcesContent":["import type { FigNode } from \"./element.ts\";\n\nexport interface FigContext<T> {\n (props: { value: T; children?: FigNode }): FigNode;\n readonly $$typeof: symbol;\n readonly defaultValue: T;\n}\n\nexport const FigContextSymbol = Symbol.for(\"fig.context\");\n\nexport function createContext<T>(defaultValue: T): FigContext<T> {\n return Object.assign(\n (props: { value: T; children?: FigNode }) => props.children,\n {\n $$typeof: FigContextSymbol,\n defaultValue,\n },\n );\n}\n\nexport function isContext(value: unknown): value is FigContext<unknown> {\n return (\n typeof value === \"function\" &&\n (value as FigContext<unknown>).$$typeof === FigContextSymbol\n );\n}\n","import {\n Assets,\n createElement,\n type FigClientReference,\n type FigElement,\n type FigNode,\n type Props,\n} from \"./element.ts\";\n\nexport type AssetResourceBlocking = \"reveal\" | \"none\";\nexport type CrossOrigin = \"anonymous\" | \"use-credentials\" | \"\";\nexport type FetchPriority = \"high\" | \"low\" | \"auto\";\nexport type AssetResourceDestination = \"head\" | \"stream\";\n\nexport type FigAssetResource =\n | StylesheetResource\n | PreloadResource\n | ModulePreloadResource\n | ScriptResource\n | FontResource\n | PreconnectResource\n | TitleResource\n | MetaResource;\n\ninterface ResourceBase {\n key?: string;\n}\n\nexport interface StylesheetResource extends ResourceBase {\n blocking?: AssetResourceBlocking;\n crossOrigin?: CrossOrigin;\n href: string;\n kind: \"stylesheet\";\n media?: string;\n precedence?: string;\n}\n\nexport interface PreloadResource extends ResourceBase {\n as: string;\n crossOrigin?: CrossOrigin;\n fetchPriority?: FetchPriority;\n href: string;\n kind: \"preload\";\n type?: string;\n}\n\nexport interface ModulePreloadResource extends ResourceBase {\n crossOrigin?: CrossOrigin;\n fetchPriority?: FetchPriority;\n href: string;\n kind: \"modulepreload\";\n}\n\nexport interface ScriptResource extends ResourceBase {\n async?: boolean;\n crossOrigin?: CrossOrigin;\n defer?: boolean;\n kind: \"script\";\n module?: boolean;\n src: string;\n}\n\nexport interface FontResource extends ResourceBase {\n crossOrigin?: CrossOrigin;\n fetchPriority?: FetchPriority;\n href: string;\n kind: \"font\";\n type: string;\n}\n\nexport interface PreconnectResource extends ResourceBase {\n crossOrigin?: CrossOrigin;\n href: string;\n kind: \"preconnect\";\n}\n\nexport interface TitleResource extends ResourceBase {\n kind: \"title\";\n value: string;\n}\n\nexport interface MetaResource extends ResourceBase {\n charset?: string;\n content?: string;\n httpEquiv?: string;\n kind: \"meta\";\n name?: string;\n property?: string;\n}\n\nexport type FigAssetResourceList =\n | FigAssetResource\n | readonly FigAssetResource[];\n\n// Asset resources a client reference contributes when it renders. Eager for\n// hand-written lists; a thunk for bundler-manifest resolution that may not be\n// available until serialization time, or that maps paths differently per build.\nexport type ClientReferenceAssets =\n | FigAssetResourceList\n | (() => FigAssetResourceList);\n\nexport interface AssetsProps {\n assets: FigAssetResourceList;\n children?: FigNode;\n}\n\nexport function assets(\n value: FigAssetResourceList,\n children?: FigNode,\n): FigElement<AssetsProps> {\n return createElement(Assets, { assets: value }, children);\n}\n\nexport function stylesheet(\n href: string,\n options: Omit<StylesheetResource, \"href\" | \"kind\"> = {},\n): StylesheetResource {\n return { ...options, href, kind: \"stylesheet\" };\n}\n\nexport function preload(\n href: string,\n as: string,\n options: Omit<PreloadResource, \"as\" | \"href\" | \"kind\"> = {},\n): PreloadResource {\n return { ...options, as, href, kind: \"preload\" };\n}\n\nexport function modulepreload(\n href: string,\n options: Omit<ModulePreloadResource, \"href\" | \"kind\"> = {},\n): ModulePreloadResource {\n return { ...options, href, kind: \"modulepreload\" };\n}\n\nexport function script(\n src: string,\n options: Omit<ScriptResource, \"kind\" | \"src\"> = {},\n): ScriptResource {\n return { ...options, kind: \"script\", src };\n}\n\nexport function font(\n href: string,\n type: string,\n options: Omit<FontResource, \"href\" | \"kind\" | \"type\"> = {},\n): FontResource {\n return { ...options, href, kind: \"font\", type };\n}\n\nexport function preconnect(\n href: string,\n options: Omit<PreconnectResource, \"href\" | \"kind\"> = {},\n): PreconnectResource {\n return { ...options, href, kind: \"preconnect\" };\n}\n\nexport function title(value: string): TitleResource {\n return { kind: \"title\", value };\n}\n\nexport function meta(options: Omit<MetaResource, \"kind\">): MetaResource {\n return { ...options, kind: \"meta\" };\n}\n\nexport function isFigAssetResource(value: unknown): value is FigAssetResource {\n if (typeof value !== \"object\" || value === null) return false;\n\n switch ((value as { kind?: unknown }).kind) {\n case \"stylesheet\":\n case \"preload\":\n case \"modulepreload\":\n case \"script\":\n case \"font\":\n case \"preconnect\":\n case \"title\":\n case \"meta\":\n return true;\n default:\n return false;\n }\n}\n\nexport function clientReferenceAssets(\n reference: FigClientReference,\n): readonly FigAssetResource[] {\n const value = reference.assets;\n if (value === undefined) return [];\n\n // Resolved on each call rather than memoized: a lazy resolver may read a\n // manifest that is not loaded until serialization, and a consumer that wants\n // to cache can do so against the stable reference identity.\n const list = typeof value === \"function\" ? value() : value;\n if (isFigAssetResource(list)) return [list];\n // A thunk that yields nothing (e.g. a missing manifest entry) normalizes to an\n // empty list rather than leaking a non-array through the readonly contract.\n return Array.isArray(list) ? list : [];\n}\n\nexport function assetResourceKey(resource: FigAssetResource): string {\n // A document carries a single <title>; collapse every title to one key even\n // when an author supplies an explicit key, so the singleton invariant cannot\n // be bypassed into emitting multiple <title> elements (invalid HTML).\n if (resource.kind === \"title\") return \"title\";\n\n // A font is serialized and inserted as <link rel=\"preload\" as=\"font\">, so an\n // explicit key must also live in the preload key space.\n if (resource.kind === \"font\" && resource.key !== undefined)\n return `preload:${resource.key}`;\n\n if (resource.key !== undefined) return `${resource.kind}:${resource.key}`;\n\n switch (resource.kind) {\n case \"stylesheet\":\n return `stylesheet:${resource.href}`;\n case \"preload\":\n return `preload:${resource.as}:${resource.href}`;\n case \"modulepreload\":\n return `modulepreload:${resource.href}`;\n case \"script\":\n return `script:${resource.src}`;\n case \"font\":\n // A font is loaded as <link rel=\"preload\" as=\"font\">, so it must share the\n // preload-font key space across every package (SSR registry, payload record,\n // client insert) — otherwise a font() and an equivalent preload(href,\n // \"font\") would key separately and fail to dedupe.\n return `preload:font:${resource.href}`;\n case \"preconnect\":\n return `preconnect:${resource.href}`;\n case \"meta\":\n return metaResourceKey(resource);\n }\n}\n\nexport function assetResourceDestination(\n resource: FigAssetResource,\n): AssetResourceDestination {\n return resource.kind === \"title\" || resource.kind === \"meta\"\n ? \"head\"\n : \"stream\";\n}\n\nexport function assetResourceFromHostProps(\n type: string,\n props: Props,\n): FigAssetResource | null {\n return resourceFromHost(type, (name) => props[name], props.children);\n}\n\nexport function assetResourceFromHostAttributes(\n type: string,\n getAttribute: (name: string) => unknown,\n): FigAssetResource | null {\n return resourceFromHost(type, getAttribute);\n}\n\nexport type AssetResourceHostAttribute = readonly [\n name: string,\n value: string | true,\n];\n\n// Canonical attribute serialization for hoisted asset-resource elements,\n// shared by the server's registry writer and the client's head insertion so\n// the two renders cannot drift. `true` marks a boolean attribute (bare on\n// the server, empty-string in the DOM). Server-only attributes (id, nonce)\n// stay with the server writer; title/meta are written by their own paths.\nexport function assetResourceHostAttributes(\n resource: FigAssetResource,\n): AssetResourceHostAttribute[] {\n const pairs: Array<readonly [string, string | true | undefined]> = [];\n\n switch (resource.kind) {\n case \"stylesheet\":\n pairs.push(\n [\"rel\", \"stylesheet\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"data-precedence\", resource.precedence],\n [\"media\", resource.media],\n [\"crossorigin\", resource.crossOrigin],\n );\n break;\n case \"preload\":\n pairs.push(\n [\"rel\", \"preload\"],\n [\"href\", resource.href],\n [\"as\", resource.as],\n [\"data-fig-resource-key\", resource.key],\n [\"type\", resource.type],\n [\"crossorigin\", resource.crossOrigin],\n [\"fetchpriority\", resource.fetchPriority],\n );\n break;\n case \"modulepreload\":\n pairs.push(\n [\"rel\", \"modulepreload\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"crossorigin\", resource.crossOrigin],\n [\"fetchpriority\", resource.fetchPriority],\n );\n break;\n case \"font\":\n pairs.push(\n [\"rel\", \"preload\"],\n [\"href\", resource.href],\n [\"as\", \"font\"],\n [\"data-fig-resource-key\", resource.key],\n [\"type\", resource.type],\n [\"crossorigin\", resource.crossOrigin ?? \"anonymous\"],\n [\"fetchpriority\", resource.fetchPriority],\n );\n break;\n case \"preconnect\":\n pairs.push(\n [\"rel\", \"preconnect\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"crossorigin\", resource.crossOrigin],\n );\n break;\n case \"script\":\n pairs.push(\n [\"src\", resource.src],\n [\"type\", resource.module === true ? \"module\" : undefined],\n [\"data-fig-resource-key\", resource.key],\n // Hoisted scripts default to async, but an explicit defer opts into\n // ordered execution and must not be overridden (async wins over\n // defer in browsers).\n [\n \"async\",\n (resource.async ?? resource.defer !== true) ? true : undefined,\n ],\n [\"defer\", resource.defer === true ? true : undefined],\n [\"crossorigin\", resource.crossOrigin],\n );\n break;\n case \"title\":\n case \"meta\":\n break;\n }\n\n return pairs.filter(\n (pair): pair is readonly [string, string | true] => pair[1] !== undefined,\n );\n}\n\nfunction resourceFromHost(\n type: string,\n prop: (name: string) => unknown,\n children?: FigNode,\n): FigAssetResource | null {\n const withKey = (resource: FigAssetResource): FigAssetResource => {\n const key = readProp(prop, \"data-fig-resource-key\");\n return key === undefined ? resource : { ...resource, key };\n };\n\n switch (type.toLowerCase()) {\n case \"title\":\n return withKey({ kind: \"title\", value: textResourceValue(children) });\n case \"meta\":\n if (readProp(prop, \"itemProp\", \"itemprop\") !== undefined) return null;\n return withKey({\n charset: readProp(prop, \"charset\", \"charSet\"),\n content: readProp(prop, \"content\"),\n httpEquiv: readProp(prop, \"httpEquiv\", \"http-equiv\"),\n kind: \"meta\",\n name: readProp(prop, \"name\"),\n property: readProp(prop, \"property\"),\n });\n case \"link\":\n return withNullableKey(linkResourceFromHost(prop), withKey);\n case \"script\": {\n const src = readProp(prop, \"src\");\n if (src === undefined) return null;\n return withKey({\n async:\n prop(\"async\") === true\n ? true\n : prop(\"async\") === false\n ? false\n : undefined,\n crossOrigin: readCrossOrigin(prop),\n defer: prop(\"defer\") === true,\n kind: \"script\",\n module: prop(\"module\") === true || prop(\"type\") === \"module\",\n src,\n });\n }\n default:\n return null;\n }\n}\n\nfunction withNullableKey(\n resource: FigAssetResource | null,\n withKey: (resource: FigAssetResource) => FigAssetResource,\n): FigAssetResource | null {\n return resource === null ? null : withKey(resource);\n}\n\nfunction linkResourceFromHost(\n prop: (name: string) => unknown,\n): FigAssetResource | null {\n const rel = readProp(prop, \"rel\")?.toLowerCase();\n const href = readProp(prop, \"href\");\n if (\n rel === undefined ||\n href === undefined ||\n readProp(prop, \"itemProp\", \"itemprop\") !== undefined\n ) {\n return null;\n }\n\n if (rel === \"stylesheet\") {\n return {\n blocking: prop(\"blocking\") === \"none\" ? \"none\" : undefined,\n crossOrigin: readCrossOrigin(prop),\n href,\n kind: \"stylesheet\",\n media: readProp(prop, \"media\"),\n // Hoisted elements serialize the canonical data-precedence attribute;\n // host-rendered <link precedence> keeps the author-facing prop name.\n precedence: readProp(prop, \"precedence\", \"data-precedence\"),\n };\n }\n\n if (rel === \"modulepreload\") {\n return {\n crossOrigin: readCrossOrigin(prop),\n fetchPriority: fetchPriorityProp(\n readProp(prop, \"fetchPriority\", \"fetchpriority\"),\n ),\n href,\n kind: \"modulepreload\",\n };\n }\n\n if (rel === \"preload\") {\n const as = readProp(prop, \"as\");\n if (as === undefined) return null;\n return {\n as,\n crossOrigin: readCrossOrigin(prop),\n fetchPriority: fetchPriorityProp(\n readProp(prop, \"fetchPriority\", \"fetchpriority\"),\n ),\n href,\n kind: \"preload\",\n type: readProp(prop, \"type\"),\n };\n }\n\n if (rel === \"preconnect\") {\n return {\n crossOrigin: readCrossOrigin(prop),\n href,\n kind: \"preconnect\",\n };\n }\n\n return null;\n}\n\nfunction readProp(\n prop: (name: string) => unknown,\n ...names: string[]\n): string | undefined {\n for (const name of names) {\n const value = stringProp(prop(name));\n if (value !== undefined) return value;\n }\n\n return undefined;\n}\n\nfunction stringProp(value: unknown): string | undefined {\n if (value === undefined || value === null || value === false)\n return undefined;\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n value === true\n ) {\n return String(value);\n }\n\n throw new Error(\n \"Resource host props must be serializable during server render.\",\n );\n}\n\nfunction readCrossOrigin(\n prop: (name: string) => unknown,\n): CrossOrigin | undefined {\n return crossOriginProp(readProp(prop, \"crossOrigin\", \"crossorigin\"));\n}\n\nfunction crossOriginProp(value: unknown): CrossOrigin | undefined {\n return value === \"anonymous\" || value === \"use-credentials\" || value === \"\"\n ? value\n : undefined;\n}\n\nfunction fetchPriorityProp(value: unknown): FetchPriority | undefined {\n return value === \"high\" || value === \"low\" || value === \"auto\"\n ? value\n : undefined;\n}\n\nfunction textResourceValue(node: FigNode): string {\n if (node === null || node === undefined || typeof node === \"boolean\") {\n return \"\";\n }\n if (typeof node === \"string\" || typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(textResourceValue).join(\"\");\n\n throw new Error(\"<title> can only contain text during server render.\");\n}\n\nfunction metaResourceKey(resource: MetaResource): string {\n if (resource.charset !== undefined) return `meta:charset:${resource.charset}`;\n if (resource.name !== undefined) return `meta:name:${resource.name}`;\n if (resource.property !== undefined)\n return `meta:property:${resource.property}`;\n if (resource.httpEquiv !== undefined) {\n return `meta:http-equiv:${resource.httpEquiv}`;\n }\n\n return `meta:${resource.content ?? \"\"}`;\n}\n","export type TransitionHandler = <T>(callback: () => T) => T;\n\nlet transitionHandler: TransitionHandler = (callback) => callback();\n\n/**\n * Runs state updates scheduled by `callback` at transition priority. If\n * `callback` returns a thenable, updates after an `await` remain in the\n * transition priority scope until it settles.\n */\nexport function transition<T>(callback: () => T): T {\n return transitionHandler(callback);\n}\n\nexport function setTransitionHandler(\n handler: TransitionHandler,\n): TransitionHandler {\n const previous = transitionHandler;\n transitionHandler = handler;\n return previous;\n}\n"],"mappings":";;AAQA,MAAa,mBAAmB,OAAO,IAAI,aAAa;AAExD,SAAgB,cAAiB,cAAgC;CAC/D,OAAO,OAAO,QACX,UAA4C,MAAM,UACnD;EACE,UAAU;EACV;CACF,CACF;AACF;AAEA,SAAgB,UAAU,OAA8C;CACtE,OACE,OAAO,UAAU,cAChB,MAA8B,aAAa;AAEhD;;;ACiFA,SAAgB,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A,SAAS,kBAAkB,MAAuB;CAChD,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,OAAO,SAAS,WACzD,OAAO;CAET,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO,OAAO,IAAI;CAC5E,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,iBAAiB,CAAC,CAAC,KAAK,EAAE;CAEnE,MAAM,IAAI,MAAM,qDAAqD;AACvE;AAEA,SAAS,gBAAgB,UAAgC;CACvD,IAAI,SAAS,YAAY,KAAA,GAAW,OAAO,gBAAgB,SAAS;CACpE,IAAI,SAAS,SAAS,KAAA,GAAW,OAAO,aAAa,SAAS;CAC9D,IAAI,SAAS,aAAa,KAAA,GACxB,OAAO,iBAAiB,SAAS;CACnC,IAAI,SAAS,cAAc,KAAA,GACzB,OAAO,mBAAmB,SAAS;CAGrC,OAAO,QAAQ,SAAS,WAAW;AACrC;;;ACjhBA,IAAI,qBAAwC,aAAa,SAAS;;;;;;AAOlE,SAAgB,WAAc,UAAsB;CAClD,OAAO,kBAAkB,QAAQ;AACnC;AAEA,SAAgB,qBACd,SACmB;CACnB,MAAM,WAAW;CACjB,oBAAoB;CACpB,OAAO;AACT"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@bgub/fig",
3
+ "version": "0.0.1",
4
+ "description": "Fig — a UI library",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/bgub/fig",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./internal": {
15
+ "types": "./dist/internal.d.ts",
16
+ "import": "./dist/internal.js",
17
+ "default": "./dist/internal.js"
18
+ },
19
+ "./server": {
20
+ "types": "./dist/server.d.ts",
21
+ "browser": "./dist/server.browser.js",
22
+ "import": "./dist/server.js",
23
+ "default": "./dist/server.js"
24
+ },
25
+ "./jsx-runtime": {
26
+ "types": "./dist/jsx-runtime.d.ts",
27
+ "import": "./dist/jsx-runtime.js",
28
+ "default": "./dist/jsx-runtime.js"
29
+ },
30
+ "./jsx-dev-runtime": {
31
+ "types": "./dist/jsx-runtime.d.ts",
32
+ "import": "./dist/jsx-runtime.js",
33
+ "default": "./dist/jsx-runtime.js"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "types": "./dist/index.d.ts",
38
+ "sideEffects": false,
39
+ "files": [
40
+ "dist",
41
+ "CHANGELOG.md"
42
+ ],
43
+ "author": "Ben Gubler <nebrelbug@gmail.com>",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/bgub/fig",
47
+ "directory": "packages/fig"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/bgub/fig/issues"
51
+ },
52
+ "license": "MIT",
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "devDependencies": {},
57
+ "engines": {
58
+ "node": "^20.19.0 || >=22.12.0"
59
+ },
60
+ "scripts": {
61
+ "build": "tsdown --config ../../tsdown.config.ts && node ../../scripts/strip-declaration-map-comments.mjs dist",
62
+ "test": "vitest run --config ../../vite.config.ts src"
63
+ }
64
+ }