@adobe/uix-core 0.6.3
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/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/debug-emitter.d.ts +25 -0
- package/dist/debug-emitter.d.ts.map +1 -0
- package/dist/debuglog.d.ts +70 -0
- package/dist/debuglog.d.ts.map +1 -0
- package/dist/emitter.d.ts +62 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/esm/index.js +259 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +266 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace-proxy.d.ts +32 -0
- package/dist/namespace-proxy.d.ts.map +1 -0
- package/dist/timeout-promise.d.ts +12 -0
- package/dist/timeout-promise.d.ts.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +36 -0
- package/src/debug-emitter.ts +83 -0
- package/src/debuglog.ts +284 -0
- package/src/emitter.ts +90 -0
- package/src/index.ts +23 -0
- package/src/namespace-proxy.ts +82 -0
- package/src/timeout-promise.ts +36 -0
- package/src/types.ts +224 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022 Adobe
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is the `@adobe/uix-core` package alone. See [/README.md](../../README.md) for details.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DebugLogger, Theme } from "./debuglog.js";
|
|
2
|
+
import { Emits } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Adds methods for logging events
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface EmitterDebugLogger extends DebugLogger {
|
|
8
|
+
/**
|
|
9
|
+
* Listen to an event and pass the logger to the handler
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
listen(type: string, listener: (logger: EmitterDebugLogger, ev: CustomEvent) => unknown): this;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Debugger for EventTarget objects like Hosts, Ports and Guests, which
|
|
16
|
+
* patches dispatchEvent to log events
|
|
17
|
+
* Adapter to attach console logging listeners to all events on an emitter.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function debugEmitter(emitter: Emits, opts: {
|
|
21
|
+
theme: Theme;
|
|
22
|
+
type?: string;
|
|
23
|
+
id?: string;
|
|
24
|
+
}): EmitterDebugLogger;
|
|
25
|
+
//# sourceMappingURL=debug-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-emitter.d.ts","sourceRoot":"","sources":["../src/debug-emitter.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,WAAW,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,KAAK,EAAgB,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD;;;OAGG;IACH,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,WAAW,KAAK,OAAO,GACjE,IAAI,CAAC;CACT;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,KAAK,EACd,IAAI,EAAE;IACJ,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,GACA,kBAAkB,CAuCpB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
declare type Layout = {
|
|
3
|
+
padX: number;
|
|
4
|
+
padY: number;
|
|
5
|
+
rounded: number;
|
|
6
|
+
fontSize: number;
|
|
7
|
+
emphasis: Style;
|
|
8
|
+
};
|
|
9
|
+
/** @internal */
|
|
10
|
+
declare type HexColor = `#${string}` | "transparent";
|
|
11
|
+
/** @internal */
|
|
12
|
+
declare type Color = {
|
|
13
|
+
text: HexColor;
|
|
14
|
+
bg: HexColor;
|
|
15
|
+
hilight: HexColor;
|
|
16
|
+
shadow: HexColor;
|
|
17
|
+
};
|
|
18
|
+
/** @internal */
|
|
19
|
+
declare type ThemeSpec = Color & Layout;
|
|
20
|
+
/** @internal */
|
|
21
|
+
declare const Layouts: Record<string, Layout>;
|
|
22
|
+
/** @internal */
|
|
23
|
+
declare const Colors: Record<string, Color>;
|
|
24
|
+
/** @internal */
|
|
25
|
+
declare type ThemeTag = `${keyof typeof Colors} ${keyof typeof Layouts}`;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare type Theme = ThemeSpec | ThemeTag;
|
|
30
|
+
/** @internal */
|
|
31
|
+
declare type Style = `${string};`;
|
|
32
|
+
/** @internal */
|
|
33
|
+
declare const stateTypes: {
|
|
34
|
+
readonly event: "️⚡️";
|
|
35
|
+
};
|
|
36
|
+
/** @internal */
|
|
37
|
+
declare type DebugState = {
|
|
38
|
+
type: keyof typeof stateTypes;
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A console, plus some methods to track event lifecycles.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export interface DebugLogger extends Console {
|
|
46
|
+
/**
|
|
47
|
+
* Stop all logging; methods do nothing
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
detach(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Add an event bubble to the log during handler.
|
|
53
|
+
*/
|
|
54
|
+
pushState(state: DebugState): void;
|
|
55
|
+
/**
|
|
56
|
+
* Remove the bubble when event is done dispatching
|
|
57
|
+
*/
|
|
58
|
+
popState(): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a console whose methods autoformat with bubbles.
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export declare function _customConsole(theme: Theme, type: string, name: string): DebugLogger;
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export declare const quietConsole: Console;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=debuglog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debuglog.d.ts","sourceRoot":"","sources":["../src/debuglog.ts"],"names":[],"mappings":"AAuBA,gBAAgB;AAChB,aAAK,MAAM,GAAG;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;CACjB,CAAC;AACF,gBAAgB;AAChB,aAAK,QAAQ,GAAG,IAAI,MAAM,EAAE,GAAG,aAAa,CAAC;AAC7C,gBAAgB;AAChB,aAAK,KAAK,GAAG;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,QAAQ,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AACF,gBAAgB;AAChB,aAAK,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEhC,gBAAgB;AAChB,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAenC,CAAC;AAEF,gBAAgB;AAChB,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAgCjC,CAAC;AAEF,gBAAgB;AAChB,aAAK,QAAQ,GAAG,GAAG,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,OAAO,EAAE,CAAC;AAEjE;;GAEG;AACH,oBAAY,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;AAKzC,gBAAgB;AAChB,aAAK,KAAK,GAAG,GAAG,MAAM,GAAG,CAAC;AAgE1B,gBAAgB;AAChB,QAAA,MAAM,UAAU;;CAEN,CAAC;AAIX,gBAAgB;AAChB,aAAK,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,OAAO,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAsBlE;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,OAAO;IAC1C;;;OAGG;IACH,MAAM,IAAI,IAAI,CAAC;IACf;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACnC;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,WAAW,CA4Cb;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,SAIvB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Emits, Unsubscriber, NamedEvent } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Browser-native {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget | EventTarget}
|
|
4
|
+
* whose {@link Emitter.addEventListener} method returns an anonymous function
|
|
5
|
+
* which unsubscribes the original handler.
|
|
6
|
+
*
|
|
7
|
+
* Also provides typed events via generics. You can create or extend this class
|
|
8
|
+
* to define custom emitters with known event names and signatures.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { NamedEvent, Emitter } from '@adobe/uix-sdk'
|
|
13
|
+
*
|
|
14
|
+
* class FizzBuzzEmitter extends Emitter<
|
|
15
|
+
* NamedEvent<"fizz", { fizzCount: number }> |
|
|
16
|
+
* NamedEvent<"buzz", { buzzCount: number }> |
|
|
17
|
+
* NamedEvent<"fizzbuzz">
|
|
18
|
+
* > {
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
* The `FizzBuzzEmitter` class will now type check its events and event
|
|
22
|
+
* listeners, providing autosuggest in editors.
|
|
23
|
+
*
|
|
24
|
+
* @see [EventTarget - MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare class Emitter<Events extends NamedEvent> extends EventTarget implements Emits<Events> {
|
|
29
|
+
/**
|
|
30
|
+
* An arbitrary string to uniquely identify this emitter and its events.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
id: string;
|
|
34
|
+
constructor(id: string);
|
|
35
|
+
/**
|
|
36
|
+
* Convenience method to construct and dispatch custom events.
|
|
37
|
+
*
|
|
38
|
+
* @param type - Name of one of the allowed events this can emit
|
|
39
|
+
* @param detail - Object to expose in the {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail | CustomEvent#detail}
|
|
40
|
+
* property.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
protected emit<Event extends Events>(type: Event["type"], detail: Event["detail"]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to an event and receive an unsubscribe callback.
|
|
46
|
+
* @see [EventTarget.addEventListener - MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
|
|
47
|
+
*
|
|
48
|
+
* Identical to `EventTarget.addEventListener`, but returns an "unsubscriber"
|
|
49
|
+
* function which detaches the listener when invoked. Solves an ergonomic
|
|
50
|
+
* problem with native EventTargets where it's impossible to detach listeners
|
|
51
|
+
* without having a reference to the original handler.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam E - Name of one of the allowed events this can emit
|
|
54
|
+
* @param type - Event type
|
|
55
|
+
* @param listener - Event handler
|
|
56
|
+
* @returns Call to unsubscribe listener.
|
|
57
|
+
*/
|
|
58
|
+
addEventListener<Type extends Events["type"], Event extends Extract<Events, {
|
|
59
|
+
type: Type;
|
|
60
|
+
}>>(type: Type, listener: (ev: Event) => unknown): Unsubscriber;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,OAAO,CAAC,MAAM,SAAS,UAAU,CAC5C,SAAQ,WACR,YAAW,KAAK,CAAC,MAAM,CAAC;IAExB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;gBACC,EAAE,EAAE,MAAM;IAItB;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,MAAM,EACjC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EACnB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,GACtB,IAAI;IAIP;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CACd,IAAI,SAAS,MAAM,CAAC,MAAM,CAAC,EAC3B,KAAK,SAAS,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,EAC7C,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,KAAK,KAAK,OAAO,GAAG,YAAY;CAI9D"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// src/debuglog.ts
|
|
2
|
+
var isDarkMode = () => typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
3
|
+
var Layouts = {
|
|
4
|
+
medium: {
|
|
5
|
+
padX: 5,
|
|
6
|
+
padY: 3,
|
|
7
|
+
rounded: 4,
|
|
8
|
+
fontSize: 100,
|
|
9
|
+
emphasis: "font-weight: bold;"
|
|
10
|
+
},
|
|
11
|
+
small: {
|
|
12
|
+
padX: 3,
|
|
13
|
+
padY: 1,
|
|
14
|
+
rounded: 2,
|
|
15
|
+
fontSize: 95,
|
|
16
|
+
emphasis: "font-style: italic;"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var Colors = {
|
|
20
|
+
yellow: {
|
|
21
|
+
text: "#333333",
|
|
22
|
+
bg: "#EBD932",
|
|
23
|
+
hilight: "#F7E434",
|
|
24
|
+
shadow: "#D1C12C"
|
|
25
|
+
},
|
|
26
|
+
green: {
|
|
27
|
+
text: "#333333",
|
|
28
|
+
bg: "#96EB5E",
|
|
29
|
+
hilight: "#9EF763",
|
|
30
|
+
shadow: "#85D154"
|
|
31
|
+
},
|
|
32
|
+
blue: {
|
|
33
|
+
text: "#333333",
|
|
34
|
+
bg: "#8DD0EB",
|
|
35
|
+
hilight: "#88F0F7",
|
|
36
|
+
shadow: "#74AED4"
|
|
37
|
+
},
|
|
38
|
+
gray: isDarkMode() ? {
|
|
39
|
+
text: "#eeeeee",
|
|
40
|
+
bg: "transparent",
|
|
41
|
+
hilight: "#cecece",
|
|
42
|
+
shadow: "#cecece"
|
|
43
|
+
} : {
|
|
44
|
+
text: "#333333",
|
|
45
|
+
bg: "#eeeeee",
|
|
46
|
+
hilight: "#f6f6f6",
|
|
47
|
+
shadow: "#cecece"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function memoizeUnary(fn) {
|
|
51
|
+
const cache = /* @__PURE__ */ new Map();
|
|
52
|
+
return (arg) => {
|
|
53
|
+
if (!cache.has(arg)) {
|
|
54
|
+
const result = fn(arg);
|
|
55
|
+
cache.set(arg, result);
|
|
56
|
+
if (cache.size > 100) {
|
|
57
|
+
cache.delete(cache.keys().next().value);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
return cache.get(arg);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
var toTheme = memoizeUnary((theme) => {
|
|
65
|
+
if (typeof theme === "string") {
|
|
66
|
+
const [color, size] = theme.split(" ");
|
|
67
|
+
return {
|
|
68
|
+
...Colors[color],
|
|
69
|
+
...Layouts[size]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return theme;
|
|
73
|
+
});
|
|
74
|
+
var block = `display: inline-block; border: 1px solid;`;
|
|
75
|
+
var flatten = (side) => `padding-${side}: 0px; border-${side}-width: 0px; border-top-${side}-radius: 0px; border-bottom-${side}-radius: 0px;`;
|
|
76
|
+
var toColor = ({ bg, hilight, shadow, text }) => `color: ${text}; background: ${bg}; border-color: ${hilight} ${shadow} ${shadow} ${hilight};`;
|
|
77
|
+
var toLayout = ({ fontSize, padY, padX, rounded }) => `font-size: ${fontSize}%; padding: ${padY}px ${padX}px; border-radius: ${rounded}px;`;
|
|
78
|
+
var toBubbleStyle = memoizeUnary((theme) => {
|
|
79
|
+
const base = `${block}${toColor(theme)}${toLayout(theme)}`;
|
|
80
|
+
return [
|
|
81
|
+
`${base}${flatten("right")}`,
|
|
82
|
+
`${base}${flatten("left")}${theme.emphasis}`
|
|
83
|
+
];
|
|
84
|
+
});
|
|
85
|
+
function toBubblePrepender(bubbleLeft, bubbleRight, theme) {
|
|
86
|
+
const prefix = `%c${bubbleLeft}%c ${bubbleRight}`;
|
|
87
|
+
const [left, right] = toBubbleStyle(theme);
|
|
88
|
+
return (args) => {
|
|
89
|
+
const bubbleArgs = [prefix, left, right];
|
|
90
|
+
if (typeof args[0] === "string") {
|
|
91
|
+
bubbleArgs[0] = `${prefix}%c ${args.shift()}`;
|
|
92
|
+
bubbleArgs.push("");
|
|
93
|
+
}
|
|
94
|
+
return [...bubbleArgs, ...args];
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
var stateTypes = {
|
|
98
|
+
event: "\uFE0F\u26A1\uFE0F"
|
|
99
|
+
};
|
|
100
|
+
var stateDelim = " \u293B ";
|
|
101
|
+
var getStateFormatter = memoizeUnary((stateJson) => {
|
|
102
|
+
const stateStack = JSON.parse(stateJson);
|
|
103
|
+
const firstState = stateStack.shift();
|
|
104
|
+
const left = stateTypes[firstState.type];
|
|
105
|
+
const right = [
|
|
106
|
+
firstState.name,
|
|
107
|
+
...stateStack.map((state) => `${stateTypes[state.type]} ${state.name}`)
|
|
108
|
+
].join(stateDelim);
|
|
109
|
+
return toBubblePrepender(left, right, toTheme("gray small"));
|
|
110
|
+
});
|
|
111
|
+
var getStatePrepender = (stateStack) => getStateFormatter(JSON.stringify(stateStack));
|
|
112
|
+
var overrideMethods = ["log", "error", "warn", "info", "debug"];
|
|
113
|
+
var identity = (x) => x;
|
|
114
|
+
var noop = () => void 0;
|
|
115
|
+
function _customConsole(theme, type, name) {
|
|
116
|
+
const prepender = toBubblePrepender(`X${type}`, name, toTheme(theme));
|
|
117
|
+
let statePrepender = identity;
|
|
118
|
+
const stateStack = [];
|
|
119
|
+
const loggerProto = {
|
|
120
|
+
detach: {
|
|
121
|
+
writable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
value() {
|
|
124
|
+
overrideMethods.forEach((method) => {
|
|
125
|
+
this[method] = noop;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
pushState: {
|
|
130
|
+
value(state) {
|
|
131
|
+
stateStack.push(state);
|
|
132
|
+
statePrepender = getStatePrepender(stateStack);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
popState: {
|
|
136
|
+
value() {
|
|
137
|
+
stateStack.pop();
|
|
138
|
+
statePrepender = stateStack.length === 0 ? identity : getStatePrepender(stateStack);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const customConsole = Object.create(
|
|
143
|
+
console,
|
|
144
|
+
overrideMethods.reduce((out, level) => {
|
|
145
|
+
out[level] = {
|
|
146
|
+
writable: true,
|
|
147
|
+
configurable: true,
|
|
148
|
+
value(...args) {
|
|
149
|
+
console[level](...prepender(statePrepender(args)));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return out;
|
|
153
|
+
}, loggerProto)
|
|
154
|
+
);
|
|
155
|
+
return customConsole;
|
|
156
|
+
}
|
|
157
|
+
var quietConsole = new Proxy(console, {
|
|
158
|
+
get() {
|
|
159
|
+
return noop;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// src/debug-emitter.ts
|
|
164
|
+
function debugEmitter(emitter, opts) {
|
|
165
|
+
const logger = _customConsole(
|
|
166
|
+
opts.theme,
|
|
167
|
+
opts.type || Object.getPrototypeOf(emitter).constructor.name,
|
|
168
|
+
opts.id || emitter.id
|
|
169
|
+
);
|
|
170
|
+
const oldDispatch = emitter.dispatchEvent;
|
|
171
|
+
emitter.dispatchEvent = (event) => {
|
|
172
|
+
logger.pushState({ type: "event", name: event.type });
|
|
173
|
+
const retVal = oldDispatch.call(emitter, event);
|
|
174
|
+
logger.popState();
|
|
175
|
+
return retVal;
|
|
176
|
+
};
|
|
177
|
+
const subscriptions = [];
|
|
178
|
+
const oldDetach = logger.detach;
|
|
179
|
+
logger.detach = () => {
|
|
180
|
+
oldDetach.call(logger);
|
|
181
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
182
|
+
};
|
|
183
|
+
function listen(type, listener) {
|
|
184
|
+
subscriptions.push(
|
|
185
|
+
emitter.addEventListener(type, (event) => listener(logger, event))
|
|
186
|
+
);
|
|
187
|
+
return logger;
|
|
188
|
+
}
|
|
189
|
+
logger.listen = listen;
|
|
190
|
+
return logger;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/emitter.ts
|
|
194
|
+
var Emitter = class extends EventTarget {
|
|
195
|
+
constructor(id) {
|
|
196
|
+
super();
|
|
197
|
+
this.id = id;
|
|
198
|
+
}
|
|
199
|
+
emit(type, detail) {
|
|
200
|
+
const event = new CustomEvent(type, { detail });
|
|
201
|
+
this.dispatchEvent(event);
|
|
202
|
+
}
|
|
203
|
+
addEventListener(type, listener) {
|
|
204
|
+
super.addEventListener(type, listener);
|
|
205
|
+
return () => super.removeEventListener(type, listener);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/namespace-proxy.ts
|
|
210
|
+
function makeNamespaceProxy(invoke, path = []) {
|
|
211
|
+
const handler = {
|
|
212
|
+
get: (target2, prop) => {
|
|
213
|
+
if (typeof prop === "string") {
|
|
214
|
+
if (!Reflect.has(target2, prop)) {
|
|
215
|
+
const next = makeNamespaceProxy(invoke, path.concat(prop));
|
|
216
|
+
Reflect.set(target2, prop, next);
|
|
217
|
+
}
|
|
218
|
+
return Reflect.get(target2, prop);
|
|
219
|
+
} else {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Cannot look up a symbol ${String(prop)} on a host connection proxy.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const target = {};
|
|
227
|
+
if (path.length < 2) {
|
|
228
|
+
return new Proxy(target, handler);
|
|
229
|
+
}
|
|
230
|
+
const invoker = (...args) => invoke({
|
|
231
|
+
path: path.slice(0, -1),
|
|
232
|
+
name: path[path.length - 1],
|
|
233
|
+
args
|
|
234
|
+
});
|
|
235
|
+
return new Proxy(invoker, {
|
|
236
|
+
...handler,
|
|
237
|
+
apply(target2, _, args) {
|
|
238
|
+
return target2(...args);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/timeout-promise.ts
|
|
244
|
+
function timeoutPromise(timeoutMs, promise) {
|
|
245
|
+
return new Promise((resolve, reject) => {
|
|
246
|
+
const timeout = setTimeout(
|
|
247
|
+
() => reject(new Error(`Timed out after ${timeoutMs}ms`)),
|
|
248
|
+
timeoutMs
|
|
249
|
+
);
|
|
250
|
+
promise.then((result) => {
|
|
251
|
+
clearTimeout(timeout);
|
|
252
|
+
resolve(result);
|
|
253
|
+
}).catch(reject);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export { Emitter, _customConsole, debugEmitter, makeNamespaceProxy, quietConsole, timeoutPromise };
|
|
258
|
+
//# sourceMappingURL=out.js.map
|
|
259
|
+
//# sourceMappingURL=index.js.map
|