chaincss 2.1.10 → 2.1.11

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.
@@ -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.11",
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",
@@ -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
+ }