@spectrum-web-components/color-field 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.
- package/README.md +142 -0
- package/package.json +70 -0
- package/sp-color-field.d.ts +6 -0
- package/sp-color-field.dev.js +4 -0
- package/sp-color-field.dev.js.map +7 -0
- package/sp-color-field.js +2 -0
- package/sp-color-field.js.map +7 -0
- package/src/ColorField.d.ts +20 -0
- package/src/ColorField.dev.js +81 -0
- package/src/ColorField.dev.js.map +7 -0
- package/src/ColorField.js +9 -0
- package/src/ColorField.js.map +7 -0
- package/src/index.d.ts +1 -0
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -0
- package/src/index.js.map +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
`<sp-color-field>` elements are textfields that allow users to input custom color values.
|
|
4
|
+
Color formats supported are `HEX, RGB, HSL, HSV, and shorthand HEX`
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@spectrum-web-components/color-field)
|
|
9
|
+
[](https://bundlephobia.com/result?p=@spectrum-web-components/color-field)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
yarn add @spectrum-web-components/color-field
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the side effectful registration of `<sp-color-field>` via:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
import '@spectrum-web-components/color-field/sp-color-field.js';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
When looking to leverage the `ColorField` base class as a type and/or for extension purposes, do so via:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
import { ColorField } from '@spectrum-web-components/color-field';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Sizes
|
|
28
|
+
|
|
29
|
+
<sp-tabs selected="m" auto label="Size Attribute Options">
|
|
30
|
+
<sp-tab value="s">Small</sp-tab>
|
|
31
|
+
<sp-tab-panel value="s">
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<sp-color-field size="s" value="#ffff00"></sp-color-field>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
</sp-tab-panel>
|
|
38
|
+
<sp-tab value="m">Medium</sp-tab>
|
|
39
|
+
<sp-tab-panel value="m">
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<sp-color-field size="m" value="#ffff00"></sp-color-field>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
</sp-tab-panel>
|
|
46
|
+
<sp-tab value="l">Large</sp-tab>
|
|
47
|
+
|
|
48
|
+
<sp-tab-panel value="l">
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<sp-color-field size="l" value="#ffff00"></sp-color-field>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
</sp-tab-panel>
|
|
55
|
+
<sp-tab value="xl">Xtra Large</sp-tab>
|
|
56
|
+
|
|
57
|
+
<sp-tab-panel value="xl">
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<sp-color-field size="xl" value="#ffff00"></sp-color-field>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
</sp-tab-panel>
|
|
64
|
+
</sp-tabs>
|
|
65
|
+
|
|
66
|
+
## View Color
|
|
67
|
+
|
|
68
|
+
When `view-color` is true, the color handle will be rendered. This is useful for development and debugging purposes.
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<sp-color-field view-color value="#f00"></sp-color-field>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Read Only
|
|
75
|
+
|
|
76
|
+
A readonly color field
|
|
77
|
+
|
|
78
|
+
```html
|
|
79
|
+
<sp-color-field readonly value="#ffff00"></sp-color-field>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quiet
|
|
83
|
+
|
|
84
|
+
A Quiet color field
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<sp-color-field quiet value="#e6e600"></sp-color-field>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Invalid Input
|
|
91
|
+
|
|
92
|
+
If the input value is not a valid color, `<sp-color-field>` will not accept it.
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<sp-color-field value="not a color"></sp-color-field>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Valid Input
|
|
99
|
+
|
|
100
|
+
If the input value is a valid color, the `<sp-color-field>` will accept it and the color handle will be updated to reflect the new color.
|
|
101
|
+
|
|
102
|
+
`<sp-color-field>` component accepts color values in various formats: `HEX, RGB, HSL, HSV, and shorthand HEX`
|
|
103
|
+
|
|
104
|
+
- **HEX**: A hexadecimal color is specified with: `#RRGGBB`. `RR` (red), `GG` (green) and `BB` (blue) are hexadecimal integers between `00` and `FF` specifying the intensity of the color.
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<sp-color-field value="#ff0000"></sp-color-field>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- **Shorthand HEX**: Shorthand hexadecimal color values are also supported. `#RGB` is a shorthand for `#RRGGBB`. In the shorthand form, `R` (red), `G` (green), and `B` (blue) are hexadecimal characters between `0` and `F`. Each character is repeated to create the full 6-digit color code. For example, `#123` would expand to `#112233`.
|
|
111
|
+
|
|
112
|
+
```html
|
|
113
|
+
<sp-color-field view-color value="#f00"></sp-color-field>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- **RGB**: An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of the color with a value between 0 and 255.
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<sp-color-field view-color value="rgb(0,2555,0)"></sp-color-field>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
- **RGBA**: An RGBA color value is specified with: `rgba(red, green, blue, alpha)`. The `alpha` parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).
|
|
123
|
+
|
|
124
|
+
```html
|
|
125
|
+
<sp-color-field view-color value="rgba(0,255,0,0.3)"></sp-color-field>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- **HSL**: An HSL color value is specified with: hsl(hue, saturation, lightness). Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue. Saturation and lightness are percentages.
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<sp-color-field view-color value="hsl(234, 70%, 50%)"></sp-color-field>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **HSV**: An HSV color value is specified with: hsv(hue, saturation, value). Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue. Saturation and value are percentages.
|
|
135
|
+
|
|
136
|
+
```html
|
|
137
|
+
<sp-color-field view-color value="hsv(0, 70%, 50%)"></sp-color-field>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Events
|
|
141
|
+
|
|
142
|
+
The sp-color-field component fires a change event when the color value is changed. You can listen for this event to react to changes in the color value.
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spectrum-web-components/color-field",
|
|
3
|
+
"version": "0.0.0-20241209155954",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Web component implementation of a Spectrum design ColorField",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/adobe/spectrum-web-components.git",
|
|
12
|
+
"directory": "packages/color-field"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"homepage": "https://adobe.github.io/spectrum-web-components/components/color-field",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/adobe/spectrum-web-components/issues"
|
|
18
|
+
},
|
|
19
|
+
"main": "src/index.js",
|
|
20
|
+
"module": "src/index.js",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
"./src/ColorField.js": {
|
|
29
|
+
"development": "./src/ColorField.dev.js",
|
|
30
|
+
"default": "./src/ColorField.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/index.js": {
|
|
33
|
+
"development": "./src/index.dev.js",
|
|
34
|
+
"default": "./src/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./sp-color-field.js": {
|
|
37
|
+
"development": "./sp-color-field.dev.js",
|
|
38
|
+
"default": "./sp-color-field.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"**/*.d.ts",
|
|
46
|
+
"**/*.js",
|
|
47
|
+
"**/*.js.map",
|
|
48
|
+
"custom-elements.json",
|
|
49
|
+
"!stories/",
|
|
50
|
+
"!test/"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"spectrum css",
|
|
54
|
+
"web components",
|
|
55
|
+
"lit-element",
|
|
56
|
+
"lit-html"
|
|
57
|
+
],
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@ctrl/tinycolor": "^4.0.3",
|
|
60
|
+
"@spectrum-web-components/base": "0.0.0-20241209155954",
|
|
61
|
+
"@spectrum-web-components/color-handle": "0.0.0-20241209155954",
|
|
62
|
+
"@spectrum-web-components/textfield": "0.0.0-20241209155954"
|
|
63
|
+
},
|
|
64
|
+
"types": "./src/index.d.ts",
|
|
65
|
+
"customElements": "custom-elements.json",
|
|
66
|
+
"sideEffects": [
|
|
67
|
+
"./sp-*.js",
|
|
68
|
+
"./**/*.dev.js"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-color-field.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 { ColorField } from './src/ColorField.dev.js'\n\ncustomElements.define('sp-color-field', ColorField);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-field': ColorField;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,kBAAkB;AAE3B,eAAe,OAAO,kBAAkB,UAAU;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-color-field.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 { ColorField } from './src/ColorField.js';\n\ncustomElements.define('sp-color-field', ColorField);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-field': ColorField;\n }\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,cAAAA,MAAkB,sBAE3B,eAAe,OAAO,iBAAkBA,CAAU",
|
|
6
|
+
"names": ["ColorField"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CSSResultArray, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { TextfieldBase } from '@spectrum-web-components/textfield';
|
|
3
|
+
/**
|
|
4
|
+
* @element sp-color-field
|
|
5
|
+
* @fires input - The value of the color-field has changed.
|
|
6
|
+
* @fires change - An alteration to the value of the color-field has been committed by the user.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ColorField extends TextfieldBase {
|
|
9
|
+
static get styles(): CSSResultArray;
|
|
10
|
+
viewColor: boolean;
|
|
11
|
+
set value(value: string);
|
|
12
|
+
get value(): string;
|
|
13
|
+
protected _value: string;
|
|
14
|
+
private cachedColor;
|
|
15
|
+
getColorValue(): string;
|
|
16
|
+
private renderColorHandle;
|
|
17
|
+
protected render(): TemplateResult;
|
|
18
|
+
private cachedTinyColor;
|
|
19
|
+
checkValidity(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
17
|
+
import { TextfieldBase } from "@spectrum-web-components/textfield";
|
|
18
|
+
export class ColorField extends TextfieldBase {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.viewColor = false;
|
|
22
|
+
this._value = "";
|
|
23
|
+
this.cachedColor = null;
|
|
24
|
+
this.cachedTinyColor = null;
|
|
25
|
+
}
|
|
26
|
+
static get styles() {
|
|
27
|
+
return [...super.styles];
|
|
28
|
+
}
|
|
29
|
+
set value(value) {
|
|
30
|
+
if (value === this.value) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const oldValue = this._value;
|
|
34
|
+
this._value = value;
|
|
35
|
+
this.requestUpdate("value", oldValue);
|
|
36
|
+
}
|
|
37
|
+
get value() {
|
|
38
|
+
return this._value;
|
|
39
|
+
}
|
|
40
|
+
getColorValue() {
|
|
41
|
+
if (!this.value) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
if (!this.cachedColor || this.cachedColor !== this.value) {
|
|
45
|
+
const tinyColor = new TinyColor(this.value);
|
|
46
|
+
this.cachedColor = tinyColor.isValid ? tinyColor.toRgbString() : "";
|
|
47
|
+
}
|
|
48
|
+
return this.cachedColor;
|
|
49
|
+
}
|
|
50
|
+
renderColorHandle() {
|
|
51
|
+
return this.viewColor ? html`
|
|
52
|
+
<sp-color-handle
|
|
53
|
+
size="m"
|
|
54
|
+
color="${this.getColorValue()}"
|
|
55
|
+
></sp-color-handle>
|
|
56
|
+
` : html``;
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
if (this.viewColor) {
|
|
60
|
+
import("@spectrum-web-components/color-handle/sp-color-handle.js");
|
|
61
|
+
}
|
|
62
|
+
return html`
|
|
63
|
+
${super.render()} ${this.renderColorHandle()}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
checkValidity() {
|
|
67
|
+
let validity = super.checkValidity();
|
|
68
|
+
if (this.value) {
|
|
69
|
+
if (!this.cachedTinyColor || this.cachedTinyColor.originalInput !== this.value) {
|
|
70
|
+
this.cachedTinyColor = new TinyColor(this.value);
|
|
71
|
+
}
|
|
72
|
+
this.valid = validity = this.cachedTinyColor.isValid;
|
|
73
|
+
this.invalid = !validity;
|
|
74
|
+
}
|
|
75
|
+
return validity;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
__decorateClass([
|
|
79
|
+
property({ type: Boolean, attribute: "view-color" })
|
|
80
|
+
], ColorField.prototype, "viewColor", 2);
|
|
81
|
+
//# sourceMappingURL=ColorField.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["ColorField.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 {\n CSSResultArray,\n html,\n TemplateResult,\n} from '@spectrum-web-components/base';\n\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { TinyColor } from '@ctrl/tinycolor';\nimport { TextfieldBase } from '@spectrum-web-components/textfield';\n\n/**\n * @element sp-color-field\n * @fires input - The value of the color-field has changed.\n * @fires change - An alteration to the value of the color-field has been committed by the user.\n */\nexport class ColorField extends TextfieldBase {\n public static override get styles(): CSSResultArray {\n return [...super.styles];\n }\n\n @property({ type: Boolean, attribute: 'view-color' })\n public viewColor = false;\n\n public override set value(value: string) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public override get value(): string {\n return this._value;\n }\n\n protected override _value = '';\n\n private cachedColor: string | null = null;\n\n public getColorValue(): string {\n if (!this.value) {\n return '';\n }\n\n if (!this.cachedColor || this.cachedColor !== this.value) {\n const tinyColor = new TinyColor(this.value);\n this.cachedColor = tinyColor.isValid ? tinyColor.toRgbString() : '';\n }\n\n return this.cachedColor;\n }\n\n private renderColorHandle(): TemplateResult {\n return this.viewColor\n ? html`\n <sp-color-handle\n size=\"m\"\n color=\"${this.getColorValue()}\"\n ></sp-color-handle>\n `\n : html``;\n }\n\n protected override render(): TemplateResult {\n if (this.viewColor) {\n import('@spectrum-web-components/color-handle/sp-color-handle.js');\n }\n return html`\n ${super.render()} ${this.renderColorHandle()}\n `;\n }\n\n private cachedTinyColor: TinyColor | null = null;\n\n public override checkValidity(): boolean {\n let validity = super.checkValidity();\n if (this.value) {\n if (\n !this.cachedTinyColor ||\n this.cachedTinyColor.originalInput !== this.value\n ) {\n this.cachedTinyColor = new TinyColor(this.value);\n }\n this.valid = validity = this.cachedTinyColor.isValid;\n this.invalid = !validity;\n }\n return validity;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA;AAAA,EAEI;AAAA,OAEG;AAEP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAOvB,aAAM,mBAAmB,cAAc;AAAA,EAAvC;AAAA;AAMH,SAAO,YAAY;AAenB,SAAmB,SAAS;AAE5B,SAAQ,cAA6B;AAmCrC,SAAQ,kBAAoC;AAAA;AAAA,EAzD5C,WAA2B,SAAyB;AAChD,WAAO,CAAC,GAAG,MAAM,MAAM;AAAA,EAC3B;AAAA,EAKA,IAAoB,MAAM,OAAe;AACrC,QAAI,UAAU,KAAK,OAAO;AACtB;AAAA,IACJ;AACA,UAAM,WAAW,KAAK;AACtB,SAAK,SAAS;AACd,SAAK,cAAc,SAAS,QAAQ;AAAA,EACxC;AAAA,EAEA,IAAoB,QAAgB;AAChC,WAAO,KAAK;AAAA,EAChB;AAAA,EAMO,gBAAwB;AAC3B,QAAI,CAAC,KAAK,OAAO;AACb,aAAO;AAAA,IACX;AAEA,QAAI,CAAC,KAAK,eAAe,KAAK,gBAAgB,KAAK,OAAO;AACtD,YAAM,YAAY,IAAI,UAAU,KAAK,KAAK;AAC1C,WAAK,cAAc,UAAU,UAAU,UAAU,YAAY,IAAI;AAAA,IACrE;AAEA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEQ,oBAAoC;AACxC,WAAO,KAAK,YACN;AAAA;AAAA;AAAA,+BAGiB,KAAK,cAAc,CAAC;AAAA;AAAA,kBAGrC;AAAA,EACV;AAAA,EAEmB,SAAyB;AACxC,QAAI,KAAK,WAAW;AAChB,aAAO,0DAA0D;AAAA,IACrE;AACA,WAAO;AAAA,cACD,MAAM,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAAA;AAAA,EAEpD;AAAA,EAIgB,gBAAyB;AACrC,QAAI,WAAW,MAAM,cAAc;AACnC,QAAI,KAAK,OAAO;AACZ,UACI,CAAC,KAAK,mBACN,KAAK,gBAAgB,kBAAkB,KAAK,OAC9C;AACE,aAAK,kBAAkB,IAAI,UAAU,KAAK,KAAK;AAAA,MACnD;AACA,WAAK,QAAQ,WAAW,KAAK,gBAAgB;AAC7C,WAAK,UAAU,CAAC;AAAA,IACpB;AACA,WAAO;AAAA,EACX;AACJ;AApEW;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,WAAW,aAAa,CAAC;AAAA,GAL3C,WAMF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=(l,t,e,i)=>{for(var r=i>1?void 0:i?h(t,e):t,o=l.length-1,s;o>=0;o--)(s=l[o])&&(r=(i?s(t,e,r):s(r))||r);return i&&r&&c(t,e,r),r};import{html as a}from"@spectrum-web-components/base";import{property as d}from"@spectrum-web-components/base/src/decorators.js";import{TinyColor as n}from"@ctrl/tinycolor";import{TextfieldBase as p}from"@spectrum-web-components/textfield";export class ColorField extends p{constructor(){super(...arguments);this.viewColor=!1;this._value="";this.cachedColor=null;this.cachedTinyColor=null}static get styles(){return[...super.styles]}set value(e){if(e===this.value)return;const i=this._value;this._value=e,this.requestUpdate("value",i)}get value(){return this._value}getColorValue(){if(!this.value)return"";if(!this.cachedColor||this.cachedColor!==this.value){const e=new n(this.value);this.cachedColor=e.isValid?e.toRgbString():""}return this.cachedColor}renderColorHandle(){return this.viewColor?a`
|
|
2
|
+
<sp-color-handle
|
|
3
|
+
size="m"
|
|
4
|
+
color="${this.getColorValue()}"
|
|
5
|
+
></sp-color-handle>
|
|
6
|
+
`:a``}render(){return this.viewColor&&import("@spectrum-web-components/color-handle/sp-color-handle.js"),a`
|
|
7
|
+
${super.render()} ${this.renderColorHandle()}
|
|
8
|
+
`}checkValidity(){let e=super.checkValidity();return this.value&&((!this.cachedTinyColor||this.cachedTinyColor.originalInput!==this.value)&&(this.cachedTinyColor=new n(this.value)),this.valid=e=this.cachedTinyColor.isValid,this.invalid=!e),e}}u([d({type:Boolean,attribute:"view-color"})],ColorField.prototype,"viewColor",2);
|
|
9
|
+
//# sourceMappingURL=ColorField.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["ColorField.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 {\n CSSResultArray,\n html,\n TemplateResult,\n} from '@spectrum-web-components/base';\n\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { TinyColor } from '@ctrl/tinycolor';\nimport { TextfieldBase } from '@spectrum-web-components/textfield';\n\n/**\n * @element sp-color-field\n * @fires input - The value of the color-field has changed.\n * @fires change - An alteration to the value of the color-field has been committed by the user.\n */\nexport class ColorField extends TextfieldBase {\n public static override get styles(): CSSResultArray {\n return [...super.styles];\n }\n\n @property({ type: Boolean, attribute: 'view-color' })\n public viewColor = false;\n\n public override set value(value: string) {\n if (value === this.value) {\n return;\n }\n const oldValue = this._value;\n this._value = value;\n this.requestUpdate('value', oldValue);\n }\n\n public override get value(): string {\n return this._value;\n }\n\n protected override _value = '';\n\n private cachedColor: string | null = null;\n\n public getColorValue(): string {\n if (!this.value) {\n return '';\n }\n\n if (!this.cachedColor || this.cachedColor !== this.value) {\n const tinyColor = new TinyColor(this.value);\n this.cachedColor = tinyColor.isValid ? tinyColor.toRgbString() : '';\n }\n\n return this.cachedColor;\n }\n\n private renderColorHandle(): TemplateResult {\n return this.viewColor\n ? html`\n <sp-color-handle\n size=\"m\"\n color=\"${this.getColorValue()}\"\n ></sp-color-handle>\n `\n : html``;\n }\n\n protected override render(): TemplateResult {\n if (this.viewColor) {\n import('@spectrum-web-components/color-handle/sp-color-handle.js');\n }\n return html`\n ${super.render()} ${this.renderColorHandle()}\n `;\n }\n\n private cachedTinyColor: TinyColor | null = null;\n\n public override checkValidity(): boolean {\n let validity = super.checkValidity();\n if (this.value) {\n if (\n !this.cachedTinyColor ||\n this.cachedTinyColor.originalInput !== this.value\n ) {\n this.cachedTinyColor = new TinyColor(this.value);\n }\n this.valid = validity = this.cachedTinyColor.isValid;\n this.invalid = !validity;\n }\n return validity;\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAWA,OAEI,QAAAA,MAEG,gCAEP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,aAAAC,MAAiB,kBAC1B,OAAS,iBAAAC,MAAqB,qCAOvB,aAAM,mBAAmBA,CAAc,CAAvC,kCAMH,KAAO,UAAY,GAenB,KAAmB,OAAS,GAE5B,KAAQ,YAA6B,KAmCrC,KAAQ,gBAAoC,KAzD5C,WAA2B,QAAyB,CAChD,MAAO,CAAC,GAAG,MAAM,MAAM,CAC3B,CAKA,IAAoB,MAAMC,EAAe,CACrC,GAAIA,IAAU,KAAK,MACf,OAEJ,MAAMC,EAAW,KAAK,OACtB,KAAK,OAASD,EACd,KAAK,cAAc,QAASC,CAAQ,CACxC,CAEA,IAAoB,OAAgB,CAChC,OAAO,KAAK,MAChB,CAMO,eAAwB,CAC3B,GAAI,CAAC,KAAK,MACN,MAAO,GAGX,GAAI,CAAC,KAAK,aAAe,KAAK,cAAgB,KAAK,MAAO,CACtD,MAAMC,EAAY,IAAIJ,EAAU,KAAK,KAAK,EAC1C,KAAK,YAAcI,EAAU,QAAUA,EAAU,YAAY,EAAI,EACrE,CAEA,OAAO,KAAK,WAChB,CAEQ,mBAAoC,CACxC,OAAO,KAAK,UACNN;AAAA;AAAA;AAAA,+BAGiB,KAAK,cAAc,CAAC;AAAA;AAAA,gBAGrCA,GACV,CAEmB,QAAyB,CACxC,OAAI,KAAK,WACL,OAAO,0DAA0D,EAE9DA;AAAA,cACD,MAAM,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAAA,SAEpD,CAIgB,eAAyB,CACrC,IAAIO,EAAW,MAAM,cAAc,EACnC,OAAI,KAAK,SAED,CAAC,KAAK,iBACN,KAAK,gBAAgB,gBAAkB,KAAK,SAE5C,KAAK,gBAAkB,IAAIL,EAAU,KAAK,KAAK,GAEnD,KAAK,MAAQK,EAAW,KAAK,gBAAgB,QAC7C,KAAK,QAAU,CAACA,GAEbA,CACX,CACJ,CApEWC,EAAA,CADNP,EAAS,CAAE,KAAM,QAAS,UAAW,YAAa,CAAC,GAL3C,WAMF",
|
|
6
|
+
"names": ["html", "property", "TinyColor", "TextfieldBase", "value", "oldValue", "tinyColor", "validity", "__decorateClass"]
|
|
7
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ColorField.js';
|
package/src/index.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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*/\nexport * from './ColorField.dev.js'\n"],
|
|
5
|
+
"mappings": ";AAWA,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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*/\nexport * from './ColorField.js';\n"],
|
|
5
|
+
"mappings": "aAWA,WAAc",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|