@liwe3/webcomponents 1.0.14 → 1.1.10
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/AIMarkdownEditor.d.ts +35 -0
- package/dist/AIMarkdownEditor.d.ts.map +1 -0
- package/dist/AIMarkdownEditor.js +412 -0
- package/dist/AIMarkdownEditor.js.map +1 -0
- package/dist/AITextEditor.d.ts +183 -0
- package/dist/AITextEditor.d.ts.map +1 -0
- package/dist/AITextEditor.js +63 -27
- package/dist/AITextEditor.js.map +1 -1
- package/dist/ButtonToolbar.d.ts +35 -0
- package/dist/ButtonToolbar.d.ts.map +1 -0
- package/dist/ButtonToolbar.js +220 -0
- package/dist/ButtonToolbar.js.map +1 -0
- package/dist/CheckList.d.ts +31 -0
- package/dist/CheckList.d.ts.map +1 -0
- package/dist/CheckList.js +336 -0
- package/dist/CheckList.js.map +1 -0
- package/dist/ChunkUploader.d.ts +125 -0
- package/dist/ChunkUploader.d.ts.map +1 -0
- package/dist/ChunkUploader.js +756 -0
- package/dist/ChunkUploader.js.map +1 -0
- package/dist/ComicBalloon.d.ts +82 -0
- package/dist/ComicBalloon.d.ts.map +1 -0
- package/dist/ComicBalloon.js +346 -0
- package/dist/ComicBalloon.js.map +1 -0
- package/dist/ContainerBox.d.ts +112 -0
- package/dist/ContainerBox.d.ts.map +1 -0
- package/dist/ContainerBox.js +359 -0
- package/dist/ContainerBox.js.map +1 -0
- package/dist/DateSelector.d.ts +103 -0
- package/dist/DateSelector.d.ts.map +1 -0
- package/dist/Dialog.d.ts +102 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +299 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Drawer.d.ts +63 -0
- package/dist/Drawer.d.ts.map +1 -0
- package/dist/Drawer.js +340 -0
- package/dist/Drawer.js.map +1 -0
- package/dist/ImageView.d.ts +42 -0
- package/dist/ImageView.d.ts.map +1 -0
- package/dist/ImageView.js +209 -0
- package/dist/ImageView.js.map +1 -0
- package/dist/MarkdownPreview.d.ts +25 -0
- package/dist/MarkdownPreview.d.ts.map +1 -0
- package/dist/MarkdownPreview.js +147 -0
- package/dist/MarkdownPreview.js.map +1 -0
- package/dist/PopoverMenu.d.ts +103 -0
- package/dist/PopoverMenu.d.ts.map +1 -0
- package/dist/ResizableCropper.d.ts +158 -0
- package/dist/ResizableCropper.d.ts.map +1 -0
- package/dist/ResizableCropper.js +562 -0
- package/dist/ResizableCropper.js.map +1 -0
- package/dist/SmartSelect.d.ts +100 -0
- package/dist/SmartSelect.d.ts.map +1 -0
- package/dist/SmartSelect.js +45 -2
- package/dist/SmartSelect.js.map +1 -1
- package/dist/Toast.d.ts +127 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +79 -49
- package/dist/Toast.js.map +1 -1
- package/dist/TreeView.d.ts +84 -0
- package/dist/TreeView.d.ts.map +1 -0
- package/dist/TreeView.js +478 -0
- package/dist/TreeView.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -14
- package/dist/index.js.map +1 -1
- package/package.json +60 -5
- package/src/AIMarkdownEditor.ts +568 -0
- package/src/AITextEditor.ts +97 -2
- package/src/ButtonToolbar.ts +302 -0
- package/src/CheckList.ts +438 -0
- package/src/ChunkUploader.ts +1135 -0
- package/src/ComicBalloon.ts +709 -0
- package/src/ContainerBox.ts +570 -0
- package/src/Dialog.ts +510 -0
- package/src/Drawer.ts +435 -0
- package/src/ImageView.ts +265 -0
- package/src/MarkdownPreview.ts +213 -0
- package/src/ResizableCropper.ts +1099 -0
- package/src/SmartSelect.ts +48 -2
- package/src/Toast.ts +96 -32
- package/src/TreeView.ts +673 -0
- package/src/index.ts +129 -27
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
class f extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(), this.state = {
|
|
4
|
+
width: 200,
|
|
5
|
+
height: 150,
|
|
6
|
+
minWidth: 50,
|
|
7
|
+
minHeight: 50,
|
|
8
|
+
aspectRatio: null,
|
|
9
|
+
contentElement: null,
|
|
10
|
+
contentLeft: 0,
|
|
11
|
+
contentTop: 0,
|
|
12
|
+
rotation: 0,
|
|
13
|
+
wrapperLeft: 0,
|
|
14
|
+
wrapperTop: 0
|
|
15
|
+
}, this.isDragging = !1, this.dragAction = null, this.dragHandle = null, this.dragStartX = 0, this.dragStartY = 0, this.dragStartWidth = 0, this.dragStartHeight = 0, this.dragStartContentLeft = 0, this.dragStartContentTop = 0, this.dragStartContentWidth = 0, this.dragStartContentHeight = 0, this.initialContentWidth = 0, this.initialContentHeight = 0, this._dragStartRotation = 0, this._dragStartPointerAngle = 0, this._dragRotateCenterX = 0, this._dragRotateCenterY = 0, this._interactionMode = "transform", this._dragPointerOffsetX = 0, this._dragPointerOffsetY = 0, this._dragMoveContainer = null, this.handleWrapperDoubleClick = (t) => {
|
|
16
|
+
this.disabled || (t.preventDefault(), t.stopPropagation(), this._setInteractionMode("crop"));
|
|
17
|
+
}, this.handleDocumentPointerDown = (t) => {
|
|
18
|
+
this._interactionMode !== "crop" || t.composedPath().includes(this) || this._setInteractionMode("transform");
|
|
19
|
+
}, this.handleWrapperPointerDown = (t) => {
|
|
20
|
+
if (this.disabled || !this.allowDrag || this._interactionMode !== "transform" || t.target.closest("[data-action]")) return;
|
|
21
|
+
t.preventDefault(), t.stopPropagation();
|
|
22
|
+
const n = this._getContainerForMove();
|
|
23
|
+
this._dragMoveContainer = n, this._ensureAbsolutePositionForMove(n), this._syncWrapperPositionFromLayout(n);
|
|
24
|
+
const i = this.getBoundingClientRect();
|
|
25
|
+
this._dragPointerOffsetX = t.clientX - i.left, this._dragPointerOffsetY = t.clientY - i.top, this.isDragging = !0, this.dragAction = "move", this.dragHandle = null, this.dragStartX = t.clientX, this.dragStartY = t.clientY, document.addEventListener("pointermove", this.handlePointerMove), document.addEventListener("pointerup", this.handlePointerUp), this.dispatchEvent(new CustomEvent("rcw:move-start", { detail: { action: "move" } }));
|
|
26
|
+
}, this.handlePointerDown = (t) => {
|
|
27
|
+
if (this.disabled) return;
|
|
28
|
+
const n = t.target.closest("[data-action]");
|
|
29
|
+
if (!n || (t.preventDefault(), t.stopPropagation(), this.dragAction = n.dataset.action, this.dragAction === "crop" && this._interactionMode !== "crop") || this.dragAction === "rotate" && !this.allowRotate) return;
|
|
30
|
+
if (this.isDragging = !0, this.dragHandle = n.dataset.corner || n.dataset.side || null, this.dragStartX = t.clientX, this.dragStartY = t.clientY, this.dragStartWidth = this.state.width, this.dragStartHeight = this.state.height, this.dragStartContentLeft = this.state.contentLeft, this.dragStartContentTop = this.state.contentTop, this.state.contentElement && (this.dragStartContentWidth = this.state.contentElement.offsetWidth, this.dragStartContentHeight = this.state.contentElement.offsetHeight), this.dragAction === "rotate") {
|
|
31
|
+
const s = this.wrapper.getBoundingClientRect();
|
|
32
|
+
this._dragRotateCenterX = s.left + s.width / 2, this._dragRotateCenterY = s.top + s.height / 2, this._dragStartPointerAngle = Math.atan2(t.clientY - this._dragRotateCenterY, t.clientX - this._dragRotateCenterX), this._dragStartRotation = this.state.rotation;
|
|
33
|
+
}
|
|
34
|
+
document.addEventListener("pointermove", this.handlePointerMove), document.addEventListener("pointerup", this.handlePointerUp);
|
|
35
|
+
const i = this.dragAction === "scale" ? "rcw:scale-start" : this.dragAction === "crop" ? "rcw:crop-start" : "rcw:rotate-start";
|
|
36
|
+
this.dispatchEvent(
|
|
37
|
+
new CustomEvent(i, {
|
|
38
|
+
detail: { action: this.dragAction, handle: this.dragHandle }
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}, this.handleContentPointerDown = (t) => {
|
|
42
|
+
this.disabled || this._interactionMode !== "crop" || !this.state.contentElement || !(this.state.contentElement.offsetWidth > this.state.width || this.state.contentElement.offsetHeight > this.state.height) || (t.preventDefault(), t.stopPropagation(), this.isDragging = !0, this.dragAction = "pan", this.dragHandle = null, this.dragStartX = t.clientX, this.dragStartY = t.clientY, this.dragStartContentLeft = this.state.contentLeft, this.dragStartContentTop = this.state.contentTop, document.addEventListener("pointermove", this.handlePointerMove), document.addEventListener("pointerup", this.handlePointerUp), this.dispatchEvent(
|
|
43
|
+
new CustomEvent("rcw:pan-start", {
|
|
44
|
+
detail: { action: "pan" }
|
|
45
|
+
})
|
|
46
|
+
));
|
|
47
|
+
}, this.handlePointerMove = (t) => {
|
|
48
|
+
if (!this.isDragging) return;
|
|
49
|
+
if (this.dragAction === "move") {
|
|
50
|
+
const i = this._dragMoveContainer || this._getContainerForMove(), s = i.getBoundingClientRect(), a = s.left + i.clientLeft, o = s.top + i.clientTop;
|
|
51
|
+
this.state.wrapperLeft = t.clientX - a + i.scrollLeft - this._dragPointerOffsetX, this.state.wrapperTop = t.clientY - o + i.scrollTop - this._dragPointerOffsetY, this.style.left = `${this.state.wrapperLeft}px`, this.style.top = `${this.state.wrapperTop}px`, this.dispatchChange("move");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.dragAction === "rotate") {
|
|
55
|
+
this.handleRotate(t.clientX, t.clientY), this.dispatchChange("rotate");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const e = t.clientX - this.dragStartX, n = t.clientY - this.dragStartY;
|
|
59
|
+
this.dragAction === "scale" ? this.handleScale(e, n, this.dragHandle) : this.dragAction === "crop" ? this.handleCrop(e, n, this.dragHandle) : this.dragAction === "pan" && this.handlePan(e, n), this.dispatchChange(this.dragAction);
|
|
60
|
+
}, this.handlePointerUp = () => {
|
|
61
|
+
this.isDragging && (this.isDragging = !1, document.removeEventListener("pointermove", this.handlePointerMove), document.removeEventListener("pointerup", this.handlePointerUp), this.dragAction && this.dispatchChange(this.dragAction), this.dragAction = null, this.dragHandle = null, this._dragMoveContainer = null);
|
|
62
|
+
}, this.attachShadow({ mode: "open" }), this.render();
|
|
63
|
+
}
|
|
64
|
+
static get observedAttributes() {
|
|
65
|
+
return ["width", "height", "min-width", "min-height", "aspect-ratio", "disabled", "allow-crop", "allow-resize", "allow-rotate", "allow-drag"];
|
|
66
|
+
}
|
|
67
|
+
attributeChangedCallback(t, e, n) {
|
|
68
|
+
if (e !== n)
|
|
69
|
+
switch (t) {
|
|
70
|
+
case "width":
|
|
71
|
+
this.state.width = parseFloat(n || "200"), this.updateWrapperDimensions();
|
|
72
|
+
break;
|
|
73
|
+
case "height":
|
|
74
|
+
this.state.height = parseFloat(n || "150"), this.updateWrapperDimensions();
|
|
75
|
+
break;
|
|
76
|
+
case "min-width":
|
|
77
|
+
this.state.minWidth = parseFloat(n || "50");
|
|
78
|
+
break;
|
|
79
|
+
case "min-height":
|
|
80
|
+
this.state.minHeight = parseFloat(n || "50");
|
|
81
|
+
break;
|
|
82
|
+
case "aspect-ratio":
|
|
83
|
+
this.state.aspectRatio = n;
|
|
84
|
+
break;
|
|
85
|
+
case "allow-crop":
|
|
86
|
+
case "allow-resize":
|
|
87
|
+
case "allow-rotate":
|
|
88
|
+
case "allow-drag":
|
|
89
|
+
this.updateHandlesVisibility(), this._applyInteractionModeUI();
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
connectedCallback() {
|
|
94
|
+
this.wrapper = this.shadowRoot.querySelector("#wrapper"), this.shadowRoot.querySelector("#clipper"), this.contentSlot = this.shadowRoot.querySelector("slot"), this.handlesContainer = this.shadowRoot.querySelector("#handles-container"), this.updateWrapperDimensions(), this.updateHandlesVisibility(), this._applyInteractionModeUI(), this._syncWrapperPositionFromLayout(this._getContainerForMove()), this.bindEvents(), this.contentSlot.addEventListener("slotchange", () => {
|
|
95
|
+
this.updateContentElement();
|
|
96
|
+
}), this.updateContentElement();
|
|
97
|
+
}
|
|
98
|
+
disconnectedCallback() {
|
|
99
|
+
this.unbindEvents();
|
|
100
|
+
}
|
|
101
|
+
_applyInteractionModeUI() {
|
|
102
|
+
this.wrapper && (this.wrapper.style.cursor = this._interactionMode === "transform" && this.allowDrag && !this.disabled ? "move" : "");
|
|
103
|
+
}
|
|
104
|
+
_setInteractionMode(t) {
|
|
105
|
+
this._interactionMode !== t && (this._interactionMode = t, this.updateHandlesVisibility(), this._applyInteractionModeUI());
|
|
106
|
+
}
|
|
107
|
+
updateContentElement() {
|
|
108
|
+
const t = this.contentSlot.assignedElements();
|
|
109
|
+
t.length > 0 && (this.state.contentElement = t[0], this.state.contentElement.style.position = "absolute", this.state.contentElement.style.left = `${this.state.contentLeft}px`, this.state.contentElement.style.top = `${this.state.contentTop}px`, this.state.contentElement instanceof HTMLImageElement && (this.state.contentElement.complete ? this.initializeContentSize() : this.state.contentElement.addEventListener("load", () => {
|
|
110
|
+
this.initializeContentSize();
|
|
111
|
+
}, { once: !0 })));
|
|
112
|
+
}
|
|
113
|
+
initializeContentSize() {
|
|
114
|
+
if (!this.state.contentElement) return;
|
|
115
|
+
const t = this.state.contentElement.offsetWidth, e = this.state.contentElement.offsetHeight;
|
|
116
|
+
t > 0 && (this.state.contentElement.style.width = `${t}px`, this.state.contentElement.style.height = "auto", this.initialContentWidth = t, this.initialContentHeight = e);
|
|
117
|
+
}
|
|
118
|
+
updateWrapperDimensions() {
|
|
119
|
+
this.wrapper && (this.wrapper.style.width = `${this.state.width}px`, this.wrapper.style.height = `${this.state.height}px`, this._applyWrapperTransform());
|
|
120
|
+
}
|
|
121
|
+
_applyWrapperTransform() {
|
|
122
|
+
this.wrapper && (this.wrapper.style.transformOrigin = "center center", this.wrapper.style.transform = `rotate(${this.state.rotation}deg)`);
|
|
123
|
+
}
|
|
124
|
+
updateHandlesVisibility() {
|
|
125
|
+
if (!this.handlesContainer) return;
|
|
126
|
+
const t = this.handlesContainer.querySelector('[data-action="scale"]'), e = this.handlesContainer.querySelector('[data-action="rotate"]'), n = this.handlesContainer.querySelectorAll('[data-action="crop"]');
|
|
127
|
+
t && (t.style.display = this.allowResize ? "" : "none"), e && (e.style.display = this.allowRotate ? "" : "none"), n.forEach((i) => {
|
|
128
|
+
i.style.display = this.allowCrop && this._interactionMode === "crop" ? "" : "none";
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
bindEvents() {
|
|
132
|
+
this.handlesContainer.addEventListener("pointerdown", this.handlePointerDown), this.wrapper.addEventListener("pointerdown", this.handleWrapperPointerDown), this.wrapper.addEventListener("dblclick", this.handleWrapperDoubleClick), document.addEventListener("pointerdown", this.handleDocumentPointerDown, !0), this.contentSlot.addEventListener("slotchange", () => {
|
|
133
|
+
const t = this.contentSlot.assignedElements();
|
|
134
|
+
t.length > 0 && t[0].addEventListener("pointerdown", this.handleContentPointerDown);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
unbindEvents() {
|
|
138
|
+
this.handlesContainer.removeEventListener("pointerdown", this.handlePointerDown), this.wrapper.removeEventListener("pointerdown", this.handleWrapperPointerDown), this.wrapper.removeEventListener("dblclick", this.handleWrapperDoubleClick), document.removeEventListener("pointerdown", this.handleDocumentPointerDown, !0);
|
|
139
|
+
const t = this.contentSlot.assignedElements();
|
|
140
|
+
t.length > 0 && t[0].removeEventListener("pointerdown", this.handleContentPointerDown);
|
|
141
|
+
}
|
|
142
|
+
_getContainerForMove() {
|
|
143
|
+
return this.parentElement || this.offsetParent || document.body;
|
|
144
|
+
}
|
|
145
|
+
_ensureContainerPositionedForMove(t) {
|
|
146
|
+
window.getComputedStyle(t).position === "static" && (t.style.position = "relative");
|
|
147
|
+
}
|
|
148
|
+
_syncWrapperPositionFromLayout(t) {
|
|
149
|
+
const e = t.getBoundingClientRect(), n = this.getBoundingClientRect(), i = t.scrollLeft, s = t.scrollTop, a = e.left + t.clientLeft, o = e.top + t.clientTop;
|
|
150
|
+
this.state.wrapperLeft = n.left - a + i, this.state.wrapperTop = n.top - o + s;
|
|
151
|
+
}
|
|
152
|
+
_ensureAbsolutePositionForMove(t) {
|
|
153
|
+
this._ensureContainerPositionedForMove(t), this._syncWrapperPositionFromLayout(t), this.style.position = "absolute", this.style.left = `${this.state.wrapperLeft}px`, this.style.top = `${this.state.wrapperTop}px`, this.style.touchAction = "none";
|
|
154
|
+
}
|
|
155
|
+
handleRotate(t, e) {
|
|
156
|
+
const s = (Math.atan2(e - this._dragRotateCenterY, t - this._dragRotateCenterX) - this._dragStartPointerAngle) * (180 / Math.PI);
|
|
157
|
+
this.state.rotation = this._dragStartRotation + s, this._applyWrapperTransform();
|
|
158
|
+
}
|
|
159
|
+
handleScale(t, e, n) {
|
|
160
|
+
if (!this.state.contentElement) return;
|
|
161
|
+
let i = this.dragStartWidth, s = this.dragStartHeight;
|
|
162
|
+
switch (n) {
|
|
163
|
+
case "br":
|
|
164
|
+
i = this.dragStartWidth + t, s = this.dragStartHeight + e;
|
|
165
|
+
break;
|
|
166
|
+
case "bl":
|
|
167
|
+
i = this.dragStartWidth - t, s = this.dragStartHeight + e;
|
|
168
|
+
break;
|
|
169
|
+
case "tr":
|
|
170
|
+
i = this.dragStartWidth + t, s = this.dragStartHeight - e;
|
|
171
|
+
break;
|
|
172
|
+
case "tl":
|
|
173
|
+
i = this.dragStartWidth - t, s = this.dragStartHeight - e;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (i = Math.max(this.state.minWidth, i), s = Math.max(this.state.minHeight, s), this.state.aspectRatio) {
|
|
177
|
+
const l = this.parseAspectRatio(this.state.aspectRatio);
|
|
178
|
+
if (l) {
|
|
179
|
+
const c = i / l, g = s * l;
|
|
180
|
+
Math.abs(i - this.dragStartWidth) > Math.abs(s - this.dragStartHeight) ? s = c : i = g, i = Math.max(this.state.minWidth, i), s = Math.max(this.state.minHeight, s);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const a = i / this.dragStartWidth, o = s / this.dragStartHeight, r = Math.min(a, o);
|
|
184
|
+
this.state.width = i, this.state.height = s, this.updateWrapperDimensions();
|
|
185
|
+
const d = this.dragStartContentWidth * r, p = this.dragStartContentHeight * r;
|
|
186
|
+
this.state.contentElement.style.width = `${d}px`, this.state.contentElement.style.height = `${p}px`, this.state.contentLeft = this.dragStartContentLeft * r, this.state.contentTop = this.dragStartContentTop * r, this.clampContentPosition();
|
|
187
|
+
}
|
|
188
|
+
handleCrop(t, e, n) {
|
|
189
|
+
let i = this.dragStartWidth, s = this.dragStartHeight;
|
|
190
|
+
switch (n) {
|
|
191
|
+
case "l":
|
|
192
|
+
i = this.dragStartWidth - t;
|
|
193
|
+
break;
|
|
194
|
+
case "r":
|
|
195
|
+
i = this.dragStartWidth + t;
|
|
196
|
+
break;
|
|
197
|
+
case "t":
|
|
198
|
+
s = this.dragStartHeight - e;
|
|
199
|
+
break;
|
|
200
|
+
case "b":
|
|
201
|
+
s = this.dragStartHeight + e;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (i = Math.max(this.state.minWidth, i), s = Math.max(this.state.minHeight, s), this.state.aspectRatio) {
|
|
205
|
+
const a = this.parseAspectRatio(this.state.aspectRatio);
|
|
206
|
+
if (a) {
|
|
207
|
+
const o = i / a, r = s * a;
|
|
208
|
+
n === "l" || n === "r" ? s = o : i = r, i = Math.max(this.state.minWidth, i), s = Math.max(this.state.minHeight, s);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (this.state.width = i, this.state.height = s, this.updateWrapperDimensions(), n === "l") {
|
|
212
|
+
const a = i - this.dragStartWidth;
|
|
213
|
+
this.state.contentLeft = this.dragStartContentLeft - a;
|
|
214
|
+
} else if (n === "t") {
|
|
215
|
+
const a = s - this.dragStartHeight;
|
|
216
|
+
this.state.contentTop = this.dragStartContentTop - a;
|
|
217
|
+
}
|
|
218
|
+
this.clampContentPosition();
|
|
219
|
+
}
|
|
220
|
+
clampContentPosition() {
|
|
221
|
+
if (!this.state.contentElement) return;
|
|
222
|
+
const t = this.state.contentElement.offsetWidth, e = this.state.contentElement.offsetHeight, n = Math.min(0, this.state.width - t), i = Math.min(0, this.state.height - e);
|
|
223
|
+
this.state.contentLeft = Math.max(n, Math.min(0, this.state.contentLeft)), this.state.contentTop = Math.max(i, Math.min(0, this.state.contentTop)), this.state.contentElement.style.left = `${this.state.contentLeft}px`, this.state.contentElement.style.top = `${this.state.contentTop}px`;
|
|
224
|
+
}
|
|
225
|
+
handlePan(t, e) {
|
|
226
|
+
this.state.contentElement && (this.state.contentLeft = this.dragStartContentLeft + t, this.state.contentTop = this.dragStartContentTop + e, this.clampContentPosition());
|
|
227
|
+
}
|
|
228
|
+
parseAspectRatio(t) {
|
|
229
|
+
const e = t.split("/");
|
|
230
|
+
if (e.length === 2) {
|
|
231
|
+
const n = parseFloat(e[0]), i = parseFloat(e[1]);
|
|
232
|
+
if (!isNaN(n) && !isNaN(i) && i !== 0)
|
|
233
|
+
return n / i;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
dispatchChange(t) {
|
|
238
|
+
const e = {
|
|
239
|
+
width: this.state.width,
|
|
240
|
+
height: this.state.height,
|
|
241
|
+
wrapperLeft: this.state.wrapperLeft,
|
|
242
|
+
wrapperTop: this.state.wrapperTop,
|
|
243
|
+
contentLeft: this.state.contentLeft,
|
|
244
|
+
contentTop: this.state.contentTop,
|
|
245
|
+
action: t,
|
|
246
|
+
rotation: this.state.rotation,
|
|
247
|
+
handle: this.dragHandle || void 0
|
|
248
|
+
};
|
|
249
|
+
this.dispatchEvent(new CustomEvent("rcw:change", { detail: e })), this.dispatchOnChange();
|
|
250
|
+
}
|
|
251
|
+
dispatchOnChange() {
|
|
252
|
+
const t = this.getValues();
|
|
253
|
+
this.dispatchEvent(
|
|
254
|
+
new CustomEvent("change", {
|
|
255
|
+
detail: t,
|
|
256
|
+
bubbles: !0,
|
|
257
|
+
composed: !0
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
render() {
|
|
262
|
+
this.shadowRoot.innerHTML = `
|
|
263
|
+
<style>
|
|
264
|
+
:host {
|
|
265
|
+
display: inline-block;
|
|
266
|
+
position: relative;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#wrapper {
|
|
270
|
+
position: relative;
|
|
271
|
+
border: 2px solid #007bff;
|
|
272
|
+
box-sizing: border-box;
|
|
273
|
+
background: rgba(0, 123, 255, 0.05);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#clipper {
|
|
277
|
+
position: absolute;
|
|
278
|
+
top: 0;
|
|
279
|
+
left: 0;
|
|
280
|
+
right: 0;
|
|
281
|
+
bottom: 0;
|
|
282
|
+
overflow: hidden;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
::slotted(*) {
|
|
286
|
+
position: absolute;
|
|
287
|
+
max-width: none;
|
|
288
|
+
max-height: none;
|
|
289
|
+
cursor: grab;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
::slotted(*:active) {
|
|
293
|
+
cursor: grabbing;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#handles-container {
|
|
297
|
+
position: absolute;
|
|
298
|
+
top: 0;
|
|
299
|
+
left: 0;
|
|
300
|
+
right: 0;
|
|
301
|
+
bottom: 0;
|
|
302
|
+
pointer-events: none;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.handle {
|
|
306
|
+
position: absolute;
|
|
307
|
+
background: white;
|
|
308
|
+
border: 2px solid #007bff;
|
|
309
|
+
pointer-events: auto;
|
|
310
|
+
touch-action: none;
|
|
311
|
+
z-index: 1000;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.handle.rotate {
|
|
315
|
+
width: 10px;
|
|
316
|
+
height: 10px;
|
|
317
|
+
border-radius: 50%;
|
|
318
|
+
top: -18px;
|
|
319
|
+
left: 50%;
|
|
320
|
+
transform: translateX(-50%);
|
|
321
|
+
cursor: grab;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.handle.rotate:active {
|
|
325
|
+
cursor: grabbing;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.handle.scale {
|
|
329
|
+
width: 12px;
|
|
330
|
+
height: 12px;
|
|
331
|
+
border-radius: 50%;
|
|
332
|
+
cursor: nwse-resize;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.handle.scale.tl {
|
|
336
|
+
top: -6px;
|
|
337
|
+
left: -6px;
|
|
338
|
+
cursor: nwse-resize;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.handle.scale.tr {
|
|
342
|
+
top: -6px;
|
|
343
|
+
right: -6px;
|
|
344
|
+
cursor: nesw-resize;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.handle.scale.bl {
|
|
348
|
+
bottom: -6px;
|
|
349
|
+
left: -6px;
|
|
350
|
+
cursor: nesw-resize;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.handle.scale.br {
|
|
354
|
+
bottom: -6px;
|
|
355
|
+
right: -6px;
|
|
356
|
+
cursor: nwse-resize;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.handle.crop {
|
|
360
|
+
background: #007bff;
|
|
361
|
+
cursor: move;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.handle.crop.t {
|
|
365
|
+
top: -2px;
|
|
366
|
+
left: 50%;
|
|
367
|
+
transform: translateX(-50%);
|
|
368
|
+
width: 40px;
|
|
369
|
+
height: 4px;
|
|
370
|
+
cursor: ns-resize;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.handle.crop.b {
|
|
374
|
+
bottom: -2px;
|
|
375
|
+
left: 50%;
|
|
376
|
+
transform: translateX(-50%);
|
|
377
|
+
width: 40px;
|
|
378
|
+
height: 4px;
|
|
379
|
+
cursor: ns-resize;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.handle.crop.l {
|
|
383
|
+
left: -2px;
|
|
384
|
+
top: 50%;
|
|
385
|
+
transform: translateY(-50%);
|
|
386
|
+
width: 4px;
|
|
387
|
+
height: 40px;
|
|
388
|
+
cursor: ew-resize;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.handle.crop.r {
|
|
392
|
+
right: -2px;
|
|
393
|
+
top: 50%;
|
|
394
|
+
transform: translateY(-50%);
|
|
395
|
+
width: 4px;
|
|
396
|
+
height: 40px;
|
|
397
|
+
cursor: ew-resize;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
:host([disabled]) #wrapper {
|
|
401
|
+
opacity: 0.6;
|
|
402
|
+
cursor: not-allowed;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
:host([disabled]) .handle {
|
|
406
|
+
display: none;
|
|
407
|
+
}
|
|
408
|
+
</style>
|
|
409
|
+
|
|
410
|
+
<div id="wrapper">
|
|
411
|
+
<div id="clipper">
|
|
412
|
+
<slot></slot>
|
|
413
|
+
</div>
|
|
414
|
+
|
|
415
|
+
<div id="handles-container">
|
|
416
|
+
<!-- Rotate handle (top-center) -->
|
|
417
|
+
<div class="handle rotate" data-action="rotate"></div>
|
|
418
|
+
|
|
419
|
+
<!-- Scale handle (only bottom-right corner) -->
|
|
420
|
+
<div class="handle scale br" data-action="scale" data-corner="br"></div>
|
|
421
|
+
|
|
422
|
+
<!-- Crop handles (only right and bottom) -->
|
|
423
|
+
<div class="handle crop b" data-action="crop" data-side="b"></div>
|
|
424
|
+
<div class="handle crop r" data-action="crop" data-side="r"></div>
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
`;
|
|
428
|
+
}
|
|
429
|
+
// Public API - Getters and Setters
|
|
430
|
+
get width() {
|
|
431
|
+
return this.state.width;
|
|
432
|
+
}
|
|
433
|
+
set width(t) {
|
|
434
|
+
this.setAttribute("width", String(t));
|
|
435
|
+
}
|
|
436
|
+
get height() {
|
|
437
|
+
return this.state.height;
|
|
438
|
+
}
|
|
439
|
+
set height(t) {
|
|
440
|
+
this.setAttribute("height", String(t));
|
|
441
|
+
}
|
|
442
|
+
get minWidth() {
|
|
443
|
+
return this.state.minWidth;
|
|
444
|
+
}
|
|
445
|
+
set minWidth(t) {
|
|
446
|
+
this.setAttribute("min-width", String(t));
|
|
447
|
+
}
|
|
448
|
+
get minHeight() {
|
|
449
|
+
return this.state.minHeight;
|
|
450
|
+
}
|
|
451
|
+
set minHeight(t) {
|
|
452
|
+
this.setAttribute("min-height", String(t));
|
|
453
|
+
}
|
|
454
|
+
get aspectRatio() {
|
|
455
|
+
return this.state.aspectRatio;
|
|
456
|
+
}
|
|
457
|
+
set aspectRatio(t) {
|
|
458
|
+
t ? this.setAttribute("aspect-ratio", t) : this.removeAttribute("aspect-ratio");
|
|
459
|
+
}
|
|
460
|
+
get disabled() {
|
|
461
|
+
return this.hasAttribute("disabled");
|
|
462
|
+
}
|
|
463
|
+
set disabled(t) {
|
|
464
|
+
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
465
|
+
}
|
|
466
|
+
get allowCrop() {
|
|
467
|
+
return this.hasAttribute("allow-crop") ? this.getAttribute("allow-crop") !== "false" : !0;
|
|
468
|
+
}
|
|
469
|
+
set allowCrop(t) {
|
|
470
|
+
t ? this.setAttribute("allow-crop", "true") : this.setAttribute("allow-crop", "false");
|
|
471
|
+
}
|
|
472
|
+
get allowResize() {
|
|
473
|
+
return this.hasAttribute("allow-resize") ? this.getAttribute("allow-resize") !== "false" : !0;
|
|
474
|
+
}
|
|
475
|
+
set allowResize(t) {
|
|
476
|
+
t ? this.setAttribute("allow-resize", "true") : this.setAttribute("allow-resize", "false");
|
|
477
|
+
}
|
|
478
|
+
get allowRotate() {
|
|
479
|
+
return this.hasAttribute("allow-rotate") ? this.getAttribute("allow-rotate") !== "false" : !0;
|
|
480
|
+
}
|
|
481
|
+
set allowRotate(t) {
|
|
482
|
+
t ? this.setAttribute("allow-rotate", "true") : this.setAttribute("allow-rotate", "false");
|
|
483
|
+
}
|
|
484
|
+
get allowDrag() {
|
|
485
|
+
return this.hasAttribute("allow-drag") ? this.getAttribute("allow-drag") !== "false" : !0;
|
|
486
|
+
}
|
|
487
|
+
set allowDrag(t) {
|
|
488
|
+
t ? this.setAttribute("allow-drag", "true") : this.setAttribute("allow-drag", "false");
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Gets the current values including wrapper size, content size, position, and zoom level
|
|
492
|
+
*/
|
|
493
|
+
getValues() {
|
|
494
|
+
this._syncWrapperPositionFromLayout(this._getContainerForMove());
|
|
495
|
+
const t = this.state.contentElement?.offsetWidth || 0, e = this.state.contentElement?.offsetHeight || 0, n = this.initialContentWidth > 0 ? t / this.initialContentWidth : 1;
|
|
496
|
+
return {
|
|
497
|
+
wrapperWidth: this.state.width,
|
|
498
|
+
wrapperHeight: this.state.height,
|
|
499
|
+
wrapperLeft: this.state.wrapperLeft,
|
|
500
|
+
wrapperTop: this.state.wrapperTop,
|
|
501
|
+
contentWidth: t,
|
|
502
|
+
contentHeight: e,
|
|
503
|
+
contentLeft: this.state.contentLeft,
|
|
504
|
+
contentTop: this.state.contentTop,
|
|
505
|
+
zoom: n,
|
|
506
|
+
rotation: this.state.rotation
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Sets the values to reproduce size, zoom and pan
|
|
511
|
+
* @param values - The values to set
|
|
512
|
+
*/
|
|
513
|
+
setValues(t) {
|
|
514
|
+
if (t.wrapperWidth !== void 0 && (this.state.width = t.wrapperWidth), t.wrapperHeight !== void 0 && (this.state.height = t.wrapperHeight), this.updateWrapperDimensions(), t.wrapperLeft !== void 0 || t.wrapperTop !== void 0) {
|
|
515
|
+
const e = this._getContainerForMove();
|
|
516
|
+
this._ensureAbsolutePositionForMove(e), t.wrapperLeft !== void 0 && (this.state.wrapperLeft = t.wrapperLeft), t.wrapperTop !== void 0 && (this.state.wrapperTop = t.wrapperTop), this.style.left = `${this.state.wrapperLeft}px`, this.style.top = `${this.state.wrapperTop}px`;
|
|
517
|
+
}
|
|
518
|
+
if (t.rotation !== void 0 && (this.state.rotation = t.rotation, this._applyWrapperTransform()), !this.state.contentElement) {
|
|
519
|
+
this.dispatchOnChange();
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (t.zoom !== void 0 && this.initialContentWidth > 0) {
|
|
523
|
+
const e = this.initialContentWidth * t.zoom, n = this.initialContentHeight * t.zoom;
|
|
524
|
+
this.state.contentElement.style.width = `${e}px`, this.state.contentElement.style.height = `${n}px`;
|
|
525
|
+
} else t.contentWidth !== void 0 && (this.state.contentElement.style.width = `${t.contentWidth}px`, t.contentHeight !== void 0 ? this.state.contentElement.style.height = `${t.contentHeight}px` : this.state.contentElement.style.height = "auto");
|
|
526
|
+
t.contentLeft !== void 0 && (this.state.contentLeft = t.contentLeft), t.contentTop !== void 0 && (this.state.contentTop = t.contentTop), this.clampContentPosition(), this.dispatchOnChange();
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Gets a serializable state snapshot of the component including flags, constraints, mode,
|
|
530
|
+
* and the current transform/crop values.
|
|
531
|
+
*/
|
|
532
|
+
getState() {
|
|
533
|
+
return {
|
|
534
|
+
mode: this._interactionMode,
|
|
535
|
+
disabled: this.disabled,
|
|
536
|
+
allowCrop: this.allowCrop,
|
|
537
|
+
allowResize: this.allowResize,
|
|
538
|
+
allowRotate: this.allowRotate,
|
|
539
|
+
allowDrag: this.allowDrag,
|
|
540
|
+
minWidth: this.minWidth,
|
|
541
|
+
minHeight: this.minHeight,
|
|
542
|
+
aspectRatio: this.aspectRatio,
|
|
543
|
+
values: this.getValues()
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Restores a state snapshot produced by getState().
|
|
548
|
+
* @param state - State to restore
|
|
549
|
+
*/
|
|
550
|
+
setState(t) {
|
|
551
|
+
t.disabled !== void 0 && (this.disabled = t.disabled), t.allowCrop !== void 0 && (this.allowCrop = t.allowCrop), t.allowResize !== void 0 && (this.allowResize = t.allowResize), t.allowRotate !== void 0 && (this.allowRotate = t.allowRotate), t.allowDrag !== void 0 && (this.allowDrag = t.allowDrag), t.minWidth !== void 0 && (this.minWidth = t.minWidth), t.minHeight !== void 0 && (this.minHeight = t.minHeight), t.aspectRatio !== void 0 && (this.aspectRatio = t.aspectRatio), t.mode !== void 0 && this._setInteractionMode(t.mode), t.values && this.setValues(t.values);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const w = (h = "liwe3-resizable-cropper") => {
|
|
555
|
+
typeof window < "u" && !window.customElements.get(h) && customElements.define(h, f);
|
|
556
|
+
};
|
|
557
|
+
w();
|
|
558
|
+
export {
|
|
559
|
+
f as ResizableCropperElement,
|
|
560
|
+
w as defineResizableCropper
|
|
561
|
+
};
|
|
562
|
+
//# sourceMappingURL=ResizableCropper.js.map
|