storybook-addon-designbook 0.7.0 → 0.8.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/dist/cli.js +78 -141
- package/dist/index.js +19 -4
- package/dist/manager.js +24 -13
- package/dist/preset.js +54 -96
- package/dist/preview.js +19 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5808,47 +5808,6 @@ var init_scene_metadata = __esm({
|
|
|
5808
5808
|
"src/renderer/scene-metadata.ts"() {
|
|
5809
5809
|
}
|
|
5810
5810
|
});
|
|
5811
|
-
function normalizeUrl(url2) {
|
|
5812
|
-
return url2.toLowerCase().replace(/\/+$/, "");
|
|
5813
|
-
}
|
|
5814
|
-
function hashReferenceUrl(url2) {
|
|
5815
|
-
const normalized = normalizeUrl(url2);
|
|
5816
|
-
return createHash("sha256").update(normalized).digest("hex").slice(0, 12);
|
|
5817
|
-
}
|
|
5818
|
-
var referenceFolderResolver;
|
|
5819
|
-
var init_reference_folder = __esm({
|
|
5820
|
-
"src/resolvers/reference-folder.ts"() {
|
|
5821
|
-
referenceFolderResolver = {
|
|
5822
|
-
name: "reference_folder",
|
|
5823
|
-
resolve(_input, config, context2) {
|
|
5824
|
-
const fromParam = config.from;
|
|
5825
|
-
if (!fromParam) {
|
|
5826
|
-
return {
|
|
5827
|
-
resolved: false,
|
|
5828
|
-
input: "",
|
|
5829
|
-
error: 'Missing "from" field in resolver config'
|
|
5830
|
-
};
|
|
5831
|
-
}
|
|
5832
|
-
const url2 = context2.params[fromParam];
|
|
5833
|
-
if (typeof url2 !== "string" || url2 === "") {
|
|
5834
|
-
return {
|
|
5835
|
-
resolved: false,
|
|
5836
|
-
input: "",
|
|
5837
|
-
error: `Parameter "${fromParam}" is missing or empty`
|
|
5838
|
-
};
|
|
5839
|
-
}
|
|
5840
|
-
const hash = hashReferenceUrl(url2);
|
|
5841
|
-
const folder = resolve(context2.config.data, "references", hash);
|
|
5842
|
-
mkdirSync(folder, { recursive: true });
|
|
5843
|
-
return {
|
|
5844
|
-
resolved: true,
|
|
5845
|
-
value: folder,
|
|
5846
|
-
input: url2
|
|
5847
|
-
};
|
|
5848
|
-
}
|
|
5849
|
-
};
|
|
5850
|
-
}
|
|
5851
|
-
});
|
|
5852
5811
|
function sanitize(str) {
|
|
5853
5812
|
return str.toLowerCase().replace(/[ '–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>{}[\]\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
5854
5813
|
}
|
|
@@ -5896,12 +5855,10 @@ var init_story_entity = __esm({
|
|
|
5896
5855
|
"src/story-entity.ts"() {
|
|
5897
5856
|
init_esm4();
|
|
5898
5857
|
init_scene_metadata();
|
|
5899
|
-
init_reference_folder();
|
|
5900
5858
|
StoryMeta = class _StoryMeta {
|
|
5901
5859
|
storyId;
|
|
5902
5860
|
section;
|
|
5903
5861
|
storyDir;
|
|
5904
|
-
reference;
|
|
5905
5862
|
_meta;
|
|
5906
5863
|
_metaPath;
|
|
5907
5864
|
constructor(storyId, section, storyDir, meta, metaPath) {
|
|
@@ -5910,12 +5867,6 @@ var init_story_entity = __esm({
|
|
|
5910
5867
|
this.storyDir = storyDir;
|
|
5911
5868
|
this._meta = meta;
|
|
5912
5869
|
this._metaPath = metaPath;
|
|
5913
|
-
this.reference = {
|
|
5914
|
-
url: meta.reference?.source?.url,
|
|
5915
|
-
origin: meta.reference?.source?.origin,
|
|
5916
|
-
screenId: meta.reference?.source?.screenId,
|
|
5917
|
-
hasMarkup: meta.reference?.source?.hasMarkup
|
|
5918
|
-
};
|
|
5919
5870
|
}
|
|
5920
5871
|
get data() {
|
|
5921
5872
|
return this._meta;
|
|
@@ -5977,27 +5928,13 @@ var init_story_entity = __esm({
|
|
|
5977
5928
|
mkdirSync(storyDir, { recursive: true });
|
|
5978
5929
|
const metaPath = resolve(storyDir, "meta.yml");
|
|
5979
5930
|
const section = _StoryMeta._deriveSection(storyId);
|
|
5980
|
-
const tmpStory = new _StoryMeta(storyId, section, storyDir, {}, metaPath);
|
|
5981
|
-
const breakpoints2 = tmpStory._getBreakpoints(config);
|
|
5982
|
-
const regions = tmpStory._deriveRegions(config);
|
|
5983
5931
|
const meta = {};
|
|
5984
|
-
if (breakpoints2.length > 0) {
|
|
5985
|
-
meta.reference = { breakpoints: {} };
|
|
5986
|
-
for (const bp2 of breakpoints2) {
|
|
5987
|
-
const regionMap = {};
|
|
5988
|
-
for (const region of regions) {
|
|
5989
|
-
regionMap[region.name] = { selector: region.selector };
|
|
5990
|
-
}
|
|
5991
|
-
meta.reference.breakpoints[bp2] = { threshold: 3, regions: regionMap };
|
|
5992
|
-
}
|
|
5993
|
-
}
|
|
5994
5932
|
writeFileSync(metaPath, dump(meta, { lineWidth: -1 }), "utf-8");
|
|
5995
5933
|
return new _StoryMeta(storyId, section, storyDir, meta, metaPath);
|
|
5996
5934
|
}
|
|
5997
5935
|
/**
|
|
5998
5936
|
* Create or load a story by scene reference. Creates the story directory if
|
|
5999
|
-
* missing, optionally seeds meta.yml with provided data
|
|
6000
|
-
* breakpoints/regions from design tokens.
|
|
5937
|
+
* missing, optionally seeds meta.yml with provided data.
|
|
6001
5938
|
*/
|
|
6002
5939
|
static createByScene(config, sceneRef, metaSeed) {
|
|
6003
5940
|
const { scenes, allScenes } = resolveScene(config.data, sceneRef);
|
|
@@ -6012,31 +5949,11 @@ var init_story_entity = __esm({
|
|
|
6012
5949
|
const content = readFileSync(metaPath, "utf-8");
|
|
6013
5950
|
meta = load(content) ?? {};
|
|
6014
5951
|
}
|
|
6015
|
-
if (metaSeed?.reference) {
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
if (metaSeed.reference.breakpoints) {
|
|
6021
|
-
meta.reference.breakpoints = { ...meta.reference.breakpoints, ...metaSeed.reference.breakpoints };
|
|
6022
|
-
}
|
|
6023
|
-
}
|
|
6024
|
-
if (!meta.reference?.breakpoints || Object.keys(meta.reference.breakpoints).length === 0) {
|
|
6025
|
-
const section = _StoryMeta._deriveSection(storyId);
|
|
6026
|
-
const tmpStory = new _StoryMeta(storyId, section, storyDir, meta, metaPath);
|
|
6027
|
-
const breakpoints2 = tmpStory._getBreakpoints(config);
|
|
6028
|
-
const regions = tmpStory._deriveRegions(config);
|
|
6029
|
-
if (breakpoints2.length > 0) {
|
|
6030
|
-
if (!meta.reference) meta.reference = {};
|
|
6031
|
-
meta.reference.breakpoints = {};
|
|
6032
|
-
for (const bp2 of breakpoints2) {
|
|
6033
|
-
const regionMap = {};
|
|
6034
|
-
for (const region of regions) {
|
|
6035
|
-
regionMap[region.name] = { selector: region.selector };
|
|
6036
|
-
}
|
|
6037
|
-
meta.reference.breakpoints[bp2] = { threshold: 3, regions: regionMap };
|
|
6038
|
-
}
|
|
6039
|
-
}
|
|
5952
|
+
if (metaSeed?.reference !== void 0) {
|
|
5953
|
+
meta.reference = metaSeed.reference;
|
|
5954
|
+
}
|
|
5955
|
+
if (metaSeed?.elements !== void 0) {
|
|
5956
|
+
meta.elements = metaSeed.elements;
|
|
6040
5957
|
}
|
|
6041
5958
|
writeFileSync(metaPath, dump(meta, { lineWidth: -1 }), "utf-8");
|
|
6042
5959
|
return _StoryMeta.load(config, storyId);
|
|
@@ -6045,26 +5962,19 @@ var init_story_entity = __esm({
|
|
|
6045
5962
|
// Serialization
|
|
6046
5963
|
// -------------------------------------------------------------------------
|
|
6047
5964
|
toJSON() {
|
|
6048
|
-
const
|
|
6049
|
-
const
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
selector: region.selector ?? "",
|
|
6055
|
-
reference_selector: region.reference_selector ?? ""
|
|
6056
|
-
};
|
|
6057
|
-
}
|
|
6058
|
-
breakpoints2[bp2] = { threshold: cfg.threshold ?? null, regions };
|
|
6059
|
-
}
|
|
6060
|
-
const referenceDir = this.reference.url ? `references/${hashReferenceUrl(this.reference.url)}` : null;
|
|
5965
|
+
const reference = this._meta.reference ?? null;
|
|
5966
|
+
const referenceDir = reference ? `references/${reference}` : null;
|
|
5967
|
+
const elements = (this._meta.elements ?? []).map((e) => ({
|
|
5968
|
+
id: e.id,
|
|
5969
|
+
selector: e.selector ?? ""
|
|
5970
|
+
}));
|
|
6061
5971
|
return {
|
|
6062
5972
|
storyId: this.storyId,
|
|
6063
5973
|
section: this.section,
|
|
6064
5974
|
storyDir: this.storyDir,
|
|
6065
|
-
reference
|
|
5975
|
+
reference,
|
|
6066
5976
|
referenceDir,
|
|
6067
|
-
|
|
5977
|
+
elements
|
|
6068
5978
|
};
|
|
6069
5979
|
}
|
|
6070
5980
|
// -------------------------------------------------------------------------
|
|
@@ -6089,18 +5999,6 @@ var init_story_entity = __esm({
|
|
|
6089
5999
|
const idx = storyId.indexOf("--");
|
|
6090
6000
|
return idx > 0 ? storyId.substring(0, idx) : storyId;
|
|
6091
6001
|
}
|
|
6092
|
-
_getBreakpoints(config) {
|
|
6093
|
-
const tokensPath = resolve(config.data, "design-system", "design-tokens.yml");
|
|
6094
|
-
if (!existsSync(tokensPath)) return [];
|
|
6095
|
-
const content = readFileSync(tokensPath, "utf-8");
|
|
6096
|
-
const tokens = load(content);
|
|
6097
|
-
const bpObj = tokens.breakpoints ?? tokens.semantic?.breakpoints;
|
|
6098
|
-
if (!bpObj) return [];
|
|
6099
|
-
return Object.keys(bpObj).filter((k) => !k.startsWith("$"));
|
|
6100
|
-
}
|
|
6101
|
-
_deriveRegions(_config) {
|
|
6102
|
-
return [{ name: "full", selector: "" }];
|
|
6103
|
-
}
|
|
6104
6002
|
};
|
|
6105
6003
|
}
|
|
6106
6004
|
});
|
|
@@ -6290,34 +6188,54 @@ var init_story_url = __esm({
|
|
|
6290
6188
|
};
|
|
6291
6189
|
}
|
|
6292
6190
|
});
|
|
6293
|
-
function
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
const meta = story.data;
|
|
6300
|
-
const bps = meta.reference?.breakpoints;
|
|
6301
|
-
if (!bps) return null;
|
|
6302
|
-
const keys = Object.keys(bps).filter((k) => !k.startsWith("$"));
|
|
6303
|
-
return keys.length > 0 ? keys : null;
|
|
6191
|
+
function normalizeUrl(url2) {
|
|
6192
|
+
return url2.toLowerCase().replace(/\/+$/, "");
|
|
6193
|
+
}
|
|
6194
|
+
function hashReferenceUrl(url2) {
|
|
6195
|
+
const normalized = normalizeUrl(url2);
|
|
6196
|
+
return createHash("sha256").update(normalized).digest("hex").slice(0, 12);
|
|
6304
6197
|
}
|
|
6198
|
+
var referenceFolderResolver;
|
|
6199
|
+
var init_reference_folder = __esm({
|
|
6200
|
+
"src/resolvers/reference-folder.ts"() {
|
|
6201
|
+
referenceFolderResolver = {
|
|
6202
|
+
name: "reference_folder",
|
|
6203
|
+
resolve(_input, config, context2) {
|
|
6204
|
+
const fromParam = config.from;
|
|
6205
|
+
if (!fromParam) {
|
|
6206
|
+
return {
|
|
6207
|
+
resolved: false,
|
|
6208
|
+
input: "",
|
|
6209
|
+
error: 'Missing "from" field in resolver config'
|
|
6210
|
+
};
|
|
6211
|
+
}
|
|
6212
|
+
const url2 = context2.params[fromParam];
|
|
6213
|
+
if (typeof url2 !== "string" || url2 === "") {
|
|
6214
|
+
return {
|
|
6215
|
+
resolved: false,
|
|
6216
|
+
input: "",
|
|
6217
|
+
error: `Parameter "${fromParam}" is missing or empty`
|
|
6218
|
+
};
|
|
6219
|
+
}
|
|
6220
|
+
const hash = hashReferenceUrl(url2);
|
|
6221
|
+
const folder = resolve(context2.config.data, "references", hash);
|
|
6222
|
+
mkdirSync(folder, { recursive: true });
|
|
6223
|
+
return {
|
|
6224
|
+
resolved: true,
|
|
6225
|
+
value: folder,
|
|
6226
|
+
input: url2
|
|
6227
|
+
};
|
|
6228
|
+
}
|
|
6229
|
+
};
|
|
6230
|
+
}
|
|
6231
|
+
});
|
|
6305
6232
|
var TOKENS_PATH, breakpointsResolver;
|
|
6306
6233
|
var init_breakpoints = __esm({
|
|
6307
6234
|
"src/resolvers/breakpoints.ts"() {
|
|
6308
|
-
init_story_entity();
|
|
6309
6235
|
TOKENS_PATH = "design-system/design-tokens.yml";
|
|
6310
6236
|
breakpointsResolver = {
|
|
6311
6237
|
name: "breakpoints",
|
|
6312
|
-
resolve(_input,
|
|
6313
|
-
const metaBreakpoints = breakpointsFromMeta(context2, config);
|
|
6314
|
-
if (metaBreakpoints) {
|
|
6315
|
-
return {
|
|
6316
|
-
resolved: true,
|
|
6317
|
-
value: metaBreakpoints.join(","),
|
|
6318
|
-
input: ""
|
|
6319
|
-
};
|
|
6320
|
-
}
|
|
6238
|
+
resolve(_input, _config, context2) {
|
|
6321
6239
|
const tokensFile = join(context2.config.data, TOKENS_PATH);
|
|
6322
6240
|
if (!existsSync(tokensFile)) {
|
|
6323
6241
|
return {
|
|
@@ -7013,8 +6931,8 @@ function pickRegionLabel(params) {
|
|
|
7013
6931
|
if (segments[0] === "design-system") {
|
|
7014
6932
|
return "shell";
|
|
7015
6933
|
}
|
|
7016
|
-
const
|
|
7017
|
-
return
|
|
6934
|
+
const basename6 = segments[segments.length - 1] ?? "";
|
|
6935
|
+
return basename6.replace(/(\.[^./]+)+$/, "");
|
|
7018
6936
|
}
|
|
7019
6937
|
return "";
|
|
7020
6938
|
}
|
|
@@ -8277,6 +8195,20 @@ async function validateSceneBuild(file, config) {
|
|
|
8277
8195
|
if (!raw || !Array.isArray(raw.scenes) || raw.scenes.length === 0) {
|
|
8278
8196
|
return { file, type: "scene", valid: true, last_validated: ts, last_passed: ts };
|
|
8279
8197
|
}
|
|
8198
|
+
const RESERVED_SCENE_NAMES = /* @__PURE__ */ new Set(["overview"]);
|
|
8199
|
+
for (const scene of raw.scenes) {
|
|
8200
|
+
const name = typeof scene?.name === "string" ? scene.name.trim().toLowerCase() : "";
|
|
8201
|
+
if (RESERVED_SCENE_NAMES.has(name)) {
|
|
8202
|
+
return {
|
|
8203
|
+
file,
|
|
8204
|
+
type: "scene",
|
|
8205
|
+
valid: false,
|
|
8206
|
+
error: `Scene name "${scene.name?.trim()}" is reserved \u2014 every scenes file already exports an "overview" story (the section overview page). A scene named "overview" collides with it and renders the section page instead of the scene. Rename the scene (e.g. to the section id or a descriptive label like "default").`,
|
|
8207
|
+
last_validated: ts,
|
|
8208
|
+
last_failed: ts
|
|
8209
|
+
};
|
|
8210
|
+
}
|
|
8211
|
+
}
|
|
8280
8212
|
const designbookDir = findDesignbookDir(file, config);
|
|
8281
8213
|
try {
|
|
8282
8214
|
await buildSceneModule(file, raw, designbookDir, {});
|
|
@@ -12090,6 +12022,12 @@ function buildInstructions(dataDir, workflowName, stageName) {
|
|
|
12090
12022
|
...stage.isolate ? { isolate: true } : {}
|
|
12091
12023
|
};
|
|
12092
12024
|
}
|
|
12025
|
+
function selectPrimaryResolvedStep(step, raw) {
|
|
12026
|
+
if (!raw) return void 0;
|
|
12027
|
+
if (!Array.isArray(raw)) return raw;
|
|
12028
|
+
const stepBasename = `${step.split(":").pop()}.md`;
|
|
12029
|
+
return raw.find((entry) => basename(entry.task_file) === stepBasename) ?? raw[0];
|
|
12030
|
+
}
|
|
12093
12031
|
async function runWorkflowCreate(opts, config) {
|
|
12094
12032
|
let initialParams = opts.params;
|
|
12095
12033
|
const configPath = findConfig();
|
|
@@ -12138,8 +12076,7 @@ async function runWorkflowCreate(opts, config) {
|
|
|
12138
12076
|
for (const [stageName, stageDef] of Object.entries(resolved.stages)) {
|
|
12139
12077
|
const step = stageDef.steps?.[0];
|
|
12140
12078
|
if (!step) continue;
|
|
12141
|
-
const
|
|
12142
|
-
const res = raw && !Array.isArray(raw) ? raw : void 0;
|
|
12079
|
+
const res = selectPrimaryResolvedStep(step, resolved.step_resolved[step]);
|
|
12143
12080
|
if (res) {
|
|
12144
12081
|
firstStepName = step;
|
|
12145
12082
|
firstStageName = stageName;
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,13 @@ var withRoundTrip = (storyFn, context) => {
|
|
|
44
44
|
});
|
|
45
45
|
return storyFn();
|
|
46
46
|
};
|
|
47
|
+
|
|
48
|
+
// src/visual-compare-path.ts
|
|
49
|
+
function referenceImagePath(referenceDir, breakpoint, region) {
|
|
50
|
+
return `/__designbook/load?path=${referenceDir}/${encodeURIComponent(breakpoint)}--${encodeURIComponent(region.name)}--${encodeURIComponent(region.state)}.png`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/withVisualCompare.ts
|
|
47
54
|
var storyCache = /* @__PURE__ */ new Map();
|
|
48
55
|
function fetchStory(storyId) {
|
|
49
56
|
const cached = storyCache.get(storyId);
|
|
@@ -53,9 +60,17 @@ function fetchStory(storyId) {
|
|
|
53
60
|
return promise;
|
|
54
61
|
}
|
|
55
62
|
function regionsFor(story, breakpoint) {
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
|
|
63
|
+
const refElements = story.referenceElements;
|
|
64
|
+
if (!refElements || refElements.length === 0) return [];
|
|
65
|
+
const storyElements = {};
|
|
66
|
+
for (const el of story.elements ?? []) {
|
|
67
|
+
storyElements[el.id] = el.selector;
|
|
68
|
+
}
|
|
69
|
+
return refElements.filter((el) => el.breakpoints.includes(breakpoint)).map((el) => ({
|
|
70
|
+
name: el.id,
|
|
71
|
+
selector: storyElements[el.id] ?? "",
|
|
72
|
+
state: el.states.find((state) => state.name === "rest")?.name ?? el.states[0]?.name ?? "rest"
|
|
73
|
+
}));
|
|
59
74
|
}
|
|
60
75
|
function applyOverlays(canvasElement, referenceDir, state, regions) {
|
|
61
76
|
if (!canvasElement.isConnected) return;
|
|
@@ -66,7 +81,7 @@ function applyOverlays(canvasElement, referenceDir, state, regions) {
|
|
|
66
81
|
const filtered = state.region ? regions.filter((r) => r.name === state.region) : regions;
|
|
67
82
|
const canvasRect = canvasElement.getBoundingClientRect();
|
|
68
83
|
for (const region of filtered) {
|
|
69
|
-
const src =
|
|
84
|
+
const src = referenceImagePath(referenceDir, state.breakpoint, region);
|
|
70
85
|
if (!region.selector) {
|
|
71
86
|
createOverlayImg(canvasElement, src, state.opacity, {
|
|
72
87
|
top: "0",
|
package/dist/manager.js
CHANGED
|
@@ -1892,21 +1892,32 @@ async function discoverBreakpoints(storyId) {
|
|
|
1892
1892
|
const res = await fetch(`/__designbook/story/${encodeURIComponent(storyId)}`);
|
|
1893
1893
|
if (!res.ok) return [];
|
|
1894
1894
|
const story = await res.json();
|
|
1895
|
-
const
|
|
1896
|
-
if (!
|
|
1895
|
+
const refElements = story.referenceElements;
|
|
1896
|
+
if (!refElements || refElements.length === 0) return [];
|
|
1897
|
+
const storyElements = {};
|
|
1898
|
+
for (const el of story.elements ?? []) {
|
|
1899
|
+
storyElements[el.id] = el.selector;
|
|
1900
|
+
}
|
|
1901
|
+
const bpMap = /* @__PURE__ */ new Map();
|
|
1902
|
+
for (const element of refElements) {
|
|
1903
|
+
for (const bp of element.breakpoints) {
|
|
1904
|
+
if (!bpMap.has(bp)) {
|
|
1905
|
+
bpMap.set(bp, []);
|
|
1906
|
+
}
|
|
1907
|
+
bpMap.get(bp).push({
|
|
1908
|
+
name: element.id,
|
|
1909
|
+
selector: storyElements[element.id] ?? "",
|
|
1910
|
+
diffPercent: null,
|
|
1911
|
+
threshold: null,
|
|
1912
|
+
pass: null,
|
|
1913
|
+
issues: []
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1897
1917
|
const breakpoints = [];
|
|
1898
|
-
for (const [name,
|
|
1918
|
+
for (const [name, regions] of bpMap.entries()) {
|
|
1899
1919
|
const width = KNOWN_BREAKPOINTS[name] ?? 0;
|
|
1900
|
-
|
|
1901
|
-
const regions = Object.entries(bp.regions ?? {}).map(([id, r]) => ({
|
|
1902
|
-
name: id,
|
|
1903
|
-
selector: r.selector ?? "",
|
|
1904
|
-
diffPercent: null,
|
|
1905
|
-
threshold,
|
|
1906
|
-
pass: null,
|
|
1907
|
-
issues: []
|
|
1908
|
-
}));
|
|
1909
|
-
breakpoints.push({ name, width, hasReference: true, threshold, regions });
|
|
1920
|
+
breakpoints.push({ name, width, hasReference: true, threshold: null, regions });
|
|
1910
1921
|
}
|
|
1911
1922
|
return breakpoints.sort((a, b) => a.width - b.width);
|
|
1912
1923
|
} catch {
|
package/dist/preset.js
CHANGED
|
@@ -10,12 +10,13 @@ import { fileURLToPath } from 'url';
|
|
|
10
10
|
import { realpath, readlink, readdir, lstat } from 'fs/promises';
|
|
11
11
|
import { unescape, escape, Minimatch, GLOBSTAR } from 'minimatch';
|
|
12
12
|
import 'child_process';
|
|
13
|
-
import { createHash } from 'crypto';
|
|
14
13
|
import { transformWithEsbuild } from 'vite';
|
|
15
14
|
import { createRequire } from 'module';
|
|
15
|
+
import 'crypto';
|
|
16
16
|
import { homedir } from 'os';
|
|
17
17
|
import 'vm';
|
|
18
18
|
import 'front-matter';
|
|
19
|
+
import { parse as parse$1 } from 'yaml';
|
|
19
20
|
|
|
20
21
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
21
22
|
var __esm = (fn, res) => function __init() {
|
|
@@ -3201,10 +3202,10 @@ var init_esm2 = __esm({
|
|
|
3201
3202
|
* Return a void Promise that resolves once the stream ends.
|
|
3202
3203
|
*/
|
|
3203
3204
|
async promise() {
|
|
3204
|
-
return new Promise((
|
|
3205
|
+
return new Promise((resolve15, reject) => {
|
|
3205
3206
|
this.on(DESTROYED, () => reject(new Error("stream destroyed")));
|
|
3206
3207
|
this.on("error", (er) => reject(er));
|
|
3207
|
-
this.on("end", () =>
|
|
3208
|
+
this.on("end", () => resolve15());
|
|
3208
3209
|
});
|
|
3209
3210
|
}
|
|
3210
3211
|
/**
|
|
@@ -3228,7 +3229,7 @@ var init_esm2 = __esm({
|
|
|
3228
3229
|
return Promise.resolve({ done: false, value: res });
|
|
3229
3230
|
if (this[EOF])
|
|
3230
3231
|
return stop();
|
|
3231
|
-
let
|
|
3232
|
+
let resolve15;
|
|
3232
3233
|
let reject;
|
|
3233
3234
|
const onerr = (er) => {
|
|
3234
3235
|
this.off("data", ondata);
|
|
@@ -3242,19 +3243,19 @@ var init_esm2 = __esm({
|
|
|
3242
3243
|
this.off("end", onend);
|
|
3243
3244
|
this.off(DESTROYED, ondestroy);
|
|
3244
3245
|
this.pause();
|
|
3245
|
-
|
|
3246
|
+
resolve15({ value, done: !!this[EOF] });
|
|
3246
3247
|
};
|
|
3247
3248
|
const onend = () => {
|
|
3248
3249
|
this.off("error", onerr);
|
|
3249
3250
|
this.off("data", ondata);
|
|
3250
3251
|
this.off(DESTROYED, ondestroy);
|
|
3251
3252
|
stop();
|
|
3252
|
-
|
|
3253
|
+
resolve15({ done: true, value: void 0 });
|
|
3253
3254
|
};
|
|
3254
3255
|
const ondestroy = () => onerr(new Error("stream destroyed"));
|
|
3255
3256
|
return new Promise((res2, rej) => {
|
|
3256
3257
|
reject = rej;
|
|
3257
|
-
|
|
3258
|
+
resolve15 = res2;
|
|
3258
3259
|
this.once(DESTROYED, ondestroy);
|
|
3259
3260
|
this.once("error", onerr);
|
|
3260
3261
|
this.once("end", onend);
|
|
@@ -4231,9 +4232,9 @@ var init_esm3 = __esm({
|
|
|
4231
4232
|
if (this.#asyncReaddirInFlight) {
|
|
4232
4233
|
await this.#asyncReaddirInFlight;
|
|
4233
4234
|
} else {
|
|
4234
|
-
let
|
|
4235
|
+
let resolve15 = () => {
|
|
4235
4236
|
};
|
|
4236
|
-
this.#asyncReaddirInFlight = new Promise((res) =>
|
|
4237
|
+
this.#asyncReaddirInFlight = new Promise((res) => resolve15 = res);
|
|
4237
4238
|
try {
|
|
4238
4239
|
for (const e of await this.#fs.promises.readdir(fullpath, {
|
|
4239
4240
|
withFileTypes: true
|
|
@@ -4246,7 +4247,7 @@ var init_esm3 = __esm({
|
|
|
4246
4247
|
children.provisional = 0;
|
|
4247
4248
|
}
|
|
4248
4249
|
this.#asyncReaddirInFlight = void 0;
|
|
4249
|
-
|
|
4250
|
+
resolve15();
|
|
4250
4251
|
}
|
|
4251
4252
|
return children.slice(0, children.provisional);
|
|
4252
4253
|
}
|
|
@@ -6195,17 +6196,6 @@ var init_validation_registry = __esm({
|
|
|
6195
6196
|
init_image();
|
|
6196
6197
|
}
|
|
6197
6198
|
});
|
|
6198
|
-
function normalizeUrl(url) {
|
|
6199
|
-
return url.toLowerCase().replace(/\/+$/, "");
|
|
6200
|
-
}
|
|
6201
|
-
function hashReferenceUrl(url) {
|
|
6202
|
-
const normalized = normalizeUrl(url);
|
|
6203
|
-
return createHash("sha256").update(normalized).digest("hex").slice(0, 12);
|
|
6204
|
-
}
|
|
6205
|
-
var init_reference_folder = __esm({
|
|
6206
|
-
"src/resolvers/reference-folder.ts"() {
|
|
6207
|
-
}
|
|
6208
|
-
});
|
|
6209
6199
|
function sanitize(str) {
|
|
6210
6200
|
return str.toLowerCase().replace(/[ '–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>{}[\]\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
6211
6201
|
}
|
|
@@ -6253,12 +6243,10 @@ var init_story_entity = __esm({
|
|
|
6253
6243
|
"src/story-entity.ts"() {
|
|
6254
6244
|
init_esm4();
|
|
6255
6245
|
init_scene_metadata();
|
|
6256
|
-
init_reference_folder();
|
|
6257
6246
|
StoryMeta = class _StoryMeta {
|
|
6258
6247
|
storyId;
|
|
6259
6248
|
section;
|
|
6260
6249
|
storyDir;
|
|
6261
|
-
reference;
|
|
6262
6250
|
_meta;
|
|
6263
6251
|
_metaPath;
|
|
6264
6252
|
constructor(storyId, section, storyDir, meta, metaPath) {
|
|
@@ -6267,12 +6255,6 @@ var init_story_entity = __esm({
|
|
|
6267
6255
|
this.storyDir = storyDir;
|
|
6268
6256
|
this._meta = meta;
|
|
6269
6257
|
this._metaPath = metaPath;
|
|
6270
|
-
this.reference = {
|
|
6271
|
-
url: meta.reference?.source?.url,
|
|
6272
|
-
origin: meta.reference?.source?.origin,
|
|
6273
|
-
screenId: meta.reference?.source?.screenId,
|
|
6274
|
-
hasMarkup: meta.reference?.source?.hasMarkup
|
|
6275
|
-
};
|
|
6276
6258
|
}
|
|
6277
6259
|
get data() {
|
|
6278
6260
|
return this._meta;
|
|
@@ -6334,27 +6316,13 @@ var init_story_entity = __esm({
|
|
|
6334
6316
|
mkdirSync(storyDir, { recursive: true });
|
|
6335
6317
|
const metaPath = resolve(storyDir, "meta.yml");
|
|
6336
6318
|
const section = _StoryMeta._deriveSection(storyId);
|
|
6337
|
-
const tmpStory = new _StoryMeta(storyId, section, storyDir, {}, metaPath);
|
|
6338
|
-
const breakpoints = tmpStory._getBreakpoints(config);
|
|
6339
|
-
const regions = tmpStory._deriveRegions(config);
|
|
6340
6319
|
const meta = {};
|
|
6341
|
-
if (breakpoints.length > 0) {
|
|
6342
|
-
meta.reference = { breakpoints: {} };
|
|
6343
|
-
for (const bp of breakpoints) {
|
|
6344
|
-
const regionMap = {};
|
|
6345
|
-
for (const region of regions) {
|
|
6346
|
-
regionMap[region.name] = { selector: region.selector };
|
|
6347
|
-
}
|
|
6348
|
-
meta.reference.breakpoints[bp] = { threshold: 3, regions: regionMap };
|
|
6349
|
-
}
|
|
6350
|
-
}
|
|
6351
6320
|
writeFileSync(metaPath, dump(meta, { lineWidth: -1 }), "utf-8");
|
|
6352
6321
|
return new _StoryMeta(storyId, section, storyDir, meta, metaPath);
|
|
6353
6322
|
}
|
|
6354
6323
|
/**
|
|
6355
6324
|
* Create or load a story by scene reference. Creates the story directory if
|
|
6356
|
-
* missing, optionally seeds meta.yml with provided data
|
|
6357
|
-
* breakpoints/regions from design tokens.
|
|
6325
|
+
* missing, optionally seeds meta.yml with provided data.
|
|
6358
6326
|
*/
|
|
6359
6327
|
static createByScene(config, sceneRef, metaSeed) {
|
|
6360
6328
|
const { scenes, allScenes } = resolveScene(config.data, sceneRef);
|
|
@@ -6369,31 +6337,11 @@ var init_story_entity = __esm({
|
|
|
6369
6337
|
const content = readFileSync(metaPath, "utf-8");
|
|
6370
6338
|
meta = load(content) ?? {};
|
|
6371
6339
|
}
|
|
6372
|
-
if (metaSeed?.reference) {
|
|
6373
|
-
|
|
6374
|
-
if (metaSeed.reference.source) {
|
|
6375
|
-
meta.reference.source = { ...meta.reference.source, ...metaSeed.reference.source };
|
|
6376
|
-
}
|
|
6377
|
-
if (metaSeed.reference.breakpoints) {
|
|
6378
|
-
meta.reference.breakpoints = { ...meta.reference.breakpoints, ...metaSeed.reference.breakpoints };
|
|
6379
|
-
}
|
|
6340
|
+
if (metaSeed?.reference !== void 0) {
|
|
6341
|
+
meta.reference = metaSeed.reference;
|
|
6380
6342
|
}
|
|
6381
|
-
if (
|
|
6382
|
-
|
|
6383
|
-
const tmpStory = new _StoryMeta(storyId, section, storyDir, meta, metaPath);
|
|
6384
|
-
const breakpoints = tmpStory._getBreakpoints(config);
|
|
6385
|
-
const regions = tmpStory._deriveRegions(config);
|
|
6386
|
-
if (breakpoints.length > 0) {
|
|
6387
|
-
if (!meta.reference) meta.reference = {};
|
|
6388
|
-
meta.reference.breakpoints = {};
|
|
6389
|
-
for (const bp of breakpoints) {
|
|
6390
|
-
const regionMap = {};
|
|
6391
|
-
for (const region of regions) {
|
|
6392
|
-
regionMap[region.name] = { selector: region.selector };
|
|
6393
|
-
}
|
|
6394
|
-
meta.reference.breakpoints[bp] = { threshold: 3, regions: regionMap };
|
|
6395
|
-
}
|
|
6396
|
-
}
|
|
6343
|
+
if (metaSeed?.elements !== void 0) {
|
|
6344
|
+
meta.elements = metaSeed.elements;
|
|
6397
6345
|
}
|
|
6398
6346
|
writeFileSync(metaPath, dump(meta, { lineWidth: -1 }), "utf-8");
|
|
6399
6347
|
return _StoryMeta.load(config, storyId);
|
|
@@ -6402,26 +6350,19 @@ var init_story_entity = __esm({
|
|
|
6402
6350
|
// Serialization
|
|
6403
6351
|
// -------------------------------------------------------------------------
|
|
6404
6352
|
toJSON() {
|
|
6405
|
-
const
|
|
6406
|
-
const
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
selector: region.selector ?? "",
|
|
6412
|
-
reference_selector: region.reference_selector ?? ""
|
|
6413
|
-
};
|
|
6414
|
-
}
|
|
6415
|
-
breakpoints[bp] = { threshold: cfg.threshold ?? null, regions };
|
|
6416
|
-
}
|
|
6417
|
-
const referenceDir = this.reference.url ? `references/${hashReferenceUrl(this.reference.url)}` : null;
|
|
6353
|
+
const reference = this._meta.reference ?? null;
|
|
6354
|
+
const referenceDir = reference ? `references/${reference}` : null;
|
|
6355
|
+
const elements = (this._meta.elements ?? []).map((e) => ({
|
|
6356
|
+
id: e.id,
|
|
6357
|
+
selector: e.selector ?? ""
|
|
6358
|
+
}));
|
|
6418
6359
|
return {
|
|
6419
6360
|
storyId: this.storyId,
|
|
6420
6361
|
section: this.section,
|
|
6421
6362
|
storyDir: this.storyDir,
|
|
6422
|
-
reference
|
|
6363
|
+
reference,
|
|
6423
6364
|
referenceDir,
|
|
6424
|
-
|
|
6365
|
+
elements
|
|
6425
6366
|
};
|
|
6426
6367
|
}
|
|
6427
6368
|
// -------------------------------------------------------------------------
|
|
@@ -6446,18 +6387,6 @@ var init_story_entity = __esm({
|
|
|
6446
6387
|
const idx = storyId.indexOf("--");
|
|
6447
6388
|
return idx > 0 ? storyId.substring(0, idx) : storyId;
|
|
6448
6389
|
}
|
|
6449
|
-
_getBreakpoints(config) {
|
|
6450
|
-
const tokensPath = resolve(config.data, "design-system", "design-tokens.yml");
|
|
6451
|
-
if (!existsSync(tokensPath)) return [];
|
|
6452
|
-
const content = readFileSync(tokensPath, "utf-8");
|
|
6453
|
-
const tokens = load(content);
|
|
6454
|
-
const bpObj = tokens.breakpoints ?? tokens.semantic?.breakpoints;
|
|
6455
|
-
if (!bpObj) return [];
|
|
6456
|
-
return Object.keys(bpObj).filter((k) => !k.startsWith("$"));
|
|
6457
|
-
}
|
|
6458
|
-
_deriveRegions(_config) {
|
|
6459
|
-
return [{ name: "full", selector: "" }];
|
|
6460
|
-
}
|
|
6461
6390
|
};
|
|
6462
6391
|
}
|
|
6463
6392
|
});
|
|
@@ -6729,6 +6658,32 @@ function scanAllWorkflows(workflowsDir, limit = 10) {
|
|
|
6729
6658
|
|
|
6730
6659
|
// src/vite-plugin.ts
|
|
6731
6660
|
init_story_entity();
|
|
6661
|
+
var Reference = class _Reference {
|
|
6662
|
+
constructor(hash, dir, data) {
|
|
6663
|
+
this.hash = hash;
|
|
6664
|
+
this.dir = dir;
|
|
6665
|
+
this.data = data;
|
|
6666
|
+
}
|
|
6667
|
+
static load(config, hash) {
|
|
6668
|
+
const dirAbs = join(config.data, "references", hash);
|
|
6669
|
+
const metaPath = join(dirAbs, "meta.yml");
|
|
6670
|
+
if (!existsSync(metaPath)) return null;
|
|
6671
|
+
const data = parse$1(readFileSync(metaPath, "utf8")) ?? {};
|
|
6672
|
+
return new _Reference(hash, `references/${hash}`, data);
|
|
6673
|
+
}
|
|
6674
|
+
toJSON() {
|
|
6675
|
+
return {
|
|
6676
|
+
source: this.data.source ?? {},
|
|
6677
|
+
dir: this.dir,
|
|
6678
|
+
elements: (this.data.elements ?? []).map((e) => ({
|
|
6679
|
+
id: e.id ?? "",
|
|
6680
|
+
selector: e.selector ?? "",
|
|
6681
|
+
breakpoints: e.breakpoints ?? [],
|
|
6682
|
+
states: e.states ?? [{ name: "rest", steps: [] }]
|
|
6683
|
+
}))
|
|
6684
|
+
};
|
|
6685
|
+
}
|
|
6686
|
+
};
|
|
6732
6687
|
|
|
6733
6688
|
// src/use-sync-with-selector-source.ts
|
|
6734
6689
|
var USES_WITH_SELECTOR_SOURCE = `import { useSyncExternalStore, useRef, useEffect, useMemo, useDebugValue } from 'react';
|
|
@@ -7178,9 +7133,12 @@ function designbookLoadPlugin(baseDir, options) {
|
|
|
7178
7133
|
res.end(JSON.stringify({ error: `Story not found: ${storyId}` }));
|
|
7179
7134
|
return;
|
|
7180
7135
|
}
|
|
7136
|
+
const storyJson = story.toJSON();
|
|
7137
|
+
const ref = storyJson.reference ? Reference.load(config, storyJson.reference) : null;
|
|
7138
|
+
const payload = { ...storyJson, referenceElements: ref ? ref.toJSON().elements : [] };
|
|
7181
7139
|
res.setHeader("Content-Type", "application/json");
|
|
7182
7140
|
res.statusCode = 200;
|
|
7183
|
-
res.end(JSON.stringify(
|
|
7141
|
+
res.end(JSON.stringify(payload));
|
|
7184
7142
|
} catch (err) {
|
|
7185
7143
|
res.statusCode = 500;
|
|
7186
7144
|
res.end(JSON.stringify({ error: err instanceof Error ? err.message : String(err) }));
|
package/dist/preview.js
CHANGED
|
@@ -36,6 +36,13 @@ var withRoundTrip = (storyFn, context) => {
|
|
|
36
36
|
});
|
|
37
37
|
return storyFn();
|
|
38
38
|
};
|
|
39
|
+
|
|
40
|
+
// src/visual-compare-path.ts
|
|
41
|
+
function referenceImagePath(referenceDir, breakpoint, region) {
|
|
42
|
+
return `/__designbook/load?path=${referenceDir}/${encodeURIComponent(breakpoint)}--${encodeURIComponent(region.name)}--${encodeURIComponent(region.state)}.png`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/withVisualCompare.ts
|
|
39
46
|
var storyCache = /* @__PURE__ */ new Map();
|
|
40
47
|
function fetchStory(storyId) {
|
|
41
48
|
const cached = storyCache.get(storyId);
|
|
@@ -45,9 +52,17 @@ function fetchStory(storyId) {
|
|
|
45
52
|
return promise;
|
|
46
53
|
}
|
|
47
54
|
function regionsFor(story, breakpoint) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
50
|
-
|
|
55
|
+
const refElements = story.referenceElements;
|
|
56
|
+
if (!refElements || refElements.length === 0) return [];
|
|
57
|
+
const storyElements = {};
|
|
58
|
+
for (const el of story.elements ?? []) {
|
|
59
|
+
storyElements[el.id] = el.selector;
|
|
60
|
+
}
|
|
61
|
+
return refElements.filter((el) => el.breakpoints.includes(breakpoint)).map((el) => ({
|
|
62
|
+
name: el.id,
|
|
63
|
+
selector: storyElements[el.id] ?? "",
|
|
64
|
+
state: el.states.find((state) => state.name === "rest")?.name ?? el.states[0]?.name ?? "rest"
|
|
65
|
+
}));
|
|
51
66
|
}
|
|
52
67
|
function applyOverlays(canvasElement, referenceDir, state, regions) {
|
|
53
68
|
if (!canvasElement.isConnected) return;
|
|
@@ -58,7 +73,7 @@ function applyOverlays(canvasElement, referenceDir, state, regions) {
|
|
|
58
73
|
const filtered = state.region ? regions.filter((r) => r.name === state.region) : regions;
|
|
59
74
|
const canvasRect = canvasElement.getBoundingClientRect();
|
|
60
75
|
for (const region of filtered) {
|
|
61
|
-
const src =
|
|
76
|
+
const src = referenceImagePath(referenceDir, state.breakpoint, region);
|
|
62
77
|
if (!region.selector) {
|
|
63
78
|
createOverlayImg(canvasElement, src, state.opacity, {
|
|
64
79
|
top: "0",
|
package/package.json
CHANGED