3d-force-graph 1.70.19 → 1.70.20

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.
@@ -1,4 +1,4 @@
1
- // Version 1.70.19 3d-force-graph - https://github.com/vasturiano/3d-force-graph
1
+ // Version 1.70.20 3d-force-graph - https://github.com/vasturiano/3d-force-graph
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -112,10 +112,10 @@
112
112
 
113
113
  /**
114
114
  * @license
115
- * Copyright 2010-2022 Three.js Authors
115
+ * Copyright 2010-2023 Three.js Authors
116
116
  * SPDX-License-Identifier: MIT
117
117
  */
118
- const REVISION = '148';
118
+ const REVISION = '149';
119
119
  const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
120
120
  const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
121
121
  const CullFaceNone = 0;
@@ -127,7 +127,6 @@
127
127
  const FrontSide = 0;
128
128
  const BackSide = 1;
129
129
  const DoubleSide = 2;
130
- const TwoPassDoubleSide = 3;
131
130
  const NoBlending = 0;
132
131
  const NormalBlending = 1;
133
132
  const AdditiveBlending = 2;
@@ -195,7 +194,6 @@
195
194
  const UnsignedShort5551Type = 1018;
196
195
  const UnsignedInt248Type = 1020;
197
196
  const AlphaFormat = 1021;
198
- const RGBFormat = 1022; // @deprecated since r137
199
197
  const RGBAFormat = 1023;
200
198
  const LuminanceFormat = 1024;
201
199
  const LuminanceAlphaFormat = 1025;
@@ -233,6 +231,10 @@
233
231
  const RGBA_ASTC_12x10_Format = 37820;
234
232
  const RGBA_ASTC_12x12_Format = 37821;
235
233
  const RGBA_BPTC_Format = 36492;
234
+ const RED_RGTC1_Format = 36283;
235
+ const SIGNED_RED_RGTC1_Format = 36284;
236
+ const RED_GREEN_RGTC2_Format = 36285;
237
+ const SIGNED_RED_GREEN_RGTC2_Format = 36286;
236
238
  const LinearEncoding = 3000;
237
239
  const sRGBEncoding = 3001;
238
240
  const BasicDepthPacking = 3200;
@@ -6819,7 +6821,7 @@
6819
6821
 
6820
6822
  class Euler {
6821
6823
 
6822
- constructor( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
6824
+ constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {
6823
6825
 
6824
6826
  this.isEuler = true;
6825
6827
 
@@ -7120,18 +7122,9 @@
7120
7122
 
7121
7123
  }
7122
7124
 
7123
- // @deprecated since r138, 02cf0df1cb4575d5842fef9c85bb5a89fe020d53
7124
-
7125
- toVector3() {
7126
-
7127
- console.error( 'THREE.Euler: .toVector3() has been removed. Use Vector3.setFromEuler() instead' );
7128
-
7129
- }
7130
-
7131
7125
  }
7132
7126
 
7133
- Euler.DefaultOrder = 'XYZ';
7134
- Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
7127
+ Euler.DEFAULT_ORDER = 'XYZ';
7135
7128
 
7136
7129
  class Layers {
7137
7130
 
@@ -7227,7 +7220,7 @@
7227
7220
  this.parent = null;
7228
7221
  this.children = [];
7229
7222
 
7230
- this.up = Object3D.DefaultUp.clone();
7223
+ this.up = Object3D.DEFAULT_UP.clone();
7231
7224
 
7232
7225
  const position = new Vector3();
7233
7226
  const rotation = new Euler();
@@ -7281,10 +7274,10 @@
7281
7274
  this.matrix = new Matrix4();
7282
7275
  this.matrixWorld = new Matrix4();
7283
7276
 
7284
- this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
7277
+ this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
7285
7278
  this.matrixWorldNeedsUpdate = false;
7286
7279
 
7287
- this.matrixWorldAutoUpdate = Object3D.DefaultMatrixWorldAutoUpdate; // checked by the renderer
7280
+ this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
7288
7281
 
7289
7282
  this.layers = new Layers();
7290
7283
  this.visible = true;
@@ -8147,9 +8140,9 @@
8147
8140
 
8148
8141
  }
8149
8142
 
8150
- Object3D.DefaultUp = /*@__PURE__*/ new Vector3( 0, 1, 0 );
8151
- Object3D.DefaultMatrixAutoUpdate = true;
8152
- Object3D.DefaultMatrixWorldAutoUpdate = true;
8143
+ Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
8144
+ Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
8145
+ Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
8153
8146
 
8154
8147
  const _v0$1 = /*@__PURE__*/ new Vector3();
8155
8148
  const _v1$3 = /*@__PURE__*/ new Vector3();
@@ -8509,6 +8502,7 @@
8509
8502
 
8510
8503
  this.alphaToCoverage = false;
8511
8504
  this.premultipliedAlpha = false;
8505
+ this.forceSinglePass = false;
8512
8506
 
8513
8507
  this.visible = true;
8514
8508
 
@@ -8790,6 +8784,7 @@
8790
8784
  if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
8791
8785
  if ( this.alphaToCoverage === true ) data.alphaToCoverage = this.alphaToCoverage;
8792
8786
  if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
8787
+ if ( this.forceSinglePass === true ) data.forceSinglePass = this.forceSinglePass;
8793
8788
 
8794
8789
  if ( this.wireframe === true ) data.wireframe = this.wireframe;
8795
8790
  if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
@@ -8910,6 +8905,7 @@
8910
8905
  this.alphaTest = source.alphaTest;
8911
8906
  this.alphaToCoverage = source.alphaToCoverage;
8912
8907
  this.premultipliedAlpha = source.premultipliedAlpha;
8908
+ this.forceSinglePass = source.forceSinglePass;
8913
8909
 
8914
8910
  this.visible = source.visible;
8915
8911
 
@@ -10578,14 +10574,14 @@
10578
10574
 
10579
10575
  }
10580
10576
 
10581
- getVertexPosition( vert, target ) {
10577
+ getVertexPosition( index, target ) {
10582
10578
 
10583
10579
  const geometry = this.geometry;
10584
10580
  const position = geometry.attributes.position;
10585
10581
  const morphPosition = geometry.morphAttributes.position;
10586
10582
  const morphTargetsRelative = geometry.morphTargetsRelative;
10587
10583
 
10588
- target.fromBufferAttribute( position, vert );
10584
+ target.fromBufferAttribute( position, index );
10589
10585
 
10590
10586
  const morphInfluences = this.morphTargetInfluences;
10591
10587
 
@@ -10600,7 +10596,7 @@
10600
10596
 
10601
10597
  if ( influence === 0 ) continue;
10602
10598
 
10603
- _tempA.fromBufferAttribute( morphAttribute, vert );
10599
+ _tempA.fromBufferAttribute( morphAttribute, index );
10604
10600
 
10605
10601
  if ( morphTargetsRelative ) {
10606
10602
 
@@ -10620,7 +10616,7 @@
10620
10616
 
10621
10617
  if ( this.isSkinnedMesh ) {
10622
10618
 
10623
- this.boneTransform( vert, target );
10619
+ this.boneTransform( index, target );
10624
10620
 
10625
10621
  }
10626
10622
 
@@ -12724,7 +12720,7 @@
12724
12720
 
12725
12721
  var shadowmap_pars_vertex = "#if NUM_SPOT_LIGHT_COORDS > 0\n uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
12726
12722
 
12727
- var shadowmap_vertex = "#if defined( USE_SHADOWMAP ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_COORDS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
12723
+ var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif";
12728
12724
 
12729
12725
  var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
12730
12726
 
@@ -14483,8 +14479,7 @@
14483
14479
 
14484
14480
  }
14485
14481
 
14486
- const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
14487
- ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
14482
+ const isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
14488
14483
 
14489
14484
  let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
14490
14485
  const maxPrecision = getMaxPrecision( precision );
@@ -14566,7 +14561,7 @@
14566
14561
  this.numPlanes = 0;
14567
14562
  this.numIntersection = 0;
14568
14563
 
14569
- this.init = function ( planes, enableLocalClipping, camera ) {
14564
+ this.init = function ( planes, enableLocalClipping ) {
14570
14565
 
14571
14566
  const enabled =
14572
14567
  planes.length !== 0 ||
@@ -14578,7 +14573,6 @@
14578
14573
 
14579
14574
  localClippingEnabled = enableLocalClipping;
14580
14575
 
14581
- globalState = projectPlanes( planes, camera, 0 );
14582
14576
  numGlobalPlanes = planes.length;
14583
14577
 
14584
14578
  return enabled;
@@ -14595,7 +14589,12 @@
14595
14589
  this.endShadows = function () {
14596
14590
 
14597
14591
  renderingShadows = false;
14598
- resetGlobalState();
14592
+
14593
+ };
14594
+
14595
+ this.setGlobalState = function ( planes, camera ) {
14596
+
14597
+ globalState = projectPlanes( planes, camera, 0 );
14599
14598
 
14600
14599
  };
14601
14600
 
@@ -15176,7 +15175,7 @@
15176
15175
 
15177
15176
  const cubeUVRenderTarget = _createRenderTarget( width, height, params );
15178
15177
 
15179
- if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width ) {
15178
+ if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height ) {
15180
15179
 
15181
15180
  if ( this._pingPongRenderTarget !== null ) {
15182
15181
 
@@ -20491,7 +20490,7 @@
20491
20490
 
20492
20491
  _maxTextureSize = _capabilities.maxTextureSize;
20493
20492
 
20494
- const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
20493
+ const shadowSide = { [ FrontSide ]: BackSide, [ BackSide ]: FrontSide, [ DoubleSide ]: DoubleSide };
20495
20494
 
20496
20495
  const shadowMaterialVertical = new ShaderMaterial( {
20497
20496
  defines: {
@@ -24160,15 +24159,6 @@
24160
24159
  if ( p === DepthFormat ) return 6402;
24161
24160
  if ( p === DepthStencilFormat ) return 34041;
24162
24161
 
24163
- // @deprecated since r137
24164
-
24165
- if ( p === RGBFormat ) {
24166
-
24167
- console.warn( 'THREE.WebGLRenderer: THREE.RGBFormat has been removed. Use THREE.RGBAFormat instead. https://github.com/mrdoob/three.js/pull/23228' );
24168
- return 6408;
24169
-
24170
- }
24171
-
24172
24162
  // WebGL 1 sRGB fallback
24173
24163
 
24174
24164
  if ( p === _SRGBAFormat ) {
@@ -24348,6 +24338,27 @@
24348
24338
 
24349
24339
  }
24350
24340
 
24341
+ // RGTC
24342
+
24343
+ if ( p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format ) {
24344
+
24345
+ extension = extensions.get( 'EXT_texture_compression_rgtc' );
24346
+
24347
+ if ( extension !== null ) {
24348
+
24349
+ if ( p === RGBA_BPTC_Format ) return extension.COMPRESSED_RED_RGTC1_EXT;
24350
+ if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT;
24351
+ if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT;
24352
+ if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
24353
+
24354
+ } else {
24355
+
24356
+ return null;
24357
+
24358
+ }
24359
+
24360
+ }
24361
+
24351
24362
  //
24352
24363
 
24353
24364
  if ( p === UnsignedInt248Type ) {
@@ -24786,6 +24797,8 @@
24786
24797
 
24787
24798
  let referenceSpace = null;
24788
24799
  let referenceSpaceType = 'local-floor';
24800
+ // Set default foveation to maximum.
24801
+ let foveation = 1.0;
24789
24802
  let customReferenceSpace = null;
24790
24803
 
24791
24804
  let pose = null;
@@ -25095,8 +25108,7 @@
25095
25108
 
25096
25109
  newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278
25097
25110
 
25098
- // Set foveation to maximum.
25099
- this.setFoveation( 1.0 );
25111
+ this.setFoveation( foveation );
25100
25112
 
25101
25113
  customReferenceSpace = null;
25102
25114
  referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
@@ -25325,36 +25337,32 @@
25325
25337
 
25326
25338
  this.getFoveation = function () {
25327
25339
 
25328
- if ( glProjLayer !== null ) {
25329
-
25330
- return glProjLayer.fixedFoveation;
25331
-
25332
- }
25333
-
25334
- if ( glBaseLayer !== null ) {
25340
+ if ( glProjLayer === null && glBaseLayer === null ) {
25335
25341
 
25336
- return glBaseLayer.fixedFoveation;
25342
+ return undefined;
25337
25343
 
25338
25344
  }
25339
25345
 
25340
- return undefined;
25346
+ return foveation;
25341
25347
 
25342
25348
  };
25343
25349
 
25344
- this.setFoveation = function ( foveation ) {
25350
+ this.setFoveation = function ( value ) {
25345
25351
 
25346
25352
  // 0 = no foveation = full resolution
25347
25353
  // 1 = maximum foveation = the edges render at lower resolution
25348
25354
 
25355
+ foveation = value;
25356
+
25349
25357
  if ( glProjLayer !== null ) {
25350
25358
 
25351
- glProjLayer.fixedFoveation = foveation;
25359
+ glProjLayer.fixedFoveation = value;
25352
25360
 
25353
25361
  }
25354
25362
 
25355
25363
  if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {
25356
25364
 
25357
- glBaseLayer.fixedFoveation = foveation;
25365
+ glBaseLayer.fixedFoveation = value;
25358
25366
 
25359
25367
  }
25360
25368
 
@@ -27419,7 +27427,7 @@
27419
27427
 
27420
27428
  function prepare( material, scene, object ) {
27421
27429
 
27422
- if ( material.transparent === true && material.side === TwoPassDoubleSide ) {
27430
+ if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
27423
27431
 
27424
27432
  material.side = BackSide;
27425
27433
  material.needsUpdate = true;
@@ -27429,7 +27437,7 @@
27429
27437
  material.needsUpdate = true;
27430
27438
  getProgram( material, scene, object );
27431
27439
 
27432
- material.side = TwoPassDoubleSide;
27440
+ material.side = DoubleSide;
27433
27441
 
27434
27442
  } else {
27435
27443
 
@@ -27573,7 +27581,7 @@
27573
27581
  _frustum.setFromProjectionMatrix( _projScreenMatrix );
27574
27582
 
27575
27583
  _localClippingEnabled = this.localClippingEnabled;
27576
- _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
27584
+ _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
27577
27585
 
27578
27586
  currentRenderList = renderLists.get( scene, renderListStack.length );
27579
27587
  currentRenderList.init();
@@ -27802,6 +27810,8 @@
27802
27810
 
27803
27811
  currentRenderState.setupLightsView( camera );
27804
27812
 
27813
+ if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera );
27814
+
27805
27815
  if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, scene, camera );
27806
27816
 
27807
27817
  if ( viewport ) state.viewport( _currentViewport.copy( viewport ) );
@@ -27901,7 +27911,7 @@
27901
27911
 
27902
27912
  material.onBeforeRender( _this, scene, camera, geometry, object, group );
27903
27913
 
27904
- if ( material.transparent === true && material.side === TwoPassDoubleSide ) {
27914
+ if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
27905
27915
 
27906
27916
  material.side = BackSide;
27907
27917
  material.needsUpdate = true;
@@ -27911,7 +27921,7 @@
27911
27921
  material.needsUpdate = true;
27912
27922
  _this.renderBufferDirect( camera, scene, geometry, material, object, group );
27913
27923
 
27914
- material.side = TwoPassDoubleSide;
27924
+ material.side = DoubleSide;
27915
27925
 
27916
27926
  } else {
27917
27927
 
@@ -28897,8 +28907,8 @@
28897
28907
  const data = super.toJSON( meta );
28898
28908
 
28899
28909
  if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
28900
- if ( this.backgroundBlurriness > 0 ) data.backgroundBlurriness = this.backgroundBlurriness;
28901
- if ( this.backgroundIntensity !== 1 ) data.backgroundIntensity = this.backgroundIntensity;
28910
+ if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
28911
+ if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
28902
28912
 
28903
28913
  return data;
28904
28914
 
@@ -31926,7 +31936,7 @@
31926
31936
 
31927
31937
  this.type = 'DirectionalLight';
31928
31938
 
31929
- this.position.copy( Object3D.DefaultUp );
31939
+ this.position.copy( Object3D.DEFAULT_UP );
31930
31940
  this.updateMatrix();
31931
31941
 
31932
31942
  this.target = new Object3D();
@@ -37948,1207 +37958,1282 @@ function InsertStackElement(node, body) {
37948
37958
 
37949
37959
  var schemePaired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
37950
37960
 
37951
- var tinycolorExports = {};
37952
- var tinycolor = {
37953
- get exports(){ return tinycolorExports; },
37954
- set exports(v){ tinycolorExports = v; },
37955
- };
37956
-
37957
- (function (module) {
37958
- // TinyColor v1.4.2
37959
- // https://github.com/bgrins/TinyColor
37960
- // Brian Grinstead, MIT License
37961
-
37962
- (function(Math) {
37963
-
37964
- var trimLeft = /^\s+/,
37965
- trimRight = /\s+$/,
37966
- tinyCounter = 0,
37967
- mathRound = Math.round,
37968
- mathMin = Math.min,
37969
- mathMax = Math.max,
37970
- mathRandom = Math.random;
37971
-
37972
- function tinycolor (color, opts) {
37973
-
37974
- color = (color) ? color : '';
37975
- opts = opts || { };
37976
-
37977
- // If input is already a tinycolor, return itself
37978
- if (color instanceof tinycolor) {
37979
- return color;
37980
- }
37981
- // If we are called as a function, call using new instead
37982
- if (!(this instanceof tinycolor)) {
37983
- return new tinycolor(color, opts);
37984
- }
37985
-
37986
- var rgb = inputToRGB(color);
37987
- this._originalInput = color,
37988
- this._r = rgb.r,
37989
- this._g = rgb.g,
37990
- this._b = rgb.b,
37991
- this._a = rgb.a,
37992
- this._roundA = mathRound(100*this._a) / 100,
37993
- this._format = opts.format || rgb.format;
37994
- this._gradientType = opts.gradientType;
37995
-
37996
- // Don't let the range of [0,255] come back in [0,1].
37997
- // Potentially lose a little bit of precision here, but will fix issues where
37998
- // .5 gets interpreted as half of the total, instead of half of 1
37999
- // If it was supposed to be 128, this was already taken care of by `inputToRgb`
38000
- if (this._r < 1) { this._r = mathRound(this._r); }
38001
- if (this._g < 1) { this._g = mathRound(this._g); }
38002
- if (this._b < 1) { this._b = mathRound(this._b); }
38003
-
38004
- this._ok = rgb.ok;
38005
- this._tc_id = tinyCounter++;
38006
- }
38007
-
38008
- tinycolor.prototype = {
38009
- isDark: function() {
38010
- return this.getBrightness() < 128;
38011
- },
38012
- isLight: function() {
38013
- return !this.isDark();
38014
- },
38015
- isValid: function() {
38016
- return this._ok;
38017
- },
38018
- getOriginalInput: function() {
38019
- return this._originalInput;
38020
- },
38021
- getFormat: function() {
38022
- return this._format;
38023
- },
38024
- getAlpha: function() {
38025
- return this._a;
38026
- },
38027
- getBrightness: function() {
38028
- //http://www.w3.org/TR/AERT#color-contrast
38029
- var rgb = this.toRgb();
38030
- return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
38031
- },
38032
- getLuminance: function() {
38033
- //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
38034
- var rgb = this.toRgb();
38035
- var RsRGB, GsRGB, BsRGB, R, G, B;
38036
- RsRGB = rgb.r/255;
38037
- GsRGB = rgb.g/255;
38038
- BsRGB = rgb.b/255;
38039
-
38040
- if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
38041
- if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
38042
- if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
38043
- return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
38044
- },
38045
- setAlpha: function(value) {
38046
- this._a = boundAlpha(value);
38047
- this._roundA = mathRound(100*this._a) / 100;
38048
- return this;
38049
- },
38050
- toHsv: function() {
38051
- var hsv = rgbToHsv(this._r, this._g, this._b);
38052
- return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
38053
- },
38054
- toHsvString: function() {
38055
- var hsv = rgbToHsv(this._r, this._g, this._b);
38056
- var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
38057
- return (this._a == 1) ?
38058
- "hsv(" + h + ", " + s + "%, " + v + "%)" :
38059
- "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
38060
- },
38061
- toHsl: function() {
38062
- var hsl = rgbToHsl(this._r, this._g, this._b);
38063
- return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
38064
- },
38065
- toHslString: function() {
38066
- var hsl = rgbToHsl(this._r, this._g, this._b);
38067
- var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
38068
- return (this._a == 1) ?
38069
- "hsl(" + h + ", " + s + "%, " + l + "%)" :
38070
- "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
38071
- },
38072
- toHex: function(allow3Char) {
38073
- return rgbToHex(this._r, this._g, this._b, allow3Char);
38074
- },
38075
- toHexString: function(allow3Char) {
38076
- return '#' + this.toHex(allow3Char);
38077
- },
38078
- toHex8: function(allow4Char) {
38079
- return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
38080
- },
38081
- toHex8String: function(allow4Char) {
38082
- return '#' + this.toHex8(allow4Char);
38083
- },
38084
- toRgb: function() {
38085
- return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
38086
- },
38087
- toRgbString: function() {
38088
- return (this._a == 1) ?
38089
- "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
38090
- "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
38091
- },
38092
- toPercentageRgb: function() {
38093
- return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
38094
- },
38095
- toPercentageRgbString: function() {
38096
- return (this._a == 1) ?
38097
- "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
38098
- "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
38099
- },
38100
- toName: function() {
38101
- if (this._a === 0) {
38102
- return "transparent";
38103
- }
38104
-
38105
- if (this._a < 1) {
38106
- return false;
38107
- }
38108
-
38109
- return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
38110
- },
38111
- toFilter: function(secondColor) {
38112
- var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
38113
- var secondHex8String = hex8String;
38114
- var gradientType = this._gradientType ? "GradientType = 1, " : "";
38115
-
38116
- if (secondColor) {
38117
- var s = tinycolor(secondColor);
38118
- secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
38119
- }
38120
-
38121
- return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
38122
- },
38123
- toString: function(format) {
38124
- var formatSet = !!format;
38125
- format = format || this._format;
38126
-
38127
- var formattedString = false;
38128
- var hasAlpha = this._a < 1 && this._a >= 0;
38129
- var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
38130
-
38131
- if (needsAlphaFormat) {
38132
- // Special case for "transparent", all other non-alpha formats
38133
- // will return rgba when there is transparency.
38134
- if (format === "name" && this._a === 0) {
38135
- return this.toName();
38136
- }
38137
- return this.toRgbString();
38138
- }
38139
- if (format === "rgb") {
38140
- formattedString = this.toRgbString();
38141
- }
38142
- if (format === "prgb") {
38143
- formattedString = this.toPercentageRgbString();
38144
- }
38145
- if (format === "hex" || format === "hex6") {
38146
- formattedString = this.toHexString();
38147
- }
38148
- if (format === "hex3") {
38149
- formattedString = this.toHexString(true);
38150
- }
38151
- if (format === "hex4") {
38152
- formattedString = this.toHex8String(true);
38153
- }
38154
- if (format === "hex8") {
38155
- formattedString = this.toHex8String();
38156
- }
38157
- if (format === "name") {
38158
- formattedString = this.toName();
38159
- }
38160
- if (format === "hsl") {
38161
- formattedString = this.toHslString();
38162
- }
38163
- if (format === "hsv") {
38164
- formattedString = this.toHsvString();
38165
- }
38166
-
38167
- return formattedString || this.toHexString();
38168
- },
38169
- clone: function() {
38170
- return tinycolor(this.toString());
38171
- },
38172
-
38173
- _applyModification: function(fn, args) {
38174
- var color = fn.apply(null, [this].concat([].slice.call(args)));
38175
- this._r = color._r;
38176
- this._g = color._g;
38177
- this._b = color._b;
38178
- this.setAlpha(color._a);
38179
- return this;
38180
- },
38181
- lighten: function() {
38182
- return this._applyModification(lighten, arguments);
38183
- },
38184
- brighten: function() {
38185
- return this._applyModification(brighten, arguments);
38186
- },
38187
- darken: function() {
38188
- return this._applyModification(darken, arguments);
38189
- },
38190
- desaturate: function() {
38191
- return this._applyModification(desaturate, arguments);
38192
- },
38193
- saturate: function() {
38194
- return this._applyModification(saturate, arguments);
38195
- },
38196
- greyscale: function() {
38197
- return this._applyModification(greyscale, arguments);
38198
- },
38199
- spin: function() {
38200
- return this._applyModification(spin, arguments);
38201
- },
38202
-
38203
- _applyCombination: function(fn, args) {
38204
- return fn.apply(null, [this].concat([].slice.call(args)));
38205
- },
38206
- analogous: function() {
38207
- return this._applyCombination(analogous, arguments);
38208
- },
38209
- complement: function() {
38210
- return this._applyCombination(complement, arguments);
38211
- },
38212
- monochromatic: function() {
38213
- return this._applyCombination(monochromatic, arguments);
38214
- },
38215
- splitcomplement: function() {
38216
- return this._applyCombination(splitcomplement, arguments);
38217
- },
38218
- triad: function() {
38219
- return this._applyCombination(triad, arguments);
38220
- },
38221
- tetrad: function() {
38222
- return this._applyCombination(tetrad, arguments);
38223
- }
38224
- };
38225
-
38226
- // If input is an object, force 1 into "1.0" to handle ratios properly
38227
- // String input requires "1.0" as input, so 1 will be treated as 1
38228
- tinycolor.fromRatio = function(color, opts) {
38229
- if (typeof color == "object") {
38230
- var newColor = {};
38231
- for (var i in color) {
38232
- if (color.hasOwnProperty(i)) {
38233
- if (i === "a") {
38234
- newColor[i] = color[i];
38235
- }
38236
- else {
38237
- newColor[i] = convertToPercentage(color[i]);
38238
- }
38239
- }
38240
- }
38241
- color = newColor;
38242
- }
38243
-
38244
- return tinycolor(color, opts);
38245
- };
38246
-
38247
- // Given a string or object, convert that input to RGB
38248
- // Possible string inputs:
38249
- //
38250
- // "red"
38251
- // "#f00" or "f00"
38252
- // "#ff0000" or "ff0000"
38253
- // "#ff000000" or "ff000000"
38254
- // "rgb 255 0 0" or "rgb (255, 0, 0)"
38255
- // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
38256
- // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
38257
- // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
38258
- // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
38259
- // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
38260
- // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
38261
- //
38262
- function inputToRGB(color) {
38263
-
38264
- var rgb = { r: 0, g: 0, b: 0 };
38265
- var a = 1;
38266
- var s = null;
38267
- var v = null;
38268
- var l = null;
38269
- var ok = false;
38270
- var format = false;
38271
-
38272
- if (typeof color == "string") {
38273
- color = stringInputToObject(color);
38274
- }
38275
-
38276
- if (typeof color == "object") {
38277
- if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
38278
- rgb = rgbToRgb(color.r, color.g, color.b);
38279
- ok = true;
38280
- format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
38281
- }
38282
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
38283
- s = convertToPercentage(color.s);
38284
- v = convertToPercentage(color.v);
38285
- rgb = hsvToRgb(color.h, s, v);
38286
- ok = true;
38287
- format = "hsv";
38288
- }
38289
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
38290
- s = convertToPercentage(color.s);
38291
- l = convertToPercentage(color.l);
38292
- rgb = hslToRgb(color.h, s, l);
38293
- ok = true;
38294
- format = "hsl";
38295
- }
38296
-
38297
- if (color.hasOwnProperty("a")) {
38298
- a = color.a;
38299
- }
38300
- }
38301
-
38302
- a = boundAlpha(a);
38303
-
38304
- return {
38305
- ok: ok,
38306
- format: color.format || format,
38307
- r: mathMin(255, mathMax(rgb.r, 0)),
38308
- g: mathMin(255, mathMax(rgb.g, 0)),
38309
- b: mathMin(255, mathMax(rgb.b, 0)),
38310
- a: a
38311
- };
38312
- }
38313
-
37961
+ // This file is autogenerated. It's used to publish ESM to npm.
37962
+ // https://github.com/bgrins/TinyColor
37963
+ // Brian Grinstead, MIT License
38314
37964
 
38315
- // Conversion Functions
38316
- // --------------------
37965
+ const trimLeft = /^\s+/;
37966
+ const trimRight = /\s+$/;
38317
37967
 
38318
- // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
38319
- // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
37968
+ function tinycolor(color, opts) {
37969
+ color = color ? color : "";
37970
+ opts = opts || {};
38320
37971
 
38321
- // `rgbToRgb`
38322
- // Handle bounds / percentage checking to conform to CSS color spec
38323
- // <http://www.w3.org/TR/css3-color/>
38324
- // *Assumes:* r, g, b in [0, 255] or [0, 1]
38325
- // *Returns:* { r, g, b } in [0, 255]
38326
- function rgbToRgb(r, g, b){
38327
- return {
38328
- r: bound01(r, 255) * 255,
38329
- g: bound01(g, 255) * 255,
38330
- b: bound01(b, 255) * 255
38331
- };
38332
- }
38333
-
38334
- // `rgbToHsl`
38335
- // Converts an RGB color value to HSL.
38336
- // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
38337
- // *Returns:* { h, s, l } in [0,1]
38338
- function rgbToHsl(r, g, b) {
38339
-
38340
- r = bound01(r, 255);
38341
- g = bound01(g, 255);
38342
- b = bound01(b, 255);
38343
-
38344
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
38345
- var h, s, l = (max + min) / 2;
38346
-
38347
- if(max == min) {
38348
- h = s = 0; // achromatic
38349
- }
38350
- else {
38351
- var d = max - min;
38352
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
38353
- switch(max) {
38354
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
38355
- case g: h = (b - r) / d + 2; break;
38356
- case b: h = (r - g) / d + 4; break;
38357
- }
37972
+ // If input is already a tinycolor, return itself
37973
+ if (color instanceof tinycolor) {
37974
+ return color;
37975
+ }
37976
+ // If we are called as a function, call using new instead
37977
+ if (!(this instanceof tinycolor)) {
37978
+ return new tinycolor(color, opts);
37979
+ }
38358
37980
 
38359
- h /= 6;
38360
- }
37981
+ var rgb = inputToRGB(color);
37982
+ (this._originalInput = color),
37983
+ (this._r = rgb.r),
37984
+ (this._g = rgb.g),
37985
+ (this._b = rgb.b),
37986
+ (this._a = rgb.a),
37987
+ (this._roundA = Math.round(100 * this._a) / 100),
37988
+ (this._format = opts.format || rgb.format);
37989
+ this._gradientType = opts.gradientType;
37990
+
37991
+ // Don't let the range of [0,255] come back in [0,1].
37992
+ // Potentially lose a little bit of precision here, but will fix issues where
37993
+ // .5 gets interpreted as half of the total, instead of half of 1
37994
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
37995
+ if (this._r < 1) this._r = Math.round(this._r);
37996
+ if (this._g < 1) this._g = Math.round(this._g);
37997
+ if (this._b < 1) this._b = Math.round(this._b);
37998
+
37999
+ this._ok = rgb.ok;
38000
+ }
38001
+
38002
+ tinycolor.prototype = {
38003
+ isDark: function () {
38004
+ return this.getBrightness() < 128;
38005
+ },
38006
+ isLight: function () {
38007
+ return !this.isDark();
38008
+ },
38009
+ isValid: function () {
38010
+ return this._ok;
38011
+ },
38012
+ getOriginalInput: function () {
38013
+ return this._originalInput;
38014
+ },
38015
+ getFormat: function () {
38016
+ return this._format;
38017
+ },
38018
+ getAlpha: function () {
38019
+ return this._a;
38020
+ },
38021
+ getBrightness: function () {
38022
+ //http://www.w3.org/TR/AERT#color-contrast
38023
+ var rgb = this.toRgb();
38024
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
38025
+ },
38026
+ getLuminance: function () {
38027
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
38028
+ var rgb = this.toRgb();
38029
+ var RsRGB, GsRGB, BsRGB, R, G, B;
38030
+ RsRGB = rgb.r / 255;
38031
+ GsRGB = rgb.g / 255;
38032
+ BsRGB = rgb.b / 255;
38033
+
38034
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;
38035
+ else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
38036
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;
38037
+ else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
38038
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;
38039
+ else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
38040
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
38041
+ },
38042
+ setAlpha: function (value) {
38043
+ this._a = boundAlpha(value);
38044
+ this._roundA = Math.round(100 * this._a) / 100;
38045
+ return this;
38046
+ },
38047
+ toHsv: function () {
38048
+ var hsv = rgbToHsv(this._r, this._g, this._b);
38049
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
38050
+ },
38051
+ toHsvString: function () {
38052
+ var hsv = rgbToHsv(this._r, this._g, this._b);
38053
+ var h = Math.round(hsv.h * 360),
38054
+ s = Math.round(hsv.s * 100),
38055
+ v = Math.round(hsv.v * 100);
38056
+ return this._a == 1
38057
+ ? "hsv(" + h + ", " + s + "%, " + v + "%)"
38058
+ : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
38059
+ },
38060
+ toHsl: function () {
38061
+ var hsl = rgbToHsl(this._r, this._g, this._b);
38062
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
38063
+ },
38064
+ toHslString: function () {
38065
+ var hsl = rgbToHsl(this._r, this._g, this._b);
38066
+ var h = Math.round(hsl.h * 360),
38067
+ s = Math.round(hsl.s * 100),
38068
+ l = Math.round(hsl.l * 100);
38069
+ return this._a == 1
38070
+ ? "hsl(" + h + ", " + s + "%, " + l + "%)"
38071
+ : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
38072
+ },
38073
+ toHex: function (allow3Char) {
38074
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
38075
+ },
38076
+ toHexString: function (allow3Char) {
38077
+ return "#" + this.toHex(allow3Char);
38078
+ },
38079
+ toHex8: function (allow4Char) {
38080
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
38081
+ },
38082
+ toHex8String: function (allow4Char) {
38083
+ return "#" + this.toHex8(allow4Char);
38084
+ },
38085
+ toRgb: function () {
38086
+ return {
38087
+ r: Math.round(this._r),
38088
+ g: Math.round(this._g),
38089
+ b: Math.round(this._b),
38090
+ a: this._a,
38091
+ };
38092
+ },
38093
+ toRgbString: function () {
38094
+ return this._a == 1
38095
+ ? "rgb(" +
38096
+ Math.round(this._r) +
38097
+ ", " +
38098
+ Math.round(this._g) +
38099
+ ", " +
38100
+ Math.round(this._b) +
38101
+ ")"
38102
+ : "rgba(" +
38103
+ Math.round(this._r) +
38104
+ ", " +
38105
+ Math.round(this._g) +
38106
+ ", " +
38107
+ Math.round(this._b) +
38108
+ ", " +
38109
+ this._roundA +
38110
+ ")";
38111
+ },
38112
+ toPercentageRgb: function () {
38113
+ return {
38114
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
38115
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
38116
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
38117
+ a: this._a,
38118
+ };
38119
+ },
38120
+ toPercentageRgbString: function () {
38121
+ return this._a == 1
38122
+ ? "rgb(" +
38123
+ Math.round(bound01(this._r, 255) * 100) +
38124
+ "%, " +
38125
+ Math.round(bound01(this._g, 255) * 100) +
38126
+ "%, " +
38127
+ Math.round(bound01(this._b, 255) * 100) +
38128
+ "%)"
38129
+ : "rgba(" +
38130
+ Math.round(bound01(this._r, 255) * 100) +
38131
+ "%, " +
38132
+ Math.round(bound01(this._g, 255) * 100) +
38133
+ "%, " +
38134
+ Math.round(bound01(this._b, 255) * 100) +
38135
+ "%, " +
38136
+ this._roundA +
38137
+ ")";
38138
+ },
38139
+ toName: function () {
38140
+ if (this._a === 0) {
38141
+ return "transparent";
38142
+ }
38361
38143
 
38362
- return { h: h, s: s, l: l };
38363
- }
38144
+ if (this._a < 1) {
38145
+ return false;
38146
+ }
38364
38147
 
38365
- // `hslToRgb`
38366
- // Converts an HSL color value to RGB.
38367
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
38368
- // *Returns:* { r, g, b } in the set [0, 255]
38369
- function hslToRgb(h, s, l) {
38370
- var r, g, b;
38148
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
38149
+ },
38150
+ toFilter: function (secondColor) {
38151
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
38152
+ var secondHex8String = hex8String;
38153
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
38154
+
38155
+ if (secondColor) {
38156
+ var s = tinycolor(secondColor);
38157
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
38158
+ }
38371
38159
 
38372
- h = bound01(h, 360);
38373
- s = bound01(s, 100);
38374
- l = bound01(l, 100);
38160
+ return (
38161
+ "progid:DXImageTransform.Microsoft.gradient(" +
38162
+ gradientType +
38163
+ "startColorstr=" +
38164
+ hex8String +
38165
+ ",endColorstr=" +
38166
+ secondHex8String +
38167
+ ")"
38168
+ );
38169
+ },
38170
+ toString: function (format) {
38171
+ var formatSet = !!format;
38172
+ format = format || this._format;
38173
+
38174
+ var formattedString = false;
38175
+ var hasAlpha = this._a < 1 && this._a >= 0;
38176
+ var needsAlphaFormat =
38177
+ !formatSet &&
38178
+ hasAlpha &&
38179
+ (format === "hex" ||
38180
+ format === "hex6" ||
38181
+ format === "hex3" ||
38182
+ format === "hex4" ||
38183
+ format === "hex8" ||
38184
+ format === "name");
38185
+
38186
+ if (needsAlphaFormat) {
38187
+ // Special case for "transparent", all other non-alpha formats
38188
+ // will return rgba when there is transparency.
38189
+ if (format === "name" && this._a === 0) {
38190
+ return this.toName();
38191
+ }
38192
+ return this.toRgbString();
38193
+ }
38194
+ if (format === "rgb") {
38195
+ formattedString = this.toRgbString();
38196
+ }
38197
+ if (format === "prgb") {
38198
+ formattedString = this.toPercentageRgbString();
38199
+ }
38200
+ if (format === "hex" || format === "hex6") {
38201
+ formattedString = this.toHexString();
38202
+ }
38203
+ if (format === "hex3") {
38204
+ formattedString = this.toHexString(true);
38205
+ }
38206
+ if (format === "hex4") {
38207
+ formattedString = this.toHex8String(true);
38208
+ }
38209
+ if (format === "hex8") {
38210
+ formattedString = this.toHex8String();
38211
+ }
38212
+ if (format === "name") {
38213
+ formattedString = this.toName();
38214
+ }
38215
+ if (format === "hsl") {
38216
+ formattedString = this.toHslString();
38217
+ }
38218
+ if (format === "hsv") {
38219
+ formattedString = this.toHsvString();
38220
+ }
38375
38221
 
38376
- function hue2rgb(p, q, t) {
38377
- if(t < 0) t += 1;
38378
- if(t > 1) t -= 1;
38379
- if(t < 1/6) return p + (q - p) * 6 * t;
38380
- if(t < 1/2) return q;
38381
- if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
38382
- return p;
38383
- }
38222
+ return formattedString || this.toHexString();
38223
+ },
38224
+ clone: function () {
38225
+ return tinycolor(this.toString());
38226
+ },
38384
38227
 
38385
- if(s === 0) {
38386
- r = g = b = l; // achromatic
38387
- }
38388
- else {
38389
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
38390
- var p = 2 * l - q;
38391
- r = hue2rgb(p, q, h + 1/3);
38392
- g = hue2rgb(p, q, h);
38393
- b = hue2rgb(p, q, h - 1/3);
38394
- }
38228
+ _applyModification: function (fn, args) {
38229
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
38230
+ this._r = color._r;
38231
+ this._g = color._g;
38232
+ this._b = color._b;
38233
+ this.setAlpha(color._a);
38234
+ return this;
38235
+ },
38236
+ lighten: function () {
38237
+ return this._applyModification(lighten, arguments);
38238
+ },
38239
+ brighten: function () {
38240
+ return this._applyModification(brighten, arguments);
38241
+ },
38242
+ darken: function () {
38243
+ return this._applyModification(darken, arguments);
38244
+ },
38245
+ desaturate: function () {
38246
+ return this._applyModification(desaturate, arguments);
38247
+ },
38248
+ saturate: function () {
38249
+ return this._applyModification(saturate, arguments);
38250
+ },
38251
+ greyscale: function () {
38252
+ return this._applyModification(greyscale, arguments);
38253
+ },
38254
+ spin: function () {
38255
+ return this._applyModification(spin, arguments);
38256
+ },
38395
38257
 
38396
- return { r: r * 255, g: g * 255, b: b * 255 };
38397
- }
38258
+ _applyCombination: function (fn, args) {
38259
+ return fn.apply(null, [this].concat([].slice.call(args)));
38260
+ },
38261
+ analogous: function () {
38262
+ return this._applyCombination(analogous, arguments);
38263
+ },
38264
+ complement: function () {
38265
+ return this._applyCombination(complement, arguments);
38266
+ },
38267
+ monochromatic: function () {
38268
+ return this._applyCombination(monochromatic, arguments);
38269
+ },
38270
+ splitcomplement: function () {
38271
+ return this._applyCombination(splitcomplement, arguments);
38272
+ },
38273
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
38274
+ // polyad: function (number) {
38275
+ // return this._applyCombination(polyad, [number]);
38276
+ // },
38277
+ triad: function () {
38278
+ return this._applyCombination(polyad, [3]);
38279
+ },
38280
+ tetrad: function () {
38281
+ return this._applyCombination(polyad, [4]);
38282
+ },
38283
+ };
38398
38284
 
38399
- // `rgbToHsv`
38400
- // Converts an RGB color value to HSV
38401
- // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
38402
- // *Returns:* { h, s, v } in [0,1]
38403
- function rgbToHsv(r, g, b) {
38285
+ // If input is an object, force 1 into "1.0" to handle ratios properly
38286
+ // String input requires "1.0" as input, so 1 will be treated as 1
38287
+ tinycolor.fromRatio = function (color, opts) {
38288
+ if (typeof color == "object") {
38289
+ var newColor = {};
38290
+ for (var i in color) {
38291
+ if (color.hasOwnProperty(i)) {
38292
+ if (i === "a") {
38293
+ newColor[i] = color[i];
38294
+ } else {
38295
+ newColor[i] = convertToPercentage(color[i]);
38296
+ }
38297
+ }
38298
+ }
38299
+ color = newColor;
38300
+ }
38404
38301
 
38405
- r = bound01(r, 255);
38406
- g = bound01(g, 255);
38407
- b = bound01(b, 255);
38302
+ return tinycolor(color, opts);
38303
+ };
38408
38304
 
38409
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
38410
- var h, s, v = max;
38305
+ // Given a string or object, convert that input to RGB
38306
+ // Possible string inputs:
38307
+ //
38308
+ // "red"
38309
+ // "#f00" or "f00"
38310
+ // "#ff0000" or "ff0000"
38311
+ // "#ff000000" or "ff000000"
38312
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
38313
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
38314
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
38315
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
38316
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
38317
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
38318
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
38319
+ //
38320
+ function inputToRGB(color) {
38321
+ var rgb = { r: 0, g: 0, b: 0 };
38322
+ var a = 1;
38323
+ var s = null;
38324
+ var v = null;
38325
+ var l = null;
38326
+ var ok = false;
38327
+ var format = false;
38328
+
38329
+ if (typeof color == "string") {
38330
+ color = stringInputToObject(color);
38331
+ }
38411
38332
 
38412
- var d = max - min;
38413
- s = max === 0 ? 0 : d / max;
38333
+ if (typeof color == "object") {
38334
+ if (
38335
+ isValidCSSUnit(color.r) &&
38336
+ isValidCSSUnit(color.g) &&
38337
+ isValidCSSUnit(color.b)
38338
+ ) {
38339
+ rgb = rgbToRgb(color.r, color.g, color.b);
38340
+ ok = true;
38341
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
38342
+ } else if (
38343
+ isValidCSSUnit(color.h) &&
38344
+ isValidCSSUnit(color.s) &&
38345
+ isValidCSSUnit(color.v)
38346
+ ) {
38347
+ s = convertToPercentage(color.s);
38348
+ v = convertToPercentage(color.v);
38349
+ rgb = hsvToRgb(color.h, s, v);
38350
+ ok = true;
38351
+ format = "hsv";
38352
+ } else if (
38353
+ isValidCSSUnit(color.h) &&
38354
+ isValidCSSUnit(color.s) &&
38355
+ isValidCSSUnit(color.l)
38356
+ ) {
38357
+ s = convertToPercentage(color.s);
38358
+ l = convertToPercentage(color.l);
38359
+ rgb = hslToRgb$1(color.h, s, l);
38360
+ ok = true;
38361
+ format = "hsl";
38362
+ }
38414
38363
 
38415
- if(max == min) {
38416
- h = 0; // achromatic
38417
- }
38418
- else {
38419
- switch(max) {
38420
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
38421
- case g: h = (b - r) / d + 2; break;
38422
- case b: h = (r - g) / d + 4; break;
38423
- }
38424
- h /= 6;
38425
- }
38426
- return { h: h, s: s, v: v };
38427
- }
38428
-
38429
- // `hsvToRgb`
38430
- // Converts an HSV color value to RGB.
38431
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
38432
- // *Returns:* { r, g, b } in the set [0, 255]
38433
- function hsvToRgb(h, s, v) {
38434
-
38435
- h = bound01(h, 360) * 6;
38436
- s = bound01(s, 100);
38437
- v = bound01(v, 100);
38438
-
38439
- var i = Math.floor(h),
38440
- f = h - i,
38441
- p = v * (1 - s),
38442
- q = v * (1 - f * s),
38443
- t = v * (1 - (1 - f) * s),
38444
- mod = i % 6,
38445
- r = [v, q, p, p, t, v][mod],
38446
- g = [t, v, v, q, p, p][mod],
38447
- b = [p, p, t, v, v, q][mod];
38448
-
38449
- return { r: r * 255, g: g * 255, b: b * 255 };
38450
- }
38451
-
38452
- // `rgbToHex`
38453
- // Converts an RGB color to hex
38454
- // Assumes r, g, and b are contained in the set [0, 255]
38455
- // Returns a 3 or 6 character hex
38456
- function rgbToHex(r, g, b, allow3Char) {
38457
-
38458
- var hex = [
38459
- pad2(mathRound(r).toString(16)),
38460
- pad2(mathRound(g).toString(16)),
38461
- pad2(mathRound(b).toString(16))
38462
- ];
38463
-
38464
- // Return a 3 character hex if possible
38465
- if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
38466
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
38467
- }
38364
+ if (color.hasOwnProperty("a")) {
38365
+ a = color.a;
38366
+ }
38367
+ }
38468
38368
 
38469
- return hex.join("");
38470
- }
38369
+ a = boundAlpha(a);
38471
38370
 
38472
- // `rgbaToHex`
38473
- // Converts an RGBA color plus alpha transparency to hex
38474
- // Assumes r, g, b are contained in the set [0, 255] and
38475
- // a in [0, 1]. Returns a 4 or 8 character rgba hex
38476
- function rgbaToHex(r, g, b, a, allow4Char) {
38371
+ return {
38372
+ ok: ok,
38373
+ format: color.format || format,
38374
+ r: Math.min(255, Math.max(rgb.r, 0)),
38375
+ g: Math.min(255, Math.max(rgb.g, 0)),
38376
+ b: Math.min(255, Math.max(rgb.b, 0)),
38377
+ a: a,
38378
+ };
38379
+ }
38477
38380
 
38478
- var hex = [
38479
- pad2(mathRound(r).toString(16)),
38480
- pad2(mathRound(g).toString(16)),
38481
- pad2(mathRound(b).toString(16)),
38482
- pad2(convertDecimalToHex(a))
38483
- ];
38381
+ // Conversion Functions
38382
+ // --------------------
38484
38383
 
38485
- // Return a 4 character hex if possible
38486
- if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
38487
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
38488
- }
38384
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
38385
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
38489
38386
 
38490
- return hex.join("");
38491
- }
38387
+ // `rgbToRgb`
38388
+ // Handle bounds / percentage checking to conform to CSS color spec
38389
+ // <http://www.w3.org/TR/css3-color/>
38390
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
38391
+ // *Returns:* { r, g, b } in [0, 255]
38392
+ function rgbToRgb(r, g, b) {
38393
+ return {
38394
+ r: bound01(r, 255) * 255,
38395
+ g: bound01(g, 255) * 255,
38396
+ b: bound01(b, 255) * 255,
38397
+ };
38398
+ }
38492
38399
 
38493
- // `rgbaToArgbHex`
38494
- // Converts an RGBA color to an ARGB Hex8 string
38495
- // Rarely used, but required for "toFilter()"
38496
- function rgbaToArgbHex(r, g, b, a) {
38400
+ // `rgbToHsl`
38401
+ // Converts an RGB color value to HSL.
38402
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
38403
+ // *Returns:* { h, s, l } in [0,1]
38404
+ function rgbToHsl(r, g, b) {
38405
+ r = bound01(r, 255);
38406
+ g = bound01(g, 255);
38407
+ b = bound01(b, 255);
38497
38408
 
38498
- var hex = [
38499
- pad2(convertDecimalToHex(a)),
38500
- pad2(mathRound(r).toString(16)),
38501
- pad2(mathRound(g).toString(16)),
38502
- pad2(mathRound(b).toString(16))
38503
- ];
38409
+ var max = Math.max(r, g, b),
38410
+ min = Math.min(r, g, b);
38411
+ var h,
38412
+ s,
38413
+ l = (max + min) / 2;
38504
38414
 
38505
- return hex.join("");
38506
- }
38415
+ if (max == min) {
38416
+ h = s = 0; // achromatic
38417
+ } else {
38418
+ var d = max - min;
38419
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
38420
+ switch (max) {
38421
+ case r:
38422
+ h = (g - b) / d + (g < b ? 6 : 0);
38423
+ break;
38424
+ case g:
38425
+ h = (b - r) / d + 2;
38426
+ break;
38427
+ case b:
38428
+ h = (r - g) / d + 4;
38429
+ break;
38430
+ }
38507
38431
 
38508
- // `equals`
38509
- // Can be called with any tinycolor input
38510
- tinycolor.equals = function (color1, color2) {
38511
- if (!color1 || !color2) { return false; }
38512
- return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
38513
- };
38432
+ h /= 6;
38433
+ }
38514
38434
 
38515
- tinycolor.random = function() {
38516
- return tinycolor.fromRatio({
38517
- r: mathRandom(),
38518
- g: mathRandom(),
38519
- b: mathRandom()
38520
- });
38521
- };
38435
+ return { h: h, s: s, l: l };
38436
+ }
38522
38437
 
38438
+ // `hslToRgb`
38439
+ // Converts an HSL color value to RGB.
38440
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
38441
+ // *Returns:* { r, g, b } in the set [0, 255]
38442
+ function hslToRgb$1(h, s, l) {
38443
+ var r, g, b;
38523
38444
 
38524
- // Modification Functions
38525
- // ----------------------
38526
- // Thanks to less.js for some of the basics here
38527
- // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
38445
+ h = bound01(h, 360);
38446
+ s = bound01(s, 100);
38447
+ l = bound01(l, 100);
38528
38448
 
38529
- function desaturate(color, amount) {
38530
- amount = (amount === 0) ? 0 : (amount || 10);
38531
- var hsl = tinycolor(color).toHsl();
38532
- hsl.s -= amount / 100;
38533
- hsl.s = clamp01(hsl.s);
38534
- return tinycolor(hsl);
38535
- }
38449
+ function hue2rgb(p, q, t) {
38450
+ if (t < 0) t += 1;
38451
+ if (t > 1) t -= 1;
38452
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
38453
+ if (t < 1 / 2) return q;
38454
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
38455
+ return p;
38456
+ }
38536
38457
 
38537
- function saturate(color, amount) {
38538
- amount = (amount === 0) ? 0 : (amount || 10);
38539
- var hsl = tinycolor(color).toHsl();
38540
- hsl.s += amount / 100;
38541
- hsl.s = clamp01(hsl.s);
38542
- return tinycolor(hsl);
38543
- }
38458
+ if (s === 0) {
38459
+ r = g = b = l; // achromatic
38460
+ } else {
38461
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
38462
+ var p = 2 * l - q;
38463
+ r = hue2rgb(p, q, h + 1 / 3);
38464
+ g = hue2rgb(p, q, h);
38465
+ b = hue2rgb(p, q, h - 1 / 3);
38466
+ }
38544
38467
 
38545
- function greyscale(color) {
38546
- return tinycolor(color).desaturate(100);
38547
- }
38468
+ return { r: r * 255, g: g * 255, b: b * 255 };
38469
+ }
38548
38470
 
38549
- function lighten (color, amount) {
38550
- amount = (amount === 0) ? 0 : (amount || 10);
38551
- var hsl = tinycolor(color).toHsl();
38552
- hsl.l += amount / 100;
38553
- hsl.l = clamp01(hsl.l);
38554
- return tinycolor(hsl);
38555
- }
38471
+ // `rgbToHsv`
38472
+ // Converts an RGB color value to HSV
38473
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
38474
+ // *Returns:* { h, s, v } in [0,1]
38475
+ function rgbToHsv(r, g, b) {
38476
+ r = bound01(r, 255);
38477
+ g = bound01(g, 255);
38478
+ b = bound01(b, 255);
38556
38479
 
38557
- function brighten(color, amount) {
38558
- amount = (amount === 0) ? 0 : (amount || 10);
38559
- var rgb = tinycolor(color).toRgb();
38560
- rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
38561
- rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
38562
- rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
38563
- return tinycolor(rgb);
38564
- }
38480
+ var max = Math.max(r, g, b),
38481
+ min = Math.min(r, g, b);
38482
+ var h,
38483
+ s,
38484
+ v = max;
38565
38485
 
38566
- function darken (color, amount) {
38567
- amount = (amount === 0) ? 0 : (amount || 10);
38568
- var hsl = tinycolor(color).toHsl();
38569
- hsl.l -= amount / 100;
38570
- hsl.l = clamp01(hsl.l);
38571
- return tinycolor(hsl);
38572
- }
38486
+ var d = max - min;
38487
+ s = max === 0 ? 0 : d / max;
38573
38488
 
38574
- // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
38575
- // Values outside of this range will be wrapped into this range.
38576
- function spin(color, amount) {
38577
- var hsl = tinycolor(color).toHsl();
38578
- var hue = (hsl.h + amount) % 360;
38579
- hsl.h = hue < 0 ? 360 + hue : hue;
38580
- return tinycolor(hsl);
38581
- }
38489
+ if (max == min) {
38490
+ h = 0; // achromatic
38491
+ } else {
38492
+ switch (max) {
38493
+ case r:
38494
+ h = (g - b) / d + (g < b ? 6 : 0);
38495
+ break;
38496
+ case g:
38497
+ h = (b - r) / d + 2;
38498
+ break;
38499
+ case b:
38500
+ h = (r - g) / d + 4;
38501
+ break;
38502
+ }
38503
+ h /= 6;
38504
+ }
38505
+ return { h: h, s: s, v: v };
38506
+ }
38507
+
38508
+ // `hsvToRgb`
38509
+ // Converts an HSV color value to RGB.
38510
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
38511
+ // *Returns:* { r, g, b } in the set [0, 255]
38512
+ function hsvToRgb(h, s, v) {
38513
+ h = bound01(h, 360) * 6;
38514
+ s = bound01(s, 100);
38515
+ v = bound01(v, 100);
38516
+
38517
+ var i = Math.floor(h),
38518
+ f = h - i,
38519
+ p = v * (1 - s),
38520
+ q = v * (1 - f * s),
38521
+ t = v * (1 - (1 - f) * s),
38522
+ mod = i % 6,
38523
+ r = [v, q, p, p, t, v][mod],
38524
+ g = [t, v, v, q, p, p][mod],
38525
+ b = [p, p, t, v, v, q][mod];
38526
+
38527
+ return { r: r * 255, g: g * 255, b: b * 255 };
38528
+ }
38529
+
38530
+ // `rgbToHex`
38531
+ // Converts an RGB color to hex
38532
+ // Assumes r, g, and b are contained in the set [0, 255]
38533
+ // Returns a 3 or 6 character hex
38534
+ function rgbToHex(r, g, b, allow3Char) {
38535
+ var hex = [
38536
+ pad2(Math.round(r).toString(16)),
38537
+ pad2(Math.round(g).toString(16)),
38538
+ pad2(Math.round(b).toString(16)),
38539
+ ];
38540
+
38541
+ // Return a 3 character hex if possible
38542
+ if (
38543
+ allow3Char &&
38544
+ hex[0].charAt(0) == hex[0].charAt(1) &&
38545
+ hex[1].charAt(0) == hex[1].charAt(1) &&
38546
+ hex[2].charAt(0) == hex[2].charAt(1)
38547
+ ) {
38548
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
38549
+ }
38582
38550
 
38583
- // Combination Functions
38584
- // ---------------------
38585
- // Thanks to jQuery xColor for some of the ideas behind these
38586
- // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
38551
+ return hex.join("");
38552
+ }
38553
+
38554
+ // `rgbaToHex`
38555
+ // Converts an RGBA color plus alpha transparency to hex
38556
+ // Assumes r, g, b are contained in the set [0, 255] and
38557
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
38558
+ function rgbaToHex(r, g, b, a, allow4Char) {
38559
+ var hex = [
38560
+ pad2(Math.round(r).toString(16)),
38561
+ pad2(Math.round(g).toString(16)),
38562
+ pad2(Math.round(b).toString(16)),
38563
+ pad2(convertDecimalToHex(a)),
38564
+ ];
38565
+
38566
+ // Return a 4 character hex if possible
38567
+ if (
38568
+ allow4Char &&
38569
+ hex[0].charAt(0) == hex[0].charAt(1) &&
38570
+ hex[1].charAt(0) == hex[1].charAt(1) &&
38571
+ hex[2].charAt(0) == hex[2].charAt(1) &&
38572
+ hex[3].charAt(0) == hex[3].charAt(1)
38573
+ ) {
38574
+ return (
38575
+ hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0)
38576
+ );
38577
+ }
38587
38578
 
38588
- function complement(color) {
38589
- var hsl = tinycolor(color).toHsl();
38590
- hsl.h = (hsl.h + 180) % 360;
38591
- return tinycolor(hsl);
38592
- }
38579
+ return hex.join("");
38580
+ }
38593
38581
 
38594
- function triad(color) {
38595
- var hsl = tinycolor(color).toHsl();
38596
- var h = hsl.h;
38597
- return [
38598
- tinycolor(color),
38599
- tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
38600
- tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
38601
- ];
38602
- }
38582
+ // `rgbaToArgbHex`
38583
+ // Converts an RGBA color to an ARGB Hex8 string
38584
+ // Rarely used, but required for "toFilter()"
38585
+ function rgbaToArgbHex(r, g, b, a) {
38586
+ var hex = [
38587
+ pad2(convertDecimalToHex(a)),
38588
+ pad2(Math.round(r).toString(16)),
38589
+ pad2(Math.round(g).toString(16)),
38590
+ pad2(Math.round(b).toString(16)),
38591
+ ];
38603
38592
 
38604
- function tetrad(color) {
38605
- var hsl = tinycolor(color).toHsl();
38606
- var h = hsl.h;
38607
- return [
38608
- tinycolor(color),
38609
- tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
38610
- tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
38611
- tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
38612
- ];
38613
- }
38593
+ return hex.join("");
38594
+ }
38614
38595
 
38615
- function splitcomplement(color) {
38616
- var hsl = tinycolor(color).toHsl();
38617
- var h = hsl.h;
38618
- return [
38619
- tinycolor(color),
38620
- tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
38621
- tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
38622
- ];
38623
- }
38624
-
38625
- function analogous(color, results, slices) {
38626
- results = results || 6;
38627
- slices = slices || 30;
38628
-
38629
- var hsl = tinycolor(color).toHsl();
38630
- var part = 360 / slices;
38631
- var ret = [tinycolor(color)];
38632
-
38633
- for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
38634
- hsl.h = (hsl.h + part) % 360;
38635
- ret.push(tinycolor(hsl));
38636
- }
38637
- return ret;
38638
- }
38596
+ // `equals`
38597
+ // Can be called with any tinycolor input
38598
+ tinycolor.equals = function (color1, color2) {
38599
+ if (!color1 || !color2) return false;
38600
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
38601
+ };
38639
38602
 
38640
- function monochromatic(color, results) {
38641
- results = results || 6;
38642
- var hsv = tinycolor(color).toHsv();
38643
- var h = hsv.h, s = hsv.s, v = hsv.v;
38644
- var ret = [];
38645
- var modification = 1 / results;
38603
+ tinycolor.random = function () {
38604
+ return tinycolor.fromRatio({
38605
+ r: Math.random(),
38606
+ g: Math.random(),
38607
+ b: Math.random(),
38608
+ });
38609
+ };
38646
38610
 
38647
- while (results--) {
38648
- ret.push(tinycolor({ h: h, s: s, v: v}));
38649
- v = (v + modification) % 1;
38650
- }
38611
+ // Modification Functions
38612
+ // ----------------------
38613
+ // Thanks to less.js for some of the basics here
38614
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
38651
38615
 
38652
- return ret;
38653
- }
38616
+ function desaturate(color, amount) {
38617
+ amount = amount === 0 ? 0 : amount || 10;
38618
+ var hsl = tinycolor(color).toHsl();
38619
+ hsl.s -= amount / 100;
38620
+ hsl.s = clamp01(hsl.s);
38621
+ return tinycolor(hsl);
38622
+ }
38654
38623
 
38655
- // Utility Functions
38656
- // ---------------------
38624
+ function saturate(color, amount) {
38625
+ amount = amount === 0 ? 0 : amount || 10;
38626
+ var hsl = tinycolor(color).toHsl();
38627
+ hsl.s += amount / 100;
38628
+ hsl.s = clamp01(hsl.s);
38629
+ return tinycolor(hsl);
38630
+ }
38657
38631
 
38658
- tinycolor.mix = function(color1, color2, amount) {
38659
- amount = (amount === 0) ? 0 : (amount || 50);
38632
+ function greyscale(color) {
38633
+ return tinycolor(color).desaturate(100);
38634
+ }
38660
38635
 
38661
- var rgb1 = tinycolor(color1).toRgb();
38662
- var rgb2 = tinycolor(color2).toRgb();
38636
+ function lighten(color, amount) {
38637
+ amount = amount === 0 ? 0 : amount || 10;
38638
+ var hsl = tinycolor(color).toHsl();
38639
+ hsl.l += amount / 100;
38640
+ hsl.l = clamp01(hsl.l);
38641
+ return tinycolor(hsl);
38642
+ }
38663
38643
 
38664
- var p = amount / 100;
38644
+ function brighten(color, amount) {
38645
+ amount = amount === 0 ? 0 : amount || 10;
38646
+ var rgb = tinycolor(color).toRgb();
38647
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
38648
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
38649
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
38650
+ return tinycolor(rgb);
38651
+ }
38665
38652
 
38666
- var rgba = {
38667
- r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
38668
- g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
38669
- b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
38670
- a: ((rgb2.a - rgb1.a) * p) + rgb1.a
38671
- };
38653
+ function darken(color, amount) {
38654
+ amount = amount === 0 ? 0 : amount || 10;
38655
+ var hsl = tinycolor(color).toHsl();
38656
+ hsl.l -= amount / 100;
38657
+ hsl.l = clamp01(hsl.l);
38658
+ return tinycolor(hsl);
38659
+ }
38672
38660
 
38673
- return tinycolor(rgba);
38674
- };
38661
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
38662
+ // Values outside of this range will be wrapped into this range.
38663
+ function spin(color, amount) {
38664
+ var hsl = tinycolor(color).toHsl();
38665
+ var hue = (hsl.h + amount) % 360;
38666
+ hsl.h = hue < 0 ? 360 + hue : hue;
38667
+ return tinycolor(hsl);
38668
+ }
38675
38669
 
38670
+ // Combination Functions
38671
+ // ---------------------
38672
+ // Thanks to jQuery xColor for some of the ideas behind these
38673
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
38676
38674
 
38677
- // Readability Functions
38678
- // ---------------------
38679
- // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
38675
+ function complement(color) {
38676
+ var hsl = tinycolor(color).toHsl();
38677
+ hsl.h = (hsl.h + 180) % 360;
38678
+ return tinycolor(hsl);
38679
+ }
38680
38680
 
38681
- // `contrast`
38682
- // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
38683
- tinycolor.readability = function(color1, color2) {
38684
- var c1 = tinycolor(color1);
38685
- var c2 = tinycolor(color2);
38686
- return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);
38687
- };
38681
+ function polyad(color, number) {
38682
+ if (isNaN(number) || number <= 0) {
38683
+ throw new Error("Argument to polyad must be a positive number");
38684
+ }
38685
+ var hsl = tinycolor(color).toHsl();
38686
+ var result = [tinycolor(color)];
38687
+ var step = 360 / number;
38688
+ for (var i = 1; i < number; i++) {
38689
+ result.push(tinycolor({ h: (hsl.h + i * step) % 360, s: hsl.s, l: hsl.l }));
38690
+ }
38688
38691
 
38689
- // `isReadable`
38690
- // Ensure that foreground and background color combinations meet WCAG2 guidelines.
38691
- // The third argument is an optional Object.
38692
- // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
38693
- // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
38694
- // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
38695
-
38696
- // *Example*
38697
- // tinycolor.isReadable("#000", "#111") => false
38698
- // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
38699
- tinycolor.isReadable = function(color1, color2, wcag2) {
38700
- var readability = tinycolor.readability(color1, color2);
38701
- var wcag2Parms, out;
38702
-
38703
- out = false;
38704
-
38705
- wcag2Parms = validateWCAG2Parms(wcag2);
38706
- switch (wcag2Parms.level + wcag2Parms.size) {
38707
- case "AAsmall":
38708
- case "AAAlarge":
38709
- out = readability >= 4.5;
38710
- break;
38711
- case "AAlarge":
38712
- out = readability >= 3;
38713
- break;
38714
- case "AAAsmall":
38715
- out = readability >= 7;
38716
- break;
38717
- }
38718
- return out;
38692
+ return result;
38693
+ }
38719
38694
 
38720
- };
38695
+ function splitcomplement(color) {
38696
+ var hsl = tinycolor(color).toHsl();
38697
+ var h = hsl.h;
38698
+ return [
38699
+ tinycolor(color),
38700
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
38701
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
38702
+ ];
38703
+ }
38721
38704
 
38722
- // `mostReadable`
38723
- // Given a base color and a list of possible foreground or background
38724
- // colors for that base, returns the most readable color.
38725
- // Optionally returns Black or White if the most readable color is unreadable.
38726
- // *Example*
38727
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
38728
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
38729
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
38730
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
38731
- tinycolor.mostReadable = function(baseColor, colorList, args) {
38732
- var bestColor = null;
38733
- var bestScore = 0;
38734
- var readability;
38735
- var includeFallbackColors, level, size ;
38736
- args = args || {};
38737
- includeFallbackColors = args.includeFallbackColors ;
38738
- level = args.level;
38739
- size = args.size;
38740
-
38741
- for (var i= 0; i < colorList.length ; i++) {
38742
- readability = tinycolor.readability(baseColor, colorList[i]);
38743
- if (readability > bestScore) {
38744
- bestScore = readability;
38745
- bestColor = tinycolor(colorList[i]);
38746
- }
38747
- }
38705
+ function analogous(color, results, slices) {
38706
+ results = results || 6;
38707
+ slices = slices || 30;
38748
38708
 
38749
- if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
38750
- return bestColor;
38751
- }
38752
- else {
38753
- args.includeFallbackColors=false;
38754
- return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
38755
- }
38756
- };
38709
+ var hsl = tinycolor(color).toHsl();
38710
+ var part = 360 / slices;
38711
+ var ret = [tinycolor(color)];
38757
38712
 
38713
+ for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results; ) {
38714
+ hsl.h = (hsl.h + part) % 360;
38715
+ ret.push(tinycolor(hsl));
38716
+ }
38717
+ return ret;
38718
+ }
38758
38719
 
38759
- // Big List of Colors
38760
- // ------------------
38761
- // <http://www.w3.org/TR/css3-color/#svg-color>
38762
- var names = tinycolor.names = {
38763
- aliceblue: "f0f8ff",
38764
- antiquewhite: "faebd7",
38765
- aqua: "0ff",
38766
- aquamarine: "7fffd4",
38767
- azure: "f0ffff",
38768
- beige: "f5f5dc",
38769
- bisque: "ffe4c4",
38770
- black: "000",
38771
- blanchedalmond: "ffebcd",
38772
- blue: "00f",
38773
- blueviolet: "8a2be2",
38774
- brown: "a52a2a",
38775
- burlywood: "deb887",
38776
- burntsienna: "ea7e5d",
38777
- cadetblue: "5f9ea0",
38778
- chartreuse: "7fff00",
38779
- chocolate: "d2691e",
38780
- coral: "ff7f50",
38781
- cornflowerblue: "6495ed",
38782
- cornsilk: "fff8dc",
38783
- crimson: "dc143c",
38784
- cyan: "0ff",
38785
- darkblue: "00008b",
38786
- darkcyan: "008b8b",
38787
- darkgoldenrod: "b8860b",
38788
- darkgray: "a9a9a9",
38789
- darkgreen: "006400",
38790
- darkgrey: "a9a9a9",
38791
- darkkhaki: "bdb76b",
38792
- darkmagenta: "8b008b",
38793
- darkolivegreen: "556b2f",
38794
- darkorange: "ff8c00",
38795
- darkorchid: "9932cc",
38796
- darkred: "8b0000",
38797
- darksalmon: "e9967a",
38798
- darkseagreen: "8fbc8f",
38799
- darkslateblue: "483d8b",
38800
- darkslategray: "2f4f4f",
38801
- darkslategrey: "2f4f4f",
38802
- darkturquoise: "00ced1",
38803
- darkviolet: "9400d3",
38804
- deeppink: "ff1493",
38805
- deepskyblue: "00bfff",
38806
- dimgray: "696969",
38807
- dimgrey: "696969",
38808
- dodgerblue: "1e90ff",
38809
- firebrick: "b22222",
38810
- floralwhite: "fffaf0",
38811
- forestgreen: "228b22",
38812
- fuchsia: "f0f",
38813
- gainsboro: "dcdcdc",
38814
- ghostwhite: "f8f8ff",
38815
- gold: "ffd700",
38816
- goldenrod: "daa520",
38817
- gray: "808080",
38818
- green: "008000",
38819
- greenyellow: "adff2f",
38820
- grey: "808080",
38821
- honeydew: "f0fff0",
38822
- hotpink: "ff69b4",
38823
- indianred: "cd5c5c",
38824
- indigo: "4b0082",
38825
- ivory: "fffff0",
38826
- khaki: "f0e68c",
38827
- lavender: "e6e6fa",
38828
- lavenderblush: "fff0f5",
38829
- lawngreen: "7cfc00",
38830
- lemonchiffon: "fffacd",
38831
- lightblue: "add8e6",
38832
- lightcoral: "f08080",
38833
- lightcyan: "e0ffff",
38834
- lightgoldenrodyellow: "fafad2",
38835
- lightgray: "d3d3d3",
38836
- lightgreen: "90ee90",
38837
- lightgrey: "d3d3d3",
38838
- lightpink: "ffb6c1",
38839
- lightsalmon: "ffa07a",
38840
- lightseagreen: "20b2aa",
38841
- lightskyblue: "87cefa",
38842
- lightslategray: "789",
38843
- lightslategrey: "789",
38844
- lightsteelblue: "b0c4de",
38845
- lightyellow: "ffffe0",
38846
- lime: "0f0",
38847
- limegreen: "32cd32",
38848
- linen: "faf0e6",
38849
- magenta: "f0f",
38850
- maroon: "800000",
38851
- mediumaquamarine: "66cdaa",
38852
- mediumblue: "0000cd",
38853
- mediumorchid: "ba55d3",
38854
- mediumpurple: "9370db",
38855
- mediumseagreen: "3cb371",
38856
- mediumslateblue: "7b68ee",
38857
- mediumspringgreen: "00fa9a",
38858
- mediumturquoise: "48d1cc",
38859
- mediumvioletred: "c71585",
38860
- midnightblue: "191970",
38861
- mintcream: "f5fffa",
38862
- mistyrose: "ffe4e1",
38863
- moccasin: "ffe4b5",
38864
- navajowhite: "ffdead",
38865
- navy: "000080",
38866
- oldlace: "fdf5e6",
38867
- olive: "808000",
38868
- olivedrab: "6b8e23",
38869
- orange: "ffa500",
38870
- orangered: "ff4500",
38871
- orchid: "da70d6",
38872
- palegoldenrod: "eee8aa",
38873
- palegreen: "98fb98",
38874
- paleturquoise: "afeeee",
38875
- palevioletred: "db7093",
38876
- papayawhip: "ffefd5",
38877
- peachpuff: "ffdab9",
38878
- peru: "cd853f",
38879
- pink: "ffc0cb",
38880
- plum: "dda0dd",
38881
- powderblue: "b0e0e6",
38882
- purple: "800080",
38883
- rebeccapurple: "663399",
38884
- red: "f00",
38885
- rosybrown: "bc8f8f",
38886
- royalblue: "4169e1",
38887
- saddlebrown: "8b4513",
38888
- salmon: "fa8072",
38889
- sandybrown: "f4a460",
38890
- seagreen: "2e8b57",
38891
- seashell: "fff5ee",
38892
- sienna: "a0522d",
38893
- silver: "c0c0c0",
38894
- skyblue: "87ceeb",
38895
- slateblue: "6a5acd",
38896
- slategray: "708090",
38897
- slategrey: "708090",
38898
- snow: "fffafa",
38899
- springgreen: "00ff7f",
38900
- steelblue: "4682b4",
38901
- tan: "d2b48c",
38902
- teal: "008080",
38903
- thistle: "d8bfd8",
38904
- tomato: "ff6347",
38905
- turquoise: "40e0d0",
38906
- violet: "ee82ee",
38907
- wheat: "f5deb3",
38908
- white: "fff",
38909
- whitesmoke: "f5f5f5",
38910
- yellow: "ff0",
38911
- yellowgreen: "9acd32"
38912
- };
38720
+ function monochromatic(color, results) {
38721
+ results = results || 6;
38722
+ var hsv = tinycolor(color).toHsv();
38723
+ var h = hsv.h,
38724
+ s = hsv.s,
38725
+ v = hsv.v;
38726
+ var ret = [];
38727
+ var modification = 1 / results;
38913
38728
 
38914
- // Make it easy to access colors via `hexNames[hex]`
38915
- var hexNames = tinycolor.hexNames = flip(names);
38729
+ while (results--) {
38730
+ ret.push(tinycolor({ h: h, s: s, v: v }));
38731
+ v = (v + modification) % 1;
38732
+ }
38916
38733
 
38734
+ return ret;
38735
+ }
38917
38736
 
38918
- // Utilities
38919
- // ---------
38737
+ // Utility Functions
38738
+ // ---------------------
38920
38739
 
38921
- // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
38922
- function flip(o) {
38923
- var flipped = { };
38924
- for (var i in o) {
38925
- if (o.hasOwnProperty(i)) {
38926
- flipped[o[i]] = i;
38927
- }
38928
- }
38929
- return flipped;
38930
- }
38740
+ tinycolor.mix = function (color1, color2, amount) {
38741
+ amount = amount === 0 ? 0 : amount || 50;
38931
38742
 
38932
- // Return a valid alpha value [0,1] with all invalid values being set to 1
38933
- function boundAlpha(a) {
38934
- a = parseFloat(a);
38743
+ var rgb1 = tinycolor(color1).toRgb();
38744
+ var rgb2 = tinycolor(color2).toRgb();
38935
38745
 
38936
- if (isNaN(a) || a < 0 || a > 1) {
38937
- a = 1;
38938
- }
38746
+ var p = amount / 100;
38939
38747
 
38940
- return a;
38941
- }
38748
+ var rgba = {
38749
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
38750
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
38751
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
38752
+ a: (rgb2.a - rgb1.a) * p + rgb1.a,
38753
+ };
38942
38754
 
38943
- // Take input from [0, n] and return it as [0, 1]
38944
- function bound01(n, max) {
38945
- if (isOnePointZero(n)) { n = "100%"; }
38755
+ return tinycolor(rgba);
38756
+ };
38946
38757
 
38947
- var processPercent = isPercentage(n);
38948
- n = mathMin(max, mathMax(0, parseFloat(n)));
38758
+ // Readability Functions
38759
+ // ---------------------
38760
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
38761
+
38762
+ // `contrast`
38763
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
38764
+ tinycolor.readability = function (color1, color2) {
38765
+ var c1 = tinycolor(color1);
38766
+ var c2 = tinycolor(color2);
38767
+ return (
38768
+ (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) /
38769
+ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)
38770
+ );
38771
+ };
38949
38772
 
38950
- // Automatically convert percentage into number
38951
- if (processPercent) {
38952
- n = parseInt(n * max, 10) / 100;
38953
- }
38773
+ // `isReadable`
38774
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
38775
+ // The third argument is an optional Object.
38776
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
38777
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
38778
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
38779
+
38780
+ // *Example*
38781
+ // tinycolor.isReadable("#000", "#111") => false
38782
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
38783
+ tinycolor.isReadable = function (color1, color2, wcag2) {
38784
+ var readability = tinycolor.readability(color1, color2);
38785
+ var wcag2Parms, out;
38786
+
38787
+ out = false;
38788
+
38789
+ wcag2Parms = validateWCAG2Parms(wcag2);
38790
+ switch (wcag2Parms.level + wcag2Parms.size) {
38791
+ case "AAsmall":
38792
+ case "AAAlarge":
38793
+ out = readability >= 4.5;
38794
+ break;
38795
+ case "AAlarge":
38796
+ out = readability >= 3;
38797
+ break;
38798
+ case "AAAsmall":
38799
+ out = readability >= 7;
38800
+ break;
38801
+ }
38802
+ return out;
38803
+ };
38954
38804
 
38955
- // Handle floating point rounding errors
38956
- if ((Math.abs(n - max) < 0.000001)) {
38957
- return 1;
38958
- }
38805
+ // `mostReadable`
38806
+ // Given a base color and a list of possible foreground or background
38807
+ // colors for that base, returns the most readable color.
38808
+ // Optionally returns Black or White if the most readable color is unreadable.
38809
+ // *Example*
38810
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
38811
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
38812
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
38813
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
38814
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
38815
+ var bestColor = null;
38816
+ var bestScore = 0;
38817
+ var readability;
38818
+ var includeFallbackColors, level, size;
38819
+ args = args || {};
38820
+ includeFallbackColors = args.includeFallbackColors;
38821
+ level = args.level;
38822
+ size = args.size;
38823
+
38824
+ for (var i = 0; i < colorList.length; i++) {
38825
+ readability = tinycolor.readability(baseColor, colorList[i]);
38826
+ if (readability > bestScore) {
38827
+ bestScore = readability;
38828
+ bestColor = tinycolor(colorList[i]);
38829
+ }
38830
+ }
38959
38831
 
38960
- // Convert into [0, 1] range if it isn't already
38961
- return (n % max) / parseFloat(max);
38962
- }
38832
+ if (
38833
+ tinycolor.isReadable(baseColor, bestColor, {
38834
+ level: level,
38835
+ size: size,
38836
+ }) ||
38837
+ !includeFallbackColors
38838
+ ) {
38839
+ return bestColor;
38840
+ } else {
38841
+ args.includeFallbackColors = false;
38842
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
38843
+ }
38844
+ };
38963
38845
 
38964
- // Force a number between 0 and 1
38965
- function clamp01(val) {
38966
- return mathMin(1, mathMax(0, val));
38967
- }
38846
+ // Big List of Colors
38847
+ // ------------------
38848
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
38849
+ var names = (tinycolor.names = {
38850
+ aliceblue: "f0f8ff",
38851
+ antiquewhite: "faebd7",
38852
+ aqua: "0ff",
38853
+ aquamarine: "7fffd4",
38854
+ azure: "f0ffff",
38855
+ beige: "f5f5dc",
38856
+ bisque: "ffe4c4",
38857
+ black: "000",
38858
+ blanchedalmond: "ffebcd",
38859
+ blue: "00f",
38860
+ blueviolet: "8a2be2",
38861
+ brown: "a52a2a",
38862
+ burlywood: "deb887",
38863
+ burntsienna: "ea7e5d",
38864
+ cadetblue: "5f9ea0",
38865
+ chartreuse: "7fff00",
38866
+ chocolate: "d2691e",
38867
+ coral: "ff7f50",
38868
+ cornflowerblue: "6495ed",
38869
+ cornsilk: "fff8dc",
38870
+ crimson: "dc143c",
38871
+ cyan: "0ff",
38872
+ darkblue: "00008b",
38873
+ darkcyan: "008b8b",
38874
+ darkgoldenrod: "b8860b",
38875
+ darkgray: "a9a9a9",
38876
+ darkgreen: "006400",
38877
+ darkgrey: "a9a9a9",
38878
+ darkkhaki: "bdb76b",
38879
+ darkmagenta: "8b008b",
38880
+ darkolivegreen: "556b2f",
38881
+ darkorange: "ff8c00",
38882
+ darkorchid: "9932cc",
38883
+ darkred: "8b0000",
38884
+ darksalmon: "e9967a",
38885
+ darkseagreen: "8fbc8f",
38886
+ darkslateblue: "483d8b",
38887
+ darkslategray: "2f4f4f",
38888
+ darkslategrey: "2f4f4f",
38889
+ darkturquoise: "00ced1",
38890
+ darkviolet: "9400d3",
38891
+ deeppink: "ff1493",
38892
+ deepskyblue: "00bfff",
38893
+ dimgray: "696969",
38894
+ dimgrey: "696969",
38895
+ dodgerblue: "1e90ff",
38896
+ firebrick: "b22222",
38897
+ floralwhite: "fffaf0",
38898
+ forestgreen: "228b22",
38899
+ fuchsia: "f0f",
38900
+ gainsboro: "dcdcdc",
38901
+ ghostwhite: "f8f8ff",
38902
+ gold: "ffd700",
38903
+ goldenrod: "daa520",
38904
+ gray: "808080",
38905
+ green: "008000",
38906
+ greenyellow: "adff2f",
38907
+ grey: "808080",
38908
+ honeydew: "f0fff0",
38909
+ hotpink: "ff69b4",
38910
+ indianred: "cd5c5c",
38911
+ indigo: "4b0082",
38912
+ ivory: "fffff0",
38913
+ khaki: "f0e68c",
38914
+ lavender: "e6e6fa",
38915
+ lavenderblush: "fff0f5",
38916
+ lawngreen: "7cfc00",
38917
+ lemonchiffon: "fffacd",
38918
+ lightblue: "add8e6",
38919
+ lightcoral: "f08080",
38920
+ lightcyan: "e0ffff",
38921
+ lightgoldenrodyellow: "fafad2",
38922
+ lightgray: "d3d3d3",
38923
+ lightgreen: "90ee90",
38924
+ lightgrey: "d3d3d3",
38925
+ lightpink: "ffb6c1",
38926
+ lightsalmon: "ffa07a",
38927
+ lightseagreen: "20b2aa",
38928
+ lightskyblue: "87cefa",
38929
+ lightslategray: "789",
38930
+ lightslategrey: "789",
38931
+ lightsteelblue: "b0c4de",
38932
+ lightyellow: "ffffe0",
38933
+ lime: "0f0",
38934
+ limegreen: "32cd32",
38935
+ linen: "faf0e6",
38936
+ magenta: "f0f",
38937
+ maroon: "800000",
38938
+ mediumaquamarine: "66cdaa",
38939
+ mediumblue: "0000cd",
38940
+ mediumorchid: "ba55d3",
38941
+ mediumpurple: "9370db",
38942
+ mediumseagreen: "3cb371",
38943
+ mediumslateblue: "7b68ee",
38944
+ mediumspringgreen: "00fa9a",
38945
+ mediumturquoise: "48d1cc",
38946
+ mediumvioletred: "c71585",
38947
+ midnightblue: "191970",
38948
+ mintcream: "f5fffa",
38949
+ mistyrose: "ffe4e1",
38950
+ moccasin: "ffe4b5",
38951
+ navajowhite: "ffdead",
38952
+ navy: "000080",
38953
+ oldlace: "fdf5e6",
38954
+ olive: "808000",
38955
+ olivedrab: "6b8e23",
38956
+ orange: "ffa500",
38957
+ orangered: "ff4500",
38958
+ orchid: "da70d6",
38959
+ palegoldenrod: "eee8aa",
38960
+ palegreen: "98fb98",
38961
+ paleturquoise: "afeeee",
38962
+ palevioletred: "db7093",
38963
+ papayawhip: "ffefd5",
38964
+ peachpuff: "ffdab9",
38965
+ peru: "cd853f",
38966
+ pink: "ffc0cb",
38967
+ plum: "dda0dd",
38968
+ powderblue: "b0e0e6",
38969
+ purple: "800080",
38970
+ rebeccapurple: "663399",
38971
+ red: "f00",
38972
+ rosybrown: "bc8f8f",
38973
+ royalblue: "4169e1",
38974
+ saddlebrown: "8b4513",
38975
+ salmon: "fa8072",
38976
+ sandybrown: "f4a460",
38977
+ seagreen: "2e8b57",
38978
+ seashell: "fff5ee",
38979
+ sienna: "a0522d",
38980
+ silver: "c0c0c0",
38981
+ skyblue: "87ceeb",
38982
+ slateblue: "6a5acd",
38983
+ slategray: "708090",
38984
+ slategrey: "708090",
38985
+ snow: "fffafa",
38986
+ springgreen: "00ff7f",
38987
+ steelblue: "4682b4",
38988
+ tan: "d2b48c",
38989
+ teal: "008080",
38990
+ thistle: "d8bfd8",
38991
+ tomato: "ff6347",
38992
+ turquoise: "40e0d0",
38993
+ violet: "ee82ee",
38994
+ wheat: "f5deb3",
38995
+ white: "fff",
38996
+ whitesmoke: "f5f5f5",
38997
+ yellow: "ff0",
38998
+ yellowgreen: "9acd32",
38999
+ });
38968
39000
 
38969
- // Parse a base-16 hex value into a base-10 integer
38970
- function parseIntFromHex(val) {
38971
- return parseInt(val, 16);
38972
- }
39001
+ // Make it easy to access colors via `hexNames[hex]`
39002
+ var hexNames = (tinycolor.hexNames = flip(names));
38973
39003
 
38974
- // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
38975
- // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
38976
- function isOnePointZero(n) {
38977
- return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
38978
- }
39004
+ // Utilities
39005
+ // ---------
38979
39006
 
38980
- // Check to see if string passed in is a percentage
38981
- function isPercentage(n) {
38982
- return typeof n === "string" && n.indexOf('%') != -1;
38983
- }
39007
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
39008
+ function flip(o) {
39009
+ var flipped = {};
39010
+ for (var i in o) {
39011
+ if (o.hasOwnProperty(i)) {
39012
+ flipped[o[i]] = i;
39013
+ }
39014
+ }
39015
+ return flipped;
39016
+ }
38984
39017
 
38985
- // Force a hex value to have 2 characters
38986
- function pad2(c) {
38987
- return c.length == 1 ? '0' + c : '' + c;
38988
- }
39018
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
39019
+ function boundAlpha(a) {
39020
+ a = parseFloat(a);
38989
39021
 
38990
- // Replace a decimal with it's percentage value
38991
- function convertToPercentage(n) {
38992
- if (n <= 1) {
38993
- n = (n * 100) + "%";
38994
- }
39022
+ if (isNaN(a) || a < 0 || a > 1) {
39023
+ a = 1;
39024
+ }
38995
39025
 
38996
- return n;
38997
- }
39026
+ return a;
39027
+ }
38998
39028
 
38999
- // Converts a decimal to a hex value
39000
- function convertDecimalToHex(d) {
39001
- return Math.round(parseFloat(d) * 255).toString(16);
39002
- }
39003
- // Converts a hex value to a decimal
39004
- function convertHexToDecimal(h) {
39005
- return (parseIntFromHex(h) / 255);
39006
- }
39029
+ // Take input from [0, n] and return it as [0, 1]
39030
+ function bound01(n, max) {
39031
+ if (isOnePointZero(n)) n = "100%";
39007
39032
 
39008
- var matchers = (function() {
39033
+ var processPercent = isPercentage(n);
39034
+ n = Math.min(max, Math.max(0, parseFloat(n)));
39009
39035
 
39010
- // <http://www.w3.org/TR/css3-values/#integers>
39011
- var CSS_INTEGER = "[-\\+]?\\d+%?";
39036
+ // Automatically convert percentage into number
39037
+ if (processPercent) {
39038
+ n = parseInt(n * max, 10) / 100;
39039
+ }
39012
39040
 
39013
- // <http://www.w3.org/TR/css3-values/#number-value>
39014
- var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
39041
+ // Handle floating point rounding errors
39042
+ if (Math.abs(n - max) < 0.000001) {
39043
+ return 1;
39044
+ }
39015
39045
 
39016
- // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
39017
- var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
39046
+ // Convert into [0, 1] range if it isn't already
39047
+ return (n % max) / parseFloat(max);
39048
+ }
39018
39049
 
39019
- // Actual matching.
39020
- // Parentheses and commas are optional, but not required.
39021
- // Whitespace can take the place of commas or opening paren
39022
- var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
39023
- var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
39050
+ // Force a number between 0 and 1
39051
+ function clamp01(val) {
39052
+ return Math.min(1, Math.max(0, val));
39053
+ }
39024
39054
 
39025
- return {
39026
- CSS_UNIT: new RegExp(CSS_UNIT),
39027
- rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
39028
- rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
39029
- hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
39030
- hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
39031
- hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
39032
- hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
39033
- hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
39034
- hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
39035
- hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
39036
- hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
39037
- };
39038
- })();
39055
+ // Parse a base-16 hex value into a base-10 integer
39056
+ function parseIntFromHex(val) {
39057
+ return parseInt(val, 16);
39058
+ }
39039
39059
 
39040
- // `isValidCSSUnit`
39041
- // Take in a single string / number and check to see if it looks like a CSS unit
39042
- // (see `matchers` above for definition).
39043
- function isValidCSSUnit(color) {
39044
- return !!matchers.CSS_UNIT.exec(color);
39045
- }
39060
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
39061
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
39062
+ function isOnePointZero(n) {
39063
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
39064
+ }
39046
39065
 
39047
- // `stringInputToObject`
39048
- // Permissive string parsing. Take in a number of formats, and output an object
39049
- // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
39050
- function stringInputToObject(color) {
39066
+ // Check to see if string passed in is a percentage
39067
+ function isPercentage(n) {
39068
+ return typeof n === "string" && n.indexOf("%") != -1;
39069
+ }
39051
39070
 
39052
- color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
39053
- var named = false;
39054
- if (names[color]) {
39055
- color = names[color];
39056
- named = true;
39057
- }
39058
- else if (color == 'transparent') {
39059
- return { r: 0, g: 0, b: 0, a: 0, format: "name" };
39060
- }
39071
+ // Force a hex value to have 2 characters
39072
+ function pad2(c) {
39073
+ return c.length == 1 ? "0" + c : "" + c;
39074
+ }
39061
39075
 
39062
- // Try to match string input using regular expressions.
39063
- // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
39064
- // Just return an object and let the conversion functions handle that.
39065
- // This way the result will be the same whether the tinycolor is initialized with string or object.
39066
- var match;
39067
- if ((match = matchers.rgb.exec(color))) {
39068
- return { r: match[1], g: match[2], b: match[3] };
39069
- }
39070
- if ((match = matchers.rgba.exec(color))) {
39071
- return { r: match[1], g: match[2], b: match[3], a: match[4] };
39072
- }
39073
- if ((match = matchers.hsl.exec(color))) {
39074
- return { h: match[1], s: match[2], l: match[3] };
39075
- }
39076
- if ((match = matchers.hsla.exec(color))) {
39077
- return { h: match[1], s: match[2], l: match[3], a: match[4] };
39078
- }
39079
- if ((match = matchers.hsv.exec(color))) {
39080
- return { h: match[1], s: match[2], v: match[3] };
39081
- }
39082
- if ((match = matchers.hsva.exec(color))) {
39083
- return { h: match[1], s: match[2], v: match[3], a: match[4] };
39084
- }
39085
- if ((match = matchers.hex8.exec(color))) {
39086
- return {
39087
- r: parseIntFromHex(match[1]),
39088
- g: parseIntFromHex(match[2]),
39089
- b: parseIntFromHex(match[3]),
39090
- a: convertHexToDecimal(match[4]),
39091
- format: named ? "name" : "hex8"
39092
- };
39093
- }
39094
- if ((match = matchers.hex6.exec(color))) {
39095
- return {
39096
- r: parseIntFromHex(match[1]),
39097
- g: parseIntFromHex(match[2]),
39098
- b: parseIntFromHex(match[3]),
39099
- format: named ? "name" : "hex"
39100
- };
39101
- }
39102
- if ((match = matchers.hex4.exec(color))) {
39103
- return {
39104
- r: parseIntFromHex(match[1] + '' + match[1]),
39105
- g: parseIntFromHex(match[2] + '' + match[2]),
39106
- b: parseIntFromHex(match[3] + '' + match[3]),
39107
- a: convertHexToDecimal(match[4] + '' + match[4]),
39108
- format: named ? "name" : "hex8"
39109
- };
39110
- }
39111
- if ((match = matchers.hex3.exec(color))) {
39112
- return {
39113
- r: parseIntFromHex(match[1] + '' + match[1]),
39114
- g: parseIntFromHex(match[2] + '' + match[2]),
39115
- b: parseIntFromHex(match[3] + '' + match[3]),
39116
- format: named ? "name" : "hex"
39117
- };
39118
- }
39076
+ // Replace a decimal with it's percentage value
39077
+ function convertToPercentage(n) {
39078
+ if (n <= 1) {
39079
+ n = n * 100 + "%";
39080
+ }
39119
39081
 
39120
- return false;
39121
- }
39082
+ return n;
39083
+ }
39084
+
39085
+ // Converts a decimal to a hex value
39086
+ function convertDecimalToHex(d) {
39087
+ return Math.round(parseFloat(d) * 255).toString(16);
39088
+ }
39089
+ // Converts a hex value to a decimal
39090
+ function convertHexToDecimal(h) {
39091
+ return parseIntFromHex(h) / 255;
39092
+ }
39093
+
39094
+ var matchers = (function () {
39095
+ // <http://www.w3.org/TR/css3-values/#integers>
39096
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
39097
+
39098
+ // <http://www.w3.org/TR/css3-values/#number-value>
39099
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
39100
+
39101
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
39102
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
39103
+
39104
+ // Actual matching.
39105
+ // Parentheses and commas are optional, but not required.
39106
+ // Whitespace can take the place of commas or opening paren
39107
+ var PERMISSIVE_MATCH3 =
39108
+ "[\\s|\\(]+(" +
39109
+ CSS_UNIT +
39110
+ ")[,|\\s]+(" +
39111
+ CSS_UNIT +
39112
+ ")[,|\\s]+(" +
39113
+ CSS_UNIT +
39114
+ ")\\s*\\)?";
39115
+ var PERMISSIVE_MATCH4 =
39116
+ "[\\s|\\(]+(" +
39117
+ CSS_UNIT +
39118
+ ")[,|\\s]+(" +
39119
+ CSS_UNIT +
39120
+ ")[,|\\s]+(" +
39121
+ CSS_UNIT +
39122
+ ")[,|\\s]+(" +
39123
+ CSS_UNIT +
39124
+ ")\\s*\\)?";
39122
39125
 
39123
- function validateWCAG2Parms(parms) {
39124
- // return valid WCAG2 parms for isReadable.
39125
- // If input parms are invalid, return {"level":"AA", "size":"small"}
39126
- var level, size;
39127
- parms = parms || {"level":"AA", "size":"small"};
39128
- level = (parms.level || "AA").toUpperCase();
39129
- size = (parms.size || "small").toLowerCase();
39130
- if (level !== "AA" && level !== "AAA") {
39131
- level = "AA";
39132
- }
39133
- if (size !== "small" && size !== "large") {
39134
- size = "small";
39135
- }
39136
- return {"level":level, "size":size};
39137
- }
39126
+ return {
39127
+ CSS_UNIT: new RegExp(CSS_UNIT),
39128
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
39129
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
39130
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
39131
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
39132
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
39133
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
39134
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
39135
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
39136
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
39137
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
39138
+ };
39139
+ })();
39140
+
39141
+ // `isValidCSSUnit`
39142
+ // Take in a single string / number and check to see if it looks like a CSS unit
39143
+ // (see `matchers` above for definition).
39144
+ function isValidCSSUnit(color) {
39145
+ return !!matchers.CSS_UNIT.exec(color);
39146
+ }
39147
+
39148
+ // `stringInputToObject`
39149
+ // Permissive string parsing. Take in a number of formats, and output an object
39150
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
39151
+ function stringInputToObject(color) {
39152
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
39153
+ var named = false;
39154
+ if (names[color]) {
39155
+ color = names[color];
39156
+ named = true;
39157
+ } else if (color == "transparent") {
39158
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
39159
+ }
39138
39160
 
39139
- // Node: Export function
39140
- if (module.exports) {
39141
- module.exports = tinycolor;
39142
- }
39143
- // AMD/requirejs: Define the module
39144
- else {
39145
- window.tinycolor = tinycolor;
39146
- }
39161
+ // Try to match string input using regular expressions.
39162
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
39163
+ // Just return an object and let the conversion functions handle that.
39164
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
39165
+ var match;
39166
+ if ((match = matchers.rgb.exec(color))) {
39167
+ return { r: match[1], g: match[2], b: match[3] };
39168
+ }
39169
+ if ((match = matchers.rgba.exec(color))) {
39170
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
39171
+ }
39172
+ if ((match = matchers.hsl.exec(color))) {
39173
+ return { h: match[1], s: match[2], l: match[3] };
39174
+ }
39175
+ if ((match = matchers.hsla.exec(color))) {
39176
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
39177
+ }
39178
+ if ((match = matchers.hsv.exec(color))) {
39179
+ return { h: match[1], s: match[2], v: match[3] };
39180
+ }
39181
+ if ((match = matchers.hsva.exec(color))) {
39182
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
39183
+ }
39184
+ if ((match = matchers.hex8.exec(color))) {
39185
+ return {
39186
+ r: parseIntFromHex(match[1]),
39187
+ g: parseIntFromHex(match[2]),
39188
+ b: parseIntFromHex(match[3]),
39189
+ a: convertHexToDecimal(match[4]),
39190
+ format: named ? "name" : "hex8",
39191
+ };
39192
+ }
39193
+ if ((match = matchers.hex6.exec(color))) {
39194
+ return {
39195
+ r: parseIntFromHex(match[1]),
39196
+ g: parseIntFromHex(match[2]),
39197
+ b: parseIntFromHex(match[3]),
39198
+ format: named ? "name" : "hex",
39199
+ };
39200
+ }
39201
+ if ((match = matchers.hex4.exec(color))) {
39202
+ return {
39203
+ r: parseIntFromHex(match[1] + "" + match[1]),
39204
+ g: parseIntFromHex(match[2] + "" + match[2]),
39205
+ b: parseIntFromHex(match[3] + "" + match[3]),
39206
+ a: convertHexToDecimal(match[4] + "" + match[4]),
39207
+ format: named ? "name" : "hex8",
39208
+ };
39209
+ }
39210
+ if ((match = matchers.hex3.exec(color))) {
39211
+ return {
39212
+ r: parseIntFromHex(match[1] + "" + match[1]),
39213
+ g: parseIntFromHex(match[2] + "" + match[2]),
39214
+ b: parseIntFromHex(match[3] + "" + match[3]),
39215
+ format: named ? "name" : "hex",
39216
+ };
39217
+ }
39147
39218
 
39148
- })(Math);
39149
- } (tinycolor));
39219
+ return false;
39220
+ }
39150
39221
 
39151
- var tinyColor = tinycolorExports;
39222
+ function validateWCAG2Parms(parms) {
39223
+ // return valid WCAG2 parms for isReadable.
39224
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
39225
+ var level, size;
39226
+ parms = parms || { level: "AA", size: "small" };
39227
+ level = (parms.level || "AA").toUpperCase();
39228
+ size = (parms.size || "small").toLowerCase();
39229
+ if (level !== "AA" && level !== "AAA") {
39230
+ level = "AA";
39231
+ }
39232
+ if (size !== "small" && size !== "large") {
39233
+ size = "small";
39234
+ }
39235
+ return { level: level, size: size };
39236
+ }
39152
39237
 
39153
39238
  function _iterableToArrayLimit$1(arr, i) {
39154
39239
  var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
@@ -39436,8 +39521,8 @@ function InsertStackElement(node, body) {
39436
39521
 
39437
39522
  var _excluded = ["objFilter"];
39438
39523
  function threeDigest(data, scene) {
39439
- var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
39440
- var _ref$objFilter = _ref.objFilter,
39524
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
39525
+ _ref$objFilter = _ref.objFilter,
39441
39526
  objFilter = _ref$objFilter === void 0 ? function () {
39442
39527
  return true;
39443
39528
  } : _ref$objFilter,
@@ -39453,10 +39538,10 @@ function InsertStackElement(node, body) {
39453
39538
  }
39454
39539
 
39455
39540
  var colorStr2Hex = function colorStr2Hex(str) {
39456
- return isNaN(str) ? parseInt(tinyColor(str).toHex(), 16) : str;
39541
+ return isNaN(str) ? parseInt(tinycolor(str).toHex(), 16) : str;
39457
39542
  };
39458
39543
  var colorAlpha = function colorAlpha(str) {
39459
- return isNaN(str) ? tinyColor(str).getAlpha() : 1;
39544
+ return isNaN(str) ? tinycolor(str).getAlpha() : 1;
39460
39545
  };
39461
39546
  var autoColorScale = ordinal(schemePaired);
39462
39547
 
@@ -39684,6 +39769,10 @@ function InsertStackElement(node, body) {
39684
39769
  nodeThreeObjectExtend: {
39685
39770
  "default": false
39686
39771
  },
39772
+ nodePositionUpdate: {
39773
+ triggerUpdate: false
39774
+ },
39775
+ // custom function to call for updating the node's position. Signature: (threeObj, { x, y, z}, node). If the function returns a truthy value, the regular node position update will not run.
39687
39776
  linkSource: {
39688
39777
  "default": 'source'
39689
39778
  },
@@ -39879,15 +39968,24 @@ function InsertStackElement(node, body) {
39879
39968
  state.layout[isD3Sim ? 'tick' : 'step'](); // Tick it
39880
39969
  state.onEngineTick();
39881
39970
  }
39971
+ var nodeThreeObjectExtendAccessor = accessorFn(state.nodeThreeObjectExtend);
39882
39972
 
39883
39973
  // Update nodes position
39884
39974
  state.graphData.nodes.forEach(function (node) {
39885
39975
  var obj = node.__threeObj;
39886
39976
  if (!obj) return;
39887
39977
  var pos = isD3Sim ? node : state.layout.getNodePosition(node[state.nodeId]);
39888
- obj.position.x = pos.x;
39889
- obj.position.y = pos.y || 0;
39890
- obj.position.z = pos.z || 0;
39978
+ var extendedObj = nodeThreeObjectExtendAccessor(node);
39979
+ if (!state.nodePositionUpdate || !state.nodePositionUpdate(extendedObj ? obj.children[0] : obj, {
39980
+ x: pos.x,
39981
+ y: pos.y,
39982
+ z: pos.z
39983
+ }, node) // pass child custom object if extending the default
39984
+ || extendedObj) {
39985
+ obj.position.x = pos.x;
39986
+ obj.position.y = pos.y || 0;
39987
+ obj.position.z = pos.z || 0;
39988
+ }
39891
39989
  });
39892
39990
 
39893
39991
  // Update links position
@@ -40437,8 +40535,9 @@ function InsertStackElement(node, body) {
40437
40535
  obj.geometry.dispose();
40438
40536
  obj.geometry = coneGeometry;
40439
40537
  }
40440
- obj.material.color = new three$1$1.Color(arrowColorAccessor(link) || _colorAccessor(link) || '#f0f0f0');
40441
- obj.material.opacity = state.linkOpacity * 3;
40538
+ var arrowColor = arrowColorAccessor(link) || _colorAccessor(link) || '#f0f0f0';
40539
+ obj.material.color = new three$1$1.Color(colorStr2Hex(arrowColor));
40540
+ obj.material.opacity = state.linkOpacity * 3 * colorAlpha(arrowColor);
40442
40541
  }
40443
40542
  });
40444
40543
  }