@pandacss/compiler 2.0.0-beta.7 → 2.0.0-beta.9
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/binding.cjs +53 -52
- package/dist/{chunk-VRB2SXJJ.js → chunk-G4RVGB4O.js} +319 -73
- package/dist/index.d.ts +15 -152
- package/dist/index.js +5 -3
- package/dist/loader.d.ts +3 -2
- package/dist/loader.js +1 -1
- package/dist/tooling/index.d.ts +105 -0
- package/dist/tooling/index.js +1047 -0
- package/dist/types-DsStlLvF.d.ts +155 -0
- package/package.json +22 -16
|
@@ -0,0 +1,1047 @@
|
|
|
1
|
+
// src/tooling/create-project.ts
|
|
2
|
+
import { defaultConfig } from "@pandacss/compiler-shared";
|
|
3
|
+
import { loadConfig } from "@pandacss/config";
|
|
4
|
+
|
|
5
|
+
// src/design-system.ts
|
|
6
|
+
import "@pandacss/compiler-shared";
|
|
7
|
+
import { readPandaVersion } from "@pandacss/config";
|
|
8
|
+
function hydrateDesignSystem(compiler, chain, consumerTokenPaths = []) {
|
|
9
|
+
if (!chain || chain.length === 0) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const pandaVersion = readPandaVersion();
|
|
13
|
+
const diagnostics = [];
|
|
14
|
+
for (const ds of chain) {
|
|
15
|
+
diagnostics.push(...hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths));
|
|
16
|
+
}
|
|
17
|
+
return diagnostics;
|
|
18
|
+
}
|
|
19
|
+
function hydrateLevel(compiler, ds, pandaVersion, consumerTokenPaths) {
|
|
20
|
+
const compat = compiler.designSystem.validate(ds.manifest, { pandaVersion });
|
|
21
|
+
if (!compat.ok) {
|
|
22
|
+
throw incompatibleManifestError(compiler, ds, compat.reason, pandaVersion);
|
|
23
|
+
}
|
|
24
|
+
const diagnostics = hydrateArtifacts(compiler, ds, pandaVersion);
|
|
25
|
+
diagnostics.push(...tokenConflictDiagnostics(ds, consumerTokenPaths));
|
|
26
|
+
return diagnostics;
|
|
27
|
+
}
|
|
28
|
+
function hydrateArtifacts(compiler, ds, pandaVersion) {
|
|
29
|
+
if (ds.optionMismatch && ds.optionMismatch.length > 0) {
|
|
30
|
+
const diagnostic = recoverFromSources(
|
|
31
|
+
compiler,
|
|
32
|
+
ds,
|
|
33
|
+
(sourceCount, severity) => optionMismatchDiagnostic(ds, sourceCount, severity)
|
|
34
|
+
);
|
|
35
|
+
return [diagnostic];
|
|
36
|
+
}
|
|
37
|
+
let buildInfo;
|
|
38
|
+
try {
|
|
39
|
+
const content = compiler.fs.readFile(ds.buildInfoPath);
|
|
40
|
+
if (content == null) {
|
|
41
|
+
throw new Error("file not found");
|
|
42
|
+
}
|
|
43
|
+
buildInfo = JSON.parse(content);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const issue = { kind: "read", detail: errorMessage(error) };
|
|
46
|
+
const diagnostic = recoverFromSources(
|
|
47
|
+
compiler,
|
|
48
|
+
ds,
|
|
49
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
50
|
+
);
|
|
51
|
+
return [diagnostic];
|
|
52
|
+
}
|
|
53
|
+
const result = compiler.designSystem.load(ds.manifest, { buildInfo, pandaVersion });
|
|
54
|
+
if (!result.ok) {
|
|
55
|
+
const issue = result.reason === "schemaVersion" ? {
|
|
56
|
+
kind: "schemaVersion",
|
|
57
|
+
received: buildInfo.schemaVersion,
|
|
58
|
+
expected: compiler.buildInfo.schemaVersion
|
|
59
|
+
} : { kind: "corrupt" };
|
|
60
|
+
const diagnostic = recoverFromSources(
|
|
61
|
+
compiler,
|
|
62
|
+
ds,
|
|
63
|
+
(sourceCount, severity) => buildInfoDiagnostic(ds, issue, sourceCount, severity)
|
|
64
|
+
);
|
|
65
|
+
return [diagnostic];
|
|
66
|
+
}
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
function recoverFromSources(compiler, ds, createDiagnostic) {
|
|
70
|
+
const sources = extractFallbackSources(compiler, ds);
|
|
71
|
+
const severity = sources.length === 0 ? "error" : "warning";
|
|
72
|
+
const diagnostic = createDiagnostic(sources.length, severity);
|
|
73
|
+
if (sources.length === 0) {
|
|
74
|
+
throw diagnosticError(diagnostic);
|
|
75
|
+
}
|
|
76
|
+
compiler.parseFiles(sources);
|
|
77
|
+
return diagnostic;
|
|
78
|
+
}
|
|
79
|
+
function extractFallbackSources(compiler, ds) {
|
|
80
|
+
if (ds.files.length === 0) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return compiler.scan({ include: ds.files, cwd: compiler.path.dirname(ds.manifestPath) });
|
|
84
|
+
}
|
|
85
|
+
function buildInfoDiagnostic(ds, issue, sourceCount, severity) {
|
|
86
|
+
const reason = buildInfoIssueMessage(issue);
|
|
87
|
+
const outcome = sourceCount > 0 ? ` Re-extracted ${sourceCount} source ${sourceCount === 1 ? "file" : "files"}.` : " No fallback source files were available.";
|
|
88
|
+
return {
|
|
89
|
+
code: "design_system_buildinfo_stale",
|
|
90
|
+
severity,
|
|
91
|
+
category: "designSystem",
|
|
92
|
+
file: ds.buildInfoPath,
|
|
93
|
+
message: `${JSON.stringify(ds.name)} build info ${reason}.${outcome}`,
|
|
94
|
+
help: [`Run \`panda lib\` in ${JSON.stringify(ds.name)} to rebuild panda.buildinfo.json.`]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function buildInfoIssueMessage(issue) {
|
|
98
|
+
if (issue.kind === "schemaVersion") {
|
|
99
|
+
return `uses schemaVersion ${formatValue(issue.received)}; expected ${issue.expected}`;
|
|
100
|
+
}
|
|
101
|
+
if (issue.kind === "read") {
|
|
102
|
+
return `could not be read: ${issue.detail}`;
|
|
103
|
+
}
|
|
104
|
+
return "is malformed or corrupt";
|
|
105
|
+
}
|
|
106
|
+
function optionMismatchDiagnostic(ds, sourceCount, severity) {
|
|
107
|
+
const options = ds.optionMismatch?.join(", ") ?? "class-name options";
|
|
108
|
+
const outcome = sourceCount > 0 ? ` Re-extracted ${sourceCount} source ${sourceCount === 1 ? "file" : "files"} with the consumer options.` : " No fallback source files were available, so the prebuilt class names cannot be used safely.";
|
|
109
|
+
return {
|
|
110
|
+
code: "design_system_option_mismatch",
|
|
111
|
+
severity,
|
|
112
|
+
category: "designSystem",
|
|
113
|
+
file: ds.manifestPath,
|
|
114
|
+
message: `${JSON.stringify(ds.name)} was built with different ${options}.${outcome}`,
|
|
115
|
+
help: [`Match ${options} with ${JSON.stringify(ds.name)}, or rebuild it with \`panda lib\`.`]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function tokenConflictDiagnostics(ds, consumerTokenPaths) {
|
|
119
|
+
if (consumerTokenPaths.length === 0 || ds.tokenPaths.length === 0) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const designSystemTokenPaths = new Set(ds.tokenPaths);
|
|
123
|
+
const conflicts = [...new Set(consumerTokenPaths.filter((path) => designSystemTokenPaths.has(path)))].sort();
|
|
124
|
+
if (conflicts.length === 0) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
const preview = conflicts.slice(0, 3).map((path) => JSON.stringify(path)).join(", ");
|
|
128
|
+
const remainder = conflicts.length > 3 ? ` and ${conflicts.length - 3} more` : "";
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
code: "design_system_token_conflict",
|
|
132
|
+
severity: "info",
|
|
133
|
+
category: "designSystem",
|
|
134
|
+
file: ds.manifestPath,
|
|
135
|
+
message: `${conflicts.length} token ${conflicts.length === 1 ? "path is" : "paths are"} defined by both ${JSON.stringify(ds.name)} and this config (${preview}${remainder}); the local values win.`
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
function incompatibleManifestError(compiler, ds, reason, pandaVersion) {
|
|
140
|
+
if (reason === "schemaVersion") {
|
|
141
|
+
return diagnosticError({
|
|
142
|
+
code: "design_system_version_mismatch",
|
|
143
|
+
severity: "error",
|
|
144
|
+
category: "designSystem",
|
|
145
|
+
file: ds.manifestPath,
|
|
146
|
+
message: `${JSON.stringify(ds.name)} panda.lib.json uses schemaVersion ${ds.manifest.schemaVersion}; expected ${compiler.designSystem.schemaVersion}.`,
|
|
147
|
+
help: [`Upgrade ${JSON.stringify(ds.name)}, or rebuild it with a compatible version of Panda.`]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const running = pandaVersion ? `; the consumer uses ${pandaVersion}` : "";
|
|
151
|
+
return diagnosticError({
|
|
152
|
+
code: "design_system_peer_range_unsatisfied",
|
|
153
|
+
severity: "error",
|
|
154
|
+
category: "designSystem",
|
|
155
|
+
file: ds.manifestPath,
|
|
156
|
+
message: `${JSON.stringify(ds.name)} requires Panda ${ds.manifest.panda}${running}.`,
|
|
157
|
+
help: [`Install a compatible Panda version or update ${JSON.stringify(ds.name)}.`]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function diagnosticError(diagnostic) {
|
|
161
|
+
const error = new Error(diagnostic.message);
|
|
162
|
+
error.diagnostics = [diagnostic];
|
|
163
|
+
return error;
|
|
164
|
+
}
|
|
165
|
+
function formatValue(value) {
|
|
166
|
+
return typeof value === "number" || typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
167
|
+
}
|
|
168
|
+
function errorMessage(error) {
|
|
169
|
+
return error instanceof Error ? error.message : String(error);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/index.ts
|
|
173
|
+
import {
|
|
174
|
+
assertProjectHooks,
|
|
175
|
+
assertProjectCallbacks,
|
|
176
|
+
BuildInfo as BuildInfo2,
|
|
177
|
+
DesignSystem as DesignSystem2,
|
|
178
|
+
getTokenCategoryValues,
|
|
179
|
+
inspectFile,
|
|
180
|
+
inspectFiles,
|
|
181
|
+
mergeCallbacks,
|
|
182
|
+
mergeHooks,
|
|
183
|
+
prepareCompilerConfig
|
|
184
|
+
} from "@pandacss/compiler-shared";
|
|
185
|
+
|
|
186
|
+
// src/callbacks.ts
|
|
187
|
+
import {
|
|
188
|
+
createPatternHelpers,
|
|
189
|
+
createTransformArgs,
|
|
190
|
+
getPatternDefaultValueRefsByTransformId,
|
|
191
|
+
mergePatternDefaultValues
|
|
192
|
+
} from "@pandacss/compiler-shared";
|
|
193
|
+
function registerCallbacks(project, callbacks, hooks, tokenDictionary) {
|
|
194
|
+
const utilityTransforms = callbacks["utility.transform"];
|
|
195
|
+
const hasUtilityTransforms = !!utilityTransforms && Object.keys(utilityTransforms).length > 0;
|
|
196
|
+
const patternTransforms = callbacks["pattern.transform"];
|
|
197
|
+
const hasPatternTransforms = !!patternTransforms && Object.keys(patternTransforms).length > 0;
|
|
198
|
+
const config = project.config();
|
|
199
|
+
const patternDefaultValues = callbacks["pattern.defaultValues"];
|
|
200
|
+
const patternDefaultValueRefs = config && patternDefaultValues ? getPatternDefaultValueRefsByTransformId(config) : /* @__PURE__ */ new Map();
|
|
201
|
+
if (hasPatternTransforms && !project.registerPatternTransform) {
|
|
202
|
+
throw new Error("Native project does not support pattern.transform callbacks");
|
|
203
|
+
}
|
|
204
|
+
if (project.registerPatternTransform && patternTransforms) {
|
|
205
|
+
for (const [id, callback] of Object.entries(patternTransforms)) {
|
|
206
|
+
const defaultValueId = patternDefaultValueRefs.get(id);
|
|
207
|
+
const defaultValue = defaultValueId ? patternDefaultValues?.[defaultValueId] : void 0;
|
|
208
|
+
project.registerPatternTransform(id, (props) => {
|
|
209
|
+
const input = props;
|
|
210
|
+
const nextProps = defaultValue ? mergePatternDefaultValues(defaultValue(input), input) : input;
|
|
211
|
+
return callback(nextProps, createPatternHelpers());
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (hasUtilityTransforms && !project.registerUtilityTransform) {
|
|
216
|
+
throw new Error("Native project does not support utility.transform callbacks");
|
|
217
|
+
}
|
|
218
|
+
if (project.registerUtilityTransform && utilityTransforms) {
|
|
219
|
+
for (const [id, callback] of Object.entries(utilityTransforms)) {
|
|
220
|
+
project.registerUtilityTransform(id, (resolved, original) => {
|
|
221
|
+
return callback(resolved, createTransformArgs(original, tokenDictionary));
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const sourceTransforms = hooks?.["parser:before"];
|
|
226
|
+
if (sourceTransforms?.length && !project.registerSourceTransform) {
|
|
227
|
+
throw new Error("Native project does not support parser:before callbacks");
|
|
228
|
+
}
|
|
229
|
+
if (project.registerSourceTransform && sourceTransforms) {
|
|
230
|
+
for (const hook of sourceTransforms) {
|
|
231
|
+
const callback = callbacks["parser:before"]?.[hook.id];
|
|
232
|
+
if (!callback) continue;
|
|
233
|
+
project.registerSourceTransform(hook.id, hook.filter, (filePath, content) => {
|
|
234
|
+
const result = callback({ filePath: String(filePath), content: String(content), original: String(content) });
|
|
235
|
+
if (isPromiseLike(result)) {
|
|
236
|
+
throw new Error(`parser:before callback \`${hook.id}\` must be synchronous`);
|
|
237
|
+
}
|
|
238
|
+
return typeof result === "string" ? result : void 0;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function isPromiseLike(value) {
|
|
244
|
+
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/fallback.ts
|
|
248
|
+
import { BuildInfo, DesignSystem } from "@pandacss/compiler-shared";
|
|
249
|
+
var fallbackBuildInfo = new BuildInfo({
|
|
250
|
+
serializeBuildInfo: () => ({
|
|
251
|
+
schemaVersion: -1,
|
|
252
|
+
panda: "",
|
|
253
|
+
configFingerprint: "",
|
|
254
|
+
strings: [],
|
|
255
|
+
atoms: [],
|
|
256
|
+
modules: {}
|
|
257
|
+
}),
|
|
258
|
+
applyBuildInfo: () => false,
|
|
259
|
+
buildInfoSchemaVersion: () => -1,
|
|
260
|
+
configFingerprint: () => ""
|
|
261
|
+
});
|
|
262
|
+
var fallbackDesignSystem = new DesignSystem(
|
|
263
|
+
{
|
|
264
|
+
createManifest: (input) => ({ ...input, schemaVersion: -1 }),
|
|
265
|
+
manifestSchemaVersion: () => -1
|
|
266
|
+
},
|
|
267
|
+
fallbackBuildInfo
|
|
268
|
+
);
|
|
269
|
+
var FallbackExtractor = class {
|
|
270
|
+
extract() {
|
|
271
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
272
|
+
}
|
|
273
|
+
extractDebug() {
|
|
274
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
275
|
+
}
|
|
276
|
+
matchImports() {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var FallbackCompiler = class _FallbackCompiler {
|
|
281
|
+
fs = {
|
|
282
|
+
readFile: (_path) => void 0,
|
|
283
|
+
exists: (_path) => false
|
|
284
|
+
};
|
|
285
|
+
path = {
|
|
286
|
+
realpath: (path) => path,
|
|
287
|
+
resolve: (path, cwd) => this.resolvePath(path, cwd),
|
|
288
|
+
join: (parts) => this.joinPath(parts),
|
|
289
|
+
dirname: (path) => this.dirname(path)
|
|
290
|
+
};
|
|
291
|
+
static fromConfig() {
|
|
292
|
+
return new _FallbackCompiler();
|
|
293
|
+
}
|
|
294
|
+
serializeBuildInfo() {
|
|
295
|
+
return fallbackBuildInfo.create({ panda: "" });
|
|
296
|
+
}
|
|
297
|
+
applyBuildInfo() {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
buildInfoSchemaVersion() {
|
|
301
|
+
return -1;
|
|
302
|
+
}
|
|
303
|
+
configFingerprint() {
|
|
304
|
+
return "";
|
|
305
|
+
}
|
|
306
|
+
createDesignSystemManifest(input) {
|
|
307
|
+
return { ...input, schemaVersion: -1 };
|
|
308
|
+
}
|
|
309
|
+
designSystemManifestSchemaVersion() {
|
|
310
|
+
return -1;
|
|
311
|
+
}
|
|
312
|
+
config() {
|
|
313
|
+
return {};
|
|
314
|
+
}
|
|
315
|
+
extractFileSource() {
|
|
316
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
317
|
+
}
|
|
318
|
+
parseFile(path) {
|
|
319
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
320
|
+
}
|
|
321
|
+
parseFileSource(path) {
|
|
322
|
+
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
323
|
+
}
|
|
324
|
+
refreshFile() {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
refreshFileSource() {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
removeFile() {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
clear() {
|
|
334
|
+
}
|
|
335
|
+
scan() {
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
realpath(path) {
|
|
339
|
+
return path;
|
|
340
|
+
}
|
|
341
|
+
readFile(_path) {
|
|
342
|
+
return void 0;
|
|
343
|
+
}
|
|
344
|
+
exists(_path) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
resolvePath(path, cwd) {
|
|
348
|
+
if (!cwd || path.startsWith("/")) return path;
|
|
349
|
+
return `${cwd.replace(/\/$/, "")}/${path}`;
|
|
350
|
+
}
|
|
351
|
+
joinPath(parts) {
|
|
352
|
+
return parts.filter(Boolean).join("/");
|
|
353
|
+
}
|
|
354
|
+
dirname(path) {
|
|
355
|
+
const index = path.lastIndexOf("/");
|
|
356
|
+
return index <= 0 ? "" : path.slice(0, index);
|
|
357
|
+
}
|
|
358
|
+
isSourceFile() {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
parseFiles(_paths) {
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
layers() {
|
|
365
|
+
return { reset: "reset", base: "base", tokens: "tokens", recipes: "recipes", utilities: "utilities" };
|
|
366
|
+
}
|
|
367
|
+
hasLayerDeclaration() {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
spec() {
|
|
371
|
+
return {
|
|
372
|
+
conditions: { keys: [], breakpoints: [], containers: [] },
|
|
373
|
+
tokens: { categories: {}, colorPalettes: [], values: {}, deprecated: {} },
|
|
374
|
+
utilities: { properties: {}, shorthands: {}, deprecated: {} },
|
|
375
|
+
keyframes: { keys: [] },
|
|
376
|
+
patterns: {},
|
|
377
|
+
recipes: {},
|
|
378
|
+
slotRecipes: {},
|
|
379
|
+
propertyOrder: []
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
sources() {
|
|
383
|
+
return [];
|
|
384
|
+
}
|
|
385
|
+
inspectFileSource(_path, _source) {
|
|
386
|
+
return { usages: [], diagnostics: [], calls: [], jsx: [], tokenRefs: [], componentEntries: [], styleEntries: [] };
|
|
387
|
+
}
|
|
388
|
+
transformSource(input) {
|
|
389
|
+
return {
|
|
390
|
+
code: input.source,
|
|
391
|
+
map: null,
|
|
392
|
+
changed: false,
|
|
393
|
+
bailed: false,
|
|
394
|
+
diagnostics: [],
|
|
395
|
+
dependencies: [],
|
|
396
|
+
helper: { needsCx: false, needsCva: false, needsSva: false }
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
inspectFile(input) {
|
|
400
|
+
return { ...this.inspectFileSource(input.path, input.source), path: input.path };
|
|
401
|
+
}
|
|
402
|
+
inspectFiles(files) {
|
|
403
|
+
return { sourceCount: files.length, files: files.map((file) => this.inspectFile(file)) };
|
|
404
|
+
}
|
|
405
|
+
resolveUtilityValue() {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
suggestTokens() {
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
suggestSemanticTokens() {
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
writeArtifacts(_options) {
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
417
|
+
writeCss(options) {
|
|
418
|
+
return emptyWriteCssResult(options.outfile);
|
|
419
|
+
}
|
|
420
|
+
writeLayerCss(options) {
|
|
421
|
+
return emptyWriteCssResult(options.outfile);
|
|
422
|
+
}
|
|
423
|
+
writeSplitCss(options) {
|
|
424
|
+
return emptyWriteFilesResult(options.outdir ?? "");
|
|
425
|
+
}
|
|
426
|
+
isEmpty() {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
atoms() {
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
recipes() {
|
|
433
|
+
return [];
|
|
434
|
+
}
|
|
435
|
+
slotRecipes() {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
encodedRecipes() {
|
|
439
|
+
return { base: [], variants: [], atomic: [] };
|
|
440
|
+
}
|
|
441
|
+
staticPatternAtoms() {
|
|
442
|
+
return { atoms: [], diagnostics: [] };
|
|
443
|
+
}
|
|
444
|
+
getFile() {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
fileManifest() {
|
|
448
|
+
return [];
|
|
449
|
+
}
|
|
450
|
+
summary() {
|
|
451
|
+
return { filesProcessed: 0, atomCount: 0, recipeCount: 0, slotRecipeCount: 0 };
|
|
452
|
+
}
|
|
453
|
+
compile() {
|
|
454
|
+
return emptyCompileOutput();
|
|
455
|
+
}
|
|
456
|
+
getLayerCss(_options) {
|
|
457
|
+
return emptyCompileOutput();
|
|
458
|
+
}
|
|
459
|
+
getSplitCss(_options) {
|
|
460
|
+
return [];
|
|
461
|
+
}
|
|
462
|
+
buildInfo = fallbackBuildInfo;
|
|
463
|
+
designSystem = fallbackDesignSystem;
|
|
464
|
+
generateArtifacts() {
|
|
465
|
+
return [];
|
|
466
|
+
}
|
|
467
|
+
generateArtifact() {
|
|
468
|
+
return void 0;
|
|
469
|
+
}
|
|
470
|
+
generateAffectedArtifacts() {
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
diagnostics() {
|
|
474
|
+
return [];
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var fallback = {
|
|
478
|
+
startTracing() {
|
|
479
|
+
return false;
|
|
480
|
+
},
|
|
481
|
+
flushTracing() {
|
|
482
|
+
},
|
|
483
|
+
takeTimingsJson() {
|
|
484
|
+
return void 0;
|
|
485
|
+
},
|
|
486
|
+
shutdownTracing() {
|
|
487
|
+
return false;
|
|
488
|
+
},
|
|
489
|
+
compile() {
|
|
490
|
+
return emptyCompileOutput();
|
|
491
|
+
},
|
|
492
|
+
scanImports() {
|
|
493
|
+
return { imports: [], diagnostics: [] };
|
|
494
|
+
},
|
|
495
|
+
matchImports() {
|
|
496
|
+
return [];
|
|
497
|
+
},
|
|
498
|
+
extractCalls() {
|
|
499
|
+
return { calls: [], diagnostics: [] };
|
|
500
|
+
},
|
|
501
|
+
extractJsx() {
|
|
502
|
+
return { jsx: [], diagnostics: [] };
|
|
503
|
+
},
|
|
504
|
+
extract() {
|
|
505
|
+
return { calls: [], jsx: [], diagnostics: [] };
|
|
506
|
+
},
|
|
507
|
+
extractDebug() {
|
|
508
|
+
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
509
|
+
},
|
|
510
|
+
Extractor: FallbackExtractor,
|
|
511
|
+
Compiler: FallbackCompiler
|
|
512
|
+
};
|
|
513
|
+
function emptyCompileOutput() {
|
|
514
|
+
return {
|
|
515
|
+
css: "",
|
|
516
|
+
manifest: { files: [], tokens: [] },
|
|
517
|
+
layerRanges: {},
|
|
518
|
+
diagnostics: []
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
function emptyWriteCssResult(path) {
|
|
522
|
+
return {
|
|
523
|
+
path,
|
|
524
|
+
...emptyCompileOutput()
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function emptyWriteFilesResult(root) {
|
|
528
|
+
return {
|
|
529
|
+
root,
|
|
530
|
+
paths: [],
|
|
531
|
+
files: []
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// src/load-binary.ts
|
|
536
|
+
import { execFileSync } from "child_process";
|
|
537
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
538
|
+
import { createRequire } from "module";
|
|
539
|
+
import { dirname, join } from "path";
|
|
540
|
+
import { fileURLToPath } from "url";
|
|
541
|
+
var bindingUrl = new URL("../binding.cjs", import.meta.url);
|
|
542
|
+
var webContainerWasiPackage = "@pandacss/compiler-wasm32-wasi";
|
|
543
|
+
function loadNativeBinding() {
|
|
544
|
+
const bindingPath = resolveBindingPath();
|
|
545
|
+
if (!bindingPath) return void 0;
|
|
546
|
+
const require2 = createRequire(bindingPath);
|
|
547
|
+
try {
|
|
548
|
+
return require2(bindingPath);
|
|
549
|
+
} catch (error) {
|
|
550
|
+
if (!isWebContainer()) throw error;
|
|
551
|
+
return loadWebContainerBinding(require2, bindingPath, error);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function resolveBindingPath() {
|
|
555
|
+
if (bindingUrl.protocol === "file:") {
|
|
556
|
+
const bindingPath = fileURLToPath(bindingUrl);
|
|
557
|
+
if (existsSync(bindingPath)) return bindingPath;
|
|
558
|
+
}
|
|
559
|
+
return fallbackBindingPaths().find((path) => existsSync(path));
|
|
560
|
+
}
|
|
561
|
+
function fallbackBindingPaths() {
|
|
562
|
+
const cwd = process.cwd();
|
|
563
|
+
const paths = [join(cwd, "packages/compiler/binding.cjs")];
|
|
564
|
+
if (isCompilerPackageRoot(cwd)) {
|
|
565
|
+
paths.unshift(join(cwd, "binding.cjs"));
|
|
566
|
+
}
|
|
567
|
+
return paths;
|
|
568
|
+
}
|
|
569
|
+
function isCompilerPackageRoot(cwd) {
|
|
570
|
+
try {
|
|
571
|
+
const packageJson = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
572
|
+
return packageJson.name === "@pandacss/compiler";
|
|
573
|
+
} catch {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function isWebContainer() {
|
|
578
|
+
const versions = process.versions;
|
|
579
|
+
return Boolean(versions.webcontainer);
|
|
580
|
+
}
|
|
581
|
+
function resolveWebContainerBinding(version, root = "/tmp") {
|
|
582
|
+
const baseDir = join(root, `pandacss-compiler-${version}`);
|
|
583
|
+
return {
|
|
584
|
+
baseDir,
|
|
585
|
+
bindingPackage: `${webContainerWasiPackage}@${version}`,
|
|
586
|
+
bindingEntry: join(baseDir, "node_modules", webContainerWasiPackage, "compiler.wasi.cjs")
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function loadWebContainerBinding(require2, bindingPath, nativeError) {
|
|
590
|
+
const version = readCompilerVersion(require2, dirname(bindingPath));
|
|
591
|
+
const { baseDir, bindingPackage, bindingEntry } = resolveWebContainerBinding(version);
|
|
592
|
+
if (!existsSync(bindingEntry)) {
|
|
593
|
+
rmSync(baseDir, { recursive: true, force: true });
|
|
594
|
+
mkdirSync(baseDir, { recursive: true });
|
|
595
|
+
execFileSync("pnpm", ["i", bindingPackage], {
|
|
596
|
+
cwd: baseDir,
|
|
597
|
+
stdio: "inherit"
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
try {
|
|
601
|
+
return require2(bindingEntry);
|
|
602
|
+
} catch (fallbackError) {
|
|
603
|
+
throw new Error("Failed to load @pandacss/compiler WebContainer WASI fallback", {
|
|
604
|
+
cause: chainError(nativeError, fallbackError)
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function readCompilerVersion(require2, packageRoot) {
|
|
609
|
+
try {
|
|
610
|
+
const packageJsonPath = require2.resolve("@pandacss/compiler/package.json");
|
|
611
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
612
|
+
return packageJson.version;
|
|
613
|
+
} catch {
|
|
614
|
+
const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
615
|
+
return packageJson.version;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function chainError(primary, cause) {
|
|
619
|
+
if (primary instanceof Error) {
|
|
620
|
+
primary.cause = cause;
|
|
621
|
+
return primary;
|
|
622
|
+
}
|
|
623
|
+
return cause;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/index.ts
|
|
627
|
+
import { createUsageReport } from "@pandacss/compiler-shared";
|
|
628
|
+
var binding = loadNativeBinding() ?? fallback;
|
|
629
|
+
var nativeCompilerFromConfig = "fromConfig" in binding.Compiler && typeof binding.Compiler.fromConfig === "function" ? binding.Compiler.fromConfig.bind(binding.Compiler) : void 0;
|
|
630
|
+
function createCompilerFromSnapshot(snapshot, options) {
|
|
631
|
+
const callbacks = mergeCallbacks(snapshot.callbacks, options?.callbacks);
|
|
632
|
+
const hooks = mergeHooks(snapshot.hooks, options?.hooks);
|
|
633
|
+
return build(snapshot.config, callbacks, { ...options, hooks });
|
|
634
|
+
}
|
|
635
|
+
function build(config, callbacks, options) {
|
|
636
|
+
assertProjectCallbacks(config, callbacks);
|
|
637
|
+
assertProjectHooks(options?.hooks, callbacks);
|
|
638
|
+
if (!nativeCompilerFromConfig) {
|
|
639
|
+
throw new Error("createCompiler is not available in this binding");
|
|
640
|
+
}
|
|
641
|
+
const prepared = prepareCompilerConfig(config);
|
|
642
|
+
const compiler = nativeCompilerFromConfig(prepared, toNativeOptions(options), createUtilityValuesCallbacks(callbacks));
|
|
643
|
+
registerCallbacks(compiler, callbacks, options?.hooks, compiler.token_dictionary?.());
|
|
644
|
+
attachFileSystem(compiler);
|
|
645
|
+
attachPathSystem(compiler);
|
|
646
|
+
attachBuildInfo(compiler);
|
|
647
|
+
attachDesignSystem(compiler);
|
|
648
|
+
attachInspection(compiler);
|
|
649
|
+
return compiler;
|
|
650
|
+
}
|
|
651
|
+
function attachFileSystem(compiler) {
|
|
652
|
+
Object.defineProperty(compiler, "fs", {
|
|
653
|
+
value: {
|
|
654
|
+
readFile: (path) => compiler.readFile(path),
|
|
655
|
+
exists: (path) => compiler.exists(path)
|
|
656
|
+
},
|
|
657
|
+
enumerable: false,
|
|
658
|
+
configurable: true
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
function attachPathSystem(compiler) {
|
|
662
|
+
Object.defineProperty(compiler, "path", {
|
|
663
|
+
value: {
|
|
664
|
+
realpath: (path) => compiler.realpath(path),
|
|
665
|
+
resolve: (path, cwd) => compiler.resolvePath(path, cwd),
|
|
666
|
+
join: (parts) => compiler.joinPath(parts),
|
|
667
|
+
dirname: (path) => compiler.dirname(path)
|
|
668
|
+
},
|
|
669
|
+
enumerable: false,
|
|
670
|
+
configurable: true
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
function attachBuildInfo(compiler) {
|
|
674
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
675
|
+
enumerable: false,
|
|
676
|
+
configurable: true,
|
|
677
|
+
get() {
|
|
678
|
+
const api = new BuildInfo2(compiler);
|
|
679
|
+
Object.defineProperty(compiler, "buildInfo", {
|
|
680
|
+
value: api,
|
|
681
|
+
enumerable: false,
|
|
682
|
+
configurable: true
|
|
683
|
+
});
|
|
684
|
+
return api;
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
function attachDesignSystem(compiler) {
|
|
689
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
690
|
+
enumerable: false,
|
|
691
|
+
configurable: true,
|
|
692
|
+
get() {
|
|
693
|
+
const api = new DesignSystem2(toDesignSystemBinding(compiler), compiler.buildInfo);
|
|
694
|
+
Object.defineProperty(compiler, "designSystem", {
|
|
695
|
+
value: api,
|
|
696
|
+
enumerable: false,
|
|
697
|
+
configurable: true
|
|
698
|
+
});
|
|
699
|
+
return api;
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
function attachInspection(compiler) {
|
|
704
|
+
Object.defineProperty(compiler, "inspectFile", {
|
|
705
|
+
enumerable: false,
|
|
706
|
+
configurable: true,
|
|
707
|
+
value: (input) => inspectFile(compiler, input)
|
|
708
|
+
});
|
|
709
|
+
Object.defineProperty(compiler, "inspectFiles", {
|
|
710
|
+
enumerable: false,
|
|
711
|
+
configurable: true,
|
|
712
|
+
value: (files) => inspectFiles(compiler, files)
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
function toDesignSystemBinding(compiler) {
|
|
716
|
+
return {
|
|
717
|
+
createManifest: (input) => compiler.createDesignSystemManifest(input),
|
|
718
|
+
manifestSchemaVersion: () => compiler.designSystemManifestSchemaVersion()
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function toNativeOptions(options) {
|
|
722
|
+
if (!options || options.crossFile === void 0) return void 0;
|
|
723
|
+
return { crossFile: options.crossFile };
|
|
724
|
+
}
|
|
725
|
+
function createUtilityValuesCallbacks(callbacks) {
|
|
726
|
+
const utilityValues = callbacks["utility.values"];
|
|
727
|
+
if (!utilityValues || Object.keys(utilityValues).length === 0) return void 0;
|
|
728
|
+
return Object.fromEntries(
|
|
729
|
+
Object.entries(utilityValues).map(([id, callback]) => [
|
|
730
|
+
id,
|
|
731
|
+
(tokenDictionary) => callback((category) => getTokenCategoryValues(category, tokenDictionary))
|
|
732
|
+
])
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// src/tooling/create-project.ts
|
|
737
|
+
function createProjectFromLoadedConfig(loaded) {
|
|
738
|
+
const compiler = createCompilerFromSnapshot({
|
|
739
|
+
config: loaded.config,
|
|
740
|
+
callbacks: loaded.callbacks,
|
|
741
|
+
hooks: loaded.hooks
|
|
742
|
+
});
|
|
743
|
+
const designSystemDiagnostics = hydrateDesignSystem(
|
|
744
|
+
compiler,
|
|
745
|
+
loaded.metadata?.designSystem,
|
|
746
|
+
loaded.metadata?.userTokenPaths ?? []
|
|
747
|
+
);
|
|
748
|
+
return {
|
|
749
|
+
compiler,
|
|
750
|
+
configPath: loaded.path,
|
|
751
|
+
dependencies: loaded.dependencies,
|
|
752
|
+
outdir: loaded.config.outdir ?? defaultConfig.outdir,
|
|
753
|
+
designSystemDiagnostics
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
async function createProjectFromConfig(key) {
|
|
757
|
+
const loaded = await loadConfig({ cwd: key.cwd, file: key.configPath });
|
|
758
|
+
return createProjectFromLoadedConfig(loaded);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/tooling/inspector.ts
|
|
762
|
+
var FileInspector = class {
|
|
763
|
+
#entries = /* @__PURE__ */ new WeakMap();
|
|
764
|
+
inspect(compiler, path, source) {
|
|
765
|
+
let byPath = this.#entries.get(compiler);
|
|
766
|
+
if (!byPath) {
|
|
767
|
+
byPath = /* @__PURE__ */ new Map();
|
|
768
|
+
this.#entries.set(compiler, byPath);
|
|
769
|
+
}
|
|
770
|
+
const sourceKey = sourceCacheKey(source);
|
|
771
|
+
const cached = byPath.get(path);
|
|
772
|
+
if (cached?.sourceKey === sourceKey) return cached.result;
|
|
773
|
+
const result = compiler.inspectFile({ path, source });
|
|
774
|
+
byPath.set(path, { sourceKey, result });
|
|
775
|
+
return result;
|
|
776
|
+
}
|
|
777
|
+
clear(compiler) {
|
|
778
|
+
if (compiler) {
|
|
779
|
+
this.#entries.delete(compiler);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
this.#entries = /* @__PURE__ */ new WeakMap();
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
function sourceCacheKey(source) {
|
|
786
|
+
let hash = 2166136261;
|
|
787
|
+
for (let i = 0; i < source.length; i++) {
|
|
788
|
+
hash ^= source.charCodeAt(i);
|
|
789
|
+
hash = Math.imul(hash, 16777619);
|
|
790
|
+
}
|
|
791
|
+
return `${source.length}:${hash >>> 0}`;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/tooling/registry.ts
|
|
795
|
+
import { watch } from "fs";
|
|
796
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
797
|
+
import { findConfig } from "@pandacss/config";
|
|
798
|
+
var ProjectRegistry = class {
|
|
799
|
+
#projects = /* @__PURE__ */ new Map();
|
|
800
|
+
#watchers = /* @__PURE__ */ new Map();
|
|
801
|
+
#createProject;
|
|
802
|
+
constructor(options = {}) {
|
|
803
|
+
this.#createProject = options.createProject ?? ((key) => createProjectFromConfig(key));
|
|
804
|
+
}
|
|
805
|
+
getProject(key) {
|
|
806
|
+
const resolvedPath = resolveConfigPath(key);
|
|
807
|
+
const cacheKey = resolvedPath ?? syntheticKey(key);
|
|
808
|
+
const cached = this.#projects.get(cacheKey);
|
|
809
|
+
if (cached) return cached;
|
|
810
|
+
if (resolvedPath) this.#watch(cacheKey, [resolvedPath]);
|
|
811
|
+
const project = this.#createProject(key);
|
|
812
|
+
project.then(
|
|
813
|
+
(resolved) => {
|
|
814
|
+
if (resolvedPath && this.#projects.get(cacheKey) === project) {
|
|
815
|
+
this.#watch(cacheKey, [resolvedPath, ...resolved.dependencies]);
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
() => this.#evict(cacheKey)
|
|
819
|
+
);
|
|
820
|
+
this.#projects.set(cacheKey, project);
|
|
821
|
+
return project;
|
|
822
|
+
}
|
|
823
|
+
// Coarse: wipes the whole cache regardless of which paths changed.
|
|
824
|
+
invalidate(_changedPaths = []) {
|
|
825
|
+
for (const watchers of this.#watchers.values()) {
|
|
826
|
+
for (const watcher of watchers) watcher.close();
|
|
827
|
+
}
|
|
828
|
+
this.#watchers.clear();
|
|
829
|
+
this.#projects.clear();
|
|
830
|
+
}
|
|
831
|
+
// Watches directories (not individual files) — editors that save via atomic
|
|
832
|
+
// rename/replace can otherwise silently stop notifying a file-level watcher.
|
|
833
|
+
#watch(cacheKey, paths) {
|
|
834
|
+
this.#closeWatchers(cacheKey);
|
|
835
|
+
const filesByDir = /* @__PURE__ */ new Map();
|
|
836
|
+
for (const path of new Set(paths)) {
|
|
837
|
+
const dir = dirname2(path);
|
|
838
|
+
if (!filesByDir.has(dir)) filesByDir.set(dir, /* @__PURE__ */ new Set());
|
|
839
|
+
filesByDir.get(dir)?.add(path);
|
|
840
|
+
}
|
|
841
|
+
const watchers = [];
|
|
842
|
+
for (const [dir, filesInDir] of filesByDir) {
|
|
843
|
+
try {
|
|
844
|
+
watchers.push(
|
|
845
|
+
watch(dir, (_event, filename) => {
|
|
846
|
+
if (filename && filesInDir.has(join2(dir, filename))) this.#evict(cacheKey);
|
|
847
|
+
})
|
|
848
|
+
);
|
|
849
|
+
} catch {
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
this.#watchers.set(cacheKey, watchers);
|
|
853
|
+
}
|
|
854
|
+
#closeWatchers(cacheKey) {
|
|
855
|
+
for (const watcher of this.#watchers.get(cacheKey) ?? []) watcher.close();
|
|
856
|
+
}
|
|
857
|
+
#evict(cacheKey) {
|
|
858
|
+
this.#closeWatchers(cacheKey);
|
|
859
|
+
this.#watchers.delete(cacheKey);
|
|
860
|
+
this.#projects.delete(cacheKey);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
function resolveConfigPath(key) {
|
|
864
|
+
try {
|
|
865
|
+
return findConfig({ cwd: key.cwd, file: key.configPath });
|
|
866
|
+
} catch {
|
|
867
|
+
return void 0;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
function syntheticKey(key) {
|
|
871
|
+
return `${key.cwd}\0${key.configPath ?? ""}`;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// src/tooling/spec-index.ts
|
|
875
|
+
var SpecIndex = class {
|
|
876
|
+
spec;
|
|
877
|
+
#categoryByProperty;
|
|
878
|
+
#literalsByProperty;
|
|
879
|
+
constructor(spec) {
|
|
880
|
+
this.spec = spec;
|
|
881
|
+
this.#categoryByProperty = buildCategoryByProperty(spec);
|
|
882
|
+
this.#literalsByProperty = buildLiteralsByProperty(spec);
|
|
883
|
+
}
|
|
884
|
+
resolveTokenValue(path) {
|
|
885
|
+
return this.spec.tokens.values[path];
|
|
886
|
+
}
|
|
887
|
+
resolveTokenPaths(prefix = "") {
|
|
888
|
+
const paths = Object.keys(this.spec.tokens.values);
|
|
889
|
+
return prefix ? paths.filter((path) => path.startsWith(prefix)) : paths;
|
|
890
|
+
}
|
|
891
|
+
resolveTokenDeprecation(path) {
|
|
892
|
+
return this.spec.tokens.deprecated[path];
|
|
893
|
+
}
|
|
894
|
+
hasCondition(name) {
|
|
895
|
+
return this.spec.conditions.keys.includes(name);
|
|
896
|
+
}
|
|
897
|
+
/** Bare style-object keys: named/custom conditions plus breakpoints (`sm`, `md`, ...). */
|
|
898
|
+
resolveStyleObjectKeys() {
|
|
899
|
+
return [.../* @__PURE__ */ new Set([...this.spec.conditions.keys, ...this.spec.conditions.breakpoints])];
|
|
900
|
+
}
|
|
901
|
+
// `property` may be a canonical utility name or one of its shorthands.
|
|
902
|
+
resolveTokenCategoryForProperty(property) {
|
|
903
|
+
return this.#categoryByProperty.get(property);
|
|
904
|
+
}
|
|
905
|
+
// Populated for fixed-literal utilities (e.g. `scrollbar: 'visible' | 'hidden'`) instead of a token category.
|
|
906
|
+
resolveLiteralsForProperty(property) {
|
|
907
|
+
return this.#literalsByProperty.get(property);
|
|
908
|
+
}
|
|
909
|
+
resolveKeyframeNames(prefix = "") {
|
|
910
|
+
const names = this.spec.keyframes.keys;
|
|
911
|
+
return prefix ? names.filter((name) => name.startsWith(prefix)) : names;
|
|
912
|
+
}
|
|
913
|
+
/** Token category names actually present in this config (`colors`, `spacing`, ...). */
|
|
914
|
+
resolveTokenCategories(prefix = "") {
|
|
915
|
+
const names = Object.keys(this.spec.tokens.categories);
|
|
916
|
+
return prefix ? names.filter((name) => name.startsWith(prefix)) : names;
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
function buildCategoryByProperty(spec) {
|
|
920
|
+
const map = /* @__PURE__ */ new Map();
|
|
921
|
+
for (const [name, property] of Object.entries(spec.utilities.properties)) {
|
|
922
|
+
if (property.tokenCategory) map.set(name, property.tokenCategory);
|
|
923
|
+
}
|
|
924
|
+
for (const [shorthand, canonical] of Object.entries(spec.utilities.shorthands)) {
|
|
925
|
+
const category = map.get(canonical);
|
|
926
|
+
if (category) map.set(shorthand, category);
|
|
927
|
+
}
|
|
928
|
+
return map;
|
|
929
|
+
}
|
|
930
|
+
function buildLiteralsByProperty(spec) {
|
|
931
|
+
const map = /* @__PURE__ */ new Map();
|
|
932
|
+
for (const [name, property] of Object.entries(spec.utilities.properties)) {
|
|
933
|
+
if (property.literals.length > 0) map.set(name, property.literals);
|
|
934
|
+
}
|
|
935
|
+
for (const [shorthand, canonical] of Object.entries(spec.utilities.shorthands)) {
|
|
936
|
+
const literals = map.get(canonical);
|
|
937
|
+
if (literals) map.set(shorthand, literals);
|
|
938
|
+
}
|
|
939
|
+
return map;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/tooling/config-tokens.ts
|
|
943
|
+
var TOKEN_REF_PATTERN = /\{([a-zA-Z0-9_.]+)\}/g;
|
|
944
|
+
function findConfigTokenRefs(text) {
|
|
945
|
+
const refs = [];
|
|
946
|
+
for (const match of text.matchAll(TOKEN_REF_PATTERN)) {
|
|
947
|
+
const start = match.index;
|
|
948
|
+
const path = match[1];
|
|
949
|
+
const pathStart = start + 1;
|
|
950
|
+
refs.push({ start, end: start + match[0].length, pathStart, pathEnd: pathStart + path.length, path });
|
|
951
|
+
}
|
|
952
|
+
return refs;
|
|
953
|
+
}
|
|
954
|
+
function findConfigTokenRefAt(text, position) {
|
|
955
|
+
return findConfigTokenRefs(text).find((ref) => position >= ref.start && position <= ref.end);
|
|
956
|
+
}
|
|
957
|
+
function completeConfigTokenPath(prefix, index) {
|
|
958
|
+
return index.resolveTokenPaths(prefix).filter((path) => index.resolveTokenDeprecation(path) === void 0);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/tooling/config-style-object.ts
|
|
962
|
+
var CSS_WIDE_KEYWORDS = ["inherit", "initial", "revert", "revert-layer", "unset"];
|
|
963
|
+
function completeConfigStyleObject(context, index) {
|
|
964
|
+
const activeProperty = context.propertyPath.find((segment) => isKnownUtilityProperty(segment, index));
|
|
965
|
+
if (context.cursorKind === "value") {
|
|
966
|
+
return activeProperty ? completeStyleValue(activeProperty, context.prefix, index) : [];
|
|
967
|
+
}
|
|
968
|
+
if (activeProperty) {
|
|
969
|
+
return completeConditionKey(context.existingKeys, context.prefix, index);
|
|
970
|
+
}
|
|
971
|
+
return completeStyleKey(context.existingKeys, context.prefix, index);
|
|
972
|
+
}
|
|
973
|
+
function completeStyleKey(existingKeys, prefix, index) {
|
|
974
|
+
const used = new Set(existingKeys);
|
|
975
|
+
const utilityNames = [
|
|
976
|
+
...Object.keys(index.spec.utilities.properties),
|
|
977
|
+
...Object.keys(index.spec.utilities.shorthands)
|
|
978
|
+
];
|
|
979
|
+
const utilities = utilityNames.filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "utility" }));
|
|
980
|
+
const conditions = index.resolveStyleObjectKeys().filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "condition" }));
|
|
981
|
+
return [...utilities, ...conditions];
|
|
982
|
+
}
|
|
983
|
+
function completeConditionKey(existingKeys, prefix, index) {
|
|
984
|
+
const used = new Set(existingKeys);
|
|
985
|
+
return index.resolveStyleObjectKeys().filter((name) => !used.has(name) && name.startsWith(prefix)).map((name) => ({ name, kind: "condition" }));
|
|
986
|
+
}
|
|
987
|
+
function completeStyleValue(property, prefix, index) {
|
|
988
|
+
if (!isKnownUtilityProperty(property, index)) return [];
|
|
989
|
+
const entries = resolvePropertyValues(property, prefix, index);
|
|
990
|
+
const keywords = CSS_WIDE_KEYWORDS.filter((keyword) => keyword.startsWith(prefix)).map((name) => ({
|
|
991
|
+
name,
|
|
992
|
+
kind: "keyword"
|
|
993
|
+
}));
|
|
994
|
+
return [...entries, ...keywords];
|
|
995
|
+
}
|
|
996
|
+
function resolvePropertyValues(property, prefix, index) {
|
|
997
|
+
const category = index.resolveTokenCategoryForProperty(property);
|
|
998
|
+
if (category === "keyframes") {
|
|
999
|
+
return index.resolveKeyframeNames(prefix).map((name) => ({ name, kind: "keyframe" }));
|
|
1000
|
+
}
|
|
1001
|
+
if (category) {
|
|
1002
|
+
const categoryPrefix = `${category}.`;
|
|
1003
|
+
return index.resolveTokenPaths(`${categoryPrefix}${prefix}`).filter((path) => index.resolveTokenDeprecation(path) === void 0).map((path) => ({ name: path.slice(categoryPrefix.length), kind: "token" }));
|
|
1004
|
+
}
|
|
1005
|
+
const literals = index.resolveLiteralsForProperty(property);
|
|
1006
|
+
if (literals) {
|
|
1007
|
+
return literals.filter((value) => value.startsWith(prefix)).map((value) => ({ name: value, kind: "literal" }));
|
|
1008
|
+
}
|
|
1009
|
+
return [];
|
|
1010
|
+
}
|
|
1011
|
+
function isKnownUtilityProperty(property, index) {
|
|
1012
|
+
return property in index.spec.utilities.properties || property in index.spec.utilities.shorthands;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// src/tooling/config-semantic-tokens.ts
|
|
1016
|
+
function completeSemanticTokenObject(context, index) {
|
|
1017
|
+
const used = new Set(context.existingKeys);
|
|
1018
|
+
if (context.cursorKind === "category") {
|
|
1019
|
+
return index.resolveTokenCategories(context.prefix).filter((name) => !used.has(name)).map((name) => ({ name, kind: "category" }));
|
|
1020
|
+
}
|
|
1021
|
+
return ["base", ...index.resolveStyleObjectKeys()].filter((name) => !used.has(name) && name.startsWith(context.prefix)).map((name) => ({ name, kind: "condition" }));
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// src/tooling/module-resolution.ts
|
|
1025
|
+
import { outdirBasename } from "@pandacss/compiler-shared";
|
|
1026
|
+
function resolveModuleTarget(specifier, importMap, options) {
|
|
1027
|
+
const outdirBase = outdirBasename(options.outdir);
|
|
1028
|
+
const roots = Object.values(importMap).flat();
|
|
1029
|
+
const usesBareOutdirConvention = roots.some((root) => root === outdirBase || root.startsWith(`${outdirBase}/`));
|
|
1030
|
+
if (!usesBareOutdirConvention) return void 0;
|
|
1031
|
+
if (specifier !== outdirBase && !specifier.startsWith(`${outdirBase}/`)) return void 0;
|
|
1032
|
+
return `./${options.outdir}${specifier.slice(outdirBase.length)}`;
|
|
1033
|
+
}
|
|
1034
|
+
export {
|
|
1035
|
+
FileInspector,
|
|
1036
|
+
ProjectRegistry,
|
|
1037
|
+
SpecIndex,
|
|
1038
|
+
completeConfigStyleObject,
|
|
1039
|
+
completeConfigTokenPath,
|
|
1040
|
+
completeSemanticTokenObject,
|
|
1041
|
+
createProjectFromConfig,
|
|
1042
|
+
createProjectFromLoadedConfig,
|
|
1043
|
+
findConfigTokenRefAt,
|
|
1044
|
+
findConfigTokenRefs,
|
|
1045
|
+
resolveModuleTarget,
|
|
1046
|
+
sourceCacheKey
|
|
1047
|
+
};
|