@spectrum-web-components/color-area 1.0.0 → 1.0.1-color-testing
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 -8
- package/src/ColorArea.d.ts +44 -6
- package/src/ColorArea.dev.js +66 -32
- package/src/ColorArea.dev.js.map +2 -2
- package/src/ColorArea.js +7 -7
- package/src/ColorArea.js.map +3 -3
- package/stories/color-area.stories.js +12 -2
- package/stories/color-area.stories.js.map +2 -2
- package/test/color-area.test.js +28 -25
- package/test/color-area.test.js.map +2 -2
- package/custom-elements.json +0 -603
package/src/ColorArea.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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": "qNAYA,OAEI,QAAAA,EAEA,mBAAAC,MAEG,gCACP,OACI,aAAAC,EACA,YAAAC,MACG,kDACP,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,OAAS,qBAAAC,MAAyB,0DAGlC,MAAO,
|
|
6
|
-
"names": ["html", "SpectrumElement", "ifDefined", "styleMap", "property", "query", "streamingListener", "ColorController", "LanguageResolutionController", "isAndroid", "isIOS", "styles", "
|
|
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';\n\nimport {\n ColorController,\n ColorTypes,\n} from '@spectrum-web-components/reactive-controllers/src/ColorController.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 /**\n * A controller for managing color interactions within the ColorArea component.\n *\n * The `ColorController` is instantiated with the `manageAs` option set to `hsv`\n * because the ColorArea component is designed to manipulate the saturation (`s`)\n * and value (`v`) components of the HSV color model along the x and y axes,\n * respectively. In the HSV color model:\n *\n * - The `hue` (h) represents the color type and is typically controlled by a separate input.\n * - The `saturation` (s) represents the intensity of the color, ranging from 0% (gray) to 100% (full color).\n * - The `value` (v) represents the brightness of the color, ranging from 0% (black) to 100% (full brightness).\n *\n * In the ColorArea component:\n *\n * - The x-axis controls the saturation (`s`), allowing users to adjust the intensity of the color.\n * - The y-axis controls the value (`v`), allowing users to adjust the brightness of the color.\n *\n * By managing the color as `hsv`, the ColorController can efficiently handle the changes in saturation and value\n * as the user interacts with the ColorArea component.\n *\n * @private\n * @type {ColorController}\n * @memberof ColorArea\n *\n * @property {ColorArea} this - The instance of the ColorArea component.\n * @property {Object} options - Configuration options for the ColorController.\n * @property {string} options.manageAs - Specifies the color model to manage, in this case 'hsv'.\n */\n private colorController = new ColorController(this, { manageAs: 'hsv' });\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(): ColorTypes {\n return this.colorController.colorValue;\n }\n\n @property({ type: String })\n public get color(): ColorTypes {\n return this.colorController.colorValue;\n }\n\n public set color(color: ColorTypes) {\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.colorController.color.hsv.s / 100;\n }\n\n public set x(x: number) {\n if (x === this.x) {\n return;\n }\n const oldValue = this.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.colorController.color.set(\n 's',\n this.inputX.valueAsNumber * 100\n );\n } else {\n this.colorController.color.set('s', x * 100);\n }\n this.requestUpdate('x', oldValue);\n }\n\n @property({ type: Number })\n public get y(): number {\n return this.colorController.color.hsv.v / 100;\n }\n\n public set y(y: number) {\n if (y === this.y) {\n return;\n }\n const oldValue = this.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.colorController.color.set(\n 'v',\n this.inputY.valueAsNumber * 100\n );\n }\n this.requestUpdate('y', oldValue);\n }\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\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\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 }\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 = y;\n\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, 1 - 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 /**\n * Overrides the `updated` method to handle changes in property values.\n *\n * @param changed - A map of changed properties with their previous values.\n *\n * This method performs the following actions:\n * - Updates the saturation (`s`) of the color if `x` has changed.\n * - Updates the value (`v`) of the color if `y` has changed.\n * - If the `focused` property has changed and is now true, it lazily binds\n * the `input[type=\"range\"]` elements in shadow roots to prevent multiple\n * tab stops within the Color Area for certain browser settings (e.g., Webkit).\n */\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (this.x !== this.inputX.valueAsNumber) {\n this.colorController.color.set(\n 's',\n this.inputX.valueAsNumber * 100\n );\n }\n if (this.y !== this.inputY.valueAsNumber) {\n this.colorController.color.set(\n 'v',\n (1 - this.inputY.valueAsNumber) * 100\n );\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": "qNAYA,OAEI,QAAAA,EAEA,mBAAAC,MAEG,gCACP,OACI,aAAAC,EACA,YAAAC,MACG,kDACP,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,OAAS,qBAAAC,MAAyB,0DAGlC,MAAO,2DAEP,OACI,mBAAAC,MAEG,uEACP,OAAS,gCAAAC,MAAoC,0EAC7C,OACI,aAAAC,EACA,SAAAC,MACG,kDAEP,OAAOC,MAAY,sBAQZ,aAAM,kBAAkBV,CAAgB,CAAxC,kCASH,KAAO,SAAW,GAGlB,KAAO,QAAU,GAGjB,KAAO,OAAS,aAGhB,KAAO,OAAS,aAKhB,KAAQ,iBAAmB,IAAIO,EAA6B,IAAI,EA8BhE,KAAQ,gBAAkB,IAAID,EAAgB,KAAM,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E,qBASH+C,EAAA,CADP/C,EAAS,CAAE,UAAW,EAAM,CAAC,GA9ErB,UA+ED,0BAGG+C,EAAA,CADV/C,EAAS,CAAE,KAAM,MAAO,CAAC,GAjFjB,UAkFE,iBAuBA+C,EAAA,CADV/C,EAAS,CAAE,KAAM,MAAO,CAAC,GAxGjB,UAyGE,iBAqBJ+C,EAAA,CADN/C,EAAS,CAAE,KAAM,MAAO,CAAC,GA7HjB,UA8HF,oBAGA+C,EAAA,CADN9C,EAAM,YAAY,GAhIV,UAiIF,sBAGA8C,EAAA,CADN9C,EAAM,YAAY,GAnIV,UAoIF",
|
|
6
|
+
"names": ["html", "SpectrumElement", "ifDefined", "styleMap", "property", "query", "streamingListener", "ColorController", "LanguageResolutionController", "isAndroid", "isIOS", "styles", "value", "color", "x", "oldValue", "y", "focusOptions", "event", "code", "key", "deltaX", "deltaY", "step", "valueAsNumber", "name", "applyDefault", "rect", "minOffsetX", "minOffsetY", "offsetX", "offsetY", "width", "height", "percentX", "percentY", "isMobile", "ariaLabel", "ariaRoleDescription", "ariaLabelX", "ariaLabelY", "ariaValueX", "ariaValueY", "style", "changed", "parentX", "parentY", "slot", "_a", "entries", "entry", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -10,10 +10,10 @@ export default {
|
|
|
10
10
|
onChange: { action: "change" },
|
|
11
11
|
color: {
|
|
12
12
|
name: "color",
|
|
13
|
-
type: { name: "
|
|
13
|
+
type: { name: "ColorTypes", required: "true" },
|
|
14
14
|
description: "The color displayed by the ColorArea.",
|
|
15
15
|
table: {
|
|
16
|
-
type: { summary: "
|
|
16
|
+
type: { summary: "ColorTypes" },
|
|
17
17
|
defaultValue: { summary: "" }
|
|
18
18
|
},
|
|
19
19
|
control: "text"
|
|
@@ -23,6 +23,7 @@ export default {
|
|
|
23
23
|
export const Default = ({ onChange, onInput }) => {
|
|
24
24
|
return html`
|
|
25
25
|
<sp-color-area
|
|
26
|
+
color="#ff0000"
|
|
26
27
|
@input=${({ target }) => {
|
|
27
28
|
const next = target.nextElementSibling;
|
|
28
29
|
next.textContent = target.color;
|
|
@@ -36,6 +37,15 @@ export const Default = ({ onChange, onInput }) => {
|
|
|
36
37
|
<div style="color: #ff0000" aria-live="off">#ff0000</div>
|
|
37
38
|
`;
|
|
38
39
|
};
|
|
40
|
+
export const appliedValues = () => {
|
|
41
|
+
return html`
|
|
42
|
+
<sp-color-area
|
|
43
|
+
.color=${{ space: "hsv", coords: [250, 90, 80] }}
|
|
44
|
+
></sp-color-area>
|
|
45
|
+
<sp-color-area color="hsv(250, 90%, 80%)"></sp-color-area>
|
|
46
|
+
<sp-color-area hue="250" x="0.1" y="0.1"></sp-color-area>
|
|
47
|
+
`;
|
|
48
|
+
};
|
|
39
49
|
export const joint = () => {
|
|
40
50
|
return html`
|
|
41
51
|
<div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["color-area.stories.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 { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '@spectrum-web-components/color-slider/sp-color-slider.js';\nimport { ColorSlider } from '@spectrum-web-components/color-slider/src/ColorSlider';\nimport '@spectrum-web-components/color-area/sp-color-area.js';\nimport { ColorArea } from '@spectrum-web-components/color-area/src/ColorArea.js';\n\nexport default {\n title: 'Color/Area',\n component: 'sp-color-area',\n argTypes: {\n onInput: { action: 'input' },\n onChange: { action: 'change' },\n color: {\n name: 'color',\n type: { name: '
|
|
5
|
-
"mappings": ";AAYA,SAAS,YAA4B;AAErC,OAAO;AAEP,OAAO;AAGP,eAAe;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AAAA,EACX,UAAU;AAAA,IACN,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,UAAU,EAAE,QAAQ,SAAS;AAAA,IAC7B,OAAO;AAAA,MACH,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,cAAc,UAAU,OAAO;AAAA,MAC7C,aAAa;AAAA,MACb,OAAO;AAAA,QACH,MAAM,EAAE,SAAS,aAAa;AAAA,QAC9B,cAAc,EAAE,SAAS,GAAG;AAAA,MAChC;AAAA,MACA,SAAS;AAAA,IACb;AAAA,EACJ;AACJ;AAOO,aAAM,UAAU,CAAC,EAAE,UAAU,QAAQ,MAAiC;AACzE,SAAO;AAAA;AAAA,
|
|
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 { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '@spectrum-web-components/color-slider/sp-color-slider.js';\nimport { ColorSlider } from '@spectrum-web-components/color-slider/src/ColorSlider';\nimport '@spectrum-web-components/color-area/sp-color-area.js';\nimport { ColorArea } from '@spectrum-web-components/color-area/src/ColorArea.js';\n\nexport default {\n title: 'Color/Area',\n component: 'sp-color-area',\n argTypes: {\n onInput: { action: 'input' },\n onChange: { action: 'change' },\n color: {\n name: 'color',\n type: { name: 'ColorTypes', required: 'true' },\n description: 'The color displayed by the ColorArea.',\n table: {\n type: { summary: 'ColorTypes' },\n defaultValue: { summary: '' },\n },\n control: 'text',\n },\n },\n};\n\ntype StoryArgs = {\n onInput: (val: string) => void;\n onChange: (val: string) => void;\n};\n\nexport const Default = ({ onChange, onInput }: StoryArgs): TemplateResult => {\n return html`\n <sp-color-area\n color=\"#ff0000\"\n @input=${({ target }: Event & { target: ColorArea }) => {\n const next = target.nextElementSibling as HTMLElement;\n next.textContent = target.color as string;\n next.style.color = target.color as string;\n onInput(target.value as string);\n }}\n @change=${({ target }: Event & { target: ColorArea }) => {\n onChange(target.value as string);\n }}\n ></sp-color-area>\n <div style=\"color: #ff0000\" aria-live=\"off\">#ff0000</div>\n `;\n};\n\nexport const appliedValues = (): TemplateResult => {\n return html`\n <sp-color-area\n .color=${{ space: 'hsv', coords: [250, 90, 80] }}\n ></sp-color-area>\n <sp-color-area color=\"hsv(250, 90%, 80%)\"></sp-color-area>\n <sp-color-area hue=\"250\" x=\"0.1\" y=\"0.1\"></sp-color-area>\n `;\n};\n\nexport const joint = (): TemplateResult => {\n return html`\n <div>\n <sp-color-area\n color=\"hsv (120 0% 100%)\"\n @input=${({ target }: Event & { target: ColorArea }) => {\n const next = target.nextElementSibling as ColorSlider;\n const display = next.nextElementSibling as HTMLElement;\n display.textContent = target.color as string;\n display.style.color = target.color as string;\n next.color = target.color;\n }}\n ></sp-color-area>\n <sp-color-slider\n color=\"hsv(120 0% 1)\"\n @input=${({\n target: {\n color,\n previousElementSibling,\n nextElementSibling,\n },\n }: Event & {\n target: ColorSlider & {\n previousElementSibling: ColorArea;\n nextElementSibling: HTMLDivElement;\n };\n }): void => {\n previousElementSibling.color = color;\n nextElementSibling.textContent = color as string;\n nextElementSibling.style.color = color as string;\n }}\n ></sp-color-slider>\n <div style=\"color: hsv(120, 0, 1)\">hsv(120, 0, 1)</div>\n </div>\n `;\n};\n\nexport const disabled = (): TemplateResult => {\n return html`\n <sp-color-area disabled></sp-color-area>\n `;\n};\n\nexport const sized = (): TemplateResult => {\n return html`\n <sp-color-area style=\"width: 72px; height: 72px\"></sp-color-area>\n `;\n};\n\nexport const canvas = (): TemplateResult => {\n return html`\n <sp-color-area>\n <canvas slot=\"gradient\"></canvas>\n </sp-color-area>\n `;\n};\n\nclass CanvasWriter extends HTMLElement {\n writeToCanvas(): void {\n const { previousElementSibling } = this;\n if (previousElementSibling) {\n const canvas = previousElementSibling.querySelector(\n 'canvas[slot=\"gradient\"]'\n ) as HTMLCanvasElement;\n\n if (canvas) {\n canvas.width = canvas.offsetWidth;\n canvas.height = canvas.offsetHeight;\n const context = canvas.getContext('2d');\n if (context) {\n context.rect(0, 0, canvas.width, canvas.height);\n\n const gradB = context.createLinearGradient(\n 0,\n 0,\n 0,\n canvas.height\n );\n gradB.addColorStop(0, 'white');\n gradB.addColorStop(1, 'black');\n const gradC = context.createLinearGradient(\n 0,\n 0,\n canvas.width,\n 0\n );\n gradC.addColorStop(0, 'hsla(0,100%,50%,0)');\n gradC.addColorStop(1, 'hsla(0,100%,50%,1)');\n\n context.fillStyle = gradB;\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.fillStyle = gradC;\n context.globalCompositeOperation = 'multiply';\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.globalCompositeOperation = 'source-over';\n }\n }\n }\n }\n\n constructor() {\n super();\n this.writeStatePromise = new Promise((res) => {\n requestAnimationFrame(() => {\n this.writeToCanvas();\n res(true);\n });\n });\n }\n\n private writeStatePromise: Promise<boolean> = Promise.resolve(false);\n\n get updateComplete(): Promise<boolean> {\n return this.writeStatePromise;\n }\n}\n\ncustomElements.define('area-canvas-writer', CanvasWriter);\n\ncanvas.decorators = [\n (story: () => TemplateResult): TemplateResult => {\n return html`\n ${story()}\n <area-canvas-writer></area-canvas-writer>\n `;\n },\n];\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,YAA4B;AAErC,OAAO;AAEP,OAAO;AAGP,eAAe;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AAAA,EACX,UAAU;AAAA,IACN,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,UAAU,EAAE,QAAQ,SAAS;AAAA,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AO,MAAM;AAClD,kBAAQ,2BAA2B;AAAA,QACvC;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAAA,EAcA,IAAI,iBAAmC;AACnC,WAAO,KAAK;AAAA,EAChB;AACJ;AAEA,eAAe,OAAO,sBAAsB,YAAY;AAExD,OAAO,aAAa;AAAA,EAChB,CAAC,UAAgD;AAC7C,WAAO;AAAA,cACD,MAAM,CAAC;AAAA;AAAA;AAAA,EAGjB;AACJ;",
|
|
6
6
|
"names": ["canvas"]
|
|
7
7
|
}
|
package/test/color-area.test.js
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
nextFrame,
|
|
8
8
|
oneEvent
|
|
9
9
|
} from "@open-wc/testing";
|
|
10
|
-
import { TinyColor } from "@ctrl/tinycolor";
|
|
11
10
|
import "@spectrum-web-components/color-area/sp-color-area.js";
|
|
12
11
|
import { sendKeys } from "@web/test-runner-commands";
|
|
13
12
|
import { spy } from "sinon";
|
|
@@ -47,7 +46,7 @@ describe("ColorArea", () => {
|
|
|
47
46
|
await el.updateComplete;
|
|
48
47
|
expect(el.x).to.equal(0.3);
|
|
49
48
|
const handle = el.shadowRoot.querySelector(".handle");
|
|
50
|
-
expect(handle.color).to.equal("hsl(0
|
|
49
|
+
expect(handle.color).to.equal("hsl(0 100% 85%)");
|
|
51
50
|
});
|
|
52
51
|
it("updates color when y value changes", async () => {
|
|
53
52
|
const el = await fixture(html`
|
|
@@ -59,7 +58,7 @@ describe("ColorArea", () => {
|
|
|
59
58
|
await el.updateComplete;
|
|
60
59
|
expect(el.y).to.equal(0.5);
|
|
61
60
|
const handle = el.shadowRoot.querySelector(".handle");
|
|
62
|
-
expect(handle.color).to.equal("hsl(0
|
|
61
|
+
expect(handle.color).to.equal("hsl(0 100% 25%)");
|
|
63
62
|
});
|
|
64
63
|
it("manages a single tab stop", async () => {
|
|
65
64
|
const test = await fixture(html`
|
|
@@ -104,6 +103,10 @@ describe("ColorArea", () => {
|
|
|
104
103
|
await sendKeys({
|
|
105
104
|
press: "ArrowDown"
|
|
106
105
|
});
|
|
106
|
+
await sendKeys({
|
|
107
|
+
press: "ArrowDown"
|
|
108
|
+
});
|
|
109
|
+
await elementUpdated(el);
|
|
107
110
|
expect(el.value).to.not.equal(value);
|
|
108
111
|
await sendKeys({
|
|
109
112
|
press: "Shift+Tab"
|
|
@@ -158,10 +161,10 @@ describe("ColorArea", () => {
|
|
|
158
161
|
`);
|
|
159
162
|
await el.updateComplete;
|
|
160
163
|
const handle = el.shadowRoot.querySelector(".handle");
|
|
161
|
-
expect(handle.color).to.equal("hsl(0
|
|
164
|
+
expect(handle.color).to.equal("hsl(0 100% 50%)");
|
|
162
165
|
el.x = 0.3;
|
|
163
166
|
await el.updateComplete;
|
|
164
|
-
expect(handle.color).to.equal("hsl(0
|
|
167
|
+
expect(handle.color).to.equal("hsl(0 100% 85%)");
|
|
165
168
|
});
|
|
166
169
|
it("updates color when y value changes", async () => {
|
|
167
170
|
const el = await fixture(html`
|
|
@@ -169,10 +172,10 @@ describe("ColorArea", () => {
|
|
|
169
172
|
`);
|
|
170
173
|
await el.updateComplete;
|
|
171
174
|
const handle = el.shadowRoot.querySelector(".handle");
|
|
172
|
-
expect(handle.color).to.equal("hsl(0
|
|
175
|
+
expect(handle.color).to.equal("hsl(0 100% 50%)");
|
|
173
176
|
el.y = 0.7;
|
|
174
177
|
await el.updateComplete;
|
|
175
|
-
expect(handle.color).to.equal("hsl(0
|
|
178
|
+
expect(handle.color).to.equal("hsl(0 100% 35%)");
|
|
176
179
|
});
|
|
177
180
|
it("accepts `hue` values", async () => {
|
|
178
181
|
const el = await fixture(html`
|
|
@@ -180,10 +183,10 @@ describe("ColorArea", () => {
|
|
|
180
183
|
`);
|
|
181
184
|
await elementUpdated(el);
|
|
182
185
|
const { handle } = el;
|
|
183
|
-
expect(handle.color).to.equal("hsl(0
|
|
186
|
+
expect(handle.color).to.equal("hsl(0 100% 50%)");
|
|
184
187
|
el.hue = 125;
|
|
185
188
|
await elementUpdated(el);
|
|
186
|
-
expect(handle.color).to.equal("hsl(125
|
|
189
|
+
expect(handle.color).to.equal("hsl(125 100% 50%)");
|
|
187
190
|
});
|
|
188
191
|
it('accepts "color" values as hsl', async () => {
|
|
189
192
|
const el = await fixture(html`
|
|
@@ -355,7 +358,7 @@ describe("ColorArea", () => {
|
|
|
355
358
|
press: "ArrowUp"
|
|
356
359
|
});
|
|
357
360
|
await elementUpdated(el);
|
|
358
|
-
expect(el.color).to.equal("
|
|
361
|
+
expect(el.color).to.equal("hsla(100, 65%, 57%, 1)");
|
|
359
362
|
expect(el.x, "first").to.equal(0.67);
|
|
360
363
|
expect(el.y).to.equal(0.85);
|
|
361
364
|
await sendKeys({
|
|
@@ -366,7 +369,7 @@ describe("ColorArea", () => {
|
|
|
366
369
|
press: "ArrowRight"
|
|
367
370
|
});
|
|
368
371
|
await elementUpdated(el);
|
|
369
|
-
expect(el.color).to.equal("
|
|
372
|
+
expect(el.color).to.equal("hsla(100, 66%, 56%, 1)");
|
|
370
373
|
expect(el.x).to.equal(0.69);
|
|
371
374
|
expect(el.y).to.equal(0.85);
|
|
372
375
|
await sendKeys({
|
|
@@ -377,7 +380,7 @@ describe("ColorArea", () => {
|
|
|
377
380
|
press: "ArrowDown"
|
|
378
381
|
});
|
|
379
382
|
await elementUpdated(el);
|
|
380
|
-
expect(el.color).to.equal("
|
|
383
|
+
expect(el.color).to.equal("hsla(100, 53%, 49%, 1)");
|
|
381
384
|
expect(el.x).to.equal(0.69);
|
|
382
385
|
expect(el.y).to.equal(0.75);
|
|
383
386
|
await sendKeys({
|
|
@@ -392,7 +395,7 @@ describe("ColorArea", () => {
|
|
|
392
395
|
up: "Shift"
|
|
393
396
|
});
|
|
394
397
|
await elementUpdated(el);
|
|
395
|
-
expect(el.color).to.equal("
|
|
398
|
+
expect(el.color).to.equal("hsla(100, 50%, 50%, 1)");
|
|
396
399
|
expect(el.x, "last").to.equal(0.67);
|
|
397
400
|
expect(el.y).to.equal(0.75);
|
|
398
401
|
});
|
|
@@ -654,7 +657,7 @@ describe("ColorArea", () => {
|
|
|
654
657
|
`);
|
|
655
658
|
await elementUpdated(el);
|
|
656
659
|
let outputColor = el.color;
|
|
657
|
-
const variance =
|
|
660
|
+
const variance = 4e-3;
|
|
658
661
|
expect(el.hue).to.equal(100);
|
|
659
662
|
expect(el.x, "x").to.equal(0.67);
|
|
660
663
|
expect(el.y, "y").to.equal(0.75);
|
|
@@ -727,7 +730,7 @@ describe("ColorArea", () => {
|
|
|
727
730
|
{ name: "Hex8", color: "cc33ccff" },
|
|
728
731
|
{ name: "Hex8 String", color: "#cc33ccff" },
|
|
729
732
|
// name
|
|
730
|
-
{ name: "string", color: "red" },
|
|
733
|
+
{ name: "string", color: "red", test: "ff0000" },
|
|
731
734
|
// hsl
|
|
732
735
|
{ name: "HSL String", color: "hsl(300, 60%, 50%)" },
|
|
733
736
|
{ name: "HSL", color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
|
|
@@ -740,20 +743,20 @@ describe("ColorArea", () => {
|
|
|
740
743
|
const el = await fixture(html`
|
|
741
744
|
<sp-color-area></sp-color-area>
|
|
742
745
|
`);
|
|
743
|
-
|
|
746
|
+
if (typeof format.color === "string") {
|
|
747
|
+
el.color = format.color;
|
|
748
|
+
} else {
|
|
749
|
+
el.color = { ...format.color };
|
|
750
|
+
}
|
|
744
751
|
if (format.name.startsWith("Hex")) {
|
|
745
752
|
expect(el.color).to.equal(format.color);
|
|
746
|
-
} else
|
|
753
|
+
} else if (format.name == "string") {
|
|
754
|
+
expect(el.color).to.equal(format.test);
|
|
755
|
+
} else {
|
|
756
|
+
expect(el.color).to.deep.equal(format.color);
|
|
757
|
+
}
|
|
747
758
|
});
|
|
748
759
|
});
|
|
749
|
-
it(`maintains \`color\` format as TinyColor`, async () => {
|
|
750
|
-
const el = await fixture(html`
|
|
751
|
-
<sp-color-area></sp-color-area>
|
|
752
|
-
`);
|
|
753
|
-
const color = new TinyColor("rgb(204, 51, 204)");
|
|
754
|
-
el.color = color;
|
|
755
|
-
expect(color.equals(el.color));
|
|
756
|
-
});
|
|
757
760
|
it(`resolves Hex3 format to Hex6 format`, async () => {
|
|
758
761
|
const el = await fixture(html`
|
|
759
762
|
<sp-color-area></sp-color-area>
|