@spectrum-web-components/slider 0.13.1-devmode.0 → 0.14.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/package.json +7 -7
- package/sp-slider-handle.js +1 -2
- package/sp-slider-handle.js.map +1 -1
- package/sp-slider.js +1 -3
- package/sp-slider.js.map +1 -1
- package/src/HandleController.js +16 -421
- package/src/HandleController.js.map +1 -1
- package/src/Slider.js +23 -306
- package/src/Slider.js.map +1 -1
- package/src/SliderHandle.js +1 -183
- package/src/SliderHandle.js.map +1 -1
- package/src/index.js +1 -3
- package/src/index.js.map +1 -1
- package/src/slider.css.js +2 -4
- package/src/slider.css.js.map +1 -1
- package/src/spectrum-slider.css.js +2 -4
- package/src/spectrum-slider.css.js.map +1 -1
- package/stories/slider.stories.js +111 -408
- package/stories/slider.stories.js.map +1 -1
- package/sync/sp-slider.js +1 -2
- package/sync/sp-slider.js.map +1 -1
- package/test/benchmark/test-basic.js +1 -4
- package/test/benchmark/test-basic.js.map +1 -1
- package/test/slider-editable-sync.test.js +1 -136
- package/test/slider-editable-sync.test.js.map +1 -1
- package/test/slider-editable.test.js +1 -155
- package/test/slider-editable.test.js.map +1 -1
- package/test/slider-handle-upgrade.test.js +2 -11
- package/test/slider-handle-upgrade.test.js.map +1 -1
- package/test/slider.test-vrt.js +1 -3
- package/test/slider.test-vrt.js.map +1 -1
- package/test/slider.test.js +43 -772
- package/test/slider.test.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/slider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@internationalized/number": "^3.1.0",
|
|
77
77
|
"@lit-labs/observers": "^1.0.1",
|
|
78
|
-
"@spectrum-web-components/base": "^0.
|
|
79
|
-
"@spectrum-web-components/field-label": "^0.
|
|
80
|
-
"@spectrum-web-components/number-field": "^0.
|
|
81
|
-
"@spectrum-web-components/shared": "^0.
|
|
82
|
-
"@spectrum-web-components/theme": "^0.
|
|
78
|
+
"@spectrum-web-components/base": "^0.7.0",
|
|
79
|
+
"@spectrum-web-components/field-label": "^0.8.0",
|
|
80
|
+
"@spectrum-web-components/number-field": "^0.5.0",
|
|
81
|
+
"@spectrum-web-components/shared": "^0.15.0",
|
|
82
|
+
"@spectrum-web-components/theme": "^0.14.0",
|
|
83
83
|
"tslib": "^2.0.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"./**/*.dev.js",
|
|
93
93
|
"./sync/sp-*.js"
|
|
94
94
|
],
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "05c81318844160db3f8156144106e643507fef97"
|
|
96
96
|
}
|
package/sp-slider-handle.js
CHANGED
package/sp-slider-handle.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-slider-handle.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2021 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { SliderHandle } from './src/SliderHandle.js';\n\ncustomElements.define('sp-slider-handle', SliderHandle);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider-handle': SliderHandle;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,qDAEA,eAAe,OAAO,mBAAoB,CAAY",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/sp-slider.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Slider } from "./src/Slider.js";
|
|
3
|
-
customElements.define("sp-slider", Slider);
|
|
1
|
+
import"./sp-slider-handle.js";import{Slider as e}from"./src/Slider.js";customElements.define("sp-slider",e);
|
|
4
2
|
//# sourceMappingURL=sp-slider.js.map
|
package/sp-slider.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-slider.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport './sp-slider-handle.js'; // codify sp-slider's implicit dependency on sp-slider-handle\nimport { Slider } from './src/Slider.js';\n\ncustomElements.define('sp-slider', Slider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider': Slider;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,8BACA,yCAEA,eAAe,OAAO,YAAa,CAAM",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/HandleController.js
CHANGED
|
@@ -1,434 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
classMap,
|
|
4
|
-
ifDefined,
|
|
5
|
-
styleMap
|
|
6
|
-
} from "@spectrum-web-components/base/src/directives.js";
|
|
7
|
-
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
8
|
-
import {
|
|
9
|
-
SliderHandle
|
|
10
|
-
} from "./SliderHandle.js";
|
|
11
|
-
export class HandleController {
|
|
12
|
-
constructor(host) {
|
|
13
|
-
this.handles = /* @__PURE__ */ new Map();
|
|
14
|
-
this.model = [];
|
|
15
|
-
this.handleOrder = [];
|
|
16
|
-
this.handleOrientation = () => {
|
|
17
|
-
this.updateBoundingRect();
|
|
18
|
-
};
|
|
19
|
-
this.extractModelFromLightDom = () => {
|
|
20
|
-
let handles = [
|
|
21
|
-
...this.host.querySelectorAll('[slot="handle"]')
|
|
22
|
-
];
|
|
23
|
-
if (handles.length === 0) {
|
|
24
|
-
handles = [this.host];
|
|
25
|
-
}
|
|
26
|
-
if (handles.some((h) => this.waitForUpgrade(h))) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
this.handles = /* @__PURE__ */ new Map();
|
|
30
|
-
this.handleOrder = [];
|
|
31
|
-
handles.forEach((handle, index) => {
|
|
32
|
-
var _a;
|
|
33
|
-
if (!((_a = handle.handleName) == null ? void 0 : _a.length)) {
|
|
34
|
-
handle.name = `handle${index + 1}`;
|
|
35
|
-
}
|
|
36
|
-
this.handles.set(handle.handleName, handle);
|
|
37
|
-
this.handleOrder.push(handle.handleName);
|
|
38
|
-
handle.handleController = this;
|
|
39
|
-
});
|
|
40
|
-
this.requestUpdate();
|
|
41
|
-
};
|
|
42
|
-
this.onInputChange = (event) => {
|
|
43
|
-
const input = event.target;
|
|
44
|
-
input.model.handle.value = input.valueAsNumber;
|
|
45
|
-
this.requestUpdate();
|
|
46
|
-
this.dispatchChangeEvent(input, input.model.handle);
|
|
47
|
-
};
|
|
48
|
-
this.onInputFocus = (event) => {
|
|
49
|
-
const input = event.target;
|
|
50
|
-
let isFocusVisible;
|
|
51
|
-
try {
|
|
52
|
-
isFocusVisible = input.matches(":focus-visible") || this.host.matches(".focus-visible");
|
|
53
|
-
} catch (error) {
|
|
54
|
-
isFocusVisible = this.host.matches(".focus-visible");
|
|
55
|
-
}
|
|
56
|
-
input.model.handle.highlight = isFocusVisible;
|
|
57
|
-
this.requestUpdate();
|
|
58
|
-
};
|
|
59
|
-
this.onInputBlur = (event) => {
|
|
60
|
-
const input = event.target;
|
|
61
|
-
input.model.handle.highlight = false;
|
|
62
|
-
this.requestUpdate();
|
|
63
|
-
};
|
|
64
|
-
this.onInputKeydown = (event) => {
|
|
65
|
-
const input = event.target;
|
|
66
|
-
input.model.handle.highlight = true;
|
|
67
|
-
this.requestUpdate();
|
|
68
|
-
};
|
|
69
|
-
this.host = host;
|
|
70
|
-
new MutationController(this.host, {
|
|
71
|
-
config: {
|
|
72
|
-
subtree: true,
|
|
73
|
-
childList: true
|
|
74
|
-
},
|
|
75
|
-
callback: () => {
|
|
76
|
-
this.extractModelFromLightDom();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
this.extractModelFromLightDom();
|
|
80
|
-
}
|
|
81
|
-
get values() {
|
|
82
|
-
const result = {};
|
|
83
|
-
for (const model of this.handles.values()) {
|
|
84
|
-
result[model.handleName] = model.value;
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
get size() {
|
|
89
|
-
return this.handles.size;
|
|
90
|
-
}
|
|
91
|
-
inputForHandle(handle) {
|
|
92
|
-
if (this.handles.has(handle.handleName)) {
|
|
93
|
-
const { input } = this.getHandleElements(handle);
|
|
94
|
-
return input;
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`No input for handle "${handle.name}"`);
|
|
97
|
-
}
|
|
98
|
-
requestUpdate() {
|
|
99
|
-
if (this.host.hasUpdated) {
|
|
100
|
-
this.host.requestUpdate();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
setValueFromHandle(handle) {
|
|
104
|
-
const elements = this.getHandleElements(handle);
|
|
105
|
-
if (!elements)
|
|
106
|
-
return;
|
|
107
|
-
const { input } = elements;
|
|
108
|
-
if (input.valueAsNumber === handle.value) {
|
|
109
|
-
if (handle.dragging) {
|
|
110
|
-
handle.dispatchInputEvent();
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
input.valueAsNumber = handle.value;
|
|
114
|
-
this.requestUpdate();
|
|
115
|
-
}
|
|
116
|
-
handle.value = input.valueAsNumber;
|
|
117
|
-
}
|
|
118
|
-
handleHasChanged(handle) {
|
|
119
|
-
if (handle !== this.host) {
|
|
120
|
-
this.requestUpdate();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
formattedValueForHandle(model) {
|
|
124
|
-
var _a;
|
|
125
|
-
const { handle } = model;
|
|
126
|
-
const numberFormat = (_a = handle.numberFormat) != null ? _a : this.host.numberFormat;
|
|
127
|
-
return handle.getAriaHandleText(model.value, numberFormat);
|
|
128
|
-
}
|
|
129
|
-
get formattedValues() {
|
|
130
|
-
const result = /* @__PURE__ */ new Map();
|
|
131
|
-
for (const model of this.model) {
|
|
132
|
-
result.set(model.name, this.formattedValueForHandle(model));
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
get focusElement() {
|
|
137
|
-
const { input } = this.getActiveHandleElements();
|
|
138
|
-
if (this.host.editable && !input.model.handle.dragging) {
|
|
139
|
-
return this.host.numberField;
|
|
140
|
-
}
|
|
141
|
-
return input;
|
|
142
|
-
}
|
|
143
|
-
hostConnected() {
|
|
144
|
-
if ("orientation" in screen) {
|
|
145
|
-
screen.orientation.addEventListener("change", this.handleOrientation);
|
|
146
|
-
} else {
|
|
147
|
-
window.addEventListener("orientationchange", this.handleOrientation);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
hostDisconnected() {
|
|
151
|
-
if ("orientation" in screen) {
|
|
152
|
-
screen.orientation.removeEventListener("change", this.handleOrientation);
|
|
153
|
-
} else {
|
|
154
|
-
window.removeEventListener("orientationchange", this.handleOrientation);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
hostUpdate() {
|
|
158
|
-
this.updateModel();
|
|
159
|
-
}
|
|
160
|
-
waitForUpgrade(handle) {
|
|
161
|
-
if (handle instanceof SliderHandle) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
handle.addEventListener("sp-slider-handle-ready", () => this.extractModelFromLightDom(), { once: true, passive: true });
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
get activeHandle() {
|
|
168
|
-
return this.handleOrder[this.handleOrder.length - 1];
|
|
169
|
-
}
|
|
170
|
-
get activeHandleInputId() {
|
|
171
|
-
const active = this.activeHandle;
|
|
172
|
-
const index = this.model.findIndex((model) => model.name === active);
|
|
173
|
-
return `input-${index}`;
|
|
174
|
-
}
|
|
175
|
-
activateHandle(name) {
|
|
176
|
-
const index = this.handleOrder.findIndex((item) => item === name);
|
|
177
|
-
if (index >= 0) {
|
|
178
|
-
this.handleOrder.splice(index, 1);
|
|
179
|
-
}
|
|
180
|
-
this.handleOrder.push(name);
|
|
181
|
-
}
|
|
182
|
-
getActiveHandleElements() {
|
|
183
|
-
const name = this.activeHandle;
|
|
184
|
-
const handleSlider = this.handles.get(name);
|
|
185
|
-
const elements = this.getHandleElements(handleSlider);
|
|
186
|
-
return { model: handleSlider, ...elements };
|
|
187
|
-
}
|
|
188
|
-
getHandleElements(sliderHandle) {
|
|
189
|
-
if (!this.handleRefMap) {
|
|
190
|
-
this.handleRefMap = /* @__PURE__ */ new WeakMap();
|
|
191
|
-
const inputNodes = this.host.shadowRoot.querySelectorAll(".handle > input");
|
|
192
|
-
for (const inputNode of inputNodes) {
|
|
193
|
-
const input = inputNode;
|
|
194
|
-
const handle = input.parentElement;
|
|
195
|
-
const model = this.handles.get(handle.getAttribute("name"));
|
|
196
|
-
if (model) {
|
|
197
|
-
this.handleRefMap.set(model, { input, handle });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const components = this.handleRefMap.get(sliderHandle);
|
|
202
|
-
return components;
|
|
203
|
-
}
|
|
204
|
-
clearHandleComponentCache() {
|
|
205
|
-
delete this.handleRefMap;
|
|
206
|
-
}
|
|
207
|
-
get boundingClientRect() {
|
|
208
|
-
if (!this._boundingClientRect) {
|
|
209
|
-
this._boundingClientRect = this.host.track.getBoundingClientRect();
|
|
210
|
-
}
|
|
211
|
-
return this._boundingClientRect;
|
|
212
|
-
}
|
|
213
|
-
updateBoundingRect() {
|
|
214
|
-
delete this._boundingClientRect;
|
|
215
|
-
}
|
|
216
|
-
extractDataFromEvent(event) {
|
|
217
|
-
if (!this._activePointerEventData) {
|
|
218
|
-
let input = event.target.querySelector(":scope > .input");
|
|
219
|
-
const resolvedInput = !input;
|
|
220
|
-
const model = input ? input.model : this.model.find((item) => item.name === this.activeHandle);
|
|
221
|
-
if (!input && !!model) {
|
|
222
|
-
input = model.handle.focusElement;
|
|
223
|
-
}
|
|
224
|
-
this._activePointerEventData = {
|
|
225
|
-
input,
|
|
226
|
-
model,
|
|
227
|
-
resolvedInput
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return this._activePointerEventData;
|
|
231
|
-
}
|
|
232
|
-
handlePointerdown(event) {
|
|
233
|
-
const { resolvedInput, model } = this.extractDataFromEvent(event);
|
|
234
|
-
if (!model || this.host.disabled || event.button !== 0) {
|
|
235
|
-
event.preventDefault();
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
this.host.track.setPointerCapture(event.pointerId);
|
|
239
|
-
this.updateBoundingRect();
|
|
240
|
-
this.host.labelEl.click();
|
|
241
|
-
this.draggingHandle = model.handle;
|
|
242
|
-
model.handle.dragging = true;
|
|
243
|
-
this.activateHandle(model.name);
|
|
244
|
-
if (resolvedInput) {
|
|
245
|
-
this.handlePointermove(event);
|
|
246
|
-
}
|
|
247
|
-
this.requestUpdate();
|
|
248
|
-
}
|
|
249
|
-
handlePointerup(event) {
|
|
250
|
-
const { input, model } = this.extractDataFromEvent(event);
|
|
251
|
-
delete this._activePointerEventData;
|
|
252
|
-
if (!model)
|
|
253
|
-
return;
|
|
254
|
-
this.host.labelEl.click();
|
|
255
|
-
this.cancelDrag(model);
|
|
256
|
-
this.requestUpdate();
|
|
257
|
-
this.host.track.releasePointerCapture(event.pointerId);
|
|
258
|
-
this.dispatchChangeEvent(input, model.handle);
|
|
259
|
-
}
|
|
260
|
-
handlePointermove(event) {
|
|
261
|
-
const { input, model } = this.extractDataFromEvent(event);
|
|
262
|
-
if (!model)
|
|
263
|
-
return;
|
|
264
|
-
if (!this.draggingHandle) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
event.stopPropagation();
|
|
268
|
-
input.value = this.calculateHandlePosition(event, model).toString();
|
|
269
|
-
model.handle.value = parseFloat(input.value);
|
|
270
|
-
this.host.indeterminate = false;
|
|
271
|
-
this.requestUpdate();
|
|
272
|
-
}
|
|
273
|
-
cancelDrag(model) {
|
|
274
|
-
model = model || this.model.find((item) => item.name === this.activeHandle);
|
|
275
|
-
if (!model)
|
|
276
|
-
return;
|
|
277
|
-
model.handle.highlight = false;
|
|
278
|
-
delete this.draggingHandle;
|
|
279
|
-
model.handle.dragging = false;
|
|
280
|
-
}
|
|
281
|
-
dispatchChangeEvent(input, handle) {
|
|
282
|
-
input.valueAsNumber = handle.value;
|
|
283
|
-
const changeEvent = new Event("change", {
|
|
284
|
-
bubbles: true,
|
|
285
|
-
composed: true
|
|
286
|
-
});
|
|
287
|
-
handle.dispatchEvent(changeEvent);
|
|
288
|
-
}
|
|
289
|
-
calculateHandlePosition(event, model) {
|
|
290
|
-
const rect = this.boundingClientRect;
|
|
291
|
-
const minOffset = rect.left;
|
|
292
|
-
const offset = event.clientX;
|
|
293
|
-
const size = rect.width;
|
|
294
|
-
const directionalOffset = this.host.isLTR ? offset - minOffset : size - (offset - minOffset);
|
|
295
|
-
const normalized = directionalOffset / size;
|
|
296
|
-
return model.normalization.fromNormalized(normalized, model.range.min, model.range.max);
|
|
297
|
-
}
|
|
298
|
-
renderHandle(model, index, zIndex, isMultiHandle) {
|
|
299
|
-
var _a;
|
|
300
|
-
const classes = {
|
|
301
|
-
handle: true,
|
|
302
|
-
dragging: ((_a = this.draggingHandle) == null ? void 0 : _a.handleName) === model.name,
|
|
303
|
-
"handle-highlight": model.highlight
|
|
304
|
-
};
|
|
305
|
-
const style = {
|
|
306
|
-
[this.host.isLTR ? "left" : "right"]: `${model.normalizedValue * 100}%`,
|
|
307
|
-
"z-index": zIndex.toString(),
|
|
308
|
-
"background-color": `var(--spectrum-slider-handle-background-color-${index}, var(--spectrum-slider-handle-default-background-color))`,
|
|
309
|
-
"border-color": `var(--spectrum-slider-handle-border-color-${index}, var(-spectrum-slider-handle-default-border-color))`
|
|
310
|
-
};
|
|
311
|
-
const ariaLabelledBy = isMultiHandle ? `label input-${index}` : "label";
|
|
312
|
-
return html`
|
|
1
|
+
import{html as m}from"@spectrum-web-components/base";import{classMap as p,ifDefined as c,styleMap as g}from"@spectrum-web-components/base/src/directives.js";import{MutationController as v}from"@lit-labs/observers/mutation_controller.js";import{SliderHandle as f}from"./SliderHandle.js";export class HandleController{constructor(e){this.handles=new Map;this.model=[];this.handleOrder=[];this.handleOrientation=()=>{this.updateBoundingRect()};this.extractModelFromLightDom=()=>{let e=[...this.host.querySelectorAll('[slot="handle"]')];e.length===0&&(e=[this.host]),!e.some(t=>this.waitForUpgrade(t))&&(this.handles=new Map,this.handleOrder=[],e.forEach((t,n)=>{var a;(a=t.handleName)!=null&&a.length||(t.name=`handle${n+1}`),this.handles.set(t.handleName,t),this.handleOrder.push(t.handleName),t.handleController=this}),this.requestUpdate())};this.onInputChange=e=>{const t=e.target;t.model.handle.value=t.valueAsNumber,this.requestUpdate(),this.dispatchChangeEvent(t,t.model.handle)};this.onInputFocus=e=>{const t=e.target;let n;try{n=t.matches(":focus-visible")||this.host.matches(".focus-visible")}catch(a){n=this.host.matches(".focus-visible")}t.model.handle.highlight=n,this.requestUpdate()};this.onInputBlur=e=>{const t=e.target;t.model.handle.highlight=!1,this.requestUpdate()};this.onInputKeydown=e=>{const t=e.target;t.model.handle.highlight=!0,this.requestUpdate()};this.host=e,new v(this.host,{config:{subtree:!0,childList:!0},callback:()=>{this.extractModelFromLightDom()}}),this.extractModelFromLightDom()}get values(){const e={};for(const t of this.handles.values())e[t.handleName]=t.value;return e}get size(){return this.handles.size}inputForHandle(e){if(this.handles.has(e.handleName)){const{input:t}=this.getHandleElements(e);return t}throw new Error(`No input for handle "${e.name}"`)}requestUpdate(){this.host.hasUpdated&&this.host.requestUpdate()}setValueFromHandle(e){const t=this.getHandleElements(e);if(!t)return;const{input:n}=t;n.valueAsNumber===e.value?e.dragging&&e.dispatchInputEvent():(n.valueAsNumber=e.value,this.requestUpdate()),e.value=n.valueAsNumber}handleHasChanged(e){e!==this.host&&this.requestUpdate()}formattedValueForHandle(e){var a;const{handle:t}=e,n=(a=t.numberFormat)!=null?a:this.host.numberFormat;return t.getAriaHandleText(e.value,n)}get formattedValues(){const e=new Map;for(const t of this.model)e.set(t.name,this.formattedValueForHandle(t));return e}get focusElement(){const{input:e}=this.getActiveHandleElements();return this.host.editable&&!e.model.handle.dragging?this.host.numberField:e}hostConnected(){"orientation"in screen?screen.orientation.addEventListener("change",this.handleOrientation):window.addEventListener("orientationchange",this.handleOrientation)}hostDisconnected(){"orientation"in screen?screen.orientation.removeEventListener("change",this.handleOrientation):window.removeEventListener("orientationchange",this.handleOrientation)}hostUpdate(){this.updateModel()}waitForUpgrade(e){return e instanceof f?!1:(e.addEventListener("sp-slider-handle-ready",()=>this.extractModelFromLightDom(),{once:!0,passive:!0}),!0)}get activeHandle(){return this.handleOrder[this.handleOrder.length-1]}get activeHandleInputId(){const e=this.activeHandle;return`input-${this.model.findIndex(n=>n.name===e)}`}activateHandle(e){const t=this.handleOrder.findIndex(n=>n===e);t>=0&&this.handleOrder.splice(t,1),this.handleOrder.push(e)}getActiveHandleElements(){const e=this.activeHandle,t=this.handles.get(e),n=this.getHandleElements(t);return{model:t,...n}}getHandleElements(e){if(!this.handleRefMap){this.handleRefMap=new WeakMap;const n=this.host.shadowRoot.querySelectorAll(".handle > input");for(const a of n){const i=a,r=i.parentElement,l=this.handles.get(r.getAttribute("name"));l&&this.handleRefMap.set(l,{input:i,handle:r})}}return this.handleRefMap.get(e)}clearHandleComponentCache(){delete this.handleRefMap}get boundingClientRect(){return this._boundingClientRect||(this._boundingClientRect=this.host.track.getBoundingClientRect()),this._boundingClientRect}updateBoundingRect(){delete this._boundingClientRect}extractDataFromEvent(e){if(!this._activePointerEventData){let t=e.target.querySelector(":scope > .input");const n=!t,a=t?t.model:this.model.find(i=>i.name===this.activeHandle);!t&&!!a&&(t=a.handle.focusElement),this._activePointerEventData={input:t,model:a,resolvedInput:n}}return this._activePointerEventData}handlePointerdown(e){const{resolvedInput:t,model:n}=this.extractDataFromEvent(e);if(!n||this.host.disabled||e.button!==0){e.preventDefault();return}this.host.track.setPointerCapture(e.pointerId),this.updateBoundingRect(),this.host.labelEl.click(),this.draggingHandle=n.handle,n.handle.dragging=!0,this.activateHandle(n.name),t&&this.handlePointermove(e),this.requestUpdate()}handlePointerup(e){const{input:t,model:n}=this.extractDataFromEvent(e);delete this._activePointerEventData,n&&(this.host.labelEl.click(),this.cancelDrag(n),this.requestUpdate(),this.host.track.releasePointerCapture(e.pointerId),this.dispatchChangeEvent(t,n.handle))}handlePointermove(e){const{input:t,model:n}=this.extractDataFromEvent(e);!n||!this.draggingHandle||(e.stopPropagation(),t.value=this.calculateHandlePosition(e,n).toString(),n.handle.value=parseFloat(t.value),this.host.indeterminate=!1,this.requestUpdate())}cancelDrag(e){e=e||this.model.find(t=>t.name===this.activeHandle),e&&(e.handle.highlight=!1,delete this.draggingHandle,e.handle.dragging=!1)}dispatchChangeEvent(e,t){e.valueAsNumber=t.value;const n=new Event("change",{bubbles:!0,composed:!0});t.dispatchEvent(n)}calculateHandlePosition(e,t){const n=this.boundingClientRect,a=n.left,i=e.clientX,r=n.width,s=(this.host.isLTR?i-a:r-(i-a))/r;return t.normalization.fromNormalized(s,t.range.min,t.range.max)}renderHandle(e,t,n,a){var s;const i={handle:!0,dragging:((s=this.draggingHandle)==null?void 0:s.handleName)===e.name,"handle-highlight":e.highlight},r={[this.host.isLTR?"left":"right"]:`${e.normalizedValue*100}%`,"z-index":n.toString(),"background-color":`var(--spectrum-slider-handle-background-color-${t}, var(--spectrum-slider-handle-default-background-color))`,"border-color":`var(--spectrum-slider-handle-border-color-${t}, var(-spectrum-slider-handle-default-border-color))`},l=a?`label input-${t}`:"label";return m`
|
|
313
2
|
<div
|
|
314
|
-
class=${
|
|
315
|
-
name=${
|
|
316
|
-
style=${
|
|
3
|
+
class=${p(i)}
|
|
4
|
+
name=${e.name}
|
|
5
|
+
style=${g(r)}
|
|
317
6
|
role="presentation"
|
|
318
7
|
>
|
|
319
8
|
<input
|
|
320
9
|
type="range"
|
|
321
10
|
class="input"
|
|
322
|
-
id="input-${
|
|
323
|
-
min=${
|
|
324
|
-
max=${
|
|
325
|
-
step=${
|
|
326
|
-
value=${
|
|
327
|
-
aria-disabled=${
|
|
328
|
-
tabindex=${
|
|
329
|
-
aria-label=${
|
|
330
|
-
aria-labelledby=${
|
|
331
|
-
aria-valuetext=${this.formattedValueForHandle(
|
|
11
|
+
id="input-${t}"
|
|
12
|
+
min=${e.clamp.min}
|
|
13
|
+
max=${e.clamp.max}
|
|
14
|
+
step=${e.step}
|
|
15
|
+
value=${e.value}
|
|
16
|
+
aria-disabled=${c(this.host.disabled?"true":void 0)}
|
|
17
|
+
tabindex=${c(this.host.editable?-1:void 0)}
|
|
18
|
+
aria-label=${c(e.ariaLabel)}
|
|
19
|
+
aria-labelledby=${l}
|
|
20
|
+
aria-valuetext=${this.formattedValueForHandle(e)}
|
|
332
21
|
@change=${this.onInputChange}
|
|
333
22
|
@focus=${this.onInputFocus}
|
|
334
23
|
@blur=${this.onInputBlur}
|
|
335
24
|
@keydown=${this.onInputKeydown}
|
|
336
|
-
.model=${
|
|
25
|
+
.model=${e}
|
|
337
26
|
/>
|
|
338
27
|
</div>
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
render() {
|
|
342
|
-
this.clearHandleComponentCache();
|
|
343
|
-
return this.model.map((model, index) => {
|
|
344
|
-
const zIndex = this.handleOrder.indexOf(model.name) + 1;
|
|
345
|
-
return this.renderHandle(model, index, zIndex, this.model.length > 1);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
trackSegments() {
|
|
349
|
-
const values = this.model.map((model) => model.normalizedValue);
|
|
350
|
-
values.sort((a, b) => a - b);
|
|
351
|
-
values.unshift(0);
|
|
352
|
-
return values.map((value, index, array) => {
|
|
353
|
-
var _a;
|
|
354
|
-
return [
|
|
355
|
-
value,
|
|
356
|
-
(_a = array[index + 1]) != null ? _a : 1
|
|
357
|
-
];
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
updateModel() {
|
|
361
|
-
const handles = [...this.handles.values()];
|
|
362
|
-
const getRangeAndClamp = (index) => {
|
|
363
|
-
const handle = handles[index];
|
|
364
|
-
const previous = handles[index - 1];
|
|
365
|
-
const next = handles[index + 1];
|
|
366
|
-
const min = typeof handle.min === "number" ? handle.min : this.host.min;
|
|
367
|
-
const max = typeof handle.max === "number" ? handle.max : this.host.max;
|
|
368
|
-
const result = {
|
|
369
|
-
range: { min, max },
|
|
370
|
-
clamp: { min, max }
|
|
371
|
-
};
|
|
372
|
-
if (handle.min === "previous") {
|
|
373
|
-
if (previous) {
|
|
374
|
-
for (let j = index - 1; j >= 0; j--) {
|
|
375
|
-
const item = handles[j];
|
|
376
|
-
if (typeof item.min === "number") {
|
|
377
|
-
result.range.min = item.min;
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
result.clamp.min = Math.max(previous.value, result.range.min);
|
|
382
|
-
}
|
|
383
|
-
if (false) {
|
|
384
|
-
if (!previous) {
|
|
385
|
-
window.__swc.warn(this.host, `<sp-slider-handle> elements that are the first child of an <sp-slider> element cannot have attribute "min='previous'"\``, "https://opensource.adobe.com/spectrum-web-components/components/slider-handle/#multi-handle-slider-with-ordered-handles");
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (handle.max === "next") {
|
|
390
|
-
if (next) {
|
|
391
|
-
for (let j = index + 1; j < handles.length; j++) {
|
|
392
|
-
const item = handles[j];
|
|
393
|
-
if (typeof item.max === "number") {
|
|
394
|
-
result.range.max = item.max;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
result.clamp.max = Math.min(next.value, result.range.max);
|
|
399
|
-
}
|
|
400
|
-
if (false) {
|
|
401
|
-
if (!next) {
|
|
402
|
-
window.__swc.warn(this.host, `<sp-slider-handle> elements that are the last child of an <sp-slider> element cannot have attribute "max='next'"`, "https://opensource.adobe.com/spectrum-web-components/components/slider-handle/#multi-handle-slider-with-ordered-handles");
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return result;
|
|
407
|
-
};
|
|
408
|
-
const modelValues = handles.map((handle, index) => {
|
|
409
|
-
var _a;
|
|
410
|
-
const rangeAndClamp = getRangeAndClamp(index);
|
|
411
|
-
const { toNormalized } = handle.normalization;
|
|
412
|
-
const clampedValue = Math.max(Math.min(handle.value, rangeAndClamp.clamp.max), rangeAndClamp.clamp.min);
|
|
413
|
-
const normalizedValue = toNormalized(clampedValue, rangeAndClamp.range.min, rangeAndClamp.range.max);
|
|
414
|
-
const model = {
|
|
415
|
-
name: handle.handleName,
|
|
416
|
-
value: clampedValue,
|
|
417
|
-
normalizedValue,
|
|
418
|
-
highlight: handle.highlight,
|
|
419
|
-
step: (_a = handle.step) != null ? _a : this.host.step,
|
|
420
|
-
normalization: handle.normalization,
|
|
421
|
-
handle,
|
|
422
|
-
ariaLabel: handle !== this.host && (handle == null ? void 0 : handle.label.length) > 0 ? handle.label : void 0,
|
|
423
|
-
...rangeAndClamp
|
|
424
|
-
};
|
|
425
|
-
return model;
|
|
426
|
-
});
|
|
427
|
-
this.model = modelValues;
|
|
428
|
-
}
|
|
429
|
-
async handleUpdatesComplete() {
|
|
430
|
-
const updates = [...this.handles.values()].filter((handle) => handle !== this.host).map((handle) => handle.updateComplete);
|
|
431
|
-
await Promise.all(updates);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
28
|
+
`}render(){return this.clearHandleComponentCache(),this.model.map((e,t)=>{const n=this.handleOrder.indexOf(e.name)+1;return this.renderHandle(e,t,n,this.model.length>1)})}trackSegments(){const e=this.model.map(t=>t.normalizedValue);return e.sort((t,n)=>t-n),e.unshift(0),e.map((t,n,a)=>{var i;return[t,(i=a[n+1])!=null?i:1]})}updateModel(){const e=[...this.handles.values()],t=a=>{const i=e[a],r=e[a-1],l=e[a+1],s=typeof i.min=="number"?i.min:this.host.min,u=typeof i.max=="number"?i.max:this.host.max,d={range:{min:s,max:u},clamp:{min:s,max:u}};if(i.min==="previous"&&r){for(let o=a-1;o>=0;o--){const h=e[o];if(typeof h.min=="number"){d.range.min=h.min;break}}d.clamp.min=Math.max(r.value,d.range.min)}if(i.max==="next"&&l){for(let o=a+1;o<e.length;o++){const h=e[o];if(typeof h.max=="number"){d.range.max=h.max;break}}d.clamp.max=Math.min(l.value,d.range.max)}return d},n=e.map((a,i)=>{var o;const r=t(i),{toNormalized:l}=a.normalization,s=Math.max(Math.min(a.value,r.clamp.max),r.clamp.min),u=l(s,r.range.min,r.range.max);return{name:a.handleName,value:s,normalizedValue:u,highlight:a.highlight,step:(o=a.step)!=null?o:this.host.step,normalization:a.normalization,handle:a,ariaLabel:a!==this.host&&(a==null?void 0:a.label.length)>0?a.label:void 0,...r}});this.model=n}async handleUpdatesComplete(){const e=[...this.handles.values()].filter(t=>t!==this.host).map(t=>t.updateComplete);await Promise.all(e)}}
|
|
434
29
|
//# sourceMappingURL=HandleController.js.map
|