@starci/gallery 0.0.0-stage → 0.1.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +38 -2
- package/dist/app/App.d.ts +2 -0
- package/dist/app/App.js +77 -0
- package/dist/app/ExplainPanel.d.ts +13 -0
- package/dist/app/ExplainPanel.js +35 -0
- package/dist/app/FlowMap.d.ts +9 -0
- package/dist/app/FlowMap.js +14 -0
- package/dist/app/Legend.d.ts +6 -0
- package/dist/app/Legend.js +9 -0
- package/dist/app/Lightbox.d.ts +18 -0
- package/dist/app/Lightbox.js +66 -0
- package/dist/app/States.d.ts +10 -0
- package/dist/app/States.js +23 -0
- package/dist/app/Tree.d.ts +11 -0
- package/dist/app/Tree.js +30 -0
- package/dist/app/Viewer.d.ts +44 -0
- package/dist/app/Viewer.js +114 -0
- package/dist/app/app.css +415 -0
- package/dist/app/cap.d.ts +2 -0
- package/dist/app/cap.js +4 -0
- package/dist/app/data.d.ts +9 -0
- package/dist/app/data.js +3 -0
- package/dist/app/inline.d.ts +5 -0
- package/dist/app/inline.js +13 -0
- package/dist/app/main.d.ts +1 -0
- package/dist/app/main.js +9 -0
- package/dist/app/media.d.ts +3 -0
- package/dist/app/media.js +17 -0
- package/dist/app/route.d.ts +15 -0
- package/dist/app/route.js +29 -0
- package/dist/app/status.d.ts +8 -0
- package/dist/app/status.js +9 -0
- package/dist/explain.d.ts +45 -0
- package/dist/explain.js +132 -0
- package/dist/frames.d.ts +2 -0
- package/dist/frames.js +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/labels.d.ts +252 -0
- package/dist/labels.js +177 -0
- package/dist/load.d.ts +35 -0
- package/dist/load.js +163 -0
- package/dist/model.d.ts +92 -0
- package/dist/model.js +112 -0
- package/dist/views.d.ts +6 -0
- package/dist/views.js +12 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +110 -0
- package/package.json +89 -4
package/dist/load.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Reads the gallery from the disk: gallery/pages (explain.md, links.json, the shots), gallery/flows.json, and the design canvas (`.starcistacks/canvas`: design.json,
|
|
2
|
+
// tokens.css, canvas.css and the fragments of pages/, skills/claude-design references/format.md). Nothing here is drawn; the plugin serves the result.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { noteToMarkdown, SHOT_WIDTHS } from "./explain.js";
|
|
7
|
+
import { frameFile } from "./frames.js";
|
|
8
|
+
const read = (file) => {
|
|
9
|
+
try {
|
|
10
|
+
return fs.readFileSync(file, "utf8");
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const readJson = (file) => {
|
|
17
|
+
const text = read(file);
|
|
18
|
+
if (text === null)
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const dirs = (dir) => {
|
|
28
|
+
try {
|
|
29
|
+
return fs
|
|
30
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
31
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
32
|
+
.map((entry) => entry.name)
|
|
33
|
+
.sort();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const sha256 = (file) => createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
40
|
+
/** The element that opens at `start` (a `<tag`), up to its matching close tag, counting nested tags of the same name; null when it never closes. */
|
|
41
|
+
export function balanced(html, start, tag) {
|
|
42
|
+
const open = new RegExp(`<${tag}\\b|</${tag}>`, "giu");
|
|
43
|
+
open.lastIndex = start;
|
|
44
|
+
let depth = 0;
|
|
45
|
+
for (let hit = open.exec(html); hit !== null; hit = open.exec(html)) {
|
|
46
|
+
depth += hit[0].startsWith("</") ? -1 : 1;
|
|
47
|
+
if (depth === 0)
|
|
48
|
+
return html.slice(start, hit.index + hit[0].length);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const attr = (tag, name) => new RegExp(`\\b${name}="([^"]*)"`, "u").exec(tag)?.[1];
|
|
53
|
+
/** The screens of one fragment: each `<section class="page" data-pid=…>` with its 1440 and 390 frames (`.scr`) and its note. */
|
|
54
|
+
export function fragmentSections(html) {
|
|
55
|
+
const sections = [];
|
|
56
|
+
for (const open of html.matchAll(/<section\b[^>]*\bdata-pid="[^"]+"[^>]*>/gu)) {
|
|
57
|
+
const body = balanced(html, open.index, "section") ?? "";
|
|
58
|
+
const scr = {};
|
|
59
|
+
for (const frame of body.matchAll(/<div class="scr w(1440|390)\b[^"]*"/gu)) {
|
|
60
|
+
const width = frame[1];
|
|
61
|
+
const element = balanced(body, frame.index, "div");
|
|
62
|
+
if (element !== null)
|
|
63
|
+
scr[width] = element;
|
|
64
|
+
}
|
|
65
|
+
const noteStart = body.search(/<div class="note"/u);
|
|
66
|
+
const note = noteStart < 0 ? undefined : (balanced(body, noteStart, "div") ?? undefined);
|
|
67
|
+
sections.push({ pid: attr(open[0], "data-pid") ?? "", route: attr(open[0], "data-route"), title: attr(open[0], "data-title"), scr, note });
|
|
68
|
+
}
|
|
69
|
+
return sections;
|
|
70
|
+
}
|
|
71
|
+
const heightOf = (element) => {
|
|
72
|
+
const px = /height:\s*(\d+(?:\.\d+)?)px/u.exec(/^<div[^>]*>/u.exec(element)?.[0] ?? "")?.[1];
|
|
73
|
+
return px === undefined ? undefined : Number(px);
|
|
74
|
+
};
|
|
75
|
+
/** The sprites of a fragment (an `<svg>` that holds `<symbol>`s) and its `<style>` blocks. */
|
|
76
|
+
function sharedParts(html) {
|
|
77
|
+
const sprites = [];
|
|
78
|
+
for (const open of html.matchAll(/<svg\b[^>]*>/gu)) {
|
|
79
|
+
const element = balanced(html, open.index, "svg");
|
|
80
|
+
if (element?.includes("<symbol") === true)
|
|
81
|
+
sprites.push(element);
|
|
82
|
+
}
|
|
83
|
+
return { sprites, styles: [...html.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gu)].map((style) => style[1] ?? "") };
|
|
84
|
+
}
|
|
85
|
+
export function loadGallery(options) {
|
|
86
|
+
const pagesDir = path.resolve(options.root, options.pages);
|
|
87
|
+
const canvasDir = path.resolve(options.root, options.canvas);
|
|
88
|
+
const design = readJson(path.join(canvasDir, "design.json"));
|
|
89
|
+
const recorded = (id) => {
|
|
90
|
+
const pages = typeof design === "object" && design !== null ? design.pages : undefined;
|
|
91
|
+
const entry = typeof pages === "object" && pages !== null ? pages[id] : undefined;
|
|
92
|
+
const shots = typeof entry === "object" && entry !== null ? entry.shots : undefined;
|
|
93
|
+
return typeof shots === "object" && shots !== null ? shots : null;
|
|
94
|
+
};
|
|
95
|
+
const screens = {};
|
|
96
|
+
for (const area of dirs(pagesDir)) {
|
|
97
|
+
for (const name of dirs(path.join(pagesDir, area))) {
|
|
98
|
+
const dir = path.join(pagesDir, area, name);
|
|
99
|
+
const id = `${area}/${name}`;
|
|
100
|
+
const shots = SHOT_WIDTHS.filter((width) => fs.existsSync(path.join(dir, `${width}.png`)));
|
|
101
|
+
const sha = recorded(id);
|
|
102
|
+
const compared = sha === null ? [] : ["1440", "390"].filter((width) => shots.includes(width) && typeof sha[width] === "string");
|
|
103
|
+
const explain = read(path.join(dir, "explain.md"));
|
|
104
|
+
const links = readJson(path.join(dir, "links.json"));
|
|
105
|
+
screens[id] = {
|
|
106
|
+
shots,
|
|
107
|
+
...(explain === null ? {} : { explain }),
|
|
108
|
+
...(links === undefined ? {} : { links }),
|
|
109
|
+
...(compared.length === 0 || sha === null ? {} : { shotsMatchRecord: compared.every((width) => sha[width] === sha256(path.join(dir, `${width}.png`))) }),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const frames = {};
|
|
114
|
+
const docs = [];
|
|
115
|
+
const sprites = new Set();
|
|
116
|
+
const styles = [];
|
|
117
|
+
const fragmentDir = path.join(canvasDir, "pages");
|
|
118
|
+
const fragments = (() => {
|
|
119
|
+
try {
|
|
120
|
+
return fs.readdirSync(fragmentDir).filter((name) => name.endsWith(".html")).sort();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
for (const name of fragments) {
|
|
127
|
+
const html = read(path.join(fragmentDir, name)) ?? "";
|
|
128
|
+
const parts = sharedParts(html);
|
|
129
|
+
for (const sprite of parts.sprites)
|
|
130
|
+
sprites.add(sprite);
|
|
131
|
+
styles.push(...parts.styles);
|
|
132
|
+
for (const section of fragmentSections(html)) {
|
|
133
|
+
const heights = {};
|
|
134
|
+
for (const width of ["1440", "390"]) {
|
|
135
|
+
const element = section.scr[width];
|
|
136
|
+
if (element === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
const height = heightOf(element);
|
|
139
|
+
if (height !== undefined)
|
|
140
|
+
heights[width] = height;
|
|
141
|
+
docs.push({ id: section.pid, width, element });
|
|
142
|
+
}
|
|
143
|
+
frames[section.pid] = {
|
|
144
|
+
widths: Object.keys(section.scr),
|
|
145
|
+
heights,
|
|
146
|
+
...(section.title === undefined ? {} : { title: section.title }),
|
|
147
|
+
...(section.route === undefined ? {} : { route: section.route }),
|
|
148
|
+
...(section.note === undefined ? {} : { noteMarkdown: noteToMarkdown(section.note) }),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const frameCss = [read(path.join(canvasDir, "tokens.css")) ?? "", read(path.join(canvasDir, "canvas.css")) ?? "", ...styles, "html,body{margin:0;background:#fff}"].join("\n");
|
|
153
|
+
const sprite = [...sprites].join("\n");
|
|
154
|
+
const frameDocs = docs.map(({ id, width, element }) => ({
|
|
155
|
+
file: frameFile(id, width),
|
|
156
|
+
// A frame is shown at real pixels by the viewer, which scales it: the board's `.zoom` (50%) would shrink it twice.
|
|
157
|
+
html: `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="frames.css"></head><body>${sprite}${element.replace(/^(<div class=")([^"]*)"/u, (_all, head, classes) => `${head}${classes.split(/\s+/u).filter((one) => one !== "zoom").join(" ")}"`)}</body></html>`,
|
|
158
|
+
}));
|
|
159
|
+
const flows = readJson(path.join(options.root, "flows.json"));
|
|
160
|
+
return { raw: { screens, frames, ...(flows === undefined ? {} : { flows }), ...(design === undefined ? {} : { design }) }, frameCss, frames: frameDocs };
|
|
161
|
+
}
|
|
162
|
+
/** The files the loader reads, for the watcher: the pages folder, the canvas folder and the flows file. */
|
|
163
|
+
export const watchedPaths = (options) => [path.resolve(options.root, options.pages), path.resolve(options.root, options.canvas), path.resolve(options.root, "flows.json")];
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { noteToMarkdown, SHOT_WIDTHS } from "./explain.js";
|
|
2
|
+
import type { Explain, Flow, Link, Width } from "./explain.js";
|
|
3
|
+
/**
|
|
4
|
+
* The status of a screen: the colour of its dot. With a design.json entry its status is the record (matches, differs, stale, notBuilt: drafted or approved with no shot). Without
|
|
5
|
+
* one it is read from what exists: a frame and a shot are `unrecorded` (coded, not recorded in design.json), a shot alone `codedOnly`, a frame alone `drawn`, neither `none`.
|
|
6
|
+
*/
|
|
7
|
+
export type Status = "matches" | "differs" | "stale" | "notBuilt" | "drawn" | "unrecorded" | "codedOnly" | "none";
|
|
8
|
+
/** The state suffixes of a screen id, in the order of the state table of PROJECT-GALLERY-6 item 2. */
|
|
9
|
+
export declare const STATE_KINDS: readonly ["detail", "empty", "first-visit", "loading", "error", "no-match", "editing"];
|
|
10
|
+
export type StateKind = (typeof STATE_KINDS)[number];
|
|
11
|
+
export interface RawFrame {
|
|
12
|
+
/** The widths the fragment draws. */
|
|
13
|
+
readonly widths: readonly ("1440" | "390")[];
|
|
14
|
+
/** The pixel height of each drawn width, when the frame states one. */
|
|
15
|
+
readonly heights: Partial<Record<"1440" | "390", number>>;
|
|
16
|
+
readonly title?: string;
|
|
17
|
+
readonly route?: string;
|
|
18
|
+
/** The note of the fragment, as explain.md text. */
|
|
19
|
+
readonly noteMarkdown?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RawScreen {
|
|
22
|
+
/** The explain.md text, absent when the folder has none. */
|
|
23
|
+
readonly explain?: string;
|
|
24
|
+
/** The parsed links.json. */
|
|
25
|
+
readonly links?: unknown;
|
|
26
|
+
/** The widths a PNG exists for in the work tree. */
|
|
27
|
+
readonly shots: readonly Width[];
|
|
28
|
+
/** Whether the PNGs in the work tree hold the sha256 design.json records; absent when nothing was compared. */
|
|
29
|
+
readonly shotsMatchRecord?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface RawGallery {
|
|
32
|
+
readonly screens: Readonly<Record<string, RawScreen>>;
|
|
33
|
+
readonly flows?: unknown;
|
|
34
|
+
readonly design?: unknown;
|
|
35
|
+
readonly frames: Readonly<Record<string, RawFrame>>;
|
|
36
|
+
}
|
|
37
|
+
export interface Screen {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly area: string;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly title: string;
|
|
42
|
+
readonly route: string | null;
|
|
43
|
+
readonly status: Status;
|
|
44
|
+
/** The designed status word of design.json, when the screen has an entry. */
|
|
45
|
+
readonly designStatus: string | null;
|
|
46
|
+
readonly board: string | null;
|
|
47
|
+
readonly shots: readonly Width[];
|
|
48
|
+
readonly frame: RawFrame | null;
|
|
49
|
+
readonly explain: Explain | null;
|
|
50
|
+
readonly links: Link[];
|
|
51
|
+
/** The page this screen is a state of (its base id) and the state; `base` for the page's own screen. */
|
|
52
|
+
readonly page: string;
|
|
53
|
+
readonly state: StateKind | "base";
|
|
54
|
+
readonly problems: number;
|
|
55
|
+
}
|
|
56
|
+
export interface Area {
|
|
57
|
+
readonly area: string;
|
|
58
|
+
readonly screens: Screen[];
|
|
59
|
+
}
|
|
60
|
+
export interface Counts {
|
|
61
|
+
readonly total: number;
|
|
62
|
+
readonly matches: number;
|
|
63
|
+
readonly differs: number;
|
|
64
|
+
readonly stale: number;
|
|
65
|
+
/** Coded (a shot exists) with no design.json record: `unrecorded` and `codedOnly`. */
|
|
66
|
+
readonly unrecorded: number;
|
|
67
|
+
/** No shot: `notBuilt`, `drawn` and `none`. total = matches + differs + stale + unrecorded + notCoded. */
|
|
68
|
+
readonly notCoded: number;
|
|
69
|
+
readonly hidden: number;
|
|
70
|
+
}
|
|
71
|
+
export interface Model {
|
|
72
|
+
readonly areas: Area[];
|
|
73
|
+
readonly screens: Record<string, Screen>;
|
|
74
|
+
readonly flows: Flow[];
|
|
75
|
+
readonly counts: Counts;
|
|
76
|
+
/** Every id of the screens of one page, its own screen first and then its states in table order. */
|
|
77
|
+
readonly pages: Record<string, string[]>;
|
|
78
|
+
}
|
|
79
|
+
/** The base id and the state of a screen id: the longest `-<state>` suffix of the table is the state, anything else is a page's own screen. */
|
|
80
|
+
export declare function splitState(id: string): {
|
|
81
|
+
page: string;
|
|
82
|
+
state: StateKind | "base";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The status of a screen: its design.json entry says drafted or approved (no code yet: not built), built (coded, not yet compared) or matches. A built or matching
|
|
86
|
+
* screen whose PNGs are not the sha256 the manifest records, and a drafted or approved one that still records shots, is stale (PROJECT-GALLERY-6 item 6).
|
|
87
|
+
*/
|
|
88
|
+
export declare function statusOf(entry: unknown, shotsMatchRecord: boolean | undefined, hasShot?: boolean, hasFrame?: boolean): Status;
|
|
89
|
+
export declare function buildModel(raw: RawGallery): Model;
|
|
90
|
+
/** The route of a screen as a path on the dev app, or null when it is dynamic (`[id]`, `:id`, `*`) and so names no one page. */
|
|
91
|
+
export declare function devPath(route: string | null): string | null;
|
|
92
|
+
export { SHOT_WIDTHS, noteToMarkdown };
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// The gallery as data: the screens of gallery/pages, the design.json of the canvas and the frames of its fragments joined into one tree of areas and screens, each
|
|
2
|
+
// with its status (the dot), its states (sibling screens of one page) and its counts. Pure: nothing here touches the disk (load.ts reads it, the app draws it).
|
|
3
|
+
import { flowList, linkList, noteToMarkdown, parseExplain, SHOT_WIDTHS } from "./explain.js";
|
|
4
|
+
/** The state suffixes of a screen id, in the order of the state table of PROJECT-GALLERY-6 item 2. */
|
|
5
|
+
export const STATE_KINDS = ["detail", "empty", "first-visit", "loading", "error", "no-match", "editing"];
|
|
6
|
+
const plain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
/** The base id and the state of a screen id: the longest `-<state>` suffix of the table is the state, anything else is a page's own screen. */
|
|
8
|
+
export function splitState(id) {
|
|
9
|
+
const slash = id.indexOf("/");
|
|
10
|
+
const area = id.slice(0, slash + 1);
|
|
11
|
+
const name = id.slice(slash + 1);
|
|
12
|
+
let best = null;
|
|
13
|
+
for (const kind of STATE_KINDS)
|
|
14
|
+
if (name.endsWith(`-${kind}`) && name.length > kind.length + 1 && (best === null || kind.length > best.length))
|
|
15
|
+
best = kind;
|
|
16
|
+
return best === null ? { page: id, state: "base" } : { page: `${area}${name.slice(0, name.length - best.length - 1)}`, state: best };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The status of a screen: its design.json entry says drafted or approved (no code yet: not built), built (coded, not yet compared) or matches. A built or matching
|
|
20
|
+
* screen whose PNGs are not the sha256 the manifest records, and a drafted or approved one that still records shots, is stale (PROJECT-GALLERY-6 item 6).
|
|
21
|
+
*/
|
|
22
|
+
export function statusOf(entry, shotsMatchRecord, hasShot = false, hasFrame = false) {
|
|
23
|
+
if (!plain(entry))
|
|
24
|
+
return hasShot ? (hasFrame ? "unrecorded" : "codedOnly") : hasFrame ? "drawn" : "none";
|
|
25
|
+
const status = entry.status;
|
|
26
|
+
const recorded = plain(entry.shots) && Object.keys(entry.shots).length > 0;
|
|
27
|
+
if (status === "matches")
|
|
28
|
+
return shotsMatchRecord === false ? "stale" : "matches";
|
|
29
|
+
if (status === "built")
|
|
30
|
+
return shotsMatchRecord === false ? "stale" : "differs";
|
|
31
|
+
if (status === "drafted" || status === "approved")
|
|
32
|
+
return recorded ? "stale" : "notBuilt";
|
|
33
|
+
return "none";
|
|
34
|
+
}
|
|
35
|
+
/** A value that is present and not empty, else undefined: an empty front matter field falls through to the next source. */
|
|
36
|
+
const nonEmpty = (value) => (value === undefined || value === "" ? undefined : value);
|
|
37
|
+
const titleOf = (id, explain, frame) => nonEmpty(explain?.meta.title) ?? nonEmpty(frame?.title) ?? id.slice(id.indexOf("/") + 1);
|
|
38
|
+
export function buildModel(raw) {
|
|
39
|
+
const designPages = plain(raw.design) && plain(raw.design.pages) ? raw.design.pages : {};
|
|
40
|
+
const ids = new Set([...Object.keys(raw.screens), ...Object.keys(designPages), ...Object.keys(raw.frames)]);
|
|
41
|
+
const screens = {};
|
|
42
|
+
let hidden = 0;
|
|
43
|
+
for (const id of [...ids].sort()) {
|
|
44
|
+
const slash = id.indexOf("/");
|
|
45
|
+
if (slash < 1)
|
|
46
|
+
continue;
|
|
47
|
+
const rawScreen = raw.screens[id];
|
|
48
|
+
const frame = raw.frames[id] ?? null;
|
|
49
|
+
const text = rawScreen?.explain ?? frame?.noteMarkdown ?? null;
|
|
50
|
+
const entry = designPages[id];
|
|
51
|
+
if (text === null && !plain(entry)) {
|
|
52
|
+
hidden++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const explain = text === null ? null : parseExplain(text);
|
|
56
|
+
const { page, state } = splitState(id);
|
|
57
|
+
screens[id] = {
|
|
58
|
+
id,
|
|
59
|
+
area: id.slice(0, slash),
|
|
60
|
+
name: id.slice(slash + 1),
|
|
61
|
+
title: titleOf(id, explain, frame),
|
|
62
|
+
route: nonEmpty(explain?.meta.route) ?? nonEmpty(frame?.route) ?? null,
|
|
63
|
+
status: statusOf(entry, rawScreen?.shotsMatchRecord, (rawScreen?.shots.length ?? 0) > 0, (frame?.widths.length ?? 0) > 0),
|
|
64
|
+
designStatus: plain(entry) && typeof entry.status === "string" ? entry.status : null,
|
|
65
|
+
board: plain(entry) && typeof entry.board === "string" ? entry.board : null,
|
|
66
|
+
shots: rawScreen?.shots ?? [],
|
|
67
|
+
frame,
|
|
68
|
+
explain,
|
|
69
|
+
links: linkList(rawScreen?.links),
|
|
70
|
+
page,
|
|
71
|
+
state,
|
|
72
|
+
problems: explain === null ? 0 : explain.regions.filter((region) => region.problems.length > 0).length + (explain.regions.length === 0 ? 1 : 0),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const byArea = new Map();
|
|
76
|
+
for (const screen of Object.values(screens))
|
|
77
|
+
byArea.set(screen.area, [...(byArea.get(screen.area) ?? []), screen]);
|
|
78
|
+
const areas = [...byArea.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([area, list]) => ({ area, screens: list }));
|
|
79
|
+
const pages = {};
|
|
80
|
+
for (const screen of Object.values(screens))
|
|
81
|
+
(pages[screen.page] ??= []).push(screen.id);
|
|
82
|
+
const order = (id) => {
|
|
83
|
+
const state = screens[id]?.state ?? "base";
|
|
84
|
+
return state === "base" ? -1 : STATE_KINDS.indexOf(state);
|
|
85
|
+
};
|
|
86
|
+
for (const list of Object.values(pages))
|
|
87
|
+
list.sort((a, b) => order(a) - order(b) || a.localeCompare(b));
|
|
88
|
+
const all = Object.values(screens);
|
|
89
|
+
const count = (status) => all.filter((screen) => screen.status === status).length;
|
|
90
|
+
return {
|
|
91
|
+
areas,
|
|
92
|
+
screens,
|
|
93
|
+
flows: flowList(raw.flows),
|
|
94
|
+
pages,
|
|
95
|
+
counts: {
|
|
96
|
+
total: all.length,
|
|
97
|
+
matches: count("matches"),
|
|
98
|
+
differs: count("differs"),
|
|
99
|
+
stale: count("stale"),
|
|
100
|
+
unrecorded: count("unrecorded") + count("codedOnly"),
|
|
101
|
+
notCoded: count("notBuilt") + count("drawn") + count("none"),
|
|
102
|
+
hidden,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The route of a screen as a path on the dev app, or null when it is dynamic (`[id]`, `:id`, `*`) and so names no one page. */
|
|
107
|
+
export function devPath(route) {
|
|
108
|
+
if (route === null || !route.startsWith("/") || /[[\]:*]/u.test(route))
|
|
109
|
+
return null;
|
|
110
|
+
return route;
|
|
111
|
+
}
|
|
112
|
+
export { SHOT_WIDTHS, noteToMarkdown };
|
package/dist/views.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The views of a screen: the design alone, the comparison of design and shot (side by side, a slider, an onion skin, a difference), the shot alone. */
|
|
2
|
+
export type View = "design" | "side" | "slider" | "onion" | "diff" | "shot";
|
|
3
|
+
export declare const COMPARE_VIEWS: readonly View[];
|
|
4
|
+
export declare const VIEWS: readonly View[];
|
|
5
|
+
/** The view to draw: the one asked for, or the side that exists when the screen has only a design or only a shot at this width (a comparison needs both). */
|
|
6
|
+
export declare function effectiveView(asked: View, hasDesign: boolean, hasShot: boolean): View;
|
package/dist/views.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const COMPARE_VIEWS = ["side", "slider", "onion", "diff"];
|
|
2
|
+
export const VIEWS = ["design", "side", "slider", "onion", "diff", "shot"];
|
|
3
|
+
/** The view to draw: the one asked for, or the side that exists when the screen has only a design or only a shot at this width (a comparison needs both). */
|
|
4
|
+
export function effectiveView(asked, hasDesign, hasShot) {
|
|
5
|
+
if (hasDesign && hasShot)
|
|
6
|
+
return asked;
|
|
7
|
+
if (hasDesign)
|
|
8
|
+
return "design";
|
|
9
|
+
if (hasShot)
|
|
10
|
+
return "shot";
|
|
11
|
+
return asked;
|
|
12
|
+
}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin, UserConfig } from "vite";
|
|
2
|
+
export interface GalleryOptions {
|
|
3
|
+
/** The app's name, shown in the title and the top bar. */
|
|
4
|
+
readonly app: string;
|
|
5
|
+
/** The app's default locale (`vi` and `en` have a table; any other reads `en`). Default `en`. */
|
|
6
|
+
readonly locale?: string;
|
|
7
|
+
/** The pages folder, relative to the gallery root. Default `pages`. */
|
|
8
|
+
readonly pages?: string;
|
|
9
|
+
/** The design canvas folder, relative to the gallery root. Default `../.starcistacks/canvas`. */
|
|
10
|
+
readonly canvas?: string;
|
|
11
|
+
/** The base URL of the dev app: a screen with a static route gets an "open on dev" link to `<devUrl><route>`. Omit when the app declares none. */
|
|
12
|
+
readonly devUrl?: string;
|
|
13
|
+
/** The hosts the dev server answers besides localhost (the dev tunnel's gallery host). Default none. */
|
|
14
|
+
readonly allowedHosts?: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** The plugin: the data module, the app entry, the shots under `/__shots/` and the frames under `/__frames/`, in dev and in the build. */
|
|
17
|
+
export declare function gallery(options: GalleryOptions): Plugin;
|
|
18
|
+
/**
|
|
19
|
+
* The whole Vite config of an app's gallery: the plugin, Tailwind for the Grammar's stylesheet, and the dev server the stack expects (the IPv4 loopback, PROJECT-GALLERY-1 item 4;
|
|
20
|
+
* the shots are many and copied in bulk, so the PNGs are not watched: reload the page after adding some).
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineGallery(options: GalleryOptions): UserConfig;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The Vite side of the gallery: an app's whole gallery is one config file, `export default defineGallery({ app, locale, allowedHosts })`. The plugin reads the pages, the
|
|
2
|
+
// flows and the design canvas at build and dev time, serves the shots and the canvas frames, and mounts the gallery app that this package compiles.
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import tailwind from "@tailwindcss/postcss";
|
|
7
|
+
import { galleryLocale } from "./labels.js";
|
|
8
|
+
import { loadGallery, watchedPaths } from "./load.js";
|
|
9
|
+
import { buildModel } from "./model.js";
|
|
10
|
+
const VIRTUAL_DATA = "virtual:starci-gallery/data";
|
|
11
|
+
const ENTRY = "/@starci-gallery/main.js";
|
|
12
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const MIME = { ".png": "image/png", ".html": "text/html; charset=utf-8", ".css": "text/css; charset=utf-8" };
|
|
14
|
+
/** The plugin: the data module, the app entry, the shots under `/__shots/` and the frames under `/__frames/`, in dev and in the build. */
|
|
15
|
+
export function gallery(options) {
|
|
16
|
+
let root = process.cwd();
|
|
17
|
+
let loaded = null;
|
|
18
|
+
const settings = () => ({ root, pages: options.pages ?? "pages", canvas: options.canvas ?? "../.starcistacks/canvas" });
|
|
19
|
+
const current = () => (loaded ??= loadGallery(settings()));
|
|
20
|
+
const shotPath = (id, width) => path.resolve(root, settings().pages, ...id.split("/"), `${width}.png`);
|
|
21
|
+
const data = () => {
|
|
22
|
+
const { raw } = current();
|
|
23
|
+
const model = buildModel(raw);
|
|
24
|
+
const json = JSON.stringify({ app: options.app, locale: galleryLocale(options.locale), devUrl: options.devUrl ?? null, model }, (key, value) => (key === "noteMarkdown" ? undefined : value));
|
|
25
|
+
return `export default ${json}`;
|
|
26
|
+
};
|
|
27
|
+
const asset = (url) => {
|
|
28
|
+
const { frames, frameCss } = current();
|
|
29
|
+
const frame = /^\/__frames\/([^/]+)$/u.exec(url)?.[1];
|
|
30
|
+
if (frame === "frames.css")
|
|
31
|
+
return { body: frameCss, type: MIME[".css"] ?? "" };
|
|
32
|
+
const doc = frame === undefined ? undefined : frames.find((one) => one.file === frame);
|
|
33
|
+
if (doc)
|
|
34
|
+
return { body: doc.html, type: MIME[".html"] ?? "" };
|
|
35
|
+
const shot = /^\/__shots\/([^/]+)\/([^/]+)\/(1440|390)\.png$/u.exec(url);
|
|
36
|
+
if (shot?.[1] !== undefined && shot[2] !== undefined && shot[3] !== undefined) {
|
|
37
|
+
const file = shotPath(`${shot[1]}/${shot[2]}`, shot[3]);
|
|
38
|
+
return fs.existsSync(file) ? { body: fs.readFileSync(file), type: MIME[".png"] ?? "" } : null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
name: "starci-gallery",
|
|
44
|
+
configResolved(config) {
|
|
45
|
+
root = config.root;
|
|
46
|
+
},
|
|
47
|
+
resolveId(id) {
|
|
48
|
+
if (id === VIRTUAL_DATA)
|
|
49
|
+
return `\0${VIRTUAL_DATA}`;
|
|
50
|
+
if (id === ENTRY)
|
|
51
|
+
return path.join(here, "app", "main.js");
|
|
52
|
+
return null;
|
|
53
|
+
},
|
|
54
|
+
load(id) {
|
|
55
|
+
return id === `\0${VIRTUAL_DATA}` ? data() : null;
|
|
56
|
+
},
|
|
57
|
+
configureServer(server) {
|
|
58
|
+
const watched = watchedPaths(settings());
|
|
59
|
+
server.watcher.add(watched);
|
|
60
|
+
const reload = (file) => {
|
|
61
|
+
if (!watched.some((one) => path.resolve(file).startsWith(one)) || file.endsWith(".png"))
|
|
62
|
+
return;
|
|
63
|
+
loaded = null;
|
|
64
|
+
const module = server.moduleGraph.getModuleById(`\0${VIRTUAL_DATA}`);
|
|
65
|
+
if (module)
|
|
66
|
+
server.moduleGraph.invalidateModule(module);
|
|
67
|
+
server.ws.send({ type: "full-reload" });
|
|
68
|
+
};
|
|
69
|
+
for (const event of ["add", "change", "unlink"])
|
|
70
|
+
server.watcher.on(event, reload);
|
|
71
|
+
server.middlewares.use((request, response, next) => {
|
|
72
|
+
const url = (request.url ?? "").split("?")[0] ?? "";
|
|
73
|
+
const found = url.startsWith("/__") ? asset(decodeURIComponent(url)) : null;
|
|
74
|
+
if (!found) {
|
|
75
|
+
next();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
response.setHeader("content-type", found.type);
|
|
79
|
+
response.setHeader("cache-control", "no-cache");
|
|
80
|
+
response.end(found.body);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
generateBundle() {
|
|
84
|
+
const { raw, frames, frameCss } = current();
|
|
85
|
+
this.emitFile({ type: "asset", fileName: "__frames/frames.css", source: frameCss });
|
|
86
|
+
for (const frame of frames)
|
|
87
|
+
this.emitFile({ type: "asset", fileName: `__frames/${frame.file}`, source: frame.html });
|
|
88
|
+
for (const [id, screen] of Object.entries(raw.screens)) {
|
|
89
|
+
for (const width of screen.shots)
|
|
90
|
+
this.emitFile({ type: "asset", fileName: `__shots/${id}/${width}.png`, source: fs.readFileSync(shotPath(id, width)) });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The whole Vite config of an app's gallery: the plugin, Tailwind for the Grammar's stylesheet, and the dev server the stack expects (the IPv4 loopback, PROJECT-GALLERY-1 item 4;
|
|
97
|
+
* the shots are many and copied in bulk, so the PNGs are not watched: reload the page after adding some).
|
|
98
|
+
*/
|
|
99
|
+
export function defineGallery(options) {
|
|
100
|
+
return {
|
|
101
|
+
plugins: [gallery(options)],
|
|
102
|
+
css: { postcss: { plugins: [tailwind()] } },
|
|
103
|
+
resolve: { dedupe: ["react", "react-dom"] },
|
|
104
|
+
server: {
|
|
105
|
+
host: "127.0.0.1",
|
|
106
|
+
allowedHosts: [...(options.allowedHosts ?? [])],
|
|
107
|
+
watch: { ignored: ["**/*.png", "**/node_modules/**"], awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 } },
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/gallery",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The screenshot gallery of a StarCi app as one Vite config: the screens of gallery/pages with their explanations, the approved design frames of the canvas beside the real shots (side by side, a slider, shot only), each screen's status from design.json, its states, the flow map. Built with the StarCi Grammar.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"starci",
|
|
7
|
+
"gallery",
|
|
8
|
+
"screenshots",
|
|
9
|
+
"design",
|
|
10
|
+
"vite",
|
|
11
|
+
"grammar"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "starci183",
|
|
15
|
+
"homepage": "https://github.com/starci183/starci-harness/tree/main/packages/gallery#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/starci183/starci-harness.git",
|
|
19
|
+
"directory": "packages/gallery"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/starci183/starci-harness/issues"
|
|
23
|
+
},
|
|
24
|
+
"private": false,
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./vite": {
|
|
34
|
+
"types": "./dist/vite.d.ts",
|
|
35
|
+
"default": "./dist/vite.js"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"!dist/**/*.spec.*",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"README.md",
|
|
44
|
+
"CHANGELOG.md"
|
|
45
|
+
],
|
|
46
|
+
"sideEffects": [
|
|
47
|
+
"./dist/**/*.css"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "node -e \"require('node:fs').rmSync('dist', {recursive: true, force: true})\" && tsc -p tsconfig.build.json && node scripts/finish-build.ts",
|
|
54
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"test": "npm run typecheck && npm run lint && node --test \"src/**/*.spec.ts\"",
|
|
57
|
+
"prepack": "npm run build",
|
|
58
|
+
"prepublishOnly": "npm test && npm run build"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@heroui/react": "3.2.6",
|
|
62
|
+
"@heroui/styles": "3.2.6",
|
|
63
|
+
"@starci/grammar": "0.45.0",
|
|
64
|
+
"@tailwindcss/postcss": "4.3.3",
|
|
65
|
+
"@xyflow/react": "12.11.6",
|
|
66
|
+
"react": "19.2.3",
|
|
67
|
+
"react-aria-components": "1.21.1",
|
|
68
|
+
"react-dom": "19.2.3",
|
|
69
|
+
"tailwindcss": "4.3.3"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"vite": ">=6"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@eslint/js": "10.0.1",
|
|
76
|
+
"@types/node": "22.20.4",
|
|
77
|
+
"@types/react": "19.3.0",
|
|
78
|
+
"@types/react-dom": "19.3.0",
|
|
79
|
+
"eslint": "10.13.0",
|
|
80
|
+
"jiti": "2.7.0",
|
|
81
|
+
"typescript": "5.9.3",
|
|
82
|
+
"typescript-eslint": "8.72.0",
|
|
83
|
+
"vite": "6.3.5"
|
|
84
|
+
},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public",
|
|
87
|
+
"provenance": true
|
|
88
|
+
},
|
|
89
|
+
"gitHead": "7010020df01f025efe699067d3bf2b97e8d4fb12",
|
|
90
|
+
"starciSource": "d3cf91bceb299b4e3eaa09621c129b9e6b6f122f3cee124141508c4d4128eb13"
|
|
91
|
+
}
|