@spectrum-web-components/color-area 0.0.0-20241209155954

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.
@@ -0,0 +1,507 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ html,
14
+ SpectrumElement
15
+ } from "@spectrum-web-components/base";
16
+ import {
17
+ ifDefined,
18
+ styleMap
19
+ } from "@spectrum-web-components/base/src/directives.js";
20
+ import {
21
+ property,
22
+ query
23
+ } from "@spectrum-web-components/base/src/decorators.js";
24
+ import { streamingListener } from "@spectrum-web-components/base/src/streaming-listener.js";
25
+ import "@spectrum-web-components/color-handle/sp-color-handle.js";
26
+ import {
27
+ ColorController
28
+ } from "@spectrum-web-components/reactive-controllers/src/Color.js";
29
+ import { LanguageResolutionController } from "@spectrum-web-components/reactive-controllers/src/LanguageResolution.js";
30
+ import {
31
+ isAndroid,
32
+ isIOS
33
+ } from "@spectrum-web-components/shared/src/platform.js";
34
+ import styles from "./color-area.css.js";
35
+ export class ColorArea extends SpectrumElement {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.disabled = false;
39
+ this.focused = false;
40
+ this.labelX = "saturation";
41
+ this.labelY = "luminosity";
42
+ this.languageResolver = new LanguageResolutionController(this);
43
+ this.colorController = new ColorController(this, {
44
+ extractColorFromState: () => ({
45
+ h: this.hue,
46
+ s: this.x,
47
+ v: this.y
48
+ }),
49
+ applyColorToState: ({ s, v }) => {
50
+ this._x = s;
51
+ this._y = v;
52
+ this.requestUpdate();
53
+ }
54
+ });
55
+ this.activeAxis = "x";
56
+ this._x = 1;
57
+ this._y = 1;
58
+ this.step = 0.01;
59
+ this.altered = 0;
60
+ this.activeKeys = /* @__PURE__ */ new Set();
61
+ this._valueChanged = false;
62
+ this._pointerDown = false;
63
+ }
64
+ static get styles() {
65
+ return [styles];
66
+ }
67
+ get hue() {
68
+ return this.colorController.hue;
69
+ }
70
+ set hue(value) {
71
+ this.colorController.hue = value;
72
+ }
73
+ get value() {
74
+ return this.colorController.color;
75
+ }
76
+ get color() {
77
+ return this.colorController.color;
78
+ }
79
+ set color(color) {
80
+ this.colorController.color = color;
81
+ }
82
+ get x() {
83
+ return this._x;
84
+ }
85
+ set x(x) {
86
+ if (x === this.x) {
87
+ return;
88
+ }
89
+ const oldValue = this.x;
90
+ this._x = x;
91
+ if (this.inputX) {
92
+ this.inputX.value = x.toString();
93
+ this._x = this.inputX.valueAsNumber;
94
+ }
95
+ this.requestUpdate("x", oldValue);
96
+ this.colorController.applyColorFromState();
97
+ }
98
+ get y() {
99
+ return this._y;
100
+ }
101
+ set y(y) {
102
+ if (y === this.y) {
103
+ return;
104
+ }
105
+ const oldValue = this.y;
106
+ this._y = y;
107
+ if (this.inputY) {
108
+ this.inputY.value = y.toString();
109
+ this._y = this.inputY.valueAsNumber;
110
+ }
111
+ this.requestUpdate("y", oldValue);
112
+ this.colorController.applyColorFromState();
113
+ }
114
+ focus(focusOptions = {}) {
115
+ super.focus(focusOptions);
116
+ this.forwardFocus();
117
+ }
118
+ forwardFocus() {
119
+ this.focused = this.hasVisibleFocusInTree();
120
+ if (this.activeAxis === "x") {
121
+ this.inputX.focus();
122
+ } else {
123
+ this.inputY.focus();
124
+ }
125
+ }
126
+ handleFocus() {
127
+ this.focused = true;
128
+ this._valueChanged = false;
129
+ }
130
+ handleBlur() {
131
+ if (this._pointerDown) {
132
+ return;
133
+ }
134
+ this.altered = 0;
135
+ this.focused = false;
136
+ this._valueChanged = false;
137
+ }
138
+ handleKeydown(event) {
139
+ const { code } = event;
140
+ this.focused = true;
141
+ this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(
142
+ (key) => !!key
143
+ ).length;
144
+ const isArrowKey = code.search("Arrow") === 0 || code.search("Page") === 0 || code.search("Home") === 0 || code.search("End") === 0;
145
+ if (isArrowKey) {
146
+ event.preventDefault();
147
+ this.activeKeys.add(code);
148
+ this.handleKeypress();
149
+ }
150
+ }
151
+ handleKeypress() {
152
+ let deltaX = 0;
153
+ let deltaY = 0;
154
+ const step = Math.max(this.step, this.altered * 5 * this.step);
155
+ this.activeKeys.forEach((code) => {
156
+ switch (code) {
157
+ case "ArrowUp":
158
+ deltaY = step;
159
+ break;
160
+ case "ArrowDown":
161
+ deltaY = step * -1;
162
+ break;
163
+ case "ArrowLeft":
164
+ deltaX = this.step * (this.isLTR ? -1 : 1);
165
+ break;
166
+ case "ArrowRight":
167
+ deltaX = this.step * (this.isLTR ? 1 : -1);
168
+ break;
169
+ case "PageUp":
170
+ deltaY = step * 10;
171
+ break;
172
+ case "PageDown":
173
+ deltaY = step * -10;
174
+ break;
175
+ case "Home":
176
+ deltaX = step * (this.isLTR ? -10 : 10);
177
+ break;
178
+ case "End":
179
+ deltaX = step * (this.isLTR ? 10 : -10);
180
+ break;
181
+ default:
182
+ break;
183
+ }
184
+ });
185
+ if (deltaX != 0) {
186
+ this.activeAxis = "x";
187
+ this.inputX.focus();
188
+ } else if (deltaY != 0) {
189
+ this.activeAxis = "y";
190
+ this.inputY.focus();
191
+ }
192
+ this.x = Math.min(1, Math.max(this.x + deltaX, 0));
193
+ this.y = Math.min(1, Math.max(this.y + deltaY, 0));
194
+ this.colorController.savePreviousColor();
195
+ this.colorController.applyColorFromState();
196
+ if (deltaX != 0 || deltaY != 0) {
197
+ this._valueChanged = true;
198
+ this.dispatchEvent(
199
+ new Event("input", {
200
+ bubbles: true,
201
+ composed: true
202
+ })
203
+ );
204
+ const applyDefault = this.dispatchEvent(
205
+ new Event("change", {
206
+ bubbles: true,
207
+ composed: true,
208
+ cancelable: true
209
+ })
210
+ );
211
+ if (!applyDefault) {
212
+ this.colorController.restorePreviousColor();
213
+ }
214
+ }
215
+ }
216
+ handleKeyup(event) {
217
+ event.preventDefault();
218
+ const { code } = event;
219
+ this.activeKeys.delete(code);
220
+ }
221
+ handleInput(event) {
222
+ const { valueAsNumber, name } = event.target;
223
+ this[name] = valueAsNumber;
224
+ this.colorController.applyColorFromState();
225
+ }
226
+ handleChange(event) {
227
+ this.handleInput(event);
228
+ this.dispatchEvent(
229
+ new Event("change", {
230
+ bubbles: true,
231
+ composed: true,
232
+ cancelable: true
233
+ })
234
+ );
235
+ }
236
+ handlePointerdown(event) {
237
+ if (event.button !== 0) {
238
+ event.preventDefault();
239
+ return;
240
+ }
241
+ this._pointerDown = true;
242
+ this.colorController.savePreviousColor();
243
+ this.boundingClientRect = this.getBoundingClientRect();
244
+ event.target.setPointerCapture(event.pointerId);
245
+ if (event.pointerType === "mouse") {
246
+ this.focused = true;
247
+ }
248
+ }
249
+ handlePointermove(event) {
250
+ const [x, y] = this.calculateHandlePosition(event);
251
+ this._valueChanged = false;
252
+ this.x = x;
253
+ this.y = 1 - y;
254
+ this.colorController.applyColorFromState();
255
+ this.dispatchEvent(
256
+ new Event("input", {
257
+ bubbles: true,
258
+ composed: true,
259
+ cancelable: true
260
+ })
261
+ );
262
+ }
263
+ handlePointerup(event) {
264
+ event.preventDefault();
265
+ this._pointerDown = false;
266
+ event.target.releasePointerCapture(event.pointerId);
267
+ const applyDefault = this.dispatchEvent(
268
+ new Event("change", {
269
+ bubbles: true,
270
+ composed: true,
271
+ cancelable: true
272
+ })
273
+ );
274
+ this.inputX.focus();
275
+ if (event.pointerType === "mouse") {
276
+ this.focused = false;
277
+ }
278
+ if (!applyDefault) {
279
+ this.colorController.restorePreviousColor();
280
+ }
281
+ }
282
+ /**
283
+ * Returns the value under the cursor
284
+ * @param: PointerEvent on slider
285
+ * @return: Slider value that correlates to the position under the pointer
286
+ */
287
+ calculateHandlePosition(event) {
288
+ if (!this.boundingClientRect) {
289
+ return [this.x, this.y];
290
+ }
291
+ const rect = this.boundingClientRect;
292
+ const minOffsetX = rect.left;
293
+ const minOffsetY = rect.top;
294
+ const offsetX = event.clientX;
295
+ const offsetY = event.clientY;
296
+ const width = rect.width;
297
+ const height = rect.height;
298
+ const percentX = Math.max(
299
+ 0,
300
+ Math.min(1, (offsetX - minOffsetX) / width)
301
+ );
302
+ const percentY = Math.max(
303
+ 0,
304
+ Math.min(1, (offsetY - minOffsetY) / height)
305
+ );
306
+ return [this.isLTR ? percentX : 1 - percentX, percentY];
307
+ }
308
+ handleAreaPointerdown(event) {
309
+ if (event.button !== 0) {
310
+ return;
311
+ }
312
+ event.stopPropagation();
313
+ event.preventDefault();
314
+ this.handle.dispatchEvent(new PointerEvent("pointerdown", event));
315
+ this.handlePointermove(event);
316
+ }
317
+ render() {
318
+ const { width = 0, height = 0 } = this.boundingClientRect || {};
319
+ const isMobile = isAndroid() || isIOS();
320
+ const defaultAriaLabel = "Color Picker";
321
+ const ariaLabel = defaultAriaLabel;
322
+ const ariaRoleDescription = ifDefined(
323
+ isMobile ? void 0 : "2d slider"
324
+ );
325
+ const ariaLabelX = this.labelX;
326
+ const ariaLabelY = this.labelY;
327
+ const ariaValueX = new Intl.NumberFormat(
328
+ this.languageResolver.language,
329
+ {
330
+ style: "percent",
331
+ unitDisplay: "narrow"
332
+ }
333
+ ).format(this.x);
334
+ const ariaValueY = new Intl.NumberFormat(
335
+ this.languageResolver.language,
336
+ {
337
+ style: "percent",
338
+ unitDisplay: "narrow"
339
+ }
340
+ ).format(this.y);
341
+ const style = {
342
+ background: `linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);`
343
+ };
344
+ return html`
345
+ <div
346
+ @pointerdown=${this.handleAreaPointerdown}
347
+ class="gradient"
348
+ style=${styleMap(style)}
349
+ >
350
+ <slot name="gradient"></slot>
351
+ </div>
352
+
353
+ <sp-color-handle
354
+ tabindex=${ifDefined(this.focused ? void 0 : "0")}
355
+ @focus=${this.forwardFocus}
356
+ ?focused=${this.focused}
357
+ class="handle"
358
+ color=${this.colorController.getHslString()}
359
+ ?disabled=${this.disabled}
360
+ style=${`transform: translate(${(this.isLTR ? this.x : 1 - this.x) * width}px, ${height - this.y * height}px);`}
361
+ ${streamingListener({
362
+ start: ["pointerdown", this.handlePointerdown],
363
+ streamInside: ["pointermove", this.handlePointermove],
364
+ end: [
365
+ ["pointerup", "pointercancel", "pointerleave"],
366
+ this.handlePointerup
367
+ ]
368
+ })}
369
+ ></sp-color-handle>
370
+
371
+ <fieldset
372
+ class="fieldset"
373
+ aria-label=${ifDefined(isMobile ? ariaLabel : void 0)}
374
+ >
375
+ <div role="presentation">
376
+ <input
377
+ type="range"
378
+ class="slider"
379
+ name="x"
380
+ aria-label=${isMobile ? ariaLabelX : `${ariaLabelX} ${ariaLabel}`}
381
+ aria-roledescription=${ariaRoleDescription}
382
+ aria-orientation="horizontal"
383
+ aria-valuetext=${isMobile ? ariaValueX : `${ariaValueX}, ${ariaLabelX}${this._valueChanged ? "" : `, ${ariaValueY}, ${ariaLabelY}`}`}
384
+ min="0"
385
+ max="1"
386
+ step=${this.step}
387
+ tabindex="-1"
388
+ .value=${String(this.x)}
389
+ @input=${this.handleInput}
390
+ @change=${this.handleChange}
391
+ />
392
+ </div>
393
+ <div role="presentation">
394
+ <input
395
+ type="range"
396
+ class="slider"
397
+ name="y"
398
+ aria-label=${isMobile ? ariaLabelY : `${ariaLabelY} ${ariaLabel}`}
399
+ aria-roledescription=${ariaRoleDescription}
400
+ aria-orientation="vertical"
401
+ aria-valuetext=${isMobile ? ariaValueY : `${ariaValueY}, ${ariaLabelY}${this._valueChanged ? "" : `, ${ariaValueX}, ${ariaLabelX}`}`}
402
+ orient="vertical"
403
+ min="0"
404
+ max="1"
405
+ step=${this.step}
406
+ tabindex="-1"
407
+ .value=${String(this.y)}
408
+ @input=${this.handleInput}
409
+ @change=${this.handleChange}
410
+ />
411
+ </div>
412
+ </fieldset>
413
+ `;
414
+ }
415
+ firstUpdated(changed) {
416
+ super.firstUpdated(changed);
417
+ this.boundingClientRect = this.getBoundingClientRect();
418
+ this.addEventListener("focus", this.handleFocus);
419
+ this.addEventListener("blur", this.handleBlur);
420
+ this.addEventListener("keyup", this.handleKeyup);
421
+ this.addEventListener("keydown", this.handleKeydown);
422
+ }
423
+ updated(changed) {
424
+ super.updated(changed);
425
+ if (this.x !== this.inputX.valueAsNumber) {
426
+ this._x = this.inputX.valueAsNumber;
427
+ }
428
+ if (this.y !== this.inputY.valueAsNumber) {
429
+ this._y = this.inputY.valueAsNumber;
430
+ }
431
+ if (changed.has("focused") && this.focused) {
432
+ const parentX = this.inputX.parentElement;
433
+ const parentY = this.inputY.parentElement;
434
+ if (!parentX.shadowRoot && !parentY.shadowRoot) {
435
+ parentX.attachShadow({ mode: "open" });
436
+ parentY.attachShadow({ mode: "open" });
437
+ const slot = '<div tabindex="-1"><slot></slot></div>';
438
+ parentX.shadowRoot.innerHTML = slot;
439
+ parentY.shadowRoot.innerHTML = slot;
440
+ }
441
+ }
442
+ }
443
+ connectedCallback() {
444
+ var _a;
445
+ super.connectedCallback();
446
+ if (!this.observer && window.ResizeObserver) {
447
+ this.observer = new window.ResizeObserver((entries) => {
448
+ for (const entry of entries) {
449
+ this.boundingClientRect = entry.contentRect;
450
+ }
451
+ this.requestUpdate();
452
+ });
453
+ }
454
+ (_a = this.observer) == null ? void 0 : _a.observe(this);
455
+ }
456
+ disconnectedCallback() {
457
+ var _a;
458
+ (_a = this.observer) == null ? void 0 : _a.unobserve(this);
459
+ super.disconnectedCallback();
460
+ }
461
+ }
462
+ __decorateClass([
463
+ property({ type: String, reflect: true })
464
+ ], ColorArea.prototype, "dir", 2);
465
+ __decorateClass([
466
+ property({ type: Boolean, reflect: true })
467
+ ], ColorArea.prototype, "disabled", 2);
468
+ __decorateClass([
469
+ property({ type: Boolean, reflect: true })
470
+ ], ColorArea.prototype, "focused", 2);
471
+ __decorateClass([
472
+ property({ type: String, attribute: "label-x" })
473
+ ], ColorArea.prototype, "labelX", 2);
474
+ __decorateClass([
475
+ property({ type: String, attribute: "label-y" })
476
+ ], ColorArea.prototype, "labelY", 2);
477
+ __decorateClass([
478
+ query(".handle")
479
+ ], ColorArea.prototype, "handle", 2);
480
+ __decorateClass([
481
+ property({ type: Number })
482
+ ], ColorArea.prototype, "hue", 1);
483
+ __decorateClass([
484
+ property({ type: String })
485
+ ], ColorArea.prototype, "value", 1);
486
+ __decorateClass([
487
+ property({ type: String })
488
+ ], ColorArea.prototype, "color", 1);
489
+ __decorateClass([
490
+ property({ attribute: false })
491
+ ], ColorArea.prototype, "activeAxis", 2);
492
+ __decorateClass([
493
+ property({ type: Number })
494
+ ], ColorArea.prototype, "x", 1);
495
+ __decorateClass([
496
+ property({ type: Number })
497
+ ], ColorArea.prototype, "y", 1);
498
+ __decorateClass([
499
+ property({ type: Number })
500
+ ], ColorArea.prototype, "step", 2);
501
+ __decorateClass([
502
+ query('[name="x"]')
503
+ ], ColorArea.prototype, "inputX", 2);
504
+ __decorateClass([
505
+ query('[name="y"]')
506
+ ], ColorArea.prototype, "inputY", 2);
507
+ //# sourceMappingURL=ColorArea.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["ColorArea.ts"],
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*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n ifDefined,\n styleMap,\n} from '@spectrum-web-components/base/src/directives.js';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { streamingListener } from '@spectrum-web-components/base/src/streaming-listener.js';\nimport { SWCResizeObserverEntry, WithSWCResizeObserver } from './types';\nimport type { ColorHandle } from '@spectrum-web-components/color-handle';\nimport '@spectrum-web-components/color-handle/sp-color-handle.js';\nimport {\n ColorController,\n ColorValue,\n} from '@spectrum-web-components/reactive-controllers/src/Color.js';\nimport { LanguageResolutionController } from '@spectrum-web-components/reactive-controllers/src/LanguageResolution.js';\nimport {\n isAndroid,\n isIOS,\n} from '@spectrum-web-components/shared/src/platform.js';\n\nimport styles from './color-area.css.js';\n\n/**\n * @element sp-color-area\n * @slot gradient - a custom gradient visually outlining the available color values\n * @fires input - The value of the Color Area has changed.\n * @fires change - An alteration to the value of the Color Area has been committed by the user.\n */\nexport class ColorArea extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String, reflect: true })\n public override dir!: 'ltr' | 'rtl';\n\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @property({ type: String, attribute: 'label-x' })\n public labelX = 'saturation';\n\n @property({ type: String, attribute: 'label-y' })\n public labelY = 'luminosity';\n\n @query('.handle')\n private handle!: ColorHandle;\n\n private languageResolver = new LanguageResolutionController(this);\n\n private colorController = new ColorController(this, {\n extractColorFromState: () => ({\n h: this.hue,\n s: this.x,\n v: this.y,\n }),\n applyColorToState: ({ s, v }) => {\n this._x = s;\n this._y = v;\n this.requestUpdate();\n },\n });\n\n @property({ type: Number })\n public get hue(): number {\n return this.colorController.hue;\n }\n\n public set hue(value: number) {\n this.colorController.hue = value;\n }\n\n @property({ type: String })\n public get value(): ColorValue {\n return this.colorController.color;\n }\n\n @property({ type: String })\n public get color(): ColorValue {\n return this.colorController.color;\n }\n\n public set color(color: ColorValue) {\n this.colorController.color = color;\n }\n\n @property({ attribute: false })\n private activeAxis = 'x';\n\n @property({ type: Number })\n public get x(): number {\n return this._x;\n }\n\n public set x(x: number) {\n if (x === this.x) {\n return;\n }\n const oldValue = this.x;\n this._x = x;\n if (this.inputX) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputX.value = x.toString();\n this._x = this.inputX.valueAsNumber;\n }\n this.requestUpdate('x', oldValue);\n this.colorController.applyColorFromState();\n }\n\n private _x = 1;\n\n @property({ type: Number })\n public get y(): number {\n return this._y;\n }\n\n public set y(y: number) {\n if (y === this.y) {\n return;\n }\n const oldValue = this.y;\n this._y = y;\n if (this.inputY) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputY.value = y.toString();\n this._y = this.inputY.valueAsNumber;\n }\n this.requestUpdate('y', oldValue);\n this.colorController.applyColorFromState();\n }\n\n private _y = 1;\n\n @property({ type: Number })\n public step = 0.01;\n\n @query('[name=\"x\"]')\n public inputX!: HTMLInputElement;\n\n @query('[name=\"y\"]')\n public inputY!: HTMLInputElement;\n\n private altered = 0;\n\n private activeKeys = new Set();\n\n private _valueChanged = false;\n\n public override focus(focusOptions: FocusOptions = {}): void {\n super.focus(focusOptions);\n this.forwardFocus();\n }\n\n private forwardFocus(): void {\n this.focused = this.hasVisibleFocusInTree();\n if (this.activeAxis === 'x') {\n this.inputX.focus();\n } else {\n this.inputY.focus();\n }\n }\n\n private handleFocus(): void {\n this.focused = true;\n this._valueChanged = false;\n }\n\n public handleBlur(): void {\n if (this._pointerDown) {\n return;\n }\n this.altered = 0;\n this.focused = false;\n this._valueChanged = false;\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n this.focused = true;\n this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(\n (key) => !!key\n ).length;\n const isArrowKey =\n code.search('Arrow') === 0 ||\n code.search('Page') === 0 ||\n code.search('Home') === 0 ||\n code.search('End') === 0;\n if (isArrowKey) {\n event.preventDefault();\n this.activeKeys.add(code);\n this.handleKeypress();\n }\n }\n\n private handleKeypress(): void {\n let deltaX = 0;\n let deltaY = 0;\n const step = Math.max(this.step, this.altered * 5 * this.step);\n this.activeKeys.forEach((code) => {\n switch (code) {\n case 'ArrowUp':\n deltaY = step;\n break;\n case 'ArrowDown':\n deltaY = step * -1;\n break;\n case 'ArrowLeft':\n deltaX = this.step * (this.isLTR ? -1 : 1);\n break;\n case 'ArrowRight':\n deltaX = this.step * (this.isLTR ? 1 : -1);\n break;\n case 'PageUp':\n deltaY = step * 10;\n break;\n case 'PageDown':\n deltaY = step * -10;\n break;\n case 'Home':\n deltaX = step * (this.isLTR ? -10 : 10);\n break;\n case 'End':\n deltaX = step * (this.isLTR ? 10 : -10);\n break;\n /* c8 ignore next 2 */\n default:\n break;\n }\n });\n if (deltaX != 0) {\n this.activeAxis = 'x';\n this.inputX.focus();\n } else if (deltaY != 0) {\n this.activeAxis = 'y';\n this.inputY.focus();\n }\n this.x = Math.min(1, Math.max(this.x + deltaX, 0));\n this.y = Math.min(1, Math.max(this.y + deltaY, 0));\n\n this.colorController.savePreviousColor();\n this.colorController.applyColorFromState();\n\n if (deltaX != 0 || deltaY != 0) {\n this._valueChanged = true;\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n })\n );\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.colorController.restorePreviousColor();\n }\n }\n }\n\n private handleKeyup(event: KeyboardEvent): void {\n event.preventDefault();\n const { code } = event;\n this.activeKeys.delete(code);\n }\n\n private handleInput(event: Event & { target: HTMLInputElement }): void {\n const { valueAsNumber, name } = event.target;\n\n this[name as 'x' | 'y'] = valueAsNumber;\n this.colorController.applyColorFromState();\n }\n\n private handleChange(event: Event & { target: HTMLInputElement }): void {\n this.handleInput(event);\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private boundingClientRect!: DOMRect;\n public _pointerDown = false;\n\n private handlePointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n event.preventDefault();\n return;\n }\n this._pointerDown = true;\n this.colorController.savePreviousColor();\n this.boundingClientRect = this.getBoundingClientRect();\n (event.target as HTMLElement).setPointerCapture(event.pointerId);\n if (event.pointerType === 'mouse') {\n this.focused = true;\n }\n }\n\n private handlePointermove(event: PointerEvent): void {\n const [x, y] = this.calculateHandlePosition(event);\n\n this._valueChanged = false;\n\n this.x = x;\n this.y = 1 - y;\n this.colorController.applyColorFromState();\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private handlePointerup(event: PointerEvent): void {\n event.preventDefault();\n this._pointerDown = false;\n (event.target as HTMLElement).releasePointerCapture(event.pointerId);\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n this.inputX.focus();\n if (event.pointerType === 'mouse') {\n this.focused = false;\n }\n if (!applyDefault) {\n this.colorController.restorePreviousColor();\n }\n }\n\n /**\n * Returns the value under the cursor\n * @param: PointerEvent on slider\n * @return: Slider value that correlates to the position under the pointer\n */\n private calculateHandlePosition(event: PointerEvent): [number, number] {\n /* c8 ignore next 3 */\n if (!this.boundingClientRect) {\n return [this.x, this.y];\n }\n const rect = this.boundingClientRect;\n const minOffsetX = rect.left;\n const minOffsetY = rect.top;\n const offsetX = event.clientX;\n const offsetY = event.clientY;\n const width = rect.width;\n const height = rect.height;\n\n const percentX = Math.max(\n 0,\n Math.min(1, (offsetX - minOffsetX) / width)\n );\n const percentY = Math.max(\n 0,\n Math.min(1, (offsetY - minOffsetY) / height)\n );\n\n return [this.isLTR ? percentX : 1 - percentX, percentY];\n }\n\n private handleAreaPointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n return;\n }\n event.stopPropagation();\n event.preventDefault();\n this.handle.dispatchEvent(new PointerEvent('pointerdown', event));\n this.handlePointermove(event);\n }\n\n protected override render(): TemplateResult {\n const { width = 0, height = 0 } = this.boundingClientRect || {};\n\n const isMobile = isAndroid() || isIOS();\n const defaultAriaLabel = 'Color Picker';\n const ariaLabel = defaultAriaLabel;\n const ariaRoleDescription = ifDefined(\n isMobile ? undefined : '2d slider'\n );\n\n const ariaLabelX = this.labelX;\n const ariaLabelY = this.labelY;\n const ariaValueX = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.x);\n const ariaValueY = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.y);\n\n const style = {\n background: `linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);`,\n };\n\n return html`\n <div\n @pointerdown=${this.handleAreaPointerdown}\n class=\"gradient\"\n style=${styleMap(style)}\n >\n <slot name=\"gradient\"></slot>\n </div>\n\n <sp-color-handle\n tabindex=${ifDefined(this.focused ? undefined : '0')}\n @focus=${this.forwardFocus}\n ?focused=${this.focused}\n class=\"handle\"\n color=${this.colorController.getHslString()}\n ?disabled=${this.disabled}\n style=${`transform: translate(${\n (this.isLTR ? this.x : 1 - this.x) * width\n }px, ${height - this.y * height}px);`}\n ${streamingListener({\n start: ['pointerdown', this.handlePointerdown],\n streamInside: ['pointermove', this.handlePointermove],\n end: [\n ['pointerup', 'pointercancel', 'pointerleave'],\n this.handlePointerup,\n ],\n })}\n ></sp-color-handle>\n\n <fieldset\n class=\"fieldset\"\n aria-label=${ifDefined(isMobile ? ariaLabel : undefined)}\n >\n <div role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"x\"\n aria-label=${isMobile\n ? ariaLabelX\n : `${ariaLabelX} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"horizontal\"\n aria-valuetext=${isMobile\n ? ariaValueX\n : `${ariaValueX}, ${ariaLabelX}${\n this._valueChanged\n ? ''\n : `, ${ariaValueY}, ${ariaLabelY}`\n }`}\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.x)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n <div role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"y\"\n aria-label=${isMobile\n ? ariaLabelY\n : `${ariaLabelY} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"vertical\"\n aria-valuetext=${isMobile\n ? ariaValueY\n : `${ariaValueY}, ${ariaLabelY}${\n this._valueChanged\n ? ''\n : `, ${ariaValueX}, ${ariaLabelX}`\n }`}\n orient=\"vertical\"\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.y)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n </fieldset>\n `;\n }\n\n protected override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n this.boundingClientRect = this.getBoundingClientRect();\n\n this.addEventListener('focus', this.handleFocus);\n this.addEventListener('blur', this.handleBlur);\n this.addEventListener('keyup', this.handleKeyup);\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (this.x !== this.inputX.valueAsNumber) {\n this._x = this.inputX.valueAsNumber;\n }\n if (this.y !== this.inputY.valueAsNumber) {\n this._y = this.inputY.valueAsNumber;\n }\n if (changed.has('focused') && this.focused) {\n // Lazily bind the `input[type=\"range\"]` elements in shadow roots\n // so that browsers with certain settings (Webkit) aren't allowed\n // multiple tab stops within the Color Area.\n const parentX = this.inputX.parentElement as HTMLDivElement;\n const parentY = this.inputY.parentElement as HTMLDivElement;\n if (!parentX.shadowRoot && !parentY.shadowRoot) {\n parentX.attachShadow({ mode: 'open' });\n parentY.attachShadow({ mode: 'open' });\n const slot = '<div tabindex=\"-1\"><slot></slot></div>';\n (parentX.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n (parentY.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n }\n }\n }\n\n private observer?: WithSWCResizeObserver['ResizeObserver'];\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (\n !this.observer &&\n (window as unknown as WithSWCResizeObserver).ResizeObserver\n ) {\n this.observer = new (\n window as unknown as WithSWCResizeObserver\n ).ResizeObserver((entries: SWCResizeObserverEntry[]) => {\n for (const entry of entries) {\n this.boundingClientRect = entry.contentRect;\n }\n this.requestUpdate();\n });\n }\n this.observer?.observe(this);\n }\n\n public override disconnectedCallback(): void {\n this.observer?.unobserve(this);\n super.disconnectedCallback();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EAEA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,yBAAyB;AAGlC,OAAO;AACP;AAAA,EACI;AAAA,OAEG;AACP,SAAS,oCAAoC;AAC7C;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,OAAO,YAAY;AAQZ,aAAM,kBAAkB,gBAAgB;AAAA,EAAxC;AAAA;AASH,SAAO,WAAW;AAGlB,SAAO,UAAU;AAGjB,SAAO,SAAS;AAGhB,SAAO,SAAS;AAKhB,SAAQ,mBAAmB,IAAI,6BAA6B,IAAI;AAEhE,SAAQ,kBAAkB,IAAI,gBAAgB,MAAM;AAAA,MAChD,uBAAuB,OAAO;AAAA,QAC1B,GAAG,KAAK;AAAA,QACR,GAAG,KAAK;AAAA,QACR,GAAG,KAAK;AAAA,MACZ;AAAA,MACA,mBAAmB,CAAC,EAAE,GAAG,EAAE,MAAM;AAC7B,aAAK,KAAK;AACV,aAAK,KAAK;AACV,aAAK,cAAc;AAAA,MACvB;AAAA,IACJ,CAAC;AA0BD,SAAQ,aAAa;AAsBrB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,MAAM,CAAC;AAAA,GA7DrB,UA8DD;AAGG;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAhEjB,UAiEE;AAsBA;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAtFjB,UAuFE;AAsBJ;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GA5GjB,UA6GF;AAGA;AAAA,EADN,MAAM,YAAY;AAAA,GA/GV,UAgHF;AAGA;AAAA,EADN,MAAM,YAAY;AAAA,GAlHV,UAmHF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var s=(c,u,e,t)=>{for(var i=t>1?void 0:t?y(u,e):u,r=c.length-1,n;r>=0;r--)(n=c[r])&&(i=(t?n(u,e,i):n(i))||i);return t&&i&&m(u,e,i),i};import{html as g,SpectrumElement as w}from"@spectrum-web-components/base";import{ifDefined as b,styleMap as C}from"@spectrum-web-components/base/src/directives.js";import{property as o,query as v}from"@spectrum-web-components/base/src/decorators.js";import{streamingListener as x}from"@spectrum-web-components/base/src/streaming-listener.js";import"@spectrum-web-components/color-handle/sp-color-handle.js";import{ColorController as $}from"@spectrum-web-components/reactive-controllers/src/Color.js";import{LanguageResolutionController as R}from"@spectrum-web-components/reactive-controllers/src/LanguageResolution.js";import{isAndroid as E,isIOS as S}from"@spectrum-web-components/shared/src/platform.js";import P from"./color-area.css.js";export class ColorArea extends w{constructor(){super(...arguments);this.disabled=!1;this.focused=!1;this.labelX="saturation";this.labelY="luminosity";this.languageResolver=new R(this);this.colorController=new $(this,{extractColorFromState:()=>({h:this.hue,s:this.x,v:this.y}),applyColorToState:({s:e,v:t})=>{this._x=e,this._y=t,this.requestUpdate()}});this.activeAxis="x";this._x=1;this._y=1;this.step=.01;this.altered=0;this.activeKeys=new Set;this._valueChanged=!1;this._pointerDown=!1}static get styles(){return[P]}get hue(){return this.colorController.hue}set hue(e){this.colorController.hue=e}get value(){return this.colorController.color}get color(){return this.colorController.color}set color(e){this.colorController.color=e}get x(){return this._x}set x(e){if(e===this.x)return;const t=this.x;this._x=e,this.inputX&&(this.inputX.value=e.toString(),this._x=this.inputX.valueAsNumber),this.requestUpdate("x",t),this.colorController.applyColorFromState()}get y(){return this._y}set y(e){if(e===this.y)return;const t=this.y;this._y=e,this.inputY&&(this.inputY.value=e.toString(),this._y=this.inputY.valueAsNumber),this.requestUpdate("y",t),this.colorController.applyColorFromState()}focus(e={}){super.focus(e),this.forwardFocus()}forwardFocus(){this.focused=this.hasVisibleFocusInTree(),this.activeAxis==="x"?this.inputX.focus():this.inputY.focus()}handleFocus(){this.focused=!0,this._valueChanged=!1}handleBlur(){this._pointerDown||(this.altered=0,this.focused=!1,this._valueChanged=!1)}handleKeydown(e){const{code:t}=e;this.focused=!0,this.altered=[e.shiftKey,e.ctrlKey,e.altKey].filter(r=>!!r).length,(t.search("Arrow")===0||t.search("Page")===0||t.search("Home")===0||t.search("End")===0)&&(e.preventDefault(),this.activeKeys.add(t),this.handleKeypress())}handleKeypress(){let e=0,t=0;const i=Math.max(this.step,this.altered*5*this.step);this.activeKeys.forEach(r=>{switch(r){case"ArrowUp":t=i;break;case"ArrowDown":t=i*-1;break;case"ArrowLeft":e=this.step*(this.isLTR?-1:1);break;case"ArrowRight":e=this.step*(this.isLTR?1:-1);break;case"PageUp":t=i*10;break;case"PageDown":t=i*-10;break;case"Home":e=i*(this.isLTR?-10:10);break;case"End":e=i*(this.isLTR?10:-10);break;default:break}}),e!=0?(this.activeAxis="x",this.inputX.focus()):t!=0&&(this.activeAxis="y",this.inputY.focus()),this.x=Math.min(1,Math.max(this.x+e,0)),this.y=Math.min(1,Math.max(this.y+t,0)),this.colorController.savePreviousColor(),this.colorController.applyColorFromState(),(e!=0||t!=0)&&(this._valueChanged=!0,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}))||this.colorController.restorePreviousColor())}handleKeyup(e){e.preventDefault();const{code:t}=e;this.activeKeys.delete(t)}handleInput(e){const{valueAsNumber:t,name:i}=e.target;this[i]=t,this.colorController.applyColorFromState()}handleChange(e){this.handleInput(e),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}))}handlePointerdown(e){if(e.button!==0){e.preventDefault();return}this._pointerDown=!0,this.colorController.savePreviousColor(),this.boundingClientRect=this.getBoundingClientRect(),e.target.setPointerCapture(e.pointerId),e.pointerType==="mouse"&&(this.focused=!0)}handlePointermove(e){const[t,i]=this.calculateHandlePosition(e);this._valueChanged=!1,this.x=t,this.y=1-i,this.colorController.applyColorFromState(),this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0,cancelable:!0}))}handlePointerup(e){e.preventDefault(),this._pointerDown=!1,e.target.releasePointerCapture(e.pointerId);const t=this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}));this.inputX.focus(),e.pointerType==="mouse"&&(this.focused=!1),t||this.colorController.restorePreviousColor()}calculateHandlePosition(e){if(!this.boundingClientRect)return[this.x,this.y];const t=this.boundingClientRect,i=t.left,r=t.top,n=e.clientX,d=e.clientY,a=t.width,l=t.height,h=Math.max(0,Math.min(1,(n-i)/a)),p=Math.max(0,Math.min(1,(d-r)/l));return[this.isLTR?h:1-h,p]}handleAreaPointerdown(e){e.button===0&&(e.stopPropagation(),e.preventDefault(),this.handle.dispatchEvent(new PointerEvent("pointerdown",e)),this.handlePointermove(e))}render(){const{width:e=0,height:t=0}=this.boundingClientRect||{},i=E()||S(),n="Color Picker",d=b(i?void 0:"2d slider"),a=this.labelX,l=this.labelY,h=new Intl.NumberFormat(this.languageResolver.language,{style:"percent",unitDisplay:"narrow"}).format(this.x),p=new Intl.NumberFormat(this.languageResolver.language,{style:"percent",unitDisplay:"narrow"}).format(this.y),f={background:`linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);`};return g`
2
+ <div
3
+ @pointerdown=${this.handleAreaPointerdown}
4
+ class="gradient"
5
+ style=${C(f)}
6
+ >
7
+ <slot name="gradient"></slot>
8
+ </div>
9
+
10
+ <sp-color-handle
11
+ tabindex=${b(this.focused?void 0:"0")}
12
+ @focus=${this.forwardFocus}
13
+ ?focused=${this.focused}
14
+ class="handle"
15
+ color=${this.colorController.getHslString()}
16
+ ?disabled=${this.disabled}
17
+ style=${`transform: translate(${(this.isLTR?this.x:1-this.x)*e}px, ${t-this.y*t}px);`}
18
+ ${x({start:["pointerdown",this.handlePointerdown],streamInside:["pointermove",this.handlePointermove],end:[["pointerup","pointercancel","pointerleave"],this.handlePointerup]})}
19
+ ></sp-color-handle>
20
+
21
+ <fieldset
22
+ class="fieldset"
23
+ aria-label=${b(i?n:void 0)}
24
+ >
25
+ <div role="presentation">
26
+ <input
27
+ type="range"
28
+ class="slider"
29
+ name="x"
30
+ aria-label=${i?a:`${a} ${n}`}
31
+ aria-roledescription=${d}
32
+ aria-orientation="horizontal"
33
+ aria-valuetext=${i?h:`${h}, ${a}${this._valueChanged?"":`, ${p}, ${l}`}`}
34
+ min="0"
35
+ max="1"
36
+ step=${this.step}
37
+ tabindex="-1"
38
+ .value=${String(this.x)}
39
+ @input=${this.handleInput}
40
+ @change=${this.handleChange}
41
+ />
42
+ </div>
43
+ <div role="presentation">
44
+ <input
45
+ type="range"
46
+ class="slider"
47
+ name="y"
48
+ aria-label=${i?l:`${l} ${n}`}
49
+ aria-roledescription=${d}
50
+ aria-orientation="vertical"
51
+ aria-valuetext=${i?p:`${p}, ${l}${this._valueChanged?"":`, ${h}, ${a}`}`}
52
+ orient="vertical"
53
+ min="0"
54
+ max="1"
55
+ step=${this.step}
56
+ tabindex="-1"
57
+ .value=${String(this.y)}
58
+ @input=${this.handleInput}
59
+ @change=${this.handleChange}
60
+ />
61
+ </div>
62
+ </fieldset>
63
+ `}firstUpdated(e){super.firstUpdated(e),this.boundingClientRect=this.getBoundingClientRect(),this.addEventListener("focus",this.handleFocus),this.addEventListener("blur",this.handleBlur),this.addEventListener("keyup",this.handleKeyup),this.addEventListener("keydown",this.handleKeydown)}updated(e){if(super.updated(e),this.x!==this.inputX.valueAsNumber&&(this._x=this.inputX.valueAsNumber),this.y!==this.inputY.valueAsNumber&&(this._y=this.inputY.valueAsNumber),e.has("focused")&&this.focused){const t=this.inputX.parentElement,i=this.inputY.parentElement;if(!t.shadowRoot&&!i.shadowRoot){t.attachShadow({mode:"open"}),i.attachShadow({mode:"open"});const r='<div tabindex="-1"><slot></slot></div>';t.shadowRoot.innerHTML=r,i.shadowRoot.innerHTML=r}}}connectedCallback(){var e;super.connectedCallback(),!this.observer&&window.ResizeObserver&&(this.observer=new window.ResizeObserver(t=>{for(const i of t)this.boundingClientRect=i.contentRect;this.requestUpdate()})),(e=this.observer)==null||e.observe(this)}disconnectedCallback(){var e;(e=this.observer)==null||e.unobserve(this),super.disconnectedCallback()}}s([o({type:String,reflect:!0})],ColorArea.prototype,"dir",2),s([o({type:Boolean,reflect:!0})],ColorArea.prototype,"disabled",2),s([o({type:Boolean,reflect:!0})],ColorArea.prototype,"focused",2),s([o({type:String,attribute:"label-x"})],ColorArea.prototype,"labelX",2),s([o({type:String,attribute:"label-y"})],ColorArea.prototype,"labelY",2),s([v(".handle")],ColorArea.prototype,"handle",2),s([o({type:Number})],ColorArea.prototype,"hue",1),s([o({type:String})],ColorArea.prototype,"value",1),s([o({type:String})],ColorArea.prototype,"color",1),s([o({attribute:!1})],ColorArea.prototype,"activeAxis",2),s([o({type:Number})],ColorArea.prototype,"x",1),s([o({type:Number})],ColorArea.prototype,"y",1),s([o({type:Number})],ColorArea.prototype,"step",2),s([v('[name="x"]')],ColorArea.prototype,"inputX",2),s([v('[name="y"]')],ColorArea.prototype,"inputY",2);
64
+ //# sourceMappingURL=ColorArea.js.map