webstudio 0.257.0 → 0.259.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/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
9
9
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
11
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
-
var _declarations, _dirtyBreakpoints,
|
|
12
|
+
var _a, _b, _c, _declarations, _dirtyBreakpoints, _d, _selector, _descendantSuffix, _mixinRules, _mixins, _declarations2, _cache, _NestingRule_instances, getDeclarations_fn, _e, _name, _f, _cached, _options, _g, _element, _name2, _h, _cssText, _mediaRules, _plainRules, _mixinRules2, _fontFaceRules, _transformValue, _element2, _i;
|
|
13
13
|
import { exit, cwd, chdir, argv } from "node:process";
|
|
14
14
|
import { hideBin } from "yargs/helpers";
|
|
15
15
|
import { join, dirname, normalize, basename, relative } from "node:path";
|
|
@@ -738,6 +738,1801 @@ new Map(
|
|
|
738
738
|
return weightData.names.map((name2) => [name2, weight]);
|
|
739
739
|
}).flat()
|
|
740
740
|
);
|
|
741
|
+
function dot3(a2, b2) {
|
|
742
|
+
return a2[0] * b2[0] + a2[1] * b2[1] + a2[2] * b2[2];
|
|
743
|
+
}
|
|
744
|
+
function multiply_v3_m3x3(input2, matrix, out = [0, 0, 0]) {
|
|
745
|
+
const x2 = dot3(input2, matrix[0]);
|
|
746
|
+
const y2 = dot3(input2, matrix[1]);
|
|
747
|
+
const z2 = dot3(input2, matrix[2]);
|
|
748
|
+
out[0] = x2;
|
|
749
|
+
out[1] = y2;
|
|
750
|
+
out[2] = z2;
|
|
751
|
+
return out;
|
|
752
|
+
}
|
|
753
|
+
function isString(str) {
|
|
754
|
+
return type$1(str) === "string";
|
|
755
|
+
}
|
|
756
|
+
function type$1(o2) {
|
|
757
|
+
let str = Object.prototype.toString.call(o2);
|
|
758
|
+
return (str.match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase();
|
|
759
|
+
}
|
|
760
|
+
function serializeNumber(n2, { precision = 16, unit }) {
|
|
761
|
+
if (isNone(n2)) {
|
|
762
|
+
return "none";
|
|
763
|
+
}
|
|
764
|
+
n2 = +toPrecision(n2, precision);
|
|
765
|
+
return n2 + (unit ?? "");
|
|
766
|
+
}
|
|
767
|
+
function isNone(n2) {
|
|
768
|
+
return n2 === null;
|
|
769
|
+
}
|
|
770
|
+
function toPrecision(n2, precision) {
|
|
771
|
+
if (n2 === 0) {
|
|
772
|
+
return 0;
|
|
773
|
+
}
|
|
774
|
+
let integer = ~~n2;
|
|
775
|
+
let digits = 0;
|
|
776
|
+
if (integer && precision) {
|
|
777
|
+
digits = ~~Math.log10(Math.abs(integer)) + 1;
|
|
778
|
+
}
|
|
779
|
+
const multiplier = 10 ** (precision - digits);
|
|
780
|
+
return Math.floor(n2 * multiplier + 0.5) / multiplier;
|
|
781
|
+
}
|
|
782
|
+
function interpolate(start, end, p2) {
|
|
783
|
+
if (isNaN(start)) {
|
|
784
|
+
return end;
|
|
785
|
+
}
|
|
786
|
+
if (isNaN(end)) {
|
|
787
|
+
return start;
|
|
788
|
+
}
|
|
789
|
+
return start + (end - start) * p2;
|
|
790
|
+
}
|
|
791
|
+
function interpolateInv(start, end, value) {
|
|
792
|
+
return (value - start) / (end - start);
|
|
793
|
+
}
|
|
794
|
+
function mapRange(from, to, value) {
|
|
795
|
+
if (!from || !to || from === to || from[0] === to[0] && from[1] === to[1] || isNaN(value) || value === null) {
|
|
796
|
+
return value;
|
|
797
|
+
}
|
|
798
|
+
return interpolate(to[0], to[1], interpolateInv(from[0], from[1], value));
|
|
799
|
+
}
|
|
800
|
+
function clamp(min, val, max) {
|
|
801
|
+
return Math.max(Math.min(max, val), min);
|
|
802
|
+
}
|
|
803
|
+
function isInstance(arg, constructor) {
|
|
804
|
+
var _a2;
|
|
805
|
+
if (arg instanceof constructor) {
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
const targetName = constructor.name;
|
|
809
|
+
while (arg) {
|
|
810
|
+
const proto = Object.getPrototypeOf(arg);
|
|
811
|
+
const constructorName = (_a2 = proto == null ? void 0 : proto.constructor) == null ? void 0 : _a2.name;
|
|
812
|
+
if (constructorName === targetName) {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
if (!constructorName || constructorName === "Object") {
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
arg = proto;
|
|
819
|
+
}
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
class Type {
|
|
823
|
+
/**
|
|
824
|
+
* @param {any} type
|
|
825
|
+
* @param {import("./types.js").CoordMeta} coordMeta
|
|
826
|
+
*/
|
|
827
|
+
constructor(type2, coordMeta) {
|
|
828
|
+
// Class properties - declared here so that type inference works
|
|
829
|
+
__publicField(this, "type");
|
|
830
|
+
__publicField(this, "coordMeta");
|
|
831
|
+
__publicField(this, "coordRange");
|
|
832
|
+
/** @type {[number, number]} */
|
|
833
|
+
__publicField(this, "range");
|
|
834
|
+
if (typeof type2 === "object") {
|
|
835
|
+
this.coordMeta = type2;
|
|
836
|
+
}
|
|
837
|
+
if (coordMeta) {
|
|
838
|
+
this.coordMeta = coordMeta;
|
|
839
|
+
this.coordRange = coordMeta.range ?? coordMeta.refRange;
|
|
840
|
+
}
|
|
841
|
+
if (typeof type2 === "string") {
|
|
842
|
+
let params = type2.trim().match(/^(?<type><[a-z]+>)(\[(?<min>-?[.\d]+),\s*(?<max>-?[.\d]+)\])?$/);
|
|
843
|
+
if (!params) {
|
|
844
|
+
throw new TypeError(`Cannot parse ${type2} as a type definition.`);
|
|
845
|
+
}
|
|
846
|
+
this.type = params.groups.type;
|
|
847
|
+
let { min, max } = params.groups;
|
|
848
|
+
if (min || max) {
|
|
849
|
+
this.range = [+min, +max];
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
/** @returns {[number, number]} */
|
|
854
|
+
get computedRange() {
|
|
855
|
+
if (this.range) {
|
|
856
|
+
return this.range;
|
|
857
|
+
}
|
|
858
|
+
if (this.type === "<percentage>") {
|
|
859
|
+
return this.percentageRange();
|
|
860
|
+
} else if (this.type === "<angle>") {
|
|
861
|
+
return [0, 360];
|
|
862
|
+
}
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
865
|
+
get unit() {
|
|
866
|
+
if (this.type === "<percentage>") {
|
|
867
|
+
return "%";
|
|
868
|
+
} else if (this.type === "<angle>") {
|
|
869
|
+
return "deg";
|
|
870
|
+
}
|
|
871
|
+
return "";
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Map a number to the internal representation
|
|
875
|
+
* @param {number} number
|
|
876
|
+
*/
|
|
877
|
+
resolve(number) {
|
|
878
|
+
if (this.type === "<angle>") {
|
|
879
|
+
return number;
|
|
880
|
+
}
|
|
881
|
+
let fromRange = this.computedRange;
|
|
882
|
+
let toRange = this.coordRange;
|
|
883
|
+
if (this.type === "<percentage>") {
|
|
884
|
+
toRange ?? (toRange = this.percentageRange());
|
|
885
|
+
}
|
|
886
|
+
return mapRange(fromRange, toRange, number);
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Serialize a number from the internal representation to a string
|
|
890
|
+
* @param {number} number
|
|
891
|
+
* @param {number} [precision]
|
|
892
|
+
*/
|
|
893
|
+
serialize(number, precision) {
|
|
894
|
+
let toRange = this.type === "<percentage>" ? this.percentageRange(100) : this.computedRange;
|
|
895
|
+
let unit = this.unit;
|
|
896
|
+
number = mapRange(this.coordRange, toRange, number);
|
|
897
|
+
return serializeNumber(number, { unit, precision });
|
|
898
|
+
}
|
|
899
|
+
toString() {
|
|
900
|
+
let ret = this.type;
|
|
901
|
+
if (this.range) {
|
|
902
|
+
let [min = "", max = ""] = this.range;
|
|
903
|
+
ret += `[${min},${max}]`;
|
|
904
|
+
}
|
|
905
|
+
return ret;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Returns a percentage range for values of this type
|
|
909
|
+
* @param {number} scale
|
|
910
|
+
* @returns {[number, number]}
|
|
911
|
+
*/
|
|
912
|
+
percentageRange(scale = 1) {
|
|
913
|
+
let range;
|
|
914
|
+
if (this.coordMeta && this.coordMeta.range || this.coordRange && this.coordRange[0] >= 0) {
|
|
915
|
+
range = [0, 1];
|
|
916
|
+
} else {
|
|
917
|
+
range = [-1, 1];
|
|
918
|
+
}
|
|
919
|
+
return [range[0] * scale, range[1] * scale];
|
|
920
|
+
}
|
|
921
|
+
static get(type2, coordMeta) {
|
|
922
|
+
if (isInstance(type2, this)) {
|
|
923
|
+
return type2;
|
|
924
|
+
}
|
|
925
|
+
return new this(type2, coordMeta);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const instance = Symbol("instance");
|
|
929
|
+
class Format {
|
|
930
|
+
/**
|
|
931
|
+
* @param {FormatInterface} format
|
|
932
|
+
* @param {ColorSpace} space
|
|
933
|
+
*/
|
|
934
|
+
constructor(format, space = format.space) {
|
|
935
|
+
// Class properties - declared here so that type inference works
|
|
936
|
+
__publicField(this, "type");
|
|
937
|
+
__publicField(this, "name");
|
|
938
|
+
__publicField(this, "spaceCoords");
|
|
939
|
+
/** @type {Type[][]} */
|
|
940
|
+
__publicField(this, "coords");
|
|
941
|
+
/** @type {string | undefined} */
|
|
942
|
+
__publicField(this, "id");
|
|
943
|
+
/** @type {boolean | undefined} */
|
|
944
|
+
__publicField(this, "alpha");
|
|
945
|
+
format[instance] = this;
|
|
946
|
+
this.type = "function";
|
|
947
|
+
this.name = "color";
|
|
948
|
+
Object.assign(this, format);
|
|
949
|
+
this.space = space;
|
|
950
|
+
if (this.type === "custom") {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
this.spaceCoords = Object.values(space.coords);
|
|
954
|
+
if (!this.coords) {
|
|
955
|
+
this.coords = this.spaceCoords.map((coordMeta) => {
|
|
956
|
+
let ret = ["<number>", "<percentage>"];
|
|
957
|
+
if (coordMeta.type === "angle") {
|
|
958
|
+
ret.push("<angle>");
|
|
959
|
+
}
|
|
960
|
+
return ret;
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
this.coords = this.coords.map(
|
|
964
|
+
/** @param {string | string[] | Type[]} types */
|
|
965
|
+
(types, i2) => {
|
|
966
|
+
let coordMeta = this.spaceCoords[i2];
|
|
967
|
+
if (typeof types === "string") {
|
|
968
|
+
types = types.trim().split(/\s*\|\s*/);
|
|
969
|
+
}
|
|
970
|
+
return types.map((type2) => Type.get(type2, coordMeta));
|
|
971
|
+
}
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* @param {Coords} coords
|
|
976
|
+
* @param {number} precision
|
|
977
|
+
* @param {Type[]} types
|
|
978
|
+
*/
|
|
979
|
+
serializeCoords(coords, precision, types) {
|
|
980
|
+
types = coords.map((_, i2) => Type.get((types == null ? void 0 : types[i2]) ?? this.coords[i2][0], this.spaceCoords[i2]));
|
|
981
|
+
return coords.map((c2, i2) => types[i2].serialize(c2, precision));
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Validates the coordinates of a color against a format's coord grammar and
|
|
985
|
+
* maps the coordinates to the range or refRange of the coordinates.
|
|
986
|
+
* @param {Coords} coords
|
|
987
|
+
* @param {[string, string, string]} types
|
|
988
|
+
*/
|
|
989
|
+
coerceCoords(coords, types) {
|
|
990
|
+
return Object.entries(this.space.coords).map(([id, coordMeta], i2) => {
|
|
991
|
+
let arg = coords[i2];
|
|
992
|
+
if (isNone(arg) || isNaN(arg)) {
|
|
993
|
+
return arg;
|
|
994
|
+
}
|
|
995
|
+
let providedType = types[i2];
|
|
996
|
+
let type2 = this.coords[i2].find((c2) => c2.type == providedType);
|
|
997
|
+
if (!type2) {
|
|
998
|
+
let coordName = coordMeta.name || id;
|
|
999
|
+
throw new TypeError(
|
|
1000
|
+
`${providedType ?? /** @type {any} */
|
|
1001
|
+
(arg == null ? void 0 : arg.raw) ?? arg} not allowed for ${coordName} in ${this.name}()`
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
arg = type2.resolve(arg);
|
|
1005
|
+
if (type2.range) {
|
|
1006
|
+
types[i2] = type2.toString();
|
|
1007
|
+
}
|
|
1008
|
+
return arg;
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* @returns {boolean | Required<FormatInterface>["serialize"]}
|
|
1013
|
+
*/
|
|
1014
|
+
canSerialize() {
|
|
1015
|
+
return this.type === "function" || /** @type {any} */
|
|
1016
|
+
this.serialize;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* @param {string} str
|
|
1020
|
+
* @returns {(import("./types.js").ColorConstructor) | undefined | null}
|
|
1021
|
+
*/
|
|
1022
|
+
parse(str) {
|
|
1023
|
+
return null;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* @param {Format | FormatInterface} format
|
|
1027
|
+
* @param {RemoveFirstElement<ConstructorParameters<typeof Format>>} args
|
|
1028
|
+
* @returns {Format}
|
|
1029
|
+
*/
|
|
1030
|
+
static get(format, ...args) {
|
|
1031
|
+
if (!format || isInstance(format, this)) {
|
|
1032
|
+
return (
|
|
1033
|
+
/** @type {Format} */
|
|
1034
|
+
format
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
if (format[instance]) {
|
|
1038
|
+
return format[instance];
|
|
1039
|
+
}
|
|
1040
|
+
return new Format(format, ...args);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
class Hooks {
|
|
1044
|
+
add(name2, callback, first) {
|
|
1045
|
+
if (typeof arguments[0] != "string") {
|
|
1046
|
+
for (var name2 in arguments[0]) {
|
|
1047
|
+
this.add(name2, arguments[0][name2], arguments[1]);
|
|
1048
|
+
}
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
(Array.isArray(name2) ? name2 : [name2]).forEach(function(name3) {
|
|
1052
|
+
this[name3] = this[name3] || [];
|
|
1053
|
+
if (callback) {
|
|
1054
|
+
this[name3][first ? "unshift" : "push"](callback);
|
|
1055
|
+
}
|
|
1056
|
+
}, this);
|
|
1057
|
+
}
|
|
1058
|
+
run(name2, env) {
|
|
1059
|
+
this[name2] = this[name2] || [];
|
|
1060
|
+
this[name2].forEach(function(callback) {
|
|
1061
|
+
callback.call(env && env.context ? env.context : env, env);
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
const hooks = new Hooks();
|
|
1066
|
+
const WHITES = {
|
|
1067
|
+
// for compatibility, the four-digit chromaticity-derived ones everyone else uses
|
|
1068
|
+
D50: [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585],
|
|
1069
|
+
D65: [0.3127 / 0.329, 1, (1 - 0.3127 - 0.329) / 0.329]
|
|
1070
|
+
};
|
|
1071
|
+
function getWhite(name2) {
|
|
1072
|
+
if (Array.isArray(name2)) {
|
|
1073
|
+
return name2;
|
|
1074
|
+
}
|
|
1075
|
+
return WHITES[name2];
|
|
1076
|
+
}
|
|
1077
|
+
function adapt(W1, W2, XYZ, options = {}) {
|
|
1078
|
+
W1 = getWhite(W1);
|
|
1079
|
+
W2 = getWhite(W2);
|
|
1080
|
+
if (!W1 || !W2) {
|
|
1081
|
+
throw new TypeError(
|
|
1082
|
+
`Missing white point to convert ${!W1 ? "from" : ""}${!W1 && !W2 ? "/" : ""}${!W2 ? "to" : ""}`
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
if (W1 === W2) {
|
|
1086
|
+
return XYZ;
|
|
1087
|
+
}
|
|
1088
|
+
let env = { W1, W2, XYZ, options };
|
|
1089
|
+
hooks.run("chromatic-adaptation-start", env);
|
|
1090
|
+
if (!env.M) {
|
|
1091
|
+
if (env.W1 === WHITES.D65 && env.W2 === WHITES.D50) {
|
|
1092
|
+
env.M = [
|
|
1093
|
+
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
|
|
1094
|
+
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
1095
|
+
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
|
|
1096
|
+
];
|
|
1097
|
+
} else if (env.W1 === WHITES.D50 && env.W2 === WHITES.D65) {
|
|
1098
|
+
env.M = [
|
|
1099
|
+
[0.955473421488075, -0.02309845494876471, 0.06325924320057072],
|
|
1100
|
+
[-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],
|
|
1101
|
+
[0.012314014864481998, -0.020507649298898964, 1.330365926242124]
|
|
1102
|
+
];
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
hooks.run("chromatic-adaptation-end", env);
|
|
1106
|
+
if (env.M) {
|
|
1107
|
+
return multiply_v3_m3x3(env.XYZ, env.M);
|
|
1108
|
+
} else {
|
|
1109
|
+
throw new TypeError("Only Bradford CAT with white points D50 and D65 supported for now.");
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const defaults = {
|
|
1113
|
+
gamut_mapping: "css",
|
|
1114
|
+
precision: 5,
|
|
1115
|
+
deltaE: "76",
|
|
1116
|
+
// Default deltaE method
|
|
1117
|
+
verbose: ((_c = (_b = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b.NODE_ENV) == null ? void 0 : _c.toLowerCase()) !== "test",
|
|
1118
|
+
warn: function warn(msg) {
|
|
1119
|
+
var _a2, _b2;
|
|
1120
|
+
if (this.verbose) {
|
|
1121
|
+
(_b2 = (_a2 = globalThis == null ? void 0 : globalThis.console) == null ? void 0 : _a2.warn) == null ? void 0 : _b2.call(_a2, msg);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
function parse(str, options) {
|
|
1126
|
+
var _a2, _b2, _c2;
|
|
1127
|
+
let env = {
|
|
1128
|
+
str: (_a2 = String(str)) == null ? void 0 : _a2.trim(),
|
|
1129
|
+
options
|
|
1130
|
+
};
|
|
1131
|
+
hooks.run("parse-start", env);
|
|
1132
|
+
if (env.color) {
|
|
1133
|
+
return env.color;
|
|
1134
|
+
}
|
|
1135
|
+
env.parsed = parseFunction(env.str);
|
|
1136
|
+
let ret;
|
|
1137
|
+
let meta = env.options ? env.options.parseMeta ?? env.options.meta : null;
|
|
1138
|
+
if (env.parsed) {
|
|
1139
|
+
let name2 = env.parsed.name;
|
|
1140
|
+
let format;
|
|
1141
|
+
let space;
|
|
1142
|
+
let coords = env.parsed.args;
|
|
1143
|
+
let types = coords.map((c2, i2) => {
|
|
1144
|
+
var _a3;
|
|
1145
|
+
return (_a3 = env.parsed.argMeta[i2]) == null ? void 0 : _a3.type;
|
|
1146
|
+
});
|
|
1147
|
+
if (name2 === "color") {
|
|
1148
|
+
let id = coords.shift();
|
|
1149
|
+
types.shift();
|
|
1150
|
+
let alternateId = id.startsWith("--") ? id.substring(2) : `--${id}`;
|
|
1151
|
+
let ids = [id, alternateId];
|
|
1152
|
+
format = ColorSpace.findFormat({ name: name2, id: ids, type: "function" });
|
|
1153
|
+
if (!format) {
|
|
1154
|
+
let didYouMean;
|
|
1155
|
+
let registryId = id in ColorSpace.registry ? id : alternateId;
|
|
1156
|
+
if (registryId in ColorSpace.registry) {
|
|
1157
|
+
let cssId = (_c2 = (_b2 = ColorSpace.registry[registryId].formats) == null ? void 0 : _b2.color) == null ? void 0 : _c2.id;
|
|
1158
|
+
if (cssId) {
|
|
1159
|
+
let altColor = str.replace("color(" + id, "color(" + cssId);
|
|
1160
|
+
didYouMean = `Did you mean ${altColor}?`;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
throw new TypeError(
|
|
1164
|
+
`Cannot parse ${env.str}. ` + (didYouMean ?? "Missing a plugin?")
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
space = format.space;
|
|
1168
|
+
if (format.id.startsWith("--") && !id.startsWith("--")) {
|
|
1169
|
+
defaults.warn(
|
|
1170
|
+
`${space.name} is a non-standard space and not currently supported in the CSS spec. Use prefixed color(${format.id}) instead of color(${id}).`
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
if (id.startsWith("--") && !format.id.startsWith("--")) {
|
|
1174
|
+
defaults.warn(
|
|
1175
|
+
`${space.name} is a standard space and supported in the CSS spec. Use color(${format.id}) instead of prefixed color(${id}).`
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
} else {
|
|
1179
|
+
format = ColorSpace.findFormat({ name: name2, type: "function" });
|
|
1180
|
+
space = format.space;
|
|
1181
|
+
}
|
|
1182
|
+
if (meta) {
|
|
1183
|
+
Object.assign(meta, {
|
|
1184
|
+
format,
|
|
1185
|
+
formatId: format.name,
|
|
1186
|
+
types,
|
|
1187
|
+
commas: env.parsed.commas
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
let alpha = 1;
|
|
1191
|
+
if (env.parsed.lastAlpha) {
|
|
1192
|
+
alpha = env.parsed.args.pop();
|
|
1193
|
+
if (meta) {
|
|
1194
|
+
meta.alphaType = types.pop();
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
let coordCount = format.coords.length;
|
|
1198
|
+
if (coords.length !== coordCount) {
|
|
1199
|
+
throw new TypeError(
|
|
1200
|
+
`Expected ${coordCount} coordinates for ${space.id} in ${env.str}), got ${coords.length}`
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
coords = format.coerceCoords(coords, types);
|
|
1204
|
+
ret = { spaceId: space.id, coords, alpha };
|
|
1205
|
+
} else {
|
|
1206
|
+
spaceloop: for (let space of ColorSpace.all) {
|
|
1207
|
+
for (let formatId in space.formats) {
|
|
1208
|
+
let format = space.formats[formatId];
|
|
1209
|
+
if (format.type !== "custom") {
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (format.test && !format.test(env.str)) {
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
let formatObject = space.getFormat(format);
|
|
1216
|
+
let color = formatObject.parse(env.str);
|
|
1217
|
+
if (color) {
|
|
1218
|
+
if (meta) {
|
|
1219
|
+
Object.assign(meta, { format: formatObject, formatId });
|
|
1220
|
+
}
|
|
1221
|
+
ret = color;
|
|
1222
|
+
break spaceloop;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (!ret) {
|
|
1228
|
+
throw new TypeError(`Could not parse ${str} as a color. Missing a plugin?`);
|
|
1229
|
+
}
|
|
1230
|
+
ret.alpha = isNone(ret.alpha) ? ret.alpha : ret.alpha === void 0 ? 1 : clamp(0, ret.alpha, 1);
|
|
1231
|
+
return ret;
|
|
1232
|
+
}
|
|
1233
|
+
const units = {
|
|
1234
|
+
"%": 0.01,
|
|
1235
|
+
deg: 1,
|
|
1236
|
+
grad: 0.9,
|
|
1237
|
+
rad: 180 / Math.PI,
|
|
1238
|
+
turn: 360
|
|
1239
|
+
};
|
|
1240
|
+
const regex = {
|
|
1241
|
+
// Need to list calc(NaN) explicitly as otherwise its ending paren would terminate the function call
|
|
1242
|
+
function: /^([a-z]+)\(((?:calc\(NaN\)|.)+?)\)$/i,
|
|
1243
|
+
number: /^([-+]?(?:[0-9]*\.)?[0-9]+(e[-+]?[0-9]+)?)$/i,
|
|
1244
|
+
unitValue: RegExp(`(${Object.keys(units).join("|")})$`),
|
|
1245
|
+
// NOTE The -+ are not just for prefix, but also for idents, and e+N notation!
|
|
1246
|
+
singleArgument: /\/?\s*(none|NaN|calc\(NaN\)|[-+\w.]+(?:%|deg|g?rad|turn)?)/g
|
|
1247
|
+
};
|
|
1248
|
+
function parseArgument(rawArg) {
|
|
1249
|
+
var _a2;
|
|
1250
|
+
let meta = {};
|
|
1251
|
+
let unit = (_a2 = rawArg.match(regex.unitValue)) == null ? void 0 : _a2[0];
|
|
1252
|
+
let value = meta.raw = rawArg;
|
|
1253
|
+
if (unit) {
|
|
1254
|
+
meta.type = unit === "%" ? "<percentage>" : "<angle>";
|
|
1255
|
+
meta.unit = unit;
|
|
1256
|
+
meta.unitless = Number(value.slice(0, -unit.length));
|
|
1257
|
+
value = meta.unitless * units[unit];
|
|
1258
|
+
} else if (regex.number.test(value)) {
|
|
1259
|
+
value = Number(value);
|
|
1260
|
+
meta.type = "<number>";
|
|
1261
|
+
} else if (value === "none") {
|
|
1262
|
+
value = null;
|
|
1263
|
+
} else if (value === "NaN" || value === "calc(NaN)") {
|
|
1264
|
+
value = NaN;
|
|
1265
|
+
meta.type = "<number>";
|
|
1266
|
+
} else {
|
|
1267
|
+
meta.type = "<ident>";
|
|
1268
|
+
}
|
|
1269
|
+
return { value: (
|
|
1270
|
+
/** @type {number} */
|
|
1271
|
+
value
|
|
1272
|
+
), meta: (
|
|
1273
|
+
/** @type {ArgumentMeta} */
|
|
1274
|
+
meta
|
|
1275
|
+
) };
|
|
1276
|
+
}
|
|
1277
|
+
function parseFunction(str) {
|
|
1278
|
+
if (!str) {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
str = str.trim();
|
|
1282
|
+
let parts = str.match(regex.function);
|
|
1283
|
+
if (parts) {
|
|
1284
|
+
let args = [];
|
|
1285
|
+
let argMeta = [];
|
|
1286
|
+
let lastAlpha = false;
|
|
1287
|
+
let name2 = parts[1].toLowerCase();
|
|
1288
|
+
let separators = parts[2].replace(regex.singleArgument, ($0, rawArg) => {
|
|
1289
|
+
let { value, meta } = parseArgument(rawArg);
|
|
1290
|
+
if (
|
|
1291
|
+
// If there's a slash here, it's modern syntax
|
|
1292
|
+
$0.startsWith("/") || // If there's still elements to process after there's already 3 in `args` (and the we're not dealing with "color()"), it's likely to be a legacy color like "hsl(0, 0%, 0%, 0.5)"
|
|
1293
|
+
name2 !== "color" && args.length === 3
|
|
1294
|
+
) {
|
|
1295
|
+
lastAlpha = true;
|
|
1296
|
+
}
|
|
1297
|
+
args.push(value);
|
|
1298
|
+
argMeta.push(meta);
|
|
1299
|
+
return "";
|
|
1300
|
+
});
|
|
1301
|
+
return {
|
|
1302
|
+
name: name2,
|
|
1303
|
+
args,
|
|
1304
|
+
argMeta,
|
|
1305
|
+
lastAlpha,
|
|
1306
|
+
commas: separators.includes(","),
|
|
1307
|
+
rawName: parts[1],
|
|
1308
|
+
rawArgs: parts[2]
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function getColor(color, options) {
|
|
1313
|
+
if (Array.isArray(color)) {
|
|
1314
|
+
return color.map((c2) => getColor(c2, options));
|
|
1315
|
+
}
|
|
1316
|
+
if (!color) {
|
|
1317
|
+
throw new TypeError("Empty color reference");
|
|
1318
|
+
}
|
|
1319
|
+
if (isString(color)) {
|
|
1320
|
+
color = parse(color, options);
|
|
1321
|
+
}
|
|
1322
|
+
let space = color.space || color.spaceId;
|
|
1323
|
+
if (typeof space === "string") {
|
|
1324
|
+
color.space = ColorSpace.get(space);
|
|
1325
|
+
}
|
|
1326
|
+
if (color.alpha === void 0) {
|
|
1327
|
+
color.alpha = 1;
|
|
1328
|
+
}
|
|
1329
|
+
return color;
|
|
1330
|
+
}
|
|
1331
|
+
const ε$1 = 75e-6;
|
|
1332
|
+
const _ColorSpace = class _ColorSpace {
|
|
1333
|
+
constructor(options) {
|
|
1334
|
+
var _a2;
|
|
1335
|
+
this.id = options.id;
|
|
1336
|
+
this.name = options.name;
|
|
1337
|
+
this.base = options.base ? _ColorSpace.get(options.base) : null;
|
|
1338
|
+
this.aliases = options.aliases;
|
|
1339
|
+
if (this.base) {
|
|
1340
|
+
this.fromBase = options.fromBase;
|
|
1341
|
+
this.toBase = options.toBase;
|
|
1342
|
+
}
|
|
1343
|
+
let coords = options.coords ?? this.base.coords;
|
|
1344
|
+
for (let name2 in coords) {
|
|
1345
|
+
if (!("name" in coords[name2])) {
|
|
1346
|
+
coords[name2].name = name2;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
this.coords = coords;
|
|
1350
|
+
let white2 = options.white ?? this.base.white ?? "D65";
|
|
1351
|
+
this.white = getWhite(white2);
|
|
1352
|
+
this.formats = options.formats ?? {};
|
|
1353
|
+
for (let name2 in this.formats) {
|
|
1354
|
+
let format = this.formats[name2];
|
|
1355
|
+
format.type || (format.type = "function");
|
|
1356
|
+
format.name || (format.name = name2);
|
|
1357
|
+
}
|
|
1358
|
+
if (!((_a2 = this.formats.color) == null ? void 0 : _a2.id)) {
|
|
1359
|
+
this.formats.color = {
|
|
1360
|
+
...this.formats.color ?? {},
|
|
1361
|
+
id: options.cssId || this.id
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
if (options.gamutSpace) {
|
|
1365
|
+
this.gamutSpace = options.gamutSpace === "self" ? this : _ColorSpace.get(options.gamutSpace);
|
|
1366
|
+
} else {
|
|
1367
|
+
if (this.isPolar) {
|
|
1368
|
+
this.gamutSpace = this.base;
|
|
1369
|
+
} else {
|
|
1370
|
+
this.gamutSpace = this;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
if (this.gamutSpace.isUnbounded) {
|
|
1374
|
+
this.inGamut = (coords2, options2) => {
|
|
1375
|
+
return true;
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
this.referred = options.referred;
|
|
1379
|
+
Object.defineProperty(this, "path", {
|
|
1380
|
+
value: getPath(this).reverse(),
|
|
1381
|
+
writable: false,
|
|
1382
|
+
enumerable: true,
|
|
1383
|
+
configurable: true
|
|
1384
|
+
});
|
|
1385
|
+
hooks.run("colorspace-init-end", this);
|
|
1386
|
+
}
|
|
1387
|
+
inGamut(coords, { epsilon = ε$1 } = {}) {
|
|
1388
|
+
if (!this.equals(this.gamutSpace)) {
|
|
1389
|
+
coords = this.to(this.gamutSpace, coords);
|
|
1390
|
+
return this.gamutSpace.inGamut(coords, { epsilon });
|
|
1391
|
+
}
|
|
1392
|
+
let coordMeta = Object.values(this.coords);
|
|
1393
|
+
return coords.every((c2, i2) => {
|
|
1394
|
+
let meta = coordMeta[i2];
|
|
1395
|
+
if (meta.type !== "angle" && meta.range) {
|
|
1396
|
+
if (isNone(c2)) {
|
|
1397
|
+
return true;
|
|
1398
|
+
}
|
|
1399
|
+
let [min, max] = meta.range;
|
|
1400
|
+
return (min === void 0 || c2 >= min - epsilon) && (max === void 0 || c2 <= max + epsilon);
|
|
1401
|
+
}
|
|
1402
|
+
return true;
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
get isUnbounded() {
|
|
1406
|
+
return Object.values(this.coords).every((coord) => !("range" in coord));
|
|
1407
|
+
}
|
|
1408
|
+
get cssId() {
|
|
1409
|
+
var _a2, _b2;
|
|
1410
|
+
return ((_b2 = (_a2 = this.formats) == null ? void 0 : _a2.color) == null ? void 0 : _b2.id) || this.id;
|
|
1411
|
+
}
|
|
1412
|
+
get isPolar() {
|
|
1413
|
+
for (let id in this.coords) {
|
|
1414
|
+
if (this.coords[id].type === "angle") {
|
|
1415
|
+
return true;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return false;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Lookup a format in this color space
|
|
1422
|
+
* @param {string | object | Format} format - Format id if string. If object, it's converted to a `Format` object and returned.
|
|
1423
|
+
* @returns {Format}
|
|
1424
|
+
*/
|
|
1425
|
+
getFormat(format) {
|
|
1426
|
+
if (!format) {
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
if (format === "default") {
|
|
1430
|
+
format = Object.values(this.formats)[0];
|
|
1431
|
+
} else if (typeof format === "string") {
|
|
1432
|
+
format = this.formats[format];
|
|
1433
|
+
}
|
|
1434
|
+
let ret = Format.get(format, this);
|
|
1435
|
+
if (ret !== format && format.name in this.formats) {
|
|
1436
|
+
this.formats[format.name] = ret;
|
|
1437
|
+
}
|
|
1438
|
+
return ret;
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Check if this color space is the same as another color space reference.
|
|
1442
|
+
* Allows proxying color space objects and comparing color spaces with ids.
|
|
1443
|
+
* @param {string | ColorSpace} space ColorSpace object or id to compare to
|
|
1444
|
+
* @returns {boolean}
|
|
1445
|
+
*/
|
|
1446
|
+
equals(space) {
|
|
1447
|
+
if (!space) {
|
|
1448
|
+
return false;
|
|
1449
|
+
}
|
|
1450
|
+
return this === space || this.id === space || this.id === space.id;
|
|
1451
|
+
}
|
|
1452
|
+
to(space, coords) {
|
|
1453
|
+
if (arguments.length === 1) {
|
|
1454
|
+
const color = getColor(space);
|
|
1455
|
+
[space, coords] = [color.space, color.coords];
|
|
1456
|
+
}
|
|
1457
|
+
space = _ColorSpace.get(space);
|
|
1458
|
+
if (this.equals(space)) {
|
|
1459
|
+
return coords;
|
|
1460
|
+
}
|
|
1461
|
+
coords = coords.map((c2) => isNone(c2) ? 0 : c2);
|
|
1462
|
+
let myPath = this.path;
|
|
1463
|
+
let otherPath = space.path;
|
|
1464
|
+
let connectionSpace, connectionSpaceIndex;
|
|
1465
|
+
for (let i2 = 0; i2 < myPath.length; i2++) {
|
|
1466
|
+
if (myPath[i2].equals(otherPath[i2])) {
|
|
1467
|
+
connectionSpace = myPath[i2];
|
|
1468
|
+
connectionSpaceIndex = i2;
|
|
1469
|
+
} else {
|
|
1470
|
+
break;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
if (!connectionSpace) {
|
|
1474
|
+
throw new Error(
|
|
1475
|
+
`Cannot convert between color spaces ${this} and ${space}: no connection space was found`
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
for (let i2 = myPath.length - 1; i2 > connectionSpaceIndex; i2--) {
|
|
1479
|
+
coords = myPath[i2].toBase(coords);
|
|
1480
|
+
}
|
|
1481
|
+
for (let i2 = connectionSpaceIndex + 1; i2 < otherPath.length; i2++) {
|
|
1482
|
+
coords = otherPath[i2].fromBase(coords);
|
|
1483
|
+
}
|
|
1484
|
+
return coords;
|
|
1485
|
+
}
|
|
1486
|
+
from(space, coords) {
|
|
1487
|
+
if (arguments.length === 1) {
|
|
1488
|
+
const color = getColor(space);
|
|
1489
|
+
[space, coords] = [color.space, color.coords];
|
|
1490
|
+
}
|
|
1491
|
+
space = _ColorSpace.get(space);
|
|
1492
|
+
return space.to(this, coords);
|
|
1493
|
+
}
|
|
1494
|
+
toString() {
|
|
1495
|
+
return `${this.name} (${this.id})`;
|
|
1496
|
+
}
|
|
1497
|
+
getMinCoords() {
|
|
1498
|
+
let ret = [];
|
|
1499
|
+
for (let id in this.coords) {
|
|
1500
|
+
let meta = this.coords[id];
|
|
1501
|
+
let range = meta.range || meta.refRange;
|
|
1502
|
+
ret.push((range == null ? void 0 : range.min) ?? 0);
|
|
1503
|
+
}
|
|
1504
|
+
return ret;
|
|
1505
|
+
}
|
|
1506
|
+
// Returns array of unique color spaces
|
|
1507
|
+
static get all() {
|
|
1508
|
+
return [...new Set(Object.values(_ColorSpace.registry))];
|
|
1509
|
+
}
|
|
1510
|
+
static register(id, space) {
|
|
1511
|
+
if (arguments.length === 1) {
|
|
1512
|
+
space = arguments[0];
|
|
1513
|
+
id = space.id;
|
|
1514
|
+
}
|
|
1515
|
+
space = this.get(space);
|
|
1516
|
+
if (this.registry[id] && this.registry[id] !== space) {
|
|
1517
|
+
throw new Error(`Duplicate color space registration: '${id}'`);
|
|
1518
|
+
}
|
|
1519
|
+
this.registry[id] = space;
|
|
1520
|
+
if (arguments.length === 1 && space.aliases) {
|
|
1521
|
+
for (let alias of space.aliases) {
|
|
1522
|
+
this.register(alias, space);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
return space;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Lookup ColorSpace object by name
|
|
1529
|
+
* @param {ColorSpace | string} name
|
|
1530
|
+
*/
|
|
1531
|
+
static get(space, ...alternatives) {
|
|
1532
|
+
if (!space || isInstance(space, this)) {
|
|
1533
|
+
return space;
|
|
1534
|
+
}
|
|
1535
|
+
let argType = type$1(space);
|
|
1536
|
+
if (argType === "string") {
|
|
1537
|
+
let ret = _ColorSpace.registry[space.toLowerCase()];
|
|
1538
|
+
if (!ret) {
|
|
1539
|
+
throw new TypeError(`No color space found with id = "${space}"`);
|
|
1540
|
+
}
|
|
1541
|
+
return ret;
|
|
1542
|
+
}
|
|
1543
|
+
if (alternatives.length) {
|
|
1544
|
+
return _ColorSpace.get(...alternatives);
|
|
1545
|
+
}
|
|
1546
|
+
throw new TypeError(`${space} is not a valid color space`);
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Look up all color spaces for a format that matches certain criteria
|
|
1550
|
+
* @param {object | string} filters
|
|
1551
|
+
* @param {Array<ColorSpace>} [spaces=ColorSpace.all]
|
|
1552
|
+
* @returns {Format | null}
|
|
1553
|
+
*/
|
|
1554
|
+
static findFormat(filters, spaces = _ColorSpace.all) {
|
|
1555
|
+
if (!filters) {
|
|
1556
|
+
return null;
|
|
1557
|
+
}
|
|
1558
|
+
if (typeof filters === "string") {
|
|
1559
|
+
filters = { name: filters };
|
|
1560
|
+
}
|
|
1561
|
+
for (let space of spaces) {
|
|
1562
|
+
for (let [name2, format] of Object.entries(space.formats)) {
|
|
1563
|
+
format.name ?? (format.name = name2);
|
|
1564
|
+
format.type ?? (format.type = "function");
|
|
1565
|
+
let matches = (!filters.name || format.name === filters.name) && (!filters.type || format.type === filters.type);
|
|
1566
|
+
if (filters.id) {
|
|
1567
|
+
let ids = format.ids || [format.id];
|
|
1568
|
+
let filterIds = Array.isArray(filters.id) ? filters.id : [filters.id];
|
|
1569
|
+
matches && (matches = filterIds.some((id) => ids.includes(id)));
|
|
1570
|
+
}
|
|
1571
|
+
if (matches) {
|
|
1572
|
+
let ret = Format.get(format, space);
|
|
1573
|
+
if (ret !== format) {
|
|
1574
|
+
space.formats[format.name] = ret;
|
|
1575
|
+
}
|
|
1576
|
+
return ret;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
return null;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Get metadata about a coordinate of a color space
|
|
1584
|
+
*
|
|
1585
|
+
* @static
|
|
1586
|
+
* @param {Array | string} ref
|
|
1587
|
+
* @param {ColorSpace | string} [workingSpace]
|
|
1588
|
+
* @return {Object}
|
|
1589
|
+
*/
|
|
1590
|
+
static resolveCoord(ref, workingSpace) {
|
|
1591
|
+
var _a2;
|
|
1592
|
+
let coordType = type$1(ref);
|
|
1593
|
+
let space, coord;
|
|
1594
|
+
if (coordType === "string") {
|
|
1595
|
+
if (ref.includes(".")) {
|
|
1596
|
+
[space, coord] = ref.split(".");
|
|
1597
|
+
} else {
|
|
1598
|
+
[space, coord] = [, ref];
|
|
1599
|
+
}
|
|
1600
|
+
} else if (Array.isArray(ref)) {
|
|
1601
|
+
[space, coord] = ref;
|
|
1602
|
+
} else {
|
|
1603
|
+
space = ref.space;
|
|
1604
|
+
coord = ref.coordId;
|
|
1605
|
+
}
|
|
1606
|
+
space = _ColorSpace.get(space);
|
|
1607
|
+
if (!space) {
|
|
1608
|
+
space = workingSpace;
|
|
1609
|
+
}
|
|
1610
|
+
if (!space) {
|
|
1611
|
+
throw new TypeError(
|
|
1612
|
+
`Cannot resolve coordinate reference ${ref}: No color space specified and relative references are not allowed here`
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
coordType = type$1(coord);
|
|
1616
|
+
if (coordType === "number" || coordType === "string" && coord >= 0) {
|
|
1617
|
+
let meta = Object.entries(space.coords)[coord];
|
|
1618
|
+
if (meta) {
|
|
1619
|
+
return { space, id: meta[0], index: coord, ...meta[1] };
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
space = _ColorSpace.get(space);
|
|
1623
|
+
let normalizedCoord = coord.toLowerCase();
|
|
1624
|
+
let i2 = 0;
|
|
1625
|
+
for (let id in space.coords) {
|
|
1626
|
+
let meta = space.coords[id];
|
|
1627
|
+
if (id.toLowerCase() === normalizedCoord || ((_a2 = meta.name) == null ? void 0 : _a2.toLowerCase()) === normalizedCoord) {
|
|
1628
|
+
return { space, id, index: i2, ...meta };
|
|
1629
|
+
}
|
|
1630
|
+
i2++;
|
|
1631
|
+
}
|
|
1632
|
+
throw new TypeError(
|
|
1633
|
+
`No "${coord}" coordinate found in ${space.name}. Its coordinates are: ${Object.keys(space.coords).join(", ")}`
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
__publicField(_ColorSpace, "registry", {});
|
|
1638
|
+
__publicField(_ColorSpace, "DEFAULT_FORMAT", {
|
|
1639
|
+
type: "functions",
|
|
1640
|
+
name: "color"
|
|
1641
|
+
});
|
|
1642
|
+
let ColorSpace = _ColorSpace;
|
|
1643
|
+
function getPath(space) {
|
|
1644
|
+
let ret = [space];
|
|
1645
|
+
for (let s2 = space; s2 = s2.base; ) {
|
|
1646
|
+
ret.push(s2);
|
|
1647
|
+
}
|
|
1648
|
+
return ret;
|
|
1649
|
+
}
|
|
1650
|
+
const xyz_d65 = new ColorSpace({
|
|
1651
|
+
id: "xyz-d65",
|
|
1652
|
+
name: "XYZ D65",
|
|
1653
|
+
coords: {
|
|
1654
|
+
x: {
|
|
1655
|
+
refRange: [0, 1],
|
|
1656
|
+
name: "X"
|
|
1657
|
+
},
|
|
1658
|
+
y: {
|
|
1659
|
+
refRange: [0, 1],
|
|
1660
|
+
name: "Y"
|
|
1661
|
+
},
|
|
1662
|
+
z: {
|
|
1663
|
+
refRange: [0, 1],
|
|
1664
|
+
name: "Z"
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
white: "D65",
|
|
1668
|
+
formats: {
|
|
1669
|
+
color: {
|
|
1670
|
+
ids: ["xyz-d65", "xyz"]
|
|
1671
|
+
}
|
|
1672
|
+
},
|
|
1673
|
+
aliases: ["xyz"]
|
|
1674
|
+
});
|
|
1675
|
+
class RGBColorSpace extends ColorSpace {
|
|
1676
|
+
/**
|
|
1677
|
+
* Creates a new RGB ColorSpace.
|
|
1678
|
+
* If coords are not specified, they will use the default RGB coords.
|
|
1679
|
+
* Instead of `fromBase()` and `toBase()` functions,
|
|
1680
|
+
* you can specify to/from XYZ matrices and have `toBase()` and `fromBase()` automatically generated.
|
|
1681
|
+
* @param {RGBOptions} options
|
|
1682
|
+
*/
|
|
1683
|
+
constructor(options) {
|
|
1684
|
+
if (!options.coords) {
|
|
1685
|
+
options.coords = {
|
|
1686
|
+
r: {
|
|
1687
|
+
range: [0, 1],
|
|
1688
|
+
name: "Red"
|
|
1689
|
+
},
|
|
1690
|
+
g: {
|
|
1691
|
+
range: [0, 1],
|
|
1692
|
+
name: "Green"
|
|
1693
|
+
},
|
|
1694
|
+
b: {
|
|
1695
|
+
range: [0, 1],
|
|
1696
|
+
name: "Blue"
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
if (!options.base) {
|
|
1701
|
+
options.base = xyz_d65;
|
|
1702
|
+
}
|
|
1703
|
+
if (options.toXYZ_M && options.fromXYZ_M) {
|
|
1704
|
+
options.toBase ?? (options.toBase = (rgb) => {
|
|
1705
|
+
let xyz = multiply_v3_m3x3(rgb, options.toXYZ_M);
|
|
1706
|
+
if (this.white !== this.base.white) {
|
|
1707
|
+
xyz = adapt(this.white, this.base.white, xyz);
|
|
1708
|
+
}
|
|
1709
|
+
return xyz;
|
|
1710
|
+
});
|
|
1711
|
+
options.fromBase ?? (options.fromBase = (xyz) => {
|
|
1712
|
+
xyz = adapt(this.base.white, this.white, xyz);
|
|
1713
|
+
return multiply_v3_m3x3(xyz, options.fromXYZ_M);
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
options.referred ?? (options.referred = "display");
|
|
1717
|
+
super(options);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
const XYZ_D50 = new ColorSpace({
|
|
1721
|
+
id: "xyz-d50",
|
|
1722
|
+
name: "XYZ D50",
|
|
1723
|
+
white: "D50",
|
|
1724
|
+
base: xyz_d65,
|
|
1725
|
+
fromBase: (coords) => adapt(xyz_d65.white, "D50", coords),
|
|
1726
|
+
toBase: (coords) => adapt("D50", xyz_d65.white, coords)
|
|
1727
|
+
});
|
|
1728
|
+
const ε = 216 / 24389;
|
|
1729
|
+
const ε3 = 24 / 116;
|
|
1730
|
+
const κ = 24389 / 27;
|
|
1731
|
+
let white = WHITES.D50;
|
|
1732
|
+
const lab = new ColorSpace({
|
|
1733
|
+
id: "lab",
|
|
1734
|
+
name: "Lab",
|
|
1735
|
+
coords: {
|
|
1736
|
+
l: {
|
|
1737
|
+
refRange: [0, 100],
|
|
1738
|
+
name: "Lightness"
|
|
1739
|
+
},
|
|
1740
|
+
a: {
|
|
1741
|
+
refRange: [-125, 125]
|
|
1742
|
+
},
|
|
1743
|
+
b: {
|
|
1744
|
+
refRange: [-125, 125]
|
|
1745
|
+
}
|
|
1746
|
+
},
|
|
1747
|
+
// Assuming XYZ is relative to D50, convert to CIE Lab
|
|
1748
|
+
// from CIE standard, which now defines these as a rational fraction
|
|
1749
|
+
white,
|
|
1750
|
+
base: XYZ_D50,
|
|
1751
|
+
// Convert D50-adapted XYX to Lab
|
|
1752
|
+
// CIE 15.3:2004 section 8.2.1.1
|
|
1753
|
+
fromBase(XYZ) {
|
|
1754
|
+
let xyz = XYZ.map((value, i2) => value / white[i2]);
|
|
1755
|
+
let f2 = xyz.map((value) => value > ε ? Math.cbrt(value) : (κ * value + 16) / 116);
|
|
1756
|
+
let L2 = 116 * f2[1] - 16;
|
|
1757
|
+
let a2 = 500 * (f2[0] - f2[1]);
|
|
1758
|
+
let b2 = 200 * (f2[1] - f2[2]);
|
|
1759
|
+
return [L2, a2, b2];
|
|
1760
|
+
},
|
|
1761
|
+
// Convert Lab to D50-adapted XYZ
|
|
1762
|
+
// Same result as CIE 15.3:2004 Appendix D although the derivation is different
|
|
1763
|
+
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
|
1764
|
+
toBase(Lab) {
|
|
1765
|
+
let [L2, a2, b2] = Lab;
|
|
1766
|
+
let f2 = [];
|
|
1767
|
+
f2[1] = (L2 + 16) / 116;
|
|
1768
|
+
f2[0] = a2 / 500 + f2[1];
|
|
1769
|
+
f2[2] = f2[1] - b2 / 200;
|
|
1770
|
+
let xyz = [
|
|
1771
|
+
f2[0] > ε3 ? Math.pow(f2[0], 3) : (116 * f2[0] - 16) / κ,
|
|
1772
|
+
Lab[0] > 8 ? Math.pow((Lab[0] + 16) / 116, 3) : Lab[0] / κ,
|
|
1773
|
+
f2[2] > ε3 ? Math.pow(f2[2], 3) : (116 * f2[2] - 16) / κ
|
|
1774
|
+
];
|
|
1775
|
+
return xyz.map((value, i2) => value * white[i2]);
|
|
1776
|
+
},
|
|
1777
|
+
formats: {
|
|
1778
|
+
lab: {
|
|
1779
|
+
coords: [
|
|
1780
|
+
"<percentage> | <number>",
|
|
1781
|
+
"<number> | <percentage>",
|
|
1782
|
+
"<number> | <percentage>"
|
|
1783
|
+
]
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
function constrain(angle) {
|
|
1788
|
+
if (typeof angle !== "number") {
|
|
1789
|
+
return angle;
|
|
1790
|
+
}
|
|
1791
|
+
return (angle % 360 + 360) % 360;
|
|
1792
|
+
}
|
|
1793
|
+
const lch = new ColorSpace({
|
|
1794
|
+
id: "lch",
|
|
1795
|
+
name: "LCH",
|
|
1796
|
+
coords: {
|
|
1797
|
+
l: {
|
|
1798
|
+
refRange: [0, 100],
|
|
1799
|
+
name: "Lightness"
|
|
1800
|
+
},
|
|
1801
|
+
c: {
|
|
1802
|
+
refRange: [0, 150],
|
|
1803
|
+
name: "Chroma"
|
|
1804
|
+
},
|
|
1805
|
+
h: {
|
|
1806
|
+
refRange: [0, 360],
|
|
1807
|
+
type: "angle",
|
|
1808
|
+
name: "Hue"
|
|
1809
|
+
}
|
|
1810
|
+
},
|
|
1811
|
+
base: lab,
|
|
1812
|
+
fromBase(Lab) {
|
|
1813
|
+
if (this.ε === void 0) {
|
|
1814
|
+
let range = Object.values(this.base.coords)[1].refRange;
|
|
1815
|
+
let extent = range[1] - range[0];
|
|
1816
|
+
this.ε = extent / 1e5;
|
|
1817
|
+
}
|
|
1818
|
+
let [L2, a2, b2] = Lab;
|
|
1819
|
+
let isAchromatic = Math.abs(a2) < this.ε && Math.abs(b2) < this.ε;
|
|
1820
|
+
let h7 = isAchromatic ? null : constrain(Math.atan2(b2, a2) * 180 / Math.PI);
|
|
1821
|
+
let C2 = isAchromatic ? 0 : Math.sqrt(a2 ** 2 + b2 ** 2);
|
|
1822
|
+
return [L2, C2, h7];
|
|
1823
|
+
},
|
|
1824
|
+
toBase(lch2) {
|
|
1825
|
+
let [L2, C2, h7] = lch2;
|
|
1826
|
+
let a2 = null, b2 = null;
|
|
1827
|
+
if (!isNone(h7)) {
|
|
1828
|
+
C2 = C2 < 0 ? 0 : C2;
|
|
1829
|
+
a2 = C2 * Math.cos(h7 * Math.PI / 180);
|
|
1830
|
+
b2 = C2 * Math.sin(h7 * Math.PI / 180);
|
|
1831
|
+
}
|
|
1832
|
+
return [L2, a2, b2];
|
|
1833
|
+
},
|
|
1834
|
+
formats: {
|
|
1835
|
+
lch: {
|
|
1836
|
+
coords: ["<percentage> | <number>", "<number> | <percentage>", "<number> | <angle>"]
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
});
|
|
1840
|
+
const XYZtoLMS_M = [
|
|
1841
|
+
[0.819022437996703, 0.3619062600528904, -0.1288737815209879],
|
|
1842
|
+
[0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
|
|
1843
|
+
[0.0481771893596242, 0.2642395317527308, 0.6335478284694309]
|
|
1844
|
+
];
|
|
1845
|
+
const LMStoXYZ_M = [
|
|
1846
|
+
[1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
|
|
1847
|
+
[-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
|
|
1848
|
+
[-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
|
|
1849
|
+
];
|
|
1850
|
+
const LMStoLab_M = [
|
|
1851
|
+
[0.210454268309314, 0.7936177747023054, -0.0040720430116193],
|
|
1852
|
+
[1.9779985324311684, -2.42859224204858, 0.450593709617411],
|
|
1853
|
+
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
|
|
1854
|
+
];
|
|
1855
|
+
const LabtoLMS_M = [
|
|
1856
|
+
[1, 0.3963377773761749, 0.2158037573099136],
|
|
1857
|
+
[1, -0.1055613458156586, -0.0638541728258133],
|
|
1858
|
+
[1, -0.0894841775298119, -1.2914855480194092]
|
|
1859
|
+
];
|
|
1860
|
+
const Oklab = new ColorSpace({
|
|
1861
|
+
id: "oklab",
|
|
1862
|
+
name: "Oklab",
|
|
1863
|
+
coords: {
|
|
1864
|
+
l: {
|
|
1865
|
+
refRange: [0, 1],
|
|
1866
|
+
name: "Lightness"
|
|
1867
|
+
},
|
|
1868
|
+
a: {
|
|
1869
|
+
refRange: [-0.4, 0.4]
|
|
1870
|
+
},
|
|
1871
|
+
b: {
|
|
1872
|
+
refRange: [-0.4, 0.4]
|
|
1873
|
+
}
|
|
1874
|
+
},
|
|
1875
|
+
// Note that XYZ is relative to D65
|
|
1876
|
+
white: "D65",
|
|
1877
|
+
base: xyz_d65,
|
|
1878
|
+
fromBase(XYZ) {
|
|
1879
|
+
let LMS = multiply_v3_m3x3(XYZ, XYZtoLMS_M);
|
|
1880
|
+
LMS[0] = Math.cbrt(LMS[0]);
|
|
1881
|
+
LMS[1] = Math.cbrt(LMS[1]);
|
|
1882
|
+
LMS[2] = Math.cbrt(LMS[2]);
|
|
1883
|
+
return multiply_v3_m3x3(LMS, LMStoLab_M, LMS);
|
|
1884
|
+
},
|
|
1885
|
+
toBase(OKLab) {
|
|
1886
|
+
let LMSg = multiply_v3_m3x3(OKLab, LabtoLMS_M);
|
|
1887
|
+
LMSg[0] = LMSg[0] ** 3;
|
|
1888
|
+
LMSg[1] = LMSg[1] ** 3;
|
|
1889
|
+
LMSg[2] = LMSg[2] ** 3;
|
|
1890
|
+
return multiply_v3_m3x3(LMSg, LMStoXYZ_M, LMSg);
|
|
1891
|
+
},
|
|
1892
|
+
formats: {
|
|
1893
|
+
oklab: {
|
|
1894
|
+
coords: [
|
|
1895
|
+
"<percentage> | <number>",
|
|
1896
|
+
"<number> | <percentage>",
|
|
1897
|
+
"<number> | <percentage>"
|
|
1898
|
+
]
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
const toXYZ_M$4 = [
|
|
1903
|
+
[0.6369580483012914, 0.14461690358620832, 0.1688809751641721],
|
|
1904
|
+
[0.2627002120112671, 0.6779980715188708, 0.05930171646986196],
|
|
1905
|
+
[0, 0.028072693049087428, 1.060985057710791]
|
|
1906
|
+
];
|
|
1907
|
+
const fromXYZ_M$4 = [
|
|
1908
|
+
[1.716651187971268, -0.355670783776392, -0.25336628137366],
|
|
1909
|
+
[-0.666684351832489, 1.616481236634939, 0.0157685458139111],
|
|
1910
|
+
[0.017639857445311, -0.042770613257809, 0.942103121235474]
|
|
1911
|
+
];
|
|
1912
|
+
const REC_2020_Linear = new RGBColorSpace({
|
|
1913
|
+
id: "rec2020-linear",
|
|
1914
|
+
cssId: "--rec2020-linear",
|
|
1915
|
+
name: "Linear REC.2020",
|
|
1916
|
+
white: "D65",
|
|
1917
|
+
toXYZ_M: toXYZ_M$4,
|
|
1918
|
+
fromXYZ_M: fromXYZ_M$4
|
|
1919
|
+
});
|
|
1920
|
+
const REC2020 = new RGBColorSpace({
|
|
1921
|
+
id: "rec2020",
|
|
1922
|
+
name: "REC.2020",
|
|
1923
|
+
base: REC_2020_Linear,
|
|
1924
|
+
// Reference electro-optical transfer function from Rec. ITU-R BT.1886 Annex 1
|
|
1925
|
+
// with b (black lift) = 0 and a (user gain) = 1
|
|
1926
|
+
// defined over the extended range, not clamped
|
|
1927
|
+
toBase(RGB) {
|
|
1928
|
+
return RGB.map(function(val) {
|
|
1929
|
+
let sign = val < 0 ? -1 : 1;
|
|
1930
|
+
let abs = val * sign;
|
|
1931
|
+
return sign * Math.pow(abs, 2.4);
|
|
1932
|
+
});
|
|
1933
|
+
},
|
|
1934
|
+
fromBase(RGB) {
|
|
1935
|
+
return RGB.map(function(val) {
|
|
1936
|
+
let sign = val < 0 ? -1 : 1;
|
|
1937
|
+
let abs = val * sign;
|
|
1938
|
+
return sign * Math.pow(abs, 1 / 2.4);
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
const toXYZ_M$3 = [
|
|
1943
|
+
[0.4865709486482162, 0.26566769316909306, 0.1982172852343625],
|
|
1944
|
+
[0.2289745640697488, 0.6917385218365064, 0.079286914093745],
|
|
1945
|
+
[0, 0.04511338185890264, 1.043944368900976]
|
|
1946
|
+
];
|
|
1947
|
+
const fromXYZ_M$3 = [
|
|
1948
|
+
[2.493496911941425, -0.9313836179191239, -0.40271078445071684],
|
|
1949
|
+
[-0.8294889695615747, 1.7626640603183463, 0.023624685841943577],
|
|
1950
|
+
[0.03584583024378447, -0.07617238926804182, 0.9568845240076872]
|
|
1951
|
+
];
|
|
1952
|
+
const P3Linear = new RGBColorSpace({
|
|
1953
|
+
id: "p3-linear",
|
|
1954
|
+
cssId: "display-p3-linear",
|
|
1955
|
+
name: "Linear P3",
|
|
1956
|
+
white: "D65",
|
|
1957
|
+
toXYZ_M: toXYZ_M$3,
|
|
1958
|
+
fromXYZ_M: fromXYZ_M$3
|
|
1959
|
+
});
|
|
1960
|
+
const toXYZ_M$2 = [
|
|
1961
|
+
[0.41239079926595934, 0.357584339383878, 0.1804807884018343],
|
|
1962
|
+
[0.21263900587151027, 0.715168678767756, 0.07219231536073371],
|
|
1963
|
+
[0.01933081871559182, 0.11919477979462598, 0.9505321522496607]
|
|
1964
|
+
];
|
|
1965
|
+
const fromXYZ_M$2 = [
|
|
1966
|
+
[3.2409699419045226, -1.537383177570094, -0.4986107602930034],
|
|
1967
|
+
[-0.9692436362808796, 1.8759675015077202, 0.04155505740717559],
|
|
1968
|
+
[0.05563007969699366, -0.20397695888897652, 1.0569715142428786]
|
|
1969
|
+
];
|
|
1970
|
+
const sRGBLinear = new RGBColorSpace({
|
|
1971
|
+
id: "srgb-linear",
|
|
1972
|
+
name: "Linear sRGB",
|
|
1973
|
+
white: "D65",
|
|
1974
|
+
toXYZ_M: toXYZ_M$2,
|
|
1975
|
+
fromXYZ_M: fromXYZ_M$2
|
|
1976
|
+
});
|
|
1977
|
+
const KEYWORDS = {
|
|
1978
|
+
aliceblue: [240 / 255, 248 / 255, 1],
|
|
1979
|
+
antiquewhite: [250 / 255, 235 / 255, 215 / 255],
|
|
1980
|
+
aqua: [0, 1, 1],
|
|
1981
|
+
aquamarine: [127 / 255, 1, 212 / 255],
|
|
1982
|
+
azure: [240 / 255, 1, 1],
|
|
1983
|
+
beige: [245 / 255, 245 / 255, 220 / 255],
|
|
1984
|
+
bisque: [1, 228 / 255, 196 / 255],
|
|
1985
|
+
black: [0, 0, 0],
|
|
1986
|
+
blanchedalmond: [1, 235 / 255, 205 / 255],
|
|
1987
|
+
blue: [0, 0, 1],
|
|
1988
|
+
blueviolet: [138 / 255, 43 / 255, 226 / 255],
|
|
1989
|
+
brown: [165 / 255, 42 / 255, 42 / 255],
|
|
1990
|
+
burlywood: [222 / 255, 184 / 255, 135 / 255],
|
|
1991
|
+
cadetblue: [95 / 255, 158 / 255, 160 / 255],
|
|
1992
|
+
chartreuse: [127 / 255, 1, 0],
|
|
1993
|
+
chocolate: [210 / 255, 105 / 255, 30 / 255],
|
|
1994
|
+
coral: [1, 127 / 255, 80 / 255],
|
|
1995
|
+
cornflowerblue: [100 / 255, 149 / 255, 237 / 255],
|
|
1996
|
+
cornsilk: [1, 248 / 255, 220 / 255],
|
|
1997
|
+
crimson: [220 / 255, 20 / 255, 60 / 255],
|
|
1998
|
+
cyan: [0, 1, 1],
|
|
1999
|
+
darkblue: [0, 0, 139 / 255],
|
|
2000
|
+
darkcyan: [0, 139 / 255, 139 / 255],
|
|
2001
|
+
darkgoldenrod: [184 / 255, 134 / 255, 11 / 255],
|
|
2002
|
+
darkgray: [169 / 255, 169 / 255, 169 / 255],
|
|
2003
|
+
darkgreen: [0, 100 / 255, 0],
|
|
2004
|
+
darkgrey: [169 / 255, 169 / 255, 169 / 255],
|
|
2005
|
+
darkkhaki: [189 / 255, 183 / 255, 107 / 255],
|
|
2006
|
+
darkmagenta: [139 / 255, 0, 139 / 255],
|
|
2007
|
+
darkolivegreen: [85 / 255, 107 / 255, 47 / 255],
|
|
2008
|
+
darkorange: [1, 140 / 255, 0],
|
|
2009
|
+
darkorchid: [153 / 255, 50 / 255, 204 / 255],
|
|
2010
|
+
darkred: [139 / 255, 0, 0],
|
|
2011
|
+
darksalmon: [233 / 255, 150 / 255, 122 / 255],
|
|
2012
|
+
darkseagreen: [143 / 255, 188 / 255, 143 / 255],
|
|
2013
|
+
darkslateblue: [72 / 255, 61 / 255, 139 / 255],
|
|
2014
|
+
darkslategray: [47 / 255, 79 / 255, 79 / 255],
|
|
2015
|
+
darkslategrey: [47 / 255, 79 / 255, 79 / 255],
|
|
2016
|
+
darkturquoise: [0, 206 / 255, 209 / 255],
|
|
2017
|
+
darkviolet: [148 / 255, 0, 211 / 255],
|
|
2018
|
+
deeppink: [1, 20 / 255, 147 / 255],
|
|
2019
|
+
deepskyblue: [0, 191 / 255, 1],
|
|
2020
|
+
dimgray: [105 / 255, 105 / 255, 105 / 255],
|
|
2021
|
+
dimgrey: [105 / 255, 105 / 255, 105 / 255],
|
|
2022
|
+
dodgerblue: [30 / 255, 144 / 255, 1],
|
|
2023
|
+
firebrick: [178 / 255, 34 / 255, 34 / 255],
|
|
2024
|
+
floralwhite: [1, 250 / 255, 240 / 255],
|
|
2025
|
+
forestgreen: [34 / 255, 139 / 255, 34 / 255],
|
|
2026
|
+
fuchsia: [1, 0, 1],
|
|
2027
|
+
gainsboro: [220 / 255, 220 / 255, 220 / 255],
|
|
2028
|
+
ghostwhite: [248 / 255, 248 / 255, 1],
|
|
2029
|
+
gold: [1, 215 / 255, 0],
|
|
2030
|
+
goldenrod: [218 / 255, 165 / 255, 32 / 255],
|
|
2031
|
+
gray: [128 / 255, 128 / 255, 128 / 255],
|
|
2032
|
+
green: [0, 128 / 255, 0],
|
|
2033
|
+
greenyellow: [173 / 255, 1, 47 / 255],
|
|
2034
|
+
grey: [128 / 255, 128 / 255, 128 / 255],
|
|
2035
|
+
honeydew: [240 / 255, 1, 240 / 255],
|
|
2036
|
+
hotpink: [1, 105 / 255, 180 / 255],
|
|
2037
|
+
indianred: [205 / 255, 92 / 255, 92 / 255],
|
|
2038
|
+
indigo: [75 / 255, 0, 130 / 255],
|
|
2039
|
+
ivory: [1, 1, 240 / 255],
|
|
2040
|
+
khaki: [240 / 255, 230 / 255, 140 / 255],
|
|
2041
|
+
lavender: [230 / 255, 230 / 255, 250 / 255],
|
|
2042
|
+
lavenderblush: [1, 240 / 255, 245 / 255],
|
|
2043
|
+
lawngreen: [124 / 255, 252 / 255, 0],
|
|
2044
|
+
lemonchiffon: [1, 250 / 255, 205 / 255],
|
|
2045
|
+
lightblue: [173 / 255, 216 / 255, 230 / 255],
|
|
2046
|
+
lightcoral: [240 / 255, 128 / 255, 128 / 255],
|
|
2047
|
+
lightcyan: [224 / 255, 1, 1],
|
|
2048
|
+
lightgoldenrodyellow: [250 / 255, 250 / 255, 210 / 255],
|
|
2049
|
+
lightgray: [211 / 255, 211 / 255, 211 / 255],
|
|
2050
|
+
lightgreen: [144 / 255, 238 / 255, 144 / 255],
|
|
2051
|
+
lightgrey: [211 / 255, 211 / 255, 211 / 255],
|
|
2052
|
+
lightpink: [1, 182 / 255, 193 / 255],
|
|
2053
|
+
lightsalmon: [1, 160 / 255, 122 / 255],
|
|
2054
|
+
lightseagreen: [32 / 255, 178 / 255, 170 / 255],
|
|
2055
|
+
lightskyblue: [135 / 255, 206 / 255, 250 / 255],
|
|
2056
|
+
lightslategray: [119 / 255, 136 / 255, 153 / 255],
|
|
2057
|
+
lightslategrey: [119 / 255, 136 / 255, 153 / 255],
|
|
2058
|
+
lightsteelblue: [176 / 255, 196 / 255, 222 / 255],
|
|
2059
|
+
lightyellow: [1, 1, 224 / 255],
|
|
2060
|
+
lime: [0, 1, 0],
|
|
2061
|
+
limegreen: [50 / 255, 205 / 255, 50 / 255],
|
|
2062
|
+
linen: [250 / 255, 240 / 255, 230 / 255],
|
|
2063
|
+
magenta: [1, 0, 1],
|
|
2064
|
+
maroon: [128 / 255, 0, 0],
|
|
2065
|
+
mediumaquamarine: [102 / 255, 205 / 255, 170 / 255],
|
|
2066
|
+
mediumblue: [0, 0, 205 / 255],
|
|
2067
|
+
mediumorchid: [186 / 255, 85 / 255, 211 / 255],
|
|
2068
|
+
mediumpurple: [147 / 255, 112 / 255, 219 / 255],
|
|
2069
|
+
mediumseagreen: [60 / 255, 179 / 255, 113 / 255],
|
|
2070
|
+
mediumslateblue: [123 / 255, 104 / 255, 238 / 255],
|
|
2071
|
+
mediumspringgreen: [0, 250 / 255, 154 / 255],
|
|
2072
|
+
mediumturquoise: [72 / 255, 209 / 255, 204 / 255],
|
|
2073
|
+
mediumvioletred: [199 / 255, 21 / 255, 133 / 255],
|
|
2074
|
+
midnightblue: [25 / 255, 25 / 255, 112 / 255],
|
|
2075
|
+
mintcream: [245 / 255, 1, 250 / 255],
|
|
2076
|
+
mistyrose: [1, 228 / 255, 225 / 255],
|
|
2077
|
+
moccasin: [1, 228 / 255, 181 / 255],
|
|
2078
|
+
navajowhite: [1, 222 / 255, 173 / 255],
|
|
2079
|
+
navy: [0, 0, 128 / 255],
|
|
2080
|
+
oldlace: [253 / 255, 245 / 255, 230 / 255],
|
|
2081
|
+
olive: [128 / 255, 128 / 255, 0],
|
|
2082
|
+
olivedrab: [107 / 255, 142 / 255, 35 / 255],
|
|
2083
|
+
orange: [1, 165 / 255, 0],
|
|
2084
|
+
orangered: [1, 69 / 255, 0],
|
|
2085
|
+
orchid: [218 / 255, 112 / 255, 214 / 255],
|
|
2086
|
+
palegoldenrod: [238 / 255, 232 / 255, 170 / 255],
|
|
2087
|
+
palegreen: [152 / 255, 251 / 255, 152 / 255],
|
|
2088
|
+
paleturquoise: [175 / 255, 238 / 255, 238 / 255],
|
|
2089
|
+
palevioletred: [219 / 255, 112 / 255, 147 / 255],
|
|
2090
|
+
papayawhip: [1, 239 / 255, 213 / 255],
|
|
2091
|
+
peachpuff: [1, 218 / 255, 185 / 255],
|
|
2092
|
+
peru: [205 / 255, 133 / 255, 63 / 255],
|
|
2093
|
+
pink: [1, 192 / 255, 203 / 255],
|
|
2094
|
+
plum: [221 / 255, 160 / 255, 221 / 255],
|
|
2095
|
+
powderblue: [176 / 255, 224 / 255, 230 / 255],
|
|
2096
|
+
purple: [128 / 255, 0, 128 / 255],
|
|
2097
|
+
rebeccapurple: [102 / 255, 51 / 255, 153 / 255],
|
|
2098
|
+
red: [1, 0, 0],
|
|
2099
|
+
rosybrown: [188 / 255, 143 / 255, 143 / 255],
|
|
2100
|
+
royalblue: [65 / 255, 105 / 255, 225 / 255],
|
|
2101
|
+
saddlebrown: [139 / 255, 69 / 255, 19 / 255],
|
|
2102
|
+
salmon: [250 / 255, 128 / 255, 114 / 255],
|
|
2103
|
+
sandybrown: [244 / 255, 164 / 255, 96 / 255],
|
|
2104
|
+
seagreen: [46 / 255, 139 / 255, 87 / 255],
|
|
2105
|
+
seashell: [1, 245 / 255, 238 / 255],
|
|
2106
|
+
sienna: [160 / 255, 82 / 255, 45 / 255],
|
|
2107
|
+
silver: [192 / 255, 192 / 255, 192 / 255],
|
|
2108
|
+
skyblue: [135 / 255, 206 / 255, 235 / 255],
|
|
2109
|
+
slateblue: [106 / 255, 90 / 255, 205 / 255],
|
|
2110
|
+
slategray: [112 / 255, 128 / 255, 144 / 255],
|
|
2111
|
+
slategrey: [112 / 255, 128 / 255, 144 / 255],
|
|
2112
|
+
snow: [1, 250 / 255, 250 / 255],
|
|
2113
|
+
springgreen: [0, 1, 127 / 255],
|
|
2114
|
+
steelblue: [70 / 255, 130 / 255, 180 / 255],
|
|
2115
|
+
tan: [210 / 255, 180 / 255, 140 / 255],
|
|
2116
|
+
teal: [0, 128 / 255, 128 / 255],
|
|
2117
|
+
thistle: [216 / 255, 191 / 255, 216 / 255],
|
|
2118
|
+
tomato: [1, 99 / 255, 71 / 255],
|
|
2119
|
+
turquoise: [64 / 255, 224 / 255, 208 / 255],
|
|
2120
|
+
violet: [238 / 255, 130 / 255, 238 / 255],
|
|
2121
|
+
wheat: [245 / 255, 222 / 255, 179 / 255],
|
|
2122
|
+
white: [1, 1, 1],
|
|
2123
|
+
whitesmoke: [245 / 255, 245 / 255, 245 / 255],
|
|
2124
|
+
yellow: [1, 1, 0],
|
|
2125
|
+
yellowgreen: [154 / 255, 205 / 255, 50 / 255]
|
|
2126
|
+
};
|
|
2127
|
+
let coordGrammar = Array(3).fill("<percentage> | <number>[0, 255]");
|
|
2128
|
+
let coordGrammarNumber = Array(3).fill("<number>[0, 255]");
|
|
2129
|
+
const sRGB = new RGBColorSpace({
|
|
2130
|
+
id: "srgb",
|
|
2131
|
+
name: "sRGB",
|
|
2132
|
+
base: sRGBLinear,
|
|
2133
|
+
fromBase: (rgb) => {
|
|
2134
|
+
return rgb.map((val) => {
|
|
2135
|
+
let sign = val < 0 ? -1 : 1;
|
|
2136
|
+
let abs = val * sign;
|
|
2137
|
+
if (abs > 31308e-7) {
|
|
2138
|
+
return sign * (1.055 * abs ** (1 / 2.4) - 0.055);
|
|
2139
|
+
}
|
|
2140
|
+
return 12.92 * val;
|
|
2141
|
+
});
|
|
2142
|
+
},
|
|
2143
|
+
toBase: (rgb) => {
|
|
2144
|
+
return rgb.map((val) => {
|
|
2145
|
+
let sign = val < 0 ? -1 : 1;
|
|
2146
|
+
let abs = val * sign;
|
|
2147
|
+
if (abs <= 0.04045) {
|
|
2148
|
+
return val / 12.92;
|
|
2149
|
+
}
|
|
2150
|
+
return sign * ((abs + 0.055) / 1.055) ** 2.4;
|
|
2151
|
+
});
|
|
2152
|
+
},
|
|
2153
|
+
formats: {
|
|
2154
|
+
rgb: {
|
|
2155
|
+
coords: coordGrammar
|
|
2156
|
+
},
|
|
2157
|
+
rgb_number: {
|
|
2158
|
+
name: "rgb",
|
|
2159
|
+
commas: true,
|
|
2160
|
+
coords: coordGrammarNumber,
|
|
2161
|
+
alpha: false
|
|
2162
|
+
},
|
|
2163
|
+
color: {
|
|
2164
|
+
/* use defaults */
|
|
2165
|
+
},
|
|
2166
|
+
rgba: {
|
|
2167
|
+
coords: coordGrammar,
|
|
2168
|
+
commas: true,
|
|
2169
|
+
alpha: true
|
|
2170
|
+
},
|
|
2171
|
+
rgba_number: {
|
|
2172
|
+
name: "rgba",
|
|
2173
|
+
commas: true,
|
|
2174
|
+
coords: coordGrammarNumber
|
|
2175
|
+
},
|
|
2176
|
+
hex: {
|
|
2177
|
+
type: "custom",
|
|
2178
|
+
toGamut: true,
|
|
2179
|
+
test: (str) => /^#(([a-f0-9]{2}){3,4}|[a-f0-9]{3,4})$/i.test(str),
|
|
2180
|
+
parse(str) {
|
|
2181
|
+
if (str.length <= 5) {
|
|
2182
|
+
str = str.replace(/[a-f0-9]/gi, "$&$&");
|
|
2183
|
+
}
|
|
2184
|
+
let rgba = [];
|
|
2185
|
+
str.replace(/[a-f0-9]{2}/gi, (component) => {
|
|
2186
|
+
rgba.push(parseInt(component, 16) / 255);
|
|
2187
|
+
});
|
|
2188
|
+
return {
|
|
2189
|
+
spaceId: "srgb",
|
|
2190
|
+
coords: (
|
|
2191
|
+
/** @type {Coords} */
|
|
2192
|
+
rgba.slice(0, 3)
|
|
2193
|
+
),
|
|
2194
|
+
alpha: (
|
|
2195
|
+
/** @type {number} */
|
|
2196
|
+
rgba.slice(3)[0]
|
|
2197
|
+
)
|
|
2198
|
+
};
|
|
2199
|
+
},
|
|
2200
|
+
serialize: (coords, alpha, {
|
|
2201
|
+
collapse = true,
|
|
2202
|
+
// collapse to 3-4 digit hex when possible?
|
|
2203
|
+
alpha: alphaFormat
|
|
2204
|
+
} = {}) => {
|
|
2205
|
+
if (alphaFormat !== false && alpha < 1 || alphaFormat === true) {
|
|
2206
|
+
coords.push(alpha);
|
|
2207
|
+
}
|
|
2208
|
+
coords = /** @type {[number, number, number]} */
|
|
2209
|
+
coords.map((c2) => Math.round(c2 * 255));
|
|
2210
|
+
let collapsible = collapse && coords.every((c2) => c2 % 17 === 0);
|
|
2211
|
+
let hex = coords.map((c2) => {
|
|
2212
|
+
if (collapsible) {
|
|
2213
|
+
return (c2 / 17).toString(16);
|
|
2214
|
+
}
|
|
2215
|
+
return c2.toString(16).padStart(2, "0");
|
|
2216
|
+
}).join("");
|
|
2217
|
+
return "#" + hex;
|
|
2218
|
+
}
|
|
2219
|
+
},
|
|
2220
|
+
keyword: {
|
|
2221
|
+
type: "custom",
|
|
2222
|
+
test: (str) => /^[a-z]+$/i.test(str),
|
|
2223
|
+
parse(str) {
|
|
2224
|
+
str = str.toLowerCase();
|
|
2225
|
+
let ret = { spaceId: "srgb", coords: null, alpha: 1 };
|
|
2226
|
+
if (str === "transparent") {
|
|
2227
|
+
ret.coords = KEYWORDS.black;
|
|
2228
|
+
ret.alpha = 0;
|
|
2229
|
+
} else {
|
|
2230
|
+
ret.coords = KEYWORDS[str];
|
|
2231
|
+
}
|
|
2232
|
+
if (ret.coords) {
|
|
2233
|
+
return ret;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
const P3 = new RGBColorSpace({
|
|
2240
|
+
id: "p3",
|
|
2241
|
+
cssId: "display-p3",
|
|
2242
|
+
name: "P3",
|
|
2243
|
+
base: P3Linear,
|
|
2244
|
+
// Gamma encoding/decoding is the same as sRGB
|
|
2245
|
+
fromBase: sRGB.fromBase,
|
|
2246
|
+
toBase: sRGB.toBase
|
|
2247
|
+
});
|
|
2248
|
+
const hsl = new ColorSpace({
|
|
2249
|
+
id: "hsl",
|
|
2250
|
+
name: "HSL",
|
|
2251
|
+
coords: {
|
|
2252
|
+
h: {
|
|
2253
|
+
refRange: [0, 360],
|
|
2254
|
+
type: "angle",
|
|
2255
|
+
name: "Hue"
|
|
2256
|
+
},
|
|
2257
|
+
s: {
|
|
2258
|
+
range: [0, 100],
|
|
2259
|
+
name: "Saturation"
|
|
2260
|
+
},
|
|
2261
|
+
l: {
|
|
2262
|
+
range: [0, 100],
|
|
2263
|
+
name: "Lightness"
|
|
2264
|
+
}
|
|
2265
|
+
},
|
|
2266
|
+
base: sRGB,
|
|
2267
|
+
// Adapted from https://drafts.csswg.org/css-color-4/better-rgbToHsl.js
|
|
2268
|
+
fromBase: (rgb) => {
|
|
2269
|
+
let max = Math.max(...rgb);
|
|
2270
|
+
let min = Math.min(...rgb);
|
|
2271
|
+
let [r2, g2, b2] = rgb;
|
|
2272
|
+
let [h7, s2, l2] = [null, 0, (min + max) / 2];
|
|
2273
|
+
let d2 = max - min;
|
|
2274
|
+
if (d2 !== 0) {
|
|
2275
|
+
s2 = l2 === 0 || l2 === 1 ? 0 : (max - l2) / Math.min(l2, 1 - l2);
|
|
2276
|
+
switch (max) {
|
|
2277
|
+
case r2:
|
|
2278
|
+
h7 = (g2 - b2) / d2 + (g2 < b2 ? 6 : 0);
|
|
2279
|
+
break;
|
|
2280
|
+
case g2:
|
|
2281
|
+
h7 = (b2 - r2) / d2 + 2;
|
|
2282
|
+
break;
|
|
2283
|
+
case b2:
|
|
2284
|
+
h7 = (r2 - g2) / d2 + 4;
|
|
2285
|
+
}
|
|
2286
|
+
h7 = h7 * 60;
|
|
2287
|
+
}
|
|
2288
|
+
if (s2 < 0) {
|
|
2289
|
+
h7 += 180;
|
|
2290
|
+
s2 = Math.abs(s2);
|
|
2291
|
+
}
|
|
2292
|
+
if (h7 >= 360) {
|
|
2293
|
+
h7 -= 360;
|
|
2294
|
+
}
|
|
2295
|
+
return [h7, s2 * 100, l2 * 100];
|
|
2296
|
+
},
|
|
2297
|
+
// Adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
|
|
2298
|
+
toBase: (hsl2) => {
|
|
2299
|
+
let [h7, s2, l2] = hsl2;
|
|
2300
|
+
h7 = h7 % 360;
|
|
2301
|
+
if (h7 < 0) {
|
|
2302
|
+
h7 += 360;
|
|
2303
|
+
}
|
|
2304
|
+
s2 /= 100;
|
|
2305
|
+
l2 /= 100;
|
|
2306
|
+
function f2(n2) {
|
|
2307
|
+
let k2 = (n2 + h7 / 30) % 12;
|
|
2308
|
+
let a2 = s2 * Math.min(l2, 1 - l2);
|
|
2309
|
+
return l2 - a2 * Math.max(-1, Math.min(k2 - 3, 9 - k2, 1));
|
|
2310
|
+
}
|
|
2311
|
+
return [f2(0), f2(8), f2(4)];
|
|
2312
|
+
},
|
|
2313
|
+
formats: {
|
|
2314
|
+
hsl: {
|
|
2315
|
+
coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"]
|
|
2316
|
+
},
|
|
2317
|
+
hsla: {
|
|
2318
|
+
coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"],
|
|
2319
|
+
commas: true,
|
|
2320
|
+
alpha: true
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
2324
|
+
const HSV = new ColorSpace({
|
|
2325
|
+
id: "hsv",
|
|
2326
|
+
name: "HSV",
|
|
2327
|
+
coords: {
|
|
2328
|
+
h: {
|
|
2329
|
+
refRange: [0, 360],
|
|
2330
|
+
type: "angle",
|
|
2331
|
+
name: "Hue"
|
|
2332
|
+
},
|
|
2333
|
+
s: {
|
|
2334
|
+
range: [0, 100],
|
|
2335
|
+
name: "Saturation"
|
|
2336
|
+
},
|
|
2337
|
+
v: {
|
|
2338
|
+
range: [0, 100],
|
|
2339
|
+
name: "Value"
|
|
2340
|
+
}
|
|
2341
|
+
},
|
|
2342
|
+
base: sRGB,
|
|
2343
|
+
// https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation
|
|
2344
|
+
fromBase(rgb) {
|
|
2345
|
+
let max = Math.max(...rgb);
|
|
2346
|
+
let min = Math.min(...rgb);
|
|
2347
|
+
let [r2, g2, b2] = rgb;
|
|
2348
|
+
let [h7, s2, v2] = [null, 0, max];
|
|
2349
|
+
let d2 = max - min;
|
|
2350
|
+
if (d2 !== 0) {
|
|
2351
|
+
switch (max) {
|
|
2352
|
+
case r2:
|
|
2353
|
+
h7 = (g2 - b2) / d2 + (g2 < b2 ? 6 : 0);
|
|
2354
|
+
break;
|
|
2355
|
+
case g2:
|
|
2356
|
+
h7 = (b2 - r2) / d2 + 2;
|
|
2357
|
+
break;
|
|
2358
|
+
case b2:
|
|
2359
|
+
h7 = (r2 - g2) / d2 + 4;
|
|
2360
|
+
}
|
|
2361
|
+
h7 = h7 * 60;
|
|
2362
|
+
}
|
|
2363
|
+
if (v2) {
|
|
2364
|
+
s2 = d2 / v2;
|
|
2365
|
+
}
|
|
2366
|
+
if (h7 >= 360) {
|
|
2367
|
+
h7 -= 360;
|
|
2368
|
+
}
|
|
2369
|
+
return [h7, s2 * 100, v2 * 100];
|
|
2370
|
+
},
|
|
2371
|
+
// Adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative
|
|
2372
|
+
toBase(hsv) {
|
|
2373
|
+
let [h7, s2, v2] = hsv;
|
|
2374
|
+
h7 = h7 % 360;
|
|
2375
|
+
if (h7 < 0) {
|
|
2376
|
+
h7 += 360;
|
|
2377
|
+
}
|
|
2378
|
+
s2 /= 100;
|
|
2379
|
+
v2 /= 100;
|
|
2380
|
+
function f2(n2) {
|
|
2381
|
+
let k2 = (n2 + h7 / 60) % 6;
|
|
2382
|
+
return v2 - v2 * s2 * Math.max(0, Math.min(k2, 4 - k2, 1));
|
|
2383
|
+
}
|
|
2384
|
+
return [f2(5), f2(3), f2(1)];
|
|
2385
|
+
},
|
|
2386
|
+
formats: {
|
|
2387
|
+
color: {
|
|
2388
|
+
id: "--hsv",
|
|
2389
|
+
coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"]
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
});
|
|
2393
|
+
const hwb = new ColorSpace({
|
|
2394
|
+
id: "hwb",
|
|
2395
|
+
name: "HWB",
|
|
2396
|
+
coords: {
|
|
2397
|
+
h: {
|
|
2398
|
+
refRange: [0, 360],
|
|
2399
|
+
type: "angle",
|
|
2400
|
+
name: "Hue"
|
|
2401
|
+
},
|
|
2402
|
+
w: {
|
|
2403
|
+
range: [0, 100],
|
|
2404
|
+
name: "Whiteness"
|
|
2405
|
+
},
|
|
2406
|
+
b: {
|
|
2407
|
+
range: [0, 100],
|
|
2408
|
+
name: "Blackness"
|
|
2409
|
+
}
|
|
2410
|
+
},
|
|
2411
|
+
base: HSV,
|
|
2412
|
+
fromBase(hsv) {
|
|
2413
|
+
let [h7, s2, v2] = hsv;
|
|
2414
|
+
return [h7, v2 * (100 - s2) / 100, 100 - v2];
|
|
2415
|
+
},
|
|
2416
|
+
toBase(hwb2) {
|
|
2417
|
+
let [h7, w2, b2] = hwb2;
|
|
2418
|
+
w2 /= 100;
|
|
2419
|
+
b2 /= 100;
|
|
2420
|
+
let sum = w2 + b2;
|
|
2421
|
+
if (sum >= 1) {
|
|
2422
|
+
let gray = w2 / sum;
|
|
2423
|
+
return [h7, 0, gray * 100];
|
|
2424
|
+
}
|
|
2425
|
+
let v2 = 1 - b2;
|
|
2426
|
+
let s2 = v2 === 0 ? 0 : 1 - w2 / v2;
|
|
2427
|
+
return [h7, s2 * 100, v2 * 100];
|
|
2428
|
+
},
|
|
2429
|
+
formats: {
|
|
2430
|
+
hwb: {
|
|
2431
|
+
coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"]
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2435
|
+
const toXYZ_M$1 = [
|
|
2436
|
+
[0.5766690429101305, 0.1855582379065463, 0.1882286462349947],
|
|
2437
|
+
[0.29734497525053605, 0.6273635662554661, 0.07529145849399788],
|
|
2438
|
+
[0.02703136138641234, 0.07068885253582723, 0.9913375368376388]
|
|
2439
|
+
];
|
|
2440
|
+
const fromXYZ_M$1 = [
|
|
2441
|
+
[2.0415879038107465, -0.5650069742788596, -0.34473135077832956],
|
|
2442
|
+
[-0.9692436362808795, 1.8759675015077202, 0.04155505740717557],
|
|
2443
|
+
[0.013444280632031142, -0.11836239223101838, 1.0151749943912054]
|
|
2444
|
+
];
|
|
2445
|
+
const A98Linear = new RGBColorSpace({
|
|
2446
|
+
id: "a98rgb-linear",
|
|
2447
|
+
cssId: "--a98-rgb-linear",
|
|
2448
|
+
name: "Linear Adobe® 98 RGB compatible",
|
|
2449
|
+
white: "D65",
|
|
2450
|
+
toXYZ_M: toXYZ_M$1,
|
|
2451
|
+
fromXYZ_M: fromXYZ_M$1
|
|
2452
|
+
});
|
|
2453
|
+
const a98rgb = new RGBColorSpace({
|
|
2454
|
+
id: "a98rgb",
|
|
2455
|
+
cssId: "a98-rgb",
|
|
2456
|
+
name: "Adobe® 98 RGB compatible",
|
|
2457
|
+
base: A98Linear,
|
|
2458
|
+
toBase: (RGB) => RGB.map((val) => Math.pow(Math.abs(val), 563 / 256) * Math.sign(val)),
|
|
2459
|
+
fromBase: (RGB) => RGB.map((val) => Math.pow(Math.abs(val), 256 / 563) * Math.sign(val))
|
|
2460
|
+
});
|
|
2461
|
+
const toXYZ_M = [
|
|
2462
|
+
[0.7977666449006423, 0.13518129740053308, 0.0313477341283922],
|
|
2463
|
+
[0.2880748288194013, 0.711835234241873, 8993693872564e-17],
|
|
2464
|
+
[0, 0, 0.8251046025104602]
|
|
2465
|
+
];
|
|
2466
|
+
const fromXYZ_M = [
|
|
2467
|
+
[1.3457868816471583, -0.25557208737979464, -0.05110186497554526],
|
|
2468
|
+
[-0.5446307051249019, 1.5082477428451468, 0.02052744743642139],
|
|
2469
|
+
[0, 0, 1.2119675456389452]
|
|
2470
|
+
];
|
|
2471
|
+
const ProPhotoLinear = new RGBColorSpace({
|
|
2472
|
+
id: "prophoto-linear",
|
|
2473
|
+
cssId: "--prophoto-rgb-linear",
|
|
2474
|
+
name: "Linear ProPhoto",
|
|
2475
|
+
white: "D50",
|
|
2476
|
+
base: XYZ_D50,
|
|
2477
|
+
toXYZ_M,
|
|
2478
|
+
fromXYZ_M
|
|
2479
|
+
});
|
|
2480
|
+
const Et = 1 / 512;
|
|
2481
|
+
const Et2 = 16 / 512;
|
|
2482
|
+
const prophoto = new RGBColorSpace({
|
|
2483
|
+
id: "prophoto",
|
|
2484
|
+
cssId: "prophoto-rgb",
|
|
2485
|
+
name: "ProPhoto",
|
|
2486
|
+
base: ProPhotoLinear,
|
|
2487
|
+
toBase(RGB) {
|
|
2488
|
+
return RGB.map((v2) => {
|
|
2489
|
+
let sign = v2 < 0 ? -1 : 1;
|
|
2490
|
+
let abs = v2 * sign;
|
|
2491
|
+
if (abs < Et2) {
|
|
2492
|
+
return v2 / 16;
|
|
2493
|
+
}
|
|
2494
|
+
return sign * abs ** 1.8;
|
|
2495
|
+
});
|
|
2496
|
+
},
|
|
2497
|
+
fromBase(RGB) {
|
|
2498
|
+
return RGB.map((v2) => {
|
|
2499
|
+
let sign = v2 < 0 ? -1 : 1;
|
|
2500
|
+
let abs = v2 * sign;
|
|
2501
|
+
if (abs >= Et) {
|
|
2502
|
+
return sign * abs ** (1 / 1.8);
|
|
2503
|
+
}
|
|
2504
|
+
return 16 * v2;
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
const oklch = new ColorSpace({
|
|
2509
|
+
id: "oklch",
|
|
2510
|
+
name: "OkLCh",
|
|
2511
|
+
coords: {
|
|
2512
|
+
l: {
|
|
2513
|
+
refRange: [0, 1],
|
|
2514
|
+
name: "Lightness"
|
|
2515
|
+
},
|
|
2516
|
+
c: {
|
|
2517
|
+
refRange: [0, 0.4],
|
|
2518
|
+
name: "Chroma"
|
|
2519
|
+
},
|
|
2520
|
+
h: {
|
|
2521
|
+
refRange: [0, 360],
|
|
2522
|
+
type: "angle",
|
|
2523
|
+
name: "Hue"
|
|
2524
|
+
}
|
|
2525
|
+
},
|
|
2526
|
+
white: "D65",
|
|
2527
|
+
base: Oklab,
|
|
2528
|
+
fromBase: lch.fromBase,
|
|
2529
|
+
toBase: lch.toBase,
|
|
2530
|
+
formats: {
|
|
2531
|
+
oklch: {
|
|
2532
|
+
coords: ["<percentage> | <number>", "<number> | <percentage>", "<number> | <angle>"]
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
741
2536
|
var prefixStyles = (styleMap) => {
|
|
742
2537
|
const newStyleMap = /* @__PURE__ */ new Map();
|
|
743
2538
|
for (const [property, value] of styleMap) {
|
|
@@ -824,6 +2619,12 @@ var toValue = (styleValue, transformValue) => {
|
|
|
824
2619
|
let [c1, c2, c3] = value.components;
|
|
825
2620
|
const alpha = typeof value.alpha === "number" ? value.alpha : toValue(value.alpha);
|
|
826
2621
|
switch (value.colorSpace) {
|
|
2622
|
+
case "hex": {
|
|
2623
|
+
const toHex = (v2) => Math.round(Math.min(Math.max(v2, 0), 1) * 255).toString(16).padStart(2, "0");
|
|
2624
|
+
const hex = `#${toHex(c1)}${toHex(c2)}${toHex(c3)}`;
|
|
2625
|
+
const alphaNum = typeof alpha === "number" ? alpha : 1;
|
|
2626
|
+
return alphaNum < 1 ? hex + toHex(alphaNum) : hex;
|
|
2627
|
+
}
|
|
827
2628
|
case "srgb": {
|
|
828
2629
|
c1 = Math.round(c1 * 255);
|
|
829
2630
|
c2 = Math.round(c2 * 255);
|
|
@@ -843,7 +2644,7 @@ var toValue = (styleValue, transformValue) => {
|
|
|
843
2644
|
case "oklch":
|
|
844
2645
|
return `oklch(${c1} ${c2} ${c3} / ${alpha})`;
|
|
845
2646
|
// Fall back to color() function for less common color spaces.
|
|
846
|
-
//
|
|
2647
|
+
// colorjs uses internal short names that differ from CSS predefined color space identifiers.
|
|
847
2648
|
case "p3":
|
|
848
2649
|
return `color(display-p3 ${c1} ${c2} ${c3} / ${alpha})`;
|
|
849
2650
|
case "a98rgb":
|
|
@@ -943,6 +2744,7 @@ var ColorValue = z.object({
|
|
|
943
2744
|
type: z.literal("color"),
|
|
944
2745
|
// all these color spaces are defined by design tokens specification
|
|
945
2746
|
colorSpace: z.union([
|
|
2747
|
+
z.literal("hex"),
|
|
946
2748
|
z.literal("srgb"),
|
|
947
2749
|
z.literal("p3"),
|
|
948
2750
|
z.literal("srgb-linear"),
|
|
@@ -1091,12 +2893,12 @@ var isLonghandValue = (value) => {
|
|
|
1091
2893
|
var mergeBorder = (styleMap, base) => {
|
|
1092
2894
|
const width = styleMap.get(`${base}-width`);
|
|
1093
2895
|
const style = styleMap.get(`${base}-style`);
|
|
1094
|
-
const
|
|
1095
|
-
if (isLonghandValue(width) && isLonghandValue(style) && isLonghandValue(
|
|
2896
|
+
const color2 = styleMap.get(`${base}-color`);
|
|
2897
|
+
if (isLonghandValue(width) && isLonghandValue(style) && isLonghandValue(color2)) {
|
|
1096
2898
|
styleMap.delete(`${base}-width`);
|
|
1097
2899
|
styleMap.delete(`${base}-style`);
|
|
1098
2900
|
styleMap.delete(`${base}-color`);
|
|
1099
|
-
styleMap.set(base, { type: "tuple", value: [width, style,
|
|
2901
|
+
styleMap.set(base, { type: "tuple", value: [width, style, color2] });
|
|
1100
2902
|
}
|
|
1101
2903
|
};
|
|
1102
2904
|
var mergeBox = (styleMap, base) => {
|
|
@@ -1254,7 +3056,7 @@ var getDeclarationKey = (declaraionKey) => {
|
|
|
1254
3056
|
const { breakpoint, selector, property } = declaraionKey;
|
|
1255
3057
|
return `${breakpoint}:${selector}:${property}`;
|
|
1256
3058
|
};
|
|
1257
|
-
var MixinRule = (
|
|
3059
|
+
var MixinRule = (_d = class {
|
|
1258
3060
|
constructor() {
|
|
1259
3061
|
// use map to avoid duplicated properties
|
|
1260
3062
|
__privateAdd(this, _declarations, /* @__PURE__ */ new Map());
|
|
@@ -1285,8 +3087,8 @@ var MixinRule = (_a = class {
|
|
|
1285
3087
|
getDeclarations() {
|
|
1286
3088
|
return __privateGet(this, _declarations).values();
|
|
1287
3089
|
}
|
|
1288
|
-
}, _declarations = new WeakMap(), _dirtyBreakpoints = new WeakMap(),
|
|
1289
|
-
var NestingRule = (
|
|
3090
|
+
}, _declarations = new WeakMap(), _dirtyBreakpoints = new WeakMap(), _d);
|
|
3091
|
+
var NestingRule = (_e = class {
|
|
1290
3092
|
constructor(mixinRules, selector, descendantSuffix) {
|
|
1291
3093
|
__privateAdd(this, _NestingRule_instances);
|
|
1292
3094
|
__privateAdd(this, _selector);
|
|
@@ -1395,8 +3197,8 @@ ${spaces}}
|
|
|
1395
3197
|
declarations.set(getDeclarationKey(declaration), declaration);
|
|
1396
3198
|
}
|
|
1397
3199
|
return declarations.values();
|
|
1398
|
-
},
|
|
1399
|
-
var MediaRule = (
|
|
3200
|
+
}, _e);
|
|
3201
|
+
var MediaRule = (_f = class {
|
|
1400
3202
|
constructor(name2, options = {}) {
|
|
1401
3203
|
__privateAdd(this, _name);
|
|
1402
3204
|
__publicField(this, "options");
|
|
@@ -1455,7 +3257,7 @@ var MediaRule = (_c = class {
|
|
|
1455
3257
|
${rules.join("\n")}
|
|
1456
3258
|
}`;
|
|
1457
3259
|
}
|
|
1458
|
-
}, _name = new WeakMap(),
|
|
3260
|
+
}, _name = new WeakMap(), _f);
|
|
1459
3261
|
var PlaintextRule = class {
|
|
1460
3262
|
constructor(cssText) {
|
|
1461
3263
|
__publicField(this, "cssText");
|
|
@@ -1465,7 +3267,7 @@ var PlaintextRule = class {
|
|
|
1465
3267
|
return this.cssText;
|
|
1466
3268
|
}
|
|
1467
3269
|
};
|
|
1468
|
-
var FontFaceRule = (
|
|
3270
|
+
var FontFaceRule = (_g = class {
|
|
1469
3271
|
constructor(options) {
|
|
1470
3272
|
__privateAdd(this, _cached);
|
|
1471
3273
|
__privateAdd(this, _options);
|
|
@@ -1495,7 +3297,7 @@ var FontFaceRule = (_d = class {
|
|
|
1495
3297
|
}`);
|
|
1496
3298
|
return __privateGet(this, _cached);
|
|
1497
3299
|
}
|
|
1498
|
-
}, _cached = new WeakMap(), _options = new WeakMap(),
|
|
3300
|
+
}, _cached = new WeakMap(), _options = new WeakMap(), _g);
|
|
1499
3301
|
var isSimulatedCondition = (options) => options.mediaType !== void 0 && options.condition === void 0 && options.minWidth === void 0 && options.maxWidth === void 0;
|
|
1500
3302
|
var isCondition = (options) => options.condition !== void 0 || isSimulatedCondition(options);
|
|
1501
3303
|
var compareMedia = (optionA, optionB) => {
|
|
@@ -1530,7 +3332,7 @@ var compareMedia = (optionA, optionB) => {
|
|
|
1530
3332
|
}
|
|
1531
3333
|
return "minWidth" in optionA ? 1 : -1;
|
|
1532
3334
|
};
|
|
1533
|
-
var StyleElement = (
|
|
3335
|
+
var StyleElement = (_h = class {
|
|
1534
3336
|
constructor(name2 = "") {
|
|
1535
3337
|
__privateAdd(this, _element);
|
|
1536
3338
|
__privateAdd(this, _name2);
|
|
@@ -1569,8 +3371,8 @@ var StyleElement = (_e = class {
|
|
|
1569
3371
|
return __privateGet(this, _element).getAttribute(name2);
|
|
1570
3372
|
}
|
|
1571
3373
|
}
|
|
1572
|
-
}, _element = new WeakMap(), _name2 = new WeakMap(),
|
|
1573
|
-
var StyleSheet = (
|
|
3374
|
+
}, _element = new WeakMap(), _name2 = new WeakMap(), _h);
|
|
3375
|
+
var StyleSheet = (_i = class {
|
|
1574
3376
|
constructor(element) {
|
|
1575
3377
|
__privateAdd(this, _cssText, "");
|
|
1576
3378
|
__privateAdd(this, _mediaRules, /* @__PURE__ */ new Map());
|
|
@@ -1680,7 +3482,7 @@ var StyleSheet = (_f = class {
|
|
|
1680
3482
|
getAttribute(name2) {
|
|
1681
3483
|
return __privateGet(this, _element2).getAttribute(name2);
|
|
1682
3484
|
}
|
|
1683
|
-
}, _cssText = new WeakMap(), _mediaRules = new WeakMap(), _plainRules = new WeakMap(), _mixinRules2 = new WeakMap(), _fontFaceRules = new WeakMap(), _transformValue = new WeakMap(), _element2 = new WeakMap(),
|
|
3485
|
+
}, _cssText = new WeakMap(), _mediaRules = new WeakMap(), _plainRules = new WeakMap(), _mixinRules2 = new WeakMap(), _fontFaceRules = new WeakMap(), _transformValue = new WeakMap(), _element2 = new WeakMap(), _i);
|
|
1684
3486
|
var StyleSheetRegular = class extends StyleSheet {
|
|
1685
3487
|
};
|
|
1686
3488
|
var createRegularStyleSheet = (options) => {
|
|
@@ -1727,6 +3529,23 @@ var generateAtomic = (sheet, options) => {
|
|
|
1727
3529
|
});
|
|
1728
3530
|
return { cssText, classes };
|
|
1729
3531
|
};
|
|
3532
|
+
ColorSpace.register(sRGB);
|
|
3533
|
+
ColorSpace.register(sRGBLinear);
|
|
3534
|
+
ColorSpace.register(hsl);
|
|
3535
|
+
ColorSpace.register(hwb);
|
|
3536
|
+
ColorSpace.register(lab);
|
|
3537
|
+
ColorSpace.register(lch);
|
|
3538
|
+
ColorSpace.register(Oklab);
|
|
3539
|
+
ColorSpace.register(oklch);
|
|
3540
|
+
ColorSpace.register(P3);
|
|
3541
|
+
ColorSpace.register(a98rgb);
|
|
3542
|
+
ColorSpace.register(prophoto);
|
|
3543
|
+
ColorSpace.register(REC2020);
|
|
3544
|
+
ColorSpace.register(xyz_d65);
|
|
3545
|
+
ColorSpace.register(XYZ_D50);
|
|
3546
|
+
ColorSpace.registry["display-p3"] = P3;
|
|
3547
|
+
ColorSpace.registry["a98-rgb"] = a98rgb;
|
|
3548
|
+
ColorSpace.registry["prophoto-rgb"] = prophoto;
|
|
1730
3549
|
var AccordionIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M13.056 8H14.5V4.101a1.3 1.3 0 0 0-1.3-1.299H2.8a1.3 1.3 0 0 0-1.3 1.3V8H13.056ZM13.056 13.198h.145a1.3 1.3 0 0 0 1.299-1.3V8h-13v3.899a1.3 1.3 0 0 0 1.3 1.299h10.256Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="m10.026 4.913.975.976.976-.976M10.026 10.111l.975.976.976-.976"/></svg>`;
|
|
1731
3550
|
var AddTemplateInstanceIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.5 2H3.333A1.333 1.333 0 0 0 2 3.333V4.5M14 12.667c0 .021 0 .042-.002.063M11.5 14h1.167a1.333 1.333 0 0 0 1.331-1.27m0 0V11.5M2 11.5v1.167A1.333 1.333 0 0 0 3.333 14H4.5M7 14h2M2 7v2M8.461 4.77H14M11.23 2v5.538"/></svg>`;
|
|
1732
3551
|
var AnimationGroupIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.5 8.3C6.3 7.7 7.8 8 9.3 11c.3-1.8 1.2-4.5 2.1-6M4.208 1.5H2.944A1.444 1.444 0 0 0 1.5 2.944v1.264m13 0V2.944A1.444 1.444 0 0 0 13.056 1.5h-1.264M14.5 13.056c0 .023 0 .046-.002.069M11.792 14.5h1.264a1.444 1.444 0 0 0 1.442-1.375m0 0v-1.333m-12.998 0v1.264A1.444 1.444 0 0 0 2.944 14.5h1.264m2.709-13h2.166m-2.166 13h2.166M1.5 6.917v2.166m13-2.166v2.166"/></svg>`;
|
|
@@ -2430,7 +4249,7 @@ var Tag = z.object({
|
|
|
2430
4249
|
defaultValue: z.undefined().optional(),
|
|
2431
4250
|
options: z.array(z.string())
|
|
2432
4251
|
});
|
|
2433
|
-
var Number = z.object({
|
|
4252
|
+
var Number$1 = z.object({
|
|
2434
4253
|
...common,
|
|
2435
4254
|
control: z.literal("number"),
|
|
2436
4255
|
type: z.literal("number"),
|
|
@@ -2574,7 +4393,7 @@ var AnimationAction = z.object({
|
|
|
2574
4393
|
});
|
|
2575
4394
|
var PropMeta = z.union([
|
|
2576
4395
|
Tag,
|
|
2577
|
-
Number,
|
|
4396
|
+
Number$1,
|
|
2578
4397
|
Range,
|
|
2579
4398
|
Text,
|
|
2580
4399
|
Resource2,
|
|
@@ -3455,15 +5274,15 @@ var coreMetas = {
|
|
|
3455
5274
|
var isCoreComponent = (component) => component === rootComponent || component === elementComponent || component === collectionComponent || component === descendantComponent || component === blockComponent || component === blockTemplateComponent;
|
|
3456
5275
|
var ROOT_INSTANCE_ID = ":root";
|
|
3457
5276
|
var traverseInstances = (instances, instanceId, callback) => {
|
|
3458
|
-
const
|
|
3459
|
-
if (
|
|
5277
|
+
const instance2 = instances.get(instanceId);
|
|
5278
|
+
if (instance2 === void 0) {
|
|
3460
5279
|
return;
|
|
3461
5280
|
}
|
|
3462
|
-
const skipTraversingChildren = callback(
|
|
5281
|
+
const skipTraversingChildren = callback(instance2);
|
|
3463
5282
|
if (skipTraversingChildren === false) {
|
|
3464
5283
|
return;
|
|
3465
5284
|
}
|
|
3466
|
-
for (const child of
|
|
5285
|
+
for (const child of instance2.children) {
|
|
3467
5286
|
if (child.type === "id") {
|
|
3468
5287
|
traverseInstances(instances, child.value, callback);
|
|
3469
5288
|
}
|
|
@@ -3471,8 +5290,8 @@ var traverseInstances = (instances, instanceId, callback) => {
|
|
|
3471
5290
|
};
|
|
3472
5291
|
var findTreeInstanceIds = (instances, rootInstanceId) => {
|
|
3473
5292
|
const ids = /* @__PURE__ */ new Set([rootInstanceId]);
|
|
3474
|
-
traverseInstances(instances, rootInstanceId, (
|
|
3475
|
-
ids.add(
|
|
5293
|
+
traverseInstances(instances, rootInstanceId, (instance2) => {
|
|
5294
|
+
ids.add(instance2.id);
|
|
3476
5295
|
});
|
|
3477
5296
|
return ids;
|
|
3478
5297
|
};
|
|
@@ -3496,16 +5315,16 @@ var getIndexesWithinAncestors = (metas, instances, rootIds) => {
|
|
|
3496
5315
|
}
|
|
3497
5316
|
const indexes = /* @__PURE__ */ new Map();
|
|
3498
5317
|
const traverseInstances2 = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
|
|
3499
|
-
const
|
|
3500
|
-
if (
|
|
5318
|
+
const instance2 = instances2.get(instanceId);
|
|
5319
|
+
if (instance2 === void 0) {
|
|
3501
5320
|
return;
|
|
3502
5321
|
}
|
|
3503
|
-
const meta = metas.get(
|
|
3504
|
-
if (ancestors.has(
|
|
5322
|
+
const meta = metas.get(instance2.component);
|
|
5323
|
+
if (ancestors.has(instance2.component)) {
|
|
3505
5324
|
latestIndexes2 = new Map(latestIndexes2);
|
|
3506
|
-
latestIndexes2.set(
|
|
5325
|
+
latestIndexes2.set(instance2.component, /* @__PURE__ */ new Map());
|
|
3507
5326
|
}
|
|
3508
|
-
if (
|
|
5327
|
+
if (instance2.component === blockTemplateComponent) {
|
|
3509
5328
|
latestIndexes2 = new Map(latestIndexes2);
|
|
3510
5329
|
for (const key of latestIndexes2.keys()) {
|
|
3511
5330
|
latestIndexes2.set(key, /* @__PURE__ */ new Map());
|
|
@@ -3514,13 +5333,13 @@ var getIndexesWithinAncestors = (metas, instances, rootIds) => {
|
|
|
3514
5333
|
if ((meta == null ? void 0 : meta.indexWithinAncestor) !== void 0) {
|
|
3515
5334
|
const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
|
|
3516
5335
|
if (ancestorIndexes) {
|
|
3517
|
-
let index = ancestorIndexes.get(
|
|
5336
|
+
let index = ancestorIndexes.get(instance2.component) ?? -1;
|
|
3518
5337
|
index += 1;
|
|
3519
|
-
ancestorIndexes.set(
|
|
3520
|
-
indexes.set(
|
|
5338
|
+
ancestorIndexes.set(instance2.component, index);
|
|
5339
|
+
indexes.set(instance2.id, index);
|
|
3521
5340
|
}
|
|
3522
5341
|
}
|
|
3523
|
-
for (const child of
|
|
5342
|
+
for (const child of instance2.children) {
|
|
3524
5343
|
if (child.type === "id") {
|
|
3525
5344
|
traverseInstances2(instances2, child.value, latestIndexes2);
|
|
3526
5345
|
}
|
|
@@ -4112,16 +5931,16 @@ var generateCss = ({
|
|
|
4112
5931
|
tagByInstanceId.set(prop.instanceId, prop.value);
|
|
4113
5932
|
}
|
|
4114
5933
|
}
|
|
4115
|
-
for (const
|
|
4116
|
-
const propTag = tagByInstanceId.get(
|
|
4117
|
-
const meta = componentMetas.get(
|
|
5934
|
+
for (const instance2 of instances.values()) {
|
|
5935
|
+
const propTag = tagByInstanceId.get(instance2.id);
|
|
5936
|
+
const meta = componentMetas.get(instance2.component);
|
|
4118
5937
|
const metaTag = Object.keys((meta == null ? void 0 : meta.presetStyle) ?? {}).at(0);
|
|
4119
|
-
let componentTags = tagsByComponent.get(
|
|
5938
|
+
let componentTags = tagsByComponent.get(instance2.component);
|
|
4120
5939
|
if (componentTags === void 0) {
|
|
4121
5940
|
componentTags = /* @__PURE__ */ new Set();
|
|
4122
|
-
tagsByComponent.set(
|
|
5941
|
+
tagsByComponent.set(instance2.component, componentTags);
|
|
4123
5942
|
}
|
|
4124
|
-
const tag =
|
|
5943
|
+
const tag = instance2.tag ?? propTag ?? metaTag;
|
|
4125
5944
|
if (tag) {
|
|
4126
5945
|
componentTags.add(tag);
|
|
4127
5946
|
}
|
|
@@ -4168,14 +5987,14 @@ var generateCss = ({
|
|
|
4168
5987
|
}
|
|
4169
5988
|
const classes = /* @__PURE__ */ new Map();
|
|
4170
5989
|
const parentIdByInstanceId = /* @__PURE__ */ new Map();
|
|
4171
|
-
for (const
|
|
4172
|
-
const presetClass = presetClasses.get(
|
|
5990
|
+
for (const instance2 of instances.values()) {
|
|
5991
|
+
const presetClass = presetClasses.get(instance2.component);
|
|
4173
5992
|
if (presetClass) {
|
|
4174
|
-
classes.set(
|
|
5993
|
+
classes.set(instance2.id, [presetClass]);
|
|
4175
5994
|
}
|
|
4176
|
-
for (const child of
|
|
5995
|
+
for (const child of instance2.children) {
|
|
4177
5996
|
if (child.type === "id") {
|
|
4178
|
-
parentIdByInstanceId.set(child.value,
|
|
5997
|
+
parentIdByInstanceId.set(child.value, instance2.id);
|
|
4179
5998
|
}
|
|
4180
5999
|
}
|
|
4181
6000
|
}
|
|
@@ -4195,11 +6014,11 @@ var generateCss = ({
|
|
|
4195
6014
|
continue;
|
|
4196
6015
|
}
|
|
4197
6016
|
let descendantSuffix = "";
|
|
4198
|
-
const
|
|
4199
|
-
if (
|
|
6017
|
+
const instance2 = instances.get(instanceId);
|
|
6018
|
+
if (instance2 === void 0) {
|
|
4200
6019
|
continue;
|
|
4201
6020
|
}
|
|
4202
|
-
if (
|
|
6021
|
+
if (instance2.component === descendantComponent) {
|
|
4203
6022
|
const parentId = parentIdByInstanceId.get(instanceId);
|
|
4204
6023
|
const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
|
|
4205
6024
|
if (parentId && descendantSelector) {
|
|
@@ -4207,9 +6026,9 @@ var generateCss = ({
|
|
|
4207
6026
|
instanceId = parentId;
|
|
4208
6027
|
}
|
|
4209
6028
|
}
|
|
4210
|
-
const meta = componentMetas.get(
|
|
4211
|
-
const [_namespace, shortName] = parseComponentName(
|
|
4212
|
-
const baseName =
|
|
6029
|
+
const meta = componentMetas.get(instance2.component);
|
|
6030
|
+
const [_namespace, shortName] = parseComponentName(instance2.component);
|
|
6031
|
+
const baseName = instance2.label ?? (meta == null ? void 0 : meta.label) ?? shortName;
|
|
4213
6032
|
const className = `w-${scope.getName(instanceId, baseName)}`;
|
|
4214
6033
|
if (atomic === false) {
|
|
4215
6034
|
let classList = classes.get(instanceId);
|
|
@@ -4628,7 +6447,7 @@ var generateJsxElement = ({
|
|
|
4628
6447
|
scope,
|
|
4629
6448
|
metas,
|
|
4630
6449
|
tagsOverrides,
|
|
4631
|
-
instance,
|
|
6450
|
+
instance: instance2,
|
|
4632
6451
|
props,
|
|
4633
6452
|
dataSources,
|
|
4634
6453
|
usedDataSources,
|
|
@@ -4637,20 +6456,20 @@ var generateJsxElement = ({
|
|
|
4637
6456
|
classesMap
|
|
4638
6457
|
}) => {
|
|
4639
6458
|
var _a2;
|
|
4640
|
-
if (
|
|
6459
|
+
if (instance2.component === descendantComponent) {
|
|
4641
6460
|
return "";
|
|
4642
6461
|
}
|
|
4643
|
-
const meta = metas.get(
|
|
6462
|
+
const meta = metas.get(instance2.component);
|
|
4644
6463
|
const hasTags = Object.keys((meta == null ? void 0 : meta.presetStyle) ?? {}).length > 0;
|
|
4645
6464
|
let generatedProps = "";
|
|
4646
|
-
const index = indexesWithinAncestors.get(
|
|
6465
|
+
const index = indexesWithinAncestors.get(instance2.id);
|
|
4647
6466
|
if (index !== void 0) {
|
|
4648
6467
|
generatedProps += `
|
|
4649
6468
|
${indexProperty}="${index}"`;
|
|
4650
6469
|
}
|
|
4651
|
-
if (
|
|
6470
|
+
if (instance2.tag !== void 0 && instance2.component !== elementComponent) {
|
|
4652
6471
|
generatedProps += `
|
|
4653
|
-
${tagProperty}=${JSON.stringify(
|
|
6472
|
+
${tagProperty}=${JSON.stringify(instance2.tag)}`;
|
|
4654
6473
|
}
|
|
4655
6474
|
let conditionValue;
|
|
4656
6475
|
let collectionDataValue;
|
|
@@ -4658,7 +6477,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
4658
6477
|
let collectionItemKeyValue;
|
|
4659
6478
|
let classNameValue;
|
|
4660
6479
|
for (const prop of props.values()) {
|
|
4661
|
-
if (prop.instanceId !==
|
|
6480
|
+
if (prop.instanceId !== instance2.id) {
|
|
4662
6481
|
continue;
|
|
4663
6482
|
}
|
|
4664
6483
|
const propValue = generatePropValue({
|
|
@@ -4684,7 +6503,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
4684
6503
|
conditionValue = propValue;
|
|
4685
6504
|
continue;
|
|
4686
6505
|
}
|
|
4687
|
-
if (
|
|
6506
|
+
if (instance2.component === collectionComponent) {
|
|
4688
6507
|
if (prop.name === "data") {
|
|
4689
6508
|
collectionDataValue = propValue;
|
|
4690
6509
|
}
|
|
@@ -4705,7 +6524,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
4705
6524
|
${name2}={${propValue}}`;
|
|
4706
6525
|
}
|
|
4707
6526
|
}
|
|
4708
|
-
const classMapArray = classesMap == null ? void 0 : classesMap.get(
|
|
6527
|
+
const classMapArray = classesMap == null ? void 0 : classesMap.get(instance2.id);
|
|
4709
6528
|
if (classMapArray || classNameValue) {
|
|
4710
6529
|
let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
|
|
4711
6530
|
if (classNameValue) {
|
|
@@ -4717,14 +6536,14 @@ ${name2}={${propValue}}`;
|
|
|
4717
6536
|
generatedProps += "\nclassName={`" + classNameTemplate + "`}";
|
|
4718
6537
|
}
|
|
4719
6538
|
let generatedElement = "";
|
|
4720
|
-
if (
|
|
6539
|
+
if (instance2.component === blockTemplateComponent) {
|
|
4721
6540
|
return "";
|
|
4722
6541
|
}
|
|
4723
|
-
if (
|
|
6542
|
+
if (instance2.component === collectionComponent) {
|
|
4724
6543
|
if (collectionDataValue === void 0 || collectionItemValue === void 0) {
|
|
4725
6544
|
return "";
|
|
4726
6545
|
}
|
|
4727
|
-
const indexVariable = scope.getName(`${
|
|
6546
|
+
const indexVariable = scope.getName(`${instance2.id}-index`, "index");
|
|
4728
6547
|
const keyVariable = collectionItemKeyValue ?? indexVariable;
|
|
4729
6548
|
generatedElement += `{${generateCollectionIterationCode({
|
|
4730
6549
|
dataExpression: collectionDataValue,
|
|
@@ -4743,22 +6562,22 @@ ${name2}={${propValue}}`;
|
|
|
4743
6562
|
`;
|
|
4744
6563
|
generatedElement += `}
|
|
4745
6564
|
`;
|
|
4746
|
-
} else if (
|
|
6565
|
+
} else if (instance2.component === blockComponent) {
|
|
4747
6566
|
generatedElement += children;
|
|
4748
6567
|
} else {
|
|
4749
6568
|
let componentVariable;
|
|
4750
|
-
if (
|
|
4751
|
-
componentVariable =
|
|
6569
|
+
if (instance2.component === elementComponent) {
|
|
6570
|
+
componentVariable = instance2.tag ?? "div";
|
|
4752
6571
|
const componentDescriptor = tagsOverrides == null ? void 0 : tagsOverrides[componentVariable];
|
|
4753
6572
|
if (componentDescriptor !== void 0) {
|
|
4754
6573
|
const [_importSource, importSpecifier] = componentDescriptor.split(":");
|
|
4755
6574
|
componentVariable = scope.getName(componentDescriptor, importSpecifier);
|
|
4756
6575
|
}
|
|
4757
6576
|
} else {
|
|
4758
|
-
const [_namespace, shortName] = parseComponentName(
|
|
4759
|
-
componentVariable = scope.getName(
|
|
6577
|
+
const [_namespace, shortName] = parseComponentName(instance2.component);
|
|
6578
|
+
componentVariable = scope.getName(instance2.component, shortName);
|
|
4760
6579
|
}
|
|
4761
|
-
if (
|
|
6580
|
+
if (instance2.children.length === 0) {
|
|
4762
6581
|
generatedElement += `<${componentVariable}${generatedProps} />
|
|
4763
6582
|
`;
|
|
4764
6583
|
} else {
|
|
@@ -4779,7 +6598,7 @@ ${name2}={${propValue}}`;
|
|
|
4779
6598
|
}
|
|
4780
6599
|
conditionalElement += `${before}(${conditionValue}) &&
|
|
4781
6600
|
`;
|
|
4782
|
-
if (
|
|
6601
|
+
if (instance2.component === collectionComponent) {
|
|
4783
6602
|
conditionalElement += "<>\n";
|
|
4784
6603
|
conditionalElement += generatedElement;
|
|
4785
6604
|
conditionalElement += "</>\n";
|
|
@@ -4829,8 +6648,8 @@ var generateJsxChildren = ({
|
|
|
4829
6648
|
}
|
|
4830
6649
|
if (child.type === "id") {
|
|
4831
6650
|
const instanceId = child.value;
|
|
4832
|
-
const
|
|
4833
|
-
if (
|
|
6651
|
+
const instance2 = instances.get(instanceId);
|
|
6652
|
+
if (instance2 === void 0) {
|
|
4834
6653
|
continue;
|
|
4835
6654
|
}
|
|
4836
6655
|
generatedChildren += generateJsxElement({
|
|
@@ -4838,7 +6657,7 @@ var generateJsxChildren = ({
|
|
|
4838
6657
|
scope,
|
|
4839
6658
|
metas,
|
|
4840
6659
|
tagsOverrides,
|
|
4841
|
-
instance,
|
|
6660
|
+
instance: instance2,
|
|
4842
6661
|
props,
|
|
4843
6662
|
dataSources,
|
|
4844
6663
|
usedDataSources,
|
|
@@ -4849,7 +6668,7 @@ var generateJsxChildren = ({
|
|
|
4849
6668
|
scope,
|
|
4850
6669
|
metas,
|
|
4851
6670
|
tagsOverrides,
|
|
4852
|
-
children:
|
|
6671
|
+
children: instance2.children,
|
|
4853
6672
|
instances,
|
|
4854
6673
|
props,
|
|
4855
6674
|
dataSources,
|
|
@@ -4875,19 +6694,19 @@ var generateWebstudioComponent = ({
|
|
|
4875
6694
|
tagsOverrides,
|
|
4876
6695
|
classesMap
|
|
4877
6696
|
}) => {
|
|
4878
|
-
const
|
|
6697
|
+
const instance2 = instances.get(rootInstanceId);
|
|
4879
6698
|
const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
|
|
4880
6699
|
rootInstanceId
|
|
4881
6700
|
]);
|
|
4882
6701
|
const usedDataSources = /* @__PURE__ */ new Map();
|
|
4883
6702
|
let generatedJsx = "<></>\n";
|
|
4884
|
-
if (
|
|
6703
|
+
if (instance2) {
|
|
4885
6704
|
generatedJsx = generateJsxElement({
|
|
4886
6705
|
context: "expression",
|
|
4887
6706
|
scope,
|
|
4888
6707
|
metas,
|
|
4889
6708
|
tagsOverrides,
|
|
4890
|
-
instance,
|
|
6709
|
+
instance: instance2,
|
|
4891
6710
|
props,
|
|
4892
6711
|
dataSources,
|
|
4893
6712
|
usedDataSources,
|
|
@@ -4897,7 +6716,7 @@ var generateWebstudioComponent = ({
|
|
|
4897
6716
|
scope,
|
|
4898
6717
|
metas,
|
|
4899
6718
|
tagsOverrides,
|
|
4900
|
-
children:
|
|
6719
|
+
children: instance2.children,
|
|
4901
6720
|
instances,
|
|
4902
6721
|
props,
|
|
4903
6722
|
dataSources,
|
|
@@ -8467,7 +10286,7 @@ audit=false
|
|
|
8467
10286
|
fund=false
|
|
8468
10287
|
`;
|
|
8469
10288
|
const prebuild = async (options) => {
|
|
8470
|
-
var _a2, _b2, _c2, _d2, _e2, _f2,
|
|
10289
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j, _k;
|
|
8471
10290
|
if (options.template.length === 0) {
|
|
8472
10291
|
log.error(
|
|
8473
10292
|
`Template is not provided
|
|
@@ -8535,12 +10354,12 @@ Please check webstudio --help for more details`
|
|
|
8535
10354
|
);
|
|
8536
10355
|
pageInstanceSet.add(ROOT_INSTANCE_ID);
|
|
8537
10356
|
const instances = [];
|
|
8538
|
-
for (const [_instanceId,
|
|
8539
|
-
if (pageInstanceSet.has(
|
|
8540
|
-
instances.push([
|
|
8541
|
-
const meta = framework.metas[
|
|
10357
|
+
for (const [_instanceId, instance2] of siteData.build.instances) {
|
|
10358
|
+
if (pageInstanceSet.has(instance2.id)) {
|
|
10359
|
+
instances.push([instance2.id, instance2]);
|
|
10360
|
+
const meta = framework.metas[instance2.component];
|
|
8542
10361
|
if (meta) {
|
|
8543
|
-
usedMetas.set(
|
|
10362
|
+
usedMetas.set(instance2.component, meta);
|
|
8544
10363
|
}
|
|
8545
10364
|
}
|
|
8546
10365
|
}
|
|
@@ -8633,7 +10452,7 @@ Please check webstudio --help for more details`
|
|
|
8633
10452
|
// pass only used metas to not generate unused preset styles
|
|
8634
10453
|
componentMetas: usedMetas,
|
|
8635
10454
|
assetBaseUrl,
|
|
8636
|
-
atomic: ((
|
|
10455
|
+
atomic: ((_g2 = siteData.build.pages.compiler) == null ? void 0 : _g2.atomicStyles) ?? true
|
|
8637
10456
|
});
|
|
8638
10457
|
await createFileIfNotExists(join(generatedDir, "index.css"), cssText);
|
|
8639
10458
|
for (const page of Object.values(siteData.pages)) {
|
|
@@ -8656,22 +10475,22 @@ Please check webstudio --help for more details`
|
|
|
8656
10475
|
if ((firstChild == null ? void 0 : firstChild.type) === "id") {
|
|
8657
10476
|
rootInstanceId = firstChild.value;
|
|
8658
10477
|
}
|
|
8659
|
-
for (const
|
|
8660
|
-
if (isCoreComponent(
|
|
10478
|
+
for (const instance2 of instances.values()) {
|
|
10479
|
+
if (isCoreComponent(instance2.component)) {
|
|
8661
10480
|
continue;
|
|
8662
10481
|
}
|
|
8663
|
-
if (((
|
|
10482
|
+
if (((_h2 = usedMetas.get(instance2.component)) == null ? void 0 : _h2.category) === "xml") {
|
|
8664
10483
|
continue;
|
|
8665
10484
|
}
|
|
8666
|
-
instances.delete(
|
|
10485
|
+
instances.delete(instance2.id);
|
|
8667
10486
|
}
|
|
8668
10487
|
}
|
|
8669
10488
|
const imports2 = /* @__PURE__ */ new Map();
|
|
8670
|
-
for (const
|
|
8671
|
-
let descriptor = framework.components[
|
|
8672
|
-
let id =
|
|
8673
|
-
if (
|
|
8674
|
-
descriptor = framework.tags[
|
|
10489
|
+
for (const instance2 of instances.values()) {
|
|
10490
|
+
let descriptor = framework.components[instance2.component];
|
|
10491
|
+
let id = instance2.component;
|
|
10492
|
+
if (instance2.component === elementComponent && instance2.tag) {
|
|
10493
|
+
descriptor = framework.tags[instance2.tag];
|
|
8675
10494
|
id = descriptor;
|
|
8676
10495
|
}
|
|
8677
10496
|
if (descriptor === void 0) {
|
|
@@ -8733,7 +10552,7 @@ Please check webstudio --help for more details`
|
|
|
8733
10552
|
const projectMeta = siteData.build.pages.meta;
|
|
8734
10553
|
const contactEmail = (
|
|
8735
10554
|
// fallback to user email when contact email is empty string
|
|
8736
|
-
(projectMeta == null ? void 0 : projectMeta.contactEmail) || ((
|
|
10555
|
+
(projectMeta == null ? void 0 : projectMeta.contactEmail) || ((_i2 = siteData.user) == null ? void 0 : _i2.email) || void 0
|
|
8737
10556
|
);
|
|
8738
10557
|
const favIconAsset = (_j = assets.get((projectMeta == null ? void 0 : projectMeta.faviconAssetId) ?? "")) == null ? void 0 : _j.name;
|
|
8739
10558
|
const pagePath = getPagePath(page.id, siteData.build.pages);
|
|
@@ -9049,7 +10868,7 @@ const getDeploymentInstructions = (deployTarget) => {
|
|
|
9049
10868
|
}
|
|
9050
10869
|
};
|
|
9051
10870
|
const name = "webstudio";
|
|
9052
|
-
const version = "0.
|
|
10871
|
+
const version = "0.259.0";
|
|
9053
10872
|
const description = "Webstudio CLI";
|
|
9054
10873
|
const author = "Webstudio <github@webstudio.is>";
|
|
9055
10874
|
const homepage = "https://webstudio.is";
|