@spectrum-web-components/base 0.4.6-lit-next.184 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/base",
3
- "version": "0.4.6-lit-next.184+aad74d6ac",
3
+ "version": "0.5.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,6 +22,12 @@
22
22
  "exports": {
23
23
  ".": "./src/index.js",
24
24
  "./src/*": "./src/*",
25
+ "./decorators": "./src/decorators.js",
26
+ "./decorators.js": "./src/decorators.js",
27
+ "./directives": "./src/directives.js",
28
+ "./directives.js": "./src/directives.js",
29
+ "./html": "./src/html.js",
30
+ "./html.js": "./src/html.js",
25
31
  "./streaming-listener": "./src/streaming-listener.js",
26
32
  "./streaming-listener.js": "./src/streaming-listener.js",
27
33
  "./package.json": "./package.json"
@@ -50,5 +56,5 @@
50
56
  "types": "./src/index.d.ts",
51
57
  "customElements": "custom-elements.json",
52
58
  "sideEffects": false,
53
- "gitHead": "aad74d6ac41d8450aee82d73aaf58ab949b72a00"
59
+ "gitHead": "df3f333ee26a45f9fc247716b6e8ef051dca630b"
54
60
  }
package/src/Base.d.ts CHANGED
@@ -6,6 +6,7 @@ declare type Constructor<T = Record<string, unknown>> = {
6
6
  export interface SpectrumInterface {
7
7
  shadowRoot: ShadowRoot;
8
8
  isLTR: boolean;
9
+ hasVisibleFocusInTree(): boolean;
9
10
  dir: 'ltr' | 'rtl';
10
11
  }
11
12
  export declare function SpectrumMixin<T extends Constructor<ReactiveElement>>(constructor: T): T & Constructor<SpectrumInterface>;
package/src/Base.js CHANGED
@@ -43,6 +43,24 @@ export function SpectrumMixin(constructor) {
43
43
  get isLTR() {
44
44
  return this.dir === 'ltr';
45
45
  }
46
+ hasVisibleFocusInTree() {
47
+ const activeElement = this.getRootNode()
48
+ .activeElement;
49
+ if (!activeElement) {
50
+ return false;
51
+ }
52
+ // Browsers without support for the `:focus-visible`
53
+ // selector will throw on the following test (Safari, older things).
54
+ // Some won't throw, but will be focusing item rather than the menu and
55
+ // will rely on the polyfill to know whether focus is "visible" or not.
56
+ try {
57
+ return (activeElement.matches(':focus-visible') ||
58
+ activeElement.matches('.focus-visible'));
59
+ }
60
+ catch (error) {
61
+ return activeElement.matches('.focus-visible');
62
+ }
63
+ }
46
64
  connectedCallback() {
47
65
  if (!this.hasAttribute('dir')) {
48
66
  let dirParent = (this.assignedSlot ||
package/src/Base.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Base.js","sourceRoot":"","sources":["Base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAkB7C,MAAM,mBAAmB,GAAqB,IAAI,GAAG,EAAE,CAAC;AAExD,MAAM,SAAS,GAAG,GAAS,EAAE;IACzB,MAAM,GAAG,GACL,QAAQ,CAAC,eAAe,CAAC,GAAG,KAAK,KAAK;QAClC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG;QAC9B,CAAC,CAAC,KAAK,CAAC;IAChB,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC/B,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAEpD,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;IAC1C,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,CAAC,KAAK,CAAC;CAC3B,CAAC,CAAC;AAMH,MAAM,yBAAyB,GAAG,CAAC,EAA2B,EAAW,EAAE,CACvE,OAAO,EAAE,CAAC,6BAA6B,KAAK,W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I,CACP,CAAC;wBACN,CAAC,CAAC,CAAC;qBACN;yBAAM;wBACF,SAAuB,CAAC,6BAA6B,CAClD,IAAI,CACP,CAAC;qBACL;iBACJ;gBACD,IAAI,CAAC,UAAU,GAAG,SAAwB,CAAC;aAC9C;YACD,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9B,CAAC;QAEM,oBAAoB;YACvB,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjB,IAAI,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,eAAe,EAAE;oBAC9C,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;iBACpC;qBAAM;oBACF,IAAI,CAAC,UAAwB,CAAC,4BAA4B,CACvD,IAAI,CACP,CAAC;iBACL;gBACD,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;aAC/B;QACL,CAAC;KACJ;IA/DG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yDACM;IAgEtC,OAAO,wBAAwB,CAAC;AACpC,CAAC;AAED,MAAM,OAAO,eAAgB,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","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, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\ntype ThemeRoot = HTMLElement & {\n startManagingContentDirection: (el: HTMLElement) => void;\n stopManagingContentDirection: (el: HTMLElement) => void;\n};\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SpectrumInterface {\n shadowRoot: ShadowRoot;\n isLTR: boolean;\n dir: 'ltr' | 'rtl';\n}\n\nconst observedForElements: Set<HTMLElement> = new Set();\n\nconst updateRTL = (): void => {\n const dir =\n document.documentElement.dir === 'rtl'\n ? document.documentElement.dir\n : 'ltr';\n observedForElements.forEach((el) => {\n el.setAttribute('dir', dir);\n });\n};\n\nconst rtlObserver = new MutationObserver(updateRTL);\n\nrtlObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['dir'],\n});\n\ntype ContentDirectionManager = HTMLElement & {\n startManagingContentDirection?(): void;\n};\n\nconst canManageContentDirection = (el: ContentDirectionManager): boolean =>\n typeof el.startManagingContentDirection !== 'undefined' ||\n el.tagName === 'SP-THEME';\n\nexport function SpectrumMixin<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<SpectrumInterface> {\n class SlotTextObservingElement extends constructor {\n /**\n * @private\n */\n public shadowRoot!: ShadowRoot;\n private _dirParent?: HTMLElement;\n\n /**\n * @private\n */\n @property({ reflect: true })\n public dir: 'ltr' | 'rtl' = 'ltr';\n\n /**\n * @private\n */\n public get isLTR(): boolean {\n return this.dir === 'ltr';\n }\n\n public connectedCallback(): void {\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement;\n while (\n dirParent !== document.documentElement &&\n !canManageContentDirection(\n dirParent as ContentDirectionManager\n )\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n ((dirParent as unknown) as ShadowRoot)\n .host) as HTMLElement;\n }\n this.dir =\n dirParent.dir === 'rtl' ? dirParent.dir : this.dir || 'ltr';\n if (dirParent === document.documentElement) {\n observedForElements.add(this);\n } else {\n const { localName } = dirParent;\n if (\n localName.search('-') > -1 &&\n !customElements.get(localName)\n ) {\n customElements.whenDefined(localName).then(() => {\n (dirParent as ThemeRoot).startManagingContentDirection(\n this\n );\n });\n } else {\n (dirParent as ThemeRoot).startManagingContentDirection(\n this\n );\n }\n }\n this._dirParent = dirParent as HTMLElement;\n }\n super.connectedCallback();\n }\n\n public disconnectedCallback(): void {\n super.disconnectedCallback();\n if (this._dirParent) {\n if (this._dirParent === document.documentElement) {\n observedForElements.delete(this);\n } else {\n (this._dirParent as ThemeRoot).stopManagingContentDirection(\n this\n );\n }\n this.removeAttribute('dir');\n }\n }\n }\n return SlotTextObservingElement;\n}\n\nexport class SpectrumElement extends SpectrumMixin(LitElement) {}\n"]}
1
+ {"version":3,"file":"Base.js","sourceRoot":"","sources":["Base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAmB7C,MAAM,mBAAmB,GAAqB,IAAI,GAAG,EAAE,CAAC;AAExD,MAAM,SAAS,GAAG,GAAS,EAAE;IACzB,MAAM,GAAG,GACL,QAAQ,CAAC,eAAe,CAAC,GAAG,KAAK,KAAK;QAClC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG;QAC9B,CAAC,CAAC,KAAK,CAAC;IAChB,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC/B,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAEpD,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;IAC1C,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,CAAC,KAAK,CAAC;CAC3B,CAAC,CAAC;AAMH,MAAM,yBAAyB,GAAG,CAAC,EAA2B,EAAW,EAAE,CACvE,OAAO,EA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. 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, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\ntype ThemeRoot = HTMLElement & {\n startManagingContentDirection: (el: HTMLElement) => void;\n stopManagingContentDirection: (el: HTMLElement) => void;\n};\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SpectrumInterface {\n shadowRoot: ShadowRoot;\n isLTR: boolean;\n hasVisibleFocusInTree(): boolean;\n dir: 'ltr' | 'rtl';\n}\n\nconst observedForElements: Set<HTMLElement> = new Set();\n\nconst updateRTL = (): void => {\n const dir =\n document.documentElement.dir === 'rtl'\n ? document.documentElement.dir\n : 'ltr';\n observedForElements.forEach((el) => {\n el.setAttribute('dir', dir);\n });\n};\n\nconst rtlObserver = new MutationObserver(updateRTL);\n\nrtlObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['dir'],\n});\n\ntype ContentDirectionManager = HTMLElement & {\n startManagingContentDirection?(): void;\n};\n\nconst canManageContentDirection = (el: ContentDirectionManager): boolean =>\n typeof el.startManagingContentDirection !== 'undefined' ||\n el.tagName === 'SP-THEME';\n\nexport function SpectrumMixin<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<SpectrumInterface> {\n class SlotTextObservingElement extends constructor {\n /**\n * @private\n */\n public shadowRoot!: ShadowRoot;\n private _dirParent?: HTMLElement;\n\n /**\n * @private\n */\n @property({ reflect: true })\n public dir: 'ltr' | 'rtl' = 'ltr';\n\n /**\n * @private\n */\n public get isLTR(): boolean {\n return this.dir === 'ltr';\n }\n\n public hasVisibleFocusInTree(): boolean {\n const activeElement = (this.getRootNode() as Document)\n .activeElement as HTMLElement;\n if (!activeElement) {\n return false;\n }\n // Browsers without support for the `:focus-visible`\n // selector will throw on the following test (Safari, older things).\n // Some won't throw, but will be focusing item rather than the menu and\n // will rely on the polyfill to know whether focus is \"visible\" or not.\n try {\n return (\n activeElement.matches(':focus-visible') ||\n activeElement.matches('.focus-visible')\n );\n } catch (error) {\n return activeElement.matches('.focus-visible');\n }\n }\n\n public connectedCallback(): void {\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement;\n while (\n dirParent !== document.documentElement &&\n !canManageContentDirection(\n dirParent as ContentDirectionManager\n )\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as unknown as ShadowRoot)\n .host) as HTMLElement;\n }\n this.dir =\n dirParent.dir === 'rtl' ? dirParent.dir : this.dir || 'ltr';\n if (dirParent === document.documentElement) {\n observedForElements.add(this);\n } else {\n const { localName } = dirParent;\n if (\n localName.search('-') > -1 &&\n !customElements.get(localName)\n ) {\n customElements.whenDefined(localName).then(() => {\n (\n dirParent as ThemeRoot\n ).startManagingContentDirection(this);\n });\n } else {\n (dirParent as ThemeRoot).startManagingContentDirection(\n this\n );\n }\n }\n this._dirParent = dirParent as HTMLElement;\n }\n super.connectedCallback();\n }\n\n public disconnectedCallback(): void {\n super.disconnectedCallback();\n if (this._dirParent) {\n if (this._dirParent === document.documentElement) {\n observedForElements.delete(this);\n } else {\n (this._dirParent as ThemeRoot).stopManagingContentDirection(\n this\n );\n }\n this.removeAttribute('dir');\n }\n }\n }\n return SlotTextObservingElement;\n}\n\nexport class SpectrumElement extends SpectrumMixin(LitElement) {}\n"]}
@@ -0,0 +1 @@
1
+ export * from 'lit/decorators.js';
@@ -0,0 +1,13 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export * from 'lit/decorators.js';
13
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,mBAAmB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from 'lit/decorators.js';\n"]}
@@ -0,0 +1,7 @@
1
+ export { ifDefined } from 'lit/directives/if-defined.js';
2
+ export { repeat } from 'lit/directives/repeat.js';
3
+ export { classMap } from 'lit/directives/class-map.js';
4
+ export { styleMap } from 'lit/directives/style-map.js';
5
+ export type { StyleInfo } from 'lit/directives/style-map.js';
6
+ export { until } from 'lit/directives/until.js';
7
+ export { live } from 'lit/directives/live.js';
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export { ifDefined } from 'lit/directives/if-defined.js';
13
+ export { repeat } from 'lit/directives/repeat.js';
14
+ export { classMap } from 'lit/directives/class-map.js';
15
+ export { styleMap } from 'lit/directives/style-map.js';
16
+ export { until } from 'lit/directives/until.js';
17
+ export { live } from 'lit/directives/live.js';
18
+ //# sourceMappingURL=directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directives.js","sourceRoot":"","sources":["directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport { ifDefined } from 'lit/directives/if-defined.js';\nexport { repeat } from 'lit/directives/repeat.js';\nexport { classMap } from 'lit/directives/class-map.js';\nexport { styleMap } from 'lit/directives/style-map.js';\nexport type { StyleInfo } from 'lit/directives/style-map.js';\nexport { until } from 'lit/directives/until.js';\nexport { live } from 'lit/directives/live.js';\n"]}
package/src/html.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { nothing, render } from 'lit/html.js';
package/src/html.js ADDED
@@ -0,0 +1,13 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export { nothing, render } from 'lit/html.js';
13
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport { nothing, render } from 'lit/html.js';\n"]}
package/src/index.d.ts CHANGED
@@ -1,12 +1,3 @@
1
1
  export * from './Base.js';
2
2
  export * from './sizedMixin.js';
3
3
  export * from 'lit';
4
- export * from 'lit/decorators.js';
5
- export { nothing, render } from 'lit/html.js';
6
- export { ifDefined } from 'lit/directives/if-defined.js';
7
- export { repeat } from 'lit/directives/repeat.js';
8
- export { classMap } from 'lit/directives/class-map.js';
9
- export { styleMap } from 'lit/directives/style-map.js';
10
- export type { StyleInfo } from 'lit/directives/style-map.js';
11
- export { until } from 'lit/directives/until.js';
12
- export { live } from 'lit/directives/live.js';
package/src/index.js CHANGED
@@ -12,12 +12,4 @@ governing permissions and limitations under the License.
12
12
  export * from './Base.js';
13
13
  export * from './sizedMixin.js';
14
14
  export * from 'lit';
15
- export * from 'lit/decorators.js';
16
- export { nothing, render } from 'lit/html.js';
17
- export { ifDefined } from 'lit/directives/if-defined.js';
18
- export { repeat } from 'lit/directives/repeat.js';
19
- export { classMap } from 'lit/directives/class-map.js';
20
- export { styleMap } from 'lit/directives/style-map.js';
21
- export { until } from 'lit/directives/until.js';
22
- export { live } from 'lit/directives/live.js';
23
15
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,KAAK,CAAC;AACpB,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Base.js';\nexport * from './sizedMixin.js';\nexport * from 'lit';\nexport * from 'lit/decorators.js';\nexport { nothing, render } from 'lit/html.js';\nexport { ifDefined } from 'lit/directives/if-defined.js';\nexport { repeat } from 'lit/directives/repeat.js';\nexport { classMap } from 'lit/directives/class-map.js';\nexport { styleMap } from 'lit/directives/style-map.js';\nexport type { StyleInfo } from 'lit/directives/style-map.js';\nexport { until } from 'lit/directives/until.js';\nexport { live } from 'lit/directives/live.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,KAAK,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Base.js';\nexport * from './sizedMixin.js';\nexport * from 'lit';\n"]}
@@ -3,12 +3,14 @@ declare type Constructor<T = Record<string, unknown>> = {
3
3
  new (...args: any[]): T;
4
4
  prototype: T;
5
5
  };
6
- export declare type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';
6
+ export declare type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
7
+ export declare type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;
7
8
  export interface SizedElementInterface {
8
9
  size: ElementSize;
9
10
  }
10
- export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, }?: {
11
+ export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, defaultSize, }?: {
11
12
  validSizes?: ElementSize[];
12
13
  noDefaultSize?: boolean;
14
+ defaultSize?: ElementSize;
13
15
  }): T & Constructor<SizedElementInterface>;
14
16
  export {};
package/src/sizedMixin.js CHANGED
@@ -1,22 +1,18 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { property } from 'lit/decorators.js';
3
- export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, } = {}) {
3
+ export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, defaultSize = 'm', } = {}) {
4
4
  class SizedElement extends constructor {
5
5
  constructor() {
6
6
  super(...arguments);
7
- this._size = 'm';
7
+ this._size = defaultSize;
8
8
  }
9
9
  get size() {
10
- return this._size || 'm';
10
+ return this._size || defaultSize;
11
11
  }
12
12
  set size(value) {
13
- const defaultSize = noDefaultSize ? null : 'm';
14
- const size = (value
15
- ? value.toLocaleLowerCase()
16
- : value);
17
- const validSize = (validSizes.includes(size)
18
- ? size
19
- : defaultSize);
13
+ const fallbackSize = noDefaultSize ? null : defaultSize;
14
+ const size = (value ? value.toLocaleLowerCase() : value);
15
+ const validSize = (validSizes.includes(size) ? size : fallbackSize);
20
16
  if (validSize) {
21
17
  this.setAttribute('size', validSize);
22
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAc7C,MAAM,UAAU,UAAU,CACtB,WAAc,EACd,EACI,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAClC,aAAa,MAIb,EAAE;IAEN,MAAM,YAAa,SAAQ,WAAW;QAAtC;;YAyBY,UAAK,GAAuB,GAAG,CAAC;Q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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 { ReactiveElement, PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || 'm';\n }\n\n public set size(value: ElementSize) {\n const defaultSize = noDefaultSize ? null : 'm';\n const size = (value\n ? value.toLocaleLowerCase()\n : value) as ElementSize;\n const validSize = (validSizes.includes(size)\n ? size\n : defaultSize) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = 'm';\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
1
+ {"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAe7C,MAAM,UAAU,U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;IA/BG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAGzC;IA8BL,OAAO,YAAY,CAAC;AACxB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nexport type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const fallbackSize = noDefaultSize ? null : defaultSize;\n const size = (\n value ? value.toLocaleLowerCase() : value\n ) as ElementSize;\n const validSize = (\n validSizes.includes(size) ? size : fallbackSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = defaultSize;\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
@@ -8,6 +8,13 @@ declare type ListenerConfigGroup = {
8
8
  streamInside?: ListenerConfig;
9
9
  streamOutside?: ListenerConfig;
10
10
  };
11
+ /**
12
+ * Performantly manage listening to event in a series, like:
13
+ * - `input[type="range"]`: input, input, etc. => change
14
+ * - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup
15
+ * Lazily bind events to the specific part of the series while
16
+ * throttling streamed events to 1/frame.
17
+ */
11
18
  declare class StreamingListenerDirective extends AsyncDirective {
12
19
  host: EventTarget | Record<string, unknown> | Element;
13
20
  element: Element;
@@ -11,7 +11,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
11
11
  governing permissions and limitations under the License.
12
12
  */
13
13
  import { nothing } from 'lit';
14
- import { directive, AsyncDirective } from 'lit/async-directive.js';
14
+ import { AsyncDirective, directive } from 'lit/async-directive.js';
15
15
  /* c8 ignore next 6 */
16
16
  const defaultListener = [
17
17
  '',
@@ -19,6 +19,13 @@ const defaultListener = [
19
19
  return;
20
20
  },
21
21
  ];
22
+ /**
23
+ * Performantly manage listening to event in a series, like:
24
+ * - `input[type="range"]`: input, input, etc. => change
25
+ * - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup
26
+ * Lazily bind events to the specific part of the series while
27
+ * throttling streamed events to 1/frame.
28
+ */
22
29
  class StreamingListenerDirective extends AsyncDirective {
23
30
  constructor() {
24
31
  super(...arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"streaming-listener.js","sourceRoot":"","sources":["streaming-listener.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;;;;;;;EAUE;AACF,OAAO,EAAE,OAAO,EAAqB,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,SAAS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,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACnE,CAAC;IAED,YAAY;QACR,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC;IAED,WAAW;QACP,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAE4B,SAAS,CAC/D,0BAA0B,CAC7B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\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 { nothing, Part, ElementPart } from 'lit';\nimport { directive, AsyncDirective } from 'lit/async-directive.js';\nimport type { DirectiveResult } from 'lit/directive.js';\n\ntype ListenerConfig = [string | string[], (event?: any) => void];\ntype ListenerConfigGroup = {\n start: ListenerConfig;\n end: ListenerConfig;\n streamInside?: ListenerConfig;\n streamOutside?: ListenerConfig;\n};\n\n/* c8 ignore next 6 */\nconst defaultListener: ListenerConfig = [\n '',\n (): void => {\n return;\n },\n];\n\nclass StreamingListenerDirective extends AsyncDirective {\n host!: EventTarget | Record<string, unknown> | Element;\n element!: Element;\n\n start: ListenerConfig = defaultListener;\n streamInside: ListenerConfig = defaultListener;\n end: ListenerConfig = defaultListener;\n streamOutside: ListenerConfig = defaultListener;\n\n state: 'off' | 'on' = 'off';\n\n /* c8 ignore next 4 */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n render(_configGroup: ListenerConfigGroup): typeof nothing {\n return nothing;\n }\n\n update(\n part: Part,\n [\n {\n start,\n end,\n streamInside = defaultListener,\n streamOutside = defaultListener,\n },\n ]: Parameters<this['render']>\n ): void {\n if (this.element !== (part as ElementPart).element) {\n this.element = (part as ElementPart).element;\n this.removeListeners();\n }\n this.host =\n (part.options?.host as Record<string, unknown>) || this.element;\n this.start = start;\n this.end = end;\n this.streamInside = streamInside;\n this.streamOutside = streamOutside;\n this.addListeners();\n }\n\n addListeners(state?: 'on' | 'off'): void {\n this.state = state || this.state;\n if (this.state === 'off') {\n this.addListener(this.streamOutside[0], this.handleBetween);\n this.addListener(this.start[0], this.handleStart);\n } else if (this.state === 'on') {\n this.addListener(this.streamInside[0], this.handleStream);\n this.addListener(this.end[0], this.handleEnd);\n }\n }\n\n callHandler(\n value: (event: Event) => void | EventListenerObject,\n event: Event\n ): void {\n if (typeof value === 'function') {\n (value as (event: Event) => void).call(this.host, event);\n } else {\n (value as EventListenerObject).handleEvent(event);\n }\n }\n\n handleStart = (event: Event): void => {\n this.callHandler(this.start[1], event);\n if (event.defaultPrevented) {\n return;\n }\n this.removeListeners();\n this.addListeners('on');\n };\n\n handleStream = (event: Event): void => {\n this.callHandler(this.streamInside[1], event);\n };\n\n handleEnd = (event: Event): void => {\n this.callHandler(this.end[1], event);\n this.removeListeners();\n this.addListeners('off');\n };\n\n handleBetween = (event: Event): void => {\n this.callHandler(this.streamOutside[1], event);\n };\n\n addListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.addEventListener(eventName, fn);\n });\n } else {\n this.element.addEventListener(type, fn);\n }\n }\n\n removeListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.removeEventListener(eventName, fn);\n });\n } else {\n this.element.removeEventListener(type, fn);\n }\n }\n\n removeListeners(): void {\n this.removeListener(this.start[0], this.handleStart);\n this.removeListener(this.streamInside[0], this.handleStream);\n this.removeListener(this.end[0], this.handleEnd);\n this.removeListener(this.streamOutside[0], this.handleBetween);\n }\n\n disconnected(): void {\n this.removeListeners();\n }\n\n reconnected(): void {\n this.addListeners();\n }\n}\n\nexport const streamingListener: (\n _configGroup: ListenerConfigGroup\n) => DirectiveResult<typeof StreamingListenerDirective> = directive(\n StreamingListenerDirective\n);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type { StreamingListenerDirective };\n"]}
1
+ {"version":3,"file":"streaming-listener.js","sourceRoot":"","sources":["streaming-listener.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;;;;;;;EAUE;AACF,OAAO,EAAe,OAAO,EAAQ,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWnE,sBAAsB;AACtB,MAAM,eAAe,GAAmB;IACpC,EAAE;IACF,GAAS,EAAE;QACP,OAAO;IACX,CAAC;CACJ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,0BAA2B,SAAQ,cAAc;IAAvD;;QAII,UAAK,GAAmB,eAAe,CAAC;QACxC,iBAAY,GAAmB,eAAe,CAAC;QAC/C,QAAG,GAAmB,eAAe,CAAC;QACtC,kBAAa,GAAmB,eAAe,CAAC;QAEhD,UAAK,GAAiB,KAAK,CAAC;QAsD5B,gBAAW,GAAG,CAAC,KAAY,EAAQ,EAAE;YACjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YACvC,IAAI,KAAK,CAAC,gBAAgB,EAAE;gBACxB,OAAO;aACV;YACD,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;QAEF,iBAAY,GAAG,CAAC,KAAY,EAAQ,EAAE;YAClC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC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AAG,CAAC,CAAC,SAAS,EAAE,EAAE;gBACnB,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;SAC9C;IACL,CAAC;IAED,eAAe;QACX,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACnE,CAAC;IAED,YAAY;QACR,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC;IAED,WAAW;QACP,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAE4B,SAAS,CAC/D,0BAA0B,CAC7B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\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 { ElementPart, nothing, Part } from 'lit';\nimport { AsyncDirective, directive } from 'lit/async-directive.js';\nimport type { DirectiveResult } from 'lit/directive.js';\n\ntype ListenerConfig = [string | string[], (event?: any) => void];\ntype ListenerConfigGroup = {\n start: ListenerConfig;\n end: ListenerConfig;\n streamInside?: ListenerConfig;\n streamOutside?: ListenerConfig;\n};\n\n/* c8 ignore next 6 */\nconst defaultListener: ListenerConfig = [\n '',\n (): void => {\n return;\n },\n];\n\n/**\n * Performantly manage listening to event in a series, like:\n * - `input[type=\"range\"]`: input, input, etc. => change\n * - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup\n * Lazily bind events to the specific part of the series while\n * throttling streamed events to 1/frame.\n */\nclass StreamingListenerDirective extends AsyncDirective {\n host!: EventTarget | Record<string, unknown> | Element;\n element!: Element;\n\n start: ListenerConfig = defaultListener;\n streamInside: ListenerConfig = defaultListener;\n end: ListenerConfig = defaultListener;\n streamOutside: ListenerConfig = defaultListener;\n\n state: 'off' | 'on' = 'off';\n\n /* c8 ignore next 4 */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n render(_configGroup: ListenerConfigGroup): typeof nothing {\n return nothing;\n }\n\n update(\n part: Part,\n [\n {\n start,\n end,\n streamInside = defaultListener,\n streamOutside = defaultListener,\n },\n ]: Parameters<this['render']>\n ): void {\n if (this.element !== (part as ElementPart).element) {\n this.element = (part as ElementPart).element;\n this.removeListeners();\n }\n this.host =\n (part.options?.host as Record<string, unknown>) || this.element;\n this.start = start;\n this.end = end;\n this.streamInside = streamInside;\n this.streamOutside = streamOutside;\n this.addListeners();\n }\n\n addListeners(state?: 'on' | 'off'): void {\n this.state = state || this.state;\n if (this.state === 'off') {\n this.addListener(this.streamOutside[0], this.handleBetween);\n this.addListener(this.start[0], this.handleStart);\n } else if (this.state === 'on') {\n this.addListener(this.streamInside[0], this.handleStream);\n this.addListener(this.end[0], this.handleEnd);\n }\n }\n\n callHandler(\n value: (event: Event) => void | EventListenerObject,\n event: Event\n ): void {\n if (typeof value === 'function') {\n (value as (event: Event) => void).call(this.host, event);\n } else {\n (value as EventListenerObject).handleEvent(event);\n }\n }\n\n handleStart = (event: Event): void => {\n this.callHandler(this.start[1], event);\n if (event.defaultPrevented) {\n return;\n }\n this.removeListeners();\n this.addListeners('on');\n };\n\n handleStream = (event: Event): void => {\n this.callHandler(this.streamInside[1], event);\n };\n\n handleEnd = (event: Event): void => {\n this.callHandler(this.end[1], event);\n this.removeListeners();\n this.addListeners('off');\n };\n\n handleBetween = (event: Event): void => {\n this.callHandler(this.streamOutside[1], event);\n };\n\n addListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.addEventListener(eventName, fn);\n });\n } else {\n this.element.addEventListener(type, fn);\n }\n }\n\n removeListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.removeEventListener(eventName, fn);\n });\n } else {\n this.element.removeEventListener(type, fn);\n }\n }\n\n removeListeners(): void {\n this.removeListener(this.start[0], this.handleStart);\n this.removeListener(this.streamInside[0], this.handleStream);\n this.removeListener(this.end[0], this.handleEnd);\n this.removeListener(this.streamOutside[0], this.handleBetween);\n }\n\n disconnected(): void {\n this.removeListeners();\n }\n\n reconnected(): void {\n this.addListeners();\n }\n}\n\nexport const streamingListener: (\n _configGroup: ListenerConfigGroup\n) => DirectiveResult<typeof StreamingListenerDirective> = directive(\n StreamingListenerDirective\n);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type { StreamingListenerDirective };\n"]}