fscss 1.1.14 → 1.1.15
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/README.md +2 -0
- package/example.fscss +9 -0
- package/lib/functions/all.js +51 -2
- package/lib/processor.js +3 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ Works in browser and backend (Node.js)
|
|
|
12
12
|
|
|
13
13
|
Supports:
|
|
14
14
|
|
|
15
|
+
- Reusable block → @define name(x,y){...} - https://github.com/fscss-ttr/FSCSS/blob/main/FSCSS_%40define_method.md
|
|
16
|
+
|
|
15
17
|
- Variables ($var, str()) → define reusable values, str(boxBased, "..."), $var:...;
|
|
16
18
|
|
|
17
19
|
- Array Methods (@arr) → define array - https://github.com/fscss-ttr/FSCSS/blob/main/FSCSS_array_method.md
|
package/example.fscss
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
@import(exec(_init themes))
|
|
2
2
|
@import(exec(style.fscss).pick(body))
|
|
3
|
+
@define card(bg, color: white){
|
|
4
|
+
background: @use(bg);
|
|
5
|
+
color: @use(color);
|
|
6
|
+
padding: 10px;
|
|
7
|
+
border-radius: 10px;
|
|
8
|
+
}
|
|
3
9
|
@arr colors[#1E2783, #8C29B2, #C41348]
|
|
4
10
|
$colors: @arr.colors!;
|
|
5
11
|
div{
|
|
@@ -13,4 +19,7 @@ $colors: @arr.colors!;
|
|
|
13
19
|
.box-b{
|
|
14
20
|
background: radial-gradient(40deg, $colors.reverse);
|
|
15
21
|
}
|
|
22
|
+
.card{
|
|
23
|
+
@card(#007999)
|
|
24
|
+
}
|
|
16
25
|
exec(_log, "Hello World!")
|
package/lib/functions/all.js
CHANGED
|
@@ -38,10 +38,12 @@ const processedCSS = css.replace(regex, (match, expression) => {
|
|
|
38
38
|
|
|
39
39
|
return (processedCSS);
|
|
40
40
|
}
|
|
41
|
-
const arraysExfscss = {}; //
|
|
41
|
+
const arraysExfscss = {}; //the global variable
|
|
42
42
|
const orderedxFscssRandom = {};
|
|
43
43
|
|
|
44
44
|
const exfMAX_DEPTH = 10; // Prevent infinite recursion
|
|
45
|
+
const defExfscss = {};
|
|
46
|
+
|
|
45
47
|
function extractBlock(css, startIndex) {
|
|
46
48
|
let depth = 0;
|
|
47
49
|
let i = startIndex;
|
|
@@ -274,6 +276,53 @@ function initlibraries(css){
|
|
|
274
276
|
});
|
|
275
277
|
return css;
|
|
276
278
|
}
|
|
279
|
+
|
|
280
|
+
function procDef(fscss) {
|
|
281
|
+
// First, extract all @define blocks and store them in defExfscss. FIGSH-FSCSS
|
|
282
|
+
let processed = fscss.replace(
|
|
283
|
+
/@define\s+([\w\_\-\—]+)\s*\(([^)]*)\)\s*\$?\{\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`|([^\}^\{]*?))\s*\}/g,
|
|
284
|
+
(match, name, paramsStr, body1, body2, body3, body4) => {
|
|
285
|
+
const params = paramsStr.split(',').map(p =>p.trim()).filter(p =>p);
|
|
286
|
+
const body = body1 ?? body2 ?? body3 ?? body4 ?? '';
|
|
287
|
+
defExfscss[name] = { params, body };
|
|
288
|
+
return ''; // Remove the define block from the output. FIGSH-FSCSS
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
// Now replace all @name(...) usages with their expanded bodies. FIGSH-FSCSS
|
|
293
|
+
processed = processed.replace(
|
|
294
|
+
/@([\w\_\-\—]+)\s*\(([\s\S]*?)\)/g,
|
|
295
|
+
(match, name, argsStr) => {
|
|
296
|
+
const def = defExfscss[name];
|
|
297
|
+
if (!def){
|
|
298
|
+
return match;
|
|
299
|
+
}// Leave unknown Def macros unchanged. FIGSH-FSCSS
|
|
300
|
+
|
|
301
|
+
const args = argsStr?.split(',').map(a => a.trim());
|
|
302
|
+
if(args[0]==='') args[0] = undefined;
|
|
303
|
+
let result = def.body;
|
|
304
|
+
|
|
305
|
+
/* Replace each @use(param) with the corresponding argument. FIGSH-FSCSS */
|
|
306
|
+
let xfVal = [];
|
|
307
|
+
def.params.forEach((param, index) => {
|
|
308
|
+
const df = def.params[index];
|
|
309
|
+
if(df&&df.includes(':')){
|
|
310
|
+
xfVal = df?.split(':')?.map(i=>i.trim()).filter(i=>i);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const dfv = xfVal[1]?xfVal[1]:'';
|
|
314
|
+
|
|
315
|
+
const arg = args[index] !== (undefined) ? args[index] : dfv;
|
|
316
|
+
const regex = new RegExp(`@use\\(\\s*${param.replace(/(\s+)?(\:(\s+)?.*)/g, '')}\\s*\\)`, 'g');
|
|
317
|
+
result = result.replace(regex, arg);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
return processed;
|
|
325
|
+
}
|
|
277
326
|
function procVar(vcss) {
|
|
278
327
|
function processSCSS(scssCode) {
|
|
279
328
|
const globalVars = {};
|
|
@@ -1266,6 +1315,6 @@ function execObj(css){
|
|
|
1266
1315
|
}
|
|
1267
1316
|
|
|
1268
1317
|
export { initlibraries,
|
|
1269
|
-
impSel, procImp, replaceRe, procExt, procVar,procFun, procArr, procEv, procRan, transformCssValues, procNum, vfc, applyFscssTransformations,procExC, procCnt, procChe, execObj
|
|
1318
|
+
impSel, procImp, replaceRe, procExt, procVar,procFun, procArr, procEv, procRan, transformCssValues, procNum, vfc, applyFscssTransformations,procExC, procCnt, procDef, procChe, execObj
|
|
1270
1319
|
}
|
|
1271
1320
|
|
package/lib/processor.js
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
vfc,
|
|
14
14
|
applyFscssTransformations,
|
|
15
15
|
procExC,
|
|
16
|
-
procCnt,
|
|
16
|
+
procCnt,
|
|
17
|
+
procDef,
|
|
17
18
|
procChe,
|
|
18
19
|
execObj
|
|
19
20
|
} from "./functions/all.js";
|
|
@@ -36,6 +37,7 @@ export async function processFscss(css, options = {}) {
|
|
|
36
37
|
if(!css.includes("exec.obj.block(fun)"))css = procFun(css);
|
|
37
38
|
if(!css.includes("exec.obj.block(length)"))css = procChe(css);
|
|
38
39
|
if(!css.includes("exec.obj.block(count)"))css = procCnt(css);
|
|
40
|
+
if(!css.includes("exec.obj.block(define)"))css = procDef(css);
|
|
39
41
|
if(!css.includes("exec.obj.block(arr)"))css = procArr(css);
|
|
40
42
|
if(!css.includes("exec.obj.block(event)"))css = procEv(css);
|
|
41
43
|
if(!css.includes("exec.obj.block(random)"))css = procRan(css);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fscss",
|
|
3
3
|
"description": "Figured Shorthand Cascading Style Sheet",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"fs-css",
|
|
22
22
|
"fscss",
|
|
23
23
|
"xfscss",
|
|
24
|
-
"preprocessor"
|
|
24
|
+
"preprocessor",
|
|
25
|
+
"lightweight"
|
|
25
26
|
],
|
|
26
27
|
"author": "Figsh",
|
|
27
28
|
"license": "MIT",
|