goatdee-canvas 0.0.71 → 0.0.73

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.
Binary file
package/dist/index.cjs CHANGED
@@ -2491,39 +2491,6 @@ const unmark = (id, index) => {
2491
2491
  console.warn("Canvas operation(unmark) failed:", error);
2492
2492
  }
2493
2493
  };
2494
- /**
2495
- * 获取当前激活态的标注信息。
2496
- * 配合 `onAction("mark" | "activate mark")` 使用:事件触发后按需调用,避免 dispatch 时反复算屏幕坐标。
2497
- * @category 对象操作
2498
- * @returns 激活态标注信息;无激活时返回 null
2499
- */
2500
- const getActiveMark = () => {
2501
- try {
2502
- const canvas = manager.getCanvas();
2503
- const jsonStr = canvas.getActiveMark();
2504
- return jsonStr ? JSON.parse(jsonStr) : null;
2505
- }
2506
- catch (error) {
2507
- console.warn("Canvas operation(getActiveMark) failed:", error);
2508
- return null;
2509
- }
2510
- };
2511
- /**
2512
- * 获取全部标注信息。
2513
- * @category 对象操作
2514
- * @returns 标注信息数组;无标注时返回 `[]`
2515
- */
2516
- const getAllMarks = () => {
2517
- try {
2518
- const canvas = manager.getCanvas();
2519
- const jsonStr = canvas.getAllMarks();
2520
- return jsonStr ? JSON.parse(jsonStr) : [];
2521
- }
2522
- catch (error) {
2523
- console.warn("Canvas operation(getAllMarks) failed:", error);
2524
- return [];
2525
- }
2526
- };
2527
2494
  /**
2528
2495
  * 向画布添加对象到指定父容器下。
2529
2496
  * @category 对象操作
@@ -3302,9 +3269,7 @@ var ManagerAPI = /*#__PURE__*/Object.freeze({
3302
3269
  exportImages: exportImages,
3303
3270
  exportToJSON: exportToJSON,
3304
3271
  fitToScreen: fitToScreen,
3305
- getActiveMark: getActiveMark,
3306
3272
  getActiveObjects: getActiveObjects,
3307
- getAllMarks: getAllMarks,
3308
3273
  getBounds: getBounds,
3309
3274
  getCrop: getCrop,
3310
3275
  getGPUMemoryStats: getGPUMemoryStats,
@@ -4479,8 +4444,6 @@ function useCanvasImperativeHandle(ref, args) {
4479
4444
  reportAction("unmark", { id, index });
4480
4445
  unmark(id, index);
4481
4446
  },
4482
- getActiveMark: () => getActiveMark(),
4483
- getAllMarks: () => getAllMarks(),
4484
4447
  add: async (parentId, properties) => {
4485
4448
  reportAction("add", { parentId, properties });
4486
4449
  return add(parentId, properties);
@@ -6393,42 +6356,33 @@ function useCanvasResize(args) {
6393
6356
  }, []);
6394
6357
  }
6395
6358
 
6396
- /**
6397
- * 监听 document 上的自定义 `onAction` 事件,把事件转发给调用方的
6398
- * `onAction` 回调,同时经 `reportAction` 上报到灯塔。
6399
- *
6400
- * 使用 ref 存储最新 props,外壳 listener 保持稳定,
6401
- * 可避免每次 props 变更都重新 add/remove 监听。
6402
- *
6403
- * 性能优化:除 `afterrender` 外,`onAction` 回调延迟到下一帧 paint 之后触发,
6404
- * 避免在 C++ 同步 `dispatchEvent` 的调用栈里跑 `getActiveObjects` + React 渲染,
6405
- * 阻塞当前帧的绘制(例如框选松手时清除选择框的那帧)。
6406
- * 具体调度:rAF + setTimeout(0),确保浏览器先完成这一帧的 paint 再通知业务侧;
6407
- * 灯塔上报保持同步,避免页面关闭/刷新时丢数据。
6408
- */
6359
+ function parseActionData(raw) {
6360
+ if (typeof raw !== "string" || raw === "") {
6361
+ return undefined;
6362
+ }
6363
+ try {
6364
+ const parsed = JSON.parse(raw);
6365
+ if (parsed !== null && typeof parsed === "object") {
6366
+ return parsed;
6367
+ }
6368
+ }
6369
+ catch (_a) { }
6370
+ return raw;
6371
+ }
6409
6372
  function useOnActionBridge(onAction, reportAction) {
6410
6373
  const handlerRef = react.useRef(() => { });
6411
6374
  const aliveRef = react.useRef(true);
6412
6375
  handlerRef.current = (event) => {
6376
+ if (!aliveRef.current)
6377
+ return;
6413
6378
  const detail = event.detail;
6414
6379
  const action = detail === null || detail === void 0 ? void 0 : detail.action;
6415
6380
  if (action == null || action === "")
6416
6381
  return;
6417
- const data = typeof (detail === null || detail === void 0 ? void 0 : detail.data) === "string" ? detail.data : undefined;
6382
+ const data = parseActionData(detail === null || detail === void 0 ? void 0 : detail.data);
6383
+ // 上报到灯塔
6418
6384
  reportAction(action);
6419
- if (action === "afterrender" ||
6420
- action === "modified" ||
6421
- action === "add") {
6422
- onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6423
- return;
6424
- }
6425
- requestAnimationFrame(() => {
6426
- setTimeout(() => {
6427
- if (!aliveRef.current)
6428
- return;
6429
- onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6430
- }, 0);
6431
- });
6385
+ onAction === null || onAction === void 0 ? void 0 : onAction(action, data);
6432
6386
  };
6433
6387
  react.useEffect(() => {
6434
6388
  aliveRef.current = true;