@spectrum-web-components/base 0.31.1-react.21 → 0.32.0
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.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -107,5 +107,5 @@
|
|
|
107
107
|
"sideEffects": [
|
|
108
108
|
"./**/*.dev.js"
|
|
109
109
|
],
|
|
110
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "c5f67662ac54d0e37debaf7cbd7c2df60e8b294e"
|
|
111
111
|
}
|
|
@@ -23,14 +23,17 @@ declare class StreamingListenerDirective extends AsyncDirective {
|
|
|
23
23
|
end: ListenerConfig;
|
|
24
24
|
streamOutside: ListenerConfig;
|
|
25
25
|
state: 'off' | 'on';
|
|
26
|
+
stream?: number;
|
|
26
27
|
render(_configGroup: ListenerConfigGroup): typeof nothing;
|
|
27
28
|
update(part: Part, [{ start, end, streamInside, streamOutside, },]: Parameters<this['render']>): void;
|
|
28
29
|
addListeners(state?: 'on' | 'off'): void;
|
|
29
30
|
callHandler(value: (event: Event) => void | EventListenerObject, event: Event): void;
|
|
31
|
+
handleStream(value: (event: Event) => void | EventListenerObject, event: Event): void;
|
|
32
|
+
clearStream(): void;
|
|
30
33
|
handleStart: (event: Event) => void;
|
|
31
|
-
|
|
34
|
+
handleInside: (event: Event) => void;
|
|
32
35
|
handleEnd: (event: Event) => void;
|
|
33
|
-
|
|
36
|
+
handleOutside: (event: Event) => void;
|
|
34
37
|
addListener(type: string | string[], fn: (event: Event) => void): void;
|
|
35
38
|
removeListener(type: string | string[], fn: (event: Event) => void): void;
|
|
36
39
|
removeListeners(): void;
|
|
@@ -16,6 +16,7 @@ class StreamingListenerDirective extends AsyncDirective {
|
|
|
16
16
|
this.streamOutside = defaultListener;
|
|
17
17
|
this.state = "off";
|
|
18
18
|
this.handleStart = (event) => {
|
|
19
|
+
this.clearStream();
|
|
19
20
|
this.callHandler(this.start[1], event);
|
|
20
21
|
if (event.defaultPrevented) {
|
|
21
22
|
return;
|
|
@@ -23,16 +24,17 @@ class StreamingListenerDirective extends AsyncDirective {
|
|
|
23
24
|
this.removeListeners();
|
|
24
25
|
this.addListeners("on");
|
|
25
26
|
};
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
27
|
+
this.handleInside = (event) => {
|
|
28
|
+
this.handleStream(this.streamInside[1], event);
|
|
28
29
|
};
|
|
29
30
|
this.handleEnd = (event) => {
|
|
31
|
+
this.clearStream();
|
|
30
32
|
this.callHandler(this.end[1], event);
|
|
31
33
|
this.removeListeners();
|
|
32
34
|
this.addListeners("off");
|
|
33
35
|
};
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
+
this.handleOutside = (event) => {
|
|
37
|
+
this.handleStream(this.streamOutside[1], event);
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
/* c8 ignore next 4 */
|
|
@@ -63,10 +65,10 @@ class StreamingListenerDirective extends AsyncDirective {
|
|
|
63
65
|
addListeners(state) {
|
|
64
66
|
this.state = state || this.state;
|
|
65
67
|
if (this.state === "off") {
|
|
66
|
-
this.addListener(this.streamOutside[0], this.
|
|
68
|
+
this.addListener(this.streamOutside[0], this.handleOutside);
|
|
67
69
|
this.addListener(this.start[0], this.handleStart);
|
|
68
70
|
} else if (this.state === "on") {
|
|
69
|
-
this.addListener(this.streamInside[0], this.
|
|
71
|
+
this.addListener(this.streamInside[0], this.handleInside);
|
|
70
72
|
this.addListener(this.end[0], this.handleEnd);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -77,6 +79,21 @@ class StreamingListenerDirective extends AsyncDirective {
|
|
|
77
79
|
value.handleEvent(event);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
82
|
+
handleStream(value, event) {
|
|
83
|
+
if (this.stream) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.callHandler(value, event);
|
|
87
|
+
this.stream = requestAnimationFrame(() => {
|
|
88
|
+
this.stream = void 0;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
clearStream() {
|
|
92
|
+
if (this.stream != null) {
|
|
93
|
+
cancelAnimationFrame(this.stream);
|
|
94
|
+
this.stream = void 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
80
97
|
addListener(type, fn) {
|
|
81
98
|
if (Array.isArray(type)) {
|
|
82
99
|
type.map((eventName) => {
|
|
@@ -97,9 +114,9 @@ class StreamingListenerDirective extends AsyncDirective {
|
|
|
97
114
|
}
|
|
98
115
|
removeListeners() {
|
|
99
116
|
this.removeListener(this.start[0], this.handleStart);
|
|
100
|
-
this.removeListener(this.streamInside[0], this.
|
|
117
|
+
this.removeListener(this.streamInside[0], this.handleInside);
|
|
101
118
|
this.removeListener(this.end[0], this.handleEnd);
|
|
102
|
-
this.removeListener(this.streamOutside[0], this.
|
|
119
|
+
this.removeListener(this.streamOutside[0], this.handleOutside);
|
|
103
120
|
}
|
|
104
121
|
disconnected() {
|
|
105
122
|
this.removeListeners();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["streaming-listener.ts"],
|
|
4
|
-
"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 override 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.
|
|
5
|
-
"mappings": ";AAYA,SAAsB,eAAqB;AAC3C,SAAS,gBAAgB,iBAAiB;AAY1C,MAAM,kBAAkC;AAAA,EACpC;AAAA,EACA,MAAY;AACR;AAAA,EACJ;AACJ;AASA,MAAM,mCAAmC,eAAe;AAAA,EAAxD;AAAA;AAII,iBAAwB;AACxB,wBAA+B;AAC/B,eAAsB;AACtB,yBAAgC;AAEhC,iBAAsB;
|
|
4
|
+
"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 // Animation frame that will unlock the next \"stream\" event if/when it is dispatched.\n stream?: number;\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 override 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.handleOutside);\n this.addListener(this.start[0], this.handleStart);\n } else if (this.state === 'on') {\n this.addListener(this.streamInside[0], this.handleInside);\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 handleStream(\n value: (event: Event) => void | EventListenerObject,\n event: Event\n ): void {\n if (this.stream) {\n return;\n }\n this.callHandler(value, event);\n this.stream = requestAnimationFrame(() => {\n this.stream = undefined;\n });\n }\n\n clearStream(): void {\n if (this.stream != null) {\n // Ensure steam events NEVER go after a start or event event.\n cancelAnimationFrame(this.stream);\n this.stream = undefined;\n }\n }\n\n handleStart = (event: Event): void => {\n this.clearStream();\n this.callHandler(this.start[1], event);\n if (event.defaultPrevented) {\n return;\n }\n this.removeListeners();\n this.addListeners('on');\n };\n\n handleInside = (event: Event): void => {\n this.handleStream(this.streamInside[1], event);\n };\n\n handleEnd = (event: Event): void => {\n this.clearStream();\n this.callHandler(this.end[1], event);\n this.removeListeners();\n this.addListeners('off');\n };\n\n handleOutside = (event: Event): void => {\n this.handleStream(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.handleInside);\n this.removeListener(this.end[0], this.handleEnd);\n this.removeListener(this.streamOutside[0], this.handleOutside);\n }\n\n override disconnected(): void {\n this.removeListeners();\n }\n\n /* c8 ignore next 3 */\n override 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"],
|
|
5
|
+
"mappings": ";AAYA,SAAsB,eAAqB;AAC3C,SAAS,gBAAgB,iBAAiB;AAY1C,MAAM,kBAAkC;AAAA,EACpC;AAAA,EACA,MAAY;AACR;AAAA,EACJ;AACJ;AASA,MAAM,mCAAmC,eAAe;AAAA,EAAxD;AAAA;AAII,iBAAwB;AACxB,wBAA+B;AAC/B,eAAsB;AACtB,yBAAgC;AAEhC,iBAAsB;AA6EtB,uBAAc,CAAC,UAAuB;AAClC,WAAK,YAAY;AACjB,WAAK,YAAY,KAAK,MAAM,CAAC,GAAG,KAAK;AACrC,UAAI,MAAM,kBAAkB;AACxB;AAAA,MACJ;AACA,WAAK,gBAAgB;AACrB,WAAK,aAAa,IAAI;AAAA,IAC1B;AAEA,wBAAe,CAAC,UAAuB;AACnC,WAAK,aAAa,KAAK,aAAa,CAAC,GAAG,KAAK;AAAA,IACjD;AAEA,qBAAY,CAAC,UAAuB;AAChC,WAAK,YAAY;AACjB,WAAK,YAAY,KAAK,IAAI,CAAC,GAAG,KAAK;AACnC,WAAK,gBAAgB;AACrB,WAAK,aAAa,KAAK;AAAA,IAC3B;AAEA,yBAAgB,CAAC,UAAuB;AACpC,WAAK,aAAa,KAAK,cAAc,CAAC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AAM;AAErB,2BAAqB,KAAK,MAAM;AAChC,WAAK,SAAS;AAAA,IAClB;AAAA,EACJ;AAAA,EA2BA,YAAY,MAAyB,IAAkC;AACnE,QAAI,MAAM,QAAQ,IAAI,GAAG;AACrB,WAAK,IAAI,CAAC,cAAc;AACpB,aAAK,QAAQ,iBAAiB,WAAW,EAAE;AAAA,MAC/C,CAAC;AAAA,IACL,OAAO;AACH,WAAK,QAAQ,iBAAiB,MAAM,EAAE;AAAA,IAC1C;AAAA,EACJ;AAAA,EAEA,eAAe,MAAyB,IAAkC;AACtE,QAAI,MAAM,QAAQ,IAAI,GAAG;AACrB,WAAK,IAAI,CAAC,cAAc;AACpB,aAAK,QAAQ,oBAAoB,WAAW,EAAE;AAAA,MAClD,CAAC;AAAA,IACL,OAAO;AACH,WAAK,QAAQ,oBAAoB,MAAM,EAAE;AAAA,IAC7C;AAAA,EACJ;AAAA,EAEA,kBAAwB;AACpB,SAAK,eAAe,KAAK,MAAM,CAAC,GAAG,KAAK,WAAW;AACnD,SAAK,eAAe,KAAK,aAAa,CAAC,GAAG,KAAK,YAAY;AAC3D,SAAK,eAAe,KAAK,IAAI,CAAC,GAAG,KAAK,SAAS;AAC/C,SAAK,eAAe,KAAK,cAAc,CAAC,GAAG,KAAK,aAAa;AAAA,EACjE;AAAA,EAES,eAAqB;AAC1B,SAAK,gBAAgB;AAAA,EACzB;AAAA;AAAA,EAGS,cAAoB;AACzB,SAAK,aAAa;AAAA,EACtB;AACJ;AAEO,aAAM,oBAE6C;AAAA,EACtD;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{nothing as
|
|
1
|
+
"use strict";import{nothing as a}from"lit";import{AsyncDirective as o,directive as h}from"lit/async-directive.js";const i=["",()=>{}];class m extends o{constructor(){super(...arguments);this.start=i;this.streamInside=i;this.end=i;this.streamOutside=i;this.state="off";this.handleStart=e=>{this.clearStream(),this.callHandler(this.start[1],e),!e.defaultPrevented&&(this.removeListeners(),this.addListeners("on"))};this.handleInside=e=>{this.handleStream(this.streamInside[1],e)};this.handleEnd=e=>{this.clearStream(),this.callHandler(this.end[1],e),this.removeListeners(),this.addListeners("off")};this.handleOutside=e=>{this.handleStream(this.streamOutside[1],e)}}render(e){return a}update(e,[{start:t,end:s,streamInside:r=i,streamOutside:d=i}]){var n;this.element!==e.element&&(this.element=e.element,this.removeListeners()),this.host=((n=e.options)==null?void 0:n.host)||this.element,this.start=t,this.end=s,this.streamInside=r,this.streamOutside=d,this.addListeners()}addListeners(e){this.state=e||this.state,this.state==="off"?(this.addListener(this.streamOutside[0],this.handleOutside),this.addListener(this.start[0],this.handleStart)):this.state==="on"&&(this.addListener(this.streamInside[0],this.handleInside),this.addListener(this.end[0],this.handleEnd))}callHandler(e,t){typeof e=="function"?e.call(this.host,t):e.handleEvent(t)}handleStream(e,t){this.stream||(this.callHandler(e,t),this.stream=requestAnimationFrame(()=>{this.stream=void 0}))}clearStream(){this.stream!=null&&(cancelAnimationFrame(this.stream),this.stream=void 0)}addListener(e,t){Array.isArray(e)?e.map(s=>{this.element.addEventListener(s,t)}):this.element.addEventListener(e,t)}removeListener(e,t){Array.isArray(e)?e.map(s=>{this.element.removeEventListener(s,t)}):this.element.removeEventListener(e,t)}removeListeners(){this.removeListener(this.start[0],this.handleStart),this.removeListener(this.streamInside[0],this.handleInside),this.removeListener(this.end[0],this.handleEnd),this.removeListener(this.streamOutside[0],this.handleOutside)}disconnected(){this.removeListeners()}reconnected(){this.addListeners()}}export const streamingListener=h(m);
|
|
2
2
|
//# sourceMappingURL=streaming-listener.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["streaming-listener.ts"],
|
|
4
|
-
"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 override 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.
|
|
5
|
-
"mappings": "aAYA,OAAsB,WAAAA,MAAqB,MAC3C,OAAS,kBAAAC,EAAgB,aAAAC,MAAiB,yBAY1C,MAAMC,EAAkC,CACpC,GACA,IAAY,CAEZ,CACJ,EASA,MAAMC,UAAmCH,CAAe,CAAxD,kCAII,WAAwBE,EACxB,kBAA+BA,EAC/B,SAAsBA,EACtB,mBAAgCA,EAEhC,WAAsB,
|
|
4
|
+
"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 // Animation frame that will unlock the next \"stream\" event if/when it is dispatched.\n stream?: number;\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 override 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.handleOutside);\n this.addListener(this.start[0], this.handleStart);\n } else if (this.state === 'on') {\n this.addListener(this.streamInside[0], this.handleInside);\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 handleStream(\n value: (event: Event) => void | EventListenerObject,\n event: Event\n ): void {\n if (this.stream) {\n return;\n }\n this.callHandler(value, event);\n this.stream = requestAnimationFrame(() => {\n this.stream = undefined;\n });\n }\n\n clearStream(): void {\n if (this.stream != null) {\n // Ensure steam events NEVER go after a start or event event.\n cancelAnimationFrame(this.stream);\n this.stream = undefined;\n }\n }\n\n handleStart = (event: Event): void => {\n this.clearStream();\n this.callHandler(this.start[1], event);\n if (event.defaultPrevented) {\n return;\n }\n this.removeListeners();\n this.addListeners('on');\n };\n\n handleInside = (event: Event): void => {\n this.handleStream(this.streamInside[1], event);\n };\n\n handleEnd = (event: Event): void => {\n this.clearStream();\n this.callHandler(this.end[1], event);\n this.removeListeners();\n this.addListeners('off');\n };\n\n handleOutside = (event: Event): void => {\n this.handleStream(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.handleInside);\n this.removeListener(this.end[0], this.handleEnd);\n this.removeListener(this.streamOutside[0], this.handleOutside);\n }\n\n override disconnected(): void {\n this.removeListeners();\n }\n\n /* c8 ignore next 3 */\n override 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"],
|
|
5
|
+
"mappings": "aAYA,OAAsB,WAAAA,MAAqB,MAC3C,OAAS,kBAAAC,EAAgB,aAAAC,MAAiB,yBAY1C,MAAMC,EAAkC,CACpC,GACA,IAAY,CAEZ,CACJ,EASA,MAAMC,UAAmCH,CAAe,CAAxD,kCAII,WAAwBE,EACxB,kBAA+BA,EAC/B,SAAsBA,EACtB,mBAAgCA,EAEhC,WAAsB,MA6EtB,iBAAeE,GAAuB,CAClC,KAAK,YAAY,EACjB,KAAK,YAAY,KAAK,MAAM,CAAC,EAAGA,CAAK,EACjC,CAAAA,EAAM,mBAGV,KAAK,gBAAgB,EACrB,KAAK,aAAa,IAAI,EAC1B,EAEA,kBAAgBA,GAAuB,CACnC,KAAK,aAAa,KAAK,aAAa,CAAC,EAAGA,CAAK,CACjD,EAEA,eAAaA,GAAuB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,OAEtB,CA2BA,YAAYU,EAAyBC,EAAkC,CAC/D,MAAM,QAAQD,CAAI,EAClBA,EAAK,IAAKE,GAAc,CACpB,KAAK,QAAQ,iBAAiBA,EAAWD,CAAE,CAC/C,CAAC,EAED,KAAK,QAAQ,iBAAiBD,EAAMC,CAAE,CAE9C,CAEA,eAAeD,EAAyBC,EAAkC,CAClE,MAAM,QAAQD,CAAI,EAClBA,EAAK,IAAKE,GAAc,CACpB,KAAK,QAAQ,oBAAoBA,EAAWD,CAAE,CAClD,CAAC,EAED,KAAK,QAAQ,oBAAoBD,EAAMC,CAAE,CAEjD,CAEA,iBAAwB,CACpB,KAAK,eAAe,KAAK,MAAM,CAAC,EAAG,KAAK,WAAW,EACnD,KAAK,eAAe,KAAK,aAAa,CAAC,EAAG,KAAK,YAAY,EAC3D,KAAK,eAAe,KAAK,IAAI,CAAC,EAAG,KAAK,SAAS,EAC/C,KAAK,eAAe,KAAK,cAAc,CAAC,EAAG,KAAK,aAAa,CACjE,CAES,cAAqB,CAC1B,KAAK,gBAAgB,CACzB,CAGS,aAAoB,CACzB,KAAK,aAAa,CACtB,CACJ,CAEO,aAAM,kBAE6Cd,EACtDE,CACJ",
|
|
6
6
|
"names": ["nothing", "AsyncDirective", "directive", "defaultListener", "StreamingListenerDirective", "event", "_configGroup", "part", "start", "end", "streamInside", "streamOutside", "_a", "state", "value", "type", "fn", "eventName"]
|
|
7
7
|
}
|