@nice2dev/ui-graphics 1.0.4 → 1.0.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/dist/cjs/animation/AnimationEditor.js +1 -1
- package/dist/cjs/animation/Audience.js +1 -1
- package/dist/cjs/core/LocalUI.js +1 -1
- package/dist/cjs/core/yjsCollaboration.js +2 -2
- package/dist/cjs/core/yjsCollaboration.js.map +1 -1
- package/dist/cjs/game/GameAsset2dEditor.js +1 -1
- package/dist/cjs/node_modules/lib0/array.js +103 -0
- package/dist/cjs/node_modules/lib0/array.js.map +1 -0
- package/dist/cjs/node_modules/lib0/binary.js +42 -0
- package/dist/cjs/node_modules/lib0/binary.js.map +1 -0
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +121 -0
- package/dist/cjs/node_modules/lib0/broadcastchannel.js.map +1 -0
- package/dist/cjs/node_modules/lib0/buffer.js +103 -0
- package/dist/cjs/node_modules/lib0/buffer.js.map +1 -0
- package/dist/cjs/node_modules/lib0/conditions.js +18 -0
- package/dist/cjs/node_modules/lib0/conditions.js.map +1 -0
- package/dist/cjs/node_modules/lib0/decoding.js +460 -0
- package/dist/cjs/node_modules/lib0/decoding.js.map +1 -0
- package/dist/cjs/node_modules/lib0/dom.js +55 -0
- package/dist/cjs/node_modules/lib0/dom.js.map +1 -0
- package/dist/cjs/node_modules/lib0/encoding.js +688 -0
- package/dist/cjs/node_modules/lib0/encoding.js.map +1 -0
- package/dist/cjs/node_modules/lib0/environment.js +129 -0
- package/dist/cjs/node_modules/lib0/environment.js.map +1 -0
- package/dist/cjs/node_modules/lib0/error.js +37 -0
- package/dist/cjs/node_modules/lib0/error.js.map +1 -0
- package/dist/cjs/node_modules/lib0/function.js +135 -0
- package/dist/cjs/node_modules/lib0/function.js.map +1 -0
- package/dist/cjs/node_modules/lib0/iterator.js +52 -0
- package/dist/cjs/node_modules/lib0/iterator.js.map +1 -0
- package/dist/cjs/node_modules/lib0/logging.common.js +63 -0
- package/dist/cjs/node_modules/lib0/logging.common.js.map +1 -0
- package/dist/cjs/node_modules/lib0/logging.js +128 -0
- package/dist/cjs/node_modules/lib0/logging.js.map +1 -0
- package/dist/cjs/node_modules/lib0/map.js +108 -0
- package/dist/cjs/node_modules/lib0/map.js.map +1 -0
- package/dist/cjs/node_modules/lib0/math.js +44 -0
- package/dist/cjs/node_modules/lib0/math.js.map +1 -0
- package/dist/cjs/node_modules/lib0/number.js +21 -0
- package/dist/cjs/node_modules/lib0/number.js.map +1 -0
- package/dist/cjs/node_modules/lib0/object.js +132 -0
- package/dist/cjs/node_modules/lib0/object.js.map +1 -0
- package/dist/cjs/node_modules/lib0/observable.js +168 -0
- package/dist/cjs/node_modules/lib0/observable.js.map +1 -0
- package/dist/cjs/node_modules/lib0/pair.js +33 -0
- package/dist/cjs/node_modules/lib0/pair.js.map +1 -0
- package/dist/cjs/node_modules/lib0/prng.js +95 -0
- package/dist/cjs/node_modules/lib0/prng.js.map +1 -0
- package/dist/cjs/node_modules/lib0/promise.js +33 -0
- package/dist/cjs/node_modules/lib0/promise.js.map +1 -0
- package/dist/cjs/node_modules/lib0/random.js +28 -0
- package/dist/cjs/node_modules/lib0/random.js.map +1 -0
- package/dist/cjs/node_modules/lib0/schema.js +1168 -0
- package/dist/cjs/node_modules/lib0/schema.js.map +1 -0
- package/dist/cjs/node_modules/lib0/set.js +12 -0
- package/dist/cjs/node_modules/lib0/set.js.map +1 -0
- package/dist/cjs/node_modules/lib0/storage.js +79 -0
- package/dist/cjs/node_modules/lib0/storage.js.map +1 -0
- package/dist/cjs/node_modules/lib0/string.js +94 -0
- package/dist/cjs/node_modules/lib0/string.js.map +1 -0
- package/dist/cjs/node_modules/lib0/symbol.js +15 -0
- package/dist/cjs/node_modules/lib0/symbol.js.map +1 -0
- package/dist/cjs/node_modules/lib0/time.js +18 -0
- package/dist/cjs/node_modules/lib0/time.js.map +1 -0
- package/dist/cjs/node_modules/lib0/trait/equality.js +32 -0
- package/dist/cjs/node_modules/lib0/trait/equality.js.map +1 -0
- package/dist/cjs/node_modules/lib0/url.js +20 -0
- package/dist/cjs/node_modules/lib0/url.js.map +1 -0
- package/dist/cjs/node_modules/lib0/webcrypto.js +8 -0
- package/dist/cjs/node_modules/lib0/webcrypto.js.map +1 -0
- package/dist/cjs/node_modules/y-protocols/auth.js +27 -0
- package/dist/cjs/node_modules/y-protocols/auth.js.map +1 -0
- package/dist/cjs/node_modules/y-protocols/awareness.js +277 -0
- package/dist/cjs/node_modules/y-protocols/awareness.js.map +1 -0
- package/dist/cjs/node_modules/y-protocols/sync.js +149 -0
- package/dist/cjs/node_modules/y-protocols/sync.js.map +1 -0
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +521 -0
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js.map +1 -0
- package/dist/cjs/node_modules/yjs/dist/yjs.js +10399 -0
- package/dist/cjs/node_modules/yjs/dist/yjs.js.map +1 -0
- package/dist/cjs/packages/ui/dist/index.js +65997 -0
- package/dist/cjs/packages/ui/dist/index.js.map +1 -0
- package/dist/cjs/pixel/PixelEditor.js +1 -1
- package/dist/cjs/pixel/PixelEditorMenuBar.js +1 -1
- package/dist/cjs/pixel/PixelEditorRightPanel.js +1 -1
- package/dist/cjs/pixel/PixelEditorTimeline.js +1 -1
- package/dist/cjs/pixel/PixelEditorToolbar.js +1 -1
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +1 -1
- package/dist/cjs/vector/VectorEditor.js +1 -1
- package/dist/cjs/vector/VectorEditorMenuBar.js +1 -1
- package/dist/cjs/vector/VectorEditorRightPanel.js +1 -1
- package/dist/esm/animation/AnimationEditor.js +5 -5
- package/dist/esm/animation/Audience.js +2 -2
- package/dist/esm/core/LocalUI.js +4 -4
- package/dist/esm/core/yjsCollaboration.js +2 -2
- package/dist/esm/core/yjsCollaboration.js.map +1 -1
- package/dist/esm/game/GameAsset2dEditor.js +19 -19
- package/dist/esm/node_modules/lib0/array.js +95 -0
- package/dist/esm/node_modules/lib0/array.js.map +1 -0
- package/dist/esm/node_modules/lib0/binary.js +30 -0
- package/dist/esm/node_modules/lib0/binary.js.map +1 -0
- package/dist/esm/node_modules/lib0/broadcastchannel.js +117 -0
- package/dist/esm/node_modules/lib0/broadcastchannel.js.map +1 -0
- package/dist/esm/node_modules/lib0/buffer.js +96 -0
- package/dist/esm/node_modules/lib0/buffer.js.map +1 -0
- package/dist/esm/node_modules/lib0/conditions.js +16 -0
- package/dist/esm/node_modules/lib0/conditions.js.map +1 -0
- package/dist/esm/node_modules/lib0/decoding.js +439 -0
- package/dist/esm/node_modules/lib0/decoding.js.map +1 -0
- package/dist/esm/node_modules/lib0/dom.js +48 -0
- package/dist/esm/node_modules/lib0/dom.js.map +1 -0
- package/dist/esm/node_modules/lib0/encoding.js +663 -0
- package/dist/esm/node_modules/lib0/encoding.js.map +1 -0
- package/dist/esm/node_modules/lib0/environment.js +121 -0
- package/dist/esm/node_modules/lib0/environment.js.map +1 -0
- package/dist/esm/node_modules/lib0/error.js +33 -0
- package/dist/esm/node_modules/lib0/error.js.map +1 -0
- package/dist/esm/node_modules/lib0/function.js +130 -0
- package/dist/esm/node_modules/lib0/function.js.map +1 -0
- package/dist/esm/node_modules/lib0/iterator.js +48 -0
- package/dist/esm/node_modules/lib0/iterator.js.map +1 -0
- package/dist/esm/node_modules/lib0/logging.common.js +52 -0
- package/dist/esm/node_modules/lib0/logging.common.js.map +1 -0
- package/dist/esm/node_modules/lib0/logging.js +115 -0
- package/dist/esm/node_modules/lib0/logging.js.map +1 -0
- package/dist/esm/node_modules/lib0/map.js +102 -0
- package/dist/esm/node_modules/lib0/map.js.map +1 -0
- package/dist/esm/node_modules/lib0/math.js +37 -0
- package/dist/esm/node_modules/lib0/math.js.map +1 -0
- package/dist/esm/node_modules/lib0/number.js +17 -0
- package/dist/esm/node_modules/lib0/number.js.map +1 -0
- package/dist/esm/node_modules/lib0/object.js +119 -0
- package/dist/esm/node_modules/lib0/object.js.map +1 -0
- package/dist/esm/node_modules/lib0/observable.js +165 -0
- package/dist/esm/node_modules/lib0/observable.js.map +1 -0
- package/dist/esm/node_modules/lib0/pair.js +30 -0
- package/dist/esm/node_modules/lib0/pair.js.map +1 -0
- package/dist/esm/node_modules/lib0/prng.js +87 -0
- package/dist/esm/node_modules/lib0/prng.js.map +1 -0
- package/dist/esm/node_modules/lib0/promise.js +31 -0
- package/dist/esm/node_modules/lib0/promise.js.map +1 -0
- package/dist/esm/node_modules/lib0/random.js +25 -0
- package/dist/esm/node_modules/lib0/random.js.map +1 -0
- package/dist/esm/node_modules/lib0/schema.js +1113 -0
- package/dist/esm/node_modules/lib0/schema.js.map +1 -0
- package/dist/esm/node_modules/lib0/set.js +10 -0
- package/dist/esm/node_modules/lib0/set.js.map +1 -0
- package/dist/esm/node_modules/lib0/storage.js +75 -0
- package/dist/esm/node_modules/lib0/storage.js.map +1 -0
- package/dist/esm/node_modules/lib0/string.js +85 -0
- package/dist/esm/node_modules/lib0/string.js.map +1 -0
- package/dist/esm/node_modules/lib0/symbol.js +13 -0
- package/dist/esm/node_modules/lib0/symbol.js.map +1 -0
- package/dist/esm/node_modules/lib0/time.js +16 -0
- package/dist/esm/node_modules/lib0/time.js.map +1 -0
- package/dist/esm/node_modules/lib0/trait/equality.js +29 -0
- package/dist/esm/node_modules/lib0/trait/equality.js.map +1 -0
- package/dist/esm/node_modules/lib0/url.js +18 -0
- package/dist/esm/node_modules/lib0/url.js.map +1 -0
- package/dist/esm/node_modules/lib0/webcrypto.js +6 -0
- package/dist/esm/node_modules/lib0/webcrypto.js.map +1 -0
- package/dist/esm/node_modules/y-protocols/auth.js +24 -0
- package/dist/esm/node_modules/y-protocols/auth.js.map +1 -0
- package/dist/esm/node_modules/y-protocols/awareness.js +271 -0
- package/dist/esm/node_modules/y-protocols/awareness.js.map +1 -0
- package/dist/esm/node_modules/y-protocols/sync.js +138 -0
- package/dist/esm/node_modules/y-protocols/sync.js.map +1 -0
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +515 -0
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js.map +1 -0
- package/dist/esm/node_modules/yjs/dist/yjs.js +10295 -0
- package/dist/esm/node_modules/yjs/dist/yjs.js.map +1 -0
- package/dist/esm/packages/ui/dist/index.js +65571 -0
- package/dist/esm/packages/ui/dist/index.js.map +1 -0
- package/dist/esm/pixel/PixelEditor.js +3 -3
- package/dist/esm/pixel/PixelEditorMenuBar.js +2 -2
- package/dist/esm/pixel/PixelEditorRightPanel.js +3 -3
- package/dist/esm/pixel/PixelEditorTimeline.js +2 -2
- package/dist/esm/pixel/PixelEditorToolbar.js +2 -2
- package/dist/esm/pixel/SpriteGeneratorPanel.js +8 -8
- package/dist/esm/vector/VectorEditor.js +3 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +3 -3
- package/dist/esm/vector/VectorEditorRightPanel.js +13 -13
- package/package.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var environment = require('./environment.js');
|
|
4
|
+
var set = require('./set.js');
|
|
5
|
+
var pair = require('./pair.js');
|
|
6
|
+
var dom = require('./dom.js');
|
|
7
|
+
var map = require('./map.js');
|
|
8
|
+
var logging_common = require('./logging.common.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Isomorphic logging module with support for colors!
|
|
12
|
+
*
|
|
13
|
+
* @module logging
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {Object<Symbol,pair.Pair<string,string>>}
|
|
19
|
+
*/
|
|
20
|
+
const _browserStyleMap = {
|
|
21
|
+
[logging_common.BOLD]: pair.create('font-weight', 'bold'),
|
|
22
|
+
[logging_common.UNBOLD]: pair.create('font-weight', 'normal'),
|
|
23
|
+
[logging_common.BLUE]: pair.create('color', 'blue'),
|
|
24
|
+
[logging_common.GREEN]: pair.create('color', 'green'),
|
|
25
|
+
[logging_common.GREY]: pair.create('color', 'grey'),
|
|
26
|
+
[logging_common.RED]: pair.create('color', 'red'),
|
|
27
|
+
[logging_common.PURPLE]: pair.create('color', 'purple'),
|
|
28
|
+
[logging_common.ORANGE]: pair.create('color', 'orange'), // not well supported in chrome when debugging node with inspector - TODO: deprecate
|
|
29
|
+
[logging_common.UNCOLOR]: pair.create('color', 'black')
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Array<string|Symbol|Object|number|function():any>} args
|
|
34
|
+
* @return {Array<string|object|number>}
|
|
35
|
+
*/
|
|
36
|
+
/* c8 ignore start */
|
|
37
|
+
const computeBrowserLoggingArgs = (args) => {
|
|
38
|
+
if (args.length === 1 && args[0]?.constructor === Function) {
|
|
39
|
+
args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]());
|
|
40
|
+
}
|
|
41
|
+
const strBuilder = [];
|
|
42
|
+
const styles = [];
|
|
43
|
+
const currentStyle = map.create();
|
|
44
|
+
/**
|
|
45
|
+
* @type {Array<string|Object|number>}
|
|
46
|
+
*/
|
|
47
|
+
let logArgs = [];
|
|
48
|
+
// try with formatting until we find something unsupported
|
|
49
|
+
let i = 0;
|
|
50
|
+
for (; i < args.length; i++) {
|
|
51
|
+
const arg = args[i];
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const style = _browserStyleMap[arg];
|
|
54
|
+
if (style !== undefined) {
|
|
55
|
+
currentStyle.set(style.left, style.right);
|
|
56
|
+
} else {
|
|
57
|
+
if (arg === undefined) {
|
|
58
|
+
break
|
|
59
|
+
}
|
|
60
|
+
if (arg.constructor === String || arg.constructor === Number) {
|
|
61
|
+
const style = dom.mapToStyleString(currentStyle);
|
|
62
|
+
if (i > 0 || style.length > 0) {
|
|
63
|
+
strBuilder.push('%c' + arg);
|
|
64
|
+
styles.push(style);
|
|
65
|
+
} else {
|
|
66
|
+
strBuilder.push(arg);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (i > 0) {
|
|
74
|
+
// create logArgs with what we have so far
|
|
75
|
+
logArgs = styles;
|
|
76
|
+
logArgs.unshift(strBuilder.join(''));
|
|
77
|
+
}
|
|
78
|
+
// append the rest
|
|
79
|
+
for (; i < args.length; i++) {
|
|
80
|
+
const arg = args[i];
|
|
81
|
+
if (!(arg instanceof Symbol)) {
|
|
82
|
+
logArgs.push(arg);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return logArgs
|
|
86
|
+
};
|
|
87
|
+
/* c8 ignore stop */
|
|
88
|
+
|
|
89
|
+
/* c8 ignore start */
|
|
90
|
+
const computeLoggingArgs = environment.supportsColor
|
|
91
|
+
? computeBrowserLoggingArgs
|
|
92
|
+
: logging_common.computeNoColorLoggingArgs;
|
|
93
|
+
/* c8 ignore stop */
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
97
|
+
*/
|
|
98
|
+
const print = (...args) => {
|
|
99
|
+
console.log(...computeLoggingArgs(args));
|
|
100
|
+
/* c8 ignore next */
|
|
101
|
+
vconsoles.forEach((vc) => vc.print(args));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/* c8 ignore start */
|
|
105
|
+
/**
|
|
106
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
107
|
+
*/
|
|
108
|
+
const warn = (...args) => {
|
|
109
|
+
console.warn(...computeLoggingArgs(args));
|
|
110
|
+
args.unshift(logging_common.ORANGE);
|
|
111
|
+
vconsoles.forEach((vc) => vc.print(args));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const vconsoles = set.create();
|
|
115
|
+
|
|
116
|
+
exports.BLUE = logging_common.BLUE;
|
|
117
|
+
exports.BOLD = logging_common.BOLD;
|
|
118
|
+
exports.GREEN = logging_common.GREEN;
|
|
119
|
+
exports.GREY = logging_common.GREY;
|
|
120
|
+
exports.ORANGE = logging_common.ORANGE;
|
|
121
|
+
exports.PURPLE = logging_common.PURPLE;
|
|
122
|
+
exports.RED = logging_common.RED;
|
|
123
|
+
exports.UNBOLD = logging_common.UNBOLD;
|
|
124
|
+
exports.UNCOLOR = logging_common.UNCOLOR;
|
|
125
|
+
exports.print = print;
|
|
126
|
+
exports.vconsoles = vconsoles;
|
|
127
|
+
exports.warn = warn;
|
|
128
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sources":["../../../../../../node_modules/lib0/logging.js"],"sourcesContent":["/**\n * Isomorphic logging module with support for colors!\n *\n * @module logging\n */\n\nimport * as env from './environment.js'\nimport * as set from './set.js'\nimport * as pair from './pair.js'\nimport * as dom from './dom.js'\nimport * as json from './json.js'\nimport * as map from './map.js'\nimport * as eventloop from './eventloop.js'\nimport * as math from './math.js'\nimport * as common from './logging.common.js'\n\nexport { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'\n\n/**\n * @type {Object<Symbol,pair.Pair<string,string>>}\n */\nconst _browserStyleMap = {\n [common.BOLD]: pair.create('font-weight', 'bold'),\n [common.UNBOLD]: pair.create('font-weight', 'normal'),\n [common.BLUE]: pair.create('color', 'blue'),\n [common.GREEN]: pair.create('color', 'green'),\n [common.GREY]: pair.create('color', 'grey'),\n [common.RED]: pair.create('color', 'red'),\n [common.PURPLE]: pair.create('color', 'purple'),\n [common.ORANGE]: pair.create('color', 'orange'), // not well supported in chrome when debugging node with inspector - TODO: deprecate\n [common.UNCOLOR]: pair.create('color', 'black')\n}\n\n/**\n * @param {Array<string|Symbol|Object|number|function():any>} args\n * @return {Array<string|object|number>}\n */\n/* c8 ignore start */\nconst computeBrowserLoggingArgs = (args) => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]())\n }\n const strBuilder = []\n const styles = []\n const currentStyle = map.create()\n /**\n * @type {Array<string|Object|number>}\n */\n let logArgs = []\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n const arg = args[i]\n // @ts-ignore\n const style = _browserStyleMap[arg]\n if (style !== undefined) {\n currentStyle.set(style.left, style.right)\n } else {\n if (arg === undefined) {\n break\n }\n if (arg.constructor === String || arg.constructor === Number) {\n const style = dom.mapToStyleString(currentStyle)\n if (i > 0 || style.length > 0) {\n strBuilder.push('%c' + arg)\n styles.push(style)\n } else {\n strBuilder.push(arg)\n }\n } else {\n break\n }\n }\n }\n if (i > 0) {\n // create logArgs with what we have so far\n logArgs = styles\n logArgs.unshift(strBuilder.join(''))\n }\n // append the rest\n for (; i < args.length; i++) {\n const arg = args[i]\n if (!(arg instanceof Symbol)) {\n logArgs.push(arg)\n }\n }\n return logArgs\n}\n/* c8 ignore stop */\n\n/* c8 ignore start */\nconst computeLoggingArgs = env.supportsColor\n ? computeBrowserLoggingArgs\n : common.computeNoColorLoggingArgs\n/* c8 ignore stop */\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const print = (...args) => {\n console.log(...computeLoggingArgs(args))\n /* c8 ignore next */\n vconsoles.forEach((vc) => vc.print(args))\n}\n\n/* c8 ignore start */\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const warn = (...args) => {\n console.warn(...computeLoggingArgs(args))\n args.unshift(common.ORANGE)\n vconsoles.forEach((vc) => vc.print(args))\n}\n/* c8 ignore stop */\n\n/**\n * @param {Error} err\n */\n/* c8 ignore start */\nexport const printError = (err) => {\n console.error(err)\n vconsoles.forEach((vc) => vc.printError(err))\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} url image location\n * @param {number} height height of the image in pixel\n */\n/* c8 ignore start */\nexport const printImg = (url, height) => {\n if (env.isBrowser) {\n console.log(\n '%c ',\n `font-size: ${height}px; background-size: contain; background-repeat: no-repeat; background-image: url(${url})`\n )\n // console.log('%c ', `font-size: ${height}x; background: url(${url}) no-repeat;`)\n }\n vconsoles.forEach((vc) => vc.printImg(url, height))\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} base64\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printImgBase64 = (base64, height) =>\n printImg(`data:image/gif;base64,${base64}`, height)\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const group = (...args) => {\n console.group(...computeLoggingArgs(args))\n /* c8 ignore next */\n vconsoles.forEach((vc) => vc.group(args))\n}\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const groupCollapsed = (...args) => {\n console.groupCollapsed(...computeLoggingArgs(args))\n /* c8 ignore next */\n vconsoles.forEach((vc) => vc.groupCollapsed(args))\n}\n\nexport const groupEnd = () => {\n console.groupEnd()\n /* c8 ignore next */\n vconsoles.forEach((vc) => vc.groupEnd())\n}\n\n/**\n * @param {function():Node} createNode\n */\n/* c8 ignore next 2 */\nexport const printDom = (createNode) =>\n vconsoles.forEach((vc) => vc.printDom(createNode()))\n\n/**\n * @param {HTMLCanvasElement} canvas\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printCanvas = (canvas, height) =>\n printImg(canvas.toDataURL(), height)\n\nexport const vconsoles = set.create()\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n * @return {Array<Element>}\n */\n/* c8 ignore start */\nconst _computeLineSpans = (args) => {\n const spans = []\n const currentStyle = new Map()\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n let arg = args[i]\n // @ts-ignore\n const style = _browserStyleMap[arg]\n if (style !== undefined) {\n currentStyle.set(style.left, style.right)\n } else {\n if (arg === undefined) {\n arg = 'undefined '\n }\n if (arg.constructor === String || arg.constructor === Number) {\n // @ts-ignore\n const span = dom.element('span', [\n pair.create('style', dom.mapToStyleString(currentStyle))\n ], [dom.text(arg.toString())])\n if (span.innerHTML === '') {\n span.innerHTML = ' '\n }\n spans.push(span)\n } else {\n break\n }\n }\n }\n // append the rest\n for (; i < args.length; i++) {\n let content = args[i]\n if (!(content instanceof Symbol)) {\n if (content.constructor !== String && content.constructor !== Number) {\n content = ' ' + json.stringify(content) + ' '\n }\n spans.push(\n dom.element('span', [], [dom.text(/** @type {string} */ (content))])\n )\n }\n }\n return spans\n}\n/* c8 ignore stop */\n\nconst lineStyle =\n 'font-family:monospace;border-bottom:1px solid #e2e2e2;padding:2px;'\n\n/* c8 ignore start */\nexport class VConsole {\n /**\n * @param {Element} dom\n */\n constructor (dom) {\n this.dom = dom\n /**\n * @type {Element}\n */\n this.ccontainer = this.dom\n this.depth = 0\n vconsoles.add(this)\n }\n\n /**\n * @param {Array<string|Symbol|Object|number>} args\n * @param {boolean} collapsed\n */\n group (args, collapsed = false) {\n eventloop.enqueue(() => {\n const triangleDown = dom.element('span', [\n pair.create('hidden', collapsed),\n pair.create('style', 'color:grey;font-size:120%;')\n ], [dom.text('▼')])\n const triangleRight = dom.element('span', [\n pair.create('hidden', !collapsed),\n pair.create('style', 'color:grey;font-size:125%;')\n ], [dom.text('▶')])\n const content = dom.element(\n 'div',\n [pair.create(\n 'style',\n `${lineStyle};padding-left:${this.depth * 10}px`\n )],\n [triangleDown, triangleRight, dom.text(' ')].concat(\n _computeLineSpans(args)\n )\n )\n const nextContainer = dom.element('div', [\n pair.create('hidden', collapsed)\n ])\n const nextLine = dom.element('div', [], [content, nextContainer])\n dom.append(this.ccontainer, [nextLine])\n this.ccontainer = nextContainer\n this.depth++\n // when header is clicked, collapse/uncollapse container\n dom.addEventListener(content, 'click', (_event) => {\n nextContainer.toggleAttribute('hidden')\n triangleDown.toggleAttribute('hidden')\n triangleRight.toggleAttribute('hidden')\n })\n })\n }\n\n /**\n * @param {Array<string|Symbol|Object|number>} args\n */\n groupCollapsed (args) {\n this.group(args, true)\n }\n\n groupEnd () {\n eventloop.enqueue(() => {\n if (this.depth > 0) {\n this.depth--\n // @ts-ignore\n this.ccontainer = this.ccontainer.parentElement.parentElement\n }\n })\n }\n\n /**\n * @param {Array<string|Symbol|Object|number>} args\n */\n print (args) {\n eventloop.enqueue(() => {\n dom.append(this.ccontainer, [\n dom.element('div', [\n pair.create(\n 'style',\n `${lineStyle};padding-left:${this.depth * 10}px`\n )\n ], _computeLineSpans(args))\n ])\n })\n }\n\n /**\n * @param {Error} err\n */\n printError (err) {\n this.print([common.RED, common.BOLD, err.toString()])\n }\n\n /**\n * @param {string} url\n * @param {number} height\n */\n printImg (url, height) {\n eventloop.enqueue(() => {\n dom.append(this.ccontainer, [\n dom.element('img', [\n pair.create('src', url),\n pair.create('height', `${math.round(height * 1.5)}px`)\n ])\n ])\n })\n }\n\n /**\n * @param {Node} node\n */\n printDom (node) {\n eventloop.enqueue(() => {\n dom.append(this.ccontainer, [node])\n })\n }\n\n destroy () {\n eventloop.enqueue(() => {\n vconsoles.delete(this)\n })\n }\n}\n/* c8 ignore stop */\n\n/**\n * @param {Element} dom\n */\n/* c8 ignore next */\nexport const createVConsole = (dom) => new VConsole(dom)\n\n/**\n * @param {string} moduleName\n * @return {function(...any):void}\n */\nexport const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)\n"],"names":["common.BOLD","pair.create","common.UNBOLD","common.BLUE","common.GREEN","common.GREY","common.RED","common.PURPLE","common.ORANGE","common.UNCOLOR","map.create","dom.mapToStyleString","env.supportsColor","common.computeNoColorLoggingArgs","set.create"],"mappings":"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","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility module to work with key-value stores.
|
|
5
|
+
*
|
|
6
|
+
* @module map
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @template K
|
|
11
|
+
* @template V
|
|
12
|
+
* @typedef {Map<K,V>} GlobalMap
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Map instance.
|
|
17
|
+
*
|
|
18
|
+
* @function
|
|
19
|
+
* @return {Map<any, any>}
|
|
20
|
+
*
|
|
21
|
+
* @function
|
|
22
|
+
*/
|
|
23
|
+
const create = () => new Map();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Copy a Map object into a fresh Map object.
|
|
27
|
+
*
|
|
28
|
+
* @function
|
|
29
|
+
* @template K,V
|
|
30
|
+
* @param {Map<K,V>} m
|
|
31
|
+
* @return {Map<K,V>}
|
|
32
|
+
*/
|
|
33
|
+
const copy = m => {
|
|
34
|
+
const r = create();
|
|
35
|
+
m.forEach((v, k) => { r.set(k, v); });
|
|
36
|
+
return r
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get map property. Create T if property is undefined and set T on map.
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* const listeners = map.setIfUndefined(events, 'eventName', set.create)
|
|
44
|
+
* listeners.add(listener)
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @function
|
|
48
|
+
* @template {Map<any, any>} MAP
|
|
49
|
+
* @template {MAP extends Map<any,infer V> ? function():V : unknown} CF
|
|
50
|
+
* @param {MAP} map
|
|
51
|
+
* @param {MAP extends Map<infer K,any> ? K : unknown} key
|
|
52
|
+
* @param {CF} createT
|
|
53
|
+
* @return {ReturnType<CF>}
|
|
54
|
+
*/
|
|
55
|
+
const setIfUndefined = (map, key, createT) => {
|
|
56
|
+
let set = map.get(key);
|
|
57
|
+
if (set === undefined) {
|
|
58
|
+
map.set(key, set = createT());
|
|
59
|
+
}
|
|
60
|
+
return set
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Creates an Array and populates it with the content of all key-value pairs using the `f(value, key)` function.
|
|
65
|
+
*
|
|
66
|
+
* @function
|
|
67
|
+
* @template K
|
|
68
|
+
* @template V
|
|
69
|
+
* @template R
|
|
70
|
+
* @param {Map<K,V>} m
|
|
71
|
+
* @param {function(V,K):R} f
|
|
72
|
+
* @return {Array<R>}
|
|
73
|
+
*/
|
|
74
|
+
const map = (m, f) => {
|
|
75
|
+
const res = [];
|
|
76
|
+
for (const [key, value] of m) {
|
|
77
|
+
res.push(f(value, key));
|
|
78
|
+
}
|
|
79
|
+
return res
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Tests whether any key-value pairs pass the test implemented by `f(value, key)`.
|
|
84
|
+
*
|
|
85
|
+
* @todo should rename to some - similarly to Array.some
|
|
86
|
+
*
|
|
87
|
+
* @function
|
|
88
|
+
* @template K
|
|
89
|
+
* @template V
|
|
90
|
+
* @param {Map<K,V>} m
|
|
91
|
+
* @param {function(V,K):boolean} f
|
|
92
|
+
* @return {boolean}
|
|
93
|
+
*/
|
|
94
|
+
const any = (m, f) => {
|
|
95
|
+
for (const [key, value] of m) {
|
|
96
|
+
if (f(value, key)) {
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.any = any;
|
|
104
|
+
exports.copy = copy;
|
|
105
|
+
exports.create = create;
|
|
106
|
+
exports.map = map;
|
|
107
|
+
exports.setIfUndefined = setIfUndefined;
|
|
108
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sources":["../../../../../../node_modules/lib0/map.js"],"sourcesContent":["/**\n * Utility module to work with key-value stores.\n *\n * @module map\n */\n\n/**\n * @template K\n * @template V\n * @typedef {Map<K,V>} GlobalMap\n */\n\n/**\n * Creates a new Map instance.\n *\n * @function\n * @return {Map<any, any>}\n *\n * @function\n */\nexport const create = () => new Map()\n\n/**\n * Copy a Map object into a fresh Map object.\n *\n * @function\n * @template K,V\n * @param {Map<K,V>} m\n * @return {Map<K,V>}\n */\nexport const copy = m => {\n const r = create()\n m.forEach((v, k) => { r.set(k, v) })\n return r\n}\n\n/**\n * Get map property. Create T if property is undefined and set T on map.\n *\n * ```js\n * const listeners = map.setIfUndefined(events, 'eventName', set.create)\n * listeners.add(listener)\n * ```\n *\n * @function\n * @template {Map<any, any>} MAP\n * @template {MAP extends Map<any,infer V> ? function():V : unknown} CF\n * @param {MAP} map\n * @param {MAP extends Map<infer K,any> ? K : unknown} key\n * @param {CF} createT\n * @return {ReturnType<CF>}\n */\nexport const setIfUndefined = (map, key, createT) => {\n let set = map.get(key)\n if (set === undefined) {\n map.set(key, set = createT())\n }\n return set\n}\n\n/**\n * Creates an Array and populates it with the content of all key-value pairs using the `f(value, key)` function.\n *\n * @function\n * @template K\n * @template V\n * @template R\n * @param {Map<K,V>} m\n * @param {function(V,K):R} f\n * @return {Array<R>}\n */\nexport const map = (m, f) => {\n const res = []\n for (const [key, value] of m) {\n res.push(f(value, key))\n }\n return res\n}\n\n/**\n * Tests whether any key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @todo should rename to some - similarly to Array.some\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const any = (m, f) => {\n for (const [key, value] of m) {\n if (f(value, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Tests whether all key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const all = (m, f) => {\n for (const [key, value] of m) {\n if (!f(value, key)) {\n return false\n }\n }\n return true\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,IAAI,GAAG;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,IAAI;AACzB,EAAE,MAAM,CAAC,GAAG,MAAM;AAClB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAC,CAAC,CAAC;AACrC,EAAE,OAAO;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,KAAK;AACrD,EAAE,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG;AACvB,EAAE,IAAI,GAAG,KAAK,SAAS,EAAE;AACzB,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,EAAE;AAChC,EAAE;AACF,EAAE,OAAO;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC7B,EAAE,MAAM,GAAG,GAAG;AACd,EAAE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE;AAChC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC;AAC1B,EAAE;AACF,EAAE,OAAO;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC7B,EAAE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE;AAChC,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;AACvB,MAAM,OAAO;AACb,IAAI;AACJ,EAAE;AACF,EAAE,OAAO;AACT;;;;;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common Math expressions.
|
|
5
|
+
*
|
|
6
|
+
* @module math
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const floor = Math.floor;
|
|
10
|
+
const abs = Math.abs;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @function
|
|
14
|
+
* @param {number} a
|
|
15
|
+
* @param {number} b
|
|
16
|
+
* @return {number} The smaller element of a and b
|
|
17
|
+
*/
|
|
18
|
+
const min = (a, b) => a < b ? a : b;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @function
|
|
22
|
+
* @param {number} a
|
|
23
|
+
* @param {number} b
|
|
24
|
+
* @return {number} The bigger element of a and b
|
|
25
|
+
*/
|
|
26
|
+
const max = (a, b) => a > b ? a : b;
|
|
27
|
+
|
|
28
|
+
const pow = Math.pow;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check whether n is negative, while considering the -0 edge case. While `-0 < 0` is false, this
|
|
32
|
+
* function returns true for -0,-1,,.. and returns false for 0,1,2,...
|
|
33
|
+
* @param {number} n
|
|
34
|
+
* @return {boolean} Wether n is negative. This function also distinguishes between -0 and +0
|
|
35
|
+
*/
|
|
36
|
+
const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0;
|
|
37
|
+
|
|
38
|
+
exports.abs = abs;
|
|
39
|
+
exports.floor = floor;
|
|
40
|
+
exports.isNegativeZero = isNegativeZero;
|
|
41
|
+
exports.max = max;
|
|
42
|
+
exports.min = min;
|
|
43
|
+
exports.pow = pow;
|
|
44
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sources":["../../../../../../node_modules/lib0/math.js"],"sourcesContent":["/**\n * Common Math expressions.\n *\n * @module math\n */\n\nexport const floor = Math.floor\nexport const ceil = Math.ceil\nexport const abs = Math.abs\nexport const imul = Math.imul\nexport const round = Math.round\nexport const log10 = Math.log10\nexport const log2 = Math.log2\nexport const log = Math.log\nexport const sqrt = Math.sqrt\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The sum of a and b\n */\nexport const add = (a, b) => a + b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The smaller element of a and b\n */\nexport const min = (a, b) => a < b ? a : b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The bigger element of a and b\n */\nexport const max = (a, b) => a > b ? a : b\n\nexport const isNaN = Number.isNaN\n\nexport const pow = Math.pow\n/**\n * Base 10 exponential function. Returns the value of 10 raised to the power of pow.\n *\n * @param {number} exp\n * @return {number}\n */\nexport const exp10 = exp => Math.pow(10, exp)\n\nexport const sign = Math.sign\n\n/**\n * Check whether n is negative, while considering the -0 edge case. While `-0 < 0` is false, this\n * function returns true for -0,-1,,.. and returns false for 0,1,2,...\n * @param {number} n\n * @return {boolean} Wether n is negative. This function also distinguishes between -0 and +0\n */\nexport const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEY,MAAC,KAAK,GAAG,IAAI,CAAC;AAEd,MAAC,GAAG,GAAG,IAAI,CAAC;;AAgBxB;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG;;AAI7B,MAAC,GAAG,GAAG,IAAI,CAAC;;AAWxB;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,cAAc,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG;;;;;;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var math = require('./math.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utility helpers for working with numbers.
|
|
7
|
+
*
|
|
8
|
+
* @module number
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
13
|
+
const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER;
|
|
14
|
+
|
|
15
|
+
/* c8 ignore next */
|
|
16
|
+
const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num);
|
|
17
|
+
|
|
18
|
+
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
|
19
|
+
exports.MIN_SAFE_INTEGER = MIN_SAFE_INTEGER;
|
|
20
|
+
exports.isInteger = isInteger;
|
|
21
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.js","sources":["../../../../../../node_modules/lib0/number.js"],"sourcesContent":["/**\n * Utility helpers for working with numbers.\n *\n * @module number\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\n\nexport const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nexport const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER\n\nexport const LOWEST_INT32 = 1 << 31\nexport const HIGHEST_INT32 = binary.BITS31\nexport const HIGHEST_UINT32 = binary.BITS32\n\n/* c8 ignore next */\nexport const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)\nexport const isNaN = Number.isNaN\nexport const parseInt = Number.parseInt\n\n/**\n * Count the number of \"1\" bits in an unsigned 32bit number.\n *\n * Super fun bitcount algorithm by Brian Kernighan.\n *\n * @param {number} n\n */\nexport const countBits = n => {\n n &= binary.BITS32\n let count = 0\n while (n) {\n n &= (n - 1)\n count++\n }\n return count\n}\n"],"names":["math.floor"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;;;AAKY,MAAC,gBAAgB,GAAG,MAAM,CAAC;AAC3B,MAAC,gBAAgB,GAAG,MAAM,CAAC;;AAMvC;AACY,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS,KAAK,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAIA,UAAU,CAAC,GAAG,CAAC,KAAK,GAAG;;;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var equality = require('./trait/equality.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {any} o
|
|
7
|
+
* @return {o is { [k:string]:any }}
|
|
8
|
+
*/
|
|
9
|
+
const isObject = o => typeof o === 'object';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Object.assign
|
|
13
|
+
*/
|
|
14
|
+
const assign = Object.assign;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Object<string,any>} obj
|
|
18
|
+
*/
|
|
19
|
+
const keys = Object.keys;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @template V
|
|
23
|
+
* @param {{[k:string]:V}} obj
|
|
24
|
+
* @param {function(V,string):any} f
|
|
25
|
+
*/
|
|
26
|
+
const forEach = (obj, f) => {
|
|
27
|
+
for (const key in obj) {
|
|
28
|
+
f(obj[key], key);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @todo implement mapToArray & map
|
|
34
|
+
*
|
|
35
|
+
* @template R
|
|
36
|
+
* @param {Object<string,any>} obj
|
|
37
|
+
* @param {function(any,string):R} f
|
|
38
|
+
* @return {Array<R>}
|
|
39
|
+
*/
|
|
40
|
+
const map = (obj, f) => {
|
|
41
|
+
const results = [];
|
|
42
|
+
for (const key in obj) {
|
|
43
|
+
results.push(f(obj[key], key));
|
|
44
|
+
}
|
|
45
|
+
return results
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {Object<string,any>} obj
|
|
50
|
+
* @return {number}
|
|
51
|
+
*/
|
|
52
|
+
const size = obj => keys(obj).length;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {Object|null|undefined} obj
|
|
56
|
+
*/
|
|
57
|
+
const isEmpty = obj => {
|
|
58
|
+
// eslint-disable-next-line no-unreachable-loop
|
|
59
|
+
for (const _k in obj) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
return true
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @template {{ [key:string|number|symbol]: any }} T
|
|
67
|
+
* @param {T} obj
|
|
68
|
+
* @param {(v:T[keyof T],k:keyof T)=>boolean} f
|
|
69
|
+
* @return {boolean}
|
|
70
|
+
*/
|
|
71
|
+
const every = (obj, f) => {
|
|
72
|
+
for (const key in obj) {
|
|
73
|
+
if (!f(obj[key], key)) {
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Calls `Object.prototype.hasOwnProperty`.
|
|
82
|
+
*
|
|
83
|
+
* @param {any} obj
|
|
84
|
+
* @param {string|number|symbol} key
|
|
85
|
+
* @return {boolean}
|
|
86
|
+
*/
|
|
87
|
+
const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {Object<string,any>} a
|
|
91
|
+
* @param {Object<string,any>} b
|
|
92
|
+
* @return {boolean}
|
|
93
|
+
*/
|
|
94
|
+
const equalFlat = (a, b) => a === b || (size(a) === size(b) && every(a, (val, key) => (val !== undefined || hasProperty(b, key)) && equality.equals(b[key], val)));
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Make an object immutable. This hurts performance and is usually not needed if you perform good
|
|
98
|
+
* coding practices.
|
|
99
|
+
*/
|
|
100
|
+
const freeze = Object.freeze;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Make an object and all its children immutable.
|
|
104
|
+
* This *really* hurts performance and is usually not needed if you perform good coding practices.
|
|
105
|
+
*
|
|
106
|
+
* @template {any} T
|
|
107
|
+
* @param {T} o
|
|
108
|
+
* @return {Readonly<T>}
|
|
109
|
+
*/
|
|
110
|
+
const deepFreeze = (o) => {
|
|
111
|
+
for (const key in o) {
|
|
112
|
+
const c = o[key];
|
|
113
|
+
if (typeof c === 'object' || typeof c === 'function') {
|
|
114
|
+
deepFreeze(o[key]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return freeze(o)
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
exports.assign = assign;
|
|
121
|
+
exports.deepFreeze = deepFreeze;
|
|
122
|
+
exports.equalFlat = equalFlat;
|
|
123
|
+
exports.every = every;
|
|
124
|
+
exports.forEach = forEach;
|
|
125
|
+
exports.freeze = freeze;
|
|
126
|
+
exports.hasProperty = hasProperty;
|
|
127
|
+
exports.isEmpty = isEmpty;
|
|
128
|
+
exports.isObject = isObject;
|
|
129
|
+
exports.keys = keys;
|
|
130
|
+
exports.map = map;
|
|
131
|
+
exports.size = size;
|
|
132
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sources":["../../../../../../node_modules/lib0/object.js"],"sourcesContent":["import * as equalityTrait from './trait/equality.js'\n\n/**\n * Utility functions for working with EcmaScript objects.\n *\n * @module object\n */\n\n/**\n * @return {Object<string,any>} obj\n */\nexport const create = () => Object.create(null)\n\n/**\n * @param {any} o\n * @return {o is { [k:string]:any }}\n */\nexport const isObject = o => typeof o === 'object'\n\n/**\n * Object.assign\n */\nexport const assign = Object.assign\n\n/**\n * @param {Object<string,any>} obj\n */\nexport const keys = Object.keys\n\n/**\n * @template V\n * @param {{[key:string]: V}} obj\n * @return {Array<V>}\n */\nexport const values = Object.values\n\n/**\n * @template V\n * @param {{[k:string]:V}} obj\n * @param {function(V,string):any} f\n */\nexport const forEach = (obj, f) => {\n for (const key in obj) {\n f(obj[key], key)\n }\n}\n\n/**\n * @todo implement mapToArray & map\n *\n * @template R\n * @param {Object<string,any>} obj\n * @param {function(any,string):R} f\n * @return {Array<R>}\n */\nexport const map = (obj, f) => {\n const results = []\n for (const key in obj) {\n results.push(f(obj[key], key))\n }\n return results\n}\n\n/**\n * @deprecated use object.size instead\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const length = obj => keys(obj).length\n\n/**\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const size = obj => keys(obj).length\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const some = (obj, f) => {\n for (const key in obj) {\n if (f(obj[key], key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @param {Object|null|undefined} obj\n */\nexport const isEmpty = obj => {\n // eslint-disable-next-line no-unreachable-loop\n for (const _k in obj) {\n return false\n }\n return true\n}\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const every = (obj, f) => {\n for (const key in obj) {\n if (!f(obj[key], key)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Calls `Object.prototype.hasOwnProperty`.\n *\n * @param {any} obj\n * @param {string|number|symbol} key\n * @return {boolean}\n */\nexport const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)\n\n/**\n * @param {Object<string,any>} a\n * @param {Object<string,any>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a === b || (size(a) === size(b) && every(a, (val, key) => (val !== undefined || hasProperty(b, key)) && equalityTrait.equals(b[key], val)))\n\n/**\n * Make an object immutable. This hurts performance and is usually not needed if you perform good\n * coding practices.\n */\nexport const freeze = Object.freeze\n\n/**\n * Make an object and all its children immutable.\n * This *really* hurts performance and is usually not needed if you perform good coding practices.\n *\n * @template {any} T\n * @param {T} o\n * @return {Readonly<T>}\n */\nexport const deepFreeze = (o) => {\n for (const key in o) {\n const c = o[key]\n if (typeof c === 'object' || typeof c === 'function') {\n deepFreeze(o[key])\n }\n }\n return freeze(o)\n}\n\n/**\n * Get object property. Create T if property is undefined and set T on object.\n *\n * @function\n * @template {object} KV\n * @template {keyof KV} [K=keyof KV]\n * @param {KV} o\n * @param {K} key\n * @param {() => KV[K]} createT\n * @return {KV[K]}\n */\nexport const setIfUndefined = (o, key, createT) => hasProperty(o, key) ? o[key] : (o[key] = createT())\n"],"names":["equalityTrait.equals"],"mappings":";;;;AAaA;AACA;AACA;AACA;AACY,MAAC,QAAQ,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK;;AAE1C;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC;;AAE7B;AACA;AACA;AACY,MAAC,IAAI,GAAG,MAAM,CAAC;;AAS3B;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK;AACnC,EAAE,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;AACzB,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG;AACnB,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK;AAC/B,EAAE,MAAM,OAAO,GAAG;AAClB,EAAE,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;AACzB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;AACjC,EAAE;AACF,EAAE,OAAO;AACT;;AASA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;;AAiBrC;AACA;AACA;AACY,MAAC,OAAO,GAAG,GAAG,IAAI;AAC9B;AACA,EAAE,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;AACxB,IAAI,OAAO;AACX,EAAE;AACF,EAAE,OAAO;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK;AACjC,EAAE,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;AACzB,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE;AAC3B,MAAM,OAAO;AACb,IAAI;AACJ,EAAE;AACF,EAAE,OAAO;AACT;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG;;AAEtF;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,KAAKA,eAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;;AAE7K;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,UAAU,GAAG,CAAC,CAAC,KAAK;AACjC,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;AACvB,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG;AACnB,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;AAC1D,MAAM,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;AACvB,IAAI;AACJ,EAAE;AACF,EAAE,OAAO,MAAM,CAAC,CAAC;AACjB;;;;;;;;;;;;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map = require('./map.js');
|
|
4
|
+
var set = require('./set.js');
|
|
5
|
+
var array = require('./array.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Observable class prototype.
|
|
9
|
+
*
|
|
10
|
+
* @module observable
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handles named events.
|
|
16
|
+
* @experimental
|
|
17
|
+
*
|
|
18
|
+
* This is basically a (better typed) duplicate of Observable, which will replace Observable in the
|
|
19
|
+
* next release.
|
|
20
|
+
*
|
|
21
|
+
* @template {{[key in keyof EVENTS]: function(...any):void}} EVENTS
|
|
22
|
+
*/
|
|
23
|
+
class ObservableV2 {
|
|
24
|
+
constructor () {
|
|
25
|
+
/**
|
|
26
|
+
* Some desc.
|
|
27
|
+
* @type {Map<string, Set<any>>}
|
|
28
|
+
*/
|
|
29
|
+
this._observers = map.create();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @template {keyof EVENTS & string} NAME
|
|
34
|
+
* @param {NAME} name
|
|
35
|
+
* @param {EVENTS[NAME]} f
|
|
36
|
+
*/
|
|
37
|
+
on (name, f) {
|
|
38
|
+
map.setIfUndefined(this._observers, /** @type {string} */ (name), set.create).add(f);
|
|
39
|
+
return f
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @template {keyof EVENTS & string} NAME
|
|
44
|
+
* @param {NAME} name
|
|
45
|
+
* @param {EVENTS[NAME]} f
|
|
46
|
+
*/
|
|
47
|
+
once (name, f) {
|
|
48
|
+
/**
|
|
49
|
+
* @param {...any} args
|
|
50
|
+
*/
|
|
51
|
+
const _f = (...args) => {
|
|
52
|
+
this.off(name, /** @type {any} */ (_f));
|
|
53
|
+
f(...args);
|
|
54
|
+
};
|
|
55
|
+
this.on(name, /** @type {any} */ (_f));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @template {keyof EVENTS & string} NAME
|
|
60
|
+
* @param {NAME} name
|
|
61
|
+
* @param {EVENTS[NAME]} f
|
|
62
|
+
*/
|
|
63
|
+
off (name, f) {
|
|
64
|
+
const observers = this._observers.get(name);
|
|
65
|
+
if (observers !== undefined) {
|
|
66
|
+
observers.delete(f);
|
|
67
|
+
if (observers.size === 0) {
|
|
68
|
+
this._observers.delete(name);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Emit a named event. All registered event listeners that listen to the
|
|
75
|
+
* specified name will receive the event.
|
|
76
|
+
*
|
|
77
|
+
* @todo This should catch exceptions
|
|
78
|
+
*
|
|
79
|
+
* @template {keyof EVENTS & string} NAME
|
|
80
|
+
* @param {NAME} name The event name.
|
|
81
|
+
* @param {Parameters<EVENTS[NAME]>} args The arguments that are applied to the event listener.
|
|
82
|
+
*/
|
|
83
|
+
emit (name, args) {
|
|
84
|
+
// copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.
|
|
85
|
+
return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
destroy () {
|
|
89
|
+
this._observers = map.create();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* c8 ignore start */
|
|
94
|
+
/**
|
|
95
|
+
* Handles named events.
|
|
96
|
+
*
|
|
97
|
+
* @deprecated
|
|
98
|
+
* @template N
|
|
99
|
+
*/
|
|
100
|
+
class Observable {
|
|
101
|
+
constructor () {
|
|
102
|
+
/**
|
|
103
|
+
* Some desc.
|
|
104
|
+
* @type {Map<N, any>}
|
|
105
|
+
*/
|
|
106
|
+
this._observers = map.create();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {N} name
|
|
111
|
+
* @param {function} f
|
|
112
|
+
*/
|
|
113
|
+
on (name, f) {
|
|
114
|
+
map.setIfUndefined(this._observers, name, set.create).add(f);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {N} name
|
|
119
|
+
* @param {function} f
|
|
120
|
+
*/
|
|
121
|
+
once (name, f) {
|
|
122
|
+
/**
|
|
123
|
+
* @param {...any} args
|
|
124
|
+
*/
|
|
125
|
+
const _f = (...args) => {
|
|
126
|
+
this.off(name, _f);
|
|
127
|
+
f(...args);
|
|
128
|
+
};
|
|
129
|
+
this.on(name, _f);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {N} name
|
|
134
|
+
* @param {function} f
|
|
135
|
+
*/
|
|
136
|
+
off (name, f) {
|
|
137
|
+
const observers = this._observers.get(name);
|
|
138
|
+
if (observers !== undefined) {
|
|
139
|
+
observers.delete(f);
|
|
140
|
+
if (observers.size === 0) {
|
|
141
|
+
this._observers.delete(name);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Emit a named event. All registered event listeners that listen to the
|
|
148
|
+
* specified name will receive the event.
|
|
149
|
+
*
|
|
150
|
+
* @todo This should catch exceptions
|
|
151
|
+
*
|
|
152
|
+
* @param {N} name The event name.
|
|
153
|
+
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
154
|
+
*/
|
|
155
|
+
emit (name, args) {
|
|
156
|
+
// copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.
|
|
157
|
+
return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
destroy () {
|
|
161
|
+
this._observers = map.create();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/* c8 ignore end */
|
|
165
|
+
|
|
166
|
+
exports.Observable = Observable;
|
|
167
|
+
exports.ObservableV2 = ObservableV2;
|
|
168
|
+
//# sourceMappingURL=observable.js.map
|