@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,6 +1,6 @@
1
1
  "use client";
2
- export { geometry3dStamp } from './chunk-IUVV52HO.mjs';
3
- export { isGeometry3DCustomData } from './chunk-DU2NFHRR.mjs';
2
+ export { geometry3dStamp } from './chunk-PWIMZIB6.mjs';
3
+ export { isGeometry3DCustomData } from './chunk-WQOABS6N.mjs';
4
4
  import './chunk-HTBLO5JO.mjs';
5
5
  import './chunk-BJTO5JO5.mjs';
6
6
  //# sourceMappingURL=geometry-3d.mjs.map
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { serializeBoard, renderGeometrySvgFromState, isGeometryCustomData, safeJsx } from './chunk-KEYZ5EZT.mjs';
2
+ import { serializeBoard, renderGeometrySvgFromState, isGeometryCustomData, safeJsx } from './chunk-G7FR3AIV.mjs';
3
3
  import { useChordShortcut, MobileToolDrawer } from './chunk-SBDMF4NQ.mjs';
4
4
  import { resolveAttrColors, paletteFor, themeLabel, themeAxis, themeGrid } from './chunk-HTBLO5JO.mjs';
5
5
  import { useIsMobile } from './chunk-P2AOIF7S.mjs';
@@ -259,8 +259,12 @@ function letterForGroup(g) {
259
259
  }
260
260
  function objKind(obj) {
261
261
  if (!obj) return "other";
262
+ const ec = typeof obj.elementClass === "number" ? obj.elementClass : null;
263
+ if (ec === 1) return "point";
264
+ if (ec === 2) return "line";
265
+ if (ec === 3) return "circle";
262
266
  const e = (obj.elType || obj.type || "").toString().toLowerCase();
263
- if (e === "point" || e === "glider" || e === "midpoint") return "point";
267
+ if (e === "point" || e === "glider" || e === "midpoint" || e === "intersection" || e === "otherintersection" || e === "reflection" || e === "mirrorpoint" || e === "mirrorelement" || e === "orthogonalprojection" || e === "parallelpoint") return "point";
264
268
  if (e === "line" || e === "segment" || e === "arrow" || e === "axis" || e === "normal" || e === "parallel" || e === "perpendicular" || e === "tangent" || e === "bisector" || e === "perpendicularsegment") return "line";
265
269
  if (e === "circle" || e === "circumcircle") return "circle";
266
270
  return "other";
@@ -282,7 +286,7 @@ function handleDown(ctx, e) {
282
286
  if (!sc) return;
283
287
  const [sx, sy] = sc;
284
288
  const hits2 = ctx.objectsAt(e).map(ctx.promoteLabel).filter((o) => o !== ctx.axisObjsRef.current.x && o !== ctx.axisObjsRef.current.y);
285
- const obj = hits2.find((o) => objKind(o) === "point") ?? hits2[0] ?? ctx.findNearestPoint(e, 12);
289
+ const obj = hits2.find((o) => objKind(o) === "point") ?? ctx.findNearestPoint(e, 12) ?? hits2[0];
286
290
  if (obj) {
287
291
  const shift = !!(e.shiftKey || e.altKey);
288
292
  ctx.toggleSelect(obj, shift);
@@ -525,7 +529,7 @@ function handleUp(ctx, e) {
525
529
  const moved = Math.hypot(sx - start.sx, sy - start.sy);
526
530
  if (moved > 4) return;
527
531
  const hits = ctx.objectsAt(e).map(ctx.promoteLabel).filter((o) => o !== ctx.axisObjsRef.current.x && o !== ctx.axisObjsRef.current.y);
528
- const best = hits.find((o) => objKind(o) === "point") ?? hits[0] ?? ctx.findNearestPoint(e, 12);
532
+ const best = hits.find((o) => objKind(o) === "point") ?? ctx.findNearestPoint(e, 12) ?? hits[0];
529
533
  if (!best) {
530
534
  ctx.lastMoveClickRef.current = { obj: null, time: 0 };
531
535
  return;
@@ -648,8 +652,16 @@ var JSXGraphMiniBoard = ({ onReady, initialState, isDark }) => {
648
652
  const nextLocalId = useCallback(() => "j" + creationLogRef.current.length, []);
649
653
  const resolveArgs = useCallback((args) => {
650
654
  return args.map((a) => {
651
- if (typeof a === "string" && objMapRef.current.has(a)) {
652
- return objMapRef.current.get(a);
655
+ if (typeof a === "string") {
656
+ if (objMapRef.current.has(a)) return objMapRef.current.get(a);
657
+ const m = /^(.+):border:(\d+)$/.exec(a);
658
+ if (m) {
659
+ const poly = objMapRef.current.get(m[1]);
660
+ const idx = parseInt(m[2], 10);
661
+ if (poly && Array.isArray(poly.borders) && poly.borders[idx]) {
662
+ return poly.borders[idx];
663
+ }
664
+ }
653
665
  }
654
666
  return a;
655
667
  });
@@ -679,15 +691,27 @@ var JSXGraphMiniBoard = ({ onReady, initialState, isDark }) => {
679
691
  [nextLocalId, resolveArgs, pushLog]
680
692
  );
681
693
  const localIdOf = useCallback((obj) => {
694
+ if (!obj) return null;
682
695
  for (const [id, o] of objMapRef.current.entries()) {
683
696
  if (o === obj) return id;
684
697
  }
698
+ for (const [id, o] of objMapRef.current.entries()) {
699
+ const borders = o?.borders;
700
+ if (Array.isArray(borders)) {
701
+ const idx = borders.indexOf(obj);
702
+ if (idx >= 0) return `${id}:border:${idx}`;
703
+ }
704
+ }
685
705
  return null;
686
706
  }, []);
687
707
  const snapshotObject = useCallback((obj, anchorScreen) => {
688
708
  const o = obj;
689
709
  const k = objKind(o);
690
710
  if (k !== "point" && k !== "line" && k !== "circle") return null;
711
+ for (const owner of objMapRef.current.values()) {
712
+ const borders = owner?.borders;
713
+ if (Array.isArray(borders) && borders.indexOf(o) >= 0) return null;
714
+ }
691
715
  const v = o.visProp ?? {};
692
716
  const showLabel = v.withlabel !== false;
693
717
  const showValue = valueLabelsRef.current.has(o);
@@ -1206,7 +1230,22 @@ var JSXGraphMiniBoard = ({ onReady, initialState, isDark }) => {
1206
1230
  const board = boardRef.current;
1207
1231
  if (!board) return false;
1208
1232
  const idMap = objMapRef.current;
1209
- const resolved = el.args.map((a) => typeof a === "string" && idMap.has(a) ? idMap.get(a) : a);
1233
+ const resolve = (a) => {
1234
+ if (typeof a === "string") {
1235
+ if (idMap.has(a)) return idMap.get(a);
1236
+ const m = /^(.+):border:(\d+)$/.exec(a);
1237
+ if (m) {
1238
+ const poly = idMap.get(m[1]);
1239
+ const idx = parseInt(m[2], 10);
1240
+ if (poly && Array.isArray(poly.borders) && poly.borders[idx]) {
1241
+ return poly.borders[idx];
1242
+ }
1243
+ }
1244
+ }
1245
+ if (Array.isArray(a)) return a.map(resolve);
1246
+ return a;
1247
+ };
1248
+ const resolved = el.args.map(resolve);
1210
1249
  try {
1211
1250
  if (el.type === "valueLabel") {
1212
1251
  const target = resolved[0];
@@ -2504,6 +2543,7 @@ var GeometryEditorPanel = forwardRef(
2504
2543
  function GeometryEditorPanel2({ initialState, onInsert, onClose, withLeftPanel = false, onStateChange, isDark, isMobile = false, onOpenDrawer, onUndo, onRedo, canUndo, canRedo }, ref) {
2505
2544
  const handleRef = useRef(null);
2506
2545
  const [ready, setReady] = useState(false);
2546
+ const [hasContent, setHasContent] = useState(false);
2507
2547
  const [propsPopover, setPropsPopover] = useState(null);
2508
2548
  const [transformPopover, setTransformPopover] = useState(null);
2509
2549
  const onStateChangeRef = useRef(onStateChange);
@@ -2512,8 +2552,10 @@ var GeometryEditorPanel = forwardRef(
2512
2552
  }, [onStateChange]);
2513
2553
  const emitState = useCallback(() => {
2514
2554
  const h = handleRef.current;
2555
+ if (!h) return;
2556
+ setHasContent(h.getCreationLog().length > 0);
2515
2557
  const cb = onStateChangeRef.current;
2516
- if (!h || !cb) return;
2558
+ if (!cb) return;
2517
2559
  cb({
2518
2560
  tool: h.getTool(),
2519
2561
  showAxis: h.getShowAxis(),
@@ -2643,7 +2685,8 @@ var GeometryEditorPanel = forwardRef(
2643
2685
  {
2644
2686
  type: "button",
2645
2687
  onClick: handleInsert,
2646
- disabled: !ready,
2688
+ disabled: !ready || !hasContent,
2689
+ title: !hasContent ? "V\u1EBD \xEDt nh\u1EA5t m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng tr\u01B0\u1EDBc khi ch\xE8n" : void 0,
2647
2690
  "data-testid": "geometry-insert-btn-mobile",
2648
2691
  className: "rounded bg-white/15 px-3 py-1.5 text-xs font-semibold transition hover:bg-white/25 disabled:opacity-50",
2649
2692
  children: "Ch\xE8n"
@@ -2743,7 +2786,8 @@ var GeometryEditorPanel = forwardRef(
2743
2786
  "button",
2744
2787
  {
2745
2788
  onClick: handleInsert,
2746
- disabled: !ready,
2789
+ disabled: !ready || !hasContent,
2790
+ title: !hasContent ? "V\u1EBD \xEDt nh\u1EA5t m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng tr\u01B0\u1EDBc khi ch\xE8n" : void 0,
2747
2791
  "data-testid": "geometry-insert-btn",
2748
2792
  className: "rounded bg-emerald-600 px-3 py-1 text-xs font-medium text-white transition hover:bg-emerald-700 disabled:opacity-50",
2749
2793
  children: "Ch\xE8n"
@@ -2860,5 +2904,5 @@ var GeometryStampHost = forwardRef(
2860
2904
  );
2861
2905
 
2862
2906
  export { GeometryStampHost };
2863
- //# sourceMappingURL=host-VDNAJMLC.mjs.map
2864
- //# sourceMappingURL=host-VDNAJMLC.mjs.map
2907
+ //# sourceMappingURL=host-DJETSFCG.mjs.map
2908
+ //# sourceMappingURL=host-DJETSFCG.mjs.map