@c2n/reorder-list 0.0.4 → 0.0.7

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.
@@ -1,473 +1,512 @@
1
- import { nothing as E } from "lit/html.js";
2
- import { directive as k, PartType as D } from "lit/directive.js";
3
- import { AsyncDirective as M } from "lit/async-directive.js";
4
- import { unsafeCSS as $, LitElement as R, html as u } from "lit";
5
- import { query as S, queryAll as T, property as y, state as O, eventOptions as B, customElement as L } from "lit/decorators.js";
6
- import { classMap as f } from "lit/directives/class-map.js";
7
- import { styleMap as F } from "lit/directives/style-map.js";
8
- const z = /* @__PURE__ */ new WeakMap();
9
- let x = 0;
10
- const v = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new WeakSet(), P = () => new Promise((i) => requestAnimationFrame(i)), C = (i, t) => {
11
- const e = i - t;
12
- return e === 0 ? void 0 : e;
13
- }, w = (i, t) => {
14
- const e = i / t;
15
- return e === 1 ? void 0 : e;
16
- }, b = { left: (i, t) => {
17
- const e = C(i, t);
18
- return { value: e, transform: e && `translateX(${e}px)` };
19
- }, top: (i, t) => {
20
- const e = C(i, t);
21
- return { value: e, transform: e && `translateY(${e}px)` };
22
- }, width: (i, t) => {
23
- const e = w(i, t);
24
- return { value: e, transform: e && `scaleX(${e})` };
25
- }, height: (i, t) => {
26
- const e = w(i, t);
27
- return { value: e, transform: e && `scaleY(${e})` };
28
- } }, U = { duration: 333, easing: "ease-in-out" }, _ = ["left", "top", "width", "height", "opacity", "color", "background"], A = /* @__PURE__ */ new WeakMap();
29
- class X extends M {
30
- constructor(t) {
31
- if (super(t), this.t = null, this.i = null, this.o = !0, this.shouldLog = !1, t.type === D.CHILD)
32
- throw Error("The `animate` directive must be used in attribute position.");
33
- this.createFinished();
34
- }
35
- createFinished() {
36
- var t;
37
- (t = this.resolveFinished) === null || t === void 0 || t.call(this), this.finished = new Promise((e) => {
38
- this.h = e;
39
- });
40
- }
41
- async resolveFinished() {
42
- var t;
43
- (t = this.h) === null || t === void 0 || t.call(this), this.h = void 0;
44
- }
45
- render(t) {
46
- return E;
47
- }
48
- getController() {
49
- return z.get(this.l);
50
- }
51
- isDisabled() {
52
- var t;
53
- return this.options.disabled || ((t = this.getController()) === null || t === void 0 ? void 0 : t.disabled);
54
- }
55
- update(t, [e]) {
56
- var s;
57
- const o = this.l === void 0;
58
- return o && (this.l = (s = t.options) === null || s === void 0 ? void 0 : s.host, this.l.addController(this), this.element = t.element, A.set(this.element, this)), this.optionsOrCallback = e, (o || typeof e != "function") && this.u(e), this.render(e);
59
- }
60
- u(t) {
61
- var e, s;
62
- t = t != null ? t : {};
63
- const o = this.getController();
64
- o !== void 0 && ((t = { ...o.defaultOptions, ...t }).keyframeOptions = { ...o.defaultOptions.keyframeOptions, ...t.keyframeOptions }), (e = (s = t).properties) !== null && e !== void 0 || (s.properties = _), this.options = t;
65
- }
66
- v() {
67
- const t = {}, e = this.element.getBoundingClientRect(), s = getComputedStyle(this.element);
68
- return this.options.properties.forEach((o) => {
69
- var r;
70
- const n = (r = e[o]) !== null && r !== void 0 ? r : b[o] ? void 0 : s[o], l = Number(n);
71
- t[o] = isNaN(l) ? n + "" : l;
72
- }), t;
73
- }
74
- p() {
75
- let t, e = !0;
76
- return this.options.guard && (t = this.options.guard(), e = ((s, o) => {
77
- if (Array.isArray(s)) {
78
- if (Array.isArray(o) && o.length === s.length && s.every((r, n) => r === o[n]))
79
- return !1;
80
- } else if (o === s)
81
- return !1;
82
- return !0;
83
- })(t, this.m)), this.o = this.l.hasUpdated && !this.isDisabled() && !this.isAnimating() && e && this.element.isConnected, this.o && (this.m = Array.isArray(t) ? Array.from(t) : t), this.o;
84
- }
85
- hostUpdate() {
86
- var t;
87
- typeof this.optionsOrCallback == "function" && this.u(this.optionsOrCallback()), this.p() && (this.g = this.v(), this.t = (t = this.t) !== null && t !== void 0 ? t : this.element.parentNode, this.i = this.element.nextSibling);
88
- }
89
- async hostUpdated() {
90
- if (!this.o || !this.element.isConnected || this.options.skipInitial && !this.isHostRendered)
91
- return;
92
- let t;
93
- this.prepare(), await P;
94
- const e = this._(), s = this.A(this.options.keyframeOptions, e), o = this.v();
95
- if (this.g !== void 0) {
96
- const { from: r, to: n } = this.O(this.g, o, e);
97
- this.log("measured", [this.g, o, r, n]), t = this.calculateKeyframes(r, n);
98
- } else {
99
- const r = v.get(this.options.inId);
100
- if (r) {
101
- v.delete(this.options.inId);
102
- const { from: n, to: l } = this.O(r, o, e);
103
- t = this.calculateKeyframes(n, l), t = this.options.in ? [{ ...this.options.in[0], ...t[0] }, ...this.options.in.slice(1), t[1]] : t, x++, t.forEach((d) => d.zIndex = x);
104
- } else
105
- this.options.in && (t = [...this.options.in, {}]);
106
- }
107
- this.animate(t, s);
108
- }
109
- resetStyles() {
110
- var t;
111
- this.P !== void 0 && (this.element.setAttribute("style", (t = this.P) !== null && t !== void 0 ? t : ""), this.P = void 0);
112
- }
113
- commitStyles() {
114
- var t, e;
115
- this.P = this.element.getAttribute("style"), (t = this.webAnimation) === null || t === void 0 || t.commitStyles(), (e = this.webAnimation) === null || e === void 0 || e.cancel();
116
- }
117
- reconnected() {
118
- }
119
- async disconnected() {
120
- var t;
121
- if (!this.o || (this.options.id !== void 0 && v.set(this.options.id, this.g), this.options.out === void 0))
122
- return;
123
- if (this.prepare(), await P(), (t = this.t) === null || t === void 0 ? void 0 : t.isConnected) {
124
- const s = this.i && this.i.parentNode === this.t ? this.i : null;
125
- if (this.t.insertBefore(this.element, s), this.options.stabilizeOut) {
126
- const o = this.v();
127
- this.log("stabilizing out");
128
- const r = this.g.left - o.left, n = this.g.top - o.top;
129
- getComputedStyle(this.element).position !== "static" || r === 0 && n === 0 || (this.element.style.position = "relative"), r !== 0 && (this.element.style.left = r + "px"), n !== 0 && (this.element.style.top = n + "px");
130
- }
131
- }
132
- const e = this.A(this.options.keyframeOptions);
133
- await this.animate(this.options.out, e), this.element.remove();
134
- }
135
- prepare() {
136
- this.createFinished();
137
- }
138
- start() {
139
- var t, e;
140
- (e = (t = this.options).onStart) === null || e === void 0 || e.call(t, this);
141
- }
142
- didFinish(t) {
143
- var e, s;
144
- t && ((s = (e = this.options).onComplete) === null || s === void 0 || s.call(e, this)), this.g = void 0, this.animatingProperties = void 0, this.frames = void 0, this.resolveFinished();
145
- }
146
- _() {
147
- const t = [];
148
- for (let e = this.element.parentNode; e; e = e == null ? void 0 : e.parentNode) {
149
- const s = A.get(e);
150
- s && !s.isDisabled() && s && t.push(s);
151
- }
152
- return t;
153
- }
154
- get isHostRendered() {
155
- const t = I.has(this.l);
156
- return t || this.l.updateComplete.then(() => {
157
- I.add(this.l);
158
- }), t;
159
- }
160
- A(t, e = this._()) {
161
- const s = { ...U };
162
- return e.forEach((o) => Object.assign(s, o.options.keyframeOptions)), Object.assign(s, t), s;
163
- }
164
- O(t, e, s) {
165
- t = { ...t }, e = { ...e };
166
- const o = s.map((l) => l.animatingProperties).filter((l) => l !== void 0);
167
- let r = 1, n = 1;
168
- return o !== void 0 && (o.forEach((l) => {
169
- l.width && (r /= l.width), l.height && (n /= l.height);
170
- }), t.left !== void 0 && e.left !== void 0 && (t.left = r * t.left, e.left = r * e.left), t.top !== void 0 && e.top !== void 0 && (t.top = n * t.top, e.top = n * e.top)), { from: t, to: e };
171
- }
172
- calculateKeyframes(t, e, s = !1) {
173
- var o;
174
- const r = {}, n = {};
175
- let l = !1;
176
- const d = {};
177
- for (const p in e) {
178
- const c = t[p], g = e[p];
179
- if (p in b) {
180
- const N = b[p];
181
- if (c === void 0 || g === void 0)
182
- continue;
183
- const m = N(c, g);
184
- m.transform !== void 0 && (d[p] = m.value, l = !0, r.transform = `${(o = r.transform) !== null && o !== void 0 ? o : ""} ${m.transform}`);
185
- } else
186
- c !== g && c !== void 0 && g !== void 0 && (l = !0, r[p] = c, n[p] = g);
187
- }
188
- return r.transformOrigin = n.transformOrigin = s ? "center center" : "top left", this.animatingProperties = d, l ? [r, n] : void 0;
189
- }
190
- async animate(t, e = this.options.keyframeOptions) {
191
- this.start(), this.frames = t;
192
- let s = !1;
193
- if (!this.isAnimating() && !this.isDisabled() && (this.options.onFrames && (this.frames = t = this.options.onFrames(this), this.log("modified frames", t)), t !== void 0)) {
194
- this.log("animate", [t, e]), s = !0, this.webAnimation = this.element.animate(t, e);
195
- const o = this.getController();
196
- o == null || o.add(this);
197
- try {
198
- await this.webAnimation.finished;
199
- } catch {
200
- }
201
- o == null || o.remove(this);
202
- }
203
- return this.didFinish(s), s;
204
- }
205
- isAnimating() {
206
- var t, e;
207
- return ((t = this.webAnimation) === null || t === void 0 ? void 0 : t.playState) === "running" || ((e = this.webAnimation) === null || e === void 0 ? void 0 : e.pending);
208
- }
209
- log(t, e) {
210
- this.shouldLog && !this.isDisabled() && console.log(t, this.options.id, e);
211
- }
1
+ import { nothing as e } from "lit/html.js";
2
+ import { PartType as t, directive as n } from "lit/directive.js";
3
+ import { AsyncDirective as r } from "lit/async-directive.js";
4
+ import { LitElement as i, html as a, unsafeCSS as o } from "lit";
5
+ import { eventOptions as s, property as c, query as l, queryAll as u, state as d } from "lit/decorators.js";
6
+ import { customElement as f } from "@c2n/core/element-helper.js";
7
+ import { classMap as p } from "lit/directives/class-map.js";
8
+ import { styleMap as m } from "lit/directives/style-map.js";
9
+ //#region ../../../node_modules/@lit-labs/motion/animate-controller.js
10
+ var h = /* @__PURE__ */ new WeakMap(), g = 0, _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new WeakSet(), y = () => new Promise((e) => requestAnimationFrame(e)), b = (e, t) => {
11
+ let n = e - t;
12
+ return n === 0 ? void 0 : n;
13
+ }, x = (e, t) => {
14
+ let n = e / t;
15
+ return n === 1 ? void 0 : n;
16
+ }, S = {
17
+ left: (e, t) => {
18
+ let n = b(e, t);
19
+ return {
20
+ value: n,
21
+ transform: n == null || isNaN(n) ? void 0 : `translateX(${n}px)`
22
+ };
23
+ },
24
+ top: (e, t) => {
25
+ let n = b(e, t);
26
+ return {
27
+ value: n,
28
+ transform: n == null || isNaN(n) ? void 0 : `translateY(${n}px)`
29
+ };
30
+ },
31
+ width: (e, t) => {
32
+ let n;
33
+ t === 0 && (t = 1, n = { width: "1px" });
34
+ let r = x(e, t);
35
+ return {
36
+ value: r,
37
+ overrideFrom: n,
38
+ transform: r == null || isNaN(r) ? void 0 : `scaleX(${r})`
39
+ };
40
+ },
41
+ height: (e, t) => {
42
+ let n;
43
+ t === 0 && (t = 1, n = { height: "1px" });
44
+ let r = x(e, t);
45
+ return {
46
+ value: r,
47
+ overrideFrom: n,
48
+ transform: r == null || isNaN(r) ? void 0 : `scaleY(${r})`
49
+ };
50
+ }
51
+ }, C = {
52
+ duration: 333,
53
+ easing: "ease-in-out"
54
+ }, w = [
55
+ "left",
56
+ "top",
57
+ "width",
58
+ "height",
59
+ "opacity",
60
+ "color",
61
+ "background"
62
+ ], T = /* @__PURE__ */ new WeakMap(), E = n(class extends r {
63
+ constructor(e) {
64
+ if (super(e), this.t = !1, this.i = null, this.o = null, this.h = !0, this.shouldLog = !1, e.type === t.CHILD) throw Error("The `animate` directive must be used in attribute position.");
65
+ this.createFinished();
66
+ }
67
+ createFinished() {
68
+ this.resolveFinished?.(), this.finished = new Promise((e) => {
69
+ this.l = e;
70
+ });
71
+ }
72
+ async resolveFinished() {
73
+ this.l?.(), this.l = void 0;
74
+ }
75
+ render(t) {
76
+ return e;
77
+ }
78
+ getController() {
79
+ return h.get(this.u);
80
+ }
81
+ isDisabled() {
82
+ return this.options.disabled || this.getController()?.disabled;
83
+ }
84
+ update(e, [t]) {
85
+ let n = this.u === void 0;
86
+ return n && (this.u = e.options?.host, this.u.addController(this), this.u.updateComplete.then((e) => this.t = !0), this.element = e.element, T.set(this.element, this)), this.optionsOrCallback = t, (n || typeof t != "function") && this.m(t), this.render(t);
87
+ }
88
+ m(e) {
89
+ e ??= {};
90
+ let t = this.getController();
91
+ t !== void 0 && ((e = {
92
+ ...t.defaultOptions,
93
+ ...e
94
+ }).keyframeOptions = {
95
+ ...t.defaultOptions.keyframeOptions,
96
+ ...e.keyframeOptions
97
+ }), e.properties ??= w, this.options = e;
98
+ }
99
+ p() {
100
+ let e = {}, t = this.element.getBoundingClientRect(), n = getComputedStyle(this.element);
101
+ return this.options.properties.forEach((r) => {
102
+ let i = t[r] ?? (S[r] ? void 0 : n[r]), a = Number(i);
103
+ e[r] = isNaN(a) ? i + "" : a;
104
+ }), e;
105
+ }
106
+ v() {
107
+ let e, t = !0;
108
+ return this.options.guard && (e = this.options.guard(), t = ((e, t) => {
109
+ if (Array.isArray(e)) {
110
+ if (Array.isArray(t) && t.length === e.length && e.every((e, n) => e === t[n])) return !1;
111
+ } else if (t === e) return !1;
112
+ return !0;
113
+ })(e, this._)), this.h = this.t && !this.isDisabled() && !this.isAnimating() && t && this.element.isConnected, this.h && (this._ = Array.isArray(e) ? Array.from(e) : e), this.h;
114
+ }
115
+ hostUpdate() {
116
+ typeof this.optionsOrCallback == "function" && this.m(this.optionsOrCallback()), this.v() && (this.A = this.p(), this.i = this.i ?? this.element.parentNode, this.o = this.element.nextSibling);
117
+ }
118
+ async hostUpdated() {
119
+ if (!this.h || !this.element.isConnected || this.options.skipInitial && !this.isHostRendered) return;
120
+ let e;
121
+ this.prepare(), await y;
122
+ let t = this.P(), n = this.V(this.options.keyframeOptions, t), r = this.p();
123
+ if (this.A !== void 0) {
124
+ let { from: n, to: i } = this.O(this.A, r, t);
125
+ this.log("measured", [
126
+ this.A,
127
+ r,
128
+ n,
129
+ i
130
+ ]), e = this.calculateKeyframes(n, i);
131
+ } else {
132
+ let n = _.get(this.options.inId);
133
+ if (n) {
134
+ _.delete(this.options.inId);
135
+ let { from: i, to: a } = this.O(n, r, t);
136
+ e = this.calculateKeyframes(i, a), e = this.options.in ? [
137
+ {
138
+ ...this.options.in[0],
139
+ ...e[0]
140
+ },
141
+ ...this.options.in.slice(1),
142
+ e[1]
143
+ ] : e, g++, e.forEach((e) => e.zIndex = g);
144
+ } else this.options.in && (e = [...this.options.in, {}]);
145
+ }
146
+ this.animate(e, n);
147
+ }
148
+ resetStyles() {
149
+ this.j !== void 0 && (this.element.setAttribute("style", this.j ?? ""), this.j = void 0);
150
+ }
151
+ commitStyles() {
152
+ this.j = this.element.getAttribute("style"), this.webAnimation?.commitStyles(), this.webAnimation?.cancel();
153
+ }
154
+ reconnected() {}
155
+ async disconnected() {
156
+ if (!this.h || (this.options.id !== void 0 && _.set(this.options.id, this.A), this.options.out === void 0)) return;
157
+ if (this.prepare(), await y(), this.i?.isConnected) {
158
+ let e = this.o && this.o.parentNode === this.i ? this.o : null;
159
+ if (this.i.insertBefore(this.element, e), this.options.stabilizeOut) {
160
+ let e = this.p();
161
+ this.log("stabilizing out");
162
+ let t = this.A.left - e.left, n = this.A.top - e.top;
163
+ getComputedStyle(this.element).position !== "static" || t === 0 && n === 0 || (this.element.style.position = "relative"), t !== 0 && (this.element.style.left = t + "px"), n !== 0 && (this.element.style.top = n + "px");
164
+ }
165
+ }
166
+ let e = this.V(this.options.keyframeOptions);
167
+ await this.animate(this.options.out, e), this.element.remove();
168
+ }
169
+ prepare() {
170
+ this.createFinished();
171
+ }
172
+ start() {
173
+ this.options.onStart?.(this);
174
+ }
175
+ didFinish(e) {
176
+ e && this.options.onComplete?.(this), this.A = void 0, this.animatingProperties = void 0, this.frames = void 0, this.resolveFinished();
177
+ }
178
+ P() {
179
+ let e = [];
180
+ for (let t = this.element.parentNode; t; t = t?.parentNode) {
181
+ let n = T.get(t);
182
+ n && !n.isDisabled() && n && e.push(n);
183
+ }
184
+ return e;
185
+ }
186
+ get isHostRendered() {
187
+ let e = v.has(this.u);
188
+ return e || this.u.updateComplete.then(() => {
189
+ v.add(this.u);
190
+ }), e;
191
+ }
192
+ V(e, t = this.P()) {
193
+ let n = { ...C };
194
+ return t.forEach((e) => Object.assign(n, e.options.keyframeOptions)), Object.assign(n, e), n;
195
+ }
196
+ O(e, t, n) {
197
+ e = { ...e }, t = { ...t };
198
+ let r = n.map((e) => e.animatingProperties).filter((e) => e !== void 0), i = 1, a = 1;
199
+ return r.length > 0 && (r.forEach((e) => {
200
+ e.width && (i /= e.width), e.height && (a /= e.height);
201
+ }), e.left !== void 0 && t.left !== void 0 && (e.left = i * e.left, t.left = i * t.left), e.top !== void 0 && t.top !== void 0 && (e.top = a * e.top, t.top = a * t.top)), {
202
+ from: e,
203
+ to: t
204
+ };
205
+ }
206
+ calculateKeyframes(e, t, n = !1) {
207
+ let r = {}, i = {}, a = !1, o = {};
208
+ for (let n in t) {
209
+ let s = e[n], c = t[n];
210
+ if (n in S) {
211
+ let e = S[n];
212
+ if (s === void 0 || c === void 0) continue;
213
+ let t = e(s, c);
214
+ t.transform !== void 0 && (o[n] = t.value, a = !0, r.transform = `${r.transform ?? ""} ${t.transform}`, t.overrideFrom !== void 0 && Object.assign(r, t.overrideFrom));
215
+ } else s !== c && s !== void 0 && c !== void 0 && (a = !0, r[n] = s, i[n] = c);
216
+ }
217
+ return r.transformOrigin = i.transformOrigin = n ? "center center" : "top left", this.animatingProperties = o, a ? [r, i] : void 0;
218
+ }
219
+ async animate(e, t = this.options.keyframeOptions) {
220
+ this.start(), this.frames = e;
221
+ let n = !1;
222
+ if (!this.isAnimating() && !this.isDisabled() && (this.options.onFrames && (this.frames = e = this.options.onFrames(this), this.log("modified frames", e)), e !== void 0)) {
223
+ this.log("animate", [e, t]), n = !0, this.webAnimation = this.element.animate(e, t);
224
+ let r = this.getController();
225
+ r?.add(this);
226
+ try {
227
+ await this.webAnimation.finished;
228
+ } catch {}
229
+ r?.remove(this);
230
+ }
231
+ return this.didFinish(n), n;
232
+ }
233
+ isAnimating() {
234
+ return this.webAnimation?.playState === "running" || this.webAnimation?.pending;
235
+ }
236
+ log(e, t) {
237
+ this.shouldLog && !this.isDisabled() && console.log(e, this.options.id, t);
238
+ }
239
+ }), D = [
240
+ "top",
241
+ "right",
242
+ "bottom",
243
+ "left"
244
+ ];
245
+ n(class extends r {
246
+ constructor(e) {
247
+ if (super(e), e.type !== t.ELEMENT) throw Error("The `position` directive must be used in attribute position.");
248
+ }
249
+ render(t, n) {
250
+ return e;
251
+ }
252
+ update(e, [t, n]) {
253
+ return this.u === void 0 && (this.u = e.options?.host, this.u.addController(this)), this.C = e.element, this.N = t, this.S = n ?? [
254
+ "left",
255
+ "top",
256
+ "width",
257
+ "height"
258
+ ], this.render(t, n);
259
+ }
260
+ hostUpdated() {
261
+ this.F();
262
+ }
263
+ F() {
264
+ let e = typeof this.N == "function" ? this.N() : this.N?.value, t = e.offsetParent;
265
+ if (e === void 0 || !t) return;
266
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
267
+ this.S?.forEach((e) => {
268
+ let t = D.includes(e) ? n[e] - r[e] : n[e];
269
+ this.C.style[e] = t + "px";
270
+ });
271
+ }
272
+ });
273
+ //#endregion
274
+ //#region src/reorder-list.scss?inline
275
+ var O = ":host{position:relative}.c2-reorder-list-container{gap:var(--c2-reorder-list--container-gap,0px);border-width:var(--c2-reorder-list--container-border-width,0px);border-color:var(--c2-reorder-list--container-border-color,#bcbcc6);border-radius:var(--c2-reorder-list--container-border-radius,8px);padding:var(--c2-reorder-list--container-padding,0px);margin:var(--c2-reorder-list--container-margin,0px);border-style:solid;flex-direction:column;display:flex;position:relative}.c2-reorder-list-container .list-item{background:var(--c2-reorder-list--item-background,transparent);padding:var(--c2-reorder-list--item-padding,0px);border-radius:initial;box-sizing:border-box;position:relative}.c2-reorder-list-container .list-item:not(:last-child){border-bottom:var(--c2-reorder-list--divider-height,0px) solid var(--c2-reorder-list--divider-color,#bcbcc6)}.c2-reorder-list-container .list-item:first-child{border-top-left-radius:inherit;border-top-right-radius:inherit}.c2-reorder-list-container .list-item:last-child{border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.c2-reorder-list-container .list-item--reorderable ::slotted(:not([data-fixed])){cursor:pointer;touch-action:none;-webkit-user-drag:none;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}.c2-reorder-list-container .dragging-placeholder{background-color:var(--c2-reorder-list--placeholder-background,transparent);z-index:1}.dragging-item{box-sizing:border-box;background-color:var(--c2-reorder-list--dragging-item-background,transparent);cursor:pointer;z-index:100000;display:none;position:fixed}.dragging-item.dragging-item--active{display:flex}";
276
+ //#endregion
277
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
278
+ function k(e, t, n, r) {
279
+ var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
280
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
281
+ else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
282
+ return i > 3 && a && Object.defineProperty(t, n, a), a;
212
283
  }
213
- const Y = k(X), j = ["top", "right", "bottom", "left"];
214
- class H extends M {
215
- constructor(t) {
216
- if (super(t), t.type !== D.ELEMENT)
217
- throw Error("The `position` directive must be used in attribute position.");
218
- }
219
- render(t, e) {
220
- return E;
221
- }
222
- update(t, [e, s]) {
223
- var o;
224
- return this.l === void 0 && (this.l = (o = t.options) === null || o === void 0 ? void 0 : o.host, this.l.addController(this)), this.j = t.element, this.S = e, this.C = s != null ? s : ["left", "top", "width", "height"], this.render(e, s);
225
- }
226
- hostUpdated() {
227
- this.F();
228
- }
229
- F() {
230
- var t, e;
231
- const s = typeof this.S == "function" ? this.S() : (t = this.S) === null || t === void 0 ? void 0 : t.value, o = s.offsetParent;
232
- if (s === void 0 || !o)
233
- return;
234
- const r = s.getBoundingClientRect(), n = o.getBoundingClientRect();
235
- (e = this.C) === null || e === void 0 || e.forEach((l) => {
236
- const d = j.includes(l) ? r[l] - n[l] : r[l];
237
- this.j.style[l] = d + "px";
238
- });
239
- }
240
- }
241
- k(H);
242
- const q = `:host{position:relative}.c2-reorder-list-container{display:flex;flex-direction:column;position:relative;gap:var(--c2-reorder-list-container-gap, 0px);border-width:var(--c2-reorder-list-container-border-width, 0px);border-color:var(--c2-reorder-list-container-border-color, #bcbcc6);border-style:solid;border-radius:var(--c2-reorder-list-container-border-radius, 8px);padding:var(--c2-reorder-list-container-padding, 0px);margin:var(--c2-reorder-list-container-margin, 0px)}.c2-reorder-list-container .list-item{background:var(--c2-reorder-list-item-background, transparent);padding:var(--c2-reorder-list-item-padding, 0px);border-radius:initial;box-sizing:border-box;position:relative}.c2-reorder-list-container .list-item:not(:last-child){border-bottom:var(--c2-reorder-list-divider-height, 0px) solid var(--c2-reorder-list-divider-color, #bcbcc6)}.c2-reorder-list-container .list-item:first-child{border-top-left-radius:inherit;border-top-right-radius:inherit}.c2-reorder-list-container .list-item:last-child{border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.c2-reorder-list-container .list-item--reorderable{cursor:pointer}.c2-reorder-list-container .list-item--reorderable ::slotted(*){touch-action:none;-webkit-user-drag:none;-webkit-tap-highlight-color:transparent;user-select:none}.c2-reorder-list-container .dragging-placeholder{background-color:var(--c2-reorder-list-placeholder-background, transparent);z-index:1}.dragging-item{box-sizing:border-box;position:fixed;background-color:var(--c2-reorder-list-dragging-item-background, transparent);cursor:pointer;z-index:100000;display:none}.dragging-item.dragging-item--active{display:flex}
243
- `;
244
- var K = Object.defineProperty, W = Object.getOwnPropertyDescriptor, h = (i, t, e, s) => {
245
- for (var o = s > 1 ? void 0 : s ? W(t, e) : t, r = i.length - 1, n; r >= 0; r--)
246
- (n = i[r]) && (o = (s ? n(t, e, o) : n(o)) || o);
247
- return s && o && K(t, e, o), o;
248
- };
249
- let a = class extends R {
250
- constructor() {
251
- super(...arguments), this.editable = !1, this.dragStartThreshold = 10, this.autoScrollDisabled = !1, this.placeholderSlotIndex = -1, this.placeholderSize = { width: "0px", height: "0px" }, this.childListObserver = null, this.hostBoundingClientRect = null, this.scrollableParent = null, this.scrollableParentRect = void 0, this.pickupPosition = { x: 0, y: 0 }, this.itemPositions = [], this.currentDraggingItem = null, this.currentDraggingSlotIndex = -1, this.skipAnimation = !1, this.hasStartedDragging = !1, this.scrollingTimer = 0, this.cacheMouseEvent = null, this.handleMouseMove = async (i) => {
252
- var t;
253
- if (!this.isUpdatePending)
254
- if (this.hasStartedDragging) {
255
- this.cacheMouseEvent = { pageX: i.pageX, pageY: i.pageY }, this.applyTransform(i);
256
- const e = this.getItemIndexFromPointerPosition(i);
257
- e > -1 && e !== this.placeholderSlotIndex && (this.placeholderSlotIndex = e);
258
- } else {
259
- const e = this.getPointerPosition(i), s = Math.abs(e.x - this.pickupPosition.x), o = Math.abs(e.y - this.pickupPosition.y);
260
- if (!(s + o >= this.dragStartThreshold))
261
- return;
262
- this.hasStartedDragging = !0, this.skipAnimation = !0;
263
- const n = this.getSlottedTargetIndex(i);
264
- if (n == -1)
265
- return;
266
- const l = i.composedPath()[n], d = l.getAttribute("slot"), p = i.composedPath()[n + 2];
267
- if (!d) {
268
- this.stopDrag();
269
- return;
270
- }
271
- this.pickupPosition = this.getPointerPosition(i);
272
- const c = p.getBoundingClientRect(), g = l.getBoundingClientRect();
273
- this.currentDraggingItem = l, this.placeholderSlotIndex = parseInt(d), this.currentDraggingSlotIndex = parseInt(d), this.placeholderSize = { width: `${g.width}px`, height: `${g.height}px` }, this.draggingElement.style.width = `${c.width}px`, this.draggingElement.style.height = `${c.height}px`, this.draggingElement.style.top = `${c.top}px`, this.draggingElement.style.left = `${c.left}px`, l.setAttribute("slot", "dragging-item"), this.applyTransform(i), this.updateItemPositions(), this.scrollableParent = this.getNearestScrollableParent(), this.scrollableParentRect = (t = this.scrollableParent) == null ? void 0 : t.getBoundingClientRect(), this.scrollableParent && this.scrollableParent.addEventListener("scroll", this.handleScroll, { passive: !0 });
274
- }
275
- }, this.handleScroll = () => {
276
- if (this.cacheMouseEvent) {
277
- this.updateItemPositions(), this.applyTransform(this.cacheMouseEvent);
278
- const i = this.getItemIndexFromPointerPosition(this.cacheMouseEvent);
279
- i > -1 && i !== this.placeholderSlotIndex && (this.placeholderSlotIndex = i);
280
- }
281
- }, this.handleMouseUp = () => {
282
- if (this.hasStartedDragging && this.currentDraggingItem) {
283
- const i = this.getSortChildrenBySlot(), t = this.placeholderSlotIndex;
284
- for (let e = 0; e < i.length; e++) {
285
- const s = parseInt(i[e].getAttribute("slot"));
286
- t > this.currentDraggingSlotIndex && s > this.currentDraggingSlotIndex && s <= t && i[e].setAttribute("slot", (s - 1).toString()), t < this.currentDraggingSlotIndex && s >= t && s < this.currentDraggingSlotIndex && i[e].setAttribute("slot", (s + 1).toString());
287
- }
288
- this.currentDraggingItem.setAttribute("slot", this.placeholderSlotIndex.toString()), this.skipAnimation = !0, this.dispatchChangeEvent();
289
- }
290
- this.stopDrag();
291
- }, this.startScrollInterval = (i) => {
292
- this.stopScrolling();
293
- const t = 2;
294
- this.scrollingTimer = window.requestAnimationFrame(() => {
295
- var e;
296
- this.skipAnimation = !0, (e = this.scrollableParent) == null || e.scrollBy(0, i === "up" ? -t : t), this.startScrollInterval(i);
297
- });
298
- };
299
- }
300
- connectedCallback() {
301
- super.connectedCallback(), this.observeChildList(), this.updateSlotMapping();
302
- }
303
- disconnectedCallback() {
304
- super.disconnectedCallback(), this.childListObserver && this.childListObserver.disconnect();
305
- }
306
- renderSlots() {
307
- const i = { "list-item--reorderable": this.editable }, t = this.createPlaceHolder(i), e = this.getChildItems().length, s = Array.from({ length: e }).map((o, r) => {
308
- const n = {
309
- id: r,
310
- inId: r,
311
- skipInitial: !0,
312
- disabled: this.skipAnimation || r === e - 1
313
- };
314
- return this.placeholderSlotIndex !== -1 && this.currentDraggingSlotIndex === r ? u`` : u`<div class="list-item ${f(i)}" ${Y(n)}>
284
+ //#endregion
285
+ //#region src/reorder-list.ts
286
+ var A = class extends i {
287
+ constructor(...e) {
288
+ super(...e), this.editable = !1, this.dragStartThreshold = 10, this.autoScrollDisabled = !1, this.placeholderSlotIndex = -1, this.placeholderSize = {
289
+ width: "0px",
290
+ height: "0px"
291
+ }, this.childListObserver = null, this.hostBoundingClientRect = null, this.scrollableParent = null, this.scrollableParentRect = void 0, this.pickupPosition = {
292
+ x: 0,
293
+ y: 0
294
+ }, this.itemPositions = [], this.currentDraggingItem = null, this.currentDraggingSlotIndex = -1, this.skipAnimation = !1, this.hasStartedDragging = !1, this.scrollingTimer = 0, this.cacheMouseEvent = null, this.handleMouseMove = async (e) => {
295
+ if (!this.isUpdatePending) {
296
+ if (this.hasStartedDragging) {
297
+ this.cacheMouseEvent = {
298
+ pageX: e.pageX,
299
+ pageY: e.pageY
300
+ }, this.applyTransform(e);
301
+ let t = this.getItemIndexFromPointerPosition(e);
302
+ t > -1 && t !== this.placeholderSlotIndex && (this.placeholderSlotIndex = t);
303
+ } else {
304
+ let t = this.getPointerPosition(e);
305
+ if (!(Math.abs(t.x - this.pickupPosition.x) + Math.abs(t.y - this.pickupPosition.y) >= this.dragStartThreshold)) return;
306
+ this.hasStartedDragging = !0, this.skipAnimation = !0;
307
+ let n = this.getSlottedTargetIndex(e);
308
+ if (n == -1) return;
309
+ let r = e.composedPath()[n], i = r.getAttribute("slot"), a = e.composedPath()[n + 2];
310
+ if (!i) {
311
+ this.stopDrag();
312
+ return;
313
+ }
314
+ this.pickupPosition = this.getPointerPosition(e);
315
+ let o = a.getBoundingClientRect(), s = r.getBoundingClientRect();
316
+ this.currentDraggingItem = r, this.placeholderSlotIndex = parseInt(i), this.currentDraggingSlotIndex = parseInt(i), this.placeholderSize = {
317
+ width: `${s.width}px`,
318
+ height: `${s.height}px`
319
+ }, this.draggingElement.style.width = `${o.width}px`, this.draggingElement.style.height = `${o.height}px`, this.draggingElement.style.top = `${o.top}px`, this.draggingElement.style.left = `${o.left}px`, r.setAttribute("slot", "dragging-item"), this.applyTransform(e), this.updateItemPositions(), this.scrollableParent = this.getNearestScrollableParent(), this.scrollableParentRect = this.scrollableParent?.getBoundingClientRect(), this.scrollableParent && this.scrollableParent.addEventListener("scroll", this.handleScroll, { passive: !0 });
320
+ }
321
+ }
322
+ }, this.handleScroll = () => {
323
+ if (this.cacheMouseEvent) {
324
+ this.updateItemPositions(), this.applyTransform(this.cacheMouseEvent);
325
+ let e = this.getItemIndexFromPointerPosition(this.cacheMouseEvent);
326
+ e > -1 && e !== this.placeholderSlotIndex && (this.placeholderSlotIndex = e);
327
+ }
328
+ }, this.handleMouseUp = () => {
329
+ if (this.hasStartedDragging && this.currentDraggingItem) {
330
+ let e = this.getSortChildrenBySlot(), t = this.placeholderSlotIndex;
331
+ for (let n = 0; n < e.length; n++) {
332
+ let r = parseInt(e[n].getAttribute("slot"));
333
+ t > this.currentDraggingSlotIndex && r > this.currentDraggingSlotIndex && r <= t && e[n].setAttribute("slot", (r - 1).toString()), t < this.currentDraggingSlotIndex && r >= t && r < this.currentDraggingSlotIndex && e[n].setAttribute("slot", (r + 1).toString());
334
+ }
335
+ this.currentDraggingItem.setAttribute("slot", this.placeholderSlotIndex.toString()), this.skipAnimation = !0, this.dispatchChangeEvent();
336
+ }
337
+ this.stopDrag();
338
+ }, this.startScrollInterval = (e) => {
339
+ this.stopScrolling(), this.scrollingTimer = window.requestAnimationFrame(() => {
340
+ this.skipAnimation = !0, this.scrollableParent?.scrollBy(0, e === "up" ? -2 : 2), this.startScrollInterval(e);
341
+ });
342
+ };
343
+ }
344
+ connectedCallback() {
345
+ super.connectedCallback(), this.observeChildList(), this.updateSlotMapping();
346
+ }
347
+ disconnectedCallback() {
348
+ super.disconnectedCallback(), this.childListObserver && this.childListObserver.disconnect();
349
+ }
350
+ renderSlots() {
351
+ let e = { "list-item--reorderable": this.editable }, t = this.createPlaceHolder(e), n = this.getChildItems().length, r = Array.from({ length: n }).map((t, r) => {
352
+ let i = {
353
+ id: r,
354
+ inId: r,
355
+ skipInitial: !0,
356
+ disabled: this.skipAnimation || r === n - 1
357
+ };
358
+ return this.placeholderSlotIndex !== -1 && this.currentDraggingSlotIndex === r ? a`` : a`<div class="list-item ${p(e)}" ${E(i)}>
315
359
  <slot name="${r}"></slot>
316
360
  </div>`;
317
- });
318
- return this.placeholderSlotIndex !== -1 && (this.placeholderSlotIndex === this.currentDraggingSlotIndex ? s[this.placeholderSlotIndex] = t : this.placeholderSlotIndex <= this.currentDraggingSlotIndex ? s.splice(this.placeholderSlotIndex, 0, t) : s.splice(this.placeholderSlotIndex + 1, 0, t)), s;
319
- }
320
- createPlaceHolder(i) {
321
- return u` <div class="list-item placeholder ${f(i)}">
361
+ });
362
+ return this.placeholderSlotIndex !== -1 && (this.placeholderSlotIndex === this.currentDraggingSlotIndex ? r[this.placeholderSlotIndex] = t : this.placeholderSlotIndex <= this.currentDraggingSlotIndex ? r.splice(this.placeholderSlotIndex, 0, t) : r.splice(this.placeholderSlotIndex + 1, 0, t)), r;
363
+ }
364
+ createPlaceHolder(e) {
365
+ return a` <div class="list-item placeholder ${p(e)}">
322
366
  <slot name="placeholder">
323
- <div class="dragging-placeholder" style=${F(this.placeholderSize)}></div>
367
+ <div class="dragging-placeholder" style=${m(this.placeholderSize)}></div>
324
368
  </slot>
325
369
  </div>`;
326
- }
327
- render() {
328
- const i = { "dragging-item--active": this.placeholderSlotIndex > -1 };
329
- return u`
370
+ }
371
+ render() {
372
+ let e = { "dragging-item--active": this.placeholderSlotIndex > -1 };
373
+ return a`
330
374
  <div class="c2-reorder-list-container" @mousedown=${this.handleMouseDown}>${this.renderSlots()}</div>
331
- <div class="dragging-item ${f(i)}">
375
+ <div class="dragging-item ${p(e)}">
332
376
  <slot name="dragging-item"></slot>
333
377
  </div>
334
378
  `;
335
- }
336
- handleMouseDown(i) {
337
- const t = this.getSlottedTargetIndex(i);
338
- if (t == -1)
339
- return;
340
- i.composedPath()[t].getAttribute("slot") && (this.hostBoundingClientRect = this.getBoundingClientRect(), this.pickupPosition = this.getPointerPosition(i), document.addEventListener("mousemove", this.handleMouseMove, { passive: !0 }), document.addEventListener("mouseup", this.handleMouseUp, { passive: !0 }));
341
- }
342
- getItemIndexFromPointerPosition(i) {
343
- return this.itemPositions.findIndex((s) => {
344
- const o = s.x + 5, r = s.y + 5, n = s.width - 5, l = s.height - 5;
345
- return o < i.pageX && r < i.pageY && o + n > i.pageX && r + l > i.pageY;
346
- });
347
- }
348
- dispatchChangeEvent() {
349
- const i = this.getChildItems().map((t) => parseInt(t.getAttribute("slot")));
350
- this.dispatchEvent(
351
- new CustomEvent("change", {
352
- bubbles: !0,
353
- cancelable: !0,
354
- detail: i
355
- })
356
- );
357
- }
358
- stopDrag() {
359
- document.removeEventListener("mousemove", this.handleMouseMove), document.removeEventListener("mouseup", this.handleMouseUp), this.scrollableParent && this.scrollableParent.removeEventListener("scroll", this.handleScroll), this.pickupPosition = { x: 0, y: 0 }, this.itemPositions = [], this.hasStartedDragging = !1, this.placeholderSlotIndex = -1, this.scrollableParent = null, this.cacheMouseEvent = null;
360
- }
361
- getPointerPosition(i) {
362
- var s, o;
363
- const t = i.pageX - (((s = this.hostBoundingClientRect) == null ? void 0 : s.left) || 0), e = i.pageY - (((o = this.hostBoundingClientRect) == null ? void 0 : o.top) || 0);
364
- return { x: t, y: e };
365
- }
366
- observeChildList() {
367
- this.childListObserver = new MutationObserver(() => {
368
- this.updateSlotMapping();
369
- }), this.childListObserver.observe(this, { subtree: !1, childList: !0 });
370
- }
371
- async firstUpdated() {
372
- this.updateSlotMapping();
373
- }
374
- updated(i) {
375
- i.has("placeholderSlotIndex") && (this.skipAnimation = !1, this.startScrollingIfNecessary(), this.updateItemPositions()), super.updated(i);
376
- }
377
- startScrollingIfNecessary() {
378
- if (this.placeholderElement && this.scrollableParent) {
379
- const i = this.placeholderElement.getBoundingClientRect(), t = i.top;
380
- t < this.scrollableParentRect.top ? this.startScrollInterval("up") : t + i.height > this.scrollableParentRect.bottom ? this.startScrollInterval("down") : this.stopScrolling();
381
- }
382
- }
383
- stopScrolling() {
384
- window.cancelAnimationFrame(this.scrollingTimer);
385
- }
386
- updateSlotMapping() {
387
- const i = this.getChildItems();
388
- let t = /* @__PURE__ */ new Map(), e = 0, s = !1;
389
- for (const n of i) {
390
- const l = n.getAttribute("slot");
391
- l && (Number.isNaN(parseInt(l)) ? l === "dragging-item" && t.set(e, this.currentDraggingSlotIndex) : t.set(e, parseInt(l))), e++;
392
- }
393
- const o = Array.from(t.keys()).sort(
394
- (n, l) => t.get(n) - t.get(l)
395
- );
396
- o.forEach((n, l) => {
397
- t.get(n), i[n].setAttribute("slot", l.toString()), s = !0;
398
- });
399
- let r = o.length;
400
- for (const n of i)
401
- n.getAttribute("slot") || (n.setAttribute("slot", r.toString()), r++, s = !0);
402
- s && (this.requestUpdate(), this.dispatchChangeEvent());
403
- }
404
- updateItemPositions() {
405
- this.itemPositions = [], this.listItemElements.forEach((i) => {
406
- this.itemPositions.push(i.getBoundingClientRect());
407
- });
408
- }
409
- applyTransform(i) {
410
- const t = this.getPointerPosition(i), e = t.x - this.pickupPosition.x, s = t.y - this.pickupPosition.y;
411
- this.draggingElement.style.transform = this.getTransform(e, s);
412
- }
413
- getTransform(i, t) {
414
- return `translate3d(${Math.round(i)}px, ${Math.round(t)}px, 0)`;
415
- }
416
- getSlottedTargetIndex(i) {
417
- return i.composedPath().findIndex((t) => t instanceof Element && !!t.getAttribute("slot"));
418
- }
419
- getChildItems() {
420
- const i = [];
421
- for (const t of this.children) {
422
- const e = t.getAttribute("slot");
423
- (e === "dragging-item" || !e || !Number.isNaN(parseInt(e))) && i.push(t);
424
- }
425
- return i;
426
- }
427
- getSortChildrenBySlot() {
428
- return this.getChildItems().filter((i) => i !== this.currentDraggingItem).sort((i, t) => {
429
- const e = i.getAttribute("slot"), s = t.getAttribute("slot");
430
- return parseInt(e || "") - parseInt(s || "");
431
- });
432
- }
433
- getNearestScrollableParent(i = this) {
434
- return i == null ? null : i.scrollHeight > i.clientHeight ? i : this.getNearestScrollableParent(i.parentNode);
435
- }
436
- };
437
- a.styles = $(q);
438
- h([
439
- S(".dragging-item")
440
- ], a.prototype, "draggingElement", 2);
441
- h([
442
- S(".placeholder")
443
- ], a.prototype, "placeholderElement", 2);
444
- h([
445
- S(".c2-reorder-list-container")
446
- ], a.prototype, "containerElement", 2);
447
- h([
448
- T(".list-item")
449
- ], a.prototype, "listItemElements", 2);
450
- h([
451
- y({ type: Boolean, reflect: !0 })
452
- ], a.prototype, "editable", 2);
453
- h([
454
- y({ type: Number })
455
- ], a.prototype, "dragStartThreshold", 2);
456
- h([
457
- y({ type: Boolean })
458
- ], a.prototype, "autoScrollDisabled", 2);
459
- h([
460
- O()
461
- ], a.prototype, "placeholderSlotIndex", 2);
462
- h([
463
- O()
464
- ], a.prototype, "placeholderSize", 2);
465
- h([
466
- B({ passive: !0 })
467
- ], a.prototype, "handleMouseDown", 1);
468
- a = h([
469
- L("c2-reorder-list")
470
- ], a);
471
- export {
472
- a as ReorderList
379
+ }
380
+ handleMouseDown(e) {
381
+ if (!this.editable) return;
382
+ let t = this.getSlottedTargetIndex(e);
383
+ if (t == -1) return;
384
+ let n = e.composedPath()[t];
385
+ n.getAttribute("slot") && !this.isFixedItem(n) && (this.hostBoundingClientRect = this.getBoundingClientRect(), this.pickupPosition = this.getPointerPosition(e), document.addEventListener("mousemove", this.handleMouseMove, { passive: !0 }), document.addEventListener("mouseup", this.handleMouseUp, { passive: !0 }));
386
+ }
387
+ isFixedItem(e) {
388
+ return !!e && !!e.dataset.fixed;
389
+ }
390
+ getItemIndexFromPointerPosition(e) {
391
+ return this.itemPositions.findIndex((t) => {
392
+ if (t.isFixed) return !1;
393
+ let n = t.x + 5, r = t.y + 5, i = t.width - 5, a = t.height - 5;
394
+ return n < e.pageX && r < e.pageY && n + i > e.pageX && r + a > e.pageY;
395
+ });
396
+ }
397
+ dispatchChangeEvent() {
398
+ let e = this.getChildItems().map((e) => parseInt(e.getAttribute("slot")));
399
+ this.dispatchEvent(new CustomEvent("change", {
400
+ bubbles: !0,
401
+ cancelable: !0,
402
+ detail: e
403
+ }));
404
+ }
405
+ stopDrag() {
406
+ document.removeEventListener("mousemove", this.handleMouseMove), document.removeEventListener("mouseup", this.handleMouseUp), this.scrollableParent && this.scrollableParent.removeEventListener("scroll", this.handleScroll), this.pickupPosition = {
407
+ x: 0,
408
+ y: 0
409
+ }, this.itemPositions = [], this.hasStartedDragging = !1, this.placeholderSlotIndex = -1, this.scrollableParent = null, this.cacheMouseEvent = null;
410
+ }
411
+ getPointerPosition(e) {
412
+ return {
413
+ x: e.pageX - (this.hostBoundingClientRect?.left || 0),
414
+ y: e.pageY - (this.hostBoundingClientRect?.top || 0)
415
+ };
416
+ }
417
+ observeChildList() {
418
+ this.childListObserver = new MutationObserver(() => {
419
+ this.updateSlotMapping();
420
+ }), this.childListObserver.observe(this, {
421
+ subtree: !1,
422
+ childList: !0
423
+ });
424
+ }
425
+ async firstUpdated() {
426
+ this.updateSlotMapping();
427
+ }
428
+ updated(e) {
429
+ e.has("placeholderSlotIndex") && (this.skipAnimation = !1, this.startScrollingIfNecessary(), this.updateItemPositions()), super.updated(e);
430
+ }
431
+ startScrollingIfNecessary() {
432
+ if (this.placeholderElement && this.scrollableParent) {
433
+ let e = this.placeholderElement.getBoundingClientRect(), t = e.top;
434
+ t < this.scrollableParentRect.top ? this.startScrollInterval("up") : t + e.height > this.scrollableParentRect.bottom ? this.startScrollInterval("down") : this.stopScrolling();
435
+ }
436
+ }
437
+ stopScrolling() {
438
+ window.cancelAnimationFrame(this.scrollingTimer);
439
+ }
440
+ updateSlotMapping() {
441
+ let e = this.getChildItems(), t = /* @__PURE__ */ new Map(), n = 0, r = !1;
442
+ for (let r of e) {
443
+ let e = r.getAttribute("slot");
444
+ e && (Number.isNaN(parseInt(e)) ? e === "dragging-item" && t.set(n, this.currentDraggingSlotIndex) : t.set(n, parseInt(e))), n++;
445
+ }
446
+ let i = Array.from(t.keys()).sort((e, n) => t.get(e) - t.get(n));
447
+ i.forEach((t, n) => {
448
+ e[t].setAttribute("slot", n.toString()), r = !0;
449
+ });
450
+ let a = i.length;
451
+ for (let t of e) t.getAttribute("slot") || (t.setAttribute("slot", a.toString()), a++, r = !0);
452
+ r && (this.requestUpdate(), this.dispatchChangeEvent());
453
+ }
454
+ updateItemPositions() {
455
+ this.itemPositions = [], this.listItemElements.forEach((e) => {
456
+ let t = e.querySelector("slot");
457
+ this.itemPositions.push({
458
+ ...j(e),
459
+ isFixed: t ? this.isFixedItem(t.assignedNodes()[0]) : !1
460
+ });
461
+ });
462
+ }
463
+ applyTransform(e) {
464
+ let t = this.getPointerPosition(e), n = t.x - this.pickupPosition.x, r = t.y - this.pickupPosition.y;
465
+ this.draggingElement.style.transform = this.getTransform(n, r);
466
+ }
467
+ getTransform(e, t) {
468
+ return `translate3d(${Math.round(e)}px, ${Math.round(t)}px, 0)`;
469
+ }
470
+ getSlottedTargetIndex(e) {
471
+ return e.composedPath().findIndex((e) => e instanceof Element && !!e.getAttribute("slot"));
472
+ }
473
+ getChildItems() {
474
+ let e = [];
475
+ for (let t of this.children) {
476
+ let n = t.getAttribute("slot");
477
+ (n === "dragging-item" || !n || !Number.isNaN(parseInt(n))) && e.push(t);
478
+ }
479
+ return e;
480
+ }
481
+ getSortChildrenBySlot() {
482
+ return this.getChildItems().filter((e) => e !== this.currentDraggingItem).sort((e, t) => {
483
+ let n = e.getAttribute("slot"), r = t.getAttribute("slot");
484
+ return parseInt(n || "") - parseInt(r || "");
485
+ });
486
+ }
487
+ getNearestScrollableParent(e = this) {
488
+ return e == null ? null : e.scrollHeight > e.clientHeight ? e : this.getNearestScrollableParent(e.parentNode);
489
+ }
490
+ static {
491
+ this.styles = o(O);
492
+ }
473
493
  };
494
+ k([l(".dragging-item")], A.prototype, "draggingElement", void 0), k([l(".placeholder")], A.prototype, "placeholderElement", void 0), k([l(".c2-reorder-list-container")], A.prototype, "containerElement", void 0), k([u(".list-item")], A.prototype, "listItemElements", void 0), k([c({
495
+ type: Boolean,
496
+ reflect: !0
497
+ })], A.prototype, "editable", void 0), k([c({ type: Number })], A.prototype, "dragStartThreshold", void 0), k([c({ type: Boolean })], A.prototype, "autoScrollDisabled", void 0), k([d()], A.prototype, "placeholderSlotIndex", void 0), k([d()], A.prototype, "placeholderSize", void 0), k([s({ passive: !0 })], A.prototype, "handleMouseDown", null), A = k([f("c2-reorder-list")], A);
498
+ function j(e) {
499
+ let t = e.getBoundingClientRect();
500
+ return {
501
+ top: t.top,
502
+ right: t.right,
503
+ bottom: t.bottom,
504
+ left: t.left,
505
+ width: t.width,
506
+ height: t.height,
507
+ x: t.x,
508
+ y: t.y
509
+ };
510
+ }
511
+ //#endregion
512
+ export { A as ReorderList, j as getMutableClientRect };