@xom11/whiteboard 0.9.1 → 0.10.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,12 +1,12 @@
1
1
  "use client";
2
- import { VIEW3D_ATTRS, DEFAULT_VIEW3D, GROUND_PLANE_RANGE, GROUND_PLANE_ATTRS, paletteFor, serializeBoard3D, isGeometry3DCustomData, parseSerializedBoard3D } from './chunk-DU2NFHRR.mjs';
2
+ import { VIEW3D_ATTRS, DEFAULT_VIEW3D, GROUND_PLANE_RANGE, GROUND_PLANE_ATTRS, paletteFor, serializeBoard3D, renderGeometry3DSvgFromState, isGeometry3DCustomData, parseSerializedBoard3D } from './chunk-WQOABS6N.mjs';
3
3
  import { useChordShortcut, MobileToolDrawer } from './chunk-SBDMF4NQ.mjs';
4
4
  import './chunk-HTBLO5JO.mjs';
5
5
  import { useIsMobile } from './chunk-P2AOIF7S.mjs';
6
6
  import { insertStampImage } from './chunk-C6SCVOMC.mjs';
7
7
  import './chunk-BJTO5JO5.mjs';
8
8
  import * as React2 from 'react';
9
- import { forwardRef, useRef, useState, useCallback, useMemo, useImperativeHandle } from 'react';
9
+ import { forwardRef, useRef, useState, useCallback, useEffect, useMemo, useImperativeHandle } from 'react';
10
10
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
11
  import { createPortal } from 'react-dom';
12
12
 
@@ -1274,8 +1274,11 @@ var MiniBoard3D = React2.forwardRef(
1274
1274
  ],
1275
1275
  {
1276
1276
  ...baseAttrs,
1277
- az: { ...baseAttrs.az, value: DEFAULT_VIEW3D.azimuth },
1278
- el: { ...baseAttrs.el, value: DEFAULT_VIEW3D.elevation }
1277
+ // JSXGraph view3d đọc giá trị khởi tạo từ az.slider.start (không
1278
+ // phải az.value). Pass nhầm `value` JSXGraph dùng default
1279
+ // 1.0/0.3, khiến DEFAULT_VIEW3D bị bỏ qua.
1280
+ az: { ...baseAttrs.az, slider: { ...baseAttrs.az.slider, start: DEFAULT_VIEW3D.azimuth } },
1281
+ el: { ...baseAttrs.el, slider: { ...baseAttrs.el.slider, start: DEFAULT_VIEW3D.elevation } }
1279
1282
  }
1280
1283
  );
1281
1284
  } catch {
@@ -1979,8 +1982,17 @@ var EditorPanel = React2.forwardRef(
1979
1982
  }, [showAxis, showGrid]);
1980
1983
  const handleView3DReady = React2.useCallback((view) => {
1981
1984
  rendererRef.current = new JxgRenderer(scene, view);
1985
+ if (initialState) {
1986
+ try {
1987
+ const v = view;
1988
+ v?.az_slide?.setValue?.(initialState.view.azimuth);
1989
+ v?.el_slide?.setValue?.(initialState.view.elevation);
1990
+ v?.board?.update?.();
1991
+ } catch {
1992
+ }
1993
+ }
1982
1994
  onReadyChange?.(true);
1983
- }, [onReadyChange, scene]);
1995
+ }, [onReadyChange, scene, initialState]);
1984
1996
  const handleClick = React2.useCallback((screen) => {
1985
1997
  const board = boardRef.current;
1986
1998
  if (!board) return;
@@ -2118,8 +2130,10 @@ var EditorPanel = React2.forwardRef(
2118
2130
  const elevation = typeof elSlider?.Value === "function" ? elSlider.Value() : 0;
2119
2131
  return sceneToBoard(
2120
2132
  scene,
2121
- { azimuth, elevation, bbox3D: [-5, -5, -5, 5, 5, 5] },
2122
- [-6, -6, 6, 6]
2133
+ { azimuth, elevation, bbox3D: [...DEFAULT_VIEW3D.bbox3D] },
2134
+ // JSXGraph boundingbox order: [xmin, ymax, xmax, ymin]. Must match
2135
+ // MiniBoard3D.initBoard so render reproduces the editor's view.
2136
+ [-6, 6, 6, -6]
2123
2137
  );
2124
2138
  },
2125
2139
  setTool: (k) => controllerRef.current.selectTool(k),
@@ -2962,10 +2976,25 @@ var Geometry3DStampHost = forwardRef(
2962
2976
  const [showGrid, setShowGrid] = useState(true);
2963
2977
  const [canUndo, setCanUndo] = useState(false);
2964
2978
  const [canRedo, setCanRedo] = useState(false);
2979
+ const [hasContent, setHasContent] = useState(false);
2965
2980
  const handleHistoryChange = useCallback((u, r) => {
2966
2981
  setCanUndo(u);
2967
2982
  setCanRedo(r);
2968
2983
  }, []);
2984
+ useEffect(() => {
2985
+ const scene = sceneRef.current;
2986
+ if (!scene) return;
2987
+ const sync = () => setHasContent(scene.list().length > 0);
2988
+ sync();
2989
+ const unsubs = [
2990
+ scene.on("add", sync),
2991
+ scene.on("delete", sync),
2992
+ scene.on("reset", sync)
2993
+ ];
2994
+ return () => {
2995
+ for (const u of unsubs) u();
2996
+ };
2997
+ }, []);
2969
2998
  const handleUndo = useCallback(() => {
2970
2999
  editorRef.current?.undo();
2971
3000
  }, []);
@@ -3013,7 +3042,15 @@ var Geometry3DStampHost = forwardRef(
3013
3042
  if (!editorRef.current.hasContent()) return false;
3014
3043
  const board = editorRef.current.serialize();
3015
3044
  if (board.elements.length === 0) return false;
3016
- void performInsert(board, 0, 0, "");
3045
+ void (async () => {
3046
+ try {
3047
+ const jsonState = serializeBoard3D(board);
3048
+ const { svgString, width, height } = await renderGeometry3DSvgFromState(jsonState);
3049
+ await performInsert(board, width, height, svgString);
3050
+ } catch (err) {
3051
+ console.error("Geometry3D insert failed:", err);
3052
+ }
3053
+ })();
3017
3054
  return true;
3018
3055
  }, [performInsert]);
3019
3056
  useImperativeHandle(
@@ -3095,7 +3132,8 @@ var Geometry3DStampHost = forwardRef(
3095
3132
  {
3096
3133
  type: "button",
3097
3134
  onClick: tryInsert,
3098
- disabled: !ready,
3135
+ disabled: !ready || !hasContent,
3136
+ title: !hasContent ? "V\u1EBD \xEDt nh\u1EA5t m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng tr\u01B0\u1EDBc khi ch\xE8n" : void 0,
3099
3137
  "data-testid": "geom3d-insert-btn-mobile",
3100
3138
  className: "rounded bg-white/15 px-3 py-1.5 text-xs font-semibold transition hover:bg-white/25 disabled:opacity-50",
3101
3139
  children: "Ch\xE8n"
@@ -3145,7 +3183,8 @@ var Geometry3DStampHost = forwardRef(
3145
3183
  "button",
3146
3184
  {
3147
3185
  onClick: tryInsert,
3148
- disabled: !ready,
3186
+ disabled: !ready || !hasContent,
3187
+ title: !hasContent ? "V\u1EBD \xEDt nh\u1EA5t m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng tr\u01B0\u1EDBc khi ch\xE8n" : void 0,
3149
3188
  "data-testid": "geom3d-insert-btn",
3150
3189
  className: "rounded bg-emerald-600 px-3 py-1 text-xs font-medium text-white transition hover:bg-emerald-700 disabled:opacity-50",
3151
3190
  children: "Ch\xE8n"
@@ -3183,5 +3222,5 @@ var Geometry3DStampHost = forwardRef(
3183
3222
  );
3184
3223
 
3185
3224
  export { Geometry3DStampHost };
3186
- //# sourceMappingURL=host-PIIDSMVE.mjs.map
3187
- //# sourceMappingURL=host-PIIDSMVE.mjs.map
3225
+ //# sourceMappingURL=host-N6ACNJKI.mjs.map
3226
+ //# sourceMappingURL=host-N6ACNJKI.mjs.map