@whzxc/agent-design-gallery 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whzxc/agent-design-gallery",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Local TSX design toolkit and SVG viewer",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,5 +1,6 @@
1
1
  import { parentPort } from 'node:worker_threads';
2
2
  import { createHash } from 'node:crypto';
3
+ import { realpathSync } from 'node:fs';
3
4
  import path from 'node:path';
4
5
  import { buildSource } from './build.mjs';
5
6
  import { createArchBrowser } from './arch-browser.mjs';
@@ -20,9 +21,12 @@ parentPort.on('message', async ({ id, config, name, type }) => {
20
21
  const build = async browser => config.overlay && name.endsWith('.mmd') ? (await import('./arch-overlay.mjs')).buildOverlay(config,path.join(config.root,name),{base:config.overlay,browser,snapshot}) : buildSource(config, path.join(name.endsWith('.mmd')?config.root:config.design, name), { write: false, snapshot, browser, allowLegacy: config.allowLegacy ?? true });
21
22
  const built = await (name.endsWith('.mmd') ? archBrowser.run(build) : build());
22
23
  const frames = JSON.parse(JSON.stringify(built.frames.map(({ document, ...frame }) => frame)));
23
- const dependencies = [...new Set(built.dependencies.map(file => path.relative(config.design, file).split(path.sep).join('/')))].sort();
24
+ const designRoot = realpathSync(config.design);
25
+ const dependencies = [...new Set(built.dependencies.map(file => path.relative(file.startsWith(designRoot + path.sep) ? designRoot : config.design, file).split(path.sep).join('/')))].sort();
24
26
  const dependencyHashes = Object.fromEntries(dependencies.map(name => {
25
- const bytes=snapshot.get(path.join(config.design,name));
27
+ const designFile = path.join(designRoot, name), rawFile = path.join(config.design, name);
28
+ const bytes = snapshot.has(designFile) ? snapshot.get(designFile) : snapshot.get(rawFile);
29
+ if (bytes === undefined) throw Error(`Missing snapshot bytes for dependency ${name}`);
26
30
  return [name,createHash('sha256').update(bytes===null?'missing\0':'present\0').update(bytes??'').digest('hex')];
27
31
  }));
28
32
  if (!shuttingDown) parentPort.postMessage({ id, result: { ...(built.observationDynamic?{observationDynamic:true}:{}), frames, parts: built.parts ?? [], css: built.css,
@@ -101,7 +101,7 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
101
101
  return encoding ? value.toString(encoding) : value;
102
102
  };
103
103
  file = realpathSync(file);
104
- const base = realpathSync(config.design), dependencies = new Set([path.join(base, 'tokens.css')]);
104
+ const base = realpathSync(config.design), dependencies = new Set();
105
105
  const imports = new Set(), sources = sourceDirectories(config);
106
106
  const result = await build({ entryPoints: [file], bundle: true, write: false, format: 'esm', platform: 'node', jsx: 'automatic', jsxImportSource: 'adg', jsxDev: true, metafile: true, logLevel: 'silent', plugins: [{ name: 'adg-sources', setup(api) {
107
107
  api.onResolve({ filter: /.*/ }, args => {
@@ -172,7 +172,9 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
172
172
  try { validateFrame(frame); if (names.has(frame.name)) throw Error(`Duplicate frame name ${frame.name}`); names.add(frame.name); }
173
173
  catch(error) { throw Error(`${relative(config,file)}: ${frame?.name ?? '-'}: ${error.message}`); }
174
174
  }
175
- const tokenSource = read(path.join(base,'tokens.css'),'utf8'), tokens = snapshot ? parseTokens(tokenSource) : loadTokens(config);
175
+ const tokenFile = path.join(base, 'tokens.css');
176
+ dependencies.add(tokenFile);
177
+ const tokenSource = read(tokenFile,'utf8'), tokens = snapshot ? parseTokens(tokenSource) : loadTokens(config);
176
178
  const compiler = await compile(`${readFileSync(path.join(tailwind,'theme.css'),'utf8')}\n${themeCss(tokens)}\n${readFileSync(path.join(tailwind,'preflight.css'),'utf8')}\n@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));\n@tailwind utilities;`);
177
179
  const classes = [...new Set(frames.flatMap(f => [...f.html.matchAll(/\bclass="([^"]*)"/g)].flatMap(m => m[1].split(/\s+/))))];
178
180
  const utilities = compiler.build(classes);