@spectrum-web-components/color-area 0.4.4 → 0.4.5
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/color-area",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@ctrl/tinycolor": "^3.3.3",
|
|
48
|
-
"@spectrum-web-components/base": "^0.5.
|
|
49
|
-
"@spectrum-web-components/color-handle": "^0.3.
|
|
48
|
+
"@spectrum-web-components/base": "^0.5.4",
|
|
49
|
+
"@spectrum-web-components/color-handle": "^0.3.5",
|
|
50
50
|
"tslib": "^2.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"sideEffects": [
|
|
58
58
|
"./sp-*.js"
|
|
59
59
|
],
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
|
|
61
61
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { html } from '@spectrum-web-components/base';
|
|
13
|
+
import '@spectrum-web-components/color-slider/sp-color-slider.js';
|
|
14
|
+
import '../sp-color-area.js';
|
|
15
|
+
export default {
|
|
16
|
+
title: 'Color/Area',
|
|
17
|
+
component: 'sp-color-area',
|
|
18
|
+
argTypes: {
|
|
19
|
+
onInput: { action: 'input' },
|
|
20
|
+
onChange: { action: 'change' },
|
|
21
|
+
color: {
|
|
22
|
+
name: 'color',
|
|
23
|
+
type: { name: 'ColorValue', required: 'true' },
|
|
24
|
+
description: 'The color displayed by the ColorArea.',
|
|
25
|
+
table: {
|
|
26
|
+
type: { summary: 'ColorValue' },
|
|
27
|
+
defaultValue: { summary: '' },
|
|
28
|
+
},
|
|
29
|
+
control: 'text',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const Default = ({ onChange, onInput }) => {
|
|
34
|
+
return html `
|
|
35
|
+
<sp-color-area
|
|
36
|
+
@input=${({ target }) => {
|
|
37
|
+
const next = target.nextElementSibling;
|
|
38
|
+
next.textContent = target.color;
|
|
39
|
+
next.style.color = target.color;
|
|
40
|
+
onInput(target.value);
|
|
41
|
+
}}
|
|
42
|
+
@change=${({ target }) => {
|
|
43
|
+
onChange(target.value);
|
|
44
|
+
}}
|
|
45
|
+
></sp-color-area>
|
|
46
|
+
<div style="color: #ff0000" aria-live="off">#ff0000</div>
|
|
47
|
+
`;
|
|
48
|
+
};
|
|
49
|
+
export const joint = () => {
|
|
50
|
+
return html `
|
|
51
|
+
<div>
|
|
52
|
+
<sp-color-area
|
|
53
|
+
color="hsv (120 0% 100%)"
|
|
54
|
+
@input=${({ target }) => {
|
|
55
|
+
const next = target.nextElementSibling;
|
|
56
|
+
const display = next.nextElementSibling;
|
|
57
|
+
display.textContent = target.color;
|
|
58
|
+
display.style.color = target.color;
|
|
59
|
+
next.color = target.color;
|
|
60
|
+
}}
|
|
61
|
+
></sp-color-area>
|
|
62
|
+
<sp-color-slider
|
|
63
|
+
color="hsv(120 0% 1)"
|
|
64
|
+
@input=${({ target: { color, previousElementSibling, nextElementSibling, }, }) => {
|
|
65
|
+
previousElementSibling.color = color;
|
|
66
|
+
nextElementSibling.textContent = color;
|
|
67
|
+
nextElementSibling.style.color = color;
|
|
68
|
+
}}
|
|
69
|
+
></sp-color-slider>
|
|
70
|
+
<div style="color: hsv(120, 0, 1)">hsv(120, 0, 1)</div>
|
|
71
|
+
</div>
|
|
72
|
+
`;
|
|
73
|
+
};
|
|
74
|
+
export const disabled = () => {
|
|
75
|
+
return html `
|
|
76
|
+
<sp-color-area disabled></sp-color-area>
|
|
77
|
+
`;
|
|
78
|
+
};
|
|
79
|
+
export const sized = () => {
|
|
80
|
+
return html `
|
|
81
|
+
<sp-color-area style="width: 72px; height: 72px"></sp-color-area>
|
|
82
|
+
`;
|
|
83
|
+
};
|
|
84
|
+
export const canvas = () => {
|
|
85
|
+
return html `
|
|
86
|
+
<sp-color-area>
|
|
87
|
+
<canvas slot="gradient"></canvas>
|
|
88
|
+
</sp-color-area>
|
|
89
|
+
`;
|
|
90
|
+
};
|
|
91
|
+
class CanvasWriter extends HTMLElement {
|
|
92
|
+
constructor() {
|
|
93
|
+
super();
|
|
94
|
+
this.writeStatePromise = Promise.resolve(false);
|
|
95
|
+
this.writeStatePromise = new Promise((res) => {
|
|
96
|
+
requestAnimationFrame(() => {
|
|
97
|
+
this.writeToCanvas();
|
|
98
|
+
res(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
writeToCanvas() {
|
|
103
|
+
const { previousElementSibling } = this;
|
|
104
|
+
if (previousElementSibling) {
|
|
105
|
+
const canvas = previousElementSibling.querySelector('canvas[slot="gradient"]');
|
|
106
|
+
if (canvas) {
|
|
107
|
+
canvas.width = canvas.offsetWidth;
|
|
108
|
+
canvas.height = canvas.offsetHeight;
|
|
109
|
+
const context = canvas.getContext('2d');
|
|
110
|
+
if (context) {
|
|
111
|
+
context.rect(0, 0, canvas.width, canvas.height);
|
|
112
|
+
const gradB = context.createLinearGradient(0, 0, 0, canvas.height);
|
|
113
|
+
gradB.addColorStop(0, 'white');
|
|
114
|
+
gradB.addColorStop(1, 'black');
|
|
115
|
+
const gradC = context.createLinearGradient(0, 0, canvas.width, 0);
|
|
116
|
+
gradC.addColorStop(0, 'hsla(0,100%,50%,0)');
|
|
117
|
+
gradC.addColorStop(1, 'hsla(0,100%,50%,1)');
|
|
118
|
+
context.fillStyle = gradB;
|
|
119
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
120
|
+
context.fillStyle = gradC;
|
|
121
|
+
context.globalCompositeOperation = 'multiply';
|
|
122
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
123
|
+
context.globalCompositeOperation = 'source-over';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
get updateComplete() {
|
|
129
|
+
return this.writeStatePromise;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
customElements.define('area-canvas-writer', CanvasWriter);
|
|
133
|
+
canvas.decorators = [
|
|
134
|
+
(story) => {
|
|
135
|
+
return html `
|
|
136
|
+
${story()}
|
|
137
|
+
<area-canvas-writer></area-canvas-writer>
|
|
138
|
+
`;
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
//# sourceMappingURL=color-area.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-area.stories.js","sourceRoot":"","sources":["color-area.stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AAErE,OAAO,0DAA0D,CAAC;AAElE,OAAO,qBAAqB,CAAC;AAG7B,eAAe;IACX,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,eAAe;IAC1B,QAAQ,EAAE;QACN,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAC5B,QAAQ,EAAE,EAAE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AC,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;AAE1D,MAAM,CAAC,UAAU,GAAG;IAChB,CAAC,KAA2B,EAAkB,EAAE;QAC5C,OAAO,IAAI,CAAA;cACL,KAAK,EAAE;;SAEZ,CAAC;IACN,CAAC;CACJ,CAAC","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 '../sp-color-area.js';\nimport { ColorArea } from '../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: 'ColorValue', required: 'true' },\n description: 'The color displayed by the ColorArea.',\n table: {\n type: { summary: 'ColorValue' },\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 @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 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"]}
|