fscss 1.1.21 → 1.1.23

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.
@@ -123,42 +123,37 @@ function parseConditionBlocks(block) {
123
123
  }
124
124
  return blocks;
125
125
  }
126
+
126
127
  function procExC(css) {
127
128
  const regex = /exec\((_log|_error|_warn|_info),\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\)/g;
128
- let jsCode = '';
129
- let match;
130
-
131
- // Replace exec(...) with nothing (remove from CSS) while collecting code
129
+
130
+ const methodMap = {
131
+ _log: console.log,
132
+ _error: console.error,
133
+ _warn: console.warn,
134
+ _info: console.info,
135
+ };
136
+
132
137
  const cleanedCSS = css.replace(regex, (full, method, dQ, sQ, raw) => {
133
- const arg = dQ || sQ || raw;
134
-
135
- if (!['_log', '_error', '_warn', '_info'].includes(method)) {
138
+ const arg = dQ ?? sQ ?? raw;
139
+
140
+ if (!methodMap[method]) {
136
141
  console.warn(`fscss[exec(console)]: Unsupported method: ${method}`);
137
- return ''; // strip it from CSS
142
+ return '';
138
143
  }
139
-
144
+
140
145
  if (!arg) {
141
146
  console.warn(`fscss[exec(console)]: Empty argument for method: ${method}`);
142
- return ''; // strip it from CSS
147
+ return '';
143
148
  }
144
-
145
- jsCode += `console.${method.slice(1)}("${arg.replace(/"/g, '\\"')}");\n`;
146
- return ''; // ensure CSS isn’t broken
149
+
150
+ methodMap[method](arg);
151
+ return '';
147
152
  });
148
-
149
- // Run console code safely
150
- if (jsCode) {
151
- try {
152
- new Function(jsCode)();
153
- } catch (e) {
154
- console.error("fscss[exec(console)]: Error executing transformed code:", e);
155
- }
156
- }
157
-
153
+
158
154
  return cleanedCSS;
159
155
  }
160
156
 
161
-
162
157
  function procEv(css) {
163
158
  const functionMap = {};
164
159
  const funcDefRegex = /@event\s+([\w-]+)\(([^)]*)\)\s*:?{/g;
@@ -315,74 +310,24 @@ function procExC(css) {
315
310
 
316
311
  return modifiedCSS.trim();
317
312
  }
313
+
318
314
  async function initlibraries(css){
319
- css = css.replace(/exec\(\s*_init\sisjs\s*\)/g, "exec(https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/isjs.fscss)");
320
- css = css.replace(/exec\(\s*_init\sthemes\s*\)/g, "exec(https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/trshapes.fthemes.fscss)")
321
- css = css.replace(/exec\(_init\sarray1to500\s*\)/g, "exec(https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/1to500.fscss)");
322
- css = css.replace(/exec\(_init\s+([\w\d\._—\-\%\*\+\&\$\=]+)(?:\/([\w\-]+))?\s*\)/g, (match, impName, impType)=>{
315
+ const xfr = 'https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/';
316
+ css = css.replace(/exec\(_init\s+([\w\d\._—\-\%\*\+\@\&\$\=]+)(?:\/([\w\-]+))?\s*\)/g, (match, impName, impType)=>{
323
317
  if(!impType){
324
- return `exec(https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/${impName}.fscss)`;
318
+ //`
319
+ return `exec(${xfr+impName}.fscss)`;
325
320
  }
326
- return `exec(https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/${impName}.${impType})`;
321
+ return `exec(${xfr+impName}.${impType})`;
327
322
  });
328
- css = css.replace(/(\@import\((?:\s+)?(?:exec)?\((?:[\w\d\.\@\—\-_*\#\$\s\,]+)\)(?:\s+)?from(?:\s+)?)([\w\d\._—\-\%\*\+\&\$\=]+)(?:\/([\w\-]+))?(?:\s+)?\)/g, (match, state, impName, impType) => {
323
+ css = css.replace(/(\@import\((?:\s+)?(?:exec)?\((?:[\w\d\.\@\—\-_*\#\$\s\,]+)\)(?:\s+)?from(?:\s+)?)([\w\d\._—\-\%\*\+\@\&\$\=]+)(?:\/([\w\-]+))?(?:\s+)?\)/g, (match, state, impName, impType) => {
329
324
  if (!impType) {
330
- return `${state}'https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/${impName}.fscss')`;
325
+ return `${state}'${xfr+impName}.fscss')`;
331
326
  }
332
- return `${state}'https://cdn.jsdelivr.net/gh/fscss-ttr/FSCSS@main/xf/styles/${impName}.${impType}')`;
327
+ return `${state}'${xfr+impName}.${impType}')`;
333
328
  });
334
329
  return css;
335
- }
336
-
337
- function procDef(fscss) {
338
- const pRegex = /@define\s+([\w\_\-\—]+)\s*\(([^)]*)\)\s*\$?\{\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`|([^\}^\{]*?))\s*\}/g;
339
-
340
- // First, extract all @define blocks and store them in defExfscss. FIGSH-FSCSS
341
- let processed = fscss.replace(pRegex,
342
- (match, name, paramsStr, body1, body2, body3, body4) => {
343
- const params = paramsStr.split(',').map(p =>p.trim()).filter(p =>p);
344
- const body = body1 ?? body2 ?? body3 ?? body4 ?? '';
345
- defExfscss[name] = { params, body };
346
- return ''; // Remove the define block from the output. FIGSH-FSCSS
347
- }
348
- );
349
-
350
- // Now replace all @name(...) usages with their expanded bodies. FIGSH-FSCSS
351
- processed = processed.replace(
352
- /@([\w\_\-\—]+)\s*\(([\s\S]*?)\)/g,
353
- (match, name, argsStr) => {
354
- const def = defExfscss[name];
355
- if (!def){
356
- return match;
357
- }// Leave unknown Def macros unchanged. FIGSH-FSCSS
358
-
359
- const args = argsStr?.split(',').map(a => a.trim());
360
- if(args[0]==='') args[0] = undefined;
361
- let result = def.body;
362
-
363
- /* Replace each @use(param) with the corresponding argument. FIGSH-FSCSS */
364
- let xfVal = [];
365
- def.params.forEach((param, index) => {
366
- const df = def.params[index];
367
- if(df&&df.includes(':')){
368
- xfVal = df?.split(':')?.map(i=>i.trim()).filter(i=>i);
369
- }
370
-
371
- const dfv = xfVal[1]?xfVal[1]:'';
372
-
373
- const arg = args[index] !== (undefined) ? args[index] : dfv;
374
- const regex = new RegExp(`@use\\(\\s*${param.replace(/(\s+)?(\:(\s+)?.*)/g, '')}\\s*\\)`, 'g');
375
- result = result.replace(regex, arg);
376
- });
377
-
378
- return result;
379
- }
380
- );
381
- if(!pRegex.test(processed)) return processed;
382
-
383
- return procDef(processed);
384
- }
385
-
330
+ }
386
331
  function procVar(vcss) {
387
332
  function processSCSS(scssCode) {
388
333
  const globalVars = {};
@@ -454,6 +399,96 @@ function procVar(vcss) {
454
399
  const result = processSCSS(vcss);
455
400
  return result.css;
456
401
  }
402
+ let defExdepth = 0;
403
+
404
+ function procDef(fscss) {
405
+
406
+ const pRegex = /@define\s+([\w\_\-\—]+)\s*\(([^)]*)\)\s*\$?\{\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`|([^\}^\{]*?))\s*\}/g;
407
+
408
+ // First, extract all @define blocks and store them in defExfscss. FIGSH-FSCSS
409
+
410
+ let processed = fscss.replace(pRegex,
411
+ (match, name, paramsStr, body1, body2, body3, body4) => {
412
+ const params = paramsStr.split(',').map(p =>p.trim()).filter(p =>p);
413
+ const body = body1 ?? body2 ?? body3 ?? body4 ?? '';
414
+ defExfscss[name] = { params, body };
415
+ return ''; // Remove the define block from the output. FIGSH-FSCSS
416
+ }
417
+ );
418
+
419
+ // Now replace all @name(...) usages with their expanded bodies. FIGSH-FSCSS
420
+
421
+ processed = processed.replace(
422
+ /@([\w\_\-\—]+)\s*\(([\s\S]*?)\)/g,
423
+ (match, name, argsStr) => {
424
+ const def = defExfscss[name];
425
+ if (!def){
426
+ return match;
427
+ }// Leave unknown Def macros unchanged. FIGSH-FSCSS
428
+
429
+ const args = argsStr?.split(',').map(a => a.trim());
430
+ if(args[0]==='') args[0] = undefined;
431
+ let result = def.body;
432
+
433
+ /* Replace each @use(param) with the corresponding argument. FIGSH-FSCSS */
434
+ let xfVal = [];
435
+ def.params.forEach((param, index) => {
436
+ const df = def.params[index];
437
+ if(df&&df.includes(':')){
438
+ xfVal = df?.split(':')?.map(i=>i.trim()).filter(i=>i);
439
+ }
440
+
441
+ const dfv = xfVal[1]?xfVal[1]:'';
442
+
443
+ const arg = args[index] !== (undefined) ? args[index] : dfv;
444
+ const regex = new RegExp(`@use\\(\\s*${param.replace(/(\s+)?(\:(\s+)?.*)/g, '')}\\s*\\)`, 'g');
445
+ result = result.replace(regex, arg);
446
+ });
447
+
448
+ return result;
449
+ }
450
+ );
451
+
452
+
453
+ if (!pRegex.test(processed)||defExdepth >= 10) {
454
+ for(let g=0;g<10;g++){
455
+ processed = processed.replace(
456
+ /@([\w\_\-\—]+)\s*\(([\s\S]*?)\)/g,
457
+ (match, name, argsStr) => {
458
+ const def = defExfscss[name];
459
+ if (!def){
460
+ return match;
461
+ }// Leave unknown Def macros unchanged. FIGSH-FSCSS
462
+
463
+ const args = argsStr?.split(',').map(a => a.trim());
464
+ if(args[0]==='') args[0] = undefined;
465
+ let result = def.body;
466
+
467
+ /* Replace each @use(param) with the corresponding argument. FIGSH-FSCSS */
468
+ let xfVal = [];
469
+ def.params.forEach((param, index) => {
470
+ const df = def.params[index];
471
+ if(df&&df.includes(':')){
472
+ xfVal = df?.split(':')?.map(i=>i.trim()).filter(i=>i);
473
+ }
474
+
475
+ const dfv = xfVal[1]?xfVal[1]:'';
476
+
477
+ const arg = args[index] !== (undefined) ? args[index] : dfv;
478
+ const regex = new RegExp(`@use\\(\\s*${param.replace(/(\s+)?(\:(\s+)?.*)/g, '')}\\s*\\)`, 'g');
479
+ result = result.replace(regex, arg);
480
+ });
481
+
482
+ return result;
483
+ }
484
+ );
485
+ }
486
+ return processed;
487
+ }
488
+ defExdepth++;
489
+
490
+ return procDef(processed);
491
+ }
457
492
 
458
493
  function procExt(css) {
459
494
  let extractedVariables = {};
@@ -463,7 +498,7 @@ function procExt(css) {
463
498
  tempCSS = tempCSS.replace(/("(?:[^"\\]|\\.)*")|('(?:[^'\\]|\\.)*')/g, function(fullMatch) {
464
499
  let quote = fullMatch[0];
465
500
  let content = fullMatch.slice(1, -1);
466
- const directiveRegex = /@ext\((-?\d+),(\d+):\s*([^)]+)\)/g;
501
+ const directiveRegex = /@ext\((?:\s+)?(-?\d+)(?:\s+)?,(?:\s+)?(\d+)(?:\s+)?:\s*([^)]+)(?:\s+)?\)/g;
467
502
  let match;
468
503
  let directivesToProcess = [];
469
504
 
@@ -500,7 +535,7 @@ function procExt(css) {
500
535
  });
501
536
 
502
537
  // Step 2: Outside strings
503
- tempCSS = tempCSS.replace(/([#.\w-]+)\s*@ext\((-?\d+),(\d+):\s*([^)]+)\)/g, function(match, token, start, len, varName) {
538
+ tempCSS = tempCSS.replace(/([#.\w-]+)\s*@ext\((?:\s+)?(-?\d+)(?:\s+)?,(?:\s+)?(\d+)(?:\s+)?:\s*([^)]+)(?:\s+)?\)/g, function(match, token, start, len, varName) {
504
539
  start = parseInt(start);
505
540
  len = parseInt(len);
506
541
  varName = varName.trim();
@@ -531,7 +566,6 @@ function procExt(css) {
531
566
  return tempCSS;
532
567
  }
533
568
 
534
-
535
569
  function procRan(input) {
536
570
  return input.replace(/@random\(\[([^\]]+)\](?:, *ordered)?\)/g, (match, valuesStr) => {
537
571
  const isOrdered = /, *ordered\)/.test(match);
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.21",
4
+ "version": "1.1.23",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "bin": {
package/public/test.html CHANGED
@@ -1,24 +1,101 @@
1
+ <!DOCTYPE html>
1
2
  <head>
2
- <link href="./public/vars.fscss" rel="stylesheet" type='text/fscss'>
3
- <script src="index.js" async=""></script>
3
+ <script src="/exec.js" async=""></script>
4
4
  </head>
5
- <h1>HELLO WORLD!</h1>
6
- <div name='foo'></div>
7
- <style>
8
- /* styling ... */
9
- body{
10
- BACKGROUND: $init-background-stack!;
11
- COLOR: $init-color!;
12
- TEXT-ALIGN: CENTER;
13
- }
14
- h1{
15
- font-family: $init-font-family!;
16
- -*-text-stroke: $init-text-stroke!;
17
- color: #299221;
18
- }
19
- $(name: foo){
20
- BORDER: $init-border!;
21
- OUTLINE: $init-outline!;
22
- %2(width, height[: 70px;])
23
- }
24
5
  <style>
6
+ @import((
7
+ flex-wrap-center as flex-wrap,
8
+ star-clip as star
9
+ ) from "vars.fscss")
10
+
11
+ body{
12
+
13
+ background: #233332;
14
+
15
+ }
16
+
17
+ .box{
18
+
19
+ %2(width, height [: 400px;])
20
+
21
+ position: absolute;
22
+
23
+ transform-style: preserve-3d;
24
+
25
+ @flex-wrap()
26
+
27
+ }
28
+
29
+ @arr pos[count(360, 10)]
30
+
31
+ .box .star:nth-child(@arr.pos[]){
32
+
33
+ $pos: @arr.pos[];
34
+
35
+ background: #2FF200;
36
+
37
+ padding: 1px;
38
+
39
+ width: 100px;
40
+
41
+ position: absolute;
42
+
43
+ transform-origin: right;
44
+
45
+ transform: rotate($pos!deg);
46
+
47
+ }
48
+
49
+ .star:before{
50
+
51
+ content: " ";
52
+
53
+ position: absolute;
54
+
55
+ width: 20px;
56
+
57
+ height: 20px;
58
+
59
+ background: #C800F2;
60
+
61
+ top: -8.5px;
62
+
63
+ left: -7px;
64
+
65
+ transform: rotate(60deg);
66
+
67
+ clip-path: @star();
68
+
69
+ }
70
+
71
+ $(@keyframes rotate,.star &[360s linear infinite alternate]){
72
+
73
+ to{
74
+
75
+ transform: rotate(0);
76
+
77
+ }
78
+
79
+ }
80
+ </style>
81
+
82
+
83
+ <div class="box"></div>
84
+
85
+
86
+ <script>
87
+
88
+ const box = document.querySelector(".box");
89
+
90
+ for(let i =0; i<360;i++){
91
+
92
+ const star = document.createElement("div");
93
+
94
+ star.className="star";
95
+
96
+ box.appendChild(star)
97
+
98
+ }
99
+
100
+ </script>
101
+
package/public/vars.fscss CHANGED
@@ -5,3 +5,14 @@ $init-text-stroke: 0.2px #871;
5
5
  $init-caret-color: rgba(%3([190,])1);
6
6
  $init-font-family: Arial, Helvetica, sans-serif;
7
7
  $init-outline: 1px groove #235000;
8
+
9
+ @define flex-wrap-center(){
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ flex-wrap: wrap;
14
+ }
15
+ @define star-clip(){
16
+ polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)
17
+ }
18
+