"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }






var _chunk7UPVCT3Kjs = require('./chunk-7UPVCT3K.js');
require('./chunk-YYO3RIFO.js');
require('./chunk-DGUM43GV.js');

// src/theme-bridge/ThemeBridgeProvider.tsx
var _react = require('react'); var React = _interopRequireWildcard(_react);

// src/theme-bridge/generateCssVars.ts
var SCOPE_ID = "sdk";
var SYSTEM_FONT_STACK = 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"';
var SPACING_CONFIG = {
  comfortable: { mult: 1.15, rhythm: "1.2rem" },
  standard: { mult: 1, rhythm: "1rem" },
  dense: { mult: 0.88, rhythm: "0.75rem" }
};
var CORNERS_CONFIG = {
  square: { control: "0px", card: "0px" },
  soft: { control: "4px", card: "8px" },
  rounded: { control: "8px", card: "12px" },
  pill: { control: "9999px", card: "16px" }
};
var SHADOWS_CONFIG = {
  none: {
    sm: "none",
    md: "none",
    lg: "none",
    elev: "none"
  },
  low: {
    sm: "0 1px 2px rgba(0,0,0,0.04)",
    md: "0 2px 4px rgba(0,0,0,0.06)",
    lg: "0 4px 8px rgba(0,0,0,0.08)",
    elev: "0 1px 3px rgba(0,0,0,0.06)"
  },
  medium: {
    sm: "0 1px 2px rgba(0,0,0,0.06)",
    md: "0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1)",
    lg: "0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1)",
    elev: "0 2px 6px rgba(0,0,0,0.08)"
  },
  high: {
    sm: "0 1px 3px rgba(0,0,0,0.08)",
    md: "0 6px 12px -2px rgba(0,0,0,0.15), 0 3px 6px -3px rgba(0,0,0,0.1)",
    lg: "0 20px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1)",
    elev: "0 4px 12px rgba(0,0,0,0.12)"
  }
};
function hexToRgb(hex) {
  const h = hex.replace(/^#/, "");
  const m = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
  if (m.length !== 6) {
    console.warn(`[ThemeBridge] Invalid hex color: ${hex}`);
    return "0 0 0";
  }
  const int = parseInt(m, 16);
  const r = int >> 16 & 255;
  const g = int >> 8 & 255;
  const b = int & 255;
  return `${r} ${g} ${b}`;
}
function normalizeTokenValue(value) {
  if (value.startsWith("var(")) {
    return value;
  }
  if (value.startsWith("#")) {
    return hexToRgb(value);
  }
  return value;
}
function generateThemeBridgeCss(config) {
  if (!config || typeof config !== "object") {
    throw new Error(
      '[ThemeBridge] Invalid config: expected an object with a "tokens" property.'
    );
  }
  if (!config.tokens || typeof config.tokens !== "object" || Array.isArray(config.tokens)) {
    throw new Error(
      '[ThemeBridge] Missing "tokens" property in config. ThemeBridgeConfig requires a "tokens" object with color definitions. Example: { tokens: { primary: "#6d28d9", background: "#ffffff" } }'
    );
  }
  const cssVars = {};
  const cssChunks = [];
  for (const [name, value] of Object.entries(config.tokens)) {
    cssVars[`--tb-${name}`] = normalizeTokenValue(value);
  }
  const typography = _nullishCoalesce(config.typography, () => ( {}));
  cssVars["--tb-font-heading"] = _nullishCoalesce(typography.headingFamily, () => ( SYSTEM_FONT_STACK));
  cssVars["--tb-font-body"] = _nullishCoalesce(typography.bodyFamily, () => ( SYSTEM_FONT_STACK));
  cssVars["--tb-font-weight-heading"] = String(_nullishCoalesce(typography.headingWeight, () => ( 600)));
  cssVars["--tb-font-weight-body"] = String(_nullishCoalesce(typography.bodyWeight, () => ( 400)));
  cssVars["--tb-fs-h1"] = "2.5rem";
  cssVars["--tb-fs-h2"] = "2rem";
  cssVars["--tb-fs-h3"] = "1.5rem";
  cssVars["--tb-fs-body"] = "1rem";
  cssVars["--tb-ls-heading"] = "-0.02em";
  cssVars["--tb-ls-body"] = "0";
  cssVars["--tb-lh-heading"] = "1.2";
  cssVars["--tb-lh-body"] = "1.6";
  cssVars["--tb-tt-heading"] = "none";
  cssVars["--tb-fv-heading"] = "normal";
  const spacingPreset = SPACING_CONFIG[_nullishCoalesce(config.spacing, () => ( "standard"))];
  cssVars["--tb-space-mult"] = String(spacingPreset.mult);
  cssVars["--tb-rt-space-y"] = spacingPreset.rhythm;
  const corners = _nullishCoalesce(config.corners, () => ( "rounded"));
  const cornersPreset = CORNERS_CONFIG[corners];
  cssVars["--tb-radius-control"] = cornersPreset.control;
  cssVars["--tb-radius-card"] = cornersPreset.card;
  const shadows = _nullishCoalesce(config.shadows, () => ( "medium"));
  const shadowsPreset = SHADOWS_CONFIG[shadows];
  cssVars["--tb-shadow-sm"] = shadowsPreset.sm;
  cssVars["--tb-shadow-md"] = shadowsPreset.md;
  cssVars["--tb-shadow-lg"] = shadowsPreset.lg;
  cssVars["--tb-shadow-elev"] = shadowsPreset.elev;
  cssVars["--tb-motion-duration"] = "180ms";
  cssVars["--tb-motion-ease"] = "cubic-bezier(0.2, 0.8, 0.2, 1)";
  const cssLines = Object.entries(cssVars).map(([key, value]) => `  ${key}: ${value};`).join("\n");
  cssChunks.push(`:where([data-theme-scope="${SCOPE_ID}"]) {
${cssLines}
}`);
  if (_optionalChain([config, 'access', _ => _.components, 'optionalAccess', _2 => _2.buttons])) {
    const buttonCss = generateButtonsCss(config, corners, shadows);
    cssChunks.push(buttonCss);
  }
  if (_optionalChain([config, 'access', _3 => _3.components, 'optionalAccess', _4 => _4.cards])) {
    const cardCss = generateCardsCss(config, corners, shadows);
    cssChunks.push(cardCss);
  }
  if (_optionalChain([config, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.inputs])) {
    const inputCss = generateInputsCss(config, corners, shadows);
    cssChunks.push(inputCss);
  }
  if (config.overrides) {
    const overrideCss = generateOverrideCss(config.overrides);
    cssChunks.push(overrideCss);
  }
  return {
    cssVars,
    css: cssChunks.join("\n\n")
  };
}
function generateButtonsCss(config, corners, shadows) {
  const buttonConfig = _optionalChain([config, 'access', _7 => _7.components, 'optionalAccess', _8 => _8.buttons]);
  let variants = _chunk7UPVCT3Kjs.getDefaultButtonVariants.call(void 0, );
  if (typeof buttonConfig === "object" && buttonConfig.variants) {
    const requestedIds = new Set(buttonConfig.variants);
    variants = variants.filter((v) => requestedIds.has(v.id));
  }
  const settings = {
    corners,
    shadow: shadows,
    borderWidth: "thin",
    fontWeight: 500,
    textTransform: "none"
  };
  return _chunk7UPVCT3Kjs.generateButtonCoreCss.call(void 0, SCOPE_ID, variants, settings);
}
function generateCardsCss(config, corners, shadows) {
  const cardConfig = _optionalChain([config, 'access', _9 => _9.components, 'optionalAccess', _10 => _10.cards]);
  let variants = _chunk7UPVCT3Kjs.getDefaultCardVariants.call(void 0, );
  if (typeof cardConfig === "object" && cardConfig.variants) {
    const requestedIds = new Set(cardConfig.variants);
    variants = variants.filter((v) => requestedIds.has(v.id));
  }
  const settings = {
    corners,
    shadow: shadows,
    borderWidth: "thin"
  };
  return _chunk7UPVCT3Kjs.generateCardCoreCss.call(void 0, SCOPE_ID, variants, settings);
}
function generateInputsCss(config, corners, shadows) {
  const settings = _chunk7UPVCT3Kjs.getDefaultInputSettings.call(void 0, );
  settings.corners = corners;
  settings.shadow = shadows === "none" ? "none" : "low";
  return _chunk7UPVCT3Kjs.generateInputCoreCss.call(void 0, SCOPE_ID, settings);
}
function generateOverrideCss(overrides) {
  const chunks = [];
  for (const [selector, rules] of Object.entries(overrides)) {
    chunks.push(`:where([data-theme-scope="${SCOPE_ID}"]) ${selector} {
  ${rules}
}`);
  }
  return chunks.join("\n\n");
}

// src/theme-bridge/ThemeBridgeProvider.tsx
var _jsxruntime = require('react/jsx-runtime');
function ThemeBridgeProvider({
  config,
  children,
  className = "",
  as: Tag = "div"
}) {
  const { css, cssVars } = React.useMemo(
    () => generateThemeBridgeCss(config),
    [config]
  );
  const inlineStyle = React.useMemo(() => {
    const style = {};
    for (const [key, value] of Object.entries(cssVars)) {
      style[key] = value;
    }
    return style;
  }, [cssVars]);
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { dangerouslySetInnerHTML: { __html: css } }),
    React.createElement(
      Tag,
      {
        "data-theme-scope": "sdk",
        className: `theme-scope ${className}`.trim(),
        style: inlineStyle
      },
      children
    )
  ] });
}
function useThemeBridgeCss(config) {
  return React.useMemo(() => generateThemeBridgeCss(config), [config]);
}




exports.ThemeBridgeProvider = ThemeBridgeProvider; exports.generateThemeBridgeCss = generateThemeBridgeCss; exports.useThemeBridgeCss = useThemeBridgeCss;
//# sourceMappingURL=theme-bridge.js.map