goatdee-canvas 0.0.42 → 0.0.43

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.
package/dist/index.cjs CHANGED
@@ -2296,13 +2296,16 @@ const unmark = (id, index) => {
2296
2296
  /**
2297
2297
  * 向画布添加对象。
2298
2298
  * @category 对象操作
2299
- * @param type - 元素类型
2300
- * @param properties - 对象初始属性,字段参考对应的对象类型定义(如 CanvasTextboxObject、CanvasImageObject 等)
2299
+ * @param properties - 对象初始属性,需包含 `type` 字段,其余字段参考对应的对象类型定义(如 CanvasTextboxObject、CanvasImageObject 等)
2301
2300
  * @returns 新创建对象的 ID;失败时返回 null
2302
2301
  */
2303
- const add = async (type, properties) => {
2302
+ const add = async (properties) => {
2304
2303
  try {
2304
+ if (!properties || !properties.type) {
2305
+ return null;
2306
+ }
2305
2307
  const canvas = manager.getCanvas();
2308
+ const type = properties.type;
2306
2309
  // 添加对象
2307
2310
  const id = canvas.add(type, properties);
2308
2311
  if (!id)
@@ -2800,7 +2803,7 @@ const addFabricJSON = async (fabricJSON, x = 0, y = 0) => {
2800
2803
  if (workareaFill !== undefined) {
2801
2804
  frameProperties.fill = workareaFill;
2802
2805
  }
2803
- return await add("frame", frameProperties);
2806
+ return await add(frameProperties);
2804
2807
  }
2805
2808
  return null;
2806
2809
  }
@@ -3293,7 +3296,8 @@ async function syncOverlayItem(element, info, isCanvasReady) {
3293
3296
  // 创建占位元素
3294
3297
  const id = element.getAttribute("data-overlay-id") ||
3295
3298
  `worker-overlay-item-${Math.random().toString(36).substring(2, 15)}`;
3296
- const placeholderId = await add("placeholder", {
3299
+ const placeholderId = await add({
3300
+ type: "placeholder",
3297
3301
  left: bounds.x,
3298
3302
  top: bounds.y,
3299
3303
  width: bounds.width,
@@ -4157,9 +4161,9 @@ function useCanvasImperativeHandle(ref, args) {
4157
4161
  reportAction("unmark", { id, index });
4158
4162
  unmark(id, index);
4159
4163
  },
4160
- add: async (type, properties) => {
4161
- reportAction("add", { type, properties });
4162
- return await add(type, properties);
4164
+ add: async (properties) => {
4165
+ reportAction("add", { properties });
4166
+ return await add(properties);
4163
4167
  },
4164
4168
  copy: async () => {
4165
4169
  reportAction("copy", null);