@spectrum-web-components/reactive-controllers 0.3.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 +10 -2
- package/src/Color.d.ts +46 -0
- package/src/Color.dev.js +197 -0
- package/src/Color.dev.js.map +7 -0
- package/src/Color.js +2 -0
- package/src/Color.js.map +7 -0
- package/src/FocusGroup.dev.js +1 -0
- package/src/FocusGroup.dev.js.map +1 -1
- package/src/FocusGroup.js +1 -1
- package/src/FocusGroup.js.map +2 -2
- package/src/LanguageResolution.d.ts +10 -0
- package/src/LanguageResolution.dev.js +34 -0
- package/src/LanguageResolution.dev.js.map +7 -0
- package/src/LanguageResolution.js +2 -0
- package/src/LanguageResolution.js.map +7 -0
- package/src/MatchMedia.dev.js +6 -2
- package/src/MatchMedia.dev.js.map +2 -2
- package/src/MatchMedia.js +1 -1
- package/src/MatchMedia.js.map +3 -3
- package/src/RovingTabindex.dev.js +4 -1
- package/src/RovingTabindex.dev.js.map +1 -1
- package/src/RovingTabindex.js +1 -1
- package/src/RovingTabindex.js.map +2 -2
- package/src/index.dev.js +1 -0
- package/src/index.dev.js.map +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/test/helpers.js +23 -0
- package/test/helpers.js.map +7 -0
- package/test/match-media.test.js +24 -2
- package/test/match-media.test.js.map +1 -1
- package/test/roving-tabindex-integration.test.js +101 -2
- package/test/roving-tabindex-integration.test.js.map +1 -1
- package/test/roving-tabindex.test.js +18 -1
- package/test/roving-tabindex.test.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/reactive-controllers",
|
|
3
|
-
"version": "0.3.
|
|
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": "
|
|
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
|
+
}
|
package/src/Color.dev.js
ADDED
|
@@ -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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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
|
package/src/Color.js.map
ADDED
|
@@ -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,EAA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AAUE,CAAK,EACjC,MAAMY,EAAS,KAAK,OAAO,OAC3B,IAAIX,EAAW,OAAOD,GAAU,UAAYA,aAAiB,OAEzDY,EAAO,WAAW,KAAK,IACvBX,EAAYD,EAAiB,WAAW,GAAG,GAG/C,KAAK,QAAU,CACX,OAAAY,EACA,SAAAX,CACJ,EAEA,KAAK,gBAAgB,KAAK,OAAQD,EAAOY,EAAQX,CAAQ,EACzD,KAAK,KAAK,cAAc,QAASmB,CAAQ,CAC7C,CAIO,SAASR,EAA4B,CACxC,MAAMS,EAAwD,CAC1D,IAAK,OACT,EACA,OAAO,KAAK,OAAOA,EAAcT,IAAS,CAC9C,CAEO,SAASZ,EAAwB,CACpC,KAAK,OAASA,EACd,MAAMC,EACF,OAAO,KAAK,OAAO,eAAkB,UACrC,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
|
+
}
|
package/src/FocusGroup.dev.js
CHANGED
|
@@ -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.removeEventListeners();\n }\n}\n"],
|
|
5
|
-
"mappings": "AAuBO,aAAM,qBAEb;AAAA,EA2EI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,
|
|
5
|
+
"mappings": ";AAuBO,aAAM,qBAEb;AAAA,EA2EI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAyB,EAAE,UAAU,MAAM,CAAC,EAAE,GAChD;AAvEF,SAAQ,gBAAgB;AAMxB,sBAAa,MAAsB;AAEnC,SAAO,kBAAkB;AAEzB,8BAAqB,CAAC,QAAiB;AACnC;AAAA,IACJ;AAoBA,SAAQ,WAAW;AAWnB,yBAAgB,CAAC,cAA2B;AAK5C,8BAAqB,CAAC,QAAoB;AAO1C,0BAAiB,MAAmB,KAAK;AAIzC,kBAAS;AA+FT,yBAAgB,CAAC,UAA4B;AACzC,UAAI,CAAC,KAAK,2BAA2B,KAAK;AAAG;AAC7C,UAAI,KAAK,yBAAyB,KAAK,GAAG;AACtC,aAAK,kBAAkB;AAAA,MAC3B;AACA,YAAM,OAAO,MAAM,aAAa;AAChC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AAO,CAAC,KAAK,SAAS,SAAS,aAAkB;AAAA,EACrD;AAAA,EAsBA,iBAAiB,MAAuB;AACpC,QAAI,SAAS,SAAS,SAAS,QAAQ;AACnC,aAAO;AAAA,IACX;AACA,YAAQ,KAAK;AAAA,WACJ;AACD,eAAO,SAAS,eAAe,SAAS;AAAA,WACvC;AACD,eAAO,SAAS,aAAa,SAAS;AAAA,WACrC;AAAA,WACA;AACD,eAAO,KAAK,WAAW,OAAO;AAAA;AAAA,EAE1C;AAAA,EA8CA,SAAe;AACX,SAAK,kBAAkB;AAAA,EAC3B;AAAA,EAEA,WAAiB;AACb,SAAK,qBAAqB;AAAA,EAC9B;AAAA,EAEA,oBAA0B;AACtB,SAAK,KAAK,iBAAiB,WAAW,KAAK,aAAa;AAAA,EAC5D;AAAA,EAEA,uBAA6B;AACzB,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAC3D,SAAK,KAAK,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,2 +1,2 @@
|
|
|
1
|
-
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()}}
|
|
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()}}
|
|
2
2
|
//# sourceMappingURL=FocusGroup.js.map
|
package/src/FocusGroup.js.map
CHANGED
|
@@ -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.removeEventListeners();\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "aAuBO,aAAM,oBAEb,CA2EI,YACIA,EACA,CACI,UAAAC,EACA,mBAAAC,EACA,SAAAC,EACA,aAAAC,EACA,mBAAAC,EACA,cAAAC,CACJ,EAAyB,CAAE,SAAU,IAAM,CAAC,CAAE,EAChD,CAvEF,KAAQ,cAAgB,GAMxB,gBAAa,IAAsB,OAEnC,KAAO,gBAAkB,EAEzB,wBAAsBC,GAAiB,CAEvC,EAoBA,KAAQ,SAAW,GAWnB,mBAAiBC,GAA2B,EAK5C,wBAAsBD,GAAoB,GAO1C,oBAAiB,IAAmB,KAAK,KAIzC,YAAS,EA+FT,mBAAiBE,GAA4B,CACzC,GAAI,CAAC,KAAK,2BAA2BA,CAAK,EAAG,OACzC,KAAK,yBAAyBA,CAAK,GACnC,KAAK,kBAAkB,EAE3B,MAAMC,EAAOD,EAAM,aAAa,EAChC,IAAIE,EAAc,GAClBD,EAAK,KAAME,IACPD,EAAc,KAAK,SAAS,QAAQC,CAAE,EAC/BD,IAAgB,GAC1B,EACD,KAAK,aAAeA,EAAc,GAAKA,EAAc,KAAK,YAC9D,EAEA,oBAAkBF,GAA4B,CACtC,KAAK,yBAAyBA,CAAK,GACnC,KAAK,0BAA0B,CAEvC,EAiBA,mBAAiBA,GAA+B,CAC5C,GAAI,CAAC,KAAK,iBAAiBA,EAAM,IAAI,GAAKA,EAAM,iBAC5C,OAEJ,IAAII,EAAO,EACX,OAAQJ,EAAM,UACL,aACDI,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QAAU,EACnB,CAEA,2BAAkC,CAC9B,KAAK,KAAK,iBAAiB,UAAW,KAAK,aAAa,EACxD,KAAK,KAAK,oBAAoB,WAAY,KAAK,cAAc,EAC7D,KAAK,KAAK,oBAAoB,UAAW,KAAK,aAAa,EAC3D,KAAK,aAAe,KAAK,aACzB,KAAK,QAAU,EACnB,CAEA,yBAAyBZ,EAA4B,CACjD,MAAMa,EAAgBb,EAAM,cAC5B,MAAO,CAAC,KAAK,SAAS,SAASa,CAAkB,CACrD,CAsBA,iBAAiBC,EAAuB,CACpC,GAAIA,IAAS,OAASA,IAAS,OAC3B,MAAO,GAEX,OAAQ,KAAK,eACJ,aACD,OAAOA,IAAS,aAAeA,IAAS,iBACvC,WACD,OAAOA,IAAS,WAAaA,IAAS,gBACrC,WACA,OACD,OAAOA,EAAK,WAAW,OAAO,EAE1C,CA8CA,QAAe,CACX,KAAK,kBAAkB,CAC3B,CAEA,UAAiB,CACb,KAAK,qBAAqB,CAC9B,CAEA,mBAA0B,CACtB,KAAK,KAAK,iBAAiB,UAAW,KAAK,aAAa,CAC5D,CAEA,sBAA6B,CACzB,KAAK,KAAK,oBAAoB,UAAW,KAAK,aAAa,EAC3D,KAAK,KAAK,oBAAoB,WAAY,KAAK,cAAc,EAC7D,KAAK,KAAK,oBAAoB,UAAW,KAAK,aAAa,CAC/D,CAEA,eAAsB,CAClB,KAAK,kBAAkB,CAC3B,CAEA,kBAAyB,CACrB,KAAK,qBAAqB,CAC9B,CACJ",
|
|
6
|
+
"names": ["host", "direction", "elementEnterAction", "elements", "focusInIndex", "isFocusableElement", "listenerScope", "_el", "_elements", "event", "path", "targetIndex", "el", "diff", "currentIndex", "focused", "options", "focusElement", "offset", "length", "steps", "nextIndex", "relatedTarget", "code"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
|
+
export declare class LanguageResolutionController implements ReactiveController {
|
|
3
|
+
private host;
|
|
4
|
+
language: string;
|
|
5
|
+
private unsubscribe?;
|
|
6
|
+
constructor(host: ReactiveElement);
|
|
7
|
+
hostConnected(): void;
|
|
8
|
+
hostDisconnected(): void;
|
|
9
|
+
private resolveLanguage;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export class LanguageResolutionController {
|
|
3
|
+
constructor(host) {
|
|
4
|
+
this.language = document.documentElement.lang || navigator.language;
|
|
5
|
+
this.host = host;
|
|
6
|
+
this.host.addController(this);
|
|
7
|
+
}
|
|
8
|
+
hostConnected() {
|
|
9
|
+
this.resolveLanguage();
|
|
10
|
+
}
|
|
11
|
+
hostDisconnected() {
|
|
12
|
+
var _a;
|
|
13
|
+
(_a = this.unsubscribe) == null ? void 0 : _a.call(this);
|
|
14
|
+
}
|
|
15
|
+
resolveLanguage() {
|
|
16
|
+
const queryThemeEvent = new CustomEvent(
|
|
17
|
+
"sp-language-context",
|
|
18
|
+
{
|
|
19
|
+
bubbles: true,
|
|
20
|
+
composed: true,
|
|
21
|
+
detail: {
|
|
22
|
+
callback: (lang, unsubscribe) => {
|
|
23
|
+
this.language = lang;
|
|
24
|
+
this.unsubscribe = unsubscribe;
|
|
25
|
+
this.host.requestUpdate();
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
cancelable: true
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
this.host.dispatchEvent(queryThemeEvent);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=LanguageResolution.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["LanguageResolution.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 { ReactiveController, ReactiveElement } from 'lit';\nimport { ProvideLang } from '@spectrum-web-components/theme';\n\nexport class LanguageResolutionController implements ReactiveController {\n private host: ReactiveElement;\n language = document.documentElement.lang || navigator.language;\n private unsubscribe?: () => void;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n public hostConnected(): void {\n this.resolveLanguage();\n }\n\n public hostDisconnected(): void {\n this.unsubscribe?.();\n }\n\n private resolveLanguage(): void {\n const queryThemeEvent = new CustomEvent<ProvideLang>(\n 'sp-language-context',\n {\n bubbles: true,\n composed: true,\n detail: {\n callback: (lang: string, unsubscribe: () => void) => {\n this.language = lang;\n this.unsubscribe = unsubscribe;\n this.host.requestUpdate();\n },\n },\n cancelable: true,\n }\n );\n this.host.dispatchEvent(queryThemeEvent);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAeO,aAAM,6BAA2D;AAAA,EAKpE,YAAY,MAAuB;AAHnC,oBAAW,SAAS,gBAAgB,QAAQ,UAAU;AAIlD,SAAK,OAAO;AACZ,SAAK,KAAK,cAAc,IAAI;AAAA,EAChC;AAAA,EAEO,gBAAsB;AACzB,SAAK,gBAAgB;AAAA,EACzB;AAAA,EAEO,mBAAyB;AA7BpC;AA8BQ,eAAK,gBAAL;AAAA,EACJ;AAAA,EAEQ,kBAAwB;AAC5B,UAAM,kBAAkB,IAAI;AAAA,MACxB;AAAA,MACA;AAAA,QACI,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,UACJ,UAAU,CAAC,MAAc,gBAA4B;AACjD,iBAAK,WAAW;AAChB,iBAAK,cAAc;AACnB,iBAAK,KAAK,cAAc;AAAA,UAC5B;AAAA,QACJ;AAAA,QACA,YAAY;AAAA,MAChB;AAAA,IACJ;AACA,SAAK,KAAK,cAAc,eAAe;AAAA,EAC3C;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";export class LanguageResolutionController{constructor(e){this.language=document.documentElement.lang||navigator.language;this.host=e,this.host.addController(this)}hostConnected(){this.resolveLanguage()}hostDisconnected(){var e;(e=this.unsubscribe)==null||e.call(this)}resolveLanguage(){const e=new CustomEvent("sp-language-context",{bubbles:!0,composed:!0,detail:{callback:(t,o)=>{this.language=t,this.unsubscribe=o,this.host.requestUpdate()}},cancelable:!0});this.host.dispatchEvent(e)}}
|
|
2
|
+
//# sourceMappingURL=LanguageResolution.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["LanguageResolution.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 { ReactiveController, ReactiveElement } from 'lit';\nimport { ProvideLang } from '@spectrum-web-components/theme';\n\nexport class LanguageResolutionController implements ReactiveController {\n private host: ReactiveElement;\n language = document.documentElement.lang || navigator.language;\n private unsubscribe?: () => void;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n public hostConnected(): void {\n this.resolveLanguage();\n }\n\n public hostDisconnected(): void {\n this.unsubscribe?.();\n }\n\n private resolveLanguage(): void {\n const queryThemeEvent = new CustomEvent<ProvideLang>(\n 'sp-language-context',\n {\n bubbles: true,\n composed: true,\n detail: {\n callback: (lang: string, unsubscribe: () => void) => {\n this.language = lang;\n this.unsubscribe = unsubscribe;\n this.host.requestUpdate();\n },\n },\n cancelable: true,\n }\n );\n this.host.dispatchEvent(queryThemeEvent);\n }\n}\n"],
|
|
5
|
+
"mappings": "aAeO,aAAM,4BAA2D,CAKpE,YAAYA,EAAuB,CAHnC,cAAW,SAAS,gBAAgB,MAAQ,UAAU,SAIlD,KAAK,KAAOA,EACZ,KAAK,KAAK,cAAc,IAAI,CAChC,CAEO,eAAsB,CACzB,KAAK,gBAAgB,CACzB,CAEO,kBAAyB,CA7BpC,IAAAC,GA8BQA,EAAA,KAAK,cAAL,MAAAA,EAAA,UACJ,CAEQ,iBAAwB,CAC5B,MAAMC,EAAkB,IAAI,YACxB,sBACA,CACI,QAAS,GACT,SAAU,GACV,OAAQ,CACJ,SAAU,CAACC,EAAcC,IAA4B,CACjD,KAAK,SAAWD,EAChB,KAAK,YAAcC,EACnB,KAAK,KAAK,cAAc,CAC5B,CACJ,EACA,WAAY,EAChB,CACJ,EACA,KAAK,KAAK,cAAcF,CAAe,CAC3C,CACJ",
|
|
6
|
+
"names": ["host", "_a", "queryThemeEvent", "lang", "unsubscribe"]
|
|
7
|
+
}
|
package/src/MatchMedia.dev.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
export const DARK_MODE = "(prefers-color-scheme: dark)";
|
|
2
3
|
export const IS_MOBILE = "(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)";
|
|
3
4
|
export class MatchMediaController {
|
|
@@ -5,16 +6,19 @@ export class MatchMediaController {
|
|
|
5
6
|
this.key = Symbol("match-media-key");
|
|
6
7
|
this.matches = false;
|
|
7
8
|
this.host = host;
|
|
9
|
+
this.host.addController(this);
|
|
8
10
|
this.media = window.matchMedia(query);
|
|
9
11
|
this.matches = this.media.matches;
|
|
10
12
|
this.onChange = this.onChange.bind(this);
|
|
11
13
|
host.addController(this);
|
|
12
14
|
}
|
|
13
15
|
hostConnected() {
|
|
14
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = this.media) == null ? void 0 : _a.addEventListener("change", this.onChange);
|
|
15
18
|
}
|
|
16
19
|
hostDisconnected() {
|
|
17
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
(_a = this.media) == null ? void 0 : _a.removeEventListener("change", this.onChange);
|
|
18
22
|
}
|
|
19
23
|
onChange(event) {
|
|
20
24
|
if (this.matches === event.matches)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["MatchMedia.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nexport const DARK_MODE = '(prefers-color-scheme: dark)';\nexport const IS_MOBILE =\n '(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)';\n\nexport class MatchMediaController implements ReactiveController {\n key = Symbol('match-media-key');\n\n matches = false;\n\n protected host: ReactiveElement;\n\n protected media: MediaQueryList;\n\n constructor(host: ReactiveElement, query: string) {\n this.host = host;\n this.media = window.matchMedia(query);\n this.matches = this.media.matches;\n this.onChange = this.onChange.bind(this);\n host.addController(this);\n }\n\n public hostConnected(): void {\n this.media
|
|
5
|
-
"mappings": "AAaO,aAAM,YAAY;AAClB,aAAM,YACT;AAEG,aAAM,qBAAmD;AAAA,EAS5D,YAAY,MAAuB,OAAe;AARlD,eAAM,OAAO,iBAAiB;AAE9B,mBAAU;AAON,SAAK,OAAO;AACZ,SAAK,QAAQ,OAAO,WAAW,KAAK;AACpC,SAAK,UAAU,KAAK,MAAM;AAC1B,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,cAAc,IAAI;AAAA,EAC3B;AAAA,EAEO,gBAAsB;
|
|
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\nexport const DARK_MODE = '(prefers-color-scheme: dark)';\nexport const IS_MOBILE =\n '(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)';\n\nexport class MatchMediaController implements ReactiveController {\n key = Symbol('match-media-key');\n\n matches = false;\n\n protected host: ReactiveElement;\n\n protected media: MediaQueryList;\n\n constructor(host: ReactiveElement, query: string) {\n this.host = host;\n this.host.addController(this);\n this.media = window.matchMedia(query);\n this.matches = this.media.matches;\n this.onChange = this.onChange.bind(this);\n host.addController(this);\n }\n\n public hostConnected(): void {\n this.media?.addEventListener('change', this.onChange);\n }\n\n public hostDisconnected(): void {\n this.media?.removeEventListener('change', this.onChange);\n }\n\n protected onChange(event: MediaQueryListEvent): void {\n if (this.matches === event.matches) return;\n this.matches = event.matches;\n this.host.requestUpdate(this.key, !this.matches);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAaO,aAAM,YAAY;AAClB,aAAM,YACT;AAEG,aAAM,qBAAmD;AAAA,EAS5D,YAAY,MAAuB,OAAe;AARlD,eAAM,OAAO,iBAAiB;AAE9B,mBAAU;AAON,SAAK,OAAO;AACZ,SAAK,KAAK,cAAc,IAAI;AAC5B,SAAK,QAAQ,OAAO,WAAW,KAAK;AACpC,SAAK,UAAU,KAAK,MAAM;AAC1B,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,cAAc,IAAI;AAAA,EAC3B;AAAA,EAEO,gBAAsB;AAnCjC;AAoCQ,eAAK,UAAL,mBAAY,iBAAiB,UAAU,KAAK;AAAA,EAChD;AAAA,EAEO,mBAAyB;AAvCpC;AAwCQ,eAAK,UAAL,mBAAY,oBAAoB,UAAU,KAAK;AAAA,EACnD;AAAA,EAEU,SAAS,OAAkC;AACjD,QAAI,KAAK,YAAY,MAAM;AAAS;AACpC,SAAK,UAAU,MAAM;AACrB,SAAK,KAAK,cAAc,KAAK,KAAK,CAAC,KAAK,OAAO;AAAA,EACnD;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/MatchMedia.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const DARK_MODE="(prefers-color-scheme: dark)",IS_MOBILE="(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)";export class MatchMediaController{constructor(e,t){this.key=Symbol("match-media-key");this.matches=!1;this.host=e,this.media=window.matchMedia(t),this.matches=this.media.matches,this.onChange=this.onChange.bind(this),e.addController(this)}hostConnected(){this.media.addEventListener("change",this.onChange)}hostDisconnected(){this.media.removeEventListener("change",this.onChange)}onChange(e){this.matches!==e.matches&&(this.matches=e.matches,this.host.requestUpdate(this.key,!this.matches))}}
|
|
1
|
+
"use strict";export const DARK_MODE="(prefers-color-scheme: dark)",IS_MOBILE="(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)";export class MatchMediaController{constructor(e,t){this.key=Symbol("match-media-key");this.matches=!1;this.host=e,this.host.addController(this),this.media=window.matchMedia(t),this.matches=this.media.matches,this.onChange=this.onChange.bind(this),e.addController(this)}hostConnected(){var e;(e=this.media)==null||e.addEventListener("change",this.onChange)}hostDisconnected(){var e;(e=this.media)==null||e.removeEventListener("change",this.onChange)}onChange(e){this.matches!==e.matches&&(this.matches=e.matches,this.host.requestUpdate(this.key,!this.matches))}}
|
|
2
2
|
//# sourceMappingURL=MatchMedia.js.map
|
package/src/MatchMedia.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["MatchMedia.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nexport const DARK_MODE = '(prefers-color-scheme: dark)';\nexport const IS_MOBILE =\n '(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)';\n\nexport class MatchMediaController implements ReactiveController {\n key = Symbol('match-media-key');\n\n matches = false;\n\n protected host: ReactiveElement;\n\n protected media: MediaQueryList;\n\n constructor(host: ReactiveElement, query: string) {\n this.host = host;\n this.media = window.matchMedia(query);\n this.matches = this.media.matches;\n this.onChange = this.onChange.bind(this);\n host.addController(this);\n }\n\n public hostConnected(): void {\n this.media
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
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\nexport const DARK_MODE = '(prefers-color-scheme: dark)';\nexport const IS_MOBILE =\n '(max-width: 700px) and (hover: none) and (pointer: coarse), (max-height: 700px) and (hover: none) and (pointer: coarse)';\n\nexport class MatchMediaController implements ReactiveController {\n key = Symbol('match-media-key');\n\n matches = false;\n\n protected host: ReactiveElement;\n\n protected media: MediaQueryList;\n\n constructor(host: ReactiveElement, query: string) {\n this.host = host;\n this.host.addController(this);\n this.media = window.matchMedia(query);\n this.matches = this.media.matches;\n this.onChange = this.onChange.bind(this);\n host.addController(this);\n }\n\n public hostConnected(): void {\n this.media?.addEventListener('change', this.onChange);\n }\n\n public hostDisconnected(): void {\n this.media?.removeEventListener('change', this.onChange);\n }\n\n protected onChange(event: MediaQueryListEvent): void {\n if (this.matches === event.matches) return;\n this.matches = event.matches;\n this.host.requestUpdate(this.key, !this.matches);\n }\n}\n"],
|
|
5
|
+
"mappings": "aAaO,aAAM,UAAY,+BACZ,UACT,0HAEG,aAAM,oBAAmD,CAS5D,YAAYA,EAAuBC,EAAe,CARlD,SAAM,OAAO,iBAAiB,EAE9B,aAAU,GAON,KAAK,KAAOD,EACZ,KAAK,KAAK,cAAc,IAAI,EAC5B,KAAK,MAAQ,OAAO,WAAWC,CAAK,EACpC,KAAK,QAAU,KAAK,MAAM,QAC1B,KAAK,SAAW,KAAK,SAAS,KAAK,IAAI,EACvCD,EAAK,cAAc,IAAI,CAC3B,CAEO,eAAsB,CAnCjC,IAAAE,GAoCQA,EAAA,KAAK,QAAL,MAAAA,EAAY,iBAAiB,SAAU,KAAK,SAChD,CAEO,kBAAyB,CAvCpC,IAAAA,GAwCQA,EAAA,KAAK,QAAL,MAAAA,EAAY,oBAAoB,SAAU,KAAK,SACnD,CAEU,SAASC,EAAkC,CAC7C,KAAK,UAAYA,EAAM,UAC3B,KAAK,QAAUA,EAAM,QACrB,KAAK,KAAK,cAAc,KAAK,IAAK,CAAC,KAAK,OAAO,EACnD,CACJ",
|
|
6
|
+
"names": ["host", "query", "_a", "event"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { FocusGroupController } from "./FocusGroup.dev.js";
|
|
2
3
|
export class RovingTabindexController extends FocusGroupController {
|
|
3
4
|
constructor() {
|
|
@@ -19,7 +20,9 @@ export class RovingTabindexController extends FocusGroupController {
|
|
|
19
20
|
super.clearElementCache(offset);
|
|
20
21
|
if (!this.managed)
|
|
21
22
|
return;
|
|
22
|
-
this.manageIndexesAnimationFrame = requestAnimationFrame(
|
|
23
|
+
this.manageIndexesAnimationFrame = requestAnimationFrame(
|
|
24
|
+
() => this.manageTabindexes()
|
|
25
|
+
);
|
|
23
26
|
}
|
|
24
27
|
manageTabindexes() {
|
|
25
28
|
if (this.focused) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["RovingTabindex.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 { FocusGroupConfig, FocusGroupController } from './FocusGroup.dev.js'\n\nexport type RovingTabindexConfig<T> = FocusGroupConfig<T>;\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<\n T extends HTMLElement\n> extends FocusGroupController<T> {\n protected override set focused(focused: boolean) {\n if (focused === this.focused) return;\n super.focused = focused;\n this.manageTabindexes();\n }\n\n protected override get focused(): boolean {\n return super.focused;\n }\n\n private managed = true;\n\n private manageIndexesAnimationFrame = 0;\n\n override clearElementCache(offset = 0): void {\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n super.clearElementCache(offset);\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n el.tabIndex = tabIndex;\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n override manage(): void {\n this.managed = true;\n this.manageTabindexes();\n super.manage();\n }\n\n override unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n super.unmanage();\n }\n\n hostUpdated(): void {\n if (!this.host.hasUpdated) {\n this.manageTabindexes();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA;
|
|
5
|
+
"mappings": ";AAWA,SAA2B,4BAA4B;AAQhD,aAAM,iCAEH,qBAAwB;AAAA,EAF3B;AAAA;AAaH,SAAQ,UAAU;AAElB,SAAQ,8BAA8B;AAAA;AAAA,EAZtC,IAAuB,QAAQ,SAAkB;AAC7C,QAAI,YAAY,KAAK;AAAS;AAC9B,UAAM,UAAU;AAChB,SAAK,iBAAiB;AAAA,EAC1B;AAAA,EAEA,IAAuB,UAAmB;AACtC,WAAO,MAAM;AAAA,EACjB;AAAA,EAMS,kBAAkB,SAAS,GAAS;AACzC,yBAAqB,KAAK,2BAA2B;AACrD,UAAM,kBAAkB,MAAM;AAC9B,QAAI,CAAC,KAAK;AAAS;AAEnB,SAAK,8BAA8B;AAAA,MAAsB,MACrD,KAAK,iBAAiB;AAAA,IAC1B;AAAA,EACJ;AAAA,EAEA,mBAAyB;AACrB,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB,OAAO,EAAE,UAAU,GAAG,EAAE;AAAA,IAClD,OAAO;AACH,WAAK,iBAAiB,CAAC,OAAsC;AACzD,eAAO;AAAA,UACH,gBACI,GAAG,SAAS,KAAK,cAAc,KAC/B,OAAO,KAAK;AAAA,UAChB,UAAU,OAAO,KAAK,iBAAiB,IAAI;AAAA,QAC/C;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AAAA,EAEA,iBAAiB,aAA0D;AACvE,SAAK,SAAS,QAAQ,CAAC,OAAO;AAC1B,YAAM,EAAE,UAAU,eAAe,IAAI,YAAY,EAAE;AACnD,UAAI,CAAC,gBAAgB;AACjB,WAAG,WAAW;AACd;AAAA,MACJ;AACA,SAAG,gBAAgB,UAAU;AAC7B,YAAM,YAAY;AAGlB,UAAI,UAAU;AAAe,kBAAU,cAAc;AAAA,IACzD,CAAC;AAAA,EACL;AAAA,EAES,SAAe;AACpB,SAAK,UAAU;AACf,SAAK,iBAAiB;AACtB,UAAM,OAAO;AAAA,EACjB;AAAA,EAES,WAAiB;AACtB,SAAK,UAAU;AACf,SAAK,iBAAiB,OAAO,EAAE,UAAU,EAAE,EAAE;AAC7C,UAAM,SAAS;AAAA,EACnB;AAAA,EAEA,cAAoB;AAChB,QAAI,CAAC,KAAK,KAAK,YAAY;AACvB,WAAK,iBAAiB;AAAA,IAC1B;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/RovingTabindex.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{FocusGroupController as s}from"./FocusGroup.js";export class RovingTabindexController extends s{constructor(){super(...arguments);this.managed=!0;this.manageIndexesAnimationFrame=0}set focused(e){e!==this.focused&&(super.focused=e,this.manageTabindexes())}get focused(){return super.focused}clearElementCache(e=0){cancelAnimationFrame(this.manageIndexesAnimationFrame),super.clearElementCache(e),this.managed&&(this.manageIndexesAnimationFrame=requestAnimationFrame(()=>this.manageTabindexes()))}manageTabindexes(){this.focused?this.updateTabindexes(()=>({tabIndex:-1})):this.updateTabindexes(e=>({removeTabIndex:e.contains(this.focusInElement)&&e!==this.focusInElement,tabIndex:e===this.focusInElement?0:-1}))}updateTabindexes(e){this.elements.forEach(a=>{const{tabIndex:t,removeTabIndex:i}=e(a);if(!i){a.tabIndex=t;return}a.removeAttribute("tabindex");const n=a;n.requestUpdate&&n.requestUpdate()})}manage(){this.managed=!0,this.manageTabindexes(),super.manage()}unmanage(){this.managed=!1,this.updateTabindexes(()=>({tabIndex:0})),super.unmanage()}hostUpdated(){this.host.hasUpdated||this.manageTabindexes()}}
|
|
1
|
+
"use strict";import{FocusGroupController as s}from"./FocusGroup.js";export class RovingTabindexController extends s{constructor(){super(...arguments);this.managed=!0;this.manageIndexesAnimationFrame=0}set focused(e){e!==this.focused&&(super.focused=e,this.manageTabindexes())}get focused(){return super.focused}clearElementCache(e=0){cancelAnimationFrame(this.manageIndexesAnimationFrame),super.clearElementCache(e),this.managed&&(this.manageIndexesAnimationFrame=requestAnimationFrame(()=>this.manageTabindexes()))}manageTabindexes(){this.focused?this.updateTabindexes(()=>({tabIndex:-1})):this.updateTabindexes(e=>({removeTabIndex:e.contains(this.focusInElement)&&e!==this.focusInElement,tabIndex:e===this.focusInElement?0:-1}))}updateTabindexes(e){this.elements.forEach(a=>{const{tabIndex:t,removeTabIndex:i}=e(a);if(!i){a.tabIndex=t;return}a.removeAttribute("tabindex");const n=a;n.requestUpdate&&n.requestUpdate()})}manage(){this.managed=!0,this.manageTabindexes(),super.manage()}unmanage(){this.managed=!1,this.updateTabindexes(()=>({tabIndex:0})),super.unmanage()}hostUpdated(){this.host.hasUpdated||this.manageTabindexes()}}
|
|
2
2
|
//# sourceMappingURL=RovingTabindex.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["RovingTabindex.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 { FocusGroupConfig, FocusGroupController } from './FocusGroup.js';\n\nexport type RovingTabindexConfig<T> = FocusGroupConfig<T>;\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<\n T extends HTMLElement\n> extends FocusGroupController<T> {\n protected override set focused(focused: boolean) {\n if (focused === this.focused) return;\n super.focused = focused;\n this.manageTabindexes();\n }\n\n protected override get focused(): boolean {\n return super.focused;\n }\n\n private managed = true;\n\n private manageIndexesAnimationFrame = 0;\n\n override clearElementCache(offset = 0): void {\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n super.clearElementCache(offset);\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n el.tabIndex = tabIndex;\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n override manage(): void {\n this.managed = true;\n this.manageTabindexes();\n super.manage();\n }\n\n override unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n super.unmanage();\n }\n\n hostUpdated(): void {\n if (!this.host.hasUpdated) {\n this.manageTabindexes();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "aAWA,OAA2B,wBAAAA,MAA4B,kBAQhD,aAAM,iCAEHA,CAAwB,CAF3B,kCAaH,KAAQ,QAAU,GAElB,KAAQ,4BAA8B,EAZtC,IAAuB,QAAQC,EAAkB,CACzCA,IAAY,KAAK,UACrB,MAAM,QAAUA,EAChB,KAAK,iBAAiB,EAC1B,CAEA,IAAuB,SAAmB,CACtC,OAAO,MAAM,OACjB,CAMS,kBAAkBC,EAAS,EAAS,CACzC,qBAAqB,KAAK,2BAA2B,EACrD,MAAM,kBAAkBA,CAAM,EACzB,KAAK,UAEV,KAAK,4BAA8B,sBAAsB,IACrD,KAAK,iBAAiB,CAC1B,EACJ,CAEA,kBAAyB,CACjB,KAAK,QACL,KAAK,iBAAiB,KAAO,CAAE,SAAU,EAAG,EAAE,EAE9C,KAAK,iBAAkBC,IACZ,CACH,eACIA,EAAG,SAAS,KAAK,cAAc,GAC/BA,IAAO,KAAK,eAChB,SAAUA,IAAO,KAAK,eAAiB,EAAI,EAC/C,EACH,CAET,CAEA,iBAAiBC,EAA0D,CACvE,KAAK,SAAS,QAASD,GAAO,CAC1B,KAAM,CAAE,SAAAE,EAAU,eAAAC,CAAe,EAAIF,EAAYD,CAAE,EACnD,GAAI,CAACG,EAAgB,CACjBH,EAAG,SAAWE,EACd,MACJ,CACAF,EAAG,gBAAgB,UAAU,EAC7B,MAAMI,EAAYJ,EAGdI,EAAU,eAAeA,EAAU,cAAc,CACzD,CAAC,CACL,CAES,QAAe,CACpB,KAAK,QAAU,GACf,KAAK,iBAAiB,EACtB,MAAM,OAAO,CACjB,CAES,UAAiB,CACtB,KAAK,QAAU,GACf,KAAK,iBAAiB,KAAO,CAAE,SAAU,CAAE,EAAE,EAC7C,MAAM,SAAS,CACnB,CAEA,aAAoB,CACX,KAAK,KAAK,YACX,KAAK,iBAAiB,CAE9B,CACJ",
|
|
6
|
+
"names": ["FocusGroupController", "focused", "offset", "el", "getTabIndex", "tabIndex", "removeTabIndex", "updatable"]
|
|
7
7
|
}
|
package/src/index.dev.js
CHANGED
package/src/index.dev.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.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*/\n\nexport * from './MatchMedia.dev.js'\nexport * from './RovingTabindex.dev.js'\n"],
|
|
5
|
-
"mappings": "AAYA;
|
|
5
|
+
"mappings": ";AAYA,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./MatchMedia.js";export*from"./RovingTabindex.js";
|
|
1
|
+
"use strict";export*from"./MatchMedia.js";export*from"./RovingTabindex.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.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*/\n\nexport * from './MatchMedia.js';\nexport * from './RovingTabindex.js';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "aAYA,WAAc,kBACd,WAAc",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/test/helpers.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export const createLanguageContext = (lang) => {
|
|
3
|
+
let language = lang;
|
|
4
|
+
const updateLanguage = (lang2) => {
|
|
5
|
+
language = lang2;
|
|
6
|
+
resolveLanguage();
|
|
7
|
+
};
|
|
8
|
+
const langResolvers = [];
|
|
9
|
+
const createLangResolver = (event) => {
|
|
10
|
+
langResolvers.push([
|
|
11
|
+
event.detail.callback,
|
|
12
|
+
() => langResolvers.splice(langResolvers.length, 1)
|
|
13
|
+
]);
|
|
14
|
+
resolveLanguage();
|
|
15
|
+
};
|
|
16
|
+
const resolveLanguage = () => {
|
|
17
|
+
langResolvers.forEach(
|
|
18
|
+
([resolver, unsubscribe]) => resolver(language, unsubscribe)
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
return [createLangResolver, updateLanguage];
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["helpers.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ProvideLang } from '@spectrum-web-components/theme';\n\nexport const createLanguageContext = (\n lang: string\n): [(event: CustomEvent<ProvideLang>) => void, (lang: string) => void] => {\n let language = lang;\n const updateLanguage = (lang: string): void => {\n language = lang;\n resolveLanguage();\n };\n const langResolvers: [ProvideLang['callback'], () => void][] = [];\n const createLangResolver = (event: CustomEvent<ProvideLang>): void => {\n langResolvers.push([\n event.detail.callback,\n () => langResolvers.splice(langResolvers.length, 1),\n ]);\n resolveLanguage();\n };\n const resolveLanguage = (): void => {\n langResolvers.forEach(([resolver, unsubscribe]) =>\n resolver(language, unsubscribe)\n );\n };\n return [createLangResolver, updateLanguage];\n};\n"],
|
|
5
|
+
"mappings": ";AAcO,aAAM,wBAAwB,CACjC,SACsE;AACtE,MAAI,WAAW;AACf,QAAM,iBAAiB,CAACA,UAAuB;AAC3C,eAAWA;AACX,oBAAgB;AAAA,EACpB;AACA,QAAM,gBAAyD,CAAC;AAChE,QAAM,qBAAqB,CAAC,UAA0C;AAClE,kBAAc,KAAK;AAAA,MACf,MAAM,OAAO;AAAA,MACb,MAAM,cAAc,OAAO,cAAc,QAAQ,CAAC;AAAA,IACtD,CAAC;AACD,oBAAgB;AAAA,EACpB;AACA,QAAM,kBAAkB,MAAY;AAChC,kBAAc;AAAA,MAAQ,CAAC,CAAC,UAAU,WAAW,MACzC,SAAS,UAAU,WAAW;AAAA,IAClC;AAAA,EACJ;AACA,SAAO,CAAC,oBAAoB,cAAc;AAC9C;",
|
|
6
|
+
"names": ["lang"]
|
|
7
|
+
}
|
package/test/match-media.test.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import { html, LitElement } from "lit";
|
|
3
|
+
import { expect, fixture, nextFrame } from "@open-wc/testing";
|
|
4
|
+
import { setViewport } from "@web/test-runner-commands";
|
|
5
|
+
import { MatchMediaController } from "@spectrum-web-components/reactive-controllers/src/MatchMedia.js";
|
|
6
|
+
describe("Match Media", () => {
|
|
7
|
+
it("responds to media changes", async () => {
|
|
8
|
+
class TestEl extends LitElement {
|
|
9
|
+
}
|
|
10
|
+
customElements.define("test-match-media-el", TestEl);
|
|
11
|
+
const el = await fixture(
|
|
12
|
+
html`
|
|
2
13
|
<test-match-media-el></test-match-media-el>
|
|
3
|
-
`
|
|
14
|
+
`
|
|
15
|
+
);
|
|
16
|
+
const controller = new MatchMediaController(
|
|
17
|
+
el,
|
|
18
|
+
"(min-width: 500px)"
|
|
19
|
+
);
|
|
20
|
+
expect(controller.matches).to.be.true;
|
|
21
|
+
await setViewport({ width: 360, height: 640 });
|
|
22
|
+
await nextFrame();
|
|
23
|
+
expect(controller.matches).to.be.false;
|
|
24
|
+
});
|
|
25
|
+
});
|
|
4
26
|
//# sourceMappingURL=match-media.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["match-media.test.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*/\n\nimport { html, LitElement } from 'lit';\nimport { expect, fixture, nextFrame } from '@open-wc/testing';\nimport { setViewport } from '@web/test-runner-commands';\nimport { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';\n\ndescribe('Match Media', () => {\n it('responds to media changes', async () => {\n class TestEl extends LitElement {}\n customElements.define('test-match-media-el', TestEl);\n const el = await fixture(\n html`\n <test-match-media-el></test-match-media-el>\n `\n );\n const controller = new MatchMediaController(\n el as LitElement & { shadowRoot: ShadowRoot },\n '(min-width: 500px)'\n );\n expect(controller.matches).to.be.true;\n await setViewport({ width: 360, height: 640 });\n // Allow viewport update to propagate.\n await nextFrame();\n expect(controller.matches).to.be.false;\n });\n});\n"],
|
|
5
|
-
"mappings": "AAYA,
|
|
5
|
+
"mappings": ";AAYA,SAAS,MAAM,kBAAkB;AACjC,SAAS,QAAQ,SAAS,iBAAiB;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAErC,SAAS,eAAe,MAAM;AAC1B,KAAG,6BAA6B,YAAY;AACxC,UAAM,eAAe,WAAW;AAAA,IAAC;AACjC,mBAAe,OAAO,uBAAuB,MAAM;AACnD,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AACA,UAAM,aAAa,IAAI;AAAA,MACnB;AAAA,MACA;AAAA,IACJ;AACA,WAAO,WAAW,OAAO,EAAE,GAAG,GAAG;AACjC,UAAM,YAAY,EAAE,OAAO,KAAK,QAAQ,IAAI,CAAC;AAE7C,UAAM,UAAU;AAChB,WAAO,WAAW,OAAO,EAAE,GAAG,GAAG;AAAA,EACrC,CAAC;AACL,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import "@spectrum-web-components/action-button/sp-action-button.js";
|
|
3
|
+
import "@spectrum-web-components/action-group/sp-action-group.js";
|
|
4
|
+
import "@spectrum-web-components/tabs/sp-tab-panel.js";
|
|
5
|
+
import "@spectrum-web-components/tabs/sp-tab.js";
|
|
6
|
+
import "@spectrum-web-components/tabs/sp-tabs.js";
|
|
7
|
+
import { elementUpdated, expect, fixture, nextFrame } from "@open-wc/testing";
|
|
8
|
+
import { html } from "@spectrum-web-components/base";
|
|
9
|
+
import { sendKeys } from "@web/test-runner-commands";
|
|
10
|
+
import { sendMouse } from "../../../test/plugins/browser.js";
|
|
11
|
+
const createTabs = async () => {
|
|
12
|
+
const tabs = await fixture(
|
|
13
|
+
html`
|
|
2
14
|
<sp-tabs selected="second">
|
|
3
15
|
<sp-tab label="Tab 1" value="first"></sp-tab>
|
|
4
16
|
<sp-tab label="Tab 2" value="second"></sp-tab>
|
|
@@ -43,5 +55,92 @@ import"@spectrum-web-components/action-button/sp-action-button.js";import"@spect
|
|
|
43
55
|
</sp-action-group>
|
|
44
56
|
</sp-tab-panel>
|
|
45
57
|
</sp-tabs>
|
|
46
|
-
`
|
|
58
|
+
`
|
|
59
|
+
);
|
|
60
|
+
await elementUpdated(tabs);
|
|
61
|
+
return tabs;
|
|
62
|
+
};
|
|
63
|
+
describe("Action Group inside of Tabs", () => {
|
|
64
|
+
it("accurately navigates the desired element", async () => {
|
|
65
|
+
const el = await createTabs();
|
|
66
|
+
const tab1 = el.querySelector('sp-tab[value="first"]');
|
|
67
|
+
const tab2 = el.querySelector('sp-tab[value="second"]');
|
|
68
|
+
const tab3 = el.querySelector('sp-tab[value="third"]');
|
|
69
|
+
const tabPanel1 = el.querySelector(
|
|
70
|
+
'sp-tab-panel[value="first"]'
|
|
71
|
+
);
|
|
72
|
+
const tabPanel2 = el.querySelector(
|
|
73
|
+
'sp-tab-panel[value="second"]'
|
|
74
|
+
);
|
|
75
|
+
const tabPanel3 = el.querySelector(
|
|
76
|
+
'sp-tab-panel[value="third"]'
|
|
77
|
+
);
|
|
78
|
+
const actionGroup1 = tabPanel1.querySelector(
|
|
79
|
+
"sp-action-group"
|
|
80
|
+
);
|
|
81
|
+
const actionGroup2 = tabPanel2.querySelector(
|
|
82
|
+
"sp-action-group"
|
|
83
|
+
);
|
|
84
|
+
const actionGroup3 = tabPanel3.querySelector(
|
|
85
|
+
"sp-action-group"
|
|
86
|
+
);
|
|
87
|
+
const actionButton1 = actionGroup1.querySelector(
|
|
88
|
+
"[selected]"
|
|
89
|
+
);
|
|
90
|
+
const actionButton2 = actionGroup2.querySelector(
|
|
91
|
+
"[selected]"
|
|
92
|
+
);
|
|
93
|
+
const actionButton3 = actionGroup3.querySelector(
|
|
94
|
+
"[selected]"
|
|
95
|
+
);
|
|
96
|
+
el.focus();
|
|
97
|
+
expect(el.contains(document.activeElement)).to.be.true;
|
|
98
|
+
expect(document.activeElement === tab2).to.be.true;
|
|
99
|
+
actionGroup2.focus();
|
|
100
|
+
expect(document.activeElement === actionButton2).to.be.true;
|
|
101
|
+
await nextFrame();
|
|
102
|
+
await sendKeys({
|
|
103
|
+
press: "ArrowLeft"
|
|
104
|
+
});
|
|
105
|
+
expect(document.activeElement === tab1).to.be.false;
|
|
106
|
+
expect(actionGroup2.contains(document.activeElement)).to.be.true;
|
|
107
|
+
el.focus();
|
|
108
|
+
expect(document.activeElement === tab2).to.be.true;
|
|
109
|
+
await sendKeys({
|
|
110
|
+
press: "ArrowRight"
|
|
111
|
+
});
|
|
112
|
+
expect(document.activeElement === tab3).to.be.true;
|
|
113
|
+
await sendKeys({
|
|
114
|
+
press: "Enter"
|
|
115
|
+
});
|
|
116
|
+
expect(document.activeElement === tab3).to.be.true;
|
|
117
|
+
actionGroup3.focus();
|
|
118
|
+
expect(document.activeElement === actionButton3).to.be.true;
|
|
119
|
+
await sendKeys({
|
|
120
|
+
press: "ArrowLeft"
|
|
121
|
+
});
|
|
122
|
+
expect(document.activeElement === tab2).to.be.false;
|
|
123
|
+
expect(actionGroup3.contains(document.activeElement)).to.be.true;
|
|
124
|
+
const boundingRect = tab1.getBoundingClientRect();
|
|
125
|
+
await sendMouse({
|
|
126
|
+
steps: [
|
|
127
|
+
{
|
|
128
|
+
type: "click",
|
|
129
|
+
position: [
|
|
130
|
+
boundingRect.left + boundingRect.width / 2,
|
|
131
|
+
boundingRect.top + boundingRect.height / 2
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
expect(document.activeElement === tab1).to.be.true;
|
|
137
|
+
actionGroup1.focus();
|
|
138
|
+
expect(document.activeElement === actionButton1).to.be.true;
|
|
139
|
+
await sendKeys({
|
|
140
|
+
press: "ArrowRight"
|
|
141
|
+
});
|
|
142
|
+
expect(document.activeElement === tab2).to.be.false;
|
|
143
|
+
expect(actionGroup1.contains(document.activeElement)).to.be.true;
|
|
144
|
+
});
|
|
145
|
+
});
|
|
47
146
|
//# sourceMappingURL=roving-tabindex-integration.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["roving-tabindex-integration.test.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 '@spectrum-web-components/action-button/sp-action-button.js';\nimport { ActionButton } from '@spectrum-web-components/action-button';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport { ActionGroup } from '@spectrum-web-components/action-group';\nimport '@spectrum-web-components/tabs/sp-tab-panel.js';\nimport '@spectrum-web-components/tabs/sp-tab.js';\nimport '@spectrum-web-components/tabs/sp-tabs.js';\nimport { Tab, TabPanel, Tabs } from '@spectrum-web-components/tabs';\nimport { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\nconst createTabs = async (): Promise<Tabs> => {\n const tabs = await fixture<Tabs>(\n html`\n <sp-tabs selected=\"second\">\n <sp-tab label=\"Tab 1\" value=\"first\"></sp-tab>\n <sp-tab label=\"Tab 2\" value=\"second\"></sp-tab>\n <sp-tab label=\"Tab 3\" value=\"third\"></sp-tab>\n <sp-tab-panel value=\"first\">\n <sp-action-group selects=\"single\">\n <sp-action-button selected value=\"1\">\n Single Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n Single Button 2\n </sp-action-button>\n <sp-action-button value=\"3\">\n Single Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"second\">\n <sp-action-group selects=\"multiple\">\n <sp-action-button value=\"1\">\n Multiple Button 1\n </sp-action-button>\n <sp-action-button selected value=\"2\">\n Multiple Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n Multiple Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n <sp-tab-panel value=\"third\">\n <sp-action-group>\n <sp-action-button value=\"1\">\n None Button 1\n </sp-action-button>\n <sp-action-button value=\"2\">\n None Button 2\n </sp-action-button>\n <sp-action-button selected value=\"3\">\n None Button 3\n </sp-action-button>\n </sp-action-group>\n </sp-tab-panel>\n </sp-tabs>\n `\n );\n await elementUpdated(tabs);\n return tabs;\n};\n\ndescribe('Action Group inside of Tabs', () => {\n it('accurately navigates the desired element', async () => {\n const el = await createTabs();\n const tab1 = el.querySelector('sp-tab[value=\"first\"]') as Tab;\n const tab2 = el.querySelector('sp-tab[value=\"second\"]');\n const tab3 = el.querySelector('sp-tab[value=\"third\"]') as Tab;\n const tabPanel1 = el.querySelector(\n 'sp-tab-panel[value=\"first\"]'\n ) as TabPanel;\n const tabPanel2 = el.querySelector(\n 'sp-tab-panel[value=\"second\"]'\n ) as TabPanel;\n const tabPanel3 = el.querySelector(\n 'sp-tab-panel[value=\"third\"]'\n ) as TabPanel;\n const actionGroup1 = tabPanel1.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup2 = tabPanel2.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionGroup3 = tabPanel3.querySelector(\n 'sp-action-group'\n ) as ActionGroup;\n const actionButton1 = actionGroup1.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton2 = actionGroup2.querySelector(\n '[selected]'\n ) as ActionButton;\n const actionButton3 = actionGroup3.querySelector(\n '[selected]'\n ) as ActionButton;\n\n el.focus();\n expect(el.contains(document.activeElement)).to.be.true;\n expect(document.activeElement === tab2).to.be.true;\n\n actionGroup2.focus();\n expect(document.activeElement === actionButton2).to.be.true;\n\n await nextFrame();\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab1).to.be.false;\n expect(actionGroup2.contains(document.activeElement)).to.be.true;\n\n el.focus();\n expect(document.activeElement === tab2).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n await sendKeys({\n press: 'Enter',\n });\n\n expect(document.activeElement === tab3).to.be.true;\n\n actionGroup3.focus();\n expect(document.activeElement === actionButton3).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup3.contains(document.activeElement)).to.be.true;\n\n const boundingRect = tab1.getBoundingClientRect();\n // tab1.click() doesn't current reach into the focus management here.\n await sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n boundingRect.left + boundingRect.width / 2,\n boundingRect.top + boundingRect.height / 2,\n ],\n },\n ],\n });\n expect(document.activeElement === tab1).to.be.true;\n\n actionGroup1.focus();\n expect(document.activeElement === actionButton1).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n expect(document.activeElement === tab2).to.be.false;\n expect(actionGroup1.contains(document.activeElement)).to.be.true;\n });\n});\n"],
|
|
5
|
-
"mappings": "AAWA,
|
|
5
|
+
"mappings": ";AAWA,OAAO;AAEP,OAAO;AAEP,OAAO;AACP,OAAO;AACP,OAAO;AAEP,SAAS,gBAAgB,QAAQ,SAAS,iBAAiB;AA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AAS,aAAa,CAAC,EAAE,GAAG,GAAG;AAAA,EAChE,CAAC;AACL,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
import { LitElement } from "lit";
|
|
3
|
+
import { expect } from "@open-wc/testing";
|
|
4
|
+
import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
|
|
5
|
+
describe("RovingTabindex", () => {
|
|
6
|
+
it("constructs with defaults", async () => {
|
|
7
|
+
class TestEl extends LitElement {
|
|
8
|
+
}
|
|
9
|
+
customElements.define("test-roving-tabindex-el", TestEl);
|
|
10
|
+
const el = new TestEl();
|
|
11
|
+
const controller = new RovingTabindexController(
|
|
12
|
+
el
|
|
13
|
+
);
|
|
14
|
+
expect(controller.direction).to.equal("both");
|
|
15
|
+
expect(controller.focusInIndex).to.equal(0);
|
|
16
|
+
expect(controller.isFocusableElement(el)).to.be.true;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
2
19
|
//# sourceMappingURL=roving-tabindex.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["roving-tabindex.test.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*/\n\nimport { LitElement } from 'lit';\nimport { expect } from '@open-wc/testing';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\n\ndescribe('RovingTabindex', () => {\n it('constructs with defaults', async () => {\n class TestEl extends LitElement {}\n customElements.define('test-roving-tabindex-el', TestEl);\n const el = new TestEl();\n const controller = new RovingTabindexController(\n el as LitElement & { shadowRoot: ShadowRoot }\n );\n expect(controller.direction).to.equal('both');\n expect(controller.focusInIndex).to.equal(0);\n expect(controller.isFocusableElement(el)).to.be.true;\n });\n});\n"],
|
|
5
|
-
"mappings": "AAYA,
|
|
5
|
+
"mappings": ";AAYA,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,gCAAgC;AAEzC,SAAS,kBAAkB,MAAM;AAC7B,KAAG,4BAA4B,YAAY;AACvC,UAAM,eAAe,WAAW;AAAA,IAAC;AACjC,mBAAe,OAAO,2BAA2B,MAAM;AACvD,UAAM,KAAK,IAAI,OAAO;AACtB,UAAM,aAAa,IAAI;AAAA,MACnB;AAAA,IACJ;AACA,WAAO,WAAW,SAAS,EAAE,GAAG,MAAM,MAAM;AAC5C,WAAO,WAAW,YAAY,EAAE,GAAG,MAAM,CAAC;AAC1C,WAAO,WAAW,mBAAmB,EAAE,CAAC,EAAE,GAAG,GAAG;AAAA,EACpD,CAAC;AACL,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|