@adobe/uix-core 0.6.5-0 → 0.6.5
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 +5 -7
- package/dist/esm/index.js +0 -259
- package/dist/esm/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/uix-core",
|
|
3
|
-
"version": "0.6.5
|
|
3
|
+
"version": "0.6.5",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
4
7
|
"description": "Internal utilities for the UIX SDK",
|
|
5
8
|
"author": "Adobe, Inc,",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"module": "dist/esm/index.js",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"browser": "dist/index.js",
|
|
10
|
-
"exports": {
|
|
11
|
-
"import": "./dist/esm/index.js",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
},
|
|
14
11
|
"types": "dist/index.d.ts",
|
|
15
12
|
"scripts": {
|
|
16
13
|
"build": "tsup",
|
|
14
|
+
"build:esm": "tsup --format esm,cjs",
|
|
17
15
|
"watch": "tsup --watch --silent"
|
|
18
16
|
},
|
|
19
17
|
"browserslist": [
|
package/dist/esm/index.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
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
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/debuglog.ts","../../src/debug-emitter.ts","../../src/emitter.ts","../../src/namespace-proxy.ts","../../src/timeout-promise.ts"],"names":["target"],"mappings":";AAmBA,IAAM,aAAa,MACjB,OAAO,OAAO,eAAe,cAC7B,OAAO,WAAW,8BAA8B,EAAE;AAuBpD,IAAM,UAAkC;AAAA,EACtC,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AACF;AAGA,IAAM,SAAgC;AAAA,EACpC,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AAAA,EACA,MAAM,WAAW,IACb;AAAA,IACE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,QAAQ;AAAA,EACV,IACA;AAAA,IACE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AACN;AAgBA,SAAS,aAAmB,IAA8B;AACxD,QAAM,QAAmB,oBAAI,IAAI;AACjC,SAAO,CAAC,QAAQ;AACd,QAAI,CAAC,MAAM,IAAI,GAAG,GAAG;AACnB,YAAM,SAAS,GAAG,GAAG;AACrB,YAAM,IAAI,KAAK,MAAM;AACrB,UAAI,MAAM,OAAO,KAAK;AACpB,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,MAAM;AAAA,EACjB,CAAC;AACH","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * Fancy looking console decorator.\n * @hidden\n * @internal\n */\n\n/** @internal */\nconst isDarkMode = () =>\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-color-scheme: dark)\").matches;\n\n/** @internal */\ntype Layout = {\n padX: number;\n padY: number;\n rounded: number;\n fontSize: number;\n emphasis: Style;\n};\n/** @internal */\ntype HexColor = `#${string}` | \"transparent\";\n/** @internal */\ntype Color = {\n text: HexColor;\n bg: HexColor;\n hilight: HexColor;\n shadow: HexColor;\n};\n/** @internal */\ntype ThemeSpec = Color & Layout;\n\n/** @internal */\nconst Layouts: Record<string, Layout> = {\n medium: {\n padX: 5,\n padY: 3,\n rounded: 4,\n fontSize: 100,\n emphasis: \"font-weight: bold;\",\n },\n small: {\n padX: 3,\n padY: 1,\n rounded: 2,\n fontSize: 95,\n emphasis: \"font-style: italic;\",\n },\n};\n\n/** @internal */\nconst Colors: Record<string, Color> = {\n yellow: {\n text: \"#333333\",\n bg: \"#EBD932\",\n hilight: \"#F7E434\",\n shadow: \"#D1C12C\",\n },\n green: {\n text: \"#333333\",\n bg: \"#96EB5E\",\n hilight: \"#9EF763\",\n shadow: \"#85D154\",\n },\n blue: {\n text: \"#333333\",\n bg: \"#8DD0EB\",\n hilight: \"#88F0F7\",\n shadow: \"#74AED4\",\n },\n gray: isDarkMode()\n ? {\n text: \"#eeeeee\",\n bg: \"transparent\",\n hilight: \"#cecece\",\n shadow: \"#cecece\",\n }\n : {\n text: \"#333333\",\n bg: \"#eeeeee\",\n hilight: \"#f6f6f6\",\n shadow: \"#cecece\",\n },\n};\n\n/** @internal */\ntype ThemeTag = `${keyof typeof Colors} ${keyof typeof Layouts}`;\n\n/**\n * @internal\n */\nexport type Theme = ThemeSpec | ThemeTag;\n\n/** @internal */\ntype LogDecorator = (...args: unknown[]) => unknown[];\n\n/** @internal */\ntype Style = `${string};`;\n\nfunction memoizeUnary<T, U>(fn: (arg: T) => U): typeof fn {\n const cache: Map<T, U> = new Map();\n return (arg) => {\n if (!cache.has(arg)) {\n const result = fn(arg);\n cache.set(arg, result);\n if (cache.size > 100) {\n cache.delete(cache.keys().next().value as T);\n }\n return result;\n }\n return cache.get(arg);\n };\n}\n\nconst toTheme = memoizeUnary((theme: Theme): ThemeSpec => {\n if (typeof theme === \"string\") {\n const [color, size] = theme.split(\" \");\n return {\n ...Colors[color],\n ...Layouts[size],\n };\n }\n return theme;\n});\n\nconst block: Style = `display: inline-block; border: 1px solid;`;\n\nconst flatten = (side: \"left\" | \"right\"): Style =>\n `padding-${side}: 0px; border-${side}-width: 0px; border-top-${side}-radius: 0px; border-bottom-${side}-radius: 0px;`;\n\nconst toColor = ({ bg, hilight, shadow, text }: Color): Style =>\n `color: ${text}; background: ${bg}; border-color: ${hilight} ${shadow} ${shadow} ${hilight};`;\n\nconst toLayout = ({ fontSize, padY, padX, rounded }: Layout) =>\n `font-size: ${fontSize}%; padding: ${padY}px ${padX}px; border-radius: ${rounded}px;`;\n\nconst toBubbleStyle = memoizeUnary((theme: ThemeSpec): string[] => {\n const base = `${block}${toColor(theme)}${toLayout(theme)}`;\n return [\n `${base}${flatten(\"right\")}`,\n `${base}${flatten(\"left\")}${theme.emphasis}`,\n ] as Style[];\n});\n\nfunction toBubblePrepender(\n bubbleLeft: string,\n bubbleRight: string,\n theme: ThemeSpec\n): LogDecorator {\n const prefix = `%c${bubbleLeft}%c ${bubbleRight}`;\n const [left, right] = toBubbleStyle(theme);\n return (args: unknown[]) => {\n const bubbleArgs = [prefix, left, right];\n if (typeof args[0] === \"string\") {\n bubbleArgs[0] = `${prefix}%c ${args.shift() as string}`;\n bubbleArgs.push(\"\"); // reset style\n }\n return [...bubbleArgs, ...args];\n };\n}\n\n/** @internal */\nconst stateTypes = {\n event: \"️⚡️\",\n} as const;\n\nconst stateDelim = \" ⤻ \";\n\n/** @internal */\ntype DebugState = { type: keyof typeof stateTypes; name: string };\n\n// Serialize to memoize.\nconst getStateFormatter = memoizeUnary((stateJson: string) => {\n const stateStack = JSON.parse(stateJson) as unknown as DebugState[];\n const firstState = stateStack.shift();\n const left = stateTypes[firstState.type];\n const right = [\n firstState.name,\n ...stateStack.map((state) => `${stateTypes[state.type]} ${state.name}`),\n ].join(stateDelim);\n return toBubblePrepender(left, right, toTheme(\"gray small\"));\n});\nconst getStatePrepender = (stateStack: DebugState[]) =>\n getStateFormatter(JSON.stringify(stateStack));\n\nconst overrideMethods = [\"log\", \"error\", \"warn\", \"info\", \"debug\"] as const;\n\nconst identity = <T>(x: T) => x;\n\nconst noop = (): (() => undefined) => undefined;\n\n/**\n * A console, plus some methods to track event lifecycles.\n * @internal\n */\nexport interface DebugLogger extends Console {\n /**\n * Stop all logging; methods do nothing\n * @internal\n */\n detach(): void;\n /**\n * Add an event bubble to the log during handler.\n */\n pushState(state: DebugState): void;\n /**\n * Remove the bubble when event is done dispatching\n */\n popState(): void;\n}\n\n/**\n * Returns a console whose methods autoformat with bubbles.\n * @internal\n */\nexport function _customConsole(\n theme: Theme,\n type: string,\n name: string\n): DebugLogger {\n const prepender = toBubblePrepender(`X${type}`, name, toTheme(theme));\n let statePrepender: LogDecorator = identity as LogDecorator;\n const stateStack: DebugState[] = [];\n const loggerProto: PropertyDescriptorMap = {\n detach: {\n writable: true,\n configurable: true,\n value(this: DebugLogger) {\n overrideMethods.forEach((method) => {\n this[method] = noop;\n });\n },\n },\n pushState: {\n value(state: DebugState) {\n stateStack.push(state);\n statePrepender = getStatePrepender(stateStack);\n },\n },\n popState: {\n value() {\n stateStack.pop();\n statePrepender =\n stateStack.length === 0\n ? (identity as LogDecorator)\n : getStatePrepender(stateStack);\n },\n },\n };\n const customConsole = Object.create(\n console,\n overrideMethods.reduce((out, level) => {\n out[level] = {\n writable: true,\n configurable: true,\n value(...args: unknown[]) {\n console[level](...prepender(statePrepender(args)));\n },\n };\n return out;\n }, loggerProto)\n ) as DebugLogger;\n return customConsole;\n}\n\n/**\n * @internal\n */\nexport const quietConsole = new Proxy(console, {\n get() {\n return noop;\n },\n});\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { _customConsole, DebugLogger, Theme } from \"./debuglog.js\";\nimport { Emits, Unsubscriber } from \"./types.js\";\n\n/**\n * Adds methods for logging events\n * @internal\n */\nexport interface EmitterDebugLogger extends DebugLogger {\n /**\n * Listen to an event and pass the logger to the handler\n * @internal\n */\n listen(\n type: string,\n listener: (logger: EmitterDebugLogger, ev: CustomEvent) => unknown\n ): this;\n}\n\n/**\n * Debugger for EventTarget objects like Hosts, Ports and Guests, which\n * patches dispatchEvent to log events\n * Adapter to attach console logging listeners to all events on an emitter.\n * @internal\n */\nexport function debugEmitter(\n emitter: Emits,\n opts: {\n theme: Theme;\n type?: string;\n id?: string;\n }\n): EmitterDebugLogger {\n const logger = _customConsole(\n opts.theme,\n opts.type ||\n (Object.getPrototypeOf(emitter) as typeof emitter).constructor.name,\n opts.id || emitter.id\n ) as EmitterDebugLogger;\n const oldDispatch = emitter.dispatchEvent;\n emitter.dispatchEvent = (event) => {\n logger.pushState({ type: \"event\", name: event.type });\n const retVal = oldDispatch.call(emitter, event) as boolean;\n logger.popState();\n return retVal;\n };\n\n const subscriptions: Unsubscriber[] = [];\n\n const oldDetach = logger.detach;\n logger.detach = () => {\n oldDetach.call(logger);\n subscriptions.forEach((unsubscribe) => unsubscribe());\n };\n\n /**\n * Listens and passes a logger to callbacks\n */\n function listen(\n type: string,\n listener: (logger: EmitterDebugLogger, ev: CustomEvent) => unknown\n ) {\n subscriptions.push(\n emitter.addEventListener(type, (event) => listener(logger, event))\n );\n return logger;\n }\n\n logger.listen = listen;\n\n return logger;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Emits, Unsubscriber, NamedEvent } from \"./types.js\";\n\n/**\n * Browser-native {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget | EventTarget}\n * whose {@link Emitter.addEventListener} method returns an anonymous function\n * which unsubscribes the original handler.\n *\n * Also provides typed events via generics. You can create or extend this class\n * to define custom emitters with known event names and signatures.\n *\n * @example\n * ```ts\n * import type { NamedEvent, Emitter } from '@adobe/uix-sdk'\n *\n * class FizzBuzzEmitter extends Emitter<\n * NamedEvent<\"fizz\", { fizzCount: number }> |\n * NamedEvent<\"buzz\", { buzzCount: number }> |\n * NamedEvent<\"fizzbuzz\">\n * > {\n * }\n * ```\n * The `FizzBuzzEmitter` class will now type check its events and event\n * listeners, providing autosuggest in editors.\n *\n * @see [EventTarget - MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)\n *\n * @public\n */\nexport class Emitter<Events extends NamedEvent>\n extends EventTarget\n implements Emits<Events>\n{\n /**\n * An arbitrary string to uniquely identify this emitter and its events.\n * @public\n */\n id: string;\n constructor(id: string) {\n super();\n this.id = id;\n }\n /**\n * Convenience method to construct and dispatch custom events.\n *\n * @param type - Name of one of the allowed events this can emit\n * @param detail - Object to expose in the {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail | CustomEvent#detail}\n * property.\n * @public\n */\n protected emit<Event extends Events>(\n type: Event[\"type\"],\n detail: Event[\"detail\"]\n ): void {\n const event = new CustomEvent<typeof detail>(type, { detail });\n this.dispatchEvent(event);\n }\n /**\n * Subscribe to an event and receive an unsubscribe callback.\n * @see [EventTarget.addEventListener - MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)\n *\n * Identical to `EventTarget.addEventListener`, but returns an \"unsubscriber\"\n * function which detaches the listener when invoked. Solves an ergonomic\n * problem with native EventTargets where it's impossible to detach listeners\n * without having a reference to the original handler.\n *\n * @typeParam E - Name of one of the allowed events this can emit\n * @param type - Event type\n * @param listener - Event handler\n * @returns Call to unsubscribe listener.\n */\n addEventListener<\n Type extends Events[\"type\"],\n Event extends Extract<Events, { type: Type }>\n >(type: Type, listener: (ev: Event) => unknown): Unsubscriber {\n super.addEventListener(type, listener);\n return () => super.removeEventListener(type, listener);\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { RemoteHostApis, RemoteMethodInvoker } from \"./types.js\";\n\n/**\n * Build a fake object that turns \"method calls\" into RPC messages\n * The resulting object will recursively make more fake proxies on demand until\n * one of the looked-up properties is invoked as a function.\n * Then it will call the passed `invoke` method with a {@link HostMethodAddress}\n * that can send the method invocation as an RPC message to another realm.\n *\n * @example\n * ```js\n * const invoker = (methodAddress) => console.log(\n * address.path,\n * address.name,\n * address.args\n * );\n * const ns = makeNamespaceProxy(invoker);\n *\n * // looking up any property on the object will work\n *\n * ns.example.builds.method.call.message(\"foo\", 1);\n *\n * // Console will log:\n * ['example','builds','method','call']\n * 'message'\n * [\"foo\", 1]\n *```\n * @internal\n *\n * @param invoke - Callback that receives address\n */\nexport function makeNamespaceProxy<ProxiedApi extends object>(\n invoke: RemoteMethodInvoker<unknown>,\n path: string[] = []\n): RemoteHostApis<ProxiedApi> {\n const handler: ProxyHandler<Record<string, any>> = {\n get: (target, prop) => {\n if (typeof prop === \"string\") {\n if (!Reflect.has(target, prop)) {\n const next = makeNamespaceProxy(invoke, path.concat(prop));\n Reflect.set(target, prop, next);\n }\n return Reflect.get(target, prop) as unknown;\n } else {\n throw new Error(\n `Cannot look up a symbol ${String(prop)} on a host connection proxy.`\n );\n }\n },\n };\n const target = {} as unknown as RemoteHostApis<ProxiedApi>;\n // Only trap the apply if there's at least two levels of namespace.\n // uix.host() is not a function, and neither is uix.host.bareMethod().\n if (path.length < 2) {\n return new Proxy<RemoteHostApis<ProxiedApi>>(target, handler);\n }\n const invoker = (...args: unknown[]) =>\n invoke({\n path: path.slice(0, -1),\n name: path[path.length - 1],\n args,\n });\n return new Proxy<typeof invoker>(invoker, {\n ...handler,\n apply(target, _, args: unknown[]) {\n return target(...args);\n },\n }) as unknown as typeof target;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * Add a timeout to a Promise. The returned Promise will resolve to the value of\n * the original Promise, but if it doesn't resolve within the timeout interval,\n * it will reject with a timeout error.\n * @internal\n *\n * @param timeoutMs - Time to wait (ms) before rejecting\n * @param promise - Original promise to set a timeout for\n * @returns - Promise that rejects after X milliseconds have passed\n */\nexport function timeoutPromise<T>(timeoutMs: number, promise: Promise<T>) {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(\n () => reject(new Error(`Timed out after ${timeoutMs}ms`)),\n timeoutMs\n );\n promise\n .then((result) => {\n clearTimeout(timeout);\n resolve(result);\n })\n .catch(reject);\n });\n}\n"]}
|