chaincss 2.1.10 → 2.1.12

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.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
  export { smartChain, smartChain as chainV3, buildChain, runtimeChain } from './core/smart-chain.js';
6
+ export { injectChainStyles } from './runtime/index.js';
6
7
  export { autoDetector, AutoDetector, type ValueType, type Mode } from './core/auto-detector.js';
7
8
  export { useSmartStyles, createSmartComponent, withSmartStyles } from './runtime/auto-hooks.js';
8
9
  export { ChainCSSCompiler, compileChainCSS } from './core/compiler.js';
package/dist/index.js CHANGED
@@ -3065,9 +3065,6 @@ function smartChain(useTokens = true) {
3065
3065
  var buildChain = (useTokens) => chain(useTokens);
3066
3066
  var runtimeChain = (useTokens) => new RuntimeChain(useTokens || true).proxy;
3067
3067
 
3068
- // src/runtime/auto-hooks.tsx
3069
- import React, { useEffect, useRef, useState } from "react";
3070
-
3071
3068
  // src/core/common-utils.ts
3072
3069
  function kebabCase(str) {
3073
3070
  return str.replace(/([A-Z])/g, "-$1").toLowerCase();
@@ -3353,7 +3350,40 @@ ${rules}}
3353
3350
  var styleInjector = new StyleInjector();
3354
3351
  var compileRuntime = (s, moduleId) => styleInjector.injectMultiple(s, moduleId);
3355
3352
 
3353
+ // src/runtime/index.ts
3354
+ function injectChainStyles(styles) {
3355
+ let css = "";
3356
+ for (const [key, obj] of Object.entries(styles)) {
3357
+ if (!obj || !obj.selectors) continue;
3358
+ const sel = "." + obj.selectors[0];
3359
+ css += sel + "{";
3360
+ for (const [k, v] of Object.entries(obj)) {
3361
+ if (["selectors", "hover", "atRules", "nestedRules", "_name", "_classes"].includes(k)) continue;
3362
+ css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3363
+ }
3364
+ css += "}";
3365
+ if (obj.hover) {
3366
+ css += sel + ":hover{";
3367
+ for (const [k, v] of Object.entries(obj.hover)) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3368
+ css += "}";
3369
+ }
3370
+ if (obj.nestedRules) {
3371
+ for (const rule of obj.nestedRules) {
3372
+ css += rule.selector.replace("&", sel) + "{";
3373
+ for (const [k, v] of Object.entries(rule.styles || {})) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3374
+ css += "}";
3375
+ }
3376
+ }
3377
+ }
3378
+ const el = document.createElement("style");
3379
+ el.setAttribute("data-chaincss", "runtime");
3380
+ el.textContent = css;
3381
+ document.head.appendChild(el);
3382
+ return el;
3383
+ }
3384
+
3356
3385
  // src/runtime/auto-hooks.tsx
3386
+ import React, { useEffect, useRef, useState } from "react";
3357
3387
  function useSmartStyles(styleBuilder, deps = [], options = {}) {
3358
3388
  const moduleId = useRef(options.moduleId || `smart-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`);
3359
3389
  const [classMap, setClassMap] = useState({});
@@ -7001,6 +7031,7 @@ export {
7001
7031
  handleShorthand,
7002
7032
  hasAnimationPreset,
7003
7033
  helpers,
7034
+ injectChainStyles,
7004
7035
  isShorthand,
7005
7036
  macros,
7006
7037
  recipe,
@@ -22,3 +22,4 @@ export declare const chainStyles: (...args: any[]) => any;
22
22
  export { setupHMR, registerForHMR } from './hmr.js';
23
23
  export { generateStyleId, hashString, kebabCase, isBrowser, isDevelopment, isProduction, debounce, memoize, cn as cnUtils, devWarn, devLog, logError, createDebugger } from './utils.js';
24
24
  export type { RuntimeStyleDefinition, UseChainStylesOptions, RuntimeCompiledResult, StyleInjector, UseAtomicClassesReturn, HMRPayload, ChainCSSDebugger } from './types.js';
25
+ export declare function injectChainStyles(styles: Record<string, any>): HTMLStyleElement;
@@ -3907,6 +3907,36 @@ var useComputedStylesSvelte = (...args) => getSvelteExports().useComputedStyles?
3907
3907
  var provideStyleContextSvelte = (...args) => getSvelteExports().provideStyleContext?.(...args);
3908
3908
  var injectStyleContextSvelte = (...args) => getSvelteExports().injectStyleContext?.(...args);
3909
3909
  var chainStyles2 = (...args) => getSvelteExports().chainStyles?.(...args);
3910
+ function injectChainStyles(styles3) {
3911
+ let css = "";
3912
+ for (const [key, obj] of Object.entries(styles3)) {
3913
+ if (!obj || !obj.selectors) continue;
3914
+ const sel = "." + obj.selectors[0];
3915
+ css += sel + "{";
3916
+ for (const [k, v] of Object.entries(obj)) {
3917
+ if (["selectors", "hover", "atRules", "nestedRules", "_name", "_classes"].includes(k)) continue;
3918
+ css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3919
+ }
3920
+ css += "}";
3921
+ if (obj.hover) {
3922
+ css += sel + ":hover{";
3923
+ for (const [k, v] of Object.entries(obj.hover)) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3924
+ css += "}";
3925
+ }
3926
+ if (obj.nestedRules) {
3927
+ for (const rule of obj.nestedRules) {
3928
+ css += rule.selector.replace("&", sel) + "{";
3929
+ for (const [k, v] of Object.entries(rule.styles || {})) css += k.replace(/([A-Z])/g, "-$1").toLowerCase() + ":" + v + ";";
3930
+ css += "}";
3931
+ }
3932
+ }
3933
+ }
3934
+ const el = document.createElement("style");
3935
+ el.setAttribute("data-chaincss", "runtime");
3936
+ el.textContent = css;
3937
+ document.head.appendChild(el);
3938
+ return el;
3939
+ }
3910
3940
  export {
3911
3941
  $,
3912
3942
  $t,
@@ -3932,6 +3962,7 @@ export {
3932
3962
  enableChainCSSDebug,
3933
3963
  generateStyleId,
3934
3964
  hashString,
3965
+ injectChainStyles,
3935
3966
  injectStyleContext,
3936
3967
  injectStyleContextSvelte,
3937
3968
  isBrowser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chaincss",
3
- "version": "2.1.10",
3
+ "version": "2.1.12",
4
4
  "description": "ChainCSS v3.0 - The first CSS-in-JS library with true auto-detection mixed mode. Zero runtime by default, dynamic when you need it.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  // 🆕 NEW: Smart Chain API (Auto-detection mixed mode)
10
10
  // ============================================================================
11
11
  export { smartChain, smartChain as chainV3, buildChain, runtimeChain } from './core/smart-chain.js';
12
+ export { injectChainStyles } from './runtime/index.js';
12
13
  export { autoDetector, AutoDetector, type ValueType, type Mode } from './core/auto-detector.js';
13
14
 
14
15
  // ============================================================================
@@ -88,4 +88,35 @@ export type {
88
88
  UseAtomicClassesReturn,
89
89
  HMRPayload,
90
90
  ChainCSSDebugger
91
- } from './types.js';
91
+ } from './types.js';
92
+ // Auto-inject styles into DOM
93
+ export function injectChainStyles(styles: Record<string, any>) {
94
+ let css = '';
95
+ for (const [key, obj] of Object.entries(styles)) {
96
+ if (!obj || !obj.selectors) continue;
97
+ const sel = '.' + obj.selectors[0];
98
+ css += sel + '{';
99
+ for (const [k, v] of Object.entries(obj)) {
100
+ if (['selectors','hover','atRules','nestedRules','_name','_classes'].includes(k)) continue;
101
+ css += k.replace(/([A-Z])/g,'-$1').toLowerCase() + ':' + v + ';';
102
+ }
103
+ css += '}';
104
+ if (obj.hover) {
105
+ css += sel + ':hover{';
106
+ for (const [k, v] of Object.entries(obj.hover)) css += k.replace(/([A-Z])/g,'-$1').toLowerCase() + ':' + v + ';';
107
+ css += '}';
108
+ }
109
+ if (obj.nestedRules) {
110
+ for (const rule of obj.nestedRules) {
111
+ css += rule.selector.replace('&', sel) + '{';
112
+ for (const [k, v] of Object.entries(rule.styles || {})) css += k.replace(/([A-Z])/g,'-$1').toLowerCase() + ':' + v + ';';
113
+ css += '}';
114
+ }
115
+ }
116
+ }
117
+ const el = document.createElement('style');
118
+ el.setAttribute('data-chaincss', 'runtime');
119
+ el.textContent = css;
120
+ document.head.appendChild(el);
121
+ return el;
122
+ }