@visactor/vutils 0.15.11 → 0.15.12

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.
@@ -159,14 +159,30 @@ export declare class Color {
159
159
  toString(): string;
160
160
  toHex(): string;
161
161
  toHsl(): string;
162
- setOpacity(o?: number): this;
163
162
  brighter(k: number): this;
163
+ add(color: Color): this;
164
+ sub(color: Color): this;
165
+ multiply(color: Color): this;
164
166
  getHSVBrightness(): number;
165
167
  getHSLBrightness(): number;
166
168
  setHsl(h?: number | null | undefined, s?: number | null | undefined, l?: number | null | undefined): this;
169
+ setRGB(r: number, g: number, b: number): this;
170
+ setHex(value: string): RGB | this;
171
+ setColorName(name: string): this;
172
+ setScalar(scalar: number): this;
173
+ setOpacity(o?: number): this;
167
174
  getLuminance(): number;
168
175
  getLuminance2(): number;
169
176
  getLuminance3(): number;
177
+ clone(): Color;
178
+ copyGammaToLinear(color: Color, gammaFactor?: number): this;
179
+ copyLinearToGamma(color: Color, gammaFactor?: number): this;
180
+ convertGammaToLinear(gammaFactor: number): this;
181
+ convertLinearToGamma(gammaFactor: number): this;
182
+ copySRGBToLinear(color: Color): this;
183
+ copyLinearToSRGB(color: Color): this;
184
+ convertSRGBToLinear(): this;
185
+ convertLinearToSRGB(): this;
170
186
  }
171
187
  export declare class RGB {
172
188
  r: number;
@@ -28,6 +28,14 @@ function rgba(value) {
28
28
  common_1.isArray)(value) ? new RGB(value[0], value[1], value[2], value[3]) : new RGB(255, 255, 255, 1);
29
29
  }
30
30
 
31
+ function SRGBToLinear(c) {
32
+ return c < .04045 ? .0773993808 * c : Math.pow(.9478672986 * c + .0521327014, 2.4);
33
+ }
34
+
35
+ function LinearToSRGB(c) {
36
+ return c < .0031308 ? 12.92 * c : 1.055 * Math.pow(c, .41666) - .055;
37
+ }
38
+
31
39
  exports.DEFAULT_COLORS = {
32
40
  aliceblue: 15792383,
33
41
  antiquewhite: 16444375,
@@ -240,14 +248,26 @@ class Color {
240
248
  toHsl() {
241
249
  return this.color.formatHsl();
242
250
  }
243
- setOpacity(o = 1) {
244
- return this.color.opacity = o, this;
245
- }
246
251
  brighter(k) {
247
252
  const {r: r, g: g, b: b} = this.color;
248
253
  return this.color.r = Math.max(0, Math.min(255, Math.floor(r * k))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * k))),
249
254
  this.color.b = Math.max(0, Math.min(255, Math.floor(b * k))), this;
250
255
  }
256
+ add(color) {
257
+ const {r: r, g: g, b: b} = this.color;
258
+ return this.color.r += Math.min(255, r + color.color.r), this.color.g += Math.min(255, g + color.color.g),
259
+ this.color.b += Math.min(255, b + color.color.b), this;
260
+ }
261
+ sub(color) {
262
+ return this.color.r = Math.max(0, this.color.r - color.color.r), this.color.g = Math.max(0, this.color.g - color.color.g),
263
+ this.color.b = Math.max(0, this.color.b - color.color.b), this;
264
+ }
265
+ multiply(color) {
266
+ const {r: r, g: g, b: b} = this.color;
267
+ return this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r))),
268
+ this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b))),
269
+ this;
270
+ }
251
271
  getHSVBrightness() {
252
272
  return Math.max(this.color.r, this.color.g, this.color.b) / 255;
253
273
  }
@@ -260,6 +280,25 @@ class Color {
260
280
  common_1.isNil)(s) ? hsl.s : s >= 0 && s <= 1 ? 100 * s : s, (0, common_1.isNil)(l) ? hsl.l : l <= 1 && l >= 0 ? 100 * l : l);
261
281
  return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this;
262
282
  }
283
+ setRGB(r, g, b) {
284
+ return !(0, common_1.isNil)(r) && (this.color.r = r), !(0, common_1.isNil)(g) && (this.color.g = g),
285
+ !(0, common_1.isNil)(b) && (this.color.b = b), this;
286
+ }
287
+ setHex(value) {
288
+ const formatValue = `${value}`.trim().toLowerCase(), isHex = REG_HEX.exec(formatValue), hex = parseInt(isHex[1], 16), hexLength = isHex[1].length;
289
+ return 3 === hexLength ? new RGB((hex >> 8 & 15) + ((hex >> 8 & 15) << 4), (hex >> 4 & 15) + ((hex >> 4 & 15) << 4), (15 & hex) + ((15 & hex) << 4), 1) : 6 === hexLength ? rgb(hex) : 8 === hexLength ? new RGB(hex >> 24 & 255, hex >> 16 & 255, hex >> 8 & 255, (255 & hex) / 255) : this;
290
+ }
291
+ setColorName(name) {
292
+ const hex = exports.DEFAULT_COLORS[name.toLowerCase()];
293
+ return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name),
294
+ this;
295
+ }
296
+ setScalar(scalar) {
297
+ return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this;
298
+ }
299
+ setOpacity(o = 1) {
300
+ return this.color.opacity = o, this;
301
+ }
263
302
  getLuminance() {
264
303
  return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255;
265
304
  }
@@ -269,6 +308,38 @@ class Color {
269
308
  getLuminance3() {
270
309
  return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255;
271
310
  }
311
+ clone() {
312
+ return new Color(this.color.toString());
313
+ }
314
+ copyGammaToLinear(color, gammaFactor = 2) {
315
+ return this.color.r = Math.pow(color.color.r, gammaFactor), this.color.g = Math.pow(color.color.g, gammaFactor),
316
+ this.color.b = Math.pow(color.color.b, gammaFactor), this;
317
+ }
318
+ copyLinearToGamma(color, gammaFactor = 2) {
319
+ const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1;
320
+ return this.color.r = Math.pow(color.color.r, safeInverse), this.color.g = Math.pow(color.color.g, safeInverse),
321
+ this.color.b = Math.pow(color.color.b, safeInverse), this;
322
+ }
323
+ convertGammaToLinear(gammaFactor) {
324
+ return this.copyGammaToLinear(this, gammaFactor), this;
325
+ }
326
+ convertLinearToGamma(gammaFactor) {
327
+ return this.copyLinearToGamma(this, gammaFactor), this;
328
+ }
329
+ copySRGBToLinear(color) {
330
+ return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g),
331
+ this.color.b = SRGBToLinear(color.color.b), this;
332
+ }
333
+ copyLinearToSRGB(color) {
334
+ return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g),
335
+ this.color.b = LinearToSRGB(color.color.b), this;
336
+ }
337
+ convertSRGBToLinear() {
338
+ return this.copySRGBToLinear(this), this;
339
+ }
340
+ convertLinearToSRGB() {
341
+ return this.copyLinearToSRGB(this), this;
342
+ }
272
343
  }
273
344
 
274
345
  exports.Color = Color;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/color/Color.ts"],"names":[],"mappings":";;;;;;AAkCA,sCAAqE;AACrE,0DAAkC;AAClC,0DAAkC;AAElC,MAAM,OAAO,GAAG,oBAAoB,CAAC;AAErC,MAAM,sBAAsB,GAAG;IAC7B,WAAW,EAAE,UAAU;CACxB,CAAC;AAEW,QAAA,cAAc,GAAG;IAC5B,SAAS,EAAE,QAAQ;IACnB,YAAY,EAAE,QAAQ;IACtB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IACf,cAAc,EAAE,QAAQ;IACxB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,QAAQ;IACf,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,UAAU,EAAE,QAAQ;IACpB,SAAS,EAAE,QAAQ;IACnB,KAAK,EAAE,QAAQ;IACf,cAAc,EAAE,QAAQ;IACxB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,aAAa,EAAE,QAAQ;IACvB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,QAAQ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AAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QAErD,OAAO,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,EAAE,CAAC;IACtG,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF;AAnCD,kBAmCC","file":"Color.js","sourcesContent":["/*\nCopyright (c) 2013, Jason Davies.\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n * The name Jason Davies may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL JASON DAVIES BE LIABLE FOR ANY DIRECT, INDIRECT,\nINCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/\n\n// Mike Bostock, https://github.com/d3/d3-color\n/**\n * 参考 d3-color 实现。用于颜色转化\n * 16进制/rgb 转化为r,g,b, o\n */\nimport { clamp, isArray, isNil, isNumber, isValid } from '../common';\nimport hslToRgb from './hslToRgb';\nimport rgbToHsl from './rgbToHsl';\n\nconst REG_HEX = /^#([0-9a-f]{3,8})$/;\n\nconst DEFAULT_COLORS_OPACITY = {\n transparent: 0xffffff00\n};\n\nexport const DEFAULT_COLORS = {\n aliceblue: 0xf0f8ff,\n antiquewhite: 0xfaebd7,\n aqua: 0x00ffff,\n aquamarine: 0x7fffd4,\n azure: 0xf0ffff,\n beige: 0xf5f5dc,\n bisque: 0xffe4c4,\n black: 0x000000,\n blanchedalmond: 0xffebcd,\n blue: 0x0000ff,\n blueviolet: 0x8a2be2,\n brown: 0xa52a2a,\n burlywood: 0xdeb887,\n cadetblue: 0x5f9ea0,\n chartreuse: 0x7fff00,\n chocolate: 0xd2691e,\n coral: 0xff7f50,\n cornflowerblue: 0x6495ed,\n cornsilk: 0xfff8dc,\n crimson: 0xdc143c,\n cyan: 0x00ffff,\n darkblue: 0x00008b,\n darkcyan: 0x008b8b,\n darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9,\n darkgreen: 0x006400,\n darkgrey: 0xa9a9a9,\n darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b,\n darkolivegreen: 0x556b2f,\n darkorange: 0xff8c00,\n darkorchid: 0x9932cc,\n darkred: 0x8b0000,\n darksalmon: 0xe9967a,\n darkseagreen: 0x8fbc8f,\n darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f,\n darkslategrey: 0x2f4f4f,\n darkturquoise: 0x00ced1,\n darkviolet: 0x9400d3,\n deeppink: 0xff1493,\n deepskyblue: 0x00bfff,\n dimgray: 0x696969,\n dimgrey: 0x696969,\n dodgerblue: 0x1e90ff,\n firebrick: 0xb22222,\n floralwhite: 0xfffaf0,\n forestgreen: 0x228b22,\n fuchsia: 0xff00ff,\n gainsboro: 0xdcdcdc,\n ghostwhite: 0xf8f8ff,\n gold: 0xffd700,\n goldenrod: 0xdaa520,\n gray: 0x808080,\n green: 0x008000,\n greenyellow: 0xadff2f,\n grey: 0x808080,\n honeydew: 0xf0fff0,\n hotpink: 0xff69b4,\n indianred: 0xcd5c5c,\n indigo: 0x4b0082,\n ivory: 0xfffff0,\n khaki: 0xf0e68c,\n lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5,\n lawngreen: 0x7cfc00,\n lemonchiffon: 0xfffacd,\n lightblue: 0xadd8e6,\n lightcoral: 0xf08080,\n lightcyan: 0xe0ffff,\n lightgoldenrodyellow: 0xfafad2,\n lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90,\n lightgrey: 0xd3d3d3,\n lightpink: 0xffb6c1,\n lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa,\n lightskyblue: 0x87cefa,\n lightslategray: 0x778899,\n lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de,\n lightyellow: 0xffffe0,\n lime: 0x00ff00,\n limegreen: 0x32cd32,\n linen: 0xfaf0e6,\n magenta: 0xff00ff,\n maroon: 0x800000,\n mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd,\n mediumorchid: 0xba55d3,\n mediumpurple: 0x9370db,\n mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee,\n mediumspringgreen: 0x00fa9a,\n mediumturquoise: 0x48d1cc,\n mediumvioletred: 0xc71585,\n midnightblue: 0x191970,\n mintcream: 0xf5fffa,\n mistyrose: 0xffe4e1,\n moccasin: 0xffe4b5,\n navajowhite: 0xffdead,\n navy: 0x000080,\n oldlace: 0xfdf5e6,\n olive: 0x808000,\n olivedrab: 0x6b8e23,\n orange: 0xffa500,\n orangered: 0xff4500,\n orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa,\n palegreen: 0x98fb98,\n paleturquoise: 0xafeeee,\n palevioletred: 0xdb7093,\n papayawhip: 0xffefd5,\n peachpuff: 0xffdab9,\n peru: 0xcd853f,\n pink: 0xffc0cb,\n plum: 0xdda0dd,\n powderblue: 0xb0e0e6,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n red: 0xff0000,\n rosybrown: 0xbc8f8f,\n royalblue: 0x4169e1,\n saddlebrown: 0x8b4513,\n salmon: 0xfa8072,\n sandybrown: 0xf4a460,\n seagreen: 0x2e8b57,\n seashell: 0xfff5ee,\n sienna: 0xa0522d,\n silver: 0xc0c0c0,\n skyblue: 0x87ceeb,\n slateblue: 0x6a5acd,\n slategray: 0x708090,\n slategrey: 0x708090,\n snow: 0xfffafa,\n springgreen: 0x00ff7f,\n steelblue: 0x4682b4,\n tan: 0xd2b48c,\n teal: 0x008080,\n thistle: 0xd8bfd8,\n tomato: 0xff6347,\n turquoise: 0x40e0d0,\n violet: 0xee82ee,\n wheat: 0xf5deb3,\n white: 0xffffff,\n whitesmoke: 0xf5f5f5,\n yellow: 0xffff00,\n yellowgreen: 0x9acd32\n};\n\nfunction hex(value: number) {\n value = Math.max(0, Math.min(255, Math.round(value) || 0));\n return (value < 16 ? '0' : '') + value.toString(16);\n}\n\nfunction rgb(value: number | number[]): RGB {\n if (isNumber(value)) {\n return new RGB((value as number) >> 16, ((value as number) >> 8) & 0xff, (value as number) & 0xff, 1);\n } else if (isArray(value)) {\n return new RGB(value[0], value[1], value[2]);\n }\n\n // default return\n return new RGB(255, 255, 255);\n}\n\nfunction rgba(value: number | number[]): RGB {\n if (isNumber(value)) {\n return new RGB(\n (value as number) >>> 24,\n ((value as number) >>> 16) & 0xff,\n ((value as number) >>> 8) & 0xff,\n (value as number) & 0xff\n );\n } else if (isArray(value)) {\n return new RGB(value[0], value[1], value[2], value[3]);\n }\n\n // default return\n return new RGB(255, 255, 255, 1);\n}\n\nexport class Color {\n color!: RGB;\n\n static Brighter(source: string, b = 1) {\n if (b === 1) {\n return source;\n }\n return new Color(source).brighter(b).toRGBA();\n }\n\n static SetOpacity(source: string, o = 1) {\n if (o === 1) {\n return source;\n }\n return new Color(source).setOpacity(o).toRGBA();\n }\n\n static getColorBrightness(source: string | Color, model: 'hsv' | 'hsl' | 'lum' | 'lum2' | 'lum3' = 'hsl') {\n const color = source instanceof Color ? source : new Color(source);\n switch (model) {\n case 'hsv':\n return color.getHSVBrightness();\n case 'hsl':\n return color.getHSLBrightness();\n case 'lum':\n return color.getLuminance();\n case 'lum2':\n return color.getLuminance2();\n case 'lum3':\n return color.getLuminance3();\n default:\n return color.getHSVBrightness();\n }\n }\n\n static parseColorString(value: string) {\n // case0: transparent\n if (isValid(DEFAULT_COLORS_OPACITY[value])) {\n return rgba(DEFAULT_COLORS_OPACITY[value]);\n }\n\n // case1: 简写 ['blue','red']\n if (isValid(DEFAULT_COLORS[value])) {\n return rgb(DEFAULT_COLORS[value]);\n }\n const formatValue = `${value}`.trim().toLowerCase();\n const isHex = REG_HEX.exec(formatValue);\n\n // case2: 16进制\n if (isHex) {\n const hex = parseInt(isHex[1], 16);\n const hexLength = isHex[1].length;\n // #fff\n if (hexLength === 3) {\n return new RGB(\n ((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4),\n ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4),\n (hex & 0xf) + ((hex & 0xf) << 4),\n 1\n );\n }\n // #ffffff\n if (hexLength === 6) {\n return rgb(hex);\n }\n // #ffffffaa\n else if (hexLength === 8) {\n return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);\n }\n\n return;\n }\n\n // case3 : rgb\n if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {\n const aColor = formatValue.replace(/(?:\\(|\\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');\n return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));\n }\n\n // case4: hsl\n if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {\n const aColor = formatValue.replace(/(?:\\(|\\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');\n const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));\n\n return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));\n }\n\n return;\n }\n\n constructor(value: string) {\n const color = Color.parseColorString(value);\n\n // case0: transparent\n if (color) {\n this.color = color;\n } else {\n // default: 白色\n console.warn(`Warn: 传入${value}无法解析为Color`);\n this.color = new RGB(255, 255, 255);\n }\n }\n toRGBA() {\n return this.color.formatRgb();\n }\n toString() {\n return this.color.formatRgb();\n }\n toHex() {\n return this.color.formatHex();\n }\n toHsl() {\n return this.color.formatHsl();\n }\n setOpacity(o = 1) {\n this.color.opacity = o;\n return this;\n }\n brighter(k: number) {\n const { r, g, b } = this.color;\n this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));\n this.color.g = Math.max(0, Math.min(255, Math.floor(g * k)));\n this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));\n return this;\n }\n\n // todo: 这里亮度计算都没考虑alpha通道\n getHSVBrightness() {\n return Math.max(this.color.r, this.color.g, this.color.b) / 255;\n }\n\n getHSLBrightness() {\n return (\n (Math.max(this.color.r, this.color.g, this.color.b) / 255 +\n Math.min(this.color.r, this.color.g, this.color.b) / 255) *\n 0.5\n );\n }\n\n setHsl(h?: number | null | undefined, s?: number | null | undefined, l?: number | null | undefined) {\n const opacity = this.color.opacity;\n const hsl = rgbToHsl(this.color.r, this.color.g, this.color.b);\n\n const rgb = hslToRgb(\n isNil(h) ? hsl.h : clamp(h as number, 0, 360),\n isNil(s) ? hsl.s : s >= 0 && s <= 1 ? s * 100 : s,\n isNil(l) ? hsl.l : l <= 1 && l >= 0 ? l * 100 : l\n );\n this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);\n\n return this;\n }\n\n getLuminance() {\n return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;\n }\n\n getLuminance2() {\n return (0.2627 * this.color.r + 0.678 * this.color.g + 0.0593 * this.color.b) / 255;\n }\n\n getLuminance3() {\n return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;\n }\n}\n\nexport class RGB {\n r: number;\n g: number;\n b: number;\n opacity: number;\n constructor(r: number, g: number, b: number, opacity?: number) {\n this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));\n this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));\n this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));\n\n if (isValid(opacity)) {\n this.opacity = isNaN(+(opacity as number)) ? 1 : Math.max(0, Math.min(1, +(opacity as number)));\n } else {\n this.opacity = 1;\n }\n }\n // 转为16进制\n formatHex() {\n return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;\n }\n formatRgb() {\n const opacity = this.opacity;\n return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;\n }\n\n formatHsl() {\n const opacity = this.opacity;\n const { h, s, l } = rgbToHsl(this.r, this.g, this.b);\n\n return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;\n }\n // 转为16进制\n toString() {\n return this.formatHex();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/color/Color.ts"],"names":[],"mappings":";;;;;;AAkCA,sCAAqE;AACrE,0DAAkC;AAClC,0DAAkC;AAElC,MAAM,OAAO,GAAG,oBAAoB,CAAC;AAErC,MAAM,sBAAsB,GAAG;IAC7B,WAAW,EAAE,UAAU;CACxB,CAAC;AAEW,QAAA,cAAc,GAAG;IAC5B,SAAS,EAAE,QAAQ;IACnB,YAAY,EAAE,QAAQ;IACtB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,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AAC,CAAC,CAAC,IAAI,OAAO,GAAG,EAAE,CAAC;IACtG,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF;AAnCD,kBAmCC","file":"Color.js","sourcesContent":["/*\nCopyright (c) 2013, Jason Davies.\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n * The name Jason Davies may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL JASON DAVIES BE LIABLE FOR ANY DIRECT, INDIRECT,\nINCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/\n\n// Mike Bostock, https://github.com/d3/d3-color\n/**\n * 参考 d3-color 实现。用于颜色转化\n * 16进制/rgb 转化为r,g,b, o\n */\nimport { clamp, isArray, isNil, isNumber, isValid } from '../common';\nimport hslToRgb from './hslToRgb';\nimport rgbToHsl from './rgbToHsl';\n\nconst REG_HEX = /^#([0-9a-f]{3,8})$/;\n\nconst DEFAULT_COLORS_OPACITY = {\n transparent: 0xffffff00\n};\n\nexport const DEFAULT_COLORS = {\n aliceblue: 0xf0f8ff,\n antiquewhite: 0xfaebd7,\n aqua: 0x00ffff,\n aquamarine: 0x7fffd4,\n azure: 0xf0ffff,\n beige: 0xf5f5dc,\n bisque: 0xffe4c4,\n black: 0x000000,\n blanchedalmond: 0xffebcd,\n blue: 0x0000ff,\n blueviolet: 0x8a2be2,\n brown: 0xa52a2a,\n burlywood: 0xdeb887,\n cadetblue: 0x5f9ea0,\n chartreuse: 0x7fff00,\n chocolate: 0xd2691e,\n coral: 0xff7f50,\n cornflowerblue: 0x6495ed,\n cornsilk: 0xfff8dc,\n crimson: 0xdc143c,\n cyan: 0x00ffff,\n darkblue: 0x00008b,\n darkcyan: 0x008b8b,\n darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9,\n darkgreen: 0x006400,\n darkgrey: 0xa9a9a9,\n darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b,\n darkolivegreen: 0x556b2f,\n darkorange: 0xff8c00,\n darkorchid: 0x9932cc,\n darkred: 0x8b0000,\n darksalmon: 0xe9967a,\n darkseagreen: 0x8fbc8f,\n darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f,\n darkslategrey: 0x2f4f4f,\n darkturquoise: 0x00ced1,\n darkviolet: 0x9400d3,\n deeppink: 0xff1493,\n deepskyblue: 0x00bfff,\n dimgray: 0x696969,\n dimgrey: 0x696969,\n dodgerblue: 0x1e90ff,\n firebrick: 0xb22222,\n floralwhite: 0xfffaf0,\n forestgreen: 0x228b22,\n fuchsia: 0xff00ff,\n gainsboro: 0xdcdcdc,\n ghostwhite: 0xf8f8ff,\n gold: 0xffd700,\n goldenrod: 0xdaa520,\n gray: 0x808080,\n green: 0x008000,\n greenyellow: 0xadff2f,\n grey: 0x808080,\n honeydew: 0xf0fff0,\n hotpink: 0xff69b4,\n indianred: 0xcd5c5c,\n indigo: 0x4b0082,\n ivory: 0xfffff0,\n khaki: 0xf0e68c,\n lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5,\n lawngreen: 0x7cfc00,\n lemonchiffon: 0xfffacd,\n lightblue: 0xadd8e6,\n lightcoral: 0xf08080,\n lightcyan: 0xe0ffff,\n lightgoldenrodyellow: 0xfafad2,\n lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90,\n lightgrey: 0xd3d3d3,\n lightpink: 0xffb6c1,\n lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa,\n lightskyblue: 0x87cefa,\n lightslategray: 0x778899,\n lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de,\n lightyellow: 0xffffe0,\n lime: 0x00ff00,\n limegreen: 0x32cd32,\n linen: 0xfaf0e6,\n magenta: 0xff00ff,\n maroon: 0x800000,\n mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd,\n mediumorchid: 0xba55d3,\n mediumpurple: 0x9370db,\n mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee,\n mediumspringgreen: 0x00fa9a,\n mediumturquoise: 0x48d1cc,\n mediumvioletred: 0xc71585,\n midnightblue: 0x191970,\n mintcream: 0xf5fffa,\n mistyrose: 0xffe4e1,\n moccasin: 0xffe4b5,\n navajowhite: 0xffdead,\n navy: 0x000080,\n oldlace: 0xfdf5e6,\n olive: 0x808000,\n olivedrab: 0x6b8e23,\n orange: 0xffa500,\n orangered: 0xff4500,\n orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa,\n palegreen: 0x98fb98,\n paleturquoise: 0xafeeee,\n palevioletred: 0xdb7093,\n papayawhip: 0xffefd5,\n peachpuff: 0xffdab9,\n peru: 0xcd853f,\n pink: 0xffc0cb,\n plum: 0xdda0dd,\n powderblue: 0xb0e0e6,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n red: 0xff0000,\n rosybrown: 0xbc8f8f,\n royalblue: 0x4169e1,\n saddlebrown: 0x8b4513,\n salmon: 0xfa8072,\n sandybrown: 0xf4a460,\n seagreen: 0x2e8b57,\n seashell: 0xfff5ee,\n sienna: 0xa0522d,\n silver: 0xc0c0c0,\n skyblue: 0x87ceeb,\n slateblue: 0x6a5acd,\n slategray: 0x708090,\n slategrey: 0x708090,\n snow: 0xfffafa,\n springgreen: 0x00ff7f,\n steelblue: 0x4682b4,\n tan: 0xd2b48c,\n teal: 0x008080,\n thistle: 0xd8bfd8,\n tomato: 0xff6347,\n turquoise: 0x40e0d0,\n violet: 0xee82ee,\n wheat: 0xf5deb3,\n white: 0xffffff,\n whitesmoke: 0xf5f5f5,\n yellow: 0xffff00,\n yellowgreen: 0x9acd32\n};\n\nfunction hex(value: number) {\n value = Math.max(0, Math.min(255, Math.round(value) || 0));\n return (value < 16 ? '0' : '') + value.toString(16);\n}\n\nfunction rgb(value: number | number[]): RGB {\n if (isNumber(value)) {\n return new RGB((value as number) >> 16, ((value as number) >> 8) & 0xff, (value as number) & 0xff, 1);\n } else if (isArray(value)) {\n return new RGB(value[0], value[1], value[2]);\n }\n\n // default return\n return new RGB(255, 255, 255);\n}\n\nfunction rgba(value: number | number[]): RGB {\n if (isNumber(value)) {\n return new RGB(\n (value as number) >>> 24,\n ((value as number) >>> 16) & 0xff,\n ((value as number) >>> 8) & 0xff,\n (value as number) & 0xff\n );\n } else if (isArray(value)) {\n return new RGB(value[0], value[1], value[2], value[3]);\n }\n\n // default return\n return new RGB(255, 255, 255, 1);\n}\n\nfunction SRGBToLinear(c: number) {\n return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);\n}\n\nfunction LinearToSRGB(c: number) {\n return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;\n}\n\nexport class Color {\n color!: RGB;\n\n static Brighter(source: string, b = 1) {\n if (b === 1) {\n return source;\n }\n return new Color(source).brighter(b).toRGBA();\n }\n\n static SetOpacity(source: string, o = 1) {\n if (o === 1) {\n return source;\n }\n return new Color(source).setOpacity(o).toRGBA();\n }\n\n static getColorBrightness(source: string | Color, model: 'hsv' | 'hsl' | 'lum' | 'lum2' | 'lum3' = 'hsl') {\n const color = source instanceof Color ? source : new Color(source);\n switch (model) {\n case 'hsv':\n return color.getHSVBrightness();\n case 'hsl':\n return color.getHSLBrightness();\n case 'lum':\n return color.getLuminance();\n case 'lum2':\n return color.getLuminance2();\n case 'lum3':\n return color.getLuminance3();\n default:\n return color.getHSVBrightness();\n }\n }\n\n static parseColorString(value: string) {\n // case0: transparent\n if (isValid(DEFAULT_COLORS_OPACITY[value])) {\n return rgba(DEFAULT_COLORS_OPACITY[value]);\n }\n\n // case1: 简写 ['blue','red']\n if (isValid(DEFAULT_COLORS[value])) {\n return rgb(DEFAULT_COLORS[value]);\n }\n const formatValue = `${value}`.trim().toLowerCase();\n const isHex = REG_HEX.exec(formatValue);\n\n // case2: 16进制\n if (isHex) {\n const hex = parseInt(isHex[1], 16);\n const hexLength = isHex[1].length;\n // #fff\n if (hexLength === 3) {\n return new RGB(\n ((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4),\n ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4),\n (hex & 0xf) + ((hex & 0xf) << 4),\n 1\n );\n }\n // #ffffff\n if (hexLength === 6) {\n return rgb(hex);\n }\n // #ffffffaa\n else if (hexLength === 8) {\n return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);\n }\n\n return;\n }\n\n // case3 : rgb\n if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {\n const aColor = formatValue.replace(/(?:\\(|\\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');\n return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));\n }\n\n // case4: hsl\n if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {\n const aColor = formatValue.replace(/(?:\\(|\\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');\n const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));\n\n return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));\n }\n\n return;\n }\n\n constructor(value: string) {\n const color = Color.parseColorString(value);\n\n // case0: transparent\n if (color) {\n this.color = color;\n } else {\n // default: 白色\n console.warn(`Warn: 传入${value}无法解析为Color`);\n this.color = new RGB(255, 255, 255);\n }\n }\n toRGBA() {\n return this.color.formatRgb();\n }\n toString() {\n return this.color.formatRgb();\n }\n toHex() {\n return this.color.formatHex();\n }\n toHsl() {\n return this.color.formatHsl();\n }\n\n brighter(k: number) {\n const { r, g, b } = this.color;\n this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));\n this.color.g = Math.max(0, Math.min(255, Math.floor(g * k)));\n this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));\n return this;\n }\n\n add(color: Color) {\n const { r, g, b } = this.color;\n this.color.r += Math.min(255, r + color.color.r);\n this.color.g += Math.min(255, g + color.color.g);\n this.color.b += Math.min(255, b + color.color.b);\n return this;\n }\n\n sub(color: Color) {\n this.color.r = Math.max(0, this.color.r - color.color.r);\n this.color.g = Math.max(0, this.color.g - color.color.g);\n this.color.b = Math.max(0, this.color.b - color.color.b);\n return this;\n }\n\n multiply(color: Color) {\n const { r, g, b } = this.color;\n this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r)));\n this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g)));\n this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b)));\n return this;\n }\n\n // todo: 这里亮度计算都没考虑alpha通道\n getHSVBrightness() {\n return Math.max(this.color.r, this.color.g, this.color.b) / 255;\n }\n\n getHSLBrightness() {\n return (\n (Math.max(this.color.r, this.color.g, this.color.b) / 255 +\n Math.min(this.color.r, this.color.g, this.color.b) / 255) *\n 0.5\n );\n }\n\n setHsl(h?: number | null | undefined, s?: number | null | undefined, l?: number | null | undefined) {\n const opacity = this.color.opacity;\n const hsl = rgbToHsl(this.color.r, this.color.g, this.color.b);\n\n const rgb = hslToRgb(\n isNil(h) ? hsl.h : clamp(h as number, 0, 360),\n isNil(s) ? hsl.s : s >= 0 && s <= 1 ? s * 100 : s,\n isNil(l) ? hsl.l : l <= 1 && l >= 0 ? l * 100 : l\n );\n this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);\n\n return this;\n }\n\n setRGB(r: number, g: number, b: number) {\n !isNil(r) && (this.color.r = r);\n !isNil(g) && (this.color.g = g);\n !isNil(b) && (this.color.b = b);\n\n return this;\n }\n\n setHex(value: string) {\n const formatValue = `${value}`.trim().toLowerCase();\n const isHex = REG_HEX.exec(formatValue);\n\n const hex = parseInt(isHex[1], 16);\n const hexLength = isHex[1].length;\n // #fff\n if (hexLength === 3) {\n return new RGB(\n ((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4),\n ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4),\n (hex & 0xf) + ((hex & 0xf) << 4),\n 1\n );\n }\n // #ffffff\n if (hexLength === 6) {\n return rgb(hex);\n }\n // #ffffffaa\n else if (hexLength === 8) {\n return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);\n }\n return this;\n }\n\n setColorName(name: string) {\n // color keywords\n const hex = DEFAULT_COLORS[name.toLowerCase()];\n\n if (typeof hex !== 'undefined') {\n // red\n this.setHex(hex);\n } else {\n // unknown color\n console.warn('THREE.Color: Unknown color ' + name);\n }\n\n return this;\n }\n\n setScalar(scalar: number) {\n this.color.r = scalar;\n this.color.g = scalar;\n this.color.b = scalar;\n return this;\n }\n\n setOpacity(o = 1) {\n this.color.opacity = o;\n return this;\n }\n\n getLuminance() {\n return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;\n }\n\n getLuminance2() {\n return (0.2627 * this.color.r + 0.678 * this.color.g + 0.0593 * this.color.b) / 255;\n }\n\n getLuminance3() {\n return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;\n }\n\n clone() {\n return new Color(this.color.toString());\n }\n\n copyGammaToLinear(color: Color, gammaFactor = 2.0) {\n this.color.r = Math.pow(color.color.r, gammaFactor);\n this.color.g = Math.pow(color.color.g, gammaFactor);\n this.color.b = Math.pow(color.color.b, gammaFactor);\n return this;\n }\n\n copyLinearToGamma(color: Color, gammaFactor = 2.0) {\n const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;\n\n this.color.r = Math.pow(color.color.r, safeInverse);\n this.color.g = Math.pow(color.color.g, safeInverse);\n this.color.b = Math.pow(color.color.b, safeInverse);\n\n return this;\n }\n\n convertGammaToLinear(gammaFactor: number) {\n this.copyGammaToLinear(this, gammaFactor);\n return this;\n }\n\n convertLinearToGamma(gammaFactor: number) {\n this.copyLinearToGamma(this, gammaFactor);\n return this;\n }\n\n copySRGBToLinear(color: Color) {\n this.color.r = SRGBToLinear(color.color.r);\n this.color.g = SRGBToLinear(color.color.g);\n this.color.b = SRGBToLinear(color.color.b);\n return this;\n }\n\n copyLinearToSRGB(color: Color) {\n this.color.r = LinearToSRGB(color.color.r);\n this.color.g = LinearToSRGB(color.color.g);\n this.color.b = LinearToSRGB(color.color.b);\n return this;\n }\n\n convertSRGBToLinear() {\n this.copySRGBToLinear(this);\n return this;\n }\n\n convertLinearToSRGB() {\n this.copyLinearToSRGB(this);\n return this;\n }\n}\n\nexport class RGB {\n r: number;\n g: number;\n b: number;\n opacity: number;\n constructor(r: number, g: number, b: number, opacity?: number) {\n this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));\n this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));\n this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));\n\n if (isValid(opacity)) {\n this.opacity = isNaN(+(opacity as number)) ? 1 : Math.max(0, Math.min(1, +(opacity as number)));\n } else {\n this.opacity = 1;\n }\n }\n // 转为16进制\n formatHex() {\n return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;\n }\n formatRgb() {\n const opacity = this.opacity;\n return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;\n }\n\n formatHsl() {\n const opacity = this.opacity;\n const { h, s, l } = rgbToHsl(this.r, this.g, this.b);\n\n return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;\n }\n // 转为16进制\n toString() {\n return this.formatHex();\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export * from './textMeasure';
2
2
  export * from './interface';
3
- export * from './test';
4
3
  export * from './util';
@@ -18,5 +18,5 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
18
18
  Object.defineProperty(exports, "__esModule", {
19
19
  value: !0
20
20
  }), __exportStar(require("./textMeasure"), exports), __exportStar(require("./interface"), exports),
21
- __exportStar(require("./test"), exports), __exportStar(require("./util"), exports);
21
+ __exportStar(require("./util"), exports);
22
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphics/text/measure/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB;AACvB,yCAAuB","file":"index.js","sourcesContent":["export * from './textMeasure';\nexport * from './interface';\nexport * from './test';\nexport * from './util';\n"]}
1
+ {"version":3,"sources":["../src/graphics/text/measure/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB","file":"index.js","sourcesContent":["export * from './textMeasure';\nexport * from './interface';\nexport * from './util';\n"]}
package/dist/index.js CHANGED
@@ -2594,6 +2594,12 @@
2594
2594
  }
2595
2595
  return new RGB(255, 255, 255, 1);
2596
2596
  }
2597
+ function SRGBToLinear(c) {
2598
+ return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
2599
+ }
2600
+ function LinearToSRGB(c) {
2601
+ return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
2602
+ }
2597
2603
  class Color {
2598
2604
  static Brighter(source, b = 1) {
2599
2605
  if (b === 1) {
@@ -2680,10 +2686,6 @@
2680
2686
  toHsl() {
2681
2687
  return this.color.formatHsl();
2682
2688
  }
2683
- setOpacity(o = 1) {
2684
- this.color.opacity = o;
2685
- return this;
2686
- }
2687
2689
  brighter(k) {
2688
2690
  const { r, g, b } = this.color;
2689
2691
  this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));
@@ -2691,6 +2693,26 @@
2691
2693
  this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));
2692
2694
  return this;
2693
2695
  }
2696
+ add(color) {
2697
+ const { r, g, b } = this.color;
2698
+ this.color.r += Math.min(255, r + color.color.r);
2699
+ this.color.g += Math.min(255, g + color.color.g);
2700
+ this.color.b += Math.min(255, b + color.color.b);
2701
+ return this;
2702
+ }
2703
+ sub(color) {
2704
+ this.color.r = Math.max(0, this.color.r - color.color.r);
2705
+ this.color.g = Math.max(0, this.color.g - color.color.g);
2706
+ this.color.b = Math.max(0, this.color.b - color.color.b);
2707
+ return this;
2708
+ }
2709
+ multiply(color) {
2710
+ const { r, g, b } = this.color;
2711
+ this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r)));
2712
+ this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g)));
2713
+ this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b)));
2714
+ return this;
2715
+ }
2694
2716
  getHSVBrightness() {
2695
2717
  return Math.max(this.color.r, this.color.g, this.color.b) / 255;
2696
2718
  }
@@ -2706,6 +2728,48 @@
2706
2728
  this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);
2707
2729
  return this;
2708
2730
  }
2731
+ setRGB(r, g, b) {
2732
+ !isNil(r) && (this.color.r = r);
2733
+ !isNil(g) && (this.color.g = g);
2734
+ !isNil(b) && (this.color.b = b);
2735
+ return this;
2736
+ }
2737
+ setHex(value) {
2738
+ const formatValue = `${value}`.trim().toLowerCase();
2739
+ const isHex = REG_HEX.exec(formatValue);
2740
+ const hex = parseInt(isHex[1], 16);
2741
+ const hexLength = isHex[1].length;
2742
+ if (hexLength === 3) {
2743
+ return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
2744
+ }
2745
+ if (hexLength === 6) {
2746
+ return rgb(hex);
2747
+ }
2748
+ else if (hexLength === 8) {
2749
+ return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
2750
+ }
2751
+ return this;
2752
+ }
2753
+ setColorName(name) {
2754
+ const hex = DEFAULT_COLORS[name.toLowerCase()];
2755
+ if (typeof hex !== 'undefined') {
2756
+ this.setHex(hex);
2757
+ }
2758
+ else {
2759
+ console.warn('THREE.Color: Unknown color ' + name);
2760
+ }
2761
+ return this;
2762
+ }
2763
+ setScalar(scalar) {
2764
+ this.color.r = scalar;
2765
+ this.color.g = scalar;
2766
+ this.color.b = scalar;
2767
+ return this;
2768
+ }
2769
+ setOpacity(o = 1) {
2770
+ this.color.opacity = o;
2771
+ return this;
2772
+ }
2709
2773
  getLuminance() {
2710
2774
  return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;
2711
2775
  }
@@ -2715,6 +2779,50 @@
2715
2779
  getLuminance3() {
2716
2780
  return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;
2717
2781
  }
2782
+ clone() {
2783
+ return new Color(this.color.toString());
2784
+ }
2785
+ copyGammaToLinear(color, gammaFactor = 2.0) {
2786
+ this.color.r = Math.pow(color.color.r, gammaFactor);
2787
+ this.color.g = Math.pow(color.color.g, gammaFactor);
2788
+ this.color.b = Math.pow(color.color.b, gammaFactor);
2789
+ return this;
2790
+ }
2791
+ copyLinearToGamma(color, gammaFactor = 2.0) {
2792
+ const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
2793
+ this.color.r = Math.pow(color.color.r, safeInverse);
2794
+ this.color.g = Math.pow(color.color.g, safeInverse);
2795
+ this.color.b = Math.pow(color.color.b, safeInverse);
2796
+ return this;
2797
+ }
2798
+ convertGammaToLinear(gammaFactor) {
2799
+ this.copyGammaToLinear(this, gammaFactor);
2800
+ return this;
2801
+ }
2802
+ convertLinearToGamma(gammaFactor) {
2803
+ this.copyLinearToGamma(this, gammaFactor);
2804
+ return this;
2805
+ }
2806
+ copySRGBToLinear(color) {
2807
+ this.color.r = SRGBToLinear(color.color.r);
2808
+ this.color.g = SRGBToLinear(color.color.g);
2809
+ this.color.b = SRGBToLinear(color.color.b);
2810
+ return this;
2811
+ }
2812
+ copyLinearToSRGB(color) {
2813
+ this.color.r = LinearToSRGB(color.color.r);
2814
+ this.color.g = LinearToSRGB(color.color.g);
2815
+ this.color.b = LinearToSRGB(color.color.b);
2816
+ return this;
2817
+ }
2818
+ convertSRGBToLinear() {
2819
+ this.copySRGBToLinear(this);
2820
+ return this;
2821
+ }
2822
+ convertLinearToSRGB() {
2823
+ this.copyLinearToSRGB(this);
2824
+ return this;
2825
+ }
2718
2826
  }
2719
2827
  class RGB {
2720
2828
  constructor(r, g, b, opacity) {
@@ -3933,81 +4041,6 @@
3933
4041
  TextMeasure.NUMBERS_CHAR_SET = '0123456789';
3934
4042
  TextMeasure.FULL_SIZE_CHAR = '字';
3935
4043
 
3936
- const getNumberChar = () => {
3937
- return TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)];
3938
- };
3939
- const getTestNumbers = (length) => Array(length).fill(0).map(getNumberChar).join('');
3940
- const getLetterChar = () => {
3941
- return TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)];
3942
- };
3943
- const getTestWord = (length) => Array(length).fill(0).map(getLetterChar).join('');
3944
- class TestTextMeasure extends TextMeasure {
3945
- test(methods, getStrCallback, count) {
3946
- const sub = (numbers) => numbers.reduce((sum, cur) => sum + cur, 0);
3947
- const mean = (numbers) => sub(numbers) / numbers.length;
3948
- const variance = (numbers) => {
3949
- const m = mean(numbers);
3950
- return mean(numbers.map(num => Math.pow(num - m, 2)));
3951
- };
3952
- const callback = getStrCallback !== null && getStrCallback !== void 0 ? getStrCallback : (() => `测试${getTestWord(8)} ${getTestNumbers(4)}/${getTestNumbers(2)}-${getTestNumbers(2)}`);
3953
- const textArr = Array(count !== null && count !== void 0 ? count : 100000)
3954
- .fill(0)
3955
- .map(callback);
3956
- const methodMap = {
3957
- vrender: this.fullMeasure.bind(this),
3958
- canvas: this.measureWithNaiveCanvas.bind(this),
3959
- simple: this.quickMeasureWithoutCanvas.bind(this),
3960
- quick: this.quickMeasure.bind(this),
3961
- old: (text) => {
3962
- if (isNil(text)) {
3963
- return { width: 0, height: 0 };
3964
- }
3965
- const str = text.toString();
3966
- const { fontSize } = this.textSpec;
3967
- return {
3968
- width: fontSize * 0.8 * str.length,
3969
- height: fontSize
3970
- };
3971
- }
3972
- };
3973
- const methodList = methods !== null && methods !== void 0 ? methods : Object.keys(methodMap);
3974
- const report = {};
3975
- const timetmp = performance.now();
3976
- const standardResult = textArr.map(this._standardMethod);
3977
- const standardTime = performance.now() - timetmp;
3978
- report.standard = {
3979
- time: standardTime
3980
- };
3981
- methodList.forEach(method => {
3982
- const testMethod = methodMap[method];
3983
- if (testMethod) {
3984
- const timetmp = performance.now();
3985
- const testResult = textArr.map(testMethod);
3986
- const testTime = performance.now() - timetmp;
3987
- const errList = textArr.map((_, i) => ({
3988
- width: testResult[i].width - standardResult[i].width,
3989
- height: testResult[i].height - standardResult[i].height
3990
- }));
3991
- report[method] = {
3992
- errMean: {
3993
- width: mean(errList.map(e => e.width)),
3994
- height: mean(errList.map(e => e.height))
3995
- },
3996
- errVar: {
3997
- width: variance(errList.map(e => e.width)),
3998
- height: variance(errList.map(e => e.height))
3999
- },
4000
- time: testTime
4001
- };
4002
- }
4003
- });
4004
- return {
4005
- report,
4006
- textArr
4007
- };
4008
- }
4009
- }
4010
-
4011
4044
  const hasConsole = typeof console !== 'undefined';
4012
4045
  function log(method, level, input) {
4013
4046
  const args = [level].concat([].slice.call(input));
@@ -4732,7 +4765,6 @@
4732
4765
  exports.SECOND = SECOND;
4733
4766
  exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
4734
4767
  exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
4735
- exports.TestTextMeasure = TestTextMeasure;
4736
4768
  exports.TextMeasure = TextMeasure;
4737
4769
  exports.YEAR = YEAR;
4738
4770
  exports.abs = abs;
@@ -4796,8 +4828,6 @@
4796
4828
  exports.getScaleY = getScaleY;
4797
4829
  exports.getScrollLeft = getScrollLeft;
4798
4830
  exports.getScrollTop = getScrollTop;
4799
- exports.getTestNumbers = getTestNumbers;
4800
- exports.getTestWord = getTestWord;
4801
4831
  exports.getTimeFormatter = getTimeFormatter;
4802
4832
  exports.halfPi = halfPi;
4803
4833
  exports.has = has;