bitwrench 2.0.32 → 2.1.1

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 (126) hide show
  1. package/README.md +211 -125
  2. package/dist/bitwrench-bccl.cjs.js +349 -188
  3. package/dist/bitwrench-bccl.cjs.min.js +2 -39
  4. package/dist/bitwrench-bccl.cjs.min.js.gz +0 -0
  5. package/dist/bitwrench-bccl.esm.js +349 -188
  6. package/dist/bitwrench-bccl.esm.min.js +2 -39
  7. package/dist/bitwrench-bccl.esm.min.js.gz +0 -0
  8. package/dist/bitwrench-bccl.umd.js +349 -188
  9. package/dist/bitwrench-bccl.umd.min.js +2 -39
  10. package/dist/bitwrench-bccl.umd.min.js.gz +0 -0
  11. package/dist/bitwrench-code-edit.cjs.js +17 -6
  12. package/dist/bitwrench-code-edit.cjs.min.js +2 -20
  13. package/dist/bitwrench-code-edit.es5.js +8 -3
  14. package/dist/bitwrench-code-edit.es5.min.js +2 -19
  15. package/dist/bitwrench-code-edit.esm.js +17 -6
  16. package/dist/bitwrench-code-edit.esm.min.js +2 -19
  17. package/dist/bitwrench-code-edit.umd.js +17 -6
  18. package/dist/bitwrench-code-edit.umd.min.js +2 -19
  19. package/dist/bitwrench-code-edit.umd.min.js.gz +0 -0
  20. package/dist/bitwrench-debug.js +1 -1
  21. package/dist/bitwrench-debug.min.js +1 -1
  22. package/dist/bitwrench-lean.cjs.js +2492 -1628
  23. package/dist/bitwrench-lean.cjs.min.js +2 -80
  24. package/dist/bitwrench-lean.cjs.min.js.gz +0 -0
  25. package/dist/bitwrench-lean.es5.js +2740 -1838
  26. package/dist/bitwrench-lean.es5.min.js +2 -49
  27. package/dist/bitwrench-lean.es5.min.js.gz +0 -0
  28. package/dist/bitwrench-lean.esm.js +2492 -1628
  29. package/dist/bitwrench-lean.esm.min.js +2 -80
  30. package/dist/bitwrench-lean.esm.min.js.gz +0 -0
  31. package/dist/bitwrench-lean.umd.js +2492 -1628
  32. package/dist/bitwrench-lean.umd.min.js +2 -80
  33. package/dist/bitwrench-lean.umd.min.js.gz +0 -0
  34. package/dist/bitwrench-util-color.cjs.js +251 -0
  35. package/dist/bitwrench-util-color.cjs.min.js +3 -0
  36. package/dist/bitwrench-util-color.es5.js +256 -0
  37. package/dist/bitwrench-util-color.es5.min.js +3 -0
  38. package/dist/bitwrench-util-color.esm.js +241 -0
  39. package/dist/bitwrench-util-color.esm.min.js +3 -0
  40. package/dist/bitwrench-util-color.umd.js +257 -0
  41. package/dist/bitwrench-util-color.umd.min.js +3 -0
  42. package/dist/bitwrench-util-css.cjs.js +2 -1
  43. package/dist/bitwrench-util-css.cjs.min.js +2 -21
  44. package/dist/bitwrench-util-css.es5.js +2 -1
  45. package/dist/bitwrench-util-css.es5.min.js +2 -20
  46. package/dist/bitwrench-util-css.esm.js +2 -1
  47. package/dist/bitwrench-util-css.esm.min.js +1 -19
  48. package/dist/bitwrench-util-css.umd.js +2 -1
  49. package/dist/bitwrench-util-css.umd.min.js +2 -20
  50. package/dist/bitwrench-util-css.umd.min.js.gz +0 -0
  51. package/dist/bitwrench.cjs.js +2826 -1801
  52. package/dist/bitwrench.cjs.min.js +2 -99
  53. package/dist/bitwrench.cjs.min.js.gz +0 -0
  54. package/dist/bitwrench.css +403 -479
  55. package/dist/bitwrench.d.ts +70 -73
  56. package/dist/bitwrench.es5.js +3106 -2020
  57. package/dist/bitwrench.es5.min.js +2 -67
  58. package/dist/bitwrench.es5.min.js.gz +0 -0
  59. package/dist/bitwrench.esm.js +2826 -1801
  60. package/dist/bitwrench.esm.min.js +2 -99
  61. package/dist/bitwrench.esm.min.js.gz +0 -0
  62. package/dist/bitwrench.min.css +1 -1
  63. package/dist/bitwrench.umd.js +2826 -1801
  64. package/dist/bitwrench.umd.min.js +2 -99
  65. package/dist/bitwrench.umd.min.js.gz +0 -0
  66. package/dist/builds.json +222 -134
  67. package/dist/bwserve.cjs.js +289 -282
  68. package/dist/bwserve.d.ts +157 -0
  69. package/dist/bwserve.esm.js +290 -283
  70. package/dist/sri.json +54 -46
  71. package/docs/README.md +6 -3
  72. package/docs/app-patterns.md +7 -6
  73. package/docs/bitwrench-for-wasm.md +53 -54
  74. package/docs/bitwrench-mcp.md +2 -2
  75. package/docs/bitwrench-northstar-principles.md +406 -0
  76. package/docs/bitwrench-taco-schema-discussion.md +2 -2
  77. package/docs/bitwrench_api.md +191 -106
  78. package/docs/bitwrench_typescript_usage.md +5 -5
  79. package/docs/bw-attach.md +29 -75
  80. package/docs/bwserve.md +200 -168
  81. package/docs/cli.md +36 -12
  82. package/docs/component-cheatsheet.md +2 -2
  83. package/docs/component-library.md +4 -4
  84. package/docs/component-lifecycle.md +234 -0
  85. package/docs/drift-lint.md +268 -0
  86. package/docs/framework-translation-table.md +4 -4
  87. package/docs/llm-bitwrench-guide.md +60 -50
  88. package/docs/routing.md +11 -13
  89. package/docs/state-management.md +110 -109
  90. package/docs/taco-format.md +13 -14
  91. package/docs/theming.md +13 -3
  92. package/docs/thinking-in-bitwrench.md +858 -983
  93. package/docs/tutorial-bwserve.md +37 -36
  94. package/docs/tutorial-embedded.md +10 -21
  95. package/docs/tutorial-website.md +2 -2
  96. package/package.json +38 -7
  97. package/readme.html +262 -161
  98. package/src/bitwrench-bccl-entry.js +2 -2
  99. package/src/bitwrench-bccl.js +346 -185
  100. package/src/bitwrench-code-edit.js +16 -5
  101. package/src/bitwrench-color-utils.js +117 -181
  102. package/src/bitwrench-file-ops.js +2 -2
  103. package/src/bitwrench-lean.js +4 -3
  104. package/src/bitwrench-router.js +5 -2
  105. package/src/bitwrench-styles.js +420 -504
  106. package/src/bitwrench-util-color.js +240 -0
  107. package/src/bitwrench-util-css.js +1 -0
  108. package/src/bitwrench-utils.js +4 -0
  109. package/src/bitwrench.d.ts +70 -73
  110. package/src/bitwrench.h +5 -0
  111. package/src/bitwrench.js +1939 -933
  112. package/src/bwserve/attach.js +0 -1
  113. package/src/bwserve/bwclient.js +172 -32
  114. package/src/bwserve/bwshell.js +0 -4
  115. package/src/bwserve/client.js +59 -220
  116. package/src/bwserve/index.js +59 -26
  117. package/src/bwserve.d.ts +157 -0
  118. package/src/bwserve.h +5 -0
  119. package/src/cli/attach.js +12 -75
  120. package/src/cli/convert.js +2 -2
  121. package/src/cli/serve.js +37 -35
  122. package/src/generate-css.js +1 -1
  123. package/src/mcp/knowledge.js +4 -4
  124. package/src/mcp/live.js +21 -13
  125. package/src/mcp/tools.js +0 -1
  126. package/src/version.js +3 -7
Binary file
@@ -0,0 +1,251 @@
1
+ /*! bitwrench-util-color v2.1.1 | BSD-2-Clause | https://deftio.github.io/bitwrench/pages */
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * bitwrench-util-color.js - Legacy color parsing and conversion utilities
8
+ *
9
+ * Self-contained module providing CSS color parsing, RGB/HSL conversion,
10
+ * and multi-stop color interpolation. Extracted from bitwrench core in v2.1.
11
+ *
12
+ * Can be loaded standalone (browser script tag after bitwrench.umd.js),
13
+ * or imported as an ES module / CJS module.
14
+ *
15
+ * @module bitwrench-util-color
16
+ * @license BSD-2-Clause
17
+ * @author M A Chatterjee <deftio [at] deftio [dot] com>
18
+ */
19
+
20
+ function _clip(val, min, max) {
21
+ return Math.max(min, Math.min(max, val));
22
+ }
23
+
24
+ function _mapScale(x, in0, in1, out0, out1, options) {
25
+ if (!options) options = {};
26
+ var doClip = options.clip || false;
27
+ var expScale = options.expScale || 1;
28
+ var normalized = (x - in0) / (in1 - in0);
29
+ if (expScale !== 1) normalized = Math.pow(normalized, expScale);
30
+ var result = normalized * (out1 - out0) + out0;
31
+ if (doClip) {
32
+ var mn = Math.min(out0, out1);
33
+ var mx = Math.max(out0, out1);
34
+ result = Math.max(mn, Math.min(mx, result));
35
+ }
36
+ return result;
37
+ }
38
+
39
+ /**
40
+ * Convert HSL to RGB.
41
+ * @param {number|Array} h - Hue 0-360, or [h,s,l,a] array
42
+ * @param {number} [s] - Saturation 0-100
43
+ * @param {number} [l] - Lightness 0-100
44
+ * @param {number} [a=255] - Alpha 0-255
45
+ * @param {boolean} [rnd=true] - Round results
46
+ * @returns {Array} [r, g, b, a, "rgb"]
47
+ */
48
+ function colorHslToRgb(h, s, l, a, rnd) {
49
+ if (a === undefined) a = 255;
50
+ if (rnd === undefined) rnd = true;
51
+ if (Array.isArray(h)) {
52
+ s = h[1]; l = h[2]; a = h[3] !== undefined ? h[3] : 255; h = h[0];
53
+ }
54
+
55
+ var hNorm = h / 360;
56
+ var sNorm = s / 100;
57
+ var lNorm = l / 100;
58
+
59
+ var r, g, b;
60
+
61
+ if (sNorm === 0) {
62
+ r = g = b = lNorm * 255;
63
+ } else {
64
+ var hue2rgb = function(p, q, t) {
65
+ if (t < 0) t += 1;
66
+ if (t > 1) t -= 1;
67
+ if (t < 1/6) return p + (q - p) * 6 * t;
68
+ if (t < 1/2) return q;
69
+ if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
70
+ return p;
71
+ };
72
+
73
+ var q = lNorm < 0.5 ? lNorm * (1 + sNorm) : lNorm + sNorm - lNorm * sNorm;
74
+ var p = 2 * lNorm - q;
75
+
76
+ r = hue2rgb(p, q, hNorm + 1/3) * 255;
77
+ g = hue2rgb(p, q, hNorm) * 255;
78
+ b = hue2rgb(p, q, hNorm - 1/3) * 255;
79
+ }
80
+
81
+ if (rnd) {
82
+ r = Math.round(r);
83
+ g = Math.round(g);
84
+ b = Math.round(b);
85
+ a = Math.round(a);
86
+ }
87
+
88
+ return [r, g, b, a, "rgb"];
89
+ }
90
+
91
+ /**
92
+ * Convert RGB to HSL.
93
+ * @param {number|Array} r - Red 0-255, or [r,g,b,a] array
94
+ * @param {number} [g] - Green 0-255
95
+ * @param {number} [b] - Blue 0-255
96
+ * @param {number} [a=255] - Alpha 0-255
97
+ * @param {boolean} [rnd=true] - Round results
98
+ * @returns {Array} [h, s, l, a, "hsl"]
99
+ */
100
+ function colorRgbToHsl(r, g, b, a, rnd) {
101
+ if (a === undefined) a = 255;
102
+ if (rnd === undefined) rnd = true;
103
+ if (Array.isArray(r)) {
104
+ g = r[1]; b = r[2]; a = r[3] !== undefined ? r[3] : 255; r = r[0];
105
+ }
106
+
107
+ r /= 255;
108
+ g /= 255;
109
+ b /= 255;
110
+
111
+ var max = Math.max(r, g, b);
112
+ var min = Math.min(r, g, b);
113
+ var h, s, l = (max + min) / 2;
114
+
115
+ if (max === min) {
116
+ h = s = 0;
117
+ } else {
118
+ var d = max - min;
119
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
120
+
121
+ switch (max) {
122
+ case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
123
+ case g: h = ((b - r) / d + 2) / 6; break;
124
+ case b: h = ((r - g) / d + 4) / 6; break;
125
+ }
126
+ }
127
+
128
+ h *= 360;
129
+ s *= 100;
130
+ l *= 100;
131
+
132
+ if (rnd) {
133
+ h = Math.round(h);
134
+ s = Math.round(s);
135
+ l = Math.round(l);
136
+ a = Math.round(a);
137
+ }
138
+
139
+ return [h, s, l, a, "hsl"];
140
+ }
141
+
142
+ /**
143
+ * Parse a CSS color string to [r, g, b, a, "rgb"].
144
+ * Handles #hex, rgb(), rgba(), hsl(), hsla(), and bitwrench color arrays.
145
+ * @param {string|Array} s - Color string or array
146
+ * @param {number} [defAlpha=255] - Default alpha
147
+ * @returns {Array} [r, g, b, a, "rgb"]
148
+ */
149
+ function colorParse(s, defAlpha) {
150
+ if (defAlpha === undefined) defAlpha = 255;
151
+ var r = [0, 0, 0, defAlpha, "rgb"];
152
+
153
+ if (Array.isArray(s)) {
154
+ var df = [0, 0, 0, 255, "rgb"];
155
+ for (var p = 0; p < s.length && p < df.length; p++) {
156
+ df[p] = s[p];
157
+ }
158
+ return df;
159
+ }
160
+
161
+ s = String(s).replace(/\s/g, "");
162
+
163
+ if (s[0] === "#") {
164
+ var hex = s.slice(1);
165
+ if (hex.length === 3 || hex.length === 4) {
166
+ for (var i = 0; i < hex.length; i++) {
167
+ r[i] = parseInt(hex[i] + hex[i], 16);
168
+ }
169
+ } else if (hex.length === 6 || hex.length === 8) {
170
+ for (var j = 0; j < hex.length; j += 2) {
171
+ r[j / 2] = parseInt(hex.substring(j, j + 2), 16);
172
+ }
173
+ }
174
+ } else {
175
+ var match = s.match(/^(rgb|hsl)a?\(([^)]+)\)$/i);
176
+ if (match) {
177
+ var type = match[1].toLowerCase();
178
+ var values = match[2].split(",").map(function(v) { return parseFloat(v); });
179
+
180
+ if (type === "rgb") {
181
+ r[0] = values[0] || 0;
182
+ r[1] = values[1] || 0;
183
+ r[2] = values[2] || 0;
184
+ r[3] = values[3] !== undefined ? values[3] * 255 : defAlpha;
185
+ r[4] = "rgb";
186
+ } else if (type === "hsl") {
187
+ var rgb = colorHslToRgb(values[0] || 0, values[1] || 0, values[2] || 0,
188
+ values[3] !== undefined ? values[3] * 255 : defAlpha);
189
+ return rgb;
190
+ }
191
+ }
192
+ }
193
+
194
+ return r;
195
+ }
196
+
197
+ /**
198
+ * Interpolate between N colors based on a mapped position.
199
+ * @param {number} x - Input value
200
+ * @param {number} in0 - Input range start
201
+ * @param {number} in1 - Input range end
202
+ * @param {Array} colors - Array of color strings
203
+ * @param {number} [stretch] - Exponential scaling factor
204
+ * @returns {Array} [r, g, b, a, "rgb"]
205
+ */
206
+ function colorInterp(x, in0, in1, colors, stretch) {
207
+ var c = Array.isArray(colors) ? colors : ["#000", "#fff"];
208
+ c = c.length === 0 ? ["#000", "#fff"] : c;
209
+ if (c.length === 1) return c[0];
210
+
211
+ c = c.map(function(col) { return colorParse(col); });
212
+
213
+ var a = _mapScale(x, in0, in1, 0, c.length - 1, { clip: true, expScale: stretch });
214
+ var i = _clip(Math.floor(a), 0, c.length - 2);
215
+ var r = a - i;
216
+
217
+ var interp = function(idx) { return _mapScale(r, 0, 1, c[i][idx], c[i + 1][idx], { clip: true }); };
218
+ return [interp(0), interp(1), interp(2), interp(3), "rgb"];
219
+ }
220
+
221
+ var utilColor = {
222
+ colorParse: colorParse,
223
+ colorRgbToHsl: colorRgbToHsl,
224
+ colorHslToRgb: colorHslToRgb,
225
+ colorInterp: colorInterp
226
+ };
227
+
228
+ /**
229
+ * Install color utilities onto a bitwrench instance.
230
+ * @param {Object} bw - The bitwrench object to extend
231
+ */
232
+ function install(bw) {
233
+ if (!bw) return;
234
+ bw.colorParse = colorParse;
235
+ bw.colorRgbToHsl = colorRgbToHsl;
236
+ bw.colorHslToRgb = colorHslToRgb;
237
+ bw.colorInterp = colorInterp;
238
+ }
239
+
240
+ if (typeof window !== 'undefined' && window.bw) {
241
+ install(window.bw);
242
+ }
243
+
244
+ exports.colorHslToRgb = colorHslToRgb;
245
+ exports.colorInterp = colorInterp;
246
+ exports.colorParse = colorParse;
247
+ exports.colorRgbToHsl = colorRgbToHsl;
248
+ exports.default = utilColor;
249
+ exports.install = install;
250
+ exports.utilColor = utilColor;
251
+ //# sourceMappingURL=bitwrench-util-color.cjs.js.map
@@ -0,0 +1,3 @@
1
+ /*! bitwrench-util-color v2.1.1 | BSD-2-Clause | https://deftio.github.io/bitwrench/pages */
2
+ "use strict";function r(r,o,t,e,a,n){n||(n={});var i=n.clip||!1,l=n.expScale||1,s=(r-o)/(t-o);1!==l&&(s=Math.pow(s,l));var u=s*(a-e)+e;if(i){var c=Math.min(e,a),f=Math.max(e,a);u=Math.max(c,Math.min(f,u))}return u}function o(r,o,t,e,a){void 0===e&&(e=255),void 0===a&&(a=!0),Array.isArray(r)&&(o=r[1],t=r[2],e=void 0!==r[3]?r[3]:255,r=r[0]);var n,i,l,s=r/360,u=o/100,c=t/100;if(0===u)n=i=l=255*c;else{var f=function(r,o,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+6*(o-r)*t:t<.5?o:t<2/3?r+(o-r)*(2/3-t)*6:r},h=c<.5?c*(1+u):c+u-c*u,g=2*c-h;n=255*f(g,h,s+1/3),i=255*f(g,h,s),l=255*f(g,h,s-1/3)}return a&&(n=Math.round(n),i=Math.round(i),l=Math.round(l),e=Math.round(e)),[n,i,l,e,"rgb"]}function t(r,o,t,e,a){void 0===e&&(e=255),void 0===a&&(a=!0),Array.isArray(r)&&(o=r[1],t=r[2],e=void 0!==r[3]?r[3]:255,r=r[0]),r/=255,o/=255,t/=255;var n,i,l=Math.max(r,o,t),s=Math.min(r,o,t),u=(l+s)/2;if(l===s)n=i=0;else{var c=l-s;switch(i=u>.5?c/(2-l-s):c/(l+s),l){case r:n=((o-t)/c+(o<t?6:0))/6;break;case o:n=((t-r)/c+2)/6;break;case t:n=((r-o)/c+4)/6}}return n*=360,i*=100,u*=100,a&&(n=Math.round(n),i=Math.round(i),u=Math.round(u),e=Math.round(e)),[n,i,u,e,"hsl"]}function e(r,t){void 0===t&&(t=255);var e=[0,0,0,t,"rgb"];if(Array.isArray(r)){for(var a=[0,0,0,255,"rgb"],n=0;n<r.length&&n<a.length;n++)a[n]=r[n];return a}if("#"===(r=String(r).replace(/\s/g,""))[0]){var i=r.slice(1);if(3===i.length||4===i.length)for(var l=0;l<i.length;l++)e[l]=parseInt(i[l]+i[l],16);else if(6===i.length||8===i.length)for(var s=0;s<i.length;s+=2)e[s/2]=parseInt(i.substring(s,s+2),16)}else{var u=r.match(/^(rgb|hsl)a?\(([^)]+)\)$/i);if(u){var c=u[1].toLowerCase(),f=u[2].split(",").map(function(r){return parseFloat(r)});if("rgb"===c)e[0]=f[0]||0,e[1]=f[1]||0,e[2]=f[2]||0,e[3]=void 0!==f[3]?255*f[3]:t,e[4]="rgb";else if("hsl"===c){return o(f[0]||0,f[1]||0,f[2]||0,void 0!==f[3]?255*f[3]:t)}}}return e}function a(o,t,a,n,i){var l=Array.isArray(n)?n:["#000","#fff"];if(1===(l=0===l.length?["#000","#fff"]:l).length)return l[0];var s,u,c,f=r(o,t,a,0,(l=l.map(function(r){return e(r)})).length-1,{clip:!0,expScale:i}),h=(s=Math.floor(f),u=0,c=l.length-2,Math.max(u,Math.min(c,s))),g=f-h,v=function(o){return r(g,0,1,l[h][o],l[h+1][o],{clip:!0})};return[v(0),v(1),v(2),v(3),"rgb"]}Object.defineProperty(exports,"__esModule",{value:!0});var n={colorParse:e,colorRgbToHsl:t,colorHslToRgb:o,colorInterp:a};function i(r){r&&(r.colorParse=e,r.colorRgbToHsl=t,r.colorHslToRgb=o,r.colorInterp=a)}"undefined"!=typeof window&&window.bw&&i(window.bw),exports.colorHslToRgb=o,exports.colorInterp=a,exports.colorParse=e,exports.colorRgbToHsl=t,exports.default=n,exports.install=i,exports.utilColor=n;
3
+ //# sourceMappingURL=bitwrench-util-color.cjs.min.js.map
@@ -0,0 +1,256 @@
1
+ /*! bitwrench-util-color v2.1.1 | BSD-2-Clause | https://deftio.github.io/bitwrench/pages */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bwUtilColor = {}));
6
+ })(this, (function (exports) { 'use strict';
7
+
8
+ /**
9
+ * bitwrench-util-color.js - Legacy color parsing and conversion utilities
10
+ *
11
+ * Self-contained module providing CSS color parsing, RGB/HSL conversion,
12
+ * and multi-stop color interpolation. Extracted from bitwrench core in v2.1.
13
+ *
14
+ * Can be loaded standalone (browser script tag after bitwrench.umd.js),
15
+ * or imported as an ES module / CJS module.
16
+ *
17
+ * @module bitwrench-util-color
18
+ * @license BSD-2-Clause
19
+ * @author M A Chatterjee <deftio [at] deftio [dot] com>
20
+ */
21
+
22
+ function _clip(val, min, max) {
23
+ return Math.max(min, Math.min(max, val));
24
+ }
25
+ function _mapScale(x, in0, in1, out0, out1, options) {
26
+ if (!options) options = {};
27
+ var doClip = options.clip || false;
28
+ var expScale = options.expScale || 1;
29
+ var normalized = (x - in0) / (in1 - in0);
30
+ if (expScale !== 1) normalized = Math.pow(normalized, expScale);
31
+ var result = normalized * (out1 - out0) + out0;
32
+ if (doClip) {
33
+ var mn = Math.min(out0, out1);
34
+ var mx = Math.max(out0, out1);
35
+ result = Math.max(mn, Math.min(mx, result));
36
+ }
37
+ return result;
38
+ }
39
+
40
+ /**
41
+ * Convert HSL to RGB.
42
+ * @param {number|Array} h - Hue 0-360, or [h,s,l,a] array
43
+ * @param {number} [s] - Saturation 0-100
44
+ * @param {number} [l] - Lightness 0-100
45
+ * @param {number} [a=255] - Alpha 0-255
46
+ * @param {boolean} [rnd=true] - Round results
47
+ * @returns {Array} [r, g, b, a, "rgb"]
48
+ */
49
+ function colorHslToRgb(h, s, l, a, rnd) {
50
+ if (a === undefined) a = 255;
51
+ if (rnd === undefined) rnd = true;
52
+ if (Array.isArray(h)) {
53
+ s = h[1];
54
+ l = h[2];
55
+ a = h[3] !== undefined ? h[3] : 255;
56
+ h = h[0];
57
+ }
58
+ var hNorm = h / 360;
59
+ var sNorm = s / 100;
60
+ var lNorm = l / 100;
61
+ var r, g, b;
62
+ if (sNorm === 0) {
63
+ r = g = b = lNorm * 255;
64
+ } else {
65
+ var hue2rgb = function hue2rgb(p, q, t) {
66
+ if (t < 0) t += 1;
67
+ if (t > 1) t -= 1;
68
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
69
+ if (t < 1 / 2) return q;
70
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
71
+ return p;
72
+ };
73
+ var q = lNorm < 0.5 ? lNorm * (1 + sNorm) : lNorm + sNorm - lNorm * sNorm;
74
+ var p = 2 * lNorm - q;
75
+ r = hue2rgb(p, q, hNorm + 1 / 3) * 255;
76
+ g = hue2rgb(p, q, hNorm) * 255;
77
+ b = hue2rgb(p, q, hNorm - 1 / 3) * 255;
78
+ }
79
+ if (rnd) {
80
+ r = Math.round(r);
81
+ g = Math.round(g);
82
+ b = Math.round(b);
83
+ a = Math.round(a);
84
+ }
85
+ return [r, g, b, a, "rgb"];
86
+ }
87
+
88
+ /**
89
+ * Convert RGB to HSL.
90
+ * @param {number|Array} r - Red 0-255, or [r,g,b,a] array
91
+ * @param {number} [g] - Green 0-255
92
+ * @param {number} [b] - Blue 0-255
93
+ * @param {number} [a=255] - Alpha 0-255
94
+ * @param {boolean} [rnd=true] - Round results
95
+ * @returns {Array} [h, s, l, a, "hsl"]
96
+ */
97
+ function colorRgbToHsl(r, g, b, a, rnd) {
98
+ if (a === undefined) a = 255;
99
+ if (rnd === undefined) rnd = true;
100
+ if (Array.isArray(r)) {
101
+ g = r[1];
102
+ b = r[2];
103
+ a = r[3] !== undefined ? r[3] : 255;
104
+ r = r[0];
105
+ }
106
+ r /= 255;
107
+ g /= 255;
108
+ b /= 255;
109
+ var max = Math.max(r, g, b);
110
+ var min = Math.min(r, g, b);
111
+ var h,
112
+ s,
113
+ l = (max + min) / 2;
114
+ if (max === min) {
115
+ h = s = 0;
116
+ } else {
117
+ var d = max - min;
118
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
119
+ switch (max) {
120
+ case r:
121
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
122
+ break;
123
+ case g:
124
+ h = ((b - r) / d + 2) / 6;
125
+ break;
126
+ case b:
127
+ h = ((r - g) / d + 4) / 6;
128
+ break;
129
+ }
130
+ }
131
+ h *= 360;
132
+ s *= 100;
133
+ l *= 100;
134
+ if (rnd) {
135
+ h = Math.round(h);
136
+ s = Math.round(s);
137
+ l = Math.round(l);
138
+ a = Math.round(a);
139
+ }
140
+ return [h, s, l, a, "hsl"];
141
+ }
142
+
143
+ /**
144
+ * Parse a CSS color string to [r, g, b, a, "rgb"].
145
+ * Handles #hex, rgb(), rgba(), hsl(), hsla(), and bitwrench color arrays.
146
+ * @param {string|Array} s - Color string or array
147
+ * @param {number} [defAlpha=255] - Default alpha
148
+ * @returns {Array} [r, g, b, a, "rgb"]
149
+ */
150
+ function colorParse(s, defAlpha) {
151
+ if (defAlpha === undefined) defAlpha = 255;
152
+ var r = [0, 0, 0, defAlpha, "rgb"];
153
+ if (Array.isArray(s)) {
154
+ var df = [0, 0, 0, 255, "rgb"];
155
+ for (var p = 0; p < s.length && p < df.length; p++) {
156
+ df[p] = s[p];
157
+ }
158
+ return df;
159
+ }
160
+ s = String(s).replace(/\s/g, "");
161
+ if (s[0] === "#") {
162
+ var hex = s.slice(1);
163
+ if (hex.length === 3 || hex.length === 4) {
164
+ for (var i = 0; i < hex.length; i++) {
165
+ r[i] = parseInt(hex[i] + hex[i], 16);
166
+ }
167
+ } else if (hex.length === 6 || hex.length === 8) {
168
+ for (var j = 0; j < hex.length; j += 2) {
169
+ r[j / 2] = parseInt(hex.substring(j, j + 2), 16);
170
+ }
171
+ }
172
+ } else {
173
+ var match = s.match(/^(rgb|hsl)a?\(([^)]+)\)$/i);
174
+ if (match) {
175
+ var type = match[1].toLowerCase();
176
+ var values = match[2].split(",").map(function (v) {
177
+ return parseFloat(v);
178
+ });
179
+ if (type === "rgb") {
180
+ r[0] = values[0] || 0;
181
+ r[1] = values[1] || 0;
182
+ r[2] = values[2] || 0;
183
+ r[3] = values[3] !== undefined ? values[3] * 255 : defAlpha;
184
+ r[4] = "rgb";
185
+ } else if (type === "hsl") {
186
+ var rgb = colorHslToRgb(values[0] || 0, values[1] || 0, values[2] || 0, values[3] !== undefined ? values[3] * 255 : defAlpha);
187
+ return rgb;
188
+ }
189
+ }
190
+ }
191
+ return r;
192
+ }
193
+
194
+ /**
195
+ * Interpolate between N colors based on a mapped position.
196
+ * @param {number} x - Input value
197
+ * @param {number} in0 - Input range start
198
+ * @param {number} in1 - Input range end
199
+ * @param {Array} colors - Array of color strings
200
+ * @param {number} [stretch] - Exponential scaling factor
201
+ * @returns {Array} [r, g, b, a, "rgb"]
202
+ */
203
+ function colorInterp(x, in0, in1, colors, stretch) {
204
+ var c = Array.isArray(colors) ? colors : ["#000", "#fff"];
205
+ c = c.length === 0 ? ["#000", "#fff"] : c;
206
+ if (c.length === 1) return c[0];
207
+ c = c.map(function (col) {
208
+ return colorParse(col);
209
+ });
210
+ var a = _mapScale(x, in0, in1, 0, c.length - 1, {
211
+ clip: true,
212
+ expScale: stretch
213
+ });
214
+ var i = _clip(Math.floor(a), 0, c.length - 2);
215
+ var r = a - i;
216
+ var interp = function interp(idx) {
217
+ return _mapScale(r, 0, 1, c[i][idx], c[i + 1][idx], {
218
+ clip: true
219
+ });
220
+ };
221
+ return [interp(0), interp(1), interp(2), interp(3), "rgb"];
222
+ }
223
+ var utilColor = {
224
+ colorParse: colorParse,
225
+ colorRgbToHsl: colorRgbToHsl,
226
+ colorHslToRgb: colorHslToRgb,
227
+ colorInterp: colorInterp
228
+ };
229
+
230
+ /**
231
+ * Install color utilities onto a bitwrench instance.
232
+ * @param {Object} bw - The bitwrench object to extend
233
+ */
234
+ function install(bw) {
235
+ if (!bw) return;
236
+ bw.colorParse = colorParse;
237
+ bw.colorRgbToHsl = colorRgbToHsl;
238
+ bw.colorHslToRgb = colorHslToRgb;
239
+ bw.colorInterp = colorInterp;
240
+ }
241
+ if (typeof window !== 'undefined' && window.bw) {
242
+ install(window.bw);
243
+ }
244
+
245
+ exports.colorHslToRgb = colorHslToRgb;
246
+ exports.colorInterp = colorInterp;
247
+ exports.colorParse = colorParse;
248
+ exports.colorRgbToHsl = colorRgbToHsl;
249
+ exports.default = utilColor;
250
+ exports.install = install;
251
+ exports.utilColor = utilColor;
252
+
253
+ Object.defineProperty(exports, '__esModule', { value: true });
254
+
255
+ }));
256
+ //# sourceMappingURL=bitwrench-util-color.es5.js.map
@@ -0,0 +1,3 @@
1
+ /*! bitwrench-util-color v2.1.1 | BSD-2-Clause | https://deftio.github.io/bitwrench/pages */
2
+ !function(r,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((r="undefined"!=typeof globalThis?globalThis:r||self).bwUtilColor={})}(this,function(r){"use strict";function o(r,o,e,t,n,a){a||(a={});var i=a.clip||!1,l=a.expScale||1,f=(r-o)/(e-o);1!==l&&(f=Math.pow(f,l));var s=f*(n-t)+t;if(i){var u=Math.min(t,n),c=Math.max(t,n);s=Math.max(u,Math.min(c,s))}return s}function e(r,o,e,t,n){void 0===t&&(t=255),void 0===n&&(n=!0),Array.isArray(r)&&(o=r[1],e=r[2],t=void 0!==r[3]?r[3]:255,r=r[0]);var a,i,l,f=r/360,s=o/100,u=e/100;if(0===s)a=i=l=255*u;else{var c=function(r,o,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+6*(o-r)*e:e<.5?o:e<2/3?r+(o-r)*(2/3-e)*6:r},h=u<.5?u*(1+s):u+s-u*s,d=2*u-h;a=255*c(d,h,f+1/3),i=255*c(d,h,f),l=255*c(d,h,f-1/3)}return n&&(a=Math.round(a),i=Math.round(i),l=Math.round(l),t=Math.round(t)),[a,i,l,t,"rgb"]}function t(r,o,e,t,n){void 0===t&&(t=255),void 0===n&&(n=!0),Array.isArray(r)&&(o=r[1],e=r[2],t=void 0!==r[3]?r[3]:255,r=r[0]),r/=255,o/=255,e/=255;var a,i,l=Math.max(r,o,e),f=Math.min(r,o,e),s=(l+f)/2;if(l===f)a=i=0;else{var u=l-f;switch(i=s>.5?u/(2-l-f):u/(l+f),l){case r:a=((o-e)/u+(o<e?6:0))/6;break;case o:a=((e-r)/u+2)/6;break;case e:a=((r-o)/u+4)/6}}return a*=360,i*=100,s*=100,n&&(a=Math.round(a),i=Math.round(i),s=Math.round(s),t=Math.round(t)),[a,i,s,t,"hsl"]}function n(r,o){void 0===o&&(o=255);var t=[0,0,0,o,"rgb"];if(Array.isArray(r)){for(var n=[0,0,0,255,"rgb"],a=0;a<r.length&&a<n.length;a++)n[a]=r[a];return n}if("#"===(r=String(r).replace(/\s/g,""))[0]){var i=r.slice(1);if(3===i.length||4===i.length)for(var l=0;l<i.length;l++)t[l]=parseInt(i[l]+i[l],16);else if(6===i.length||8===i.length)for(var f=0;f<i.length;f+=2)t[f/2]=parseInt(i.substring(f,f+2),16)}else{var s=r.match(/^(rgb|hsl)a?\(([^)]+)\)$/i);if(s){var u=s[1].toLowerCase(),c=s[2].split(",").map(function(r){return parseFloat(r)});if("rgb"===u)t[0]=c[0]||0,t[1]=c[1]||0,t[2]=c[2]||0,t[3]=void 0!==c[3]?255*c[3]:o,t[4]="rgb";else if("hsl"===u){return e(c[0]||0,c[1]||0,c[2]||0,void 0!==c[3]?255*c[3]:o)}}}return t}function a(r,e,t,a,i){var l=Array.isArray(a)?a:["#000","#fff"];if(1===(l=0===l.length?["#000","#fff"]:l).length)return l[0];var f,s,u,c=o(r,e,t,0,(l=l.map(function(r){return n(r)})).length-1,{clip:!0,expScale:i}),h=(f=Math.floor(c),s=0,u=l.length-2,Math.max(s,Math.min(u,f))),d=c-h,g=function(r){return o(d,0,1,l[h][r],l[h+1][r],{clip:!0})};return[g(0),g(1),g(2),g(3),"rgb"]}var i={colorParse:n,colorRgbToHsl:t,colorHslToRgb:e,colorInterp:a};function l(r){r&&(r.colorParse=n,r.colorRgbToHsl=t,r.colorHslToRgb=e,r.colorInterp=a)}"undefined"!=typeof window&&window.bw&&l(window.bw),r.colorHslToRgb=e,r.colorInterp=a,r.colorParse=n,r.colorRgbToHsl=t,r.default=i,r.install=l,r.utilColor=i,Object.defineProperty(r,"__esModule",{value:!0})});
3
+ //# sourceMappingURL=bitwrench-util-color.es5.min.js.map