@spectrum-web-components/reactive-controllers 0.3.0-devmode.0 → 0.3.1

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/reactive-controllers",
3
- "version": "0.3.0-devmode.0+1a8b29491",
3
+ "version": "0.3.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,10 +25,18 @@
25
25
  "default": "./src/index.js"
26
26
  },
27
27
  "./package.json": "./package.json",
28
+ "./src/Color.js": {
29
+ "development": "./src/Color.dev.js",
30
+ "default": "./src/Color.js"
31
+ },
28
32
  "./src/FocusGroup.js": {
29
33
  "development": "./src/FocusGroup.dev.js",
30
34
  "default": "./src/FocusGroup.js"
31
35
  },
36
+ "./src/LanguageResolution.js": {
37
+ "development": "./src/LanguageResolution.dev.js",
38
+ "default": "./src/LanguageResolution.js"
39
+ },
32
40
  "./src/MatchMedia.js": {
33
41
  "development": "./src/MatchMedia.dev.js",
34
42
  "default": "./src/MatchMedia.js"
@@ -68,5 +76,5 @@
68
76
  "sideEffects": [
69
77
  "./**/*.dev.js"
70
78
  ],
71
- "gitHead": "1a8b294911ab377fa4f07e16eb016f1e3bf7b517"
79
+ "gitHead": "15588c72c774b17cfac605b20ac52a27d123bd03"
72
80
  }
package/src/Color.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import type { ReactiveElement } from 'lit';
2
+ import { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor } from '@ctrl/tinycolor';
3
+ export type { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor };
4
+ export declare type ColorValue = string | number | TinyColor | HSVA | HSV | RGB | RGBA | HSL | HSLA;
5
+ export declare const extractHueAndSaturationRegExp: RegExp;
6
+ export declare const replaceHueAndSaturationRegExp: RegExp;
7
+ export declare const replaceHueRegExp: RegExp;
8
+ export declare class ColorController {
9
+ protected host: ReactiveElement;
10
+ protected applyColorToState: ({ h, s, v, }: {
11
+ h: number;
12
+ s: number;
13
+ v: number;
14
+ }) => void;
15
+ protected extractColorFromState: (controller: ColorController) => ColorValue;
16
+ protected setColorProcess(currentColor: TinyColor, nextColor: ColorValue, format: string, isString: boolean): void;
17
+ protected setColorMaintainHue(currentColor: TinyColor, nextColor: ColorValue, format: string, isString: boolean): void;
18
+ protected setColorMaintainSaturation(currentColor: TinyColor, nextColor: ColorValue, format: string, isString: boolean): void;
19
+ protected maintains: 'hue' | 'saturation';
20
+ private saturation;
21
+ constructor(host: ReactiveElement, { applyColorToState, extractColorFromState, maintains, }: {
22
+ applyColorToState({ h, s, v, }: {
23
+ h: number;
24
+ s: number;
25
+ v: number;
26
+ }): void;
27
+ extractColorFromState(controller: ColorController): ColorValue;
28
+ maintains?: 'hue' | 'saturation';
29
+ });
30
+ applyColorFromState(): void;
31
+ get hue(): number;
32
+ set hue(value: number);
33
+ private _hue;
34
+ protected getColorProcesses: Record<string, (color: TinyColor, isString: boolean) => ColorValue>;
35
+ get value(): ColorValue;
36
+ get color(): ColorValue;
37
+ set color(color: ColorValue);
38
+ private _color;
39
+ getColor(format: string): ColorValue;
40
+ setColor(color: TinyColor): void;
41
+ getHslString(): string;
42
+ private _previousColor;
43
+ savePreviousColor(): void;
44
+ restorePreviousColor(): void;
45
+ private _format;
46
+ }
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ import { TinyColor } from "@ctrl/tinycolor";
3
+ export const extractHueAndSaturationRegExp = /^hs[v|l]a?\s?\((\d{1,3}\.?\d*?),?\s?(\d{1,3})/;
4
+ export const replaceHueAndSaturationRegExp = /(^hs[v|l]a?\s?\()\d{1,3}\.?\d*?(,?\s?)\d{1,3}/;
5
+ export const replaceHueRegExp = /(^hs[v|l]a?\()\d{1,3}/;
6
+ const getHexValue = (color, isString) => isString ? color.toHexString() : color.toHex();
7
+ export class ColorController {
8
+ constructor(host, {
9
+ applyColorToState,
10
+ extractColorFromState,
11
+ maintains
12
+ }) {
13
+ this.maintains = "hue";
14
+ this._hue = 0;
15
+ this.getColorProcesses = {
16
+ rgb: (color, isString) => isString ? color.toRgbString() : color.toRgb(),
17
+ prgb: (color, isString) => isString ? color.toPercentageRgbString() : color.toPercentageRgb(),
18
+ hex8: (color, isString) => isString ? color.toHex8String() : color.toHex8(),
19
+ name: (color) => color.toName() || color.toRgbString(),
20
+ hsl: (color, isString) => {
21
+ if (this.maintains === "hue") {
22
+ if (isString) {
23
+ const hslString = color.toHslString();
24
+ return hslString.replace(replaceHueRegExp, `$1${this.hue}`);
25
+ } else {
26
+ const { s, l, a } = color.toHsl();
27
+ return { h: this.hue, s, l, a };
28
+ }
29
+ } else {
30
+ if (isString) {
31
+ const hslString = color.toHslString();
32
+ return hslString.replace(
33
+ replaceHueAndSaturationRegExp,
34
+ `$1${this.hue}$2${this.saturation}`
35
+ );
36
+ } else {
37
+ const { s, l, a } = color.toHsl();
38
+ return { h: this.hue, s, l, a };
39
+ }
40
+ }
41
+ },
42
+ hsv: (color, isString) => {
43
+ if (this.maintains === "hue") {
44
+ if (isString) {
45
+ const hsvString = color.toHsvString();
46
+ return hsvString.replace(replaceHueRegExp, `$1${this.hue}`);
47
+ } else {
48
+ const { s, v, a } = color.toHsv();
49
+ return { h: this.hue, s, v, a };
50
+ }
51
+ } else {
52
+ if (isString) {
53
+ const hsvString = color.toHsvString();
54
+ return hsvString.replace(
55
+ replaceHueAndSaturationRegExp,
56
+ `$1${this.hue}$2${this.saturation}`
57
+ );
58
+ } else {
59
+ const { s, v, a } = color.toHsv();
60
+ return { h: this.hue, s, v, a };
61
+ }
62
+ }
63
+ },
64
+ hex: getHexValue,
65
+ hex3: getHexValue,
66
+ hex4: getHexValue,
67
+ hex6: getHexValue
68
+ };
69
+ this._color = new TinyColor({ h: 0, s: 1, v: 1 });
70
+ this._previousColor = new TinyColor({ h: 0, s: 1, v: 1 });
71
+ this._format = {
72
+ format: "",
73
+ isString: false
74
+ };
75
+ this.host = host;
76
+ this.applyColorToState = applyColorToState;
77
+ this.extractColorFromState = extractColorFromState;
78
+ this.maintains = maintains || this.maintains;
79
+ }
80
+ setColorProcess(currentColor, nextColor, format, isString) {
81
+ if (this.maintains === "hue") {
82
+ this.setColorMaintainHue(currentColor, nextColor, format, isString);
83
+ } else if (this.maintains === "saturation") {
84
+ this.setColorMaintainSaturation(
85
+ currentColor,
86
+ nextColor,
87
+ format,
88
+ isString
89
+ );
90
+ }
91
+ }
92
+ setColorMaintainHue(currentColor, nextColor, format, isString) {
93
+ const { h, s, v } = this._color.toHsv();
94
+ let originalHue = void 0;
95
+ if (isString && format.startsWith("hs")) {
96
+ const values = extractHueAndSaturationRegExp.exec(
97
+ nextColor
98
+ );
99
+ if (values !== null) {
100
+ const [, h2] = values;
101
+ originalHue = Number(h2);
102
+ }
103
+ } else if (!isString && format.startsWith("hs")) {
104
+ const colorInput = currentColor.originalInput;
105
+ const colorValues = Object.values(colorInput);
106
+ originalHue = colorValues[0];
107
+ }
108
+ this.hue = originalHue || h;
109
+ this.applyColorToState({ h, s, v });
110
+ }
111
+ setColorMaintainSaturation(currentColor, nextColor, format, isString) {
112
+ if (isString && format.startsWith("hs")) {
113
+ const values = extractHueAndSaturationRegExp.exec(
114
+ nextColor
115
+ );
116
+ if (values !== null) {
117
+ const [, h, s] = values;
118
+ this.hue = Number(h);
119
+ this.saturation = Number(s);
120
+ }
121
+ } else if (!isString && format.startsWith("hs")) {
122
+ const colorInput = currentColor.originalInput;
123
+ const colorValues = Object.values(colorInput);
124
+ this.hue = colorValues[0];
125
+ this.saturation = colorValues[1];
126
+ } else {
127
+ const { h } = currentColor.toHsv();
128
+ this.hue = h;
129
+ }
130
+ this.applyColorToState(currentColor.toHsv());
131
+ }
132
+ applyColorFromState() {
133
+ this._color = new TinyColor(this.extractColorFromState(this));
134
+ }
135
+ get hue() {
136
+ return this._hue;
137
+ }
138
+ set hue(value) {
139
+ const hue = Math.min(360, Math.max(0, value));
140
+ if (hue === this.hue) {
141
+ return;
142
+ }
143
+ const oldValue = this.hue;
144
+ const { s, v } = this._color.toHsv();
145
+ this._color = new TinyColor({ h: hue, s, v });
146
+ this._hue = hue;
147
+ this.host.requestUpdate("hue", oldValue);
148
+ }
149
+ get value() {
150
+ return this.color;
151
+ }
152
+ get color() {
153
+ return this.getColorProcesses[this._format.format || "hex"](
154
+ this._color,
155
+ this._format.isString
156
+ );
157
+ }
158
+ set color(color) {
159
+ if (color === this.color) {
160
+ return;
161
+ }
162
+ const oldValue = this._color;
163
+ this._color = new TinyColor(color);
164
+ const format = this._color.format;
165
+ let isString = typeof color === "string" || color instanceof String;
166
+ if (format.startsWith("hex")) {
167
+ isString = color.startsWith("#");
168
+ }
169
+ this._format = {
170
+ format,
171
+ isString
172
+ };
173
+ this.setColorProcess(this._color, color, format, isString);
174
+ this.host.requestUpdate("color", oldValue);
175
+ }
176
+ getColor(format) {
177
+ const formatOptions = {
178
+ hsl: "toHsl"
179
+ };
180
+ return this._color[formatOptions[format]]();
181
+ }
182
+ setColor(color) {
183
+ this._color = color;
184
+ const isString = typeof this._color.originalInput === "string" || this._color.originalInput instanceof String;
185
+ this.setColorProcess(this._color, color, this._color.format, isString);
186
+ }
187
+ getHslString() {
188
+ return this._color.toHslString();
189
+ }
190
+ savePreviousColor() {
191
+ this._previousColor = this._color.clone();
192
+ }
193
+ restorePreviousColor() {
194
+ this.setColor(this._previousColor);
195
+ }
196
+ }
197
+ //# sourceMappingURL=Color.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["Color.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 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 type { ReactiveElement } from 'lit';\nimport { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor } from '@ctrl/tinycolor';\nexport type { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor };\n\nexport type ColorValue =\n | string\n | number\n | TinyColor\n | HSVA\n | HSV\n | RGB\n | RGBA\n | HSL\n | HSLA;\n\nexport const extractHueAndSaturationRegExp =\n /^hs[v|l]a?\\s?\\((\\d{1,3}\\.?\\d*?),?\\s?(\\d{1,3})/;\nexport const replaceHueAndSaturationRegExp =\n /(^hs[v|l]a?\\s?\\()\\d{1,3}\\.?\\d*?(,?\\s?)\\d{1,3}/;\nexport const replaceHueRegExp = /(^hs[v|l]a?\\()\\d{1,3}/;\n\ntype TinyColorToValue = {\n toHex: ColorValue;\n toHexString: ColorValue;\n toHsv: ColorValue;\n toHsvString: ColorValue;\n toHsl: ColorValue;\n toHslString: ColorValue;\n toHex8: ColorValue;\n toHex8String: ColorValue;\n toPercentageRgb: ColorValue;\n toPercentageRgbString: ColorValue;\n toRgb: ColorValue;\n toRgbString: ColorValue;\n};\n\nconst getHexValue = (color: TinyColor, isString: boolean): ColorValue =>\n isString ? color.toHexString() : color.toHex();\n\nexport class ColorController {\n protected host: ReactiveElement;\n\n protected applyColorToState!: ({\n h,\n s,\n v,\n }: {\n h: number;\n s: number;\n v: number;\n }) => void;\n\n protected extractColorFromState!: (\n controller: ColorController\n ) => ColorValue;\n\n protected setColorProcess(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n if (this.maintains === 'hue') {\n this.setColorMaintainHue(currentColor, nextColor, format, isString);\n } else if (this.maintains === 'saturation') {\n this.setColorMaintainSaturation(\n currentColor,\n nextColor,\n format,\n isString\n );\n }\n }\n\n protected setColorMaintainHue(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n const { h, s, v } = this._color.toHsv();\n let originalHue: number | undefined = undefined;\n\n if (isString && format.startsWith('hs')) {\n const values = extractHueAndSaturationRegExp.exec(\n nextColor as string\n );\n\n if (values !== null) {\n const [, h] = values;\n originalHue = Number(h);\n }\n } else if (!isString && format.startsWith('hs')) {\n const colorInput = currentColor.originalInput;\n const colorValues = Object.values(colorInput);\n originalHue = colorValues[0];\n }\n\n this.hue = originalHue || h;\n this.applyColorToState({ h, s, v });\n }\n\n protected setColorMaintainSaturation(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n if (isString && format.startsWith('hs')) {\n const values = extractHueAndSaturationRegExp.exec(\n nextColor as string\n );\n\n if (values !== null) {\n const [, h, s] = values;\n this.hue = Number(h);\n this.saturation = Number(s);\n }\n } else if (!isString && format.startsWith('hs')) {\n const colorInput = currentColor.originalInput;\n const colorValues = Object.values(colorInput);\n this.hue = colorValues[0];\n this.saturation = colorValues[1];\n } else {\n const { h } = currentColor.toHsv();\n this.hue = h;\n }\n this.applyColorToState(currentColor.toHsv());\n }\n\n protected maintains: 'hue' | 'saturation' = 'hue';\n private saturation!: number;\n\n constructor(\n host: ReactiveElement,\n {\n applyColorToState,\n extractColorFromState,\n maintains,\n }: {\n applyColorToState({\n h,\n s,\n v,\n }: {\n h: number;\n s: number;\n v: number;\n }): void;\n extractColorFromState(controller: ColorController): ColorValue;\n maintains?: 'hue' | 'saturation';\n }\n ) {\n this.host = host;\n this.applyColorToState = applyColorToState;\n this.extractColorFromState = extractColorFromState;\n this.maintains = maintains || this.maintains;\n }\n\n public applyColorFromState(): void {\n this._color = new TinyColor(this.extractColorFromState(this));\n }\n\n public get hue(): number {\n return this._hue;\n }\n\n public set hue(value: number) {\n const hue = Math.min(360, Math.max(0, value));\n if (hue === this.hue) {\n return;\n }\n const oldValue = this.hue;\n const { s, v } = this._color.toHsv();\n this._color = new TinyColor({ h: hue, s, v });\n this._hue = hue;\n this.host.requestUpdate('hue', oldValue);\n }\n\n private _hue = 0;\n\n protected getColorProcesses: Record<\n string,\n (color: TinyColor, isString: boolean) => ColorValue\n > = {\n rgb: (color, isString) =>\n isString ? color.toRgbString() : color.toRgb(),\n prgb: (color, isString) =>\n isString ? color.toPercentageRgbString() : color.toPercentageRgb(),\n hex8: (color, isString) =>\n isString ? color.toHex8String() : color.toHex8(),\n name: (color) => color.toName() || color.toRgbString(),\n hsl: (color, isString) => {\n if (this.maintains === 'hue') {\n if (isString) {\n const hslString = color.toHslString();\n return hslString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, l, a } = color.toHsl();\n return { h: this.hue, s, l, a };\n }\n } else {\n if (isString) {\n const hslString = color.toHslString();\n return hslString.replace(\n replaceHueAndSaturationRegExp,\n `$1${this.hue}$2${this.saturation}`\n );\n } else {\n const { s, l, a } = color.toHsl();\n return { h: this.hue, s, l, a };\n }\n }\n },\n hsv: (color, isString) => {\n if (this.maintains === 'hue') {\n if (isString) {\n const hsvString = color.toHsvString();\n return hsvString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, v, a } = color.toHsv();\n return { h: this.hue, s, v, a };\n }\n } else {\n if (isString) {\n const hsvString = color.toHsvString();\n return hsvString.replace(\n replaceHueAndSaturationRegExp,\n `$1${this.hue}$2${this.saturation}`\n );\n } else {\n const { s, v, a } = color.toHsv();\n return { h: this.hue, s, v, a };\n }\n }\n },\n hex: getHexValue,\n hex3: getHexValue,\n hex4: getHexValue,\n hex6: getHexValue,\n };\n\n public get value(): ColorValue {\n return this.color;\n }\n\n public get color(): ColorValue {\n return this.getColorProcesses[this._format.format || 'hex'](\n this._color,\n this._format.isString\n );\n }\n\n public set color(color: ColorValue) {\n if (color === this.color) {\n return;\n }\n const oldValue = this._color;\n this._color = new TinyColor(color);\n const format = this._color.format;\n let isString = typeof color === 'string' || color instanceof String;\n\n if (format.startsWith('hex')) {\n isString = (color as string).startsWith('#');\n }\n\n this._format = {\n format,\n isString,\n };\n\n this.setColorProcess(this._color, color, format, isString);\n this.host.requestUpdate('color', oldValue);\n }\n\n private _color = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public getColor(format: string): ColorValue {\n const formatOptions: Record<string, keyof TinyColorToValue> = {\n hsl: 'toHsl',\n };\n return this._color[formatOptions[format]]();\n }\n\n public setColor(color: TinyColor): void {\n this._color = color;\n const isString =\n typeof this._color.originalInput === 'string' ||\n this._color.originalInput instanceof String;\n this.setColorProcess(this._color, color, this._color.format, isString);\n }\n\n public getHslString(): string {\n return this._color.toHslString();\n }\n\n private _previousColor = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n public restorePreviousColor(): void {\n this.setColor(this._previousColor);\n }\n\n private _format: { format: string; isString: boolean } = {\n format: '',\n isString: false,\n };\n}\n"],
5
+ "mappings": ";AAaA,SAA0C,iBAAiB;AAcpD,aAAM,gCACT;AACG,aAAM,gCACT;AACG,aAAM,mBAAmB;AAiBhC,MAAM,cAAc,CAAC,OAAkB,aACnC,WAAW,MAAM,YAAY,IAAI,MAAM,MAAM;AAE1C,aAAM,gBAAgB;AAAA,EA8FzB,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAaF;AAtBF,SAAU,YAAkC;AAiD5C,SAAQ,OAAO;AAEf,SAAU,oBAGN;AAAA,MACA,KAAK,CAAC,OAAO,aACT,WAAW,MAAM,YAAY,IAAI,MAAM,MAAM;AAAA,MACjD,MAAM,CAAC,OAAO,aACV,WAAW,MAAM,sBAAsB,IAAI,MAAM,gBAAgB;AAAA,MACrE,MAAM,CAAC,OAAO,aACV,WAAW,MAAM,aAAa,IAAI,MAAM,OAAO;AAAA,MACnD,MAAM,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,YAAY;AAAA,MACrD,KAAK,CAAC,OAAO,aAAa;AACtB,YAAI,KAAK,cAAc,OAAO;AAC1B,cAAI,UAAU;AACV,kBAAM,YAAY,MAAM,YAAY;AACpC,mBAAO,UAAU,QAAQ,kBAAkB,KAAK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;AACjC,UAAM,SAAS,KAAK,OAAO;AAC3B,QAAI,WAAW,OAAO,UAAU,YAAY,iBAAiB;AAE7D,QAAI,OAAO,WAAW,KAAK,GAAG;AAC1B,iBAAY,MAAiB,WAAW,GAAG;AAAA,IAC/C;AAEA,SAAK,UAAU;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAEA,SAAK,gBAAgB,KAAK,QAAQ,OAAO,QAAQ,QAAQ;AACzD,SAAK,KAAK,cAAc,SAAS,QAAQ;AAAA,EAC7C;AAAA,EAIO,SAAS,QAA4B;AACxC,UAAM,gBAAwD;AAAA,MAC1D,KAAK;AAAA,IACT;AACA,WAAO,KAAK,OAAO,cAAc,SAAS;AAAA,EAC9C;AAAA,EAEO,SAAS,OAAwB;AACpC,SAAK,SAAS;AACd,UAAM,WACF,OAAO,KAAK,OAAO,kBAAkB,YACrC,KAAK,OAAO,yBAAyB;AACzC,SAAK,gBAAgB,KAAK,QAAQ,OAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,EACzE;AAAA,EAEO,eAAuB;AAC1B,WAAO,KAAK,OAAO,YAAY;AAAA,EACnC;AAAA,EAIO,oBAA0B;AAC7B,SAAK,iBAAiB,KAAK,OAAO,MAAM;AAAA,EAC5C;AAAA,EAEO,uBAA6B;AAChC,SAAK,SAAS,KAAK,cAAc;AAAA,EACrC;AAMJ;",
6
+ "names": ["h"]
7
+ }
package/src/Color.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";import{TinyColor as l}from"@ctrl/tinycolor";export const extractHueAndSaturationRegExp=/^hs[v|l]a?\s?\((\d{1,3}\.?\d*?),?\s?(\d{1,3})/,replaceHueAndSaturationRegExp=/(^hs[v|l]a?\s?\()\d{1,3}\.?\d*?(,?\s?)\d{1,3}/,replaceHueRegExp=/(^hs[v|l]a?\()\d{1,3}/;const a=(h,t)=>t?h.toHexString():h.toHex();export class ColorController{constructor(t,{applyColorToState:o,extractColorFromState:e,maintains:r}){this.maintains="hue";this._hue=0;this.getColorProcesses={rgb:(t,o)=>o?t.toRgbString():t.toRgb(),prgb:(t,o)=>o?t.toPercentageRgbString():t.toPercentageRgb(),hex8:(t,o)=>o?t.toHex8String():t.toHex8(),name:t=>t.toName()||t.toRgbString(),hsl:(t,o)=>{if(this.maintains==="hue"){if(o)return t.toHslString().replace(replaceHueRegExp,`$1${this.hue}`);{const{s:e,l:r,a:s}=t.toHsl();return{h:this.hue,s:e,l:r,a:s}}}else{if(o)return t.toHslString().replace(replaceHueAndSaturationRegExp,`$1${this.hue}$2${this.saturation}`);{const{s:e,l:r,a:s}=t.toHsl();return{h:this.hue,s:e,l:r,a:s}}}},hsv:(t,o)=>{if(this.maintains==="hue"){if(o)return t.toHsvString().replace(replaceHueRegExp,`$1${this.hue}`);{const{s:e,v:r,a:s}=t.toHsv();return{h:this.hue,s:e,v:r,a:s}}}else{if(o)return t.toHsvString().replace(replaceHueAndSaturationRegExp,`$1${this.hue}$2${this.saturation}`);{const{s:e,v:r,a:s}=t.toHsv();return{h:this.hue,s:e,v:r,a:s}}}},hex:a,hex3:a,hex4:a,hex6:a};this._color=new l({h:0,s:1,v:1});this._previousColor=new l({h:0,s:1,v:1});this._format={format:"",isString:!1};this.host=t,this.applyColorToState=o,this.extractColorFromState=e,this.maintains=r||this.maintains}setColorProcess(t,o,e,r){this.maintains==="hue"?this.setColorMaintainHue(t,o,e,r):this.maintains==="saturation"&&this.setColorMaintainSaturation(t,o,e,r)}setColorMaintainHue(t,o,e,r){const{h:s,s:i,v:u}=this._color.toHsv();let c;if(r&&e.startsWith("hs")){const n=extractHueAndSaturationRegExp.exec(o);if(n!==null){const[,g]=n;c=Number(g)}}else if(!r&&e.startsWith("hs")){const n=t.originalInput;c=Object.values(n)[0]}this.hue=c||s,this.applyColorToState({h:s,s:i,v:u})}setColorMaintainSaturation(t,o,e,r){if(r&&e.startsWith("hs")){const s=extractHueAndSaturationRegExp.exec(o);if(s!==null){const[,i,u]=s;this.hue=Number(i),this.saturation=Number(u)}}else if(!r&&e.startsWith("hs")){const s=t.originalInput,i=Object.values(s);this.hue=i[0],this.saturation=i[1]}else{const{h:s}=t.toHsv();this.hue=s}this.applyColorToState(t.toHsv())}applyColorFromState(){this._color=new l(this.extractColorFromState(this))}get hue(){return this._hue}set hue(t){const o=Math.min(360,Math.max(0,t));if(o===this.hue)return;const e=this.hue,{s:r,v:s}=this._color.toHsv();this._color=new l({h:o,s:r,v:s}),this._hue=o,this.host.requestUpdate("hue",e)}get value(){return this.color}get color(){return this.getColorProcesses[this._format.format||"hex"](this._color,this._format.isString)}set color(t){if(t===this.color)return;const o=this._color;this._color=new l(t);const e=this._color.format;let r=typeof t=="string"||t instanceof String;e.startsWith("hex")&&(r=t.startsWith("#")),this._format={format:e,isString:r},this.setColorProcess(this._color,t,e,r),this.host.requestUpdate("color",o)}getColor(t){const o={hsl:"toHsl"};return this._color[o[t]]()}setColor(t){this._color=t;const o=typeof this._color.originalInput=="string"||this._color.originalInput instanceof String;this.setColorProcess(this._color,t,this._color.format,o)}getHslString(){return this._color.toHslString()}savePreviousColor(){this._previousColor=this._color.clone()}restorePreviousColor(){this.setColor(this._previousColor)}}
2
+ //# sourceMappingURL=Color.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["Color.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 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 type { ReactiveElement } from 'lit';\nimport { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor } from '@ctrl/tinycolor';\nexport type { HSL, HSLA, HSV, HSVA, RGB, RGBA, TinyColor };\n\nexport type ColorValue =\n | string\n | number\n | TinyColor\n | HSVA\n | HSV\n | RGB\n | RGBA\n | HSL\n | HSLA;\n\nexport const extractHueAndSaturationRegExp =\n /^hs[v|l]a?\\s?\\((\\d{1,3}\\.?\\d*?),?\\s?(\\d{1,3})/;\nexport const replaceHueAndSaturationRegExp =\n /(^hs[v|l]a?\\s?\\()\\d{1,3}\\.?\\d*?(,?\\s?)\\d{1,3}/;\nexport const replaceHueRegExp = /(^hs[v|l]a?\\()\\d{1,3}/;\n\ntype TinyColorToValue = {\n toHex: ColorValue;\n toHexString: ColorValue;\n toHsv: ColorValue;\n toHsvString: ColorValue;\n toHsl: ColorValue;\n toHslString: ColorValue;\n toHex8: ColorValue;\n toHex8String: ColorValue;\n toPercentageRgb: ColorValue;\n toPercentageRgbString: ColorValue;\n toRgb: ColorValue;\n toRgbString: ColorValue;\n};\n\nconst getHexValue = (color: TinyColor, isString: boolean): ColorValue =>\n isString ? color.toHexString() : color.toHex();\n\nexport class ColorController {\n protected host: ReactiveElement;\n\n protected applyColorToState!: ({\n h,\n s,\n v,\n }: {\n h: number;\n s: number;\n v: number;\n }) => void;\n\n protected extractColorFromState!: (\n controller: ColorController\n ) => ColorValue;\n\n protected setColorProcess(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n if (this.maintains === 'hue') {\n this.setColorMaintainHue(currentColor, nextColor, format, isString);\n } else if (this.maintains === 'saturation') {\n this.setColorMaintainSaturation(\n currentColor,\n nextColor,\n format,\n isString\n );\n }\n }\n\n protected setColorMaintainHue(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n const { h, s, v } = this._color.toHsv();\n let originalHue: number | undefined = undefined;\n\n if (isString && format.startsWith('hs')) {\n const values = extractHueAndSaturationRegExp.exec(\n nextColor as string\n );\n\n if (values !== null) {\n const [, h] = values;\n originalHue = Number(h);\n }\n } else if (!isString && format.startsWith('hs')) {\n const colorInput = currentColor.originalInput;\n const colorValues = Object.values(colorInput);\n originalHue = colorValues[0];\n }\n\n this.hue = originalHue || h;\n this.applyColorToState({ h, s, v });\n }\n\n protected setColorMaintainSaturation(\n currentColor: TinyColor,\n nextColor: ColorValue,\n format: string,\n isString: boolean\n ): void {\n if (isString && format.startsWith('hs')) {\n const values = extractHueAndSaturationRegExp.exec(\n nextColor as string\n );\n\n if (values !== null) {\n const [, h, s] = values;\n this.hue = Number(h);\n this.saturation = Number(s);\n }\n } else if (!isString && format.startsWith('hs')) {\n const colorInput = currentColor.originalInput;\n const colorValues = Object.values(colorInput);\n this.hue = colorValues[0];\n this.saturation = colorValues[1];\n } else {\n const { h } = currentColor.toHsv();\n this.hue = h;\n }\n this.applyColorToState(currentColor.toHsv());\n }\n\n protected maintains: 'hue' | 'saturation' = 'hue';\n private saturation!: number;\n\n constructor(\n host: ReactiveElement,\n {\n applyColorToState,\n extractColorFromState,\n maintains,\n }: {\n applyColorToState({\n h,\n s,\n v,\n }: {\n h: number;\n s: number;\n v: number;\n }): void;\n extractColorFromState(controller: ColorController): ColorValue;\n maintains?: 'hue' | 'saturation';\n }\n ) {\n this.host = host;\n this.applyColorToState = applyColorToState;\n this.extractColorFromState = extractColorFromState;\n this.maintains = maintains || this.maintains;\n }\n\n public applyColorFromState(): void {\n this._color = new TinyColor(this.extractColorFromState(this));\n }\n\n public get hue(): number {\n return this._hue;\n }\n\n public set hue(value: number) {\n const hue = Math.min(360, Math.max(0, value));\n if (hue === this.hue) {\n return;\n }\n const oldValue = this.hue;\n const { s, v } = this._color.toHsv();\n this._color = new TinyColor({ h: hue, s, v });\n this._hue = hue;\n this.host.requestUpdate('hue', oldValue);\n }\n\n private _hue = 0;\n\n protected getColorProcesses: Record<\n string,\n (color: TinyColor, isString: boolean) => ColorValue\n > = {\n rgb: (color, isString) =>\n isString ? color.toRgbString() : color.toRgb(),\n prgb: (color, isString) =>\n isString ? color.toPercentageRgbString() : color.toPercentageRgb(),\n hex8: (color, isString) =>\n isString ? color.toHex8String() : color.toHex8(),\n name: (color) => color.toName() || color.toRgbString(),\n hsl: (color, isString) => {\n if (this.maintains === 'hue') {\n if (isString) {\n const hslString = color.toHslString();\n return hslString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, l, a } = color.toHsl();\n return { h: this.hue, s, l, a };\n }\n } else {\n if (isString) {\n const hslString = color.toHslString();\n return hslString.replace(\n replaceHueAndSaturationRegExp,\n `$1${this.hue}$2${this.saturation}`\n );\n } else {\n const { s, l, a } = color.toHsl();\n return { h: this.hue, s, l, a };\n }\n }\n },\n hsv: (color, isString) => {\n if (this.maintains === 'hue') {\n if (isString) {\n const hsvString = color.toHsvString();\n return hsvString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, v, a } = color.toHsv();\n return { h: this.hue, s, v, a };\n }\n } else {\n if (isString) {\n const hsvString = color.toHsvString();\n return hsvString.replace(\n replaceHueAndSaturationRegExp,\n `$1${this.hue}$2${this.saturation}`\n );\n } else {\n const { s, v, a } = color.toHsv();\n return { h: this.hue, s, v, a };\n }\n }\n },\n hex: getHexValue,\n hex3: getHexValue,\n hex4: getHexValue,\n hex6: getHexValue,\n };\n\n public get value(): ColorValue {\n return this.color;\n }\n\n public get color(): ColorValue {\n return this.getColorProcesses[this._format.format || 'hex'](\n this._color,\n this._format.isString\n );\n }\n\n public set color(color: ColorValue) {\n if (color === this.color) {\n return;\n }\n const oldValue = this._color;\n this._color = new TinyColor(color);\n const format = this._color.format;\n let isString = typeof color === 'string' || color instanceof String;\n\n if (format.startsWith('hex')) {\n isString = (color as string).startsWith('#');\n }\n\n this._format = {\n format,\n isString,\n };\n\n this.setColorProcess(this._color, color, format, isString);\n this.host.requestUpdate('color', oldValue);\n }\n\n private _color = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public getColor(format: string): ColorValue {\n const formatOptions: Record<string, keyof TinyColorToValue> = {\n hsl: 'toHsl',\n };\n return this._color[formatOptions[format]]();\n }\n\n public setColor(color: TinyColor): void {\n this._color = color;\n const isString =\n typeof this._color.originalInput === 'string' ||\n this._color.originalInput instanceof String;\n this.setColorProcess(this._color, color, this._color.format, isString);\n }\n\n public getHslString(): string {\n return this._color.toHslString();\n }\n\n private _previousColor = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n public restorePreviousColor(): void {\n this.setColor(this._previousColor);\n }\n\n private _format: { format: string; isString: boolean } = {\n format: '',\n isString: false,\n };\n}\n"],
5
+ "mappings": "aAaA,OAA0C,aAAAA,MAAiB,kBAcpD,aAAM,8BACT,gDACS,8BACT,gDACS,iBAAmB,wBAiBhC,MAAMC,EAAc,CAACC,EAAkBC,IACnCA,EAAWD,EAAM,YAAY,EAAIA,EAAM,MAAM,EAE1C,aAAM,eAAgB,CA8FzB,YACIE,EACA,CACI,kBAAAC,EACA,sBAAAC,EACA,UAAAC,CACJ,EAaF,CAtBF,KAAU,UAAkC,MAiD5C,KAAQ,KAAO,EAEf,KAAU,kBAGN,CACA,IAAK,CAACL,EAAOC,IACTA,EAAWD,EAAM,YAAY,EAAIA,EAAM,MAAM,EACjD,KAAM,CAACA,EAAOC,IACVA,EAAWD,EAAM,sBAAsB,EAAIA,EAAM,gBAAgB,EACrE,KAAM,CAACA,EAAOC,IACVA,EAAWD,EAAM,aAAa,EAAIA,EAAM,OAAO,EACnD,KAAOA,GAAUA,EAAM,OAAO,GAAKA,EAAM,YAAY,EACrD,IAAK,CAACA,EAAOC,IAAa,CACtB,GAAI,KAAK,YAAc,MAAO,CAC1B,GAAIA,EAEA,OADkBD,EAAM,YAAY,EACnB,QAAQ,iBAAkB,KAAK,KAAK,KAAK,EACvD,CACH,KAAM,CAAE,EAAAM,EAAG,EAAAC,EAAG,EAAAC,CAAE,EAAIR,EAAM,MAAM,EAChC,MAAO,CAAE,EAAG,KAAK,IAAK,EAAAM,EAAG,EAAAC,EAAG,EAAAC,CAAE,CAClC,CACJ,KAAO,CACH,GAAIP,EAEA,OADkBD,EAAM,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rC,KAAK,OAAO,yBAAyB,OACzC,KAAK,gBAAgB,KAAK,OAAQD,EAAO,KAAK,OAAO,OAAQC,CAAQ,CACzE,CAEO,cAAuB,CAC1B,OAAO,KAAK,OAAO,YAAY,CACnC,CAIO,mBAA0B,CAC7B,KAAK,eAAiB,KAAK,OAAO,MAAM,CAC5C,CAEO,sBAA6B,CAChC,KAAK,SAAS,KAAK,cAAc,CACrC,CAMJ",
6
+ "names": ["TinyColor", "getHexValue", "color", "isString", "host", "applyColorToState", "extractColorFromState", "maintains", "s", "l", "a", "v", "currentColor", "nextColor", "format", "h", "originalHue", "values", "colorInput", "colorValues", "value", "hue", "oldValue", "formatOptions"]
7
+ }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  export class FocusGroupController {
2
3
  constructor(host, {
3
4
  direction,
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["FocusGroup.ts"],
4
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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\ntype DirectionTypes = 'horizontal' | 'vertical' | 'both' | 'grid';\nexport type FocusGroupConfig<T> = {\n focusInIndex?: (_elements: T[]) => number;\n direction?: DirectionTypes | (() => DirectionTypes);\n elementEnterAction?: (el: T) => void;\n elements: () => T[];\n isFocusableElement?: (el: T) => boolean;\n listenerScope?: HTMLElement | (() => HTMLElement);\n};\n\nexport class FocusGroupController<T extends HTMLElement>\n implements ReactiveController\n{\n protected cachedElements?: T[];\n\n get currentIndex(): number {\n if (this._currentIndex === -1) {\n this._currentIndex = this.focusInIndex;\n }\n return this._currentIndex - this.offset;\n }\n\n set currentIndex(currentIndex) {\n this._currentIndex = currentIndex + this.offset;\n }\n\n private _currentIndex = -1;\n\n get direction(): DirectionTypes {\n return this._direction();\n }\n\n _direction = (): DirectionTypes => 'both';\n\n public directionLength = 5;\n\n elementEnterAction = (_el: T): void => {\n return;\n };\n\n get elements(): T[] {\n if (!this.cachedElements) {\n this.cachedElements = this._elements();\n }\n return this.cachedElements;\n }\n\n private _elements!: () => T[];\n\n protected set focused(focused: boolean) {\n if (focused === this.focused) return;\n this._focused = focused;\n }\n\n protected get focused(): boolean {\n return this._focused;\n }\n\n private _focused = false;\n\n get focusInElement(): T {\n return this.elements[this.focusInIndex];\n }\n\n get focusInIndex(): number {\n return this._focusInIndex(this.elements);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _focusInIndex = (_elements: T[]): number => 0;\n\n host: ReactiveElement;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n isFocusableElement = (_el: T): boolean => true;\n\n isEventWithinListenerScope(event: Event): boolean {\n if (this._listenerScope() === this.host) return true;\n return event.composedPath().includes(this._listenerScope());\n }\n\n _listenerScope = (): HTMLElement => this.host;\n\n // When elements are virtualized, the delta between the first element\n // and the first rendered element.\n offset = 0;\n\n constructor(\n host: ReactiveElement,\n {\n direction,\n elementEnterAction,\n elements,\n focusInIndex,\n isFocusableElement,\n listenerScope,\n }: FocusGroupConfig<T> = { elements: () => [] }\n ) {\n this.host = host;\n this.host.addController(this);\n this._elements = elements;\n this.isFocusableElement = isFocusableElement || this.isFocusableElement;\n // @TODO: abstract a method to simplify the conditional wrapping of the values as functions.\n if (typeof direction === 'string') {\n this._direction = () => direction;\n } else if (typeof direction === 'function') {\n this._direction = direction;\n }\n this.elementEnterAction = elementEnterAction || this.elementEnterAction;\n if (typeof focusInIndex === 'number') {\n this._focusInIndex = () => focusInIndex;\n } else if (typeof focusInIndex === 'function') {\n this._focusInIndex = focusInIndex;\n }\n if (typeof listenerScope === 'object') {\n this._listenerScope = () => listenerScope;\n } else if (typeof listenerScope === 'function') {\n this._listenerScope = listenerScope;\n }\n }\n\n update({ elements }: FocusGroupConfig<T> = { elements: () => [] }): void {\n this.unmanage();\n this._elements = elements;\n this.clearElementCache();\n this.manage();\n }\n\n focus(options?: FocusOptions): void {\n let focusElement = this.elements[this.currentIndex];\n if (!focusElement || !this.isFocusableElement(focusElement)) {\n this.setCurrentIndexCircularly(1);\n focusElement = this.elements[this.currentIndex];\n }\n if (focusElement && this.isFocusableElement(focusElement)) {\n focusElement.focus(options);\n }\n }\n\n clearElementCache(offset = 0): void {\n delete this.cachedElements;\n this.offset = offset;\n }\n\n setCurrentIndexCircularly(diff: number): void {\n const { length } = this.elements;\n let steps = length;\n // start at a possibly not 0 index\n let nextIndex = (length + this.currentIndex + diff) % length;\n while (\n // don't cycle the elements more than once\n steps &&\n this.elements[nextIndex] &&\n !this.isFocusableElement(this.elements[nextIndex])\n ) {\n nextIndex = (length + nextIndex + diff) % length;\n steps -= 1;\n }\n this.currentIndex = nextIndex;\n }\n\n hostContainsFocus(): void {\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.addEventListener('keydown', this.handleKeydown);\n this.focused = true;\n }\n\n hostNoLongerContainsFocus(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n this.currentIndex = this.focusInIndex;\n this.focused = false;\n }\n\n isRelatedTargetAnElement(event: FocusEvent): boolean {\n const relatedTarget = event.relatedTarget as null | Element;\n return !this.elements.includes(relatedTarget as T);\n }\n\n handleFocusin = (event: FocusEvent): void => {\n if (!this.isEventWithinListenerScope(event)) return;\n if (this.isRelatedTargetAnElement(event)) {\n this.hostContainsFocus();\n }\n const path = event.composedPath() as T[];\n let targetIndex = -1;\n path.find((el) => {\n targetIndex = this.elements.indexOf(el);\n return targetIndex !== -1;\n });\n this.currentIndex = targetIndex > -1 ? targetIndex : this.currentIndex;\n };\n\n handleFocusout = (event: FocusEvent): void => {\n if (this.isRelatedTargetAnElement(event)) {\n this.hostNoLongerContainsFocus();\n }\n };\n\n acceptsEventCode(code: string): boolean {\n if (code === 'End' || code === 'Home') {\n return true;\n }\n switch (this.direction) {\n case 'horizontal':\n return code === 'ArrowLeft' || code === 'ArrowRight';\n case 'vertical':\n return code === 'ArrowUp' || code === 'ArrowDown';\n case 'both':\n case 'grid':\n return code.startsWith('Arrow');\n }\n }\n\n handleKeydown = (event: KeyboardEvent): void => {\n if (!this.acceptsEventCode(event.code) || event.defaultPrevented) {\n return;\n }\n let diff = 0;\n switch (event.code) {\n case 'ArrowRight':\n diff += 1;\n break;\n case 'ArrowDown':\n diff += this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'ArrowLeft':\n diff -= 1;\n break;\n case 'ArrowUp':\n diff -= this.direction === 'grid' ? this.directionLength : 1;\n break;\n case 'End':\n this.currentIndex = 0;\n diff -= 1;\n break;\n case 'Home':\n this.currentIndex = this.elements.length - 1;\n diff += 1;\n break;\n }\n event.preventDefault();\n if (this.direction === 'grid' && this.currentIndex + diff < 0) {\n this.currentIndex = 0;\n } else if (\n this.direction === 'grid' &&\n this.currentIndex + diff > this.elements.length - 1\n ) {\n this.currentIndex = this.elements.length - 1;\n } else {\n this.setCurrentIndexCircularly(diff);\n }\n // To allow the `focusInIndex` to be calculated with the \"after\" state of the keyboard interaction\n // do `elementEnterAction` _before_ focusing the next element.\n this.elementEnterAction(this.elements[this.currentIndex]);\n this.focus();\n };\n\n manage(): void {\n this.addEventListeners();\n }\n\n unmanage(): void {\n this.removeEventListeners();\n }\n\n addEventListeners(): void {\n this.host.addEventListener('focusin', this.handleFocusin);\n }\n\n removeEventListeners(): void {\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n this.host.removeEventListener('keydown', this.handleKeydown);\n }\n\n hostConnected(): void {\n this.addEventListeners();\n }\n\n hostDisconnected(): void {\n this.remov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,oBAAoB,YAAY,KAAK,cAAc;AAC7D,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAAA,EAC/D;AAAA,EAEA,gBAAsB;AAClB,SAAK,kBAAkB;AAAA,EAC3B;AAAA,EAEA,mBAAyB;AACrB,SAAK,qBAAqB;AAAA,EAC9B;AACJ;",
6
6
  "names": []
7
7
  }
package/src/FocusGroup.js CHANGED
@@ -1,217 +1,2 @@
1
- export class FocusGroupController {
2
- constructor(host, {
3
- direction,
4
- elementEnterAction,
5
- elements,
6
- focusInIndex,
7
- isFocusableElement,
8
- listenerScope
9
- } = { elements: () => [] }) {
10
- this._currentIndex = -1;
11
- this._direction = () => "both";
12
- this.directionLength = 5;
13
- this.elementEnterAction = (_el) => {
14
- return;
15
- };
16
- this._focused = false;
17
- this._focusInIndex = (_elements) => 0;
18
- this.isFocusableElement = (_el) => true;
19
- this._listenerScope = () => this.host;
20
- this.offset = 0;
21
- this.handleFocusin = (event) => {
22
- if (!this.isEventWithinListenerScope(event))
23
- return;
24
- if (this.isRelatedTargetAnElement(event)) {
25
- this.hostContainsFocus();
26
- }
27
- const path = event.composedPath();
28
- let targetIndex = -1;
29
- path.find((el) => {
30
- targetIndex = this.elements.indexOf(el);
31
- return targetIndex !== -1;
32
- });
33
- this.currentIndex = targetIndex > -1 ? targetIndex : this.currentIndex;
34
- };
35
- this.handleFocusout = (event) => {
36
- if (this.isRelatedTargetAnElement(event)) {
37
- this.hostNoLongerContainsFocus();
38
- }
39
- };
40
- this.handleKeydown = (event) => {
41
- if (!this.acceptsEventCode(event.code) || event.defaultPrevented) {
42
- return;
43
- }
44
- let diff = 0;
45
- switch (event.code) {
46
- case "ArrowRight":
47
- diff += 1;
48
- break;
49
- case "ArrowDown":
50
- diff += this.direction === "grid" ? this.directionLength : 1;
51
- break;
52
- case "ArrowLeft":
53
- diff -= 1;
54
- break;
55
- case "ArrowUp":
56
- diff -= this.direction === "grid" ? this.directionLength : 1;
57
- break;
58
- case "End":
59
- this.currentIndex = 0;
60
- diff -= 1;
61
- break;
62
- case "Home":
63
- this.currentIndex = this.elements.length - 1;
64
- diff += 1;
65
- break;
66
- }
67
- event.preventDefault();
68
- if (this.direction === "grid" && this.currentIndex + diff < 0) {
69
- this.currentIndex = 0;
70
- } else if (this.direction === "grid" && this.currentIndex + diff > this.elements.length - 1) {
71
- this.currentIndex = this.elements.length - 1;
72
- } else {
73
- this.setCurrentIndexCircularly(diff);
74
- }
75
- this.elementEnterAction(this.elements[this.currentIndex]);
76
- this.focus();
77
- };
78
- this.host = host;
79
- this.host.addController(this);
80
- this._elements = elements;
81
- this.isFocusableElement = isFocusableElement || this.isFocusableElement;
82
- if (typeof direction === "string") {
83
- this._direction = () => direction;
84
- } else if (typeof direction === "function") {
85
- this._direction = direction;
86
- }
87
- this.elementEnterAction = elementEnterAction || this.elementEnterAction;
88
- if (typeof focusInIndex === "number") {
89
- this._focusInIndex = () => focusInIndex;
90
- } else if (typeof focusInIndex === "function") {
91
- this._focusInIndex = focusInIndex;
92
- }
93
- if (typeof listenerScope === "object") {
94
- this._listenerScope = () => listenerScope;
95
- } else if (typeof listenerScope === "function") {
96
- this._listenerScope = listenerScope;
97
- }
98
- }
99
- get currentIndex() {
100
- if (this._currentIndex === -1) {
101
- this._currentIndex = this.focusInIndex;
102
- }
103
- return this._currentIndex - this.offset;
104
- }
105
- set currentIndex(currentIndex) {
106
- this._currentIndex = currentIndex + this.offset;
107
- }
108
- get direction() {
109
- return this._direction();
110
- }
111
- get elements() {
112
- if (!this.cachedElements) {
113
- this.cachedElements = this._elements();
114
- }
115
- return this.cachedElements;
116
- }
117
- set focused(focused) {
118
- if (focused === this.focused)
119
- return;
120
- this._focused = focused;
121
- }
122
- get focused() {
123
- return this._focused;
124
- }
125
- get focusInElement() {
126
- return this.elements[this.focusInIndex];
127
- }
128
- get focusInIndex() {
129
- return this._focusInIndex(this.elements);
130
- }
131
- isEventWithinListenerScope(event) {
132
- if (this._listenerScope() === this.host)
133
- return true;
134
- return event.composedPath().includes(this._listenerScope());
135
- }
136
- update({ elements } = { elements: () => [] }) {
137
- this.unmanage();
138
- this._elements = elements;
139
- this.clearElementCache();
140
- this.manage();
141
- }
142
- focus(options) {
143
- let focusElement = this.elements[this.currentIndex];
144
- if (!focusElement || !this.isFocusableElement(focusElement)) {
145
- this.setCurrentIndexCircularly(1);
146
- focusElement = this.elements[this.currentIndex];
147
- }
148
- if (focusElement && this.isFocusableElement(focusElement)) {
149
- focusElement.focus(options);
150
- }
151
- }
152
- clearElementCache(offset = 0) {
153
- delete this.cachedElements;
154
- this.offset = offset;
155
- }
156
- setCurrentIndexCircularly(diff) {
157
- const { length } = this.elements;
158
- let steps = length;
159
- let nextIndex = (length + this.currentIndex + diff) % length;
160
- while (steps && this.elements[nextIndex] && !this.isFocusableElement(this.elements[nextIndex])) {
161
- nextIndex = (length + nextIndex + diff) % length;
162
- steps -= 1;
163
- }
164
- this.currentIndex = nextIndex;
165
- }
166
- hostContainsFocus() {
167
- this.host.addEventListener("focusout", this.handleFocusout);
168
- this.host.addEventListener("keydown", this.handleKeydown);
169
- this.focused = true;
170
- }
171
- hostNoLongerContainsFocus() {
172
- this.host.addEventListener("focusin", this.handleFocusin);
173
- this.host.removeEventListener("focusout", this.handleFocusout);
174
- this.host.removeEventListener("keydown", this.handleKeydown);
175
- this.currentIndex = this.focusInIndex;
176
- this.focused = false;
177
- }
178
- isRelatedTargetAnElement(event) {
179
- const relatedTarget = event.relatedTarget;
180
- return !this.elements.includes(relatedTarget);
181
- }
182
- acceptsEventCode(code) {
183
- if (code === "End" || code === "Home") {
184
- return true;
185
- }
186
- switch (this.direction) {
187
- case "horizontal":
188
- return code === "ArrowLeft" || code === "ArrowRight";
189
- case "vertical":
190
- return code === "ArrowUp" || code === "ArrowDown";
191
- case "both":
192
- case "grid":
193
- return code.startsWith("Arrow");
194
- }
195
- }
196
- manage() {
197
- this.addEventListeners();
198
- }
199
- unmanage() {
200
- this.removeEventListeners();
201
- }
202
- addEventListeners() {
203
- this.host.addEventListener("focusin", this.handleFocusin);
204
- }
205
- removeEventListeners() {
206
- this.host.removeEventListener("focusin", this.handleFocusin);
207
- this.host.removeEventListener("focusout", this.handleFocusout);
208
- this.host.removeEventListener("keydown", this.handleKeydown);
209
- }
210
- hostConnected() {
211
- this.addEventListeners();
212
- }
213
- hostDisconnected() {
214
- this.removeEventListeners();
215
- }
216
- }
1
+ "use strict";export class FocusGroupController{constructor(e,{direction:t,elementEnterAction:s,elements:n,focusInIndex:i,isFocusableElement:r,listenerScope:o}={elements:()=>[]}){this._currentIndex=-1;this._direction=()=>"both";this.directionLength=5;this.elementEnterAction=e=>{};this._focused=!1;this._focusInIndex=e=>0;this.isFocusableElement=e=>!0;this._listenerScope=()=>this.host;this.offset=0;this.handleFocusin=e=>{if(!this.isEventWithinListenerScope(e))return;this.isRelatedTargetAnElement(e)&&this.hostContainsFocus();const t=e.composedPath();let s=-1;t.find(n=>(s=this.elements.indexOf(n),s!==-1)),this.currentIndex=s>-1?s:this.currentIndex};this.handleFocusout=e=>{this.isRelatedTargetAnElement(e)&&this.hostNoLongerContainsFocus()};this.handleKeydown=e=>{if(!this.acceptsEventCode(e.code)||e.defaultPrevented)return;let t=0;switch(e.code){case"ArrowRight":t+=1;break;case"ArrowDown":t+=this.direction==="grid"?this.directionLength:1;break;case"ArrowLeft":t-=1;break;case"ArrowUp":t-=this.direction==="grid"?this.directionLength:1;break;case"End":this.currentIndex=0,t-=1;break;case"Home":this.currentIndex=this.elements.length-1,t+=1;break}e.preventDefault(),this.direction==="grid"&&this.currentIndex+t<0?this.currentIndex=0:this.direction==="grid"&&this.currentIndex+t>this.elements.length-1?this.currentIndex=this.elements.length-1:this.setCurrentIndexCircularly(t),this.elementEnterAction(this.elements[this.currentIndex]),this.focus()};this.host=e,this.host.addController(this),this._elements=n,this.isFocusableElement=r||this.isFocusableElement,typeof t=="string"?this._direction=()=>t:typeof t=="function"&&(this._direction=t),this.elementEnterAction=s||this.elementEnterAction,typeof i=="number"?this._focusInIndex=()=>i:typeof i=="function"&&(this._focusInIndex=i),typeof o=="object"?this._listenerScope=()=>o:typeof o=="function"&&(this._listenerScope=o)}get currentIndex(){return this._currentIndex===-1&&(this._currentIndex=this.focusInIndex),this._currentIndex-this.offset}set currentIndex(e){this._currentIndex=e+this.offset}get direction(){return this._direction()}get elements(){return this.cachedElements||(this.cachedElements=this._elements()),this.cachedElements}set focused(e){e!==this.focused&&(this._focused=e)}get focused(){return this._focused}get focusInElement(){return this.elements[this.focusInIndex]}get focusInIndex(){return this._focusInIndex(this.elements)}isEventWithinListenerScope(e){return this._listenerScope()===this.host?!0:e.composedPath().includes(this._listenerScope())}update({elements:e}={elements:()=>[]}){this.unmanage(),this._elements=e,this.clearElementCache(),this.manage()}focus(e){let t=this.elements[this.currentIndex];(!t||!this.isFocusableElement(t))&&(this.setCurrentIndexCircularly(1),t=this.elements[this.currentIndex]),t&&this.isFocusableElement(t)&&t.focus(e)}clearElementCache(e=0){delete this.cachedElements,this.offset=e}setCurrentIndexCircularly(e){const{length:t}=this.elements;let s=t,n=(t+this.currentIndex+e)%t;for(;s&&this.elements[n]&&!this.isFocusableElement(this.elements[n]);)n=(t+n+e)%t,s-=1;this.currentIndex=n}hostContainsFocus(){this.host.addEventListener("focusout",this.handleFocusout),this.host.addEventListener("keydown",this.handleKeydown),this.focused=!0}hostNoLongerContainsFocus(){this.host.addEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown),this.currentIndex=this.focusInIndex,this.focused=!1}isRelatedTargetAnElement(e){const t=e.relatedTarget;return!this.elements.includes(t)}acceptsEventCode(e){if(e==="End"||e==="Home")return!0;switch(this.direction){case"horizontal":return e==="ArrowLeft"||e==="ArrowRight";case"vertical":return e==="ArrowUp"||e==="ArrowDown";case"both":case"grid":return e.startsWith("Arrow")}}manage(){this.addEventListeners()}unmanage(){this.removeEventListeners()}addEventListeners(){this.host.addEventListener("focusin",this.handleFocusin)}removeEventListeners(){this.host.removeEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown)}hostConnected(){this.addEventListeners()}hostDisconnected(){this.removeEventListeners()}}
217
2
  //# sourceMappingURL=FocusGroup.js.map