@contember/utilities 2.1.0-alpha.36 → 2.1.0-alpha.39
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/development/index.cjs +17 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +17 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/assert-types/assertNever.cjs +7 -0
- package/dist/development/src/assert-types/assertNever.cjs.map +1 -0
- package/dist/development/src/assert-types/assertNever.js +7 -0
- package/dist/development/src/assert-types/assertNever.js.map +1 -0
- package/dist/development/src/deprecate/deprecate.cjs +20 -0
- package/dist/development/src/deprecate/deprecate.cjs.map +1 -0
- package/dist/development/src/deprecate/deprecate.js +20 -0
- package/dist/development/src/deprecate/deprecate.js.map +1 -0
- package/dist/development/src/dom/dataAttribute.cjs +13 -0
- package/dist/development/src/dom/dataAttribute.cjs.map +1 -0
- package/dist/development/src/dom/dataAttribute.js +13 -0
- package/dist/development/src/dom/dataAttribute.js.map +1 -0
- package/dist/development/src/dom/svgSizeProps.cjs +15 -0
- package/dist/development/src/dom/svgSizeProps.cjs.map +1 -0
- package/dist/development/src/dom/svgSizeProps.js +15 -0
- package/dist/development/src/dom/svgSizeProps.js.map +1 -0
- package/dist/development/src/structures/BijectiveIndexedMap.cjs +133 -0
- package/dist/development/src/structures/BijectiveIndexedMap.cjs.map +1 -0
- package/dist/development/src/structures/BijectiveIndexedMap.js +133 -0
- package/dist/development/src/structures/BijectiveIndexedMap.js.map +1 -0
- package/dist/development/src/structures/LRUCache.cjs +32 -0
- package/dist/development/src/structures/LRUCache.cjs.map +1 -0
- package/dist/development/src/structures/LRUCache.js +32 -0
- package/dist/development/src/structures/LRUCache.js.map +1 -0
- package/dist/development/src/structures/WeakIdCache.cjs +30 -0
- package/dist/development/src/structures/WeakIdCache.cjs.map +1 -0
- package/dist/development/src/structures/WeakIdCache.js +30 -0
- package/dist/development/src/structures/WeakIdCache.js.map +1 -0
- package/dist/production/index.cjs +17 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +17 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/assert-types/assertNever.cjs +7 -0
- package/dist/production/src/assert-types/assertNever.cjs.map +1 -0
- package/dist/production/src/assert-types/assertNever.js +7 -0
- package/dist/production/src/assert-types/assertNever.js.map +1 -0
- package/dist/production/src/deprecate/deprecate.cjs +6 -0
- package/dist/production/src/deprecate/deprecate.cjs.map +1 -0
- package/dist/production/src/deprecate/deprecate.js +6 -0
- package/dist/production/src/deprecate/deprecate.js.map +1 -0
- package/dist/production/src/dom/dataAttribute.cjs +13 -0
- package/dist/production/src/dom/dataAttribute.cjs.map +1 -0
- package/dist/production/src/dom/dataAttribute.js +13 -0
- package/dist/production/src/dom/dataAttribute.js.map +1 -0
- package/dist/production/src/dom/svgSizeProps.cjs +15 -0
- package/dist/production/src/dom/svgSizeProps.cjs.map +1 -0
- package/dist/production/src/dom/svgSizeProps.js +15 -0
- package/dist/production/src/dom/svgSizeProps.js.map +1 -0
- package/dist/production/src/structures/BijectiveIndexedMap.cjs +133 -0
- package/dist/production/src/structures/BijectiveIndexedMap.cjs.map +1 -0
- package/dist/production/src/structures/BijectiveIndexedMap.js +133 -0
- package/dist/production/src/structures/BijectiveIndexedMap.js.map +1 -0
- package/dist/production/src/structures/LRUCache.cjs +32 -0
- package/dist/production/src/structures/LRUCache.cjs.map +1 -0
- package/dist/production/src/structures/LRUCache.js +32 -0
- package/dist/production/src/structures/LRUCache.js.map +1 -0
- package/dist/production/src/structures/WeakIdCache.cjs +30 -0
- package/dist/production/src/structures/WeakIdCache.cjs.map +1 -0
- package/dist/production/src/structures/WeakIdCache.js +30 -0
- package/dist/production/src/structures/WeakIdCache.js.map +1 -0
- package/dist/types/assert-types/assertNever.d.ts +2 -0
- package/dist/types/assert-types/assertNever.d.ts.map +1 -0
- package/dist/types/assert-types/index.d.ts +2 -0
- package/dist/types/assert-types/index.d.ts.map +1 -0
- package/dist/types/deprecate/deprecate.d.ts +19 -0
- package/dist/types/deprecate/deprecate.d.ts.map +1 -0
- package/dist/types/deprecate/index.d.ts +3 -0
- package/dist/types/deprecate/index.d.ts.map +1 -0
- package/dist/types/deprecate/types.d.ts +2 -0
- package/dist/types/deprecate/types.d.ts.map +1 -0
- package/dist/types/dom/dataAttribute.d.ts +4 -0
- package/dist/types/dom/dataAttribute.d.ts.map +1 -0
- package/dist/types/dom/index.d.ts +3 -0
- package/dist/types/dom/index.d.ts.map +1 -0
- package/dist/types/dom/svgSizeProps.d.ts +7 -0
- package/dist/types/dom/svgSizeProps.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/structures/BijectiveIndexedMap.d.ts +26 -0
- package/dist/types/structures/BijectiveIndexedMap.d.ts.map +1 -0
- package/dist/types/structures/LRUCache.d.ts +9 -0
- package/dist/types/structures/LRUCache.d.ts.map +1 -0
- package/dist/types/structures/WeakIdCache.d.ts +9 -0
- package/dist/types/structures/WeakIdCache.d.ts.map +1 -0
- package/dist/types/structures/index.d.ts +4 -0
- package/dist/types/structures/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/Narrow.d.ts +10 -0
- package/dist/types/types/Narrow.d.ts.map +1 -0
- package/dist/types/types/NonOptional.d.ts +8 -0
- package/dist/types/types/NonOptional.d.ts.map +1 -0
- package/dist/types/types/Partial.d.ts +3 -0
- package/dist/types/types/Partial.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const BijectiveIndexedMap = require("./src/structures/BijectiveIndexedMap.cjs");
|
|
4
|
+
const LRUCache = require("./src/structures/LRUCache.cjs");
|
|
5
|
+
const WeakIdCache = require("./src/structures/WeakIdCache.cjs");
|
|
6
|
+
const assertNever = require("./src/assert-types/assertNever.cjs");
|
|
7
|
+
const dataAttribute = require("./src/dom/dataAttribute.cjs");
|
|
8
|
+
const deprecate = require("./src/deprecate/deprecate.cjs");
|
|
9
|
+
const svgSizeProps = require("./src/dom/svgSizeProps.cjs");
|
|
10
|
+
exports.BijectiveIndexedMap = BijectiveIndexedMap.BijectiveIndexedMap;
|
|
11
|
+
exports.LRUCache = LRUCache.LRUCache;
|
|
12
|
+
exports.WeakIdCache = WeakIdCache.WeakIdCache;
|
|
13
|
+
exports.assertNever = assertNever.assertNever;
|
|
14
|
+
exports.dataAttribute = dataAttribute.dataAttribute;
|
|
15
|
+
exports.deprecate = deprecate.deprecate;
|
|
16
|
+
exports.svgSizeProps = svgSizeProps.svgSizeProps;
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BijectiveIndexedMap } from "./src/structures/BijectiveIndexedMap.js";
|
|
2
|
+
import { LRUCache } from "./src/structures/LRUCache.js";
|
|
3
|
+
import { WeakIdCache } from "./src/structures/WeakIdCache.js";
|
|
4
|
+
import { assertNever } from "./src/assert-types/assertNever.js";
|
|
5
|
+
import { dataAttribute } from "./src/dom/dataAttribute.js";
|
|
6
|
+
import { deprecate } from "./src/deprecate/deprecate.js";
|
|
7
|
+
import { svgSizeProps } from "./src/dom/svgSizeProps.js";
|
|
8
|
+
export {
|
|
9
|
+
BijectiveIndexedMap,
|
|
10
|
+
LRUCache,
|
|
11
|
+
WeakIdCache,
|
|
12
|
+
assertNever,
|
|
13
|
+
dataAttribute,
|
|
14
|
+
deprecate,
|
|
15
|
+
svgSizeProps
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function assertNever(_) {
|
|
4
|
+
throw new Error("Exhaustive Error: This line should never be reached.");
|
|
5
|
+
}
|
|
6
|
+
exports.assertNever = assertNever;
|
|
7
|
+
//# sourceMappingURL=assertNever.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertNever.cjs","sources":["../../../../../packages/utilities/src/assert-types/assertNever.ts"],"sourcesContent":["export function assertNever(_: never): never {\n\tthrow new Error('Exhaustive Error: This line should never be reached.')\n}\n"],"names":[],"mappings":";;AAAO,SAAS,YAAY,GAAiB;AAC5C,QAAM,IAAI,MAAM,sDAAsD;AACvE;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertNever.js","sources":["../../../../../packages/utilities/src/assert-types/assertNever.ts"],"sourcesContent":["export function assertNever(_: never): never {\n\tthrow new Error('Exhaustive Error: This line should never be reached.')\n}\n"],"names":[],"mappings":"AAAO,SAAS,YAAY,GAAiB;AAC5C,QAAM,IAAI,MAAM,sDAAsD;AACvE;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function deprecate(removal, condition, deprecated, replacement) {
|
|
4
|
+
if (condition === true) {
|
|
5
|
+
{
|
|
6
|
+
const shouldThrow = Boolean(void 0);
|
|
7
|
+
if (shouldThrow) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
`Support for ${deprecated} was planned to be removed in the ${removal} release.${replacement ? ` Replace it with ${replacement} instead.` : "Remove it."}`
|
|
10
|
+
);
|
|
11
|
+
} else {
|
|
12
|
+
console.warn(
|
|
13
|
+
`Use of ${deprecated} is deprecated and might be removed in the next release.${replacement ? ` Use ${replacement} instead.` : " There is no replacement."}`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.deprecate = deprecate;
|
|
20
|
+
//# sourceMappingURL=deprecate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate.cjs","sources":["../../../../../packages/utilities/src/deprecate/deprecate.ts"],"sourcesContent":["import { SemverString } from './types'\n\n/**\n * Logs a deprecation warning if the assertion is `false`.\n * @internal\n *\n * @param removal - Version when the deprecated feature will be removed\n * @param condition - Condition under which the deprecation warning will be logged\n * @param deprecated - Name of the deprecated feature\n * @param replacement - Name of the feature that replaces the deprecated feature\n *\n * @example\n * ```ts\n * const { visible } = props\n * deprecate(visible !== 'default', '1.3.0', '\"default\"', '\"hidden\"')\n * // Logs: Use of \"default\" is deprecated and might be removed in the next release. Use \"hidden\" instead.\n * ```\n */\nexport function deprecate(removal: SemverString, condition: boolean, deprecated: string, replacement: string | null): void {\n\tif (condition === true) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst shouldThrow = Boolean(import.meta.env.VITE_CONTEMBER_ADMIN_STRICT_DEPRECATIONS)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Support for ${deprecated} was planned to be removed in the ${removal} release.${\n\t\t\t\t\t\treplacement ? ` Replace it with ${replacement} instead.` : 'Remove it.'\n\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Use of ${deprecated} is deprecated and might be removed in the next release.${\n\t\t\t\t\t\treplacement ? ` Use ${replacement} instead.` : ' There is no replacement.'\n\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAkBO,SAAS,UAAU,SAAuB,WAAoB,YAAoB,aAAkC;AAC1H,MAAI,cAAc,MAAM;AACE;AACxB,YAAM,cAAc,QAAQ,MAAA;AAE5B,UAAI,aAAa;AAChB,cAAM,IAAI;AAAA,UACT,eAAe,UAAU,qCAAqC,OAAO,YACpE,cAAc,oBAAoB,WAAW,cAAc,YAC5D;AAAA,QAAA;AAAA,MAEF,OAAO;AACN,gBAAQ;AAAA,UACP,UAAU,UAAU,2DACnB,cAAc,QAAQ,WAAW,cAAc,2BAChD;AAAA,QAAA;AAAA,MAEF;AAAA,IACD;AAAA,EACD;AACD;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function deprecate(removal, condition, deprecated, replacement) {
|
|
2
|
+
if (condition === true) {
|
|
3
|
+
{
|
|
4
|
+
const shouldThrow = Boolean(void 0);
|
|
5
|
+
if (shouldThrow) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
`Support for ${deprecated} was planned to be removed in the ${removal} release.${replacement ? ` Replace it with ${replacement} instead.` : "Remove it."}`
|
|
8
|
+
);
|
|
9
|
+
} else {
|
|
10
|
+
console.warn(
|
|
11
|
+
`Use of ${deprecated} is deprecated and might be removed in the next release.${replacement ? ` Use ${replacement} instead.` : " There is no replacement."}`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
deprecate
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=deprecate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate.js","sources":["../../../../../packages/utilities/src/deprecate/deprecate.ts"],"sourcesContent":["import { SemverString } from './types'\n\n/**\n * Logs a deprecation warning if the assertion is `false`.\n * @internal\n *\n * @param removal - Version when the deprecated feature will be removed\n * @param condition - Condition under which the deprecation warning will be logged\n * @param deprecated - Name of the deprecated feature\n * @param replacement - Name of the feature that replaces the deprecated feature\n *\n * @example\n * ```ts\n * const { visible } = props\n * deprecate(visible !== 'default', '1.3.0', '\"default\"', '\"hidden\"')\n * // Logs: Use of \"default\" is deprecated and might be removed in the next release. Use \"hidden\" instead.\n * ```\n */\nexport function deprecate(removal: SemverString, condition: boolean, deprecated: string, replacement: string | null): void {\n\tif (condition === true) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst shouldThrow = Boolean(import.meta.env.VITE_CONTEMBER_ADMIN_STRICT_DEPRECATIONS)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Support for ${deprecated} was planned to be removed in the ${removal} release.${\n\t\t\t\t\t\treplacement ? ` Replace it with ${replacement} instead.` : 'Remove it.'\n\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Use of ${deprecated} is deprecated and might be removed in the next release.${\n\t\t\t\t\t\treplacement ? ` Use ${replacement} instead.` : ' There is no replacement.'\n\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAkBO,SAAS,UAAU,SAAuB,WAAoB,YAAoB,aAAkC;AAC1H,MAAI,cAAc,MAAM;AACE;AACxB,YAAM,cAAc,QAAQ,MAAA;AAE5B,UAAI,aAAa;AAChB,cAAM,IAAI;AAAA,UACT,eAAe,UAAU,qCAAqC,OAAO,YACpE,cAAc,oBAAoB,WAAW,cAAc,YAC5D;AAAA,QAAA;AAAA,MAEF,OAAO;AACN,gBAAQ;AAAA,UACP,UAAU,UAAU,2DACnB,cAAc,QAAQ,WAAW,cAAc,2BAChD;AAAA,QAAA;AAAA,MAEF;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function dataAttribute(value) {
|
|
4
|
+
if (value === false || value === void 0 || value === null) {
|
|
5
|
+
return void 0;
|
|
6
|
+
} else if (value === true) {
|
|
7
|
+
return "";
|
|
8
|
+
} else {
|
|
9
|
+
return String(value);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.dataAttribute = dataAttribute;
|
|
13
|
+
//# sourceMappingURL=dataAttribute.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataAttribute.cjs","sources":["../../../../../packages/utilities/src/dom/dataAttribute.ts"],"sourcesContent":["export function dataAttribute(value: boolean | null | undefined): '' | undefined\nexport function dataAttribute<const T extends string>(value: T): T\nexport function dataAttribute(value: boolean | string | number | undefined | null): string | undefined\nexport function dataAttribute(value: unknown): string | true | undefined {\n\tif (value === false || value === undefined || value === null) {\n\t\treturn undefined\n\t} else if (value === true) {\n\t\t// Closest to HTML: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n\t\t// React issue: https://github.com/facebook/react/issues/24812\n\t\treturn ''\n\t} else {\n\t\treturn String(value)\n\t}\n}\n"],"names":[],"mappings":";;AAGO,SAAS,cAAc,OAA2C;AACxE,MAAI,UAAU,SAAS,UAAU,UAAa,UAAU,MAAM;AAC7D,WAAO;AAAA,EACR,WAAW,UAAU,MAAM;AAG1B,WAAO;AAAA,EACR,OAAO;AACN,WAAO,OAAO,KAAK;AAAA,EACpB;AACD;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function dataAttribute(value) {
|
|
2
|
+
if (value === false || value === void 0 || value === null) {
|
|
3
|
+
return void 0;
|
|
4
|
+
} else if (value === true) {
|
|
5
|
+
return "";
|
|
6
|
+
} else {
|
|
7
|
+
return String(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
dataAttribute
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=dataAttribute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataAttribute.js","sources":["../../../../../packages/utilities/src/dom/dataAttribute.ts"],"sourcesContent":["export function dataAttribute(value: boolean | null | undefined): '' | undefined\nexport function dataAttribute<const T extends string>(value: T): T\nexport function dataAttribute(value: boolean | string | number | undefined | null): string | undefined\nexport function dataAttribute(value: unknown): string | true | undefined {\n\tif (value === false || value === undefined || value === null) {\n\t\treturn undefined\n\t} else if (value === true) {\n\t\t// Closest to HTML: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n\t\t// React issue: https://github.com/facebook/react/issues/24812\n\t\treturn ''\n\t} else {\n\t\treturn String(value)\n\t}\n}\n"],"names":[],"mappings":"AAGO,SAAS,cAAc,OAA2C;AACxE,MAAI,UAAU,SAAS,UAAU,UAAa,UAAU,MAAM;AAC7D,WAAO;AAAA,EACR,WAAW,UAAU,MAAM;AAG1B,WAAO;AAAA,EACR,OAAO;AACN,WAAO,OAAO,KAAK;AAAA,EACpB;AACD;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function svgSizeProps(width, height, crop = 0) {
|
|
4
|
+
const viewBoxWidth = width - crop * 2;
|
|
5
|
+
const viewBoxHeight = (height ?? width) - crop * 2;
|
|
6
|
+
const viewBoxX = crop;
|
|
7
|
+
const viewBoxY = crop;
|
|
8
|
+
return {
|
|
9
|
+
width: viewBoxWidth,
|
|
10
|
+
height: viewBoxHeight,
|
|
11
|
+
viewBox: `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.svgSizeProps = svgSizeProps;
|
|
15
|
+
//# sourceMappingURL=svgSizeProps.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svgSizeProps.cjs","sources":["../../../../../packages/utilities/src/dom/svgSizeProps.ts"],"sourcesContent":["export interface SvgSizeProps {\n\twidth: number\n\theight: number\n\tviewBox: string\n}\n\nexport function svgSizeProps(\n\twidth: number,\n\theight?: number,\n\tcrop: number = 0,\n): SvgSizeProps {\n\tconst viewBoxWidth = width - crop * 2\n\tconst viewBoxHeight = (height ?? width) - crop * 2\n\tconst viewBoxX = crop\n\tconst viewBoxY = crop\n\treturn {\n\t\twidth: viewBoxWidth,\n\t\theight: viewBoxHeight,\n\t\tviewBox: `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`,\n\t}\n}\n"],"names":[],"mappings":";;AAMO,SAAS,aACf,OACA,QACA,OAAe,GACA;AACf,QAAM,eAAe,QAAQ,OAAO;AACpC,QAAM,iBAAiB,UAAU,SAAS,OAAO;AACjD,QAAM,WAAW;AACjB,QAAM,WAAW;AACjB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS,GAAG,QAAQ,IAAI,QAAQ,IAAI,YAAY,IAAI,aAAa;AAAA,EAAA;AAEnE;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function svgSizeProps(width, height, crop = 0) {
|
|
2
|
+
const viewBoxWidth = width - crop * 2;
|
|
3
|
+
const viewBoxHeight = (height ?? width) - crop * 2;
|
|
4
|
+
const viewBoxX = crop;
|
|
5
|
+
const viewBoxY = crop;
|
|
6
|
+
return {
|
|
7
|
+
width: viewBoxWidth,
|
|
8
|
+
height: viewBoxHeight,
|
|
9
|
+
viewBox: `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
svgSizeProps
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=svgSizeProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svgSizeProps.js","sources":["../../../../../packages/utilities/src/dom/svgSizeProps.ts"],"sourcesContent":["export interface SvgSizeProps {\n\twidth: number\n\theight: number\n\tviewBox: string\n}\n\nexport function svgSizeProps(\n\twidth: number,\n\theight?: number,\n\tcrop: number = 0,\n): SvgSizeProps {\n\tconst viewBoxWidth = width - crop * 2\n\tconst viewBoxHeight = (height ?? width) - crop * 2\n\tconst viewBoxX = crop\n\tconst viewBoxY = crop\n\treturn {\n\t\twidth: viewBoxWidth,\n\t\theight: viewBoxHeight,\n\t\tviewBox: `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`,\n\t}\n}\n"],"names":[],"mappings":"AAMO,SAAS,aACf,OACA,QACA,OAAe,GACA;AACf,QAAM,eAAe,QAAQ,OAAO;AACpC,QAAM,iBAAiB,UAAU,SAAS,OAAO;AACjD,QAAM,WAAW;AACjB,QAAM,WAAW;AACjB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS,GAAG,QAAQ,IAAI,QAAQ,IAAI,YAAY,IAAI,aAAa;AAAA,EAAA;AAEnE;"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
var _a;
|
|
7
|
+
class BijectiveIndexedMap {
|
|
8
|
+
constructor(inverseOrMap) {
|
|
9
|
+
__publicField(this, "valueStore");
|
|
10
|
+
__publicField(this, "index");
|
|
11
|
+
__publicField(this, "indexSeed");
|
|
12
|
+
__publicField(this, "inverse");
|
|
13
|
+
__publicField(this, _a, "BijectiveIndexedMap");
|
|
14
|
+
if (inverseOrMap instanceof BijectiveIndexedMap) {
|
|
15
|
+
this.valueStore = new Map(inverseOrMap.valueStore);
|
|
16
|
+
this.index = new Map(inverseOrMap.index);
|
|
17
|
+
this.indexSeed = inverseOrMap.indexSeed;
|
|
18
|
+
this.inverse = inverseOrMap.inverse;
|
|
19
|
+
} else {
|
|
20
|
+
this.valueStore = /* @__PURE__ */ new Map();
|
|
21
|
+
this.index = /* @__PURE__ */ new Map();
|
|
22
|
+
this.indexSeed = 0;
|
|
23
|
+
this.inverse = inverseOrMap;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getNewIndex() {
|
|
27
|
+
return this.indexSeed++;
|
|
28
|
+
}
|
|
29
|
+
get size() {
|
|
30
|
+
return this.valueStore.size;
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.valueStore.clear();
|
|
34
|
+
this.index.clear();
|
|
35
|
+
}
|
|
36
|
+
delete(key) {
|
|
37
|
+
const index = this.index.get(key);
|
|
38
|
+
if (index === void 0) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
this.valueStore.delete(index);
|
|
42
|
+
this.index.delete(key);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
forEach(callback, thisArg) {
|
|
46
|
+
for (const [key, value] of this.entries()) {
|
|
47
|
+
callback.call(thisArg, value, key, this);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
get(key) {
|
|
51
|
+
const index = this.index.get(key);
|
|
52
|
+
if (index === void 0) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
return this.valueStore.get(index);
|
|
56
|
+
}
|
|
57
|
+
has(key) {
|
|
58
|
+
return this.index.has(key);
|
|
59
|
+
}
|
|
60
|
+
getOrInsert(key, defaultValue) {
|
|
61
|
+
const existing = this.get(key);
|
|
62
|
+
if (existing !== void 0) {
|
|
63
|
+
return existing;
|
|
64
|
+
}
|
|
65
|
+
this.set(key, defaultValue);
|
|
66
|
+
return defaultValue;
|
|
67
|
+
}
|
|
68
|
+
getOrInsertComputed(key, callback) {
|
|
69
|
+
const existing = this.get(key);
|
|
70
|
+
if (existing !== void 0) {
|
|
71
|
+
return existing;
|
|
72
|
+
}
|
|
73
|
+
const value = callback(key);
|
|
74
|
+
this.set(key, value);
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
set(key, value) {
|
|
78
|
+
const existingIndex = this.index.get(key);
|
|
79
|
+
if (existingIndex === void 0) {
|
|
80
|
+
const newIndex = this.getNewIndex();
|
|
81
|
+
this.index.set(key, newIndex);
|
|
82
|
+
this.valueStore.set(newIndex, value);
|
|
83
|
+
} else {
|
|
84
|
+
this.valueStore.set(existingIndex, value);
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
// This doesn't use the inverse in order to avoid confusion.
|
|
89
|
+
// See the description above.
|
|
90
|
+
changeKey(oldKey, newKey) {
|
|
91
|
+
const index = this.index.get(oldKey);
|
|
92
|
+
if (index === void 0) {
|
|
93
|
+
throw new Error();
|
|
94
|
+
}
|
|
95
|
+
this.index.delete(oldKey);
|
|
96
|
+
this.index.set(newKey, index);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
changeKeyOrder(newOrder) {
|
|
100
|
+
for (const key of newOrder) {
|
|
101
|
+
const keyIndex = this.index.get(key);
|
|
102
|
+
if (keyIndex === void 0) {
|
|
103
|
+
throw new Error();
|
|
104
|
+
}
|
|
105
|
+
const value = this.valueStore.get(keyIndex);
|
|
106
|
+
this.valueStore.delete(keyIndex);
|
|
107
|
+
this.valueStore.set(keyIndex, value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
*[(_a = Symbol.toStringTag, Symbol.iterator)]() {
|
|
111
|
+
yield* this.entries();
|
|
112
|
+
}
|
|
113
|
+
*entries() {
|
|
114
|
+
for (const value of this.values()) {
|
|
115
|
+
yield [this.inverse(value), value];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
*keys() {
|
|
119
|
+
for (const value of this.values()) {
|
|
120
|
+
yield this.inverse(value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
*values() {
|
|
124
|
+
for (const value of this.valueStore.values()) {
|
|
125
|
+
if (value === void 0) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
yield value;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.BijectiveIndexedMap = BijectiveIndexedMap;
|
|
133
|
+
//# sourceMappingURL=BijectiveIndexedMap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BijectiveIndexedMap.cjs","sources":["../../../../../packages/utilities/src/structures/BijectiveIndexedMap.ts"],"sourcesContent":["// Bijective as in we need to supply the inverse and also guarantee that the values are unique.\n// Provided this invariant, this should behave more or less like a regular map except it has a somewhat special\n// iteration order. Unlike a regular map, which just honors insertion order, this also provides a special method\n// changeKey. With this, we can change the key under which a value (that is already on the map) is accessible.\n// With an ordinary map, that operation would require us to delete the original [K1, V] pair and insert\n// a new one [K2, V]. That would however change the order of iteration. This main purpose of this data structure is\n// the ability to avoid that and enable the value V to preserve its original place.\nexport class BijectiveIndexedMap<K, V> implements Map<K, V> {\n\tprivate readonly valueStore: Map<number, V>\n\tprivate readonly index: Map<K, number>\n\tprivate indexSeed: number\n\n\tprivate readonly inverse: (value: V) => K\n\n\tpublic readonly [Symbol.toStringTag] = 'BijectiveIndexedMap'\n\n\tpublic constructor(originalMap: BijectiveIndexedMap<K, V>)\n\tpublic constructor(inverse: (value: V) => K)\n\tpublic constructor(inverseOrMap: BijectiveIndexedMap<K, V> | ((value: V) => K)) {\n\t\tif (inverseOrMap instanceof BijectiveIndexedMap) {\n\t\t\tthis.valueStore = new Map(inverseOrMap.valueStore)\n\t\t\tthis.index = new Map(inverseOrMap.index)\n\t\t\tthis.indexSeed = inverseOrMap.indexSeed\n\t\t\tthis.inverse = inverseOrMap.inverse\n\t\t} else {\n\t\t\tthis.valueStore = new Map()\n\t\t\tthis.index = new Map()\n\t\t\tthis.indexSeed = 0\n\t\t\tthis.inverse = inverseOrMap\n\t\t}\n\t}\n\n\tprivate getNewIndex() {\n\t\treturn this.indexSeed++\n\t}\n\n\tpublic get size(): number {\n\t\treturn this.valueStore.size\n\t}\n\n\tpublic clear(): void {\n\t\tthis.valueStore.clear()\n\t\tthis.index.clear()\n\t}\n\tpublic delete(key: K): boolean {\n\t\tconst index = this.index.get(key)\n\n\t\tif (index === undefined) {\n\t\t\treturn false\n\t\t}\n\t\tthis.valueStore.delete(index)\n\t\tthis.index.delete(key)\n\t\treturn true\n\t}\n\tpublic forEach(callback: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tfor (const [key, value] of this.entries()) {\n\t\t\tcallback.call(thisArg, value, key, this)\n\t\t}\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst index = this.index.get(key)\n\n\t\tif (index === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.valueStore.get(index)\n\t}\n\tpublic has(key: K): boolean {\n\t\treturn this.index.has(key)\n\t}\n\tpublic getOrInsert(key: K, defaultValue: V): V {\n\t\tconst existing = this.get(key)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\t\tthis.set(key, defaultValue)\n\t\treturn defaultValue\n\t}\n\n\tpublic getOrInsertComputed(key: K, callback: (key: K) => V): V {\n\t\tconst existing = this.get(key)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\t\tconst value = callback(key)\n\t\tthis.set(key, value)\n\t\treturn value\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tconst existingIndex = this.index.get(key)\n\n\t\tif (existingIndex === undefined) {\n\t\t\tconst newIndex = this.getNewIndex()\n\t\t\tthis.index.set(key, newIndex)\n\t\t\tthis.valueStore.set(newIndex, value)\n\t\t} else {\n\t\t\tthis.valueStore.set(existingIndex, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t// This doesn't use the inverse in order to avoid confusion.\n\t// See the description above.\n\tpublic changeKey(oldKey: K, newKey: K): this {\n\t\tconst index = this.index.get(oldKey)\n\t\tif (index === undefined) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.index.delete(oldKey)\n\t\tthis.index.set(newKey, index)\n\t\treturn this\n\t}\n\n\tpublic changeKeyOrder(newOrder: Iterable<K>) {\n\t\tfor (const key of newOrder) {\n\t\t\tconst keyIndex = this.index.get(key)\n\t\t\tif (keyIndex === undefined) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tconst value = this.valueStore.get(keyIndex)!\n\n\t\t\t// This effectively removes value from wherever it was and puts it at the end.\n\t\t\t// Provided newOrder.size is the same as valueStore, by the end of this loop\n\t\t\t// the values will be in the correct order.\n\t\t\tthis.valueStore.delete(keyIndex)\n\t\t\tthis.valueStore.set(keyIndex, value)\n\t\t}\n\t}\n\n\tpublic *[Symbol.iterator](): MapIterator<[K, V]> {\n\t\tyield* this.entries()\n\t}\n\n\tpublic *entries(): MapIterator<[K, V]> {\n\t\tfor (const value of this.values()) {\n\t\t\tyield [this.inverse(value), value]\n\t\t}\n\t}\n\n\tpublic *keys(): MapIterator<K> {\n\t\tfor (const value of this.values()) {\n\t\t\tyield this.inverse(value)\n\t\t}\n\t}\n\n\tpublic *values(): MapIterator<V> {\n\t\tfor (const value of this.valueStore.values()) {\n\t\t\tif (value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tyield value\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
var _a;
|
|
5
|
+
class BijectiveIndexedMap {
|
|
6
|
+
constructor(inverseOrMap) {
|
|
7
|
+
__publicField(this, "valueStore");
|
|
8
|
+
__publicField(this, "index");
|
|
9
|
+
__publicField(this, "indexSeed");
|
|
10
|
+
__publicField(this, "inverse");
|
|
11
|
+
__publicField(this, _a, "BijectiveIndexedMap");
|
|
12
|
+
if (inverseOrMap instanceof BijectiveIndexedMap) {
|
|
13
|
+
this.valueStore = new Map(inverseOrMap.valueStore);
|
|
14
|
+
this.index = new Map(inverseOrMap.index);
|
|
15
|
+
this.indexSeed = inverseOrMap.indexSeed;
|
|
16
|
+
this.inverse = inverseOrMap.inverse;
|
|
17
|
+
} else {
|
|
18
|
+
this.valueStore = /* @__PURE__ */ new Map();
|
|
19
|
+
this.index = /* @__PURE__ */ new Map();
|
|
20
|
+
this.indexSeed = 0;
|
|
21
|
+
this.inverse = inverseOrMap;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getNewIndex() {
|
|
25
|
+
return this.indexSeed++;
|
|
26
|
+
}
|
|
27
|
+
get size() {
|
|
28
|
+
return this.valueStore.size;
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
this.valueStore.clear();
|
|
32
|
+
this.index.clear();
|
|
33
|
+
}
|
|
34
|
+
delete(key) {
|
|
35
|
+
const index = this.index.get(key);
|
|
36
|
+
if (index === void 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
this.valueStore.delete(index);
|
|
40
|
+
this.index.delete(key);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
forEach(callback, thisArg) {
|
|
44
|
+
for (const [key, value] of this.entries()) {
|
|
45
|
+
callback.call(thisArg, value, key, this);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get(key) {
|
|
49
|
+
const index = this.index.get(key);
|
|
50
|
+
if (index === void 0) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
return this.valueStore.get(index);
|
|
54
|
+
}
|
|
55
|
+
has(key) {
|
|
56
|
+
return this.index.has(key);
|
|
57
|
+
}
|
|
58
|
+
getOrInsert(key, defaultValue) {
|
|
59
|
+
const existing = this.get(key);
|
|
60
|
+
if (existing !== void 0) {
|
|
61
|
+
return existing;
|
|
62
|
+
}
|
|
63
|
+
this.set(key, defaultValue);
|
|
64
|
+
return defaultValue;
|
|
65
|
+
}
|
|
66
|
+
getOrInsertComputed(key, callback) {
|
|
67
|
+
const existing = this.get(key);
|
|
68
|
+
if (existing !== void 0) {
|
|
69
|
+
return existing;
|
|
70
|
+
}
|
|
71
|
+
const value = callback(key);
|
|
72
|
+
this.set(key, value);
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
set(key, value) {
|
|
76
|
+
const existingIndex = this.index.get(key);
|
|
77
|
+
if (existingIndex === void 0) {
|
|
78
|
+
const newIndex = this.getNewIndex();
|
|
79
|
+
this.index.set(key, newIndex);
|
|
80
|
+
this.valueStore.set(newIndex, value);
|
|
81
|
+
} else {
|
|
82
|
+
this.valueStore.set(existingIndex, value);
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
// This doesn't use the inverse in order to avoid confusion.
|
|
87
|
+
// See the description above.
|
|
88
|
+
changeKey(oldKey, newKey) {
|
|
89
|
+
const index = this.index.get(oldKey);
|
|
90
|
+
if (index === void 0) {
|
|
91
|
+
throw new Error();
|
|
92
|
+
}
|
|
93
|
+
this.index.delete(oldKey);
|
|
94
|
+
this.index.set(newKey, index);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
changeKeyOrder(newOrder) {
|
|
98
|
+
for (const key of newOrder) {
|
|
99
|
+
const keyIndex = this.index.get(key);
|
|
100
|
+
if (keyIndex === void 0) {
|
|
101
|
+
throw new Error();
|
|
102
|
+
}
|
|
103
|
+
const value = this.valueStore.get(keyIndex);
|
|
104
|
+
this.valueStore.delete(keyIndex);
|
|
105
|
+
this.valueStore.set(keyIndex, value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
*[(_a = Symbol.toStringTag, Symbol.iterator)]() {
|
|
109
|
+
yield* this.entries();
|
|
110
|
+
}
|
|
111
|
+
*entries() {
|
|
112
|
+
for (const value of this.values()) {
|
|
113
|
+
yield [this.inverse(value), value];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
*keys() {
|
|
117
|
+
for (const value of this.values()) {
|
|
118
|
+
yield this.inverse(value);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
*values() {
|
|
122
|
+
for (const value of this.valueStore.values()) {
|
|
123
|
+
if (value === void 0) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
yield value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
BijectiveIndexedMap
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=BijectiveIndexedMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BijectiveIndexedMap.js","sources":["../../../../../packages/utilities/src/structures/BijectiveIndexedMap.ts"],"sourcesContent":["// Bijective as in we need to supply the inverse and also guarantee that the values are unique.\n// Provided this invariant, this should behave more or less like a regular map except it has a somewhat special\n// iteration order. Unlike a regular map, which just honors insertion order, this also provides a special method\n// changeKey. With this, we can change the key under which a value (that is already on the map) is accessible.\n// With an ordinary map, that operation would require us to delete the original [K1, V] pair and insert\n// a new one [K2, V]. That would however change the order of iteration. This main purpose of this data structure is\n// the ability to avoid that and enable the value V to preserve its original place.\nexport class BijectiveIndexedMap<K, V> implements Map<K, V> {\n\tprivate readonly valueStore: Map<number, V>\n\tprivate readonly index: Map<K, number>\n\tprivate indexSeed: number\n\n\tprivate readonly inverse: (value: V) => K\n\n\tpublic readonly [Symbol.toStringTag] = 'BijectiveIndexedMap'\n\n\tpublic constructor(originalMap: BijectiveIndexedMap<K, V>)\n\tpublic constructor(inverse: (value: V) => K)\n\tpublic constructor(inverseOrMap: BijectiveIndexedMap<K, V> | ((value: V) => K)) {\n\t\tif (inverseOrMap instanceof BijectiveIndexedMap) {\n\t\t\tthis.valueStore = new Map(inverseOrMap.valueStore)\n\t\t\tthis.index = new Map(inverseOrMap.index)\n\t\t\tthis.indexSeed = inverseOrMap.indexSeed\n\t\t\tthis.inverse = inverseOrMap.inverse\n\t\t} else {\n\t\t\tthis.valueStore = new Map()\n\t\t\tthis.index = new Map()\n\t\t\tthis.indexSeed = 0\n\t\t\tthis.inverse = inverseOrMap\n\t\t}\n\t}\n\n\tprivate getNewIndex() {\n\t\treturn this.indexSeed++\n\t}\n\n\tpublic get size(): number {\n\t\treturn this.valueStore.size\n\t}\n\n\tpublic clear(): void {\n\t\tthis.valueStore.clear()\n\t\tthis.index.clear()\n\t}\n\tpublic delete(key: K): boolean {\n\t\tconst index = this.index.get(key)\n\n\t\tif (index === undefined) {\n\t\t\treturn false\n\t\t}\n\t\tthis.valueStore.delete(index)\n\t\tthis.index.delete(key)\n\t\treturn true\n\t}\n\tpublic forEach(callback: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tfor (const [key, value] of this.entries()) {\n\t\t\tcallback.call(thisArg, value, key, this)\n\t\t}\n\t}\n\n\tpublic get(key: K): V | undefined {\n\t\tconst index = this.index.get(key)\n\n\t\tif (index === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.valueStore.get(index)\n\t}\n\tpublic has(key: K): boolean {\n\t\treturn this.index.has(key)\n\t}\n\tpublic getOrInsert(key: K, defaultValue: V): V {\n\t\tconst existing = this.get(key)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\t\tthis.set(key, defaultValue)\n\t\treturn defaultValue\n\t}\n\n\tpublic getOrInsertComputed(key: K, callback: (key: K) => V): V {\n\t\tconst existing = this.get(key)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\t\tconst value = callback(key)\n\t\tthis.set(key, value)\n\t\treturn value\n\t}\n\n\tpublic set(key: K, value: V): this {\n\t\tconst existingIndex = this.index.get(key)\n\n\t\tif (existingIndex === undefined) {\n\t\t\tconst newIndex = this.getNewIndex()\n\t\t\tthis.index.set(key, newIndex)\n\t\t\tthis.valueStore.set(newIndex, value)\n\t\t} else {\n\t\t\tthis.valueStore.set(existingIndex, value)\n\t\t}\n\t\treturn this\n\t}\n\n\t// This doesn't use the inverse in order to avoid confusion.\n\t// See the description above.\n\tpublic changeKey(oldKey: K, newKey: K): this {\n\t\tconst index = this.index.get(oldKey)\n\t\tif (index === undefined) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.index.delete(oldKey)\n\t\tthis.index.set(newKey, index)\n\t\treturn this\n\t}\n\n\tpublic changeKeyOrder(newOrder: Iterable<K>) {\n\t\tfor (const key of newOrder) {\n\t\t\tconst keyIndex = this.index.get(key)\n\t\t\tif (keyIndex === undefined) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tconst value = this.valueStore.get(keyIndex)!\n\n\t\t\t// This effectively removes value from wherever it was and puts it at the end.\n\t\t\t// Provided newOrder.size is the same as valueStore, by the end of this loop\n\t\t\t// the values will be in the correct order.\n\t\t\tthis.valueStore.delete(keyIndex)\n\t\t\tthis.valueStore.set(keyIndex, value)\n\t\t}\n\t}\n\n\tpublic *[Symbol.iterator](): MapIterator<[K, V]> {\n\t\tyield* this.entries()\n\t}\n\n\tpublic *entries(): MapIterator<[K, V]> {\n\t\tfor (const value of this.values()) {\n\t\t\tyield [this.inverse(value), value]\n\t\t}\n\t}\n\n\tpublic *keys(): MapIterator<K> {\n\t\tfor (const value of this.values()) {\n\t\t\tyield this.inverse(value)\n\t\t}\n\t}\n\n\tpublic *values(): MapIterator<V> {\n\t\tfor (const value of this.valueStore.values()) {\n\t\t\tif (value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tyield value\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
6
|
+
class LRUCache {
|
|
7
|
+
constructor(maxSize) {
|
|
8
|
+
this.maxSize = maxSize;
|
|
9
|
+
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
10
|
+
}
|
|
11
|
+
get(key) {
|
|
12
|
+
const value = this.cache.get(key);
|
|
13
|
+
if (value !== void 0) {
|
|
14
|
+
this.cache.delete(key);
|
|
15
|
+
this.cache.set(key, value);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
set(key, value) {
|
|
20
|
+
if (this.cache.has(key)) {
|
|
21
|
+
this.cache.delete(key);
|
|
22
|
+
} else if (this.cache.size === this.maxSize) {
|
|
23
|
+
this.cache.delete(this.getOldestKey());
|
|
24
|
+
}
|
|
25
|
+
this.cache.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
getOldestKey() {
|
|
28
|
+
return this.cache.keys().next().value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.LRUCache = LRUCache;
|
|
32
|
+
//# sourceMappingURL=LRUCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LRUCache.cjs","sources":["../../../../../packages/utilities/src/structures/LRUCache.ts"],"sourcesContent":["// This is heavily inspired by https://stackoverflow.com/a/46432113\nexport class LRUCache<Key, Value> {\n\tprivate readonly cache = new Map<Key, Value>()\n\n\tpublic constructor(private readonly maxSize: number) {}\n\n\tpublic get(key: Key): Value | undefined {\n\t\tconst value = this.cache.get(key)\n\n\t\tif (value !== undefined) {\n\t\t\tthis.cache.delete(key)\n\t\t\tthis.cache.set(key, value)\n\t\t}\n\t\treturn value\n\t}\n\n\tpublic set(key: Key, value: Value) {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key) // Refresh this key\n\t\t} else if (this.cache.size === this.maxSize) {\n\t\t\tthis.cache.delete(this.getOldestKey()) // Evict the oldest value\n\t\t}\n\t\tthis.cache.set(key, value)\n\t}\n\n\tprivate getOldestKey(): Key {\n\t\treturn this.cache.keys().next().value!\n\t}\n}\n"],"names":[],"mappings":";;;;;AACO,MAAM,SAAqB;AAAA,EAG1B,YAA6B,SAAiB;AAAjB,SAAA,UAAA;AAFpC,kBAAA,MAAiB,6BAAY,IAAA,CAAgB;AAAA,EAES;AAAA,EAE/C,IAAI,KAA6B;AACvC,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAEhC,QAAI,UAAU,QAAW;AACxB,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,MAAM,IAAI,KAAK,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEO,IAAI,KAAU,OAAc;AAClC,QAAI,KAAK,MAAM,IAAI,GAAG,GAAG;AACxB,WAAK,MAAM,OAAO,GAAG;AAAA,IACtB,WAAW,KAAK,MAAM,SAAS,KAAK,SAAS;AAC5C,WAAK,MAAM,OAAO,KAAK,aAAA,CAAc;AAAA,IACtC;AACA,SAAK,MAAM,IAAI,KAAK,KAAK;AAAA,EAC1B;AAAA,EAEQ,eAAoB;AAC3B,WAAO,KAAK,MAAM,KAAA,EAAO,OAAO;AAAA,EACjC;AACD;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
4
|
+
class LRUCache {
|
|
5
|
+
constructor(maxSize) {
|
|
6
|
+
this.maxSize = maxSize;
|
|
7
|
+
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
const value = this.cache.get(key);
|
|
11
|
+
if (value !== void 0) {
|
|
12
|
+
this.cache.delete(key);
|
|
13
|
+
this.cache.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
set(key, value) {
|
|
18
|
+
if (this.cache.has(key)) {
|
|
19
|
+
this.cache.delete(key);
|
|
20
|
+
} else if (this.cache.size === this.maxSize) {
|
|
21
|
+
this.cache.delete(this.getOldestKey());
|
|
22
|
+
}
|
|
23
|
+
this.cache.set(key, value);
|
|
24
|
+
}
|
|
25
|
+
getOldestKey() {
|
|
26
|
+
return this.cache.keys().next().value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
LRUCache
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=LRUCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LRUCache.js","sources":["../../../../../packages/utilities/src/structures/LRUCache.ts"],"sourcesContent":["// This is heavily inspired by https://stackoverflow.com/a/46432113\nexport class LRUCache<Key, Value> {\n\tprivate readonly cache = new Map<Key, Value>()\n\n\tpublic constructor(private readonly maxSize: number) {}\n\n\tpublic get(key: Key): Value | undefined {\n\t\tconst value = this.cache.get(key)\n\n\t\tif (value !== undefined) {\n\t\t\tthis.cache.delete(key)\n\t\t\tthis.cache.set(key, value)\n\t\t}\n\t\treturn value\n\t}\n\n\tpublic set(key: Key, value: Value) {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key) // Refresh this key\n\t\t} else if (this.cache.size === this.maxSize) {\n\t\t\tthis.cache.delete(this.getOldestKey()) // Evict the oldest value\n\t\t}\n\t\tthis.cache.set(key, value)\n\t}\n\n\tprivate getOldestKey(): Key {\n\t\treturn this.cache.keys().next().value!\n\t}\n}\n"],"names":[],"mappings":";;;AACO,MAAM,SAAqB;AAAA,EAG1B,YAA6B,SAAiB;AAAjB,SAAA,UAAA;AAFpC,kBAAA,MAAiB,6BAAY,IAAA,CAAgB;AAAA,EAES;AAAA,EAE/C,IAAI,KAA6B;AACvC,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAEhC,QAAI,UAAU,QAAW;AACxB,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,MAAM,IAAI,KAAK,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEO,IAAI,KAAU,OAAc;AAClC,QAAI,KAAK,MAAM,IAAI,GAAG,GAAG;AACxB,WAAK,MAAM,OAAO,GAAG;AAAA,IACtB,WAAW,KAAK,MAAM,SAAS,KAAK,SAAS;AAC5C,WAAK,MAAM,OAAO,KAAK,aAAA,CAAc;AAAA,IACtC;AACA,SAAK,MAAM,IAAI,KAAK,KAAK;AAAA,EAC1B;AAAA,EAEQ,eAAoB;AAC3B,WAAO,KAAK,MAAM,KAAA,EAAO,OAAO;AAAA,EACjC;AACD;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
class WeakIdCache {
|
|
7
|
+
constructor() {
|
|
8
|
+
__publicField(this, "cache", /* @__PURE__ */ new WeakMap());
|
|
9
|
+
__publicField(this, "seed", 0);
|
|
10
|
+
__publicField(this, "rootId", this.seedToId(this.seed++));
|
|
11
|
+
}
|
|
12
|
+
getId(key) {
|
|
13
|
+
let existing = this.cache.get(key);
|
|
14
|
+
if (existing === void 0) {
|
|
15
|
+
this.cache.set(key, existing = this.seedToId(this.seed++));
|
|
16
|
+
}
|
|
17
|
+
return existing;
|
|
18
|
+
}
|
|
19
|
+
getOptionalKeyId(key) {
|
|
20
|
+
if (key === void 0) {
|
|
21
|
+
return this.rootId;
|
|
22
|
+
}
|
|
23
|
+
return this.getId(key);
|
|
24
|
+
}
|
|
25
|
+
seedToId(seed) {
|
|
26
|
+
return seed.toFixed(0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.WeakIdCache = WeakIdCache;
|
|
30
|
+
//# sourceMappingURL=WeakIdCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WeakIdCache.cjs","sources":["../../../../../packages/utilities/src/structures/WeakIdCache.ts"],"sourcesContent":["export class WeakIdCache<K extends object> {\n\tprivate readonly cache = new WeakMap<K, string>()\n\tprivate seed = 0\n\tprivate readonly rootId = this.seedToId(this.seed++)\n\n\tpublic getId(key: K): string {\n\t\tlet existing = this.cache.get(key)\n\n\t\tif (existing === undefined) {\n\t\t\tthis.cache.set(key, existing = this.seedToId(this.seed++))\n\t\t}\n\t\treturn existing\n\t}\n\n\tpublic getOptionalKeyId(key: K | undefined): string {\n\t\tif (key === undefined) {\n\t\t\treturn this.rootId\n\t\t}\n\t\treturn this.getId(key)\n\t}\n\n\tprivate seedToId(seed: number): string {\n\t\treturn seed.toFixed(0)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAAO,MAAM,YAA8B;AAAA,EAApC,cAAA;AACN,kBAAA,MAAiB,6BAAY,QAAA,CAAmB;AAChD,kBAAA,MAAQ,QAAO,CAAA;AACf,kBAAA,MAAiB,UAAS,KAAK,SAAS,KAAK,MAAM,CAAA;AAAA,EAAA;AAAA,EAE5C,MAAM,KAAgB;AAC5B,QAAI,WAAW,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,aAAa,QAAW;AAC3B,WAAK,MAAM,IAAI,KAAK,WAAW,KAAK,SAAS,KAAK,MAAM,CAAC;AAAA,IAC1D;AACA,WAAO;AAAA,EACR;AAAA,EAEO,iBAAiB,KAA4B;AACnD,QAAI,QAAQ,QAAW;AACtB,aAAO,KAAK;AAAA,IACb;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACtB;AAAA,EAEQ,SAAS,MAAsB;AACtC,WAAO,KAAK,QAAQ,CAAC;AAAA,EACtB;AACD;;"}
|