grimoire3d 0.0.0-dev.ef50bb6 → 0.0.0-dev.f7e9e26
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/README.md +28 -124
- package/cli/cli.js +348 -0
- package/cli/content.js +382 -0
- package/cli/cover-options.d.ts +15 -0
- package/cli/cover-options.js +105 -0
- package/cli/markdown.js +139 -0
- package/cli/markup.d.ts +3 -0
- package/cli/markup.js +60 -0
- package/cli/routes.d.ts +6 -0
- package/cli/routes.js +19 -0
- package/cli/static-pages.js +467 -0
- package/cli/video-url.d.ts +5 -0
- package/cli/video-url.js +51 -0
- package/dist/BookViewer-CwCn-LTn.js +332 -0
- package/dist/components/BookModel.d.ts +20 -0
- package/dist/components/BookViewer.d.ts +17 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +5 -0
- package/dist/grimoire3d.css +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/main.d.ts +1 -0
- package/dist/site/assets/BookReader-BxKrexRZ.js +2 -0
- package/dist/site/assets/BookScene-DN1_Kxe3.js +4045 -0
- package/dist/site/assets/MermaidDiagram-Dma3Cwvn.js +312 -0
- package/dist/site/assets/PageMarkdown-C-gI_dXg.js +37 -0
- package/dist/site/assets/abnfDiagram-S7VZAUFO-BIA2ezcb.js +1 -0
- package/dist/site/assets/alcove-cyX4Tv3E.avif +0 -0
- package/dist/site/assets/architectureDiagram-YGSQEFNW-DMB5UtEZ.js +36 -0
- package/dist/site/assets/blockDiagram-APKKGZFW-CeBSUSaW.js +140 -0
- package/dist/site/assets/bpmnIcons-APHXDYXF-ByGoYv9M.js +1 -0
- package/dist/site/assets/c4Diagram-KJ2TOQU5-BmBo2PHu.js +38 -0
- package/dist/site/assets/catalog-07-UR91A.avif +0 -0
- package/dist/site/assets/chunk-2Q5K7J3B-BDgDFVbx.js +1 -0
- package/dist/site/assets/chunk-5VM5RSS4-CCNs5Q1j.js +15 -0
- package/dist/site/assets/chunk-HFQBQIA3-B8uXoLoT.js +1 -0
- package/dist/site/assets/chunk-JWPE2WC7-BiKy7CcD.js +1 -0
- package/dist/site/assets/chunk-KQLB2F66-D_kpUTKA.js +2 -0
- package/dist/site/assets/chunk-KS47KZWR-C_s_qnHf.js +1 -0
- package/dist/site/assets/chunk-OY52VR5R-D8f7gl4W.js +88 -0
- package/dist/site/assets/chunk-TU62E6Q5-Bm44Znlj.js +1 -0
- package/dist/site/assets/chunk-XXDRQBXY-ChLLr56_.js +1 -0
- package/dist/site/assets/classDiagram-v2-L25IHNXF-DwKi-r2i.js +217 -0
- package/dist/site/assets/cose-bilkent-JH36ORCC-8N6YUm1i.js +1 -0
- package/dist/site/assets/cover-blue-Bh8Xp4T5.avif +0 -0
- package/dist/site/assets/cover-blue-mobile-YcuYIg0I.avif +0 -0
- package/dist/site/assets/cover-green-By13JjUx.avif +0 -0
- package/dist/site/assets/cover-green-mobile-BNTgNt7v.avif +0 -0
- package/dist/site/assets/cover-red-mobile-DHOCz3wI.avif +0 -0
- package/dist/site/assets/cover-red-qvZEk3PI.avif +0 -0
- package/dist/site/assets/cynefin-EF2NZ3EQ-Df5ATUPb.js +141 -0
- package/dist/site/assets/cynefinDiagram-L36ESFBY-DmAbfxAU.js +62 -0
- package/dist/site/assets/cytoscape.esm-BHa1VTXv.js +321 -0
- package/dist/site/assets/d3-scale-4DPf7zan.js +1 -0
- package/dist/site/assets/dagre-SPEB5RXH-B_2grAE7.js +4 -0
- package/dist/site/assets/diagram-3B7GL73J-C9FXwDlf.js +200 -0
- package/dist/site/assets/diagram-DNEMPZML-DflAT3gr.js +24 -0
- package/dist/site/assets/diagram-L3MUGCDN-B04gjrM_.js +41 -0
- package/dist/site/assets/diagram-LA4NIPWU-cfWJg8HX.js +24 -0
- package/dist/site/assets/diagram-MHCOC4E2-jRbOs2Df.js +3 -0
- package/dist/site/assets/diagram-XPFHEONP-yR45xV59.js +30 -0
- package/dist/site/assets/ebnfDiagram-UZSYDL2S-DlmNJUx4.js +1 -0
- package/dist/site/assets/elk-XV6XMXQE-cHLdRN7u.js +27 -0
- package/dist/site/assets/erDiagram-EYBAPDEH-7HsRsmBI.js +99 -0
- package/dist/site/assets/es-DoLiZPBX.js +2 -0
- package/dist/site/assets/favicon-C9YRygge.png +0 -0
- package/dist/site/assets/flowDiagram-MALGAFMO-DoJjw4RA.js +213 -0
- package/dist/site/assets/ganttDiagram-23REXITY-D2uZtX_8.js +292 -0
- package/dist/site/assets/gitGraphDiagram-STJD7YCW-CjftfLRK.js +106 -0
- package/dist/site/assets/graph-D8UmR1vK.js +1 -0
- package/dist/site/assets/index-CqcyU6rA.js +1 -0
- package/dist/site/assets/index-DWW-KDWe.css +1 -0
- package/dist/site/assets/infoDiagram-KBXO4MBG-HN-1tqq1.js +2 -0
- package/dist/site/assets/ishikawaDiagram-M35NCXHK-DcnRwsO0.js +70 -0
- package/dist/site/assets/journeyDiagram-OPLOXDXO-CMZGp8mG.js +139 -0
- package/dist/site/assets/kanban-definition-BZKZHSQY-C9vGS-EW.js +89 -0
- package/dist/site/assets/katex-DLSO0Xi6.js +257 -0
- package/dist/site/assets/mindmap-definition-I2QAS2VK-R2SGME7R.js +98 -0
- package/dist/site/assets/mobile-cabinet-BUr9vtlo.avif +0 -0
- package/dist/site/assets/mobile-cabinet-sm-pauJUfRH.avif +0 -0
- package/dist/site/assets/mobile-paper-DF0CuLes.avif +0 -0
- package/dist/site/assets/mobile-paper-sm-77eJHX6h.avif +0 -0
- package/dist/site/assets/open-nWGD2hyb.glb +0 -0
- package/dist/site/assets/pegDiagram-FD4XPPHP-eDMY4Hpd.js +1 -0
- package/dist/site/assets/pieDiagram-J4AKIIQI-DoHNiqwi.js +39 -0
- package/dist/site/assets/quadrantDiagram-XTYBLID2-Bz5idec8.js +7 -0
- package/dist/site/assets/railroadDiagram-MRQ6NCDL-DHJisW8P.js +1 -0
- package/dist/site/assets/requirementDiagram-Y7LWUY3S-5aETRIZz.js +84 -0
- package/dist/site/assets/resting-amber-BSjsErIg.avif +0 -0
- package/dist/site/assets/resting-black-DDQ4XMJI.avif +0 -0
- package/dist/site/assets/resting-blue-DDOT8IQ8.avif +0 -0
- package/dist/site/assets/resting-green-DkRrV8eX.avif +0 -0
- package/dist/site/assets/resting-ivory-CEqoG5yI.avif +0 -0
- package/dist/site/assets/resting-plum-B-8tkSmP.avif +0 -0
- package/dist/site/assets/resting-red-D0hLpMpz.avif +0 -0
- package/dist/site/assets/resting-slate-CH8Z_Rky.avif +0 -0
- package/dist/site/assets/resting-teal-CGt6jFmT.avif +0 -0
- package/dist/site/assets/resting-walnut-t3WgHgUO.avif +0 -0
- package/dist/site/assets/sankeyDiagram-WGJFYUXA-C7O4v9rg.js +40 -0
- package/dist/site/assets/search-stage-B8cH1AE_.avif +0 -0
- package/dist/site/assets/search-stage-mobile-BZ58ew4F.avif +0 -0
- package/dist/site/assets/sequenceDiagram-5NDRBG5M-D4sVU6s6.js +169 -0
- package/dist/site/assets/sizeCapture-INFHLROL-Bi2DkFS3.js +1 -0
- package/dist/site/assets/stateDiagram-v2-FJ4FJNEA-WqXK7YOd.js +291 -0
- package/dist/site/assets/swimlanes-UMQ2AFYF-Czo9WyoV.js +1 -0
- package/dist/site/assets/swimlanesDiagram-OMPLPG4O-BH5aEx0X.js +8 -0
- package/dist/site/assets/three-core-Dkab0Vtn.js +40 -0
- package/dist/site/assets/timeline-definition-SEUHKTQE-KGKDZW_q.js +120 -0
- package/dist/site/assets/usecaseDiagram-AFA6YXN4-S0_9S22K.js +370 -0
- package/dist/site/assets/vennDiagram-NNMJR3RB-DJOjLlbA.js +34 -0
- package/dist/site/assets/wardleyDiagram-S7YFUSEH-BnzYzY-n.js +78 -0
- package/dist/site/assets/xychartDiagram-GGNKY7IX-CKOVznoa.js +7 -0
- package/dist/site/index.html +14 -0
- package/dist/types/index.d.ts +163 -0
- package/package.json +27 -11
- package/dist/grimoire3d.js +0 -54501
- package/dist/grimoire3d.umd.cjs +0 -4212
package/cli/content.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { extname, isAbsolute, join, posix, relative, sep } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
import { coverOptions } from "./cover-options.js";
|
|
5
|
+
import { readMarkdown } from "./markdown.js";
|
|
6
|
+
|
|
7
|
+
const rootId = "_root";
|
|
8
|
+
const languages = new Set(["en", "ja"]);
|
|
9
|
+
const collator = new Intl.Collator("en", { numeric: true });
|
|
10
|
+
|
|
11
|
+
function sortNames(a, b) {
|
|
12
|
+
return collator.compare(a, b) || (a < b ? -1 : Number(a > b));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function titleFromPath(path) {
|
|
16
|
+
return path.replace(/^\d+[-_]+/, "").replace(/[-_]+/g, " ");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function visibleEntry(name) {
|
|
20
|
+
return !name.startsWith(".") && !name.startsWith("_") && name !== "assets";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isMarkdown(name) {
|
|
24
|
+
return extname(name).toLowerCase() === ".md";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function pageId(path) {
|
|
28
|
+
return path.replace(/\.md$/i, "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function encodePath(path) {
|
|
32
|
+
return path.split("/").map(encodeURIComponent).join("/");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function readPages(root, directory, nested) {
|
|
36
|
+
const entries = (
|
|
37
|
+
await readdir(join(root, directory), { withFileTypes: true })
|
|
38
|
+
)
|
|
39
|
+
.filter((entry) => visibleEntry(entry.name))
|
|
40
|
+
.sort((a, b) => sortNames(a.name, b.name));
|
|
41
|
+
const pages = [];
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const path = posix.join(directory, entry.name);
|
|
44
|
+
if (entry.isDirectory() && nested) {
|
|
45
|
+
pages.push(...(await readPages(root, path, true)));
|
|
46
|
+
} else if (entry.isFile() && isMarkdown(entry.name)) {
|
|
47
|
+
const markdown = await readFile(join(root, path), "utf8");
|
|
48
|
+
pages.push({ path, ...readMarkdown(markdown) });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return pages;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function comparePages(a, b) {
|
|
55
|
+
// Treat index.md as the first page of its folder, without reordering the folders.
|
|
56
|
+
return sortNames(
|
|
57
|
+
a.path.replace(/(^|\/)index\.md$/i, "$1!index.md"),
|
|
58
|
+
b.path.replace(/(^|\/)index\.md$/i, "$1!index.md")
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function describeBook(pages, folder, fallback) {
|
|
63
|
+
const index = pages.find(
|
|
64
|
+
(page) =>
|
|
65
|
+
page.path.toLowerCase() === posix.join(folder, "index.md").toLowerCase()
|
|
66
|
+
);
|
|
67
|
+
const id = folder || rootId;
|
|
68
|
+
const title = index?.metadata.title || index?.heading || fallback;
|
|
69
|
+
const cover = index?.metadata.cover;
|
|
70
|
+
if (cover && !Object.hasOwn(coverOptions, cover)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`${index.path}: cover "${cover}" must be one of ${Object.keys(coverOptions).join(", ")}.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const groups = new Map(
|
|
76
|
+
pages
|
|
77
|
+
.filter((page) => /\/index\.md$/i.test(page.path))
|
|
78
|
+
.map((page) => [posix.dirname(page.path), page.heading])
|
|
79
|
+
);
|
|
80
|
+
return {
|
|
81
|
+
id,
|
|
82
|
+
title,
|
|
83
|
+
cover,
|
|
84
|
+
chapters: pages.sort(comparePages).map((page) => {
|
|
85
|
+
const group = posix.dirname(page.path);
|
|
86
|
+
const inBook = folder ? page.path.slice(folder.length + 1) : page.path;
|
|
87
|
+
const file = posix.basename(pageId(page.path));
|
|
88
|
+
const groupTitle =
|
|
89
|
+
group !== (folder || ".")
|
|
90
|
+
? groups.get(group) || titleFromPath(posix.basename(group))
|
|
91
|
+
: undefined;
|
|
92
|
+
return {
|
|
93
|
+
id: pageId(inBook),
|
|
94
|
+
path: page.path,
|
|
95
|
+
title:
|
|
96
|
+
page.metadata.title ||
|
|
97
|
+
page.heading ||
|
|
98
|
+
(file === "index" ? groupTitle || title : titleFromPath(file)),
|
|
99
|
+
group: groupTitle,
|
|
100
|
+
sheets: page.sheets,
|
|
101
|
+
metadata: page.metadata,
|
|
102
|
+
hasTitle: Boolean(page.heading),
|
|
103
|
+
excerpt: page.excerpt,
|
|
104
|
+
markdown: page.markdown,
|
|
105
|
+
headingIds: page.headingIds,
|
|
106
|
+
urls: page.urls,
|
|
107
|
+
};
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function inside(parent, path) {
|
|
113
|
+
const fromParent = relative(parent, path);
|
|
114
|
+
return (
|
|
115
|
+
fromParent !== ".." &&
|
|
116
|
+
!fromParent.startsWith(`..${sep}`) &&
|
|
117
|
+
!isAbsolute(fromParent)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function readSettings(cwd) {
|
|
122
|
+
let source;
|
|
123
|
+
try {
|
|
124
|
+
source = await readFile(join(cwd, "grimoire.yml"), "utf8");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error.code === "ENOENT") return { locale: "en" };
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
let settings;
|
|
130
|
+
try {
|
|
131
|
+
settings = parse(source) ?? {};
|
|
132
|
+
} catch {
|
|
133
|
+
throw new Error(
|
|
134
|
+
"grimoire.yml contains invalid YAML / grimoire.yml の YAML を確認してください。"
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const {
|
|
138
|
+
locale = "en",
|
|
139
|
+
title,
|
|
140
|
+
outDir,
|
|
141
|
+
description,
|
|
142
|
+
siteUrl,
|
|
143
|
+
socialImage,
|
|
144
|
+
author,
|
|
145
|
+
magicMode,
|
|
146
|
+
} = settings;
|
|
147
|
+
if (
|
|
148
|
+
typeof settings !== "object" ||
|
|
149
|
+
Array.isArray(settings) ||
|
|
150
|
+
!languages.has(locale)
|
|
151
|
+
) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
"grimoire.yml: set locale to en or ja / locale は en または ja を指定してください。"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (
|
|
157
|
+
(title !== undefined && typeof title !== "string") ||
|
|
158
|
+
(outDir !== undefined && (typeof outDir !== "string" || !outDir.trim()))
|
|
159
|
+
) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
"grimoire.yml: title and outDir must be text / title と outDir は文字列で指定してください。"
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (
|
|
165
|
+
[description, siteUrl, socialImage, author].some(
|
|
166
|
+
(value) =>
|
|
167
|
+
value !== undefined && (typeof value !== "string" || !value.trim())
|
|
168
|
+
) ||
|
|
169
|
+
(magicMode !== undefined && typeof magicMode !== "boolean")
|
|
170
|
+
)
|
|
171
|
+
throw new Error(
|
|
172
|
+
"grimoire.yml: description, siteUrl, socialImage and author must be text, and magicMode must be true or false."
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
locale,
|
|
177
|
+
title,
|
|
178
|
+
outDir,
|
|
179
|
+
description,
|
|
180
|
+
socialImage,
|
|
181
|
+
author,
|
|
182
|
+
magicMode,
|
|
183
|
+
siteUrl: siteUrl && normalizeSiteUrl(siteUrl),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function absoluteWebUrl(value) {
|
|
188
|
+
try {
|
|
189
|
+
const url = new URL(value);
|
|
190
|
+
if (
|
|
191
|
+
["http:", "https:"].includes(url.protocol) &&
|
|
192
|
+
!url.username &&
|
|
193
|
+
!url.password
|
|
194
|
+
)
|
|
195
|
+
return url;
|
|
196
|
+
} catch {}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function normalizeSiteUrl(value) {
|
|
201
|
+
const url = absoluteWebUrl(value);
|
|
202
|
+
if (!url || url.search || url.hash) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
"grimoire.yml: siteUrl must be an absolute HTTP(S) URL without a query or fragment."
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (!url.pathname.endsWith("/")) url.pathname += "/";
|
|
208
|
+
return url.href;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function loadLink(url, page, links, docs, assets, issues) {
|
|
212
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/)/i.test(url)) return undefined;
|
|
213
|
+
const match = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(url);
|
|
214
|
+
if (!match) return undefined;
|
|
215
|
+
const [, path, query = "", anchor = ""] = match;
|
|
216
|
+
let decoded;
|
|
217
|
+
try {
|
|
218
|
+
decoded = decodeURIComponent(path);
|
|
219
|
+
} catch {
|
|
220
|
+
issues.push(`${page.path}: ${url}`);
|
|
221
|
+
return "";
|
|
222
|
+
}
|
|
223
|
+
const target = path
|
|
224
|
+
? posix.normalize(posix.join(posix.dirname(page.path), decoded))
|
|
225
|
+
: page.path;
|
|
226
|
+
const targetPage =
|
|
227
|
+
links.get(target) ?? links.get(posix.join(target, "index.md"));
|
|
228
|
+
if (targetPage) {
|
|
229
|
+
const fragment = anchor.slice(1);
|
|
230
|
+
if (!fragment) return targetPage;
|
|
231
|
+
try {
|
|
232
|
+
return `${targetPage}?anchor=${encodeURIComponent(decodeURIComponent(fragment))}`;
|
|
233
|
+
} catch {
|
|
234
|
+
return `${targetPage}?anchor=${encodeURIComponent(fragment)}`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (target.startsWith("../") || target === ".." || !path) {
|
|
238
|
+
issues.push(`${page.path}: ${url}`);
|
|
239
|
+
return "";
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const absolute = await realpath(join(docs, target));
|
|
243
|
+
if (!inside(docs, absolute) || !(await stat(absolute)).isFile()) {
|
|
244
|
+
issues.push(`${page.path}: ${url}`);
|
|
245
|
+
return "";
|
|
246
|
+
}
|
|
247
|
+
assets.set(target, absolute);
|
|
248
|
+
return `./content/${encodePath(target)}${query}${anchor}`;
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (!["ENOENT", "ENOTDIR"].includes(error.code)) throw error;
|
|
251
|
+
issues.push(`${page.path}: ${url}`);
|
|
252
|
+
return "";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export async function readLibrary(cwd, settings) {
|
|
257
|
+
const { locale, title } = settings;
|
|
258
|
+
const docs = await realpath(join(cwd, "docs")).catch((error) => {
|
|
259
|
+
if (error.code === "ENOENT") throw missingMarkdown(locale);
|
|
260
|
+
throw error;
|
|
261
|
+
});
|
|
262
|
+
const entries = (await readdir(docs, { withFileTypes: true }))
|
|
263
|
+
.filter((entry) => entry.isDirectory() && visibleEntry(entry.name))
|
|
264
|
+
.sort((a, b) => sortNames(a.name, b.name));
|
|
265
|
+
const books = [];
|
|
266
|
+
const rootPages = await readPages(docs, "", false);
|
|
267
|
+
if (rootPages.length)
|
|
268
|
+
books.push(describeBook(rootPages, "", title ?? "Grimoire3D"));
|
|
269
|
+
|
|
270
|
+
for (const { name } of entries) {
|
|
271
|
+
const pages = await readPages(docs, name, true);
|
|
272
|
+
if (pages.length)
|
|
273
|
+
books.push(describeBook(pages, name, titleFromPath(name)));
|
|
274
|
+
}
|
|
275
|
+
if (!books.length) throw missingMarkdown(locale);
|
|
276
|
+
|
|
277
|
+
const shelf = books.some((book) => book.id !== rootId);
|
|
278
|
+
const assets = new Map();
|
|
279
|
+
const links = new Map();
|
|
280
|
+
const issues = [];
|
|
281
|
+
for (const book of books) {
|
|
282
|
+
for (const page of book.chapters) {
|
|
283
|
+
links.set(
|
|
284
|
+
page.path,
|
|
285
|
+
`#/${encodeURIComponent(book.id)}/${encodeURIComponent(page.id)}`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function socialAsset(value, path) {
|
|
290
|
+
if (!value) return undefined;
|
|
291
|
+
const remote = absoluteWebUrl(value);
|
|
292
|
+
if (remote) return remote.href;
|
|
293
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(value)) {
|
|
294
|
+
issues.push(`${path}: ${value}`);
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
const image = await loadLink(
|
|
298
|
+
value,
|
|
299
|
+
{ path },
|
|
300
|
+
new Map(),
|
|
301
|
+
docs,
|
|
302
|
+
assets,
|
|
303
|
+
issues
|
|
304
|
+
);
|
|
305
|
+
return image || undefined;
|
|
306
|
+
}
|
|
307
|
+
const socialImage = await socialAsset(settings.socialImage, "index.md");
|
|
308
|
+
const publishedBooks = [];
|
|
309
|
+
const documents = [];
|
|
310
|
+
for (const { id, title, cover, chapters } of books) {
|
|
311
|
+
const pages = [];
|
|
312
|
+
for (const chapter of chapters) {
|
|
313
|
+
const {
|
|
314
|
+
id: chapterId,
|
|
315
|
+
title: chapterTitle,
|
|
316
|
+
group,
|
|
317
|
+
sheets,
|
|
318
|
+
urls,
|
|
319
|
+
} = chapter;
|
|
320
|
+
const paths = await Promise.all(
|
|
321
|
+
urls.map(async (url) => [
|
|
322
|
+
url,
|
|
323
|
+
await loadLink(url, chapter, links, docs, assets, issues),
|
|
324
|
+
])
|
|
325
|
+
);
|
|
326
|
+
const chapterLinks = Object.fromEntries(
|
|
327
|
+
paths.filter(([, path]) => path !== undefined)
|
|
328
|
+
);
|
|
329
|
+
for (const sheet of sheets) {
|
|
330
|
+
pages.push({
|
|
331
|
+
id: chapterId,
|
|
332
|
+
title: chapterTitle,
|
|
333
|
+
group,
|
|
334
|
+
...sheet,
|
|
335
|
+
links: chapterLinks,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
documents.push({
|
|
339
|
+
book: id,
|
|
340
|
+
chapter: chapterId,
|
|
341
|
+
title: chapterTitle,
|
|
342
|
+
hasTitle: chapter.hasTitle,
|
|
343
|
+
description:
|
|
344
|
+
chapter.metadata.description ||
|
|
345
|
+
chapter.excerpt ||
|
|
346
|
+
settings.description,
|
|
347
|
+
socialImage:
|
|
348
|
+
(await socialAsset(chapter.metadata.socialImage, chapter.path)) ||
|
|
349
|
+
socialImage,
|
|
350
|
+
markdown: chapter.markdown,
|
|
351
|
+
headingIds: chapter.headingIds,
|
|
352
|
+
links: chapterLinks,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
publishedBooks.push({ id, title, cover, pages });
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
manifest: {
|
|
359
|
+
locale,
|
|
360
|
+
shelf,
|
|
361
|
+
title: title ?? "Grimoire3D",
|
|
362
|
+
description: settings.description,
|
|
363
|
+
siteUrl: settings.siteUrl,
|
|
364
|
+
socialImage,
|
|
365
|
+
author: settings.author,
|
|
366
|
+
magicMode: settings.magicMode,
|
|
367
|
+
books: books.map(({ id, title, cover }) => ({ id, title, cover })),
|
|
368
|
+
},
|
|
369
|
+
books: publishedBooks,
|
|
370
|
+
documents,
|
|
371
|
+
assets,
|
|
372
|
+
issues: [...new Set(issues)].sort(sortNames),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function missingMarkdown(locale) {
|
|
377
|
+
return new Error(
|
|
378
|
+
locale === "ja"
|
|
379
|
+
? "docs/ に Markdown がありません。docs/index.md に「# 最初の本」と書いてください。"
|
|
380
|
+
: 'No Markdown in docs/. Start with "# My first book" in docs/index.md.'
|
|
381
|
+
);
|
|
382
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface CoverOption {
|
|
2
|
+
base: "red" | "green" | "blue";
|
|
3
|
+
filter: string;
|
|
4
|
+
edge: string;
|
|
5
|
+
mobile: string;
|
|
6
|
+
hue: string;
|
|
7
|
+
dye: string;
|
|
8
|
+
light: string;
|
|
9
|
+
lettering?: string;
|
|
10
|
+
}
|
|
11
|
+
export const coverOptions: Readonly<Record<string, CoverOption>> & {
|
|
12
|
+
red: CoverOption;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function selectCover(id: string, requested?: string): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export const coverOptions = {
|
|
2
|
+
red: {
|
|
3
|
+
base: "red",
|
|
4
|
+
filter: "brightness(1)",
|
|
5
|
+
edge: "#6d2022",
|
|
6
|
+
mobile: "none",
|
|
7
|
+
hue: "0deg",
|
|
8
|
+
dye: "",
|
|
9
|
+
light: ".22,.064,.060",
|
|
10
|
+
},
|
|
11
|
+
green: {
|
|
12
|
+
base: "green",
|
|
13
|
+
filter: "brightness(1)",
|
|
14
|
+
edge: "#424624",
|
|
15
|
+
mobile: "hue-rotate(66deg) saturate(.62)",
|
|
16
|
+
hue: "72deg",
|
|
17
|
+
dye: ".57,.83,.25",
|
|
18
|
+
light: ".105,.128,.049",
|
|
19
|
+
},
|
|
20
|
+
blue: {
|
|
21
|
+
base: "blue",
|
|
22
|
+
filter: "brightness(1)",
|
|
23
|
+
edge: "#34314c",
|
|
24
|
+
mobile: "hue-rotate(248deg) saturate(.62)",
|
|
25
|
+
hue: "235deg",
|
|
26
|
+
dye: ".37,.51,.85",
|
|
27
|
+
light: ".08,.102,.164",
|
|
28
|
+
},
|
|
29
|
+
plum: {
|
|
30
|
+
base: "red",
|
|
31
|
+
filter: "hue-rotate(-47deg) saturate(.79)",
|
|
32
|
+
edge: "#572c50",
|
|
33
|
+
mobile: "hue-rotate(-47deg) saturate(.79)",
|
|
34
|
+
hue: "313deg",
|
|
35
|
+
dye: ".71,.31,.67",
|
|
36
|
+
light: ".15,.069,.14",
|
|
37
|
+
},
|
|
38
|
+
amber: {
|
|
39
|
+
base: "red",
|
|
40
|
+
filter: "hue-rotate(34deg) saturate(.85) brightness(1.28)",
|
|
41
|
+
edge: "#8a551e",
|
|
42
|
+
mobile: "hue-rotate(34deg) brightness(1.28)",
|
|
43
|
+
hue: "34deg",
|
|
44
|
+
dye: "1.24,.68,.20",
|
|
45
|
+
light: ".27,.17,.055",
|
|
46
|
+
},
|
|
47
|
+
teal: {
|
|
48
|
+
base: "green",
|
|
49
|
+
filter: "hue-rotate(63deg) saturate(.86) brightness(1.18)",
|
|
50
|
+
edge: "#245452",
|
|
51
|
+
mobile: "hue-rotate(152deg) saturate(.65)",
|
|
52
|
+
hue: "150deg",
|
|
53
|
+
dye: ".26,.81,.75",
|
|
54
|
+
light: ".06,.16,.15",
|
|
55
|
+
},
|
|
56
|
+
black: {
|
|
57
|
+
base: "blue",
|
|
58
|
+
filter: "grayscale(1) brightness(.82)",
|
|
59
|
+
edge: "#252321",
|
|
60
|
+
mobile: "grayscale(1) brightness(.68)",
|
|
61
|
+
hue: "0deg",
|
|
62
|
+
dye: ".38,.37,.36",
|
|
63
|
+
light: ".072,.07,.068",
|
|
64
|
+
},
|
|
65
|
+
ivory: {
|
|
66
|
+
base: "red",
|
|
67
|
+
filter: "grayscale(1) invert(.86) sepia(.33) brightness(1.05)",
|
|
68
|
+
edge: "#d9c5a3",
|
|
69
|
+
mobile: "grayscale(1) invert(.86) sepia(.33)",
|
|
70
|
+
hue: "32deg",
|
|
71
|
+
dye: "3.2,2.7,2.02",
|
|
72
|
+
light: ".38,.315,.22",
|
|
73
|
+
lettering: "#392518",
|
|
74
|
+
},
|
|
75
|
+
walnut: {
|
|
76
|
+
base: "red",
|
|
77
|
+
filter: "hue-rotate(22deg) saturate(.58) brightness(.78)",
|
|
78
|
+
edge: "#50301c",
|
|
79
|
+
mobile: "hue-rotate(22deg) saturate(.58) brightness(.78)",
|
|
80
|
+
hue: "23deg",
|
|
81
|
+
dye: ".70,.43,.25",
|
|
82
|
+
light: ".15,.09,.048",
|
|
83
|
+
},
|
|
84
|
+
slate: {
|
|
85
|
+
base: "blue",
|
|
86
|
+
filter: "grayscale(.66) brightness(1.42)",
|
|
87
|
+
edge: "#5e6570",
|
|
88
|
+
mobile: "hue-rotate(213deg) saturate(.24) brightness(1.23)",
|
|
89
|
+
hue: "220deg",
|
|
90
|
+
dye: ".75,.82,.91",
|
|
91
|
+
light: ".17,.19,.21",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const fallbackCovers = ["red", "blue", "green"];
|
|
96
|
+
|
|
97
|
+
/** @param {string} id @param {string} [requested] */
|
|
98
|
+
export function selectCover(id, requested) {
|
|
99
|
+
if (requested && Object.hasOwn(coverOptions, requested)) return requested;
|
|
100
|
+
let hash = 2166136261;
|
|
101
|
+
for (const character of id.replace(/^\d+[-_]+/, "")) {
|
|
102
|
+
hash = Math.imul(hash ^ (character.codePointAt(0) ?? 0), 16777619);
|
|
103
|
+
}
|
|
104
|
+
return fallbackCovers[(hash >>> 10) % fallbackCovers.length];
|
|
105
|
+
}
|
package/cli/markdown.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
+
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
3
|
+
import { gfm } from "micromark-extension-gfm";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
|
|
6
|
+
function textOf(node) {
|
|
7
|
+
if (node.type === "image") return node.alt ?? "";
|
|
8
|
+
return node.value ?? node.children?.map(textOf).join("") ?? "";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function headingSlug(title) {
|
|
12
|
+
return (
|
|
13
|
+
title
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.trim()
|
|
16
|
+
.replace(/[^\p{Letter}\p{Number}\s_-]/gu, "")
|
|
17
|
+
.replace(/\s+/g, "-") || "section"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isDefinition(node) {
|
|
22
|
+
return node.type === "definition" || node.type === "footnoteDefinition";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readMarkdown(source) {
|
|
26
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(source);
|
|
27
|
+
let raw;
|
|
28
|
+
if (front) {
|
|
29
|
+
try {
|
|
30
|
+
raw = parse(front[1]);
|
|
31
|
+
} catch {
|
|
32
|
+
raw = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const metadata =
|
|
36
|
+
raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
37
|
+
const markdown = raw === metadata ? source.slice(front[0].length) : source;
|
|
38
|
+
const tree = fromMarkdown(markdown, {
|
|
39
|
+
extensions: [gfm()],
|
|
40
|
+
mdastExtensions: [gfmFromMarkdown()],
|
|
41
|
+
});
|
|
42
|
+
const headings = new Map();
|
|
43
|
+
const anchors = new Set();
|
|
44
|
+
const urls = new Set();
|
|
45
|
+
function visit(node) {
|
|
46
|
+
if (node.type === "heading") {
|
|
47
|
+
const title = textOf(node).trim();
|
|
48
|
+
const slug = headingSlug(title);
|
|
49
|
+
let id = slug;
|
|
50
|
+
for (let suffix = 1; anchors.has(id); suffix += 1) {
|
|
51
|
+
id = `${slug}-${suffix}`;
|
|
52
|
+
}
|
|
53
|
+
anchors.add(id);
|
|
54
|
+
headings.set(node, { id, title });
|
|
55
|
+
}
|
|
56
|
+
if (["link", "image", "definition"].includes(node.type)) urls.add(node.url);
|
|
57
|
+
node.children?.forEach(visit);
|
|
58
|
+
}
|
|
59
|
+
visit(tree);
|
|
60
|
+
|
|
61
|
+
const heading = tree.children.find(
|
|
62
|
+
(node) => node.type === "heading" && node.depth === 1
|
|
63
|
+
);
|
|
64
|
+
const boundaries = [{ start: 0 }];
|
|
65
|
+
let hasChapterContent = false;
|
|
66
|
+
for (const node of tree.children) {
|
|
67
|
+
if (node.type === "heading" && node.depth === 2) {
|
|
68
|
+
const section = headings.get(node);
|
|
69
|
+
if (hasChapterContent) {
|
|
70
|
+
boundaries.push({ start: node.position.start.offset, section });
|
|
71
|
+
} else {
|
|
72
|
+
// The chapter already starts on a fresh page, so its title can share that page.
|
|
73
|
+
boundaries[0].section = section;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (node !== heading && !isDefinition(node)) hasChapterContent = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const definitions = tree.children.filter(isDefinition);
|
|
80
|
+
const headingOffsets = [...headings].map(([node, { id }]) => ({
|
|
81
|
+
offset: node.position.start.offset,
|
|
82
|
+
id,
|
|
83
|
+
}));
|
|
84
|
+
let nextHeading = 0;
|
|
85
|
+
const sheets = boundaries.map(({ start, section }, index) => {
|
|
86
|
+
const end = boundaries[index + 1]?.start ?? markdown.length;
|
|
87
|
+
const headingIds = {};
|
|
88
|
+
while (headingOffsets[nextHeading]?.offset < end) {
|
|
89
|
+
const { offset, id } = headingOffsets[nextHeading];
|
|
90
|
+
headingIds[offset - start] = id;
|
|
91
|
+
nextHeading += 1;
|
|
92
|
+
}
|
|
93
|
+
const references = definitions
|
|
94
|
+
.filter(
|
|
95
|
+
({ position }) =>
|
|
96
|
+
position.start.offset < start || position.start.offset >= end
|
|
97
|
+
)
|
|
98
|
+
.map(({ position }) =>
|
|
99
|
+
markdown.slice(position.start.offset, position.end.offset)
|
|
100
|
+
);
|
|
101
|
+
const content = markdown.slice(start, end);
|
|
102
|
+
return {
|
|
103
|
+
markdown: references.length
|
|
104
|
+
? [content, ...references].join("\n\n")
|
|
105
|
+
: content,
|
|
106
|
+
headingIds,
|
|
107
|
+
section,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const paragraph = tree.children.find((node) => node.type === "paragraph");
|
|
112
|
+
const excerpt = paragraph
|
|
113
|
+
? textOf(paragraph).replace(/\s+/g, " ").trim()
|
|
114
|
+
: "";
|
|
115
|
+
return {
|
|
116
|
+
heading: headings.get(heading)?.title,
|
|
117
|
+
metadata: {
|
|
118
|
+
cover:
|
|
119
|
+
typeof metadata.cover === "string" ? metadata.cover.trim() : undefined,
|
|
120
|
+
title:
|
|
121
|
+
typeof metadata.title === "string" ? metadata.title.trim() : undefined,
|
|
122
|
+
description:
|
|
123
|
+
typeof metadata.description === "string"
|
|
124
|
+
? metadata.description.trim()
|
|
125
|
+
: undefined,
|
|
126
|
+
socialImage:
|
|
127
|
+
typeof metadata.socialImage === "string"
|
|
128
|
+
? metadata.socialImage.trim()
|
|
129
|
+
: undefined,
|
|
130
|
+
},
|
|
131
|
+
excerpt: [...excerpt].slice(0, 170).join(""),
|
|
132
|
+
markdown,
|
|
133
|
+
headingIds: Object.fromEntries(
|
|
134
|
+
headingOffsets.map(({ offset, id }) => [offset, id])
|
|
135
|
+
),
|
|
136
|
+
sheets,
|
|
137
|
+
urls: [...urls],
|
|
138
|
+
};
|
|
139
|
+
}
|
package/cli/markup.d.ts
ADDED
package/cli/markup.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const inline = {
|
|
2
|
+
underline: "u",
|
|
3
|
+
highlight: "mark",
|
|
4
|
+
red: "span",
|
|
5
|
+
};
|
|
6
|
+
const alertNames = {
|
|
7
|
+
en: {
|
|
8
|
+
NOTE: "Note",
|
|
9
|
+
TIP: "Tip",
|
|
10
|
+
IMPORTANT: "Important",
|
|
11
|
+
WARNING: "Warning",
|
|
12
|
+
CAUTION: "Caution",
|
|
13
|
+
},
|
|
14
|
+
ja: {
|
|
15
|
+
NOTE: "注記",
|
|
16
|
+
TIP: "ヒント",
|
|
17
|
+
IMPORTANT: "重要",
|
|
18
|
+
WARNING: "警告",
|
|
19
|
+
CAUTION: "注意",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** @param {"en" | "ja"} [locale] */
|
|
24
|
+
export function remarkGrimoire(locale = "en") {
|
|
25
|
+
/** @param {any} node */
|
|
26
|
+
function visit(node) {
|
|
27
|
+
if (node.type === "textDirective" && Object.hasOwn(inline, node.name)) {
|
|
28
|
+
node.data = { hName: inline[node.name] };
|
|
29
|
+
if (node.name === "red")
|
|
30
|
+
node.data.hProperties = { className: ["paper-red"] };
|
|
31
|
+
}
|
|
32
|
+
if (node.type === "blockquote") {
|
|
33
|
+
const paragraph = node.children[0];
|
|
34
|
+
const first = paragraph?.type === "paragraph" && paragraph.children[0];
|
|
35
|
+
const marker =
|
|
36
|
+
first?.type === "text" &&
|
|
37
|
+
/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\](?:\r?\n|$)/.exec(
|
|
38
|
+
first.value
|
|
39
|
+
);
|
|
40
|
+
if (marker) {
|
|
41
|
+
const name = marker[1];
|
|
42
|
+
first.value = first.value.slice(marker[0].length);
|
|
43
|
+
if (!first.value) paragraph.children.shift();
|
|
44
|
+
if (!paragraph.children.length) node.children.shift();
|
|
45
|
+
node.children.unshift({
|
|
46
|
+
type: "paragraph",
|
|
47
|
+
data: { hProperties: { className: ["paper-alert-label"] } },
|
|
48
|
+
children: [{ type: "text", value: alertNames[locale][name] }],
|
|
49
|
+
});
|
|
50
|
+
node.data = {
|
|
51
|
+
hProperties: {
|
|
52
|
+
className: ["paper-alert", `paper-alert-${name.toLowerCase()}`],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
node.children?.forEach(visit);
|
|
58
|
+
}
|
|
59
|
+
return visit;
|
|
60
|
+
}
|