docblocks-react-ui 0.11.0 → 0.13.0

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.
@@ -1,8 +1,9 @@
1
- import { $t as CodeXml, At as Skeleton, E as SegmentSelector, Qt as Eye, Yt as INLINE_CODE_CLASS, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, o as childrenSlot, s as CodeHeader, u as TextBlock } from "../Editor-g5aY0giB.mjs";
2
- import { f as LoaderCircle, l as TriangleAlert } from "../constants-D8PSgkwi.mjs";
1
+ import { $t as Eye, At as Skeleton, E as SegmentSelector, Yt as INLINE_CODE_CLASS, Zt as RotateCcw, dt as Button, en as CodeXml, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, o as childrenSlot, s as CodeHeader, u as TextBlock } from "../Editor-dcSgC9ho.mjs";
2
+ import { a as preventDefault, d as Minus, f as LoaderCircle, l as TriangleAlert, r as clamp, u as Plus } from "../constants-D8PSgkwi.mjs";
3
+ import { t as Maximize } from "../Maximize-BBHnCDWL.mjs";
3
4
  import { useEffect, useRef, useState } from "react";
4
5
  import { useTranslation } from "react-i18next";
5
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
6
7
  import mermaid from "mermaid";
7
8
  //#region src/mermaid/mermaid-config.ts
8
9
  /** The mermaid renderer's config stand (the v1 security + behavior stand —
@@ -131,7 +132,6 @@ function MermaidDiagram({ id, text }) {
131
132
  "data-slot": "docblocks/mermaid",
132
133
  "data-state": "error",
133
134
  variant: "destructive",
134
- className: "mt-(--docblocks-block-spacing)",
135
135
  children: [
136
136
  /* @__PURE__ */ jsx(TriangleAlert, {}),
137
137
  /* @__PURE__ */ jsx(AlertTitle, {
@@ -150,7 +150,7 @@ function MermaidDiagram({ id, text }) {
150
150
  ref: containerRef,
151
151
  "data-slot": "docblocks/mermaid",
152
152
  "data-state": "diagram",
153
- className: "mt-(--docblocks-block-spacing)",
153
+ className: "w-full",
154
154
  children: /* @__PURE__ */ jsx("div", {
155
155
  "data-slot": "docblocks/mermaid-diagram",
156
156
  dangerouslySetInnerHTML: { __html: state.svg }
@@ -160,7 +160,7 @@ function MermaidDiagram({ id, text }) {
160
160
  ref: containerRef,
161
161
  "data-slot": "docblocks/mermaid",
162
162
  "data-state": "loading",
163
- className: "relative mt-(--docblocks-block-spacing)",
163
+ className: "relative w-full",
164
164
  children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-24 w-full" }), /* @__PURE__ */ jsxs("div", {
165
165
  className: "absolute inset-0 flex items-center justify-center gap-2",
166
166
  children: [/* @__PURE__ */ jsx(LoaderCircle, { className: "size-4 animate-spin" }), /* @__PURE__ */ jsx("span", {
@@ -171,6 +171,431 @@ function MermaidDiagram({ id, text }) {
171
171
  });
172
172
  }
173
173
  //#endregion
174
+ //#region src/mermaid/MermaidViewport.tsx
175
+ /** The zoom range (the min / max scale). */
176
+ const VIEWPORT_MIN_SCALE = .25;
177
+ const VIEWPORT_MAX_SCALE = 4;
178
+ /** The toolbar's multiplicative zoom step (per in / out press). */
179
+ const VIEWPORT_ZOOM_STEP = 1.2;
180
+ /** The wheel's continuous zoom factor (the exponential of the delta, the canvas pinch idiom). */
181
+ const VIEWPORT_WHEEL_ZOOM = .002;
182
+ /** The view's persist debounce (the gesture's bursts stand one doc write per rest). */
183
+ const VIEWPORT_PERSIST_DEBOUNCE_MS = 250;
184
+ /** The height's minimum (px): the toolbar's usable area's stand (the non-CSS environment's parity). */
185
+ const VIEWPORT_MIN_HEIGHT = 160;
186
+ /** The resize handle's key step (px per arrow press). */
187
+ const VIEWPORT_RESIZE_KEY_STEP = 16;
188
+ /** The identity view: the diagram at its natural size, no pan. */
189
+ const VIEWPORT_IDENTITY = {
190
+ scale: 1,
191
+ x: 0,
192
+ y: 0
193
+ };
194
+ /** The view over the block's persisted attrs (the null idiom's restore). */
195
+ function viewOfAttrs(zoom, panX, panY) {
196
+ return {
197
+ scale: zoom ?? 1,
198
+ x: panX ?? 0,
199
+ y: panY ?? 0
200
+ };
201
+ }
202
+ /**
203
+ * The view's wire stand: the gesture's floating-point's residue must not
204
+ * stand a non-identity's persist (the zoom-out/in's round-trip lands the
205
+ * 0.9999…'s "identity"). The zoom's round to the label's 1%'s precision,
206
+ * the pan's to the 0.1 px (the sub-pixel's residue stands the identity).
207
+ */
208
+ function roundViewValue(value, places) {
209
+ const factor = 10 ** places;
210
+ return Math.round(value * factor) / factor;
211
+ }
212
+ /** The diagram's natural size (the transform's no-op's stand — the
213
+ * transform never affects the layout). The svg's box (the diagram's
214
+ * true extent) over the layer's box (the no-svg's stand — the error /
215
+ * the loading's states). */
216
+ function measureContent(layer) {
217
+ if (layer === null) return {
218
+ w: 0,
219
+ h: 0
220
+ };
221
+ const svg = layer.querySelector("svg");
222
+ return {
223
+ w: svg !== null ? svg.clientWidth || layer.clientWidth : layer.clientWidth,
224
+ h: svg !== null ? svg.clientHeight || layer.clientHeight : layer.clientHeight
225
+ };
226
+ }
227
+ /**
228
+ * Clamp the pan against the scaled diagram's overflow over the wrapper:
229
+ * the rendered diagram bigger than the wrapper bounds the pan (the
230
+ * diagram's edge reaches the wrapper's edge at most), smaller centers it.
231
+ */
232
+ function clampPan(scale, x, y, wrapW, wrapH, contentW, contentH) {
233
+ if (wrapW <= 0 || wrapH <= 0) return {
234
+ x,
235
+ y
236
+ };
237
+ const cw = contentW > 0 ? contentW : wrapW;
238
+ const ch = contentH > 0 ? contentH : wrapH;
239
+ const rx = cw * scale;
240
+ const ry = ch * scale;
241
+ return {
242
+ x: rx > wrapW ? clamp(x, wrapW - rx, 0) : (wrapW - rx) / 2,
243
+ y: ry > wrapH ? clamp(y, wrapH - ry, 0) : (wrapH - ry) / 2
244
+ };
245
+ }
246
+ /** Zoom keeping the screen point `(cx, cy)` fixed: the content under it stands. */
247
+ function zoomAtPoint(view, cx, cy, nextScale) {
248
+ const factor = nextScale / view.scale;
249
+ return {
250
+ scale: nextScale,
251
+ x: cx - (cx - view.x) * factor,
252
+ y: cy - (cy - view.y) * factor
253
+ };
254
+ }
255
+ /**
256
+ * The diagram's viewport over one mermaid code block (the `nested`'s
257
+ * stand — the diagram + the legacy's nested children render inside the
258
+ * transform's layer). The wrapper's height stands the `height` attr
259
+ * (the stretched stand; absent = the natural's auto's stand).
260
+ */
261
+ function MermaidViewport({ id, block, children }) {
262
+ const { t } = useTranslation("blocks");
263
+ const { doc, viewMode } = useEditorContext();
264
+ const wrapperRef = useRef(null);
265
+ const layerRef = useRef(null);
266
+ const [view, setView] = useState(() => viewOfAttrs(block.attrs?.zoom, block.attrs?.panX, block.attrs?.panY));
267
+ const viewRef = useRef(view);
268
+ viewRef.current = view;
269
+ const [height, setHeight] = useState(block.attrs?.height ?? null);
270
+ const heightRef = useRef(height);
271
+ heightRef.current = height;
272
+ const panSession = useRef(null);
273
+ const resizeSession = useRef(null);
274
+ /** The clamped view over the measured's boxes (the gesture's helper). */
275
+ const clampView = (next) => {
276
+ const rect = wrapperRef.current?.getBoundingClientRect();
277
+ const content = measureContent(layerRef.current);
278
+ return {
279
+ scale: next.scale,
280
+ ...clampPan(next.scale, next.x, next.y, rect?.width ?? 0, rect?.height ?? 0, content.w, content.h)
281
+ };
282
+ };
283
+ useEffect(() => {
284
+ const wrapper = wrapperRef.current;
285
+ if (wrapper === null) return;
286
+ const onWheel = (event) => {
287
+ const current = viewRef.current;
288
+ const rect = wrapper.getBoundingClientRect();
289
+ const cx = event.clientX - rect.left;
290
+ const cy = event.clientY - rect.top;
291
+ let next = null;
292
+ if (event.ctrlKey || event.metaKey) {
293
+ const nextScale = clamp(current.scale * Math.exp(-event.deltaY * VIEWPORT_WHEEL_ZOOM), VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
294
+ if (nextScale !== current.scale) next = clampView({
295
+ ...zoomAtPoint(current, cx, cy, nextScale),
296
+ scale: nextScale
297
+ });
298
+ } else {
299
+ const content = measureContent(layerRef.current);
300
+ const clamped = clampPan(current.scale, current.x, current.y - event.deltaY, rect.width, rect.height, content.w, content.h);
301
+ if (clamped.y !== current.y) next = {
302
+ ...current,
303
+ ...clamped
304
+ };
305
+ }
306
+ if (next === null) return;
307
+ event.preventDefault();
308
+ setView(next);
309
+ };
310
+ wrapper.addEventListener("wheel", onWheel, { passive: false });
311
+ return () => wrapper.removeEventListener("wheel", onWheel);
312
+ }, []);
313
+ /** The toolbar's center-anchored zoom (the wrapper's center stands fixed). */
314
+ const zoomBy = (step) => {
315
+ const wrapper = wrapperRef.current;
316
+ if (wrapper === null) return;
317
+ const rect = wrapper.getBoundingClientRect();
318
+ const content = measureContent(layerRef.current);
319
+ setView((v) => {
320
+ const nextScale = clamp(v.scale * step, VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
321
+ if (nextScale === v.scale) return v;
322
+ const zoomed = zoomAtPoint(v, rect.width / 2, rect.height / 2, nextScale);
323
+ return {
324
+ scale: nextScale,
325
+ ...clampPan(nextScale, zoomed.x, zoomed.y, rect.width, rect.height, content.w, content.h)
326
+ };
327
+ });
328
+ };
329
+ const zoomIn = () => zoomBy(VIEWPORT_ZOOM_STEP);
330
+ const zoomOut = () => zoomBy(1 / VIEWPORT_ZOOM_STEP);
331
+ const resetView = () => setView(clampView(VIEWPORT_IDENTITY));
332
+ const atIdentity = (() => {
333
+ const rect = wrapperRef.current?.getBoundingClientRect();
334
+ const content = measureContent(layerRef.current);
335
+ const clamped = clampPan(VIEWPORT_IDENTITY.scale, 0, 0, rect?.width ?? 0, rect?.height ?? 0, content.w, content.h);
336
+ return view.scale === VIEWPORT_IDENTITY.scale && view.x === clamped.x && view.y === clamped.y;
337
+ })();
338
+ /**
339
+ * The fit's stand (the default's restore for the large diagram): the
340
+ * scale's min over the width / height's ratio, capped at 1 (the small
341
+ * diagram's stand the natural's size — no upscaling), centered over the
342
+ * visible viewport's box (the clipped stand included). The no-content's
343
+ * stand (the error / loading's states): the no-op.
344
+ */
345
+ const fitView = () => {
346
+ const wrapper = wrapperRef.current;
347
+ if (wrapper === null) return;
348
+ const rect = wrapper.getBoundingClientRect();
349
+ const content = measureContent(layerRef.current);
350
+ if (rect.width <= 0 || rect.height <= 0 || content.w <= 0 || content.h <= 0) return;
351
+ const scale = clamp(Math.min(rect.width / content.w, rect.height / content.h, 1), VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
352
+ setView({
353
+ scale,
354
+ x: (rect.width - content.w * scale) / 2,
355
+ y: (rect.height - content.h * scale) / 2
356
+ });
357
+ };
358
+ /**
359
+ * The persisted view's write (the debounce over the gesture's bursts):
360
+ * the non-identity view stands the block's attrs (the null idiom: the
361
+ * identity parts stand `null`, the reader's restore), so the reload's /
362
+ * the new tab's diagram stands the same view. The canonical's stand:
363
+ * the write stands the clamped view (the centering's offset over the
364
+ * sub-wrapper content's stand the canonical's coordinate — the peer's
365
+ * adopt's clamped read stands the no-write parity over it: a raw
366
+ * identity's persist stands the peer's re-centering's write-back over
367
+ * the wire, the reset's no-restore's stand). The no-op stand: a view
368
+ * equal to the block's own attrs writes nothing (no updatedAt's stamp,
369
+ * no wire update).
370
+ */
371
+ useEffect(() => {
372
+ const clamped = clampView(view);
373
+ const zoom = roundViewValue(clamped.scale, 2);
374
+ const x = roundViewValue(clamped.x, 1);
375
+ const y = roundViewValue(clamped.y, 1);
376
+ const attrs = block.attrs ?? {};
377
+ const canonical = clampView({
378
+ scale: attrs.zoom ?? 1,
379
+ x: attrs.panX ?? 0,
380
+ y: attrs.panY ?? 0
381
+ });
382
+ if (zoom === roundViewValue(canonical.scale, 2) && x === roundViewValue(canonical.x, 1) && y === roundViewValue(canonical.y, 1)) return;
383
+ const timer = window.setTimeout(() => {
384
+ doc.updateBlock(id, {
385
+ zoom: zoom === 1 ? null : zoom,
386
+ panX: x === 0 ? null : x,
387
+ panY: y === 0 ? null : y
388
+ });
389
+ }, VIEWPORT_PERSIST_DEBOUNCE_MS);
390
+ return () => window.clearTimeout(timer);
391
+ }, [
392
+ view,
393
+ block.attrs,
394
+ doc,
395
+ id
396
+ ]);
397
+ /**
398
+ * The remote's stand: the panes share the persisted view over the wire —
399
+ * a pane's peer lands a view different from the local's (the block's
400
+ * attrs stand the peer's write), so the local's view adopts it. Own
401
+ * writes land equal to the local's view and stand no adopt. The adopt
402
+ * clamps the restored pan to the current wrapper (a stale pan over a
403
+ * narrower pane's clip must not blank the diagram; the clamp's
404
+ * centering over the sub-wrapper content's stand the canonical's
405
+ * coordinate the persist writes — the mount's stand included: the
406
+ * initial raw's view clamps to its canonical's stand).
407
+ */
408
+ useEffect(() => {
409
+ const target = {
410
+ scale: block.attrs?.zoom ?? 1,
411
+ x: block.attrs?.panX ?? 0,
412
+ y: block.attrs?.panY ?? 0
413
+ };
414
+ const clamped = clampView(target);
415
+ const v = viewRef.current;
416
+ if (clamped.scale === v.scale && clamped.x === v.x && clamped.y === v.y) return;
417
+ setView(clamped);
418
+ }, [block.attrs]);
419
+ /** The remote's stand over the height (the panes' shared stand over the
420
+ * wire — the adopt's parity over the embed's idiom). */
421
+ useEffect(() => {
422
+ const attrHeight = block.attrs?.height ?? null;
423
+ if (attrHeight === heightRef.current) return;
424
+ setHeight(attrHeight);
425
+ }, [block.attrs]);
426
+ const onPointerDown = (event) => {
427
+ if (event.button !== 0) return;
428
+ const target = event.target;
429
+ if (target.closest("button") !== null || target.closest("[data-slot=\"docblocks/mermaid-resize\"]") !== null) return;
430
+ event.preventDefault();
431
+ wrapperRef.current?.setPointerCapture(event.pointerId);
432
+ panSession.current = {
433
+ pointerId: event.pointerId,
434
+ lastX: event.clientX,
435
+ lastY: event.clientY
436
+ };
437
+ };
438
+ const onPointerMove = (event) => {
439
+ const session = panSession.current;
440
+ if (session === null || event.pointerId !== session.pointerId) return;
441
+ const dx = event.clientX - session.lastX;
442
+ const dy = event.clientY - session.lastY;
443
+ session.lastX = event.clientX;
444
+ session.lastY = event.clientY;
445
+ setView((v) => clampView({
446
+ scale: v.scale,
447
+ x: v.x + dx,
448
+ y: v.y + dy
449
+ }));
450
+ };
451
+ const endPan = (event) => {
452
+ const session = panSession.current;
453
+ if (session === null || event.pointerId !== session.pointerId) return;
454
+ wrapperRef.current?.releasePointerCapture(event.pointerId);
455
+ panSession.current = null;
456
+ };
457
+ const onResizePointerDown = (event) => {
458
+ if (event.button !== 0) return;
459
+ event.stopPropagation();
460
+ const wrapper = wrapperRef.current;
461
+ if (wrapper === null) return;
462
+ event.target.setPointerCapture?.(event.pointerId);
463
+ const startHeight = wrapper.getBoundingClientRect().height;
464
+ resizeSession.current = {
465
+ pointerId: event.pointerId,
466
+ startY: event.clientY,
467
+ startHeight,
468
+ lastHeight: startHeight
469
+ };
470
+ };
471
+ const onResizePointerMove = (event) => {
472
+ const session = resizeSession.current;
473
+ if (session === null || event.pointerId !== session.pointerId) return;
474
+ const next = Math.max(session.startHeight + (event.clientY - session.startY), VIEWPORT_MIN_HEIGHT);
475
+ session.lastHeight = next;
476
+ setHeight(next);
477
+ };
478
+ const endResize = (event) => {
479
+ const session = resizeSession.current;
480
+ if (session === null || event.pointerId !== session.pointerId) return;
481
+ event.target.releasePointerCapture?.(event.pointerId);
482
+ resizeSession.current = null;
483
+ const committed = Math.round(session.lastHeight);
484
+ const current = block.attrs?.height ?? null;
485
+ if (committed <= VIEWPORT_MIN_HEIGHT) {
486
+ if (current !== null) doc.updateBlock(id, { height: null });
487
+ } else if (committed !== current) doc.updateBlock(id, { height: committed });
488
+ };
489
+ const onResizeKeyDown = (event) => {
490
+ const wrapper = wrapperRef.current;
491
+ if (wrapper === null) return;
492
+ const delta = event.key === "ArrowDown" ? VIEWPORT_RESIZE_KEY_STEP : event.key === "ArrowUp" ? -16 : null;
493
+ if (delta === null) return;
494
+ event.preventDefault();
495
+ const current = Math.max(heightRef.current ?? wrapper.clientHeight, 0);
496
+ const next = Math.max(current + delta, VIEWPORT_MIN_HEIGHT);
497
+ setHeight(next <= VIEWPORT_MIN_HEIGHT ? null : next);
498
+ const value = next <= VIEWPORT_MIN_HEIGHT ? null : next;
499
+ if (value === (block.attrs?.height ?? null)) return;
500
+ doc.updateBlock(id, { height: value });
501
+ };
502
+ return /* @__PURE__ */ jsxs("div", {
503
+ ref: wrapperRef,
504
+ "data-slot": "docblocks/mermaid-viewport",
505
+ contentEditable: false,
506
+ className: "group relative mt-(--docblocks-block-spacing) w-full overflow-hidden outline-none",
507
+ style: {
508
+ ...height !== null ? { height: Math.max(height, VIEWPORT_MIN_HEIGHT) } : {},
509
+ cursor: panSession.current !== null ? "grabbing" : "grab"
510
+ },
511
+ onPointerDown,
512
+ onPointerMove,
513
+ onPointerUp: endPan,
514
+ onPointerCancel: endPan,
515
+ children: [
516
+ /* @__PURE__ */ jsx("div", {
517
+ ref: layerRef,
518
+ "data-slot": "docblocks/mermaid-viewport-layer",
519
+ style: {
520
+ transform: `translate(${view.x}px, ${view.y}px) scale(${view.scale})`,
521
+ transformOrigin: "0 0"
522
+ },
523
+ children
524
+ }),
525
+ /* @__PURE__ */ jsxs("div", {
526
+ "data-slot": "docblocks/mermaid-viewport-toolbar",
527
+ className: "\n pointer-events-none absolute top-1.5 right-1.5 z-10 flex items-center gap-0.5 rounded-(--docblocks-radius)\n border-(length:--docblocks-divider-border-width) border-(--docblocks-divider-border-color)\n bg-(--docblocks-page-card-background) p-0.5 text-(--docblocks-text-color) opacity-0\n shadow-(--docblocks-formatbar-shadow) transition-opacity\n group-focus-within:pointer-events-auto group-focus-within:opacity-100\n group-hover:pointer-events-auto group-hover:opacity-100\n ",
528
+ children: [
529
+ /* @__PURE__ */ jsx(Button, {
530
+ "data-slot": "docblocks/mermaid-zoom-out",
531
+ variant: "ghost",
532
+ size: "icon",
533
+ "aria-label": t("code.diagramZoomOut"),
534
+ className: "size-6 cursor-default rounded-sm text-(--docblocks-text-color) disabled:opacity-50",
535
+ disabled: view.scale <= VIEWPORT_MIN_SCALE,
536
+ onMouseDown: preventDefault,
537
+ onClick: zoomOut,
538
+ children: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
539
+ }),
540
+ /* @__PURE__ */ jsxs("span", {
541
+ "data-slot": "docblocks/mermaid-zoom",
542
+ className: "min-w-10 px-1 text-center text-xs text-(--docblocks-text-color) tabular-nums",
543
+ children: [Math.round(view.scale * 100), "%"]
544
+ }),
545
+ /* @__PURE__ */ jsx(Button, {
546
+ "data-slot": "docblocks/mermaid-zoom-in",
547
+ variant: "ghost",
548
+ size: "icon",
549
+ "aria-label": t("code.diagramZoomIn"),
550
+ className: "size-6 cursor-default rounded-sm text-(--docblocks-text-color) disabled:opacity-50",
551
+ disabled: view.scale >= VIEWPORT_MAX_SCALE,
552
+ onMouseDown: preventDefault,
553
+ onClick: zoomIn,
554
+ children: /* @__PURE__ */ jsx(Plus, { className: "size-4" })
555
+ }),
556
+ /* @__PURE__ */ jsx(Button, {
557
+ "data-slot": "docblocks/mermaid-fit",
558
+ variant: "ghost",
559
+ size: "icon",
560
+ "aria-label": t("code.diagramFit"),
561
+ className: "size-6 cursor-default rounded-sm text-(--docblocks-text-color)",
562
+ onMouseDown: preventDefault,
563
+ onClick: fitView,
564
+ children: /* @__PURE__ */ jsx(Maximize, { className: "size-4" })
565
+ }),
566
+ /* @__PURE__ */ jsx(Button, {
567
+ "data-slot": "docblocks/mermaid-zoom-reset",
568
+ variant: "ghost",
569
+ size: "icon",
570
+ "aria-label": t("code.diagramZoomReset"),
571
+ className: "size-6 cursor-default rounded-sm text-(--docblocks-text-color) disabled:opacity-50",
572
+ disabled: atIdentity,
573
+ onMouseDown: preventDefault,
574
+ onClick: resetView,
575
+ children: /* @__PURE__ */ jsx(RotateCcw, { className: "size-4" })
576
+ })
577
+ ]
578
+ }),
579
+ !viewMode && /* @__PURE__ */ jsx("div", {
580
+ "data-slot": "docblocks/mermaid-resize",
581
+ role: "slider",
582
+ "aria-orientation": "vertical",
583
+ "aria-valuemin": VIEWPORT_MIN_HEIGHT,
584
+ "aria-valuenow": Math.max(height ?? wrapperRef.current?.clientHeight ?? VIEWPORT_MIN_HEIGHT, VIEWPORT_MIN_HEIGHT),
585
+ "aria-label": t("code.diagramResizeHeight"),
586
+ tabIndex: 0,
587
+ className: "\n absolute inset-x-0 bottom-0 z-10 flex h-2 cursor-row-resize items-end justify-center opacity-0\n transition-opacity outline-none\n group-focus-within:opacity-100\n group-hover:opacity-100\n ",
588
+ onPointerDown: onResizePointerDown,
589
+ onPointerMove: onResizePointerMove,
590
+ onPointerUp: endResize,
591
+ onPointerCancel: endResize,
592
+ onKeyDown: onResizeKeyDown,
593
+ children: /* @__PURE__ */ jsx("div", { className: "mb-0.5 h-0.5 w-10 rounded-full bg-(--docblocks-divider-border-color)" })
594
+ })
595
+ ]
596
+ });
597
+ }
598
+ //#endregion
174
599
  //#region src/mermaid/MermaidCodeRenderer.tsx
175
600
  function MermaidModeSelector({ id, block }) {
176
601
  const { doc } = useEditorContext();
@@ -231,10 +656,14 @@ function MermaidCodeBlock({ id, block }) {
231
656
  })
232
657
  }),
233
658
  codeBodyHidden: mode === "preview",
234
- nested: mode === "preview" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(MermaidDiagram, {
659
+ nested: mode === "preview" ? /* @__PURE__ */ jsxs(MermaidViewport, {
235
660
  id,
236
- text: textOf(block.content)
237
- }), nested] }) : nested
661
+ block,
662
+ children: [/* @__PURE__ */ jsx(MermaidDiagram, {
663
+ id,
664
+ text: textOf(block.content)
665
+ }), nested]
666
+ }) : nested
238
667
  });
239
668
  }
240
669
  /**
@@ -1,4 +1,4 @@
1
- import { v as PdfPreviewProps } from "../index-DPLVe3Mf.mjs";
1
+ import { y as PdfPreviewProps } from "../index-BA6ZzJK8.mjs";
2
2
  //#region src/pdf/PdfFirstPage.d.ts
3
3
  declare function PdfFirstPage({ id, blockType, url, name }: PdfPreviewProps): import("react").JSX.Element;
4
4
  //#endregion
@@ -1,31 +1,10 @@
1
1
  import { c as X, d as Minus, f as LoaderCircle, i as isSafeDownloadHref, l as TriangleAlert, m as ChevronLeft, p as ChevronRight, r as clamp, s as cn, t as isEmbeddablePdfUrl, u as Plus } from "../constants-D8PSgkwi.mjs";
2
+ import { t as Maximize } from "../Maximize-BBHnCDWL.mjs";
2
3
  import { useCallback, useEffect, useRef, useState } from "react";
3
4
  import { useTranslation } from "react-i18next";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
6
  import { createPortal } from "react-dom";
6
7
  import { GlobalWorkerOptions, RenderingCancelledException, getDocument } from "pdfjs-dist";
7
- //#region src/shared/ui/icons/Maximize.tsx
8
- function Maximize(props) {
9
- return /* @__PURE__ */ jsxs("svg", {
10
- xmlns: "http://www.w3.org/2000/svg",
11
- width: 24,
12
- height: 24,
13
- viewBox: "0 0 24 24",
14
- fill: "none",
15
- stroke: "currentColor",
16
- strokeWidth: 2,
17
- strokeLinecap: "round",
18
- strokeLinejoin: "round",
19
- ...props,
20
- children: [
21
- /* @__PURE__ */ jsx("path", { d: "M8 3H5a2 2 0 0 0-2 2v3" }),
22
- /* @__PURE__ */ jsx("path", { d: "M21 8V5a2 2 0 0 0-2-2h-3" }),
23
- /* @__PURE__ */ jsx("path", { d: "M3 16v3a2 2 0 0 0 2 2h3" }),
24
- /* @__PURE__ */ jsx("path", { d: "M16 21h3a2 2 0 0 0 2-2v-3" })
25
- ]
26
- });
27
- }
28
- //#endregion
29
8
  //#region src/shared/ui/icons/Minimize.tsx
30
9
  function Minimize(props) {
31
10
  return /* @__PURE__ */ jsxs("svg", {
package/dist/styles.css CHANGED
@@ -392,6 +392,9 @@
392
392
  .z-40 {
393
393
  z-index: 40;
394
394
  }
395
+ .z-45 {
396
+ z-index: 45;
397
+ }
395
398
  .z-50 {
396
399
  z-index: 50;
397
400
  }
@@ -533,9 +536,6 @@
533
536
  .block {
534
537
  display: block;
535
538
  }
536
- .contents {
537
- display: contents;
538
- }
539
539
  .flex {
540
540
  display: flex;
541
541
  }
@@ -923,10 +923,18 @@
923
923
  --tw-translate-x: calc(calc(1 / 2 * 100%) * -1);
924
924
  translate: var(--tw-translate-x) var(--tw-translate-y);
925
925
  }
926
+ .translate-x-3 {
927
+ --tw-translate-x: calc(var(--spacing) * 3);
928
+ translate: var(--tw-translate-x) var(--tw-translate-y);
929
+ }
926
930
  .-translate-y-1\/2 {
927
931
  --tw-translate-y: calc(calc(1 / 2 * 100%) * -1);
928
932
  translate: var(--tw-translate-x) var(--tw-translate-y);
929
933
  }
934
+ .translate-y-3 {
935
+ --tw-translate-y: calc(var(--spacing) * 3);
936
+ translate: var(--tw-translate-x) var(--tw-translate-y);
937
+ }
930
938
  .translate-y-\[calc\(-50\%-2px\)\] {
931
939
  --tw-translate-y: calc(-50% - 2px);
932
940
  translate: var(--tw-translate-x) var(--tw-translate-y);
@@ -1255,6 +1263,9 @@
1255
1263
  .border-\(--border\) {
1256
1264
  border-color: var(--border);
1257
1265
  }
1266
+ .border-\(--docblocks-canvas-group-border-color\) {
1267
+ border-color: var(--docblocks-canvas-group-border-color);
1268
+ }
1258
1269
  .border-\(--docblocks-canvas-selection-border-color\) {
1259
1270
  border-color: var(--docblocks-canvas-selection-border-color);
1260
1271
  }
@@ -3583,7 +3594,7 @@
3583
3594
  * docblocks/format-palette),
3584
3595
  * plus the per-block elements;
3585
3596
  * + `data-block-type` / `data-list` / `data-depth` / `data-variant` / `data-checked`
3586
- * / `data-kind` / `data-selected` / `data-state` / `data-doc-id` / `data-readonly`.
3597
+ * / `data-kind` / `data-selected` / `data-state` / `data-doc-id` / `data-mode` / `data-readonly`.
3587
3598
  */
3588
3599
 
3589
3600
  /*
@@ -3906,12 +3917,29 @@
3906
3917
 
3907
3918
  /*
3908
3919
  * The read-only stand (view / published modes): the editor's content is
3909
- * read-only — the text selection stands no stand (the native range's
3910
- * gesture is an editing's affordance). The caret is already impossible
3911
- * (the inners stand contenteditable="false"), this keeps the
3912
- * selection's gesture off over the whole content.
3920
+ * read-only — the inners stand contenteditable="false" (the caret's
3921
+ * editing's affordance is impossible).
3922
+ *
3923
+ * The PUBLISHED stand also blocks the text selection: the reader's copy
3924
+ * stands no stand (the published state is readable over the rendered page
3925
+ * only — no range, no copy). The VIEW stand keeps
3926
+ * the native selection (the live document is read-only but copyable: the
3927
+ * text is the reader's to quote, and the editor's copy payload serves it
3928
+ * — see use-editing). The `data-readonly` over the standalone's read-only
3929
+ * grid (no `data-mode` — the consumer's own surfaces) keeps the no-select
3930
+ * stand.
3931
+ */
3932
+ [data-slot="docblocks/editor"][data-readonly="true"]:not([data-mode="view"]) {
3933
+ user-select: none;
3934
+ }
3935
+
3936
+ /*
3937
+ * The view's mode over the canvas: the page's text stands selectable, the
3938
+ * canvas's world keeps the read-only's no-select stand — the native range
3939
+ * would fight the pan's drag (the observing gesture) and the world's text
3940
+ * is not an editing surface.
3913
3941
  */
3914
- [data-slot="docblocks/editor"][data-readonly="true"] {
3942
+ [data-slot="docblocks/editor"][data-mode="view"] [data-slot="docblocks/canvas-world"] {
3915
3943
  user-select: none;
3916
3944
  }
3917
3945
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docblocks-react-ui",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
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.4.0",
37
+ "docblocks-core": "^0.6.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",