@vorplex/core 0.0.8 → 0.0.9
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/consts/mime-type.const.d.ts +456 -0
- package/dist/consts/mime-type.const.js +456 -0
- package/dist/consts/unit.const.d.ts +22 -0
- package/dist/consts/unit.const.js +22 -0
- package/dist/functions/debounce.function.d.ts +1 -0
- package/dist/functions/debounce.function.js +12 -0
- package/dist/functions/is-node-environment.function.d.ts +1 -0
- package/dist/functions/is-node-environment.function.js +3 -0
- package/dist/functions/parse-path-selector.function.d.ts +2 -0
- package/dist/functions/parse-path-selector.function.js +17 -0
- package/dist/functions/parse-url.function.d.ts +12 -0
- package/dist/functions/parse-url.function.js +25 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +93 -0
- package/dist/interfaces/group.interface.d.ts +4 -0
- package/dist/interfaces/group.interface.js +0 -0
- package/dist/interfaces/key-value.interface.d.ts +4 -0
- package/dist/interfaces/key-value.interface.js +0 -0
- package/dist/modules/api/socket.model.d.ts +26 -0
- package/dist/modules/api/socket.model.js +66 -0
- package/dist/modules/api/web-client.model.d.ts +16 -0
- package/dist/modules/api/web-client.model.js +34 -0
- package/dist/modules/array/array.util.d.ts +17 -0
- package/dist/modules/array/array.util.js +105 -0
- package/dist/modules/changes/changes.util.d.ts +45 -0
- package/dist/modules/changes/changes.util.js +330 -0
- package/dist/modules/color/color-data.interface.d.ts +10 -0
- package/dist/modules/color/color-data.interface.js +0 -0
- package/dist/modules/color/color-formats.const.d.ts +9 -0
- package/dist/modules/color/color-formats.const.js +8 -0
- package/dist/modules/color/color.type.d.ts +4 -0
- package/dist/modules/color/color.type.js +0 -0
- package/dist/modules/color/color.util.d.ts +41 -0
- package/dist/modules/color/color.util.js +327 -0
- package/dist/modules/color/colors.const.d.ts +151 -0
- package/dist/modules/color/colors.const.js +150 -0
- package/dist/modules/color/hsl.interface.d.ts +6 -0
- package/dist/modules/color/hsl.interface.js +0 -0
- package/dist/modules/color/hsv.interface.d.ts +6 -0
- package/dist/modules/color/hsv.interface.js +0 -0
- package/dist/modules/color/rgb.interface.d.ts +6 -0
- package/dist/modules/color/rgb.interface.js +0 -0
- package/dist/modules/compression/compression.util.d.ts +4 -0
- package/dist/modules/compression/compression.util.js +52 -0
- package/dist/modules/date/date.util.d.ts +37 -0
- package/dist/modules/date/date.util.js +84 -0
- package/dist/modules/enum/enum.util.d.ts +17 -0
- package/dist/modules/enum/enum.util.js +69 -0
- package/dist/modules/hash/hash.util.d.ts +3 -0
- package/dist/modules/hash/hash.util.js +9 -0
- package/dist/modules/id/id.util.d.ts +7 -0
- package/dist/modules/id/id.util.js +33 -0
- package/dist/modules/injector/decorators/inject-token.decorator.d.ts +14 -0
- package/dist/modules/injector/decorators/inject-token.decorator.js +12 -0
- package/dist/modules/injector/decorators/injectable.decorator.d.ts +9 -0
- package/dist/modules/injector/decorators/injectable.decorator.js +7 -0
- package/dist/modules/injector/injector.model.d.ts +25 -0
- package/dist/modules/injector/injector.model.js +152 -0
- package/dist/modules/injector/provider-scopes.enum.d.ts +5 -0
- package/dist/modules/injector/provider-scopes.enum.js +6 -0
- package/dist/modules/injector/provider.interface.d.ts +10 -0
- package/dist/modules/injector/provider.interface.js +0 -0
- package/dist/modules/json-filter/json-filter.function.d.ts +41 -0
- package/dist/modules/json-filter/json-filter.function.js +75 -0
- package/dist/modules/logging/console-logger.model.d.ts +36 -0
- package/dist/modules/logging/console-logger.model.js +44 -0
- package/dist/modules/logging/logger.model.d.ts +6 -0
- package/dist/modules/logging/logger.model.js +7 -0
- package/dist/modules/logging/task.d.ts +38 -0
- package/dist/modules/logging/task.js +133 -0
- package/dist/modules/math/line.d.ts +12 -0
- package/dist/modules/math/line.js +50 -0
- package/dist/modules/math/point.d.ts +34 -0
- package/dist/modules/math/point.js +71 -0
- package/dist/modules/math/polygon.d.ts +45 -0
- package/dist/modules/math/polygon.js +273 -0
- package/dist/modules/math/rect.d.ts +6 -0
- package/dist/modules/math/rect.js +0 -0
- package/dist/modules/math/size.d.ts +4 -0
- package/dist/modules/math/size.js +0 -0
- package/dist/modules/number/number.util.d.ts +9 -0
- package/dist/modules/number/number.util.js +27 -0
- package/dist/modules/object/object.util.d.ts +7 -0
- package/dist/modules/object/object.util.js +63 -0
- package/dist/modules/path/path.util.d.ts +11 -0
- package/dist/modules/path/path.util.js +59 -0
- package/dist/modules/random/random.util.d.ts +17 -0
- package/dist/modules/random/random.util.js +57 -0
- package/dist/modules/readable-stream/readable-stream.util.d.ts +3 -0
- package/dist/modules/readable-stream/readable-stream.util.js +26 -0
- package/dist/modules/reflection/interfaces/parameter.interface.d.ts +4 -0
- package/dist/modules/reflection/interfaces/parameter.interface.js +0 -0
- package/dist/modules/reflection/models/attribute.model.d.ts +12 -0
- package/dist/modules/reflection/models/attribute.model.js +17 -0
- package/dist/modules/reflection/models/class-attribute.model.d.ts +4 -0
- package/dist/modules/reflection/models/class-attribute.model.js +6 -0
- package/dist/modules/reflection/models/method-attribute.model.d.ts +5 -0
- package/dist/modules/reflection/models/method-attribute.model.js +8 -0
- package/dist/modules/reflection/models/parameter-attribute.model.d.ts +7 -0
- package/dist/modules/reflection/models/parameter-attribute.model.js +21 -0
- package/dist/modules/reflection/models/property-attribute.model.d.ts +5 -0
- package/dist/modules/reflection/models/property-attribute.model.js +8 -0
- package/dist/modules/reflection/models/property-proxy-attribute.model.d.ts +15 -0
- package/dist/modules/reflection/models/property-proxy-attribute.model.js +19 -0
- package/dist/modules/reflection/types/constructor.type.d.ts +2 -0
- package/dist/modules/reflection/types/constructor.type.js +0 -0
- package/dist/modules/reflection/types/instance.type.d.ts +7 -0
- package/dist/modules/reflection/types/instance.type.js +0 -0
- package/dist/modules/reflection/types/type.type.d.ts +2 -0
- package/dist/modules/reflection/types/type.type.js +0 -0
- package/dist/modules/reflection/utils/decorator.util.d.ts +70 -0
- package/dist/modules/reflection/utils/decorator.util.js +135 -0
- package/dist/modules/reflection/utils/reflection.util.d.ts +140 -0
- package/dist/modules/reflection/utils/reflection.util.js +311 -0
- package/dist/modules/router/router.util.d.ts +33 -0
- package/dist/modules/router/router.util.js +59 -0
- package/dist/modules/state/adaptors/array/array-adaptor.util.d.ts +25 -0
- package/dist/modules/state/adaptors/array/array-adaptor.util.js +97 -0
- package/dist/modules/state/adaptors/entity/entity-adaptor.util.d.ts +35 -0
- package/dist/modules/state/adaptors/entity/entity-adaptor.util.js +158 -0
- package/dist/modules/state/adaptors/entity/entity-map.type.d.ts +4 -0
- package/dist/modules/state/adaptors/entity/entity-map.type.js +0 -0
- package/dist/modules/state/adaptors/entity/entity.interface.d.ts +3 -0
- package/dist/modules/state/adaptors/entity/entity.interface.js +0 -0
- package/dist/modules/state/state.model.d.ts +46 -0
- package/dist/modules/state/state.model.js +129 -0
- package/dist/modules/state/update.type.d.ts +2 -0
- package/dist/modules/state/update.type.js +0 -0
- package/dist/modules/string/string.util.d.ts +11 -0
- package/dist/modules/string/string.util.js +42 -0
- package/dist/modules/subscribable/subscribable.model.d.ts +10 -0
- package/dist/modules/subscribable/subscribable.model.js +34 -0
- package/dist/modules/subscribable/subscription.interface.d.ts +3 -0
- package/dist/modules/subscribable/subscription.interface.js +0 -0
- package/dist/modules/tson/error.d.ts +8 -0
- package/dist/modules/tson/error.js +13 -0
- package/dist/modules/tson/schema.d.ts +10 -0
- package/dist/modules/tson/schema.js +0 -0
- package/dist/modules/tson/schemas/any.d.ts +14 -0
- package/dist/modules/tson/schemas/any.js +27 -0
- package/dist/modules/tson/schemas/array.d.ts +21 -0
- package/dist/modules/tson/schemas/array.js +80 -0
- package/dist/modules/tson/schemas/boolean.d.ts +14 -0
- package/dist/modules/tson/schemas/boolean.js +38 -0
- package/dist/modules/tson/schemas/enum.d.ts +15 -0
- package/dist/modules/tson/schemas/enum.js +43 -0
- package/dist/modules/tson/schemas/number.d.ts +20 -0
- package/dist/modules/tson/schemas/number.js +66 -0
- package/dist/modules/tson/schemas/object.d.ts +33 -0
- package/dist/modules/tson/schemas/object.js +88 -0
- package/dist/modules/tson/schemas/schema-base.d.ts +12 -0
- package/dist/modules/tson/schemas/schema-base.js +14 -0
- package/dist/modules/tson/schemas/string.d.ts +19 -0
- package/dist/modules/tson/schemas/string.js +60 -0
- package/dist/modules/tson/schemas/union.d.ts +16 -0
- package/dist/modules/tson/schemas/union.js +56 -0
- package/dist/modules/tson/tson.d.ts +41 -0
- package/dist/modules/tson/tson.js +138 -0
- package/dist/modules/tson/type.d.ts +53 -0
- package/dist/modules/tson/type.js +0 -0
- package/dist/modules/value/value.util.d.ts +18 -0
- package/dist/modules/value/value.util.js +180 -0
- package/dist/types/awaitable.type.d.ts +1 -0
- package/dist/types/awaitable.type.js +0 -0
- package/dist/types/camel-to-kebab.type.d.ts +1 -0
- package/dist/types/camel-to-kebab.type.js +0 -0
- package/dist/types/has-key.type.d.ts +3 -0
- package/dist/types/has-key.type.js +0 -0
- package/dist/types/is-union.type.d.ts +1 -0
- package/dist/types/is-union.type.js +0 -0
- package/dist/types/keys-of-type.type.d.ts +5 -0
- package/dist/types/keys-of-type.type.js +0 -0
- package/dist/types/keys-with-fix.type.d.ts +3 -0
- package/dist/types/keys-with-fix.type.js +0 -0
- package/dist/types/optional-keys.type.d.ts +6 -0
- package/dist/types/optional-keys.type.js +0 -0
- package/dist/types/partial.type.d.ts +6 -0
- package/dist/types/partial.type.js +0 -0
- package/dist/types/predicate.type.d.ts +1 -0
- package/dist/types/predicate.type.js +0 -0
- package/dist/types/recursive-readonly.type.d.ts +3 -0
- package/dist/types/recursive-readonly.type.js +0 -0
- package/dist/types/recursive-value.type.d.ts +3 -0
- package/dist/types/recursive-value.type.js +0 -0
- package/dist/types/selector.type.d.ts +1 -0
- package/dist/types/selector.type.js +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { $Object } from '../object/object.util';
|
|
2
|
+
import { $Reflection } from '../reflection/utils/reflection.util';
|
|
3
|
+
export const JsonFilters = {
|
|
4
|
+
query: (selector, operator) => (value) => operator(selector(value)),
|
|
5
|
+
and: (...operators) => (value) => operators.every((arg) => arg(value)),
|
|
6
|
+
or: (...operators) => (value) => operators.some((arg) => arg(value)),
|
|
7
|
+
not: (operator) => (value) => !operator(value),
|
|
8
|
+
equals: (arg) => (value) => value === arg || String(value).toLowerCase() === String(arg).toLowerCase(),
|
|
9
|
+
length: (arg) => (value) => (Array.isArray(value) ? value.length === arg : typeof value === 'object' ? Object.keys(value).length === arg : String(value).length === arg),
|
|
10
|
+
contains: (arg) => (value) => value === arg || String(value).toLowerCase().includes(String(arg).toLowerCase()),
|
|
11
|
+
starts: (arg) => (value) => value === arg || String(value).toLowerCase().startsWith(String(arg).toLowerCase()),
|
|
12
|
+
ends: (arg) => (value) => value === arg || String(value).toLowerCase().endsWith(String(arg).toLowerCase()),
|
|
13
|
+
greater: (arg) => (value) => {
|
|
14
|
+
switch ($Reflection.getSimpleTypeName(value)) {
|
|
15
|
+
case 'array':
|
|
16
|
+
return value.length > Number(arg);
|
|
17
|
+
case 'string':
|
|
18
|
+
return String(value).length > Number(arg);
|
|
19
|
+
case 'number':
|
|
20
|
+
return Number(value) > Number(arg);
|
|
21
|
+
case 'date':
|
|
22
|
+
return new Date(value) > new Date(arg);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
less: (arg) => (value) => {
|
|
26
|
+
switch ($Reflection.getSimpleTypeName(value)) {
|
|
27
|
+
case 'array':
|
|
28
|
+
return value.length < Number(arg);
|
|
29
|
+
case 'string':
|
|
30
|
+
return String(value).length < Number(arg);
|
|
31
|
+
case 'number':
|
|
32
|
+
return Number(value) < Number(arg);
|
|
33
|
+
case 'date':
|
|
34
|
+
return new Date(value) < new Date(arg);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const JsonFilterOperators = {
|
|
39
|
+
and: (arg, options) => JsonFilters.and(...arg.map((arg) => jsonFilter(arg, { ...options, operator: 'and' }))),
|
|
40
|
+
or: (arg, options) => JsonFilters.or(...arg.map((arg) => jsonFilter(arg, { ...options, operator: 'or' }))),
|
|
41
|
+
not: (arg, options) => JsonFilters.not(jsonFilter(arg, options)),
|
|
42
|
+
equals: JsonFilters.equals,
|
|
43
|
+
contains: JsonFilters.contains,
|
|
44
|
+
starts: JsonFilters.starts,
|
|
45
|
+
ends: JsonFilters.ends,
|
|
46
|
+
greater: JsonFilters.greater,
|
|
47
|
+
less: JsonFilters.less,
|
|
48
|
+
};
|
|
49
|
+
export const DefaultJsonFilterOptions = {
|
|
50
|
+
operatorPrefix: '$',
|
|
51
|
+
operator: 'and',
|
|
52
|
+
operators: JsonFilterOperators,
|
|
53
|
+
};
|
|
54
|
+
export function jsonFilter(query, options = {}) {
|
|
55
|
+
options = $Object.getDefaults(options, DefaultJsonFilterOptions);
|
|
56
|
+
const filters = [];
|
|
57
|
+
for (const property in query) {
|
|
58
|
+
const value = query[property];
|
|
59
|
+
let filter;
|
|
60
|
+
if (property.startsWith(options.operatorPrefix)) {
|
|
61
|
+
const operator = options.operators[property.substring(1)];
|
|
62
|
+
if (operator) {
|
|
63
|
+
filter = operator(value, options);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(`Unknown operator '${property.substring(1)}'`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
filter = JsonFilters.query((item) => item[property], jsonFilter(value, options));
|
|
71
|
+
}
|
|
72
|
+
filters.push(filter);
|
|
73
|
+
}
|
|
74
|
+
return options.operator === 'and' ? JsonFilters.and(...filters) : JsonFilters.or(...filters);
|
|
75
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Logger } from './logger.model';
|
|
2
|
+
export declare class Chalk {
|
|
3
|
+
static readonly Reset: "\u001B[0m";
|
|
4
|
+
static readonly Normal: "\u001B[22m";
|
|
5
|
+
static readonly Bright: "\u001B[1m";
|
|
6
|
+
static readonly Dim: "\u001B[2m";
|
|
7
|
+
static readonly Underscore: "\u001B[4m";
|
|
8
|
+
static readonly Blink: "\u001B[5m";
|
|
9
|
+
static readonly Reverse: "\u001B[7m";
|
|
10
|
+
static readonly Hidden: "\u001B[8m";
|
|
11
|
+
static readonly Black: "\u001B[30m";
|
|
12
|
+
static readonly Red: "\u001B[31m";
|
|
13
|
+
static readonly Green: "\u001B[32m";
|
|
14
|
+
static readonly Yellow: "\u001B[33m";
|
|
15
|
+
static readonly Orange: "\u001B[38;5;172m";
|
|
16
|
+
static readonly Blue: "\u001B[34m";
|
|
17
|
+
static readonly Magenta: "\u001B[35m";
|
|
18
|
+
static readonly Cyan: "\u001B[36m";
|
|
19
|
+
static readonly White: "\u001B[37m";
|
|
20
|
+
static readonly DarkGray: "\u001B[38;5;244m";
|
|
21
|
+
static readonly Gray: "\u001B[38;5;247m";
|
|
22
|
+
static readonly BlackBackground: "\u001B[40m";
|
|
23
|
+
static readonly RedBackground: "\u001B[41m";
|
|
24
|
+
static readonly GreenBackground: "\u001B[42m";
|
|
25
|
+
static readonly YellowBackground: "\u001B[43m";
|
|
26
|
+
static readonly BlueBackground: "\u001B[44m";
|
|
27
|
+
static readonly MagentaBackground: "\u001B[45m";
|
|
28
|
+
static readonly CyanBackground: "\u001B[46m";
|
|
29
|
+
static readonly WhiteBackground: "\u001B[47m";
|
|
30
|
+
static hue(hue: number): string;
|
|
31
|
+
}
|
|
32
|
+
export declare class ConsoleLogger extends Logger {
|
|
33
|
+
log(...message: string[]): void;
|
|
34
|
+
warn(...message: string[]): void;
|
|
35
|
+
error(error: string | Error): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from './logger.model';
|
|
2
|
+
export class Chalk {
|
|
3
|
+
static Reset = '\u001b[0m';
|
|
4
|
+
static Normal = '\u001b[22m';
|
|
5
|
+
static Bright = '\u001b[1m';
|
|
6
|
+
static Dim = '\u001b[2m';
|
|
7
|
+
static Underscore = '\u001b[4m';
|
|
8
|
+
static Blink = '\u001b[5m';
|
|
9
|
+
static Reverse = '\u001b[7m';
|
|
10
|
+
static Hidden = '\u001b[8m';
|
|
11
|
+
static Black = '\u001b[30m';
|
|
12
|
+
static Red = '\u001b[31m';
|
|
13
|
+
static Green = '\u001b[32m';
|
|
14
|
+
static Yellow = '\u001b[33m';
|
|
15
|
+
static Orange = '\u001b[38;5;172m';
|
|
16
|
+
static Blue = '\u001b[34m';
|
|
17
|
+
static Magenta = '\u001b[35m';
|
|
18
|
+
static Cyan = '\u001b[36m';
|
|
19
|
+
static White = '\u001b[37m';
|
|
20
|
+
static DarkGray = '\u001b[38;5;244m';
|
|
21
|
+
static Gray = '\u001b[38;5;247m';
|
|
22
|
+
static BlackBackground = '\u001b[40m';
|
|
23
|
+
static RedBackground = '\u001b[41m';
|
|
24
|
+
static GreenBackground = '\u001b[42m';
|
|
25
|
+
static YellowBackground = '\u001b[43m';
|
|
26
|
+
static BlueBackground = '\u001b[44m';
|
|
27
|
+
static MagentaBackground = '\u001b[45m';
|
|
28
|
+
static CyanBackground = '\u001b[46m';
|
|
29
|
+
static WhiteBackground = '\u001b[47m';
|
|
30
|
+
static hue(hue) {
|
|
31
|
+
return `\u001b[38;5;${hue}m`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class ConsoleLogger extends Logger {
|
|
35
|
+
log(...message) {
|
|
36
|
+
console.log([Chalk.DarkGray, ...message, Chalk.Reset].join(''));
|
|
37
|
+
}
|
|
38
|
+
warn(...message) {
|
|
39
|
+
console.warn([Chalk.Orange, ...message, Chalk.Reset].join(''));
|
|
40
|
+
}
|
|
41
|
+
error(error) {
|
|
42
|
+
console.error([Chalk.Red, error instanceof Error ? error.message : error, Chalk.Reset].join(''));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Subscribable } from '../subscribable/subscribable.model';
|
|
2
|
+
export declare const TaskStatus: {
|
|
3
|
+
readonly Busy: "busy";
|
|
4
|
+
readonly Failed: "failed";
|
|
5
|
+
readonly Done: "done";
|
|
6
|
+
};
|
|
7
|
+
export type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus];
|
|
8
|
+
export interface Attachment {
|
|
9
|
+
type: 'json' | 'yaml' | 'text' | 'typescript';
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Log {
|
|
13
|
+
timestamp: number;
|
|
14
|
+
message: string;
|
|
15
|
+
level: 'info' | 'warning' | 'error';
|
|
16
|
+
attachments: Record<string, Attachment>;
|
|
17
|
+
}
|
|
18
|
+
export declare class Task extends Subscribable<Task> {
|
|
19
|
+
startTimestamp: number;
|
|
20
|
+
finishTimestamp: number;
|
|
21
|
+
status: TaskStatus;
|
|
22
|
+
name: string;
|
|
23
|
+
parent?: Task;
|
|
24
|
+
tasks: Task[];
|
|
25
|
+
logs: Log[];
|
|
26
|
+
constructor(name: string, task?: Task);
|
|
27
|
+
do<T>(name: string, callback: (task: Task) => Promise<T> | T): Promise<T>;
|
|
28
|
+
static do<T>(name: string, callback: (task: Task) => Promise<T> | T): Promise<T>;
|
|
29
|
+
log(message: string, options?: {
|
|
30
|
+
level?: 'info' | 'warning' | 'error';
|
|
31
|
+
attachments?: Record<string, Attachment>;
|
|
32
|
+
}): void;
|
|
33
|
+
fail(error?: string | Error): void;
|
|
34
|
+
complete(): void;
|
|
35
|
+
getStatus(): TaskStatus;
|
|
36
|
+
hasWarning(): boolean;
|
|
37
|
+
toConsoleLog(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Unit } from '../../consts/unit.const';
|
|
2
|
+
import { $Array } from '../array/array.util';
|
|
3
|
+
import { $Date } from '../date/date.util';
|
|
4
|
+
import { $Number } from '../number/number.util';
|
|
5
|
+
import { $String } from '../string/string.util';
|
|
6
|
+
import { Subscribable } from '../subscribable/subscribable.model';
|
|
7
|
+
import { Chalk } from './console-logger.model';
|
|
8
|
+
export const TaskStatus = {
|
|
9
|
+
Busy: 'busy',
|
|
10
|
+
Failed: 'failed',
|
|
11
|
+
Done: 'done',
|
|
12
|
+
};
|
|
13
|
+
export class Task extends Subscribable {
|
|
14
|
+
startTimestamp = Date.now();
|
|
15
|
+
finishTimestamp;
|
|
16
|
+
status = TaskStatus.Busy;
|
|
17
|
+
name;
|
|
18
|
+
parent;
|
|
19
|
+
tasks = [];
|
|
20
|
+
logs = [];
|
|
21
|
+
constructor(name, task) {
|
|
22
|
+
super();
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.parent = task;
|
|
25
|
+
this.subscribe(task => task.parent?.emit(this.parent));
|
|
26
|
+
}
|
|
27
|
+
async do(name, callback) {
|
|
28
|
+
const task = new Task(name, this);
|
|
29
|
+
this.tasks.push(task);
|
|
30
|
+
this.emit(this);
|
|
31
|
+
try {
|
|
32
|
+
const result = await callback(task);
|
|
33
|
+
task.complete();
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
task.fail();
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static async do(name, callback) {
|
|
42
|
+
const task = new Task(name);
|
|
43
|
+
try {
|
|
44
|
+
return await callback(task);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
task.fail(error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
task.complete();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
log(message, options) {
|
|
55
|
+
this.logs.push({
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
message,
|
|
58
|
+
level: options?.level ?? 'info',
|
|
59
|
+
attachments: options?.attachments ?? {}
|
|
60
|
+
});
|
|
61
|
+
this.emit(this);
|
|
62
|
+
}
|
|
63
|
+
fail(error) {
|
|
64
|
+
if (this.status !== 'failed') {
|
|
65
|
+
if (error)
|
|
66
|
+
this.log(error instanceof Error ? error.stack ?? error.message : error, { level: 'error' });
|
|
67
|
+
this.status = 'failed';
|
|
68
|
+
this.finishTimestamp = Date.now();
|
|
69
|
+
this.emit(this);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
complete() {
|
|
73
|
+
if (this.status === 'busy') {
|
|
74
|
+
this.status = 'done';
|
|
75
|
+
this.finishTimestamp = Date.now();
|
|
76
|
+
this.emit(this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getStatus() {
|
|
80
|
+
let failed;
|
|
81
|
+
for (const task of this.tasks) {
|
|
82
|
+
const status = task.getStatus();
|
|
83
|
+
if (status === 'failed')
|
|
84
|
+
failed = true;
|
|
85
|
+
if (status === 'busy')
|
|
86
|
+
return 'busy';
|
|
87
|
+
}
|
|
88
|
+
if (failed)
|
|
89
|
+
return 'failed';
|
|
90
|
+
return this.status;
|
|
91
|
+
}
|
|
92
|
+
hasWarning() {
|
|
93
|
+
for (const log of this.logs) {
|
|
94
|
+
if (log.level === 'warning')
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
for (const task of this.tasks) {
|
|
98
|
+
const warning = task.hasWarning();
|
|
99
|
+
if (warning)
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
toConsoleLog() {
|
|
105
|
+
const formatter = {
|
|
106
|
+
task: (task) => {
|
|
107
|
+
const status = { done: `${Chalk.White}★ [Done]`, busy: `${Chalk.Orange}★ [Busy]`, failed: `${Chalk.Red}★ [Failed]` }[task.getStatus()];
|
|
108
|
+
const date = $Date.format(new Date(task.startTimestamp), '[YYYY-MM-DD hh:mm:ss]');
|
|
109
|
+
const duration = $Number.toUnitString(task.finishTimestamp - task.startTimestamp, Unit.Time);
|
|
110
|
+
return `${status} ${date} ${task.name} ${Chalk.Dim}${duration}${Chalk.Reset}`;
|
|
111
|
+
},
|
|
112
|
+
log: (log) => {
|
|
113
|
+
const color = { info: Chalk.DarkGray, warning: Chalk.Orange, error: Chalk.Red }[log.level];
|
|
114
|
+
const level = { info: '●', warning: 'o', error: 'x' }[log.level];
|
|
115
|
+
const date = $Date.format(new Date(log.timestamp), '[YYYY-MM-DD hh:mm:ss]');
|
|
116
|
+
let message = $String.indent(log.message, 2).slice(2);
|
|
117
|
+
let attachments = '';
|
|
118
|
+
for (const [attachmentName, attachmentValue] of Object.entries(log.attachments)) {
|
|
119
|
+
message = message.replaceAll(`$[${attachmentName}]`, attachmentName);
|
|
120
|
+
attachments += `\n${attachmentName}: ${attachmentValue.value == null ? 'null' : attachmentValue.value === '' ? "" : attachmentValue.value}`;
|
|
121
|
+
}
|
|
122
|
+
return `${color}${level} ${date} ${message}${Chalk.Dim}${attachments ? $String.indent(attachments, 2) : ''}${Chalk.Reset}`;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const items = $Array.orderBy([...this.logs.map(log => ({ type: 'log', value: log })), ...this.tasks.map(task => ({ type: 'task', value: task }))], item => item.type === 'task' ? item.value.startTimestamp : item.value.timestamp);
|
|
126
|
+
let log = `${formatter.task(this)}\n`;
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
const entry = item.type === 'task' ? item.value.toConsoleLog() : formatter.log(item.value);
|
|
129
|
+
log += `${$String.indent(entry, 2)}\n`;
|
|
130
|
+
}
|
|
131
|
+
return log.trim();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Point } from './point';
|
|
2
|
+
export interface Line {
|
|
3
|
+
start: Point;
|
|
4
|
+
end: Point;
|
|
5
|
+
}
|
|
6
|
+
export declare class Line {
|
|
7
|
+
static contains(line: Line, point: Point): boolean;
|
|
8
|
+
static getMiddle(line: Line): Point;
|
|
9
|
+
static getIntersect(a: Line, b: Line): Point;
|
|
10
|
+
static equals(a: Line, b: Line): boolean;
|
|
11
|
+
static toString(line: Line): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { $Point } from './point';
|
|
2
|
+
export class Line {
|
|
3
|
+
static contains(line, point) {
|
|
4
|
+
const { x: x1, y: y1 } = line.start;
|
|
5
|
+
const { x: x2, y: y2 } = line.end;
|
|
6
|
+
const { x, y } = point;
|
|
7
|
+
// Check if the point is within the bounding box of the line segment
|
|
8
|
+
const withinBoundingBox = x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
|
|
9
|
+
if (!withinBoundingBox) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
// Check if the point satisfies the line equation
|
|
13
|
+
const slope = (y2 - y1) / (x2 - x1);
|
|
14
|
+
const equation = y - y1 === slope * (x - x1);
|
|
15
|
+
return equation;
|
|
16
|
+
}
|
|
17
|
+
static getMiddle(line) {
|
|
18
|
+
return {
|
|
19
|
+
x: (line.start.x + line.end.x) / 2,
|
|
20
|
+
y: (line.start.y + line.end.y) / 2,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
static getIntersect(a, b) {
|
|
24
|
+
const { x: x1, y: y1 } = a.start;
|
|
25
|
+
const { x: x2, y: y2 } = a.end;
|
|
26
|
+
const { x: x3, y: y3 } = b.start;
|
|
27
|
+
const { x: x4, y: y4 } = b.end;
|
|
28
|
+
const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
29
|
+
if (denom === 0) {
|
|
30
|
+
return null; // Lines are parallel or coincident
|
|
31
|
+
}
|
|
32
|
+
const ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
|
|
33
|
+
const ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
|
|
34
|
+
if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
|
|
35
|
+
// Intersection point lies within both line segments
|
|
36
|
+
const x = x1 + ua * (x2 - x1);
|
|
37
|
+
const y = y1 + ua * (y2 - y1);
|
|
38
|
+
return $Point.create(x, y);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return null; // Intersection point is outside the line segments
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
static equals(a, b) {
|
|
45
|
+
return $Point.equals(a.start, b.start) && $Point.equals(a.end, b.end);
|
|
46
|
+
}
|
|
47
|
+
static toString(line) {
|
|
48
|
+
return `${line.start.toString()}${line.end.toString()}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Rect } from './rect';
|
|
2
|
+
export interface Point {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class $Point {
|
|
7
|
+
private static parse;
|
|
8
|
+
static create(): Point;
|
|
9
|
+
static create(value: number): Point;
|
|
10
|
+
static create(x: number, y: number): Point;
|
|
11
|
+
static create(point: Partial<Point>): Point;
|
|
12
|
+
static create(...args: [] | [number] | [number, number] | [Partial<Point>]): Point;
|
|
13
|
+
static plus(point: Point, value: number): Point;
|
|
14
|
+
static plus(point: Point, x: number, y: number): Point;
|
|
15
|
+
static plus(a: Point, b: Partial<Point>): Point;
|
|
16
|
+
static minus(point: Point, value: number): Point;
|
|
17
|
+
static minus(point: Point, x: number, y: number): Point;
|
|
18
|
+
static minus(a: Point, b: Partial<Point>): Point;
|
|
19
|
+
static times(point: Point, value: number): Point;
|
|
20
|
+
static times(point: Point, x: number, y: number): Point;
|
|
21
|
+
static times(a: Point, b: Partial<Point>): Point;
|
|
22
|
+
static divide(point: Point, value: number): Point;
|
|
23
|
+
static divide(point: Point, x: number, y: number): Point;
|
|
24
|
+
static divide(a: Point, b: Partial<Point>): Point;
|
|
25
|
+
static distance({ x: x1, y: y1 }: Point, { x: x2, y: y2 }?: Point): number;
|
|
26
|
+
static isPointInCircle({ x, y, r }: Point & {
|
|
27
|
+
r: number;
|
|
28
|
+
}, point: Point): boolean;
|
|
29
|
+
static isPointInRect(point: Point, rect: Rect): boolean;
|
|
30
|
+
static move(point: Point, length: number, radian?: number): Point;
|
|
31
|
+
static equals(a: Point, b: Point): boolean;
|
|
32
|
+
static snap({ x, y }: Point, snap: number): Point;
|
|
33
|
+
static toString(value: Point): string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { $Number } from '../number/number.util';
|
|
2
|
+
import { $Object } from '../object/object.util';
|
|
3
|
+
export class $Point {
|
|
4
|
+
static parse(...args) {
|
|
5
|
+
return $Point.create(...args);
|
|
6
|
+
}
|
|
7
|
+
static create(...args) {
|
|
8
|
+
let value;
|
|
9
|
+
if (args.length === 0) {
|
|
10
|
+
value = { x: 0, y: 0 };
|
|
11
|
+
}
|
|
12
|
+
else if (args.length === 1) {
|
|
13
|
+
if (typeof args[0] === 'number') {
|
|
14
|
+
value = { x: args[0], y: args[0] };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
value = $Object.getDefaults(args[0], { x: 0, y: 0 });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
value = { x: args[0], y: args[1] };
|
|
22
|
+
}
|
|
23
|
+
return { x: value.x, y: value.y };
|
|
24
|
+
}
|
|
25
|
+
static plus(...params) {
|
|
26
|
+
const value = $Point.parse(...params.slice(1));
|
|
27
|
+
return {
|
|
28
|
+
x: params[0].x + value.x, y: params[0].y + value.y
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static minus(...params) {
|
|
32
|
+
const value = $Point.parse(...params.slice(1));
|
|
33
|
+
return {
|
|
34
|
+
x: params[0].x - value.x, y: params[0].y - value.y
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
static times(...params) {
|
|
38
|
+
const value = $Point.parse(...params.slice(1));
|
|
39
|
+
return { x: params[0].x * value.x, y: params[0].y * value.y };
|
|
40
|
+
}
|
|
41
|
+
static divide(...params) {
|
|
42
|
+
const value = $Point.parse(...params.slice(1));
|
|
43
|
+
return { x: params[0].x / value.x, y: params[0].y / value.y };
|
|
44
|
+
}
|
|
45
|
+
static distance({ x: x1, y: y1 }, { x: x2, y: y2 } = $Point.create()) {
|
|
46
|
+
const x = x1 - x2;
|
|
47
|
+
const y = y1 - y2;
|
|
48
|
+
return Math.sqrt(x * x + y * y);
|
|
49
|
+
}
|
|
50
|
+
static isPointInCircle({ x, y, r }, point) {
|
|
51
|
+
return $Point.distance($Point.parse(x, y), point) < r;
|
|
52
|
+
}
|
|
53
|
+
static isPointInRect(point, rect) {
|
|
54
|
+
return rect.x <= point.x && point.x <= rect.x + rect.width && rect.y <= point.y && point.y <= rect.y + rect.height;
|
|
55
|
+
}
|
|
56
|
+
static move(point, length, radian = 0) {
|
|
57
|
+
return $Point.create({
|
|
58
|
+
x: point.x + length * Math.cos(radian),
|
|
59
|
+
y: point.y + length * Math.sin(radian),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
static equals(a, b) {
|
|
63
|
+
return a === b || (a?.x === b?.x && a?.y === b?.y);
|
|
64
|
+
}
|
|
65
|
+
static snap({ x, y }, snap) {
|
|
66
|
+
return { x: $Number.snap(x, snap), y: $Number.snap(y, snap) };
|
|
67
|
+
}
|
|
68
|
+
static toString(value) {
|
|
69
|
+
return `(${value.x}, ${value.y})`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Line } from './line';
|
|
2
|
+
import { type Point } from './point';
|
|
3
|
+
export type PolygonIntersection = {
|
|
4
|
+
polygonA: Polygon;
|
|
5
|
+
polygonB: Polygon;
|
|
6
|
+
edgeIndexA: number;
|
|
7
|
+
edgeIndexB: number;
|
|
8
|
+
edgeA: Line;
|
|
9
|
+
edgeB: Line;
|
|
10
|
+
point: Point;
|
|
11
|
+
};
|
|
12
|
+
export declare class Polygon {
|
|
13
|
+
readonly vertices: Point[];
|
|
14
|
+
constructor(vertices: Point[]);
|
|
15
|
+
static getEdge(polygon: Polygon, index: number): Line;
|
|
16
|
+
getEdge(index: number): Line;
|
|
17
|
+
static getEdges(polygon: Polygon): Line[];
|
|
18
|
+
getEdges(): Line[];
|
|
19
|
+
static containsPoint(polygon: Polygon, point: Point): boolean;
|
|
20
|
+
containsPoint(point: Point): boolean;
|
|
21
|
+
static move(polygon: Polygon, position: Point): Polygon;
|
|
22
|
+
move(position: Point): Polygon;
|
|
23
|
+
static getIntersections(a: Polygon, b: Polygon, unique?: boolean): {
|
|
24
|
+
intersections: PolygonIntersection[];
|
|
25
|
+
edges: Record<string, PolygonIntersection[]>;
|
|
26
|
+
points: Record<string, PolygonIntersection>;
|
|
27
|
+
};
|
|
28
|
+
getIntersections(polygon: Polygon, unique?: boolean): {
|
|
29
|
+
intersections: PolygonIntersection[];
|
|
30
|
+
edges: Record<string, PolygonIntersection[]>;
|
|
31
|
+
points: Record<string, PolygonIntersection>;
|
|
32
|
+
};
|
|
33
|
+
static getLineIntersections(polygon: Polygon, line: Line): {
|
|
34
|
+
edgeIndex: number;
|
|
35
|
+
edge: Line;
|
|
36
|
+
point: Point;
|
|
37
|
+
}[];
|
|
38
|
+
getLineIntersections(polygon: Polygon, line: Line): {
|
|
39
|
+
edgeIndex: number;
|
|
40
|
+
edge: Line;
|
|
41
|
+
point: Point;
|
|
42
|
+
}[];
|
|
43
|
+
static subtract(a: Polygon, b: Polygon): Polygon[];
|
|
44
|
+
subtract(polygon: Polygon): Polygon[];
|
|
45
|
+
}
|