@printine/pod-editor 0.1.20 → 0.1.23

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.
@@ -0,0 +1,261 @@
1
+ import { create as h } from "zustand";
2
+ import { HistoryManager as g } from "./engine/history.js";
3
+ import { loadFontFile as b } from "./engine/utils/font.js";
4
+ import { FONT_WEIGHT as v, LAYER_BLACK_LIST as S } from "./engine/constants.js";
5
+ let f = null;
6
+ function z(e) {
7
+ f = e;
8
+ }
9
+ function m() {
10
+ if (!f)
11
+ throw new Error(
12
+ "[printine-designer] Editor asset API client is not ready. Render <PrintineDesigner /> before calling the API."
13
+ );
14
+ return f;
15
+ }
16
+ function l(e) {
17
+ return typeof e == "string" ? e : "";
18
+ }
19
+ function d(e, s) {
20
+ return {
21
+ data: e,
22
+ meta: {
23
+ current_page: s?.page ?? 1,
24
+ last_page: s?.total_pages ?? 1,
25
+ total: s?.total ?? e.length
26
+ }
27
+ };
28
+ }
29
+ function x(e) {
30
+ const s = [];
31
+ for (const t of e) {
32
+ const n = [];
33
+ for (const i of t.variants ?? []) {
34
+ const r = typeof i.weight == "number" ? i.weight : 400, a = i.style === "italic" ? "italic" : "normal", c = `${r}${a === "normal" ? "" : "italic"}`, p = l(i.url);
35
+ p && n.push({
36
+ style: a,
37
+ variant: c,
38
+ weight: r,
39
+ label: v[c] || `${r}`,
40
+ url: p
41
+ });
42
+ }
43
+ const o = l(t.name);
44
+ !o || !n.length || s.push({
45
+ category: "",
46
+ family: o,
47
+ variants: [...new Set(n.map((i) => i.variant ?? `${i.weight}`))],
48
+ files: n
49
+ });
50
+ }
51
+ return s;
52
+ }
53
+ function y(e) {
54
+ const s = l(e.id), t = l(e.asset_url);
55
+ if (!s || !t) return null;
56
+ const n = l(e.thumbnail_url);
57
+ return { id: s, name: l(e.name), url: t, ...n ? { thumbnailUrl: n } : {} };
58
+ }
59
+ function A(e) {
60
+ return y(e);
61
+ }
62
+ const O = {
63
+ async getFontList() {
64
+ const e = await m().get("fonts");
65
+ return x(e.data);
66
+ },
67
+ async getShapeList(e) {
68
+ const { size: s, ...t } = e, n = await m().get("shapes", {
69
+ ...t,
70
+ page: typeof e.page == "number" ? e.page : 1,
71
+ limit: typeof s == "number" ? s : 30
72
+ }), o = n.data.map(y).filter((i) => i !== null);
73
+ return d(o, n.pagination);
74
+ },
75
+ async getClipArtCategories() {
76
+ const s = (await m().get("clipart-categories")).data.map((t) => {
77
+ const n = l(t.id);
78
+ return n ? {
79
+ id: n,
80
+ name: l(t.name),
81
+ clip_arts: (t.cliparts ?? []).map(A).filter((o) => o !== null)
82
+ } : null;
83
+ }).filter((t) => t !== null);
84
+ return d(s);
85
+ }
86
+ };
87
+ function C(e) {
88
+ return String(e.type).includes("i-text") || e.type === "text" ? "text" : e.sourceType === "svg" || e.clip ? "svg" : e.type === "image" ? "image" : null;
89
+ }
90
+ function I(e, s) {
91
+ return s.flatMap((t) => (Array.isArray(e[t.name]?.objects) ? e[t.name].objects : []).filter((n) => n.id != null && !S.includes(String(n.id))).map((n) => ({
92
+ id: String(n.id),
93
+ placement: t.name,
94
+ placementLabel: t.display_name || t.name,
95
+ kind: C(n),
96
+ name: n.name || n.__rawText || n.text || "",
97
+ source: n.src || n.originSrc || "",
98
+ object: n
99
+ })).reverse());
100
+ }
101
+ function P(e, s) {
102
+ return {
103
+ name: s,
104
+ description: "",
105
+ enableOption: !1,
106
+ options: [],
107
+ moveable: !1,
108
+ ...e === "text" ? { maxCount: "", hintText: "", enableOptionalFont: !1, optionalFontList: [], enableColor: !1 } : {},
109
+ ...e === "image" ? { enableAI: !1, backgroundRemove: !1, portraitCutout: !1, cartoonize: !1, stickerOutline: !1 } : {},
110
+ ...e === "svg" ? { enableColor: !0 } : {}
111
+ };
112
+ }
113
+ function K(e, s) {
114
+ const t = (o) => ({ error: o, config: void 0 });
115
+ if (!String(s.name || "").trim()) return t("Field name is required");
116
+ const n = { ...s, name: s.name.trim(), options: (s.options || []).filter((o) => String(o.value || "").trim()) };
117
+ if (s.maxCount !== "" && s.maxCount != null) {
118
+ const o = Number(s.maxCount);
119
+ if (!Number.isInteger(o) || o < 1) return t("Enter a positive whole number for the character limit.");
120
+ n.maxCount = o;
121
+ } else delete n.maxCount;
122
+ return n.enableOption && !n.options.length ? t("Add at least one preset option.") : e === "text" && n.maxCount && n.enableOption && n.options.some((o) => [...o.value].length > n.maxCount) ? t("A preset exceeds the character limit.") : n.enableOptionalFont && !(n.optionalFontList || []).length ? t("Choose at least one optional font.") : e === "svg" && !n.enableColor && !n.moveable ? t("Allow color or placement changes for this vector.") : { config: n, error: void 0 };
123
+ }
124
+ function B(e, s, t) {
125
+ const n = { ...e, [s]: t };
126
+ if (t.syncKey) for (const [o, i] of Object.entries(e))
127
+ i?.syncKey === t.syncKey && (n[o] = { ...t });
128
+ return n;
129
+ }
130
+ function w(e, s, t, n) {
131
+ const o = { ...e };
132
+ if (e[t]) {
133
+ const a = e[t];
134
+ return delete o[t], { configs: o, drafts: { ...s, [t]: a } };
135
+ }
136
+ const i = s[t], r = i?.syncKey ? Object.values(e).find((a) => a?.syncKey === i.syncKey) : void 0;
137
+ return o[t] = { ...r || i || n }, { configs: o, drafts: s };
138
+ }
139
+ function D(e, s) {
140
+ const t = JSON.parse(JSON.stringify(e));
141
+ for (const n of Object.values(t))
142
+ if (Array.isArray(n.objects))
143
+ for (const o of n.objects) {
144
+ const i = s[String(o.id)];
145
+ delete o.customConfig, !(!i || !C(o)) && (o.customConfig = JSON.parse(JSON.stringify(i)), i.moveable || (o.customConfig.originalWidth = (o.width || 0) * Math.abs(o.scaleX ?? 1), o.customConfig.originalHeight = (o.height || 0) * Math.abs(o.scaleY ?? 1)));
146
+ }
147
+ return t;
148
+ }
149
+ function N(e) {
150
+ const s = /* @__PURE__ */ new Map();
151
+ for (const t of e) {
152
+ const n = t.object.customConfig;
153
+ if (!n || !t.kind) continue;
154
+ const o = n.syncKey ? `${t.kind}:sync:${n.syncKey}` : `${t.placement}:${t.id}`, i = s.get(o);
155
+ i ? i.targets.push(t) : s.set(o, { key: o, config: n, kind: t.kind, targets: [t] });
156
+ }
157
+ return [...s.values()];
158
+ }
159
+ function $(e, s, t) {
160
+ const n = { ...e };
161
+ return s.forEach((o, i) => {
162
+ const r = n[o.placement];
163
+ !r || !t[i] || (n[o.placement] = { ...r, objects: r.objects.map((a) => String(a.id) === o.id ? { ...a, ...t[i] } : a) });
164
+ }), n;
165
+ }
166
+ function T(e, s, t, n) {
167
+ const o = (e.width || 1) * Math.abs(e.scaleX ?? 1), i = (e.height || 1) * Math.abs(e.scaleY ?? 1), r = Math.max(o / t, i / n), a = o / r, c = i / r;
168
+ return {
169
+ src: s,
170
+ originSrc: s,
171
+ fullSizeSrc: s,
172
+ width: a,
173
+ height: c,
174
+ cropX: (t - a) / 2,
175
+ cropY: (n - c) / 2,
176
+ scaleX: r * (Math.sign(e.scaleX ?? 1) || 1),
177
+ scaleY: r * (Math.sign(e.scaleY ?? 1) || 1)
178
+ };
179
+ }
180
+ let u = 0;
181
+ const k = h((e, s) => ({
182
+ currentSide: "",
183
+ historyManager: new g(""),
184
+ fontList: [],
185
+ backgroundColor: "",
186
+ colors: [],
187
+ activeObjects: [],
188
+ rendering: !1,
189
+ copiedObjects: null,
190
+ semiCustom: {},
191
+ semiCustomDrafts: {},
192
+ semiCustomBackground: { colors: [], palette: !1, enable: !1 },
193
+ initData: (t, n) => {
194
+ const { getFontList: o, getColors: i } = s();
195
+ o(t), i(n);
196
+ },
197
+ getFontList: async (t) => {
198
+ try {
199
+ e({ fontList: await (t ? t() : O.getFontList()) });
200
+ } catch {
201
+ e({ fontList: [] });
202
+ }
203
+ },
204
+ loadMultipleFont: async (t) => {
205
+ const { fontList: n } = s(), o = t.map((i) => n.find((r) => r.family === i)).filter((i) => !!i);
206
+ await Promise.all(o.map((i) => b(i)));
207
+ },
208
+ getColors: async (t) => {
209
+ const n = ++u;
210
+ e({ colors: [] });
211
+ try {
212
+ const o = t ? await t() : [];
213
+ n === u && e({ colors: Array.isArray(o) ? o.filter((i) => typeof i == "string" && i.trim()) : [] });
214
+ } catch {
215
+ n === u && e({ colors: [] });
216
+ }
217
+ },
218
+ setActiveObjects: (t) => e({ activeObjects: t }),
219
+ setCurrentSide: (t) => e({ currentSide: t }),
220
+ setBackgroundColor: (t) => e({ backgroundColor: t }),
221
+ setHistoryManager: (t) => e({ historyManager: t }),
222
+ setRendering: (t) => e({ rendering: t }),
223
+ setCopiedObjects: (t) => e({ copiedObjects: t }),
224
+ setSemiCustom: (t) => e({ semiCustom: t }),
225
+ setSemiCustomItem: (t, n) => e({ semiCustom: { ...s().semiCustom, [t]: n } }),
226
+ toggleSemiCustomItem: (t, n) => {
227
+ const o = w(s().semiCustom, s().semiCustomDrafts, t, n);
228
+ e({ semiCustom: o.configs, semiCustomDrafts: o.drafts });
229
+ },
230
+ delSemiCustomInfo: (t) => e({ semiCustom: { ...s().semiCustom, [t]: void 0 } }),
231
+ setSemiCustomBackground: (t) => e({ semiCustomBackground: t }),
232
+ setSemiCustomBackgroundItem: (t, n) => e({ semiCustomBackground: { ...s().semiCustomBackground, [t]: n } }),
233
+ reset: () => {
234
+ u += 1, e({
235
+ historyManager: new g(""),
236
+ activeObjects: [],
237
+ backgroundColor: "",
238
+ currentSide: "",
239
+ copiedObjects: null,
240
+ semiCustom: {},
241
+ semiCustomDrafts: {},
242
+ semiCustomBackground: { colors: [], palette: !1, enable: !1 },
243
+ colors: []
244
+ });
245
+ }
246
+ })), E = k;
247
+ export {
248
+ O as A,
249
+ E as a,
250
+ I as b,
251
+ $ as c,
252
+ T as d,
253
+ C as e,
254
+ P as f,
255
+ K as g,
256
+ D as h,
257
+ B as i,
258
+ N as p,
259
+ z as s,
260
+ k as u
261
+ };
@@ -134,7 +134,7 @@ const E = ["cropRect", "cropOverlay", "workspace", "loading", "bg"], F = [0.01,
134
134
  ai: "AI image generator",
135
135
  files: "My files",
136
136
  background: "Background color",
137
- sca: "Custom"
137
+ sca: "Personalization"
138
138
  };
139
139
  export {
140
140
  t as ALIGN_TYPES,
@@ -25,6 +25,12 @@ export type AppEvents = {
25
25
  extraData?: any;
26
26
  };
27
27
  'design:preview': void;
28
+ 'design:personalizationSettings': {
29
+ id: string;
30
+ placement?: string;
31
+ };
32
+ 'design:personalizationBackgroundSettings': void;
33
+ 'design:buyerPreview': void;
28
34
  'design:editorCommand': 'SELECT_ALL' | 'COPY' | 'PASTE';
29
35
  'search:open': void;
30
36
  };
@@ -5,7 +5,7 @@ import { HistoryManager as D } from "../history.js";
5
5
  import { SnaplineManager as L } from "./snapline.js";
6
6
  import { TextProcessor as T } from "../processors/text.js";
7
7
  import { toVerticalStack as z } from "../utils/common.js";
8
- import { u as R } from "../../designer-store-Da9fICz8.js";
8
+ import { u as R } from "../../designer-store-BZFMaojO.js";
9
9
  import { fabric as x } from "fabric";
10
10
  class V {
11
11
  constructor(t, o) {
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { c as s } from "./design-Ce0Lyr8f.js";
3
+ import { c as s } from "./design-D5jmLHez.js";
4
4
  import "./engine/events.js";
5
5
  import "zustand/react/shallow";
6
6
  import "./engine/history.js";
@@ -8,7 +8,7 @@ import "lodash-es/throttle";
8
8
  import "./engine/constants.js";
9
9
  import "./engine/utils/common.js";
10
10
  import "./pixel-map-CSpWvUYE.js";
11
- import "./designer-store-Da9fICz8.js";
11
+ import "./designer-store-BZFMaojO.js";
12
12
  export {
13
13
  s as default
14
14
  };
@@ -0,0 +1,3 @@
1
+ export declare const personalizationMessages: {
2
+ es: Record<string, string>;
3
+ };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { AdvancedIText as G } from "./engine/fabric.js";
2
- import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-Ce0Lyr8f.js";
3
- import { F as K, S as V, u as X } from "./design-Ce0Lyr8f.js";
2
+ import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-D5jmLHez.js";
3
+ import { F as K, S as V, u as X } from "./design-D5jmLHez.js";
4
4
  import { jsx as r, jsxs as R } from "react/jsx-runtime";
5
5
  import { useMemo as b, useEffect as a } from "react";
6
6
  import { DEFAULT_PRINTINE_ASSET_BASE_URL as U, createAssetCenterApiClient as B } from "./api/asset-client.js";
7
- import { s as d } from "./designer-store-Da9fICz8.js";
8
- import { A as $, u as q } from "./designer-store-Da9fICz8.js";
7
+ import { s as d } from "./designer-store-BZFMaojO.js";
8
+ import { A as $, u as q } from "./designer-store-BZFMaojO.js";
9
9
  import { d as y, s as M } from "./config-D2qm60gf.js";
10
- import { P as Q, a as ee } from "./semi-interact-editor-DpzQN5ZB.js";
10
+ import { P as Q, a as ee } from "./semi-interact-editor-BUWPFgWU.js";
11
11
  import { P as te } from "./pixel-map-CSpWvUYE.js";
12
12
  import { CanvasDesigner as ae, renderPlacementPreviews as ne } from "./engine/canvas-designer.js";
13
13
  import { Editor as ie } from "./engine/editor.js";
@@ -0,0 +1,78 @@
1
+ import type { Mockup } from '../contracts/api-design';
2
+ export type PersonalizationKind = 'text' | 'image' | 'svg';
3
+ export type DesignDocuments = Record<string, Record<string, any>>;
4
+ export type PersonalizationConfigs = Record<string, Record<string, any> | undefined>;
5
+ export interface PersonalizationLayer {
6
+ id: string;
7
+ placement: string;
8
+ placementLabel: string;
9
+ kind: PersonalizationKind | null;
10
+ name: string;
11
+ source: string;
12
+ object: Record<string, any>;
13
+ }
14
+ export interface PersonalizationField {
15
+ key: string;
16
+ kind: PersonalizationKind;
17
+ config: Record<string, any>;
18
+ targets: PersonalizationLayer[];
19
+ }
20
+ export declare function personalizationKind(object: Record<string, any>): PersonalizationKind | null;
21
+ export declare function personalizationLayers(data: DesignDocuments, areas: Mockup[]): PersonalizationLayer[];
22
+ /** Only new permissions use these conservative defaults; restored configs are not rewritten. */
23
+ export declare function defaultPersonalizationConfig(kind: PersonalizationKind, name: string): {
24
+ enableColor?: boolean | undefined;
25
+ enableAI?: boolean | undefined;
26
+ backgroundRemove?: boolean | undefined;
27
+ portraitCutout?: boolean | undefined;
28
+ cartoonize?: boolean | undefined;
29
+ stickerOutline?: boolean | undefined;
30
+ maxCount?: string | undefined;
31
+ hintText?: string | undefined;
32
+ enableOptionalFont?: boolean | undefined;
33
+ optionalFontList?: never[] | undefined;
34
+ name: string;
35
+ description: string;
36
+ enableOption: boolean;
37
+ options: never[];
38
+ moveable: boolean;
39
+ };
40
+ /** Shared validation for dialog saves and live inspector changes. Keeps host metadata. */
41
+ export declare function preparePersonalizationConfig(kind: PersonalizationKind, config: Record<string, any>): {
42
+ error: string;
43
+ config: undefined;
44
+ } | {
45
+ config: Record<string, any>;
46
+ error: undefined;
47
+ };
48
+ export declare function updateLinkedPersonalization(configs: PersonalizationConfigs, id: string, config: Record<string, any>): {
49
+ [x: string]: Record<string, any> | undefined;
50
+ };
51
+ /** Disabled rules are kept only in editor memory, never in the saved design payload. */
52
+ export declare function togglePersonalization(configs: PersonalizationConfigs, drafts: PersonalizationConfigs, id: string, defaults: Record<string, any>): {
53
+ configs: {
54
+ [x: string]: Record<string, any> | undefined;
55
+ };
56
+ drafts: {
57
+ [x: string]: Record<string, any> | undefined;
58
+ };
59
+ };
60
+ /** Builds an isolated preview document using the same customConfig fields as saving. */
61
+ export declare function personalizationSnapshot(data: DesignDocuments, configs: PersonalizationConfigs): DesignDocuments;
62
+ export declare function personalizationFields(layers: PersonalizationLayer[]): PersonalizationField[];
63
+ /** Replaces only the explicit targets; fixed layers and other placements retain their state. */
64
+ export declare function patchPersonalizationTargets(data: DesignDocuments, targets: PersonalizationLayer[], patches: Record<string, any>[]): {
65
+ [x: string]: Record<string, any>;
66
+ };
67
+ /** Center-crop to the template box, preserving its position, angle and flipped axes. */
68
+ export declare function personalizationImagePatch(object: Record<string, any>, source: string, width: number, height: number): {
69
+ src: string;
70
+ originSrc: string;
71
+ fullSizeSrc: string;
72
+ width: number;
73
+ height: number;
74
+ cropX: number;
75
+ cropY: number;
76
+ scaleX: number;
77
+ scaleY: number;
78
+ };