@trops/dash-core 0.1.575 → 0.1.576

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -36921,20 +36921,146 @@ var PanelThemeStudio = function PanelThemeStudio(_ref) {
36921
36921
  });
36922
36922
  };
36923
36923
 
36924
- // Color harmony helpers — inlined so dash-core can ship the new
36925
- // "From Colors" generator without first publishing matching
36926
- // exports from @trops/dash-react. Same math as the planned dash-react
36927
- // counterparts; can be replaced with a re-export once both ship in
36928
- // the same cycle.
36924
+ /**
36925
+ * themeGenerator.js
36926
+ *
36927
+ * Utility for generating themes via presets, random generation,
36928
+ * and color-harmony-based generation from a user-selected base color.
36929
+ */
36930
+ // All color math is inlined here (no @trops/dash-react import). This
36931
+ // file is reachable from Electron's main process via
36932
+ // `electron/controller/paletteToThemeMapper.js`. Importing dash-react
36933
+ // from a main-process reachable file pulls dash-react's renderer
36934
+ // bundle into the main bundle — that bundle has top-level browser
36935
+ // API access (`window.ResizeObserver` in CodeEditorVS) which throws
36936
+ // when required under Node. Keeping this module pure-JS / no-deps
36937
+ // breaks the chain.
36938
+
36939
+ var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
36940
+ function isHexColor(value) {
36941
+ return typeof value === "string" && HEX_RE.test(value.trim());
36942
+ }
36943
+ function normalizeHex(input) {
36944
+ if (typeof input !== "string") return null;
36945
+ var s = input.trim().toLowerCase();
36946
+ if (!s.startsWith("#")) s = "#".concat(s);
36947
+ if (!HEX_RE.test(s)) return null;
36948
+ if (s.length === 4) s = "#".concat(s[1]).concat(s[1]).concat(s[2]).concat(s[2]).concat(s[3]).concat(s[3]);else if (s.length === 5) s = "#".concat(s[1]).concat(s[1]).concat(s[2]).concat(s[2]).concat(s[3]).concat(s[3]);else if (s.length === 9) s = s.slice(0, 7);
36949
+ return s;
36950
+ }
36951
+ function hexToRgb(hex) {
36952
+ var n = normalizeHex(hex);
36953
+ if (!n) return null;
36954
+ var v = parseInt(n.slice(1), 16);
36955
+ return {
36956
+ r: v >> 16 & 0xff,
36957
+ g: v >> 8 & 0xff,
36958
+ b: v & 0xff
36959
+ };
36960
+ }
36961
+ function rgbToHex(_ref) {
36962
+ var r = _ref.r,
36963
+ g = _ref.g,
36964
+ b = _ref.b;
36965
+ var c = function c(x) {
36966
+ return Math.max(0, Math.min(255, Math.round(x)));
36967
+ };
36968
+ var h = function h(x) {
36969
+ return c(x).toString(16).padStart(2, "0");
36970
+ };
36971
+ return "#".concat(h(r)).concat(h(g)).concat(h(b));
36972
+ }
36973
+ function rgbToHsl(_ref2) {
36974
+ var r = _ref2.r,
36975
+ g = _ref2.g,
36976
+ b = _ref2.b;
36977
+ var R = r / 255,
36978
+ G = g / 255,
36979
+ B = b / 255;
36980
+ var max = Math.max(R, G, B),
36981
+ min = Math.min(R, G, B);
36982
+ var l = (max + min) / 2;
36983
+ var h = 0,
36984
+ s = 0;
36985
+ if (max !== min) {
36986
+ var d = max - min;
36987
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
36988
+ switch (max) {
36989
+ case R:
36990
+ h = (G - B) / d + (G < B ? 6 : 0);
36991
+ break;
36992
+ case G:
36993
+ h = (B - R) / d + 2;
36994
+ break;
36995
+ default:
36996
+ h = (R - G) / d + 4;
36997
+ }
36998
+ h *= 60;
36999
+ }
37000
+ return {
37001
+ h: h,
37002
+ s: s,
37003
+ l: l
37004
+ };
37005
+ }
37006
+ function hslToRgb(_ref3) {
37007
+ var h = _ref3.h,
37008
+ s = _ref3.s,
37009
+ l = _ref3.l;
37010
+ if (s === 0) {
37011
+ var v = l * 255;
37012
+ return {
37013
+ r: v,
37014
+ g: v,
37015
+ b: v
37016
+ };
37017
+ }
37018
+ var c = (1 - Math.abs(2 * l - 1)) * s;
37019
+ var x = c * (1 - Math.abs(h / 60 % 2 - 1));
37020
+ var m = l - c / 2;
37021
+ var rp, gp, bp;
37022
+ if (h < 60) {
37023
+ rp = c;
37024
+ gp = x;
37025
+ bp = 0;
37026
+ } else if (h < 120) {
37027
+ rp = x;
37028
+ gp = c;
37029
+ bp = 0;
37030
+ } else if (h < 180) {
37031
+ rp = 0;
37032
+ gp = c;
37033
+ bp = x;
37034
+ } else if (h < 240) {
37035
+ rp = 0;
37036
+ gp = x;
37037
+ bp = c;
37038
+ } else if (h < 300) {
37039
+ rp = x;
37040
+ gp = 0;
37041
+ bp = c;
37042
+ } else {
37043
+ rp = c;
37044
+ gp = 0;
37045
+ bp = x;
37046
+ }
37047
+ return {
37048
+ r: (rp + m) * 255,
37049
+ g: (gp + m) * 255,
37050
+ b: (bp + m) * 255
37051
+ };
37052
+ }
37053
+
37054
+ // Color harmony helpers — pure JS, no DOM/window access.
36929
37055
  function rotateHex(hex, deltaH) {
36930
- var rgb = DashReact.hexToRgb(hex);
37056
+ var rgb = hexToRgb(hex);
36931
37057
  if (!rgb) return null;
36932
- var _rgbToHsl = DashReact.rgbToHsl(rgb),
37058
+ var _rgbToHsl = rgbToHsl(rgb),
36933
37059
  h = _rgbToHsl.h,
36934
37060
  s = _rgbToHsl.s,
36935
37061
  l = _rgbToHsl.l;
36936
37062
  var newH = ((h + deltaH) % 360 + 360) % 360;
36937
- return DashReact.rgbToHex(DashReact.hslToRgb({
37063
+ return rgbToHex(hslToRgb({
36938
37064
  h: newH,
36939
37065
  s: s,
36940
37066
  l: l
@@ -36966,9 +37092,9 @@ function tetradicHexes(hex) {
36966
37092
  }
36967
37093
  function monochromaticHexes(hex) {
36968
37094
  var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
36969
- var rgb = DashReact.hexToRgb(hex);
37095
+ var rgb = hexToRgb(hex);
36970
37096
  if (!rgb) return null;
36971
- var _rgbToHsl2 = DashReact.rgbToHsl(rgb),
37097
+ var _rgbToHsl2 = rgbToHsl(rgb),
36972
37098
  h = _rgbToHsl2.h,
36973
37099
  s = _rgbToHsl2.s;
36974
37100
  var out = [];
@@ -36976,7 +37102,7 @@ function monochromaticHexes(hex) {
36976
37102
  var t = count === 1 ? 0.5 : i / (count - 1);
36977
37103
  var l = 0.15 + t * 0.7;
36978
37104
  var sAdj = s * (1 - 0.3 * Math.abs(t - 0.5) * 2);
36979
- out.push(DashReact.rgbToHex(DashReact.hslToRgb({
37105
+ out.push(rgbToHex(hslToRgb({
36980
37106
  h: h,
36981
37107
  s: sAdj,
36982
37108
  l: l
@@ -36988,13 +37114,13 @@ function adjustHsl(hex) {
36988
37114
  var dH = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
36989
37115
  var dS = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
36990
37116
  var dL = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
36991
- var rgb = DashReact.hexToRgb(hex);
37117
+ var rgb = hexToRgb(hex);
36992
37118
  if (!rgb) return null;
36993
- var hsl = DashReact.rgbToHsl(rgb);
37119
+ var hsl = rgbToHsl(rgb);
36994
37120
  var h = ((hsl.h + dH) % 360 + 360) % 360;
36995
37121
  var s = Math.max(0, Math.min(1, hsl.s + dS));
36996
37122
  var l = Math.max(0, Math.min(1, hsl.l + dL));
36997
- return DashReact.rgbToHex(DashReact.hslToRgb({
37123
+ return rgbToHex(hslToRgb({
36998
37124
  h: h,
36999
37125
  s: s,
37000
37126
  l: l
@@ -37180,7 +37306,7 @@ function generateRandomTheme() {
37180
37306
  function generateHarmonyTheme(baseColor) {
37181
37307
  var strategy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "complementary";
37182
37308
  var hslNudge = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
37183
- if (typeof baseColor === "string" && DashReact.isHexColor(baseColor)) {
37309
+ if (typeof baseColor === "string" && isHexColor(baseColor)) {
37184
37310
  return generateHexHarmonyTheme(baseColor, strategy, hslNudge);
37185
37311
  }
37186
37312
  var baseHue = COLOR_WHEEL[baseColor];
@@ -37224,7 +37350,7 @@ function generateHarmonyTheme(baseColor) {
37224
37350
  * almost fully, keeping the same hue family for a cohesive feel.
37225
37351
  */
37226
37352
  function generateHexHarmonyTheme(baseHex, strategy, hslNudge) {
37227
- var base = DashReact.normalizeHex(baseHex);
37353
+ var base = normalizeHex(baseHex);
37228
37354
  if (!base) return generateRandomTheme();
37229
37355
  var primary = base;
37230
37356
  var secondary;