docblocks-react-ui 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/LICENSE +21 -0
  3. package/README.md +592 -2
  4. package/dist/Editor-CiJY5R4v.mjs +26587 -0
  5. package/dist/Editor-DT7RkRXf.d.mts +32 -0
  6. package/dist/LoaderCircle-AGVFE4IP.mjs +19 -0
  7. package/dist/Skeleton-D922Ths5.mjs +13 -0
  8. package/dist/constants-D4FTL0ph.mjs +81 -0
  9. package/dist/fonts/OFL.txt +162 -0
  10. package/dist/fonts/inter-300-c.woff2 +0 -0
  11. package/dist/fonts/inter-300-l.woff2 +0 -0
  12. package/dist/fonts/inter-300i-c.woff2 +0 -0
  13. package/dist/fonts/inter-300i-l.woff2 +0 -0
  14. package/dist/fonts/inter-400-c.woff2 +0 -0
  15. package/dist/fonts/inter-400-l.woff2 +0 -0
  16. package/dist/fonts/inter-400i-c.woff2 +0 -0
  17. package/dist/fonts/inter-400i-l.woff2 +0 -0
  18. package/dist/fonts/inter-600-c.woff2 +0 -0
  19. package/dist/fonts/inter-600-l.woff2 +0 -0
  20. package/dist/fonts/inter-600i-c.woff2 +0 -0
  21. package/dist/fonts/inter-600i-l.woff2 +0 -0
  22. package/dist/fonts/jetbrains-mono-300-c.woff2 +0 -0
  23. package/dist/fonts/jetbrains-mono-300-l.woff2 +0 -0
  24. package/dist/fonts/jetbrains-mono-300i-c.woff2 +0 -0
  25. package/dist/fonts/jetbrains-mono-300i-l.woff2 +0 -0
  26. package/dist/fonts/jetbrains-mono-400-c.woff2 +0 -0
  27. package/dist/fonts/jetbrains-mono-400-l.woff2 +0 -0
  28. package/dist/fonts/jetbrains-mono-400i-c.woff2 +0 -0
  29. package/dist/fonts/jetbrains-mono-400i-l.woff2 +0 -0
  30. package/dist/fonts/jetbrains-mono-600-c.woff2 +0 -0
  31. package/dist/fonts/jetbrains-mono-600-l.woff2 +0 -0
  32. package/dist/fonts/jetbrains-mono-600i-c.woff2 +0 -0
  33. package/dist/fonts/jetbrains-mono-600i-l.woff2 +0 -0
  34. package/dist/fonts/lora-400-c.woff2 +0 -0
  35. package/dist/fonts/lora-400-l.woff2 +0 -0
  36. package/dist/fonts/lora-400i-c.woff2 +0 -0
  37. package/dist/fonts/lora-400i-l.woff2 +0 -0
  38. package/dist/fonts/lora-600-c.woff2 +0 -0
  39. package/dist/fonts/lora-600-l.woff2 +0 -0
  40. package/dist/fonts/lora-600i-c.woff2 +0 -0
  41. package/dist/fonts/lora-600i-l.woff2 +0 -0
  42. package/dist/fonts/lora-700-c.woff2 +0 -0
  43. package/dist/fonts/lora-700-l.woff2 +0 -0
  44. package/dist/fonts/lora-700i-c.woff2 +0 -0
  45. package/dist/fonts/lora-700i-l.woff2 +0 -0
  46. package/dist/fonts/open-sans-300-c.woff2 +0 -0
  47. package/dist/fonts/open-sans-300-l.woff2 +0 -0
  48. package/dist/fonts/open-sans-300i-c.woff2 +0 -0
  49. package/dist/fonts/open-sans-300i-l.woff2 +0 -0
  50. package/dist/fonts/open-sans-400-c.woff2 +0 -0
  51. package/dist/fonts/open-sans-400-l.woff2 +0 -0
  52. package/dist/fonts/open-sans-400i-c.woff2 +0 -0
  53. package/dist/fonts/open-sans-400i-l.woff2 +0 -0
  54. package/dist/fonts/open-sans-600-c.woff2 +0 -0
  55. package/dist/fonts/open-sans-600-l.woff2 +0 -0
  56. package/dist/fonts/open-sans-600i-c.woff2 +0 -0
  57. package/dist/fonts/open-sans-600i-l.woff2 +0 -0
  58. package/dist/fonts/pt-sans-400-c.woff2 +0 -0
  59. package/dist/fonts/pt-sans-400-l.woff2 +0 -0
  60. package/dist/fonts/pt-sans-400i-c.woff2 +0 -0
  61. package/dist/fonts/pt-sans-400i-l.woff2 +0 -0
  62. package/dist/fonts/pt-sans-700-c.woff2 +0 -0
  63. package/dist/fonts/pt-sans-700-l.woff2 +0 -0
  64. package/dist/fonts/pt-sans-700i-c.woff2 +0 -0
  65. package/dist/fonts/pt-sans-700i-l.woff2 +0 -0
  66. package/dist/fonts/pt-serif-400-c.woff2 +0 -0
  67. package/dist/fonts/pt-serif-400-l.woff2 +0 -0
  68. package/dist/fonts/pt-serif-400i-c.woff2 +0 -0
  69. package/dist/fonts/pt-serif-400i-l.woff2 +0 -0
  70. package/dist/fonts/pt-serif-700-c.woff2 +0 -0
  71. package/dist/fonts/pt-serif-700-l.woff2 +0 -0
  72. package/dist/fonts/pt-serif-700i-c.woff2 +0 -0
  73. package/dist/fonts/pt-serif-700i-l.woff2 +0 -0
  74. package/dist/index-D6_ysSmQ.d.mts +1075 -0
  75. package/dist/index-YJcgf8Hh.d.mts +39 -0
  76. package/dist/index.d.mts +388 -0
  77. package/dist/index.mjs +641 -0
  78. package/dist/mermaid/index.d.mts +10 -0
  79. package/dist/mermaid/index.mjs +252 -0
  80. package/dist/motion/index.d.mts +8 -0
  81. package/dist/motion/index.mjs +1009 -0
  82. package/dist/pdf/index.d.mts +5 -0
  83. package/dist/pdf/index.mjs +164 -0
  84. package/dist/pdf/jbig2.wasm +0 -0
  85. package/dist/pdf/jbig2_nowasm_fallback.js +15 -0
  86. package/dist/pdf/pdf.worker.min.mjs +28 -0
  87. package/dist/styles.css +4562 -0
  88. package/package.json +99 -4
  89. package/theme.css +128 -0
@@ -0,0 +1,5 @@
1
+ import { f as PdfPreviewProps } from "../index-D6_ysSmQ.mjs";
2
+ //#region src/pdf/PdfFirstPage.d.ts
3
+ declare function PdfFirstPage({ id, url, name }: PdfPreviewProps): import("react").JSX.Element;
4
+ //#endregion
5
+ export { PdfFirstPage, type PdfPreviewProps };
@@ -0,0 +1,164 @@
1
+ import { a as isSafeDownloadHref, c as cn, n as TriangleAlert, t as isEmbeddablePdfUrl } from "../constants-D4FTL0ph.mjs";
2
+ import { t as LoaderCircle } from "../LoaderCircle-AGVFE4IP.mjs";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { GlobalWorkerOptions, RenderingCancelledException, getDocument } from "pdfjs-dist";
6
+ //#region src/pdf/pdf-worker.ts
7
+ /** The pdfjs-dist worker wiring (the side-effect): the worker file is
8
+ * copied next to this entry at build time (dist/pdf/), so the relative
9
+ * reference resolves in the consumer's browser with no bundler asset
10
+ * handling (the dist is served as static ESM). The path is composed at
11
+ * runtime so the bundler leaves the new URL untouched.
12
+ *
13
+ * The JBIG2 decoder (the wasm module + the no-wasm js fallback) is copied
14
+ * next to the worker at build time and loaded by the worker from this
15
+ * base url — pdfjs resolves `${wasmUrl}jbig2.wasm`, so the worker's
16
+ * directory is the base. Derived from the worker URL object (not
17
+ * import.meta.url) so a bundler's `new URL(_, import.meta.url)` asset
18
+ * rewrite cannot mangle the directory form. Scanned PDFs encode their
19
+ * text layers as JBIG2; without a resolvable wasmUrl the worker fails to
20
+ * initialize those layers and the page renders as a bare background image
21
+ * (the text is dropped). */
22
+ const WORKER_URL = new URL(`./pdf.worker.min.mjs`, import.meta.url);
23
+ GlobalWorkerOptions.workerSrc = WORKER_URL.toString();
24
+ const WASM_URL = new URL("./", WORKER_URL).toString();
25
+ //#endregion
26
+ //#region src/pdf/PdfFirstPage.tsx
27
+ /** The first-page preview of one `pdf`-subtype image block: fetch the
28
+ * resolved blob, render page 1 to a canvas via pdfjs-dist. The previous
29
+ * phase stands until the (re-)render settles (no flicker while the url
30
+ * changes). A failure stands the error note over the native iframe
31
+ * fallback (the document stays viewable). The in-flight fetch is aborted
32
+ * on unmount / url change and the render task + document are released,
33
+ * so a torn-down preview leaves no network request or pdf.js worker
34
+ * behind. */
35
+ function PdfFirstPage({ id, url, name }) {
36
+ const canvasRef = useRef(null);
37
+ const loadingTaskRef = useRef(null);
38
+ const renderTaskRef = useRef(null);
39
+ const [phase, setPhase] = useState("loading");
40
+ const [error, setError] = useState(null);
41
+ useEffect(() => {
42
+ const controller = new AbortController();
43
+ let cancelled = false;
44
+ setPhase("loading");
45
+ setError(null);
46
+ const run = async () => {
47
+ try {
48
+ const response = await fetch(url, { signal: controller.signal });
49
+ if (cancelled) return;
50
+ if (!response.ok) throw new Error(`Failed to fetch the PDF (HTTP ${response.status}).`);
51
+ const data = new Uint8Array(await response.arrayBuffer());
52
+ if (cancelled) return;
53
+ const task = getDocument({
54
+ data,
55
+ wasmUrl: WASM_URL
56
+ });
57
+ loadingTaskRef.current = task;
58
+ const pdf = await task.promise;
59
+ if (cancelled) {
60
+ loadingTaskRef.current = null;
61
+ task.destroy().catch(() => void 0);
62
+ return;
63
+ }
64
+ const page = await pdf.getPage(1);
65
+ if (cancelled) {
66
+ loadingTaskRef.current = null;
67
+ task.destroy().catch(() => void 0);
68
+ return;
69
+ }
70
+ const canvas = canvasRef.current;
71
+ if (canvas === null) return;
72
+ const ratio = window.devicePixelRatio || 1;
73
+ const viewport = page.getViewport({ scale: ratio });
74
+ canvas.width = Math.max(1, Math.floor(viewport.width));
75
+ canvas.height = Math.max(1, Math.floor(viewport.height));
76
+ canvas.style.width = `${Math.max(1, Math.floor(viewport.width / ratio))}px`;
77
+ canvas.style.height = `${Math.max(1, Math.floor(viewport.height / ratio))}px`;
78
+ const renderTask = page.render({
79
+ canvas,
80
+ viewport
81
+ });
82
+ renderTaskRef.current = renderTask;
83
+ await renderTask.promise;
84
+ if (renderTaskRef.current === renderTask) renderTaskRef.current = null;
85
+ if (!cancelled) setPhase("ready");
86
+ } catch (cause) {
87
+ if (cancelled || cause instanceof RenderingCancelledException || cause instanceof DOMException && cause.name === "AbortError") return;
88
+ const message = cause instanceof Error ? cause.message : String(cause);
89
+ setError(message);
90
+ setPhase("error");
91
+ }
92
+ };
93
+ run();
94
+ return () => {
95
+ cancelled = true;
96
+ controller.abort();
97
+ const renderTask = renderTaskRef.current;
98
+ renderTaskRef.current = null;
99
+ if (renderTask !== null) renderTask.cancel();
100
+ const task = loadingTaskRef.current;
101
+ loadingTaskRef.current = null;
102
+ if (task !== null) task.destroy().catch(() => void 0);
103
+ };
104
+ }, [url]);
105
+ if (phase === "error") return /* @__PURE__ */ jsxs("div", {
106
+ "data-slot": "docblocks/image-pdf-preview",
107
+ "data-block-id": id,
108
+ "data-block-type": "image",
109
+ "data-phase": "error",
110
+ className: "mx-0 my-(--docblocks-block-spacing)",
111
+ children: [/* @__PURE__ */ jsxs("div", {
112
+ "data-slot": "docblocks/image-pdf-error",
113
+ 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 ",
114
+ children: [/* @__PURE__ */ jsx(TriangleAlert, { className: "size-4 shrink-0" }), /* @__PURE__ */ jsxs("span", {
115
+ className: "min-w-0 flex-1 truncate",
116
+ children: [
117
+ "PDF preview unavailable (",
118
+ error,
119
+ "). Showing the built-in viewer."
120
+ ]
121
+ })]
122
+ }), isEmbeddablePdfUrl(url) ? /* @__PURE__ */ jsx("iframe", {
123
+ "data-slot": "docblocks/image-pdf",
124
+ "data-subtype": "pdf",
125
+ sandbox: "",
126
+ src: url,
127
+ title: name ?? "document",
128
+ 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 "
129
+ }) : isSafeDownloadHref(url) ? /* @__PURE__ */ jsx("a", {
130
+ "data-slot": "docblocks/image-pdf-download",
131
+ href: url,
132
+ download: name ?? void 0,
133
+ className: "inline-block text-sm underline underline-offset-2",
134
+ children: name ?? "document"
135
+ }) : /* @__PURE__ */ jsx("span", {
136
+ "data-slot": "docblocks/image-pdf-download",
137
+ className: "inline-block text-sm",
138
+ children: name ?? "document"
139
+ })]
140
+ });
141
+ return /* @__PURE__ */ jsxs("div", {
142
+ "data-slot": "docblocks/image-pdf-preview",
143
+ "data-block-id": id,
144
+ "data-block-type": "image",
145
+ "data-phase": phase,
146
+ className: "relative mx-0 my-(--docblocks-block-spacing) flex justify-center",
147
+ children: [/* @__PURE__ */ jsx("canvas", {
148
+ ref: canvasRef,
149
+ "data-slot": "docblocks/image-pdf-canvas",
150
+ className: cn(`
151
+ block max-w-full rounded-(--docblocks-image-radius) border-(length:--docblocks-table-border-width)
152
+ border-(--docblocks-table-border-color) bg-(--background)
153
+ `, phase === "ready" ? "h-auto" : "hidden")
154
+ }), phase === "loading" && /* @__PURE__ */ jsxs("div", {
155
+ className: "flex h-48 w-full items-center justify-center gap-2 text-sm text-(--muted-foreground)",
156
+ children: [/* @__PURE__ */ jsx(LoaderCircle, { className: "size-4 animate-spin" }), /* @__PURE__ */ jsx("span", {
157
+ "data-slot": "docblocks/image-pdf-loading",
158
+ children: "loading preview…"
159
+ })]
160
+ })]
161
+ });
162
+ }
163
+ //#endregion
164
+ export { PdfFirstPage };
Binary file