@pandacss/compiler-wasm 2.0.0-beta.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Chakra Systems Inc.
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,14 @@
1
+ # @pandacss/compiler-wasm
2
+
3
+ The WebAssembly build of the Panda CSS compiler engine, for browser and playground targets where the native
4
+ `@pandacss/compiler` binding can't run.
5
+
6
+ This package is consumed by Panda tooling; you typically don't install it directly.
7
+
8
+ ## Documentation
9
+
10
+ Visit the [Panda CSS documentation](https://panda-css.com) to learn more.
11
+
12
+ ## License
13
+
14
+ MIT © [Chakra Systems Inc.](https://github.com/chakra-ui)
@@ -0,0 +1,108 @@
1
+ // src/web.ts
2
+ import {
3
+ assertProjectCallbacks,
4
+ assertProjectHooks,
5
+ getTokenCategoryValues,
6
+ makeBuildInfoApi,
7
+ mergeCallbacks,
8
+ prepareCompilerConfig
9
+ } from "@pandacss/compiler-shared";
10
+
11
+ // src/callbacks.ts
12
+ import {
13
+ createPatternHelpers,
14
+ createTransformArgs,
15
+ getPatternDefaultValueRefsByTransformId,
16
+ mergePatternDefaultValues
17
+ } from "@pandacss/compiler-shared";
18
+ function registerCallbacks(project, callbacks, hooks, tokenDictionary) {
19
+ const utilityTransforms = callbacks["utility.transform"];
20
+ if (utilityTransforms && Object.keys(utilityTransforms).length > 0 && !project.registerUtilityTransform) {
21
+ throw new Error("WASM project does not support utility.transform callbacks");
22
+ }
23
+ if (project.registerUtilityTransform && utilityTransforms && Object.keys(utilityTransforms).length > 0) {
24
+ for (const [id, callback] of Object.entries(utilityTransforms)) {
25
+ project.registerUtilityTransform(id, (resolved, original) => {
26
+ return callback(resolved, createTransformArgs(original, tokenDictionary));
27
+ });
28
+ }
29
+ }
30
+ const patternTransforms = callbacks["pattern.transform"];
31
+ if (patternTransforms && Object.keys(patternTransforms).length > 0 && !project.registerPatternTransform) {
32
+ throw new Error("WASM project does not support pattern.transform callbacks");
33
+ }
34
+ const config = project.config();
35
+ const patternDefaultValues = callbacks["pattern.defaultValues"];
36
+ const patternDefaultValueRefs = config && patternDefaultValues ? getPatternDefaultValueRefsByTransformId(config) : /* @__PURE__ */ new Map();
37
+ if (project.registerPatternTransform && patternTransforms && Object.keys(patternTransforms).length > 0) {
38
+ for (const [id, callback] of Object.entries(patternTransforms)) {
39
+ const defaultValueId = patternDefaultValueRefs.get(id);
40
+ const defaultValue = defaultValueId ? patternDefaultValues?.[defaultValueId] : void 0;
41
+ project.registerPatternTransform(id, (props) => {
42
+ const input = props;
43
+ const nextProps = defaultValue ? mergePatternDefaultValues(defaultValue(input), input) : input;
44
+ return callback(nextProps, createPatternHelpers());
45
+ });
46
+ }
47
+ }
48
+ const sourceTransforms = hooks?.["parser:before"];
49
+ if (sourceTransforms?.length && !project.registerSourceTransform) {
50
+ throw new Error("WASM project does not support parser:before callbacks");
51
+ }
52
+ if (project.registerSourceTransform && sourceTransforms) {
53
+ for (const hook of sourceTransforms) {
54
+ const callback = callbacks["parser:before"]?.[hook.id];
55
+ if (!callback) continue;
56
+ project.registerSourceTransform(hook.id, hook.filter, (filePath, content) => {
57
+ const result = callback({ filePath: String(filePath), content: String(content), original: String(content) });
58
+ if (isPromiseLike(result)) {
59
+ throw new Error(`parser:before callback \`${hook.id}\` must be synchronous`);
60
+ }
61
+ return typeof result === "string" ? result : void 0;
62
+ });
63
+ }
64
+ }
65
+ }
66
+ function isPromiseLike(value) {
67
+ return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
68
+ }
69
+
70
+ // src/web.ts
71
+ function createCompilerFromWasmModule(mod, config, options) {
72
+ return build(mod, config, options?.callbacks ?? {}, options?.hooks);
73
+ }
74
+ function build(mod, config, callbacks, hooks) {
75
+ const fs = new mod.WasmFileSystem();
76
+ assertProjectCallbacks(config, callbacks);
77
+ assertProjectHooks(hooks, callbacks);
78
+ const prepared = prepareCompilerConfig(config);
79
+ const compiler = mod.WasmCompiler.fromConfig(fs, prepared, buildFromConfigOptions(callbacks));
80
+ registerCallbacks(compiler, callbacks, hooks, compiler.token_dictionary?.());
81
+ compiler.fs = fs;
82
+ Object.defineProperty(compiler, "buildInfo", {
83
+ value: makeBuildInfoApi(compiler),
84
+ enumerable: false
85
+ });
86
+ return compiler;
87
+ }
88
+ function buildFromConfigOptions(callbacks) {
89
+ const utilityValues = callbacks["utility.values"];
90
+ if (!utilityValues || Object.keys(utilityValues).length === 0) return void 0;
91
+ return {
92
+ configCallbacks: {
93
+ utilityValues: Object.fromEntries(
94
+ Object.entries(utilityValues).map(([id, callback]) => [
95
+ id,
96
+ (tokenDictionary) => callback((category) => getTokenCategoryValues(category, tokenDictionary))
97
+ ])
98
+ )
99
+ }
100
+ };
101
+ }
102
+
103
+ export {
104
+ mergeCallbacks,
105
+ createCompilerFromWasmModule,
106
+ build,
107
+ buildFromConfigOptions
108
+ };
@@ -0,0 +1,222 @@
1
+ import { ParseFileReport, ScanOptions, LayerNames, Spec, SourceEntry, FileInspectionResult, GenerateArtifactOptions, CompileOptions, WriteCssResult, WriteFilesResult, SerializedHookFilter, Atom, RecipeEntry, EncodedRecipeStyles, ProjectSummary, CompileOutput, StylesheetLayerName, CssFile, CodegenArtifact, CodegenArtifactId, CodegenDependency, Diagnostic, CompileFileManifest, ParsedFileView, StaticPatternResult, BuildInfo, SerializedConfig, CompilerOptions, Compiler, ProjectCallbacks, ProjectHooks, ConfigSnapshot, Driver } from '@pandacss/compiler-shared';
2
+ export * from '@pandacss/compiler-shared';
3
+ export { PatternHelpers, mergeCallbacks } from '@pandacss/compiler-shared';
4
+
5
+ /**
6
+ * TS-facing types that mirror the wasm-bindgen generated interfaces.
7
+ * Kept hand-written (rather than re-exporting from `../pkg-node/*`) so
8
+ * `tsc` typechecks succeed before the wasm artifact is built.
9
+ *
10
+ * The data shapes (`Atom`, `Diagnostic`, `CompileOutput`, …) come from
11
+ * `@pandacss/compiler-shared` — the single contract shared with the native
12
+ * binding. Only the wasm-bindgen *class* shapes live here.
13
+ *
14
+ * Run `pnpm build:wasm` to (re)generate the actual wasm bundle.
15
+ */
16
+
17
+ interface MatcherInput {
18
+ /** Module specifier substrings to match (e.g. `["@panda/css"]`). */
19
+ modules: string[];
20
+ /**
21
+ * Allowed imported names. Omit (or pass `null`) to accept any name —
22
+ * used for recipe/pattern matchers where names are user-defined.
23
+ */
24
+ names?: string[] | null;
25
+ }
26
+ interface TokenDictionaryInput {
27
+ /** `path → raw value` (e.g. `colors.red.500 → #ef4444`). */
28
+ values: Record<string, string>;
29
+ /** `path → CSS var form` (e.g. `colors.red.500 → var(--colors-red-500)`). */
30
+ vars: Record<string, string>;
31
+ }
32
+ type JsxFramework = 'react' | 'solid' | 'preact' | 'vue' | 'qwik' | (string & {});
33
+ type CssSyntax = 'template-literal' | 'object-literal';
34
+ interface MatchersInput {
35
+ css?: MatcherInput;
36
+ recipe?: MatcherInput;
37
+ pattern?: MatcherInput;
38
+ jsx?: MatcherInput;
39
+ tokens?: MatcherInput;
40
+ /** Configured JSX framework. Enables JSX-aware extraction diagnostics. */
41
+ jsxFramework?: JsxFramework;
42
+ /** Defaults to `["styled"]` when omitted. */
43
+ jsxFactories?: string[];
44
+ /** CSS authoring syntax preference. Omit for object-literal mode. */
45
+ syntax?: CssSyntax;
46
+ /** Enable `token('…')` folding by passing a resolved dictionary. */
47
+ tokenDictionary?: TokenDictionaryInput;
48
+ }
49
+ declare class WasmFileSystem {
50
+ constructor();
51
+ addFile(path: string, content: string): void;
52
+ removeFile(path: string): boolean;
53
+ readFile(path: string): string | undefined;
54
+ exists(path: string): boolean;
55
+ fileCount(): number;
56
+ }
57
+ declare class WasmExtractor {
58
+ constructor(fs: WasmFileSystem, matchers: MatchersInput);
59
+ parseFile(path: string, source: string): unknown;
60
+ }
61
+ /** Stateful compiler handle over a `WasmFileSystem`. Cross-file resolution
62
+ * always shares the same FS — `import { x } from './tokens'` references
63
+ * resolve through whatever the JS host has populated.
64
+ *
65
+ * Mirrors the native `Compiler` class. The TS facade adapts this into the
66
+ * shared {@link @pandacss/compiler-shared#Compiler} surface (attaching `fs`,
67
+ * hiding `registerUtilityTransform` / `registerPatternTransform`). */
68
+ declare class WasmCompiler {
69
+ static fromConfig(fs: WasmFileSystem, config: Record<string, unknown>, options?: unknown): WasmCompiler;
70
+ config(): Record<string, unknown> | null;
71
+ extractFileSource(path: string, source: string): unknown;
72
+ parseFile(path: string): ParseFileReport;
73
+ parseFileSource(path: string, source: string): ParseFileReport;
74
+ refreshFile(path: string): boolean;
75
+ refreshFileSource(path: string, source: string): boolean;
76
+ removeFile(path: string): boolean;
77
+ clear(): void;
78
+ scan(options?: ScanOptions): string[];
79
+ realpath(path: string): string;
80
+ resolvePath(path: string, cwd?: string): string;
81
+ joinPath(parts: string[]): string;
82
+ dirname(path: string): string;
83
+ isSourceFile(path: string): boolean;
84
+ parseFiles(paths: string[]): ParseFileReport[];
85
+ layers(): LayerNames;
86
+ hasLayerDeclaration(css: string): boolean;
87
+ spec(): Spec;
88
+ sources(): SourceEntry[];
89
+ inspectFileSource(path: string, source: string): FileInspectionResult;
90
+ writeArtifacts(outdir: string, cwd?: string, options?: GenerateArtifactOptions): string[];
91
+ writeCss(outfile: string, cwd?: string, options?: CompileOptions): WriteCssResult;
92
+ writeSplitCss(outdir: string, cwd?: string): WriteFilesResult;
93
+ isEmpty(): boolean;
94
+ registerUtilityTransform?(id: string, callback: (resolved: unknown, original: unknown) => unknown): void;
95
+ registerPatternTransform?(id: string, callback: (props: unknown, helpers: Record<string, unknown>) => unknown): void;
96
+ registerSourceTransform?(id: string, filter: SerializedHookFilter | undefined, callback: (filePath: string, content: string) => string | undefined): void;
97
+ atoms(): Atom[];
98
+ recipes(): RecipeEntry[];
99
+ slotRecipes(): RecipeEntry[];
100
+ encodedRecipes(): EncodedRecipeStyles;
101
+ summary(): ProjectSummary;
102
+ compile(options?: CompileOptions): CompileOutput;
103
+ layerCss(layers: StylesheetLayerName[]): string;
104
+ splitCss(): CssFile[];
105
+ generateArtifacts(options?: GenerateArtifactOptions): CodegenArtifact[];
106
+ generateArtifact(id: CodegenArtifactId, options?: GenerateArtifactOptions): CodegenArtifact | undefined;
107
+ generateAffectedArtifacts(dependencies: CodegenDependency[], options?: GenerateArtifactOptions): CodegenArtifact[];
108
+ diagnostics(): Diagnostic[];
109
+ fileManifest(): CompileFileManifest[];
110
+ /** Per-file view, or `null` when `path` isn't known. */
111
+ getFile(path: string): ParsedFileView | null;
112
+ staticPatternAtoms(): StaticPatternResult;
113
+ serializeBuildInfo(panda: string): BuildInfo;
114
+ applyBuildInfo(name: string, buildInfo: BuildInfo, only?: string[]): boolean;
115
+ buildInfoSchemaVersion(): number;
116
+ configFingerprint(): string;
117
+ }
118
+
119
+ /**
120
+ * `@pandacss/compiler-wasm/web` — browser-only facade.
121
+ *
122
+ * Exports only the wasm-module facade (`createCompilerFromWasmModule`) and the
123
+ * types/helpers that go with it. Has **no** `import('../pkg-node/...')` in its
124
+ * module graph, so tsup injects no Node `fileURLToPath` shim into the browser
125
+ * bundle.
126
+ *
127
+ * Browser consumers:
128
+ *
129
+ * ```ts
130
+ * import initWasm, * as wasmMod from '@pandacss/compiler-wasm/pkg-web/compiler_wasm.js'
131
+ * import { createCompilerFromWasmModule } from '@pandacss/compiler-wasm/web'
132
+ *
133
+ * await initWasm(new URL('/compiler_wasm_bg.wasm', window.location.origin))
134
+ * const compiler = createCompilerFromWasmModule(wasmMod, config, options)
135
+ * ```
136
+ */
137
+
138
+ /** `configCallbacks` carry construction-time `utility.values` resolvers. */
139
+ interface WasmFromConfigOptions {
140
+ configCallbacks?: {
141
+ utilityValues?: Record<string, (tokenDictionary: TokenDictionaryInput | undefined) => unknown>;
142
+ };
143
+ }
144
+ /** The raw wasm instance — superset of {@link Compiler} carrying the internal
145
+ * `token_dictionary` the facade hides. */
146
+ interface RawWasmCompiler extends WasmCompiler {
147
+ token_dictionary?(): TokenDictionaryInput | undefined;
148
+ }
149
+ interface WasmModule {
150
+ WasmFileSystem: new () => WasmFileSystem;
151
+ WasmExtractor: new (fs: WasmFileSystem, matchers: unknown) => unknown;
152
+ WasmCompiler: {
153
+ fromConfig(fs: WasmFileSystem, config: SerializedConfig, options?: WasmFromConfigOptions): RawWasmCompiler;
154
+ };
155
+ installPanicHook: () => void;
156
+ }
157
+ /**
158
+ * Build a compiler from an already-loaded wasm module. Browser callers that
159
+ * import `./pkg-web/compiler_wasm.js` should call its default `init()` first,
160
+ * then pass the initialized module here.
161
+ */
162
+ declare function createCompilerFromWasmModule(mod: WasmModule, config: SerializedConfig, options?: CompilerOptions): Compiler;
163
+ declare function build(mod: WasmModule, config: SerializedConfig, callbacks: ProjectCallbacks, hooks?: ProjectHooks): Compiler;
164
+ declare function buildFromConfigOptions(callbacks: ProjectCallbacks): WasmFromConfigOptions | undefined;
165
+
166
+ interface BrowserDriverOptions {
167
+ /** Pre-built config snapshot (no in-browser bundling — Rolldown is Node-only). */
168
+ snapshot: ConfigSnapshot;
169
+ /** Source files to stage into the in-memory fs before the first `scan`. */
170
+ sources?: Record<string, string>;
171
+ /**
172
+ * An initialized `pkg-web` wasm module — the browser path: the caller does
173
+ * `import init, * as mod from '@pandacss/compiler-wasm/pkg-web/compiler_wasm.js'; await init()`
174
+ * and passes `mod` here. Omit in Node/SSR/tests to load the bundled `pkg-node`
175
+ * artifact via `loadWasm`.
176
+ */
177
+ module?: WasmModule;
178
+ }
179
+ /**
180
+ * Build a {@link Driver} backed by the wasm compiler (`MemoryFileSystem`). The
181
+ * browser has no disk, so the host hands in a pre-built config snapshot and
182
+ * stages source files into the in-memory fs; `scan` then runs over that tree in
183
+ * Rust.
184
+ *
185
+ * Pass an initialized `pkg-web` `module` for the real browser path; omit it in
186
+ * Node/SSR/tests to load the bundled `pkg-node` artifact.
187
+ */
188
+ declare function createBrowserDriver(options: BrowserDriverOptions): Promise<Driver>;
189
+
190
+ /**
191
+ * `@pandacss/compiler-wasm` — WebAssembly binding for the Panda Rust engine.
192
+ *
193
+ * Two output targets are bundled:
194
+ * - `./pkg-node/*` — CommonJS, for Node / Vitest / SSR.
195
+ * - `./pkg-web/*` — ESM with `fetch`-based init, for browser playgrounds.
196
+ *
197
+ * Consumers should `import { createCompiler } from '@pandacss/compiler-wasm'`.
198
+ * It loads the wasm module and resolves to a `Compiler` — the same flat shape
199
+ * as the native binding, with the shared in-memory FS exposed as `compiler.fs`.
200
+ *
201
+ * Browser consumers that want a shim-free bundle should import from
202
+ * `@pandacss/compiler-wasm/web` instead — it carries only the wasm-module
203
+ * facade with no `pkg-node` / `loadWasm` in its module graph.
204
+ */
205
+
206
+ /**
207
+ * Load the Node-targeted wasm module. Idempotent — a single shared binding
208
+ * handle is cached after first call. Browser consumers should import
209
+ * `./pkg-web/*` directly and call its `init()`.
210
+ */
211
+ declare function loadWasm(): Promise<WasmModule>;
212
+ /**
213
+ * Build a compiler from a resolved, JSON-safe Panda config. Resolves to a
214
+ * `Compiler` whose `fs` is the shared in-memory filesystem — populate it
215
+ * (`compiler.fs.addFile(...)`) so cross-file imports fold during extraction.
216
+ */
217
+ declare function createCompiler(config: SerializedConfig, options?: CompilerOptions): Promise<Compiler>;
218
+ /** Like {@link createCompiler}, but takes a `{ config, callbacks }` snapshot.
219
+ * Snapshot callbacks merge under any passed in `options.callbacks`. */
220
+ declare function createCompilerFromSnapshot(snapshot: ConfigSnapshot, options?: CompilerOptions): Promise<Compiler>;
221
+
222
+ export { type BrowserDriverOptions, type MatcherInput, type MatchersInput, type TokenDictionaryInput, WasmCompiler, WasmExtractor, WasmFileSystem, type WasmModule, build, buildFromConfigOptions, createBrowserDriver, createCompiler, createCompilerFromSnapshot, createCompilerFromWasmModule, loadWasm };
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ import {
2
+ build,
3
+ buildFromConfigOptions,
4
+ createCompilerFromWasmModule,
5
+ mergeCallbacks
6
+ } from "./chunk-R2J25HLY.js";
7
+
8
+ // src/index.ts
9
+ import { createRequire } from "module";
10
+ import { mergeCallbacks as mergeCallbacks2, mergeHooks } from "@pandacss/compiler-shared";
11
+
12
+ // src/driver.ts
13
+ import {
14
+ BaseDriver
15
+ } from "@pandacss/compiler-shared";
16
+ var NO_CHANGE = { hasChanged: false, dependencies: [], recipes: [], patterns: [], changes: [] };
17
+ async function createBrowserDriver(options) {
18
+ const compiler = options.module ? createCompilerFromWasmModule(options.module, options.snapshot.config, {
19
+ callbacks: options.snapshot.callbacks
20
+ }) : await createCompilerFromSnapshot(options.snapshot);
21
+ if (options.sources) {
22
+ for (const [path, content] of Object.entries(options.sources)) {
23
+ compiler.fs?.addFile(path, content);
24
+ }
25
+ }
26
+ return new BrowserDriver(compiler, options.snapshot.config);
27
+ }
28
+ var BrowserDriver = class extends BaseDriver {
29
+ #config;
30
+ constructor(compiler, config) {
31
+ super(compiler);
32
+ this.#config = config;
33
+ }
34
+ get config() {
35
+ return this.#config;
36
+ }
37
+ get configPath() {
38
+ return void 0;
39
+ }
40
+ get configDependencies() {
41
+ return [];
42
+ }
43
+ // Browser drivers are snapshot-fed; reloading happens by constructing a fresh
44
+ // driver with a new snapshot, so there's nothing to diff here.
45
+ async reload() {
46
+ return NO_CHANGE;
47
+ }
48
+ applyChange(change) {
49
+ if (change.kind === "unlink") {
50
+ this.compiler.fs?.removeFile(change.path);
51
+ return this.compiler.removeFile(change.path);
52
+ }
53
+ if (change.content == null) return false;
54
+ this.compiler.fs?.addFile(change.path, change.content);
55
+ this.compiler.parseFileSource(change.path, change.content);
56
+ return true;
57
+ }
58
+ getOutdir(outdir) {
59
+ return this.compiler.resolvePath(this.getConfiguredOutdir(outdir));
60
+ }
61
+ };
62
+
63
+ // src/index.ts
64
+ var cached = null;
65
+ var require2 = createRequire(import.meta.url);
66
+ async function loadWasm() {
67
+ if (cached) return cached;
68
+ const mod = require2("../pkg-node/compiler_wasm.js");
69
+ cached = mod;
70
+ if (typeof mod.installPanicHook === "function") {
71
+ mod.installPanicHook();
72
+ }
73
+ return mod;
74
+ }
75
+ async function createCompiler(config, options) {
76
+ const { createCompilerFromWasmModule: createCompilerFromWasmModule2 } = await import("./web-Z44NGLTK.js");
77
+ return createCompilerFromWasmModule2(await loadWasm(), config, options);
78
+ }
79
+ async function createCompilerFromSnapshot(snapshot, options) {
80
+ const callbacks = mergeCallbacks2(snapshot.callbacks, options?.callbacks);
81
+ const hooks = mergeHooks(snapshot.hooks, options?.hooks);
82
+ return build(await loadWasm(), snapshot.config, callbacks, hooks);
83
+ }
84
+ export {
85
+ build,
86
+ buildFromConfigOptions,
87
+ createBrowserDriver,
88
+ createCompiler,
89
+ createCompilerFromSnapshot,
90
+ createCompilerFromWasmModule,
91
+ loadWasm,
92
+ mergeCallbacks
93
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ build,
3
+ buildFromConfigOptions,
4
+ createCompilerFromWasmModule,
5
+ mergeCallbacks
6
+ } from "./chunk-R2J25HLY.js";
7
+ export {
8
+ build,
9
+ buildFromConfigOptions,
10
+ createCompilerFromWasmModule,
11
+ mergeCallbacks
12
+ };
package/dist/web.d.ts ADDED
@@ -0,0 +1,166 @@
1
+ import { ParseFileReport, ScanOptions, LayerNames, Spec, SourceEntry, FileInspectionResult, GenerateArtifactOptions, CompileOptions, WriteCssResult, WriteFilesResult, SerializedHookFilter, Atom, RecipeEntry, EncodedRecipeStyles, ProjectSummary, CompileOutput, StylesheetLayerName, CssFile, CodegenArtifact, CodegenArtifactId, CodegenDependency, Diagnostic, CompileFileManifest, ParsedFileView, StaticPatternResult, BuildInfo, SerializedConfig, CompilerOptions, Compiler, ProjectCallbacks, ProjectHooks } from '@pandacss/compiler-shared';
2
+ export * from '@pandacss/compiler-shared';
3
+ export { PatternHelpers, mergeCallbacks } from '@pandacss/compiler-shared';
4
+
5
+ /**
6
+ * TS-facing types that mirror the wasm-bindgen generated interfaces.
7
+ * Kept hand-written (rather than re-exporting from `../pkg-node/*`) so
8
+ * `tsc` typechecks succeed before the wasm artifact is built.
9
+ *
10
+ * The data shapes (`Atom`, `Diagnostic`, `CompileOutput`, …) come from
11
+ * `@pandacss/compiler-shared` — the single contract shared with the native
12
+ * binding. Only the wasm-bindgen *class* shapes live here.
13
+ *
14
+ * Run `pnpm build:wasm` to (re)generate the actual wasm bundle.
15
+ */
16
+
17
+ interface MatcherInput {
18
+ /** Module specifier substrings to match (e.g. `["@panda/css"]`). */
19
+ modules: string[];
20
+ /**
21
+ * Allowed imported names. Omit (or pass `null`) to accept any name —
22
+ * used for recipe/pattern matchers where names are user-defined.
23
+ */
24
+ names?: string[] | null;
25
+ }
26
+ interface TokenDictionaryInput {
27
+ /** `path → raw value` (e.g. `colors.red.500 → #ef4444`). */
28
+ values: Record<string, string>;
29
+ /** `path → CSS var form` (e.g. `colors.red.500 → var(--colors-red-500)`). */
30
+ vars: Record<string, string>;
31
+ }
32
+ type JsxFramework = 'react' | 'solid' | 'preact' | 'vue' | 'qwik' | (string & {});
33
+ type CssSyntax = 'template-literal' | 'object-literal';
34
+ interface MatchersInput {
35
+ css?: MatcherInput;
36
+ recipe?: MatcherInput;
37
+ pattern?: MatcherInput;
38
+ jsx?: MatcherInput;
39
+ tokens?: MatcherInput;
40
+ /** Configured JSX framework. Enables JSX-aware extraction diagnostics. */
41
+ jsxFramework?: JsxFramework;
42
+ /** Defaults to `["styled"]` when omitted. */
43
+ jsxFactories?: string[];
44
+ /** CSS authoring syntax preference. Omit for object-literal mode. */
45
+ syntax?: CssSyntax;
46
+ /** Enable `token('…')` folding by passing a resolved dictionary. */
47
+ tokenDictionary?: TokenDictionaryInput;
48
+ }
49
+ declare class WasmFileSystem {
50
+ constructor();
51
+ addFile(path: string, content: string): void;
52
+ removeFile(path: string): boolean;
53
+ readFile(path: string): string | undefined;
54
+ exists(path: string): boolean;
55
+ fileCount(): number;
56
+ }
57
+ declare class WasmExtractor {
58
+ constructor(fs: WasmFileSystem, matchers: MatchersInput);
59
+ parseFile(path: string, source: string): unknown;
60
+ }
61
+ /** Stateful compiler handle over a `WasmFileSystem`. Cross-file resolution
62
+ * always shares the same FS — `import { x } from './tokens'` references
63
+ * resolve through whatever the JS host has populated.
64
+ *
65
+ * Mirrors the native `Compiler` class. The TS facade adapts this into the
66
+ * shared {@link @pandacss/compiler-shared#Compiler} surface (attaching `fs`,
67
+ * hiding `registerUtilityTransform` / `registerPatternTransform`). */
68
+ declare class WasmCompiler {
69
+ static fromConfig(fs: WasmFileSystem, config: Record<string, unknown>, options?: unknown): WasmCompiler;
70
+ config(): Record<string, unknown> | null;
71
+ extractFileSource(path: string, source: string): unknown;
72
+ parseFile(path: string): ParseFileReport;
73
+ parseFileSource(path: string, source: string): ParseFileReport;
74
+ refreshFile(path: string): boolean;
75
+ refreshFileSource(path: string, source: string): boolean;
76
+ removeFile(path: string): boolean;
77
+ clear(): void;
78
+ scan(options?: ScanOptions): string[];
79
+ realpath(path: string): string;
80
+ resolvePath(path: string, cwd?: string): string;
81
+ joinPath(parts: string[]): string;
82
+ dirname(path: string): string;
83
+ isSourceFile(path: string): boolean;
84
+ parseFiles(paths: string[]): ParseFileReport[];
85
+ layers(): LayerNames;
86
+ hasLayerDeclaration(css: string): boolean;
87
+ spec(): Spec;
88
+ sources(): SourceEntry[];
89
+ inspectFileSource(path: string, source: string): FileInspectionResult;
90
+ writeArtifacts(outdir: string, cwd?: string, options?: GenerateArtifactOptions): string[];
91
+ writeCss(outfile: string, cwd?: string, options?: CompileOptions): WriteCssResult;
92
+ writeSplitCss(outdir: string, cwd?: string): WriteFilesResult;
93
+ isEmpty(): boolean;
94
+ registerUtilityTransform?(id: string, callback: (resolved: unknown, original: unknown) => unknown): void;
95
+ registerPatternTransform?(id: string, callback: (props: unknown, helpers: Record<string, unknown>) => unknown): void;
96
+ registerSourceTransform?(id: string, filter: SerializedHookFilter | undefined, callback: (filePath: string, content: string) => string | undefined): void;
97
+ atoms(): Atom[];
98
+ recipes(): RecipeEntry[];
99
+ slotRecipes(): RecipeEntry[];
100
+ encodedRecipes(): EncodedRecipeStyles;
101
+ summary(): ProjectSummary;
102
+ compile(options?: CompileOptions): CompileOutput;
103
+ layerCss(layers: StylesheetLayerName[]): string;
104
+ splitCss(): CssFile[];
105
+ generateArtifacts(options?: GenerateArtifactOptions): CodegenArtifact[];
106
+ generateArtifact(id: CodegenArtifactId, options?: GenerateArtifactOptions): CodegenArtifact | undefined;
107
+ generateAffectedArtifacts(dependencies: CodegenDependency[], options?: GenerateArtifactOptions): CodegenArtifact[];
108
+ diagnostics(): Diagnostic[];
109
+ fileManifest(): CompileFileManifest[];
110
+ /** Per-file view, or `null` when `path` isn't known. */
111
+ getFile(path: string): ParsedFileView | null;
112
+ staticPatternAtoms(): StaticPatternResult;
113
+ serializeBuildInfo(panda: string): BuildInfo;
114
+ applyBuildInfo(name: string, buildInfo: BuildInfo, only?: string[]): boolean;
115
+ buildInfoSchemaVersion(): number;
116
+ configFingerprint(): string;
117
+ }
118
+
119
+ /**
120
+ * `@pandacss/compiler-wasm/web` — browser-only facade.
121
+ *
122
+ * Exports only the wasm-module facade (`createCompilerFromWasmModule`) and the
123
+ * types/helpers that go with it. Has **no** `import('../pkg-node/...')` in its
124
+ * module graph, so tsup injects no Node `fileURLToPath` shim into the browser
125
+ * bundle.
126
+ *
127
+ * Browser consumers:
128
+ *
129
+ * ```ts
130
+ * import initWasm, * as wasmMod from '@pandacss/compiler-wasm/pkg-web/compiler_wasm.js'
131
+ * import { createCompilerFromWasmModule } from '@pandacss/compiler-wasm/web'
132
+ *
133
+ * await initWasm(new URL('/compiler_wasm_bg.wasm', window.location.origin))
134
+ * const compiler = createCompilerFromWasmModule(wasmMod, config, options)
135
+ * ```
136
+ */
137
+
138
+ /** `configCallbacks` carry construction-time `utility.values` resolvers. */
139
+ interface WasmFromConfigOptions {
140
+ configCallbacks?: {
141
+ utilityValues?: Record<string, (tokenDictionary: TokenDictionaryInput | undefined) => unknown>;
142
+ };
143
+ }
144
+ /** The raw wasm instance — superset of {@link Compiler} carrying the internal
145
+ * `token_dictionary` the facade hides. */
146
+ interface RawWasmCompiler extends WasmCompiler {
147
+ token_dictionary?(): TokenDictionaryInput | undefined;
148
+ }
149
+ interface WasmModule {
150
+ WasmFileSystem: new () => WasmFileSystem;
151
+ WasmExtractor: new (fs: WasmFileSystem, matchers: unknown) => unknown;
152
+ WasmCompiler: {
153
+ fromConfig(fs: WasmFileSystem, config: SerializedConfig, options?: WasmFromConfigOptions): RawWasmCompiler;
154
+ };
155
+ installPanicHook: () => void;
156
+ }
157
+ /**
158
+ * Build a compiler from an already-loaded wasm module. Browser callers that
159
+ * import `./pkg-web/compiler_wasm.js` should call its default `init()` first,
160
+ * then pass the initialized module here.
161
+ */
162
+ declare function createCompilerFromWasmModule(mod: WasmModule, config: SerializedConfig, options?: CompilerOptions): Compiler;
163
+ declare function build(mod: WasmModule, config: SerializedConfig, callbacks: ProjectCallbacks, hooks?: ProjectHooks): Compiler;
164
+ declare function buildFromConfigOptions(callbacks: ProjectCallbacks): WasmFromConfigOptions | undefined;
165
+
166
+ export { type MatcherInput, type MatchersInput, type TokenDictionaryInput, WasmCompiler, WasmExtractor, WasmFileSystem, type WasmModule, build, buildFromConfigOptions, createCompilerFromWasmModule };