@spectrum-web-components/color-wheel 0.3.5 → 0.3.6

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-wheel",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,9 +45,9 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "@ctrl/tinycolor": "^3.3.3",
48
- "@spectrum-web-components/base": "^0.5.3",
49
- "@spectrum-web-components/color-handle": "^0.3.4",
50
- "@spectrum-web-components/shared": "^0.13.5",
48
+ "@spectrum-web-components/base": "^0.5.4",
49
+ "@spectrum-web-components/color-handle": "^0.3.5",
50
+ "@spectrum-web-components/shared": "^0.13.6",
51
51
  "tslib": "^2.0.0"
52
52
  },
53
53
  "devDependencies": {
@@ -58,5 +58,5 @@
58
58
  "sideEffects": [
59
59
  "./sp-*.js"
60
60
  ],
61
- "gitHead": "57aba8030b6af96af4015a0aa830e342a17dc219"
61
+ "gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
62
62
  }
@@ -0,0 +1,91 @@
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 '../sp-color-wheel.js';
14
+ export default {
15
+ title: 'Color/Wheel',
16
+ component: 'sp-color-wheel',
17
+ };
18
+ export const Default = () => {
19
+ return html `
20
+ <sp-color-wheel></sp-color-wheel>
21
+ `;
22
+ };
23
+ export const sized = () => {
24
+ return html `
25
+ <sp-color-wheel style="width: 300px; height: 300px;"></sp-color-wheel>
26
+ `;
27
+ };
28
+ export const wheelDisabled = () => {
29
+ return html `
30
+ <sp-color-wheel disabled></sp-color-wheel>
31
+ `;
32
+ };
33
+ export const canvas = () => {
34
+ return html `
35
+ <sp-color-wheel>
36
+ <canvas slot="gradient"></canvas>
37
+ </sp-color-wheel>
38
+ `;
39
+ };
40
+ class CanvasWriter extends HTMLElement {
41
+ constructor() {
42
+ super();
43
+ this.writeStatePromise = Promise.resolve(false);
44
+ this.writeStatePromise = new Promise((res) => {
45
+ requestAnimationFrame(() => {
46
+ this.writeToCanvas();
47
+ res(true);
48
+ });
49
+ });
50
+ }
51
+ writeToCanvas() {
52
+ const { previousElementSibling } = this;
53
+ if (previousElementSibling) {
54
+ const canvas = previousElementSibling.querySelector('canvas[slot="gradient"]');
55
+ if (canvas) {
56
+ canvas.width = canvas.offsetWidth;
57
+ canvas.height = canvas.offsetHeight;
58
+ const context = canvas.getContext('2d');
59
+ if (context) {
60
+ context.rect(0, 0, canvas.width, canvas.height);
61
+ const width = canvas.width;
62
+ const height = canvas.height;
63
+ const centerX = width / 2;
64
+ const centerY = height / 2;
65
+ const ringSize = 57;
66
+ for (let i = 0; i < 360; i += Math.PI / 8) {
67
+ const rad = (i * (2 * Math.PI)) / 360;
68
+ context.strokeStyle = `hsla(${i}, 100%, 50%, 1.0)`;
69
+ context.beginPath();
70
+ context.moveTo(centerX + ringSize * Math.cos(rad), centerY + ringSize * Math.sin(rad));
71
+ context.lineTo(centerX + centerX * Math.cos(rad), centerY + centerY * Math.sin(rad));
72
+ context.stroke();
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ get updateComplete() {
79
+ return this.writeStatePromise;
80
+ }
81
+ }
82
+ customElements.define('wheel-canvas-writer', CanvasWriter);
83
+ canvas.decorators = [
84
+ (story) => {
85
+ return html `
86
+ ${story()}
87
+ <wheel-canvas-writer></wheel-canvas-writer>
88
+ `;
89
+ },
90
+ ];
91
+ //# sourceMappingURL=color-wheel.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-wheel.stories.js","sourceRoot":"","sources":["color-wheel.stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AAErE,OAAO,sBAAsB,CAAC;AAE9B,eAAe;IACX,KAAK,EAAE,aAAa;IACpB,SAAS,EAAE,gBAAgB;CAC9B,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,GAAmB,EAAE;IACxC,OAAO,IAAI,CAAA;;KAEV,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,GAAmB,EAAE;IACtC,OAAO,IAAI,CAAA;;KAEV,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAmB,EAAE;IAC9C,OAAO,IAAI,CAAA;;KAEV,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,GAAmB,EAAE;IACvC,OAAO,IAAI,CAAA;;;;KAIV,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,YAAa,SAAQ,WAAW;IAwClC;QACI,KAAK,EAAE,CAAC;QASJ,sBAAiB,GAAqB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QARjE,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACzC,qBAAqB,CAAC,GAAG,EAAE;gBACvB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,GAAG,CAAC,IAAI,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IA/CD,aAAa;QACT,MAAM,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC;QACxC,IAAI,sBAAsB,EAAE;YACxB,MAAM,MA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G,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CACpC,CAAC;wBACF,OAAO,CAAC,MAAM,EAAE,CAAC;qBACpB;iBACJ;aACJ;SACJ;IACL,CAAC;IAcD,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;AAE3D,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 '../sp-color-wheel.js';\n\nexport default {\n title: 'Color/Wheel',\n component: 'sp-color-wheel',\n};\n\nexport const Default = (): TemplateResult => {\n return html`\n <sp-color-wheel></sp-color-wheel>\n `;\n};\n\nexport const sized = (): TemplateResult => {\n return html`\n <sp-color-wheel style=\"width: 300px; height: 300px;\"></sp-color-wheel>\n `;\n};\n\nexport const wheelDisabled = (): TemplateResult => {\n return html`\n <sp-color-wheel disabled></sp-color-wheel>\n `;\n};\n\nexport const canvas = (): TemplateResult => {\n return html`\n <sp-color-wheel>\n <canvas slot=\"gradient\"></canvas>\n </sp-color-wheel>\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 width = canvas.width;\n const height = canvas.height;\n const centerX = width / 2;\n const centerY = height / 2;\n const ringSize = 57;\n\n for (let i = 0; i < 360; i += Math.PI / 8) {\n const rad = (i * (2 * Math.PI)) / 360;\n context.strokeStyle = `hsla(${i}, 100%, 50%, 1.0)`;\n context.beginPath();\n context.moveTo(\n centerX + ringSize * Math.cos(rad),\n centerY + ringSize * Math.sin(rad)\n );\n context.lineTo(\n centerX + centerX * Math.cos(rad),\n centerY + centerY * Math.sin(rad)\n );\n context.stroke();\n }\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('wheel-canvas-writer', CanvasWriter);\n\ncanvas.decorators = [\n (story: () => TemplateResult): TemplateResult => {\n return html`\n ${story()}\n <wheel-canvas-writer></wheel-canvas-writer>\n `;\n },\n];\n"]}