docblocks-react-ui 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +43 -32
- package/dist/{Editor-BBbAwxWT.mjs → Editor-DcQTuUsM.mjs} +13617 -13396
- package/dist/{constants-BaAj3jDA.mjs → constants-2VXoyPmd.mjs} +76 -43
- package/dist/{index-DtVBbaEs.d.mts → index-DyPFy2m5.d.mts} +40 -75
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +3 -3
- package/dist/mermaid/index.mjs +2 -2
- package/dist/pdf/index.d.mts +2 -2
- package/dist/pdf/index.mjs +253 -60
- package/dist/styles.css +9 -3
- package/package.json +2 -2
package/dist/pdf/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as TriangleAlert, d as ChevronRight, f as ChevronLeft, i as isSafeDownloadHref, l as Plus, p as cn, r as clamp, s as X, t as isEmbeddablePdfUrl, u as Minus } from "../constants-2VXoyPmd.mjs";
|
|
2
2
|
import { t as LoaderCircle } from "../LoaderCircle-AGVFE4IP.mjs";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -49,6 +49,52 @@ function Minimize(props) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
|
+
//#region src/shared/ui/icons/StretchHorizontal.tsx
|
|
53
|
+
function StretchHorizontal(props) {
|
|
54
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
55
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
56
|
+
width: 24,
|
|
57
|
+
height: 24,
|
|
58
|
+
viewBox: "0 0 24 24",
|
|
59
|
+
fill: "none",
|
|
60
|
+
stroke: "currentColor",
|
|
61
|
+
strokeWidth: 2,
|
|
62
|
+
strokeLinecap: "round",
|
|
63
|
+
strokeLinejoin: "round",
|
|
64
|
+
...props,
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx("path", { d: "M5 4v16" }),
|
|
67
|
+
/* @__PURE__ */ jsx("path", { d: "M19 4v16" }),
|
|
68
|
+
/* @__PURE__ */ jsx("path", { d: "M9 12h6" }),
|
|
69
|
+
/* @__PURE__ */ jsx("path", { d: "m12 9-3 3 3 3" }),
|
|
70
|
+
/* @__PURE__ */ jsx("path", { d: "m12 9 3 3-3 3" })
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/shared/ui/icons/StretchVertical.tsx
|
|
76
|
+
function StretchVertical(props) {
|
|
77
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
78
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
79
|
+
width: 24,
|
|
80
|
+
height: 24,
|
|
81
|
+
viewBox: "0 0 24 24",
|
|
82
|
+
fill: "none",
|
|
83
|
+
stroke: "currentColor",
|
|
84
|
+
strokeWidth: 2,
|
|
85
|
+
strokeLinecap: "round",
|
|
86
|
+
strokeLinejoin: "round",
|
|
87
|
+
...props,
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsx("path", { d: "M4 5h16" }),
|
|
90
|
+
/* @__PURE__ */ jsx("path", { d: "M4 19h16" }),
|
|
91
|
+
/* @__PURE__ */ jsx("path", { d: "M12 9v6" }),
|
|
92
|
+
/* @__PURE__ */ jsx("path", { d: "m9 12 3-3 3 3" }),
|
|
93
|
+
/* @__PURE__ */ jsx("path", { d: "m9 12 3 3 3-3" })
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
52
98
|
//#region src/pdf/pdf-worker.ts
|
|
53
99
|
/** The pdfjs-dist worker wiring (the side-effect): the worker file is
|
|
54
100
|
* copied next to this entry at build time (dist/pdf/), so the relative
|
|
@@ -73,17 +119,33 @@ if (typeof window !== "undefined") fetch(WORKER_URL, { method: "HEAD" }).catch((
|
|
|
73
119
|
});
|
|
74
120
|
//#endregion
|
|
75
121
|
//#region src/pdf/PdfFirstPage.tsx
|
|
76
|
-
/** The PDF preview of one
|
|
122
|
+
/** The PDF preview of one file block: fetch the resolved
|
|
77
123
|
* blob, render the pages to a canvas via pdfjs-dist. The inline view stands
|
|
78
124
|
* the first page over the page row; the controls (the previous/next page
|
|
79
125
|
* buttons + the page indicator + the fullscreen toggle) stand a bar under
|
|
80
126
|
* the canvas. The fullscreen mode opens a portal overlay over the viewport
|
|
81
|
-
* (the page scaled to fill the viewport, the same page navigation, the
|
|
82
|
-
*
|
|
127
|
+
* (the page scaled to fill the viewport, the same page navigation, the zoom
|
|
128
|
+
* bar — the zoom in/out buttons over the scale + the fit-width / the
|
|
129
|
+
* fit-height — a separate
|
|
130
|
+
* pill to the left of the page controls, the Escape key / the arrow keys /
|
|
131
|
+
* the close button / the outside click exit). The overlay's open locks the
|
|
132
|
+
* body's scroll (a wheel over the fixed portal chains to the document's
|
|
133
|
+
* scroll container — the page behind must not scroll). The page indicator's
|
|
134
|
+
* and the scale's numbers stand a fixed width (the digit count's change
|
|
135
|
+
* must not shift the buttons). The preview's chrome stands no text
|
|
136
|
+
* selection (`select-none`): the page indicator's and the controls' text
|
|
137
|
+
* is not document content, and a selection stood there would flag the
|
|
138
|
+
* block / pull the format toolbar over a non-text range. A failure stands
|
|
83
139
|
* the error note over the native iframe fallback (the document stays
|
|
84
|
-
* viewable). The in-flight fetch is aborted on unmount / url change and
|
|
85
|
-
* render task + document are released, so a torn-down preview leaves
|
|
86
|
-
* network request or pdf.js worker behind. */
|
|
140
|
+
* viewable). The in-flight fetch is aborted on unmount / url change and
|
|
141
|
+
* the render task + document are released, so a torn-down preview leaves
|
|
142
|
+
* no network request or pdf.js worker behind. */
|
|
143
|
+
/** The fullscreen zoom's bounds + the per-click step: the scale's units
|
|
144
|
+
* are the css px per pdf point (the device pixel ratio stands the backing
|
|
145
|
+
* store's scale, not this factor). */
|
|
146
|
+
const ZOOM_MIN = .25;
|
|
147
|
+
const ZOOM_MAX = 4;
|
|
148
|
+
const ZOOM_STEP = 1.25;
|
|
87
149
|
/** Render one page to a canvas (the natural page size, the backing store
|
|
88
150
|
* scaled by the device pixel ratio for a crisp retina display). Returns the
|
|
89
151
|
* render task (the caller awaits its promise + cancels it on teardown).
|
|
@@ -103,26 +165,7 @@ function renderPageToCanvas(pdf, pageNumber, canvas) {
|
|
|
103
165
|
});
|
|
104
166
|
});
|
|
105
167
|
}
|
|
106
|
-
|
|
107
|
-
* object-fit: contain behavior — the page's aspect ratio is preserved, the
|
|
108
|
-
* page fills the container's width or height). Returns the render task. */
|
|
109
|
-
function renderPageToCanvasScaled(pdf, pageNumber, canvas, containerWidth, containerHeight) {
|
|
110
|
-
return pdf.getPage(pageNumber).then((page) => {
|
|
111
|
-
const pageViewport = page.getViewport({ scale: 1 });
|
|
112
|
-
const scale = Math.min(containerWidth / pageViewport.width, containerHeight / pageViewport.height);
|
|
113
|
-
const ratio = window.devicePixelRatio || 1;
|
|
114
|
-
const viewport = page.getViewport({ scale: scale * ratio });
|
|
115
|
-
canvas.width = Math.max(1, Math.floor(viewport.width));
|
|
116
|
-
canvas.height = Math.max(1, Math.floor(viewport.height));
|
|
117
|
-
canvas.style.width = `${Math.max(1, Math.floor(viewport.width / ratio))}px`;
|
|
118
|
-
canvas.style.height = `${Math.max(1, Math.floor(viewport.height / ratio))}px`;
|
|
119
|
-
return page.render({
|
|
120
|
-
canvas,
|
|
121
|
-
viewport
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function PdfFirstPage({ id, url, name }) {
|
|
168
|
+
function PdfFirstPage({ id, blockType, url, name }) {
|
|
126
169
|
const { t } = useTranslation("blocks");
|
|
127
170
|
const canvasRef = useRef(null);
|
|
128
171
|
const fullscreenCanvasRef = useRef(null);
|
|
@@ -134,6 +177,8 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
134
177
|
const [currentPage, setCurrentPage] = useState(1);
|
|
135
178
|
const [totalPages, setTotalPages] = useState(0);
|
|
136
179
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
180
|
+
const [fullscreenZoom, setFullscreenZoom] = useState(null);
|
|
181
|
+
const [fullscreenScale, setFullscreenScale] = useState(1);
|
|
137
182
|
useEffect(() => {
|
|
138
183
|
const controller = new AbortController();
|
|
139
184
|
let cancelled = false;
|
|
@@ -211,53 +256,143 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
211
256
|
const container = fullscreenContainerRef.current;
|
|
212
257
|
if (pdf === null || canvas === null || container === null) return;
|
|
213
258
|
let cancelled = false;
|
|
259
|
+
let renderToken = 0;
|
|
214
260
|
let renderTask = null;
|
|
215
|
-
|
|
261
|
+
let renderedOnce = false;
|
|
262
|
+
const render = async () => {
|
|
263
|
+
const token = ++renderToken;
|
|
216
264
|
const width = container.clientWidth;
|
|
217
265
|
const height = container.clientHeight;
|
|
218
266
|
if (width === 0 || height === 0) return;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
})
|
|
267
|
+
const page = await pdf.getPage(currentPage);
|
|
268
|
+
if (cancelled || token !== renderToken) return;
|
|
269
|
+
const pageViewport = page.getViewport({ scale: 1 });
|
|
270
|
+
const fit = Math.min(width / pageViewport.width, height / pageViewport.height);
|
|
271
|
+
const scale = fullscreenZoom ?? fit;
|
|
272
|
+
setFullscreenScale(scale);
|
|
273
|
+
const ratio = window.devicePixelRatio || 1;
|
|
274
|
+
const viewport = page.getViewport({ scale: scale * ratio });
|
|
275
|
+
const storeWidth = Math.max(1, Math.floor(viewport.width));
|
|
276
|
+
const storeHeight = Math.max(1, Math.floor(viewport.height));
|
|
277
|
+
if (renderedOnce && canvas.width === storeWidth && canvas.height === storeHeight) return;
|
|
278
|
+
renderedOnce = true;
|
|
279
|
+
if (renderTask !== null) {
|
|
280
|
+
renderTask.cancel();
|
|
281
|
+
renderTask = null;
|
|
282
|
+
}
|
|
283
|
+
canvas.width = storeWidth;
|
|
284
|
+
canvas.height = storeHeight;
|
|
285
|
+
canvas.style.width = `${Math.max(1, Math.floor(viewport.width / ratio))}px`;
|
|
286
|
+
canvas.style.height = `${Math.max(1, Math.floor(viewport.height / ratio))}px`;
|
|
287
|
+
try {
|
|
288
|
+
renderTask = page.render({
|
|
289
|
+
canvas,
|
|
290
|
+
viewport
|
|
291
|
+
});
|
|
292
|
+
await renderTask.promise;
|
|
293
|
+
} catch (cause) {
|
|
294
|
+
if (cancelled || cause instanceof RenderingCancelledException || cause instanceof DOMException && cause.name === "AbortError") return;
|
|
295
|
+
}
|
|
227
296
|
};
|
|
228
297
|
render();
|
|
229
|
-
const observer = new ResizeObserver(() =>
|
|
298
|
+
const observer = new ResizeObserver(() => {
|
|
299
|
+
render();
|
|
300
|
+
});
|
|
230
301
|
observer.observe(container);
|
|
231
302
|
return () => {
|
|
232
303
|
cancelled = true;
|
|
304
|
+
renderToken += 1;
|
|
233
305
|
observer.disconnect();
|
|
234
306
|
if (renderTask !== null) renderTask.cancel();
|
|
235
307
|
};
|
|
236
308
|
}, [
|
|
237
309
|
isFullscreen,
|
|
238
310
|
currentPage,
|
|
239
|
-
phase
|
|
311
|
+
phase,
|
|
312
|
+
fullscreenZoom
|
|
240
313
|
]);
|
|
314
|
+
const prevPage = useCallback(() => {
|
|
315
|
+
setCurrentPage((page) => Math.max(1, page - 1));
|
|
316
|
+
}, []);
|
|
317
|
+
const nextPage = useCallback(() => {
|
|
318
|
+
setCurrentPage((page) => Math.min(totalPages, page + 1));
|
|
319
|
+
}, [totalPages]);
|
|
320
|
+
const zoomBy = useCallback((factor) => {
|
|
321
|
+
const pdf = pdfDocRef.current;
|
|
322
|
+
const container = fullscreenContainerRef.current;
|
|
323
|
+
if (pdf === null || container === null) return;
|
|
324
|
+
const width = container.clientWidth;
|
|
325
|
+
const height = container.clientHeight;
|
|
326
|
+
if (width === 0 || height === 0) return;
|
|
327
|
+
pdf.getPage(currentPage).then((page) => {
|
|
328
|
+
const pageViewport = page.getViewport({ scale: 1 });
|
|
329
|
+
const fit = Math.min(width / pageViewport.width, height / pageViewport.height);
|
|
330
|
+
setFullscreenZoom(clamp((fullscreenZoom ?? fit) * factor, ZOOM_MIN, ZOOM_MAX));
|
|
331
|
+
});
|
|
332
|
+
}, [currentPage, fullscreenZoom]);
|
|
333
|
+
const fitWidth = useCallback(() => {
|
|
334
|
+
const pdf = pdfDocRef.current;
|
|
335
|
+
const container = fullscreenContainerRef.current;
|
|
336
|
+
if (pdf === null || container === null) return;
|
|
337
|
+
const width = container.clientWidth;
|
|
338
|
+
if (width === 0) return;
|
|
339
|
+
pdf.getPage(currentPage).then((page) => {
|
|
340
|
+
const pageViewport = page.getViewport({ scale: 1 });
|
|
341
|
+
setFullscreenZoom(clamp(width / pageViewport.width, ZOOM_MIN, ZOOM_MAX));
|
|
342
|
+
});
|
|
343
|
+
}, [currentPage]);
|
|
344
|
+
const fitHeight = useCallback(() => {
|
|
345
|
+
const pdf = pdfDocRef.current;
|
|
346
|
+
const container = fullscreenContainerRef.current;
|
|
347
|
+
if (pdf === null || container === null) return;
|
|
348
|
+
const height = container.clientHeight;
|
|
349
|
+
if (height === 0) return;
|
|
350
|
+
pdf.getPage(currentPage).then((page) => {
|
|
351
|
+
const pageViewport = page.getViewport({ scale: 1 });
|
|
352
|
+
setFullscreenZoom(clamp(height / pageViewport.height, ZOOM_MIN, ZOOM_MAX));
|
|
353
|
+
});
|
|
354
|
+
}, [currentPage]);
|
|
355
|
+
const openFullscreen = useCallback(() => {
|
|
356
|
+
setFullscreenZoom(null);
|
|
357
|
+
setFullscreenScale(1);
|
|
358
|
+
setIsFullscreen(true);
|
|
359
|
+
}, []);
|
|
241
360
|
useEffect(() => {
|
|
242
361
|
if (!isFullscreen) return;
|
|
243
362
|
const onKeyDown = (event) => {
|
|
244
|
-
if (event.key === "Escape")
|
|
363
|
+
if (event.key === "Escape") {
|
|
364
|
+
setIsFullscreen(false);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
|
368
|
+
const target = event.target instanceof HTMLElement ? event.target : null;
|
|
369
|
+
if (target !== null && /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName)) return;
|
|
370
|
+
event.preventDefault();
|
|
371
|
+
if (event.key === "ArrowLeft") prevPage();
|
|
372
|
+
else nextPage();
|
|
245
373
|
};
|
|
246
374
|
window.addEventListener("keydown", onKeyDown);
|
|
247
375
|
return () => window.removeEventListener("keydown", onKeyDown);
|
|
376
|
+
}, [
|
|
377
|
+
isFullscreen,
|
|
378
|
+
prevPage,
|
|
379
|
+
nextPage
|
|
380
|
+
]);
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (!isFullscreen) return;
|
|
383
|
+
const body = document.body;
|
|
384
|
+
const previous = body.style.overflow;
|
|
385
|
+
body.style.overflow = "hidden";
|
|
386
|
+
return () => {
|
|
387
|
+
body.style.overflow = previous;
|
|
388
|
+
};
|
|
248
389
|
}, [isFullscreen]);
|
|
249
|
-
const prevPage = useCallback(() => {
|
|
250
|
-
setCurrentPage((page) => Math.max(1, page - 1));
|
|
251
|
-
}, []);
|
|
252
|
-
const nextPage = useCallback(() => {
|
|
253
|
-
setCurrentPage((page) => Math.min(totalPages, page + 1));
|
|
254
|
-
}, [totalPages]);
|
|
255
390
|
if (phase === "error") return /* @__PURE__ */ jsxs("div", {
|
|
256
391
|
"data-slot": "docblocks/image-pdf-preview",
|
|
257
392
|
"data-block-id": id,
|
|
258
|
-
"data-block-type":
|
|
393
|
+
"data-block-type": blockType,
|
|
259
394
|
"data-phase": "error",
|
|
260
|
-
className: "mx-0 my-(--docblocks-block-spacing)",
|
|
395
|
+
className: "mx-0 my-(--docblocks-block-spacing) select-none",
|
|
261
396
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
262
397
|
"data-slot": "docblocks/image-pdf-error",
|
|
263
398
|
className: "\n mb-2 flex items-center gap-2 rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width)\n border-(--docblocks-table-border-color) bg-(--muted) px-3 py-2 text-sm text-(--muted-foreground)\n ",
|
|
@@ -270,18 +405,18 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
270
405
|
"data-subtype": "pdf",
|
|
271
406
|
sandbox: "",
|
|
272
407
|
src: url,
|
|
273
|
-
title: name
|
|
408
|
+
title: name,
|
|
274
409
|
className: "\n block aspect-video w-full rounded-(--docblocks-image-radius)\n border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) outline-none\n "
|
|
275
410
|
}) : isSafeDownloadHref(url) ? /* @__PURE__ */ jsx("a", {
|
|
276
411
|
"data-slot": "docblocks/image-pdf-download",
|
|
277
412
|
href: url,
|
|
278
|
-
download: name
|
|
413
|
+
download: name,
|
|
279
414
|
className: "inline-block text-sm underline underline-offset-2",
|
|
280
|
-
children: name
|
|
415
|
+
children: name
|
|
281
416
|
}) : /* @__PURE__ */ jsx("span", {
|
|
282
417
|
"data-slot": "docblocks/image-pdf-download",
|
|
283
418
|
className: "inline-block text-sm",
|
|
284
|
-
children: name
|
|
419
|
+
children: name
|
|
285
420
|
})]
|
|
286
421
|
});
|
|
287
422
|
const inlineControls = /* @__PURE__ */ jsxs("div", {
|
|
@@ -301,7 +436,11 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
301
436
|
"data-slot": "docblocks/image-pdf-page-indicator",
|
|
302
437
|
className: "px-1 text-xs text-(--muted-foreground) tabular-nums",
|
|
303
438
|
children: [
|
|
304
|
-
|
|
439
|
+
/* @__PURE__ */ jsx("span", {
|
|
440
|
+
className: "inline-block text-right",
|
|
441
|
+
style: { minWidth: `${Math.max(1, String(totalPages).length)}ch` },
|
|
442
|
+
children: currentPage
|
|
443
|
+
}),
|
|
305
444
|
" / ",
|
|
306
445
|
totalPages
|
|
307
446
|
]
|
|
@@ -318,7 +457,7 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
318
457
|
/* @__PURE__ */ jsx("button", {
|
|
319
458
|
type: "button",
|
|
320
459
|
"data-slot": "docblocks/image-pdf-fullscreen",
|
|
321
|
-
onClick:
|
|
460
|
+
onClick: openFullscreen,
|
|
322
461
|
"aria-label": t("code.pdfFullscreen"),
|
|
323
462
|
className: "\n ml-1 flex size-6 items-center justify-center rounded-sm text-(--muted-foreground) transition-colors\n hover:bg-(--accent) hover:text-(--accent-foreground)\n ",
|
|
324
463
|
children: /* @__PURE__ */ jsx(Maximize, { className: "size-4" })
|
|
@@ -327,7 +466,7 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
327
466
|
});
|
|
328
467
|
const fullscreenControls = /* @__PURE__ */ jsxs("div", {
|
|
329
468
|
"data-slot": "docblocks/image-pdf-controls",
|
|
330
|
-
className: "\n flex items-center justify-center gap-1 rounded-(--radius) border border-(--border) bg-(--muted) px-2 py-1\n ",
|
|
469
|
+
className: "\n flex items-center justify-center gap-1 rounded-(--radius) border border-(--border) bg-(--muted) px-2 py-1\n select-none\n ",
|
|
331
470
|
children: [
|
|
332
471
|
/* @__PURE__ */ jsx("button", {
|
|
333
472
|
type: "button",
|
|
@@ -342,7 +481,11 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
342
481
|
"data-slot": "docblocks/image-pdf-page-indicator",
|
|
343
482
|
className: "px-1 text-xs text-(--muted-foreground) tabular-nums",
|
|
344
483
|
children: [
|
|
345
|
-
|
|
484
|
+
/* @__PURE__ */ jsx("span", {
|
|
485
|
+
className: "inline-block text-right",
|
|
486
|
+
style: { minWidth: `${Math.max(1, String(totalPages).length)}ch` },
|
|
487
|
+
children: currentPage
|
|
488
|
+
}),
|
|
346
489
|
" / ",
|
|
347
490
|
totalPages
|
|
348
491
|
]
|
|
@@ -366,12 +509,57 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
366
509
|
})
|
|
367
510
|
]
|
|
368
511
|
});
|
|
512
|
+
const fullscreenZoomControls = /* @__PURE__ */ jsxs("div", {
|
|
513
|
+
"data-slot": "docblocks/image-pdf-zoom",
|
|
514
|
+
className: "\n flex items-center justify-center gap-1 rounded-(--radius) border border-(--border) bg-(--muted) px-2 py-1\n select-none\n ",
|
|
515
|
+
children: [
|
|
516
|
+
/* @__PURE__ */ jsx("button", {
|
|
517
|
+
type: "button",
|
|
518
|
+
"data-slot": "docblocks/image-pdf-zoom-out",
|
|
519
|
+
onClick: () => zoomBy(1 / ZOOM_STEP),
|
|
520
|
+
disabled: fullscreenScale <= .250000001,
|
|
521
|
+
"aria-label": t("code.pdfZoomOut"),
|
|
522
|
+
className: "\n flex size-6 items-center justify-center rounded-sm text-(--muted-foreground) transition-colors\n hover:bg-(--accent) hover:text-(--accent-foreground)\n disabled:pointer-events-none disabled:opacity-40\n ",
|
|
523
|
+
children: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
|
|
524
|
+
}),
|
|
525
|
+
/* @__PURE__ */ jsxs("span", {
|
|
526
|
+
"data-slot": "docblocks/image-pdf-zoom-indicator",
|
|
527
|
+
className: "inline-block min-w-[4ch] px-1 text-right text-xs text-(--muted-foreground) tabular-nums",
|
|
528
|
+
children: [Math.round(fullscreenScale * 100), "%"]
|
|
529
|
+
}),
|
|
530
|
+
/* @__PURE__ */ jsx("button", {
|
|
531
|
+
type: "button",
|
|
532
|
+
"data-slot": "docblocks/image-pdf-zoom-in",
|
|
533
|
+
onClick: () => zoomBy(ZOOM_STEP),
|
|
534
|
+
disabled: fullscreenScale >= 3.999999999,
|
|
535
|
+
"aria-label": t("code.pdfZoomIn"),
|
|
536
|
+
className: "\n flex size-6 items-center justify-center rounded-sm text-(--muted-foreground) transition-colors\n hover:bg-(--accent) hover:text-(--accent-foreground)\n disabled:pointer-events-none disabled:opacity-40\n ",
|
|
537
|
+
children: /* @__PURE__ */ jsx(Plus, { className: "size-4" })
|
|
538
|
+
}),
|
|
539
|
+
/* @__PURE__ */ jsx("button", {
|
|
540
|
+
type: "button",
|
|
541
|
+
"data-slot": "docblocks/image-pdf-fit-width",
|
|
542
|
+
onClick: fitWidth,
|
|
543
|
+
"aria-label": t("code.pdfFitWidth"),
|
|
544
|
+
className: "\n flex size-6 items-center justify-center rounded-sm text-(--muted-foreground) transition-colors\n hover:bg-(--accent) hover:text-(--accent-foreground)\n ",
|
|
545
|
+
children: /* @__PURE__ */ jsx(StretchHorizontal, { className: "size-4" })
|
|
546
|
+
}),
|
|
547
|
+
/* @__PURE__ */ jsx("button", {
|
|
548
|
+
type: "button",
|
|
549
|
+
"data-slot": "docblocks/image-pdf-fit-height",
|
|
550
|
+
onClick: fitHeight,
|
|
551
|
+
"aria-label": t("code.pdfFitHeight"),
|
|
552
|
+
className: "\n flex size-6 items-center justify-center rounded-sm text-(--muted-foreground) transition-colors\n hover:bg-(--accent) hover:text-(--accent-foreground)\n ",
|
|
553
|
+
children: /* @__PURE__ */ jsx(StretchVertical, { className: "size-4" })
|
|
554
|
+
})
|
|
555
|
+
]
|
|
556
|
+
});
|
|
369
557
|
return /* @__PURE__ */ jsxs("div", {
|
|
370
558
|
"data-slot": "docblocks/image-pdf-preview",
|
|
371
559
|
"data-block-id": id,
|
|
372
|
-
"data-block-type":
|
|
560
|
+
"data-block-type": blockType,
|
|
373
561
|
"data-phase": phase,
|
|
374
|
-
className: "relative mx-0 my-(--docblocks-block-spacing) flex flex-col items-center gap-2",
|
|
562
|
+
className: "relative mx-0 my-(--docblocks-block-spacing) flex flex-col items-center gap-2 select-none",
|
|
375
563
|
children: [
|
|
376
564
|
/* @__PURE__ */ jsxs("div", {
|
|
377
565
|
className: "relative flex w-full justify-center",
|
|
@@ -402,6 +590,7 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
402
590
|
if (target === null) return;
|
|
403
591
|
if (target.closest("[data-slot=\"docblocks/image-pdf-fullscreen-canvas\"]") !== null) return;
|
|
404
592
|
if (target.closest("[data-slot=\"docblocks/image-pdf-controls\"]") !== null) return;
|
|
593
|
+
if (target.closest("[data-slot=\"docblocks/image-pdf-zoom\"]") !== null) return;
|
|
405
594
|
setIsFullscreen(false);
|
|
406
595
|
},
|
|
407
596
|
children: [
|
|
@@ -415,14 +604,18 @@ function PdfFirstPage({ id, url, name }) {
|
|
|
415
604
|
}),
|
|
416
605
|
/* @__PURE__ */ jsx("div", {
|
|
417
606
|
ref: fullscreenContainerRef,
|
|
418
|
-
|
|
607
|
+
"data-slot": "docblocks/image-pdf-fullscreen-container",
|
|
608
|
+
className: "flex h-[calc(100vh-6rem)] w-[calc(100vw-4rem)] overflow-auto",
|
|
419
609
|
children: /* @__PURE__ */ jsx("canvas", {
|
|
420
610
|
ref: fullscreenCanvasRef,
|
|
421
611
|
"data-slot": "docblocks/image-pdf-fullscreen-canvas",
|
|
422
|
-
className: "
|
|
612
|
+
className: "m-auto border border-(--border) bg-(--background) shadow-lg"
|
|
423
613
|
})
|
|
424
614
|
}),
|
|
425
|
-
|
|
615
|
+
/* @__PURE__ */ jsxs("div", {
|
|
616
|
+
className: "flex items-center gap-2",
|
|
617
|
+
children: [fullscreenZoomControls, fullscreenControls]
|
|
618
|
+
})
|
|
426
619
|
]
|
|
427
620
|
}), document.body)
|
|
428
621
|
]
|
package/dist/styles.css
CHANGED
|
@@ -430,6 +430,9 @@
|
|
|
430
430
|
.m-0 {
|
|
431
431
|
margin: 0px;
|
|
432
432
|
}
|
|
433
|
+
.m-auto {
|
|
434
|
+
margin: auto;
|
|
435
|
+
}
|
|
433
436
|
.-mx-1 {
|
|
434
437
|
margin-inline: calc(var(--spacing) * -1);
|
|
435
438
|
}
|
|
@@ -692,9 +695,6 @@
|
|
|
692
695
|
.max-h-80 {
|
|
693
696
|
max-height: calc(var(--spacing) * 80);
|
|
694
697
|
}
|
|
695
|
-
.max-h-full {
|
|
696
|
-
max-height: 100%;
|
|
697
|
-
}
|
|
698
698
|
.min-h-0 {
|
|
699
699
|
min-height: 0px;
|
|
700
700
|
}
|
|
@@ -827,6 +827,9 @@
|
|
|
827
827
|
.min-w-110 {
|
|
828
828
|
min-width: calc(var(--spacing) * 110);
|
|
829
829
|
}
|
|
830
|
+
.min-w-\[4ch\] {
|
|
831
|
+
min-width: 4ch;
|
|
832
|
+
}
|
|
830
833
|
.min-w-full {
|
|
831
834
|
min-width: 100%;
|
|
832
835
|
}
|
|
@@ -1028,6 +1031,9 @@
|
|
|
1028
1031
|
.gap-\(--docblocks-block-spacing\) {
|
|
1029
1032
|
gap: var(--docblocks-block-spacing);
|
|
1030
1033
|
}
|
|
1034
|
+
.gap-0 {
|
|
1035
|
+
gap: 0px;
|
|
1036
|
+
}
|
|
1031
1037
|
.gap-0\.5 {
|
|
1032
1038
|
gap: calc(var(--spacing) * 0.5);
|
|
1033
1039
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docblocks-react-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "React rendering + editing layer for docblocks: hooks, block renderers, caret/selection, keyboard, clipboard.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"docblocks-core": "^0.
|
|
37
|
+
"docblocks-core": "^0.3.0",
|
|
38
38
|
"framer-motion": "^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
39
39
|
"mermaid": "^12.0.0",
|
|
40
40
|
"pdfjs-dist": "^6.0.0",
|