fscss 1.1.6 → 1.1.7

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.
@@ -0,0 +1,59 @@
1
+ // lib/functions/impSel.js
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+
5
+ export async function impSel(text, { inputDir = process.cwd() } = {}) {
6
+ const validImpExt = [".fscss", ".css", ".txt", ".scss", ".less", ".xfscss"];
7
+ const regex = /@import\(exec\(([^)]+)\)\s*\.\s*(?:pick|find)\(([^)]+)\)\)/g;
8
+ const matches = [...text.matchAll(regex)];
9
+
10
+ let result = text;
11
+
12
+ for (const match of matches) {
13
+ const [fullMatch, urlSrc, part] = match;
14
+
15
+ try {
16
+ const impUrl = urlSrc.replace(/["']/g, "");
17
+ const impExt = impUrl.slice(impUrl.lastIndexOf(".")).toLowerCase();
18
+
19
+ if (impUrl.trim().startsWith("_init") && impUrl.includes(" ")) {
20
+ console.warn(`fscss[@import] library not found for: ${impUrl}`);
21
+ continue;
22
+ }
23
+
24
+ if (!validImpExt.includes(impExt)) {
25
+ console.warn(`fscss[@import] invalid extension for: ${impUrl}`);
26
+ continue;
27
+ }
28
+
29
+ let resText;
30
+
31
+ if (/^https?:\/\//.test(impUrl)) {
32
+ // Remote import
33
+ const response = await fetch(impUrl);
34
+ if (!response.ok) {
35
+ throw new Error(`fscss[@import] HTTP ${response.status} for ${impUrl}`);
36
+ }
37
+ resText = await response.text();
38
+ } else {
39
+ // Local import
40
+ const filePath = path.resolve(inputDir, impUrl);
41
+ resText = await fs.readFile(filePath, "utf8");
42
+ }
43
+
44
+ const extracted = extractOnlyBlock(resText, part.trim());
45
+ result = result.replace(fullMatch, extracted || `/* fscss[@import pick] No block matches: ${part} */`);
46
+ } catch (err) {
47
+ console.error(`fscss[@import] Failed: ${urlSrc}`, err);
48
+ result = result.replace(fullMatch, `/* Failed import: ${urlSrc} */`);
49
+ }
50
+ }
51
+
52
+ return result;
53
+ }
54
+
55
+ function extractOnlyBlock(cssText, blockName) {
56
+ const regex = new RegExp(`${blockName}\\s*{[^}]*}`, "g");
57
+ const match = cssText.match(regex);
58
+ return match ? match.join("\n") : null;
59
+ }
@@ -0,0 +1,50 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import https from "https";
4
+ import http from "http";
5
+
6
+ function fetchRemote(url) {
7
+ return new Promise((resolve, reject) => {
8
+ const client = url.startsWith("https") ? https : http;
9
+ client.get(url, res => {
10
+ if (res.statusCode !== 200) {
11
+ reject(new Error(`Failed to fetch ${url}, status ${res.statusCode}`));
12
+ return;
13
+ }
14
+ let data = "";
15
+ res.on("data", chunk => (data += chunk));
16
+ res.on("end", () => resolve(data));
17
+ }).on("error", reject);
18
+ });
19
+ }
20
+
21
+ export async function procImp(css, { inputDir }) {
22
+ // async replace: collect promises then resolve
23
+ const matches = [...css.matchAll(/@import\(exec\(([^)]+)\)\)/g)];
24
+
25
+ for (const match of matches) {
26
+ const rawPath = match[1].trim();
27
+ let importedContent = "";
28
+
29
+ if (rawPath.startsWith("http://") || rawPath.startsWith("https://")) {
30
+ // remote import
31
+ importedContent = await fetchRemote(rawPath);
32
+ } else {
33
+ // local import
34
+ const absPath = path.resolve(inputDir, rawPath);
35
+ if (!fs.existsSync(absPath)) {
36
+ throw new Error(`FSCSS import failed: file not found ${absPath}`);
37
+ }
38
+ importedContent = fs.readFileSync(absPath, "utf8");
39
+
40
+ // 🔁 recursive support (nested imports)
41
+ importedContent = await procImp(importedContent, {
42
+ inputDir: path.dirname(absPath),
43
+ });
44
+ }
45
+
46
+ css = css.replace(match[0], importedContent);
47
+ }
48
+
49
+ return css;
50
+ }
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // lib/index.js
2
+ export { processFscss } from "./processor.js";
@@ -0,0 +1,47 @@
1
+ // lib/processor.js
2
+ import {
3
+ initlibraries,
4
+ replaceRe,
5
+ procExt,
6
+ procVar,
7
+ procFun,
8
+ procArr,
9
+ procEv,
10
+ procRan,
11
+ transformCssValues,
12
+ procNum,
13
+ applyFscssTransformations,
14
+ procExC,
15
+ execObj
16
+ } from "./functions/all.js";
17
+ import { procImp } from "./functions/procImp.js";
18
+ import { impSel } from "./functions/impSel.js";
19
+ export async function processFscss(css, options = {}) {
20
+ const { inputDir = process.cwd() } = options;
21
+
22
+ if (!css.includes("exec.obj.block(all)")) {
23
+ if (!css.includes("exec.obj.block(init lab)")) css = initlibraries(css);
24
+ if (!css.includes("exec.obj.block(f import)") || !css.includes("exec.obj.block(f import pick)")) {
25
+ css = await impSel(css, { inputDir });
26
+ }
27
+ if (!css.includes("exec.obj.block(f import)")) {
28
+ css = await procImp(css, { inputDir });
29
+ }
30
+
31
+ if (!css.includes("exec.obj.block(store:before)") || !css.includes("exec.obj.block(store)")) css = replaceRe(css);
32
+ if (!css.includes("exec.obj.block(ext:before)") || !css.includes("exec.obj.block(ext)")) css = procExt(css);
33
+ if (!css.includes("exec.obj.block(f var)")) css = procVar(css);
34
+ if (!css.includes("exec.obj.block(fun)")) css = procFun(css);
35
+ if (!css.includes("exec.obj.block(arr)")) css = procArr(css);
36
+ if (!css.includes("exec.obj.block(event)")) css = procEv(css);
37
+ if (!css.includes("exec.obj.block(random)")) css = procRan(css);
38
+ if (!css.includes("exec.obj.block(copy)")) css = transformCssValues(css);
39
+ if (!css.includes("exec.obj.block(store:after)") || !css.includes("exec.obj.block(store)")) css = replaceRe(css);
40
+ if (!css.includes("exec.obj.block(num)")) css = procNum(css);
41
+ if (!css.includes("exec.obj.block(ext:after)") || !css.includes("exec.obj.block(ext)")) css = procExt(css);
42
+ if (!css.includes("exec.obj.block(t group)")) css = applyFscssTransformations(css);
43
+ if (!css.includes("exec.obj.block(debug)")) css = procExC(css);
44
+ }
45
+
46
+ return execObj(css);
47
+ }
package/package.json CHANGED
@@ -1,39 +1,42 @@
1
1
  {
2
2
  "name": "fscss",
3
- "version": "1.1.6",
4
3
  "description": "Figured Shorthand Cascading Style Sheet",
5
- "keywords": [
6
- "node",
7
- "express",
8
- "npm",
9
- "fscss",
10
- "shorthand",
11
- "css",
12
- "figuredshorthand"
13
- ],
14
- "homepage": "https://github.com/Figsh/xfscss#readme",
15
- "bugs": {
16
- "url": "https://github.com/Figsh/xfscss/issues"
4
+ "version": "1.1.7",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "bin": {
8
+ "fscss": "bin/fscss.js"
9
+ },
10
+ "scripts": {
11
+ "start": "node index.js",
12
+ "test": "node bin/fscss.js example.fscss example.css"
17
13
  },
18
14
  "repository": {
19
15
  "type": "git",
20
16
  "url": "git+https://github.com/Figsh/xfscss.git"
21
17
  },
18
+ "keywords": [
19
+ "node",
20
+ "figsh_css",
21
+ "fs-css",
22
+ "fscss",
23
+ "xfscss"
24
+ ],
25
+ "author": "Figsh",
22
26
  "license": "MIT",
23
- "author": "figsh",
24
- "type": "commonjs",
25
- "main": "index.js",
26
- "scripts": {
27
- "start": "node index.js",
28
- "test": "mocha"
27
+ "bugs": {
28
+ "url": "https://github.com/Figsh/xfscss/issues"
29
29
  },
30
+ "homepage": "https://github.com/Figsh/xfscss#readme",
30
31
  "dependencies": {
31
- "dotenv": "^16.0.3",
32
32
  "express": "^4.18.2",
33
- "fscss": "^1.1.6"
33
+ "dotenv": "^16.0.3"
34
34
  },
35
35
  "devDependencies": {
36
- "chai": "^4.3.4",
37
- "mocha": "^10.0.0"
36
+ "mocha": "^10.0.0",
37
+ "chai": "^4.3.4"
38
+ },
39
+ "directories": {
40
+ "lib": "lib"
38
41
  }
39
42
  }
@@ -0,0 +1,24 @@
1
+ <head>
2
+ <link href="./public/vars.fscss" rel="stylesheet" type='text/fscss'>
3
+ <script src="index.js" async=""></script>
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
+ <style>
@@ -0,0 +1,7 @@
1
+ $init-color: #521125;
2
+ $init-border: 2px solid mx(#,"5");
3
+ $init-background-stack: #479 conic-gradient(#eafffe, #eaaccd, #eacfec, #ffffff) no-repeat;
4
+ $init-text-stroke: 0.2px #871;
5
+ $init-caret-color: rgba(%3([190,])1);
6
+ $init-font-family: Arial, Helvetica, sans-serif;
7
+ $init-outline: 1px groove #235000;
package/style.fscss ADDED
@@ -0,0 +1,4 @@
1
+ body{
2
+ Background: @event.theme(light);
3
+ color: blue;
4
+ }
package/xfscss.min.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export var text='text';export var url='fromUrl';export var external='fromUrl';export var fromUrl='fromUrl';export var write='text';function inf(host,jsdl){if(typeof jsdl!=='undefined'&&host!=='undefined'){var ht=host.replace(/github/gi, 'gh');var cov=jsdl.replace(/\s*-\>\s*/g, '/').replace(/\n/g, '');var url=`https://cdn.jsdelivr.net/${ht}/${cov}`;var ScrT=document.createElement('script');ScrT.type='text/javascript';ScrT.async='true';ScrT.src=url;document.body.appendChild(ScrT);}}function exec(text,fscss_style_sheet){if(typeof fscss_style_sheet !== 'undefined' && text == 'text'){var doc=document;var SrT = doc.createElement('script');
2
- SrT.type='text/javascript';SrT.async='true';SrT.src='https://cdn.jsdelivr.net/gh/Figsh/FSCSS@main/rtF4.js';doc.body.appendChild(SrT);doc.body.innerHTML += (`<style>${fscss_style_sheet}</style>`);}else if(typeof fscss_style_sheet!=='undefined'&&text=='fromUrl'){var doc=document;var SrT=doc.createElement('script');SrT.type = 'text/javascript';SrT.async='true';SrT.src= 'https://combinatronics.io/Figsh/FSCSS/refs/heads/4.0.1/fscss_exec.js ';doc.body.appendChild(SrT);fetch(fscss_style_sheet).then(response =>response.text()).then(data=>{const AJWinDocStyleElement = document.createElement("style");
3
- AJWinDocStyleElement.innerHTML = `${data}`;
4
- document.head.appendChild(AJWinDocStyleElement);}).catch(error=>{});}}export{ inf };export{ exec };
2
+ SrT.type='text/javascript';SrT.async='true';SrT.src='https://cdn.jsdelivr.net/gh/Figsh/FSCSS@main/rtF4.js ';doc.body.appendChild(SrT);doc.body.innerHTML += (`<style>${fscss_style_sheet}</style>`);}else if(typeof fscss_style_sheet!=='undefined'&&text=='fromUrl'){var doc=document;var SrT=doc.createElement('script');SrT.type = 'text/javascript';SrT.async='true';SrT.src= 'https://combinatronics.io/Figsh/FSCSS/refs/heads/4.0.1/fscss_exec.js ';doc.body.appendChild(SrT);fetch(fscss_style_sheet).then(response =>response.text()).then(data=>{const AJWinDocStyleElement = document.createElement("style");
3
+ AJWinDocStyleElement.innerHTML = `${data}`;
4
+ document.head.appendChild(AJWinDocStyleElement);}).catch(error=>{});}}export{ inf };export{ exec };
package/e/index.js DELETED
@@ -1,9 +0,0 @@
1
-
2
- function loadFScript(src, async = true){const script=document.createElement('script');script.type='text/javascript';script.async= async;src="https://cdn.jsdelivr.net/gh/Figsh/FSCSS@main/rtF4.js";script.src = src;document.body.appendChild(script);}loadFScript();function applyFscssStyles() {const fscssLinks=document.querySelectorAll('[type*="fscss"]');fscssLinks.forEach(link => {fetch(link.href).then(response=>response.text()).then(css =>{const style=document.createElement('style');style.textContent = css;document.head.appendChild(style);}).catch(error => {
3
- console.error(`Failed to load FSCSS from ${link.href}`, error);});});}function inf({ host, path }) {if (!host || !path) {console.error("Both 'host' and 'path' are required.");
4
- return;}const sanitizedHost = host.replace(/github/gi, 'gh');const sanitizedPath = path.replace(/\s*->\s*/g, '/').replace(/\n/g, '');const finalUrl = `https://cdn.jsdelivr.net/${sanitizedHost}/${sanitizedPath}`;loadFScript(finalUrl);
5
- }function exec({ type = 'text', content, onError, onSuccess }) {if (!content) {const errorText = 'No CSS content or URL provided.';console.error(errorText);if (onError) onError(errorText);
6
- return;
7
- }const style=document.createElement('style');const appendStyle=cssText=> {style.textContent = cssText;document.head.appendChild(style);if (onSuccess)onSuccess(style);};if (type==='text'||type==='auto'|| type==='text/fscss'||type==='text/css'){appendStyle(content);}else if (type==='fromUrl'||type==='URL' ||type==='fromURL'||type==='link') {fetch(content).then(res => {if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`);
8
- return res.text();}).then(css => appendStyle(css)).catch(err => {console.error(`Failed to load CSS from URL: ${content}`, err);if (onError) onError(err.message);});} else {const errorText = `Unsupported type "${type}". Use "text" or "fromUrl".`;console.error(errorText);if(onError) onError(errorText);}}
9
- /* v-- */
package/e/xfscss.min.js DELETED
@@ -1,9 +0,0 @@
1
- /* v-- */function loadFScript(src, async = true){const script=document.createElement('script');script.type='text/javascript';script.async= async;src="https://cdn.jsdelivr.net/gh/Figsh/FSCSS@main/rtF4.js";script.src = src;document.body.appendChild(script);}loadFScript();export function applyFscssStyles() {const fscssLinks=document.querySelectorAll('[type*="fscss"]');fscssLinks.forEach(link => {fetch(link.href).then(response=>response.text()).then(css =>{const style=document.createElement('style');style.textContent = css;document.head.appendChild(style);}).catch(error => {
2
- console.error(`Failed to load FSCSS from ${link.href}`, error);});});}export function inf({ host, path }) {if (!host || !path) {console.error("Both 'host' and 'path' are required.");
3
- return;}const sanitizedHost = host.replace(/github/gi, 'gh');const sanitizedPath = path.replace(/\s*->\s*/g, '/').replace(/\n/g, '');const finalUrl = `https://cdn.jsdelivr.net/${sanitizedHost}/${sanitizedPath}`;loadFScript(finalUrl);
4
- }export function exec({ type = 'text', content, onError, onSuccess }) {if (!content) {const errorText = 'No CSS content or URL provided.';console.error(errorText);if (onError) onError(errorText);
5
- return;
6
- }const style=document.createElement('style');const appendStyle=cssText=> {style.textContent = cssText;document.head.appendChild(style);if (onSuccess)onSuccess(style);};if (type==='text'||type==='auto'|| type==='text/fscss'||type==='text/css'){appendStyle(content);}else if (type==='fromUrl'||type==='URL' ||type==='fromURL'||type==='link') {fetch(content).then(res => {if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`);
7
- return res.text();}).then(css => appendStyle(css)).catch(err => {console.error(`Failed to load CSS from URL: ${content}`, err);if (onError) onError(err.message);});} else {const errorText = `Unsupported type "${type}". Use "text" or "fromUrl".`;console.error(errorText);if(onError) onError(errorText);}}
8
-
9
-
package/strg/de DELETED
@@ -1,5 +0,0 @@
1
- fshs >{th.exec(type, this){
2
- type = url || text;
3
- this = if -url >url, if text -text >text;
4
- }
5
- }
package/strg/xvars.fscss DELETED
@@ -1,23 +0,0 @@
1
-
2
- /* == as initial values == */
3
- $init-border: 2px groove lightgreen;
4
- $init-outline: 2px groove lightblue;
5
- $init-box-size: 100px;
6
- $init-color: #312213;
7
- $init-font: 15px Arial, sans-serif;
8
- $init-background-stack: linear-gradient(#fee, #eff);
9
- /* == initial values ended == */
10
-
11
- /* == as Global variables == */
12
- $black-du: mx(#,"1");
13
- $front-card-z-index: 5;
14
- $back-card-z-index: -1;
15
- $line-cont: rpt(8,"_");
16
- $rotate-both0deg: %2(rotateX,rotateY[(0)]);
17
- $rotate-both-full: %22(rotateX,rotateY[(3360deg)]);
18
- $rotate-x0deg: rotateX(0);
19
- $rotate-x-full: rotateX(360deg);
20
- $rotate-y0deg: rotateY(0);
21
- $rotate-y-full: rotateY(360deg);
22
- /* == Global variables ended == */
23
-