@codingfactory/mediables-vue 2.19.1 → 2.19.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.
- package/dist/{PixiFrameExporter-64httBgJ.js → PixiFrameExporter-CRe8z6ua.js} +2 -2
- package/dist/{PixiFrameExporter-64httBgJ.js.map → PixiFrameExporter-CRe8z6ua.js.map} +1 -1
- package/dist/{PixiFrameExporter-DkXTPJWn.cjs → PixiFrameExporter-R6iQjzVw.cjs} +2 -2
- package/dist/{PixiFrameExporter-DkXTPJWn.cjs.map → PixiFrameExporter-R6iQjzVw.cjs.map} +1 -1
- package/dist/{editor-CiTXlIVO.js → editor-BQ_nY4P6.js} +634 -659
- package/dist/editor-BQ_nY4P6.js.map +1 -0
- package/dist/editor-CUV1pIsV.cjs +2 -0
- package/dist/editor-CUV1pIsV.cjs.map +1 -0
- package/dist/{index-Dinl1Puu.js → index-B8LxZ37n.js} +3 -3
- package/dist/{index-Dinl1Puu.js.map → index-B8LxZ37n.js.map} +1 -1
- package/dist/{index-2jP5K__o.cjs → index-DutUeSES.cjs} +3 -3
- package/dist/{index-2jP5K__o.cjs.map → index-DutUeSES.cjs.map} +1 -1
- package/dist/mediables-vanilla.cjs +1 -1
- package/dist/mediables-vanilla.mjs +1 -1
- package/dist/mediables-vue.cjs +1 -1
- package/dist/mediables-vue.mjs +2 -2
- package/package.json +1 -1
- package/dist/editor-CiTXlIVO.js.map +0 -1
- package/dist/editor-P9MyuiTc.cjs +0 -2
- package/dist/editor-P9MyuiTc.cjs.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var Me = Object.defineProperty;
|
|
2
|
-
var Fe = (
|
|
3
|
-
var oe = (
|
|
4
|
-
import { E as
|
|
2
|
+
var Fe = (f, e, t) => e in f ? Me(f, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : f[e] = t;
|
|
3
|
+
var oe = (f, e, t) => Fe(f, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { E as se, d as Se } from "./index-Dae8SHT7.js";
|
|
5
5
|
const Re = Object.freeze(["normal", "multiply", "screen", "overlay"]), E = Object.freeze({
|
|
6
6
|
stroke: Object.freeze({ enabled: !1, color: "#000000", width: 0 }),
|
|
7
7
|
shadow: Object.freeze({ enabled: !1, color: "#000000", alpha: 0.5, blur: 0, distance: 0, angle: 45 }),
|
|
8
8
|
glow: Object.freeze({ enabled: !1, color: "#ffffff", alpha: 0.5, blur: 0 }),
|
|
9
9
|
backdrop: Object.freeze({ enabled: !1, color: "#000000", opacity: 0.5, padding: 0, radius: 0, blur: 0 })
|
|
10
10
|
});
|
|
11
|
-
class Te extends
|
|
11
|
+
class Te extends se {
|
|
12
12
|
constructor() {
|
|
13
13
|
super(), this.app = null, this.sprite = null, this.originalTexture = null, this.baseTexture = null, this.fitScale = 1, this.zoom = 1, this._container = null, this._lastExportDimensions = null, this._mountPromise = null, this._mountToken = 0, this._destroyed = !1, this._layerDocument = null, this._layerDisplayObjects = /* @__PURE__ */ new Map(), this._renderableLayerIds = [], this._loadedTextureUrl = null, this._layerRenderToken = 0, this._layerFilterFactory = null;
|
|
14
14
|
}
|
|
@@ -26,8 +26,8 @@ class Te extends re {
|
|
|
26
26
|
* canvas getter which throws when renderer is undefined.
|
|
27
27
|
*/
|
|
28
28
|
_getCssSize() {
|
|
29
|
-
var
|
|
30
|
-
const e = (
|
|
29
|
+
var r, s, o, n, a, l;
|
|
30
|
+
const e = (s = (r = this.app) == null ? void 0 : r.renderer) == null ? void 0 : s.canvas, t = (e == null ? void 0 : e.clientWidth) ?? ((n = (o = this.app) == null ? void 0 : o.screen) == null ? void 0 : n.width) ?? 0, i = (e == null ? void 0 : e.clientHeight) ?? ((l = (a = this.app) == null ? void 0 : a.screen) == null ? void 0 : l.height) ?? 0;
|
|
31
31
|
return { w: t, h: i };
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
@@ -52,15 +52,15 @@ class Te extends re {
|
|
|
52
52
|
t();
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
let i = !1,
|
|
56
|
-
const
|
|
57
|
-
i || (i = !0, window.clearTimeout(
|
|
55
|
+
let i = !1, r = 0;
|
|
56
|
+
const s = () => {
|
|
57
|
+
i || (i = !0, window.clearTimeout(r), t());
|
|
58
58
|
};
|
|
59
|
-
if (
|
|
60
|
-
window.requestAnimationFrame(() =>
|
|
59
|
+
if (r = window.setTimeout(s, e), typeof window.requestAnimationFrame == "function") {
|
|
60
|
+
window.requestAnimationFrame(() => s());
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
s();
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
@@ -72,16 +72,16 @@ class Te extends re {
|
|
|
72
72
|
if (!this.app || !e) return 1;
|
|
73
73
|
const { w: t, h: i } = this._getCssSize();
|
|
74
74
|
if (t <= 1 || i <= 1) return 1;
|
|
75
|
-
let
|
|
76
|
-
return (!Number.isFinite(
|
|
75
|
+
let r = Math.min(t / e.width, i / e.height) * 0.9;
|
|
76
|
+
return (!Number.isFinite(r) || r <= 0) && (r = 1), r;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Apply view transform (position and scale) to sprite
|
|
80
80
|
*/
|
|
81
81
|
applyViewTransform(e = {}) {
|
|
82
82
|
if (!this.app || !this.sprite || !this.originalTexture) return;
|
|
83
|
-
const t = this.fitScale * this.zoom, { w: i, h:
|
|
84
|
-
this.sprite.width = this.originalTexture.width * t, this.sprite.height = this.originalTexture.height * t, this.sprite.x =
|
|
83
|
+
const t = this.fitScale * this.zoom, { w: i, h: r } = this._getCssSize(), s = e.keepCenter ? { x: this.sprite.x + this.sprite.width / 2, y: this.sprite.y + this.sprite.height / 2 } : e.center ?? { x: i / 2, y: r / 2 };
|
|
84
|
+
this.sprite.width = this.originalTexture.width * t, this.sprite.height = this.originalTexture.height * t, this.sprite.x = s.x - this.sprite.width / 2, this.sprite.y = s.y - this.sprite.height / 2, this._syncLayerDisplayObjects(), this.render();
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Set zoom level
|
|
@@ -108,12 +108,12 @@ class Te extends re {
|
|
|
108
108
|
async mount(e, t = 16777215, i = {}) {
|
|
109
109
|
if (!e) return;
|
|
110
110
|
this._destroyed = !1, this._container = e;
|
|
111
|
-
const
|
|
112
|
-
var
|
|
111
|
+
const r = ++this._mountToken, s = async () => {
|
|
112
|
+
var u;
|
|
113
113
|
const o = window.PIXI;
|
|
114
114
|
if (!o)
|
|
115
115
|
throw new Error("PIXI.js not found. Please ensure PIXI is loaded globally.");
|
|
116
|
-
(
|
|
116
|
+
(u = o.Assets) != null && u.setPreferences && o.Assets.setPreferences({ crossOrigin: "anonymous" });
|
|
117
117
|
const n = e.clientWidth || 600, a = e.clientHeight || 400, l = typeof i.backgroundAlpha == "number" ? i.backgroundAlpha : 1, h = new o.Application();
|
|
118
118
|
if (this.app = h, await h.init({
|
|
119
119
|
width: n,
|
|
@@ -123,7 +123,7 @@ class Te extends re {
|
|
|
123
123
|
antialias: !0,
|
|
124
124
|
autoDensity: !0,
|
|
125
125
|
resolution: window.devicePixelRatio || 1
|
|
126
|
-
}), this._destroyed || this._mountToken !==
|
|
126
|
+
}), this._destroyed || this._mountToken !== r || this.app !== h) {
|
|
127
127
|
try {
|
|
128
128
|
h.destroy(!0, { children: !0, texture: !0 });
|
|
129
129
|
} catch {
|
|
@@ -134,7 +134,7 @@ class Te extends re {
|
|
|
134
134
|
const c = h.canvas;
|
|
135
135
|
return c.classList.add("pixi-canvas"), c.style.width = "100%", c.style.height = "100%", c.style.transform = "translateZ(0)", c.style.willChange = "transform", c.setAttribute("role", "img"), c.setAttribute("aria-label", "Image editor canvas — use toolbar controls to edit the image"), this.emit("mounted", { width: n, height: a }), !0;
|
|
136
136
|
};
|
|
137
|
-
return this._mountPromise =
|
|
137
|
+
return this._mountPromise = s(), await this._mountPromise;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Load an image texture
|
|
@@ -144,15 +144,15 @@ class Te extends re {
|
|
|
144
144
|
* has been superseded and must not mutate the renderer.
|
|
145
145
|
*/
|
|
146
146
|
async loadTexture(e, t = {}) {
|
|
147
|
-
var h, c,
|
|
147
|
+
var h, c, u;
|
|
148
148
|
const i = () => typeof t.isCurrent != "function" || t.isCurrent() !== !1;
|
|
149
149
|
if (this._mountPromise && await this._mountPromise, !((h = this.app) != null && h.renderer) || !i()) return !1;
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
152
|
-
const o =
|
|
150
|
+
const r = window.PIXI, s = await this._loadImageElement(e);
|
|
151
|
+
if (!s || !((c = this.app) != null && c.renderer) || !i() || (await this._waitForNextFrame(), !((u = this.app) != null && u.renderer) || !i())) return !1;
|
|
152
|
+
const o = r.Texture.from(s);
|
|
153
153
|
if (!o)
|
|
154
154
|
return !1;
|
|
155
|
-
this.originalTexture = o, this.baseTexture = o, this._loadedTextureUrl = typeof e == "string" ? e : null, this.sprite && (this.app.stage.removeChild(this.sprite), this.sprite.destroy()), this.sprite = new
|
|
155
|
+
this.originalTexture = o, this.baseTexture = o, this._loadedTextureUrl = typeof e == "string" ? e : null, this.sprite && (this.app.stage.removeChild(this.sprite), this.sprite.destroy()), this.sprite = new r.Sprite(o), this.app.stage.addChild(this.sprite), this.fitScale = this.getFitScaleFor(o), this.zoom = 1;
|
|
156
156
|
const { w: n, h: a } = this._getCssSize();
|
|
157
157
|
this.applyViewTransform({ center: { x: n / 2, y: a / 2 } });
|
|
158
158
|
const l = this.getFitScaleFor(o);
|
|
@@ -171,35 +171,35 @@ class Te extends re {
|
|
|
171
171
|
return !1;
|
|
172
172
|
const t = window.PIXI;
|
|
173
173
|
if (!t) return !1;
|
|
174
|
-
const i = ++this._layerRenderToken,
|
|
174
|
+
const i = ++this._layerRenderToken, r = () => i === this._layerRenderToken;
|
|
175
175
|
this._destroyLayerDisplayObjects(), this._layerDocument = JSON.parse(JSON.stringify(e)), this._renderableLayerIds = [];
|
|
176
176
|
try {
|
|
177
177
|
this.app.stage.removeChild(this.sprite);
|
|
178
178
|
} catch {
|
|
179
179
|
}
|
|
180
|
-
let
|
|
180
|
+
let s = !1;
|
|
181
181
|
for (const n of this._layerDocument.layers) {
|
|
182
182
|
if (!n || n.visible === !1) {
|
|
183
|
-
(n == null ? void 0 : n.role) === "subject" && (this.sprite.visible = !1, this.sprite.__layerId = n.id,
|
|
183
|
+
(n == null ? void 0 : n.role) === "subject" && (this.sprite.visible = !1, this.sprite.__layerId = n.id, s = !0);
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
186
186
|
if (this._isSubjectLayer(n)) {
|
|
187
187
|
const l = await this._createSubjectDisplayObjectForLayer(t, n);
|
|
188
|
-
if (!
|
|
188
|
+
if (!r())
|
|
189
189
|
return this._destroyTransientDisplayObject(l), !1;
|
|
190
190
|
if (l) {
|
|
191
|
-
this.sprite.visible = !1, l.__layerId = n.id, l.visible = !0, l.alpha = this._layerOpacity(n), this._layerDisplayObjects.set(n.id, { layer: n, displayObject: l }), this._syncLayerDisplayObject(n, l), this.app.stage.addChild(l), this._renderableLayerIds.push(n.id),
|
|
191
|
+
this.sprite.visible = !1, l.__layerId = n.id, l.visible = !0, l.alpha = this._layerOpacity(n), this._layerDisplayObjects.set(n.id, { layer: n, displayObject: l }), this._syncLayerDisplayObject(n, l), this.app.stage.addChild(l), this._renderableLayerIds.push(n.id), s = !0;
|
|
192
192
|
continue;
|
|
193
193
|
}
|
|
194
|
-
this.sprite.__layerId = n.id, this.sprite.visible = !0, this.sprite.alpha = this._layerOpacity(n), this._applyLayerFilterInstances(this.sprite, n), this.app.stage.addChild(this.sprite), this._renderableLayerIds.push(n.id),
|
|
194
|
+
this.sprite.__layerId = n.id, this.sprite.visible = !0, this.sprite.alpha = this._layerOpacity(n), this._applyLayerFilterInstances(this.sprite, n), this.app.stage.addChild(this.sprite), this._renderableLayerIds.push(n.id), s = !0;
|
|
195
195
|
continue;
|
|
196
196
|
}
|
|
197
197
|
const a = await this._createDisplayObjectForLayer(t, n);
|
|
198
|
-
if (!
|
|
198
|
+
if (!r())
|
|
199
199
|
return this._destroyTransientDisplayObject(a), !1;
|
|
200
200
|
a && (a.__layerId = n.id, a.visible = !0, a.alpha = this._layerOpacity(n), this._layerDisplayObjects.set(n.id, { layer: n, displayObject: a }), this._syncLayerDisplayObject(n, a), this.app.stage.addChild(a), this._renderableLayerIds.push(n.id));
|
|
201
201
|
}
|
|
202
|
-
return
|
|
202
|
+
return s || (this.sprite.visible = !1), r() ? (this.render(), !0) : !1;
|
|
203
203
|
}
|
|
204
204
|
getRenderableLayerIds() {
|
|
205
205
|
return [...this._renderableLayerIds];
|
|
@@ -213,10 +213,10 @@ class Te extends re {
|
|
|
213
213
|
this._layerDocument = JSON.parse(JSON.stringify(e));
|
|
214
214
|
for (const i of this._layerDocument.layers) {
|
|
215
215
|
if (!i) continue;
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
let
|
|
219
|
-
!
|
|
216
|
+
const r = this._layerDisplayObjects.get(i.id) || null;
|
|
217
|
+
r && (r.layer = i);
|
|
218
|
+
let s = (r == null ? void 0 : r.displayObject) || null;
|
|
219
|
+
!s && this._isSubjectLayer(i) && ((t = this.sprite) == null ? void 0 : t.__layerId) === i.id && (s = this.sprite), s && this._applyLayerFilterInstances(s, i);
|
|
220
220
|
}
|
|
221
221
|
return this.render(), !0;
|
|
222
222
|
}
|
|
@@ -233,10 +233,10 @@ class Te extends re {
|
|
|
233
233
|
}
|
|
234
234
|
_applyLayerFilterInstances(e, t, i = {}) {
|
|
235
235
|
if (!e || !this._layerSupportsImageFilters(t)) return;
|
|
236
|
-
let
|
|
236
|
+
let r = [];
|
|
237
237
|
if (this._layerFilterFactory)
|
|
238
238
|
try {
|
|
239
|
-
|
|
239
|
+
r = this._layerFilterFactory(t, {
|
|
240
240
|
displayObject: e,
|
|
241
241
|
forExport: i.forExport === !0,
|
|
242
242
|
previewToNativeScale: i.previewToNativeScale || 1,
|
|
@@ -244,10 +244,10 @@ class Te extends re {
|
|
|
244
244
|
sourceHeight: i.sourceHeight
|
|
245
245
|
}) || [];
|
|
246
246
|
} catch {
|
|
247
|
-
|
|
247
|
+
r = [];
|
|
248
248
|
}
|
|
249
|
-
const
|
|
250
|
-
for (const a of
|
|
249
|
+
const s = Array.isArray(r) ? r.filter(Boolean) : [];
|
|
250
|
+
for (const a of s)
|
|
251
251
|
if (!(!a || typeof a != "object" && typeof a != "function"))
|
|
252
252
|
try {
|
|
253
253
|
Object.defineProperty(a, "__mediablesLayerImageFilter", {
|
|
@@ -260,24 +260,24 @@ class Te extends re {
|
|
|
260
260
|
} catch {
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
const n = [...Array.isArray(e.filters) ? e.filters.filter((a) => (a == null ? void 0 : a.__mediablesLayerImageFilter) !== !0) : [], ...
|
|
263
|
+
const n = [...Array.isArray(e.filters) ? e.filters.filter((a) => (a == null ? void 0 : a.__mediablesLayerImageFilter) !== !0) : [], ...s];
|
|
264
264
|
e.filters = n.length > 0 ? n : null;
|
|
265
265
|
}
|
|
266
266
|
async _createDisplayObjectForLayer(e, t) {
|
|
267
267
|
var o, n;
|
|
268
268
|
const i = this._createTextDisplayObjectForLayer(e, t);
|
|
269
269
|
if (i) return i;
|
|
270
|
-
const
|
|
271
|
-
if (
|
|
272
|
-
const
|
|
273
|
-
if ((
|
|
274
|
-
const a = await this._textureForLayerSource(e,
|
|
270
|
+
const r = await this._createImageDisplayObjectForLayer(e, t);
|
|
271
|
+
if (r) return r;
|
|
272
|
+
const s = this._backgroundFillForLayer(t);
|
|
273
|
+
if ((s == null ? void 0 : s.kind) === "media") {
|
|
274
|
+
const a = await this._textureForLayerSource(e, s.source);
|
|
275
275
|
if (!a) return null;
|
|
276
|
-
const l = this._createBackgroundSprite(e, a,
|
|
277
|
-
return l.__sourceWidth = Number((o =
|
|
276
|
+
const l = this._createBackgroundSprite(e, a, s.fit);
|
|
277
|
+
return l.__sourceWidth = Number((o = s.source) == null ? void 0 : o.originalWidth) || a.width || 1, l.__sourceHeight = Number((n = s.source) == null ? void 0 : n.originalHeight) || a.height || 1, this._applyLayerEffects(e, l, t), this._applyLayerFilterInstances(l, t), l;
|
|
278
278
|
}
|
|
279
|
-
if ((
|
|
280
|
-
const a = this._createGradientTexture(e,
|
|
279
|
+
if ((s == null ? void 0 : s.kind) === "gradient") {
|
|
280
|
+
const a = this._createGradientTexture(e, s, 512, 512);
|
|
281
281
|
if (!a || typeof e.Sprite != "function") return null;
|
|
282
282
|
const l = new e.Sprite(a);
|
|
283
283
|
return l.__ownsTexture = !0, l.__sourceWidth = 512, l.__sourceHeight = 512, this._applyLayerEffects(e, l, t), l;
|
|
@@ -301,9 +301,9 @@ class Te extends re {
|
|
|
301
301
|
height: this._clampNumber(t.height, 0.05, 1, 0.18)
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
|
-
_clampNumber(e, t, i,
|
|
305
|
-
const
|
|
306
|
-
return Number.isFinite(
|
|
304
|
+
_clampNumber(e, t, i, r) {
|
|
305
|
+
const s = Number(e);
|
|
306
|
+
return Number.isFinite(s) ? Math.max(t, Math.min(i, s)) : r;
|
|
307
307
|
}
|
|
308
308
|
_supportedTextFontFamily(e) {
|
|
309
309
|
const t = ["Inter", "Arial", "Helvetica", "Georgia", "Times New Roman", "Courier New", "Verdana"], i = typeof e == "string" ? e.trim() : "";
|
|
@@ -321,25 +321,25 @@ class Te extends re {
|
|
|
321
321
|
const t = (i = e == null ? void 0 : e.text) == null ? void 0 : i.content;
|
|
322
322
|
return t == null ? "" : String(t);
|
|
323
323
|
}
|
|
324
|
-
_textStyleForLayer(e, t = 1, i = 1,
|
|
324
|
+
_textStyleForLayer(e, t = 1, i = 1, r = {}) {
|
|
325
325
|
var m;
|
|
326
|
-
const
|
|
327
|
-
fontFamily: this._supportedTextFontFamily(
|
|
326
|
+
const s = (m = e == null ? void 0 : e.text) != null && m.style && typeof e.text.style == "object" ? e.text.style : {}, o = this._textEffectsForLayer(e), n = this._clampNumber(s.fontSize, 8, 400, 64), a = this._clampNumber(s.lineHeight, 0.8, 3, 1.2), l = this._clampNumber(s.letterSpacing, -100, 100, 0), h = this._normalizeTextFontWeight(s.fontWeight), c = ["normal", "italic"].includes(s.fontStyle) ? s.fontStyle : "normal", u = ["left", "center", "right"].includes(s.align) ? s.align : "center", p = r.fill || (typeof s.fill == "string" && /^#[0-9a-f]{6}$/i.test(s.fill) ? s.fill : "#ffffff"), g = {
|
|
327
|
+
fontFamily: this._supportedTextFontFamily(s.fontFamily),
|
|
328
328
|
fontSize: n * t,
|
|
329
329
|
fontWeight: h,
|
|
330
330
|
fontStyle: c,
|
|
331
|
-
fill:
|
|
332
|
-
align:
|
|
331
|
+
fill: p,
|
|
332
|
+
align: u,
|
|
333
333
|
lineHeight: n * a * t,
|
|
334
334
|
letterSpacing: l * t,
|
|
335
335
|
wordWrap: !0,
|
|
336
336
|
wordWrapWidth: Math.max(1, i),
|
|
337
337
|
breakWords: !0
|
|
338
338
|
};
|
|
339
|
-
return
|
|
339
|
+
return r.stroke !== !1 && o.stroke.enabled && o.stroke.width > 0 && (g.stroke = {
|
|
340
340
|
color: o.stroke.color,
|
|
341
341
|
width: o.stroke.width * t
|
|
342
|
-
}),
|
|
342
|
+
}), g;
|
|
343
343
|
}
|
|
344
344
|
_normalizeTextFontWeight(e) {
|
|
345
345
|
if (e === "normal") return 400;
|
|
@@ -349,7 +349,7 @@ class Te extends re {
|
|
|
349
349
|
}
|
|
350
350
|
_textEffectsForLayer(e) {
|
|
351
351
|
var n;
|
|
352
|
-
const t = (n = e == null ? void 0 : e.text) != null && n.effects && typeof e.text.effects == "object" ? e.text.effects : {}, i = t.stroke && typeof t.stroke == "object" ? t.stroke : {},
|
|
352
|
+
const t = (n = e == null ? void 0 : e.text) != null && n.effects && typeof e.text.effects == "object" ? e.text.effects : {}, i = t.stroke && typeof t.stroke == "object" ? t.stroke : {}, r = t.shadow && typeof t.shadow == "object" ? t.shadow : {}, s = t.glow && typeof t.glow == "object" ? t.glow : {}, o = t.backdrop && typeof t.backdrop == "object" ? t.backdrop : {};
|
|
353
353
|
return {
|
|
354
354
|
stroke: {
|
|
355
355
|
enabled: i.enabled === !0,
|
|
@@ -357,18 +357,18 @@ class Te extends re {
|
|
|
357
357
|
width: this._clampNumber(i.width, 0, 80, E.stroke.width)
|
|
358
358
|
},
|
|
359
359
|
shadow: {
|
|
360
|
-
enabled:
|
|
361
|
-
color: this._supportedTextColor(
|
|
362
|
-
alpha: this._clampNumber(
|
|
363
|
-
blur: this._clampNumber(
|
|
364
|
-
distance: this._clampNumber(
|
|
365
|
-
angle: this._normalizeDegrees(
|
|
360
|
+
enabled: r.enabled === !0,
|
|
361
|
+
color: this._supportedTextColor(r.color, E.shadow.color),
|
|
362
|
+
alpha: this._clampNumber(r.alpha, 0, 1, E.shadow.alpha),
|
|
363
|
+
blur: this._clampNumber(r.blur, 0, 120, E.shadow.blur),
|
|
364
|
+
distance: this._clampNumber(r.distance, 0, 200, E.shadow.distance),
|
|
365
|
+
angle: this._normalizeDegrees(r.angle ?? E.shadow.angle)
|
|
366
366
|
},
|
|
367
367
|
glow: {
|
|
368
|
-
enabled:
|
|
369
|
-
color: this._supportedTextColor(
|
|
370
|
-
alpha: this._clampNumber(
|
|
371
|
-
blur: this._clampNumber(
|
|
368
|
+
enabled: s.enabled === !0,
|
|
369
|
+
color: this._supportedTextColor(s.color, E.glow.color),
|
|
370
|
+
alpha: this._clampNumber(s.alpha, 0, 1, E.glow.alpha),
|
|
371
|
+
blur: this._clampNumber(s.blur, 0, 120, E.glow.blur)
|
|
372
372
|
},
|
|
373
373
|
backdrop: {
|
|
374
374
|
enabled: o.enabled === !0,
|
|
@@ -395,8 +395,8 @@ class Te extends re {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
_textEffectPadding(e, t) {
|
|
398
|
-
const i = e.stroke.enabled ? e.stroke.width * t : 0,
|
|
399
|
-
return Math.ceil(Math.max(i,
|
|
398
|
+
const i = e.stroke.enabled ? e.stroke.width * t : 0, r = e.shadow.enabled ? (e.shadow.distance + e.shadow.blur * 2) * t : 0, s = e.glow.enabled ? e.glow.blur * 2 * t : 0, o = e.backdrop.enabled ? (e.backdrop.padding + e.backdrop.blur * 2) * t : 0;
|
|
399
|
+
return Math.ceil(Math.max(i, r, s, o, 0));
|
|
400
400
|
}
|
|
401
401
|
_createTextDisplayObjectForLayer(e, t) {
|
|
402
402
|
if (!this._isTextLayer(t) || typeof (e == null ? void 0 : e.Text) != "function") return null;
|
|
@@ -404,8 +404,8 @@ class Te extends re {
|
|
|
404
404
|
if (!i) return null;
|
|
405
405
|
if (typeof e.Container != "function" || typeof e.Graphics != "function")
|
|
406
406
|
return i;
|
|
407
|
-
const
|
|
408
|
-
return
|
|
407
|
+
const r = new e.Container(), s = new e.Graphics(), o = new e.Graphics(), n = new e.Graphics(), a = this._createTextPrimitive(e, t), l = this._createTextPrimitive(e, t);
|
|
408
|
+
return r.__isTextLayerContainer = !0, r.__textObject = i, r.__textMask = s, r.__textEffectMask = o, r.__textBackdrop = n, r.__textShadow = a, r.__textGlow = l, n.visible = !1, a && (a.visible = !1), l && (l.visible = !1), i.mask = s, r.addChild(n), a && r.addChild(a), l && r.addChild(l), r.addChild(i), r.addChild(o), r.addChild(s), r;
|
|
409
409
|
}
|
|
410
410
|
_createTextPrimitive(e, t) {
|
|
411
411
|
try {
|
|
@@ -426,12 +426,12 @@ class Te extends re {
|
|
|
426
426
|
return !i || i === this._loadedTextureUrl ? null : this._createImageDisplayObjectForLayer(e, t);
|
|
427
427
|
}
|
|
428
428
|
async _createImageDisplayObjectForLayer(e, t) {
|
|
429
|
-
var
|
|
429
|
+
var s, o;
|
|
430
430
|
if ((t == null ? void 0 : t.type) !== "image") return null;
|
|
431
431
|
const i = await this._textureForLayerSource(e, t.source);
|
|
432
432
|
if (!i || typeof e.Sprite != "function") return null;
|
|
433
|
-
const
|
|
434
|
-
return
|
|
433
|
+
const r = new e.Sprite(i);
|
|
434
|
+
return r.__sourceWidth = Number((s = t.source) == null ? void 0 : s.originalWidth) || i.width || 1, r.__sourceHeight = Number((o = t.source) == null ? void 0 : o.originalHeight) || i.height || 1, this._applyLayerEffects(e, r, t), this._applyLayerFilterInstances(r, t), r;
|
|
435
435
|
}
|
|
436
436
|
_backgroundFillForLayer(e) {
|
|
437
437
|
const t = e == null ? void 0 : e.fill;
|
|
@@ -458,29 +458,29 @@ class Te extends re {
|
|
|
458
458
|
async _textureForLayerSource(e, t) {
|
|
459
459
|
const i = this._sourceUrlForLayerSource(t);
|
|
460
460
|
if (!i) return null;
|
|
461
|
-
const
|
|
462
|
-
return
|
|
461
|
+
const r = await this._loadImageElement(i);
|
|
462
|
+
return r ? e.Texture.from(r) : null;
|
|
463
463
|
}
|
|
464
464
|
_createBackgroundSprite(e, t, i = "cover") {
|
|
465
465
|
if (i === "tile" && typeof e.TilingSprite == "function")
|
|
466
466
|
try {
|
|
467
|
-
const
|
|
468
|
-
return
|
|
467
|
+
const r = new e.TilingSprite({ texture: t, width: 1, height: 1 });
|
|
468
|
+
return r.__isTilingBackground = !0, r;
|
|
469
469
|
} catch {
|
|
470
470
|
try {
|
|
471
|
-
const
|
|
472
|
-
return
|
|
471
|
+
const s = new e.TilingSprite(t, 1, 1);
|
|
472
|
+
return s.__isTilingBackground = !0, s;
|
|
473
473
|
} catch {
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
return new e.Sprite(t);
|
|
477
477
|
}
|
|
478
|
-
_createGradientTexture(e, t, i,
|
|
478
|
+
_createGradientTexture(e, t, i, r) {
|
|
479
479
|
var l;
|
|
480
480
|
if (typeof document > "u" || !((l = e == null ? void 0 : e.Texture) != null && l.from)) return null;
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const o =
|
|
481
|
+
const s = document.createElement("canvas");
|
|
482
|
+
s.width = Math.max(1, Math.round(i)), s.height = Math.max(1, Math.round(r));
|
|
483
|
+
const o = s.getContext("2d");
|
|
484
484
|
if (!o) return null;
|
|
485
485
|
const n = Array.isArray(t == null ? void 0 : t.stops) && t.stops.length > 0 ? t.stops : [
|
|
486
486
|
{ offset: 0, color: "#111827" },
|
|
@@ -488,42 +488,42 @@ class Te extends re {
|
|
|
488
488
|
];
|
|
489
489
|
let a;
|
|
490
490
|
if ((t == null ? void 0 : t.gradientType) === "radial") {
|
|
491
|
-
const h = Math.max(
|
|
491
|
+
const h = Math.max(s.width, s.height) / 2;
|
|
492
492
|
a = o.createRadialGradient(
|
|
493
|
-
|
|
494
|
-
|
|
493
|
+
s.width / 2,
|
|
494
|
+
s.height / 2,
|
|
495
495
|
0,
|
|
496
|
-
|
|
497
|
-
|
|
496
|
+
s.width / 2,
|
|
497
|
+
s.height / 2,
|
|
498
498
|
h
|
|
499
499
|
);
|
|
500
500
|
} else {
|
|
501
|
-
const h = (Number(t == null ? void 0 : t.angle) || 0) * Math.PI / 180, c =
|
|
502
|
-
a = o.createLinearGradient(c -
|
|
501
|
+
const h = (Number(t == null ? void 0 : t.angle) || 0) * Math.PI / 180, c = s.width / 2, u = s.height / 2, p = Math.sqrt(s.width ** 2 + s.height ** 2) / 2, g = Math.cos(h) * p, m = Math.sin(h) * p;
|
|
502
|
+
a = o.createLinearGradient(c - g, u - m, c + g, u + m);
|
|
503
503
|
}
|
|
504
504
|
for (const h of n) {
|
|
505
505
|
if (!h || typeof h.color != "string") continue;
|
|
506
506
|
const c = Number.isFinite(Number(h.offset)) ? Math.max(0, Math.min(1, Number(h.offset))) : 0;
|
|
507
507
|
a.addColorStop(c, h.color);
|
|
508
508
|
}
|
|
509
|
-
return o.fillStyle = a, o.fillRect(0, 0,
|
|
509
|
+
return o.fillStyle = a, o.fillRect(0, 0, s.width, s.height), e.Texture.from(s);
|
|
510
510
|
}
|
|
511
511
|
_backgroundBlurAmount(e) {
|
|
512
|
-
var
|
|
513
|
-
const i = (Array.isArray(e == null ? void 0 : e.effects) ? e.effects : []).find((o) => (o == null ? void 0 : o.id) === "background-blur" || (o == null ? void 0 : o.type) === "blur"),
|
|
514
|
-
return Number.isFinite(
|
|
512
|
+
var s;
|
|
513
|
+
const i = (Array.isArray(e == null ? void 0 : e.effects) ? e.effects : []).find((o) => (o == null ? void 0 : o.id) === "background-blur" || (o == null ? void 0 : o.type) === "blur"), r = Number((s = i == null ? void 0 : i.params) == null ? void 0 : s.amount);
|
|
514
|
+
return Number.isFinite(r) ? Math.max(0, r) : 0;
|
|
515
515
|
}
|
|
516
516
|
_applyLayerEffects(e, t, i) {
|
|
517
|
-
const
|
|
518
|
-
if (!(
|
|
517
|
+
const r = this._backgroundBlurAmount(i);
|
|
518
|
+
if (!(r <= 0 || typeof (e == null ? void 0 : e.BlurFilter) != "function"))
|
|
519
519
|
try {
|
|
520
|
-
let
|
|
520
|
+
let s;
|
|
521
521
|
try {
|
|
522
|
-
|
|
522
|
+
s = new e.BlurFilter({ strength: r, quality: 4 });
|
|
523
523
|
} catch {
|
|
524
|
-
|
|
524
|
+
s = new e.BlurFilter(r);
|
|
525
525
|
}
|
|
526
|
-
typeof
|
|
526
|
+
typeof s.blur == "number" && (s.blur = r), typeof s.strength == "number" && (s.strength = r), s.padding = Math.max(Number(s.padding) || 0, Math.ceil(r * 2)), t.filters = Array.isArray(t.filters) ? [...t.filters, s] : [s];
|
|
527
527
|
} catch {
|
|
528
528
|
}
|
|
529
529
|
}
|
|
@@ -563,11 +563,11 @@ class Te extends re {
|
|
|
563
563
|
e.fill(t), e.alpha = i;
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
_syncTextEffectPrimitive(e, t, i,
|
|
566
|
+
_syncTextEffectPrimitive(e, t, i, r, s, o, n, a) {
|
|
567
567
|
if (!t) return;
|
|
568
|
-
const l = s
|
|
568
|
+
const l = r[s];
|
|
569
569
|
if (t.visible = (l == null ? void 0 : l.enabled) === !0, t.filters = null, t.mask = t.visible ? a : null, !!t.visible) {
|
|
570
|
-
if (t.text = this._textContentForLayer(i), t.rotation = 0,
|
|
570
|
+
if (t.text = this._textContentForLayer(i), t.rotation = 0, s === "shadow") {
|
|
571
571
|
const h = l.angle * Math.PI / 180;
|
|
572
572
|
t.x = Math.cos(h) * l.distance * o, t.y = Math.sin(h) * l.distance * o, t.alpha = l.alpha, t.style = this._textStyleForLayer(i, o, n, {
|
|
573
573
|
fill: l.color,
|
|
@@ -577,7 +577,7 @@ class Te extends re {
|
|
|
577
577
|
t.filters = c ? [c] : null;
|
|
578
578
|
return;
|
|
579
579
|
}
|
|
580
|
-
if (
|
|
580
|
+
if (s === "glow") {
|
|
581
581
|
t.x = 0, t.y = 0, t.alpha = l.alpha, t.style = this._textStyleForLayer(i, o, n, {
|
|
582
582
|
fill: l.color,
|
|
583
583
|
stroke: !1
|
|
@@ -587,64 +587,64 @@ class Te extends re {
|
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
|
-
_syncTextBackdrop(e, t, i,
|
|
590
|
+
_syncTextBackdrop(e, t, i, r, s, o, n) {
|
|
591
591
|
if (!t) return;
|
|
592
592
|
const a = i.backdrop;
|
|
593
593
|
if (t.visible = a.enabled === !0, t.filters = null, t.mask = t.visible ? n : null, t.alpha = 1, typeof t.clear == "function" && t.clear(), !t.visible) return;
|
|
594
|
-
const l = a.padding *
|
|
595
|
-
h > 0 && typeof t.roundRect == "function" ? t.roundRect(c,
|
|
596
|
-
const m = this._createTextBlurFilter(e, a.blur *
|
|
594
|
+
const l = a.padding * r, h = a.radius * r, c = -l, u = -l, p = s + l * 2, g = o + l * 2;
|
|
595
|
+
h > 0 && typeof t.roundRect == "function" ? t.roundRect(c, u, p, g, h) : typeof t.rect == "function" && t.rect(c, u, p, g), this._fillTextEffectGraphics(t, a.color, a.opacity);
|
|
596
|
+
const m = this._createTextBlurFilter(e, a.blur * r);
|
|
597
597
|
t.filters = m ? [m] : null;
|
|
598
598
|
}
|
|
599
599
|
_fitTextDisplayObjectToRect(e, t, i) {
|
|
600
600
|
var m, b;
|
|
601
|
-
const
|
|
602
|
-
e.x =
|
|
603
|
-
const
|
|
604
|
-
if (
|
|
601
|
+
const r = this._normalizeTextBox(t), s = i.x + r.x * i.width, o = i.y + r.y * i.height, n = r.width * i.width, a = r.height * i.height, l = Number((m = this.originalTexture) == null ? void 0 : m.width) || i.width, h = l > 0 ? i.width / l : 1, c = this._textEffectsForLayer(t);
|
|
602
|
+
e.x = s, e.y = o, e.rotation = this._normalizeDegrees(Number((b = t == null ? void 0 : t.transform) == null ? void 0 : b.rotation) || 0) * Math.PI / 180, e.blendMode = this._textBlendMode(t), e.__textBox = r, e.__textLayout = { x: s, y: o, width: n, height: a, scale: h };
|
|
603
|
+
const u = e.__textObject || e, p = e.__textMask || null, g = e.__textEffectMask || null;
|
|
604
|
+
if (u.text = this._textContentForLayer(t), u.style = this._textStyleForLayer(t, h, n), u.x = 0, u.y = 0, u.rotation = 0, p && typeof p.clear == "function" && typeof p.rect == "function" && typeof p.fill == "function" && (p.clear(), p.rect(0, 0, n, a).fill(16777215), u.mask = p), g && typeof g.clear == "function" && typeof g.rect == "function" && typeof g.fill == "function") {
|
|
605
605
|
const C = this._textEffectPadding(c, h);
|
|
606
|
-
|
|
606
|
+
g.clear(), g.rect(-C, -C, n + C * 2, a + C * 2).fill(16777215);
|
|
607
607
|
}
|
|
608
|
-
this._syncTextBackdrop(window.PIXI, e.__textBackdrop, c, h, n, a,
|
|
608
|
+
this._syncTextBackdrop(window.PIXI, e.__textBackdrop, c, h, n, a, g), this._syncTextEffectPrimitive(window.PIXI, e.__textShadow, t, c, "shadow", h, n, g), this._syncTextEffectPrimitive(window.PIXI, e.__textGlow, t, c, "glow", h, n, g);
|
|
609
609
|
}
|
|
610
610
|
_fitDisplayObjectToRect(e, t, i) {
|
|
611
|
-
var c,
|
|
612
|
-
const
|
|
611
|
+
var c, u, p, g, m, b, C, x;
|
|
612
|
+
const r = this._backgroundFillForLayer(t), s = (r == null ? void 0 : r.fit) || "cover";
|
|
613
613
|
if (e.__isTilingBackground) {
|
|
614
|
-
e.x = i.x, e.y = i.y, e.width = i.width, e.height = i.height, (
|
|
614
|
+
e.x = i.x, e.y = i.y, e.width = i.width, e.height = i.height, (u = (c = e.tilePosition) == null ? void 0 : c.set) == null || u.call(c, 0, 0), (g = (p = e.tileScale) == null ? void 0 : p.set) == null || g.call(p, 1, 1);
|
|
615
615
|
return;
|
|
616
616
|
}
|
|
617
|
-
if (
|
|
617
|
+
if (s === "stretch" || (r == null ? void 0 : r.kind) === "gradient" || (r == null ? void 0 : r.kind) === "color") {
|
|
618
618
|
e.x = i.x, e.y = i.y, e.width = i.width, e.height = i.height;
|
|
619
619
|
return;
|
|
620
620
|
}
|
|
621
|
-
const o = Number(e.__sourceWidth || ((m =
|
|
621
|
+
const o = Number(e.__sourceWidth || ((m = r == null ? void 0 : r.source) == null ? void 0 : m.originalWidth) || ((b = e.texture) == null ? void 0 : b.width) || i.width), n = Number(e.__sourceHeight || ((C = r == null ? void 0 : r.source) == null ? void 0 : C.originalHeight) || ((x = e.texture) == null ? void 0 : x.height) || i.height);
|
|
622
622
|
if (!Number.isFinite(o) || !Number.isFinite(n) || o <= 0 || n <= 0) {
|
|
623
623
|
e.x = i.x, e.y = i.y, e.width = i.width, e.height = i.height;
|
|
624
624
|
return;
|
|
625
625
|
}
|
|
626
|
-
const a =
|
|
626
|
+
const a = s === "contain" ? Math.min(i.width / o, i.height / n) : Math.max(i.width / o, i.height / n), l = o * a, h = n * a;
|
|
627
627
|
e.x = i.x + (i.width - l) / 2, e.y = i.y + (i.height - h) / 2, e.width = l, e.height = h;
|
|
628
628
|
}
|
|
629
629
|
_destroyLayerDisplayObjects() {
|
|
630
|
-
var e, t, i,
|
|
630
|
+
var e, t, i, r, s;
|
|
631
631
|
if ((e = this._layerDisplayObjects) != null && e.size) {
|
|
632
632
|
for (const { displayObject: o } of this._layerDisplayObjects.values()) {
|
|
633
633
|
try {
|
|
634
|
-
(
|
|
634
|
+
(r = (i = (t = this.app) == null ? void 0 : t.stage) == null ? void 0 : i.removeChild) == null || r.call(i, o);
|
|
635
635
|
} catch {
|
|
636
636
|
}
|
|
637
637
|
const n = (o == null ? void 0 : o.__ownsTexture) === !0;
|
|
638
|
-
(
|
|
638
|
+
(s = o == null ? void 0 : o.destroy) == null || s.call(o, { children: !0, texture: n, textureSource: n });
|
|
639
639
|
}
|
|
640
640
|
this._layerDisplayObjects.clear(), this._renderableLayerIds = [];
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
643
|
_destroyTransientDisplayObject(e) {
|
|
644
|
-
var i,
|
|
644
|
+
var i, r, s, o;
|
|
645
645
|
if (!e) return;
|
|
646
646
|
try {
|
|
647
|
-
(
|
|
647
|
+
(s = (r = (i = this.app) == null ? void 0 : i.stage) == null ? void 0 : r.removeChild) == null || s.call(r, e);
|
|
648
648
|
} catch {
|
|
649
649
|
}
|
|
650
650
|
const t = (e == null ? void 0 : e.__ownsTexture) === !0;
|
|
@@ -668,13 +668,13 @@ class Te extends re {
|
|
|
668
668
|
* @returns {{ width: number, height: number }}
|
|
669
669
|
*/
|
|
670
670
|
getRotatedBounds(e, t, i) {
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
671
|
+
const r = this._normalizeDegrees(i);
|
|
672
|
+
if (r === 0)
|
|
673
673
|
return {
|
|
674
674
|
width: Math.max(1, Math.round(e)),
|
|
675
675
|
height: Math.max(1, Math.round(t))
|
|
676
676
|
};
|
|
677
|
-
const
|
|
677
|
+
const s = r * Math.PI / 180, o = Math.abs(Math.cos(s)), n = Math.abs(Math.sin(s)), a = o < 1e-10 ? 0 : o, l = n < 1e-10 ? 0 : n;
|
|
678
678
|
return {
|
|
679
679
|
width: Math.max(1, Math.ceil(e * a + t * l)),
|
|
680
680
|
height: Math.max(1, Math.ceil(e * l + t * a))
|
|
@@ -694,9 +694,9 @@ class Te extends re {
|
|
|
694
694
|
if (t === 0) return !0;
|
|
695
695
|
if (!((m = this.app) != null && m.renderer) || !this.originalTexture || !this.sprite)
|
|
696
696
|
return !1;
|
|
697
|
-
const i = window.PIXI,
|
|
698
|
-
if (
|
|
699
|
-
const { width: o, height: n } = this.getRotatedBounds(
|
|
697
|
+
const i = window.PIXI, r = Math.round(this.originalTexture.width), s = Math.round(this.originalTexture.height);
|
|
698
|
+
if (r <= 0 || s <= 0) return !1;
|
|
699
|
+
const { width: o, height: n } = this.getRotatedBounds(r, s, t), a = t * Math.PI / 180, l = new i.Container(), h = new i.Sprite(this.originalTexture);
|
|
700
700
|
(C = (b = h.anchor) == null ? void 0 : b.set) == null || C.call(b, 0.5), h.x = o / 2, h.y = n / 2, h.rotation = a, l.addChild(h);
|
|
701
701
|
const c = i.RenderTexture.create({ width: o, height: n, resolution: 1 });
|
|
702
702
|
try {
|
|
@@ -711,10 +711,10 @@ class Te extends re {
|
|
|
711
711
|
} finally {
|
|
712
712
|
l.removeChildren(), h.destroy({ children: !1, texture: !1, textureSource: !1 }), l.destroy({ children: !1 });
|
|
713
713
|
}
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
const
|
|
717
|
-
return
|
|
714
|
+
const u = this.originalTexture, p = Array.isArray(this.sprite.filters) ? [...this.sprite.filters] : null;
|
|
715
|
+
u && u !== this.baseTexture && u.destroy(!0), this.originalTexture = c, this._lastExportDimensions = null, this.app.stage.removeChild(this.sprite), this.sprite.destroy({ children: !1, texture: !1, textureSource: !1 });
|
|
716
|
+
const g = new i.Sprite(c);
|
|
717
|
+
return p != null && p.length && (g.filters = p), this.app.stage.addChild(g), this.sprite = g, this.fitScale = this.getFitScaleFor(c), this.zoom = 1, this.applyViewTransform({ keepCenter: !1 }), this.render(), this.emit("textureRotated", { width: o, height: n, degrees: t }), !0;
|
|
718
718
|
}
|
|
719
719
|
/**
|
|
720
720
|
* Export the current image with filters applied.
|
|
@@ -728,7 +728,7 @@ class Te extends re {
|
|
|
728
728
|
* to keep the export under that cap while preserving aspect ratio.
|
|
729
729
|
* @returns {string|null} Data URL
|
|
730
730
|
*/
|
|
731
|
-
exportImage(e = "png", t = 0.92, i = 0,
|
|
731
|
+
exportImage(e = "png", t = 0.92, i = 0, r = !0, s = 0) {
|
|
732
732
|
var F;
|
|
733
733
|
if (!((F = this.app) != null && F.renderer) || !this.originalTexture || !this.sprite)
|
|
734
734
|
return null;
|
|
@@ -738,12 +738,12 @@ class Te extends re {
|
|
|
738
738
|
const l = this.sprite.width, h = this.sprite.height;
|
|
739
739
|
if (l <= 0 || h <= 0)
|
|
740
740
|
return null;
|
|
741
|
-
const c = l / n,
|
|
742
|
-
if (!
|
|
741
|
+
const c = l / n, u = c > 0 ? 1 / c : 1, p = this._layerDocument, g = p && Array.isArray(p.layers), m = [];
|
|
742
|
+
if (!g && Array.isArray(this.sprite.filters)) {
|
|
743
743
|
for (const y of this.sprite.filters)
|
|
744
744
|
if (y)
|
|
745
745
|
if (typeof y.createExportFilter == "function") {
|
|
746
|
-
const w = y.createExportFilter({ previewToNativeScale:
|
|
746
|
+
const w = y.createExportFilter({ previewToNativeScale: u });
|
|
747
747
|
w && m.push(w);
|
|
748
748
|
} else
|
|
749
749
|
m.push(y);
|
|
@@ -759,7 +759,7 @@ class Te extends re {
|
|
|
759
759
|
const v = new o.Sprite(this.originalTexture);
|
|
760
760
|
v.x = y, v.y = y, v.scale.set(1, 1), v.alpha = _ ? this._layerOpacity(_) : 1, _ && this._applyLayerFilterInstances(v, _, {
|
|
761
761
|
forExport: !0,
|
|
762
|
-
previewToNativeScale:
|
|
762
|
+
previewToNativeScale: u,
|
|
763
763
|
sourceWidth: n,
|
|
764
764
|
sourceHeight: a
|
|
765
765
|
}), m.length > 0 && (v.filters = m, v.filterArea = new o.Rectangle(0, 0, n, a)), k.addChild(v), N.push(v);
|
|
@@ -768,9 +768,9 @@ class Te extends re {
|
|
|
768
768
|
const v = (R = this._layerDisplayObjects.get(_.id)) == null ? void 0 : R.displayObject, I = (v == null ? void 0 : v.texture) || (this._isSubjectLayer(_) ? this.originalTexture : null);
|
|
769
769
|
if (!I || typeof o.Sprite != "function") return !1;
|
|
770
770
|
const D = new o.Sprite(I);
|
|
771
|
-
return D.__sourceWidth = Number(((K = _.source) == null ? void 0 : K.originalWidth) || (v == null ? void 0 : v.__sourceWidth) || I.width || n), D.__sourceHeight = Number(((Y = _.source) == null ? void 0 : Y.originalHeight) || (v == null ? void 0 : v.__sourceHeight) || I.height || a), this._fitDisplayObjectToRect(D, _, { x: y, y, width: n, height: a }), D.alpha = this._layerOpacity(_), !
|
|
771
|
+
return D.__sourceWidth = Number(((K = _.source) == null ? void 0 : K.originalWidth) || (v == null ? void 0 : v.__sourceWidth) || I.width || n), D.__sourceHeight = Number(((Y = _.source) == null ? void 0 : Y.originalHeight) || (v == null ? void 0 : v.__sourceHeight) || I.height || a), this._fitDisplayObjectToRect(D, _, { x: y, y, width: n, height: a }), D.alpha = this._layerOpacity(_), !g && this._isSubjectLayer(_) && m.length > 0 && (D.filters = m, D.filterArea = new o.Rectangle(0, 0, n, a)), this._applyLayerEffects(o, D, _), this._applyLayerFilterInstances(D, _, {
|
|
772
772
|
forExport: !0,
|
|
773
|
-
previewToNativeScale:
|
|
773
|
+
previewToNativeScale: u,
|
|
774
774
|
sourceWidth: n,
|
|
775
775
|
sourceHeight: a
|
|
776
776
|
}), k.addChild(D), N.push(D), !0;
|
|
@@ -791,14 +791,14 @@ class Te extends re {
|
|
|
791
791
|
}
|
|
792
792
|
return R ? (R.alpha = this._layerOpacity(_), this._applyLayerEffects(o, R, _), this._applyLayerFilterInstances(R, _, {
|
|
793
793
|
forExport: !0,
|
|
794
|
-
previewToNativeScale:
|
|
794
|
+
previewToNativeScale: u,
|
|
795
795
|
sourceWidth: n,
|
|
796
796
|
sourceHeight: a
|
|
797
797
|
}), k.addChild(R), N.push(R), !0) : !1;
|
|
798
798
|
}, z = (_) => {
|
|
799
799
|
const v = this._createTextDisplayObjectForLayer(o, _);
|
|
800
800
|
return v ? (this._fitTextDisplayObjectToRect(v, _, { x: y, y, width: n, height: a }), v.alpha = this._layerOpacity(_), k.addChild(v), N.push(v), !0) : !1;
|
|
801
|
-
}, V =
|
|
801
|
+
}, V = p, q = g;
|
|
802
802
|
if (q) {
|
|
803
803
|
for (const _ of V.layers)
|
|
804
804
|
if (!(!_ || _.visible === !1)) {
|
|
@@ -871,7 +871,7 @@ class Te extends re {
|
|
|
871
871
|
return null;
|
|
872
872
|
let w = B(y.canvas, y.width, y.height);
|
|
873
873
|
if (!w)
|
|
874
|
-
if (
|
|
874
|
+
if (g && y.childCount === 0)
|
|
875
875
|
w = {
|
|
876
876
|
x: y.margin,
|
|
877
877
|
y: y.margin,
|
|
@@ -892,10 +892,10 @@ class Te extends re {
|
|
|
892
892
|
if (i > 0) {
|
|
893
893
|
const M = Math.max(S, k);
|
|
894
894
|
let T = i / M;
|
|
895
|
-
|
|
895
|
+
r && (T = Math.min(1, T)), S = Math.max(1, Math.round(S * T)), k = Math.max(1, Math.round(k * T));
|
|
896
896
|
}
|
|
897
|
-
if (
|
|
898
|
-
const M = Math.sqrt(
|
|
897
|
+
if (s > 0 && S * k > s) {
|
|
898
|
+
const M = Math.sqrt(s / (S * k));
|
|
899
899
|
S = Math.max(1, Math.floor(S * M)), k = Math.max(1, Math.floor(k * M));
|
|
900
900
|
}
|
|
901
901
|
const N = document.createElement("canvas");
|
|
@@ -931,17 +931,17 @@ class Te extends re {
|
|
|
931
931
|
if (this._lastExportDimensions)
|
|
932
932
|
return { ...this._lastExportDimensions };
|
|
933
933
|
const e = this.originalTexture, t = Math.round((e == null ? void 0 : e.width) || 0), i = Math.round((e == null ? void 0 : e.height) || 0);
|
|
934
|
-
let
|
|
935
|
-
const
|
|
936
|
-
if (Array.isArray(
|
|
937
|
-
for (const n of
|
|
934
|
+
let r = 0;
|
|
935
|
+
const s = (o = this.sprite) == null ? void 0 : o.filters;
|
|
936
|
+
if (Array.isArray(s))
|
|
937
|
+
for (const n of s) {
|
|
938
938
|
if (!n) continue;
|
|
939
939
|
const a = typeof n._exportPadding == "number" ? n._exportPadding : typeof n.padding == "number" ? n.padding : 0;
|
|
940
|
-
a >
|
|
940
|
+
a > r && (r = a);
|
|
941
941
|
}
|
|
942
942
|
return {
|
|
943
|
-
width: t + 2 *
|
|
944
|
-
height: i + 2 *
|
|
943
|
+
width: t + 2 * r,
|
|
944
|
+
height: i + 2 * r
|
|
945
945
|
};
|
|
946
946
|
}
|
|
947
947
|
/**
|
|
@@ -952,15 +952,15 @@ class Te extends re {
|
|
|
952
952
|
* @returns {Promise<{ blob: Blob, width: number, height: number } | null>}
|
|
953
953
|
*/
|
|
954
954
|
async exportBlob(e = "png", t = 0.92, i = {}) {
|
|
955
|
-
const
|
|
955
|
+
const r = this.exportImage(
|
|
956
956
|
e,
|
|
957
957
|
t,
|
|
958
958
|
i.maxEdge ?? 0,
|
|
959
959
|
i.dontUpscale !== !1,
|
|
960
960
|
i.maxPixels ?? 0
|
|
961
961
|
);
|
|
962
|
-
if (!
|
|
963
|
-
const o = await (await fetch(
|
|
962
|
+
if (!r) return null;
|
|
963
|
+
const o = await (await fetch(r)).blob(), n = this.getExportDimensions();
|
|
964
964
|
return { blob: o, width: n.width, height: n.height };
|
|
965
965
|
}
|
|
966
966
|
/**
|
|
@@ -968,15 +968,15 @@ class Te extends re {
|
|
|
968
968
|
* @param {HTMLElement} container
|
|
969
969
|
*/
|
|
970
970
|
resizeTo(e) {
|
|
971
|
-
var
|
|
972
|
-
if (!((
|
|
971
|
+
var r;
|
|
972
|
+
if (!((r = this.app) != null && r.renderer) || !e) return;
|
|
973
973
|
const t = e.clientWidth, i = e.clientHeight;
|
|
974
974
|
if (!(t === Math.round(this.app.screen.width) && i === Math.round(this.app.screen.height)) && !(t <= 0 || i <= 0) && (this.app.renderer.resize(t, i), this.originalTexture && this.sprite)) {
|
|
975
|
-
const
|
|
975
|
+
const s = {
|
|
976
976
|
x: this.sprite.x + this.sprite.width / 2,
|
|
977
977
|
y: this.sprite.y + this.sprite.height / 2
|
|
978
978
|
};
|
|
979
|
-
this.fitScale = this.getFitScaleFor(this.originalTexture), this.applyViewTransform({ center:
|
|
979
|
+
this.fitScale = this.getFitScaleFor(this.originalTexture), this.applyViewTransform({ center: s });
|
|
980
980
|
}
|
|
981
981
|
}
|
|
982
982
|
/**
|
|
@@ -1080,14 +1080,14 @@ const _e = '<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none"
|
|
|
1080
1080
|
icon: be
|
|
1081
1081
|
}
|
|
1082
1082
|
], Ke = Object.fromEntries(
|
|
1083
|
-
ue.filter((
|
|
1083
|
+
ue.filter((f) => Array.isArray(f.registryCategories) && f.registryCategories.length > 0).map((f) => [f.id, f.registryCategories])
|
|
1084
1084
|
), Ye = Object.fromEntries(
|
|
1085
|
-
ue.filter((
|
|
1085
|
+
ue.filter((f) => Array.isArray(f.registryCategories)).flatMap((f) => f.registryCategories.map((e) => [e, f.id]))
|
|
1086
1086
|
);
|
|
1087
|
-
function Je(
|
|
1088
|
-
return Ke[
|
|
1087
|
+
function Je(f) {
|
|
1088
|
+
return Ke[f] || [f];
|
|
1089
1089
|
}
|
|
1090
|
-
class Qe extends
|
|
1090
|
+
class Qe extends se {
|
|
1091
1091
|
constructor(e, t) {
|
|
1092
1092
|
super(), this.state = e, this.renderer = t, this.instances = {}, this._filterRegistry = null;
|
|
1093
1093
|
}
|
|
@@ -1097,7 +1097,7 @@ class Qe extends re {
|
|
|
1097
1097
|
*/
|
|
1098
1098
|
setRegistry(e) {
|
|
1099
1099
|
var t, i;
|
|
1100
|
-
this._filterRegistry = e, (i = (t = this.renderer) == null ? void 0 : t.setLayerFilterFactory) == null || i.call(t, (
|
|
1100
|
+
this._filterRegistry = e, (i = (t = this.renderer) == null ? void 0 : t.setLayerFilterFactory) == null || i.call(t, (r, s) => this.createFiltersForLayer(r, s));
|
|
1101
1101
|
}
|
|
1102
1102
|
/**
|
|
1103
1103
|
* Get filter definition by ID
|
|
@@ -1123,11 +1123,11 @@ class Qe extends re {
|
|
|
1123
1123
|
*/
|
|
1124
1124
|
getFiltersByCategory(e) {
|
|
1125
1125
|
if (!this._filterRegistry) return [];
|
|
1126
|
-
const t = Je(e), i = [],
|
|
1127
|
-
for (const
|
|
1128
|
-
const o = this._filterRegistry.getFiltersByCategory(
|
|
1126
|
+
const t = Je(e), i = [], r = /* @__PURE__ */ new Set();
|
|
1127
|
+
for (const s of t) {
|
|
1128
|
+
const o = this._filterRegistry.getFiltersByCategory(s) || [];
|
|
1129
1129
|
for (const n of o)
|
|
1130
|
-
|
|
1130
|
+
r.has(n.id) || (r.add(n.id), i.push(n));
|
|
1131
1131
|
}
|
|
1132
1132
|
return i;
|
|
1133
1133
|
}
|
|
@@ -1151,12 +1151,12 @@ class Qe extends re {
|
|
|
1151
1151
|
if (!t.includes(".") && !t.includes("["))
|
|
1152
1152
|
return e[t];
|
|
1153
1153
|
const i = t.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1154
|
-
let
|
|
1155
|
-
for (const
|
|
1156
|
-
if (
|
|
1157
|
-
|
|
1154
|
+
let r = e;
|
|
1155
|
+
for (const s of i) {
|
|
1156
|
+
if (r == null) return;
|
|
1157
|
+
r = r[s];
|
|
1158
1158
|
}
|
|
1159
|
-
return
|
|
1159
|
+
return r;
|
|
1160
1160
|
}
|
|
1161
1161
|
/**
|
|
1162
1162
|
* Set a deep property on an object
|
|
@@ -1170,14 +1170,14 @@ class Qe extends re {
|
|
|
1170
1170
|
e[t] = i;
|
|
1171
1171
|
return;
|
|
1172
1172
|
}
|
|
1173
|
-
const
|
|
1174
|
-
let
|
|
1175
|
-
for (let n = 0; n <
|
|
1176
|
-
const a =
|
|
1177
|
-
if (!(a in
|
|
1173
|
+
const r = t.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1174
|
+
let s = e;
|
|
1175
|
+
for (let n = 0; n < r.length - 1; n++) {
|
|
1176
|
+
const a = r[n];
|
|
1177
|
+
if (!(a in s) || (s = s[a], s == null)) return;
|
|
1178
1178
|
}
|
|
1179
|
-
const o =
|
|
1180
|
-
|
|
1179
|
+
const o = r[r.length - 1];
|
|
1180
|
+
s[o] = i;
|
|
1181
1181
|
}
|
|
1182
1182
|
/**
|
|
1183
1183
|
* Initialize filter values from definition defaults.
|
|
@@ -1189,12 +1189,12 @@ class Qe extends re {
|
|
|
1189
1189
|
initializeValues(e, t = void 0) {
|
|
1190
1190
|
const i = this.getFilterDef(e);
|
|
1191
1191
|
if (!i) return;
|
|
1192
|
-
const
|
|
1192
|
+
const r = this.state.getFilterValues(e), s = new Set((i.controls || []).map((o) => o.id));
|
|
1193
1193
|
if (i.defaultParams)
|
|
1194
1194
|
for (const [o, n] of Object.entries(i.defaultParams))
|
|
1195
|
-
!
|
|
1195
|
+
!s.has(o) && !(o in r) && this.state.setFilterValue(e, o, n, t);
|
|
1196
1196
|
i.controls && i.controls.forEach((o) => {
|
|
1197
|
-
o.id in
|
|
1197
|
+
o.id in r || this.state.setFilterValue(e, o.id, o.default, t);
|
|
1198
1198
|
});
|
|
1199
1199
|
}
|
|
1200
1200
|
/**
|
|
@@ -1205,12 +1205,12 @@ class Qe extends re {
|
|
|
1205
1205
|
resetValues(e, t = void 0) {
|
|
1206
1206
|
const i = this.getFilterDef(e);
|
|
1207
1207
|
if (!i) return;
|
|
1208
|
-
const
|
|
1208
|
+
const r = new Set((i.controls || []).map((s) => s.id));
|
|
1209
1209
|
if (i.defaultParams)
|
|
1210
|
-
for (const [
|
|
1211
|
-
|
|
1212
|
-
i.controls && i.controls.forEach((
|
|
1213
|
-
this.state.setFilterValue(e,
|
|
1210
|
+
for (const [s, o] of Object.entries(i.defaultParams))
|
|
1211
|
+
r.has(s) || this.state.setFilterValue(e, s, o, t);
|
|
1212
|
+
i.controls && i.controls.forEach((s) => {
|
|
1213
|
+
this.state.setFilterValue(e, s.id, s.default, t);
|
|
1214
1214
|
});
|
|
1215
1215
|
}
|
|
1216
1216
|
/**
|
|
@@ -1242,25 +1242,25 @@ class Qe extends re {
|
|
|
1242
1242
|
* @param {*} value
|
|
1243
1243
|
* @returns {boolean} True if updated in-place, false if caller must recreate
|
|
1244
1244
|
*/
|
|
1245
|
-
updateValue(e, t, i,
|
|
1246
|
-
const
|
|
1247
|
-
if (!this._matchesExpectedFilterLayer(
|
|
1248
|
-
const o = this.getFilterDef(e), n = o == null ? void 0 : o.controls.find((
|
|
1249
|
-
if (!a && this.state.setFilterValue(e, t,
|
|
1245
|
+
updateValue(e, t, i, r = void 0) {
|
|
1246
|
+
const s = this._normalizeValue(i);
|
|
1247
|
+
if (!this._matchesExpectedFilterLayer(r)) return !1;
|
|
1248
|
+
const o = this.getFilterDef(e), n = o == null ? void 0 : o.controls.find((u) => u.id === t), a = !n && (t.includes("[") || t.includes("."));
|
|
1249
|
+
if (!a && this.state.setFilterValue(e, t, s, r) === !1)
|
|
1250
1250
|
return !1;
|
|
1251
1251
|
const l = this.instances[e];
|
|
1252
1252
|
if (!l) return !1;
|
|
1253
1253
|
const h = (n == null ? void 0 : n.property) || t;
|
|
1254
1254
|
if (typeof l.updateUIParam == "function") {
|
|
1255
|
-
if (l.updateUIParam(h,
|
|
1256
|
-
const
|
|
1257
|
-
for (const [
|
|
1258
|
-
this.state.setFilterValue(e,
|
|
1255
|
+
if (l.updateUIParam(h, s), a && typeof l.getSerializableParams == "function") {
|
|
1256
|
+
const u = l.getSerializableParams();
|
|
1257
|
+
for (const [p, g] of Object.entries(u))
|
|
1258
|
+
this.state.setFilterValue(e, p, g, r);
|
|
1259
1259
|
}
|
|
1260
1260
|
return !0;
|
|
1261
1261
|
}
|
|
1262
1262
|
const c = this._getDeepProp(l, h);
|
|
1263
|
-
return typeof c == "function" ? !1 : l.uniforms && h in l.uniforms ? (l.uniforms[h] =
|
|
1263
|
+
return typeof c == "function" ? !1 : l.uniforms && h in l.uniforms ? (l.uniforms[h] = s, !0) : c !== void 0 ? (this._setDeepProp(l, h, s), !0) : !1;
|
|
1264
1264
|
}
|
|
1265
1265
|
/**
|
|
1266
1266
|
* Perform a filter action (e.g. addColorStop, removeColorStop) and sync
|
|
@@ -1273,11 +1273,11 @@ class Qe extends re {
|
|
|
1273
1273
|
*/
|
|
1274
1274
|
performFilterAction(e, t, i = void 0) {
|
|
1275
1275
|
if (!this._matchesExpectedFilterLayer(i)) return !1;
|
|
1276
|
-
const
|
|
1277
|
-
if (!
|
|
1278
|
-
if (
|
|
1279
|
-
const
|
|
1280
|
-
for (const [o, n] of Object.entries(
|
|
1276
|
+
const r = this.instances[e];
|
|
1277
|
+
if (!r || typeof r.updateUIParam != "function") return !1;
|
|
1278
|
+
if (r.updateUIParam(t, !0), typeof r.getSerializableParams == "function") {
|
|
1279
|
+
const s = r.getSerializableParams();
|
|
1280
|
+
for (const [o, n] of Object.entries(s))
|
|
1281
1281
|
this.state.setFilterValue(e, o, n, i);
|
|
1282
1282
|
}
|
|
1283
1283
|
return this.applyFilters(), this.emit("filterActionPerformed", { filterId: e, action: t }), !0;
|
|
@@ -1295,27 +1295,27 @@ class Qe extends re {
|
|
|
1295
1295
|
return e && e.version === 2 && Array.isArray(e.layers) ? e : null;
|
|
1296
1296
|
}
|
|
1297
1297
|
_sourceDimensionsForLayer(e, t = {}) {
|
|
1298
|
-
var
|
|
1299
|
-
const i = (e == null ? void 0 : e.source) || ((
|
|
1298
|
+
var r, s, o, n, a, l, h, c, u;
|
|
1299
|
+
const i = (e == null ? void 0 : e.source) || ((r = e == null ? void 0 : e.fill) == null ? void 0 : r.source) || null;
|
|
1300
1300
|
return {
|
|
1301
|
-
width: Math.round(Number(t.sourceWidth || (i == null ? void 0 : i.originalWidth) || ((o = (
|
|
1302
|
-
height: Math.round(Number(t.sourceHeight || (i == null ? void 0 : i.originalHeight) || ((h = (l = this.renderer) == null ? void 0 : l.originalTexture) == null ? void 0 : h.height) || ((
|
|
1301
|
+
width: Math.round(Number(t.sourceWidth || (i == null ? void 0 : i.originalWidth) || ((o = (s = this.renderer) == null ? void 0 : s.originalTexture) == null ? void 0 : o.width) || ((a = (n = this.renderer) == null ? void 0 : n.sprite) == null ? void 0 : a.width) || 0)),
|
|
1302
|
+
height: Math.round(Number(t.sourceHeight || (i == null ? void 0 : i.originalHeight) || ((h = (l = this.renderer) == null ? void 0 : l.originalTexture) == null ? void 0 : h.height) || ((u = (c = this.renderer) == null ? void 0 : c.sprite) == null ? void 0 : u.height) || 0))
|
|
1303
1303
|
};
|
|
1304
1304
|
}
|
|
1305
1305
|
_paramsForFilterState(e, t, i) {
|
|
1306
|
-
const
|
|
1306
|
+
const r = t != null && t.values && typeof t.values == "object" ? t.values : {}, s = e.defaultParams ? { ...e.defaultParams } : {};
|
|
1307
1307
|
e.controls && Array.isArray(e.controls) && e.controls.forEach((n) => {
|
|
1308
1308
|
const a = n.property || n.id;
|
|
1309
|
-
|
|
1309
|
+
s[a] = r[n.id] ?? n.default;
|
|
1310
1310
|
});
|
|
1311
1311
|
const o = new Set((e.controls || []).map((n) => n.id));
|
|
1312
|
-
for (const [n, a] of Object.entries(
|
|
1313
|
-
o.has(n) || (
|
|
1314
|
-
return
|
|
1312
|
+
for (const [n, a] of Object.entries(r))
|
|
1313
|
+
o.has(n) || (s[n] = a);
|
|
1314
|
+
return s._sourceWidth = i.width, s._sourceHeight = i.height, s;
|
|
1315
1315
|
}
|
|
1316
1316
|
createFiltersForLayer(e, t = {}) {
|
|
1317
1317
|
if (!Array.isArray(e == null ? void 0 : e.filters) || e.filters.length === 0) return [];
|
|
1318
|
-
const i = [],
|
|
1318
|
+
const i = [], r = this.state.get("activeLayerId"), s = e.id === r && t.forExport !== !0, o = this._sourceDimensionsForLayer(e, t);
|
|
1319
1319
|
for (const n of e.filters)
|
|
1320
1320
|
if (!(!n || n.enabled === !1 || typeof n.id != "string"))
|
|
1321
1321
|
try {
|
|
@@ -1326,7 +1326,7 @@ class Qe extends re {
|
|
|
1326
1326
|
let h = l;
|
|
1327
1327
|
t.forExport === !0 && typeof l.createExportFilter == "function" && (h = l.createExportFilter({
|
|
1328
1328
|
previewToNativeScale: t.previewToNativeScale || 1
|
|
1329
|
-
}) || l), i.push(h),
|
|
1329
|
+
}) || l), i.push(h), s && (this.instances[n.id] = l);
|
|
1330
1330
|
} catch {
|
|
1331
1331
|
}
|
|
1332
1332
|
return i;
|
|
@@ -1338,56 +1338,56 @@ class Qe extends re {
|
|
|
1338
1338
|
* PIXI v8's filter pipeline correctly processes changes.
|
|
1339
1339
|
*/
|
|
1340
1340
|
applyFilters() {
|
|
1341
|
-
var o, n, a, l, h, c,
|
|
1341
|
+
var o, n, a, l, h, c, u;
|
|
1342
1342
|
const e = this._layerDocument();
|
|
1343
1343
|
if (e) {
|
|
1344
|
-
for (const
|
|
1345
|
-
delete this.instances[
|
|
1346
|
-
(n = (o = this.renderer) == null ? void 0 : o.setLayerFilterFactory) == null || n.call(o, (
|
|
1347
|
-
const
|
|
1344
|
+
for (const g in this.instances)
|
|
1345
|
+
delete this.instances[g];
|
|
1346
|
+
(n = (o = this.renderer) == null ? void 0 : o.setLayerFilterFactory) == null || n.call(o, (g, m) => this.createFiltersForLayer(g, m));
|
|
1347
|
+
const p = (l = (a = this.renderer) == null ? void 0 : a.applyLayerFilters) == null ? void 0 : l.call(a, e);
|
|
1348
1348
|
this.emit("filtersApplied", {
|
|
1349
1349
|
count: ((h = this.state.get("activeFilters")) == null ? void 0 : h.size) ?? 0,
|
|
1350
1350
|
failed: [],
|
|
1351
1351
|
scopedToLayer: !0
|
|
1352
|
-
}),
|
|
1352
|
+
}), p || (u = (c = this.renderer) == null ? void 0 : c.render) == null || u.call(c);
|
|
1353
1353
|
return;
|
|
1354
1354
|
}
|
|
1355
1355
|
const t = this.renderer.sprite;
|
|
1356
1356
|
if (!t) return;
|
|
1357
|
-
for (const
|
|
1358
|
-
delete this.instances[
|
|
1359
|
-
const i = [],
|
|
1360
|
-
this.state.get("activeFilters").forEach((
|
|
1357
|
+
for (const p in this.instances)
|
|
1358
|
+
delete this.instances[p];
|
|
1359
|
+
const i = [], r = [];
|
|
1360
|
+
this.state.get("activeFilters").forEach((p) => {
|
|
1361
1361
|
try {
|
|
1362
|
-
const
|
|
1363
|
-
if (!
|
|
1362
|
+
const g = this.getFilterDef(p);
|
|
1363
|
+
if (!g || !g.createFilter || typeof g.createFilter != "function")
|
|
1364
1364
|
return;
|
|
1365
|
-
const m = this.state.getFilterValues(
|
|
1366
|
-
|
|
1365
|
+
const m = this.state.getFilterValues(p), b = g.defaultParams ? { ...g.defaultParams } : {};
|
|
1366
|
+
g.controls && Array.isArray(g.controls) && g.controls.forEach((F) => {
|
|
1367
1367
|
const J = F.property || F.id;
|
|
1368
1368
|
b[J] = m[F.id] ?? F.default;
|
|
1369
1369
|
});
|
|
1370
|
-
const C = new Set((
|
|
1370
|
+
const C = new Set((g.controls || []).map((F) => F.id));
|
|
1371
1371
|
for (const [F, J] of Object.entries(m))
|
|
1372
1372
|
C.has(F) || (b[F] = J);
|
|
1373
1373
|
const x = this.renderer.sprite, B = this.renderer.originalTexture;
|
|
1374
1374
|
b._sourceWidth = Math.round((B == null ? void 0 : B.width) || (x == null ? void 0 : x.width) || 0), b._sourceHeight = Math.round((B == null ? void 0 : B.height) || (x == null ? void 0 : x.height) || 0);
|
|
1375
|
-
const A =
|
|
1376
|
-
A && (i.push(A), this.instances[
|
|
1375
|
+
const A = g.createFilter(b);
|
|
1376
|
+
A && (i.push(A), this.instances[p] = A);
|
|
1377
1377
|
} catch {
|
|
1378
|
-
|
|
1378
|
+
r.push(p);
|
|
1379
1379
|
}
|
|
1380
1380
|
});
|
|
1381
1381
|
try {
|
|
1382
|
-
t.filters = null, t.filters = i.length ? i : null, this.renderer.render(), this.emit("filtersApplied", { count: i.length, failed:
|
|
1383
|
-
} catch (
|
|
1382
|
+
t.filters = null, t.filters = i.length ? i : null, this.renderer.render(), this.emit("filtersApplied", { count: i.length, failed: r });
|
|
1383
|
+
} catch (p) {
|
|
1384
1384
|
try {
|
|
1385
1385
|
t.filters = null, this.renderer.render();
|
|
1386
1386
|
} catch {
|
|
1387
1387
|
}
|
|
1388
|
-
this.emit("filtersError", { error:
|
|
1388
|
+
this.emit("filtersError", { error: p, failedFilters: r });
|
|
1389
1389
|
}
|
|
1390
|
-
|
|
1390
|
+
r.length > 0;
|
|
1391
1391
|
}
|
|
1392
1392
|
/**
|
|
1393
1393
|
* Reset all filters.
|
|
@@ -1396,8 +1396,8 @@ class Qe extends re {
|
|
|
1396
1396
|
* destroy any applied crop, which is a separate concern.
|
|
1397
1397
|
*/
|
|
1398
1398
|
resetAll(e = void 0) {
|
|
1399
|
-
for (const
|
|
1400
|
-
delete this.instances[
|
|
1399
|
+
for (const r in this.instances)
|
|
1400
|
+
delete this.instances[r];
|
|
1401
1401
|
return this.state.resetFilters(e) === !1 ? !1 : this._layerDocument() ? (this.applyFilters(), this.emit("filtersReset"), !0) : (this.renderer.sprite && (this.renderer.sprite.filters = null), this.renderer.render(), this.emit("filtersReset"), !0);
|
|
1402
1402
|
}
|
|
1403
1403
|
/**
|
|
@@ -1409,7 +1409,7 @@ class Qe extends re {
|
|
|
1409
1409
|
return this.instances[e] || null;
|
|
1410
1410
|
}
|
|
1411
1411
|
}
|
|
1412
|
-
const U = class U extends
|
|
1412
|
+
const U = class U extends se {
|
|
1413
1413
|
constructor(e, t) {
|
|
1414
1414
|
super(), this.state = e, this.renderer = t, this._overlayCanvas = null, this._isDragging = !1, this._dragStart = null, this._dragMode = null, this._startRect = null, this._hoverMode = null, this._lastAutoZoomCheck = 0, this.HANDLE_SIZE = 14, this.EDGE_HIT_PAD = 10, this._onPointerDown = this._handlePointerDown.bind(this), this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerUp = this._handlePointerUp.bind(this);
|
|
1415
1415
|
}
|
|
@@ -1437,9 +1437,9 @@ const U = class U extends re {
|
|
|
1437
1437
|
if (t[e] !== void 0) return t[e];
|
|
1438
1438
|
const i = e.split(":");
|
|
1439
1439
|
if (i.length === 2) {
|
|
1440
|
-
const
|
|
1441
|
-
if (Number.isFinite(
|
|
1442
|
-
return
|
|
1440
|
+
const r = parseFloat(i[0]), s = parseFloat(i[1]);
|
|
1441
|
+
if (Number.isFinite(r) && Number.isFinite(s) && s > 0)
|
|
1442
|
+
return r / s;
|
|
1443
1443
|
}
|
|
1444
1444
|
return null;
|
|
1445
1445
|
}
|
|
@@ -1475,15 +1475,10 @@ const U = class U extends re {
|
|
|
1475
1475
|
if (!e) return;
|
|
1476
1476
|
const t = this.renderer.sprite, i = this.renderer.app;
|
|
1477
1477
|
if (!t || !i) return;
|
|
1478
|
-
const
|
|
1479
|
-
if (r !==
|
|
1480
|
-
const
|
|
1481
|
-
e.width =
|
|
1482
|
-
} else
|
|
1483
|
-
e.width = Math.min(e.width, o.w), e.height = Math.min(e.height, o.h);
|
|
1484
|
-
if (e.x = Math.max(o.x, Math.min(e.x, o.x + o.w - e.width)), e.y = Math.max(o.y, Math.min(e.y, o.y + o.h - e.height)), s !== "free" || this.state.get("crop.aspect") === "1:1") {
|
|
1485
|
-
const n = Math.min(e.width, e.height);
|
|
1486
|
-
e.width = n, e.height = n;
|
|
1478
|
+
const r = this.state.get("crop.shape"), s = { x: 0, y: 0, w: i.screen.width, h: i.screen.height };
|
|
1479
|
+
if (e.x = Math.max(s.x, Math.min(e.x, s.x + s.w - e.width)), e.y = Math.max(s.y, Math.min(e.y, s.y + s.h - e.height)), e.width = Math.min(e.width, s.w), e.height = Math.min(e.height, s.h), r !== "free" || this.state.get("crop.aspect") === "1:1") {
|
|
1480
|
+
const o = Math.min(e.width, e.height);
|
|
1481
|
+
e.width = o, e.height = o;
|
|
1487
1482
|
}
|
|
1488
1483
|
this.state.set("crop.rect", e);
|
|
1489
1484
|
}
|
|
@@ -1500,19 +1495,19 @@ const U = class U extends re {
|
|
|
1500
1495
|
* @param {number} currentZoom - Current zoom level
|
|
1501
1496
|
* @returns {number|null} Target zoom level, or null if no zoom needed
|
|
1502
1497
|
*/
|
|
1503
|
-
static calcAutoZoom(e, t, i,
|
|
1504
|
-
if (!e || !
|
|
1498
|
+
static calcAutoZoom(e, t, i, r, s, o, n) {
|
|
1499
|
+
if (!e || !r || !s || !o) return null;
|
|
1505
1500
|
const a = e.width > t, l = e.height > i;
|
|
1506
1501
|
if (!a && !l) return null;
|
|
1507
1502
|
const h = U.AUTO_ZOOM_PADDING;
|
|
1508
1503
|
let c = n;
|
|
1509
1504
|
if (a) {
|
|
1510
|
-
const
|
|
1511
|
-
c = Math.min(c,
|
|
1505
|
+
const u = e.width / (h * r * o);
|
|
1506
|
+
c = Math.min(c, u);
|
|
1512
1507
|
}
|
|
1513
1508
|
if (l) {
|
|
1514
|
-
const
|
|
1515
|
-
c = Math.min(c,
|
|
1509
|
+
const u = e.height / (h * s * o);
|
|
1510
|
+
c = Math.min(c, u);
|
|
1516
1511
|
}
|
|
1517
1512
|
return c = Math.max(0.1, c), c >= n - 0.01 ? null : c;
|
|
1518
1513
|
}
|
|
@@ -1525,18 +1520,18 @@ const U = class U extends re {
|
|
|
1525
1520
|
const e = Date.now();
|
|
1526
1521
|
if (e - this._lastAutoZoomCheck < U.AUTO_ZOOM_THROTTLE_MS) return;
|
|
1527
1522
|
this._lastAutoZoomCheck = e;
|
|
1528
|
-
const t = this.state.get("crop.rect"), i = this.renderer.sprite,
|
|
1529
|
-
if (!t || !i || !
|
|
1530
|
-
const
|
|
1523
|
+
const t = this.state.get("crop.rect"), i = this.renderer.sprite, r = this.renderer.originalTexture;
|
|
1524
|
+
if (!t || !i || !r) return;
|
|
1525
|
+
const s = U.calcAutoZoom(
|
|
1531
1526
|
t,
|
|
1532
1527
|
i.width,
|
|
1533
1528
|
i.height,
|
|
1534
|
-
|
|
1535
|
-
|
|
1529
|
+
r.width,
|
|
1530
|
+
r.height,
|
|
1536
1531
|
this.renderer.fitScale,
|
|
1537
1532
|
this.renderer.zoom
|
|
1538
1533
|
);
|
|
1539
|
-
|
|
1534
|
+
s !== null && this.renderer.setZoom(s, { keepCenter: !0 });
|
|
1540
1535
|
}
|
|
1541
1536
|
/**
|
|
1542
1537
|
* Draw crop overlay on canvas
|
|
@@ -1546,11 +1541,11 @@ const U = class U extends re {
|
|
|
1546
1541
|
if (!e) return;
|
|
1547
1542
|
const t = this.renderer.app;
|
|
1548
1543
|
if (!t) return;
|
|
1549
|
-
const i = t.canvas,
|
|
1550
|
-
(e.width !== Math.max(1, Math.floor(
|
|
1544
|
+
const i = t.canvas, r = i.clientWidth, s = i.clientHeight, o = window.devicePixelRatio || 1;
|
|
1545
|
+
(e.width !== Math.max(1, Math.floor(r * o)) || e.height !== Math.max(1, Math.floor(s * o))) && (e.width = Math.max(1, Math.floor(r * o)), e.height = Math.max(1, Math.floor(s * o)), e.style.width = r + "px", e.style.height = s + "px");
|
|
1551
1546
|
const n = e.getContext("2d");
|
|
1552
1547
|
if (!n) return;
|
|
1553
|
-
n.setTransform(o, 0, 0, o, 0, 0), n.clearRect(0, 0,
|
|
1548
|
+
n.setTransform(o, 0, 0, o, 0, 0), n.clearRect(0, 0, r, s), n.fillStyle = "rgba(0, 0, 0, 0.5)", n.fillRect(0, 0, r, s);
|
|
1554
1549
|
const a = this.state.get("crop.rect");
|
|
1555
1550
|
if (!a) return;
|
|
1556
1551
|
const l = this.state.get("crop.shape");
|
|
@@ -1569,19 +1564,19 @@ const U = class U extends re {
|
|
|
1569
1564
|
const h = a.width / 3, c = a.height / 3;
|
|
1570
1565
|
for (let b = 1; b <= 2; b++)
|
|
1571
1566
|
n.beginPath(), n.moveTo(a.x + h * b, a.y), n.lineTo(a.x + h * b, a.y + a.height), n.stroke(), n.beginPath(), n.moveTo(a.x, a.y + c * b), n.lineTo(a.x + a.width, a.y + c * b), n.stroke();
|
|
1572
|
-
const
|
|
1567
|
+
const u = this.HANDLE_SIZE, p = [
|
|
1573
1568
|
{ x: a.x, y: a.y, m: "resize-nw" },
|
|
1574
1569
|
{ x: a.x + a.width, y: a.y, m: "resize-ne" },
|
|
1575
1570
|
{ x: a.x, y: a.y + a.height, m: "resize-sw" },
|
|
1576
1571
|
{ x: a.x + a.width, y: a.y + a.height, m: "resize-se" }
|
|
1577
|
-
],
|
|
1572
|
+
], g = [
|
|
1578
1573
|
{ x: a.x + a.width / 2, y: a.y, m: "n" },
|
|
1579
1574
|
{ x: a.x + a.width / 2, y: a.y + a.height, m: "s" },
|
|
1580
1575
|
{ x: a.x, y: a.y + a.height / 2, m: "w" },
|
|
1581
1576
|
{ x: a.x + a.width, y: a.y + a.height / 2, m: "e" }
|
|
1582
|
-
], m = [...
|
|
1577
|
+
], m = [...p, ...g];
|
|
1583
1578
|
for (const b of m) {
|
|
1584
|
-
const C = this._hoverMode === b.m, x = C ?
|
|
1579
|
+
const C = this._hoverMode === b.m, x = C ? u + 4 : u;
|
|
1585
1580
|
n.beginPath(), n.rect(b.x - x / 2, b.y - x / 2, x, x), n.fillStyle = C ? "#4da3ff" : "#ffffff", n.strokeStyle = "rgba(0,0,0,0.6)", n.lineWidth = 1, n.fill(), n.stroke();
|
|
1586
1581
|
}
|
|
1587
1582
|
}
|
|
@@ -1594,8 +1589,8 @@ const U = class U extends re {
|
|
|
1594
1589
|
_hitHandle(e, t) {
|
|
1595
1590
|
const i = this.state.get("crop.rect");
|
|
1596
1591
|
if (!i) return null;
|
|
1597
|
-
const
|
|
1598
|
-
return
|
|
1592
|
+
const r = (s, o, n, a, l) => Math.abs(s - n) <= l && Math.abs(o - a) <= l;
|
|
1593
|
+
return r(e, t, i.x, i.y, this.HANDLE_SIZE) ? "resize-nw" : r(e, t, i.x + i.width, i.y, this.HANDLE_SIZE) ? "resize-ne" : r(e, t, i.x, i.y + i.height, this.HANDLE_SIZE) ? "resize-sw" : r(e, t, i.x + i.width, i.y + i.height, this.HANDLE_SIZE) ? "resize-se" : Math.abs(t - i.y) <= this.EDGE_HIT_PAD && e >= i.x && e <= i.x + i.width ? "n" : Math.abs(t - (i.y + i.height)) <= this.EDGE_HIT_PAD && e >= i.x && e <= i.x + i.width ? "s" : Math.abs(e - i.x) <= this.EDGE_HIT_PAD && t >= i.y && t <= i.y + i.height ? "w" : Math.abs(e - (i.x + i.width)) <= this.EDGE_HIT_PAD && t >= i.y && t <= i.y + i.height ? "e" : e >= i.x && e <= i.x + i.width && t >= i.y && t <= i.y + i.height ? "move" : null;
|
|
1599
1594
|
}
|
|
1600
1595
|
/**
|
|
1601
1596
|
* Handle pointer down event
|
|
@@ -1610,67 +1605,47 @@ const U = class U extends re {
|
|
|
1610
1605
|
* Handle pointer move event
|
|
1611
1606
|
*/
|
|
1612
1607
|
_handlePointerMove(e) {
|
|
1613
|
-
var l, h, c
|
|
1608
|
+
var a, l, h, c;
|
|
1614
1609
|
const t = this.renderer.app;
|
|
1615
1610
|
if (!t) return;
|
|
1616
1611
|
const i = e.global;
|
|
1617
1612
|
if (!this._isDragging || !this._dragStart || !this._startRect) {
|
|
1618
|
-
this._hoverMode = this._hitHandle(i.x, i.y), t.stage.cursor = this._hoverMode === "move" ? "move" : this._hoverMode === "n" || this._hoverMode === "s" ? "ns-resize" : this._hoverMode === "e" || this._hoverMode === "w" ? "ew-resize" : (
|
|
1613
|
+
this._hoverMode = this._hitHandle(i.x, i.y), t.stage.cursor = this._hoverMode === "move" ? "move" : this._hoverMode === "n" || this._hoverMode === "s" ? "ns-resize" : this._hoverMode === "e" || this._hoverMode === "w" ? "ew-resize" : (a = this._hoverMode) != null && a.endsWith("nw") || (l = this._hoverMode) != null && l.endsWith("se") ? "nwse-resize" : (h = this._hoverMode) != null && h.endsWith("ne") || (c = this._hoverMode) != null && c.endsWith("sw") ? "nesw-resize" : "crosshair", this.drawOverlay();
|
|
1619
1614
|
return;
|
|
1620
1615
|
}
|
|
1621
|
-
const
|
|
1622
|
-
if (!
|
|
1623
|
-
const
|
|
1616
|
+
const r = this.state.get("crop.rect");
|
|
1617
|
+
if (!r) return;
|
|
1618
|
+
const s = i.x - this._dragStart.x, o = i.y - this._dragStart.y;
|
|
1624
1619
|
switch (this._dragMode) {
|
|
1625
1620
|
case "move":
|
|
1626
|
-
|
|
1621
|
+
r.x = this._startRect.x + s, r.y = this._startRect.y + o;
|
|
1627
1622
|
break;
|
|
1628
|
-
case "n":
|
|
1629
|
-
|
|
1630
|
-
if (s.y = this._startRect.y + o, s.height = u, n) {
|
|
1631
|
-
const f = u * n;
|
|
1632
|
-
s.x = this._startRect.x + (this._startRect.width - f) / 2, s.width = f;
|
|
1633
|
-
}
|
|
1623
|
+
case "n":
|
|
1624
|
+
r.y = this._startRect.y + o, r.height = this._startRect.height - o;
|
|
1634
1625
|
break;
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
const u = this._startRect.height + o;
|
|
1638
|
-
if (s.height = u, n) {
|
|
1639
|
-
const f = u * n;
|
|
1640
|
-
s.x = this._startRect.x + (this._startRect.width - f) / 2, s.width = f;
|
|
1641
|
-
}
|
|
1626
|
+
case "s":
|
|
1627
|
+
r.height = this._startRect.height + o;
|
|
1642
1628
|
break;
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
const u = this._startRect.width - r;
|
|
1646
|
-
if (s.x = this._startRect.x + r, s.width = u, n) {
|
|
1647
|
-
const f = u / n;
|
|
1648
|
-
s.y = this._startRect.y + (this._startRect.height - f) / 2, s.height = f;
|
|
1649
|
-
}
|
|
1629
|
+
case "w":
|
|
1630
|
+
r.x = this._startRect.x + s, r.width = this._startRect.width - s;
|
|
1650
1631
|
break;
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
const u = this._startRect.width + r;
|
|
1654
|
-
if (s.width = u, n) {
|
|
1655
|
-
const f = u / n;
|
|
1656
|
-
s.y = this._startRect.y + (this._startRect.height - f) / 2, s.height = f;
|
|
1657
|
-
}
|
|
1632
|
+
case "e":
|
|
1633
|
+
r.width = this._startRect.width + s;
|
|
1658
1634
|
break;
|
|
1659
|
-
}
|
|
1660
1635
|
case "resize-nw":
|
|
1661
|
-
|
|
1636
|
+
r.x = this._startRect.x + s, r.y = this._startRect.y + o, r.width = this._startRect.width - s, r.height = this._startRect.height - o;
|
|
1662
1637
|
break;
|
|
1663
1638
|
case "resize-ne":
|
|
1664
|
-
|
|
1639
|
+
r.y = this._startRect.y + o, r.width = this._startRect.width + s, r.height = this._startRect.height - o;
|
|
1665
1640
|
break;
|
|
1666
1641
|
case "resize-sw":
|
|
1667
|
-
|
|
1642
|
+
r.x = this._startRect.x + s, r.width = this._startRect.width - s, r.height = this._startRect.height + o;
|
|
1668
1643
|
break;
|
|
1669
1644
|
case "resize-se":
|
|
1670
|
-
|
|
1645
|
+
r.width = this._startRect.width + s, r.height = this._startRect.height + o;
|
|
1671
1646
|
break;
|
|
1672
1647
|
}
|
|
1673
|
-
|
|
1648
|
+
r.width = Math.max(50, r.width), r.height = Math.max(50, r.height), this.state.set("crop.rect", r), this.state.set("crop.dirty", !0), this.state.get("crop.shape") === "circle" && this.state.get("crop.aspect") !== "1:1" && this.state.set("crop.aspect", "1:1"), this.applyAspectRatio(), this._dragMode !== "move" && this._checkAutoZoom(), this.constrainCropRect(), this.drawOverlay();
|
|
1674
1649
|
}
|
|
1675
1650
|
/**
|
|
1676
1651
|
* Handle pointer up event
|
|
@@ -1690,18 +1665,18 @@ const U = class U extends re {
|
|
|
1690
1665
|
const o = this.state.get("crop.aspect"), n = this._getAspectRatio(o);
|
|
1691
1666
|
let a, l;
|
|
1692
1667
|
if (n) {
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1668
|
+
const u = t.width * 0.9, p = t.height * 0.9;
|
|
1669
|
+
u / p > n ? (l = p, a = l * n) : (a = u, l = a / n);
|
|
1695
1670
|
} else {
|
|
1696
|
-
const
|
|
1697
|
-
a =
|
|
1671
|
+
const u = Math.min(e.screen.width, e.screen.height) * 0.7;
|
|
1672
|
+
a = u, l = u;
|
|
1698
1673
|
}
|
|
1699
1674
|
const h = t.x + (t.width - a) / 2, c = t.y + (t.height - l) / 2;
|
|
1700
1675
|
i = { x: h, y: c, width: a, height: l }, this.state.set("crop.rect", i), o !== "free" && this.constrainCropRect();
|
|
1701
1676
|
}
|
|
1702
1677
|
this.state.set("crop.dirty", !1);
|
|
1703
|
-
const
|
|
1704
|
-
|
|
1678
|
+
const r = e.stage;
|
|
1679
|
+
r.eventMode = "static", r.hitArea = e.screen, r.cursor = "crosshair", r.on("pointerdown", this._onPointerDown), r.on("pointermove", this._onPointerMove), r.on("pointerup", this._onPointerUp), r.on("pointerupoutside", this._onPointerUp), this.state.set("mode", "crop"), this.drawOverlay(), this.emit("enabled");
|
|
1705
1680
|
}
|
|
1706
1681
|
/**
|
|
1707
1682
|
* Disable crop mode
|
|
@@ -1721,20 +1696,20 @@ const U = class U extends re {
|
|
|
1721
1696
|
* @returns {{ texture: PIXI.Texture, preservedZoom: number }|null}
|
|
1722
1697
|
*/
|
|
1723
1698
|
apply() {
|
|
1724
|
-
const e = this.renderer.app, t = this.renderer.sprite, i = this.renderer.originalTexture,
|
|
1725
|
-
if (!
|
|
1726
|
-
const
|
|
1727
|
-
let c = Math.round(Math.max(1,
|
|
1728
|
-
if (c <= 0 ||
|
|
1729
|
-
const m = new
|
|
1699
|
+
const e = this.renderer.app, t = this.renderer.sprite, i = this.renderer.originalTexture, r = this.state.get("crop.rect");
|
|
1700
|
+
if (!r || !t || !e || !i) return null;
|
|
1701
|
+
const s = window.PIXI, o = this.renderer.zoom, n = i.width / t.width, a = i.height / t.height, l = (r.x - t.x) * n, h = (r.y - t.y) * a;
|
|
1702
|
+
let c = Math.round(Math.max(1, r.width * n)), u = Math.round(Math.max(1, r.height * a)), p = Math.round(l), g = Math.round(h);
|
|
1703
|
+
if (c <= 0 || u <= 0) return null;
|
|
1704
|
+
const m = new s.Container(), b = new s.Sprite(i);
|
|
1730
1705
|
if (this.state.get("crop.shape") === "circle") {
|
|
1731
|
-
const k = Math.round(Math.max(c,
|
|
1732
|
-
|
|
1733
|
-
const M = new
|
|
1734
|
-
typeof M.circle == "function" && typeof M.fill == "function" ? M.circle(c / 2,
|
|
1706
|
+
const k = Math.round(Math.max(c, u)), N = p + c / 2, P = g + u / 2;
|
|
1707
|
+
p = Math.round(N - k / 2), g = Math.round(P - k / 2), c = u = k;
|
|
1708
|
+
const M = new s.Graphics();
|
|
1709
|
+
typeof M.circle == "function" && typeof M.fill == "function" ? M.circle(c / 2, u / 2, c / 2).fill(16777215) : (M.beginFill(16777215, 1), M.drawCircle(c / 2, u / 2, c / 2), M.endFill()), b.mask = M, m.addChild(M);
|
|
1735
1710
|
}
|
|
1736
|
-
b.x = -
|
|
1737
|
-
const x =
|
|
1711
|
+
b.x = -p, b.y = -g, m.addChild(b);
|
|
1712
|
+
const x = s.RenderTexture.create({ width: c, height: u });
|
|
1738
1713
|
e.renderer.render({
|
|
1739
1714
|
container: m,
|
|
1740
1715
|
target: x,
|
|
@@ -1742,15 +1717,15 @@ const U = class U extends re {
|
|
|
1742
1717
|
}), m.destroy({ children: !0 });
|
|
1743
1718
|
const B = this.renderer.originalTexture;
|
|
1744
1719
|
B && B !== this.renderer.baseTexture && B.destroy(!0), this.renderer.originalTexture = x, e.stage.removeChild(t), t.destroy();
|
|
1745
|
-
const A = new
|
|
1720
|
+
const A = new s.Sprite(x);
|
|
1746
1721
|
e.stage.addChild(A), this.renderer.sprite = A, this.renderer.fitScale = this.renderer.getFitScaleFor(x), this.renderer.setZoom(o, { keepCenter: !1 }), this.renderer.applyViewTransform(), this.renderer.render();
|
|
1747
1722
|
const F = this.state.get("crop.appliedRect"), y = F && Number.isFinite(F.x) && Number.isFinite(F.y) && Number.isFinite(F.width) && Number.isFinite(F.height) ? {
|
|
1748
|
-
x: Math.round(F.x +
|
|
1749
|
-
y: Math.round(F.y +
|
|
1723
|
+
x: Math.round(F.x + p),
|
|
1724
|
+
y: Math.round(F.y + g),
|
|
1750
1725
|
width: c,
|
|
1751
|
-
height:
|
|
1752
|
-
} : { x:
|
|
1753
|
-
return this.disable(), this.state.set("crop.appliedRect", y), this.state.set("crop.appliedShape", w), this.state.set("crop.appliedAspect", S), this.state.set("crop.dirty", !1), this.emit("applied", { width: c, height:
|
|
1726
|
+
height: u
|
|
1727
|
+
} : { x: p, y: g, width: c, height: u }, w = this.state.get("crop.shape") || "free", S = this.state.get("crop.aspect") || "free";
|
|
1728
|
+
return this.disable(), this.state.set("crop.appliedRect", y), this.state.set("crop.appliedShape", w), this.state.set("crop.appliedAspect", S), this.state.set("crop.dirty", !1), this.emit("applied", { width: c, height: u }), { texture: x, preservedZoom: o };
|
|
1754
1729
|
}
|
|
1755
1730
|
/**
|
|
1756
1731
|
* Apply a crop from saved texture-pixel coordinates (for state rehydration).
|
|
@@ -1760,25 +1735,25 @@ const U = class U extends re {
|
|
|
1760
1735
|
* @returns {{ texture: Object, preservedZoom: number }|null}
|
|
1761
1736
|
*/
|
|
1762
1737
|
applyFromPixelRect(e, t = "free") {
|
|
1763
|
-
const i = this.renderer.app,
|
|
1764
|
-
if (!e || !
|
|
1738
|
+
const i = this.renderer.app, r = this.renderer.sprite, s = this.renderer.originalTexture;
|
|
1739
|
+
if (!e || !r || !i || !s) return null;
|
|
1765
1740
|
const o = window.PIXI, n = this.renderer.zoom;
|
|
1766
1741
|
let a = Math.round(Math.max(1, e.width)), l = Math.round(Math.max(1, e.height)), h = Math.round(e.x), c = Math.round(e.y);
|
|
1767
1742
|
if (a <= 0 || l <= 0) return null;
|
|
1768
|
-
const
|
|
1743
|
+
const u = new o.Container(), p = new o.Sprite(s);
|
|
1769
1744
|
if (t === "circle") {
|
|
1770
1745
|
const C = Math.round(Math.max(a, l)), x = h + a / 2, B = c + l / 2;
|
|
1771
1746
|
h = Math.round(x - C / 2), c = Math.round(B - C / 2), a = l = C;
|
|
1772
1747
|
const A = new o.Graphics();
|
|
1773
|
-
typeof A.circle == "function" && typeof A.fill == "function" ? A.circle(a / 2, l / 2, a / 2).fill(16777215) : (A.beginFill(16777215, 1), A.drawCircle(a / 2, l / 2, a / 2), A.endFill()),
|
|
1748
|
+
typeof A.circle == "function" && typeof A.fill == "function" ? A.circle(a / 2, l / 2, a / 2).fill(16777215) : (A.beginFill(16777215, 1), A.drawCircle(a / 2, l / 2, a / 2), A.endFill()), p.mask = A, u.addChild(A);
|
|
1774
1749
|
}
|
|
1775
|
-
|
|
1776
|
-
const
|
|
1777
|
-
i.renderer.render({ container:
|
|
1750
|
+
p.x = -h, p.y = -c, u.addChild(p);
|
|
1751
|
+
const g = o.RenderTexture.create({ width: a, height: l });
|
|
1752
|
+
i.renderer.render({ container: u, target: g, clear: !0 }), u.destroy({ children: !0 });
|
|
1778
1753
|
const m = this.renderer.originalTexture;
|
|
1779
|
-
m && m !== this.renderer.baseTexture && m.destroy(!0), this.renderer.originalTexture =
|
|
1780
|
-
const b = new o.Sprite(
|
|
1781
|
-
return i.stage.addChild(b), this.renderer.sprite = b, this.renderer.fitScale = this.renderer.getFitScaleFor(
|
|
1754
|
+
m && m !== this.renderer.baseTexture && m.destroy(!0), this.renderer.originalTexture = g, i.stage.removeChild(r), r.destroy();
|
|
1755
|
+
const b = new o.Sprite(g);
|
|
1756
|
+
return i.stage.addChild(b), this.renderer.sprite = b, this.renderer.fitScale = this.renderer.getFitScaleFor(g), this.renderer.setZoom(n, { keepCenter: !1 }), this.renderer.applyViewTransform(), this.renderer.render(), { texture: g, preservedZoom: n };
|
|
1782
1757
|
}
|
|
1783
1758
|
/**
|
|
1784
1759
|
* Cancel crop
|
|
@@ -1882,13 +1857,13 @@ class Xe {
|
|
|
1882
1857
|
* @returns {Promise<{dataUrl: string, model: string, processMs: string}>}
|
|
1883
1858
|
*/
|
|
1884
1859
|
async removeBackground(e, t = {}) {
|
|
1885
|
-
const i = typeof Blob < "u" && t.blob instanceof Blob ? t : await this.preparePreviewRequest(e, t),
|
|
1886
|
-
a.append("image_file",
|
|
1860
|
+
const i = typeof Blob < "u" && t.blob instanceof Blob ? t : await this.preparePreviewRequest(e, t), r = i.blob, s = i.operationId, o = i.sessionKey, n = i.sourceHash, a = new FormData();
|
|
1861
|
+
a.append("image_file", r, "image.png"), a.append("operation_id", s), a.append("session_key", o), a.append("source_hash", n), a.append("tier", i.tier || "balanced"), i.targetRef && a.append("target_ref", i.targetRef), i.model && a.append("model", i.model), i.alpha_matting && (a.append("alpha_matting", "true"), a.append("alpha_f", String(i.alpha_f ?? 10)), a.append("alpha_fr", String(i.alpha_fr ?? 15)), a.append("alpha_erode_size", String(i.alpha_erode_size ?? 10))), i.max_megapixels !== void 0 && a.append("max_megapixels", String(i.max_megapixels));
|
|
1887
1862
|
let l, h;
|
|
1888
|
-
const c = this._createAbortController(),
|
|
1863
|
+
const c = this._createAbortController(), u = (p) => c ? { ...p, signal: c.signal } : p;
|
|
1889
1864
|
try {
|
|
1890
1865
|
try {
|
|
1891
|
-
l = await fetch(this._endpoint,
|
|
1866
|
+
l = await fetch(this._endpoint, u({
|
|
1892
1867
|
method: "POST",
|
|
1893
1868
|
body: a,
|
|
1894
1869
|
credentials: "include"
|
|
@@ -1901,7 +1876,7 @@ class Xe {
|
|
|
1901
1876
|
}
|
|
1902
1877
|
if ((!l || !l.ok) && this._fallbackEndpoint)
|
|
1903
1878
|
try {
|
|
1904
|
-
l = await fetch(this._fallbackEndpoint,
|
|
1879
|
+
l = await fetch(this._fallbackEndpoint, u({
|
|
1905
1880
|
method: "POST",
|
|
1906
1881
|
body: a
|
|
1907
1882
|
}));
|
|
@@ -1921,12 +1896,12 @@ class Xe {
|
|
|
1921
1896
|
}
|
|
1922
1897
|
throw new Error(m);
|
|
1923
1898
|
}
|
|
1924
|
-
const
|
|
1899
|
+
const p = await l.blob();
|
|
1925
1900
|
return {
|
|
1926
|
-
dataUrl: await this._blobToDataUrl(
|
|
1901
|
+
dataUrl: await this._blobToDataUrl(p),
|
|
1927
1902
|
model: l.headers.get("X-Model-Used") || "unknown",
|
|
1928
1903
|
processMs: l.headers.get("X-Process-Ms") || "0",
|
|
1929
|
-
operationId: l.headers.get("X-Operation-Id") ||
|
|
1904
|
+
operationId: l.headers.get("X-Operation-Id") || s,
|
|
1930
1905
|
sessionKey: l.headers.get("X-Session-Key") || o,
|
|
1931
1906
|
sourceHash: l.headers.get("X-Source-Hash") || n,
|
|
1932
1907
|
targetRef: l.headers.get("X-Target-Ref") || i.targetRef || null
|
|
@@ -1957,10 +1932,10 @@ class Xe {
|
|
|
1957
1932
|
tier: e.tier || "balanced"
|
|
1958
1933
|
};
|
|
1959
1934
|
e.model && (i.model = e.model), e.alpha_matting !== void 0 && (i.alpha_matting = !!e.alpha_matting), e.max_megapixels !== void 0 && (i.max_megapixels = Number(e.max_megapixels));
|
|
1960
|
-
const
|
|
1961
|
-
let
|
|
1935
|
+
const r = this._createAbortController();
|
|
1936
|
+
let s;
|
|
1962
1937
|
try {
|
|
1963
|
-
if (
|
|
1938
|
+
if (s = await fetch(t, {
|
|
1964
1939
|
method: "POST",
|
|
1965
1940
|
body: JSON.stringify(i),
|
|
1966
1941
|
credentials: "include",
|
|
@@ -1968,19 +1943,19 @@ class Xe {
|
|
|
1968
1943
|
Accept: "application/json",
|
|
1969
1944
|
"Content-Type": "application/json"
|
|
1970
1945
|
},
|
|
1971
|
-
...
|
|
1972
|
-
}), !
|
|
1973
|
-
let o = `Background removal failed (HTTP ${
|
|
1946
|
+
...r ? { signal: r.signal } : {}
|
|
1947
|
+
}), !s.ok) {
|
|
1948
|
+
let o = `Background removal failed (HTTP ${s.status})`;
|
|
1974
1949
|
try {
|
|
1975
|
-
const n = await
|
|
1950
|
+
const n = await s.json();
|
|
1976
1951
|
n != null && n.message && (o += `: ${n.message}`);
|
|
1977
1952
|
} catch {
|
|
1978
1953
|
}
|
|
1979
1954
|
throw new Error(o);
|
|
1980
1955
|
}
|
|
1981
|
-
return await
|
|
1956
|
+
return await s.json();
|
|
1982
1957
|
} finally {
|
|
1983
|
-
this._releaseAbortController(
|
|
1958
|
+
this._releaseAbortController(r);
|
|
1984
1959
|
}
|
|
1985
1960
|
}
|
|
1986
1961
|
/**
|
|
@@ -1990,7 +1965,7 @@ class Xe {
|
|
|
1990
1965
|
*/
|
|
1991
1966
|
async _dataUrlToBlob(e) {
|
|
1992
1967
|
if (e.startsWith("data:")) {
|
|
1993
|
-
const [i,
|
|
1968
|
+
const [i, r] = e.split(","), s = i.match(/:(.*?);/), o = s ? s[1] : "image/png", n = atob(r), a = new Uint8Array(n.length);
|
|
1994
1969
|
for (let l = 0; l < n.length; l++)
|
|
1995
1970
|
a[l] = n.charCodeAt(l);
|
|
1996
1971
|
return new Blob([a], { type: o });
|
|
@@ -2004,8 +1979,8 @@ class Xe {
|
|
|
2004
1979
|
*/
|
|
2005
1980
|
_blobToDataUrl(e) {
|
|
2006
1981
|
return new Promise((t, i) => {
|
|
2007
|
-
const
|
|
2008
|
-
|
|
1982
|
+
const r = new FileReader();
|
|
1983
|
+
r.onload = () => t(r.result), r.onerror = () => i(new Error("Failed to read blob as data URL")), r.readAsDataURL(e);
|
|
2009
1984
|
});
|
|
2010
1985
|
}
|
|
2011
1986
|
/**
|
|
@@ -2054,61 +2029,61 @@ class Xe {
|
|
|
2054
2029
|
}
|
|
2055
2030
|
async _sha256Hex(e) {
|
|
2056
2031
|
const t = await e.arrayBuffer(), i = await globalThis.crypto.subtle.digest("SHA-256", t);
|
|
2057
|
-
return [...new Uint8Array(i)].map((
|
|
2032
|
+
return [...new Uint8Array(i)].map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
2058
2033
|
}
|
|
2059
2034
|
}
|
|
2060
|
-
function d(
|
|
2061
|
-
const i = document.createElement(
|
|
2062
|
-
for (const [
|
|
2063
|
-
if (
|
|
2064
|
-
if (
|
|
2065
|
-
i.className =
|
|
2066
|
-
else if (
|
|
2067
|
-
Object.assign(i.style,
|
|
2068
|
-
else if (
|
|
2069
|
-
const o =
|
|
2070
|
-
i.addEventListener(o,
|
|
2071
|
-
} else
|
|
2072
|
-
for (const
|
|
2073
|
-
typeof
|
|
2035
|
+
function d(f, e = {}, ...t) {
|
|
2036
|
+
const i = document.createElement(f);
|
|
2037
|
+
for (const [r, s] of Object.entries(e))
|
|
2038
|
+
if (s != null)
|
|
2039
|
+
if (r === "className")
|
|
2040
|
+
i.className = s;
|
|
2041
|
+
else if (r === "style" && typeof s == "object")
|
|
2042
|
+
Object.assign(i.style, s);
|
|
2043
|
+
else if (r.startsWith("on") && typeof s == "function") {
|
|
2044
|
+
const o = r.slice(2).toLowerCase();
|
|
2045
|
+
i.addEventListener(o, s);
|
|
2046
|
+
} else r === "dataset" && typeof s == "object" ? Object.assign(i.dataset, s) : i.setAttribute(r, s);
|
|
2047
|
+
for (const r of t)
|
|
2048
|
+
typeof r == "string" ? i.appendChild(document.createTextNode(r)) : r instanceof HTMLElement && i.appendChild(r);
|
|
2074
2049
|
return i;
|
|
2075
2050
|
}
|
|
2076
|
-
function ve({ id:
|
|
2077
|
-
const n =
|
|
2051
|
+
function ve({ id: f, label: e, min: t = 0, max: i = 1, step: r = 0.01, value: s = 0.5, onChange: o }) {
|
|
2052
|
+
const n = f.includes("-") ? f.split("-").slice(1).join("-") : f, a = d("div", {
|
|
2078
2053
|
className: "slider-control slider-wrapper",
|
|
2079
2054
|
"data-control": n,
|
|
2080
2055
|
"data-testid": `slider-${n}`
|
|
2081
2056
|
}), l = d(
|
|
2082
2057
|
"div",
|
|
2083
2058
|
{ className: "slider-header" },
|
|
2084
|
-
d("label", { for:
|
|
2085
|
-
d("span", { className: "slider-value", id: `${
|
|
2059
|
+
d("label", { for: f, className: "slider-label" }, e),
|
|
2060
|
+
d("span", { className: "slider-value", id: `${f}-value` }, ae(s))
|
|
2086
2061
|
), h = d("input", {
|
|
2087
2062
|
type: "range",
|
|
2088
|
-
id:
|
|
2063
|
+
id: f,
|
|
2089
2064
|
className: "slider-input",
|
|
2090
2065
|
min: String(t),
|
|
2091
2066
|
max: String(i),
|
|
2092
|
-
step: String(
|
|
2093
|
-
value: String(
|
|
2067
|
+
step: String(r),
|
|
2068
|
+
value: String(s),
|
|
2094
2069
|
onInput: (c) => {
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2070
|
+
const u = parseFloat(c.target.value), p = a.querySelector(".slider-value");
|
|
2071
|
+
p && (p.textContent = ae(u)), o == null || o(u);
|
|
2097
2072
|
}
|
|
2098
2073
|
});
|
|
2099
2074
|
return a.appendChild(l), a.appendChild(h), a.setValue = (c) => {
|
|
2100
2075
|
h.value = String(c);
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2076
|
+
const u = a.querySelector(".slider-value");
|
|
2077
|
+
u && (u.textContent = ae(c));
|
|
2103
2078
|
}, a;
|
|
2104
2079
|
}
|
|
2105
|
-
function ae(
|
|
2106
|
-
return Number.isInteger(
|
|
2080
|
+
function ae(f) {
|
|
2081
|
+
return Number.isInteger(f) ? String(f) : f.toFixed(2);
|
|
2107
2082
|
}
|
|
2108
|
-
function we({ id:
|
|
2109
|
-
const
|
|
2083
|
+
function we({ id: f, label: e, checked: t = !1, onChange: i }) {
|
|
2084
|
+
const r = d("div", { className: "toggle-control" }), s = d("label", { className: "toggle-label", for: f }, e), o = d("input", {
|
|
2110
2085
|
type: "checkbox",
|
|
2111
|
-
id:
|
|
2086
|
+
id: f,
|
|
2112
2087
|
className: "toggle-input",
|
|
2113
2088
|
checked: t ? "checked" : void 0,
|
|
2114
2089
|
onChange: (l) => i == null ? void 0 : i(l.target.checked)
|
|
@@ -2118,32 +2093,32 @@ function we({ id: g, label: e, checked: t = !1, onChange: i }) {
|
|
|
2118
2093
|
l.target !== o && (o.checked = !o.checked, i == null || i(o.checked));
|
|
2119
2094
|
}
|
|
2120
2095
|
}), a = d("span", { className: "toggle-slider" });
|
|
2121
|
-
return n.appendChild(o), n.appendChild(a),
|
|
2096
|
+
return n.appendChild(o), n.appendChild(a), r.appendChild(s), r.appendChild(n), r.setChecked = (l) => {
|
|
2122
2097
|
o.checked = l;
|
|
2123
|
-
},
|
|
2098
|
+
}, r;
|
|
2124
2099
|
}
|
|
2125
|
-
function xe({ id:
|
|
2126
|
-
const
|
|
2100
|
+
function xe({ id: f, label: e, value: t = "#000000", onChange: i }) {
|
|
2101
|
+
const r = d("div", { className: "color-control" }), s = d("label", { className: "color-label", for: f }, e), o = d("input", {
|
|
2127
2102
|
type: "color",
|
|
2128
|
-
id:
|
|
2103
|
+
id: f,
|
|
2129
2104
|
className: "color-input",
|
|
2130
2105
|
value: t,
|
|
2131
2106
|
onInput: (n) => i == null ? void 0 : i(n.target.value)
|
|
2132
2107
|
});
|
|
2133
|
-
return
|
|
2108
|
+
return r.appendChild(s), r.appendChild(o), r.setValue = (n) => {
|
|
2134
2109
|
o.value = n;
|
|
2135
|
-
},
|
|
2110
|
+
}, r;
|
|
2136
2111
|
}
|
|
2137
|
-
function Ce({ id:
|
|
2138
|
-
const
|
|
2112
|
+
function Ce({ id: f, label: e, value: t = "", placeholder: i = "", onCommit: r }) {
|
|
2113
|
+
const s = d("div", {
|
|
2139
2114
|
className: "text-control",
|
|
2140
|
-
"data-control":
|
|
2141
|
-
"data-testid": `text-${
|
|
2142
|
-
}), o = d("label", { className: "text-label", for:
|
|
2115
|
+
"data-control": f,
|
|
2116
|
+
"data-testid": `text-${f}`
|
|
2117
|
+
}), o = d("label", { className: "text-label", for: f }, e);
|
|
2143
2118
|
let n = t;
|
|
2144
2119
|
const a = d("input", {
|
|
2145
2120
|
type: "text",
|
|
2146
|
-
id:
|
|
2121
|
+
id: f,
|
|
2147
2122
|
className: "text-input",
|
|
2148
2123
|
value: t,
|
|
2149
2124
|
placeholder: i,
|
|
@@ -2154,72 +2129,72 @@ function Ce({ id: g, label: e, value: t = "", placeholder: i = "", onCommit: s }
|
|
|
2154
2129
|
});
|
|
2155
2130
|
function l() {
|
|
2156
2131
|
const h = a.value;
|
|
2157
|
-
h !== n && (n = h,
|
|
2132
|
+
h !== n && (n = h, r == null || r(h));
|
|
2158
2133
|
}
|
|
2159
|
-
return
|
|
2134
|
+
return s.appendChild(o), s.appendChild(a), s.setValue = (h) => {
|
|
2160
2135
|
const c = h == null ? "" : String(h);
|
|
2161
2136
|
a.value = c, n = c;
|
|
2162
|
-
},
|
|
2137
|
+
}, s;
|
|
2163
2138
|
}
|
|
2164
|
-
function ke({ id:
|
|
2165
|
-
const
|
|
2166
|
-
id:
|
|
2139
|
+
function ke({ id: f, label: e, options: t = [], value: i, onChange: r }) {
|
|
2140
|
+
const s = d("div", { className: "select-control" }), o = d("label", { className: "select-label", for: f }, e), n = d("select", {
|
|
2141
|
+
id: f,
|
|
2167
2142
|
className: "select-input",
|
|
2168
|
-
onChange: (a) =>
|
|
2143
|
+
onChange: (a) => r == null ? void 0 : r(a.target.value)
|
|
2169
2144
|
});
|
|
2170
2145
|
for (const a of t) {
|
|
2171
2146
|
const l = d("option", { value: a.value }, a.label);
|
|
2172
2147
|
a.value === i && (l.selected = !0), n.appendChild(l);
|
|
2173
2148
|
}
|
|
2174
|
-
return
|
|
2149
|
+
return s.appendChild(o), s.appendChild(n), s.setValue = (a) => {
|
|
2175
2150
|
n.value = a;
|
|
2176
|
-
},
|
|
2151
|
+
}, s;
|
|
2177
2152
|
}
|
|
2178
|
-
function j({ label:
|
|
2179
|
-
const
|
|
2153
|
+
function j({ label: f, className: e = "", onClick: t, icon: i = null, disabled: r = !1 }) {
|
|
2154
|
+
const s = d("button", {
|
|
2180
2155
|
type: "button",
|
|
2181
2156
|
className: `btn ${e}`.trim(),
|
|
2182
2157
|
onClick: t,
|
|
2183
|
-
disabled:
|
|
2158
|
+
disabled: r ? "disabled" : void 0
|
|
2184
2159
|
});
|
|
2185
2160
|
if (i) {
|
|
2186
2161
|
const o = d("span", { className: "btn-icon" });
|
|
2187
2162
|
o.innerHTML = i;
|
|
2188
2163
|
const n = o.querySelector("svg");
|
|
2189
|
-
n && n.setAttribute("aria-hidden", "true"),
|
|
2164
|
+
n && n.setAttribute("aria-hidden", "true"), s.appendChild(o);
|
|
2190
2165
|
}
|
|
2191
|
-
return
|
|
2166
|
+
return f && s.appendChild(document.createTextNode(f)), s;
|
|
2192
2167
|
}
|
|
2193
|
-
function O({ icon:
|
|
2168
|
+
function O({ icon: f, title: e, className: t = "", onClick: i, disabled: r = !1, testId: s = null, ariaLabel: o = null }) {
|
|
2194
2169
|
const n = {
|
|
2195
2170
|
type: "button",
|
|
2196
2171
|
className: `icon-btn ${t}`.trim(),
|
|
2197
2172
|
title: e,
|
|
2198
2173
|
"aria-label": o || e,
|
|
2199
2174
|
onClick: i,
|
|
2200
|
-
disabled:
|
|
2175
|
+
disabled: r ? "disabled" : void 0
|
|
2201
2176
|
};
|
|
2202
|
-
|
|
2177
|
+
s && (n.dataset = { testid: s });
|
|
2203
2178
|
const a = d("button", n);
|
|
2204
|
-
a.innerHTML =
|
|
2179
|
+
a.innerHTML = f;
|
|
2205
2180
|
const l = a.querySelector("svg");
|
|
2206
2181
|
return l && l.setAttribute("aria-hidden", "true"), a;
|
|
2207
2182
|
}
|
|
2208
|
-
function
|
|
2209
|
-
const
|
|
2183
|
+
function re({ label: f, icon: e, active: t = !1, onClick: i }) {
|
|
2184
|
+
const r = d("button", {
|
|
2210
2185
|
type: "button",
|
|
2211
2186
|
className: `chip ${t ? "active" : ""}`.trim(),
|
|
2212
2187
|
onClick: i
|
|
2213
2188
|
});
|
|
2214
2189
|
if (e) {
|
|
2215
|
-
const
|
|
2216
|
-
|
|
2217
|
-
const o =
|
|
2218
|
-
o && o.setAttribute("aria-hidden", "true"),
|
|
2190
|
+
const s = d("span", { className: "chip-icon" });
|
|
2191
|
+
s.innerHTML = e;
|
|
2192
|
+
const o = s.querySelector("svg");
|
|
2193
|
+
o && o.setAttribute("aria-hidden", "true"), r.appendChild(s);
|
|
2219
2194
|
}
|
|
2220
|
-
return
|
|
2221
|
-
|
|
2222
|
-
},
|
|
2195
|
+
return r.appendChild(d("span", { className: "chip-label" }, f)), r.setActive = (s) => {
|
|
2196
|
+
r.classList.toggle("active", s);
|
|
2197
|
+
}, r;
|
|
2223
2198
|
}
|
|
2224
2199
|
class et {
|
|
2225
2200
|
constructor(e, t) {
|
|
@@ -2258,7 +2233,7 @@ class et {
|
|
|
2258
2233
|
this.state.get("mode") === "crop" ? this.editor.setMode("filters") : this.editor.setMode("crop");
|
|
2259
2234
|
}
|
|
2260
2235
|
});
|
|
2261
|
-
const
|
|
2236
|
+
const r = d("div", { className: "remove-bg-control" });
|
|
2262
2237
|
this._removeBgTierSelect = d("select", {
|
|
2263
2238
|
className: "remove-bg-tier-select",
|
|
2264
2239
|
title: "Background removal quality",
|
|
@@ -2300,8 +2275,8 @@ class et {
|
|
|
2300
2275
|
role: "status",
|
|
2301
2276
|
"aria-live": "polite",
|
|
2302
2277
|
"aria-atomic": "true"
|
|
2303
|
-
}),
|
|
2304
|
-
const
|
|
2278
|
+
}), r.appendChild(this._removeBgTierSelect), r.appendChild(this._removeBgBtn), r.appendChild(this._removeBgStatus);
|
|
2279
|
+
const s = O({
|
|
2305
2280
|
icon: ye,
|
|
2306
2281
|
title: "Reset All",
|
|
2307
2282
|
className: "toolbar-btn",
|
|
@@ -2327,7 +2302,7 @@ class et {
|
|
|
2327
2302
|
ariaLabel: "Close editor",
|
|
2328
2303
|
onClick: () => this.editor.close()
|
|
2329
2304
|
});
|
|
2330
|
-
return i.appendChild(this._themeBtn), i.appendChild(this._cropBtn), i.appendChild(
|
|
2305
|
+
return i.appendChild(this._themeBtn), i.appendChild(this._cropBtn), i.appendChild(r), i.appendChild(s), i.appendChild(o), i.appendChild(l), this.element.appendChild(e), this.element.appendChild(i), this._subscribeToState(), this.element;
|
|
2331
2306
|
}
|
|
2332
2307
|
/**
|
|
2333
2308
|
* Subscribe to state changes
|
|
@@ -2343,10 +2318,10 @@ class et {
|
|
|
2343
2318
|
this._unsubscribers.push(t);
|
|
2344
2319
|
const i = this.state.on("change:hasImage", () => this._updateRemoveBgButton());
|
|
2345
2320
|
this._unsubscribers.push(i);
|
|
2346
|
-
const
|
|
2347
|
-
this._unsubscribers.push(s);
|
|
2348
|
-
const r = this.state.on("change:backgroundRemovalAvailable", () => this._updateRemoveBgButton());
|
|
2321
|
+
const r = this.state.on("change:isProcessing", () => this._updateRemoveBgButton());
|
|
2349
2322
|
this._unsubscribers.push(r);
|
|
2323
|
+
const s = this.state.on("change:backgroundRemovalAvailable", () => this._updateRemoveBgButton());
|
|
2324
|
+
this._unsubscribers.push(s);
|
|
2350
2325
|
const o = this.state.on("change:editorDocument", () => this._updateRemoveBgButton());
|
|
2351
2326
|
this._unsubscribers.push(o);
|
|
2352
2327
|
const n = this.state.on("change:layers", () => this._updateRemoveBgButton());
|
|
@@ -2393,13 +2368,13 @@ class tt {
|
|
|
2393
2368
|
className: "carousel-nav carousel-nav-left",
|
|
2394
2369
|
onClick: () => this._scrollLeft()
|
|
2395
2370
|
}), this._carousel = d("div", { className: "category-carousel" }), ie.forEach((i) => {
|
|
2396
|
-
const
|
|
2371
|
+
const r = re({
|
|
2397
2372
|
label: i.name,
|
|
2398
2373
|
icon: i.icon,
|
|
2399
2374
|
active: this.state.get("selectedCategory") === i.id,
|
|
2400
2375
|
onClick: () => this._selectCategory(i.id)
|
|
2401
2376
|
});
|
|
2402
|
-
|
|
2377
|
+
r.dataset.categoryId = i.id, r.dataset.category = i.id, r.dataset.testid = `category-${i.id}`, this._chips.set(i.id, r), this._carousel.appendChild(r);
|
|
2403
2378
|
}), this._rightBtn = O({
|
|
2404
2379
|
icon: me,
|
|
2405
2380
|
title: "Next categories",
|
|
@@ -2412,7 +2387,7 @@ class tt {
|
|
|
2412
2387
|
});
|
|
2413
2388
|
const t = Math.ceil(ie.length / 3);
|
|
2414
2389
|
for (let i = 0; i < t; i++) {
|
|
2415
|
-
const
|
|
2390
|
+
const r = d("button", {
|
|
2416
2391
|
type: "button",
|
|
2417
2392
|
className: `pagination-dot ${i === 0 ? "active" : ""}`,
|
|
2418
2393
|
role: "tab",
|
|
@@ -2420,7 +2395,7 @@ class tt {
|
|
|
2420
2395
|
"aria-selected": i === 0 ? "true" : "false",
|
|
2421
2396
|
onClick: () => this._scrollToPage(i)
|
|
2422
2397
|
});
|
|
2423
|
-
this._pagination.appendChild(
|
|
2398
|
+
this._pagination.appendChild(r);
|
|
2424
2399
|
}
|
|
2425
2400
|
return this.element.appendChild(this._leftBtn), this.element.appendChild(this._carousel), this.element.appendChild(this._rightBtn), this.element.appendChild(this._pagination), this._subscribeToState(), this._updateNavButtons(), this.element;
|
|
2426
2401
|
}
|
|
@@ -2429,8 +2404,8 @@ class tt {
|
|
|
2429
2404
|
*/
|
|
2430
2405
|
_subscribeToState() {
|
|
2431
2406
|
const e = this.state.on("change:selectedCategory", ({ value: t }) => {
|
|
2432
|
-
this._chips.forEach((i,
|
|
2433
|
-
i.setActive(
|
|
2407
|
+
this._chips.forEach((i, r) => {
|
|
2408
|
+
i.setActive(r === t);
|
|
2434
2409
|
});
|
|
2435
2410
|
});
|
|
2436
2411
|
this._unsubscribers.push(e);
|
|
@@ -2440,12 +2415,12 @@ class tt {
|
|
|
2440
2415
|
* @param {string} categoryId
|
|
2441
2416
|
*/
|
|
2442
2417
|
_selectCategory(e) {
|
|
2443
|
-
var
|
|
2418
|
+
var r;
|
|
2444
2419
|
this.state.set("selectedCategory", e);
|
|
2445
2420
|
const t = this.state.get("mode");
|
|
2446
2421
|
e === "crop" ? t !== "crop" && this.editor.setMode("crop") : t !== "filters" && this.editor.setMode("filters");
|
|
2447
2422
|
const i = this._chips.get(e);
|
|
2448
|
-
i && this._carousel && i.scrollIntoView({ behavior: "smooth", inline: "center", block: "nearest" }), (
|
|
2423
|
+
i && this._carousel && i.scrollIntoView({ behavior: "smooth", inline: "center", block: "nearest" }), (r = this._onSelect) == null || r.call(this, e);
|
|
2449
2424
|
}
|
|
2450
2425
|
/**
|
|
2451
2426
|
* Scroll carousel left
|
|
@@ -2492,9 +2467,9 @@ class tt {
|
|
|
2492
2467
|
_updatePagination() {
|
|
2493
2468
|
if (this._pagination) {
|
|
2494
2469
|
const e = this._pagination.querySelectorAll(".pagination-dot"), t = Math.floor(this._scrollIndex / 3);
|
|
2495
|
-
e.forEach((i,
|
|
2496
|
-
const
|
|
2497
|
-
i.classList.toggle("active",
|
|
2470
|
+
e.forEach((i, r) => {
|
|
2471
|
+
const s = r === t;
|
|
2472
|
+
i.classList.toggle("active", s), i.setAttribute("aria-selected", s ? "true" : "false");
|
|
2498
2473
|
});
|
|
2499
2474
|
}
|
|
2500
2475
|
}
|
|
@@ -2559,13 +2534,13 @@ class it {
|
|
|
2559
2534
|
this._carousel.innerHTML = "", this._filterCards.clear(), this._scrollIndex = 0;
|
|
2560
2535
|
const e = this.state.get("selectedCategory");
|
|
2561
2536
|
if (e === "crop") return;
|
|
2562
|
-
const t = this.filterManager.getFiltersByCategory(e), i = this.state.get("activeFilters"),
|
|
2563
|
-
t.forEach((
|
|
2564
|
-
const o = this._createFilterCard(
|
|
2565
|
-
isActive: i.has(
|
|
2566
|
-
isSelected:
|
|
2537
|
+
const t = this.filterManager.getFiltersByCategory(e), i = this.state.get("activeFilters"), r = this.state.get("selectedFilter");
|
|
2538
|
+
t.forEach((s) => {
|
|
2539
|
+
const o = this._createFilterCard(s, {
|
|
2540
|
+
isActive: i.has(s.id),
|
|
2541
|
+
isSelected: r === s.id
|
|
2567
2542
|
});
|
|
2568
|
-
this._filterCards.set(
|
|
2543
|
+
this._filterCards.set(s.id, o), this._carousel.appendChild(o);
|
|
2569
2544
|
}), this._updateNavButtons();
|
|
2570
2545
|
}
|
|
2571
2546
|
/**
|
|
@@ -2575,23 +2550,23 @@ class it {
|
|
|
2575
2550
|
* @returns {HTMLElement}
|
|
2576
2551
|
*/
|
|
2577
2552
|
_createFilterCard(e, { isActive: t, isSelected: i }) {
|
|
2578
|
-
const
|
|
2553
|
+
const r = d("div", {
|
|
2579
2554
|
className: `filter-card ${t ? "active" : ""} ${i ? "selected" : ""}`,
|
|
2580
2555
|
"data-filter": e.id,
|
|
2581
2556
|
"data-testid": `filter-${e.id}`,
|
|
2582
2557
|
onClick: () => this._handleCardClick(e.id)
|
|
2583
|
-
}),
|
|
2584
|
-
|
|
2558
|
+
}), s = d("div", { className: "filter-preview" }), o = d("span", { className: "filter-preview-text" }, e.name.charAt(0));
|
|
2559
|
+
s.appendChild(o);
|
|
2585
2560
|
const n = d("span", { className: "filter-name", title: e.name }, e.name), a = d("button", {
|
|
2586
2561
|
className: `filter-toggle ${t ? "active" : ""}`,
|
|
2587
2562
|
onClick: (l) => {
|
|
2588
|
-
var
|
|
2563
|
+
var u;
|
|
2589
2564
|
l.stopPropagation();
|
|
2590
2565
|
const c = !this.state.get("activeFilters").has(e.id);
|
|
2591
|
-
this._handleToggle(e.id, c), c && (this.state.set("selectedFilter", e.id), (
|
|
2566
|
+
this._handleToggle(e.id, c), c && (this.state.set("selectedFilter", e.id), (u = this._onSelect) == null || u.call(this, e.id));
|
|
2592
2567
|
}
|
|
2593
2568
|
});
|
|
2594
|
-
return a.innerHTML = t ? he : "",
|
|
2569
|
+
return a.innerHTML = t ? he : "", r.appendChild(s), r.appendChild(n), r.appendChild(a), r._toggle = a, r._isActive = t, r;
|
|
2595
2570
|
}
|
|
2596
2571
|
/**
|
|
2597
2572
|
* Handle filter card click (select)
|
|
@@ -2616,8 +2591,8 @@ class it {
|
|
|
2616
2591
|
_updateActiveStates() {
|
|
2617
2592
|
const e = this.state.get("activeFilters");
|
|
2618
2593
|
this._filterCards.forEach((t, i) => {
|
|
2619
|
-
const
|
|
2620
|
-
t.classList.toggle("active",
|
|
2594
|
+
const r = e.has(i);
|
|
2595
|
+
t.classList.toggle("active", r), t._toggle.classList.toggle("active", r), t._toggle.innerHTML = r ? he : "", t._isActive = r;
|
|
2621
2596
|
});
|
|
2622
2597
|
}
|
|
2623
2598
|
/**
|
|
@@ -2670,7 +2645,7 @@ class it {
|
|
|
2670
2645
|
this._unsubscribers.forEach((t) => t()), this._unsubscribers = [], this._filterCards.clear(), (e = this.element) == null || e.remove(), this.element = null;
|
|
2671
2646
|
}
|
|
2672
2647
|
}
|
|
2673
|
-
class
|
|
2648
|
+
class rt {
|
|
2674
2649
|
constructor(e, t) {
|
|
2675
2650
|
this.state = e, this.filterManager = t, this.element = null, this._controls = /* @__PURE__ */ new Map(), this._onChange = null, this._onReset = null, this._onAction = null, this._unsubscribers = [];
|
|
2676
2651
|
}
|
|
@@ -2724,10 +2699,10 @@ class st {
|
|
|
2724
2699
|
className: "btn-text",
|
|
2725
2700
|
onClick: () => this._handleReset(e)
|
|
2726
2701
|
})), this.element.appendChild(i);
|
|
2727
|
-
const
|
|
2702
|
+
const r = d("div", { className: "adjustments-grid" }), s = this.state.getFilterValues(e);
|
|
2728
2703
|
(t.controls || []).forEach((n) => {
|
|
2729
|
-
const a =
|
|
2730
|
-
l && (this._controls.set(n.id, l),
|
|
2704
|
+
const a = s[n.id] ?? n.default, l = this._createControl(e, n, a);
|
|
2705
|
+
l && (this._controls.set(n.id, l), r.appendChild(l));
|
|
2731
2706
|
});
|
|
2732
2707
|
const o = this.filterManager.getInstance(e);
|
|
2733
2708
|
if (o && typeof o.getDynamicControls == "function") {
|
|
@@ -2737,11 +2712,11 @@ class st {
|
|
|
2737
2712
|
} catch {
|
|
2738
2713
|
}
|
|
2739
2714
|
n.forEach((a) => {
|
|
2740
|
-
const l = a.property || a.id, h =
|
|
2741
|
-
c && (this._controls.set(a.id, c),
|
|
2715
|
+
const l = a.property || a.id, h = s[l] ?? a.default, c = this._createControl(e, a, h);
|
|
2716
|
+
c && (this._controls.set(a.id, c), r.appendChild(c));
|
|
2742
2717
|
});
|
|
2743
2718
|
}
|
|
2744
|
-
this.element.appendChild(
|
|
2719
|
+
this.element.appendChild(r);
|
|
2745
2720
|
}
|
|
2746
2721
|
/**
|
|
2747
2722
|
* Create a control element based on type.
|
|
@@ -2759,12 +2734,12 @@ class st {
|
|
|
2759
2734
|
*/
|
|
2760
2735
|
_createControl(e, t, i) {
|
|
2761
2736
|
if (t.hidden) return null;
|
|
2762
|
-
const
|
|
2763
|
-
switch (
|
|
2737
|
+
const r = t.label || t.id, s = this._normalizeControlType(t.type), o = t.property || t.id;
|
|
2738
|
+
switch (s) {
|
|
2764
2739
|
case "slider":
|
|
2765
2740
|
return ve({
|
|
2766
2741
|
id: `${e}-${t.id}`,
|
|
2767
|
-
label:
|
|
2742
|
+
label: r,
|
|
2768
2743
|
min: t.min ?? 0,
|
|
2769
2744
|
max: t.max ?? 1,
|
|
2770
2745
|
step: t.step ?? 0.01,
|
|
@@ -2774,14 +2749,14 @@ class st {
|
|
|
2774
2749
|
case "toggle":
|
|
2775
2750
|
return we({
|
|
2776
2751
|
id: `${e}-${t.id}`,
|
|
2777
|
-
label:
|
|
2752
|
+
label: r,
|
|
2778
2753
|
checked: !!i,
|
|
2779
2754
|
onChange: (l) => this._handleChange(e, o, l)
|
|
2780
2755
|
});
|
|
2781
2756
|
case "color":
|
|
2782
2757
|
return xe({
|
|
2783
2758
|
id: `${e}-${t.id}`,
|
|
2784
|
-
label:
|
|
2759
|
+
label: r,
|
|
2785
2760
|
value: typeof i == "string" && i.startsWith("#") ? i : t.default || "#000000",
|
|
2786
2761
|
onChange: (l) => this._handleChange(e, o, l)
|
|
2787
2762
|
});
|
|
@@ -2789,7 +2764,7 @@ class st {
|
|
|
2789
2764
|
const n = this._normalizeOptions(t.options);
|
|
2790
2765
|
return ke({
|
|
2791
2766
|
id: `${e}-${t.id}`,
|
|
2792
|
-
label:
|
|
2767
|
+
label: r,
|
|
2793
2768
|
options: n,
|
|
2794
2769
|
value: i ?? t.default,
|
|
2795
2770
|
onChange: (l) => this._handleChange(e, o, l)
|
|
@@ -2797,7 +2772,7 @@ class st {
|
|
|
2797
2772
|
case "text":
|
|
2798
2773
|
return Ce({
|
|
2799
2774
|
id: `${e}-${t.id}`,
|
|
2800
|
-
label:
|
|
2775
|
+
label: r,
|
|
2801
2776
|
value: typeof i == "string" ? i : t.default ?? "",
|
|
2802
2777
|
placeholder: t.placeholder || "",
|
|
2803
2778
|
onCommit: (l) => this._handleChange(e, o, l)
|
|
@@ -2805,7 +2780,7 @@ class st {
|
|
|
2805
2780
|
case "button":
|
|
2806
2781
|
const a = d("div", { className: "button-control" });
|
|
2807
2782
|
return a.appendChild(j({
|
|
2808
|
-
label:
|
|
2783
|
+
label: r,
|
|
2809
2784
|
className: "btn-secondary",
|
|
2810
2785
|
onClick: () => this._handleAction(e, t.action || t.id)
|
|
2811
2786
|
})), a;
|
|
@@ -2846,8 +2821,8 @@ class st {
|
|
|
2846
2821
|
* @param {*} value
|
|
2847
2822
|
*/
|
|
2848
2823
|
_handleChange(e, t, i) {
|
|
2849
|
-
var
|
|
2850
|
-
(
|
|
2824
|
+
var r;
|
|
2825
|
+
(r = this._onChange) == null || r.call(this, e, t, i);
|
|
2851
2826
|
}
|
|
2852
2827
|
/**
|
|
2853
2828
|
* Handle reset button
|
|
@@ -2876,11 +2851,11 @@ class st {
|
|
|
2876
2851
|
const e = this.state.get("selectedFilter");
|
|
2877
2852
|
if (!e) return;
|
|
2878
2853
|
const t = this.state.getFilterValues(e), i = this.filterManager.getFilterDef(e);
|
|
2879
|
-
i && i.controls.forEach((
|
|
2880
|
-
const
|
|
2881
|
-
if (
|
|
2882
|
-
const o = t[
|
|
2883
|
-
|
|
2854
|
+
i && i.controls.forEach((r) => {
|
|
2855
|
+
const s = this._controls.get(r.id);
|
|
2856
|
+
if (s && typeof s.setValue == "function") {
|
|
2857
|
+
const o = t[r.id] ?? r.default;
|
|
2858
|
+
s.setValue(o);
|
|
2884
2859
|
}
|
|
2885
2860
|
});
|
|
2886
2861
|
}
|
|
@@ -2904,7 +2879,7 @@ class st {
|
|
|
2904
2879
|
this._unsubscribers.forEach((t) => t()), this._unsubscribers = [], this._controls.clear(), (e = this.element) == null || e.remove(), this.element = null;
|
|
2905
2880
|
}
|
|
2906
2881
|
}
|
|
2907
|
-
class
|
|
2882
|
+
class st {
|
|
2908
2883
|
constructor(e, t) {
|
|
2909
2884
|
this.state = e, this.filterManager = t, this._drawer = null, this._body = null, this._titleEl = null, this._isOpen = !1, this._currentFilterId = null, this._controls = /* @__PURE__ */ new Map(), this._onChange = null, this._onReset = null, this._onRemove = null, this._onAction = null, this._container = null;
|
|
2910
2885
|
}
|
|
@@ -2913,8 +2888,8 @@ class rt {
|
|
|
2913
2888
|
* @param {HTMLElement} container - Parent element (controls-section)
|
|
2914
2889
|
* @param {Object} callbacks - { onChange, onReset, onRemove, onAction }
|
|
2915
2890
|
*/
|
|
2916
|
-
build(e, { onChange: t, onReset: i, onRemove:
|
|
2917
|
-
this._onChange = t, this._onReset = i, this._onRemove =
|
|
2891
|
+
build(e, { onChange: t, onReset: i, onRemove: r, onAction: s }) {
|
|
2892
|
+
this._onChange = t, this._onReset = i, this._onRemove = r, this._onAction = s, this._container = e, this._drawer = d("div", { className: "mobile-filter-drawer" });
|
|
2918
2893
|
const o = d("div", { className: "drawer-header" });
|
|
2919
2894
|
this._titleEl = d("span", { className: "drawer-title" }, "Filter");
|
|
2920
2895
|
const n = d("div", { className: "drawer-header-actions" }), a = j({
|
|
@@ -2991,19 +2966,19 @@ class rt {
|
|
|
2991
2966
|
if (!e) return;
|
|
2992
2967
|
this._titleEl.textContent = e.name;
|
|
2993
2968
|
const t = d("div", { className: "adjustments-grid" }), i = this.state.getFilterValues(this._currentFilterId);
|
|
2994
|
-
(e.controls || []).forEach((
|
|
2995
|
-
if (
|
|
2996
|
-
const o = this._createControl(this._currentFilterId,
|
|
2997
|
-
o && (this._controls.set(
|
|
2969
|
+
(e.controls || []).forEach((s) => {
|
|
2970
|
+
if (s.hidden) return;
|
|
2971
|
+
const o = this._createControl(this._currentFilterId, s, i[s.id] ?? s.default);
|
|
2972
|
+
o && (this._controls.set(s.id, o), t.appendChild(o));
|
|
2998
2973
|
});
|
|
2999
|
-
const
|
|
3000
|
-
if (
|
|
3001
|
-
let
|
|
2974
|
+
const r = this.filterManager.getInstance(this._currentFilterId);
|
|
2975
|
+
if (r && typeof r.getDynamicControls == "function") {
|
|
2976
|
+
let s = [];
|
|
3002
2977
|
try {
|
|
3003
|
-
|
|
2978
|
+
s = r.getDynamicControls() || [];
|
|
3004
2979
|
} catch {
|
|
3005
2980
|
}
|
|
3006
|
-
|
|
2981
|
+
s.forEach((o) => {
|
|
3007
2982
|
const n = o.property || o.id, a = i[n] ?? o.default, l = this._createControl(this._currentFilterId, o, a);
|
|
3008
2983
|
l && (this._controls.set(o.id, l), t.appendChild(l));
|
|
3009
2984
|
});
|
|
@@ -3020,12 +2995,12 @@ class rt {
|
|
|
3020
2995
|
*/
|
|
3021
2996
|
_createControl(e, t, i) {
|
|
3022
2997
|
if (t.hidden) return null;
|
|
3023
|
-
const
|
|
3024
|
-
switch (
|
|
2998
|
+
const r = t.label || t.id, s = this._normalizeControlType(t.type), o = t.property || t.id;
|
|
2999
|
+
switch (s) {
|
|
3025
3000
|
case "slider":
|
|
3026
3001
|
return ve({
|
|
3027
3002
|
id: `drawer-${e}-${t.id}`,
|
|
3028
|
-
label:
|
|
3003
|
+
label: r,
|
|
3029
3004
|
min: t.min ?? 0,
|
|
3030
3005
|
max: t.max ?? 1,
|
|
3031
3006
|
step: t.step ?? 0.01,
|
|
@@ -3038,7 +3013,7 @@ class rt {
|
|
|
3038
3013
|
case "toggle":
|
|
3039
3014
|
return we({
|
|
3040
3015
|
id: `drawer-${e}-${t.id}`,
|
|
3041
|
-
label:
|
|
3016
|
+
label: r,
|
|
3042
3017
|
checked: !!i,
|
|
3043
3018
|
onChange: (n) => {
|
|
3044
3019
|
var a;
|
|
@@ -3048,7 +3023,7 @@ class rt {
|
|
|
3048
3023
|
case "color":
|
|
3049
3024
|
return xe({
|
|
3050
3025
|
id: `drawer-${e}-${t.id}`,
|
|
3051
|
-
label:
|
|
3026
|
+
label: r,
|
|
3052
3027
|
value: typeof i == "string" && i.startsWith("#") ? i : t.default || "#000000",
|
|
3053
3028
|
onChange: (n) => {
|
|
3054
3029
|
var a;
|
|
@@ -3059,7 +3034,7 @@ class rt {
|
|
|
3059
3034
|
const n = this._normalizeOptions(t.options);
|
|
3060
3035
|
return ke({
|
|
3061
3036
|
id: `drawer-${e}-${t.id}`,
|
|
3062
|
-
label:
|
|
3037
|
+
label: r,
|
|
3063
3038
|
options: n,
|
|
3064
3039
|
value: i ?? t.default,
|
|
3065
3040
|
onChange: (a) => {
|
|
@@ -3071,7 +3046,7 @@ class rt {
|
|
|
3071
3046
|
case "text":
|
|
3072
3047
|
return Ce({
|
|
3073
3048
|
id: `drawer-${e}-${t.id}`,
|
|
3074
|
-
label:
|
|
3049
|
+
label: r,
|
|
3075
3050
|
value: typeof i == "string" ? i : t.default ?? "",
|
|
3076
3051
|
placeholder: t.placeholder || "",
|
|
3077
3052
|
onCommit: (n) => {
|
|
@@ -3082,7 +3057,7 @@ class rt {
|
|
|
3082
3057
|
case "button": {
|
|
3083
3058
|
const n = d("div", { className: "button-control" });
|
|
3084
3059
|
return n.appendChild(j({
|
|
3085
|
-
label:
|
|
3060
|
+
label: r,
|
|
3086
3061
|
className: "btn-secondary",
|
|
3087
3062
|
onClick: () => {
|
|
3088
3063
|
var a;
|
|
@@ -3165,8 +3140,8 @@ class nt {
|
|
|
3165
3140
|
e.forEach((t) => {
|
|
3166
3141
|
const i = this.filterManager.getFilterDef(t);
|
|
3167
3142
|
if (!i) return;
|
|
3168
|
-
const
|
|
3169
|
-
this._chips.set(t,
|
|
3143
|
+
const r = this._createChip(t, i);
|
|
3144
|
+
this._chips.set(t, r), this._scrollContainer.appendChild(r);
|
|
3170
3145
|
}), this._updateSelectedState();
|
|
3171
3146
|
}
|
|
3172
3147
|
_createChip(e, t) {
|
|
@@ -3174,13 +3149,13 @@ class nt {
|
|
|
3174
3149
|
className: "active-filter-chip",
|
|
3175
3150
|
"data-filter-id": e,
|
|
3176
3151
|
"data-testid": `active-chip-${e}`
|
|
3177
|
-
}),
|
|
3152
|
+
}), r = d("span", {
|
|
3178
3153
|
className: "active-filter-chip-label",
|
|
3179
3154
|
onClick: (o) => {
|
|
3180
3155
|
var n;
|
|
3181
3156
|
o.stopPropagation(), (n = this._onSelect) == null || n.call(this, e);
|
|
3182
3157
|
}
|
|
3183
|
-
}, t.name),
|
|
3158
|
+
}, t.name), s = d("button", {
|
|
3184
3159
|
className: "active-filter-chip-check",
|
|
3185
3160
|
"aria-label": `Remove ${t.name} filter`,
|
|
3186
3161
|
onClick: (o) => {
|
|
@@ -3188,7 +3163,7 @@ class nt {
|
|
|
3188
3163
|
o.stopPropagation(), (n = this._onToggle) == null || n.call(this, e, !1);
|
|
3189
3164
|
}
|
|
3190
3165
|
});
|
|
3191
|
-
return
|
|
3166
|
+
return s.innerHTML = '<svg width="10" height="10" viewBox="0 0 12 12"><path d="M2 6l3 3 5-5" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>', i.appendChild(r), i.appendChild(s), i;
|
|
3192
3167
|
}
|
|
3193
3168
|
_updateSelectedState() {
|
|
3194
3169
|
const e = this.state.get("selectedFilter");
|
|
@@ -3218,9 +3193,9 @@ const ot = [
|
|
|
3218
3193
|
{ id: "180", label: "180°", angle: 180 },
|
|
3219
3194
|
{ id: "270", label: "270°", angle: 270 }
|
|
3220
3195
|
];
|
|
3221
|
-
function W(
|
|
3222
|
-
if (!Number.isFinite(Number(
|
|
3223
|
-
const e = Number(
|
|
3196
|
+
function W(f) {
|
|
3197
|
+
if (!Number.isFinite(Number(f))) return 0;
|
|
3198
|
+
const e = Number(f) % 360;
|
|
3224
3199
|
return e < 0 ? e + 360 : e;
|
|
3225
3200
|
}
|
|
3226
3201
|
class ht {
|
|
@@ -3248,7 +3223,7 @@ class ht {
|
|
|
3248
3223
|
e.appendChild(d("label", { className: "section-label" }, "Shape"));
|
|
3249
3224
|
const t = d("div", { className: "chip-row" }), i = this.state.get("crop.shape");
|
|
3250
3225
|
ot.forEach((l) => {
|
|
3251
|
-
const h =
|
|
3226
|
+
const h = re({
|
|
3252
3227
|
label: l.name,
|
|
3253
3228
|
icon: l.icon,
|
|
3254
3229
|
active: i === l.id,
|
|
@@ -3256,15 +3231,15 @@ class ht {
|
|
|
3256
3231
|
});
|
|
3257
3232
|
h.dataset.shape = l.id, h.dataset.testid = `crop-shape-${l.id}`, this._shapeChips.set(l.id, h), t.appendChild(h);
|
|
3258
3233
|
}), e.appendChild(t), this.element.appendChild(e), this.state.get("lockCropShape") && (e.style.display = "none"), this._shapeSection = e, this._aspectSection = d("div", { className: "crop-section" }), this._aspectSection.appendChild(d("label", { className: "section-label" }, "Aspect Ratio"));
|
|
3259
|
-
const
|
|
3234
|
+
const r = d("div", { className: "chip-row aspect-row" }), s = this.state.get("crop.aspect");
|
|
3260
3235
|
at.forEach((l) => {
|
|
3261
|
-
const h =
|
|
3236
|
+
const h = re({
|
|
3262
3237
|
label: l.name,
|
|
3263
|
-
active:
|
|
3238
|
+
active: s === l.id,
|
|
3264
3239
|
onClick: () => this._selectAspect(l.id)
|
|
3265
3240
|
});
|
|
3266
|
-
h.dataset.ratio = l.id, h.dataset.testid = `crop-ratio-${l.id}`, this._aspectChips.set(l.id, h),
|
|
3267
|
-
}), this._aspectSection.appendChild(
|
|
3241
|
+
h.dataset.ratio = l.id, h.dataset.testid = `crop-ratio-${l.id}`, this._aspectChips.set(l.id, h), r.appendChild(h);
|
|
3242
|
+
}), this._aspectSection.appendChild(r), this.element.appendChild(this._aspectSection), this._updateAspectVisibility();
|
|
3268
3243
|
const o = d("div", { className: "crop-actions" }), n = j({
|
|
3269
3244
|
label: "Cancel",
|
|
3270
3245
|
className: "btn-secondary crop-cancel-btn",
|
|
@@ -3290,33 +3265,33 @@ class ht {
|
|
|
3290
3265
|
onClick: () => this._rotateBy(-90)
|
|
3291
3266
|
});
|
|
3292
3267
|
i.dataset.testid = "rotate-left-90";
|
|
3293
|
-
const
|
|
3268
|
+
const r = j({
|
|
3294
3269
|
label: "Right 90°",
|
|
3295
3270
|
className: "btn-secondary rotation-action-btn",
|
|
3296
3271
|
icon: Pe,
|
|
3297
3272
|
onClick: () => this._rotateBy(90)
|
|
3298
3273
|
});
|
|
3299
|
-
|
|
3300
|
-
const
|
|
3274
|
+
r.dataset.testid = "rotate-right-90";
|
|
3275
|
+
const s = j({
|
|
3301
3276
|
label: "Rotate 180°",
|
|
3302
3277
|
className: "btn-secondary rotation-action-btn",
|
|
3303
3278
|
onClick: () => this._rotateBy(180)
|
|
3304
3279
|
});
|
|
3305
|
-
|
|
3280
|
+
s.dataset.testid = "rotate-180";
|
|
3306
3281
|
const o = j({
|
|
3307
3282
|
label: "Rotate 270°",
|
|
3308
3283
|
className: "btn-secondary rotation-action-btn",
|
|
3309
3284
|
onClick: () => this._rotateBy(270)
|
|
3310
3285
|
});
|
|
3311
|
-
o.dataset.testid = "rotate-270", t.appendChild(i), t.appendChild(
|
|
3286
|
+
o.dataset.testid = "rotate-270", t.appendChild(i), t.appendChild(r), t.appendChild(s), t.appendChild(o), e.appendChild(t);
|
|
3312
3287
|
const n = d("div", { className: "chip-row rotation-preset-row" }), a = W(this.state.get("transform.rotation") ?? 0);
|
|
3313
|
-
lt.forEach((
|
|
3314
|
-
const
|
|
3315
|
-
label:
|
|
3316
|
-
active: Math.round(a) ===
|
|
3317
|
-
onClick: () => this._setRotation(
|
|
3288
|
+
lt.forEach((p) => {
|
|
3289
|
+
const g = re({
|
|
3290
|
+
label: p.label,
|
|
3291
|
+
active: Math.round(a) === p.angle,
|
|
3292
|
+
onClick: () => this._setRotation(p.angle)
|
|
3318
3293
|
});
|
|
3319
|
-
|
|
3294
|
+
g.dataset.angle = p.id, g.dataset.testid = `rotation-preset-${p.id}`, this._rotationPresetChips.set(p.id, g), n.appendChild(g);
|
|
3320
3295
|
}), e.appendChild(n);
|
|
3321
3296
|
const l = d("div", { className: "rotation-arbitrary" }), h = d(
|
|
3322
3297
|
"div",
|
|
@@ -3333,8 +3308,8 @@ class ht {
|
|
|
3333
3308
|
step: "1",
|
|
3334
3309
|
value: String(Math.round(a)),
|
|
3335
3310
|
"aria-label": "Rotation angle",
|
|
3336
|
-
onInput: (
|
|
3337
|
-
onChange: (
|
|
3311
|
+
onInput: (p) => this._previewAngleValue(p.target.value),
|
|
3312
|
+
onChange: (p) => this._setRotation(Number(p.target.value))
|
|
3338
3313
|
}), this._rotationNumber = d("input", {
|
|
3339
3314
|
type: "number",
|
|
3340
3315
|
className: "text-input rotation-number-input",
|
|
@@ -3343,10 +3318,10 @@ class ht {
|
|
|
3343
3318
|
step: "1",
|
|
3344
3319
|
value: this._formatPlainAngle(a),
|
|
3345
3320
|
"aria-label": "Rotation angle in degrees",
|
|
3346
|
-
onKeyDown: (
|
|
3347
|
-
|
|
3321
|
+
onKeyDown: (p) => {
|
|
3322
|
+
p.key === "Enter" && (p.preventDefault(), this._setRotation(Number(p.target.value)), p.target.blur());
|
|
3348
3323
|
},
|
|
3349
|
-
onBlur: (
|
|
3324
|
+
onBlur: (p) => this._setRotation(Number(p.target.value))
|
|
3350
3325
|
});
|
|
3351
3326
|
const c = d(
|
|
3352
3327
|
"div",
|
|
@@ -3355,42 +3330,42 @@ class ht {
|
|
|
3355
3330
|
this._rotationNumber
|
|
3356
3331
|
);
|
|
3357
3332
|
l.appendChild(h), l.appendChild(c);
|
|
3358
|
-
const
|
|
3333
|
+
const u = j({
|
|
3359
3334
|
label: "Reset rotation",
|
|
3360
3335
|
className: "btn-text rotation-reset-btn",
|
|
3361
3336
|
onClick: () => this._setRotation(0)
|
|
3362
3337
|
});
|
|
3363
|
-
return
|
|
3338
|
+
return u.dataset.testid = "reset-rotation", l.appendChild(u), e.appendChild(l), e;
|
|
3364
3339
|
}
|
|
3365
3340
|
/**
|
|
3366
3341
|
* Subscribe to state changes
|
|
3367
3342
|
*/
|
|
3368
3343
|
_subscribeToState() {
|
|
3369
|
-
const e = this.state.on("change:crop.shape", ({ value:
|
|
3370
|
-
this._shapeChips.forEach((
|
|
3371
|
-
|
|
3344
|
+
const e = this.state.on("change:crop.shape", ({ value: r }) => {
|
|
3345
|
+
this._shapeChips.forEach((s, o) => {
|
|
3346
|
+
s.setActive(o === r);
|
|
3372
3347
|
}), this._updateAspectVisibility();
|
|
3373
3348
|
});
|
|
3374
3349
|
this._unsubscribers.push(e);
|
|
3375
|
-
const t = this.state.on("change:crop.aspect", ({ value:
|
|
3376
|
-
this._aspectChips.forEach((
|
|
3377
|
-
|
|
3350
|
+
const t = this.state.on("change:crop.aspect", ({ value: r }) => {
|
|
3351
|
+
this._aspectChips.forEach((s, o) => {
|
|
3352
|
+
s.setActive(o === r);
|
|
3378
3353
|
});
|
|
3379
3354
|
});
|
|
3380
3355
|
this._unsubscribers.push(t);
|
|
3381
|
-
const i = this.state.on("change:transform.rotation", ({ value:
|
|
3382
|
-
this._syncRotationControls(
|
|
3356
|
+
const i = this.state.on("change:transform.rotation", ({ value: r }) => {
|
|
3357
|
+
this._syncRotationControls(r);
|
|
3383
3358
|
});
|
|
3384
3359
|
this._unsubscribers.push(i);
|
|
3385
3360
|
}
|
|
3386
3361
|
_rotateBy(e) {
|
|
3387
|
-
var i,
|
|
3388
|
-
((
|
|
3362
|
+
var i, r;
|
|
3363
|
+
((r = (i = this.editor) == null ? void 0 : i.rotateBy) == null ? void 0 : r.call(i, e)) !== !1 && this._syncRotationControls(this.state.get("transform.rotation") ?? 0);
|
|
3389
3364
|
}
|
|
3390
3365
|
_setRotation(e) {
|
|
3391
|
-
var
|
|
3366
|
+
var r, s;
|
|
3392
3367
|
const t = W(e);
|
|
3393
|
-
if (((
|
|
3368
|
+
if (((s = (r = this.editor) == null ? void 0 : r.setRotationAngle) == null ? void 0 : s.call(r, t)) === !1) {
|
|
3394
3369
|
this._syncRotationControls(this.state.get("transform.rotation") ?? 0);
|
|
3395
3370
|
return;
|
|
3396
3371
|
}
|
|
@@ -3406,8 +3381,8 @@ class ht {
|
|
|
3406
3381
|
}
|
|
3407
3382
|
_refreshPresetChips(e) {
|
|
3408
3383
|
const t = Math.round(W(e)) % 360;
|
|
3409
|
-
this._rotationPresetChips.forEach((i,
|
|
3410
|
-
i.setActive(Number(
|
|
3384
|
+
this._rotationPresetChips.forEach((i, r) => {
|
|
3385
|
+
i.setActive(Number(r) === t);
|
|
3411
3386
|
});
|
|
3412
3387
|
}
|
|
3413
3388
|
_formatAngle(e) {
|
|
@@ -3467,8 +3442,8 @@ class ct {
|
|
|
3467
3442
|
* @param {Object} options - { onRemove, onReset, onClearAll, onUpdateValue, onSelect }
|
|
3468
3443
|
* @returns {HTMLElement}
|
|
3469
3444
|
*/
|
|
3470
|
-
render({ onRemove: e, onReset: t, onClearAll: i, onUpdateValue:
|
|
3471
|
-
this._onRemove = e, this._onReset = t, this._onClearAll = i, this._onUpdateValue =
|
|
3445
|
+
render({ onRemove: e, onReset: t, onClearAll: i, onUpdateValue: r, onSelect: s }) {
|
|
3446
|
+
this._onRemove = e, this._onReset = t, this._onClearAll = i, this._onUpdateValue = r, this._onSelect = s, this.element = d("div", {
|
|
3472
3447
|
className: "active-filters-panel",
|
|
3473
3448
|
"data-testid": "active-filters-panel"
|
|
3474
3449
|
});
|
|
@@ -3522,8 +3497,8 @@ class ct {
|
|
|
3522
3497
|
e.forEach((t) => {
|
|
3523
3498
|
const i = this.filterManager.getFilterDef(t);
|
|
3524
3499
|
if (!i) return;
|
|
3525
|
-
const
|
|
3526
|
-
this._filterItems.set(t,
|
|
3500
|
+
const r = this._createFilterItem(t, i);
|
|
3501
|
+
this._filterItems.set(t, r), this._listContainer.appendChild(r);
|
|
3527
3502
|
});
|
|
3528
3503
|
}
|
|
3529
3504
|
/**
|
|
@@ -3533,12 +3508,12 @@ class ct {
|
|
|
3533
3508
|
* @returns {HTMLElement}
|
|
3534
3509
|
*/
|
|
3535
3510
|
_createFilterItem(e, t) {
|
|
3536
|
-
const
|
|
3537
|
-
className: `active-filter-item ${
|
|
3511
|
+
const r = this.state.get("selectedFilter") === e, s = d("div", {
|
|
3512
|
+
className: `active-filter-item ${r ? "selected" : ""}`,
|
|
3538
3513
|
"data-active-filter": e,
|
|
3539
3514
|
"data-testid": `active-filter-${e}`,
|
|
3540
|
-
onClick: (
|
|
3541
|
-
|
|
3515
|
+
onClick: (p) => {
|
|
3516
|
+
p.target.closest(".filter-item-actions") || this._handleSelect(e);
|
|
3542
3517
|
}
|
|
3543
3518
|
}), o = d("div", { className: "filter-item-header" }), n = d("span", { className: "filter-item-name" }, t.name), a = d("div", { className: "filter-item-actions" }), l = O({
|
|
3544
3519
|
icon: ye,
|
|
@@ -3551,9 +3526,9 @@ class ct {
|
|
|
3551
3526
|
className: "btn-icon-sm btn-danger",
|
|
3552
3527
|
onClick: () => this._handleRemove(e)
|
|
3553
3528
|
});
|
|
3554
|
-
a.appendChild(l), a.appendChild(h), o.appendChild(n), o.appendChild(a),
|
|
3555
|
-
const c = this.state.getFilterValues(e),
|
|
3556
|
-
return
|
|
3529
|
+
a.appendChild(l), a.appendChild(h), o.appendChild(n), o.appendChild(a), s.appendChild(o);
|
|
3530
|
+
const c = this.state.getFilterValues(e), u = d("div", { className: "filter-item-summary" });
|
|
3531
|
+
return u.textContent = this._getValuesSummary(t, c), s.appendChild(u), s._summaryEl = u, s;
|
|
3557
3532
|
}
|
|
3558
3533
|
/**
|
|
3559
3534
|
* Normalize control type (handle aliases)
|
|
@@ -3582,11 +3557,11 @@ class ct {
|
|
|
3582
3557
|
if (!e.controls || !Array.isArray(e.controls))
|
|
3583
3558
|
return "Default values";
|
|
3584
3559
|
const i = [];
|
|
3585
|
-
return e.controls.forEach((
|
|
3586
|
-
const
|
|
3587
|
-
if (
|
|
3588
|
-
const o =
|
|
3589
|
-
n !==
|
|
3560
|
+
return e.controls.forEach((r) => {
|
|
3561
|
+
const s = this._normalizeControlType(r.type);
|
|
3562
|
+
if (s === "button") return;
|
|
3563
|
+
const o = r.label || r.id, n = t[r.id] ?? r.default;
|
|
3564
|
+
n !== r.default && (s === "slider" ? i.push(`${o}: ${this._formatValue(n)}`) : s === "toggle" ? n && i.push(o) : s === "color" ? i.push(`${o}: ${n}`) : s === "select" && i.push(`${o}: ${n}`));
|
|
3590
3565
|
}), i.length > 0 ? i.join(", ") : "Default values";
|
|
3591
3566
|
}
|
|
3592
3567
|
/**
|
|
@@ -3604,8 +3579,8 @@ class ct {
|
|
|
3604
3579
|
this._filterItems.forEach((e, t) => {
|
|
3605
3580
|
const i = this.filterManager.getFilterDef(t);
|
|
3606
3581
|
if (!i || !e._summaryEl) return;
|
|
3607
|
-
const
|
|
3608
|
-
e._summaryEl.textContent = this._getValuesSummary(i,
|
|
3582
|
+
const r = this.state.getFilterValues(t);
|
|
3583
|
+
e._summaryEl.textContent = this._getValuesSummary(i, r);
|
|
3609
3584
|
});
|
|
3610
3585
|
}
|
|
3611
3586
|
/**
|
|
@@ -3716,35 +3691,35 @@ const $ = {
|
|
|
3716
3691
|
lockAspectRatio: !1
|
|
3717
3692
|
}
|
|
3718
3693
|
};
|
|
3719
|
-
function dt(
|
|
3720
|
-
if (!
|
|
3694
|
+
function dt(f) {
|
|
3695
|
+
if (!f)
|
|
3721
3696
|
return { ...le.free };
|
|
3722
|
-
if (typeof
|
|
3723
|
-
return { ...$, ...
|
|
3724
|
-
const e = le[
|
|
3697
|
+
if (typeof f == "object" && f !== null)
|
|
3698
|
+
return { ...$, ...f };
|
|
3699
|
+
const e = le[f];
|
|
3725
3700
|
return e ? { ...e } : { ...le.free };
|
|
3726
3701
|
}
|
|
3727
|
-
function Z(
|
|
3728
|
-
if (!Number.isFinite(Number(
|
|
3729
|
-
const e = Number(
|
|
3702
|
+
function Z(f) {
|
|
3703
|
+
if (!Number.isFinite(Number(f))) return 0;
|
|
3704
|
+
const e = Number(f) % 360;
|
|
3730
3705
|
return e < 0 ? e + 360 : e;
|
|
3731
3706
|
}
|
|
3732
|
-
function ut(
|
|
3733
|
-
const t = Z(
|
|
3707
|
+
function ut(f, e) {
|
|
3708
|
+
const t = Z(f);
|
|
3734
3709
|
return (Z(e) - t + 540) % 360 - 180;
|
|
3735
3710
|
}
|
|
3736
|
-
class kt extends
|
|
3711
|
+
class kt extends se {
|
|
3737
3712
|
/**
|
|
3738
3713
|
* Create a new VanillaImageEditor
|
|
3739
3714
|
* @param {HTMLElement} container - Container element to mount the editor
|
|
3740
3715
|
* @param {Object} options - Configuration options
|
|
3741
3716
|
*/
|
|
3742
3717
|
constructor(e, t = {}) {
|
|
3743
|
-
var
|
|
3718
|
+
var s, o, n, a;
|
|
3744
3719
|
if (super(), !e)
|
|
3745
3720
|
throw new Error("VanillaImageEditor: container element is required");
|
|
3746
3721
|
this._container = e, this._destroyed = !1, this._loadVersion = 0, this._objectUrls = /* @__PURE__ */ new Set(), this._activeObjectUrl = null;
|
|
3747
|
-
const i = t.preset ? dt(t.preset) : null,
|
|
3722
|
+
const i = t.preset ? dt(t.preset) : null, r = i ? {
|
|
3748
3723
|
initialMode: i.initialMode === "crop" ? "crop" : "adjust",
|
|
3749
3724
|
cropShape: i.cropShape,
|
|
3750
3725
|
initialAspectRatio: i.aspectRatio
|
|
@@ -3761,9 +3736,9 @@ class kt extends re {
|
|
|
3761
3736
|
optionsEndpoint: "/api/v1/media/background-removal/options",
|
|
3762
3737
|
fallbackEndpoint: null
|
|
3763
3738
|
},
|
|
3764
|
-
...
|
|
3739
|
+
...r,
|
|
3765
3740
|
...t
|
|
3766
|
-
}, this._preset = i, this._state = Se(), this._state.set("theme", this._options.theme), this._state.set("crop.shape", this._options.cropShape), this._state.set("crop.aspect", this._options.initialAspectRatio), this._preset && (this._state.set("lockCropShape", !!this._preset.lockCropShape), this._state.set("lockAspectRatio", !!this._preset.lockAspectRatio), this._state.set("showFilters", this._preset.showFilters !== !1), this._state.set("showCropControls", this._preset.showCropControls !== !1), this._state.set("autoZoomOnCropOverflow", !!this._preset.autoZoomOnCropOverflow)), this._renderer = new Te(), this._filterManager = new Qe(this._state, this._renderer), this._cropManager = new ce(this._state, this._renderer), this._removeBgManager = null, this._backgroundRemovalAvailable = !1, ((
|
|
3741
|
+
}, this._preset = i, this._state = Se(), this._state.set("theme", this._options.theme), this._state.set("crop.shape", this._options.cropShape), this._state.set("crop.aspect", this._options.initialAspectRatio), this._preset && (this._state.set("lockCropShape", !!this._preset.lockCropShape), this._state.set("lockAspectRatio", !!this._preset.lockAspectRatio), this._state.set("showFilters", this._preset.showFilters !== !1), this._state.set("showCropControls", this._preset.showCropControls !== !1), this._state.set("autoZoomOnCropOverflow", !!this._preset.autoZoomOnCropOverflow)), this._renderer = new Te(), this._filterManager = new Qe(this._state, this._renderer), this._cropManager = new ce(this._state, this._renderer), this._removeBgManager = null, this._backgroundRemovalAvailable = !1, ((s = this._options.backgroundRemoval) == null ? void 0 : s.enabled) !== !1 && (this._removeBgManager = new Xe({
|
|
3767
3742
|
endpoint: (o = this._options.backgroundRemoval) == null ? void 0 : o.endpoint,
|
|
3768
3743
|
optionsEndpoint: (n = this._options.backgroundRemoval) == null ? void 0 : n.optionsEndpoint,
|
|
3769
3744
|
fallbackEndpoint: (a = this._options.backgroundRemoval) == null ? void 0 : a.fallbackEndpoint
|
|
@@ -3795,44 +3770,44 @@ class kt extends re {
|
|
|
3795
3770
|
accept: "image/*",
|
|
3796
3771
|
className: "hidden-file-input",
|
|
3797
3772
|
"aria-label": "Choose image file to edit",
|
|
3798
|
-
onChange: (
|
|
3773
|
+
onChange: (r) => this._handleFileSelect(r)
|
|
3799
3774
|
}), this._editorEl.appendChild(this._fileInput), this._container.appendChild(this._editorEl);
|
|
3800
3775
|
}
|
|
3801
3776
|
/**
|
|
3802
3777
|
* Initialize UI components
|
|
3803
3778
|
*/
|
|
3804
3779
|
_initUI() {
|
|
3805
|
-
this._toolbar = new et(this._state, this), this._toolbarContainer.appendChild(this._toolbar.render()), this._filterControlsEl = d("div", { className: "filter-controls-container" }), this._categoryCarousel = new tt(this._state, this), this._filterControlsEl.appendChild(this._categoryCarousel.render((
|
|
3780
|
+
this._toolbar = new et(this._state, this), this._toolbarContainer.appendChild(this._toolbar.render()), this._filterControlsEl = d("div", { className: "filter-controls-container" }), this._categoryCarousel = new tt(this._state, this), this._filterControlsEl.appendChild(this._categoryCarousel.render((r) => {
|
|
3806
3781
|
}));
|
|
3807
3782
|
const e = d("div", { className: "filter-layout" }), t = d("div", { className: "filter-left-column" });
|
|
3808
3783
|
this._filterCarousel = new it(this._state, this._filterManager), t.appendChild(this._filterCarousel.render({
|
|
3809
|
-
onToggle: (
|
|
3810
|
-
onSelect: (
|
|
3811
|
-
this._handleFilterSelect(
|
|
3784
|
+
onToggle: (r, s) => this._handleFilterToggle(r, s),
|
|
3785
|
+
onSelect: (r) => {
|
|
3786
|
+
this._handleFilterSelect(r), this._isMobile && this._mobileFilterDrawer && this._mobileFilterDrawer.open(r);
|
|
3812
3787
|
}
|
|
3813
|
-
})), this._filterAdjustments = new
|
|
3814
|
-
onChange: (
|
|
3815
|
-
onReset: (
|
|
3816
|
-
onAction: (
|
|
3788
|
+
})), this._filterAdjustments = new rt(this._state, this._filterManager), t.appendChild(this._filterAdjustments.render({
|
|
3789
|
+
onChange: (r, s, o) => this._handleFilterChange(r, s, o),
|
|
3790
|
+
onReset: (r) => this._handleFilterReset(r),
|
|
3791
|
+
onAction: (r, s) => this._handleFilterAction(r, s)
|
|
3817
3792
|
})), e.appendChild(t);
|
|
3818
3793
|
const i = d("div", { className: "filter-right-column" });
|
|
3819
3794
|
this._activeFiltersPanel = new ct(this._state, this._filterManager), i.appendChild(this._activeFiltersPanel.render({
|
|
3820
|
-
onRemove: (
|
|
3821
|
-
onReset: (
|
|
3795
|
+
onRemove: (r) => this._handleFilterToggle(r, !1),
|
|
3796
|
+
onReset: (r) => this._handleFilterReset(r),
|
|
3822
3797
|
onClearAll: () => this.resetAll(),
|
|
3823
|
-
onSelect: (
|
|
3798
|
+
onSelect: (r) => this._handleFilterSelect(r)
|
|
3824
3799
|
})), e.appendChild(i), this._filterControlsEl.appendChild(e), this._mobileActiveFilters = new nt(this._state, this._filterManager), this._filterControlsEl.appendChild(this._mobileActiveFilters.render({
|
|
3825
|
-
onToggle: (
|
|
3826
|
-
onSelect: (
|
|
3827
|
-
this._handleFilterSelect(
|
|
3800
|
+
onToggle: (r, s) => this._handleFilterToggle(r, s),
|
|
3801
|
+
onSelect: (r) => {
|
|
3802
|
+
this._handleFilterSelect(r), this._isMobile && this._mobileFilterDrawer && this._mobileFilterDrawer.open(r);
|
|
3828
3803
|
}
|
|
3829
|
-
})), this._cropControls = new ht(this._state, this._cropManager, this), this._cropControlsEl = this._cropControls.render(), this._cropControlsEl.style.display = "none", this._controlsSection.appendChild(this._filterControlsEl), this._controlsSection.appendChild(this._cropControlsEl), this._mobileFilterDrawer = new
|
|
3830
|
-
onChange: (
|
|
3831
|
-
onReset: (
|
|
3832
|
-
onRemove: (
|
|
3833
|
-
this._handleFilterToggle(
|
|
3804
|
+
})), this._cropControls = new ht(this._state, this._cropManager, this), this._cropControlsEl = this._cropControls.render(), this._cropControlsEl.style.display = "none", this._controlsSection.appendChild(this._filterControlsEl), this._controlsSection.appendChild(this._cropControlsEl), this._mobileFilterDrawer = new st(this._state, this._filterManager), this._mobileFilterDrawer.build(this._controlsSection, {
|
|
3805
|
+
onChange: (r, s, o) => this._handleFilterChange(r, s, o),
|
|
3806
|
+
onReset: (r) => this._handleFilterReset(r),
|
|
3807
|
+
onRemove: (r) => {
|
|
3808
|
+
this._handleFilterToggle(r, !1), this._state.set("selectedFilter", null);
|
|
3834
3809
|
},
|
|
3835
|
-
onAction: (
|
|
3810
|
+
onAction: (r, s) => this._handleFilterAction(r, s)
|
|
3836
3811
|
});
|
|
3837
3812
|
}
|
|
3838
3813
|
/**
|
|
@@ -3961,20 +3936,20 @@ class kt extends re {
|
|
|
3961
3936
|
if (this._destroyed) return;
|
|
3962
3937
|
(a = (n = this._removeBgManager) == null ? void 0 : n.cancelActiveRequests) == null || a.call(n, "image-load");
|
|
3963
3938
|
const i = ++this._loadVersion;
|
|
3964
|
-
let
|
|
3965
|
-
this._resetEditorState(), this._state.set("hasImage", !1), this._state.set("imageUrl", null), e instanceof Blob && (
|
|
3966
|
-
const o = await this._renderer.loadTexture(
|
|
3939
|
+
let r = e, s = null;
|
|
3940
|
+
this._resetEditorState(), this._state.set("hasImage", !1), this._state.set("imageUrl", null), e instanceof Blob && (r = URL.createObjectURL(e), s = r, this._objectUrls.add(r));
|
|
3941
|
+
const o = await this._renderer.loadTexture(r, {
|
|
3967
3942
|
isCurrent: () => !this._destroyed && this._loadVersion === i
|
|
3968
3943
|
});
|
|
3969
3944
|
if (this._destroyed || this._loadVersion !== i) {
|
|
3970
|
-
this._revokeObjectUrl(
|
|
3945
|
+
this._revokeObjectUrl(s);
|
|
3971
3946
|
return;
|
|
3972
3947
|
}
|
|
3973
3948
|
if (!o) {
|
|
3974
|
-
this._revokeObjectUrl(
|
|
3949
|
+
this._revokeObjectUrl(s), this.emit("error", new Error("Failed to load image"));
|
|
3975
3950
|
return;
|
|
3976
3951
|
}
|
|
3977
|
-
|
|
3952
|
+
s ? this._replaceActiveObjectUrl(s) : this._clearActiveObjectUrl(), this._state.set("hasImage", !0), this._state.set("imageUrl", r), t.state && this._hydrateState(t.state), this._options.initialMode === "crop" && this.setMode("crop"), this.emit("imageLoaded", { url: r });
|
|
3978
3953
|
}
|
|
3979
3954
|
/**
|
|
3980
3955
|
* Reset all editor state (filters + crop) to a clean baseline.
|
|
@@ -3993,20 +3968,20 @@ class kt extends re {
|
|
|
3993
3968
|
if (!e || e.version !== 1) return;
|
|
3994
3969
|
const t = Z(((i = e.transform) == null ? void 0 : i.rotation) ?? 0);
|
|
3995
3970
|
if (t !== 0 && this._renderer.rotateBy(t) && this._state.set("transform.rotation", t), e.crop) {
|
|
3996
|
-
const
|
|
3997
|
-
e.crop.rect && (this._cropManager.applyFromPixelRect(e.crop.rect,
|
|
3971
|
+
const r = e.crop.shape || "free", s = e.crop.aspectRatio || "free";
|
|
3972
|
+
e.crop.rect && (this._cropManager.applyFromPixelRect(e.crop.rect, r), this._state.set("crop.appliedRect", { ...e.crop.rect }), this._state.set("crop.appliedShape", r), this._state.set("crop.appliedAspect", s)), this._state.set("crop.shape", r), this._state.set("crop.aspect", s);
|
|
3998
3973
|
}
|
|
3999
3974
|
if (Array.isArray(e.filters)) {
|
|
4000
|
-
let
|
|
4001
|
-
for (const
|
|
4002
|
-
if (
|
|
4003
|
-
for (const [o, n] of Object.entries(
|
|
4004
|
-
this._state.setFilterValue(
|
|
4005
|
-
if (
|
|
4006
|
-
this._state.set("selectedFilter",
|
|
4007
|
-
const
|
|
4008
|
-
if (typeof (
|
|
4009
|
-
const o = Ye[
|
|
3975
|
+
let r = null;
|
|
3976
|
+
for (const s of e.filters)
|
|
3977
|
+
if (s.enabled && (r === null && (r = s.id), this._state.toggleFilter(s.id, !0), this._filterManager.initializeValues(s.id), s.values))
|
|
3978
|
+
for (const [o, n] of Object.entries(s.values))
|
|
3979
|
+
this._state.setFilterValue(s.id, o, n);
|
|
3980
|
+
if (r !== null) {
|
|
3981
|
+
this._state.set("selectedFilter", r);
|
|
3982
|
+
const s = this._filterManager.getFilterDef(r);
|
|
3983
|
+
if (typeof (s == null ? void 0 : s.category) == "string") {
|
|
3984
|
+
const o = Ye[s.category] ?? s.category;
|
|
4010
3985
|
this._state.set("selectedCategory", o);
|
|
4011
3986
|
}
|
|
4012
3987
|
}
|
|
@@ -4092,11 +4067,11 @@ class kt extends re {
|
|
|
4092
4067
|
values: { ...n }
|
|
4093
4068
|
});
|
|
4094
4069
|
}
|
|
4095
|
-
const i = this._state.get("crop.appliedRect"),
|
|
4070
|
+
const i = this._state.get("crop.appliedRect"), r = this._state.get("crop.rect"), s = i || r;
|
|
4096
4071
|
return {
|
|
4097
4072
|
version: 1,
|
|
4098
4073
|
crop: {
|
|
4099
|
-
rect:
|
|
4074
|
+
rect: s ? { ...s } : null,
|
|
4100
4075
|
aspectRatio: this._state.get("crop.appliedAspect") || this._state.get("crop.aspect") || "free",
|
|
4101
4076
|
shape: this._state.get("crop.appliedShape") || this._state.get("crop.shape") || "free"
|
|
4102
4077
|
},
|
|
@@ -4137,11 +4112,11 @@ class kt extends re {
|
|
|
4137
4112
|
}
|
|
4138
4113
|
setRotationAngle(e) {
|
|
4139
4114
|
if (!this._state.get("hasImage")) return !1;
|
|
4140
|
-
const t = Z(this._state.get("transform.rotation") ?? 0), i = Z(e),
|
|
4141
|
-
if (Math.abs(
|
|
4142
|
-
if (
|
|
4143
|
-
return
|
|
4144
|
-
this._filterManager.applyFilters(), this._state.set("crop.rect", null), this._state.set("crop.dirty", !1),
|
|
4115
|
+
const t = Z(this._state.get("transform.rotation") ?? 0), i = Z(e), r = ut(t, i), s = this._state.get("mode") === "crop";
|
|
4116
|
+
if (Math.abs(r) > 1e-3) {
|
|
4117
|
+
if (s && this._cropManager.disable(), !this._renderer.rotateBy(r))
|
|
4118
|
+
return s && this._cropManager.enable(), !1;
|
|
4119
|
+
this._filterManager.applyFilters(), this._state.set("crop.rect", null), this._state.set("crop.dirty", !1), s && this._cropManager.enable();
|
|
4145
4120
|
}
|
|
4146
4121
|
return this._state.set("transform.rotation", i), this.emit("transformChanged", { rotation: i }), !0;
|
|
4147
4122
|
}
|
|
@@ -4195,10 +4170,10 @@ class kt extends re {
|
|
|
4195
4170
|
throw new Error("Background removal is not available for the current editor state");
|
|
4196
4171
|
this._state.set("isProcessing", !0), this._showLoadingOverlay("Removing background...");
|
|
4197
4172
|
try {
|
|
4198
|
-
const
|
|
4199
|
-
if (!
|
|
4173
|
+
const r = this.exportImage("png");
|
|
4174
|
+
if (!r)
|
|
4200
4175
|
throw new Error("Failed to export image for background removal");
|
|
4201
|
-
const
|
|
4176
|
+
const s = await this._removeBgManager.preparePreviewRequest(r, e), o = this._buildPreviewBackgroundRemovalContext(s), n = await this._removeBgManager.removeBackground(s.blob, s);
|
|
4202
4177
|
return await this._isCurrentPreviewBackgroundRemovalContext(o, n) ? (await this.loadImage(n.dataUrl), this.emit("background-removed", {
|
|
4203
4178
|
model: n.model,
|
|
4204
4179
|
processMs: n.processMs
|
|
@@ -4209,8 +4184,8 @@ class kt extends re {
|
|
|
4209
4184
|
operationId: o.operationId,
|
|
4210
4185
|
sourceHash: o.sourceHash
|
|
4211
4186
|
}), { stale: !0 });
|
|
4212
|
-
} catch (
|
|
4213
|
-
throw this.emit("error", { error:
|
|
4187
|
+
} catch (r) {
|
|
4188
|
+
throw this.emit("error", { error: r, context: "background-removal" }), r;
|
|
4214
4189
|
} finally {
|
|
4215
4190
|
(i = (t = this._state) == null ? void 0 : t.set) == null || i.call(t, "isProcessing", !1), this._hideLoadingOverlay();
|
|
4216
4191
|
}
|
|
@@ -4260,8 +4235,8 @@ class kt extends re {
|
|
|
4260
4235
|
d("div", { className: "editor-loading-text" }, e)
|
|
4261
4236
|
]);
|
|
4262
4237
|
else {
|
|
4263
|
-
const
|
|
4264
|
-
|
|
4238
|
+
const r = this._loadingOverlay.querySelector(".editor-loading-text");
|
|
4239
|
+
r && (r.textContent = e);
|
|
4265
4240
|
}
|
|
4266
4241
|
const t = (i = this._canvasContainer) == null ? void 0 : i.parentElement;
|
|
4267
4242
|
t && !this._loadingOverlay.parentElement && t.appendChild(this._loadingOverlay);
|
|
@@ -4277,14 +4252,14 @@ class kt extends re {
|
|
|
4277
4252
|
* Destroy the editor and clean up
|
|
4278
4253
|
*/
|
|
4279
4254
|
destroy() {
|
|
4280
|
-
var e, t, i,
|
|
4255
|
+
var e, t, i, r, s, o, n, a, l, h, c, u;
|
|
4281
4256
|
this._destroyed = !0, (t = (e = this._removeBgManager) == null ? void 0 : e.cancelActiveRequests) == null || t.call(e, "editor-destroy");
|
|
4282
|
-
for (const
|
|
4257
|
+
for (const p of this._objectUrls)
|
|
4283
4258
|
try {
|
|
4284
|
-
URL.revokeObjectURL(
|
|
4259
|
+
URL.revokeObjectURL(p);
|
|
4285
4260
|
} catch {
|
|
4286
4261
|
}
|
|
4287
|
-
this._objectUrls.clear(), this._activeObjectUrl = null, (i = this._resizeObserver) == null || i.disconnect(), this._renderer.destroy(), this._cropManager.disable(), this._handleWindowResize && window.removeEventListener("resize", this._handleWindowResize), (
|
|
4262
|
+
this._objectUrls.clear(), this._activeObjectUrl = null, (i = this._resizeObserver) == null || i.disconnect(), this._renderer.destroy(), this._cropManager.disable(), this._handleWindowResize && window.removeEventListener("resize", this._handleWindowResize), (r = this._toolbar) == null || r.destroy(), (s = this._categoryCarousel) == null || s.destroy(), (o = this._filterCarousel) == null || o.destroy(), (n = this._filterAdjustments) == null || n.destroy(), (a = this._mobileFilterDrawer) == null || a.destroy(), (l = this._mobileActiveFilters) == null || l.destroy(), (h = this._cropControls) == null || h.destroy(), (c = this._activeFiltersPanel) == null || c.destroy(), (u = this._editorEl) == null || u.remove(), this._container = null, this._state = null, this.emit("destroyed"), this.removeAllListeners();
|
|
4288
4263
|
}
|
|
4289
4264
|
}
|
|
4290
4265
|
export {
|
|
@@ -4324,4 +4299,4 @@ export {
|
|
|
4324
4299
|
ht as y,
|
|
4325
4300
|
_t as z
|
|
4326
4301
|
};
|
|
4327
|
-
//# sourceMappingURL=editor-
|
|
4302
|
+
//# sourceMappingURL=editor-BQ_nY4P6.js.map
|