@bitbybit-dev/base 1.6.2 → 1.7.0
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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +20 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- package/lib/api/inputs/io-inputs.d.ts +527 -59
- package/lib/api/inputs/io-inputs.js +432 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/settings.d.ts +82 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +22 -2
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.js +2 -3
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +3 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +1 -0
- package/lib/api/services/helpers/color/color-forms.js +4 -1
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +24 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +85 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +24 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +18 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +84 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +5 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +252 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +60 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +28 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +193 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +81 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +81 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +69 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +71 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +78 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +556 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +247 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +65 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +32 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +34 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +108 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +16 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +153 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +13 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/io/drawing.d.ts +170 -0
- package/lib/api/services/io/drawing.js +212 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +64 -0
- package/lib/api/services/io/svg.js +102 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +4 -1
- package/lib/api/services/text.d.ts +4 -1
- package/lib/api/services/text.js +8 -3
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Base } from "../inputs/base-inputs";
|
|
2
|
+
/**
|
|
3
|
+
* The settings one bitbybit instance works by: choices made once for a whole app, not per call.
|
|
4
|
+
* The renderer holds them for its scene, each worker is told them once and keeps them, and a
|
|
5
|
+
* program that runs a kernel itself sets them on that kernel. A setting left out keeps the
|
|
6
|
+
* behaviour the libraries had before it existed.
|
|
7
|
+
*/
|
|
8
|
+
export interface BitbybitSettings {
|
|
9
|
+
/**
|
|
10
|
+
* The coordinate system the model's numbers are in: left-handed for a default Babylon.js scene,
|
|
11
|
+
* right-handed for three.js, PlayCanvas and a program without a scene. Files, drawings and text
|
|
12
|
+
* map by it. Left out, they map as they did before the choice existed.
|
|
13
|
+
*/
|
|
14
|
+
coordinateSystem?: Base.coordinateSystemEnum | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Checks settings that arrived from outside - a worker message, a file, a caller's object - and
|
|
18
|
+
* returns them as a new plain object holding only what was set, its keys in a fixed order.
|
|
19
|
+
*
|
|
20
|
+
* A name that is no setting and a value its setting does not take are refused as an `InputError`
|
|
21
|
+
* naming the property, so a misspelt setting is never silently ignored. Nothing, or an empty
|
|
22
|
+
* object, gives no settings.
|
|
23
|
+
* @param given - The settings as they arrived
|
|
24
|
+
* @returns The settings that were set
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkedSettings(given: unknown): BitbybitSettings;
|
|
27
|
+
/**
|
|
28
|
+
* The settings as a worker keeps its results apart by them: nothing when none are set, so a result
|
|
29
|
+
* made with no settings is found under the key it had before settings existed.
|
|
30
|
+
* @param settings - The settings the worker works by
|
|
31
|
+
* @returns The settings, or nothing when none are set
|
|
32
|
+
*/
|
|
33
|
+
export declare function settingsCacheKey(settings: BitbybitSettings): BitbybitSettings | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Keeps the settings a kernel worker manager is given and tells its worker them: what the OCCT,
|
|
36
|
+
* JSCAD and Manifold managers share. Settings are checked where they arrive, so a refused one
|
|
37
|
+
* rejects and changes nothing, whether a worker is set or not. Accepted ones are sent at once, as a
|
|
38
|
+
* call of their own, to the worker set now and to every worker set after it. Nothing waits for the
|
|
39
|
+
* worker's answer: a worker answers calls in the order they came, holding those that arrive before
|
|
40
|
+
* its kernel is ready, so every call made after the settings works by them. A worker that refuses
|
|
41
|
+
* them all the same, one built before a setting existed, is reported through `refused`.
|
|
42
|
+
*/
|
|
43
|
+
export declare class SettingsRelay {
|
|
44
|
+
private readonly send;
|
|
45
|
+
private readonly refused;
|
|
46
|
+
private kept;
|
|
47
|
+
/**
|
|
48
|
+
* @param send - Sends settings to the worker as a call of their own, settled by its answer
|
|
49
|
+
* @param refused - Told what a worker answered when it refused the settings it was sent
|
|
50
|
+
*/
|
|
51
|
+
constructor(send: (settings: BitbybitSettings) => Promise<unknown>, refused: (reason: unknown) => void);
|
|
52
|
+
/**
|
|
53
|
+
* Checks the settings, keeps them, and sends them to the worker when one is set.
|
|
54
|
+
* @param settings - The settings as they arrived
|
|
55
|
+
* @param toWorker - True when a worker is set to send them to now
|
|
56
|
+
* @returns The settings kept; a refusal rejects and keeps the earlier ones
|
|
57
|
+
*/
|
|
58
|
+
set(settings: unknown, toWorker: boolean): Promise<BitbybitSettings>;
|
|
59
|
+
/**
|
|
60
|
+
* Sends the settings kept to a worker just set, when any were ever given.
|
|
61
|
+
*/
|
|
62
|
+
workerSet(): void;
|
|
63
|
+
private tell;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The newest conventions level these libraries know: 1, where a model's numbers are in the
|
|
67
|
+
* engine's own coordinate system. Content made today is saved with it.
|
|
68
|
+
*/
|
|
69
|
+
export declare const CURRENT_CONVENTIONS = 1;
|
|
70
|
+
/**
|
|
71
|
+
* The settings that content saved with a conventions level runs by. Content carries one whole
|
|
72
|
+
* number instead of the settings themselves, since the right settings depend on the engine that runs it:
|
|
73
|
+
* 0, or no level at all, is the behaviour from before settings existed, and 1 and above are the
|
|
74
|
+
* engine's own settings. Levels only add, so one newer than this version knows runs by the newest
|
|
75
|
+
* it has.
|
|
76
|
+
*
|
|
77
|
+
* Anything but a whole number from 0 is refused as an `InputError`.
|
|
78
|
+
* @param level - The level the content was saved with, or nothing for content saved without one
|
|
79
|
+
* @param engineSettings - The settings that fit the engine, as a renderer's `engineSettings` gives them
|
|
80
|
+
* @returns The settings to run the content by
|
|
81
|
+
*/
|
|
82
|
+
export declare function settingsOfConventions(level: unknown, engineSettings: BitbybitSettings): BitbybitSettings;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Base } from "../inputs/base-inputs";
|
|
2
|
+
import { InputError } from "./errors";
|
|
3
|
+
const COORDINATE_SYSTEMS = Object.values(Base.coordinateSystemEnum);
|
|
4
|
+
const REFUSALS = new Map([
|
|
5
|
+
["coordinateSystem", value => (COORDINATE_SYSTEMS.includes(value) ? undefined : `it is ${COORDINATE_SYSTEMS.join(", ")} or left out`)],
|
|
6
|
+
]);
|
|
7
|
+
/**
|
|
8
|
+
* Checks settings that arrived from outside - a worker message, a file, a caller's object - and
|
|
9
|
+
* returns them as a new plain object holding only what was set, its keys in a fixed order.
|
|
10
|
+
*
|
|
11
|
+
* A name that is no setting and a value its setting does not take are refused as an `InputError`
|
|
12
|
+
* naming the property, so a misspelt setting is never silently ignored. Nothing, or an empty
|
|
13
|
+
* object, gives no settings.
|
|
14
|
+
* @param given - The settings as they arrived
|
|
15
|
+
* @returns The settings that were set
|
|
16
|
+
*/
|
|
17
|
+
export function checkedSettings(given) {
|
|
18
|
+
if (given === undefined || given === null) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
if (typeof given !== "object" || Array.isArray(given)) {
|
|
22
|
+
throw new InputError("The settings are an object of setting names and values.", "settings");
|
|
23
|
+
}
|
|
24
|
+
const entries = given;
|
|
25
|
+
const unknown = Object.keys(entries).find(name => !REFUSALS.has(name));
|
|
26
|
+
if (unknown !== undefined) {
|
|
27
|
+
throw new InputError(`\`${unknown}\` is not a setting; the settings are ${[...REFUSALS.keys()].join(", ")}.`, unknown);
|
|
28
|
+
}
|
|
29
|
+
const settings = {};
|
|
30
|
+
REFUSALS.forEach((refusalOf, name) => {
|
|
31
|
+
const value = entries[name];
|
|
32
|
+
if (value === undefined || value === null) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const refusal = refusalOf(value);
|
|
36
|
+
if (refusal !== undefined) {
|
|
37
|
+
throw new InputError(`\`${name}\` is ${JSON.stringify(value)}; ${refusal}.`, name);
|
|
38
|
+
}
|
|
39
|
+
settings[name] = value;
|
|
40
|
+
});
|
|
41
|
+
return settings;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The settings as a worker keeps its results apart by them: nothing when none are set, so a result
|
|
45
|
+
* made with no settings is found under the key it had before settings existed.
|
|
46
|
+
* @param settings - The settings the worker works by
|
|
47
|
+
* @returns The settings, or nothing when none are set
|
|
48
|
+
*/
|
|
49
|
+
export function settingsCacheKey(settings) {
|
|
50
|
+
return Object.keys(settings).length === 0 ? undefined : settings;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Keeps the settings a kernel worker manager is given and tells its worker them: what the OCCT,
|
|
54
|
+
* JSCAD and Manifold managers share. Settings are checked where they arrive, so a refused one
|
|
55
|
+
* rejects and changes nothing, whether a worker is set or not. Accepted ones are sent at once, as a
|
|
56
|
+
* call of their own, to the worker set now and to every worker set after it. Nothing waits for the
|
|
57
|
+
* worker's answer: a worker answers calls in the order they came, holding those that arrive before
|
|
58
|
+
* its kernel is ready, so every call made after the settings works by them. A worker that refuses
|
|
59
|
+
* them all the same, one built before a setting existed, is reported through `refused`.
|
|
60
|
+
*/
|
|
61
|
+
export class SettingsRelay {
|
|
62
|
+
/**
|
|
63
|
+
* @param send - Sends settings to the worker as a call of their own, settled by its answer
|
|
64
|
+
* @param refused - Told what a worker answered when it refused the settings it was sent
|
|
65
|
+
*/
|
|
66
|
+
constructor(send, refused) {
|
|
67
|
+
this.send = send;
|
|
68
|
+
this.refused = refused;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks the settings, keeps them, and sends them to the worker when one is set.
|
|
72
|
+
* @param settings - The settings as they arrived
|
|
73
|
+
* @param toWorker - True when a worker is set to send them to now
|
|
74
|
+
* @returns The settings kept; a refusal rejects and keeps the earlier ones
|
|
75
|
+
*/
|
|
76
|
+
set(settings, toWorker) {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const checked = checkedSettings(settings);
|
|
79
|
+
this.kept = checked;
|
|
80
|
+
if (toWorker) {
|
|
81
|
+
this.tell(checked);
|
|
82
|
+
}
|
|
83
|
+
resolve(Object.assign({}, checked));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sends the settings kept to a worker just set, when any were ever given.
|
|
88
|
+
*/
|
|
89
|
+
workerSet() {
|
|
90
|
+
if (this.kept !== undefined) {
|
|
91
|
+
this.tell(this.kept);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
tell(settings) {
|
|
95
|
+
this.send(Object.assign({}, settings)).catch(this.refused);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The newest conventions level these libraries know: 1, where a model's numbers are in the
|
|
100
|
+
* engine's own coordinate system. Content made today is saved with it.
|
|
101
|
+
*/
|
|
102
|
+
export const CURRENT_CONVENTIONS = 1;
|
|
103
|
+
/**
|
|
104
|
+
* The settings that content saved with a conventions level runs by. Content carries one whole
|
|
105
|
+
* number instead of the settings themselves, since the right settings depend on the engine that runs it:
|
|
106
|
+
* 0, or no level at all, is the behaviour from before settings existed, and 1 and above are the
|
|
107
|
+
* engine's own settings. Levels only add, so one newer than this version knows runs by the newest
|
|
108
|
+
* it has.
|
|
109
|
+
*
|
|
110
|
+
* Anything but a whole number from 0 is refused as an `InputError`.
|
|
111
|
+
* @param level - The level the content was saved with, or nothing for content saved without one
|
|
112
|
+
* @param engineSettings - The settings that fit the engine, as a renderer's `engineSettings` gives them
|
|
113
|
+
* @returns The settings to run the content by
|
|
114
|
+
*/
|
|
115
|
+
export function settingsOfConventions(level, engineSettings) {
|
|
116
|
+
if (level === undefined || level === null) {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
if (typeof level !== "number" || !Number.isSafeInteger(level) || level < 0) {
|
|
120
|
+
throw new InputError(`A conventions level is a whole number from 0, got ${JSON.stringify(level)}.`, "conventions");
|
|
121
|
+
}
|
|
122
|
+
return level === 0 ? {} : checkedSettings(engineSettings);
|
|
123
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { Base } from "../inputs/base-inputs";
|
|
1
2
|
import type { RecipeSurfaceMesh } from "./recipe-types";
|
|
2
|
-
export declare function recipeSurfaceMeshes(value: unknown, roots?: readonly number[], adjustZtoY?: boolean): (RecipeSurfaceMesh | undefined)[];
|
|
3
|
+
export declare function recipeSurfaceMeshes(value: unknown, roots?: readonly number[], adjustZtoY?: boolean, coordinateSystem?: Base.coordinateSystemEnum): (RecipeSurfaceMesh | undefined)[];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Base } from "../inputs/base-inputs";
|
|
1
2
|
import { InputError } from "../kernel-calls/errors";
|
|
2
3
|
import { followedBy, linearDeterminant, movedCoordinate } from "../services/helpers/geometry/matrices";
|
|
4
|
+
import { meshMatrixInModel } from "../services/helpers/files/mesh-file-axes";
|
|
3
5
|
import { POINT3_SIZE, TRIANGLE_CORNERS } from "./limits.constants";
|
|
4
6
|
import { toRecipe } from "./validate";
|
|
5
7
|
import { isIndexBelow } from "./checks";
|
|
6
|
-
const Z_TO_Y = [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1];
|
|
7
8
|
const X = 0;
|
|
8
9
|
const Y = 1;
|
|
9
10
|
const Z = 2;
|
|
@@ -57,7 +58,7 @@ function meshOfPieces(buffers, pieces) {
|
|
|
57
58
|
}
|
|
58
59
|
return { positions, indices };
|
|
59
60
|
}
|
|
60
|
-
export function recipeSurfaceMeshes(value, roots, adjustZtoY = false) {
|
|
61
|
+
export function recipeSurfaceMeshes(value, roots, adjustZtoY = false, coordinateSystem) {
|
|
61
62
|
const recipe = toRecipe(value);
|
|
62
63
|
const asked = roots !== null && roots !== void 0 ? roots : recipe.roots.map((_, index) => index);
|
|
63
64
|
const bad = asked.find((index) => !isIndexBelow(index, recipe.roots.length));
|
|
@@ -67,7 +68,8 @@ export function recipeSurfaceMeshes(value, roots, adjustZtoY = false) {
|
|
|
67
68
|
return asked.map((index) => {
|
|
68
69
|
const root = recipe.roots[index];
|
|
69
70
|
const pieces = [];
|
|
70
|
-
const
|
|
71
|
+
const turn = meshMatrixInModel(coordinateSystem !== null && coordinateSystem !== void 0 ? coordinateSystem : Base.coordinateSystemEnum.rightHanded, adjustZtoY);
|
|
72
|
+
const placement = turn === undefined ? root.matrix : followedBy(root.matrix, turn);
|
|
71
73
|
return collectPieces(recipe.nodes, root.node, placement, pieces) ? meshOfPieces(recipe.buffers, pieces) : undefined;
|
|
72
74
|
});
|
|
73
75
|
}
|
|
@@ -130,14 +130,33 @@ export declare namespace Frame {
|
|
|
130
130
|
* the way `resolveDto` hands a DTO to the code that reads it.
|
|
131
131
|
*/
|
|
132
132
|
export declare namespace IO {
|
|
133
|
+
type DrawingArcSegmentDto = Inputs.IO.DrawingArcSegmentDto;
|
|
134
|
+
type DrawingCircleSegmentDto = Inputs.IO.DrawingCircleSegmentDto;
|
|
135
|
+
type DrawingEllipseSegmentDto = WithDefaults<Inputs.IO.DrawingEllipseSegmentDto, "startParameter" | "endParameter">;
|
|
136
|
+
type DrawingLineSegmentDto = Inputs.IO.DrawingLineSegmentDto;
|
|
137
|
+
type DrawingPartDto = WithDefaults<Inputs.IO.DrawingPartDto, "layer" | "color" | "lineType">;
|
|
138
|
+
type DrawingPathDto = Inputs.IO.DrawingPathDto;
|
|
139
|
+
type DrawingPolylineSegmentDto = WithDefaults<Inputs.IO.DrawingPolylineSegmentDto, "closed">;
|
|
140
|
+
type DrawingSplineSegmentDto = WithDefaults<Inputs.IO.DrawingSplineSegmentDto, "degree" | "closed">;
|
|
133
141
|
type DxfArcSegmentDto = Inputs.IO.DxfArcSegmentDto;
|
|
134
142
|
type DxfCircleSegmentDto = Inputs.IO.DxfCircleSegmentDto;
|
|
143
|
+
type DxfDrawingDto = Inputs.IO.DxfDrawingDto;
|
|
144
|
+
type DxfEllipseSegmentDto = WithDefaults<Inputs.IO.DxfEllipseSegmentDto, "startParameter" | "endParameter">;
|
|
135
145
|
type DxfLineSegmentDto = Inputs.IO.DxfLineSegmentDto;
|
|
136
|
-
type DxfModelDto = WithDefaults<Inputs.IO.DxfModelDto, "colorFormat" | "acadVersion">;
|
|
146
|
+
type DxfModelDto = WithDefaults<Inputs.IO.DxfModelDto, "colorFormat" | "acadVersion" | "curveTolerance">;
|
|
137
147
|
type DxfPathDto = Inputs.IO.DxfPathDto;
|
|
138
|
-
type DxfPathsPartDto = WithDefaults<Inputs.IO.DxfPathsPartDto, "layer" | "color">;
|
|
148
|
+
type DxfPathsPartDto = WithDefaults<Inputs.IO.DxfPathsPartDto, "layer" | "color" | "lineType">;
|
|
139
149
|
type DxfPolylineSegmentDto = WithDefaults<Inputs.IO.DxfPolylineSegmentDto, "closed">;
|
|
150
|
+
type DxfReadDto = WithDefaults<Inputs.IO.DxfReadDto, "includeHiddenLayers">;
|
|
140
151
|
type DxfSplineSegmentDto = WithDefaults<Inputs.IO.DxfSplineSegmentDto, "degree" | "closed">;
|
|
152
|
+
type DxfToSvgDto = WithDefaults<Inputs.IO.DxfToSvgDto, "includeHiddenLayers" | "tolerance">;
|
|
153
|
+
type DxfToSvgResultDto = Inputs.IO.DxfToSvgResultDto;
|
|
154
|
+
type SvgDrawingDto = Inputs.IO.SvgDrawingDto;
|
|
155
|
+
type SvgModelDto = WithDefaults<Inputs.IO.SvgModelDto, "tolerance">;
|
|
156
|
+
type SvgPathDataDto = WithDefaults<Inputs.IO.SvgPathDataDto, "flipY" | "tolerance">;
|
|
157
|
+
type SvgReadDto = WithDefaults<Inputs.IO.SvgReadDto, "includeInvisible">;
|
|
158
|
+
type SvgToDxfDto = WithDefaults<Inputs.IO.SvgToDxfDto, "includeInvisible" | "colorFormat" | "acadVersion" | "curveTolerance">;
|
|
159
|
+
type SvgToDxfResultDto = Inputs.IO.SvgToDxfResultDto;
|
|
141
160
|
}
|
|
142
161
|
/**
|
|
143
162
|
* The Line inputs DTOs as their defaults leave them: every property with a default is present,
|
|
@@ -148,6 +167,7 @@ export declare namespace Line {
|
|
|
148
167
|
type DrawLinesDto<T> = WithDefaults<Inputs.Line.DrawLinesDto<T>, "opacity" | "colours" | "size" | "updatable">;
|
|
149
168
|
type LineDto = Inputs.Line.LineDto;
|
|
150
169
|
type LineLineIntersectionDto = WithDefaults<Inputs.Line.LineLineIntersectionDto, "checkSegmentsOnly" | "tolerance">;
|
|
170
|
+
type LinePointDistanceDto = Inputs.Line.LinePointDistanceDto;
|
|
151
171
|
type LinePointsDto = Inputs.Line.LinePointsDto;
|
|
152
172
|
type LinesDto = Inputs.Line.LinesDto;
|
|
153
173
|
type LineStartEndPointsDto = Inputs.Line.LineStartEndPointsDto;
|
|
@@ -3,6 +3,7 @@ import { Dates } from "./dates";
|
|
|
3
3
|
import { Engineering } from "./engineering";
|
|
4
4
|
import { Frame } from "./frame";
|
|
5
5
|
import { GeometryHelper } from "./geometry-helper";
|
|
6
|
+
import type { BitbybitSettings } from "../kernel-calls/settings";
|
|
6
7
|
import { IoBitByBit } from "./io";
|
|
7
8
|
import { Line } from "./line";
|
|
8
9
|
import { Lists } from "./lists";
|
|
@@ -38,5 +39,16 @@ export declare class BaseBitByBit {
|
|
|
38
39
|
readonly dates: Dates;
|
|
39
40
|
readonly engineering: Engineering;
|
|
40
41
|
readonly recipes: Recipes;
|
|
42
|
+
private checked;
|
|
43
|
+
/**
|
|
44
|
+
* The settings this instance works by, such as the coordinate system its numbers are in, set by
|
|
45
|
+
* whoever owns this object: the renderer for its scene, a worker when it is told them, a
|
|
46
|
+
* program in Node for itself. A setting left out keeps the behaviour from before it existed.
|
|
47
|
+
* Settings are checked as they are set: a name that is no setting, or a value its setting does
|
|
48
|
+
* not take, is refused as an `InputError` and the earlier settings stay. The settings read back
|
|
49
|
+
* are frozen, so they change only by assigning new ones.
|
|
50
|
+
*/
|
|
51
|
+
get settings(): BitbybitSettings;
|
|
52
|
+
set settings(settings: BitbybitSettings);
|
|
41
53
|
constructor();
|
|
42
54
|
}
|
|
@@ -3,6 +3,7 @@ import { Dates } from "./dates";
|
|
|
3
3
|
import { Engineering } from "./engineering";
|
|
4
4
|
import { Frame } from "./frame";
|
|
5
5
|
import { GeometryHelper } from "./geometry-helper";
|
|
6
|
+
import { checkedSettings } from "../kernel-calls/settings";
|
|
6
7
|
import { IoBitByBit } from "./io";
|
|
7
8
|
import { Line } from "./line";
|
|
8
9
|
import { Lists } from "./lists";
|
|
@@ -21,23 +22,38 @@ import { Vector } from "./vector";
|
|
|
21
22
|
* calls the same maths a user does.
|
|
22
23
|
*/
|
|
23
24
|
export class BaseBitByBit {
|
|
25
|
+
/**
|
|
26
|
+
* The settings this instance works by, such as the coordinate system its numbers are in, set by
|
|
27
|
+
* whoever owns this object: the renderer for its scene, a worker when it is told them, a
|
|
28
|
+
* program in Node for itself. A setting left out keeps the behaviour from before it existed.
|
|
29
|
+
* Settings are checked as they are set: a name that is no setting, or a value its setting does
|
|
30
|
+
* not take, is refused as an `InputError` and the earlier settings stay. The settings read back
|
|
31
|
+
* are frozen, so they change only by assigning new ones.
|
|
32
|
+
*/
|
|
33
|
+
get settings() {
|
|
34
|
+
return this.checked;
|
|
35
|
+
}
|
|
36
|
+
set settings(settings) {
|
|
37
|
+
this.checked = Object.freeze(checkedSettings(settings));
|
|
38
|
+
}
|
|
24
39
|
constructor() {
|
|
40
|
+
this.checked = Object.freeze({});
|
|
25
41
|
this.geometryHelper = new GeometryHelper();
|
|
26
42
|
this.math = new MathBitByBit();
|
|
27
43
|
this.vector = new Vector(this.math, this.geometryHelper);
|
|
28
44
|
this.transforms = new Transforms(this.vector, this.math);
|
|
29
45
|
this.lists = new Lists();
|
|
30
|
-
this.point = new Point(this.geometryHelper, this.transforms, this.vector, this.lists);
|
|
46
|
+
this.point = new Point(this.geometryHelper, this.transforms, this.vector, this.lists, () => this.settings);
|
|
31
47
|
this.line = new Line(this.vector, this.point, this.geometryHelper);
|
|
32
48
|
this.polyline = new Polyline(this.vector, this.point, this.line, this.geometryHelper);
|
|
33
49
|
this.mesh = new MeshBitByBit(this.vector, this.polyline);
|
|
34
|
-
this.textService = new TextBitByBit(this.point);
|
|
50
|
+
this.textService = new TextBitByBit(this.point, () => this.settings);
|
|
35
51
|
this.io = new IoBitByBit();
|
|
36
52
|
this.frame = new Frame(this.vector, this.math, this.geometryHelper);
|
|
37
53
|
this.color = new Color(this.math);
|
|
38
54
|
this.logic = new Logic();
|
|
39
55
|
this.dates = new Dates();
|
|
40
56
|
this.engineering = new Engineering();
|
|
41
|
-
this.recipes = new Recipes();
|
|
57
|
+
this.recipes = new Recipes(() => this.settings);
|
|
42
58
|
}
|
|
43
59
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { resolveDto } from "../kernel-calls";
|
|
3
3
|
import { linearToSrgb, srgbToLinear } from "./helpers/color/color-space";
|
|
4
|
-
import { hexChannels, hslChannels } from "./helpers/color/color-forms";
|
|
4
|
+
import { hexChannels, hexOfChannels, hslChannels } from "./helpers/color/color-forms";
|
|
5
5
|
import { InputError } from "../kernel-calls/errors";
|
|
6
|
-
const HEX_RADIX = 16;
|
|
7
6
|
/**
|
|
8
7
|
* Colors in the two forms the library uses: a hex text such as `#ff5733`, and an object `{ r, g, b
|
|
9
8
|
* }` or `{ r, g, b, a }` whose channels run either from 0 to 255 or from 0 to 1. The methods here
|
|
@@ -221,7 +220,7 @@ export class Color {
|
|
|
221
220
|
const scaled = resolved.min === 0 && resolved.max === 255 ? channel : this.math.remap({ number: channel, fromLow: resolved.min, fromHigh: resolved.max, toLow: 0, toHigh: 255 });
|
|
222
221
|
return Math.min(255, Math.max(0, Math.round(scaled)));
|
|
223
222
|
};
|
|
224
|
-
return
|
|
223
|
+
return hexOfChannels([byteOf(resolved.r), byteOf(resolved.g), byteOf(resolved.b)]);
|
|
225
224
|
}
|
|
226
225
|
/**
|
|
227
226
|
* Writes an `{ r, g, b }` color as a hex color.
|
|
@@ -5,3 +5,6 @@ export declare const HUE_FALL_START = 9;
|
|
|
5
5
|
export declare const RED_OFFSET = 0;
|
|
6
6
|
export declare const GREEN_OFFSET = 8;
|
|
7
7
|
export declare const BLUE_OFFSET = 4;
|
|
8
|
+
export declare const HEX_LEAD = 16777216;
|
|
9
|
+
export declare const RED_PLACE = 65536;
|
|
10
|
+
export declare const GREEN_PLACE = 256;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function hexChannels(text: string): [number, number, number] | undefined;
|
|
2
|
+
export declare function hexOfChannels(channels: readonly [number, number, number]): string;
|
|
2
3
|
export declare function hslChannels(hue: number, saturation: number, lightness: number): [number, number, number];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BLUE_OFFSET, GREEN_OFFSET, HUE_DEGREES_PER_STEP, HUE_FALL_START, HUE_RISE_START, HUE_STEPS, RED_OFFSET } from "./color-forms.constants";
|
|
1
|
+
import { BLUE_OFFSET, GREEN_OFFSET, GREEN_PLACE, HEX_LEAD, HUE_DEGREES_PER_STEP, HUE_FALL_START, HUE_RISE_START, HUE_STEPS, RED_OFFSET, RED_PLACE } from "./color-forms.constants";
|
|
2
2
|
const HEX_RADIX = 16;
|
|
3
3
|
const LONG_HEX = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
4
4
|
const SHORT_HEX = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
@@ -14,6 +14,9 @@ export function hexChannels(text) {
|
|
|
14
14
|
const doubled = (digit) => parseInt(digit + digit, HEX_RADIX);
|
|
15
15
|
return [doubled(short[1]), doubled(short[2]), doubled(short[3])];
|
|
16
16
|
}
|
|
17
|
+
export function hexOfChannels(channels) {
|
|
18
|
+
return `#${(HEX_LEAD + channels[0] * RED_PLACE + channels[1] * GREEN_PLACE + channels[2]).toString(HEX_RADIX).substring(1)}`;
|
|
19
|
+
}
|
|
17
20
|
export function hslChannels(hue, saturation, lightness) {
|
|
18
21
|
const reach = saturation * Math.min(lightness, 1 - lightness);
|
|
19
22
|
const channel = (offset) => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const CHANNEL_MAX = 255;
|
|
2
|
+
export declare const PERCENT = 100;
|
|
3
|
+
export declare const RGB_CHANNELS = 3;
|
|
4
|
+
export declare const RGB_WITH_ALPHA = 4;
|
|
5
|
+
export declare const SHORT_HEX_DIGITS = 3;
|
|
6
|
+
export declare const SHORT_HEX_WITH_ALPHA_DIGITS = 4;
|
|
7
|
+
export declare const LONG_HEX_DIGITS = 6;
|
|
8
|
+
export declare const LONG_HEX_WITH_ALPHA_DIGITS = 8;
|
|
9
|
+
export declare const CSS_NAMED_COLORS: ReadonlyMap<string, string>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export const CHANNEL_MAX = 255;
|
|
2
|
+
export const PERCENT = 100;
|
|
3
|
+
export const RGB_CHANNELS = 3;
|
|
4
|
+
export const RGB_WITH_ALPHA = 4;
|
|
5
|
+
export const SHORT_HEX_DIGITS = 3;
|
|
6
|
+
export const SHORT_HEX_WITH_ALPHA_DIGITS = 4;
|
|
7
|
+
export const LONG_HEX_DIGITS = 6;
|
|
8
|
+
export const LONG_HEX_WITH_ALPHA_DIGITS = 8;
|
|
9
|
+
export const CSS_NAMED_COLORS = new Map([
|
|
10
|
+
["aliceblue", "#f0f8ff"],
|
|
11
|
+
["antiquewhite", "#faebd7"],
|
|
12
|
+
["aqua", "#00ffff"],
|
|
13
|
+
["aquamarine", "#7fffd4"],
|
|
14
|
+
["azure", "#f0ffff"],
|
|
15
|
+
["beige", "#f5f5dc"],
|
|
16
|
+
["bisque", "#ffe4c4"],
|
|
17
|
+
["black", "#000000"],
|
|
18
|
+
["blanchedalmond", "#ffebcd"],
|
|
19
|
+
["blue", "#0000ff"],
|
|
20
|
+
["blueviolet", "#8a2be2"],
|
|
21
|
+
["brown", "#a52a2a"],
|
|
22
|
+
["burlywood", "#deb887"],
|
|
23
|
+
["cadetblue", "#5f9ea0"],
|
|
24
|
+
["chartreuse", "#7fff00"],
|
|
25
|
+
["chocolate", "#d2691e"],
|
|
26
|
+
["coral", "#ff7f50"],
|
|
27
|
+
["cornflowerblue", "#6495ed"],
|
|
28
|
+
["cornsilk", "#fff8dc"],
|
|
29
|
+
["crimson", "#dc143c"],
|
|
30
|
+
["cyan", "#00ffff"],
|
|
31
|
+
["darkblue", "#00008b"],
|
|
32
|
+
["darkcyan", "#008b8b"],
|
|
33
|
+
["darkgoldenrod", "#b8860b"],
|
|
34
|
+
["darkgray", "#a9a9a9"],
|
|
35
|
+
["darkgreen", "#006400"],
|
|
36
|
+
["darkgrey", "#a9a9a9"],
|
|
37
|
+
["darkkhaki", "#bdb76b"],
|
|
38
|
+
["darkmagenta", "#8b008b"],
|
|
39
|
+
["darkolivegreen", "#556b2f"],
|
|
40
|
+
["darkorange", "#ff8c00"],
|
|
41
|
+
["darkorchid", "#9932cc"],
|
|
42
|
+
["darkred", "#8b0000"],
|
|
43
|
+
["darksalmon", "#e9967a"],
|
|
44
|
+
["darkseagreen", "#8fbc8f"],
|
|
45
|
+
["darkslateblue", "#483d8b"],
|
|
46
|
+
["darkslategray", "#2f4f4f"],
|
|
47
|
+
["darkslategrey", "#2f4f4f"],
|
|
48
|
+
["darkturquoise", "#00ced1"],
|
|
49
|
+
["darkviolet", "#9400d3"],
|
|
50
|
+
["deeppink", "#ff1493"],
|
|
51
|
+
["deepskyblue", "#00bfff"],
|
|
52
|
+
["dimgray", "#696969"],
|
|
53
|
+
["dimgrey", "#696969"],
|
|
54
|
+
["dodgerblue", "#1e90ff"],
|
|
55
|
+
["firebrick", "#b22222"],
|
|
56
|
+
["floralwhite", "#fffaf0"],
|
|
57
|
+
["forestgreen", "#228b22"],
|
|
58
|
+
["fuchsia", "#ff00ff"],
|
|
59
|
+
["gainsboro", "#dcdcdc"],
|
|
60
|
+
["ghostwhite", "#f8f8ff"],
|
|
61
|
+
["gold", "#ffd700"],
|
|
62
|
+
["goldenrod", "#daa520"],
|
|
63
|
+
["gray", "#808080"],
|
|
64
|
+
["green", "#008000"],
|
|
65
|
+
["greenyellow", "#adff2f"],
|
|
66
|
+
["grey", "#808080"],
|
|
67
|
+
["honeydew", "#f0fff0"],
|
|
68
|
+
["hotpink", "#ff69b4"],
|
|
69
|
+
["indianred", "#cd5c5c"],
|
|
70
|
+
["indigo", "#4b0082"],
|
|
71
|
+
["ivory", "#fffff0"],
|
|
72
|
+
["khaki", "#f0e68c"],
|
|
73
|
+
["lavender", "#e6e6fa"],
|
|
74
|
+
["lavenderblush", "#fff0f5"],
|
|
75
|
+
["lawngreen", "#7cfc00"],
|
|
76
|
+
["lemonchiffon", "#fffacd"],
|
|
77
|
+
["lightblue", "#add8e6"],
|
|
78
|
+
["lightcoral", "#f08080"],
|
|
79
|
+
["lightcyan", "#e0ffff"],
|
|
80
|
+
["lightgoldenrodyellow", "#fafad2"],
|
|
81
|
+
["lightgray", "#d3d3d3"],
|
|
82
|
+
["lightgreen", "#90ee90"],
|
|
83
|
+
["lightgrey", "#d3d3d3"],
|
|
84
|
+
["lightpink", "#ffb6c1"],
|
|
85
|
+
["lightsalmon", "#ffa07a"],
|
|
86
|
+
["lightseagreen", "#20b2aa"],
|
|
87
|
+
["lightskyblue", "#87cefa"],
|
|
88
|
+
["lightslategray", "#778899"],
|
|
89
|
+
["lightslategrey", "#778899"],
|
|
90
|
+
["lightsteelblue", "#b0c4de"],
|
|
91
|
+
["lightyellow", "#ffffe0"],
|
|
92
|
+
["lime", "#00ff00"],
|
|
93
|
+
["limegreen", "#32cd32"],
|
|
94
|
+
["linen", "#faf0e6"],
|
|
95
|
+
["magenta", "#ff00ff"],
|
|
96
|
+
["maroon", "#800000"],
|
|
97
|
+
["mediumaquamarine", "#66cdaa"],
|
|
98
|
+
["mediumblue", "#0000cd"],
|
|
99
|
+
["mediumorchid", "#ba55d3"],
|
|
100
|
+
["mediumpurple", "#9370db"],
|
|
101
|
+
["mediumseagreen", "#3cb371"],
|
|
102
|
+
["mediumslateblue", "#7b68ee"],
|
|
103
|
+
["mediumspringgreen", "#00fa9a"],
|
|
104
|
+
["mediumturquoise", "#48d1cc"],
|
|
105
|
+
["mediumvioletred", "#c71585"],
|
|
106
|
+
["midnightblue", "#191970"],
|
|
107
|
+
["mintcream", "#f5fffa"],
|
|
108
|
+
["mistyrose", "#ffe4e1"],
|
|
109
|
+
["moccasin", "#ffe4b5"],
|
|
110
|
+
["navajowhite", "#ffdead"],
|
|
111
|
+
["navy", "#000080"],
|
|
112
|
+
["oldlace", "#fdf5e6"],
|
|
113
|
+
["olive", "#808000"],
|
|
114
|
+
["olivedrab", "#6b8e23"],
|
|
115
|
+
["orange", "#ffa500"],
|
|
116
|
+
["orangered", "#ff4500"],
|
|
117
|
+
["orchid", "#da70d6"],
|
|
118
|
+
["palegoldenrod", "#eee8aa"],
|
|
119
|
+
["palegreen", "#98fb98"],
|
|
120
|
+
["paleturquoise", "#afeeee"],
|
|
121
|
+
["palevioletred", "#db7093"],
|
|
122
|
+
["papayawhip", "#ffefd5"],
|
|
123
|
+
["peachpuff", "#ffdab9"],
|
|
124
|
+
["peru", "#cd853f"],
|
|
125
|
+
["pink", "#ffc0cb"],
|
|
126
|
+
["plum", "#dda0dd"],
|
|
127
|
+
["powderblue", "#b0e0e6"],
|
|
128
|
+
["purple", "#800080"],
|
|
129
|
+
["rebeccapurple", "#663399"],
|
|
130
|
+
["red", "#ff0000"],
|
|
131
|
+
["rosybrown", "#bc8f8f"],
|
|
132
|
+
["royalblue", "#4169e1"],
|
|
133
|
+
["saddlebrown", "#8b4513"],
|
|
134
|
+
["salmon", "#fa8072"],
|
|
135
|
+
["sandybrown", "#f4a460"],
|
|
136
|
+
["seagreen", "#2e8b57"],
|
|
137
|
+
["seashell", "#fff5ee"],
|
|
138
|
+
["sienna", "#a0522d"],
|
|
139
|
+
["silver", "#c0c0c0"],
|
|
140
|
+
["skyblue", "#87ceeb"],
|
|
141
|
+
["slateblue", "#6a5acd"],
|
|
142
|
+
["slategray", "#708090"],
|
|
143
|
+
["slategrey", "#708090"],
|
|
144
|
+
["snow", "#fffafa"],
|
|
145
|
+
["springgreen", "#00ff7f"],
|
|
146
|
+
["steelblue", "#4682b4"],
|
|
147
|
+
["tan", "#d2b48c"],
|
|
148
|
+
["teal", "#008080"],
|
|
149
|
+
["thistle", "#d8bfd8"],
|
|
150
|
+
["tomato", "#ff6347"],
|
|
151
|
+
["turquoise", "#40e0d0"],
|
|
152
|
+
["violet", "#ee82ee"],
|
|
153
|
+
["wheat", "#f5deb3"],
|
|
154
|
+
["white", "#ffffff"],
|
|
155
|
+
["whitesmoke", "#f5f5f5"],
|
|
156
|
+
["yellow", "#ffff00"],
|
|
157
|
+
["yellowgreen", "#9acd32"],
|
|
158
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cssColorHex(text: string): string | undefined;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { hexChannels, hexOfChannels } from "./color-forms";
|
|
2
|
+
import { CHANNEL_MAX, CSS_NAMED_COLORS, LONG_HEX_DIGITS, LONG_HEX_WITH_ALPHA_DIGITS, PERCENT, RGB_CHANNELS, RGB_WITH_ALPHA, SHORT_HEX_DIGITS, SHORT_HEX_WITH_ALPHA_DIGITS, } from "./css-colors.constants";
|
|
3
|
+
const HEX_COLOR = /^#([a-f\d]+)$/i;
|
|
4
|
+
const RGB_FUNCTION = /^rgba?\(([^()]*)\)$/i;
|
|
5
|
+
const CSS_NUMBER = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%?)$/i;
|
|
6
|
+
const SPACES = /\s+/;
|
|
7
|
+
const DIGITS_WITHOUT_ALPHA = new Map([
|
|
8
|
+
[SHORT_HEX_DIGITS, SHORT_HEX_DIGITS],
|
|
9
|
+
[SHORT_HEX_WITH_ALPHA_DIGITS, SHORT_HEX_DIGITS],
|
|
10
|
+
[LONG_HEX_DIGITS, LONG_HEX_DIGITS],
|
|
11
|
+
[LONG_HEX_WITH_ALPHA_DIGITS, LONG_HEX_DIGITS],
|
|
12
|
+
]);
|
|
13
|
+
const hexOfDigits = (digits) => {
|
|
14
|
+
const kept = DIGITS_WITHOUT_ALPHA.get(digits.length);
|
|
15
|
+
const channels = kept === undefined ? undefined : hexChannels(digits.slice(0, kept));
|
|
16
|
+
return channels === undefined ? undefined : hexOfChannels(channels);
|
|
17
|
+
};
|
|
18
|
+
const cssNumberOf = (text) => {
|
|
19
|
+
const match = CSS_NUMBER.exec(text.trim());
|
|
20
|
+
if (!match) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const value = parseFloat(match[1]);
|
|
24
|
+
return Number.isFinite(value) ? { value, percent: match[2] === "%" } : undefined;
|
|
25
|
+
};
|
|
26
|
+
const channelOf = (number) => {
|
|
27
|
+
const scaled = number.percent ? number.value / PERCENT * CHANNEL_MAX : number.value;
|
|
28
|
+
return Math.min(CHANNEL_MAX, Math.max(0, Math.round(scaled)));
|
|
29
|
+
};
|
|
30
|
+
const rgbArguments = (text) => {
|
|
31
|
+
if (text.includes(",")) {
|
|
32
|
+
const parts = text.split(",");
|
|
33
|
+
return parts.length === RGB_CHANNELS || parts.length === RGB_WITH_ALPHA ? parts : undefined;
|
|
34
|
+
}
|
|
35
|
+
const [channels, alpha, ...rest] = text.split("/");
|
|
36
|
+
const values = channels.trim().split(SPACES);
|
|
37
|
+
if (rest.length > 0 || values.length !== RGB_CHANNELS) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return alpha === undefined ? values : values.concat(alpha);
|
|
41
|
+
};
|
|
42
|
+
const rgbHex = (text) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const numbers = ((_a = rgbArguments(text)) !== null && _a !== void 0 ? _a : []).map(cssNumberOf);
|
|
45
|
+
if (numbers.length === 0 || numbers.some(number => number === undefined)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return hexOfChannels([channelOf(numbers[0]), channelOf(numbers[1]), channelOf(numbers[2])]);
|
|
49
|
+
};
|
|
50
|
+
export function cssColorHex(text) {
|
|
51
|
+
const trimmed = text.trim();
|
|
52
|
+
const hex = HEX_COLOR.exec(trimmed);
|
|
53
|
+
if (hex) {
|
|
54
|
+
return hexOfDigits(hex[1]);
|
|
55
|
+
}
|
|
56
|
+
const rgb = RGB_FUNCTION.exec(trimmed);
|
|
57
|
+
if (rgb) {
|
|
58
|
+
return rgbHex(rgb[1]);
|
|
59
|
+
}
|
|
60
|
+
return CSS_NAMED_COLORS.get(trimmed.toLowerCase());
|
|
61
|
+
}
|