simview 3.2__py3-none-any.whl

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.
Files changed (163) hide show
  1. simview/__init__.py +69 -0
  2. simview/__main__.py +174 -0
  3. simview/launcher.py +109 -0
  4. simview/live.py +204 -0
  5. simview/merge.py +593 -0
  6. simview/model.py +690 -0
  7. simview/py.typed +0 -0
  8. simview/scene.py +603 -0
  9. simview/server.py +739 -0
  10. simview/state.py +190 -0
  11. simview/static/css/controls.css +36 -0
  12. simview/static/js/SimView.js +601 -0
  13. simview/static/js/components/AnimationController.js +654 -0
  14. simview/static/js/components/BatchManager.js +198 -0
  15. simview/static/js/components/InteractionController.js +446 -0
  16. simview/static/js/components/InteractionControls.js +116 -0
  17. simview/static/js/components/Scene.js +166 -0
  18. simview/static/js/components/StateStore.js +188 -0
  19. simview/static/js/config.js +233 -0
  20. simview/static/js/main.js +3 -0
  21. simview/static/js/objects/Body.js +616 -0
  22. simview/static/js/objects/StaticObject.js +181 -0
  23. simview/static/js/objects/Terrain.js +514 -0
  24. simview/static/js/objects/utils.js +378 -0
  25. simview/static/js/ui/AnalysisPanel.js +233 -0
  26. simview/static/js/ui/BatchLegend.js +207 -0
  27. simview/static/js/ui/BodyStateWindow.js +521 -0
  28. simview/static/js/ui/Controls.js +586 -0
  29. simview/static/js/ui/ErrorMetrics.js +664 -0
  30. simview/static/js/ui/Legend.js +87 -0
  31. simview/static/js/ui/PlaybackControls.js +314 -0
  32. simview/static/js/ui/ScalarPlotter.js +575 -0
  33. simview/static/js/utils/blobCodec.js +73 -0
  34. simview/static/js/utils/bodyTransforms.js +151 -0
  35. simview/static/js/utils/csv.js +46 -0
  36. simview/static/js/utils/errorMath.js +69 -0
  37. simview/static/js/utils/injectStyles.js +16 -0
  38. simview/static/js/utils/interpolate.js +65 -0
  39. simview/static/js/utils/liveFollow.js +17 -0
  40. simview/static/js/utils/loadRecordingLibs.js +34 -0
  41. simview/static/js/utils/viewState.js +226 -0
  42. simview/static/lib/chroma-js-3.1.2/index.min.js +8 -0
  43. simview/static/lib/chroma-js-3.1.2/src/Color.js +49 -0
  44. simview/static/lib/chroma-js-3.1.2/src/chroma.js +10 -0
  45. simview/static/lib/chroma-js-3.1.2/src/colors/colorbrewer.js +81 -0
  46. simview/static/lib/chroma-js-3.1.2/src/colors/w3cx11.js +164 -0
  47. simview/static/lib/chroma-js-3.1.2/src/generator/average.js +88 -0
  48. simview/static/lib/chroma-js-3.1.2/src/generator/bezier.js +86 -0
  49. simview/static/lib/chroma-js-3.1.2/src/generator/blend.js +57 -0
  50. simview/static/lib/chroma-js-3.1.2/src/generator/cubehelix.js +87 -0
  51. simview/static/lib/chroma-js-3.1.2/src/generator/mix.js +19 -0
  52. simview/static/lib/chroma-js-3.1.2/src/generator/random.js +12 -0
  53. simview/static/lib/chroma-js-3.1.2/src/generator/scale.js +394 -0
  54. simview/static/lib/chroma-js-3.1.2/src/interpolator/_hsx.js +59 -0
  55. simview/static/lib/chroma-js-3.1.2/src/interpolator/hcg.js +12 -0
  56. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsi.js +12 -0
  57. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsl.js +12 -0
  58. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsv.js +12 -0
  59. simview/static/lib/chroma-js-3.1.2/src/interpolator/index.js +1 -0
  60. simview/static/lib/chroma-js-3.1.2/src/interpolator/lab.js +19 -0
  61. simview/static/lib/chroma-js-3.1.2/src/interpolator/lch.js +13 -0
  62. simview/static/lib/chroma-js-3.1.2/src/interpolator/lrgb.js +19 -0
  63. simview/static/lib/chroma-js-3.1.2/src/interpolator/num.js +15 -0
  64. simview/static/lib/chroma-js-3.1.2/src/interpolator/oklab.js +19 -0
  65. simview/static/lib/chroma-js-3.1.2/src/interpolator/oklch.js +12 -0
  66. simview/static/lib/chroma-js-3.1.2/src/interpolator/rgb.js +18 -0
  67. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/cmyk2rgb.js +16 -0
  68. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/index.js +27 -0
  69. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/rgb2cmyk.js +17 -0
  70. simview/static/lib/chroma-js-3.1.2/src/io/css/css2rgb.js +238 -0
  71. simview/static/lib/chroma-js-3.1.2/src/io/css/hsl2css.js +26 -0
  72. simview/static/lib/chroma-js-3.1.2/src/io/css/index.js +27 -0
  73. simview/static/lib/chroma-js-3.1.2/src/io/css/lab2css.js +24 -0
  74. simview/static/lib/chroma-js-3.1.2/src/io/css/lch2css.js +24 -0
  75. simview/static/lib/chroma-js-3.1.2/src/io/css/oklab2css.js +16 -0
  76. simview/static/lib/chroma-js-3.1.2/src/io/css/oklch2css.js +16 -0
  77. simview/static/lib/chroma-js-3.1.2/src/io/css/rgb2css.js +61 -0
  78. simview/static/lib/chroma-js-3.1.2/src/io/gl/index.js +22 -0
  79. simview/static/lib/chroma-js-3.1.2/src/io/hcg/hcg2rgb.js +55 -0
  80. simview/static/lib/chroma-js-3.1.2/src/io/hcg/index.js +27 -0
  81. simview/static/lib/chroma-js-3.1.2/src/io/hcg/rgb2hcg.js +23 -0
  82. simview/static/lib/chroma-js-3.1.2/src/io/hex/hex2rgb.js +56 -0
  83. simview/static/lib/chroma-js-3.1.2/src/io/hex/index.js +29 -0
  84. simview/static/lib/chroma-js-3.1.2/src/io/hex/rgb2hex.js +29 -0
  85. simview/static/lib/chroma-js-3.1.2/src/io/hsi/hsi2rgb.js +45 -0
  86. simview/static/lib/chroma-js-3.1.2/src/io/hsi/index.js +27 -0
  87. simview/static/lib/chroma-js-3.1.2/src/io/hsi/rgb2hsi.js +31 -0
  88. simview/static/lib/chroma-js-3.1.2/src/io/hsl/hsl2rgb.js +35 -0
  89. simview/static/lib/chroma-js-3.1.2/src/io/hsl/index.js +27 -0
  90. simview/static/lib/chroma-js-3.1.2/src/io/hsl/rgb2hsl.js +45 -0
  91. simview/static/lib/chroma-js-3.1.2/src/io/hsv/hsv2rgb.js +47 -0
  92. simview/static/lib/chroma-js-3.1.2/src/io/hsv/index.js +27 -0
  93. simview/static/lib/chroma-js-3.1.2/src/io/hsv/rgb2hsv.js +32 -0
  94. simview/static/lib/chroma-js-3.1.2/src/io/input.js +4 -0
  95. simview/static/lib/chroma-js-3.1.2/src/io/lab/index.js +28 -0
  96. simview/static/lib/chroma-js-3.1.2/src/io/lab/lab-constants.js +120 -0
  97. simview/static/lib/chroma-js-3.1.2/src/io/lab/lab2rgb.js +101 -0
  98. simview/static/lib/chroma-js-3.1.2/src/io/lab/rgb2lab.js +67 -0
  99. simview/static/lib/chroma-js-3.1.2/src/io/lch/hcl2rgb.js +9 -0
  100. simview/static/lib/chroma-js-3.1.2/src/io/lch/index.js +35 -0
  101. simview/static/lib/chroma-js-3.1.2/src/io/lch/lab2lch.js +12 -0
  102. simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2lab.js +18 -0
  103. simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2rgb.js +13 -0
  104. simview/static/lib/chroma-js-3.1.2/src/io/lch/rgb2lch.js +12 -0
  105. simview/static/lib/chroma-js-3.1.2/src/io/named/index.js +30 -0
  106. simview/static/lib/chroma-js-3.1.2/src/io/num/index.js +32 -0
  107. simview/static/lib/chroma-js-3.1.2/src/io/num/num2rgb.js +13 -0
  108. simview/static/lib/chroma-js-3.1.2/src/io/num/rgb2num.js +8 -0
  109. simview/static/lib/chroma-js-3.1.2/src/io/oklab/index.js +27 -0
  110. simview/static/lib/chroma-js-3.1.2/src/io/oklab/oklab2rgb.js +34 -0
  111. simview/static/lib/chroma-js-3.1.2/src/io/oklab/rgb2oklab.js +37 -0
  112. simview/static/lib/chroma-js-3.1.2/src/io/oklch/index.js +27 -0
  113. simview/static/lib/chroma-js-3.1.2/src/io/oklch/oklch2rgb.js +13 -0
  114. simview/static/lib/chroma-js-3.1.2/src/io/oklch/rgb2oklch.js +12 -0
  115. simview/static/lib/chroma-js-3.1.2/src/io/rgb/index.js +44 -0
  116. simview/static/lib/chroma-js-3.1.2/src/io/temp/index.js +22 -0
  117. simview/static/lib/chroma-js-3.1.2/src/io/temp/rgb2temperature.js +30 -0
  118. simview/static/lib/chroma-js-3.1.2/src/io/temp/temperature2rgb.js +39 -0
  119. simview/static/lib/chroma-js-3.1.2/src/ops/alpha.js +13 -0
  120. simview/static/lib/chroma-js-3.1.2/src/ops/clipped.js +5 -0
  121. simview/static/lib/chroma-js-3.1.2/src/ops/darken.js +17 -0
  122. simview/static/lib/chroma-js-3.1.2/src/ops/get.js +13 -0
  123. simview/static/lib/chroma-js-3.1.2/src/ops/luminance.js +54 -0
  124. simview/static/lib/chroma-js-3.1.2/src/ops/mix.js +10 -0
  125. simview/static/lib/chroma-js-3.1.2/src/ops/premultiply.js +12 -0
  126. simview/static/lib/chroma-js-3.1.2/src/ops/saturate.js +15 -0
  127. simview/static/lib/chroma-js-3.1.2/src/ops/set.js +43 -0
  128. simview/static/lib/chroma-js-3.1.2/src/ops/shade.js +11 -0
  129. simview/static/lib/chroma-js-3.1.2/src/utils/analyze.js +191 -0
  130. simview/static/lib/chroma-js-3.1.2/src/utils/clip_rgb.js +15 -0
  131. simview/static/lib/chroma-js-3.1.2/src/utils/contrast.js +12 -0
  132. simview/static/lib/chroma-js-3.1.2/src/utils/contrastAPCA.js +68 -0
  133. simview/static/lib/chroma-js-3.1.2/src/utils/delta-e.js +62 -0
  134. simview/static/lib/chroma-js-3.1.2/src/utils/distance.js +17 -0
  135. simview/static/lib/chroma-js-3.1.2/src/utils/index.js +27 -0
  136. simview/static/lib/chroma-js-3.1.2/src/utils/last.js +8 -0
  137. simview/static/lib/chroma-js-3.1.2/src/utils/limit.js +5 -0
  138. simview/static/lib/chroma-js-3.1.2/src/utils/multiply-matrices.js +36 -0
  139. simview/static/lib/chroma-js-3.1.2/src/utils/scales.js +15 -0
  140. simview/static/lib/chroma-js-3.1.2/src/utils/type.js +18 -0
  141. simview/static/lib/chroma-js-3.1.2/src/utils/unpack.js +17 -0
  142. simview/static/lib/chroma-js-3.1.2/src/utils/valid.js +11 -0
  143. simview/static/lib/chroma-js-3.1.2/src/version.js +2 -0
  144. simview/static/lib/download.js +132 -0
  145. simview/static/lib/js-colormaps.js +19335 -0
  146. simview/static/lib/tar.js +334 -0
  147. simview/static/lib/three-0.174.0/addons/controls/OrbitControls.js +1556 -0
  148. simview/static/lib/three-0.174.0/addons/libs/lil-gui.module.min.js +8 -0
  149. simview/static/lib/three-0.174.0/three.core.js +48830 -0
  150. simview/static/lib/three-0.174.0/three.module.js +17313 -0
  151. simview/static/lib/uPlot.esm.js +6140 -0
  152. simview/static/lib/uPlot.min.css +2 -0
  153. simview/static/textures/contacts/red-cross0.png +0 -0
  154. simview/static/textures/points/ball0.png +0 -0
  155. simview/static/textures/points/ball1.png +0 -0
  156. simview/templates/index.html +81 -0
  157. simview/utils.py +41 -0
  158. simview-3.2.dist-info/METADATA +552 -0
  159. simview-3.2.dist-info/RECORD +163 -0
  160. simview-3.2.dist-info/WHEEL +5 -0
  161. simview-3.2.dist-info/entry_points.txt +2 -0
  162. simview-3.2.dist-info/licenses/LICENSE +28 -0
  163. simview-3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,394 @@
1
+ // minimal multi-purpose interface
2
+
3
+ // @requires utils color analyze
4
+ import chroma from '../chroma.js';
5
+ import { limit, type } from '../utils/index.js';
6
+
7
+ const { pow } = Math;
8
+
9
+ export default function (colors) {
10
+ // constructor
11
+ let _mode = 'rgb';
12
+ let _nacol = chroma('#ccc');
13
+ let _spread = 0;
14
+ // const _fixed = false;
15
+ let _domain = [0, 1];
16
+ let _pos = [];
17
+ let _padding = [0, 0];
18
+ let _classes = false;
19
+ let _colors = [];
20
+ let _out = false;
21
+ let _min = 0;
22
+ let _max = 1;
23
+ let _correctLightness = false;
24
+ let _colorCache = {};
25
+ let _useCache = true;
26
+ let _gamma = 1;
27
+
28
+ // private methods
29
+
30
+ const setColors = function (colors) {
31
+ colors = colors || ['#fff', '#000'];
32
+ if (
33
+ colors &&
34
+ type(colors) === 'string' &&
35
+ chroma.brewer &&
36
+ chroma.brewer[colors.toLowerCase()]
37
+ ) {
38
+ colors = chroma.brewer[colors.toLowerCase()];
39
+ }
40
+ if (type(colors) === 'array') {
41
+ // handle single color
42
+ if (colors.length === 1) {
43
+ colors = [colors[0], colors[0]];
44
+ }
45
+ // make a copy of the colors
46
+ colors = colors.slice(0);
47
+ // convert to chroma classes
48
+ for (let c = 0; c < colors.length; c++) {
49
+ colors[c] = chroma(colors[c]);
50
+ }
51
+ // auto-fill color position
52
+ _pos.length = 0;
53
+ for (let c = 0; c < colors.length; c++) {
54
+ _pos.push(c / (colors.length - 1));
55
+ }
56
+ }
57
+ resetCache();
58
+ return (_colors = colors);
59
+ };
60
+
61
+ const getClass = function (value) {
62
+ if (_classes != null) {
63
+ const n = _classes.length - 1;
64
+ let i = 0;
65
+ while (i < n && value >= _classes[i]) {
66
+ i++;
67
+ }
68
+ return i - 1;
69
+ }
70
+ return 0;
71
+ };
72
+
73
+ let tMapLightness = (t) => t;
74
+ let tMapDomain = (t) => t;
75
+
76
+ // const classifyValue = function(value) {
77
+ // let val = value;
78
+ // if (_classes.length > 2) {
79
+ // const n = _classes.length-1;
80
+ // const i = getClass(value);
81
+ // const minc = _classes[0] + ((_classes[1]-_classes[0]) * (0 + (_spread * 0.5))); // center of 1st class
82
+ // const maxc = _classes[n-1] + ((_classes[n]-_classes[n-1]) * (1 - (_spread * 0.5))); // center of last class
83
+ // val = _min + ((((_classes[i] + ((_classes[i+1] - _classes[i]) * 0.5)) - minc) / (maxc-minc)) * (_max - _min));
84
+ // }
85
+ // return val;
86
+ // };
87
+
88
+ const getColor = function (val, bypassMap) {
89
+ let col, t;
90
+ if (bypassMap == null) {
91
+ bypassMap = false;
92
+ }
93
+ if (isNaN(val) || val === null) {
94
+ return _nacol;
95
+ }
96
+ if (!bypassMap) {
97
+ if (_classes && _classes.length > 2) {
98
+ // find the class
99
+ const c = getClass(val);
100
+ t = c / (_classes.length - 2);
101
+ } else if (_max !== _min) {
102
+ // just interpolate between min/max
103
+ t = (val - _min) / (_max - _min);
104
+ } else {
105
+ t = 1;
106
+ }
107
+ } else {
108
+ t = val;
109
+ }
110
+
111
+ // domain map
112
+ t = tMapDomain(t);
113
+
114
+ if (!bypassMap) {
115
+ t = tMapLightness(t); // lightness correction
116
+ }
117
+
118
+ if (_gamma !== 1) {
119
+ t = pow(t, _gamma);
120
+ }
121
+
122
+ t = _padding[0] + t * (1 - _padding[0] - _padding[1]);
123
+
124
+ t = limit(t, 0, 1);
125
+
126
+ const k = Math.floor(t * 10000);
127
+
128
+ if (_useCache && _colorCache[k]) {
129
+ col = _colorCache[k];
130
+ } else {
131
+ if (type(_colors) === 'array') {
132
+ //for i in [0.._pos.length-1]
133
+ for (let i = 0; i < _pos.length; i++) {
134
+ const p = _pos[i];
135
+ if (t <= p) {
136
+ col = _colors[i];
137
+ break;
138
+ }
139
+ if (t >= p && i === _pos.length - 1) {
140
+ col = _colors[i];
141
+ break;
142
+ }
143
+ if (t > p && t < _pos[i + 1]) {
144
+ t = (t - p) / (_pos[i + 1] - p);
145
+ col = chroma.interpolate(
146
+ _colors[i],
147
+ _colors[i + 1],
148
+ t,
149
+ _mode
150
+ );
151
+ break;
152
+ }
153
+ }
154
+ } else if (type(_colors) === 'function') {
155
+ col = _colors(t);
156
+ }
157
+ if (_useCache) {
158
+ _colorCache[k] = col;
159
+ }
160
+ }
161
+ return col;
162
+ };
163
+
164
+ var resetCache = () => (_colorCache = {});
165
+
166
+ setColors(colors);
167
+
168
+ // public interface
169
+
170
+ const f = function (v) {
171
+ const c = chroma(getColor(v));
172
+ if (_out && c[_out]) {
173
+ return c[_out]();
174
+ } else {
175
+ return c;
176
+ }
177
+ };
178
+
179
+ f.classes = function (classes) {
180
+ if (classes != null) {
181
+ if (type(classes) === 'array') {
182
+ _classes = classes;
183
+ _domain = [classes[0], classes[classes.length - 1]];
184
+ } else {
185
+ const d = chroma.analyze(_domain);
186
+ if (classes === 0) {
187
+ _classes = [d.min, d.max];
188
+ } else {
189
+ _classes = chroma.limits(d, 'e', classes);
190
+ }
191
+ }
192
+ return f;
193
+ }
194
+ return _classes;
195
+ };
196
+
197
+ f.domain = function (domain) {
198
+ if (!arguments.length) {
199
+ return _domain;
200
+ }
201
+ _min = domain[0];
202
+ _max = domain[domain.length - 1];
203
+ _pos = [];
204
+ const k = _colors.length;
205
+ if (domain.length === k && _min !== _max) {
206
+ // update positions
207
+ for (let d of Array.from(domain)) {
208
+ _pos.push((d - _min) / (_max - _min));
209
+ }
210
+ } else {
211
+ for (let c = 0; c < k; c++) {
212
+ _pos.push(c / (k - 1));
213
+ }
214
+ if (domain.length > 2) {
215
+ // set domain map
216
+ const tOut = domain.map((d, i) => i / (domain.length - 1));
217
+ const tBreaks = domain.map((d) => (d - _min) / (_max - _min));
218
+ if (!tBreaks.every((val, i) => tOut[i] === val)) {
219
+ tMapDomain = (t) => {
220
+ if (t <= 0 || t >= 1) return t;
221
+ let i = 0;
222
+ while (t >= tBreaks[i + 1]) i++;
223
+ const f =
224
+ (t - tBreaks[i]) / (tBreaks[i + 1] - tBreaks[i]);
225
+ const out = tOut[i] + f * (tOut[i + 1] - tOut[i]);
226
+ return out;
227
+ };
228
+ }
229
+ }
230
+ }
231
+ _domain = [_min, _max];
232
+ return f;
233
+ };
234
+
235
+ f.mode = function (_m) {
236
+ if (!arguments.length) {
237
+ return _mode;
238
+ }
239
+ _mode = _m;
240
+ resetCache();
241
+ return f;
242
+ };
243
+
244
+ f.range = function (colors, _pos) {
245
+ setColors(colors, _pos);
246
+ return f;
247
+ };
248
+
249
+ f.out = function (_o) {
250
+ _out = _o;
251
+ return f;
252
+ };
253
+
254
+ f.spread = function (val) {
255
+ if (!arguments.length) {
256
+ return _spread;
257
+ }
258
+ _spread = val;
259
+ return f;
260
+ };
261
+
262
+ f.correctLightness = function (v) {
263
+ if (v == null) {
264
+ v = true;
265
+ }
266
+ _correctLightness = v;
267
+ resetCache();
268
+ if (_correctLightness) {
269
+ tMapLightness = function (t) {
270
+ const L0 = getColor(0, true).lab()[0];
271
+ const L1 = getColor(1, true).lab()[0];
272
+ const pol = L0 > L1;
273
+ let L_actual = getColor(t, true).lab()[0];
274
+ const L_ideal = L0 + (L1 - L0) * t;
275
+ let L_diff = L_actual - L_ideal;
276
+ let t0 = 0;
277
+ let t1 = 1;
278
+ let max_iter = 20;
279
+ while (Math.abs(L_diff) > 1e-2 && max_iter-- > 0) {
280
+ (function () {
281
+ if (pol) {
282
+ L_diff *= -1;
283
+ }
284
+ if (L_diff < 0) {
285
+ t0 = t;
286
+ t += (t1 - t) * 0.5;
287
+ } else {
288
+ t1 = t;
289
+ t += (t0 - t) * 0.5;
290
+ }
291
+ L_actual = getColor(t, true).lab()[0];
292
+ return (L_diff = L_actual - L_ideal);
293
+ })();
294
+ }
295
+ return t;
296
+ };
297
+ } else {
298
+ tMapLightness = (t) => t;
299
+ }
300
+ return f;
301
+ };
302
+
303
+ f.padding = function (p) {
304
+ if (p != null) {
305
+ if (type(p) === 'number') {
306
+ p = [p, p];
307
+ }
308
+ _padding = p;
309
+ return f;
310
+ } else {
311
+ return _padding;
312
+ }
313
+ };
314
+
315
+ f.colors = function (numColors, out) {
316
+ // If no arguments are given, return the original colors that were provided
317
+ if (arguments.length < 2) {
318
+ out = 'hex';
319
+ }
320
+ let result = [];
321
+
322
+ if (arguments.length === 0) {
323
+ result = _colors.slice(0);
324
+ } else if (numColors === 1) {
325
+ result = [f(0.5)];
326
+ } else if (numColors > 1) {
327
+ const dm = _domain[0];
328
+ const dd = _domain[1] - dm;
329
+ result = __range__(0, numColors, false).map((i) =>
330
+ f(dm + (i / (numColors - 1)) * dd)
331
+ );
332
+ } else {
333
+ // returns all colors based on the defined classes
334
+ colors = [];
335
+ let samples = [];
336
+ if (_classes && _classes.length > 2) {
337
+ for (
338
+ let i = 1, end = _classes.length, asc = 1 <= end;
339
+ asc ? i < end : i > end;
340
+ asc ? i++ : i--
341
+ ) {
342
+ samples.push((_classes[i - 1] + _classes[i]) * 0.5);
343
+ }
344
+ } else {
345
+ samples = _domain;
346
+ }
347
+ result = samples.map((v) => f(v));
348
+ }
349
+
350
+ if (chroma[out]) {
351
+ result = result.map((c) => c[out]());
352
+ }
353
+ return result;
354
+ };
355
+
356
+ f.cache = function (c) {
357
+ if (c != null) {
358
+ _useCache = c;
359
+ return f;
360
+ } else {
361
+ return _useCache;
362
+ }
363
+ };
364
+
365
+ f.gamma = function (g) {
366
+ if (g != null) {
367
+ _gamma = g;
368
+ return f;
369
+ } else {
370
+ return _gamma;
371
+ }
372
+ };
373
+
374
+ f.nodata = function (d) {
375
+ if (d != null) {
376
+ _nacol = chroma(d);
377
+ return f;
378
+ } else {
379
+ return _nacol;
380
+ }
381
+ };
382
+
383
+ return f;
384
+ }
385
+
386
+ function __range__(left, right, inclusive) {
387
+ let range = [];
388
+ let ascending = left < right;
389
+ let end = !inclusive ? right : ascending ? right + 1 : right - 1;
390
+ for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
391
+ range.push(i);
392
+ }
393
+ return range;
394
+ }
@@ -0,0 +1,59 @@
1
+ import Color from '../Color.js';
2
+
3
+ export default (col1, col2, f, m) => {
4
+ let xyz0, xyz1;
5
+ if (m === 'hsl') {
6
+ xyz0 = col1.hsl();
7
+ xyz1 = col2.hsl();
8
+ } else if (m === 'hsv') {
9
+ xyz0 = col1.hsv();
10
+ xyz1 = col2.hsv();
11
+ } else if (m === 'hcg') {
12
+ xyz0 = col1.hcg();
13
+ xyz1 = col2.hcg();
14
+ } else if (m === 'hsi') {
15
+ xyz0 = col1.hsi();
16
+ xyz1 = col2.hsi();
17
+ } else if (m === 'lch' || m === 'hcl') {
18
+ m = 'hcl';
19
+ xyz0 = col1.hcl();
20
+ xyz1 = col2.hcl();
21
+ } else if (m === 'oklch') {
22
+ xyz0 = col1.oklch().reverse();
23
+ xyz1 = col2.oklch().reverse();
24
+ }
25
+
26
+ let hue0, hue1, sat0, sat1, lbv0, lbv1;
27
+ if (m.substr(0, 1) === 'h' || m === 'oklch') {
28
+ [hue0, sat0, lbv0] = xyz0;
29
+ [hue1, sat1, lbv1] = xyz1;
30
+ }
31
+
32
+ let sat, hue, lbv, dh;
33
+
34
+ if (!isNaN(hue0) && !isNaN(hue1)) {
35
+ // both colors have hue
36
+ if (hue1 > hue0 && hue1 - hue0 > 180) {
37
+ dh = hue1 - (hue0 + 360);
38
+ } else if (hue1 < hue0 && hue0 - hue1 > 180) {
39
+ dh = hue1 + 360 - hue0;
40
+ } else {
41
+ dh = hue1 - hue0;
42
+ }
43
+ hue = hue0 + f * dh;
44
+ } else if (!isNaN(hue0)) {
45
+ hue = hue0;
46
+ if ((lbv1 == 1 || lbv1 == 0) && m != 'hsv') sat = sat0;
47
+ } else if (!isNaN(hue1)) {
48
+ hue = hue1;
49
+ if ((lbv0 == 1 || lbv0 == 0) && m != 'hsv') sat = sat1;
50
+ } else {
51
+ hue = Number.NaN;
52
+ }
53
+
54
+ if (sat === undefined) sat = sat0 + f * (sat1 - sat0);
55
+ lbv = lbv0 + f * (lbv1 - lbv0);
56
+ return m === 'oklch'
57
+ ? new Color([lbv, sat, hue], m)
58
+ : new Color([hue, sat, lbv], m);
59
+ };
@@ -0,0 +1,12 @@
1
+ import '../io/hcg/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const hcg = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'hcg');
7
+ };
8
+
9
+ // register interpolator
10
+ index.hcg = hcg;
11
+
12
+ export default hcg;
@@ -0,0 +1,12 @@
1
+ import '../io/hsi/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const hsi = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'hsi');
7
+ };
8
+
9
+ // register interpolator
10
+ index.hsi = hsi;
11
+
12
+ export default hsi;
@@ -0,0 +1,12 @@
1
+ import '../io/hsl/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const hsl = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'hsl');
7
+ };
8
+
9
+ // register interpolator
10
+ index.hsl = hsl;
11
+
12
+ export default hsl;
@@ -0,0 +1,12 @@
1
+ import '../io/hsv/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const hsv = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'hsv');
7
+ };
8
+
9
+ // register interpolator
10
+ index.hsv = hsv;
11
+
12
+ export default hsv;
@@ -0,0 +1 @@
1
+ export default {};
@@ -0,0 +1,19 @@
1
+ import '../io/lab/index.js';
2
+ import index from './index.js';
3
+ import Color from '../Color.js';
4
+
5
+ const lab = (col1, col2, f) => {
6
+ const xyz0 = col1.lab();
7
+ const xyz1 = col2.lab();
8
+ return new Color(
9
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
10
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
11
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
12
+ 'lab'
13
+ );
14
+ };
15
+
16
+ // register interpolator
17
+ index.lab = lab;
18
+
19
+ export default lab;
@@ -0,0 +1,13 @@
1
+ import '../io/lch/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const lch = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'lch');
7
+ };
8
+
9
+ // register interpolator
10
+ index.lch = lch;
11
+ index.hcl = lch;
12
+
13
+ export default lch;
@@ -0,0 +1,19 @@
1
+ import Color from '../Color.js';
2
+ const { sqrt, pow } = Math;
3
+ import index from './index.js';
4
+
5
+ const lrgb = (col1, col2, f) => {
6
+ const [x1, y1, z1] = col1._rgb;
7
+ const [x2, y2, z2] = col2._rgb;
8
+ return new Color(
9
+ sqrt(pow(x1, 2) * (1 - f) + pow(x2, 2) * f),
10
+ sqrt(pow(y1, 2) * (1 - f) + pow(y2, 2) * f),
11
+ sqrt(pow(z1, 2) * (1 - f) + pow(z2, 2) * f),
12
+ 'rgb'
13
+ );
14
+ };
15
+
16
+ // register interpolator
17
+ index.lrgb = lrgb;
18
+
19
+ export default lrgb;
@@ -0,0 +1,15 @@
1
+ import '../io/num/index.js';
2
+ import index from './index.js';
3
+
4
+ import Color from '../Color.js';
5
+
6
+ const num = (col1, col2, f) => {
7
+ const c1 = col1.num();
8
+ const c2 = col2.num();
9
+ return new Color(c1 + f * (c2 - c1), 'num');
10
+ };
11
+
12
+ // register interpolator
13
+ index.num = num;
14
+
15
+ export default num;
@@ -0,0 +1,19 @@
1
+ import '../io/oklab/index.js';
2
+ import index from './index.js';
3
+ import Color from '../Color.js';
4
+
5
+ const oklab = (col1, col2, f) => {
6
+ const xyz0 = col1.oklab();
7
+ const xyz1 = col2.oklab();
8
+ return new Color(
9
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
10
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
11
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
12
+ 'oklab'
13
+ );
14
+ };
15
+
16
+ // register interpolator
17
+ index.oklab = oklab;
18
+
19
+ export default oklab;
@@ -0,0 +1,12 @@
1
+ import '../io/lch/index.js';
2
+ import interpolate_hsx from './_hsx.js';
3
+ import index from './index.js';
4
+
5
+ const oklch = (col1, col2, f) => {
6
+ return interpolate_hsx(col1, col2, f, 'oklch');
7
+ };
8
+
9
+ // register interpolator
10
+ index.oklch = oklch;
11
+
12
+ export default oklch;
@@ -0,0 +1,18 @@
1
+ import Color from '../Color.js';
2
+ import index from './index.js';
3
+
4
+ const rgb = (col1, col2, f) => {
5
+ const xyz0 = col1._rgb;
6
+ const xyz1 = col2._rgb;
7
+ return new Color(
8
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
9
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
10
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
11
+ 'rgb'
12
+ );
13
+ };
14
+
15
+ // register interpolator
16
+ index.rgb = rgb;
17
+
18
+ export default rgb;
@@ -0,0 +1,16 @@
1
+ import { unpack } from '../../utils/index.js';
2
+
3
+ const cmyk2rgb = (...args) => {
4
+ args = unpack(args, 'cmyk');
5
+ const [c, m, y, k] = args;
6
+ const alpha = args.length > 4 ? args[4] : 1;
7
+ if (k === 1) return [0, 0, 0, alpha];
8
+ return [
9
+ c >= 1 ? 0 : 255 * (1 - c) * (1 - k), // r
10
+ m >= 1 ? 0 : 255 * (1 - m) * (1 - k), // g
11
+ y >= 1 ? 0 : 255 * (1 - y) * (1 - k), // b
12
+ alpha
13
+ ];
14
+ };
15
+
16
+ export default cmyk2rgb;
@@ -0,0 +1,27 @@
1
+ import chroma from '../../chroma.js';
2
+ import Color from '../../Color.js';
3
+ import input from '../input.js';
4
+ import { unpack, type } from '../../utils/index.js';
5
+ import cmyk2rgb from './cmyk2rgb.js';
6
+ import rgb2cmyk from './rgb2cmyk.js';
7
+
8
+ Color.prototype.cmyk = function () {
9
+ return rgb2cmyk(this._rgb);
10
+ };
11
+
12
+ const cmyk = (...args) => new Color(...args, 'cmyk');
13
+ Object.assign(chroma, { cmyk });
14
+
15
+ input.format.cmyk = cmyk2rgb;
16
+
17
+ input.autodetect.push({
18
+ p: 2,
19
+ test: (...args) => {
20
+ args = unpack(args, 'cmyk');
21
+ if (type(args) === 'array' && args.length === 4) {
22
+ return 'cmyk';
23
+ }
24
+ }
25
+ });
26
+
27
+ export { cmyk };
@@ -0,0 +1,17 @@
1
+ import { unpack } from '../../utils/index.js';
2
+ const { max } = Math;
3
+
4
+ const rgb2cmyk = (...args) => {
5
+ let [r, g, b] = unpack(args, 'rgb');
6
+ r = r / 255;
7
+ g = g / 255;
8
+ b = b / 255;
9
+ const k = 1 - max(r, max(g, b));
10
+ const f = k < 1 ? 1 / (1 - k) : 0;
11
+ const c = (1 - r - k) * f;
12
+ const m = (1 - g - k) * f;
13
+ const y = (1 - b - k) * f;
14
+ return [c, m, y, k];
15
+ };
16
+
17
+ export default rgb2cmyk;