@fragments-sdk/cli 0.7.14 → 0.7.15
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/dist/bin.js +7 -7
- package/dist/{chunk-CRTN6BIW.js → chunk-QLTLLQBI.js} +2 -2
- package/dist/{chunk-TQOGBAOZ.js → chunk-WLXFE6XW.js} +91 -2
- package/dist/chunk-WLXFE6XW.js.map +1 -0
- package/dist/core/index.d.ts +44 -3
- package/dist/core/index.js +11 -3
- package/dist/{defineFragment-C6PFzZyo.d.ts → defineFragment-BI9KoPrs.d.ts} +1 -1
- package/dist/{generate-ZPERYZLF.js → generate-ICIPKCKV.js} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{init-GID2DXB3.js → init-V42FFMUJ.js} +3 -3
- package/dist/mcp-bin.js +2 -2
- package/dist/{scan-BSMLGBX4.js → scan-X3DI2X5G.js} +2 -2
- package/dist/{service-QACVPR37.js → service-JEWWTSKI.js} +2 -2
- package/dist/{static-viewer-2RQD5QLR.js → static-viewer-JIWCYKVK.js} +2 -2
- package/dist/{tokens-A3BZIQPB.js → tokens-K2AGUUOJ.js} +2 -2
- package/dist/{viewer-CNLZQUFO.js → viewer-7I4WGVU3.js} +60 -12
- package/dist/viewer-7I4WGVU3.js.map +1 -0
- package/package.json +1 -1
- package/src/core/__tests__/preview-runtime.test.tsx +111 -0
- package/src/core/index.ts +13 -0
- package/src/core/preview-runtime.tsx +144 -0
- package/src/viewer/components/App.tsx +3 -3
- package/src/viewer/components/FragmentRenderer.tsx +61 -0
- package/src/viewer/components/IsolatedPreviewFrame.tsx +10 -8
- package/src/viewer/components/PreviewFrameHost.tsx +27 -60
- package/src/viewer/components/SkeletonLoader.tsx +114 -125
- package/src/viewer/components/VariantMatrix.tsx +3 -3
- package/src/viewer/entry.tsx +26 -2
- package/src/viewer/index.html +1 -1
- package/src/viewer/public/favicon.ico +0 -0
- package/src/viewer/server.ts +1 -0
- package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +19 -0
- package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +1 -1
- package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +69 -104
- package/src/viewer/vite-plugin.ts +58 -1
- package/dist/chunk-TQOGBAOZ.js.map +0 -1
- package/dist/viewer-CNLZQUFO.js.map +0 -1
- package/src/viewer/components/StoryRenderer.tsx +0 -121
- /package/dist/{chunk-CRTN6BIW.js.map → chunk-QLTLLQBI.js.map} +0 -0
- /package/dist/{generate-ZPERYZLF.js.map → generate-ICIPKCKV.js.map} +0 -0
- /package/dist/{init-GID2DXB3.js.map → init-V42FFMUJ.js.map} +0 -0
- /package/dist/{scan-BSMLGBX4.js.map → scan-X3DI2X5G.js.map} +0 -0
- /package/dist/{service-QACVPR37.js.map → service-JEWWTSKI.js.map} +0 -0
- /package/dist/{static-viewer-2RQD5QLR.js.map → static-viewer-JIWCYKVK.js.map} +0 -0
- /package/dist/{tokens-A3BZIQPB.js.map → tokens-K2AGUUOJ.js.map} +0 -0
|
@@ -98,7 +98,7 @@ import {
|
|
|
98
98
|
sleep,
|
|
99
99
|
summarizePatternsForPrompt
|
|
100
100
|
} from "./chunk-YMPGYEWK.js";
|
|
101
|
-
import "./chunk-
|
|
101
|
+
import "./chunk-WLXFE6XW.js";
|
|
102
102
|
import "./chunk-7CRC46HV.js";
|
|
103
103
|
import {
|
|
104
104
|
BRAND,
|
|
@@ -207,4 +207,4 @@ export {
|
|
|
207
207
|
sleep,
|
|
208
208
|
summarizePatternsForPrompt
|
|
209
209
|
};
|
|
210
|
-
//# sourceMappingURL=service-
|
|
210
|
+
//# sourceMappingURL=service-JEWWTSKI.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
generateStaticViewer,
|
|
4
4
|
generateViewerFromJson
|
|
5
5
|
} from "./chunk-TOIE7VXF.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-WLXFE6XW.js";
|
|
7
7
|
import "./chunk-7CRC46HV.js";
|
|
8
8
|
import "./chunk-EKLMXTWU.js";
|
|
9
9
|
import "./chunk-Z7EY4VHE.js";
|
|
@@ -11,4 +11,4 @@ export {
|
|
|
11
11
|
generateStaticViewer,
|
|
12
12
|
generateViewerFromJson
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=static-viewer-
|
|
14
|
+
//# sourceMappingURL=static-viewer-JIWCYKVK.js.map
|
|
@@ -6,7 +6,7 @@ import "./chunk-AWYCDRPG.js";
|
|
|
6
6
|
import {
|
|
7
7
|
parseTokenFiles
|
|
8
8
|
} from "./chunk-YMPGYEWK.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-WLXFE6XW.js";
|
|
10
10
|
import "./chunk-7CRC46HV.js";
|
|
11
11
|
import {
|
|
12
12
|
BRAND
|
|
@@ -173,4 +173,4 @@ export {
|
|
|
173
173
|
tokens_default as default,
|
|
174
174
|
tokens
|
|
175
175
|
};
|
|
176
|
-
//# sourceMappingURL=tokens-
|
|
176
|
+
//# sourceMappingURL=tokens-K2AGUUOJ.js.map
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
findPreviewConfigPath,
|
|
4
4
|
findStorybookDir,
|
|
5
5
|
generatePreviewModule,
|
|
6
|
-
loadConfig
|
|
6
|
+
loadConfig,
|
|
7
|
+
parseFragmentFile
|
|
7
8
|
} from "./chunk-57OW43NL.js";
|
|
8
9
|
import {
|
|
9
10
|
discoverFragmentFiles,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
} from "./chunk-AWYCDRPG.js";
|
|
12
13
|
import {
|
|
13
14
|
generateContext
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-WLXFE6XW.js";
|
|
15
16
|
import "./chunk-7CRC46HV.js";
|
|
16
17
|
import {
|
|
17
18
|
BRAND
|
|
@@ -360,7 +361,7 @@ var sharedRenderPool = null;
|
|
|
360
361
|
var browserPoolModule = null;
|
|
361
362
|
async function getSharedRenderPool() {
|
|
362
363
|
if (!browserPoolModule) {
|
|
363
|
-
browserPoolModule = await import("./service-
|
|
364
|
+
browserPoolModule = await import("./service-JEWWTSKI.js");
|
|
364
365
|
}
|
|
365
366
|
if (!sharedRenderPool) {
|
|
366
367
|
sharedRenderPool = new browserPoolModule.BrowserPool({
|
|
@@ -603,7 +604,7 @@ function fragmentsPlugin(options) {
|
|
|
603
604
|
const address = _server.httpServer?.address();
|
|
604
605
|
const port = typeof address === "object" && address ? address.port : 6006;
|
|
605
606
|
const renderViewport = viewport || { width: 800, height: 600 };
|
|
606
|
-
const { FigmaClient, bufferToBase64Url } = await import("./service-
|
|
607
|
+
const { FigmaClient, bufferToBase64Url } = await import("./service-JEWWTSKI.js");
|
|
607
608
|
const figmaClient = new FigmaClient({
|
|
608
609
|
accessToken: figmaToken
|
|
609
610
|
});
|
|
@@ -694,7 +695,7 @@ function fragmentsPlugin(options) {
|
|
|
694
695
|
);
|
|
695
696
|
return;
|
|
696
697
|
}
|
|
697
|
-
const { FigmaClient } = await import("./service-
|
|
698
|
+
const { FigmaClient } = await import("./service-JEWWTSKI.js");
|
|
698
699
|
const figmaClient = new FigmaClient({ accessToken: figmaToken });
|
|
699
700
|
const { fileKey, nodeId } = figmaClient.parseUrl(figmaUrl);
|
|
700
701
|
const figmaDesignProps = await figmaClient.getNodeProperties(
|
|
@@ -735,7 +736,7 @@ function fragmentsPlugin(options) {
|
|
|
735
736
|
}));
|
|
736
737
|
return;
|
|
737
738
|
}
|
|
738
|
-
const { getSharedTokenRegistry } = await import("./service-
|
|
739
|
+
const { getSharedTokenRegistry } = await import("./service-JEWWTSKI.js");
|
|
739
740
|
const registry = getSharedTokenRegistry();
|
|
740
741
|
if (!registry.isInitialized()) {
|
|
741
742
|
await registry.initialize(config.tokens, projectRoot);
|
|
@@ -795,7 +796,7 @@ function fragmentsPlugin(options) {
|
|
|
795
796
|
}));
|
|
796
797
|
return;
|
|
797
798
|
}
|
|
798
|
-
const { getSharedTokenRegistry } = await import("./service-
|
|
799
|
+
const { getSharedTokenRegistry } = await import("./service-JEWWTSKI.js");
|
|
799
800
|
const registry = getSharedTokenRegistry();
|
|
800
801
|
if (!registry.isInitialized()) {
|
|
801
802
|
await registry.initialize(config.tokens, projectRoot);
|
|
@@ -857,7 +858,7 @@ function fragmentsPlugin(options) {
|
|
|
857
858
|
res.end(JSON.stringify({ error: "Could not resolve fragment file path" }));
|
|
858
859
|
return;
|
|
859
860
|
}
|
|
860
|
-
const { getSharedTokenRegistry } = await import("./service-
|
|
861
|
+
const { getSharedTokenRegistry } = await import("./service-JEWWTSKI.js");
|
|
861
862
|
const registry = getSharedTokenRegistry();
|
|
862
863
|
if (!registry.isInitialized()) {
|
|
863
864
|
await registry.initialize(config.tokens, projectRoot);
|
|
@@ -1056,7 +1057,7 @@ function fragmentsPlugin(options) {
|
|
|
1056
1057
|
const {
|
|
1057
1058
|
getSharedTokenRegistry,
|
|
1058
1059
|
generateTokenPatches
|
|
1059
|
-
} = await import("./service-
|
|
1060
|
+
} = await import("./service-JEWWTSKI.js");
|
|
1060
1061
|
const registry = getSharedTokenRegistry();
|
|
1061
1062
|
if (!registry.isInitialized()) {
|
|
1062
1063
|
await registry.initialize(config.tokens, projectRoot);
|
|
@@ -1424,6 +1425,28 @@ async function extractDependenciesFromSource(absolutePath) {
|
|
|
1424
1425
|
}
|
|
1425
1426
|
}
|
|
1426
1427
|
async function generateFragmentsModule(fragmentFiles, config, previewConfigPath) {
|
|
1428
|
+
const authoredVariantCodeCache = /* @__PURE__ */ new Map();
|
|
1429
|
+
async function loadAuthoredVariantCode(fragmentFilePath) {
|
|
1430
|
+
if (authoredVariantCodeCache.has(fragmentFilePath)) {
|
|
1431
|
+
return authoredVariantCodeCache.get(fragmentFilePath);
|
|
1432
|
+
}
|
|
1433
|
+
try {
|
|
1434
|
+
const source = await readFile(fragmentFilePath, "utf-8");
|
|
1435
|
+
const parsed = parseFragmentFile(source, fragmentFilePath);
|
|
1436
|
+
const variantCodeByName = {};
|
|
1437
|
+
for (const variant of parsed.variants) {
|
|
1438
|
+
if (typeof variant.code !== "string") continue;
|
|
1439
|
+
const normalized = variant.code.trim();
|
|
1440
|
+
if (normalized.length === 0) continue;
|
|
1441
|
+
variantCodeByName[variant.name] = normalized;
|
|
1442
|
+
}
|
|
1443
|
+
authoredVariantCodeCache.set(fragmentFilePath, variantCodeByName);
|
|
1444
|
+
return variantCodeByName;
|
|
1445
|
+
} catch {
|
|
1446
|
+
authoredVariantCodeCache.set(fragmentFilePath, {});
|
|
1447
|
+
return {};
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1427
1450
|
const filesByBasePath = /* @__PURE__ */ new Map();
|
|
1428
1451
|
for (const file of fragmentFiles) {
|
|
1429
1452
|
const basePath = getBaseComponentPath(file.relativePath);
|
|
@@ -1442,6 +1465,8 @@ async function generateFragmentsModule(fragmentFiles, config, previewConfigPath)
|
|
|
1442
1465
|
if (!primaryFile) return null;
|
|
1443
1466
|
const isStory = !!files.storyFile;
|
|
1444
1467
|
const metadataPath = files.storyFile && files.fragmentFile ? files.fragmentFile.absolutePath : null;
|
|
1468
|
+
const codeSourceFile = files.fragmentFile && files.fragmentFile.absolutePath ? files.fragmentFile.absolutePath : !isStory ? primaryFile.absolutePath : null;
|
|
1469
|
+
const authoredVariantCode = codeSourceFile ? await loadAuthoredVariantCode(codeSourceFile) : {};
|
|
1445
1470
|
const componentName = extractComponentName(primaryFile.relativePath);
|
|
1446
1471
|
const fragmentSource = files.fragmentFile || primaryFile;
|
|
1447
1472
|
const dependencies = await extractDependenciesFromSource(fragmentSource.absolutePath);
|
|
@@ -1451,7 +1476,8 @@ async function generateFragmentsModule(fragmentFiles, config, previewConfigPath)
|
|
|
1451
1476
|
componentName: ${JSON.stringify(componentName)},
|
|
1452
1477
|
dependencies: ${JSON.stringify(dependencies)},
|
|
1453
1478
|
loader: () => import("${primaryFile.absolutePath}"),
|
|
1454
|
-
metadataLoader: ${metadataPath ? `() => import("${metadataPath}")` : "null"}
|
|
1479
|
+
metadataLoader: ${metadataPath ? `() => import("${metadataPath}")` : "null"},
|
|
1480
|
+
authoredVariantCode: ${JSON.stringify(authoredVariantCode)}
|
|
1455
1481
|
}`;
|
|
1456
1482
|
})
|
|
1457
1483
|
);
|
|
@@ -1520,6 +1546,20 @@ function mergeMetadata(fragment, metadataModule) {
|
|
|
1520
1546
|
return fragment;
|
|
1521
1547
|
}
|
|
1522
1548
|
|
|
1549
|
+
function mergeAuthoredVariantCode(fragment, authoredVariantCode) {
|
|
1550
|
+
if (!fragment?.variants || !authoredVariantCode) return fragment;
|
|
1551
|
+
|
|
1552
|
+
for (const variant of fragment.variants) {
|
|
1553
|
+
if (!variant || variant.code) continue;
|
|
1554
|
+
const code = authoredVariantCode[variant.name];
|
|
1555
|
+
if (typeof code === "string" && code.trim().length > 0) {
|
|
1556
|
+
variant.code = code;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
return fragment;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1523
1563
|
// Load all fragments (for initial render)
|
|
1524
1564
|
// Gracefully handles individual failures - one bad story won't break all fragments
|
|
1525
1565
|
export async function loadAllFragments() {
|
|
@@ -1557,6 +1597,8 @@ export async function loadAllFragments() {
|
|
|
1557
1597
|
}
|
|
1558
1598
|
}
|
|
1559
1599
|
|
|
1600
|
+
fragment = mergeAuthoredVariantCode(fragment, loader.authoredVariantCode);
|
|
1601
|
+
|
|
1560
1602
|
loadedFragments.set(loader.path, fragment);
|
|
1561
1603
|
return { path: loader.path, fragment };
|
|
1562
1604
|
} catch (error) {
|
|
@@ -1614,6 +1656,10 @@ export async function loadFragment(path) {
|
|
|
1614
1656
|
}
|
|
1615
1657
|
}
|
|
1616
1658
|
|
|
1659
|
+
if (fragment) {
|
|
1660
|
+
fragment = mergeAuthoredVariantCode(fragment, loader.authoredVariantCode);
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1617
1663
|
if (fragment) {
|
|
1618
1664
|
loadedFragments.set(path, fragment);
|
|
1619
1665
|
}
|
|
@@ -1995,7 +2041,7 @@ async function loadFullFragmentForCompare(_server, _fragmentFiles, componentName
|
|
|
1995
2041
|
}
|
|
1996
2042
|
}
|
|
1997
2043
|
async function compareImages(image1Base64, image2Base64, threshold) {
|
|
1998
|
-
const { DiffEngine, base64UrlToBuffer, bufferToBase64Url } = await import("./service-
|
|
2044
|
+
const { DiffEngine, base64UrlToBuffer, bufferToBase64Url } = await import("./service-JEWWTSKI.js");
|
|
1999
2045
|
const { PNG } = await import("pngjs");
|
|
2000
2046
|
const buffer1 = base64UrlToBuffer(image1Base64);
|
|
2001
2047
|
const buffer2 = base64UrlToBuffer(image2Base64);
|
|
@@ -2234,6 +2280,8 @@ async function createDevServer(options = {}) {
|
|
|
2234
2280
|
// Don't load config again
|
|
2235
2281
|
root: projectRoot,
|
|
2236
2282
|
// Run from PROJECT root
|
|
2283
|
+
publicDir: resolve2(viewerRoot, "public"),
|
|
2284
|
+
// Serve static assets (favicon) from viewer
|
|
2237
2285
|
base: "/",
|
|
2238
2286
|
server: {
|
|
2239
2287
|
port,
|
|
@@ -2339,4 +2387,4 @@ export {
|
|
|
2339
2387
|
createDevServer,
|
|
2340
2388
|
fragmentsPlugin
|
|
2341
2389
|
};
|
|
2342
|
-
//# sourceMappingURL=viewer-
|
|
2390
|
+
//# sourceMappingURL=viewer-7I4WGVU3.js.map
|