grimoire3d 0.3.1 → 0.3.2-dev.1c36947
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 +18 -8
- package/cli/cli.js +24 -12
- package/cli/content.js +64 -15
- package/cli/markdown.js +1 -0
- package/dist/site/assets/{BookReader-DCWs90gY.js → BookReader-1Rx9lwH4.js} +2 -2
- package/dist/site/assets/{BookScene-DgLf6Enk.js → BookScene--RuFQb95.js} +1 -1
- package/dist/site/assets/DiagramViewer-C75RFqYX.js +1 -0
- package/dist/site/assets/MermaidDiagram-DhQQuwgn.js +44 -0
- package/dist/site/assets/{PageMarkdown-BDd7uOW4.js → PageMarkdown-B4BO0Wb7.js} +57 -57
- package/dist/site/assets/{abnfDiagram-S7VZAUFO-Y8BZ4vf8.js → abnfDiagram-S7VZAUFO-CHrjcVVg.js} +1 -1
- package/dist/site/assets/{architecture-WOLXFQ4H-TQCyxI9u.js → architecture-WOLXFQ4H-cQMVJp1t.js} +1 -1
- package/dist/site/assets/{architectureDiagram-YGSQEFNW-Bn495Re4.js → architectureDiagram-YGSQEFNW-BUjB-I3O.js} +1 -1
- package/dist/site/assets/{blockDiagram-APKKGZFW-hTc94DZr.js → blockDiagram-APKKGZFW-DueAWoGW.js} +1 -1
- package/dist/site/assets/{c4Diagram-KJ2TOQU5-3w_jvLJE.js → c4Diagram-KJ2TOQU5-BmGBv3SY.js} +1 -1
- package/dist/site/assets/{chunk-6MUBBAK2-BkD8UD1y.js → chunk-6MUBBAK2-CqYkDdSL.js} +1 -1
- package/dist/site/assets/{chunk-AXFCVDMN-Rq07LJGo.js → chunk-AXFCVDMN-Be4KhxoB.js} +1 -1
- package/dist/site/assets/{chunk-BG4553SI-BbFZng8F.js → chunk-BG4553SI-ugjmrE92.js} +1 -1
- package/dist/site/assets/{chunk-DQASFODM-8AEVeEgt.js → chunk-DQASFODM-rcBUhSZK.js} +1 -1
- package/dist/site/assets/{chunk-HFQBQIA3-C40nK8Y3.js → chunk-HFQBQIA3-mvlTepFi.js} +1 -1
- package/dist/site/assets/{chunk-KQLB2F66-Bf_S_2K6.js → chunk-KQLB2F66-DrNZgrs2.js} +1 -1
- package/dist/site/assets/{chunk-KS47KZWR-CV-CVFml.js → chunk-KS47KZWR-Cof0kJNw.js} +1 -1
- package/dist/site/assets/{chunk-LEVMRMFU-OVwQP4HJ.js → chunk-LEVMRMFU-CCztXsdV.js} +1 -1
- package/dist/site/assets/{chunk-M57EVK23-BEQIQAdR.js → chunk-M57EVK23-Cg-zUatn.js} +1 -1
- package/dist/site/assets/{chunk-OY52VR5R-3JkK4aqh.js → chunk-OY52VR5R-BK8aO5ZZ.js} +1 -1
- package/dist/site/assets/{chunk-QB3YPZ4I-CLGXTebg.js → chunk-QB3YPZ4I-BPGtUadt.js} +1 -1
- package/dist/site/assets/{chunk-R3KSYZAL-Co3KR3vY.js → chunk-R3KSYZAL-DCaUKkHs.js} +1 -1
- package/dist/site/assets/{chunk-STOXU5M4-BbHn-JCi.js → chunk-STOXU5M4-B0gzF3dV.js} +1 -1
- package/dist/site/assets/{chunk-TU62E6Q5-DkhMx9Q4.js → chunk-TU62E6Q5-DB1GH6Dp.js} +1 -1
- package/dist/site/assets/{chunk-X4PVCEUW-Cw_6SQQl.js → chunk-X4PVCEUW-MLmGnwfA.js} +1 -1
- package/dist/site/assets/{chunk-XXDRQBXY-CRYRc_Wt.js → chunk-XXDRQBXY-BODQ_hls.js} +1 -1
- package/dist/site/assets/{classDiagram-v2-L25IHNXF-DjHToGrh.js → classDiagram-v2-L25IHNXF-fVcqduZz.js} +1 -1
- package/dist/site/assets/{cose-bilkent-JH36ORCC-7nTgLcm_.js → cose-bilkent-JH36ORCC-DEl-TmPE.js} +1 -1
- package/dist/site/assets/cynefin-EF2NZ3EQ-D5cCROoG.js +1 -0
- package/dist/site/assets/{cynefinDiagram-L36ESFBY-D6H0WCez.js → cynefinDiagram-L36ESFBY-BVV9A1wk.js} +1 -1
- package/dist/site/assets/{d3-selection-_ztfYxKb.js → d3-selection-CIfMyhZ8.js} +1 -1
- package/dist/site/assets/{dagre-SPEB5RXH-CqCGPgYG.js → dagre-SPEB5RXH-DbWiPsqB.js} +1 -1
- package/dist/site/assets/{diagram-3B7GL73J-DDNF89rH.js → diagram-3B7GL73J-DjhFYOHO.js} +1 -1
- package/dist/site/assets/{diagram-DNEMPZML-DnHTiWSl.js → diagram-DNEMPZML-H2UjYM6I.js} +1 -1
- package/dist/site/assets/{diagram-L3MUGCDN-BP4RDryv.js → diagram-L3MUGCDN-BlfYQl4y.js} +1 -1
- package/dist/site/assets/{diagram-LA4NIPWU-YhfaR52L.js → diagram-LA4NIPWU-DLRkFIEP.js} +1 -1
- package/dist/site/assets/{diagram-MHCOC4E2-B2CokZ6p.js → diagram-MHCOC4E2-DRj0tpug.js} +1 -1
- package/dist/site/assets/{diagram-XPFHEONP-BiXyQAhI.js → diagram-XPFHEONP-B0HMnPQu.js} +1 -1
- package/dist/site/assets/{dist-DNnrlBGx.js → dist-ORv2jhYn.js} +1 -1
- package/dist/site/assets/{ebnfDiagram-UZSYDL2S-HqUNigiS.js → ebnfDiagram-UZSYDL2S-Cw60ZstU.js} +1 -1
- package/dist/site/assets/{elk-XV6XMXQE-B1gKu4To.js → elk-XV6XMXQE-CEfAH4PF.js} +1 -1
- package/dist/site/assets/{erDiagram-EYBAPDEH-87mLelxm.js → erDiagram-EYBAPDEH-ocbKXoj7.js} +1 -1
- package/dist/site/assets/{eventmodeling-K75KTNOO-DlYKH73r.js → eventmodeling-K75KTNOO-C9cxZN6P.js} +1 -1
- package/dist/site/assets/flowDiagram-MALGAFMO-Dh3EqH8d.js +1 -0
- package/dist/site/assets/{ganttDiagram-23REXITY-BW5D0BwF.js → ganttDiagram-23REXITY-BngB_oU6.js} +1 -1
- package/dist/site/assets/gitGraph-VSP46ZUC-6omgkyj2.js +1 -0
- package/dist/site/assets/{gitGraphDiagram-STJD7YCW-C1OitBdM.js → gitGraphDiagram-STJD7YCW-CQzHoz6h.js} +1 -1
- package/dist/site/assets/{index-DeHKbPiY.js → index-B6T7Jb92.js} +2 -2
- package/dist/site/assets/{index-ETbk37vV.css → index-B_4d4y5z.css} +1 -1
- package/dist/site/assets/info-OHQRW6UA-B065NqAQ.js +1 -0
- package/dist/site/assets/{infoDiagram-KBXO4MBG-DYvBfRFf.js → infoDiagram-KBXO4MBG-Bkd74MFs.js} +1 -1
- package/dist/site/assets/{ishikawaDiagram-M35NCXHK-HxvcNDvi.js → ishikawaDiagram-M35NCXHK-DYM6VEu8.js} +1 -1
- package/dist/site/assets/{journeyDiagram-OPLOXDXO-YgjSYtDU.js → journeyDiagram-OPLOXDXO-CQB2dZTT.js} +1 -1
- package/dist/site/assets/{kanban-definition-BZKZHSQY-B60A1uY_.js → kanban-definition-BZKZHSQY-BeDk6Xof.js} +1 -1
- package/dist/site/assets/{mermaid-parser.core-CqUMb98c.js → mermaid-parser.core-9cGGF8Pu.js} +3 -3
- package/dist/site/assets/{mindmap-definition-I2QAS2VK-Bbg1xV3W.js → mindmap-definition-I2QAS2VK-BD-lFr_6.js} +1 -1
- package/dist/site/assets/packet-JDAUHWVQ-CxnEBs6x.js +1 -0
- package/dist/site/assets/{pegDiagram-FD4XPPHP-BzXEwr79.js → pegDiagram-FD4XPPHP-CykYCgIl.js} +1 -1
- package/dist/site/assets/pie-XZMESJXO-BLhW0CA4.js +1 -0
- package/dist/site/assets/{pieDiagram-J4AKIIQI--1HbHEjB.js → pieDiagram-J4AKIIQI-CzRnl7XO.js} +1 -1
- package/dist/site/assets/{quadrantDiagram-XTYBLID2-4ICy76mk.js → quadrantDiagram-XTYBLID2-HI_ZooY4.js} +1 -1
- package/dist/site/assets/radar-ABXABTNO-DUsb61Mj.js +1 -0
- package/dist/site/assets/railroad-I3PHUGI6-Bw7F_n9p.js +1 -0
- package/dist/site/assets/{railroad-abnf-LNEFI6M7-DA6sDEMP.js → railroad-abnf-LNEFI6M7-BjMniwA1.js} +1 -1
- package/dist/site/assets/{railroad-ebnf-DWYD2UWJ-fdx4cu4d.js → railroad-ebnf-DWYD2UWJ-CKbT-ggQ.js} +1 -1
- package/dist/site/assets/{railroad-peg-JR7BVNR7-D2sGopBU.js → railroad-peg-JR7BVNR7-CRD6PqFD.js} +1 -1
- package/dist/site/assets/{railroadDiagram-MRQ6NCDL-DfWDmouy.js → railroadDiagram-MRQ6NCDL-CUatHYWM.js} +1 -1
- package/dist/site/assets/{requirementDiagram-Y7LWUY3S-Dfwwar5x.js → requirementDiagram-Y7LWUY3S-6-tdE1bT.js} +1 -1
- package/dist/site/assets/{sankeyDiagram-WGJFYUXA-CQgnTJdB.js → sankeyDiagram-WGJFYUXA-BZxoTMTR.js} +1 -1
- package/dist/site/assets/{sequenceDiagram-5NDRBG5M-DjlGr37h.js → sequenceDiagram-5NDRBG5M-DkSkx6oI.js} +1 -1
- package/dist/site/assets/{stateDiagram-v2-FJ4FJNEA-C8hPnY9-.js → stateDiagram-v2-FJ4FJNEA-t64xErFa.js} +1 -1
- package/dist/site/assets/{swimlanes-UMQ2AFYF-BJByBjS8.js → swimlanes-UMQ2AFYF-CHDnVRJ4.js} +1 -1
- package/dist/site/assets/swimlanesDiagram-OMPLPG4O-uvM4eUuH.js +8 -0
- package/dist/site/assets/{timeline-definition-SEUHKTQE-HH42rWWR.js → timeline-definition-SEUHKTQE-CtPo9Kaf.js} +1 -1
- package/dist/site/assets/treeView-D4JQ5SDB-CB0wo8mv.js +1 -0
- package/dist/site/assets/treemap-SAJKECNS-DySoDizs.js +1 -0
- package/dist/site/assets/{usecaseDiagram-AFA6YXN4-D5o7N3Yj.js → usecaseDiagram-AFA6YXN4-b7sQeEOm.js} +1 -1
- package/dist/site/assets/{vennDiagram-NNMJR3RB-DwQU-u3H.js → vennDiagram-NNMJR3RB-By9v_HhH.js} +1 -1
- package/dist/site/assets/wardley-7MLQ67FV-DNou8ufP.js +1 -0
- package/dist/site/assets/{wardleyDiagram-S7YFUSEH-FsHgD8JM.js → wardleyDiagram-S7YFUSEH-CduONMmV.js} +1 -1
- package/dist/site/assets/{xychartDiagram-GGNKY7IX-DJx6ZmCD.js → xychartDiagram-GGNKY7IX-BCSrpash.js} +1 -1
- package/dist/site/index.html +2 -2
- package/package.json +3 -2
- package/dist/site/assets/MermaidDiagram-DzLLjQd2.js +0 -44
- package/dist/site/assets/cynefin-EF2NZ3EQ-Cu61kdvu.js +0 -1
- package/dist/site/assets/flowDiagram-MALGAFMO-KSUWrWQ2.js +0 -1
- package/dist/site/assets/gitGraph-VSP46ZUC-BJLoizwA.js +0 -1
- package/dist/site/assets/info-OHQRW6UA-BCub5SIv.js +0 -1
- package/dist/site/assets/packet-JDAUHWVQ-m4zlsMGW.js +0 -1
- package/dist/site/assets/pie-XZMESJXO-csYvMoQI.js +0 -1
- package/dist/site/assets/radar-ABXABTNO-DFrK7OJ2.js +0 -1
- package/dist/site/assets/railroad-I3PHUGI6--GZDM0oV.js +0 -1
- package/dist/site/assets/swimlanesDiagram-OMPLPG4O-B2wKaVby.js +0 -8
- package/dist/site/assets/treeView-D4JQ5SDB-98lIHgvt.js +0 -1
- package/dist/site/assets/treemap-SAJKECNS-BtSu7-Ys.js +0 -1
- package/dist/site/assets/wardley-7MLQ67FV-WT1ESs67.js +0 -1
package/README.md
CHANGED
|
@@ -8,14 +8,22 @@ Turn Markdown into 3D books you can open and flip through in a browser.
|
|
|
8
8
|
|
|
9
9
|
[Read the documentation](https://kkm-horikawa.github.io/grimoire3d/)
|
|
10
10
|
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
Run `npx grimoire3d serve` from your project directory and open the URL it prints. Grimoire3D looks for Markdown in the `docs/` folder directly under that directory by default. Existing Markdown works without a scaffold. See the [configuration guide](https://kkm-horikawa.github.io/grimoire3d/read/publishing/metadata/) when you want to customize the library.
|
|
14
|
+
|
|
15
|
+
If your Markdown lives in `handbook/`, add `--docs-dir handbook` to either `serve` or `build`.
|
|
16
|
+
|
|
11
17
|
## Install
|
|
12
18
|
|
|
13
|
-
Use a maintained Node.js 22, 24, or 26 release.
|
|
19
|
+
Use a maintained Node.js 22, 24, or 26 release. To pin the CLI for your project, add it as a development dependency.
|
|
14
20
|
|
|
15
21
|
```sh
|
|
16
22
|
npm install --save-dev grimoire3d
|
|
17
23
|
```
|
|
18
24
|
|
|
25
|
+
For a global installation, run `npm install -g grimoire3d`, then use `grimo serve` or `grimo build`.
|
|
26
|
+
|
|
19
27
|
## Write and preview
|
|
20
28
|
|
|
21
29
|
Create `docs/field-notes/index.md`.
|
|
@@ -26,21 +34,23 @@ Create `docs/field-notes/index.md`.
|
|
|
26
34
|
This is my first 3D book.
|
|
27
35
|
```
|
|
28
36
|
|
|
29
|
-
`docs
|
|
37
|
+
Each folder directly under `docs/` becomes a book, and its Markdown files become chapters. Loose Markdown files directly in `docs/` share a separate book. Nested folders form chapter groups within the same book.
|
|
38
|
+
|
|
39
|
+
Books use the title or top-level heading in their `index.md`, then the first heading in their `README.md`. The default title is **Overview** for loose files and the folder name for each folder book.
|
|
30
40
|
|
|
31
41
|
```text
|
|
32
42
|
docs/
|
|
33
|
-
├── index.md #
|
|
43
|
+
├── index.md # Book of loose Markdown files
|
|
34
44
|
├── notes.md
|
|
35
|
-
└── field-notes/ #
|
|
36
|
-
├── index.md #
|
|
45
|
+
└── field-notes/ # Another book
|
|
46
|
+
├── index.md # Introduction and book settings
|
|
37
47
|
├── setup.md
|
|
38
|
-
└── examples/ #
|
|
48
|
+
└── examples/ # Chapter group in the same book
|
|
39
49
|
├── index.md
|
|
40
50
|
└── cli.md
|
|
41
51
|
```
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
Set `chapters: [setup.md, examples/]` in each folder's `index.md` front matter to choose what follows its introduction. Unlisted chapters follow in natural filename order. Title search appears with seven or more books, or whenever a book has a category or publication date.
|
|
44
54
|
|
|
45
55
|
```sh
|
|
46
56
|
npx grimoire3d serve
|
|
@@ -58,6 +68,6 @@ npx grimoire3d build
|
|
|
58
68
|
|
|
59
69
|
Deploy the contents of `dist/` to any static host, including Cloudflare Pages and GitHub Pages. Use `--out-dir site` to choose a different output directory.
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
Block quotes, lists, task lists, collapsible notes, math, definition lists, syntax highlighting, and footnotes are supported. See the [syntax and rendered examples](https://kkm-horikawa.github.io/grimoire3d/read/writing/formatting/) and [site settings and SEO examples](https://kkm-horikawa.github.io/grimoire3d/read/publishing/metadata/).
|
|
62
72
|
|
|
63
73
|
[Contributing](CONTRIBUTING.md) · [MIT License](LICENSE)
|
package/cli/cli.js
CHANGED
|
@@ -140,8 +140,10 @@ function snapshot(library) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function serve(cwd, port, initial) {
|
|
143
|
+
function serve(cwd, port, initial, docsDir) {
|
|
144
144
|
let current = snapshot(initial);
|
|
145
|
+
let watchedDirectory = initial.docsDirectory;
|
|
146
|
+
let docsWatcher = watch(watchedDirectory, { recursive: true }, schedule);
|
|
145
147
|
let timer;
|
|
146
148
|
let changes = 0;
|
|
147
149
|
const clients = new Set();
|
|
@@ -151,8 +153,18 @@ function serve(cwd, port, initial) {
|
|
|
151
153
|
async function refresh() {
|
|
152
154
|
const revision = ++changes;
|
|
153
155
|
try {
|
|
154
|
-
const library = await readLibrary(cwd, await readSettings(cwd));
|
|
156
|
+
const library = await readLibrary(cwd, await readSettings(cwd), docsDir);
|
|
155
157
|
if (revision !== changes) return;
|
|
158
|
+
if (library.docsDirectory !== watchedDirectory) {
|
|
159
|
+
const nextWatcher = watch(
|
|
160
|
+
library.docsDirectory,
|
|
161
|
+
{ recursive: true },
|
|
162
|
+
schedule
|
|
163
|
+
);
|
|
164
|
+
docsWatcher.close();
|
|
165
|
+
docsWatcher = nextWatcher;
|
|
166
|
+
watchedDirectory = library.docsDirectory;
|
|
167
|
+
}
|
|
156
168
|
current = snapshot(library);
|
|
157
169
|
showIssues(library);
|
|
158
170
|
} catch (error) {
|
|
@@ -166,12 +178,9 @@ function serve(cwd, port, initial) {
|
|
|
166
178
|
clearTimeout(timer);
|
|
167
179
|
timer = setTimeout(() => void refresh(), 140);
|
|
168
180
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (name === "grimoire.yml") schedule();
|
|
173
|
-
}),
|
|
174
|
-
];
|
|
181
|
+
const settingsWatcher = watch(cwd, (_event, name) => {
|
|
182
|
+
if (name === "grimoire.yml") schedule();
|
|
183
|
+
});
|
|
175
184
|
|
|
176
185
|
const server = createServer(async (request, response) => {
|
|
177
186
|
try {
|
|
@@ -285,7 +294,8 @@ function serve(cwd, port, initial) {
|
|
|
285
294
|
});
|
|
286
295
|
const stopWatchers = () => {
|
|
287
296
|
clearTimeout(timer);
|
|
288
|
-
|
|
297
|
+
docsWatcher.close();
|
|
298
|
+
settingsWatcher.close();
|
|
289
299
|
};
|
|
290
300
|
server.on("error", (error) => {
|
|
291
301
|
stopWatchers();
|
|
@@ -307,12 +317,13 @@ async function main() {
|
|
|
307
317
|
options: {
|
|
308
318
|
help: { type: "boolean", short: "h" },
|
|
309
319
|
port: { type: "string" },
|
|
320
|
+
"docs-dir": { type: "string" },
|
|
310
321
|
"out-dir": { type: "string" },
|
|
311
322
|
},
|
|
312
323
|
});
|
|
313
324
|
if (!command || values.help) {
|
|
314
325
|
console.log(
|
|
315
|
-
"grimoire3d serve [--port 3000]\ngrimoire3d build [--out-dir dist]"
|
|
326
|
+
"grimoire3d serve [--docs-dir docs] [--port 3000]\ngrimoire3d build [--docs-dir docs] [--out-dir dist]"
|
|
316
327
|
);
|
|
317
328
|
return;
|
|
318
329
|
}
|
|
@@ -320,7 +331,8 @@ async function main() {
|
|
|
320
331
|
throw new Error(`Unknown command: ${command}. See --help.`);
|
|
321
332
|
const cwd = process.cwd();
|
|
322
333
|
const settings = await readSettings(cwd);
|
|
323
|
-
const
|
|
334
|
+
const docsDir = values["docs-dir"];
|
|
335
|
+
const library = await readLibrary(cwd, settings, docsDir);
|
|
324
336
|
showIssues(library);
|
|
325
337
|
if (command === "build") {
|
|
326
338
|
const output = await writeStaticSite(
|
|
@@ -341,7 +353,7 @@ async function main() {
|
|
|
341
353
|
: "--port must be an integer from 0 to 65535."
|
|
342
354
|
);
|
|
343
355
|
}
|
|
344
|
-
serve(cwd, port, library);
|
|
356
|
+
serve(cwd, port, library, docsDir);
|
|
345
357
|
}
|
|
346
358
|
|
|
347
359
|
main().catch((error) => {
|
package/cli/content.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
basename,
|
|
4
|
+
extname,
|
|
5
|
+
isAbsolute,
|
|
6
|
+
join,
|
|
7
|
+
posix,
|
|
8
|
+
relative,
|
|
9
|
+
resolve,
|
|
10
|
+
sep,
|
|
11
|
+
} from "node:path";
|
|
3
12
|
import { parse } from "yaml";
|
|
4
13
|
import { coverOptions } from "./cover-options.js";
|
|
5
14
|
import { readMarkdown } from "./markdown.js";
|
|
@@ -116,13 +125,22 @@ function readPublicationDate(index) {
|
|
|
116
125
|
);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
function describeBook(pages, folder, fallback) {
|
|
128
|
+
function describeBook(pages, folder, fallback, configuredTitle) {
|
|
120
129
|
const index = pages.find(
|
|
121
130
|
(page) =>
|
|
122
131
|
page.path.toLowerCase() === posix.join(folder, "index.md").toLowerCase()
|
|
123
132
|
);
|
|
133
|
+
const readme = pages.find(
|
|
134
|
+
(page) =>
|
|
135
|
+
page.path.toLowerCase() === posix.join(folder, "README.md").toLowerCase()
|
|
136
|
+
);
|
|
124
137
|
const id = folder || rootId;
|
|
125
|
-
const title =
|
|
138
|
+
const title =
|
|
139
|
+
index?.metadata.title ||
|
|
140
|
+
index?.heading ||
|
|
141
|
+
configuredTitle ||
|
|
142
|
+
readme?.firstHeading ||
|
|
143
|
+
fallback;
|
|
126
144
|
const cover = index?.metadata.cover;
|
|
127
145
|
if (cover && !Object.hasOwn(coverOptions, cover)) {
|
|
128
146
|
throw new Error(
|
|
@@ -200,6 +218,7 @@ export async function readSettings(cwd) {
|
|
|
200
218
|
const {
|
|
201
219
|
locale = "en",
|
|
202
220
|
title,
|
|
221
|
+
docsDir,
|
|
203
222
|
outDir,
|
|
204
223
|
description,
|
|
205
224
|
siteUrl,
|
|
@@ -220,10 +239,13 @@ export async function readSettings(cwd) {
|
|
|
220
239
|
}
|
|
221
240
|
if (
|
|
222
241
|
(title !== undefined && typeof title !== "string") ||
|
|
223
|
-
|
|
242
|
+
[docsDir, outDir].some(
|
|
243
|
+
(value) =>
|
|
244
|
+
value !== undefined && (typeof value !== "string" || !value.trim())
|
|
245
|
+
)
|
|
224
246
|
) {
|
|
225
247
|
throw new Error(
|
|
226
|
-
"grimoire.yml: title and outDir must be text / title
|
|
248
|
+
"grimoire.yml: title, docsDir and outDir must be text / title、docsDir、outDir は文字列で指定してください。"
|
|
227
249
|
);
|
|
228
250
|
}
|
|
229
251
|
if (
|
|
@@ -240,6 +262,7 @@ export async function readSettings(cwd) {
|
|
|
240
262
|
return {
|
|
241
263
|
locale,
|
|
242
264
|
title,
|
|
265
|
+
docsDir,
|
|
243
266
|
outDir,
|
|
244
267
|
description,
|
|
245
268
|
socialImage,
|
|
@@ -336,26 +359,50 @@ async function loadLink(url, page, links, docs, assets, issues) {
|
|
|
336
359
|
}
|
|
337
360
|
}
|
|
338
361
|
|
|
339
|
-
|
|
362
|
+
async function projectTitle(cwd) {
|
|
363
|
+
const filename = join(cwd, "package.json");
|
|
364
|
+
try {
|
|
365
|
+
const name = JSON.parse(await readFile(filename, "utf8"))?.name;
|
|
366
|
+
if (typeof name === "string" && name.trim()) return name.trim();
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (error.code !== "ENOENT" && !(error instanceof SyntaxError)) throw error;
|
|
369
|
+
}
|
|
370
|
+
return basename(cwd);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export async function readLibrary(
|
|
374
|
+
cwd,
|
|
375
|
+
settings,
|
|
376
|
+
docsDir = settings.docsDir ?? "docs"
|
|
377
|
+
) {
|
|
340
378
|
const { locale, title } = settings;
|
|
341
|
-
|
|
342
|
-
|
|
379
|
+
if (!docsDir.trim()) throw new Error("--docs-dir must name a directory.");
|
|
380
|
+
const docs = await realpath(resolve(cwd, docsDir)).catch((error) => {
|
|
381
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code))
|
|
382
|
+
throw missingMarkdown(locale, docsDir);
|
|
343
383
|
throw error;
|
|
344
384
|
});
|
|
345
|
-
const entries = (
|
|
385
|
+
const entries = (
|
|
386
|
+
await readdir(docs, { withFileTypes: true }).catch((error) => {
|
|
387
|
+
if (error.code === "ENOTDIR") throw missingMarkdown(locale, docsDir);
|
|
388
|
+
throw error;
|
|
389
|
+
})
|
|
390
|
+
)
|
|
346
391
|
.filter((entry) => entry.isDirectory() && visibleEntry(entry.name))
|
|
347
392
|
.sort((a, b) => sortNames(a.name, b.name));
|
|
348
393
|
const books = [];
|
|
349
394
|
const rootPages = await readPages(docs, "", false);
|
|
350
395
|
if (rootPages.length)
|
|
351
|
-
books.push(
|
|
396
|
+
books.push(
|
|
397
|
+
describeBook(rootPages, "", locale === "ja" ? "概要" : "Overview", title)
|
|
398
|
+
);
|
|
352
399
|
|
|
353
400
|
for (const { name } of entries) {
|
|
354
401
|
const pages = await readPages(docs, name, true);
|
|
355
402
|
if (pages.length)
|
|
356
403
|
books.push(describeBook(pages, name, titleFromPath(name)));
|
|
357
404
|
}
|
|
358
|
-
if (!books.length) throw missingMarkdown(locale);
|
|
405
|
+
if (!books.length) throw missingMarkdown(locale, docsDir);
|
|
359
406
|
|
|
360
407
|
const shelf = books.some((book) => book.id !== rootId);
|
|
361
408
|
const assets = new Map();
|
|
@@ -467,10 +514,11 @@ export async function readLibrary(cwd, settings) {
|
|
|
467
514
|
publishedBooks.push({ id, title, cover, pages });
|
|
468
515
|
}
|
|
469
516
|
return {
|
|
517
|
+
docsDirectory: docs,
|
|
470
518
|
manifest: {
|
|
471
519
|
locale,
|
|
472
520
|
shelf,
|
|
473
|
-
title: title ??
|
|
521
|
+
title: title ?? (await projectTitle(cwd)),
|
|
474
522
|
description: settings.description,
|
|
475
523
|
siteUrl: settings.siteUrl,
|
|
476
524
|
socialImage,
|
|
@@ -486,10 +534,11 @@ export async function readLibrary(cwd, settings) {
|
|
|
486
534
|
};
|
|
487
535
|
}
|
|
488
536
|
|
|
489
|
-
function missingMarkdown(locale) {
|
|
537
|
+
function missingMarkdown(locale, docsDir) {
|
|
538
|
+
const index = join(docsDir, "index.md");
|
|
490
539
|
return new Error(
|
|
491
540
|
locale === "ja"
|
|
492
|
-
?
|
|
493
|
-
:
|
|
541
|
+
? `${docsDir} に Markdown がありません。${index} に「# 最初の本」と書いてください。`
|
|
542
|
+
: `No Markdown in ${docsDir}. Start with "# My first book" in ${index}.`
|
|
494
543
|
);
|
|
495
544
|
}
|
package/cli/markdown.js
CHANGED
|
@@ -121,6 +121,7 @@ export function readMarkdown(source) {
|
|
|
121
121
|
: "";
|
|
122
122
|
return {
|
|
123
123
|
heading: headings.get(heading)?.title,
|
|
124
|
+
firstHeading: headings.values().next().value?.title,
|
|
124
125
|
metadata: {
|
|
125
126
|
cover:
|
|
126
127
|
typeof metadata.cover === "string" ? metadata.cover.trim() : undefined,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BookScene
|
|
2
|
-
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,t as f,u as p}from"./index-DeHKbPiY.js";import{a as m,d as h,f as g,g as _,h as v,l as y,p as b,r as ee,t as x,u as S}from"./jsxRuntime-WpZ1bTm4.js";var C={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};C.node;var te=u(C),w={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};w.node;var ne=u(w),re={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};re.node;var ie=u(re);function T(e,t){let n=t?.querySelectorAll(`video`),r=Array.from(e.querySelectorAll(`video`),(e,t)=>{let r=n?.[t]??e,i=document.createElement(`canvas`);i.className=e.className,i.width=Math.max(1,e.clientWidth),i.height=Math.max(1,e.clientHeight);let a=i.getContext(`2d`);return a&&r.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&new URL(r.currentSrc,document.baseURI).origin===window.location.origin&&a.drawImage(r,0,0,i.width,i.height),e.replaceWith(i),{video:e,still:i}});return()=>{for(let{video:e,still:t}of r)t.replaceWith(e)}}function ae(e,t){let n=t?.querySelectorAll(`.paper-table`),r=[];for(let[t,i]of Array.from(e.querySelectorAll(`.paper-table > table`)).entries()){let e=n?.[t]?.scrollLeft||0;if(e){i.style.translate=`${-e}px`,r.push(i);for(let t of i.querySelectorAll(`tr > :first-child`))t.style.translate=`${e}px`,r.push(t)}}return()=>{for(let e of r)e.style.removeProperty(`translate`)}}function oe(e,t){let n=`.paper-diagram, .paper-diagram-source`,r=t?.querySelectorAll(n),i=[];for(let[t,a]of Array.from(e.querySelectorAll(n)).entries()){let e=r?.[t];if(!(e instanceof HTMLImageElement))continue;let n=e.cloneNode();n instanceof HTMLImageElement&&(n.classList.add(`paper-diagram-copy`),a.parentNode?.insertBefore(n,a),i.push(n))}return()=>{for(let e of i)e.remove()}}async function se(e,t,n,r){let{toCanvas:i}=await f(async()=>{let{toCanvas:e}=await import(`./es-YYQGP5MR.js`);return{toCanvas:e}},[],import.meta.url);await document.fonts.ready;let a=T(e,r),o=ae(e,r),s=oe(e,r),c=t.getBoundingClientRect(),l=await i(t,{pixelRatio:1.4,skipFonts:!0,style:{position:`relative`,inset:`auto`,overflow:`hidden`,visibility:`visible`,backgroundColor:`transparent`}}).finally(()=>{s(),o(),a()}),u=document.createElement(`canvas`),d=Math.min(1.35,2304/n.width,1440/n.height);u.width=Math.round(n.width*d),u.height=Math.round(n.height*d);let p=u.getContext(`2d`);return!p||!l.width?null:(p.drawImage(l,(c.left-n.left)/n.width*u.width,(c.top-n.top)/n.height*u.height,c.width/n.width*u.width,c.height/n.height*u.height),u)}var ce=[`left`,`right`,`front`,`back`];function E(e,t){return t?Math.floor(e/2)*2:e}function le(e,t){let n=E(e,!0),r=E(t,!0);if(n===r)return null;let i=n<r?1:-1,a=Math.min(n,r),o=Math.max(n,r);return{to:t,direction:i,panels:{left:{index:a,side:`left`},right:{index:o+1,side:`right`},front:{index:a+1,side:`right`},back:{index:o,side:`left`}}}}function ue(e,t){return{width:Math.min(e*.86,t*2.2),height:Math.min(t*.88,e*.82)}}var D=860;function de(e,t){let n=document.createRange();return n.selectNodeContents(e),[...n.getClientRects()].filter(e=>e.width>0&&e.height>0&&e.bottom>t.top&&e.top<t.bottom)}function O(e,t,n){let r=document.createElement(`span`);return r.className=n,r.style.left=`${t.left-e.bounds.left}px`,r.style.top=`${t.top-e.bounds.top}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,e.overlay.append(r),r}function fe(e,t,n){let r=de(t,e.bounds);if(!r.length||r.length>6)return;t.classList.add(`spell-drawing-${n}`),e.changed.push(t);let i=D/r.length,a=r.flatMap((t,r)=>{let a=O(e,t,`spell-ink spell-ink-${n}`),o=document.createElement(`span`);o.className=`spell-stroke`,a.append(o);let s={delay:r*i,duration:i,fill:`both`},c=o.animate([{transform:`scaleX(0)`},{transform:`scaleX(0)`,offset:.12},{transform:`scaleX(1)`,offset:.84},{transform:`scaleX(1)`}],s);if(n===`underline`)return[c];let l=document.createElement(`span`);return l.className=n===`mark`?`spell-marker-tip`:`spell-ink-dust`,a.append(l),[c,l.animate([{transform:`translate(0,-.45em)`,opacity:0},{transform:`translateX(0)`,opacity:1,offset:.12},{transform:`translateX(${t.width}px)`,opacity:1,offset:.84},{transform:`translate(${t.width}px,-.55em)`,opacity:0}],s)]});e.running.push(...a),Promise.allSettled(a.map(e=>e.finished)).then(()=>{t.classList.remove(`spell-drawing-${n}`);for(let e of a)e.effect instanceof KeyframeEffect&&e.effect.target instanceof Element&&e.effect.target.parentElement?.remove()})}function k(e,t,n){if(t.childNodes.length!==1||!(t.firstChild instanceof Text))return;let r=t.firstChild,i=[...new Intl.Segmenter().segment(r.data)];if(!i.length||i.length>46)return;let a=document.createRange(),o=getComputedStyle(t).font,s=[];for(let{index:t,segment:n}of i){if(!n.trim())continue;a.setStart(r,t),a.setEnd(r,t+n.length);let i=a.getBoundingClientRect();if(!i.width||i.bottom<=e.bounds.top||i.top>=e.bounds.bottom){for(let{glyph:e}of s)e.remove();return}let c=O(e,i,`spell-letter`);c.style.font=o,c.textContent=n,s.push({glyph:c,rect:i})}if(!s.length)return;let c=s.map(({glyph:t,rect:n})=>{a.selectNodeContents(t);let r=a.getBoundingClientRect();return{glyph:t,left:n.left-e.bounds.left+n.left-r.left,top:n.top-e.bounds.top+n.top-r.top}});for(let{glyph:e,left:t,top:n}of c)e.style.left=`${t}px`,e.style.top=`${n}px`;t.classList.add(`spell-letters-rising`),e.changed.push(t);let l=s.map(({glyph:e},t)=>e.animate([{transform:`translateY(0)`},{transform:`translate(${n?(t%3-1)*.4:0}em,${n?-.9-t%2*.35:-.38}em) rotate(${t%2?9:-7}deg)`,offset:.48},{transform:`translateY(0)`}],{duration:n?810:520,delay:Math.min(t*38,250),easing:`ease-in-out`,fill:`both`}));e.running.push(...l),Promise.allSettled(l.map(e=>e.finished)).then(()=>{t.classList.remove(`spell-letters-rising`);for(let{glyph:e}of s)e.remove()})}function A(e,t){if(t.matches(`.paper-alert`)){let n=O(e,t.getBoundingClientRect(),`spell-seal`);n.textContent=`!`,e.running.push(n.animate([{transform:`translateY(-1em) scale(1.5) rotate(-18deg)`,opacity:0},{transform:`scale(1)`,opacity:1,offset:.45},{transform:`scale(1)`,opacity:0}],{duration:920,fill:`both`}));return}if(t.matches(`.paper-red`)){let n=O(e,t.getBoundingClientRect(),`spell-red-drop`);e.running.push(n.animate([{transform:`translateY(-.9em)`,opacity:0},{transform:`translateY(0)`,opacity:1,offset:.54},{transform:`translateY(.22em) scale(1.35,.45)`,opacity:0}],{duration:680,fill:`both`}));return}if(t.localName===`code`){if(t.closest(`pre`))return;let n=O(e,t.getBoundingClientRect(),`spell-code-frame`),r=document.createElement(`span`),i=document.createElement(`span`);r.textContent=`[`,i.textContent=`]`,n.append(r,i);for(let[t,n]of[r,i].entries())e.running.push(n.animate([{transform:`translateX(${t?.8:-.8}em)`,opacity:0},{transform:`translateX(0)`,opacity:.7,offset:.62},{transform:`translateX(0)`,opacity:0}],{duration:790,fill:`both`}));return}let n=t.classList.contains(`paper-diagram`)?[{clipPath:`inset(0 0 100% 0)`},{clipPath:`inset(0)`}]:[{opacity:.78,textShadow:`0 .17em .08em #5639235c`},{opacity:1,textShadow:`none`}];e.running.push(t.animate(n,{duration:660,easing:`ease-out`}))}function pe(e){let t=[];for(let n of e.querySelectorAll(`:scope > .book-sheet .page-text`)){let e=document.createElement(`div`);e.className=`spell-overlay`,e.setAttribute(`aria-hidden`,`true`),e.style.insetInlineStart=`${n.scrollLeft}px`,e.style.insetBlockStart=`${n.scrollTop}px`,e.style.width=`${n.clientWidth}px`,e.style.height=`${n.clientHeight}px`,n.append(e);let r={article:n,bounds:n.getBoundingClientRect(),overlay:e,running:[],changed:[]},i=n.querySelectorAll(`mark,u,del,strong,em,h1,h2,h3,code,.paper-red,.paper-alert,.paper-diagram`);for(let e of[...i].slice(0,24)){let t=e.getBoundingClientRect();t.bottom<r.bounds.top||t.top>r.bounds.bottom||(e.matches(`mark,u,del`)?fe(r,e,e.localName===`mark`?`mark`:e.localName===`u`?`underline`:`cross`):e.matches(`strong,em`)?k(r,e,e.matches(`strong`)):A(r,e))}if(!r.running.length){e.remove();continue}let a=!1,o=()=>{if(!a){a=!0,n.removeEventListener(`scroll`,o),window.removeEventListener(`resize`,o);for(let e of r.running)e.cancel();for(let e of r.changed)e.classList.remove(`spell-drawing-mark`,`spell-drawing-underline`,`spell-drawing-cross`,`spell-letters-rising`);e.remove()}};n.addEventListener(`scroll`,o,{passive:!0}),window.addEventListener(`resize`,o),t.push(o),Promise.allSettled(r.running.map(e=>e.finished)).then(o)}return()=>{for(let e of t)e()}}var me=m(()=>f(()=>import(`./BookScene-DgLf6Enk.js`),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),he=()=>f(()=>import(`./PageMarkdown-BDd7uOW4.js`),__vite__mapDeps([5,1,3,4]),import.meta.url),j=m(he),ge=`(min-width: 700px)`,_e=`(prefers-reduced-motion: reduce)`;function ve(e){let[t,n]=b(()=>matchMedia(e).matches);return y(()=>{let t=matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ye({page:e,number:t,side:n,anchor:r,bookTitle:i,text:a,locale:o}){let s=h(null),c=g(()=>{if(!s.current||(s.current.scrollTop=0,!r))return;let e=Array.from(s.current.querySelectorAll(`[id]`)).find(e=>e.id===r);e&&(s.current.scrollTop=e.getBoundingClientRect().top-s.current.getBoundingClientRect().top)},[r]);S(()=>c(),[c]);let l=g(()=>{c(),s.current?.dispatchEvent(new Event(`grimoire-content`,{bubbles:!0}))},[c]);function u(e){if(!(e.target instanceof Element))return;let t=e.target.closest(`a[data-footnote-ref], a[data-footnote-backref]`);if(!t||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let n=decodeURIComponent(new URL(t.href).hash.slice(1)),r=Array.from(s.current?.querySelectorAll(`[id]`)??[]).find(e=>e.id===n);r&&s.current&&(e.preventDefault(),s.current.scrollTop+=r.getBoundingClientRect().top-s.current.getBoundingClientRect().top,r.focus({preventScroll:!0}))}return x(`div`,{className:`book-sheet book-sheet--${n}`,"data-sheet":n,"data-page-id":e?.id,"data-page-key":e&&d(e),"data-section-id":e?.section?.id,children:e&&x(_,{children:[e.preparedHtml===void 0?x(`article`,{ref:s,onClick:u,"aria-label":e.section?.title||e.title,className:`page-text`,children:[n===`left`&&e.group&&x(`p`,{className:`page-running-head`,children:i}),x(ee,{fallback:x(`p`,{"data-markdown-loading":!0,"aria-busy":`true`,children:a.loading}),children:x(j,{page:e,text:a,locale:o,onReady:l})})]}):x(`article`,{ref:s,onClick:u,"aria-label":e.section?.title||e.title,className:`page-text`,dangerouslySetInnerHTML:{__html:e.preparedHtml}}),x(`span`,{"aria-hidden":`true`,className:`folio-number`,children:t})]})})}function be(e,t){let n=[];for(let[r,i]of e.entries()){let e=n.at(-1);e?.id!==i.id&&(e={id:i.id,label:r===0&&i.id===`index`?t:i.title,first:r,sections:[]},n.push(e)),i.section&&e.sections.push({section:i.section,position:r})}return n}function xe({library:u,text:f,book:m,pageId:_,anchor:C,onPaperReady:w,onReturn:re}){let[T,ae]=b(!1),[oe,D]=b(!1),[de,O]=b(!1),[fe,k]=b(),A=h(new Map),[j,xe]=b(!1),[M,Se]=b(!1),[N,Ce]=b(u.magicMode??!1),P=h(void 0),[we,Te]=b(()=>new Set),F=h(null),Ee=h(null),I=h(null),L=h(null),De=h(null),R=e?.dataset.initialBook===m.id?e:null,z=ve(ge),B=ve(_e),V=z&&!M,Oe=h(!!w);y(()=>{!w&&Oe.current&&z&&!B&&(Oe.current=!1,D(!0))},[w,B,z]),y(()=>{z||ae(!1)},[z]);let{pages:H}=m,{binding:ke,style:Ae}=s(m.id,m.cover??(u.shelf?void 0:`red`)),je=v(()=>M?be(H,f.cover):[],[M,H,f.cover]),U=c(H,_,C),[W,Me]=b(U),[Ne,Pe]=b(null),Fe=h(null),G=v(()=>z&&!j&&!B?le(W,U):null,[j,B,U,W,z]),Ie=G?U:fe,K=v(()=>Ie===void 0||!z||j||B?null:le(W,Ie),[Ie,B,j,W,z]),q=T&&G&&Ne?.plan===K?Ne:null,Le=z&&!B&&(oe||!!G),Re=T&&(!!q||de);y(()=>{G&&D(!0)},[G]);let ze=g(e=>{ae(e),xe(!e)},[]),J=G?W:U,Y=E(J,z),Be=J===U?C:null,X=h(void 0);S(()=>{if(!N){X.current=void 0;return}let e=I.current;if(!e||B||w||M||G||X.current===Y)return;let t,n=0,r=!1,i=!1,a=()=>{i||n||r||X.current===Y||(n=requestAnimationFrame(()=>{if(n=0,e.querySelector(`:scope > .book-sheet [data-markdown-loading]`))return;let i=[...e.querySelectorAll(`:scope > .book-sheet`)].flatMap(e=>e.getAnimations()).filter(e=>e.pending||e.playState===`running`);i.length?(r=!0,Promise.allSettled(i.map(e=>e.finished)).then(()=>{r=!1,a()})):(X.current=Y,t=pe(e))}))};return e.addEventListener(`grimoire-content`,a),a(),()=>{i=!0,e.removeEventListener(`grimoire-content`,a),cancelAnimationFrame(n),t?.()}},[N,M,w,B,Y,G]);let Ve=g(e=>{O(!0),Me(e.plan.to),Pe(null);let t=E(e.plan.to,!0)+e.plan.direction*2;k(t>=0&&t<H.length?t:void 0)},[H.length]);function Z(e){!z||B||j||G||!H[e]||(D(!0),k(e),H[e]?.preparedHtml===void 0&&he())}y(()=>{let e=()=>{A.current.clear(),k(void 0)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),S(()=>{if(q)for(let e of I.current?.querySelectorAll(`:scope > .book-sheet video`)??[])e.pause()},[q]),S(()=>{let e=I.current;if(!e||!V)return;let t=()=>{let t=ue(e.clientWidth,e.clientHeight);e.style.setProperty(`--read-paper-width`,`${t.width}px`),e.style.setProperty(`--read-paper-height`,`${t.height}px`)},n=new ResizeObserver(t);return t(),n.observe(e),()=>{n.disconnect(),e.style.removeProperty(`--read-paper-width`),e.style.removeProperty(`--read-paper-height`)}},[V]),S(()=>{let e=De.current;if(R instanceof HTMLDivElement&&e)return e.append(R),L.current=R,()=>{R.remove(),L.current=null}},[R]),S(()=>{w&&L.current&&w(L.current)},[w]),y(()=>{G||Me(U)},[U,G]),y(()=>{if(!K){Pe(null);return}let e=Fe.current;if(!T||M||!e)return;let t=K,n=!0;async function r(){if(e?.querySelector(`[data-markdown-loading]`)&&(await he(),await new Promise(e=>requestAnimationFrame(()=>e()))),!n)return;let r=I.current,i=r?.getBoundingClientRect();if(!i)throw Error(`Missing book dimensions`);let a=i;async function o(n){let i=t.panels[n],o=H[i.index];if(!o)return null;let s=e?.querySelector(`[data-ink-face="${n}"] .book-sheet`),c=s?.querySelector(`article`);if(!s||!c)throw Error(`Missing turning page`);let l=r?.querySelector(`:scope > [data-sheet="${i.side}"]`),u=l?.dataset.pageKey===d(o)?l.querySelector(`article`)??void 0:void 0,f=u??c,p=f.scrollTop,m=[...f.querySelectorAll(`.paper-table`)],h=[d(o),i.side,Math.round(a.width),Math.round(a.height),p,...m.map(e=>e.scrollLeft)].join(`:`),g=!f.querySelector(`video,iframe,.paper-diagram-source,[aria-busy=true]`);if(g){let e=A.current.get(h);if(e)return e}let _=c.firstElementChild;if(p&&_ instanceof HTMLElement){let e=Number.parseFloat(getComputedStyle(_).marginTop)||0;c.style.height=`${f.clientHeight}px`,_.style.marginTop=`${e-p}px`}let v=await se(c,s,a,u);if(v&&g){let e=A.current;if(e.size>=6){let t=e.keys().next().value;t!==void 0&&e.delete(t)}e.set(h,v)}if(!v)throw Error(`Unable to render turning page`);return v}let[s,c,l,u]=await Promise.all([o(`left`),o(`right`),o(`front`),o(`back`)]);n&&Pe({plan:t,ink:{left:s,right:c,front:l,back:u}})}return r().catch(()=>{n&&xe(!0)}),()=>{n=!1}},[K,M,H,T]);let He=z&&Y+1<H.length,Ue=z?2:1,Q=Y-Ue,$=Y+Ue,We=H[J],Ge=We?.title||m.title;y(()=>{if(!M)return;let e=F.current;e&&!e.open&&(e.showModal(),e.querySelector(`[aria-current=page]`)?.scrollIntoView({block:`nearest`}))},[M]),y(()=>{let e=e=>{if(M||w||G||document.querySelector(`.diagram-viewer[open]`)||e.altKey||e.metaKey||e.ctrlKey||e.defaultPrevented||e.target instanceof HTMLElement&&e.target.closest(`input,textarea,select,video,[contenteditable],.paper-table,.paper-embed`))return;let t=e.key===`ArrowLeft`?H[Q]:e.key===`ArrowRight`?H[$]:void 0;t&&(e.preventDefault(),l(a(m.id,t.id,t.section?.id)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m.id,$,w,M,H,Q,G]);function Ke(e){P.current=void 0,z||M||w||e.pointerType!==`touch`||!e.isPrimary||e.target instanceof Element&&e.target.closest(`a,button,summary,input,select,textarea,video,iframe,pre,.paper-table,.paper-embed,[contenteditable]`)||(P.current={id:e.pointerId,x:e.clientX,y:e.clientY})}function qe(e){let t=P.current;if(P.current=void 0,!t||t.id!==e.pointerId||M||z)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(Math.abs(n)<48||Math.abs(n)<=1.4*Math.abs(r))return;let i=H[n<0?$:Q];i&&l(a(m.id,i.id,i.section?.id))}function Je(){Se(!1),requestAnimationFrame(()=>Ee.current?.focus())}let Ye=z?Y+1:Y,Xe=H[Ye],Ze=Ye+1;return x(`main`,{tabIndex:-1,"data-magic":N||void 0,className:`reader ${M?`reader--catalog`:``}`,children:[x(`header`,{className:`reader-header`,"data-magic-control":u.magicMode||void 0,children:[u.shelf?x(`a`,{href:t,className:`brand`,onClick:re,children:[x(te,{size:23,"aria-hidden":!0}),f.library]}):x(`span`,{className:`brand`,children:[x(r,{size:26,"aria-hidden":!0}),u.title]}),u.magicMode&&x(`button`,{className:`magic-mode`,type:`button`,"aria-pressed":N,onClick:()=>Ce(!N),children:[x(ie,{size:18,"aria-hidden":!0}),` `,f.magic]}),x(`button`,{type:`button`,ref:Ee,className:`contents-button`,"aria-haspopup":`dialog`,disabled:!!G,onClick:()=>Se(!0),children:[x(ne,{size:22,"aria-hidden":!0}),f.contents]})]}),x(`div`,{className:`reader-stage`,ref:I,"data-ready":Re,"data-binding":ke,style:Ae,"data-wide":z,"data-frame":V?`reading`:void 0,"data-page-turn":!!q,onScrollCapture:()=>{G||k(void 0)},onPointerDown:Ke,onPointerUp:qe,onPointerCancel:()=>{P.current=void 0},children:[R?x(`div`,{className:`resting-art-slot`,ref:De,"aria-hidden":`true`}):x(`div`,{className:`book-fallback`,ref:L,"aria-hidden":`true`,children:z&&x(`div`,{className:`book-resting`,style:{backgroundImage:`url("${i(ke)}")`}})}),G&&!q&&x(`span`,{className:`page-pickup`,"data-direction":G.direction,"aria-hidden":`true`}),Le&&x(`div`,{className:`book-scene`,"aria-hidden":`true`,children:x(ee,{fallback:null,children:x(me,{binding:ke,fittedRead:V,onReady:ze,turn:q,onTurnDone:Ve})})}),z&&x(ye,{page:H[Y],side:`left`,number:Y+1,anchor:Y===J?Be:null,bookTitle:m.title,text:f,locale:u.locale},H[Y]?d(H[Y]):`blank`),x(ye,{page:Xe,side:`right`,number:Ze,anchor:J===Ye?Be:null,bookTitle:m.title,text:f,locale:u.locale},Xe?d(Xe):`blank-right`),K&&T&&!q&&!M&&x(`div`,{className:`turn-capture`,ref:Fe,"aria-hidden":`true`,inert:!0,children:ce.map(e=>{let t=K.panels[e];return H[t.index]&&x(`div`,{className:`turn-capture-face`,"data-ink-face":e,children:x(ye,{page:H[t.index],number:t.index+1,side:t.side,anchor:null,bookTitle:m.title,text:f,locale:u.locale})},e)})})]}),x(`nav`,{className:`reader-pagination`,"aria-label":f.contents,children:[H[Q]?x(`a`,{className:`turn-button`,href:a(m.id,H[Q].id,H[Q].section?.id),"aria-label":f.previous,"aria-disabled":!!G,tabIndex:G?-1:void 0,onClick:e=>{G&&e.preventDefault()},onPointerEnter:()=>Z(Q),onFocus:()=>Z(Q),children:x(te,{"aria-hidden":!0,size:24})}):x(`button`,{type:`button`,className:`turn-button`,"aria-label":f.previous,disabled:!0,children:x(te,{size:24})}),x(`div`,{className:`reading-position`,"aria-live":`polite`,children:[x(`span`,{title:Ge,children:Ge}),x(`span`,{children:[He?`${Y+1}–${Y+2}`:Y+1,` / `,H.length]})]}),H[$]?x(`a`,{className:`turn-button`,href:a(m.id,H[$].id,H[$].section?.id),"aria-label":f.next,"aria-disabled":!!G,tabIndex:G?-1:void 0,onClick:e=>{G&&e.preventDefault()},onPointerEnter:()=>Z($),onFocus:()=>Z($),children:x(p,{"aria-hidden":!0,size:24})}):x(`button`,{type:`button`,className:`turn-button`,"aria-label":f.next,disabled:!0,children:x(p,{size:24})})]}),x(`dialog`,{className:`catalog`,ref:F,onPointerDown:e=>{e.target===e.currentTarget&&F.current?.close()},onClose:Je,"aria-labelledby":M?`catalog-title`:void 0,children:M&&x(`div`,{className:`catalog-paper`,children:[x(`div`,{className:`catalog-header`,children:[x(`h2`,{id:`catalog-title`,children:f.contents}),x(`button`,{type:`button`,"aria-label":f.close,onClick:()=>F.current?.close(),children:x(o,{"aria-hidden":!0,size:24})})]}),x(`ol`,{className:`catalog-pages`,style:{"--folio-digits":String(H.length).length},children:je.map(e=>{let t=We?.id===e.id,r=e.sections,i=r.length>0&&!we.has(e.id),o=t&&i&&(J>e.first||Be)?We.section?.id:void 0;return x(`li`,{children:[x(`div`,{className:`catalog-row`,"data-expandable":r.length>0||void 0,children:[x(`a`,{href:a(m.id,e.id),"aria-current":t&&!o?`page`:void 0,onClick:()=>F.current?.close(),children:[x(`span`,{className:`catalog-label`,children:e.label}),x(`span`,{className:`catalog-leader`,"aria-hidden":`true`}),x(`span`,{className:`catalog-folio`,children:e.first+1})]}),r.length>0&&x(`button`,{type:`button`,className:`catalog-expand`,"aria-label":f.chapterPages(e.label),"aria-expanded":i,onClick:()=>Te(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:x(n,{"aria-hidden":!0,size:15})})]}),i&&x(`ol`,{className:`catalog-nested`,children:r.map(({section:t,position:n})=>x(`li`,{children:x(`a`,{href:a(m.id,e.id,t.id),"aria-current":o===t.id?`page`:void 0,onClick:()=>F.current?.close(),children:[x(`span`,{className:`catalog-label`,children:t.title}),x(`span`,{className:`catalog-leader`,"aria-hidden":`true`}),x(`span`,{className:`catalog-folio`,children:n+1})]})},t.id))})]},e.id)})})]})})]})}export{xe as BookReader,ce as n,ue as t};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BookScene--RuFQb95.js","./jsxRuntime-WpZ1bTm4.js","./three-core-B1q6MRTI.js","./index-B6T7Jb92.js","./index-B_4d4y5z.css","./PageMarkdown-B4BO0Wb7.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,t as f,u as p}from"./index-B6T7Jb92.js";import{a as m,d as h,f as g,g as _,h as v,l as y,p as b,r as ee,t as x,u as S}from"./jsxRuntime-WpZ1bTm4.js";var C={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};C.node;var te=u(C),w={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};w.node;var ne=u(w),re={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};re.node;var ie=u(re);function T(e,t){let n=t?.querySelectorAll(`video`),r=Array.from(e.querySelectorAll(`video`),(e,t)=>{let r=n?.[t]??e,i=document.createElement(`canvas`);i.className=e.className,i.width=Math.max(1,e.clientWidth),i.height=Math.max(1,e.clientHeight);let a=i.getContext(`2d`);return a&&r.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&new URL(r.currentSrc,document.baseURI).origin===window.location.origin&&a.drawImage(r,0,0,i.width,i.height),e.replaceWith(i),{video:e,still:i}});return()=>{for(let{video:e,still:t}of r)t.replaceWith(e)}}function ae(e,t){let n=t?.querySelectorAll(`.paper-table`),r=[];for(let[t,i]of Array.from(e.querySelectorAll(`.paper-table > table`)).entries()){let e=n?.[t]?.scrollLeft||0;if(e){i.style.translate=`${-e}px`,r.push(i);for(let t of i.querySelectorAll(`tr > :first-child`))t.style.translate=`${e}px`,r.push(t)}}return()=>{for(let e of r)e.style.removeProperty(`translate`)}}function oe(e,t){let n=`.paper-diagram, .paper-diagram-source`,r=t?.querySelectorAll(n),i=[];for(let[t,a]of Array.from(e.querySelectorAll(n)).entries()){let e=r?.[t];if(!(e instanceof HTMLImageElement))continue;let n=e.cloneNode();n instanceof HTMLImageElement&&(n.classList.add(`paper-diagram-copy`),a.parentNode?.insertBefore(n,a),i.push(n))}return()=>{for(let e of i)e.remove()}}async function se(e,t,n,r){let{toCanvas:i}=await f(async()=>{let{toCanvas:e}=await import(`./es-YYQGP5MR.js`);return{toCanvas:e}},[],import.meta.url);await document.fonts.ready;let a=T(e,r),o=ae(e,r),s=oe(e,r),c=t.getBoundingClientRect(),l=await i(t,{pixelRatio:1.4,skipFonts:!0,style:{position:`relative`,inset:`auto`,overflow:`hidden`,visibility:`visible`,backgroundColor:`transparent`}}).finally(()=>{s(),o(),a()}),u=document.createElement(`canvas`),d=Math.min(1.35,2304/n.width,1440/n.height);u.width=Math.round(n.width*d),u.height=Math.round(n.height*d);let p=u.getContext(`2d`);return!p||!l.width?null:(p.drawImage(l,(c.left-n.left)/n.width*u.width,(c.top-n.top)/n.height*u.height,c.width/n.width*u.width,c.height/n.height*u.height),u)}var ce=[`left`,`right`,`front`,`back`];function E(e,t){return t?Math.floor(e/2)*2:e}function le(e,t){let n=E(e,!0),r=E(t,!0);if(n===r)return null;let i=n<r?1:-1,a=Math.min(n,r),o=Math.max(n,r);return{to:t,direction:i,panels:{left:{index:a,side:`left`},right:{index:o+1,side:`right`},front:{index:a+1,side:`right`},back:{index:o,side:`left`}}}}function ue(e,t){return{width:Math.min(e*.86,t*2.2),height:Math.min(t*.88,e*.82)}}var D=860;function de(e,t){let n=document.createRange();return n.selectNodeContents(e),[...n.getClientRects()].filter(e=>e.width>0&&e.height>0&&e.bottom>t.top&&e.top<t.bottom)}function O(e,t,n){let r=document.createElement(`span`);return r.className=n,r.style.left=`${t.left-e.bounds.left}px`,r.style.top=`${t.top-e.bounds.top}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,e.overlay.append(r),r}function fe(e,t,n){let r=de(t,e.bounds);if(!r.length||r.length>6)return;t.classList.add(`spell-drawing-${n}`),e.changed.push(t);let i=D/r.length,a=r.flatMap((t,r)=>{let a=O(e,t,`spell-ink spell-ink-${n}`),o=document.createElement(`span`);o.className=`spell-stroke`,a.append(o);let s={delay:r*i,duration:i,fill:`both`},c=o.animate([{transform:`scaleX(0)`},{transform:`scaleX(0)`,offset:.12},{transform:`scaleX(1)`,offset:.84},{transform:`scaleX(1)`}],s);if(n===`underline`)return[c];let l=document.createElement(`span`);return l.className=n===`mark`?`spell-marker-tip`:`spell-ink-dust`,a.append(l),[c,l.animate([{transform:`translate(0,-.45em)`,opacity:0},{transform:`translateX(0)`,opacity:1,offset:.12},{transform:`translateX(${t.width}px)`,opacity:1,offset:.84},{transform:`translate(${t.width}px,-.55em)`,opacity:0}],s)]});e.running.push(...a),Promise.allSettled(a.map(e=>e.finished)).then(()=>{t.classList.remove(`spell-drawing-${n}`);for(let e of a)e.effect instanceof KeyframeEffect&&e.effect.target instanceof Element&&e.effect.target.parentElement?.remove()})}function k(e,t,n){if(t.childNodes.length!==1||!(t.firstChild instanceof Text))return;let r=t.firstChild,i=[...new Intl.Segmenter().segment(r.data)];if(!i.length||i.length>46)return;let a=document.createRange(),o=getComputedStyle(t).font,s=[];for(let{index:t,segment:n}of i){if(!n.trim())continue;a.setStart(r,t),a.setEnd(r,t+n.length);let i=a.getBoundingClientRect();if(!i.width||i.bottom<=e.bounds.top||i.top>=e.bounds.bottom){for(let{glyph:e}of s)e.remove();return}let c=O(e,i,`spell-letter`);c.style.font=o,c.textContent=n,s.push({glyph:c,rect:i})}if(!s.length)return;let c=s.map(({glyph:t,rect:n})=>{a.selectNodeContents(t);let r=a.getBoundingClientRect();return{glyph:t,left:n.left-e.bounds.left+n.left-r.left,top:n.top-e.bounds.top+n.top-r.top}});for(let{glyph:e,left:t,top:n}of c)e.style.left=`${t}px`,e.style.top=`${n}px`;t.classList.add(`spell-letters-rising`),e.changed.push(t);let l=s.map(({glyph:e},t)=>e.animate([{transform:`translateY(0)`},{transform:`translate(${n?(t%3-1)*.4:0}em,${n?-.9-t%2*.35:-.38}em) rotate(${t%2?9:-7}deg)`,offset:.48},{transform:`translateY(0)`}],{duration:n?810:520,delay:Math.min(t*38,250),easing:`ease-in-out`,fill:`both`}));e.running.push(...l),Promise.allSettled(l.map(e=>e.finished)).then(()=>{t.classList.remove(`spell-letters-rising`);for(let{glyph:e}of s)e.remove()})}function A(e,t){if(t.matches(`.paper-alert`)){let n=O(e,t.getBoundingClientRect(),`spell-seal`);n.textContent=`!`,e.running.push(n.animate([{transform:`translateY(-1em) scale(1.5) rotate(-18deg)`,opacity:0},{transform:`scale(1)`,opacity:1,offset:.45},{transform:`scale(1)`,opacity:0}],{duration:920,fill:`both`}));return}if(t.matches(`.paper-red`)){let n=O(e,t.getBoundingClientRect(),`spell-red-drop`);e.running.push(n.animate([{transform:`translateY(-.9em)`,opacity:0},{transform:`translateY(0)`,opacity:1,offset:.54},{transform:`translateY(.22em) scale(1.35,.45)`,opacity:0}],{duration:680,fill:`both`}));return}if(t.localName===`code`){if(t.closest(`pre`))return;let n=O(e,t.getBoundingClientRect(),`spell-code-frame`),r=document.createElement(`span`),i=document.createElement(`span`);r.textContent=`[`,i.textContent=`]`,n.append(r,i);for(let[t,n]of[r,i].entries())e.running.push(n.animate([{transform:`translateX(${t?.8:-.8}em)`,opacity:0},{transform:`translateX(0)`,opacity:.7,offset:.62},{transform:`translateX(0)`,opacity:0}],{duration:790,fill:`both`}));return}let n=t.classList.contains(`paper-diagram`)?[{clipPath:`inset(0 0 100% 0)`},{clipPath:`inset(0)`}]:[{opacity:.78,textShadow:`0 .17em .08em #5639235c`},{opacity:1,textShadow:`none`}];e.running.push(t.animate(n,{duration:660,easing:`ease-out`}))}function pe(e){let t=[];for(let n of e.querySelectorAll(`:scope > .book-sheet .page-text`)){let e=document.createElement(`div`);e.className=`spell-overlay`,e.setAttribute(`aria-hidden`,`true`),e.style.insetInlineStart=`${n.scrollLeft}px`,e.style.insetBlockStart=`${n.scrollTop}px`,e.style.width=`${n.clientWidth}px`,e.style.height=`${n.clientHeight}px`,n.append(e);let r={article:n,bounds:n.getBoundingClientRect(),overlay:e,running:[],changed:[]},i=n.querySelectorAll(`mark,u,del,strong,em,h1,h2,h3,code,.paper-red,.paper-alert,.paper-diagram`);for(let e of[...i].slice(0,24)){let t=e.getBoundingClientRect();t.bottom<r.bounds.top||t.top>r.bounds.bottom||(e.matches(`mark,u,del`)?fe(r,e,e.localName===`mark`?`mark`:e.localName===`u`?`underline`:`cross`):e.matches(`strong,em`)?k(r,e,e.matches(`strong`)):A(r,e))}if(!r.running.length){e.remove();continue}let a=!1,o=()=>{if(!a){a=!0,n.removeEventListener(`scroll`,o),window.removeEventListener(`resize`,o);for(let e of r.running)e.cancel();for(let e of r.changed)e.classList.remove(`spell-drawing-mark`,`spell-drawing-underline`,`spell-drawing-cross`,`spell-letters-rising`);e.remove()}};n.addEventListener(`scroll`,o,{passive:!0}),window.addEventListener(`resize`,o),t.push(o),Promise.allSettled(r.running.map(e=>e.finished)).then(o)}return()=>{for(let e of t)e()}}var me=m(()=>f(()=>import(`./BookScene--RuFQb95.js`),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),he=()=>f(()=>import(`./PageMarkdown-B4BO0Wb7.js`),__vite__mapDeps([5,1,3,4]),import.meta.url),j=m(he),ge=`(min-width: 700px)`,_e=`(prefers-reduced-motion: reduce)`;function ve(e){let[t,n]=b(()=>matchMedia(e).matches);return y(()=>{let t=matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ye({page:e,number:t,side:n,anchor:r,bookTitle:i,text:a,locale:o}){let s=h(null),c=g(()=>{if(!s.current||(s.current.scrollTop=0,!r))return;let e=Array.from(s.current.querySelectorAll(`[id]`)).find(e=>e.id===r);e&&(s.current.scrollTop=e.getBoundingClientRect().top-s.current.getBoundingClientRect().top)},[r]);S(()=>c(),[c]);let l=g(()=>{c(),s.current?.dispatchEvent(new Event(`grimoire-content`,{bubbles:!0}))},[c]);function u(e){if(!(e.target instanceof Element))return;let t=e.target.closest(`a[data-footnote-ref], a[data-footnote-backref]`);if(!t||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let n=decodeURIComponent(new URL(t.href).hash.slice(1)),r=Array.from(s.current?.querySelectorAll(`[id]`)??[]).find(e=>e.id===n);r&&s.current&&(e.preventDefault(),s.current.scrollTop+=r.getBoundingClientRect().top-s.current.getBoundingClientRect().top,r.focus({preventScroll:!0}))}return x(`div`,{className:`book-sheet book-sheet--${n}`,"data-sheet":n,"data-page-id":e?.id,"data-page-key":e&&d(e),"data-section-id":e?.section?.id,children:e&&x(_,{children:[e.preparedHtml===void 0?x(`article`,{ref:s,onClick:u,"aria-label":e.section?.title||e.title,className:`page-text`,children:[n===`left`&&e.group&&x(`p`,{className:`page-running-head`,children:i}),x(ee,{fallback:x(`p`,{"data-markdown-loading":!0,"aria-busy":`true`,children:a.loading}),children:x(j,{page:e,text:a,locale:o,onReady:l})})]}):x(`article`,{ref:s,onClick:u,"aria-label":e.section?.title||e.title,className:`page-text`,dangerouslySetInnerHTML:{__html:e.preparedHtml}}),x(`span`,{"aria-hidden":`true`,className:`folio-number`,children:t})]})})}function be(e,t){let n=[];for(let[r,i]of e.entries()){let e=n.at(-1);e?.id!==i.id&&(e={id:i.id,label:r===0&&i.id===`index`?t:i.title,first:r,sections:[]},n.push(e)),i.section&&e.sections.push({section:i.section,position:r})}return n}function xe({library:u,text:f,book:m,pageId:_,anchor:C,onPaperReady:w,onReturn:re}){let[T,ae]=b(!1),[oe,D]=b(!1),[de,O]=b(!1),[fe,k]=b(),A=h(new Map),[j,xe]=b(!1),[M,Se]=b(!1),[N,Ce]=b(u.magicMode??!1),P=h(void 0),[we,Te]=b(()=>new Set),F=h(null),Ee=h(null),I=h(null),L=h(null),De=h(null),R=e?.dataset.initialBook===m.id?e:null,z=ve(ge),B=ve(_e),V=z&&!M,Oe=h(!!w);y(()=>{!w&&Oe.current&&z&&!B&&(Oe.current=!1,D(!0))},[w,B,z]),y(()=>{z||ae(!1)},[z]);let{pages:H}=m,{binding:ke,style:Ae}=s(m.id,m.cover??(u.shelf?void 0:`red`)),je=v(()=>M?be(H,f.cover):[],[M,H,f.cover]),U=c(H,_,C),[W,Me]=b(U),[Ne,Pe]=b(null),Fe=h(null),G=v(()=>z&&!j&&!B?le(W,U):null,[j,B,U,W,z]),Ie=G?U:fe,K=v(()=>Ie===void 0||!z||j||B?null:le(W,Ie),[Ie,B,j,W,z]),q=T&&G&&Ne?.plan===K?Ne:null,Le=z&&!B&&(oe||!!G),Re=T&&(!!q||de);y(()=>{G&&D(!0)},[G]);let ze=g(e=>{ae(e),xe(!e)},[]),J=G?W:U,Y=E(J,z),Be=J===U?C:null,X=h(void 0);S(()=>{if(!N){X.current=void 0;return}let e=I.current;if(!e||B||w||M||G||X.current===Y)return;let t,n=0,r=!1,i=!1,a=()=>{i||n||r||X.current===Y||(n=requestAnimationFrame(()=>{if(n=0,e.querySelector(`:scope > .book-sheet [data-markdown-loading]`))return;let i=[...e.querySelectorAll(`:scope > .book-sheet`)].flatMap(e=>e.getAnimations()).filter(e=>e.pending||e.playState===`running`);i.length?(r=!0,Promise.allSettled(i.map(e=>e.finished)).then(()=>{r=!1,a()})):(X.current=Y,t=pe(e))}))};return e.addEventListener(`grimoire-content`,a),a(),()=>{i=!0,e.removeEventListener(`grimoire-content`,a),cancelAnimationFrame(n),t?.()}},[N,M,w,B,Y,G]);let Ve=g(e=>{O(!0),Me(e.plan.to),Pe(null);let t=E(e.plan.to,!0)+e.plan.direction*2;k(t>=0&&t<H.length?t:void 0)},[H.length]);function Z(e){!z||B||j||G||!H[e]||(D(!0),k(e),H[e]?.preparedHtml===void 0&&he())}y(()=>{let e=()=>{A.current.clear(),k(void 0)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),S(()=>{if(q)for(let e of I.current?.querySelectorAll(`:scope > .book-sheet video`)??[])e.pause()},[q]),S(()=>{let e=I.current;if(!e||!V)return;let t=()=>{let t=ue(e.clientWidth,e.clientHeight);e.style.setProperty(`--read-paper-width`,`${t.width}px`),e.style.setProperty(`--read-paper-height`,`${t.height}px`)},n=new ResizeObserver(t);return t(),n.observe(e),()=>{n.disconnect(),e.style.removeProperty(`--read-paper-width`),e.style.removeProperty(`--read-paper-height`)}},[V]),S(()=>{let e=De.current;if(R instanceof HTMLDivElement&&e)return e.append(R),L.current=R,()=>{R.remove(),L.current=null}},[R]),S(()=>{w&&L.current&&w(L.current)},[w]),y(()=>{G||Me(U)},[U,G]),y(()=>{if(!K){Pe(null);return}let e=Fe.current;if(!T||M||!e)return;let t=K,n=!0;async function r(){if(e?.querySelector(`[data-markdown-loading]`)&&(await he(),await new Promise(e=>requestAnimationFrame(()=>e()))),!n)return;let r=I.current,i=r?.getBoundingClientRect();if(!i)throw Error(`Missing book dimensions`);let a=i;async function o(n){let i=t.panels[n],o=H[i.index];if(!o)return null;let s=e?.querySelector(`[data-ink-face="${n}"] .book-sheet`),c=s?.querySelector(`article`);if(!s||!c)throw Error(`Missing turning page`);let l=r?.querySelector(`:scope > [data-sheet="${i.side}"]`),u=l?.dataset.pageKey===d(o)?l.querySelector(`article`)??void 0:void 0,f=u??c,p=f.scrollTop,m=[...f.querySelectorAll(`.paper-table`)],h=[d(o),i.side,Math.round(a.width),Math.round(a.height),p,...m.map(e=>e.scrollLeft)].join(`:`),g=!f.querySelector(`video,iframe,.paper-diagram-source,[aria-busy=true]`);if(g){let e=A.current.get(h);if(e)return e}let _=c.firstElementChild;if(p&&_ instanceof HTMLElement){let e=Number.parseFloat(getComputedStyle(_).marginTop)||0;c.style.height=`${f.clientHeight}px`,_.style.marginTop=`${e-p}px`}let v=await se(c,s,a,u);if(v&&g){let e=A.current;if(e.size>=6){let t=e.keys().next().value;t!==void 0&&e.delete(t)}e.set(h,v)}if(!v)throw Error(`Unable to render turning page`);return v}let[s,c,l,u]=await Promise.all([o(`left`),o(`right`),o(`front`),o(`back`)]);n&&Pe({plan:t,ink:{left:s,right:c,front:l,back:u}})}return r().catch(()=>{n&&xe(!0)}),()=>{n=!1}},[K,M,H,T]);let He=z&&Y+1<H.length,Ue=z?2:1,Q=Y-Ue,$=Y+Ue,We=H[J],Ge=We?.title||m.title;y(()=>{if(!M)return;let e=F.current;e&&!e.open&&(e.showModal(),e.querySelector(`[aria-current=page]`)?.scrollIntoView({block:`nearest`}))},[M]),y(()=>{let e=e=>{if(M||w||G||document.querySelector(`.diagram-viewer[open]`)||e.altKey||e.metaKey||e.ctrlKey||e.defaultPrevented||e.target instanceof HTMLElement&&e.target.closest(`input,textarea,select,video,[contenteditable],.paper-table,.paper-embed`))return;let t=e.key===`ArrowLeft`?H[Q]:e.key===`ArrowRight`?H[$]:void 0;t&&(e.preventDefault(),l(a(m.id,t.id,t.section?.id)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m.id,$,w,M,H,Q,G]);function Ke(e){P.current=void 0,z||M||w||e.pointerType!==`touch`||!e.isPrimary||e.target instanceof Element&&e.target.closest(`a,button,summary,input,select,textarea,video,iframe,pre,.paper-table,.paper-embed,[contenteditable]`)||(P.current={id:e.pointerId,x:e.clientX,y:e.clientY})}function qe(e){let t=P.current;if(P.current=void 0,!t||t.id!==e.pointerId||M||z)return;let n=e.clientX-t.x,r=e.clientY-t.y;if(Math.abs(n)<48||Math.abs(n)<=1.4*Math.abs(r))return;let i=H[n<0?$:Q];i&&l(a(m.id,i.id,i.section?.id))}function Je(){Se(!1),requestAnimationFrame(()=>Ee.current?.focus())}let Ye=z?Y+1:Y,Xe=H[Ye],Ze=Ye+1;return x(`main`,{tabIndex:-1,"data-magic":N||void 0,className:`reader ${M?`reader--catalog`:``}`,children:[x(`header`,{className:`reader-header`,"data-magic-control":u.magicMode||void 0,children:[u.shelf?x(`a`,{href:t,className:`brand`,onClick:re,children:[x(te,{size:23,"aria-hidden":!0}),f.library]}):x(`span`,{className:`brand`,children:[x(r,{size:26,"aria-hidden":!0}),u.title]}),u.magicMode&&x(`button`,{className:`magic-mode`,type:`button`,"aria-pressed":N,onClick:()=>Ce(!N),children:[x(ie,{size:18,"aria-hidden":!0}),` `,f.magic]}),x(`button`,{type:`button`,ref:Ee,className:`contents-button`,"aria-haspopup":`dialog`,disabled:!!G,onClick:()=>Se(!0),children:[x(ne,{size:22,"aria-hidden":!0}),f.contents]})]}),x(`div`,{className:`reader-stage`,ref:I,"data-ready":Re,"data-binding":ke,style:Ae,"data-wide":z,"data-frame":V?`reading`:void 0,"data-page-turn":!!q,onScrollCapture:()=>{G||k(void 0)},onPointerDown:Ke,onPointerUp:qe,onPointerCancel:()=>{P.current=void 0},children:[R?x(`div`,{className:`resting-art-slot`,ref:De,"aria-hidden":`true`}):x(`div`,{className:`book-fallback`,ref:L,"aria-hidden":`true`,children:z&&x(`div`,{className:`book-resting`,style:{backgroundImage:`url("${i(ke)}")`}})}),G&&!q&&x(`span`,{className:`page-pickup`,"data-direction":G.direction,"aria-hidden":`true`}),Le&&x(`div`,{className:`book-scene`,"aria-hidden":`true`,children:x(ee,{fallback:null,children:x(me,{binding:ke,fittedRead:V,onReady:ze,turn:q,onTurnDone:Ve})})}),z&&x(ye,{page:H[Y],side:`left`,number:Y+1,anchor:Y===J?Be:null,bookTitle:m.title,text:f,locale:u.locale},H[Y]?d(H[Y]):`blank`),x(ye,{page:Xe,side:`right`,number:Ze,anchor:J===Ye?Be:null,bookTitle:m.title,text:f,locale:u.locale},Xe?d(Xe):`blank-right`),K&&T&&!q&&!M&&x(`div`,{className:`turn-capture`,ref:Fe,"aria-hidden":`true`,inert:!0,children:ce.map(e=>{let t=K.panels[e];return H[t.index]&&x(`div`,{className:`turn-capture-face`,"data-ink-face":e,children:x(ye,{page:H[t.index],number:t.index+1,side:t.side,anchor:null,bookTitle:m.title,text:f,locale:u.locale})},e)})})]}),x(`nav`,{className:`reader-pagination`,"aria-label":f.contents,children:[H[Q]?x(`a`,{className:`turn-button`,href:a(m.id,H[Q].id,H[Q].section?.id),"aria-label":f.previous,"aria-disabled":!!G,tabIndex:G?-1:void 0,onClick:e=>{G&&e.preventDefault()},onPointerEnter:()=>Z(Q),onFocus:()=>Z(Q),children:x(te,{"aria-hidden":!0,size:24})}):x(`button`,{type:`button`,className:`turn-button`,"aria-label":f.previous,disabled:!0,children:x(te,{size:24})}),x(`div`,{className:`reading-position`,"aria-live":`polite`,children:[x(`span`,{title:Ge,children:Ge}),x(`span`,{children:[He?`${Y+1}–${Y+2}`:Y+1,` / `,H.length]})]}),H[$]?x(`a`,{className:`turn-button`,href:a(m.id,H[$].id,H[$].section?.id),"aria-label":f.next,"aria-disabled":!!G,tabIndex:G?-1:void 0,onClick:e=>{G&&e.preventDefault()},onPointerEnter:()=>Z($),onFocus:()=>Z($),children:x(p,{"aria-hidden":!0,size:24})}):x(`button`,{type:`button`,className:`turn-button`,"aria-label":f.next,disabled:!0,children:x(p,{size:24})})]}),x(`dialog`,{className:`catalog`,ref:F,onPointerDown:e=>{e.target===e.currentTarget&&F.current?.close()},onClose:Je,"aria-labelledby":M?`catalog-title`:void 0,children:M&&x(`div`,{className:`catalog-paper`,children:[x(`div`,{className:`catalog-header`,children:[x(`h2`,{id:`catalog-title`,children:f.contents}),x(`button`,{type:`button`,"aria-label":f.close,onClick:()=>F.current?.close(),children:x(o,{"aria-hidden":!0,size:24})})]}),x(`ol`,{className:`catalog-pages`,style:{"--folio-digits":String(H.length).length},children:je.map(e=>{let t=We?.id===e.id,r=e.sections,i=r.length>0&&!we.has(e.id),o=t&&i&&(J>e.first||Be)?We.section?.id:void 0;return x(`li`,{children:[x(`div`,{className:`catalog-row`,"data-expandable":r.length>0||void 0,children:[x(`a`,{href:a(m.id,e.id),"aria-current":t&&!o?`page`:void 0,onClick:()=>F.current?.close(),children:[x(`span`,{className:`catalog-label`,children:e.label}),x(`span`,{className:`catalog-leader`,"aria-hidden":`true`}),x(`span`,{className:`catalog-folio`,children:e.first+1})]}),r.length>0&&x(`button`,{type:`button`,className:`catalog-expand`,"aria-label":f.chapterPages(e.label),"aria-expanded":i,onClick:()=>Te(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:x(n,{"aria-hidden":!0,size:15})})]}),i&&x(`ol`,{className:`catalog-nested`,children:r.map(({section:t,position:n})=>x(`li`,{children:x(`a`,{href:a(m.id,e.id,t.id),"aria-current":o===t.id?`page`:void 0,onClick:()=>F.current?.close(),children:[x(`span`,{className:`catalog-label`,children:t.title}),x(`span`,{className:`catalog-leader`,"aria-hidden":`true`}),x(`span`,{className:`catalog-folio`,children:n+1})]})},t.id))})]},e.id)})})]})})]})}export{xe as BookReader,ce as n,ue as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e,l as t,t as n,u as r}from"./jsxRuntime-WpZ1bTm4.js";import{$ as i,$n as a,A as o,An as s,At as c,B as l,Bn as u,C as d,Cn as f,Ct as p,D as m,Dn as h,Dt as g,E as _,Et as v,F as y,Fn as b,Ft as x,G as S,Gn as C,H as w,Hn as T,I as E,In as D,J as O,Jn as k,K as A,Kn as ee,L as j,Mn as M,N as te,Nn as N,O as P,On as F,Ot as ne,P as re,Pn as ie,Pt as ae,Q as I,Qn as oe,R as se,Rn as ce,S as L,Sn as le,St as ue,T as de,Tn as fe,Tt as pe,U as me,Un as he,V as ge,Vn as _e,W as ve,Wn as R,X as ye,Xn as be,Y as xe,Yn as Se,Z as Ce,Zn as we,_ as Te,_n as Ee,_t as De,a as Oe,ar as z,at as B,b as ke,bt as Ae,c as je,cr as Me,ct as Ne,d as V,dn as Pe,dt as H,er as U,et as Fe,f as W,fn as Ie,ft as G,g as Le,gn as K,gt as q,h as Re,hn as ze,ht as Be,i as Ve,ir as He,it as Ue,j as We,jn as Ge,k as Ke,kn as qe,lt as Je,m as Ye,mt as Xe,n as Ze,nr as Qe,nt as $e,o as et,or as tt,ot as nt,p as J,pn as rt,pt as it,q as at,qn as ot,r as st,rr as ct,rt as lt,s as ut,sr as Y,st as dt,tr as ft,tt as pt,u as mt,ut as ht,v as gt,vt as _t,w as vt,wn as yt,wt as bt,x as xt,xt as St,y as Ct,yt as wt}from"./three-core-B1q6MRTI.js";import{m as Tt}from"./index-
|
|
1
|
+
import{d as e,l as t,t as n,u as r}from"./jsxRuntime-WpZ1bTm4.js";import{$ as i,$n as a,A as o,An as s,At as c,B as l,Bn as u,C as d,Cn as f,Ct as p,D as m,Dn as h,Dt as g,E as _,Et as v,F as y,Fn as b,Ft as x,G as S,Gn as C,H as w,Hn as T,I as E,In as D,J as O,Jn as k,K as A,Kn as ee,L as j,Mn as M,N as te,Nn as N,O as P,On as F,Ot as ne,P as re,Pn as ie,Pt as ae,Q as I,Qn as oe,R as se,Rn as ce,S as L,Sn as le,St as ue,T as de,Tn as fe,Tt as pe,U as me,Un as he,V as ge,Vn as _e,W as ve,Wn as R,X as ye,Xn as be,Y as xe,Yn as Se,Z as Ce,Zn as we,_ as Te,_n as Ee,_t as De,a as Oe,ar as z,at as B,b as ke,bt as Ae,c as je,cr as Me,ct as Ne,d as V,dn as Pe,dt as H,er as U,et as Fe,f as W,fn as Ie,ft as G,g as Le,gn as K,gt as q,h as Re,hn as ze,ht as Be,i as Ve,ir as He,it as Ue,j as We,jn as Ge,k as Ke,kn as qe,lt as Je,m as Ye,mt as Xe,n as Ze,nr as Qe,nt as $e,o as et,or as tt,ot as nt,p as J,pn as rt,pt as it,q as at,qn as ot,r as st,rr as ct,rt as lt,s as ut,sr as Y,st as dt,tr as ft,tt as pt,u as mt,ut as ht,v as gt,vt as _t,w as vt,wn as yt,wt as bt,x as xt,xt as St,y as Ct,yt as wt}from"./three-core-B1q6MRTI.js";import{m as Tt}from"./index-B6T7Jb92.js";import{n as Et,t as Dt}from"./BookReader-1Rx9lwH4.js";function Ot(){let e=null,t=!1,n=null,r=null;function i(t,a){r=e.requestAnimationFrame(i),n(t,a)}return{start:function(){t!==!0&&n!==null&&e!==null&&(r=e.requestAnimationFrame(i),t=!0)},stop:function(){e!==null&&e.cancelAnimationFrame(r),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function kt(e){let t=new WeakMap;function n(t,n){let r=t.array,i=t.usage,a=r.byteLength,o=e.createBuffer();e.bindBuffer(n,o),e.bufferData(n,r,i),t.onUploadCallback();let s;if(r instanceof Float32Array)s=e.FLOAT;else if(typeof Float16Array<`u`&&r instanceof Float16Array)s=e.HALF_FLOAT;else if(r instanceof Uint16Array)s=t.isFloat16BufferAttribute?e.HALF_FLOAT:e.UNSIGNED_SHORT;else if(r instanceof Int16Array)s=e.SHORT;else if(r instanceof Uint32Array)s=e.UNSIGNED_INT;else if(r instanceof Int32Array)s=e.INT;else if(r instanceof Int8Array)s=e.BYTE;else if(r instanceof Uint8Array)s=e.UNSIGNED_BYTE;else if(r instanceof Uint8ClampedArray)s=e.UNSIGNED_BYTE;else throw Error(`THREE.WebGLAttributes: Unsupported buffer data format: `+r);return{buffer:o,type:s,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,size:a}}function r(t,n,r){let i=n.array,a=n.updateRanges;if(e.bindBuffer(r,t),a.length===0)e.bufferSubData(r,0,i);else{a.sort((e,t)=>e.start-t.start);let t=0;for(let e=1;e<a.length;e++){let n=a[t],r=a[e];r.start<=n.start+n.count+1?n.count=Math.max(n.count,r.start+r.count-n.start):(++t,a[t]=r)}a.length=t+1;for(let t=0,n=a.length;t<n;t++){let n=a[t];e.bufferSubData(r,n.start*i.BYTES_PER_ELEMENT,i,n.start,n.count)}n.clearUpdateRanges()}n.onUploadCallback()}function i(e){return e.isInterleavedBufferAttribute&&(e=e.data),t.get(e)}function a(n){n.isInterleavedBufferAttribute&&(n=n.data);let r=t.get(n);r&&(e.deleteBuffer(r.buffer),t.delete(n))}function o(e,i){if(e.isInterleavedBufferAttribute&&(e=e.data),e.isGLBufferAttribute){let n=t.get(e);(!n||n.version<e.version)&&t.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version});return}let a=t.get(e);if(a===void 0)t.set(e,n(e,i));else if(a.version<e.version){if(a.size!==e.array.byteLength)throw Error(`THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.`);r(a.buffer,e,i),a.version=e.version}}return{get:i,remove:a,update:o}}var X={alphahash_fragment:`#ifdef USE_ALPHAHASH
|
|
2
2
|
if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
|
|
3
3
|
#endif`,alphahash_pars_fragment:`#ifdef USE_ALPHAHASH
|
|
4
4
|
const float ALPHA_HASH_SCALE = 0.05;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{l as e,p as t}from"./index-B6T7Jb92.js";import{d as n,p as r,t as i,u as a}from"./jsxRuntime-WpZ1bTm4.js";var o={name:`maximize-2`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]};o.node;var s=t(o),c={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};c.node;var l=t(c),u={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};u.node;var d=t(u),f=16;function p({image:t,imageLabel:o,text:c,onClose:u}){let p=o??c.diagram,m=n(null),h=n(null),[g,_]=r({width:0,height:0}),[v,y]=r(1),[b,x]=r(!1),S=n({x:.5,y:.5}),C=n(null);a(()=>{let e=m.current,t=h.current;if(!e||!t)return;e.showModal();let n=()=>{_({width:t.clientWidth,height:t.clientHeight})},r=new ResizeObserver(n);return r.observe(t),n(),t.focus({preventScroll:!0}),()=>r.disconnect()},[]);let w=Math.min(g.width,g.height*t.ratio)*v,T=w/t.ratio,E=Math.max(g.width,w),D=Math.max(g.height,T);a(()=>{let e=h.current;e&&(e.scrollLeft=S.current.x*E-e.clientWidth/2,e.scrollTop=S.current.y*D-e.clientHeight/2)},[D,E]);function O(e){let t=h.current,n=Math.min(f,Math.max(1,e));t&&n!==v&&(S.current=n===1?{x:.5,y:.5}:{x:(t.scrollLeft+t.clientWidth/2)/Math.max(1,t.scrollWidth),y:(t.scrollTop+t.clientHeight/2)/Math.max(1,t.scrollHeight)},y(n))}function k(e){let t=e.currentTarget;e.pointerType===`touch`||e.button!==0||!e.isPrimary||t.scrollWidth<=t.clientWidth&&t.scrollHeight<=t.clientHeight||(C.current={pointer:e.pointerId,x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop},t.setPointerCapture(e.pointerId),x(!0))}function A(e){let t=C.current;if(!t||e.pointerId!==t.pointer)return;let n=e.currentTarget;n.scrollLeft=t.left+t.x-e.clientX,n.scrollTop=t.top+t.y-e.clientY}function j(e){e.pointerId===C.current?.pointer&&(C.current=null,x(!1))}function M(e){if(!(e.target instanceof Element)||e.touches.length)return;let t=e.target.closest(`button:not(:disabled)`),n=e.changedTouches.item(0);if(!t||!n)return;let r=t.getBoundingClientRect();n.clientX<r.left||n.clientX>r.right||n.clientY<r.top||n.clientY>r.bottom||(e.preventDefault(),t.click())}return i(`dialog`,{ref:m,className:o?`diagram-viewer image-lightbox`:`diagram-viewer`,"aria-label":p,onClose:u,onKeyDown:e=>{if(e.key===`+`||e.key===`=`)O(v*1.5);else if(e.key===`-`)O(v/1.5);else if(e.key===`0`)O(1);else return;e.preventDefault()},children:[i(`header`,{className:`diagram-toolbar`,children:[i(`h2`,{children:p}),i(`div`,{className:`diagram-controls`,onTouchEnd:M,children:[i(`button`,{type:`button`,"aria-label":c.zoomOut,disabled:v<=1,onClick:()=>O(v/1.5),children:i(l,{size:19,"aria-hidden":`true`})}),!o&&i(`output`,{"aria-live":`polite`,children:[Math.round(v*100),`%`]}),i(`button`,{type:`button`,"aria-label":c.zoomIn,disabled:v>=f,onClick:()=>O(v*1.5),children:i(d,{size:19,"aria-hidden":`true`})}),i(`button`,{type:`button`,"aria-label":o?c.imageFit:c.diagramFit,onClick:()=>O(1),children:o?c.fit:i(s,{size:18,"aria-hidden":`true`})}),i(`button`,{type:`button`,"aria-label":c.close,onClick:()=>m.current?.close(),children:i(e,{size:21,"aria-hidden":`true`})})]})]}),i(`section`,{className:`diagram-viewport`,ref:h,"aria-label":o?c.imagePan:c.diagramPan,tabIndex:0,"data-pannable":v>1||void 0,"data-grabbing":b||void 0,onPointerDown:k,onPointerMove:A,onPointerUp:j,onPointerCancel:j,onLostPointerCapture:j,children:i(`div`,{className:`diagram-surface`,style:{width:E,height:D},children:i(`img`,{src:t.src,alt:p,draggable:!1,style:{width:w,height:T}})})})]})}export{p as DiagramViewer};
|