labellife-design-tool 1.3.1 → 1.3.2

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.
@@ -547,7 +547,7 @@ function initJsxCompat() {
547
547
  }
548
548
 
549
549
  // src/CanvasEditor.tsx
550
- import React17, { useRef as useRef4, useEffect as useEffect4, useMemo, useCallback as useCallback4 } from "react";
550
+ import React17, { useRef as useRef4, useEffect as useEffect4, useMemo, useCallback as useCallback4, forwardRef, useImperativeHandle } from "react";
551
551
  import { Stage, Layer, Rect as Rect2 } from "react-konva";
552
552
 
553
553
  // src/elements/EditableTextElement.tsx
@@ -2716,16 +2716,16 @@ var RightSidebar = ({
2716
2716
  var RightSidebar_default = RightSidebar;
2717
2717
 
2718
2718
  // src/CanvasEditor.tsx
2719
- var CanvasEditor = ({
2720
- name,
2721
- config,
2722
- store
2723
- }) => {
2719
+ var CanvasEditor = forwardRef(({ name, config, store }, ref) => {
2720
+ if (!store) {
2721
+ console.error("CanvasEditor: store prop is required but was not provided");
2722
+ return /* @__PURE__ */ React17.createElement("div", null, "Error: Store is required");
2723
+ }
2724
2724
  const stageRef = useRef4(null);
2725
2725
  const fileInputRef = useRef4(null);
2726
2726
  const jsonInputRef = useRef4(null);
2727
2727
  const containerRef = useRef4(null);
2728
- const currentPage = store.design.pages.find((p) => p.id === store.activePageId) || store.design.pages[0] || null;
2728
+ const currentPage = store.design?.pages.find((p) => p.id === store.activePageId) || store.design?.pages[0] || null;
2729
2729
  const selectedElement = currentPage?.elements.find((el) => el.id === store.selectedId) || null;
2730
2730
  useEffect4(() => {
2731
2731
  const handleDesignChange = (newDesign) => {};
@@ -2763,25 +2763,25 @@ var CanvasEditor = ({
2763
2763
  }
2764
2764
  }, [store]);
2765
2765
  const addText = useCallback4(() => {
2766
- if (!store.activePage)
2766
+ if (!store?.activePage)
2767
2767
  return;
2768
2768
  store.activePage.addElement({
2769
2769
  type: "text",
2770
2770
  text: "Edit this text",
2771
- x: store.design.width / 2 - 50,
2772
- y: store.design.height / 2 - 15,
2771
+ x: (store.design?.width || 800) / 2 - 50,
2772
+ y: (store.design?.height || 600) / 2 - 15,
2773
2773
  width: 100,
2774
2774
  height: 30
2775
2775
  });
2776
2776
  }, [store]);
2777
2777
  const addShape = useCallback4((shapeType) => {
2778
- if (!store.activePage)
2778
+ if (!store?.activePage)
2779
2779
  return;
2780
2780
  store.activePage.addElement({
2781
2781
  type: "shape",
2782
2782
  shapeType,
2783
- x: store.design.width / 2 - 50,
2784
- y: store.design.height / 2 - 50,
2783
+ x: (store.design?.width || 800) / 2 - 50,
2784
+ y: (store.design?.height || 600) / 2 - 50,
2785
2785
  width: 100,
2786
2786
  height: 100
2787
2787
  });
@@ -2900,12 +2900,12 @@ var CanvasEditor = ({
2900
2900
  reader.onload = (event) => {
2901
2901
  const img = new window.Image;
2902
2902
  img.onload = () => {
2903
- if (store.activePage) {
2903
+ if (store?.activePage) {
2904
2904
  store.activePage.addElement({
2905
2905
  type: "image",
2906
2906
  src: event.target?.result,
2907
- x: store.design.width / 2 - img.width / 2,
2908
- y: store.design.height / 2 - img.height / 2,
2907
+ x: (store.design?.width || 800) / 2 - img.width / 2,
2908
+ y: (store.design?.height || 600) / 2 - img.height / 2,
2909
2909
  width: img.width,
2910
2910
  height: img.height
2911
2911
  });
@@ -2916,6 +2916,31 @@ var CanvasEditor = ({
2916
2916
  reader.readAsDataURL(file);
2917
2917
  }
2918
2918
  }, [store]);
2919
+ useImperativeHandle(ref, () => ({
2920
+ stage: stageRef.current,
2921
+ exportToPNG: () => {
2922
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToPNG: exportToPNG2 }) => {
2923
+ exportToPNG2(stageRef.current, store.design);
2924
+ });
2925
+ },
2926
+ exportToJPG: () => {
2927
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToJPG: exportToJPG2 }) => {
2928
+ exportToJPG2(stageRef.current, store.design);
2929
+ });
2930
+ },
2931
+ exportToJSON: () => {
2932
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToJSON: exportToJSON2 }) => {
2933
+ exportToJSON2(store.design);
2934
+ });
2935
+ },
2936
+ getDesign: () => store.design,
2937
+ setCanvasSize: (width, height) => {
2938
+ store.updateDesign({ width, height });
2939
+ },
2940
+ loadDesign: async (jsonData) => {
2941
+ await store.loadJSON(jsonData);
2942
+ }
2943
+ }), [stageRef.current, store.design]);
2919
2944
  return /* @__PURE__ */ React17.createElement("div", {
2920
2945
  className: "w-full h-full flex flex-col bg-gray-900"
2921
2946
  }, /* @__PURE__ */ React17.createElement(Header_default, {
@@ -2962,15 +2987,15 @@ var CanvasEditor = ({
2962
2987
  }
2963
2988
  }, /* @__PURE__ */ React17.createElement(Stage, {
2964
2989
  ref: stageRef,
2965
- width: store.design.width,
2966
- height: store.design.height,
2990
+ width: store.design?.width || 800,
2991
+ height: store.design?.height || 600,
2967
2992
  onClick: handleStageClick,
2968
2993
  onTap: handleStageClick
2969
2994
  }, /* @__PURE__ */ React17.createElement(Layer, null, /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(Rect2, {
2970
2995
  x: 0,
2971
2996
  y: 0,
2972
- width: store.design.width,
2973
- height: store.design.height,
2997
+ width: store.design?.width || 800,
2998
+ height: store.design?.height || 600,
2974
2999
  fill: currentPage.backgroundImageObject ? undefined : currentPage.background,
2975
3000
  fillPatternImage: currentPage.backgroundImageObject,
2976
3001
  fillPatternRepeat: "no-repeat"
@@ -3014,7 +3039,7 @@ var CanvasEditor = ({
3014
3039
  }
3015
3040
  })))))), config?.multiPage && /* @__PURE__ */ React17.createElement("div", {
3016
3041
  className: "absolute bottom-4 left-4 flex items-center space-x-2"
3017
- }, store.design.pages.map((page, index) => /* @__PURE__ */ React17.createElement("button", {
3042
+ }, (store.design?.pages || []).map((page, index) => /* @__PURE__ */ React17.createElement("button", {
3018
3043
  key: page.id,
3019
3044
  onClick: () => store.setActivePage(page.id),
3020
3045
  className: `px-3 py-1 rounded text-sm ${page.id === store.activePageId ? "bg-blue-600 text-white" : "bg-gray-800 text-gray-300 hover:bg-gray-700"}`
@@ -3041,7 +3066,8 @@ var CanvasEditor = ({
3041
3066
  onChange: handleImportJSON,
3042
3067
  style: { display: "none" }
3043
3068
  }));
3044
- };
3069
+ });
3070
+ CanvasEditor.displayName = "CanvasEditor";
3045
3071
  var CanvasEditor_default = CanvasEditor;
3046
3072
  // src/store/simpleStore.ts
3047
3073
  class SimpleCanvasStore {
@@ -547,7 +547,7 @@ function initJsxCompat() {
547
547
  }
548
548
 
549
549
  // src/CanvasEditor.tsx
550
- import React17, { useRef as useRef4, useEffect as useEffect4, useMemo, useCallback as useCallback4 } from "react";
550
+ import React17, { useRef as useRef4, useEffect as useEffect4, useMemo, useCallback as useCallback4, forwardRef, useImperativeHandle } from "react";
551
551
  import { Stage, Layer, Rect as Rect2 } from "react-konva";
552
552
 
553
553
  // src/elements/EditableTextElement.tsx
@@ -2716,16 +2716,16 @@ var RightSidebar = ({
2716
2716
  var RightSidebar_default = RightSidebar;
2717
2717
 
2718
2718
  // src/CanvasEditor.tsx
2719
- var CanvasEditor = ({
2720
- name,
2721
- config,
2722
- store
2723
- }) => {
2719
+ var CanvasEditor = forwardRef(({ name, config, store }, ref) => {
2720
+ if (!store) {
2721
+ console.error("CanvasEditor: store prop is required but was not provided");
2722
+ return /* @__PURE__ */ React17.createElement("div", null, "Error: Store is required");
2723
+ }
2724
2724
  const stageRef = useRef4(null);
2725
2725
  const fileInputRef = useRef4(null);
2726
2726
  const jsonInputRef = useRef4(null);
2727
2727
  const containerRef = useRef4(null);
2728
- const currentPage = store.design.pages.find((p) => p.id === store.activePageId) || store.design.pages[0] || null;
2728
+ const currentPage = store.design?.pages.find((p) => p.id === store.activePageId) || store.design?.pages[0] || null;
2729
2729
  const selectedElement = currentPage?.elements.find((el) => el.id === store.selectedId) || null;
2730
2730
  useEffect4(() => {
2731
2731
  const handleDesignChange = (newDesign) => {};
@@ -2763,25 +2763,25 @@ var CanvasEditor = ({
2763
2763
  }
2764
2764
  }, [store]);
2765
2765
  const addText = useCallback4(() => {
2766
- if (!store.activePage)
2766
+ if (!store?.activePage)
2767
2767
  return;
2768
2768
  store.activePage.addElement({
2769
2769
  type: "text",
2770
2770
  text: "Edit this text",
2771
- x: store.design.width / 2 - 50,
2772
- y: store.design.height / 2 - 15,
2771
+ x: (store.design?.width || 800) / 2 - 50,
2772
+ y: (store.design?.height || 600) / 2 - 15,
2773
2773
  width: 100,
2774
2774
  height: 30
2775
2775
  });
2776
2776
  }, [store]);
2777
2777
  const addShape = useCallback4((shapeType) => {
2778
- if (!store.activePage)
2778
+ if (!store?.activePage)
2779
2779
  return;
2780
2780
  store.activePage.addElement({
2781
2781
  type: "shape",
2782
2782
  shapeType,
2783
- x: store.design.width / 2 - 50,
2784
- y: store.design.height / 2 - 50,
2783
+ x: (store.design?.width || 800) / 2 - 50,
2784
+ y: (store.design?.height || 600) / 2 - 50,
2785
2785
  width: 100,
2786
2786
  height: 100
2787
2787
  });
@@ -2900,12 +2900,12 @@ var CanvasEditor = ({
2900
2900
  reader.onload = (event) => {
2901
2901
  const img = new window.Image;
2902
2902
  img.onload = () => {
2903
- if (store.activePage) {
2903
+ if (store?.activePage) {
2904
2904
  store.activePage.addElement({
2905
2905
  type: "image",
2906
2906
  src: event.target?.result,
2907
- x: store.design.width / 2 - img.width / 2,
2908
- y: store.design.height / 2 - img.height / 2,
2907
+ x: (store.design?.width || 800) / 2 - img.width / 2,
2908
+ y: (store.design?.height || 600) / 2 - img.height / 2,
2909
2909
  width: img.width,
2910
2910
  height: img.height
2911
2911
  });
@@ -2916,6 +2916,31 @@ var CanvasEditor = ({
2916
2916
  reader.readAsDataURL(file);
2917
2917
  }
2918
2918
  }, [store]);
2919
+ useImperativeHandle(ref, () => ({
2920
+ stage: stageRef.current,
2921
+ exportToPNG: () => {
2922
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToPNG: exportToPNG2 }) => {
2923
+ exportToPNG2(stageRef.current, store.design);
2924
+ });
2925
+ },
2926
+ exportToJPG: () => {
2927
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToJPG: exportToJPG2 }) => {
2928
+ exportToJPG2(stageRef.current, store.design);
2929
+ });
2930
+ },
2931
+ exportToJSON: () => {
2932
+ Promise.resolve().then(() => exports_exportImportUtils).then(({ exportToJSON: exportToJSON2 }) => {
2933
+ exportToJSON2(store.design);
2934
+ });
2935
+ },
2936
+ getDesign: () => store.design,
2937
+ setCanvasSize: (width, height) => {
2938
+ store.updateDesign({ width, height });
2939
+ },
2940
+ loadDesign: async (jsonData) => {
2941
+ await store.loadJSON(jsonData);
2942
+ }
2943
+ }), [stageRef.current, store.design]);
2919
2944
  return /* @__PURE__ */ React17.createElement("div", {
2920
2945
  className: "w-full h-full flex flex-col bg-gray-900"
2921
2946
  }, /* @__PURE__ */ React17.createElement(Header_default, {
@@ -2962,15 +2987,15 @@ var CanvasEditor = ({
2962
2987
  }
2963
2988
  }, /* @__PURE__ */ React17.createElement(Stage, {
2964
2989
  ref: stageRef,
2965
- width: store.design.width,
2966
- height: store.design.height,
2990
+ width: store.design?.width || 800,
2991
+ height: store.design?.height || 600,
2967
2992
  onClick: handleStageClick,
2968
2993
  onTap: handleStageClick
2969
2994
  }, /* @__PURE__ */ React17.createElement(Layer, null, /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(Rect2, {
2970
2995
  x: 0,
2971
2996
  y: 0,
2972
- width: store.design.width,
2973
- height: store.design.height,
2997
+ width: store.design?.width || 800,
2998
+ height: store.design?.height || 600,
2974
2999
  fill: currentPage.backgroundImageObject ? undefined : currentPage.background,
2975
3000
  fillPatternImage: currentPage.backgroundImageObject,
2976
3001
  fillPatternRepeat: "no-repeat"
@@ -3014,7 +3039,7 @@ var CanvasEditor = ({
3014
3039
  }
3015
3040
  })))))), config?.multiPage && /* @__PURE__ */ React17.createElement("div", {
3016
3041
  className: "absolute bottom-4 left-4 flex items-center space-x-2"
3017
- }, store.design.pages.map((page, index) => /* @__PURE__ */ React17.createElement("button", {
3042
+ }, (store.design?.pages || []).map((page, index) => /* @__PURE__ */ React17.createElement("button", {
3018
3043
  key: page.id,
3019
3044
  onClick: () => store.setActivePage(page.id),
3020
3045
  className: `px-3 py-1 rounded text-sm ${page.id === store.activePageId ? "bg-blue-600 text-white" : "bg-gray-800 text-gray-300 hover:bg-gray-700"}`
@@ -3041,7 +3066,8 @@ var CanvasEditor = ({
3041
3066
  onChange: handleImportJSON,
3042
3067
  style: { display: "none" }
3043
3068
  }));
3044
- };
3069
+ });
3070
+ CanvasEditor.displayName = "CanvasEditor";
3045
3071
  var CanvasEditor_default = CanvasEditor;
3046
3072
  // src/store/simpleStore.ts
3047
3073
  class SimpleCanvasStore {
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
2
  import { Config } from "./types/Config";
3
3
  import { SimpleCanvasStore } from "./store/simpleStore";
4
- declare const CanvasEditor: React.FC<{
4
+ import type { CanvasEditorRef } from "./lib/index";
5
+ declare const CanvasEditor: React.ForwardRefExoticComponent<{
5
6
  name: string;
6
7
  config?: Config;
7
8
  store: SimpleCanvasStore;
8
- }>;
9
+ } & React.RefAttributes<CanvasEditorRef>>;
9
10
  export default CanvasEditor;
10
11
  //# sourceMappingURL=CanvasEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CanvasEditor.d.ts","sourceRoot":"","sources":["../../src/CanvasEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmF,MAAM,OAAO,CAAC;AA4ExG,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAqB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,CA0cvF,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"CanvasEditor.d.ts","sourceRoot":"","sources":["../../src/CanvasEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmF,MAAM,OAAO,CAAC;AA4ExG,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAqB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,QAAA,MAAM,YAAY;UAAuC,MAAM;aAAW,MAAM;WAAS,iBAAiB;yCA6exG,CAAC;AAIH,eAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labellife-design-tool",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Professional canvas editor built with React, TypeScript, and Konva",
5
5
  "main": "./dist/lib/lib/index.js",
6
6
  "module": "./dist/lib/lib/index.js",