@greypan/web-ui 4.0.0 → 6.0.0
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/README.CN.md +259 -139
- package/README.md +296 -139
- package/dist/assets/glass.js +1 -1
- package/dist/assets/glass.js.map +1 -1
- package/dist/assets/menu-portal.js +1 -1
- package/dist/assets/menu-portal.js.map +1 -1
- package/dist/components/autocomplete/index.d.ts +8 -0
- package/dist/components/autocomplete/index.js +108 -50
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/autocomplete/style.js +1 -1
- package/dist/components/autocomplete/style.js.map +1 -1
- package/dist/components/back-top/index.js +1 -1
- package/dist/components/back-top/index.js.map +1 -1
- package/dist/components/back-top/style.js +1 -1
- package/dist/components/back-top/style.js.map +1 -1
- package/dist/components/button/index.js +33 -32
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button/style.js +1 -1
- package/dist/components/button/style.js.map +1 -1
- package/dist/components/button-group/index.js +14 -12
- package/dist/components/button-group/index.js.map +1 -1
- package/dist/components/button-group/style.js +1 -1
- package/dist/components/button-group/style.js.map +1 -1
- package/dist/components/checkbox/index.js +23 -16
- package/dist/components/checkbox/index.js.map +1 -1
- package/dist/components/checkbox/style.js +1 -1
- package/dist/components/checkbox/style.js.map +1 -1
- package/dist/components/collapse/index.d.ts +66 -0
- package/dist/components/collapse/index.js +159 -0
- package/dist/components/collapse/index.js.map +1 -0
- package/dist/components/collapse/style.js +6 -0
- package/dist/components/collapse/style.js.map +1 -0
- package/dist/components/context-menu/index.d.ts +9 -0
- package/dist/components/context-menu/index.js +109 -51
- package/dist/components/context-menu/index.js.map +1 -1
- package/dist/components/dialog/index.d.ts +6 -0
- package/dist/components/dialog/index.js +28 -7
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/dialog/style.js +1 -1
- package/dist/components/dialog/style.js.map +1 -1
- package/dist/components/drawer/index.d.ts +32 -2
- package/dist/components/drawer/index.js +229 -39
- package/dist/components/drawer/index.js.map +1 -1
- package/dist/components/drawer/style.js +1 -1
- package/dist/components/drawer/style.js.map +1 -1
- package/dist/components/dropdown/index.d.ts +8 -0
- package/dist/components/dropdown/index.js +84 -40
- package/dist/components/dropdown/index.js.map +1 -1
- package/dist/components/dropdown-item/style.js +1 -1
- package/dist/components/dropdown-item/style.js.map +1 -1
- package/dist/components/empty/index.d.ts +1 -0
- package/dist/components/empty/index.js +23 -21
- package/dist/components/empty/index.js.map +1 -1
- package/dist/components/empty/style.js +1 -1
- package/dist/components/empty/style.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +28 -27
- package/dist/components/input/style.js +1 -1
- package/dist/components/input/style.js.map +1 -1
- package/dist/components/input-number/style.js +1 -1
- package/dist/components/input-number/style.js.map +1 -1
- package/dist/components/layout/index.d.ts +23 -0
- package/dist/components/layout/index.js +134 -30
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/layout/style.js +1 -1
- package/dist/components/layout/style.js.map +1 -1
- package/dist/components/option/style.js +1 -1
- package/dist/components/option/style.js.map +1 -1
- package/dist/components/popover/index.d.ts +4 -1
- package/dist/components/popover/index.js +18 -6
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/popover/style.js +1 -1
- package/dist/components/popover/style.js.map +1 -1
- package/dist/components/radio/index.js +18 -15
- package/dist/components/radio/index.js.map +1 -1
- package/dist/components/radio/style.js +1 -1
- package/dist/components/radio/style.js.map +1 -1
- package/dist/components/segmented/index.d.ts +8 -1
- package/dist/components/segmented/index.js +87 -21
- package/dist/components/segmented/index.js.map +1 -1
- package/dist/components/segmented/style.js +1 -1
- package/dist/components/segmented/style.js.map +1 -1
- package/dist/components/segmented-trigger/index.js +17 -14
- package/dist/components/segmented-trigger/index.js.map +1 -1
- package/dist/components/segmented-trigger/style.js +1 -1
- package/dist/components/segmented-trigger/style.js.map +1 -1
- package/dist/components/select/index.js +33 -29
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/select/style.js +1 -1
- package/dist/components/select/style.js.map +1 -1
- package/dist/components/slider/index.d.ts +3 -2
- package/dist/components/slider/index.js +65 -47
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/slider/style.js +1 -1
- package/dist/components/slider/style.js.map +1 -1
- package/dist/components/spinner/index.js.map +1 -1
- package/dist/components/switch/index.d.ts +8 -0
- package/dist/components/switch/index.js +72 -25
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/style.js +1 -1
- package/dist/components/switch/style.js.map +1 -1
- package/dist/components/textarea/index.js +1 -4
- package/dist/components/textarea/index.js.map +1 -1
- package/dist/components/textarea/style.js +1 -1
- package/dist/components/textarea/style.js.map +1 -1
- package/dist/components/theme/style.js +1 -1
- package/dist/components/theme/style.js.map +1 -1
- package/dist/components/toast/style.js +1 -1
- package/dist/components/toast/style.js.map +1 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +9 -4
- package/dist/components/tooltip/index.js.map +1 -1
- package/dist/components/tooltip/style.js +1 -1
- package/dist/components/tooltip/style.js.map +1 -1
- package/dist/icons/generated/heroicons-arrow-down-16-solid.d.ts +6 -0
- package/dist/icons/generated/heroicons-arrow-up-16-solid.d.ts +6 -0
- package/dist/icons/generated/heroicons-bars-arrow-down-16-solid.d.ts +6 -0
- package/dist/icons/generated/heroicons-bars-arrow-down-16-solid.js +10 -0
- package/dist/icons/generated/heroicons-bars-arrow-down-16-solid.js.map +1 -0
- package/dist/icons/generated/heroicons-bars-arrow-up-16-solid.d.ts +6 -0
- package/dist/icons/generated/heroicons-bars-arrow-up-16-solid.js +10 -0
- package/dist/icons/generated/heroicons-bars-arrow-up-16-solid.js.map +1 -0
- package/dist/icons/generated/lucide-code.d.ts +6 -0
- package/dist/icons/generated/lucide-code.js +10 -0
- package/dist/icons/generated/lucide-code.js.map +1 -0
- package/dist/icons/generated/lucide-ellipsis-vertical.d.ts +6 -0
- package/dist/icons/generated/lucide-ellipsis-vertical.js +10 -0
- package/dist/icons/generated/lucide-ellipsis-vertical.js.map +1 -0
- package/dist/icons/generated/lucide-list-filter.d.ts +6 -0
- package/dist/icons/generated/lucide-list-filter.js +10 -0
- package/dist/icons/generated/lucide-list-filter.js.map +1 -0
- package/dist/icons/generated/lucide-list-restart.d.ts +6 -0
- package/dist/icons/generated/lucide-list-restart.js +10 -0
- package/dist/icons/generated/lucide-list-restart.js.map +1 -0
- package/dist/icons/generated/lucide-tag.d.ts +6 -0
- package/dist/icons/generated/lucide-tag.js +10 -0
- package/dist/icons/generated/lucide-tag.js.map +1 -0
- package/dist/icons/generated/tabler-sort-ascending-letters.d.ts +6 -0
- package/dist/icons/generated/tabler-sort-ascending-letters.js +10 -0
- package/dist/icons/generated/tabler-sort-ascending-letters.js.map +1 -0
- package/dist/icons/index.d.ts +8 -0
- package/dist/icons/index.js +18 -10
- package/dist/shared/gesture/drag-gesture.js +133 -0
- package/dist/shared/gesture/drag-gesture.js.map +1 -0
- package/dist/shared/gesture/physics.js +45 -0
- package/dist/shared/gesture/physics.js.map +1 -0
- package/dist/shared/group-management/index.js +49 -47
- package/dist/shared/group-management/index.js.map +1 -1
- package/dist/shared/menu-portal/menu-portal.js +22 -10
- package/dist/shared/menu-portal/menu-portal.js.map +1 -1
- package/dist/shared/menu-portal/menu-tree.js +63 -2
- package/dist/shared/menu-portal/menu-tree.js.map +1 -1
- package/dist/shared/option-portal/index.js +1 -1
- package/dist/shared/option-portal/index.js.map +1 -1
- package/dist/shared/overlay/native-dialog-presence.js.map +1 -1
- package/dist/shared/overlay/nested-drawer-layers.js +55 -0
- package/dist/shared/overlay/nested-drawer-layers.js.map +1 -0
- package/dist/shared/overlay/overlay.js.map +1 -1
- package/dist/shared/overlay/portal.js +119 -16
- package/dist/shared/overlay/portal.js.map +1 -1
- package/package.json +8 -3
|
@@ -2,15 +2,17 @@ import e from "../../_virtual/_@oxc-project_runtime@0.146.0/helpers/esm/decorate
|
|
|
2
2
|
import t from "../../assets/glass.js";
|
|
3
3
|
import { FormAssociationController as n, defineFormAssociation as r } from "../../shared/form-association/index.js";
|
|
4
4
|
import { normalizeNumber as i } from "../../shared/normalize/index.js";
|
|
5
|
-
import a from "
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { attachDragGesture as a } from "../../shared/gesture/drag-gesture.js";
|
|
6
|
+
import { clamp as o } from "../../shared/gesture/physics.js";
|
|
7
|
+
import s from "./style.js";
|
|
8
|
+
import { LitElement as c, html as l, unsafeCSS as u } from "lit";
|
|
9
|
+
import { customElement as d, property as f, state as p } from "lit/decorators.js";
|
|
10
|
+
import { classMap as m } from "lit/directives/class-map.js";
|
|
11
|
+
import { styleMap as h } from "lit/directives/style-map.js";
|
|
10
12
|
//#region src/components/slider/index.ts
|
|
11
|
-
var
|
|
13
|
+
var g = class extends c {
|
|
12
14
|
constructor(...e) {
|
|
13
|
-
super(...e), this.disabled = !1, this.marks = !1, this.vertical = !1, this.name = "", this.required = !1, this._value = 0, this._min = 0, this._max = 100, this._step = 1, this._dragging = !1, this._formAssociation = r({
|
|
15
|
+
super(...e), this.disabled = !1, this.marks = !1, this.vertical = !1, this.name = "", this.required = !1, this._value = 0, this._min = 0, this._max = 100, this._step = 1, this._dragging = !1, this._pressed = !1, this._dragGestureHandle = null, this._formAssociation = r({
|
|
14
16
|
host: this,
|
|
15
17
|
initialize: () => {
|
|
16
18
|
this._value = this._normalizeValue(this._value);
|
|
@@ -32,7 +34,7 @@ var m = class extends o {
|
|
|
32
34
|
}).make(), this._formAssociationController = new n(this, this._formAssociation);
|
|
33
35
|
}
|
|
34
36
|
static {
|
|
35
|
-
this.styles = [
|
|
37
|
+
this.styles = [u(t), u(s)];
|
|
36
38
|
}
|
|
37
39
|
static {
|
|
38
40
|
this.formAssociated = !0;
|
|
@@ -62,6 +64,9 @@ var m = class extends o {
|
|
|
62
64
|
set step(e) {
|
|
63
65
|
this._step = i(e, -Infinity, Infinity, 1);
|
|
64
66
|
}
|
|
67
|
+
disconnectedCallback() {
|
|
68
|
+
super.disconnectedCallback(), this._dragGestureHandle?.destroy(), this._dragGestureHandle = null;
|
|
69
|
+
}
|
|
65
70
|
get _isDisabled() {
|
|
66
71
|
return this.disabled || this._formAssociation.isFormDisabled();
|
|
67
72
|
}
|
|
@@ -105,8 +110,8 @@ var m = class extends o {
|
|
|
105
110
|
}
|
|
106
111
|
_normalizeValue(e) {
|
|
107
112
|
if (!Number.isFinite(e)) return this.min;
|
|
108
|
-
let t = Math.min(this.min, this.max), n = Math.max(this.min, this.max), r =
|
|
109
|
-
return Number((t +
|
|
113
|
+
let t = Math.min(this.min, this.max), n = Math.max(this.min, this.max), r = o(e, t, n), i = Math.round((r - t) / this._safeStep);
|
|
114
|
+
return Number((t + i * this._safeStep).toFixed(this._precision));
|
|
110
115
|
}
|
|
111
116
|
get _precision() {
|
|
112
117
|
return Math.max(this._decimalPlaces(this.min), this._decimalPlaces(this.max), this._decimalPlaces(this._safeStep));
|
|
@@ -124,27 +129,41 @@ var m = class extends o {
|
|
|
124
129
|
})), !0);
|
|
125
130
|
}
|
|
126
131
|
_setValueFromPointer(e) {
|
|
127
|
-
let t =
|
|
132
|
+
let t = this._slider;
|
|
133
|
+
if (!t) return !1;
|
|
134
|
+
let n = t.getBoundingClientRect();
|
|
128
135
|
if (this.vertical) {
|
|
129
|
-
if (
|
|
130
|
-
let
|
|
131
|
-
return this._setValue(this.min +
|
|
136
|
+
if (n.height <= 0) return !1;
|
|
137
|
+
let t = o(1 - (e.clientY - n.top) / n.height, 0, 1);
|
|
138
|
+
return this._setValue(this.min + t * this._range);
|
|
132
139
|
}
|
|
133
|
-
if (
|
|
134
|
-
let
|
|
135
|
-
return this._setValue(this.min +
|
|
140
|
+
if (n.width <= 0) return !1;
|
|
141
|
+
let r = o((e.clientX - n.left) / n.width, 0, 1);
|
|
142
|
+
return this._setValue(this.min + r * this._range);
|
|
136
143
|
}
|
|
137
144
|
_handlePointerDown(e) {
|
|
138
|
-
this._isDisabled || (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
this._isDisabled || (this._pressed = !0, this._interactionStartValue = this.value, this._setValueFromPointer(e), this._dragGestureHandle?.destroy(), this._dragGestureHandle = a(e, {
|
|
146
|
+
axis: this.vertical ? "y" : "x",
|
|
147
|
+
threshold: 6,
|
|
148
|
+
onMove: (e, t) => {
|
|
149
|
+
this._dragging = !0, this._setValueFromPointer(t);
|
|
150
|
+
},
|
|
151
|
+
onEnd: (e, t) => {
|
|
152
|
+
this._setValueFromPointer(t), this._pressed = !1, this._dragging = !1, this._interactionStartValue !== this.value && this.dispatchEvent(new Event("change", {
|
|
153
|
+
bubbles: !0,
|
|
154
|
+
composed: !0
|
|
155
|
+
})), this._interactionStartValue = void 0;
|
|
156
|
+
},
|
|
157
|
+
onTap: () => {
|
|
158
|
+
this._interactionStartValue !== this.value && this.dispatchEvent(new Event("change", {
|
|
159
|
+
bubbles: !0,
|
|
160
|
+
composed: !0
|
|
161
|
+
}));
|
|
162
|
+
},
|
|
163
|
+
onCancel: () => {
|
|
164
|
+
this._pressed = !1, this._dragging = !1, this._interactionStartValue = void 0;
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
148
167
|
}
|
|
149
168
|
_handleKeyDown(e) {
|
|
150
169
|
if (this._isDisabled) return;
|
|
@@ -164,15 +183,17 @@ var m = class extends o {
|
|
|
164
183
|
})));
|
|
165
184
|
}
|
|
166
185
|
render() {
|
|
167
|
-
let e =
|
|
186
|
+
let e = m({
|
|
168
187
|
"wui-slider-track": !0,
|
|
188
|
+
"is-dragging": this._dragging,
|
|
169
189
|
"is-disabled": this._isDisabled
|
|
170
|
-
}), t =
|
|
190
|
+
}), t = m({
|
|
171
191
|
"wui-slider-thumb": !0,
|
|
172
192
|
"wui-glass": !0,
|
|
193
|
+
"is-pressed": this._pressed,
|
|
173
194
|
"is-dragging": this._dragging
|
|
174
|
-
}), n =
|
|
175
|
-
return
|
|
195
|
+
}), n = h({ "--percent": `${this._percent}%` });
|
|
196
|
+
return l`
|
|
176
197
|
<div
|
|
177
198
|
class=${e}
|
|
178
199
|
style=${n}
|
|
@@ -186,15 +207,12 @@ var m = class extends o {
|
|
|
186
207
|
aria-disabled=${String(this._isDisabled)}
|
|
187
208
|
@keydown=${this._handleKeyDown}
|
|
188
209
|
@pointerdown=${this._handlePointerDown}
|
|
189
|
-
@pointermove=${this._handlePointerMove}
|
|
190
|
-
@pointerup=${this._handlePointerUp}
|
|
191
|
-
@pointercancel=${this._handlePointerUp}
|
|
192
210
|
>
|
|
193
211
|
<div class="wui-slider-progress"></div>
|
|
194
212
|
<div class="wui-slider-marks">
|
|
195
|
-
${this._markValues.map((e) =>
|
|
213
|
+
${this._markValues.map((e) => l`<span
|
|
196
214
|
class="wui-slider-mark"
|
|
197
|
-
style=${
|
|
215
|
+
style=${h({ "--percent": `${(e - this.min) / this._range * 100}%` })}
|
|
198
216
|
></span>`)}
|
|
199
217
|
</div>
|
|
200
218
|
<div class=${t}></div>
|
|
@@ -202,35 +220,35 @@ var m = class extends o {
|
|
|
202
220
|
`;
|
|
203
221
|
}
|
|
204
222
|
};
|
|
205
|
-
e([
|
|
223
|
+
e([f({
|
|
206
224
|
type: Boolean,
|
|
207
225
|
reflect: !0
|
|
208
|
-
})],
|
|
226
|
+
})], g.prototype, "disabled", void 0), e([f({
|
|
209
227
|
type: Boolean,
|
|
210
228
|
reflect: !0
|
|
211
|
-
})],
|
|
229
|
+
})], g.prototype, "marks", void 0), e([f({
|
|
212
230
|
type: Boolean,
|
|
213
231
|
reflect: !0
|
|
214
|
-
})],
|
|
232
|
+
})], g.prototype, "vertical", void 0), e([f({
|
|
215
233
|
type: String,
|
|
216
234
|
reflect: !0
|
|
217
|
-
})],
|
|
235
|
+
})], g.prototype, "name", void 0), e([f({
|
|
218
236
|
type: Boolean,
|
|
219
237
|
reflect: !0
|
|
220
|
-
})],
|
|
238
|
+
})], g.prototype, "required", void 0), e([f({
|
|
221
239
|
type: Number,
|
|
222
240
|
reflect: !0
|
|
223
|
-
})],
|
|
241
|
+
})], g.prototype, "value", null), e([f({
|
|
224
242
|
type: Number,
|
|
225
243
|
reflect: !0
|
|
226
|
-
})],
|
|
244
|
+
})], g.prototype, "min", null), e([f({
|
|
227
245
|
type: Number,
|
|
228
246
|
reflect: !0
|
|
229
|
-
})],
|
|
247
|
+
})], g.prototype, "max", null), e([f({
|
|
230
248
|
type: Number,
|
|
231
249
|
reflect: !0
|
|
232
|
-
})],
|
|
250
|
+
})], g.prototype, "step", null), e([p()], g.prototype, "_dragging", void 0), e([p()], g.prototype, "_pressed", void 0), g = e([d("web-ui-slider")], g);
|
|
233
251
|
//#endregion
|
|
234
|
-
export {
|
|
252
|
+
export { g as WebUiSlider };
|
|
235
253
|
|
|
236
254
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/slider/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { styleMap } from 'lit/directives/style-map.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\nimport { normalizeNumber } from '@/shared/normalize'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-slider')\nexport class WebUiSlider extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n\n static formAssociated = true\n\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) marks = false\n @property({ type: Boolean, reflect: true }) vertical = false\n @property({ type: String, reflect: true }) name = ''\n @property({ type: Boolean, reflect: true }) required = false\n\n // value 使用访问器模式同步表单关联状态。\n private _value = 0\n @property({ type: Number, reflect: true })\n get value(): number {\n return this._value\n }\n set value(v: number) {\n const normalized = normalizeNumber(v, -Infinity, Infinity, 0)\n const old = this._value\n this._value = normalized\n this._formAssociation.sync()\n this.requestUpdate('value', old)\n }\n\n private _min = 0\n @property({ type: Number, reflect: true })\n get min(): number {\n return this._min\n }\n set min(v: number) {\n this._min = normalizeNumber(v, -Infinity, Infinity, 0)\n }\n\n private _max = 100\n @property({ type: Number, reflect: true })\n get max(): number {\n return this._max\n }\n set max(v: number) {\n this._max = normalizeNumber(v, -Infinity, Infinity, 100)\n }\n\n private _step = 1\n @property({ type: Number, reflect: true })\n get step(): number {\n return this._step\n }\n set step(v: number) {\n this._step = normalizeNumber(v, -Infinity, Infinity, 1)\n }\n\n @state() private _dragging = false\n // 避免未改变数值的点击被误认为一次表单提交\n private _interactionStartValue: number | undefined\n\n private readonly _formAssociation = defineFormAssociation<number>({\n host: this,\n initialize: () => {\n this._value = this._normalizeValue(this._value)\n },\n getState: () => this._value,\n setState: value => {\n this.value = value\n },\n getFormValue: () => String(this._value),\n getFormState: () => String(this._value),\n restoreState: state => {\n if (typeof state !== 'string') return\n const value = Number(state)\n if (Number.isFinite(value)) this.value = value\n },\n syncValidity: internals => {\n if (typeof internals.setValidity === 'function') internals.setValidity({})\n }\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n private get _isDisabled(): boolean {\n return this.disabled || this._formAssociation.isFormDisabled()\n }\n\n override willUpdate(changed: Map<string, unknown>) {\n if (changed.has('value') || changed.has('min') || changed.has('max') || changed.has('step')) {\n const normalizedValue = this._normalizeValue(this.value)\n if (normalizedValue !== this.value) this.value = normalizedValue\n }\n }\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n // 将焦点移至滑块,供表单或外部控制使用\n override focus(options?: FocusOptions) {\n this._slider?.focus(options)\n }\n\n // 移除滑块焦点\n override blur() {\n this._slider?.blur()\n }\n\n private get _slider(): HTMLDivElement | null {\n return this.renderRoot.querySelector<HTMLDivElement>('[role=\"slider\"]')\n }\n\n private get _range(): number {\n return Math.max(0, this.max - this.min)\n }\n\n private get _percent(): number {\n return this._range === 0 ? 0 : ((this.value - this.min) / this._range) * 100\n }\n\n private get _markValues(): number[] {\n if (!this.marks || this._range === 0) return []\n const count = Math.min(100, Math.floor(this._range / this._safeStep))\n return Array.from({ length: count + 1 }, (_, index) => this.min + index * this._safeStep)\n }\n\n private get _safeStep(): number {\n return Number.isFinite(this.step) && this.step > 0 ? this.step : 1\n }\n\n private _normalizeValue(value: number): number {\n if (!Number.isFinite(value)) return this.min\n const lower = Math.min(this.min, this.max)\n const upper = Math.max(this.min, this.max)\n const clamped = Math.min(upper, Math.max(lower, value))\n const steps = Math.round((clamped - lower) / this._safeStep)\n return Number((lower + steps * this._safeStep).toFixed(this._precision))\n }\n\n private get _precision(): number {\n return Math.max(this._decimalPlaces(this.min), this._decimalPlaces(this.max), this._decimalPlaces(this._safeStep))\n }\n\n private _decimalPlaces(value: number): number {\n const [, decimal = ''] = String(value).split('.')\n return decimal.length\n }\n\n private _setValue(value: number): boolean {\n if (this._isDisabled) return false\n const nextValue = this._normalizeValue(value)\n if (nextValue === this.value) return false\n this.value = nextValue\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n return true\n }\n\n private _setValueFromPointer(event: PointerEvent): boolean {\n const track = event.currentTarget as HTMLElement\n const rect = track.getBoundingClientRect()\n if (this.vertical) {\n if (rect.height <= 0) return false\n // 视觉上的数值从下往上增长,与坐标系相反。\n const ratio = Math.min(1, Math.max(0, 1 - (event.clientY - rect.top) / rect.height))\n return this._setValue(this.min + ratio * this._range)\n }\n if (rect.width <= 0) return false\n const ratio = Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width))\n return this._setValue(this.min + ratio * this._range)\n }\n\n private _handlePointerDown(event: PointerEvent) {\n if (this._isDisabled) return\n const track = event.currentTarget as HTMLElement\n track.setPointerCapture?.(event.pointerId)\n this._interactionStartValue = this.value\n this._dragging = true\n this._setValueFromPointer(event)\n }\n\n private _handlePointerMove(event: PointerEvent) {\n if (!this._dragging) return\n this._setValueFromPointer(event)\n }\n\n private _handlePointerUp(event: PointerEvent) {\n if (!this._dragging) return\n this._setValueFromPointer(event)\n this._dragging = false\n if (this._interactionStartValue !== this.value) {\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n this._interactionStartValue = undefined\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n if (this._isDisabled) return\n const pageStep = this._safeStep * 10\n const keyValues: Record<string, number> = {\n ArrowDown: this.value - this._safeStep,\n ArrowLeft: this.value - this._safeStep,\n ArrowUp: this.value + this._safeStep,\n ArrowRight: this.value + this._safeStep,\n PageDown: this.value - pageStep,\n PageUp: this.value + pageStep,\n Home: this.min,\n End: this.max\n }\n const nextValue = keyValues[event.key]\n if (nextValue === undefined) return\n event.preventDefault()\n if (this._setValue(nextValue)) this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n\n override render() {\n const trackClass = classMap({\n 'wui-slider-track': true,\n 'is-disabled': this._isDisabled\n })\n const thumbClass = classMap({\n 'wui-slider-thumb': true,\n 'wui-glass': true,\n 'is-dragging': this._dragging\n })\n const trackStyle = styleMap({ '--percent': `${this._percent}%` })\n\n return html`\n <div\n class=${trackClass}\n style=${trackStyle}\n role=\"slider\"\n tabindex=${this._isDisabled ? '-1' : '0'}\n aria-label=\"滑块\"\n aria-orientation=${this.vertical ? 'vertical' : 'horizontal'}\n aria-valuemin=${this.min}\n aria-valuemax=${this.max}\n aria-valuenow=${this.value}\n aria-disabled=${String(this._isDisabled)}\n @keydown=${this._handleKeyDown}\n @pointerdown=${this._handlePointerDown}\n @pointermove=${this._handlePointerMove}\n @pointerup=${this._handlePointerUp}\n @pointercancel=${this._handlePointerUp}\n >\n <div class=\"wui-slider-progress\"></div>\n <div class=\"wui-slider-marks\">\n ${this._markValues.map(\n mark =>\n html`<span\n class=\"wui-slider-mark\"\n style=${styleMap({ '--percent': `${((mark - this.min) / this._range) * 100}%` })}\n ></span>`\n )}\n </div>\n <div class=${thumbClass}></div>\n </div>\n `\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-slider': WebUiSlider\n }\n}\n"],"mappings":";;;;;;;;;;AAYO,IAAM,IAAN,cAA0B,EAAW;;EA6EI,aAxES,KAAA,WAAA,IACH,KAAA,QAAA,IACG,KAAA,WAAA,IACL,KAAA,OAAA,IACK,KAAA,WAAA,IAGtC,KAAA,SAAA,GAaF,KAAA,OAAA,GASA,KAAA,OAAA,KASC,KAAA,QAAA,GASa,KAAA,YAAA,IAIO,KAAA,mBAAA,EAA8B;GAChE,MAAM;GACN,kBAAkB;IAChB,KAAK,SAAS,KAAK,gBAAgB,KAAK,MAAM;GAChD;GACA,gBAAgB,KAAK;GACrB,WAAU,MAAS;IACjB,KAAK,QAAQ;GACf;GACA,oBAAoB,OAAO,KAAK,MAAM;GACtC,oBAAoB,OAAO,KAAK,MAAM;GACtC,eAAc,MAAS;IACrB,IAAI,OAAO,KAAU,UAAU;IAC/B,IAAM,IAAQ,OAAO,CAAK;IAC1B,AAAI,OAAO,SAAS,CAAK,MAAG,KAAK,QAAQ;GAC3C;GACA,eAAc,MAAa;IACzB,AAAI,OAAO,EAAU,eAAgB,cAAY,EAAU,YAAY,CAAC,CAAC;GAC3E;EACF,CAAC,CAAC,CAAC,KAAK,GAEsC,KAAA,6BAAA,IAAI,EAA0B,MAAM,KAAK,gBAAgB;;;EA5E9E,KAAA,SAAA,CAAC,EAAU,CAAK,GAAG,EAAU,CAAK,CAAC;;;EAEpC,KAAA,iBAAA;;CAUxB,IACI,QAAgB;EAClB,OAAO,KAAK;CACd;CACA,IAAI,MAAM,GAAW;EACnB,IAAM,IAAa,EAAgB,GAAG,WAAW,UAAU,CAAC,GACtD,IAAM,KAAK;EAGj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AAA,WAAA,QAAA,KAAA,CAAA,GACxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GAIzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,SAAA,IAAA,GAaxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,OAAA,IAAA,GASxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,OAAA,IAAA,GASxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,QAAA,IAAA,GAQxC,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,aAAA,KAAA,CAAA,GArDR,IAAA,EAAA,CAAA,EAAc,eAAe,CAAA,GAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/slider/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { styleMap } from 'lit/directives/style-map.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\nimport { attachDragGesture, type DragGestureHandle } from '@/shared/gesture/drag-gesture'\nimport { clamp } from '@/shared/gesture/physics'\nimport { normalizeNumber } from '@/shared/normalize'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-slider')\nexport class WebUiSlider extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n\n static formAssociated = true\n\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) marks = false\n @property({ type: Boolean, reflect: true }) vertical = false\n @property({ type: String, reflect: true }) name = ''\n @property({ type: Boolean, reflect: true }) required = false\n\n // value 使用访问器模式同步表单关联状态。\n private _value = 0\n @property({ type: Number, reflect: true })\n get value(): number {\n return this._value\n }\n set value(v: number) {\n const normalized = normalizeNumber(v, -Infinity, Infinity, 0)\n const old = this._value\n this._value = normalized\n this._formAssociation.sync()\n this.requestUpdate('value', old)\n }\n\n private _min = 0\n @property({ type: Number, reflect: true })\n get min(): number {\n return this._min\n }\n set min(v: number) {\n this._min = normalizeNumber(v, -Infinity, Infinity, 0)\n }\n\n private _max = 100\n @property({ type: Number, reflect: true })\n get max(): number {\n return this._max\n }\n set max(v: number) {\n this._max = normalizeNumber(v, -Infinity, Infinity, 100)\n }\n\n private _step = 1\n @property({ type: Number, reflect: true })\n get step(): number {\n return this._step\n }\n set step(v: number) {\n this._step = normalizeNumber(v, -Infinity, Infinity, 1)\n }\n\n @state() private _dragging = false\n @state() private _pressed = false\n // 避免未改变数值的点击被误认为一次表单提交\n private _interactionStartValue: number | undefined\n private _dragGestureHandle: DragGestureHandle | null = null\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n this._dragGestureHandle?.destroy()\n this._dragGestureHandle = null\n }\n\n private readonly _formAssociation = defineFormAssociation<number>({\n host: this,\n initialize: () => {\n this._value = this._normalizeValue(this._value)\n },\n getState: () => this._value,\n setState: value => {\n this.value = value\n },\n getFormValue: () => String(this._value),\n getFormState: () => String(this._value),\n restoreState: state => {\n if (typeof state !== 'string') return\n const value = Number(state)\n if (Number.isFinite(value)) this.value = value\n },\n syncValidity: internals => {\n if (typeof internals.setValidity === 'function') internals.setValidity({})\n }\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n private get _isDisabled(): boolean {\n return this.disabled || this._formAssociation.isFormDisabled()\n }\n\n override willUpdate(changed: Map<string, unknown>) {\n if (changed.has('value') || changed.has('min') || changed.has('max') || changed.has('step')) {\n const normalizedValue = this._normalizeValue(this.value)\n if (normalizedValue !== this.value) this.value = normalizedValue\n }\n }\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n // 将焦点移至滑块,供表单或外部控制使用\n override focus(options?: FocusOptions) {\n this._slider?.focus(options)\n }\n\n override blur() {\n this._slider?.blur()\n }\n\n private get _slider(): HTMLDivElement | null {\n return this.renderRoot.querySelector<HTMLDivElement>('[role=\"slider\"]')\n }\n\n private get _range(): number {\n return Math.max(0, this.max - this.min)\n }\n\n private get _percent(): number {\n return this._range === 0 ? 0 : ((this.value - this.min) / this._range) * 100\n }\n\n private get _markValues(): number[] {\n if (!this.marks || this._range === 0) return []\n const count = Math.min(100, Math.floor(this._range / this._safeStep))\n return Array.from({ length: count + 1 }, (_, index) => this.min + index * this._safeStep)\n }\n\n private get _safeStep(): number {\n return Number.isFinite(this.step) && this.step > 0 ? this.step : 1\n }\n\n private _normalizeValue(value: number): number {\n if (!Number.isFinite(value)) return this.min\n const lower = Math.min(this.min, this.max)\n const upper = Math.max(this.min, this.max)\n const clamped = clamp(value, lower, upper)\n const steps = Math.round((clamped - lower) / this._safeStep)\n return Number((lower + steps * this._safeStep).toFixed(this._precision))\n }\n\n private get _precision(): number {\n return Math.max(this._decimalPlaces(this.min), this._decimalPlaces(this.max), this._decimalPlaces(this._safeStep))\n }\n\n private _decimalPlaces(value: number): number {\n const [, decimal = ''] = String(value).split('.')\n return decimal.length\n }\n\n private _setValue(value: number): boolean {\n if (this._isDisabled) return false\n const nextValue = this._normalizeValue(value)\n if (nextValue === this.value) return false\n this.value = nextValue\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n return true\n }\n\n private _setValueFromPointer(event: PointerEvent): boolean {\n const track = this._slider\n if (!track) return false\n const rect = track.getBoundingClientRect()\n if (this.vertical) {\n if (rect.height <= 0) return false\n // 视觉上的数值从下往上增长,与坐标系相反。\n const ratio = clamp(1 - (event.clientY - rect.top) / rect.height, 0, 1)\n return this._setValue(this.min + ratio * this._range)\n }\n if (rect.width <= 0) return false\n const ratio = clamp((event.clientX - rect.left) / rect.width, 0, 1)\n return this._setValue(this.min + ratio * this._range)\n }\n\n private _handlePointerDown(event: PointerEvent) {\n if (this._isDisabled) return\n this._pressed = true\n this._interactionStartValue = this.value\n this._setValueFromPointer(event)\n\n this._dragGestureHandle?.destroy()\n this._dragGestureHandle = attachDragGesture(event, {\n axis: this.vertical ? 'y' : 'x',\n threshold: 6,\n onMove: (_info, e) => {\n this._dragging = true\n this._setValueFromPointer(e)\n },\n onEnd: (_info, e) => {\n this._setValueFromPointer(e)\n this._pressed = false\n this._dragging = false\n if (this._interactionStartValue !== this.value) {\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n this._interactionStartValue = undefined\n },\n onTap: () => {\n if (this._interactionStartValue !== this.value) {\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n },\n onCancel: () => {\n this._pressed = false\n this._dragging = false\n this._interactionStartValue = undefined\n }\n })\n }\n\n private _handleKeyDown(event: KeyboardEvent) {\n if (this._isDisabled) return\n const pageStep = this._safeStep * 10\n const keyValues: Record<string, number> = {\n ArrowDown: this.value - this._safeStep,\n ArrowLeft: this.value - this._safeStep,\n ArrowUp: this.value + this._safeStep,\n ArrowRight: this.value + this._safeStep,\n PageDown: this.value - pageStep,\n PageUp: this.value + pageStep,\n Home: this.min,\n End: this.max\n }\n const nextValue = keyValues[event.key]\n if (nextValue === undefined) return\n event.preventDefault()\n if (this._setValue(nextValue)) this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n\n override render() {\n const trackClass = classMap({\n 'wui-slider-track': true,\n 'is-dragging': this._dragging,\n 'is-disabled': this._isDisabled\n })\n const thumbClass = classMap({\n 'wui-slider-thumb': true,\n 'wui-glass': true,\n 'is-pressed': this._pressed,\n 'is-dragging': this._dragging\n })\n const trackStyle = styleMap({ '--percent': `${this._percent}%` })\n\n return html`\n <div\n class=${trackClass}\n style=${trackStyle}\n role=\"slider\"\n tabindex=${this._isDisabled ? '-1' : '0'}\n aria-label=\"滑块\"\n aria-orientation=${this.vertical ? 'vertical' : 'horizontal'}\n aria-valuemin=${this.min}\n aria-valuemax=${this.max}\n aria-valuenow=${this.value}\n aria-disabled=${String(this._isDisabled)}\n @keydown=${this._handleKeyDown}\n @pointerdown=${this._handlePointerDown}\n >\n <div class=\"wui-slider-progress\"></div>\n <div class=\"wui-slider-marks\">\n ${this._markValues.map(\n mark =>\n html`<span\n class=\"wui-slider-mark\"\n style=${styleMap({ '--percent': `${((mark - this.min) / this._range) * 100}%` })}\n ></span>`\n )}\n </div>\n <div class=${thumbClass}></div>\n </div>\n `\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-slider': WebUiSlider\n }\n}\n"],"mappings":";;;;;;;;;;;;AAcO,IAAM,IAAN,cAA0B,EAAW;;EAqFI,aAhFS,KAAA,WAAA,IACH,KAAA,QAAA,IACG,KAAA,WAAA,IACL,KAAA,OAAA,IACK,KAAA,WAAA,IAGtC,KAAA,SAAA,GAaF,KAAA,OAAA,GASA,KAAA,OAAA,KASC,KAAA,QAAA,GASa,KAAA,YAAA,IACD,KAAA,WAAA,IAG2B,KAAA,qBAAA,MAQnB,KAAA,mBAAA,EAA8B;GAChE,MAAM;GACN,kBAAkB;IAChB,KAAK,SAAS,KAAK,gBAAgB,KAAK,MAAM;GAChD;GACA,gBAAgB,KAAK;GACrB,WAAU,MAAS;IACjB,KAAK,QAAQ;GACf;GACA,oBAAoB,OAAO,KAAK,MAAM;GACtC,oBAAoB,OAAO,KAAK,MAAM;GACtC,eAAc,MAAS;IACrB,IAAI,OAAO,KAAU,UAAU;IAC/B,IAAM,IAAQ,OAAO,CAAK;IAC1B,AAAI,OAAO,SAAS,CAAK,MAAG,KAAK,QAAQ;GAC3C;GACA,eAAc,MAAa;IACzB,AAAI,OAAO,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,GAAA,EAAA,WAAA,QAAA,IAAA,GAQxC,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,aAAA,KAAA,CAAA,GACN,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GAtDR,IAAA,EAAA,CAAA,EAAc,eAAe,CAAA,GAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/components/slider/style.css?inline
|
|
2
|
-
var e = "*,:before,:after{box-sizing:border-box}:host{width:var(--wui-slider-width,200px);display:inline-block}:host([vertical]){width:auto;height:var(--wui-slider-vertical-height,200px)}:host([disabled]){cursor:not-allowed}.wui-slider-track{cursor:
|
|
2
|
+
var e = "*,:before,:after{box-sizing:border-box}:host{width:var(--wui-slider-width,200px);display:inline-block}:host([vertical]){width:auto;height:var(--wui-slider-vertical-height,200px)}:host([disabled]){cursor:not-allowed}.wui-slider-track{cursor:default;-webkit-user-select:none;user-select:none;width:100%;height:var(--wui-slider-height,var(--wui-slider-track-size,6px));background-color:var(--wui-color-surface-track,#e5e5ea);border-radius:2147483647px;position:relative}.wui-slider-track:focus-visible{outline-color:var(--wui-color-focus-ring,#08f6)}.wui-slider-track.is-disabled{cursor:not-allowed;opacity:.38}.wui-slider-track.is-dragging{cursor:grabbing}:host([vertical]) .wui-slider-track{width:var(--wui-slider-height,var(--wui-slider-track-size,6px));height:100%}.wui-slider-progress{z-index:1;width:var(--percent);border-radius:inherit;background-color:var(--wui-color-accent,#08f);position:absolute;top:0;bottom:0;left:0}:host([vertical]) .wui-slider-progress{width:100%;height:var(--percent);top:auto;bottom:0}.wui-slider-marks{pointer-events:none;z-index:2;top:calc(100% + 2px);right:var(--wui-slider-marks-inset,0);left:var(--wui-slider-marks-inset,0);height:4px;margin-left:2px;margin-right:2px;position:absolute}:host([vertical]) .wui-slider-marks{top:var(--wui-slider-marks-inset,0);right:auto;bottom:var(--wui-slider-marks-inset,0);width:4px;height:auto;margin:2px 0;left:calc(100% + 2px)}.wui-slider-mark{top:0;left:var(--percent);background-color:var(--wui-color-surface-track,#e5e5ea);border-radius:2147483647px;width:4px;height:4px;position:absolute;transform:translate(-50%)}:host([vertical]) .wui-slider-mark{top:auto;bottom:var(--percent);left:50%;transform:translate(-50%,50%)}.wui-slider-thumb{cursor:inherit;z-index:3;top:50%;left:var(--percent);transform-origin:50%;width:var(--wui-slider-thumb-width,30px);height:var(--wui-slider-thumb-height,20px);transition:transform var(--wui-duration-press,80ms) cubic-bezier(.4, 0, .2, 1), background-color var(--wui-duration-press,80ms) ease;border-radius:2147483647px;position:absolute;transform:translate(-50%,-50%)scale(1)}.wui-slider-thumb:not(.is-dragging){background-color:var(--wui-color-on-control,#fff)}.wui-slider-thumb.is-pressed:not(.is-dragging){background-color:var(--wui-color-surface-glass,#fafafa57);transform:translate(-50%,-50%)scale(1.5)}.wui-slider-thumb.is-dragging{cursor:grabbing;background-color:#0000;transform:translate(-50%,-50%)scale(1.5)}:host([vertical]) .wui-slider-thumb{top:auto;bottom:var(--percent);left:50%;transform:translate(-50%,50%)scale(1)}:host([vertical]) .wui-slider-thumb.is-pressed:not(.is-dragging),:host([vertical]) .wui-slider-thumb.is-dragging{transform:translate(-50%,50%)scale(1.5)}";
|
|
3
3
|
//#endregion
|
|
4
4
|
export { e as default };
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/slider/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n display: inline-block;\n width: var(--wui-slider-width, 200px);\n}\n\n:host([vertical]) {\n width: auto;\n height: var(--wui-slider-vertical-height, 200px);\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.wui-slider-track {\n cursor:
|
|
1
|
+
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/slider/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n display: inline-block;\n width: var(--wui-slider-width, 200px);\n}\n\n:host([vertical]) {\n width: auto;\n height: var(--wui-slider-vertical-height, 200px);\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.wui-slider-track {\n cursor: default;\n user-select: none;\n\n position: relative;\n\n width: 100%;\n height: var(--wui-slider-height, var(--wui-slider-track-size, 6px));\n border-radius: calc(infinity * 1px);\n\n background-color: var(--wui-color-surface-track, #e5e5ea);\n\n &:focus-visible {\n outline-color: var(--wui-color-focus-ring, rgb(0 136 255 / 0.4));\n }\n\n &.is-disabled {\n cursor: not-allowed;\n opacity: 0.38;\n }\n\n &.is-dragging {\n cursor: grabbing;\n }\n}\n\n:host([vertical]) .wui-slider-track {\n width: var(--wui-slider-height, var(--wui-slider-track-size, 6px));\n height: 100%;\n}\n\n.wui-slider-progress {\n position: absolute;\n z-index: 1;\n top: 0;\n bottom: 0;\n left: 0;\n\n width: var(--percent);\n border-radius: inherit;\n\n background-color: var(--wui-color-accent, #08f);\n}\n\n:host([vertical]) .wui-slider-progress {\n top: auto;\n bottom: 0;\n width: 100%;\n height: var(--percent);\n}\n\n.wui-slider-marks {\n pointer-events: none;\n\n position: absolute;\n z-index: 2;\n top: calc(100% + 2px);\n right: var(--wui-slider-marks-inset, 0);\n left: var(--wui-slider-marks-inset, 0);\n\n height: 4px;\n margin-right: 2px;\n margin-left: 2px;\n}\n\n:host([vertical]) .wui-slider-marks {\n top: var(--wui-slider-marks-inset, 0);\n right: auto;\n bottom: var(--wui-slider-marks-inset, 0);\n left: calc(100% + 2px);\n\n width: 4px;\n height: auto;\n margin: 2px 0;\n}\n\n.wui-slider-mark {\n position: absolute;\n top: 0;\n left: var(--percent);\n transform: translateX(-50%);\n\n width: 4px;\n height: 4px;\n border-radius: calc(infinity * 1px);\n\n background-color: var(--wui-color-surface-track, #e5e5ea);\n}\n\n:host([vertical]) .wui-slider-mark {\n top: auto;\n bottom: var(--percent);\n left: 50%;\n transform: translate(-50%, 50%);\n}\n\n.wui-slider-thumb {\n cursor: inherit;\n\n position: absolute;\n z-index: 3;\n top: 50%;\n left: var(--percent);\n transform-origin: center center;\n transform: translate(-50%, -50%) scale(1);\n\n width: var(--wui-slider-thumb-width, 30px);\n height: var(--wui-slider-thumb-height, 20px);\n border-radius: calc(infinity * 1px);\n\n transition:\n transform var(--wui-duration-press, 80ms) cubic-bezier(0.4, 0, 0.2, 1),\n background-color var(--wui-duration-press, 80ms) ease;\n\n &:not(.is-dragging) {\n background-color: var(--wui-color-on-control, #fff);\n }\n\n &.is-pressed:not(.is-dragging) {\n transform: translate(-50%, -50%) scale(1.5);\n background-color: var(--wui-color-surface-glass, rgb(250 250 250 / 0.34));\n }\n\n &.is-dragging {\n cursor: grabbing;\n transform: translate(-50%, -50%) scale(1.5);\n background-color: transparent;\n }\n}\n\n:host([vertical]) .wui-slider-thumb {\n top: auto;\n bottom: var(--percent);\n left: 50%;\n transform: translate(-50%, 50%) scale(1);\n\n &.is-pressed:not(.is-dragging) {\n transform: translate(-50%, 50%) scale(1.5);\n }\n\n &.is-dragging {\n transform: translate(-50%, 50%) scale(1.5);\n }\n}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/spinner/index.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { repeat } from 'lit/directives/repeat.js'\n\nimport style from './style.css?inline'\n\nconst LEAF_COUNT = 8\n\n@customElement('web-ui-spinner')\nexport class WebUiSpinner extends LitElement {\n static override styles = unsafeCSS(style)\n\n @property({ type: Number, reflect: true }) size = 24\n @property({ type: String }) description = ''\n\n //
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/spinner/index.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { repeat } from 'lit/directives/repeat.js'\n\nimport style from './style.css?inline'\n\nconst LEAF_COUNT = 8\n\n@customElement('web-ui-spinner')\nexport class WebUiSpinner extends LitElement {\n static override styles = unsafeCSS(style)\n\n @property({ type: Number, reflect: true }) size = 24\n @property({ type: String }) description = ''\n\n // 自动创建并挂载全屏实例。\n static show(options?: { size?: number; duration?: number; description?: string }): WebUiSpinner {\n const el = document.createElement('web-ui-spinner')\n el._imperative = true\n if (options?.size) el.size = options.size\n if (options?.description) el.description = options.description\n document.body.appendChild(el)\n if (options?.duration && options.duration > 0) {\n el._timer = window.setTimeout(() => WebUiSpinner.hide(), options.duration)\n }\n return el\n }\n\n // 销毁由 show() 挂载的全屏实例。\n static hide() {\n if (WebUiSpinner._current?._timer) {\n clearTimeout(WebUiSpinner._current._timer)\n WebUiSpinner._current._timer = undefined\n }\n WebUiSpinner._current?.remove()\n WebUiSpinner._current = undefined\n }\n\n /** @internal 当前命令式实例 */\n static _current?: WebUiSpinner\n\n /** @internal */\n _imperative = false\n /** @internal */\n _timer?: ReturnType<typeof setTimeout>\n\n override connectedCallback() {\n super.connectedCallback()\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'status')\n }\n if (!this.hasAttribute('aria-label')) {\n this.setAttribute('aria-label', '加载中')\n }\n if (this._imperative) {\n WebUiSpinner._current?.remove()\n WebUiSpinner._current = this\n this.classList.add('wui-spinner-overlay')\n }\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n if (this._timer) {\n clearTimeout(this._timer)\n this._timer = undefined\n }\n }\n\n protected override updated(props: PropertyValues) {\n super.updated(props)\n if (props.has('size')) {\n this.style.setProperty('--wui-spinner-size', `${this.size}px`)\n }\n }\n\n override render() {\n const spinner = html`\n <div class=\"wui-spinner\">\n ${repeat(\n Array.from({ length: LEAF_COUNT }, (_, i) => i),\n i =>\n html`<span\n style=\"transform:rotate(${i * 45}deg);animation-delay:calc(-${LEAF_COUNT - i} / ${LEAF_COUNT} * 0.8s)\"\n ></span>`\n )}\n </div>\n ${this.description ? html`<div class=\"spinner-description\">${this.description}</div>` : nothing}\n <slot name=\"description\"></slot>\n `\n return this._imperative ? html`<div class=\"wui-spinner-overlay\">${spinner}</div>` : spinner\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-spinner': WebUiSpinner\n }\n}\n"],"mappings":";;;;;;OAMM,IAAa,GAGN,IAAN,cAA2B,EAAW;;;;;EAiC7B,aA9BoC,KAAA,OAAA,IACR,KAAA,cAAA,IA6B5B,KAAA,cAAA;;;EAhCW,KAAA,SAAA,EAAU,CAAK;;CAMxC,OAAO,KAAK,GAAoF;EAC9F,IAAM,IAAK,SAAS,cAAc,gBAAgB;EAQlD,OAPA,EAAG,cAAc,IACb,GAAS,SAAM,EAAG,OAAO,EAAQ,OACjC,GAAS,gBAAa,EAAG,cAAc,EAAQ,cACnD,SAAS,KAAK,YAAY,CAAE,GACxB,GAAS,YAAY,EAAQ,WAAW,MAC1C,EAAG,SAAS,OAAO,iBAAA,EAA8B,KAAK,GAAG,EAAQ,QAAQ,IAEpE;CACT;CAGA,OAAO,OAAO;EAMZ,AALA,EAAiB,UAAU,WACzB,aAAA,EAA0B,SAAS,MAAM,GACzC,EAAa,SAAS,SAAS,KAAA,IAEjC,EAAa,UAAU,OAAO,GAC9B,EAAa,WAAW,KAAA;CAC1B;CAUA,oBAA6B;EAQ3B,AAPA,MAAM,kBAAkB,GACnB,KAAK,aAAa,MAAM,KAC3B,KAAK,aAAa,QAAQ,QAAQ,GAE/B,KAAK,aAAa,YAAY,KACjC,KAAK,aAAa,cAAc,KAAK,GAEnC,KAAK,gBACP,EAAa,UAAU,OAAO,GAC9B,EAAa,WAAW,MACxB,KAAK,UAAU,IAAI,qBAAqB;CAE5C;CAEA,uBAAgC;EAE9B,AADA,MAAM,qBAAqB,GAC3B,AAEE,KAAK,YADL,aAAa,KAAK,MAAM,GACV,KAAA;CAElB;CAEA,QAA2B,GAAuB;EAEhD,AADA,MAAM,QAAQ,CAAK,GACf,EAAM,IAAI,MAAM,KAClB,KAAK,MAAM,YAAY,sBAAsB,GAAG,KAAK,KAAK,GAAG;CAEjE;CAEA,SAAkB;EAChB,IAAM,IAAU,CAAI;;UAEd,EACA,MAAM,KAAK,EAAE,QAAQ,EAAW,IAAI,GAAG,MAAM,CAAC,IAC9C,MACE,CAAI;wCACwB,IAAI,GAAG,6BAA6B,IAAa,EAAE,KAAK,EAAW;qBAEnG,EAAE;;QAEF,KAAK,cAAc,CAAI,oCAAoC,KAAK,YAAY,UAAU,EAAQ;;;EAGlG,OAAO,KAAK,cAAc,CAAI,oCAAoC,EAAQ,UAAU;CACtF;AACF;AAhFG,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,QAAA,KAAA,CAAA,GACxC,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,EAAA,WAAA,eAAA,KAAA,CAAA,GAL3B,IAAA,IAAA,EAAA,CAAA,EAAc,gBAAgB,CAAA,GAAA,CAAA"}
|
|
@@ -11,6 +11,14 @@ export declare class WebUiSwitch extends LitElement {
|
|
|
11
11
|
required: boolean;
|
|
12
12
|
loading: boolean;
|
|
13
13
|
private _pressed;
|
|
14
|
+
private _isDragging;
|
|
15
|
+
private _dragOffset;
|
|
16
|
+
private _dragProgress;
|
|
17
|
+
private _dragged;
|
|
18
|
+
private _maxTravel;
|
|
19
|
+
private _startOffset;
|
|
20
|
+
private _dragGestureHandle;
|
|
21
|
+
disconnectedCallback(): void;
|
|
14
22
|
private get _isDisabled();
|
|
15
23
|
private readonly _formAssociation;
|
|
16
24
|
private readonly _formAssociationController;
|
|
@@ -3,14 +3,17 @@ import "../icon/index.js";
|
|
|
3
3
|
import t from "../../icons/generated/lucide-loader-circle.js";
|
|
4
4
|
import n from "../../assets/glass.js";
|
|
5
5
|
import { FormAssociationController as r, defineFormAssociation as i } from "../../shared/form-association/index.js";
|
|
6
|
-
import a from "
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import { attachDragGesture as a } from "../../shared/gesture/drag-gesture.js";
|
|
7
|
+
import { clamp as o, normalizeProgress as s } from "../../shared/gesture/physics.js";
|
|
8
|
+
import c from "./style.js";
|
|
9
|
+
import { LitElement as l, html as u, unsafeCSS as d } from "lit";
|
|
10
|
+
import { customElement as f, property as p, state as m } from "lit/decorators.js";
|
|
11
|
+
import { classMap as h } from "lit/directives/class-map.js";
|
|
12
|
+
import { styleMap as g } from "lit/directives/style-map.js";
|
|
10
13
|
//#region src/components/switch/index.ts
|
|
11
|
-
var
|
|
14
|
+
var _ = class extends l {
|
|
12
15
|
constructor(...e) {
|
|
13
|
-
super(...e), this._checked = !1, this.name = "", this.value = "", this.disabled = !1, this.required = !1, this.loading = !1, this._pressed = !1, this._formAssociation = i({
|
|
16
|
+
super(...e), this._checked = !1, this.name = "", this.value = "", this.disabled = !1, this.required = !1, this.loading = !1, this._pressed = !1, this._isDragging = !1, this._dragOffset = 0, this._dragProgress = 0, this._dragged = !1, this._maxTravel = 20, this._startOffset = 0, this._dragGestureHandle = null, this._formAssociation = i({
|
|
14
17
|
host: this,
|
|
15
18
|
initialize: () => {
|
|
16
19
|
this.hasAttribute("checked") && (this._checked = !0);
|
|
@@ -28,7 +31,7 @@ var p = class extends o {
|
|
|
28
31
|
}).make(), this._formAssociationController = new r(this, this._formAssociation);
|
|
29
32
|
}
|
|
30
33
|
static {
|
|
31
|
-
this.styles = [
|
|
34
|
+
this.styles = [d(n), d(c)];
|
|
32
35
|
}
|
|
33
36
|
static {
|
|
34
37
|
this.formAssociated = !0;
|
|
@@ -40,6 +43,9 @@ var p = class extends o {
|
|
|
40
43
|
let t = this._checked;
|
|
41
44
|
this._checked = e, this._formAssociation.sync(), this.requestUpdate("checked", t);
|
|
42
45
|
}
|
|
46
|
+
disconnectedCallback() {
|
|
47
|
+
super.disconnectedCallback(), this._dragGestureHandle?.destroy(), this._dragGestureHandle = null;
|
|
48
|
+
}
|
|
43
49
|
get _isDisabled() {
|
|
44
50
|
return this.disabled || this._formAssociation.isFormDisabled();
|
|
45
51
|
}
|
|
@@ -57,7 +63,11 @@ var p = class extends o {
|
|
|
57
63
|
!e || typeof e.setValidity != "function" || (this._isDisabled || !this.required || this._checked ? e.setValidity({}) : e.setValidity({ valueMissing: !0 }, "请启用此项"));
|
|
58
64
|
}
|
|
59
65
|
handleClick(e) {
|
|
60
|
-
if (e.preventDefault(), this.
|
|
66
|
+
if (e.preventDefault(), this._dragged) {
|
|
67
|
+
this._dragged = !1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this._isDisabled || this.loading) return;
|
|
61
71
|
let t = this._checked;
|
|
62
72
|
this._checked = !t, this._formAssociation.sync(), this.requestUpdate("checked", t), this.dispatchEvent(new Event("input", {
|
|
63
73
|
bubbles: !0,
|
|
@@ -67,28 +77,65 @@ var p = class extends o {
|
|
|
67
77
|
composed: !0
|
|
68
78
|
}));
|
|
69
79
|
}
|
|
70
|
-
handlePointerDown() {
|
|
71
|
-
this._isDisabled || this.loading
|
|
80
|
+
handlePointerDown(e) {
|
|
81
|
+
if (this._isDisabled || this.loading) return;
|
|
82
|
+
this._pressed = !0;
|
|
83
|
+
let t = this.renderRoot.querySelector(".wui-switch-track");
|
|
84
|
+
if (t) {
|
|
85
|
+
let e = t.getBoundingClientRect().width || 40;
|
|
86
|
+
this._maxTravel = Math.max(1, e - 4 - 20);
|
|
87
|
+
} else this._maxTravel = 16;
|
|
88
|
+
this._startOffset = this._checked ? this._maxTravel : 0, this._dragOffset = this._startOffset, this._dragProgress = +!!this._checked, this._dragGestureHandle?.destroy(), this._dragGestureHandle = a(e, {
|
|
89
|
+
axis: "x",
|
|
90
|
+
threshold: 6,
|
|
91
|
+
onMove: (e) => {
|
|
92
|
+
this._isDragging = !0;
|
|
93
|
+
let t = o(this._startOffset + e.deltaX, 0, this._maxTravel);
|
|
94
|
+
this._dragOffset = t, this._dragProgress = s(t, 0, this._maxTravel), this.requestUpdate();
|
|
95
|
+
},
|
|
96
|
+
onEnd: (e) => {
|
|
97
|
+
let t = this._isDragging;
|
|
98
|
+
if (this._isDragging = !1, this._pressed = !1, t) {
|
|
99
|
+
this._dragged = !0;
|
|
100
|
+
let t = this._checked;
|
|
101
|
+
if (t = e.velocityX > 300 ? !0 : e.velocityX < -300 ? !1 : this._dragProgress >= .5, t !== this._checked) {
|
|
102
|
+
let e = this._checked;
|
|
103
|
+
this._checked = t, this._formAssociation.sync(), this.requestUpdate("checked", e), this.dispatchEvent(new Event("input", {
|
|
104
|
+
bubbles: !0,
|
|
105
|
+
composed: !0
|
|
106
|
+
})), this.dispatchEvent(new Event("change", {
|
|
107
|
+
bubbles: !0,
|
|
108
|
+
composed: !0
|
|
109
|
+
}));
|
|
110
|
+
} else this.requestUpdate();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
onCancel: () => {
|
|
114
|
+
this._isDragging = !1, this._pressed = !1, this.requestUpdate();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
72
117
|
}
|
|
73
118
|
handlePointerUp() {
|
|
74
119
|
this._pressed = !1;
|
|
75
120
|
}
|
|
76
121
|
handlePointerLeave() {
|
|
77
|
-
this._pressed = !1;
|
|
122
|
+
this._isDragging || (this._pressed = !1);
|
|
78
123
|
}
|
|
79
124
|
render() {
|
|
80
125
|
let e = {
|
|
81
126
|
"wui-switch-track": !0,
|
|
82
|
-
"is-open": this._checked,
|
|
127
|
+
"is-open": this._isDragging ? this._dragProgress >= .5 : this._checked,
|
|
128
|
+
"is-dragging": this._isDragging,
|
|
83
129
|
"is-disabled": this._isDisabled || this.loading
|
|
84
130
|
}, n = {
|
|
85
131
|
"wui-switch-thumb": !0,
|
|
86
|
-
"wui-glass": this._pressed,
|
|
87
|
-
"is-pressed": this._pressed
|
|
88
|
-
};
|
|
89
|
-
return
|
|
132
|
+
"wui-glass": this._pressed || this._isDragging,
|
|
133
|
+
"is-pressed": this._pressed || this._isDragging
|
|
134
|
+
}, r = this._isDragging ? { "--wui-switch-drag-offset": `${this._dragOffset}px` } : {};
|
|
135
|
+
return u`
|
|
90
136
|
<label
|
|
91
|
-
class=${
|
|
137
|
+
class=${h(e)}
|
|
138
|
+
style=${g(r)}
|
|
92
139
|
role="switch"
|
|
93
140
|
aria-checked=${String(this._checked)}
|
|
94
141
|
@click=${this.handleClick}
|
|
@@ -103,8 +150,8 @@ var p = class extends o {
|
|
|
103
150
|
?disabled=${this._isDisabled || this.loading}
|
|
104
151
|
class="sr-only"
|
|
105
152
|
/>
|
|
106
|
-
<div class=${
|
|
107
|
-
${this.loading ?
|
|
153
|
+
<div class=${h(n)}>
|
|
154
|
+
${this.loading ? u`<div class="wui-switch-loading">
|
|
108
155
|
<web-ui-icon .icon=${t} size="14" color="#08f" spin></web-ui-icon>
|
|
109
156
|
</div>` : ""}
|
|
110
157
|
</div>
|
|
@@ -112,20 +159,20 @@ var p = class extends o {
|
|
|
112
159
|
`;
|
|
113
160
|
}
|
|
114
161
|
};
|
|
115
|
-
e([
|
|
162
|
+
e([m()], _.prototype, "_checked", void 0), e([p({
|
|
116
163
|
type: String,
|
|
117
164
|
reflect: !0
|
|
118
|
-
})],
|
|
165
|
+
})], _.prototype, "name", void 0), e([p({ type: String })], _.prototype, "value", void 0), e([p({
|
|
119
166
|
type: Boolean,
|
|
120
167
|
reflect: !0
|
|
121
|
-
})],
|
|
168
|
+
})], _.prototype, "disabled", void 0), e([p({
|
|
122
169
|
type: Boolean,
|
|
123
170
|
reflect: !0
|
|
124
|
-
})],
|
|
171
|
+
})], _.prototype, "required", void 0), e([p({
|
|
125
172
|
type: Boolean,
|
|
126
173
|
reflect: !0
|
|
127
|
-
})],
|
|
174
|
+
})], _.prototype, "loading", void 0), e([m()], _.prototype, "_pressed", void 0), e([m()], _.prototype, "_isDragging", void 0), e([m()], _.prototype, "_dragOffset", void 0), e([m()], _.prototype, "_dragProgress", void 0), _ = e([f("web-ui-switch")], _);
|
|
128
175
|
//#endregion
|
|
129
|
-
export {
|
|
176
|
+
export { _ as WebUiSwitch };
|
|
130
177
|
|
|
131
178
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/switch/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\n\nimport '@/components/icon'\nimport glass from '@/assets/glass.css?inline'\nimport { lucideLoaderCircle } from '@/icons'\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-switch')\nexport class WebUiSwitch extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n static formAssociated = true\n\n @state() private _checked = false\n\n get checked(): boolean {\n return this._checked\n }\n\n set checked(v: boolean) {\n const old = this._checked\n this._checked = v\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n }\n\n @property({ type: String, reflect: true }) name = ''\n @property({ type: String }) value = ''\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) required = false\n @property({ type: Boolean, reflect: true }) loading = false\n @state() private _pressed = false\n\n private get _isDisabled(): boolean {\n return this.disabled || this._formAssociation.isFormDisabled()\n }\n\n private readonly _formAssociation = defineFormAssociation<boolean>({\n host: this,\n initialize: () => {\n if (this.hasAttribute('checked')) this._checked = true\n },\n getState: () => this._checked,\n setState: checked => {\n this.checked = checked\n },\n getFormValue: () => (this._checked ? this.value || 'on' : null),\n getFormState: () => String(this._checked),\n restoreState: state => {\n if (typeof state === 'string') this.checked = state === 'true'\n },\n syncValidity: () => this._syncValidity()\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n private _syncValidity() {\n const internals = this._formAssociation.getInternals()\n if (!internals || typeof internals.setValidity !== 'function') return\n if (this._isDisabled || !this.required || this._checked) internals.setValidity({})\n else internals.setValidity({ valueMissing: true }, '请启用此项')\n }\n\n // 用户点击切换开关状态,阻止 label 默认行为避免原生 checkbox 重复触发\n private handleClick(e: Event) {\n e.preventDefault()\n if (this._isDisabled || this.loading) return\n const old = this._checked\n this._checked = !old\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n\n private handlePointerDown() {\n if (this._isDisabled || this.loading) return\n this._pressed = true\n }\n\n private handlePointerUp() {\n this._pressed = false\n }\n\n private handlePointerLeave() {\n this._pressed = false\n }\n\n override render() {\n const trackCls = {\n 'wui-switch-track': true,\n 'is-open': this._checked,\n 'is-disabled': this._isDisabled || this.loading\n }\n const thumbCls = {\n 'wui-switch-thumb': true,\n 'wui-glass': this._pressed,\n 'is-pressed': this._pressed\n }\n\n return html`\n <label\n class=${classMap(trackCls)}\n role=\"switch\"\n aria-checked=${String(this._checked)}\n @click=${this.handleClick}\n @pointerdown=${this.handlePointerDown}\n @pointerup=${this.handlePointerUp}\n @pointercancel=${this.handlePointerUp}\n @pointerleave=${this.handlePointerLeave}\n >\n <input\n type=\"checkbox\"\n .checked=${this._checked}\n ?disabled=${this._isDisabled || this.loading}\n class=\"sr-only\"\n />\n <div class=${classMap(thumbCls)}>\n ${\n this.loading\n ? html`<div class=\"wui-switch-loading\">\n <web-ui-icon .icon=${lucideLoaderCircle} size=\"14\" color=\"#08f\" spin></web-ui-icon>\n </div>`\n : ''\n }\n </div>\n </label>\n `\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-switch': WebUiSwitch\n }\n}\n"],"mappings":";;;;;;;;;;AAYO,IAAM,IAAN,cAA0B,EAAW;;E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C,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,EAAA,WAAA,SAAA,KAAA,CAAA,GACzB,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,WAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GAvBR,IAAA,EAAA,CAAA,EAAc,eAAe,CAAA,GAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/switch/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { styleMap } from 'lit/directives/style-map.js'\n\nimport '@/components/icon'\nimport glass from '@/assets/glass.css?inline'\nimport { lucideLoaderCircle } from '@/icons'\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\nimport { attachDragGesture, type DragGestureHandle } from '@/shared/gesture/drag-gesture'\nimport { clamp, normalizeProgress } from '@/shared/gesture/physics'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-switch')\nexport class WebUiSwitch extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n static formAssociated = true\n\n @state() private _checked = false\n\n get checked(): boolean {\n return this._checked\n }\n\n set checked(v: boolean) {\n const old = this._checked\n this._checked = v\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n }\n\n @property({ type: String, reflect: true }) name = ''\n @property({ type: String }) value = ''\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) required = false\n @property({ type: Boolean, reflect: true }) loading = false\n @state() private _pressed = false\n @state() private _isDragging = false\n @state() private _dragOffset = 0\n @state() private _dragProgress = 0\n\n private _dragged = false\n private _maxTravel = 20\n private _startOffset = 0\n private _dragGestureHandle: DragGestureHandle | null = null\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n this._dragGestureHandle?.destroy()\n this._dragGestureHandle = null\n }\n\n private get _isDisabled(): boolean {\n return this.disabled || this._formAssociation.isFormDisabled()\n }\n\n private readonly _formAssociation = defineFormAssociation<boolean>({\n host: this,\n initialize: () => {\n if (this.hasAttribute('checked')) this._checked = true\n },\n getState: () => this._checked,\n setState: checked => {\n this.checked = checked\n },\n getFormValue: () => (this._checked ? this.value || 'on' : null),\n getFormState: () => String(this._checked),\n restoreState: state => {\n if (typeof state === 'string') this.checked = state === 'true'\n },\n syncValidity: () => this._syncValidity()\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n private _syncValidity() {\n const internals = this._formAssociation.getInternals()\n if (!internals || typeof internals.setValidity !== 'function') return\n if (this._isDisabled || !this.required || this._checked) internals.setValidity({})\n else internals.setValidity({ valueMissing: true }, '请启用此项')\n }\n\n // 阻止 label 默认行为,避免原生 checkbox 重复触发点击。\n private handleClick(e: Event) {\n e.preventDefault()\n if (this._dragged) {\n this._dragged = false\n return\n }\n if (this._isDisabled || this.loading) return\n const old = this._checked\n this._checked = !old\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n\n private handlePointerDown(e: PointerEvent) {\n if (this._isDisabled || this.loading) return\n this._pressed = true\n\n const track = this.renderRoot.querySelector<HTMLElement>('.wui-switch-track')\n if (track) {\n const trackWidth = track.getBoundingClientRect().width || 40\n // 拖拽时 thumb 的 pressed 布局盒为 20px(scale(1.5) 视觉放大),因此行程按 20px 布局盒钳制;\n // 释放后的 checked 静止位移为 20px(16px thumb),两者由 transition 衔接。\n this._maxTravel = Math.max(1, trackWidth - 4 - 20)\n } else {\n this._maxTravel = 16\n }\n\n this._startOffset = this._checked ? this._maxTravel : 0\n this._dragOffset = this._startOffset\n this._dragProgress = this._checked ? 1 : 0\n\n this._dragGestureHandle?.destroy()\n this._dragGestureHandle = attachDragGesture(e, {\n axis: 'x',\n threshold: 6,\n onMove: info => {\n this._isDragging = true\n const current = clamp(this._startOffset + info.deltaX, 0, this._maxTravel)\n this._dragOffset = current\n this._dragProgress = normalizeProgress(current, 0, this._maxTravel)\n this.requestUpdate()\n },\n onEnd: info => {\n const wasDragging = this._isDragging\n this._isDragging = false\n this._pressed = false\n\n if (wasDragging) {\n this._dragged = true\n let targetChecked = this._checked\n if (info.velocityX > 300) {\n targetChecked = true\n } else if (info.velocityX < -300) {\n targetChecked = false\n } else {\n targetChecked = this._dragProgress >= 0.5\n }\n\n if (targetChecked !== this._checked) {\n const old = this._checked\n this._checked = targetChecked\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n } else {\n this.requestUpdate()\n }\n }\n },\n onCancel: () => {\n this._isDragging = false\n this._pressed = false\n this.requestUpdate()\n }\n })\n }\n\n private handlePointerUp() {\n this._pressed = false\n }\n\n private handlePointerLeave() {\n if (!this._isDragging) {\n this._pressed = false\n }\n }\n\n override render() {\n const isOpen = this._isDragging ? this._dragProgress >= 0.5 : this._checked\n const trackCls = {\n 'wui-switch-track': true,\n 'is-open': isOpen,\n 'is-dragging': this._isDragging,\n 'is-disabled': this._isDisabled || this.loading\n }\n const thumbCls = {\n 'wui-switch-thumb': true,\n 'wui-glass': this._pressed || this._isDragging,\n 'is-pressed': this._pressed || this._isDragging\n }\n const trackStyle = this._isDragging ? { '--wui-switch-drag-offset': `${this._dragOffset}px` } : {}\n\n return html`\n <label\n class=${classMap(trackCls)}\n style=${styleMap(trackStyle)}\n role=\"switch\"\n aria-checked=${String(this._checked)}\n @click=${this.handleClick}\n @pointerdown=${this.handlePointerDown}\n @pointerup=${this.handlePointerUp}\n @pointercancel=${this.handlePointerUp}\n @pointerleave=${this.handlePointerLeave}\n >\n <input\n type=\"checkbox\"\n .checked=${this._checked}\n ?disabled=${this._isDisabled || this.loading}\n class=\"sr-only\"\n />\n <div class=${classMap(thumbCls)}>\n ${\n this.loading\n ? html`<div class=\"wui-switch-loading\">\n <web-ui-icon .icon=${lucideLoaderCircle} size=\"14\" color=\"#08f\" spin></web-ui-icon>\n </div>`\n : ''\n }\n </div>\n </label>\n `\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-switch': WebUiSwitch\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAeO,IAAM,IAAN,cAA0B,EAAW;;EA2DI,aAvDlB,KAAA,WAAA,IAasB,KAAA,OAAA,IACd,KAAA,QAAA,IACmB,KAAA,WAAA,IACA,KAAA,WAAA,IACD,KAAA,UAAA,IAC1B,KAAA,WAAA,IACG,KAAA,cAAA,IACA,KAAA,cAAA,GACE,KAAA,gBAAA,GAEd,KAAA,WAAA,IACE,KAAA,aAAA,IACE,KAAA,eAAA,GACgC,KAAA,qBAAA,MAYnB,KAAA,mBAAA,EAA+B;GACjE,MAAM;GACN,kBAAkB;IAChB,AAAI,KAAK,aAAa,SAAS,MAAG,KAAK,WAAW;GACpD;GACA,gBAAgB,KAAK;GACrB,WAAU,MAAW;IACnB,KAAK,UAAU;GACjB;GACA,oBAAqB,KAAK,WAAW,KAAK,SAAS,OAAO;GAC1D,oBAAoB,OAAO,KAAK,QAAQ;GACxC,eAAc,MAAS;IACrB,AAAI,OAAO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AAA,WAAA,SAAA,KAAA,CAAA,GACzB,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,WAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACN,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,eAAA,KAAA,CAAA,GACN,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,eAAA,KAAA,CAAA,GACN,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,iBAAA,KAAA,CAAA,GA1BR,IAAA,EAAA,CAAA,EAAc,eAAe,CAAA,GAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/components/switch/style.css?inline
|
|
2
|
-
var e = "*,:before,:after{box-sizing:border-box}:host{display:inline-block}:host([disabled]){cursor:not-allowed}.sr-only{white-space:nowrap;clip-path:inset(50%);border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.wui-switch-track{cursor:
|
|
2
|
+
var e = "*,:before,:after{box-sizing:border-box}:host{display:inline-block}:host([disabled]){cursor:not-allowed}.sr-only{white-space:nowrap;clip-path:inset(50%);border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.wui-switch-track{touch-action:pan-y;cursor:default;-webkit-user-select:none;user-select:none;background-color:var(--wui-color-surface-track,#e5e5ea);outline:var(--wui-focus-ring-width,3px) solid transparent;outline-offset:2px;width:40px;height:20px;transition:background-color var(--wui-duration-trigger,.16s) ease;border-radius:2147483647px;justify-content:space-between;align-items:center;display:flex;position:relative}.wui-switch-track:focus-within{outline-color:var(--wui-color-focus-ring,#08f6)}.wui-switch-track.is-open{background-color:var(--wui-color-accent,#08f)}.wui-switch-track.is-disabled{cursor:not-allowed;opacity:.4}.wui-switch-thumb{transform-origin:50%;width:16px;height:16px;transition:width var(--wui-duration-press,80ms) cubic-bezier(.4, 0, .2, 1), transform var(--wui-duration-trigger,.16s) cubic-bezier(.4, 0, .2, 1), border-radius var(--wui-duration-press,80ms) cubic-bezier(.4, 0, .2, 1), background-color var(--wui-duration-press,80ms) ease;border-radius:2147483647px;position:absolute;top:2px;left:2px;overflow:hidden;transform:translate(0)scale(1)}.wui-switch-thumb.is-pressed{background-color:#0000;border-radius:2147483647px;width:20px;transform:translate(0)scale(1.5)}.wui-switch-thumb:not(.is-pressed){background-color:var(--wui-color-on-control,#fff);box-shadow:1px 2px 6px #0003}.wui-switch-track.is-open .wui-switch-thumb{transform:translate(20px)scale(1)}.wui-switch-track.is-open .wui-switch-thumb.is-pressed{transform:translate(16px)scale(1.5)}.wui-switch-track.is-dragging{cursor:grabbing}.wui-switch-track.is-dragging .wui-switch-thumb,.wui-switch-track.is-dragging .wui-switch-thumb.is-pressed{transform:translateX(var(--wui-switch-drag-offset,0)) scale(1.5);transition:none}.wui-switch-loading{pointer-events:none;justify-content:center;align-items:center;display:flex;position:absolute;inset:0}";
|
|
3
3
|
//#endregion
|
|
4
4
|
export { e as default };
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/switch/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n display: inline-block;\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n/*\n标准视觉隐藏技术(sr-only):\n业内标准的“屏幕阅读器专用”隐藏方案。\n把复选框缩放到 1x1 像素,但保留在 dom 中,\n既让肉眼看不见,又能让读屏软件识别,并允许键盘用户通过空格键切换状态。\n*/\n.sr-only {\n position: absolute;\n\n overflow: hidden;\n\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n border: 0;\n\n white-space: nowrap;\n\n clip-path: inset(50%);\n}\n\n.wui-switch-track {\n cursor:
|
|
1
|
+
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/switch/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n display: inline-block;\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n/*\n标准视觉隐藏技术(sr-only):\n业内标准的“屏幕阅读器专用”隐藏方案。\n把复选框缩放到 1x1 像素,但保留在 dom 中,\n既让肉眼看不见,又能让读屏软件识别,并允许键盘用户通过空格键切换状态。\n*/\n.sr-only {\n position: absolute;\n\n overflow: hidden;\n\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n border: 0;\n\n white-space: nowrap;\n\n clip-path: inset(50%);\n}\n\n.wui-switch-track {\n touch-action: pan-y;\n cursor: default;\n user-select: none;\n\n position: relative;\n\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n width: 40px;\n height: 20px;\n border-radius: calc(infinity * 1px);\n\n background-color: var(--wui-color-surface-track, #e5e5ea);\n outline: var(--wui-focus-ring-width, 3px) solid transparent;\n outline-offset: 2px;\n\n transition: background-color var(--wui-duration-trigger, 160ms) ease;\n\n /* 实际获得焦点的是内部 sr-only 的 checkbox,track 本身不可聚焦;\n :focus-visible 在 track 上永不匹配,需用 :focus-within 让键盘焦点环生效 */\n &:focus-within {\n outline-color: var(--wui-color-focus-ring, rgb(0 136 255 / 0.4));\n }\n\n &.is-open {\n background-color: var(--wui-color-accent, #08f);\n }\n\n &.is-disabled {\n cursor: not-allowed;\n opacity: 0.4;\n }\n}\n\n.wui-switch-thumb {\n position: absolute;\n top: 2px;\n left: 2px;\n transform-origin: center center;\n transform: translateX(0) scale(1);\n\n overflow: hidden;\n\n width: 16px;\n height: 16px;\n border-radius: calc(infinity * 1px);\n\n transition:\n width var(--wui-duration-press, 80ms) cubic-bezier(0.4, 0, 0.2, 1),\n transform var(--wui-duration-trigger, 160ms) cubic-bezier(0.4, 0, 0.2, 1),\n border-radius var(--wui-duration-press, 80ms) cubic-bezier(0.4, 0, 0.2, 1),\n background-color var(--wui-duration-press, 80ms) ease;\n\n &.is-pressed {\n transform: translateX(0) scale(1.5);\n width: 20px;\n border-radius: calc(infinity * 1px);\n background-color: transparent;\n }\n\n &:not(.is-pressed) {\n background-color: var(--wui-color-on-control, #fff);\n box-shadow: 1px 2px 6px rgb(0 0 0 / 0.2);\n }\n}\n\n.wui-switch-track.is-open .wui-switch-thumb {\n transform: translateX(20px) scale(1);\n\n &.is-pressed {\n transform: translateX(16px) scale(1.5);\n }\n}\n\n.wui-switch-track.is-dragging {\n cursor: grabbing;\n}\n\n.wui-switch-track.is-dragging .wui-switch-thumb,\n.wui-switch-track.is-dragging .wui-switch-thumb.is-pressed {\n transform: translateX(var(--wui-switch-drag-offset, 0)) scale(1.5);\n transition: none;\n}\n\n.wui-switch-loading {\n pointer-events: none;\n\n position: absolute;\n inset: 0;\n\n display: flex;\n align-items: center;\n justify-content: center;\n}\n"],"mappings":""}
|
|
@@ -91,10 +91,7 @@ var g = class extends o {
|
|
|
91
91
|
this._resizeObserver?.disconnect(), this._resizeObserver = null, e && this._textarea?.style.removeProperty("height");
|
|
92
92
|
}
|
|
93
93
|
_autosize() {
|
|
94
|
-
|
|
95
|
-
this._textarea.style.height = "auto";
|
|
96
|
-
let e = this.rows * 20, t = this._textarea.scrollHeight, n = Math.max(t, e);
|
|
97
|
-
this._textarea.style.height = `${n}px`;
|
|
94
|
+
!this._textarea || !this.autosize || (this._textarea.style.height = "auto", this._textarea.style.height = `${this._textarea.scrollHeight}px`);
|
|
98
95
|
}
|
|
99
96
|
handleInput(e) {
|
|
100
97
|
e.target instanceof HTMLTextAreaElement && (this._value = e.target.value, this._formAssociation.sync(), this._syncValidity(), this._autosize());
|