@starci/gallery 0.0.0-stage → 0.1.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/CHANGELOG.md +17 -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 +140 -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 +90 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
- Changed (`explain`): the explain reader skips the section `## Phương án đã cân nhắc` (the record of the options weighed, PROJECT-GALLERY-7) instead of reading it as a region, as `starci app check` does.
|
|
6
|
+
|
|
7
|
+
## 0.1.0 - 2026-11-18
|
|
8
|
+
|
|
9
|
+
The screenshot gallery of a StarCi app as one Vite config, built with the StarCi Grammar.
|
|
10
|
+
|
|
11
|
+
- Added: `@starci/gallery/vite` (`defineGallery({ app, locale, allowedHosts, devUrl, pages, canvas })`, and the plugin `gallery(options)` alone). The plugin reads `gallery/pages/**` (explain.md, links.json, the shots), `gallery/flows.json`, and the design canvas (`.starcistacks/canvas`: design.json and the fragments of `pages/`) at build and dev time, serves the shots and the canvas frames, and mounts the gallery app. The canvas folder defaults to `../.starcistacks/canvas`.
|
|
12
|
+
- Added: the gallery app. A top bar with the app name and "screens, matches, not built", a width switch (1440, 390: the two widths of the gallery) and a view switch (side by side, slider, shot only); a tree of areas and screens with the status dot of design.json (matches green, built but differs amber, stale red, not built grey); the states of a page as chips (`-detail`, `-empty`, `-first-visit`, `-loading`, `-error`, `-no-match`, `-editing`); the explain.md of the screen on the right with its gallery id, status, route and a link to the dev app when the route is static; the flow map. Words in `vi` and `en` (any other locale reads `en`).
|
|
13
|
+
- Added: `@starci/gallery` (the pure side): `parseExplain`, `buildModel`, `statusOf`, `splitState`, `noteToMarkdown`, `LABELS`, kept answering like the reader of `starci app check`.
|
|
14
|
+
- Added: side by side holds while each column keeps 320px, so at a 1440 window the design and the shot stand next to each other; the explanation panel narrows with the window (18rem to 26rem) before the columns stack, and a button in the top bar hides or shows it, remembered per viewer in localStorage (the panel stays open when storage is blocked).
|
|
15
|
+
- Added: labels derived from a folder, a state or a title are capitalized for display by the app's locale (`capitalize`), never the ids; a press on a frame or a shot opens it full size in a Dialog with zoom (buttons and `+`, `-`, `0`), drag to pan and Escape to close; the explanation shows the overview and the business regions (Nghiệp vụ, Tổng quan, Phản biện) first, and every other region as one closed disclosure; the board is as tall as its frames; below 1100px one pane shows at a time (Bản vẽ, Ảnh thật, Trượt so, Giải thích).
|
|
16
|
+
- Changed: the status of a screen is read truthfully. A design.json entry is the record; with none, a frame and a shot are "coded, not recorded" (with a hint to record it), a shot alone is "coded, no drawing", a frame alone "drawn, not coded", neither "no drawing yet". The top bar counts add up (screens = khớp + lệch + cũ + đã code chưa ghi duyệt + chưa code), the column title says "approved" only from an approved status on, and a legend button explains the dots.
|
|
17
|
+
- Added: the views Bản vẽ, Đối chiếu (side by side, slider, onion skin, difference) and Ảnh thật, each disabled with its reason when the screen has only one side; every canvas page shows in the tree and renders read-only with its note, drafted or not coded yet. On a phone the panes are Bản vẽ, Ảnh thật, Đối chiếu and Giải thích.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 starci183
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@starci/gallery`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The screenshot gallery of a StarCi app ([contexts/project/gallery.md](../../contexts/project/gallery.md)) as one Vite config. The app's `gallery/`
|
|
4
|
+
folder holds the pages (`pages/<area>/<screen>/` with the shots, `explain.md`, `links.json`), `flows.json` and `routes.json`; this package reads them with the
|
|
5
|
+
design canvas (`.starcistacks/canvas`: `design.json` and the fragments of `pages/`) and shows each screen.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// gallery/vite.config.js (managed by `starci app sync`)
|
|
9
|
+
import { defineGallery } from "@starci/gallery/vite"
|
|
10
|
+
|
|
11
|
+
export default defineGallery({ app: "starci-next", locale: "vi", allowedHosts: [] })
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| option | meaning |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `app` | the app's name (title and top bar) |
|
|
17
|
+
| `locale` | the app's default locale; `vi` and `en` have a table, any other reads `en` |
|
|
18
|
+
| `allowedHosts` | the hosts the dev server answers besides localhost (the dev tunnel's gallery host) |
|
|
19
|
+
| `devUrl` | the base URL of the dev app: a screen with a static route gets "Mở trên dev" |
|
|
20
|
+
| `pages` | the pages folder, default `pages` |
|
|
21
|
+
| `canvas` | the canvas folder, default `../.starcistacks/canvas` |
|
|
22
|
+
|
|
23
|
+
`defineGallery` also sets the dev server the stack expects (the IPv4 loopback, the PNGs not watched) and Tailwind for the Grammar's stylesheet. The page
|
|
24
|
+
`index.html` of the app loads the entry `/@starci-gallery/main.js`.
|
|
25
|
+
|
|
26
|
+
## What it shows
|
|
27
|
+
|
|
28
|
+
- The top bar: counts ("127 màn · 0 khớp · 6 đã code chưa ghi duyệt · 121 chưa code", which add up), the width switch (1440, 390), the three views (Bản vẽ, Đối chiếu, Ảnh thật) and a legend of the dots. Đối chiếu compares the approved design frame and the real shot side by side, with a slider, as an onion skin or as a difference (a shape that differs lights up); a view that needs the missing side is disabled with its reason. A canvas page with no shot yet (drafted, or approved and not coded) shows read-only with its note. The flow map is a second view.
|
|
29
|
+
- The tree: areas and screens, each with the dot of its status in `design.json`: matches green, built but differs amber, stale red (the shots are not the recorded
|
|
30
|
+
sha256, or an approved screen still records shots), not built grey.
|
|
31
|
+
- The states of a page: sibling screens named with the state suffixes of PROJECT-GALLERY-6 (`-detail`, `-empty`, `-first-visit`, `-loading`, `-error`,
|
|
32
|
+
`-no-match`, `-editing`) are chips over the viewer.
|
|
33
|
+
- The explanation: the screen's `explain.md` (or the note of its canvas fragment when it has no folder yet), the overview as rows, each region with
|
|
34
|
+
its `Vì sao`, `Luật` and `Grammar` lines, the flags `CHƯA RÕ` and `SAI`.
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
`@starci/gallery` exports the pure side: `parseExplain`, `linkList`, `flowList`, `noteToMarkdown`, `buildModel`, `statusOf`, `splitState`, `devPath`,
|
|
39
|
+
`LABELS`. `npm test` typechecks, lints and runs the specs of the loader (tree, statuses, counts and states of a fixture gallery with its `design.json`).
|
package/dist/app/App.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Badge, CoreGrammarRoot, Heading, IconButton, Tabs, Text, Tooltip } from "@starci/grammar/core";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { data } from "./data.js";
|
|
5
|
+
import { fill, labelsFor } from "../labels.js";
|
|
6
|
+
import { ExplainPanel } from "./ExplainPanel.js";
|
|
7
|
+
import { FlowMap } from "./FlowMap.js";
|
|
8
|
+
import { useNarrow } from "./media.js";
|
|
9
|
+
import { statusLabel, TONE } from "./status.js";
|
|
10
|
+
import { useRoute } from "./route.js";
|
|
11
|
+
import { COMPARE_VIEWS, effectiveView } from "../views.js";
|
|
12
|
+
import { States } from "./States.js";
|
|
13
|
+
import { Legend } from "./Legend.js";
|
|
14
|
+
import { Tree } from "./Tree.js";
|
|
15
|
+
import { CompareModes, Viewer, ViewSwitches } from "./Viewer.js";
|
|
16
|
+
const { model, devUrl } = data;
|
|
17
|
+
const labels = labelsFor(data.locale);
|
|
18
|
+
/** "67 màn · 41 khớp · 26 chưa code": the screens, how many match and how many have no shot; the other counts only when there are some. They add up: total = khớp + lệch + cũ + đã code chưa ghi duyệt + chưa code. */
|
|
19
|
+
function summary() {
|
|
20
|
+
const { counts } = model;
|
|
21
|
+
return [
|
|
22
|
+
fill(labels.counts, { total: counts.total }),
|
|
23
|
+
fill(labels.countsMatches, { n: counts.matches }),
|
|
24
|
+
...(counts.differs > 0 ? [fill(labels.countsDiffers, { n: counts.differs })] : []),
|
|
25
|
+
...(counts.stale > 0 ? [fill(labels.countsStale, { n: counts.stale })] : []),
|
|
26
|
+
...(counts.unrecorded > 0 ? [fill(labels.countsUnrecorded, { n: counts.unrecorded })] : []),
|
|
27
|
+
fill(labels.countsNotCoded, { n: counts.notCoded }),
|
|
28
|
+
].join(" · ");
|
|
29
|
+
}
|
|
30
|
+
const PANEL_KEY = "starci-gallery:explain-open";
|
|
31
|
+
/** Whether the explanation panel is open: remembered per viewer, open when storage is blocked or empty. */
|
|
32
|
+
function storedOpen() {
|
|
33
|
+
try {
|
|
34
|
+
return window.localStorage.getItem(PANEL_KEY) !== "0";
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function App() {
|
|
41
|
+
const [explainOpen, setExplainOpen] = useState(storedOpen);
|
|
42
|
+
const toggleExplain = () => {
|
|
43
|
+
const next = !explainOpen;
|
|
44
|
+
setExplainOpen(next);
|
|
45
|
+
try {
|
|
46
|
+
window.localStorage.setItem(PANEL_KEY, next ? "1" : "0");
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// storage is blocked: the choice lasts until the page closes
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const [route, go] = useRoute();
|
|
53
|
+
const narrow = useNarrow();
|
|
54
|
+
const [pane, setPane] = useState("design");
|
|
55
|
+
const screen = route.screen === null ? null : (model.screens[route.screen] ?? null);
|
|
56
|
+
const hasDesign = screen?.frame?.widths.includes(route.width) ?? false;
|
|
57
|
+
const hasShot = screen?.shots.includes(route.width) ?? false;
|
|
58
|
+
const view = effectiveView(route.view, hasDesign, hasShot);
|
|
59
|
+
const open = (id) => {
|
|
60
|
+
go({ screen: id, flows: false });
|
|
61
|
+
};
|
|
62
|
+
return (_jsx(CoreGrammarRoot, { children: _jsxs("div", { className: "sg-shell", "data-explain": explainOpen ? "open" : "closed", children: [_jsxs("header", { className: "sg-top", children: [_jsxs("div", { className: "sg-brand", children: [_jsxs("div", { className: "sg-title", children: [_jsx(Heading, { level: 1, children: fill(labels.title, { app: data.app }) }), _jsx(Text, { size: "xs", tone: "muted", tabular: true, children: model.counts.hidden > 0 ? `${summary()} · ${fill(labels.hidden, { n: model.counts.hidden })}` : summary() })] }), _jsx(Legend, { labels: labels })] }), _jsx(Tabs, { appearance: "primary", label: labels.view, selectedKey: route.flows ? "flows" : "screens", onSelect: (key) => {
|
|
63
|
+
go({ flows: key === "flows", screen: key === "flows" ? null : route.screen });
|
|
64
|
+
}, items: [
|
|
65
|
+
{ id: "screens", label: labels.screens },
|
|
66
|
+
{ id: "flows", label: labels.flows },
|
|
67
|
+
] }), screen !== null && !route.flows ? _jsx(ViewSwitches, { labels: labels, width: route.width, view: view, hasDesign: hasDesign, hasShot: hasShot, showView: !narrow, onChange: go }) : null, screen !== null && !route.flows && !narrow ? (_jsx(Tooltip, { content: explainOpen ? labels.hideExplain : labels.showExplain, trigger: _jsx(IconButton, { glyph: "panel-end", intent: "neutral", size: "sm", label: explainOpen ? labels.hideExplain : labels.showExplain, isActive: explainOpen, "aria-expanded": explainOpen, onPress: toggleExplain }) })) : null] }), _jsx("nav", { className: "sg-tree", "aria-label": labels.screens, children: _jsx(Tree, { model: model, labels: labels, selected: route.screen, onSelect: open }) }), _jsxs("main", { className: "sg-main", children: [route.flows ? _jsx(FlowMap, { model: model, labels: labels, onOpen: open }) : null, !route.flows && screen !== null ? (_jsxs(_Fragment, { children: [_jsx(States, { screen: screen, model: model, labels: labels, onOpen: open }), (!narrow && COMPARE_VIEWS.includes(view)) || (narrow && pane === "compare" && hasDesign && hasShot) ? (_jsx(CompareModes, { labels: labels, view: COMPARE_VIEWS.includes(view) ? view : "slider", onChange: (next) => {
|
|
68
|
+
go({ view: next });
|
|
69
|
+
} })) : null, hasDesign && hasShot ? null : (_jsx("div", { className: "sg-reason", children: _jsx(Text, { size: "sm", tone: "muted", children: hasDesign ? labels.reasonNoShot : labels.reasonNoDesign }) })), narrow ? (_jsx("div", { className: "sg-reason", children: _jsx(Badge, { isDot: true, tone: TONE[screen.status], children: statusLabel(labels, screen.status, screen.designStatus) }) })) : null, narrow ? (_jsx(Tabs, { appearance: "primary", label: labels.pane, selectedKey: pane, onSelect: (key) => {
|
|
70
|
+
setPane(key);
|
|
71
|
+
}, items: [
|
|
72
|
+
{ id: "design", label: labels.paneDesign, isDisabled: !hasDesign },
|
|
73
|
+
{ id: "shot", label: labels.paneShot, isDisabled: !hasShot },
|
|
74
|
+
{ id: "compare", label: labels.viewCompare, isDisabled: !(hasDesign && hasShot) },
|
|
75
|
+
{ id: "explain", label: labels.explain },
|
|
76
|
+
] })) : null, narrow && pane === "explain" ? (_jsx("div", { className: "sg-explain-narrow", children: _jsx(ExplainPanel, { screen: screen, labels: labels, devUrl: devUrl }) })) : (_jsx(Viewer, { screen: screen, model: model, labels: labels, width: route.width, view: view, pane: narrow ? (pane === "explain" ? "design" : pane) : null, onOpen: open }))] })) : null, !route.flows && screen === null ? _jsx(Text, { tone: "muted", children: model.counts.total === 0 ? labels.empty : labels.screens }) : null] }), !route.flows && screen !== null && explainOpen && !narrow ? (_jsx("aside", { className: "sg-explain", "aria-label": labels.explain, children: _jsx(ExplainPanel, { screen: screen, labels: labels, devUrl: devUrl }) })) : null] }) }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Labels } from "../labels.js";
|
|
3
|
+
import type { Screen } from "../model.js";
|
|
4
|
+
export interface ExplainProps {
|
|
5
|
+
readonly screen: Screen;
|
|
6
|
+
readonly labels: Labels;
|
|
7
|
+
readonly devUrl: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The explain.md of a screen: its id and status, the way to the dev app, the overview first (the introduction as rows, then the business regions), and each other region as one
|
|
11
|
+
* disclosure, closed, so its title stays visible and its Vì sao, Luật and Grammar lines open on a press.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ExplainPanel({ screen, labels, devUrl }: ExplainProps): ReactElement;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Badge, Divider, DisclosureList, Heading, Link, Section, Text } from "@starci/grammar/core";
|
|
3
|
+
import { FIELDS, introClauses } from "../explain.js";
|
|
4
|
+
import { fill } from "../labels.js";
|
|
5
|
+
import { devPath } from "../model.js";
|
|
6
|
+
import { cap } from "./cap.js";
|
|
7
|
+
import { Inline } from "./inline.js";
|
|
8
|
+
import { statusLabel, TONE } from "./status.js";
|
|
9
|
+
/** A region that is the business reading of the screen (Nghiệp vụ, Tổng quan, Phản biện): read first, open. Every other region folds its lines behind its title. */
|
|
10
|
+
const OVERVIEW = /nghiệp vụ|tổng quan|phản biện|overview|business|critique/iu;
|
|
11
|
+
const isOverview = (region) => OVERVIEW.test(region.name);
|
|
12
|
+
function Rows({ region, labels }) {
|
|
13
|
+
return (_jsxs("dl", { className: "sg-rows", children: [region.problems.map((problem) => (_jsx("div", { className: "sg-row", children: _jsx(Badge, { tone: "danger", children: fill(problem.kind === "missing" ? labels.problemMissing : labels.problemUnclear, { field: problem.field }) }) }, `${problem.kind}-${problem.field}`))), FIELDS.map((field) => {
|
|
14
|
+
const value = region.fields[field];
|
|
15
|
+
return value === undefined || value === "" ? null : (_jsxs("div", { className: "sg-row", children: [_jsx("dt", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: field }) }), _jsx("dd", { children: _jsx(Text, { size: "sm", children: _jsx(Inline, { text: value }) }) })] }, field));
|
|
16
|
+
})] }));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The explain.md of a screen: its id and status, the way to the dev app, the overview first (the introduction as rows, then the business regions), and each other region as one
|
|
20
|
+
* disclosure, closed, so its title stays visible and its Vì sao, Luật and Grammar lines open on a press.
|
|
21
|
+
*/
|
|
22
|
+
export function ExplainPanel({ screen, labels, devUrl }) {
|
|
23
|
+
const explain = screen.explain;
|
|
24
|
+
const dev = devUrl !== null && devPath(screen.route) !== null ? `${devUrl.replace(/\/$/u, "")}${screen.route ?? ""}` : null;
|
|
25
|
+
const regions = explain?.regions ?? [];
|
|
26
|
+
const overview = regions.filter(isOverview);
|
|
27
|
+
const rest = regions.filter((region) => !isOverview(region));
|
|
28
|
+
return (_jsxs("div", { className: "sg-explain-body", children: [_jsxs("div", { className: "sg-explain-head", children: [_jsx(Heading, { level: 2, children: cap(screen.title) }), _jsxs("div", { className: "sg-chips", children: [_jsx(Badge, { isDot: true, tone: TONE[screen.status], children: statusLabel(labels, screen.status, screen.designStatus) }), _jsx(Text, { size: "xs", tone: "muted", mono: true, children: screen.id })] }), screen.status === "unrecorded" || screen.status === "codedOnly" ? (_jsx(Text, { size: "sm", tone: "muted", children: labels.unrecordedHint })) : null, screen.route === null ? null : (_jsx(Text, { size: "sm", tone: "muted", mono: true, children: `${labels.route}: ${screen.route}` })), _jsxs("div", { className: "sg-chips", children: [dev === null ? null : (_jsx(Link, { href: dev, kind: "external", externalHint: "", children: labels.openDev })), screen.board === null ? null : (_jsx(Link, { href: screen.board, kind: "external", externalHint: "", children: labels.board }))] })] }), _jsx(Divider, {}), explain === null ? _jsx(Text, { tone: "muted", children: labels.noExplain }) : null, explain !== null && explain.intro !== "" ? (_jsx(Section, { title: labels.intro, children: _jsx("dl", { className: "sg-rows", children: introClauses(explain.intro).map((row, index) => (_jsxs("div", { className: "sg-row", children: [row.label === null ? null : (_jsx("dt", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: row.label }) })), _jsx("dd", { children: _jsx(Text, { size: "sm", children: _jsx(Inline, { text: row.text }) }) })] }, index))) }) })) : null, explain !== null && regions.length === 0 ? _jsx(Badge, { tone: "danger", children: labels.noRegions }) : null, overview.map((region) => (_jsx(Section, { title: cap(region.name), children: _jsx(Rows, { region: region, labels: labels }) }, region.name))), rest.length === 0 ? null : (_jsx(Section, { title: labels.regions, children: _jsx(DisclosureList, { label: labels.regions, items: rest.map((region) => ({
|
|
29
|
+
id: region.name,
|
|
30
|
+
title: cap(region.name),
|
|
31
|
+
headingLevel: 3,
|
|
32
|
+
...(region.problems.length === 0 ? {} : { summary: fill(labels.problems, { n: region.problems.length }) }),
|
|
33
|
+
body: _jsx(Rows, { region: region, labels: labels }),
|
|
34
|
+
})) }) }))] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Labels } from "../labels.js";
|
|
3
|
+
import type { Model } from "../model.js";
|
|
4
|
+
/** The flow map (PROJECT-GALLERY-3): each named flow as its screens in order, then every link of every links.json as an edge. Each step opens its screen. */
|
|
5
|
+
export declare function FlowMap({ model, labels, onOpen }: {
|
|
6
|
+
readonly model: Model;
|
|
7
|
+
readonly labels: Labels;
|
|
8
|
+
readonly onOpen: (id: string) => void;
|
|
9
|
+
}): ReactElement;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Section, Text } from "@starci/grammar/core";
|
|
3
|
+
import { cap } from "./cap.js";
|
|
4
|
+
/** The flow map (PROJECT-GALLERY-3): each named flow as its screens in order, then every link of every links.json as an edge. Each step opens its screen. */
|
|
5
|
+
export function FlowMap({ model, labels, onOpen }) {
|
|
6
|
+
const edges = Object.values(model.screens).flatMap((screen) => screen.links.map((link) => [screen.id, link.to]));
|
|
7
|
+
if (model.flows.length === 0 && edges.length === 0)
|
|
8
|
+
return _jsx(Text, { tone: "muted", children: labels.noFlows });
|
|
9
|
+
const step = (id) => {
|
|
10
|
+
const screen = model.screens[id];
|
|
11
|
+
return screen === undefined ? (_jsx(Text, { tone: "muted", mono: true, children: id }, id)) : (_jsxs("button", { type: "button", className: "sg-step", onClick: () => { onOpen(id); }, children: [_jsx(Text, { size: "sm", isStrong: true, children: cap(screen.title) }), _jsx(Text, { size: "xs", tone: "muted", mono: true, children: id })] }, id));
|
|
12
|
+
};
|
|
13
|
+
return (_jsxs("div", { className: "sg-flows", children: [model.flows.map((flow) => (_jsx(Section, { title: cap(flow.name), children: _jsx("ol", { className: "sg-flow", children: flow.screens.map((id, index) => (_jsxs("li", { className: "sg-edge", children: [index > 0 ? _jsx(Text, { tone: "muted", children: "\u2192" }) : null, step(id)] }, `${id}-${String(index)}`))) }) }, flow.name))), edges.length > 0 ? (_jsx(Section, { title: labels.linksHeading, children: _jsx("ul", { className: "sg-edges", children: edges.map(([from, to], index) => (_jsxs("li", { className: "sg-edge", children: [step(from), _jsx(Text, { tone: "muted", children: "\u2192" }), step(to)] }, `${from}-${to}-${String(index)}`))) }) })) : null] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Labels } from "../labels.js";
|
|
3
|
+
/** What each dot means: an info icon button of the top bar, named and explained by a tooltip, opening a popover. */
|
|
4
|
+
export declare function Legend({ labels }: {
|
|
5
|
+
readonly labels: Labels;
|
|
6
|
+
}): ReactElement;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IconButton, Popover, StatusDot, Text, Tooltip } from "@starci/grammar/core";
|
|
3
|
+
import { dotTone, statusLabel } from "./status.js";
|
|
4
|
+
/** The statuses a dot can show, one row each (a screen with no design and no shot has no dot). `codedOnly` shares the dot of `unrecorded`. */
|
|
5
|
+
const ROWS = ["matches", "differs", "stale", "unrecorded", "codedOnly", "notBuilt"];
|
|
6
|
+
/** What each dot means: an info icon button of the top bar, named and explained by a tooltip, opening a popover. */
|
|
7
|
+
export function Legend({ labels }) {
|
|
8
|
+
return (_jsx(Popover, { title: labels.legend, placement: "bottom", trigger: _jsx(Tooltip, { content: labels.legend, trigger: _jsx(IconButton, { glyph: "info", label: labels.legend, intent: "neutral", size: "sm" }) }), children: _jsx("ul", { className: "sg-legend", children: ROWS.map((status) => (_jsxs("li", { children: [_jsx(StatusDot, { tone: dotTone(status), "aria-label": statusLabel(labels, status) }), _jsx(Text, { size: "sm", children: statusLabel(labels, status) })] }, status))) }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Width } from "../explain.js";
|
|
3
|
+
import type { Labels } from "../labels.js";
|
|
4
|
+
import type { Screen } from "../model.js";
|
|
5
|
+
/** What the lightbox opens: the approved design frame or the real shot. */
|
|
6
|
+
export type LightboxKind = "design" | "shot";
|
|
7
|
+
export interface LightboxProps {
|
|
8
|
+
readonly screen: Screen;
|
|
9
|
+
readonly kind: LightboxKind;
|
|
10
|
+
readonly width: Width;
|
|
11
|
+
readonly labels: Labels;
|
|
12
|
+
readonly onClose: () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A frame or a shot at full size in a modal Dialog (focus trapped, Escape or a press outside closes it): step 1 fits the width of the view, the buttons
|
|
16
|
+
* and the `+`, `-` and `0` keys zoom, a drag pans, and the arrow keys scroll it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Lightbox({ screen, kind, width, labels, onClose }: LightboxProps): ReactElement;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Dialog, Text } from "@starci/grammar/core";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { frameFile } from "../frames.js";
|
|
5
|
+
import { cap } from "./cap.js";
|
|
6
|
+
/** The lightbox pads its scroll area by 0.5rem on each side (app.css `.sg-lightbox`). */
|
|
7
|
+
const LIGHTBOX_PADDING = 16;
|
|
8
|
+
const STEPS = [0.5, 0.75, 1, 1.5, 2, 3];
|
|
9
|
+
const base = () => import.meta.env.BASE_URL;
|
|
10
|
+
/**
|
|
11
|
+
* A frame or a shot at full size in a modal Dialog (focus trapped, Escape or a press outside closes it): step 1 fits the width of the view, the buttons
|
|
12
|
+
* and the `+`, `-` and `0` keys zoom, a drag pans, and the arrow keys scroll it.
|
|
13
|
+
*/
|
|
14
|
+
export function Lightbox({ screen, kind, width, labels, onClose }) {
|
|
15
|
+
const [step, setStep] = useState(2);
|
|
16
|
+
const [view, setView] = useState(null);
|
|
17
|
+
const [viewWidth, setViewWidth] = useState(0);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (view === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
const observer = new ResizeObserver(() => {
|
|
22
|
+
setViewWidth(view.clientWidth);
|
|
23
|
+
});
|
|
24
|
+
observer.observe(view);
|
|
25
|
+
setViewWidth(view.clientWidth);
|
|
26
|
+
return () => {
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
};
|
|
29
|
+
}, [view]);
|
|
30
|
+
const drag = useRef(null);
|
|
31
|
+
const zoom = STEPS[step] ?? 1;
|
|
32
|
+
const natural = width === "390" ? 390 : 1440;
|
|
33
|
+
const drawn = width === "390" ? "390" : "1440";
|
|
34
|
+
const height = screen.frame?.heights[drawn] ?? 900;
|
|
35
|
+
const stage = Math.max(viewWidth - LIGHTBOX_PADDING, 0) * zoom;
|
|
36
|
+
const clamp = (next) => {
|
|
37
|
+
setStep(Math.min(STEPS.length - 1, Math.max(0, next)));
|
|
38
|
+
};
|
|
39
|
+
const onKey = (event) => {
|
|
40
|
+
if (event.key === "+" || event.key === "=")
|
|
41
|
+
clamp(step + 1);
|
|
42
|
+
else if (event.key === "-")
|
|
43
|
+
clamp(step - 1);
|
|
44
|
+
else if (event.key === "0")
|
|
45
|
+
setStep(2);
|
|
46
|
+
};
|
|
47
|
+
const onDown = (event) => {
|
|
48
|
+
if (view === null)
|
|
49
|
+
return;
|
|
50
|
+
drag.current = { x: event.clientX, y: event.clientY, left: view.scrollLeft, top: view.scrollTop };
|
|
51
|
+
view.setPointerCapture(event.pointerId);
|
|
52
|
+
};
|
|
53
|
+
const onMove = (event) => {
|
|
54
|
+
const start = drag.current;
|
|
55
|
+
if (start === null || view === null)
|
|
56
|
+
return;
|
|
57
|
+
view.scrollLeft = start.left - (event.clientX - start.x);
|
|
58
|
+
view.scrollTop = start.top - (event.clientY - start.y);
|
|
59
|
+
};
|
|
60
|
+
return (_jsx(Dialog, { isOpen: true, onOpenChange: (open) => {
|
|
61
|
+
if (!open)
|
|
62
|
+
onClose();
|
|
63
|
+
}, title: cap(screen.title), description: `${screen.id} · ${width}`, closeLabel: labels.close, size: "full", footer: _jsxs("div", { className: "sg-zoom", children: [_jsx(Button, { intent: "neutral", size: "sm", isDisabled: step === 0, onPress: () => { clamp(step - 1); }, children: labels.zoomOut }), _jsx(Text, { size: "sm", tabular: true, children: `${String(Math.round(zoom * 100))}%` }), _jsx(Button, { intent: "neutral", size: "sm", isDisabled: step === STEPS.length - 1, onPress: () => { clamp(step + 1); }, children: labels.zoomIn }), _jsx(Button, { intent: "neutral", size: "sm", onPress: () => { setStep(2); }, children: labels.zoomFit })] }), children: _jsx("div", { ref: setView, className: "sg-lightbox", role: "region", "aria-label": `${screen.title} ${width}`, tabIndex: 0, onKeyDown: onKey, onPointerDown: onDown, onPointerMove: onMove, onPointerUp: () => {
|
|
64
|
+
drag.current = null;
|
|
65
|
+
}, children: kind === "design" ? (_jsx("div", { className: "sg-frame", style: { width: stage, height: (height * stage) / natural }, children: _jsx("iframe", { title: `${labels.design} ${screen.id} ${drawn}`, src: `${base()}__frames/${frameFile(screen.id, drawn)}`, width: natural, height: height, style: { transform: `scale(${String(stage / natural)})` } }) })) : (_jsx("img", { className: "sg-lightbox-img", src: `${base()}__shots/${screen.id}/${width}.png`, alt: `${screen.id} ${width}`, style: { width: stage }, draggable: false })) }) }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Labels } from "../labels.js";
|
|
3
|
+
import type { Model, Screen } from "../model.js";
|
|
4
|
+
/** The states of the screen's page (its sibling screen folders: `-empty`, `-loading`, `-error` …), one chip each; nothing when the page has one screen only. */
|
|
5
|
+
export declare function States({ screen, model, labels, onOpen }: {
|
|
6
|
+
readonly screen: Screen;
|
|
7
|
+
readonly model: Model;
|
|
8
|
+
readonly labels: Labels;
|
|
9
|
+
readonly onOpen: (id: string) => void;
|
|
10
|
+
}): ReactElement | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tabs } from "@starci/grammar/core";
|
|
3
|
+
import { cap } from "./cap.js";
|
|
4
|
+
const stateLabel = (labels, state) => ({
|
|
5
|
+
base: labels.stateBase,
|
|
6
|
+
detail: labels.stateDetail,
|
|
7
|
+
empty: labels.stateEmpty,
|
|
8
|
+
"first-visit": labels.stateFirstVisit,
|
|
9
|
+
loading: labels.stateLoading,
|
|
10
|
+
error: labels.stateError,
|
|
11
|
+
"no-match": labels.stateNoMatch,
|
|
12
|
+
editing: labels.stateEditing,
|
|
13
|
+
})[state];
|
|
14
|
+
/** The states of the screen's page (its sibling screen folders: `-empty`, `-loading`, `-error` …), one chip each; nothing when the page has one screen only. */
|
|
15
|
+
export function States({ screen, model, labels, onOpen }) {
|
|
16
|
+
const ids = model.pages[screen.page] ?? [];
|
|
17
|
+
if (ids.length < 2)
|
|
18
|
+
return null;
|
|
19
|
+
return (_jsx(Tabs, { kind: "filter", label: labels.states, selectedKey: screen.id, onSelect: onOpen, items: ids.map((id) => {
|
|
20
|
+
const one = model.screens[id];
|
|
21
|
+
return { id, label: cap(one === undefined ? id : stateLabel(labels, one.state)) };
|
|
22
|
+
}) }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Labels } from "../labels.js";
|
|
3
|
+
import type { Model } from "../model.js";
|
|
4
|
+
export interface TreeProps {
|
|
5
|
+
readonly model: Model;
|
|
6
|
+
readonly labels: Labels;
|
|
7
|
+
readonly selected: string | null;
|
|
8
|
+
readonly onSelect: (id: string) => void;
|
|
9
|
+
}
|
|
10
|
+
/** The areas and their screens, each screen with the dot of its status, narrowed by the search. */
|
|
11
|
+
export declare function Tree({ model, labels, selected, onSelect }: TreeProps): ReactElement;
|
package/dist/app/Tree.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ListBox, SearchField, StatusDot, Text } from "@starci/grammar/core";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { cap } from "./cap.js";
|
|
5
|
+
import { dotTone, statusLabel } from "./status.js";
|
|
6
|
+
/** The areas and their screens, each screen with the dot of its status, narrowed by the search. */
|
|
7
|
+
export function Tree({ model, labels, selected, onSelect }) {
|
|
8
|
+
const [query, setQuery] = useState("");
|
|
9
|
+
const sections = useMemo(() => {
|
|
10
|
+
const needle = query.trim().toLowerCase();
|
|
11
|
+
return model.areas
|
|
12
|
+
.map((area) => ({
|
|
13
|
+
id: `area:${area.area}`,
|
|
14
|
+
label: cap(area.area),
|
|
15
|
+
items: area.screens
|
|
16
|
+
.filter((screen) => needle === "" || screen.id.toLowerCase().includes(needle) || screen.title.toLowerCase().includes(needle))
|
|
17
|
+
.map((screen) => ({
|
|
18
|
+
id: screen.id,
|
|
19
|
+
label: cap(screen.title),
|
|
20
|
+
labelLeading: screen.status === "none" ? undefined : _jsx(StatusDot, { tone: dotTone(screen.status), "aria-label": statusLabel(labels, screen.status, screen.designStatus) }),
|
|
21
|
+
description: screen.name,
|
|
22
|
+
descriptionLines: 1,
|
|
23
|
+
size: "sm",
|
|
24
|
+
})),
|
|
25
|
+
}))
|
|
26
|
+
.filter((section) => section.items.length > 0);
|
|
27
|
+
}, [model, labels, query]);
|
|
28
|
+
return (_jsxs("div", { className: "sg-tree-body", children: [_jsx(SearchField, { label: labels.search, isLabelHidden: true, placeholder: labels.search, value: query, onValueChange: setQuery, onClear: () => { setQuery(""); }, clearLabel: labels.clear }), _jsx(ListBox, { label: labels.screens, sections: sections, size: "sm", selectionMode: "single", selectionIndicator: "none", selectedIds: selected === null ? [] : [selected], onSelectionChange: (ids) => { const next = ids[0]; if (next !== undefined)
|
|
29
|
+
onSelect(next); }, emptyContent: _jsx(Text, { tone: "muted", children: labels.noScreens }) })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Width } from "../explain.js";
|
|
3
|
+
import type { Labels } from "../labels.js";
|
|
4
|
+
import type { Model, Screen } from "../model.js";
|
|
5
|
+
import type { View } from "../views.js";
|
|
6
|
+
import type { Pane } from "./route.js";
|
|
7
|
+
export interface ViewerProps {
|
|
8
|
+
readonly screen: Screen;
|
|
9
|
+
readonly model: Model;
|
|
10
|
+
readonly labels: Labels;
|
|
11
|
+
readonly width: Width;
|
|
12
|
+
/** The view of a wide window: the design, a comparison of design and shot, the shot. */
|
|
13
|
+
readonly view: View;
|
|
14
|
+
/** The pane of a narrow window (one at a time): design, shot or the comparison (its way is `view`). */
|
|
15
|
+
readonly pane: Exclude<Pane, "explain"> | null;
|
|
16
|
+
readonly onOpen: (id: string) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The viewer: the design frame alone, the real shot alone, or the two compared: side by side, a slider that wipes the shot over the design, an onion skin (the shot over the
|
|
20
|
+
* design at an opacity), a difference (the shot over the design with mix-blend-mode difference, so a shape that differs lights up). Both images are aligned to the same
|
|
21
|
+
* width at the top left. Each frame opens full size on a press; in a narrow window one pane shows at a time.
|
|
22
|
+
*/
|
|
23
|
+
export declare function Viewer({ screen, model, labels, width, view, pane, onOpen }: ViewerProps): ReactElement;
|
|
24
|
+
export interface SwitchesProps {
|
|
25
|
+
readonly labels: Labels;
|
|
26
|
+
readonly width: Width;
|
|
27
|
+
readonly view: View;
|
|
28
|
+
/** Whether the screen has a design frame and a shot at this width: a view that needs the missing one is disabled. */
|
|
29
|
+
readonly hasDesign: boolean;
|
|
30
|
+
readonly hasShot: boolean;
|
|
31
|
+
readonly showView: boolean;
|
|
32
|
+
readonly onChange: (next: {
|
|
33
|
+
width?: Width;
|
|
34
|
+
view?: View;
|
|
35
|
+
}) => void;
|
|
36
|
+
}
|
|
37
|
+
/** The widths and, in a wide window, the three views (Bản vẽ, Đối chiếu, Ảnh thật); a view with only one side to show is disabled, and the reason stands beside. */
|
|
38
|
+
export declare function ViewSwitches({ labels, width, view, hasDesign, hasShot, showView, onChange }: SwitchesProps): ReactElement;
|
|
39
|
+
/** The ways to compare, under the Đối chiếu view. */
|
|
40
|
+
export declare function CompareModes({ labels, view, onChange }: {
|
|
41
|
+
readonly labels: Labels;
|
|
42
|
+
readonly view: View;
|
|
43
|
+
readonly onChange: (view: View) => void;
|
|
44
|
+
}): ReactElement;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Slider, Tabs, Text } from "@starci/grammar/core";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { frameFile } from "../frames.js";
|
|
5
|
+
import { fill } from "../labels.js";
|
|
6
|
+
import { Lightbox } from "./Lightbox.js";
|
|
7
|
+
import { COMPARE_VIEWS } from "../views.js";
|
|
8
|
+
const pct = (fraction) => `${String((fraction ?? 0) * 100)}%`;
|
|
9
|
+
const base = () => import.meta.env.BASE_URL;
|
|
10
|
+
/** A phone screen is drawn no wider than this on the board; a desktop one takes the width its host gives it. */
|
|
11
|
+
const PHONE_STAGE = 520;
|
|
12
|
+
/** The board pads its content by 1rem on each side (app.css `.sg-board`); the frames are scaled to what is left. */
|
|
13
|
+
const BOARD_PADDING = 32;
|
|
14
|
+
/** Side by side holds while each column keeps at least this width; below it the two stack. */
|
|
15
|
+
const MIN_COLUMN = 320;
|
|
16
|
+
const COLUMN_GAP = 16;
|
|
17
|
+
/** The design.json statuses from which the drawing is the approved one. */
|
|
18
|
+
const APPROVED = ["approved", "built", "matches"];
|
|
19
|
+
/** The width of an element, followed while the window is resized. */
|
|
20
|
+
function useWidth() {
|
|
21
|
+
const ref = useRef(null);
|
|
22
|
+
const [width, setWidth] = useState(0);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const node = ref.current;
|
|
25
|
+
if (node === null)
|
|
26
|
+
return undefined;
|
|
27
|
+
const observer = new ResizeObserver(() => {
|
|
28
|
+
setWidth(node.clientWidth);
|
|
29
|
+
});
|
|
30
|
+
observer.observe(node);
|
|
31
|
+
setWidth(node.clientWidth);
|
|
32
|
+
return () => {
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return [ref, width];
|
|
37
|
+
}
|
|
38
|
+
/** The approved design frame of a screen at real pixels, scaled to fill the width its host gives it, aspect kept. */
|
|
39
|
+
function DesignFrame({ screen, width, labels, available, onOpen }) {
|
|
40
|
+
const [measured, setMeasured] = useState(null);
|
|
41
|
+
const frame = screen.frame;
|
|
42
|
+
if (!frame?.widths.includes(width))
|
|
43
|
+
return _jsx(Text, { tone: "muted", children: labels.noDesign });
|
|
44
|
+
const natural = Number(width);
|
|
45
|
+
const height = frame.heights[width] ?? measured ?? 900;
|
|
46
|
+
const scale = available > 0 ? available / natural : 1;
|
|
47
|
+
return (_jsxs("div", { className: "sg-frame", style: { height: height * scale }, children: [_jsx("iframe", { title: `${labels.design} ${screen.id} ${width}`, src: `${base()}__frames/${frameFile(screen.id, width)}`, width: natural, height: height, style: { transform: `scale(${String(scale)})` }, tabIndex: -1, onLoad: (event) => {
|
|
48
|
+
const body = event.currentTarget.contentDocument?.body;
|
|
49
|
+
if (body && frame.heights[width] === undefined)
|
|
50
|
+
setMeasured(body.scrollHeight);
|
|
51
|
+
} }), onOpen === undefined ? null : _jsx("button", { type: "button", className: "sg-open", "aria-label": labels.openFrame, title: labels.openFrame, onClick: onOpen })] }));
|
|
52
|
+
}
|
|
53
|
+
/** The real shot with the hotspots of links.json over it; a press elsewhere opens it full size. */
|
|
54
|
+
function Shot({ screen, width, labels, model, onOpenScreen, onOpen }) {
|
|
55
|
+
if (!screen.shots.includes(width))
|
|
56
|
+
return _jsx(Text, { tone: "muted", children: screen.shots.length === 0 ? labels.noShot : labels.noShotAtWidth });
|
|
57
|
+
return (_jsxs("div", { className: "sg-shot", children: [_jsx("img", { src: `${base()}__shots/${screen.id}/${width}.png`, alt: `${screen.id} ${width}` }), onOpen === undefined ? null : _jsx("button", { type: "button", className: "sg-open", "aria-label": labels.openFrame, title: labels.openFrame, onClick: onOpen }), screen.links.map((link, index) => (_jsx("button", { type: "button", className: "sg-hotspot", title: fill(labels.openScreen, { to: link.to }), "aria-label": fill(labels.openScreen, { to: link.to }), disabled: model.screens[link.to] === undefined, style: { left: pct(link.x), top: pct(link.y), width: pct(link.w), height: pct(link.h) }, onClick: () => {
|
|
58
|
+
onOpenScreen(link.to);
|
|
59
|
+
} }, index)))] }));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The viewer: the design frame alone, the real shot alone, or the two compared: side by side, a slider that wipes the shot over the design, an onion skin (the shot over the
|
|
63
|
+
* design at an opacity), a difference (the shot over the design with mix-blend-mode difference, so a shape that differs lights up). Both images are aligned to the same
|
|
64
|
+
* width at the top left. Each frame opens full size on a press; in a narrow window one pane shows at a time.
|
|
65
|
+
*/
|
|
66
|
+
export function Viewer({ screen, model, labels, width, view, pane, onOpen }) {
|
|
67
|
+
const [ref, outer] = useWidth();
|
|
68
|
+
const [amount, setAmount] = useState(50);
|
|
69
|
+
const [lightbox, setLightbox] = useState(null);
|
|
70
|
+
const available = Math.max(outer - BOARD_PADDING, 0);
|
|
71
|
+
const designTitle = screen.designStatus !== null && APPROVED.includes(screen.designStatus) ? labels.designApproved : labels.design;
|
|
72
|
+
const narrow = pane !== null;
|
|
73
|
+
const mode = narrow ? (pane === "design" ? "design" : pane === "shot" ? "shot" : COMPARE_VIEWS.includes(view) ? view : "slider") : view;
|
|
74
|
+
const columns = mode === "side" && available >= 2 * MIN_COLUMN + COLUMN_GAP ? 2 : 1;
|
|
75
|
+
const each = columns === 2 ? (available - COLUMN_GAP) / 2 : available;
|
|
76
|
+
const cap = (value) => (width === "390" ? Math.min(value, PHONE_STAGE) : value);
|
|
77
|
+
const open = (kind) => () => {
|
|
78
|
+
setLightbox(kind);
|
|
79
|
+
};
|
|
80
|
+
const overlay = mode === "slider" || mode === "onion" || mode === "diff";
|
|
81
|
+
const overStyle = mode === "slider" ? { clipPath: `inset(0 ${String(100 - amount)}% 0 0)` } : mode === "onion" ? { opacity: amount / 100 } : mode === "diff" ? { mixBlendMode: "difference" } : {};
|
|
82
|
+
return (_jsxs("div", { ref: ref, className: "sg-board", children: [mode === "side" ? (_jsxs("div", { className: "sg-columns", "data-columns": columns, children: [_jsxs("figure", { children: [_jsx("figcaption", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: designTitle }) }), _jsx(DesignFrame, { screen: screen, width: width, labels: labels, available: cap(each), onOpen: open("design") })] }), _jsxs("figure", { children: [_jsx("figcaption", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: labels.shot }) }), _jsx("div", { style: width === "390" ? { maxWidth: PHONE_STAGE } : undefined, children: _jsx(Shot, { screen: screen, width: width, labels: labels, model: model, onOpenScreen: onOpen, onOpen: open("shot") }) })] })] })) : null, mode === "design" ? (_jsxs("figure", { className: "sg-single", children: [_jsx("figcaption", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: designTitle }) }), _jsx(DesignFrame, { screen: screen, width: width, labels: labels, available: cap(available), onOpen: open("design") })] })) : null, overlay ? (_jsxs("div", { className: "sg-slider", children: [mode === "diff" ? null : (_jsx(Slider, { label: mode === "onion" ? labels.onionOpacity : labels.slider, value: amount, minValue: 0, maxValue: 100, step: 1, onValueChange: (value) => {
|
|
83
|
+
setAmount(typeof value === "number" ? value : (value[0] ?? 50));
|
|
84
|
+
} })), _jsxs("div", { className: "sg-stage", "data-mode": mode, style: width === "390" ? { maxWidth: PHONE_STAGE } : undefined, children: [_jsx("div", { className: "sg-under", children: _jsx(DesignFrame, { screen: screen, width: width, labels: labels, available: cap(available) }) }), _jsx("div", { className: "sg-over", style: overStyle, children: _jsx(Shot, { screen: screen, width: width, labels: labels, model: model, onOpenScreen: onOpen }) }), mode === "slider" ? _jsx("div", { className: "sg-handle", style: { left: `${String(amount)}%` }, "aria-hidden": "true" }) : null] })] })) : null, mode === "shot" ? (_jsxs("figure", { className: "sg-single", style: width === "390" ? { maxWidth: PHONE_STAGE } : undefined, children: [_jsx("figcaption", { children: _jsx(Text, { size: "xs", tone: "muted", isStrong: true, children: labels.shot }) }), _jsx(Shot, { screen: screen, width: width, labels: labels, model: model, onOpenScreen: onOpen, onOpen: open("shot") })] })) : null, lightbox === null ? null : (_jsx(Lightbox, { screen: screen, kind: lightbox, width: width, labels: labels, onClose: () => {
|
|
85
|
+
setLightbox(null);
|
|
86
|
+
} }))] }));
|
|
87
|
+
}
|
|
88
|
+
/** The widths and, in a wide window, the three views (Bản vẽ, Đối chiếu, Ảnh thật); a view with only one side to show is disabled, and the reason stands beside. */
|
|
89
|
+
export function ViewSwitches({ labels, width, view, hasDesign, hasShot, showView, onChange }) {
|
|
90
|
+
const group = view === "design" || view === "shot" ? view : "compare";
|
|
91
|
+
return (_jsxs("div", { className: "sg-switches", children: [_jsx(Tabs, { appearance: "primary", label: labels.width, selectedKey: width, onSelect: (key) => {
|
|
92
|
+
onChange({ width: key });
|
|
93
|
+
}, items: [
|
|
94
|
+
{ id: "1440", label: "1440" },
|
|
95
|
+
{ id: "390", label: "390" },
|
|
96
|
+
] }), showView ? (_jsx(Tabs, { appearance: "primary", label: labels.view, selectedKey: group, onSelect: (key) => {
|
|
97
|
+
onChange({ view: key === "compare" ? (COMPARE_VIEWS.includes(view) ? view : "side") : key });
|
|
98
|
+
}, items: [
|
|
99
|
+
{ id: "design", label: labels.viewDesign, isDisabled: !hasDesign },
|
|
100
|
+
{ id: "compare", label: labels.viewCompare, isDisabled: !(hasDesign && hasShot) },
|
|
101
|
+
{ id: "shot", label: labels.viewShot, isDisabled: !hasShot },
|
|
102
|
+
] })) : null] }));
|
|
103
|
+
}
|
|
104
|
+
/** The ways to compare, under the Đối chiếu view. */
|
|
105
|
+
export function CompareModes({ labels, view, onChange }) {
|
|
106
|
+
return (_jsx(Tabs, { kind: "filter", label: labels.viewCompare, selectedKey: view, onSelect: (key) => {
|
|
107
|
+
onChange(key);
|
|
108
|
+
}, items: [
|
|
109
|
+
{ id: "side", label: labels.viewSide },
|
|
110
|
+
{ id: "slider", label: labels.viewSlider },
|
|
111
|
+
{ id: "onion", label: labels.viewOnion },
|
|
112
|
+
{ id: "diff", label: labels.viewDiff },
|
|
113
|
+
] }));
|
|
114
|
+
}
|