@ydesign/react-editor 0.1.1 → 0.1.3

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.
Files changed (36) hide show
  1. package/README.md +20 -119
  2. package/dist/canvas/workspace.d.ts +1 -1
  3. package/dist/chunk-3PMUQSBH.js +1 -0
  4. package/dist/chunk-3UOBPTKL.js +151 -0
  5. package/dist/{chunk-RBRSKAZL.js → chunk-AMEXYVS6.js} +1 -1
  6. package/dist/chunk-C4XMVZO4.js +1 -0
  7. package/dist/chunk-OV7AL42Z.js +1 -0
  8. package/dist/{chunk-WFMCGQ5V.js → chunk-Q7N7SBSC.js} +1 -1
  9. package/dist/{chunk-SR5OYO6O.js → chunk-SEZLO2OE.js} +15 -15
  10. package/dist/{chunk-63A6RW6Y.js → chunk-VIU27HHW.js} +1 -1
  11. package/dist/config.d.ts +2 -221
  12. package/dist/config.js +1 -1
  13. package/dist/model/store.d.ts +1 -1
  14. package/dist/model/store.js +1 -1
  15. package/dist/project.d.ts +11 -1
  16. package/dist/project.js +1 -1
  17. package/dist/side-panel/index.d.ts +1 -1
  18. package/dist/side-panel/index.js +1 -1
  19. package/dist/side-panel/side-panel.d.ts +1 -1
  20. package/dist/side-panel/side-panel.js +1 -1
  21. package/dist/{store-DfmY1m2j.d.ts → store-CgxwnT-h.d.ts} +3 -0
  22. package/dist/toolbar/download-button.d.ts +1 -1
  23. package/dist/toolbar/download-button.js +1 -1
  24. package/dist/toolbar/toolbar.d.ts +1 -1
  25. package/dist/toolbar/toolbar.js +3 -3
  26. package/dist/toolbar/zoom-buttons.d.ts +1 -1
  27. package/dist/topbar/create-design.d.ts +28 -0
  28. package/dist/topbar/create-design.js +1 -0
  29. package/dist/topbar/topbar.d.ts +1 -1
  30. package/dist/topbar/topbar.js +5 -155
  31. package/dist/utils/l10n.d.ts +228 -0
  32. package/dist/utils/l10n.js +1 -0
  33. package/package.json +2 -2
  34. package/dist/chunk-2AZQIJ4K.js +0 -1
  35. package/dist/chunk-EUTDQZKU.js +0 -1
  36. package/dist/chunk-KERQXVBL.js +0 -1
@@ -1,154 +1,4 @@
1
- import{a as de}from"../chunk-RBRSKAZL.js";import{a as W,c as K}from"../chunk-2AZQIJ4K.js";import"../chunk-KERQXVBL.js";import"../chunk-YBC2DYJX.js";import{b as U,c as E}from"../chunk-5C2MNUBC.js";import{a as H}from"../chunk-EWOU5F3O.js";import{c as P}from"../chunk-WFMCGQ5V.js";import{a as ae,b as le,e as ce}from"../chunk-EUTDQZKU.js";import"../chunk-O2XFH626.js";import X from"styled-components";import{observer as Ce}from"mobx-react-lite";import{Dropdown as dt,Button as pt,Modal as mt}from"antd";import{Menu as gt,Plus as ht,Languages as ut,Check as be}from"lucide-react";import{useState as ft}from"react";import{observer as xt}from"mobx-react-lite";import{Modal as Fe,Button as Ke,ColorPicker as He,InputNumber as ge,Select as je,Tooltip as he,App as Ve,theme as Ge}from"antd";import{Grid2X2 as Xe,Star as qe,ShoppingBag as Je,FileText as Ze,Presentation as Qe,Share2 as Ye,Printer as et,ImagePlus as tt,FolderPlus as o,LockKeyholeOpen as ot,LockKeyhole as it}from"lucide-react";import{useRef as nt,useState as k,useMemo as ue,useCallback as $}from"react";import G from"styled-components";import{App as We,Modal as Ee,Upload as pe}from"antd";import{Inbox as _e}from"lucide-react";import{useRef as $e,useState as Oe}from"react";import{jsx as d,jsxs as _}from"react/jsx-runtime";var{Dragger:Ae}=pe,me=({visible:n,onClose:s})=>{let{message:u,modal:b}=We.useApp(),[g,v]=Oe(!1),l=$e(null),M=K();return d(Ee,{width:750,title:"\u4E0A\u4F20 PSD \u6587\u4EF6",open:n,onCancel:()=>{if(g){u.warning("\u6587\u4EF6\u6B63\u5728\u89E3\u6790\u4E2D\uFF0C\u8BF7\u7A0D\u5019...");return}s()},footer:null,mask:{closable:!g},styles:{body:{height:"calc(100% - 40px)",padding:"10px 0 0 0"},container:{height:500}},centered:!0,children:d("div",{style:{height:"100%"},children:_(Ae,{...{name:"file-psd",multiple:!1,accept:".psd",showUploadList:!1,beforeUpload(p){return p.name.toLowerCase().endsWith(".psd")?!0:(u.error("\u4EC5\u652F\u6301 .psd \u683C\u5F0F\u6587\u4EF6"),pe.LIST_IGNORE)},customRequest(p){let{file:r,onSuccess:x,onError:c,onProgress:C}=p;v(!0),l.current=u.loading("PSD \u6587\u4EF6\u89E3\u6790\u4E2D\uFF0C\u8BF7\u7A0D\u5019...",0);let h=new FormData;h.append("file",r),W.post(le().url,h,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress(f){f.total&&C&&C({percent:Math.round(f.loaded/f.total*100)})}}).then(f=>{x?.(f)}).catch(f=>{c?.(f)})},async onChange(p){let{status:r}=p.file;if(console.log("info",p),r==="done"){l.current?.(),l.current=null,v(!1),u.success(`${p.file.name} \u89E3\u6790\u6210\u529F`);let x=p.file.response;console.log("PSD \u89E3\u6790\u7ED3\u679C:",x.result);let{thumbnailUrl:c,content:C,name:h,width:f,height:y,filename:q,parseUrl:T}=x.result,O={sourceResourcesId:crypto.randomUUID(),content:C,width:f,height:y,parseUrl:T,thumbnailUrl:c,filename:q,name:h};console.log("postRecord ---> ",O);let S=ce(O);console.log("postData",S);try{let I=await W.post(S.url,S.data);console.log("res ---> ",I.result);let J=I.result,R=`${M.urls.editorUrl}?id=${J.id}&type=record`;console.log("editUrl",R);let B=window.open(R,"_blank");(!B||B.closed)&&b.info({title:"\u5141\u8BB8\u663E\u793A\u5F39\u51FA\u7A97\u53E3",width:480,content:_("div",{style:{padding:"16px 0"},children:[d("p",{style:{marginBottom:8,color:"#666"},children:"\u4F60\u9700\u8981\u6388\u6743\u672C\u7AD9\u5728\u6D4F\u89C8\u5668\u6253\u5F00\u591A\u4E2A\u7A97\u53E3\u3002"}),_("div",{style:{marginBottom:12},children:[d("p",{children:d("b",{children:"\u7B2C1\u6B65"})}),d("p",{children:"\u70B9\u51FB\u6D4F\u89C8\u5668\u53F3\u4FA7\u9876\u90E8\u5F39\u51FA\u7684\u963B\u6B62\u7A0B\u5E8F\u56FE\u6807\u3002"})]}),_("div",{style:{marginBottom:12},children:[d("p",{children:d("b",{children:"\u7B2C2\u6B65"})}),d("p",{children:"\u70B9\u51FB\u59CB\u7EC8\u5141\u8BB8\u663E\u793A\u5F39\u51FA\u5F0F\u7A97\u53E3\u548C\u8FDB\u884C\u91CD\u5B9A\u5411\u3002"})]}),_("div",{style:{marginBottom:12},children:[d("p",{children:d("b",{children:"\u7B2C3\u6B65"})}),d("p",{children:"\u70B9\u51FB\u5B8C\u6210\u6309\u94AE\uFF0C\u5373\u53EF\u6B63\u5E38\u4F7F\u7528\u529F\u80FD\u5566~"})]})]}),okText:"\u6211\u77E5\u9053\u5566"})}catch(I){console.error(I)}}else if(r==="error"){l.current?.(),l.current=null,v(!1);let x=p.file.error?.message||"\u89E3\u6790\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5";u.error(x)}}},disabled:g,children:[d("p",{className:"flex items-center justify-center",children:d(_e,{size:60})}),d("p",{className:"ant-upload-text",children:g?"\u89E3\u6790\u4E2D...":"\u62D6\u62FD\u6587\u4EF6\u5230\u6B64\u5904\u4E0A\u4F20\u6216\u70B9\u51FB\u4E0A\u4F20"}),d("p",{className:"ant-upload-hint",children:d("a",{href:"https://www.yuque.com/meitumcp/vvtts5/gfv8e5",target:"_blank",onClick:p=>{p.stopPropagation()},children:"PSD\u6587\u4EF6\u5BFC\u5165\u89C4\u8303"})})]})})})};import{Fragment as ct,jsx as e,jsxs as m}from"react/jsx-runtime";var st=[{key:"all",label:"\u5168\u90E8",icon:Xe},{key:"common",label:"\u5E38\u7528\u5C3A\u5BF8",icon:qe},{key:"ecommerce",label:"\u7535\u5546\u7269\u6599",icon:Je},{key:"office",label:"\u884C\u653F\u529E\u516C",icon:Ze},{key:"presentation",label:"\u6F14\u793A\u6587\u7A3F",icon:Qe},{key:"social",label:"\u793E\u4EA4\u5A92\u4F53",icon:Ye},{key:"print",label:"\u5370\u5237\u7269\u6599",icon:et}],fe=[{key:"common",label:"\u5E38\u7528\u5C3A\u5BF8",sizes:[{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF081:1\uFF09",desc:"1440x1440px",width:1440,height:1440,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF081:1\uFF09",desc:"800x800px",width:800,height:800,unit:"px"},{icon:e(o,{size:24}),name:"\u624B\u673A\u6D77\u62A5",desc:"1242x2208px",width:1242,height:2208,unit:"px"},{icon:e(o,{size:24}),name:"\u5C0F\u7EA2\u4E66\u5C01\u9762",desc:"1242x1656px",width:1242,height:1656,unit:"px"},{icon:e(o,{size:24}),name:"\u7AD6\u7248\u89C6\u9891\u5C01\u9762",desc:"1080x1920px",width:1080,height:1920,unit:"px"},{icon:e(o,{size:24}),name:"PPT\uFF0816:9\uFF09",desc:"1920x1080px",width:1920,height:1080,unit:"px"}]},{key:"ecommerce",label:"\u7535\u5546\u7269\u6599",sizes:[{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF081:1\uFF09",desc:"1440x1440px",width:1440,height:1440,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF081:1\uFF09",desc:"800x800px",width:800,height:800,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF083:4\uFF09",desc:"1440x1920px",width:1440,height:1920,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u4E3B\u56FE\uFF083:4\uFF09",desc:"750x1000px",width:750,height:1e3,unit:"px"},{icon:e(o,{size:24}),name:"\u76F4\u64AD\u95F4\u80CC\u666F",desc:"1242x2690px",width:1242,height:2690,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u8BE6\u60C5\u9875",desc:"750x1000px",width:750,height:1e3,unit:"px"},{icon:e(o,{size:24}),name:"\u7535\u5546\u7AD6\u7248\u6D77\u62A5",desc:"1200x1920px",width:1200,height:1920,unit:"px"}]},{key:"office",label:"\u884C\u653F\u529E\u516C",sizes:[{icon:e(o,{size:24}),name:"\u7B80\u5386",desc:"2480x3507px",width:2480,height:3507,unit:"px"},{icon:e(o,{size:24}),name:"\u5DE5\u724C\u5DE5\u4F5C\u8BC1",desc:"709x1087px",width:709,height:1087,unit:"px"},{icon:e(o,{size:24}),name:"\u5956\u72B6\u8BC1\u4E66",desc:"3437x2550px",width:3437,height:2550,unit:"px"}]},{key:"presentation",label:"\u6F14\u793A\u6587\u7A3F",sizes:[{icon:e(o,{size:24}),name:"PPT\uFF0816:9\uFF09",desc:"1920x1080px",width:1920,height:1080,unit:"px"},{icon:e(o,{size:24}),name:"PPT\uFF084:3\uFF09",desc:"1024x768px",width:1024,height:768,unit:"px"}]},{key:"social",label:"\u793E\u4EA4\u5A92\u4F53",sizes:[{icon:e(o,{size:24}),name:"\u624B\u673A\u6D77\u62A5",desc:"1242x2208px",width:1242,height:2208,unit:"px"},{icon:e(o,{size:24}),name:"\u624B\u673A\u5168\u5C4F\u6D77\u62A5",desc:"1242x2688px",width:1242,height:2688,unit:"px"},{icon:e(o,{size:24}),name:"\u7AD6\u7248\u89C6\u9891\u5C01\u9762",desc:"1080x1920px",width:1080,height:1920,unit:"px"},{icon:e(o,{size:24}),name:"\u6A2A\u7248\u89C6\u9891\u5C01\u9762",desc:"1920x1080px",width:1920,height:1080,unit:"px"},{icon:e(o,{size:24}),name:"\u5C0F\u7EA2\u4E66\u5C01\u9762",desc:"1242x1656px",width:1242,height:1656,unit:"px"},{icon:e(o,{size:24}),name:"\u6296\u97F3\u56FE\u6587\u5E26\u8D27",desc:"1242x1656px",width:1242,height:1656,unit:"px"},{icon:e(o,{size:24}),name:"\u516C\u4F17\u53F7\u9996\u56FE",desc:"900x383px",width:900,height:383,unit:"px"},{icon:e(o,{size:24}),name:"\u516C\u4F17\u53F7\u6B21\u56FE",desc:"900x800px",width:900,height:800,unit:"px"},{icon:e(o,{size:24}),name:"\u957F\u56FE\u6D77\u62A5",desc:"800x2000px",width:800,height:2e3,unit:"px"}]},{key:"print",label:"\u5370\u5237\u7269\u6599",sizes:[{icon:e(o,{size:24}),name:"\u4E00\u5BF8\u8BC1\u4EF6\u7167",desc:"23x35mm",width:25,height:35,unit:"mm"},{icon:e(o,{size:24}),name:"\u4E8C\u5BF8\u8BC1\u4EF6\u7167",desc:"35x53mm",width:35,height:53,unit:"mm"},{icon:e(o,{size:24}),name:"1.8\u7C73\u5C55\u67B6",desc:"80x180cm",width:80,height:180,unit:"cm"},{icon:e(o,{size:24}),name:"2m\u6613\u62C9\u5B9D",desc:"80x200cm",width:80,height:200,unit:"cm"},{icon:e(o,{size:24}),name:"\u540D\u7247",desc:"96x60mm",width:96,height:60,unit:"mm"},{icon:e(o,{size:24}),name:"\u4F18\u60E0\u5238",desc:"186x66mm",width:186,height:66,unit:"mm"},{icon:e(o,{size:24}),name:"\u4F20\u5355",desc:"216x291cm",width:216,height:291,unit:"cm"}]}],xe=G.div`
2
- padding: 16px 24px;
3
- height: 60px;
4
- flex: 1;
5
- display: flex;
6
- cursor: pointer;
7
- align-items: center;
8
- border-radius: 8px;
9
- border: 1px dashed #d0d2d6;
10
- &:hover {
11
- background-color: rgba(0, 31, 92, 0.06);
12
- }
13
- span {
14
- margin-left: 8px;
15
- }
16
- `,rt=G.div`
17
- flex: 1;
18
- margin-left: 14px;
19
- height: 100%;
20
-
21
- .createrContentInner {
22
- margin-bottom: 16px;
23
- }
24
-
25
- .scrollbars div:first-child {
26
- scroll-behavior: smooth;
27
- }
28
-
29
- .Widget.categorySection[data-is-folded='false'] .categoryFoldBtn,
30
- .Widget.categorySection[data-is-multi-row='false'] .categoryFoldBtn {
31
- display: none;
32
- }
33
-
34
- .Widget.categorySection[data-is-folded='true'] ul {
35
- height: 97px;
36
- overflow: hidden;
37
- }
38
- `,at=G.div`
39
- width: 100%;
40
- height: 100%;
41
- position: relative;
42
- padding-top: 16px;
43
- overflow: hidden;
44
-
45
- display: flex;
46
- flex-direction: column;
47
- align-items: center;
48
-
49
- border-radius: 8px;
50
- background-color: rgba(0, 0, 0, 0.05);
51
-
52
- .canvasSizeName {
53
- color: #616366;
54
- font-size: 12px;
55
- font-weight: 600;
56
- line-height: 16px;
57
- margin-top: 8px;
58
- }
59
-
60
- .canvasSizeSize {
61
- height: 14px;
62
- overflow: hidden;
63
- width: 100%;
64
- margin-top: 4px;
65
-
66
- span {
67
- color: #abadb2;
68
- display: block;
69
- font-size: 20px;
70
- font-weight: 400;
71
- height: 200%;
72
- line-height: 26px;
73
- text-align: center;
74
- -webkit-transform: scale(0.5);
75
- transform: scale(0.5);
76
- -webkit-transform-origin: top left;
77
- transform-origin: top left;
78
- width: 200%;
79
- }
80
- }
81
-
82
- .canvasSizeMask {
83
- background: rgba(0, 0, 0, 0.25);
84
- display: none;
85
- height: 100%;
86
- left: 0;
87
- position: absolute;
88
- top: 0;
89
- width: 100%;
90
- }
91
- .canvasSizeMask,
92
- .canvasSizeMask button {
93
- justify-content: center;
94
- align-items: center;
95
- }
96
-
97
- .canvasSizeMask button {
98
- background-color: #fff;
99
- width: 66px;
100
- height: 26px;
101
- display: flex;
102
- padding: 0 8px;
103
- outline: none;
104
- line-height: 16px;
105
- font-size: 12px;
106
- cursor: pointer;
107
- color: #1c1d1f;
108
- border-radius: 6px;
109
- }
110
- .canvasSizeMask button:active {
111
- background-color: #f2f2f2;
112
- }
113
-
114
- &:hover .canvasSizeMask {
115
- display: flex;
116
- }
117
- `,lt=G.div`
118
- display: flex;
119
- margin-top: 20px;
120
- flex-wrap: wrap;
121
- align-items: center;
122
- position: relative;
123
-
124
- .sizeWarning {
125
- width: 100%;
126
- margin-bottom: 8px;
127
- padding: 4px 8px;
128
- font-size: 12px;
129
- color: #ff4d4f;
130
- background-color: #fff2f0;
131
- border: 1px solid #ffccc7;
132
- border-radius: 4px;
133
- }
134
-
135
- .Widget.sizeInpueBox {
136
- display: flex;
137
- align-items: center;
138
-
139
- flex: 1;
140
- }
141
-
142
- .Widget.sizeInpueBox .sizeInput {
143
- flex: 1;
144
- }
145
- .Widget.sizeInpueBox .linkIcon {
146
- padding: 8px;
147
- background-color: #001f5c0f;
148
- border-radius: 8px;
149
- margin: 0 4px;
150
- }
151
- `,L=72,j=130,V=8e3,ye=({project:n,visible:s,onClose:u,onConfirm:b})=>{let{message:g,modal:v}=Ve.useApp(),[l,M]=k("all"),N=nt(null),{token:p}=Ge.useToken(),[r,x]=k(null),[c,C]=k(null),[h,f]=k("px"),[y,q]=k(!1),[T,O]=k(1),[S,I]=k("#ffffff"),[J,R]=k(!1),B=ue(()=>r?E({unitVal:r,dpi:L,unit:h}):0,[r,h]),Z=ue(()=>c?E({unitVal:c,dpi:L,unit:h}):0,[c,h]),Q=r!=null&&c!=null&&r>0&&c>0,A=Q&&(B>V||Z>V),F=Q&&(B<j||Z<j),Y=!Q||A||F,te=A?`\u8D85\u51FA\u753B\u5E03\u5C3A\u5BF8\u9650\u5236\uFF1A${V} * ${V} px`:F?`\u4F4E\u4E8E\u753B\u5E03\u5C3A\u5BF8\u9650\u5236\uFF1A${j} * ${j} px`:"",Se=$(t=>{x(t),y&&t&&t>0&&C(Math.round(t/T))},[y,T]),Pe=$(t=>{C(t),y&&t&&t>0&&x(Math.round(t*T))},[y,T]),Ne=$(()=>{!y&&r&&c&&r>0&&c>0&&O(r/c),q(t=>!t)},[y,r,c]),Te=$(t=>{if(r){let i=E({unitVal:r,dpi:L,unit:h});x(Math.round(U({px:i,dpi:L,unit:t,precious:0})))}if(c){let i=E({unitVal:c,dpi:L,unit:h});C(Math.round(U({px:i,dpi:L,unit:t,precious:0})))}f(t)},[r,c,h]),Ie=$(()=>{if(Y)return;let t=JSON.stringify({bg:{backgroundColor:S}}),i=new URLSearchParams({create:"",createEmptyPoster:"true",createInfo:t,height:String(c),unit:h,width:String(r)});console.log("params \u7684\u53C2\u6570 ---> ",i.toString()),console.log("project ",n.urls.editorUrl),window.open(`${n.urls.editorUrl}?${i.toString()}`,"_blank")},[Y,S,Z,B,h]),Be=t=>{M(t);let i=N.current;if(!i)return;let w=i.querySelector(`[data-category-id="${t}"]`);w&&i.scrollTo({top:w.offsetTop,behavior:"smooth"})},[Ue,Le]=k(()=>{let t={};return fe.forEach(i=>{t[i.key]=i.sizes.length>6}),t});return m(ct,{children:[m(Fe,{title:"\u521B\u5EFA\u8BBE\u8BA1",open:s,onCancel:u,footer:null,width:880,mask:{closable:!1},styles:{body:{display:"flex",flex:1,padding:"20px 0",height:"100%"},container:{height:550}},children:[e("div",{className:"createrSideBar",style:{width:140,"--sidebar-active-bg":p.colorPrimaryBg,"--sidebar-hover-bg":p.colorPrimaryBgHover},children:st.map(t=>m("div",{"data-active":t.key===l,className:H("createrSideBarItem","flex h-[40px] px-2 mb-2 cursor-pointer rounded-md items-center hover:bg-[var(--sidebar-hover-bg)]",{"bg-[var(--sidebar-active-bg)] hover:bg-[var(--sidebar-active-bg)]":t.key===l}),onClick:()=>Be(t.key),children:[e(t.icon,{size:16,className:"ml-2"}),e("span",{className:"ml-2",children:t.label})]},t.key))}),e(rt,{children:e("div",{className:"scrollbars",style:{position:"relative",overflow:"hidden",width:"100%",height:"100%"},children:e("div",{ref:N,style:{position:"absolute",inset:0,overflow:"scroll"},children:m("div",{className:"createrContentInner",children:[e("div",{"data-category-id":"all"}),m("div",{className:"openBtns flex",children:[m(xe,{onClick:()=>{let t=document.createElement("input");t.type="file",t.accept="image/*",t.onchange=async()=>{let i=t.files?.[0];if(i)try{g.loading("\u6B63\u5728\u4E0A\u4F20...",0);let w=ae(),D=new FormData;D.append("file",i);let oe=await W.post(w.url,D,{headers:{"Content-Type":"multipart/form-data"}});console.log("res",oe);let{url:ie,width:ne,height:se}=oe.result;console.log("url",ie,ne,se);let Me=encodeURIComponent(encodeURIComponent(ie)),Re=new URLSearchParams({createEmptyPoster:"true",width:String(ne),height:String(se),unit:"px"});g.destroy();let De=`${n.urls.editorUrl}/?${Re.toString()}&open=${Me}`,re=window.open(De,"_blank");(!re||re.closed)&&v.info({title:"\u5141\u8BB8\u663E\u793A\u5F39\u51FA\u7A97\u53E3",width:480,content:m("div",{style:{padding:"16px 0"},children:[e("p",{style:{marginBottom:8,color:"#666"},children:"\u4F60\u9700\u8981\u6388\u6743\u672C\u7AD9\u5728\u6D4F\u89C8\u5668\u6253\u5F00\u591A\u4E2A\u7A97\u53E3\u3002"}),m("div",{style:{marginBottom:12},children:[e("p",{children:e("b",{children:"\u7B2C1\u6B65"})}),e("p",{children:"\u70B9\u51FB\u6D4F\u89C8\u5668\u53F3\u4FA7\u9876\u90E8\u5F39\u51FA\u7684\u963B\u6B62\u7A0B\u5E8F\u56FE\u6807\u3002"})]}),m("div",{style:{marginBottom:12},children:[e("p",{children:e("b",{children:"\u7B2C2\u6B65"})}),e("p",{children:"\u70B9\u51FB\u59CB\u7EC8\u5141\u8BB8\u663E\u793A\u5F39\u51FA\u5F0F\u7A97\u53E3\u548C\u8FDB\u884C\u91CD\u5B9A\u5411\u3002"})]}),m("div",{style:{marginBottom:12},children:[e("p",{children:e("b",{children:"\u7B2C3\u6B65"})}),e("p",{children:"\u70B9\u51FB\u5B8C\u6210\u6309\u94AE\uFF0C\u5373\u53EF\u6B63\u5E38\u4F7F\u7528\u529F\u80FD\u5566~"})]})]}),okText:"\u6211\u77E5\u9053\u5566"})}catch(w){g.destroy();let D=w?.message||"\u4E0A\u4F20\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5";g.error(D),console.error("\u4E0A\u4F20\u5931\u8D25:",D,w)}},t.click()},children:[e(tt,{style:{color:p.colorPrimary}}),e("span",{children:"\u6253\u5F00\u56FE\u7247"})]}),e(he,{title:"\u4EC5\u652F\u6301psd\u683C\u5F0F\u6587\u4EF6",children:m(xe,{style:{marginLeft:12},onClick:()=>{R(!0),console.log("\u70B9\u51FB")},children:[e(o,{style:{color:p.colorPrimary}}),e("span",{children:"\u6253\u5F00PSD"})]})})]}),fe.map(t=>m("div",{className:H("Widget categorySection","mt-6"),"data-category-id":t.key,"data-is-folded":Ue[t.key]??!1,"data-is-multi-row":t.sizes.length>6,children:[m("div",{className:H("categoryHeader","flex items-center justify-between"),children:[e("div",{className:"categoryTitle text-sm font-semibold",children:t.label}),e("div",{className:"categoryFoldBtn flex items-center cursor-pointer",onClick:()=>Le(i=>({...i,[t.key]:!1})),children:e("span",{className:"text-[#616366]",children:"\u67E5\u770B\u66F4\u591A"})})]}),t.key==="common"&&m(lt,{children:[te&&e("div",{className:"sizeWarning",children:te}),m("div",{className:"Widget sizeInpueBox",children:[e("div",{className:"sizeInput",children:e(ge,{prefix:"\u5BBD",value:r,min:0,precision:0,status:A||F?"error":void 0,onChange:Se,styles:{actions:{opacity:1,width:24}},style:{width:"100%"}})}),e(he,{title:y?"\u89E3\u9501\u6BD4\u4F8B":"\u9501\u5B9A\u6BD4\u4F8B",children:e("div",{className:"linkIcon",style:{cursor:"pointer"},onClick:Ne,children:y?e(it,{size:16}):e(ot,{size:16})})}),e("div",{className:"sizeInput",children:e(ge,{prefix:"\u9AD8",value:c,min:0,precision:0,status:A||F?"error":void 0,onChange:Pe,styles:{actions:{opacity:1,width:24}},style:{width:"100%"}})}),e("div",{className:"sizeUnitSelect",style:{width:98,marginLeft:12},children:e(je,{value:h,style:{width:98},onChange:Te,options:[{label:"px \u50CF\u7D20",value:"px"},{label:"cm \u5398\u7C73",value:"cm"},{label:"mm \u6BEB\u7C73",value:"mm"}]})})]}),e("div",{className:"widgets-color-picker",style:{width:98,marginLeft:12},children:e(He,{mode:"single",format:"hex",value:S,onChange:i=>I(i.toHexString()),styles:{root:{width:98},body:{width:92}}})}),e(Ke,{type:"primary",disabled:Y,style:{width:98,marginLeft:12},onClick:Ie,children:"\u521B\u5EFA"})]}),e("ul",{className:"flex mt-4 flex-wrap gap-3",children:t.sizes.map((i,w)=>e("li",{style:{width:"calc((100% - 60px) / 6)",height:97},children:m(at,{children:[i.icon,e("div",{className:"canvasSizeName",children:i.name}),e("div",{className:"canvasSizeSize",children:e("span",{children:i.desc})}),e("div",{className:"canvasSizeMask",onClick:()=>{b({...i,bgColor:S})},children:e("button",{type:"button",children:"\u521B\u5EFA"})})]})},w))})]},t.key))]})})})})]}),e(me,{visible:J,onClose:()=>R(!1)})]})};import{Fragment as bt,jsx as z,jsxs as vt}from"react/jsx-runtime";var{confirm:yt}=mt,ve=xt(({store:n,project:s})=>{let[u,b]=ft(!1),g=[{label:P("topbar.newDesign"),key:"new_design",icon:z(ht,{size:16})},{label:P("topbar.language"),key:"language",icon:z("div",{style:{height:22,display:"flex",alignItems:"center"},children:z(ut,{size:16})}),children:[{key:"en",label:"English",onClick:()=>{s.setLanguage("en")},extra:s.language==="en"?z(be,{size:16}):null},{key:"zh",label:"\u4E2D\u6587",onClick:()=>{s.setLanguage("zh")},extra:s.language==="zh"?z(be,{size:16}):null}]}];return vt(bt,{children:[z(dt,{menu:{items:g,onClick:({key:l})=>{l==="new_design"&&b(!0)}},trigger:["click"],styles:{root:{width:188}},children:z(pt,{type:"text",children:z(gt,{size:16})})}),z(ye,{visible:u,onClose:()=>b(!1),onConfirm:l=>{yt({title:"\u521B\u5EFA\u8BBE\u8BA1\u540E\uFF0C\u5C06\u65B0\u5EFA\u753B\u5E03\uFF0C\u5F53\u524D\u6D77\u62A5\u5185\u5BB9\u53EF\u5728\u4F5C\u56FE\u8BB0\u5F55\u4E2D\u67E5\u770B\u3002",okText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",onOk(){console.log("OK"),console.log("size ---> ",l);let M=JSON.stringify({bg:{backgroundColor:l.bgColor}}),N=new URLSearchParams({create:"",createEmptyPoster:"true",createInfo:M,height:String(l.height),unit:l.unit,width:String(l.width)});console.log("params \u7684\u53C2\u6570 ---> ",N.toString()),console.log("\u9700\u8981\u8DF3\u8F6C\u7684\u7F16\u8F91\u5668\u5730\u5740",s.urls.editorUrl),window.open(`${s.urls.editorUrl}?${N.toString()}`,"_blank")}})},store:n,project:s})]})});import{Input as wt,Tooltip as kt,Button as zt,theme as Ct,Divider as St}from"antd";import{CloudUpload as ke,Loader as Pt,Check as Nt}from"lucide-react";var we="https://pub-d7c4dca6f69c4b329766184b707dc826.r2.dev/images/2026-03-17/e406e8b1-eb6d-4d8a-8c22-ddd100a0a40e/1b04fb1b-7275-4123-b495-d205197c21d4/ddc303f2-0cda-4d34-9864-76df19a9e7d6.png";import{jsx as a,jsxs as ee}from"react/jsx-runtime";var Tt=X("div")`
1
+ import{a as x}from"../chunk-3UOBPTKL.js";import{c as u}from"../chunk-OV7AL42Z.js";import"../chunk-C4XMVZO4.js";import"../chunk-YBC2DYJX.js";import"../chunk-EWOU5F3O.js";import{b as g}from"../chunk-5C2MNUBC.js";import"../chunk-3PMUQSBH.js";import{a as h}from"../chunk-AMEXYVS6.js";import{c as n}from"../chunk-Q7N7SBSC.js";import"../chunk-O2XFH626.js";import d from"styled-components";import{observer as C}from"mobx-react-lite";import{Dropdown as T,Button as S,Modal as L}from"antd";import{Menu as N,Plus as P,Languages as z,Check as b}from"lucide-react";import{useState as I}from"react";import{observer as B}from"mobx-react-lite";import{Fragment as K,jsx as a,jsxs as M}from"react/jsx-runtime";var{confirm:D}=L,v=B(({store:o,project:t})=>{let[l,i]=I(!1),s=[{label:n("topbar.newDesign"),key:"new_design",icon:a(P,{size:16})},{label:n("topbar.language"),key:"language",icon:a("div",{style:{height:22,display:"flex",alignItems:"center"},children:a(z,{size:16})}),children:[{key:"en",label:"English",onClick:()=>{t.setLanguage("en")},extra:t.language==="en"?a(b,{size:16}):null},{key:"zh",label:"\u4E2D\u6587",onClick:()=>{t.setLanguage("zh")},extra:t.language==="zh"?a(b,{size:16}):null}]}];return M(K,{children:[a(T,{menu:{items:s,onClick:({key:r})=>{r==="new_design"&&i(!0)}},trigger:["click"],styles:{root:{width:188}},children:a(S,{type:"text",children:a(N,{size:16})})}),a(x,{visible:l,onClose:()=>i(!1),onConfirm:r=>{D({title:"\u521B\u5EFA\u8BBE\u8BA1\u540E\uFF0C\u5C06\u65B0\u5EFA\u753B\u5E03\uFF0C\u5F53\u524D\u6D77\u62A5\u5185\u5BB9\u53EF\u5728\u4F5C\u56FE\u8BB0\u5F55\u4E2D\u67E5\u770B\u3002",okText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",onOk(){console.log("OK"),console.log("size ---> ",r);let c=JSON.stringify({bg:{backgroundColor:r.bgColor}}),y=new URLSearchParams({create:"",createEmptyPoster:"true",createInfo:c,height:String(r.height),unit:r.unit,width:String(r.width)});console.log("params \u7684\u53C2\u6570 ---> ",y.toString()),console.log("\u9700\u8981\u8DF3\u8F6C\u7684\u7F16\u8F91\u5668\u5730\u5740",t.urls.editorUrl),window.open(`${t.urls.editorUrl}?${y.toString()}`,"_blank")}})},store:o,project:t})]})});import{Input as O,Tooltip as R,Button as U,theme as _,Divider as E}from"antd";import{CloudUpload as m,Loader as F,Check as $}from"lucide-react";var w="https://pub-d7c4dca6f69c4b329766184b707dc826.r2.dev/images/2026-03-20/90d9e12a-edaa-447b-9ac2-6fdd7ec6397c/97900353-048f-4792-91bd-bdcd2d751d3b/e03bc692-c918-4fd5-bb0b-d3d93eb012a3.png";import{jsx as e,jsxs as f}from"react/jsx-runtime";var j=d("div")`
152
2
  white-space: nowrap;
153
3
  height: 55px;
154
4
  padding: 0 15px;
@@ -161,18 +11,18 @@ import{a as de}from"../chunk-RBRSKAZL.js";import{a as W,c as K}from"../chunk-2AZ
161
11
  overflow-y: hidden;
162
12
  max-width: 100vw;
163
13
  }
164
- `,It=X("div")`
14
+ `,A=d("div")`
165
15
  @media screen and (max-width: 500px) {
166
16
  display: flex;
167
17
  }
168
- `,Bt=X("div")`
18
+ `,G=d("div")`
169
19
  float: left;
170
20
  display: flex;
171
21
  align-items: center;
172
22
  height: 55px;
173
- `,Ut=X("div")`
23
+ `,H=d("div")`
174
24
  float: right;
175
25
  display: flex;
176
26
  align-items: center;
177
27
  height: 55px;
178
- `,ze={loading:{icon:a(ke,{size:16,style:{display:"flex"}}),textKey:"topbar.statusLoading"},saved:{icon:a(Nt,{size:16,style:{display:"flex",color:"#52c41a"}}),textKey:"topbar.statusSaved",color:"#52c41a"},"has-changes":{icon:a(ke,{size:16,style:{display:"flex",color:"#faad14"}}),textKey:"topbar.statusHasChanges",color:"#faad14"},saving:{icon:a(Pt,{size:16,style:{display:"flex"}}),textKey:"topbar.statusSaving"}},Lt=Ce(({project:n})=>{let s=ze[n.status]||ze.saved;return a(kt,{title:P(s.textKey),children:a(zt,{type:"text",style:{marginLeft:14,color:s.color},icon:s.icon,onClick:()=>{(n.status==="loading"||n.status==="saved")&&n.save()},children:P(s.textKey)})})}),yo=Ce(({store:n,logo:s,logoUrl:u})=>{let b=K(),{token:g}=Ct.useToken(),v=s===void 0?a("img",{src:we,className:"h-[28px]"}):typeof s=="string"?a("img",{src:s,className:"h-[28px]"}):s,l=u?a("a",{href:u,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center"},children:v}):a("div",{style:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>window.history.back(),children:v});return a(Tt,{className:"topbar",style:{backgroundColor:g.colorBgContainer,color:g.colorText,borderBottom:`1px solid ${g.colorBorder}`},children:ee(It,{children:[ee(Bt,{children:[a("div",{style:{display:"flex",alignItems:"center"},children:l}),a(St,{orientation:"vertical",style:{height:"1.3em",borderColor:"#ebe6e7",marginLeft:15}}),a(ve,{store:n,project:b}),a("div",{style:{paddingLeft:10,maxWidth:200},children:a(wt,{placeholder:P("topbar.editableTextPlaceholder")})}),ee("div",{style:{paddingLeft:16,fontSize:14},className:"text-gray-600",children:[U({px:n.width,unit:n.unit,dpi:n.dpi,precious:0})," x"," ",U({px:n.height,unit:n.unit,dpi:n.dpi,precious:0})," ",n.unit]}),a(Lt,{project:b})]}),a(Ut,{children:a(de,{store:n})})]})})});export{yo as Topbar};
28
+ `,k={loading:{icon:e(m,{size:16,style:{display:"flex"}}),textKey:"topbar.statusLoading"},save:{icon:e(m,{size:16,style:{display:"flex"}}),textKey:"topbar.statusSave"},saved:{icon:e($,{size:16,style:{display:"flex",color:"#52c41a"}}),textKey:"topbar.statusSaved",color:"#52c41a"},"has-changes":{icon:e(m,{size:16,style:{display:"flex",color:"#faad14"}}),textKey:"topbar.statusHasChanges",color:"#faad14"},saving:{icon:e(F,{size:16,style:{display:"flex"}}),textKey:"topbar.statusSaving"}},J=C(({project:o})=>{let t=k[o.status]||k.saved;return e(R,{title:n(t.textKey),children:e(U,{type:"text",style:{marginLeft:14,color:t.color},icon:t.icon,onClick:()=>{(o.status==="save"||o.status==="saved")&&o.save()},children:n(t.textKey)})})}),ge=C(({store:o,logo:t,logoUrl:l})=>{let i=u(),{token:s}=_.useToken(),p=t===void 0?e("img",{src:w,className:"h-[28px]"}):typeof t=="string"?e("img",{src:t,className:"h-[28px]"}):t,r=l?e("a",{href:l,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center"},children:p}):e("div",{style:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>window.history.back(),children:p});return e(j,{className:"topbar",style:{backgroundColor:s.colorBgContainer,color:s.colorText,borderBottom:`1px solid ${s.colorBorder}`},children:f(A,{children:[f(G,{children:[e("div",{style:{display:"flex",alignItems:"center"},children:r}),e(E,{orientation:"vertical",style:{height:"1.3em",borderColor:"#ebe6e7",marginLeft:15}}),e(v,{store:o,project:i}),e("div",{style:{paddingLeft:10,maxWidth:200},children:e(O,{value:i.name,placeholder:n("topbar.editableTextPlaceholder"),onChange:c=>i.name=c.target.value})}),f("div",{style:{paddingLeft:16,fontSize:14},className:"text-gray-600",children:[g({px:o.width,unit:o.unit,dpi:o.dpi,precious:0})," x"," ",g({px:o.height,unit:o.unit,dpi:o.dpi,precious:0})," ",o.unit]}),e(J,{project:i})]}),e(H,{children:e(h,{store:o})})]})})});export{ge as Topbar};
@@ -0,0 +1,228 @@
1
+ /**
2
+ * 设置/更新翻译
3
+ * @param {object} newTranslations - 新的翻译对象
4
+ * @param {object} options - 配置选项
5
+ * @param {boolean} options.validate - 是否验证翻译完整性
6
+ */
7
+ declare const setTranslations: (newTranslations: any, { validate }?: {
8
+ validate?: boolean | undefined;
9
+ }) => void;
10
+ /**
11
+ * 获取所有翻译(返回普通 JS 对象)
12
+ * @returns {object}
13
+ */
14
+ declare const getTranslations: () => {
15
+ toolbar: {
16
+ undo: string;
17
+ redo: string;
18
+ duration: string;
19
+ opacity: string;
20
+ effects: string;
21
+ blur: string;
22
+ textBackground: string;
23
+ backgroundCornerRadius: string;
24
+ backgroundOpacity: string;
25
+ backgroundPadding: string;
26
+ backgroundColor: string;
27
+ brightness: string;
28
+ filters: string;
29
+ sepia: string;
30
+ grayscale: string;
31
+ contrast: string;
32
+ saturation: string;
33
+ vibrance: string;
34
+ hueRotation: string;
35
+ noise: string;
36
+ pixelate: string;
37
+ textStroke: string;
38
+ shadow: string;
39
+ border: string;
40
+ cornerRadius: string;
41
+ textleft: string;
42
+ textcenter: string;
43
+ textright: string;
44
+ textjustify: string;
45
+ textBold: string;
46
+ textItalic: string;
47
+ textUnderline: string;
48
+ textStrikethrough: string;
49
+ splitByGrapheme: string;
50
+ position: string;
51
+ layering: string;
52
+ toForward: string;
53
+ up: string;
54
+ down: string;
55
+ toBottom: string;
56
+ alignLeft: string;
57
+ alignCenter: string;
58
+ alignRight: string;
59
+ alignTop: string;
60
+ alignMiddle: string;
61
+ alignBottom: string;
62
+ flip: string;
63
+ flipHorizontally: string;
64
+ flipVertically: string;
65
+ fitToBackground: string;
66
+ removeBackground: string;
67
+ removeBackgroundTitle: string;
68
+ cancelRemoveBackground: string;
69
+ confirmRemoveBackground: string;
70
+ eraserPen: string;
71
+ eraserPenTitle: string;
72
+ cancelEraserPen: string;
73
+ confirmEraserPen: string;
74
+ crop: string;
75
+ cropDone: string;
76
+ cropCancel: string;
77
+ clip: string;
78
+ removeClip: string;
79
+ removeMask: string;
80
+ transparency: string;
81
+ lockedDescription: string;
82
+ unlockedDescription: string;
83
+ removeElements: string;
84
+ duplicateElements: string;
85
+ download: string;
86
+ saveAsImage: string;
87
+ saveAsPDF: string;
88
+ lineHeight: string;
89
+ letterSpacing: string;
90
+ offsetX: string;
91
+ offsetY: string;
92
+ color: string;
93
+ selectable: string;
94
+ draggable: string;
95
+ removable: string;
96
+ resizable: string;
97
+ contentEditable: string;
98
+ styleEditable: string;
99
+ alwaysOnTop: string;
100
+ showInExport: string;
101
+ ungroupElements: string;
102
+ groupElements: string;
103
+ lineSize: string;
104
+ fade: string;
105
+ move: string;
106
+ zoom: string;
107
+ rotate: string;
108
+ none: string;
109
+ bounce: string;
110
+ blink: string;
111
+ strength: string;
112
+ spaceEvenly: string;
113
+ horizontalDistribution: string;
114
+ verticalDistribution: string;
115
+ strokeWidth: string;
116
+ strokeSettings: string;
117
+ colorPicker: {
118
+ solid: string;
119
+ linear: string;
120
+ angle: string;
121
+ };
122
+ aiText: {
123
+ aiWrite: string;
124
+ rewrite: string;
125
+ shorten: string;
126
+ continue: string;
127
+ proofread: string;
128
+ tones: string;
129
+ friendly: string;
130
+ professional: string;
131
+ humorous: string;
132
+ formal: string;
133
+ customPrompt: string;
134
+ generatedResult: string;
135
+ cancel: string;
136
+ generate: string;
137
+ back: string;
138
+ tryAgain: string;
139
+ insert: string;
140
+ promptPlaceholder: string;
141
+ };
142
+ addImage: string;
143
+ addText: string;
144
+ fileType: string;
145
+ quality: string;
146
+ multiplier: string;
147
+ size: string;
148
+ };
149
+ workspace: {
150
+ noPages: string;
151
+ addPage: string;
152
+ removePage: string;
153
+ duplicatePage: string;
154
+ moveUp: string;
155
+ moveDown: string;
156
+ };
157
+ scale: {
158
+ reset: string;
159
+ };
160
+ error: {
161
+ removeBackground: string;
162
+ };
163
+ sidePanel: {
164
+ templates: string;
165
+ searchTemplatesWithSameSize: string;
166
+ searchPlaceholder: string;
167
+ otherFormats: string;
168
+ noResults: string;
169
+ error: string;
170
+ text: string;
171
+ uploadFont: string;
172
+ myFonts: string;
173
+ photos: string;
174
+ videos: string;
175
+ animations: string;
176
+ effects: string;
177
+ elements: string;
178
+ shapes: string;
179
+ lines: string;
180
+ upload: string;
181
+ uploadImage: string;
182
+ uploadTip: string;
183
+ background: string;
184
+ resize: string;
185
+ layers: string;
186
+ layerTypes: {
187
+ image: string;
188
+ text: string;
189
+ svg: string;
190
+ line: string;
191
+ figure: string;
192
+ group: string;
193
+ };
194
+ layersTip: string;
195
+ noLayers: string;
196
+ namePlaceholder: string;
197
+ useMagicResize: string;
198
+ clipImage: string;
199
+ width: string;
200
+ height: string;
201
+ magicResizeDescription: string;
202
+ headerText: string;
203
+ createHeader: string;
204
+ subHeaderText: string;
205
+ createSubHeader: string;
206
+ bodyText: string;
207
+ createBody: string;
208
+ units: string;
209
+ };
210
+ topbar: {
211
+ newDesign: string;
212
+ language: string;
213
+ editableTextPlaceholder: string;
214
+ statusLoading: string;
215
+ statusSave: string;
216
+ statusSaved: string;
217
+ statusHasChanges: string;
218
+ statusSaving: string;
219
+ };
220
+ };
221
+ /**
222
+ * 获取翻译文本
223
+ * @param {string} key - 翻译键,如 'toolbar.opacity'
224
+ * @returns {string} 翻译文本,如果不存在则返回格式化后的键名
225
+ */
226
+ declare const translate: (key: string) => string;
227
+
228
+ export { getTranslations, setTranslations, translate };
@@ -0,0 +1 @@
1
+ import{a,b,c}from"../chunk-Q7N7SBSC.js";import"../chunk-O2XFH626.js";export{b as getTranslations,a as setTranslations,c as translate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ydesign/react-editor",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "设计编辑器UI组件库,基于react版本",
5
5
  "main": "dist/app.js",
6
6
  "module": "dist/app.js",
@@ -120,7 +120,7 @@
120
120
  "tailwind-merge": "^3.3.1",
121
121
  "tailwindcss": "^4.1.17",
122
122
  "tw-animate-css": "^1.4.0",
123
- "@ydesign/core": "^0.0.9"
123
+ "@ydesign/core": "^0.1.0"
124
124
  },
125
125
  "browserslist": [
126
126
  "> 0.5%",
@@ -1 +0,0 @@
1
- import{d as g}from"./chunk-KERQXVBL.js";import{b as m}from"./chunk-YBC2DYJX.js";import{c as l,d as p}from"./chunk-EUTDQZKU.js";import{a as s}from"./chunk-O2XFH626.js";import*as d from"mobx";import{createContext as f,useContext as y}from"react";import h from"axios";var i=h.create({timeout:6e4});i.interceptors.request.use(t=>{let e=g();return e.token&&(t.headers.Authorization=`Bearer ${e.token}`,t.headers["yitu-workspace-id"]=e.workspaceId),t},t=>Promise.reject(t));i.interceptors.response.use(t=>{let{data:e}=t,r=e?.statusCode??e?.status;if(r!=null){if(r>=200&&r<=201)return e;let n=e?.result?.message||e?.message||"An error occurred";return Promise.reject(new Error(n))}if(t.status>=200&&t.status<300&&e)return e;let o=new Error(e?.message||"An error occurred");return Promise.reject(o)},t=>{let e=t?.response?.data,r=e?.result?.message||e?.message||t.message||"An error occurred";return Promise.reject(new Error(r))});var c=i;var w=t=>{try{return localStorage.getItem(t)}catch{return null}},P=(t,e)=>{try{localStorage.setItem(t,e)}catch{}},u=class{constructor({store:e}){s(this,"saveTimeout",null);s(this,"isOne",!1);s(this,"store");s(this,"id","");s(this,"name","");s(this,"user",{});s(this,"skipSaving",!1);s(this,"cloudEnabled",!1);s(this,"status","loading");s(this,"language",w("ydesign-language")||navigator.language||"en");s(this,"designsLength",0);s(this,"urls",{editorUrl:"/design"});d.makeAutoObservable(this),this.store=e,e.on("change",()=>{if(!this.isOne){this.isOne=!0;return}this.requestSave()})}setLanguage(e){this.language=e,P("ydesign-language",e)}requestSave(){this.status="has-changes",!this.saveTimeout&&(this.saveTimeout=setTimeout(()=>{this.saveTimeout=null,this.save()},5e3))}async firstLoad(e){if(e)this.store.loadJSON(e);else{let r=new URL(window.location.href),o=new URLSearchParams(r.search),n=o.get("type")||"",a=o.get("id")||"";console.log("\u6765\u6E90 ---> ",n,a),this.loadById(a,n)}}async loadById(e,r){if(e){if(console.log("\u53BB\u8FDC\u7A0B\u83B7\u53D6\u6570\u636E"),r==="me"){let o=l(e),n=await c.post(o.url,o.data),{content:a}=n.result;console.log("\u4E2A\u4EBA\u8D44\u4EA7 ---> ",a),this.store.loadJSON(a);return}if(r==="record"){let o=p(e),n=await c.get(o.url),{content:a}=n.result;console.log("\u4F5C\u56FE\u8BB0\u5F55 ---> ",a),this.store.loadJSON(a);return}console.log("\u6CA1\u6709\u5339\u914D\u5230\u7684\u6765\u6E90")}else console.log("\u6CA1\u6709id\u65E0\u6CD5\u83B7\u53D6\u8FDC\u7A0B\u6570\u636E")}updateUrlWithProjectId(){if(!this.id||this.id==="local"){window.history.replaceState({},"","/");return}let e=new URL(window.location.href);new URLSearchParams(e.search).set("id",this.id),window.history.replaceState({},"",`/design/${this.id}`)}async save(){this.status="saving";let e=this.store.toJSON();console.log("storeJSON",e);try{await new Promise(r=>setTimeout(r,2e3))}catch(r){console.error("save error",r)}this.status="saved"}async getGlobalFont(e){return e?.length?(m(e),e):[]}},S=f(null),R=()=>{let t=y(S);if(!t)throw new Error("useProject must be used within a ProjectProvider");return t},T=t=>new u(t),N=T;export{c as a,S as b,R as c,T as d,N as e};
@@ -1 +0,0 @@
1
- var s="http://219.151.185.37:9003",a=`${s}/api`,e=()=>s+"/api",r={fontList:()=>({url:`${e()}/fonts`}),templateList:()=>({url:`${e()}/templates/list`}),templateDetail:t=>({url:`${e()}/templates/detail/${t}`}),uploadImage:()=>({url:`${e()}/images/upload`}),psdParse:()=>({url:`${e()}/psd/parser`}),createRecord:t=>({method:"POST",url:`${e()}/record`,data:t}),recordDetail:t=>({url:`${e()}/record/${t}`}),resourcesDetail:t=>({method:"POST",url:`${e()}/resources/detail`,data:{type:"template",id:t}})};var n=()=>r.uploadImage(),l=()=>r.psdParse(),p=t=>r.resourcesDetail(t),i=t=>r.recordDetail(t),c=t=>r.createRecord(t),u=(t,o)=>{r[t]=o};export{n as a,l as b,p as c,i as d,c as e,u as f};
@@ -1 +0,0 @@
1
- import{a as l,c as g,d as m,e as p}from"./chunk-YBC2DYJX.js";import{types as a,cast as b,flow as f,destroy as h,getSnapshot as E,onSnapshot as x}from"mobx-state-tree";async function u(e,t){let o=document.createElement("a"),i=URL.createObjectURL(e);o.href=i,o.download=t,document.body.appendChild(o),o.click(),setTimeout(function(){document.body.removeChild(o),window.URL.revokeObjectURL(i)},0)}import{observable as j,toJS as S}from"mobx";import{isEqual as F}from"es-toolkit/compat";var s=(e,t)=>{if(e?.objects)for(let o of e.objects){if(t(o)===!0)break;s(o,t)}},k=a.model("Font",{fontFamily:a.string,name:a.optional(a.string,""),url:a.optional(a.string,""),img:a.optional(a.string,""),styles:a.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),O=a.model("Store",{name:"yitu-design",token:"",workspaceId:"",width:1080,height:1080,scale:1,scaleToFit:1,unit:"px",dpi:72,bleed:0,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:a.array(a.string),backgroundColor:a.optional(a.union(a.string,a.frozen()),"#fff"),fonts:a.array(k),editor:a.frozen(null),custom:a.frozen(),objects:a.array(a.frozen()),_key:"",_updateTrigger:0,_updateFontSize:0}).views(e=>({get selectedElements(){let t=e._updateTrigger;return console.log("_trigger\u90FD\u53D8\u5316\u662F\u89E6\u53D1\u805A\u7126\u5143\u7D20\u7684\u5237\u65B0 ---> ",t),e.selectedElementsIds.map(o=>e.editor?.objectsHandler.findOneById(o))}})).views(e=>({get selectedShapes(){let t=[];return s({objects:e.selectedElements},o=>{o?.type!=="group"&&t.push(o)}),t},find(t){let o,i=e.editor?.customCanvas.canvas.getObjects();if(i)return s({objects:i},r=>{if(!o&&t(r))return o=r,!0}),o},getElementById(t){return e.editor?.objectsHandler.findOneById(t)}})).actions(e=>({_setEditor(t){e.editor=t},_triggerUpdate(){e._updateTrigger=e._updateTrigger+1},_fontSizeUpdate(){e._updateFontSize=e._updateFontSize+1},_syncBackgroundColor(t){e.backgroundColor=t}})).actions(e=>({setBackgroundColor(t,o){e.backgroundColor=t,e.editor?.workareaHandler.setWorkareaBgColor(t,o)},set(t,o){e.editor?.objectsHandler.update(t,o?.id)},setUnit({unit:t,dpi:o}){e.unit=t||e.unit,e.dpi=o||e.dpi},setObjects(t){e.objects=t},selectElements(t){e.selectedElementsIds=b(t)},openSidePanel(t){e.openedSidePanel!==t&&(e.openedSidePanel=t)},deleteElements(t){t.forEach(o=>{e.editor?.objectsHandler.remove(o)})},setScale(t){e.scale=t},clone(){e.editor?.objectsHandler.clone()},addElement(t,o){return console.log("\u6DFB\u52A0json\u6570\u636E",t),e.editor?.objectsHandler.addJson(t,o)},setSize({width:t,height:o}){e.width=t,e.height=o,e.editor?.workareaHandler.setSize({width:t,height:o})},setupEditorListeners(){e.editor&&(e.editor.on("object:modified",()=>{e._triggerUpdate()}),e.editor.on("textbox:modified",()=>{e._fontSizeUpdate()}),e.editor.on("history:changed",t=>{t?.backgroundColor!==void 0&&e._syncBackgroundColor(t.backgroundColor)}))}})).actions(e=>({_forEachElementUp(t,o){if(!e.editor)return;let i=e.editor.layerHandler.getEffectiveLayers(),r=t.map(n=>({id:n,index:i.findIndex(d=>d.id===n)}));r.sort((n,d)=>d.index-n.index);for(let{index:n}of r){if(n==-1)continue;let d=n<i.length-1&&i[n+1],c=t.indexOf(d?.id)>=0;n===i.length-1||c||o(n)}},_forEachElementDown(t,o){if(!e.editor)return;let i=e.editor.layerHandler.getEffectiveLayers(),r=t.map(n=>({id:n,index:i.findIndex(d=>d.id===n)}));r.sort((n,d)=>d.index-n.index);for(let{index:n}of r){if(n==-1)continue;let d=n>0&&i[n-1],c=t.indexOf(d?.id)>=0;n===0||c||o(n)}return!1}})).actions(e=>({canMoveElementsUp(t){let o=!1;return e._forEachElementUp(t,()=>{o=!0}),o},moveElementsUp(t){if(!e.editor)return;let o=e.editor.layerHandler.getEffectiveLayers();[...t].map(r=>({id:r,index:o.findIndex(n=>n.id===r)})).filter(r=>r.index!==-1).sort((r,n)=>n.index-r.index).map(r=>r.id).forEach(r=>{e.editor?.layerHandler.bringForward(r)}),e._triggerUpdate()},canMoveElementsTop(t){return this.canMoveElementsUp(t)},moveElementsTop(t){e.editor&&(t.forEach(o=>{e.editor?.layerHandler.bringToFront(o)}),e._triggerUpdate())},canMoveElementsDown(t){let o=!1;return e._forEachElementDown(t,()=>{o=!0}),o},moveElementsDown(t){if(!e.editor)return;let o=e.editor.layerHandler.getEffectiveLayers();[...t].map(r=>({id:r,index:o.findIndex(n=>n.id===r)})).filter(r=>r.index!==-1).sort((r,n)=>r.index-n.index).map(r=>r.id).forEach(r=>{e.editor?.layerHandler.sendBackwards(r)}),e._triggerUpdate()},canMoveElementsBottom(t){return this.canMoveElementsDown(t)},moveElementsBottom(t){e.editor&&(t.forEach(o=>{e.editor?.layerHandler.sendToBack(o)}),e._triggerUpdate())},setElementZIndex(){}})).actions(e=>({async toDataURL(t){return e.editor?.rendererHandler.toDataURL(t)},async toBlob(t){return e.editor?.rendererHandler.toBlob(t)},async saveAsImage(t){if(!e.editor)return;let{fileName:o,...i}=t||{multiplier:1},r=await e.editor.rendererHandler.toBlob(i);r&&u(r,o||"yitu."+i.format)},toJSON(){return e.editor?.rendererHandler.toJSON()},toObject(){return e.editor?.rendererHandler.toObject()},loadJSON:f(function*(t){if(!e.editor)return;let o=yield e.editor.sceneHandler.importFromJSON(t);o&&(e.width=o.width,e.height=o.height,e.backgroundColor=o.fill)}),clear(){}})).actions(e=>({removeFont(t){e.fonts.filter(o=>o.fontFamily===t).forEach(o=>{h(o)})},addFont(t){this.removeFont(t.fontFamily),e.fonts.push(t),this.loadFont(t.fontFamily)},async loadFont(t){let o=e.fonts.find(n=>n.fontFamily===t)||l.find(n=>n.fontFamily===t),r=[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return o?(o.styles&&(r=o.styles.map(n=>({fontStyle:n.fontStyle||"normal",fontWeight:n.fontWeight||"normal"}))),m(o)):p(t),Promise.all(r.map(n=>g(t,n.fontStyle,n.fontWeight)))}})).actions(e=>({on(t,o){if(t==="change"){let i=E(e.objects);return x(e.objects,r=>{let n=r;F(i,n)||(i=n,o(n))})}}})),y=j({token:"",workspaceId:""}),T=()=>S(y);function w({key:e,token:t,workspaceId:o}){return y={token:t??"",workspaceId:o??""},O.create({_key:e,token:t??"",workspaceId:o??""})}var z=w;export{s as a,k as b,O as c,T as d,w as e,z as f};