oncss 1.1.2 → 1.1.4

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/core.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { CSSOptionProps, CSSFactoryType, CSSProps } from './types';
2
2
  export declare const CSSFactory: Map<string, CSSFactoryType>;
3
- export declare const uid: (str: string) => string;
4
3
  export declare const formatCSSProp: (prop: string) => string;
5
4
  export declare const formatCSSValue: (prop: string, val: any) => any;
6
5
  export declare const cssPrefix: (prop: string, value: string) => {
7
6
  prop: string;
8
7
  value: string;
9
8
  };
10
- export declare const style: <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, cls?: string, opt?: CSSOptionProps<Aliases, BreakpointKeys>) => CSSFactoryType | {
9
+ export declare const style: <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, cls?: string, opt?: CSSOptionProps<Aliases, BreakpointKeys>, dept?: number) => CSSFactoryType | {
11
10
  cache: boolean;
12
11
  cachekey: string;
13
12
  classname: string;
package/core.js CHANGED
@@ -1,16 +1,7 @@
1
+ import youid from "youid";
1
2
  const _global = typeof window !== "undefined" ? window : global;
2
3
  _global.Factory = _global.Factory || /* @__PURE__ */ new Map();
3
4
  const CSSFactory = _global.Factory;
4
- const uid = (str) => {
5
- var hash = 0, len = str.length;
6
- for (var i = 0; i < len; i++) {
7
- hash = (hash << 5) - hash + str.charCodeAt(i);
8
- hash |= 0;
9
- }
10
- let id = hash.toString(32).slice(-10).replace(/-/g, "");
11
- if (/^\d/.test(id.charAt(0))) id = "c" + id;
12
- return id;
13
- };
14
5
  const number_val_props = [
15
6
  "fontWeight",
16
7
  "font-weight",
@@ -75,7 +66,7 @@ const cssPrefix = (prop, value) => {
75
66
  PREFIXCACHE.set(prop, { _prop, _vprefix });
76
67
  return { prop: _prop, value: _value };
77
68
  };
78
- const style = (_css, cls, opt) => {
69
+ const style = (_css, cls, opt, dept = 1) => {
79
70
  let cachekey;
80
71
  let classname = cls;
81
72
  if (!cls) {
@@ -85,7 +76,7 @@ const style = (_css, cls, opt) => {
85
76
  has.cache = true;
86
77
  return has;
87
78
  }
88
- classname = (opt?.classPrefix || "") + uid(cachekey);
79
+ classname = `${opt?.classPrefix || ""}x${youid(cachekey)}`;
89
80
  } else if (typeof cls !== "string") {
90
81
  throw new Error(`Invalid class name: ${cls}`);
91
82
  }
@@ -97,7 +88,7 @@ const style = (_css, cls, opt) => {
97
88
  let firstChar = prop.charAt(0);
98
89
  if (firstChar === "&") {
99
90
  let ncls = prop.replace(/&/g, classname);
100
- const r = style(val, ncls, opt);
91
+ const r = style(val, ncls, opt, ++dept);
101
92
  if (opt?.skipProps) {
102
93
  skiped = {
103
94
  ...skiped,
@@ -109,7 +100,7 @@ const style = (_css, cls, opt) => {
109
100
  if (prop.startsWith("@global") || prop.startsWith("@keyframes")) {
110
101
  let _css2 = "";
111
102
  for (let selector in val) {
112
- let r = style(val[selector], selector, opt);
103
+ let r = style(val[selector], selector, opt, ++dept);
113
104
  _css2 += r.stack;
114
105
  if (opt?.skipProps) {
115
106
  skiped = {
@@ -124,7 +115,7 @@ const style = (_css, cls, opt) => {
124
115
  stack.push(_css2);
125
116
  }
126
117
  } else {
127
- let r = style(val, classname, opt);
118
+ let r = style(val, classname, opt, ++dept);
128
119
  const atcss = prop + "{" + r.stack + "}";
129
120
  stack.push(atcss);
130
121
  if (opt?.skipProps) {
@@ -135,7 +126,7 @@ const style = (_css, cls, opt) => {
135
126
  }
136
127
  }
137
128
  } else {
138
- if (opt?.skipProps && opt.skipProps(prop, val)) {
129
+ if (opt?.skipProps && opt.skipProps(prop, val, dept)) {
139
130
  if (!(classname in skiped)) skiped[classname] = [];
140
131
  skiped[classname].push(prop);
141
132
  continue;
@@ -155,7 +146,7 @@ const style = (_css, cls, opt) => {
155
146
  }
156
147
  }
157
148
  let _css2 = { [prop]: val[media] };
158
- let r = style(_css2, classname, opt);
149
+ let r = style(_css2, classname, opt, dept);
159
150
  let _style = r.stack;
160
151
  let mediakey = `@media (min-width: ${breakpoint}px)`;
161
152
  medias[mediakey] = medias[mediakey] ? medias[mediakey] + _style : _style;
@@ -168,7 +159,7 @@ const style = (_css, cls, opt) => {
168
159
  }
169
160
  } else {
170
161
  if (opt?.getProps) {
171
- let _props = opt.getProps(prop, val, _css);
162
+ let _props = opt.getProps(prop, val, _css, dept);
172
163
  if (_props) {
173
164
  let r = style(_props, classname, {
174
165
  ...opt,
@@ -190,14 +181,14 @@ const style = (_css, cls, opt) => {
190
181
  let r = style(_props, classname, {
191
182
  ...opt,
192
183
  aliases: void 0
193
- });
184
+ }, dept);
194
185
  r.stack = r.stack.replace(`${classname}{`, "").replace(`}`, "");
195
186
  stack[0] += r.stack;
196
187
  continue;
197
188
  }
198
189
  }
199
190
  if (opt?.getValue) {
200
- val = opt.getValue(prop, val, _css);
191
+ val = opt.getValue(prop, val, _css, dept);
201
192
  }
202
193
  let p = cssPrefix(prop, val);
203
194
  stack[0] += `${p.prop}:${p.value};`;
@@ -247,7 +238,6 @@ export {
247
238
  cssPrefix,
248
239
  formatCSSProp,
249
240
  formatCSSValue,
250
- style,
251
- uid
241
+ style
252
242
  };
253
243
  //# sourceMappingURL=core.js.map
package/core.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/core.ts"],
4
- "sourcesContent": ["import { CSSOptionProps, CSSFactoryType, CSSProps } from './types';\n\nconst _global: any = typeof window !== 'undefined' ? window : global;\n_global.Factory = _global.Factory || new Map<string, CSSFactoryType>();\nexport const CSSFactory = _global.Factory as Map<string, CSSFactoryType>\n\nexport const uid = (str: string) => {\n var hash = 0, len = str.length;\n for (var i = 0; i < len; i++) {\n hash = ((hash << 5) - hash) + str.charCodeAt(i);\n hash |= 0;\n }\n let id = hash.toString(32).slice(-10).replace(/-/g, \"\");\n if (/^\\d/.test(id.charAt(0))) id = 'c' + id;\n return id;\n}\n\nconst number_val_props = [\n \"fontWeight\",\n \"font-weight\",\n \"lineHeight\",\n \"line-height\",\n \"opacity\",\n \"zIndex\",\n \"z-index\",\n \"flex\",\n \"order\",\n \"flexGrow\",\n \"flex-grow\",\n \"flexShrink\",\n \"flex-shrink\",\n \"flexBasis\",\n \"flex-basis\",\n \"columns\",\n \"perspective\",\n \"stroke-dashoffset\"\n]\n\nexport const formatCSSProp = (prop: string) => prop.split(/(?=[A-Z])/).join(\"-\").toLowerCase();\nexport const formatCSSValue = (prop: string, val: any) => typeof val === 'number' && !number_val_props.includes(prop) ? `${val}px` : val\n\nconst PREFIXES = ['webkit', 'moz', 'ms', 'o'];\nlet _declaration: CSSStyleDeclaration;\nconst PREFIXCACHE = new Map();\n\nexport const cssPrefix = (prop: string, value: string): { prop: string, value: string } => {\n value = formatCSSValue(prop, value);\n prop = formatCSSProp(prop);\n\n if (typeof window === 'undefined') {\n return { prop, value };\n }\n\n const declaration = _declaration || (_declaration = document.createElement(\"div\").style);\n value = value?.toString();\n\n // Check if the property and value work as is\n if (declaration.setProperty(prop, value), declaration.getPropertyValue(prop) === value) {\n return { prop, value };\n }\n\n // Check cached property and value prefix\n const cached = PREFIXCACHE.get(prop);\n if (cached) {\n return { prop: cached._prop, value: `${cached._vprefix}${value}` };\n }\n\n let _prop = prop;\n let _value = value;\n let _vprefix = '';\n\n // Try property prefixes\n const camelCaseProp = prop.includes('-') ? prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) : prop;\n for (const prefix of PREFIXES) {\n if (declaration[`${prefix}${camelCaseProp}` as any] !== undefined) {\n _prop = `-${prefix}-${prop}`;\n break;\n }\n }\n\n // Check if prefixed property works with the value\n declaration.setProperty(_prop, value);\n if (!declaration.getPropertyValue(_prop)) {\n for (const prefix of PREFIXES) {\n const prefixedValue = `-${prefix}-${value}`;\n if (declaration.setProperty(_prop, prefixedValue), declaration.getPropertyValue(_prop) === prefixedValue) {\n _value = prefixedValue;\n _vprefix = `-${prefix}-`;\n break;\n }\n }\n }\n\n PREFIXCACHE.set(prop, { _prop, _vprefix });\n return { prop: _prop, value: _value };\n};\n\nexport const style = <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, cls?: string, opt?: CSSOptionProps<Aliases, BreakpointKeys>) => {\n let cachekey\n let classname = cls\n if (!cls) {\n cachekey = JSON.stringify(_css)\n const has = CSSFactory.get(cachekey)\n if (has) {\n has.cache = true\n return has\n }\n classname = (opt?.classPrefix || \"\") + uid(cachekey)\n } else if (typeof cls !== 'string') {\n throw new Error(`Invalid class name: ${cls}`)\n }\n\n let stack: any = [`${classname}{`]\n let medias: any = {}\n let skiped: any = {}\n\n for (let prop in _css) {\n let val = (_css as any)[prop]\n let firstChar = prop.charAt(0)\n if (firstChar === '&') {\n let ncls = prop.replace(/&/g, classname as string)\n const r: any = style(val, ncls, opt)\n if (opt?.skipProps) {\n skiped = {\n ...skiped,\n ...r.skiped\n }\n }\n stack.push(r.stack)\n } else if (firstChar === '@') {\n if (prop.startsWith(\"@global\") || prop.startsWith(\"@keyframes\")) {\n let _css = ''\n for (let selector in val) {\n let r: any = style(val[selector], selector, opt)\n _css += r.stack\n if (opt?.skipProps) {\n skiped = {\n ...skiped,\n ...r.skiped\n }\n }\n }\n if (prop.startsWith(\"@keyframes\")) {\n stack.push(`${prop}{${_css}}`)\n } else {\n stack.push(_css)\n }\n } else {\n let r: any = style(val, classname, opt)\n const atcss = prop + \"{\" + r.stack + \"}\"\n stack.push(atcss)\n if (opt?.skipProps) {\n skiped = {\n ...skiped,\n ...r.skiped\n }\n }\n }\n } else {\n if (opt?.skipProps && opt.skipProps(prop, val)) {\n if (!((classname as any) in skiped)) skiped[classname as string] = []\n skiped[classname as string].push(prop)\n continue\n }\n if (typeof val === 'object') {\n for (let media in val) {\n if (typeof val[media] === 'object' || typeof val[media] === 'function' || Array.isArray(val[media])) {\n throw new Error(`Invalid css value: ${val[media]}`);\n }\n let breakpoint = media\n let isNumber = !isNaN(parseInt(breakpoint))\n if (!isNumber) {\n if (opt?.breakpoints && !isNaN(parseInt((opt.breakpoints as any)[media]))) {\n breakpoint = opt.breakpoints[media as BreakpointKeys].toString()\n } else {\n throw new Error(`Invalid breakpoint prop: ${media}`);\n }\n }\n let _css = { [prop]: val[media] }\n let r: any = style(_css, classname, opt)\n let _style = r.stack\n let mediakey = `@media (min-width: ${breakpoint}px)`\n medias[mediakey] = medias[mediakey] ? medias[mediakey] + _style : _style\n if (opt?.skipProps) {\n skiped = {\n ...skiped,\n ...r.skiped\n }\n }\n }\n } else {\n if (opt?.getProps) {\n let _props: any = opt.getProps(prop, val, _css)\n if (_props) {\n let r: any = style(_props, classname, {\n ...opt,\n getProps: undefined\n })\n if (opt?.skipProps) {\n skiped = {\n ...skiped,\n ...r.skiped\n }\n }\n stack.push(r.stack)\n continue;\n }\n }\n if (opt?.aliases && (opt.aliases as any)[prop]) {\n let _props = (opt.aliases as any)[prop](val)\n if (_props) {\n let r: any = style(_props, classname, {\n ...opt,\n aliases: undefined\n })\n r.stack = r.stack.replace(`${classname}{`, '').replace(`}`, '')\n stack[0] += r.stack\n continue;\n }\n }\n if (opt?.getValue) {\n val = opt.getValue(prop, val, _css)\n }\n let p = cssPrefix(prop, val)\n stack[0] += `${p.prop}:${p.value};`\n }\n }\n }\n stack[0] += \"}\"\n if (stack[0] === `${classname}{}`) {\n stack[0] = \"\"\n }\n stack = stack.join('')\n for (let media in medias) {\n stack += `${media}{${medias[media].replace(new RegExp(`}\\\\${classname}\\\\{`, 'g'), '')}}`\n }\n\n if (cachekey) {\n stack = stack.replace(new RegExp(classname as string, 'g'), `.${classname}`)\n const r = {\n cache: false,\n cachekey,\n classname: classname as string,\n css: stack,\n cssraw: _css,\n skiped,\n getStyleTag: () => document?.querySelector(`[data-oncss=\"${classname}\"]`) as HTMLStyleElement | null,\n deleteStyle: () => {\n const tag = document?.querySelector(`[data-oncss=\"${classname}\"]`)\n tag && tag.remove()\n },\n }\n r.toString = () => classname as string\n CSSFactory.set(cachekey, r)\n let inject = opt?.injectStyle || true\n if (inject && typeof window !== 'undefined') {\n if (!document.querySelector(`[data-oncss=\"${classname}\"]`)) {\n const tag = document.createElement(\"style\");\n tag.innerHTML = r.css\n tag.setAttribute(`data-oncss`, classname as string)\n document.head.append(tag)\n }\n }\n return r\n }\n return { stack, skiped }\n}"],
5
- "mappings": "AAEA,MAAM,UAAe,OAAO,WAAW,cAAc,SAAS;AAC9D,QAAQ,UAAU,QAAQ,WAAW,oBAAI,IAA4B;AAC9D,MAAM,aAAa,QAAQ;AAE3B,MAAM,MAAM,CAAC,QAAgB;AAChC,MAAI,OAAO,GAAG,MAAM,IAAI;AACxB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC1B,YAAS,QAAQ,KAAK,OAAQ,IAAI,WAAW,CAAC;AAC9C,YAAQ;AAAA,EACZ;AACA,MAAI,KAAK,KAAK,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,QAAQ,MAAM,EAAE;AACtD,MAAI,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,EAAG,MAAK,MAAM;AACzC,SAAO;AACX;AAEA,MAAM,mBAAmB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEO,MAAM,gBAAgB,CAAC,SAAiB,KAAK,MAAM,WAAW,EAAE,KAAK,GAAG,EAAE,YAAY;AACtF,MAAM,iBAAiB,CAAC,MAAc,QAAa,OAAO,QAAQ,YAAY,CAAC,iBAAiB,SAAS,IAAI,IAAI,GAAG,GAAG,OAAO;AAErI,MAAM,WAAW,CAAC,UAAU,OAAO,MAAM,GAAG;AAC5C,IAAI;AACJ,MAAM,cAAc,oBAAI,IAAI;AAErB,MAAM,YAAY,CAAC,MAAc,UAAmD;AACvF,UAAQ,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AC;AAAA,EACzF;AAEA,MAAI,UAAU;AACV,YAAQ,MAAM,QAAQ,IAAI,OAAO,WAAqB,GAAG,GAAG,IAAI,SAAS,EAAE;AAC3E,UAAM,IAAI;AAAA,MACN,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA,KAAK;AAAA,MACL,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,MAAM,UAAU,cAAc,gBAAgB,SAAS,IAAI;AAAA,MACxE,aAAa,MAAM;AACf,cAAM,MAAM,UAAU,cAAc,gBAAgB,SAAS,IAAI;AACjE,eAAO,IAAI,OAAO;AAAA,MACtB;AAAA,IACJ;AACA,MAAE,WAAW,MAAM;AACnB,eAAW,IAAI,UAAU,CAAC;AAC1B,QAAI,SAAS,KAAK,eAAe;AACjC,QAAI,UAAU,OAAO,WAAW,aAAa;AACzC,UAAI,CAAC,SAAS,cAAc,gBAAgB,SAAS,IAAI,GAAG;AACxD,cAAM,MAAM,SAAS,cAAc,OAAO;AAC1C,YAAI,YAAY,EAAE;AAClB,YAAI,aAAa,cAAc,SAAmB;AAClD,iBAAS,KAAK,OAAO,GAAG;AAAA,MAC5B;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AACA,SAAO,EAAE,OAAO,OAAO;AAC3B;",
4
+ "sourcesContent": ["import { CSSOptionProps, CSSFactoryType, CSSProps } from './types';\r\nimport youid from 'youid';\r\nconst _global: any = typeof window !== 'undefined' ? window : global;\r\n_global.Factory = _global.Factory || new Map<string, CSSFactoryType>();\r\nexport const CSSFactory = _global.Factory as Map<string, CSSFactoryType>\r\n\r\n\r\nconst number_val_props = [\r\n \"fontWeight\",\r\n \"font-weight\",\r\n \"lineHeight\",\r\n \"line-height\",\r\n \"opacity\",\r\n \"zIndex\",\r\n \"z-index\",\r\n \"flex\",\r\n \"order\",\r\n \"flexGrow\",\r\n \"flex-grow\",\r\n \"flexShrink\",\r\n \"flex-shrink\",\r\n \"flexBasis\",\r\n \"flex-basis\",\r\n \"columns\",\r\n \"perspective\",\r\n \"stroke-dashoffset\"\r\n]\r\n\r\nexport const formatCSSProp = (prop: string) => prop.split(/(?=[A-Z])/).join(\"-\").toLowerCase();\r\nexport const formatCSSValue = (prop: string, val: any) => typeof val === 'number' && !number_val_props.includes(prop) ? `${val}px` : val\r\n\r\nconst PREFIXES = ['webkit', 'moz', 'ms', 'o'];\r\nlet _declaration: CSSStyleDeclaration;\r\nconst PREFIXCACHE = new Map();\r\n\r\nexport const cssPrefix = (prop: string, value: string): { prop: string, value: string } => {\r\n value = formatCSSValue(prop, value);\r\n prop = formatCSSProp(prop);\r\n\r\n if (typeof window === 'undefined') {\r\n return { prop, value };\r\n }\r\n\r\n const declaration = _declaration || (_declaration = document.createElement(\"div\").style);\r\n value = value?.toString();\r\n\r\n // Check if the property and value work as is\r\n if (declaration.setProperty(prop, value), declaration.getPropertyValue(prop) === value) {\r\n return { prop, value };\r\n }\r\n\r\n // Check cached property and value prefix\r\n const cached = PREFIXCACHE.get(prop);\r\n if (cached) {\r\n return { prop: cached._prop, value: `${cached._vprefix}${value}` };\r\n }\r\n\r\n let _prop = prop;\r\n let _value = value;\r\n let _vprefix = '';\r\n\r\n // Try property prefixes\r\n const camelCaseProp = prop.includes('-') ? prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) : prop;\r\n for (const prefix of PREFIXES) {\r\n if (declaration[`${prefix}${camelCaseProp}` as any] !== undefined) {\r\n _prop = `-${prefix}-${prop}`;\r\n break;\r\n }\r\n }\r\n\r\n // Check if prefixed property works with the value\r\n declaration.setProperty(_prop, value);\r\n if (!declaration.getPropertyValue(_prop)) {\r\n for (const prefix of PREFIXES) {\r\n const prefixedValue = `-${prefix}-${value}`;\r\n if (declaration.setProperty(_prop, prefixedValue), declaration.getPropertyValue(_prop) === prefixedValue) {\r\n _value = prefixedValue;\r\n _vprefix = `-${prefix}-`;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n PREFIXCACHE.set(prop, { _prop, _vprefix });\r\n return { prop: _prop, value: _value };\r\n};\r\n\r\nexport const style = <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, cls?: string, opt?: CSSOptionProps<Aliases, BreakpointKeys>, dept = 1) => {\r\n let cachekey\r\n let classname = cls\r\n if (!cls) {\r\n cachekey = JSON.stringify(_css)\r\n const has = CSSFactory.get(cachekey)\r\n if (has) {\r\n has.cache = true\r\n return has\r\n }\r\n classname = `${opt?.classPrefix || \"\"}x${youid(cachekey)}`\r\n } else if (typeof cls !== 'string') {\r\n throw new Error(`Invalid class name: ${cls}`)\r\n }\r\n\r\n let stack: any = [`${classname}{`]\r\n let medias: any = {}\r\n let skiped: any = {}\r\n for (let prop in _css) {\r\n let val = (_css as any)[prop]\r\n let firstChar = prop.charAt(0)\r\n if (firstChar === '&') {\r\n let ncls = prop.replace(/&/g, classname as string)\r\n const r: any = style(val, ncls, opt, ++dept)\r\n if (opt?.skipProps) {\r\n skiped = {\r\n ...skiped,\r\n ...r.skiped\r\n }\r\n }\r\n stack.push(r.stack)\r\n } else if (firstChar === '@') {\r\n if (prop.startsWith(\"@global\") || prop.startsWith(\"@keyframes\")) {\r\n let _css = ''\r\n for (let selector in val) {\r\n let r: any = style(val[selector], selector, opt, ++dept)\r\n _css += r.stack\r\n if (opt?.skipProps) {\r\n skiped = {\r\n ...skiped,\r\n ...r.skiped\r\n }\r\n }\r\n }\r\n if (prop.startsWith(\"@keyframes\")) {\r\n stack.push(`${prop}{${_css}}`)\r\n } else {\r\n stack.push(_css)\r\n }\r\n } else {\r\n let r: any = style(val, classname, opt, ++dept)\r\n const atcss = prop + \"{\" + r.stack + \"}\"\r\n stack.push(atcss)\r\n if (opt?.skipProps) {\r\n skiped = {\r\n ...skiped,\r\n ...r.skiped\r\n }\r\n }\r\n }\r\n } else {\r\n if (opt?.skipProps && opt.skipProps(prop, val, dept)) {\r\n if (!((classname as any) in skiped)) skiped[classname as string] = []\r\n skiped[classname as string].push(prop)\r\n continue\r\n }\r\n if (typeof val === 'object') {\r\n for (let media in val) {\r\n if (typeof val[media] === 'object' || typeof val[media] === 'function' || Array.isArray(val[media])) {\r\n throw new Error(`Invalid css value: ${val[media]}`);\r\n }\r\n let breakpoint = media\r\n let isNumber = !isNaN(parseInt(breakpoint))\r\n if (!isNumber) {\r\n if (opt?.breakpoints && !isNaN(parseInt((opt.breakpoints as any)[media]))) {\r\n breakpoint = opt.breakpoints[media as BreakpointKeys].toString()\r\n } else {\r\n throw new Error(`Invalid breakpoint prop: ${media}`);\r\n }\r\n }\r\n let _css = { [prop]: val[media] }\r\n let r: any = style(_css, classname, opt, dept)\r\n let _style = r.stack\r\n let mediakey = `@media (min-width: ${breakpoint}px)`\r\n medias[mediakey] = medias[mediakey] ? medias[mediakey] + _style : _style\r\n if (opt?.skipProps) {\r\n skiped = {\r\n ...skiped,\r\n ...r.skiped\r\n }\r\n }\r\n }\r\n } else {\r\n if (opt?.getProps) {\r\n let _props: any = opt.getProps(prop, val, _css, dept)\r\n if (_props) {\r\n let r: any = style(_props, classname, {\r\n ...opt,\r\n getProps: undefined\r\n })\r\n if (opt?.skipProps) {\r\n skiped = {\r\n ...skiped,\r\n ...r.skiped\r\n }\r\n }\r\n stack.push(r.stack)\r\n continue;\r\n }\r\n }\r\n if (opt?.aliases && (opt.aliases as any)[prop]) {\r\n let _props = (opt.aliases as any)[prop](val)\r\n if (_props) {\r\n let r: any = style(_props, classname, {\r\n ...opt,\r\n aliases: undefined\r\n }, dept)\r\n r.stack = r.stack.replace(`${classname}{`, '').replace(`}`, '')\r\n stack[0] += r.stack\r\n continue;\r\n }\r\n }\r\n if (opt?.getValue) {\r\n val = opt.getValue(prop, val, _css, dept)\r\n }\r\n let p = cssPrefix(prop, val)\r\n stack[0] += `${p.prop}:${p.value};`\r\n }\r\n }\r\n }\r\n stack[0] += \"}\"\r\n if (stack[0] === `${classname}{}`) {\r\n stack[0] = \"\"\r\n }\r\n stack = stack.join('')\r\n for (let media in medias) {\r\n stack += `${media}{${medias[media].replace(new RegExp(`}\\\\${classname}\\\\{`, 'g'), '')}}`\r\n }\r\n\r\n if (cachekey) {\r\n stack = stack.replace(new RegExp(classname as string, 'g'), `.${classname}`)\r\n const r = {\r\n cache: false,\r\n cachekey,\r\n classname: classname as string,\r\n css: stack,\r\n cssraw: _css,\r\n skiped,\r\n getStyleTag: () => document?.querySelector(`[data-oncss=\"${classname}\"]`) as HTMLStyleElement | null,\r\n deleteStyle: () => {\r\n const tag = document?.querySelector(`[data-oncss=\"${classname}\"]`)\r\n tag && tag.remove()\r\n },\r\n }\r\n r.toString = () => classname as string\r\n CSSFactory.set(cachekey, r)\r\n let inject = opt?.injectStyle || true\r\n if (inject && typeof window !== 'undefined') {\r\n if (!document.querySelector(`[data-oncss=\"${classname}\"]`)) {\r\n const tag = document.createElement(\"style\");\r\n tag.innerHTML = r.css\r\n tag.setAttribute(`data-oncss`, classname as string)\r\n document.head.append(tag)\r\n }\r\n }\r\n return r\r\n }\r\n return { stack, skiped }\r\n}"],
5
+ "mappings": "AACA,OAAO,WAAW;AAClB,MAAM,UAAe,OAAO,WAAW,cAAc,SAAS;AAC9D,QAAQ,UAAU,QAAQ,WAAW,oBAAI,IAA4B;AAC9D,MAAM,aAAa,QAAQ;AAGlC,MAAM,mBAAmB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEO,MAAM,gBAAgB,CAAC,SAAiB,KAAK,MAAM,WAAW,EAAE,KAAK,GAAG,EAAE,YAAY;AACtF,MAAM,iBAAiB,CAAC,MAAc,QAAa,OAAO,QAAQ,YAAY,CAAC,iBAAiB,SAAS,IAAI,IAAI,GAAG,GAAG,OAAO;AAErI,MAAM,WAAW,CAAC,UAAU,OAAO,MAAM,GAAG;AAC5C,IAAI;AACJ,MAAM,cA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EACf;AACA,UAAQ,MAAM,KAAK,EAAE;AACrB,WAAS,SAAS,QAAQ;AACtB,aAAS,GAAG,KAAK,IAAI,OAAO,KAAK,EAAE,QAAQ,IAAI,OAAO,MAAM,SAAS,OAAO,GAAG,GAAG,EAAE,CAAC;AAAA,EACzF;AAEA,MAAI,UAAU;AACV,YAAQ,MAAM,QAAQ,IAAI,OAAO,WAAqB,GAAG,GAAG,IAAI,SAAS,EAAE;AAC3E,UAAM,IAAI;AAAA,MACN,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA,KAAK;AAAA,MACL,QAAQ;AAAA,MACR;AAAA,MACA,aAAa,MAAM,UAAU,cAAc,gBAAgB,SAAS,IAAI;AAAA,MACxE,aAAa,MAAM;AACf,cAAM,MAAM,UAAU,cAAc,gBAAgB,SAAS,IAAI;AACjE,eAAO,IAAI,OAAO;AAAA,MACtB;AAAA,IACJ;AACA,MAAE,WAAW,MAAM;AACnB,eAAW,IAAI,UAAU,CAAC;AAC1B,QAAI,SAAS,KAAK,eAAe;AACjC,QAAI,UAAU,OAAO,WAAW,aAAa;AACzC,UAAI,CAAC,SAAS,cAAc,gBAAgB,SAAS,IAAI,GAAG;AACxD,cAAM,MAAM,SAAS,cAAc,OAAO;AAC1C,YAAI,YAAY,EAAE;AAClB,YAAI,aAAa,cAAc,SAAmB;AAClD,iBAAS,KAAK,OAAO,GAAG;AAAA,MAC5B;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AACA,SAAO,EAAE,OAAO,OAAO;AAC3B;",
6
6
  "names": ["_css"]
7
7
  }
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import { style } from \"./core\";\nimport { CSSProps, CSSOptionProps, CSSFactoryType } from \"./types\";\nexport { CSSFactory, formatCSSProp, formatCSSValue } from './core'\nexport * from './types'\n\nexport const css = <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, options?: CSSOptionProps<Aliases, BreakpointKeys>): CSSFactoryType => style<Aliases, BreakpointKeys>(_css, undefined, options) as any\nexport default css"],
4
+ "sourcesContent": ["import { style } from \"./core\";\r\nimport { CSSProps, CSSOptionProps, CSSFactoryType } from \"./types\";\r\nexport { CSSFactory, formatCSSProp, formatCSSValue } from './core'\r\nexport * from './types'\r\n\r\nexport const css = <Aliases, BreakpointKeys extends string>(_css: CSSProps<Aliases, BreakpointKeys>, options?: CSSOptionProps<Aliases, BreakpointKeys>): CSSFactoryType => style<Aliases, BreakpointKeys>(_css, undefined, options) as any\r\nexport default css"],
5
5
  "mappings": "AAAA,SAAS,aAAa;AAEtB,SAAS,YAAY,eAAe,sBAAsB;AAC1D,cAAc;AAEP,MAAM,MAAM,CAAyC,MAAyC,YAAsE,MAA+B,MAAM,QAAW,OAAO;AAClO,IAAO,gBAAQ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,35 +1,38 @@
1
- {
2
- "name": "oncss",
3
- "version": "1.1.2",
4
- "description": "A CSS framework for modern web development.",
5
- "main": "./index.js",
6
- "scripts": {
7
- "start": "makepack serve -p 4000",
8
- "pack": "makepack pack",
9
- "publish:pack": "makepack pack -p"
10
- },
11
- "devDependencies": {
12
- "@types/react": "^19.0.2",
13
- "@types/react-dom": "^19.0.2",
14
- "makepack": "^1.3.4",
15
- "react": "^19.0.0",
16
- "react-dom": "^19.0.0",
17
- "typescript": "^4.4.2"
18
- },
19
- "keywords": [
20
- "css",
21
- "oncss",
22
- "styles",
23
- "web development",
24
- "frontend"
25
- ],
26
- "author": "Your Name",
27
- "license": "MIT",
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/yourusername/oncss.git"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/yourusername/oncss/issues"
34
- }
1
+ {
2
+ "name": "oncss",
3
+ "version": "1.1.4",
4
+ "description": "A CSS framework for modern web development.",
5
+ "main": "./index.js",
6
+ "scripts": {
7
+ "start": "makepack serve -p 4000",
8
+ "pack": "makepack pack",
9
+ "publish:pack": "makepack pack -p"
10
+ },
11
+ "devDependencies": {
12
+ "@types/react": "^19.0.2",
13
+ "@types/react-dom": "^19.0.2",
14
+ "makepack": "^1.3.4",
15
+ "react": "^19.0.0",
16
+ "react-dom": "^19.0.0",
17
+ "typescript": "^4.4.2"
18
+ },
19
+ "keywords": [
20
+ "css",
21
+ "oncss",
22
+ "styles",
23
+ "web development",
24
+ "frontend"
25
+ ],
26
+ "author": "Your Name",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/yourusername/oncss.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/yourusername/oncss/issues"
34
+ },
35
+ "dependencies": {
36
+ "youid": "^1.0.2"
37
+ }
35
38
  }
package/readme.md CHANGED
@@ -1,397 +1,397 @@
1
- <p align="center">
2
- <img width="120" src="https://raw.githubusercontent.com/devnax/oncss/main/logo.png" alt="ONCSS Logo">
3
- </p>
4
-
5
- <h1 align="center">ONCSS</h1>
6
-
7
- `oncss` is a CSS-in-JS library that provides developers with a powerful `css` function to style their web applications. It enables modern styling techniques, including nested selectors, responsive design, and dynamic keyframes, all while offering seamless integration with JavaScript frameworks like React.
8
-
9
- ---
10
-
11
- ## Installation
12
-
13
- Install the `oncss` package via npm:
14
-
15
- ```bash
16
- npm install oncss
17
- ```
18
-
19
- Import the `css` function in your project:
20
-
21
- ```javascript
22
- import css from 'oncss';
23
- ```
24
-
25
- ---
26
-
27
- ## Core Concept: The `css` Function
28
-
29
- The `css` function is the heart of `oncss`, designed to dynamically generate and inject CSS into your application. It supports:
30
-
31
- - **CSS Properties**: Use standard CSS properties and values.
32
- - **Nested Selectors**: Apply styles to child elements or states using `&`.
33
- - **Media Queries**: Implement responsive designs with `@media` rules.
34
- - **Keyframes**: Create animations with `@keyframes`.
35
- - **Global Styles**: Apply styles globally with `@global`.
36
- - **Custom Breakpoints**: Define reusable breakpoints for responsiveness.
37
- - **Other At-Rules**: Utilize additional at-rules like `@container`, `@layer`, and `@supports`.
38
-
39
- ### Basic Example
40
-
41
- ```typescript
42
- const buttonStyles = css({
43
- backgroundColor: 'blue',
44
- color: 'white',
45
- padding: '10px 20px',
46
- borderRadius: '5px',
47
- '&:hover': {
48
- backgroundColor: 'darkblue',
49
- },
50
- '@media (min-width: 768px)': {
51
- padding: '15px 30px',
52
- },
53
- });
54
-
55
- console.log(buttonStyles);
56
- ```
57
-
58
- ---
59
-
60
- ## Configuration Options
61
-
62
- The `css` function can be customized through an options object:
63
-
64
- ### Available Properties
65
-
66
- | Property | Type | Description |
67
- | ------------- | ---------- | ------------------------------------------ |
68
- | `classPrefix` | `string` | Adds a prefix to generated class names. |
69
- | `breakpoints` | `object` | Custom breakpoints for responsive designs. |
70
- | `aliases` | `object` | Custom shorthand properties for CSS rules. |
71
- | `injectStyle` | `boolean` | Controls whether styles are auto-injected. |
72
- | `skipProps` | `function` | Filters out unwanted properties. |
73
- | `getValue` | `function` | Transforms property values dynamically. |
74
- | `getProps` | `function` | Customizes specific property handling. |
75
-
76
- ### Example with Options
77
-
78
- ```typescript
79
- const styles = css({
80
- fontSize: 16,
81
- padding: 10,
82
- }, {
83
- classPrefix: 'myprefix',
84
- breakpoints: {
85
- sm: 480,
86
- md: 768,
87
- lg: 1024,
88
- },
89
- });
90
- ```
91
-
92
- ### Using Breakpoints
93
-
94
- You can use the defined breakpoints in your styles to create responsive designs:
95
-
96
- ```typescript
97
- const responsiveStyles = css({
98
- fontSize: 14,
99
- padding: {
100
- sm: 12,
101
- lg: 24
102
- },
103
-
104
- }, {
105
- breakpoints: {
106
- sm: 480,
107
- md: 768,
108
- lg: 1024,
109
- },
110
- });
111
- ```
112
-
113
- ---
114
-
115
- ## React Integration
116
-
117
- oncss integrates seamlessly with React. Simply pass the generated class name to your component.
118
-
119
- ### React Example
120
-
121
- ```typescript
122
- import React from 'react';
123
- import css from 'oncss';
124
-
125
- const buttonStyle = css({
126
- backgroundColor: 'green',
127
- color: 'white',
128
- padding: '10px 20px',
129
- borderRadius: '8px',
130
- '&:hover': {
131
- backgroundColor: 'darkgreen',
132
- },
133
- });
134
-
135
- function Button() {
136
- return <button className={buttonStyle.toString()}>Click Me</button>;
137
- }
138
-
139
- export default Button;
140
- ```
141
-
142
- ---
143
-
144
- ## Advanced Features
145
-
146
- ### Nested Selectors
147
-
148
- Apply styles to child elements or pseudo-classes:
149
-
150
- ```typescript
151
- const cardStyles = css({
152
- padding: '20px',
153
- border: '1px solid #ccc',
154
- '& h1': {
155
- fontSize: '24px',
156
- margin: 0,
157
- },
158
- '&:hover': {
159
- boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
160
- },
161
- });
162
- ```
163
-
164
- ### Media Queries
165
-
166
- Easily add responsive styles:
167
-
168
- ```typescript
169
- const responsiveStyles = css({
170
- fontSize: '14px',
171
- '@media (min-width: 768px)': {
172
- fontSize: '18px',
173
- },
174
- });
175
- ```
176
-
177
- ### Keyframes
178
-
179
- Define and use animations:
180
-
181
- ```typescript
182
- const animationStyles = css({
183
- '@keyframes fadeIn': {
184
- from: { opacity: 0 },
185
- to: { opacity: 1 },
186
- },
187
- animation: 'fadeIn 2s ease-in-out',
188
- });
189
- ```
190
-
191
- ### Global Styles
192
-
193
- Apply global styles effortlessly:
194
-
195
- ```typescript
196
- const globalStyles = css({
197
- '@global': {
198
- body: {
199
- margin: 0,
200
- fontFamily: 'Arial, sans-serif',
201
- },
202
- a: {
203
- color: 'blue',
204
- textDecoration: 'none',
205
- },
206
- },
207
- });
208
- ```
209
-
210
- ---
211
-
212
- ## Supported At-Rules
213
-
214
- `oncss` supports various CSS at-rules to enhance your styling capabilities. Here is a list of supported at-rules with descriptions:
215
-
216
- | At-Rule | Description |
217
- | ------------ | ---------------------------------------------------------------------------- |
218
- | `@media` | Used for applying styles based on media queries for responsive design. |
219
- | `@keyframes` | Defines animations that can be applied to elements. |
220
- | `@global` | Applies styles globally across the entire application. |
221
- | `@container` | Used for container queries to apply styles based on container size. |
222
- | `@layer` | Defines style layers to control the order of style application. |
223
- | `@supports` | Applies styles based on the support of specific CSS features in the browser. |
224
-
225
- ---
226
-
227
- ## Server-Side Styling
228
-
229
- `oncss` supports server-side rendering (SSR) by utilizing the `CSSFactory` to store and manage generated CSS styles. This allows you to extract and inject styles into your server-rendered HTML.
230
-
231
- ### Example with React
232
-
233
- Here's an example of how to use `oncss` for server-side rendering with React:
234
-
235
- ```tsx
236
- import React from 'react';
237
- import ReactDOMServer from 'react-dom/server';
238
- import css, { CSSFactory } from 'oncss';
239
-
240
- const buttonStyle = css({
241
- backgroundColor: 'blue',
242
- color: 'white',
243
- padding: '10px 20px',
244
- borderRadius: '5px',
245
- '&:hover': {
246
- backgroundColor: 'darkblue',
247
- },
248
- });
249
-
250
- function Button() {
251
- return <button className={buttonStyle}>Click Me</button>;
252
- }
253
-
254
- const App = () => (
255
- <div>
256
- <Button />
257
- </div>
258
- );
259
-
260
- // Render the component to a string
261
- const html = ReactDOMServer.renderToString(<App />);
262
-
263
- let styles: any = Array.from(CSSFactory.values()).map((style) => {
264
- return `<style data-oncss="${style.classname}">${style.css}</style>`
265
- });
266
-
267
- // Inject the styles into the HTML
268
- const fullHtml = `
269
- <!DOCTYPE html>
270
- <html lang="en">
271
- <head>
272
- <meta charset="UTF-8">
273
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
274
- <title>SSR with oncss</title>
275
- ${styles}
276
- </head>
277
- <body>
278
- <div id="root">${html}</div>
279
- </body>
280
- </html>
281
- `;
282
-
283
- console.log(fullHtml);
284
- ```
285
-
286
- In this example, the `CSSFactory` is used to collect all generated CSS styles during the server-side rendering process. These styles are then injected into the HTML document, ensuring that the styles are applied correctly when the page is loaded in the browser.
287
-
288
- ---
289
-
290
- ## Utility Functions
291
-
292
- ### CSSFactory
293
-
294
- `CSSFactory` is a global cache for storing generated CSS styles. It helps in reusing styles and avoiding redundant style generation.
295
-
296
- ### formatCSSProp
297
-
298
- `formatCSSProp` is a utility function that converts camelCase CSS property names to kebab-case.
299
-
300
- ```typescript
301
- import { formatCSSProp } from 'oncss';
302
-
303
- const formattedProp = formatCSSProp('backgroundColor');
304
- console.log(formattedProp); // 'background-color'
305
- ```
306
-
307
- ### formatCSSValue
308
-
309
- `formatCSSValue` is a utility function that formats CSS values, adding units like `px` where necessary.
310
-
311
- ```typescript
312
- import { formatCSSValue } from 'oncss';
313
-
314
- const formattedValue = formatCSSValue('width', 100);
315
- console.log(formattedValue); // '100px'
316
- ```
317
-
318
- ---
319
-
320
- ## TypeScript Integration
321
-
322
- `oncss` provides full TypeScript support, allowing you to define types for your CSS properties and options.
323
-
324
- ### Defining CSS Properties
325
-
326
- You can define the types for your CSS properties using the `CSSProps` type:
327
-
328
- ```typescript
329
- import { CSSProps } from 'oncss';
330
-
331
- interface MyAliases {
332
- customColor?: string;
333
- }
334
-
335
- const styles: CSSProps<MyAliases, 'sm' | 'md' | 'lg'> = {
336
- backgroundColor: 'blue',
337
- customColor: 'red',
338
- '@media (min-width: 768px)': {
339
- backgroundColor: 'green',
340
- },
341
- };
342
- ```
343
-
344
- ### Using Options with Types
345
-
346
- You can also define types for the options object:
347
-
348
- ```typescript
349
- import { CSSOptionProps } from 'oncss';
350
-
351
- const options: CSSOptionProps<MyAliases, 'sm' | 'md' | 'lg'> = {
352
- classPrefix: 'myprefix',
353
- breakpoints: {
354
- sm: 480,
355
- md: 768,
356
- lg: 1024,
357
- },
358
- aliases: {
359
- customColor: (value) => ({ color: value }),
360
- },
361
- };
362
-
363
- const styles = css({
364
- fontSize: 16,
365
- padding: 10,
366
- }, options);
367
- ```
368
-
369
- ---
370
-
371
- ## Conclusion
372
-
373
- `oncss` simplifies styling for modern web applications. Its robust feature set, from responsive design to keyframe animations, makes it an invaluable tool for developers.
374
-
375
- ## Author
376
-
377
- <table>
378
- <tr>
379
- <td>
380
- <img src="https://raw.githubusercontent.com/devnax/devnax/main/me-circle-200.png" alt="devnax" width="100" height="100">
381
- </td>
382
- <td>
383
- <strong>Naxrul Ahmed</strong><br>
384
- <a href="https://github.com/devnax">GitHub Profile</a><br>
385
- <a href="https://www.npmjs.com/~devnax">npm Profile</a><br>
386
- <a href="https://github.com/devnax/open-source">Open Source Projects</a>
387
- </td>
388
- </tr>
389
- </table>
390
-
391
- <h2>⚡️ Where to find me</h2>
392
-
393
- <p><a target="_blank" href="mailto:devnaxrul@gmail.com" style="display: inline-block;"><img src="https://img.shields.io/badge/-Email-05122A?style=for-the-badge&logo=gmail&logoColor=white&color=orange" alt="gmail" /></a>
394
- <a target="_blank" href="https://twitter.com/devnaxx" style="display: inline-block;"><img src="https://img.shields.io/badge/twitter-x?style=for-the-badge&logo=x&logoColor=white&color=%230f1419" alt="twitter" /></a>
395
- <a target="_blank" href="https://www.linkedin.com/in/devnax" style="display: inline-block;"><img src="https://img.shields.io/badge/linkedin-logo?style=for-the-badge&logo=linkedin&logoColor=white&color=%230a77b6" alt="linkedin" /></a>
396
- <a target="_blank" href="https://www.facebook.com/devnax" style="display: inline-block;"><img src="https://img.shields.io/badge/facebook-logo?style=for-the-badge&logo=facebook&logoColor=white&color=%230866ff" alt="facebook" /></a>
397
- <a target="_blank" href="https://www.instagram.com/devnaxx" style="display: inline-block;"><img src="https://img.shields.io/badge/instagram-logo?style=for-the-badge&logo=instagram&logoColor=white&color=%23F35369" alt="instagram" /></a></p>
1
+ <p align="center">
2
+ <img width="120" src="https://raw.githubusercontent.com/devnax/oncss/main/logo.png" alt="ONCSS Logo">
3
+ </p>
4
+
5
+ <h1 align="center">ONCSS</h1>
6
+
7
+ `oncss` is a CSS-in-JS library that provides developers with a powerful `css` function to style their web applications. It enables modern styling techniques, including nested selectors, responsive design, and dynamic keyframes, all while offering seamless integration with JavaScript frameworks like React.
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ Install the `oncss` package via npm:
14
+
15
+ ```bash
16
+ npm install oncss
17
+ ```
18
+
19
+ Import the `css` function in your project:
20
+
21
+ ```javascript
22
+ import css from 'oncss';
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Core Concept: The `css` Function
28
+
29
+ The `css` function is the heart of `oncss`, designed to dynamically generate and inject CSS into your application. It supports:
30
+
31
+ - **CSS Properties**: Use standard CSS properties and values.
32
+ - **Nested Selectors**: Apply styles to child elements or states using `&`.
33
+ - **Media Queries**: Implement responsive designs with `@media` rules.
34
+ - **Keyframes**: Create animations with `@keyframes`.
35
+ - **Global Styles**: Apply styles globally with `@global`.
36
+ - **Custom Breakpoints**: Define reusable breakpoints for responsiveness.
37
+ - **Other At-Rules**: Utilize additional at-rules like `@container`, `@layer`, and `@supports`.
38
+
39
+ ### Basic Example
40
+
41
+ ```typescript
42
+ const buttonStyles = css({
43
+ backgroundColor: 'blue',
44
+ color: 'white',
45
+ padding: '10px 20px',
46
+ borderRadius: '5px',
47
+ '&:hover': {
48
+ backgroundColor: 'darkblue',
49
+ },
50
+ '@media (min-width: 768px)': {
51
+ padding: '15px 30px',
52
+ },
53
+ });
54
+
55
+ console.log(buttonStyles);
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Configuration Options
61
+
62
+ The `css` function can be customized through an options object:
63
+
64
+ ### Available Properties
65
+
66
+ | Property | Type | Description |
67
+ | ------------- | ---------- | ------------------------------------------------------------------------------------------------- |
68
+ | `classPrefix` | `string` | Adds a prefix to generated class names. |
69
+ | `breakpoints` | `object` | Custom breakpoints for responsive designs. |
70
+ | `aliases` | `object` | Custom shorthand properties for CSS rules. |
71
+ | `injectStyle` | `boolean` | Controls whether styles are auto-injected. |
72
+ | `skipProps` | `function` | Filters out unwanted properties. Receives `prop`, `value`, and `dept` as arguments. |
73
+ | `getValue` | `function` | Transforms property values dynamically. Receives `value`, `prop`, `css`, and `dept` as arguments. |
74
+ | `getProps` | `function` | Customizes specific property handling. Receives `prop`, `value`, `css`, and `dept` as arguments. |
75
+
76
+ ### Example with Options
77
+
78
+ ```typescript
79
+ const styles = css({
80
+ fontSize: 16,
81
+ padding: 10,
82
+ }, {
83
+ classPrefix: 'myprefix',
84
+ breakpoints: {
85
+ sm: 480,
86
+ md: 768,
87
+ lg: 1024,
88
+ },
89
+ });
90
+ ```
91
+
92
+ ### Using Breakpoints
93
+
94
+ You can use the defined breakpoints in your styles to create responsive designs:
95
+
96
+ ```typescript
97
+ const responsiveStyles = css({
98
+ fontSize: 14,
99
+ padding: {
100
+ sm: 12,
101
+ lg: 24
102
+ },
103
+
104
+ }, {
105
+ breakpoints: {
106
+ sm: 480,
107
+ md: 768,
108
+ lg: 1024,
109
+ },
110
+ });
111
+ ```
112
+
113
+ ---
114
+
115
+ ## React Integration
116
+
117
+ oncss integrates seamlessly with React. Simply pass the generated class name to your component.
118
+
119
+ ### React Example
120
+
121
+ ```typescript
122
+ import React from 'react';
123
+ import css from 'oncss';
124
+
125
+ const buttonStyle = css({
126
+ backgroundColor: 'green',
127
+ color: 'white',
128
+ padding: '10px 20px',
129
+ borderRadius: '8px',
130
+ '&:hover': {
131
+ backgroundColor: 'darkgreen',
132
+ },
133
+ });
134
+
135
+ function Button() {
136
+ return <button className={buttonStyle.toString()}>Click Me</button>;
137
+ }
138
+
139
+ export default Button;
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Advanced Features
145
+
146
+ ### Nested Selectors
147
+
148
+ Apply styles to child elements or pseudo-classes:
149
+
150
+ ```typescript
151
+ const cardStyles = css({
152
+ padding: '20px',
153
+ border: '1px solid #ccc',
154
+ '& h1': {
155
+ fontSize: '24px',
156
+ margin: 0,
157
+ },
158
+ '&:hover': {
159
+ boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
160
+ },
161
+ });
162
+ ```
163
+
164
+ ### Media Queries
165
+
166
+ Easily add responsive styles:
167
+
168
+ ```typescript
169
+ const responsiveStyles = css({
170
+ fontSize: '14px',
171
+ '@media (min-width: 768px)': {
172
+ fontSize: '18px',
173
+ },
174
+ });
175
+ ```
176
+
177
+ ### Keyframes
178
+
179
+ Define and use animations:
180
+
181
+ ```typescript
182
+ const animationStyles = css({
183
+ '@keyframes fadeIn': {
184
+ from: { opacity: 0 },
185
+ to: { opacity: 1 },
186
+ },
187
+ animation: 'fadeIn 2s ease-in-out',
188
+ });
189
+ ```
190
+
191
+ ### Global Styles
192
+
193
+ Apply global styles effortlessly:
194
+
195
+ ```typescript
196
+ const globalStyles = css({
197
+ '@global': {
198
+ body: {
199
+ margin: 0,
200
+ fontFamily: 'Arial, sans-serif',
201
+ },
202
+ a: {
203
+ color: 'blue',
204
+ textDecoration: 'none',
205
+ },
206
+ },
207
+ });
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Supported At-Rules
213
+
214
+ `oncss` supports various CSS at-rules to enhance your styling capabilities. Here is a list of supported at-rules with descriptions:
215
+
216
+ | At-Rule | Description |
217
+ | ------------ | ---------------------------------------------------------------------------- |
218
+ | `@media` | Used for applying styles based on media queries for responsive design. |
219
+ | `@keyframes` | Defines animations that can be applied to elements. |
220
+ | `@global` | Applies styles globally across the entire application. |
221
+ | `@container` | Used for container queries to apply styles based on container size. |
222
+ | `@layer` | Defines style layers to control the order of style application. |
223
+ | `@supports` | Applies styles based on the support of specific CSS features in the browser. |
224
+
225
+ ---
226
+
227
+ ## Server-Side Styling
228
+
229
+ `oncss` supports server-side rendering (SSR) by utilizing the `CSSFactory` to store and manage generated CSS styles. This allows you to extract and inject styles into your server-rendered HTML.
230
+
231
+ ### Example with React
232
+
233
+ Here's an example of how to use `oncss` for server-side rendering with React:
234
+
235
+ ```tsx
236
+ import React from 'react';
237
+ import ReactDOMServer from 'react-dom/server';
238
+ import css, { CSSFactory } from 'oncss';
239
+
240
+ const buttonStyle = css({
241
+ backgroundColor: 'blue',
242
+ color: 'white',
243
+ padding: '10px 20px',
244
+ borderRadius: '5px',
245
+ '&:hover': {
246
+ backgroundColor: 'darkblue',
247
+ },
248
+ });
249
+
250
+ function Button() {
251
+ return <button className={buttonStyle}>Click Me</button>;
252
+ }
253
+
254
+ const App = () => (
255
+ <div>
256
+ <Button />
257
+ </div>
258
+ );
259
+
260
+ // Render the component to a string
261
+ const html = ReactDOMServer.renderToString(<App />);
262
+
263
+ let styles: any = Array.from(CSSFactory.values()).map((style) => {
264
+ return `<style data-oncss="${style.classname}">${style.css}</style>`
265
+ });
266
+
267
+ // Inject the styles into the HTML
268
+ const fullHtml = `
269
+ <!DOCTYPE html>
270
+ <html lang="en">
271
+ <head>
272
+ <meta charset="UTF-8">
273
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
274
+ <title>SSR with oncss</title>
275
+ ${styles}
276
+ </head>
277
+ <body>
278
+ <div id="root">${html}</div>
279
+ </body>
280
+ </html>
281
+ `;
282
+
283
+ console.log(fullHtml);
284
+ ```
285
+
286
+ In this example, the `CSSFactory` is used to collect all generated CSS styles during the server-side rendering process. These styles are then injected into the HTML document, ensuring that the styles are applied correctly when the page is loaded in the browser.
287
+
288
+ ---
289
+
290
+ ## Utility Functions
291
+
292
+ ### CSSFactory
293
+
294
+ `CSSFactory` is a global cache for storing generated CSS styles. It helps in reusing styles and avoiding redundant style generation.
295
+
296
+ ### formatCSSProp
297
+
298
+ `formatCSSProp` is a utility function that converts camelCase CSS property names to kebab-case.
299
+
300
+ ```typescript
301
+ import { formatCSSProp } from 'oncss';
302
+
303
+ const formattedProp = formatCSSProp('backgroundColor');
304
+ console.log(formattedProp); // 'background-color'
305
+ ```
306
+
307
+ ### formatCSSValue
308
+
309
+ `formatCSSValue` is a utility function that formats CSS values, adding units like `px` where necessary.
310
+
311
+ ```typescript
312
+ import { formatCSSValue } from 'oncss';
313
+
314
+ const formattedValue = formatCSSValue('width', 100);
315
+ console.log(formattedValue); // '100px'
316
+ ```
317
+
318
+ ---
319
+
320
+ ## TypeScript Integration
321
+
322
+ `oncss` provides full TypeScript support, allowing you to define types for your CSS properties and options.
323
+
324
+ ### Defining CSS Properties
325
+
326
+ You can define the types for your CSS properties using the `CSSProps` type:
327
+
328
+ ```typescript
329
+ import { CSSProps } from 'oncss';
330
+
331
+ interface MyAliases {
332
+ customColor?: string;
333
+ }
334
+
335
+ const styles: CSSProps<MyAliases, 'sm' | 'md' | 'lg'> = {
336
+ backgroundColor: 'blue',
337
+ customColor: 'red',
338
+ '@media (min-width: 768px)': {
339
+ backgroundColor: 'green',
340
+ },
341
+ };
342
+ ```
343
+
344
+ ### Using Options with Types
345
+
346
+ You can also define types for the options object:
347
+
348
+ ```typescript
349
+ import { CSSOptionProps } from 'oncss';
350
+
351
+ const options: CSSOptionProps<MyAliases, 'sm' | 'md' | 'lg'> = {
352
+ classPrefix: 'myprefix',
353
+ breakpoints: {
354
+ sm: 480,
355
+ md: 768,
356
+ lg: 1024,
357
+ },
358
+ aliases: {
359
+ customColor: (value) => ({ color: value }),
360
+ },
361
+ };
362
+
363
+ const styles = css({
364
+ fontSize: 16,
365
+ padding: 10,
366
+ }, options);
367
+ ```
368
+
369
+ ---
370
+
371
+ ## Conclusion
372
+
373
+ `oncss` simplifies styling for modern web applications. Its robust feature set, from responsive design to keyframe animations, makes it an invaluable tool for developers.
374
+
375
+ ## Author
376
+
377
+ <table>
378
+ <tr>
379
+ <td>
380
+ <img src="https://raw.githubusercontent.com/devnax/devnax/main/me-circle-200.png" alt="devnax" width="100" height="100">
381
+ </td>
382
+ <td>
383
+ <strong>Naxrul Ahmed</strong><br>
384
+ <a href="https://github.com/devnax">GitHub Profile</a><br>
385
+ <a href="https://www.npmjs.com/~devnax">npm Profile</a><br>
386
+ <a href="https://github.com/devnax/open-source">Open Source Projects</a>
387
+ </td>
388
+ </tr>
389
+ </table>
390
+
391
+ <h2>⚡️ Where to find me</h2>
392
+
393
+ <p><a target="_blank" href="mailto:devnaxrul@gmail.com" style="display: inline-block;"><img src="https://img.shields.io/badge/-Email-05122A?style=for-the-badge&logo=gmail&logoColor=white&color=orange" alt="gmail" /></a>
394
+ <a target="_blank" href="https://twitter.com/devnaxx" style="display: inline-block;"><img src="https://img.shields.io/badge/twitter-x?style=for-the-badge&logo=x&logoColor=white&color=%230f1419" alt="twitter" /></a>
395
+ <a target="_blank" href="https://www.linkedin.com/in/devnax" style="display: inline-block;"><img src="https://img.shields.io/badge/linkedin-logo?style=for-the-badge&logo=linkedin&logoColor=white&color=%230a77b6" alt="linkedin" /></a>
396
+ <a target="_blank" href="https://www.facebook.com/devnax" style="display: inline-block;"><img src="https://img.shields.io/badge/facebook-logo?style=for-the-badge&logo=facebook&logoColor=white&color=%230866ff" alt="facebook" /></a>
397
+ <a target="_blank" href="https://www.instagram.com/devnaxx" style="display: inline-block;"><img src="https://img.shields.io/badge/instagram-logo?style=for-the-badge&logo=instagram&logoColor=white&color=%23F35369" alt="instagram" /></a></p>
package/types.d.ts CHANGED
@@ -44,9 +44,9 @@ export interface CSSOptionProps<Aliases, BreakpointKeys extends string> {
44
44
  };
45
45
  aliases?: OptionAliases<Aliases>;
46
46
  injectStyle?: boolean;
47
- skipProps?: (prop: string, value: string | number) => boolean | void;
48
- getValue?: (value: string | number, prop: string, css: CSSProps<Aliases, BreakpointKeys>) => (string | number);
49
- getProps?: (prop: string, value: string | number, css: CSSProps<Aliases, BreakpointKeys>) => CSSProps<Aliases, BreakpointKeys> | void;
47
+ skipProps?: (prop: string, value: string | number, dept: number) => boolean | void;
48
+ getValue?: (value: string | number, prop: string, css: CSSProps<Aliases, BreakpointKeys>, dept: number) => (string | number);
49
+ getProps?: (prop: string, value: string | number, css: CSSProps<Aliases, BreakpointKeys>, dept: number) => CSSProps<Aliases, BreakpointKeys> | void;
50
50
  }
51
51
  export type CSSFactoryType = {
52
52
  css: string;