@spectrum-web-components/reactive-controllers 0.3.5 → 0.3.6-react.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/reactive-controllers",
3
- "version": "0.3.5",
3
+ "version": "0.3.6-react.78+e4fada004",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -79,5 +79,5 @@
79
79
  "sideEffects": [
80
80
  "./**/*.dev.js"
81
81
  ],
82
- "gitHead": "02534b6685ff89a21dba86c09b2169f5b30a46f2"
82
+ "gitHead": "e4fada0040dcaf1e1267f2159f366ec708cb2d09"
83
83
  }
package/src/Color.dev.js CHANGED
@@ -146,6 +146,7 @@ export class ColorController {
146
146
  this._hue = hue;
147
147
  this.host.requestUpdate("hue", oldValue);
148
148
  }
149
+ /* c8 ignore next 3 */
149
150
  get value() {
150
151
  return this.color;
151
152
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["Color.ts"],
4
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 /* c8 ignore next 3 */\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 /* c8 ignore next 3 */\n if (color === this.color) {\n return;\n }\n const oldValue = this._color;\n this._color = new TinyColor(color);\n const format = this._color.format;\n let isString = typeof color === 'string' || color instanceof String;\n\n if (format.startsWith('hex')) {\n isString = (color as string).startsWith('#');\n }\n\n this._format = {\n format,\n isString,\n };\n\n this.setColorProcess(this._color, color, format, isString);\n this.host.requestUpdate('color', oldValue);\n }\n\n private _color = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public getColor(format: string): ColorValue {\n const formatOptions: Record<string, keyof TinyColorToValue> = {\n hsl: 'toHsl',\n };\n return this._color[formatOptions[format]]();\n }\n\n public setColor(color: TinyColor): void {\n this._color = color;\n const isString =\n typeof this._color.originalInput === 'string' ||\n this._color.originalInput instanceof String;\n this.setColorProcess(this._color, color, this._color.format, isString);\n }\n\n public getHslString(): string {\n return this._color.toHslString();\n }\n\n private _previousColor = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n public restorePreviousColor(): void {\n this.setColor(this._previousColor);\n }\n\n private _format: { format: string; isString: boolean } = {\n format: '',\n isString: false,\n };\n}\n"],
5
- "mappings": ";AAaA,SAA0C,iBAAiB;AAcpD,aAAM,gCACT;AACG,aAAM,gCACT;AACG,aAAM,mBAAmB;AAiBhC,MAAM,cAAc,CAAC,OAAkB,aACnC,WAAW,MAAM,YAAY,IAAI,MAAM,MAAM;AAE1C,aAAM,gBAAgB;AAAA,EA8FzB,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAaF;AAtBF,SAAU,YAAkC;AAiD5C,SAAQ,OAAO;AAEf,SAAU,oBAGN;AAAA,MACA,KAAK,CAAC,OAAO,aACT,WAAW,MAAM,YAAY,IAAI,MAAM,MAAM;AAAA,MACjD,MAAM,CAAC,OAAO,aACV,WAAW,MAAM,sBAAsB,IAAI,MAAM,gBAAgB;AAAA,MACrE,MAAM,CAAC,OAAO,aACV,WAAW,MAAM,aAAa,IAAI,MAAM,OAAO;AAAA,MACnD,MAAM,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,YAAY;AAAA,MACrD,KAAK,CAAC,OAAO,aAAa;AACtB,YAAI,KAAK,cAAc,OAAO;AAC1B,cAAI,UAAU;AACV,kBAAM,YAAY,MAAM,YAAY;AACpC,mBAAO,UAAU,QAAQ,kBAAkB,KAAK,KAAK,KAAK;AAAA,UAC9D,OAAO;AACH,kBAAM,EAAE,GAAG,GAAG,EAAE,IAAI,MAAM,MAAM;AAChC,mBAAO,EAAE,GAAG,KAAK,KAAK,GAAG,GAAG,EAAE;AAAA,UAClC;AAAA,QACJ,OAAO;AACH,cAAI,UAAU;AACV,kBAAM,YAAY,MAAM,YAAY;AACpC,mBAAO,UAAU;AAAA,cACb;AAAA,cACA,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AA,EAEA,IAAW,MAAM,OAAmB;AAEhC,QAAI,UAAU,KAAK,OAAO;AACtB;AAAA,IACJ;AACA,UAAM,WAAW,KAAK;AACtB,SAAK,SAAS,IAAI,UAAU,KAAK;AACjC,UAAM,SAAS,KAAK,OAAO;AAC3B,QAAI,WAAW,OAAO,UAAU,YAAY,iBAAiB;AAE7D,QAAI,OAAO,WAAW,KAAK,GAAG;AAC1B,iBAAY,MAAiB,WAAW,GAAG;AAAA,IAC/C;AAEA,SAAK,UAAU;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAEA,SAAK,gBAAgB,KAAK,QAAQ,OAAO,QAAQ,QAAQ;AACzD,SAAK,KAAK,cAAc,SAAS,QAAQ;AAAA,EAC7C;AAAA,EAIO,SAAS,QAA4B;AACxC,UAAM,gBAAwD;AAAA,MAC1D,KAAK;AAAA,IACT;AACA,WAAO,KAAK,OAAO,cAAc,MAAM,CAAC,EAAE;AAAA,EAC9C;AAAA,EAEO,SAAS,OAAwB;AACpC,SAAK,SAAS;AACd,UAAM,WACF,OAAO,KAAK,OAAO,kBAAkB,YACrC,KAAK,OAAO,yBAAyB;AACzC,SAAK,gBAAgB,KAAK,QAAQ,OAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,EACzE;AAAA,EAEO,eAAuB;AAC1B,WAAO,KAAK,OAAO,YAAY;AAAA,EACnC;AAAA,EAIO,oBAA0B;AAC7B,SAAK,iBAAiB,KAAK,OAAO,MAAM;AAAA,EAC5C;AAAA,EAEO,uBAA6B;AAChC,SAAK,SAAS,KAAK,cAAc;AAAA,EACrC;AAMJ;",
6
6
  "names": ["h"]
7
7
  }
package/src/Color.js.map CHANGED
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["Color.ts"],
4
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 /* c8 ignore next 3 */\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 /* c8 ignore next 3 */\n if (color === this.color) {\n return;\n }\n const oldValue = this._color;\n this._color = new TinyColor(color);\n const format = this._color.format;\n let isString = typeof color === 'string' || color instanceof String;\n\n if (format.startsWith('hex')) {\n isString = (color as string).startsWith('#');\n }\n\n this._format = {\n format,\n isString,\n };\n\n this.setColorProcess(this._color, color, format, isString);\n this.host.requestUpdate('color', oldValue);\n }\n\n private _color = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public getColor(format: string): ColorValue {\n const formatOptions: Record<string, keyof TinyColorToValue> = {\n hsl: 'toHsl',\n };\n return this._color[formatOptions[format]]();\n }\n\n public setColor(color: TinyColor): void {\n this._color = color;\n const isString =\n typeof this._color.originalInput === 'string' ||\n this._color.originalInput instanceof String;\n this.setColorProcess(this._color, color, this._color.format, isString);\n }\n\n public getHslString(): string {\n return this._color.toHslString();\n }\n\n private _previousColor = new TinyColor({ h: 0, s: 1, v: 1 });\n\n public savePreviousColor(): void {\n this._previousColor = this._color.clone();\n }\n\n public restorePreviousColor(): void {\n this.setColor(this._previousColor);\n }\n\n private _format: { format: string; isString: boolean } = {\n format: '',\n isString: false,\n };\n}\n"],
5
- "mappings": "aAaA,OAA0C,aAAAA,MAAiB,kBAcpD,aAAM,8BACT,gDACS,8BACT,gDACS,iBAAmB,wBAiBhC,MAAMC,EAAc,CAACC,EAAkBC,IACnCA,EAAWD,EAAM,YAAY,EAAIA,EAAM,MAAM,EAE1C,aAAM,eAAgB,CA8FzB,YACIE,EACA,CACI,kBAAAC,EACA,sBAAAC,EACA,UAAAC,CACJ,EAaF,CAtBF,KAAU,UAAkC,MAiD5C,KAAQ,KAAO,EAEf,KAAU,kBAGN,CACA,IAAK,CAACL,EAAOC,IACTA,EAAWD,EAAM,YAAY,EAAIA,EAAM,MAAM,EACjD,KAAM,CAACA,EAAOC,IACVA,EAAWD,EAAM,sBAAsB,EAAIA,EAAM,gBAAgB,EACrE,KAAM,CAACA,EAAOC,IACVA,EAAWD,EAAM,aAAa,EAAIA,EAAM,OAAO,EACnD,KAAOA,GAAUA,EAAM,OAAO,GAAKA,EAAM,YAAY,EACrD,IAAK,C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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,CAAM,CAAC,EAAE,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
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
7
  }
@@ -23,9 +23,13 @@ export class FocusGroupController {
23
23
  return;
24
24
  };
25
25
  this._focused = false;
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
27
  this._focusInIndex = (_elements) => 0;
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
29
  this.isFocusableElement = (_el) => true;
28
30
  this._listenerScope = () => this.host;
31
+ // When elements are virtualized, the delta between the first element
32
+ // and the first rendered element.
29
33
  this.offset = 0;
30
34
  this.handleFocusin = (event) => {
31
35
  if (!this.isEventWithinListenerScope(event))
@@ -166,7 +170,10 @@ export class FocusGroupController {
166
170
  const { length } = this.elements;
167
171
  let steps = length;
168
172
  let nextIndex = (length + this.currentIndex + diff) % length;
169
- while (steps && this.elements[nextIndex] && !this.isFocusableElement(this.elements[nextIndex])) {
173
+ while (
174
+ // don't cycle the elements more than once
175
+ steps && this.elements[nextIndex] && !this.isFocusableElement(this.elements[nextIndex])
176
+ ) {
170
177
  nextIndex = (length + nextIndex + diff) % length;
171
178
  steps -= 1;
172
179
  }
@@ -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\nfunction ensureMethod<T, RT>(\n value: T | RT | undefined,\n type: string,\n fallback: T\n): T {\n if (typeof value === type) {\n return (() => value) as T;\n } else if (typeof value === 'function') {\n return value as T;\n }\n return fallback;\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 /* c8 ignore next 1 */\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 this._direction = ensureMethod<() => DirectionTypes, DirectionTypes>(\n direction,\n 'string',\n this._direction\n );\n this.elementEnterAction = elementEnterAction || this.elementEnterAction;\n this._focusInIndex = ensureMethod<(_elements: T[]) => number, number>(\n focusInIndex,\n 'number',\n this._focusInIndex\n );\n this._listenerScope = ensureMethod<() => HTMLElement, HTMLElement>(\n listenerScope,\n 'object',\n this._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": ";AAuBA,SAAS,aACL,OACA,MACA,UACC;AACD,MAAI,OAAO,UAAU,MAAM;AACvB,WAAQ,MAAM;AAAA,EAClB,WAAW,OAAO,UAAU,YAAY;AACpC,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,aAAM,qBAEb;AAAA,EA4EI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IAC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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
  }
@@ -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\nfunction ensureMethod<T, RT>(\n value: T | RT | undefined,\n type: string,\n fallback: T\n): T {\n if (typeof value === type) {\n return (() => value) as T;\n } else if (typeof value === 'function') {\n return value as T;\n }\n return fallback;\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 /* c8 ignore next 1 */\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 this._direction = ensureMethod<() => DirectionTypes, DirectionTypes>(\n direction,\n 'string',\n this._direction\n );\n this.elementEnterAction = elementEnterAction || this.elementEnterAction;\n this._focusInIndex = ensureMethod<(_elements: T[]) => number, number>(\n focusInIndex,\n 'number',\n this._focusInIndex\n );\n this._listenerScope = ensureMethod<() => HTMLElement, HTMLElement>(\n listenerScope,\n 'object',\n this._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": "aAuBA,SAASA,EACLC,EACAC,EACAC,EACC,CACD,OAAI,OAAOF,IAAUC,EACT,IAAMD,EACP,OAAOA,GAAU,WACjBA,EAEJE,CACX,CAEO,aAAM,oBAEb,CA4EI,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["ensureMethod", "value", "type", "fallback", "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
  }