Clean Code include src folder
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s

This commit is contained in:
2026-05-04 12:06:09 +02:00
parent 39a67b94fc
commit ab0e6e0697
13 changed files with 105 additions and 68 deletions

8
dist/sigpro.esm.js vendored
View File

@@ -1,4 +1,4 @@
// sigpro.js // src/sigpro.js
var isFunc = (f) => typeof f === "function"; var isFunc = (f) => typeof f === "function";
var isObj = (o) => o && typeof o === "object"; var isObj = (o) => o && typeof o === "object";
var isArr = Array.isArray; var isArr = Array.isArray;
@@ -224,7 +224,7 @@ var watch = (sources, cb) => {
return () => dispose(effect2); return () => dispose(effect2);
} }
const effect = createEffect(() => { const effect = createEffect(() => {
const vals = Array.isArray(sources) ? sources.map((s) => s()) : sources(); const vals = isArr(sources) ? sources.map((s) => s()) : sources();
untrack(() => cb(vals)); untrack(() => cb(vals));
}); });
effect(); effect();
@@ -250,10 +250,8 @@ var validateAttr = (key, val) => {
return null; return null;
if (isDangerousAttr(key)) { if (isDangerousAttr(key)) {
const sVal = String(val); const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) { if (DANGEROUS_PROTOCOL.test(sVal))
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`);
return "#"; return "#";
}
} }
return val; return val;
}; };

File diff suppressed because one or more lines are too long

10
dist/sigpro.js vendored
View File

@@ -1,5 +1,5 @@
(() => { (() => {
// sigpro.js // src/sigpro.js
var isFunc = (f) => typeof f === "function"; var isFunc = (f) => typeof f === "function";
var isObj = (o) => o && typeof o === "object"; var isObj = (o) => o && typeof o === "object";
var isArr = Array.isArray; var isArr = Array.isArray;
@@ -225,7 +225,7 @@
return () => dispose(effect2); return () => dispose(effect2);
} }
const effect = createEffect(() => { const effect = createEffect(() => {
const vals = Array.isArray(sources) ? sources.map((s) => s()) : sources(); const vals = isArr(sources) ? sources.map((s) => s()) : sources();
untrack(() => cb(vals)); untrack(() => cb(vals));
}); });
effect(); effect();
@@ -251,10 +251,8 @@
return null; return null;
if (isDangerousAttr(key)) { if (isDangerousAttr(key)) {
const sVal = String(val); const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) { if (DANGEROUS_PROTOCOL.test(sVal))
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`);
return "#"; return "#";
}
} }
return val; return val;
}; };
@@ -520,7 +518,7 @@
}); });
} }
// sigpro_umd.js // src/build_umd.js
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
Object.assign(window, { $, $$, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj }); Object.assign(window, { $, $$, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj });
} }

2
dist/sigpro.min.js vendored

File diff suppressed because one or more lines are too long

View File

View File

@@ -1,5 +1,5 @@
(() => { (() => {
// sigpro.js // src/sigpro.js
var isFunc = (f) => typeof f === "function"; var isFunc = (f) => typeof f === "function";
var isObj = (o) => o && typeof o === "object"; var isObj = (o) => o && typeof o === "object";
var isArr = Array.isArray; var isArr = Array.isArray;
@@ -225,7 +225,7 @@
return () => dispose(effect2); return () => dispose(effect2);
} }
const effect = createEffect(() => { const effect = createEffect(() => {
const vals = Array.isArray(sources) ? sources.map((s) => s()) : sources(); const vals = isArr(sources) ? sources.map((s) => s()) : sources();
untrack(() => cb(vals)); untrack(() => cb(vals));
}); });
effect(); effect();
@@ -251,10 +251,8 @@
return null; return null;
if (isDangerousAttr(key)) { if (isDangerousAttr(key)) {
const sVal = String(val); const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) { if (DANGEROUS_PROTOCOL.test(sVal))
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`);
return "#"; return "#";
}
} }
return val; return val;
}; };
@@ -520,7 +518,7 @@
}); });
} }
// sigpro_umd.js // src/build_umd.js
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
Object.assign(window, { $, $$, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj }); Object.assign(window, { $, $$, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj });
} }

View File

@@ -1,2 +0,0 @@
// index.js
export * from './sigpro.js';

View File

@@ -1,6 +1,6 @@
{ {
"name": "sigpro", "name": "sigpro",
"version": "1.2.32", "version": "1.2.35",
"type": "module", "type": "module",
"license": "MIT", "license": "MIT",
"author": { "author": {
@@ -19,12 +19,12 @@
"script": "./dist/sigpro.min.js", "script": "./dist/sigpro.min.js",
"types": "./sigpro.d.ts" "types": "./sigpro.d.ts"
}, },
"./vite": "./vite/index.js", "./vite": {
"./vite/*": "./vite/*.js" "import": "./dist/vite.js"
}
}, },
"files": [ "files": [
"dist/", "dist/",
"vite/",
"README.md", "README.md",
"LICENSE", "LICENSE",
"sigpro.d.ts" "sigpro.d.ts"
@@ -39,21 +39,22 @@
"email": "sigpro@natxocc.com" "email": "sigpro@natxocc.com"
}, },
"scripts": { "scripts": {
"del": "bun pm cache rm && rm -f bun.lockb && rm -f bun.lock",
"clean": "rm -rf dist", "clean": "rm -rf dist",
"prebuild": "npm run clean", "prebuild": "npm run clean",
"build:iife": "bun build ./sigpro_umd.js --bundle --outfile=./dist/sigpro.js --format=iife --global-name=sp", "build:iife": "bun build ./src/build_umd.js --bundle --outfile=./dist/sigpro.js --format=iife --global-name=sp",
"build:iife:min": "bun build ./sigpro_umd.js --bundle --outfile=./dist/sigpro.min.js --format=iife --global-name=sp --minify", "build:iife:min": "bun build ./src/build_umd.js --bundle --outfile=./dist/sigpro.min.js --format=iife --global-name=sp --minify",
"build:esm": "bun build ./sigpro.js --bundle --outfile=./dist/sigpro.esm.js --format=esm", "build:esm": "bun build ./src/sigpro.js --bundle --outfile=./dist/sigpro.esm.js --format=esm",
"build:esm:min": "bun build ./sigpro.js --bundle --outfile=./dist/sigpro.esm.min.js --format=esm --minify", "build:esm:min": "bun build ./src/sigpro.js --bundle --outfile=./dist/sigpro.esm.min.js --format=esm --minify",
"build:docs": "bun build ./sigpro_umd.js --bundle --outfile=./docs/sigpro.js --format=iife --global-name=sp", "build:copy": "cp ./src/vite.js ./dist/vite.js && cp ./dist/sigpro.js ./docs/sigpro.js",
"build": "bun run build:iife && bun run build:iife:min && bun run build:esm && bun run build:esm:min && bun run build:docs", "build": "bun run build:iife && bun run build:iife:min && bun run build:esm && bun run build:esm:min && bun run build:copy",
"docs": "bun x serve docs", "docs": "bun x serve docs"
"prepublishOnly": "npm run build"
}, },
"keywords": [ "keywords": [
"signals", "signals",
"reactivity", "reactivity",
"reactive", "reactive",
"pure",
"vanilla", "vanilla",
"js", "js",
"ui", "ui",
@@ -62,7 +63,6 @@
"frontend", "frontend",
"spa", "spa",
"lightweight", "lightweight",
"no-vdom",
"sigpro" "sigpro"
] ]
} }

View File

@@ -1,10 +0,0 @@
import { h } from '../sigpro.js';
if (typeof window !== 'undefined') {
'a abbr article aside audio b blockquote br button canvas caption cite code col colgroup datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hr i iframe img input ins kbd label legend li main mark meter nav object ol optgroup option output p picture pre progress section select slot small source span strong sub summary sup svg table tbody td template textarea tfoot th thead time tr u ul video'
.split(' ').forEach(tag => {
window[tag] = (props, children) => h(tag, props, children);
// window[tag] = (...args) => h(tag, ...args);
});
console.log('SigPro tags ready');
}

View File

@@ -1,19 +0,0 @@
import { filterXSS } from '../sigpro.js';
const DANGEROUS_PROTOCOL = /^\s*(javascript|data|vbscript):/i;
const DANGEROUS_URI_ATTRS = new Set(["src", "href", "formaction", "action", "background", "code", "archive"]);
const isDangerousAttr = key => DANGEROUS_URI_ATTRS.has(key) || key.startsWith("on");
const validateAttr = (key, val) => {
if (val == null || val === false) return null;
if (isDangerousAttr(key)) {
const sVal = String(val);
if (DANGEROUS_PROTOCOL.test(sVal)) {
console.warn(`[SigPro XSS] Locked ${key}`);
return '#';
}
}
return val;
};
filterXSS(validateAttr);

View File

@@ -213,7 +213,7 @@ const watch = (sources, cb) => {
return () => dispose(effect) return () => dispose(effect)
} }
const effect = createEffect(() => { const effect = createEffect(() => {
const vals = Array.isArray(sources) ? sources.map(s => s()) : sources() const vals = isArr(sources) ? sources.map(s => s()) : sources()
untrack(() => cb(vals)) untrack(() => cb(vals))
}) })
effect() effect()
@@ -238,10 +238,7 @@ const validateAttr = (key, val) => {
if (val == null || val === false) return null if (val == null || val === false) return null
if (isDangerousAttr(key)) { if (isDangerousAttr(key)) {
const sVal = String(val) const sVal = String(val)
if (DANGEROUS_PROTOCOL.test(sVal)) { if (DANGEROUS_PROTOCOL.test(sVal)) return '#'
console.warn(`[SigPro] Bloqueado protocolo peligroso en ${key}`)
return '#'
}
} }
return val return val
} }

77
src/vite.js Normal file
View File

@@ -0,0 +1,77 @@
/**
* SigPro Vite Plugin - File-based Routing
* @module sigpro/vite
*/
import fs from 'node:fs';
import path from 'node:path';
export default function sigproRouter() {
const virtualModuleId = 'virtual:sigpro-routes';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
// Helper para escanear archivos
const getFiles = (dir) => {
if (!fs.existsSync(dir)) return [];
return fs.readdirSync(dir, { recursive: true })
.filter(file => /\.(js|jsx)$/.test(file) && !path.basename(file).startsWith('_'))
.map(file => path.resolve(dir, file));
};
// Transformador de ruta de archivo a URL de router
const pathToUrl = (pagesDir, filePath) => {
let relative = path.relative(pagesDir, filePath)
.replace(/\\/g, '/')
.replace(/\.(js|jsx)$/, '')
.replace(/\/index$/, '')
.replace(/^index$/, '');
return ('/' + relative)
.replace(/\/+/g, '/')
.replace(/\[\.\.\.([^\]]+)\]/g, '*')
.replace(/\[([^\]]+)\]/g, ':$1')
.replace(/\/$/, '') || '/';
};
return {
name: 'sigpro-router',
resolveId(id) {
if (id === virtualModuleId) return resolvedVirtualModuleId;
},
load(id) {
if (id !== resolvedVirtualModuleId) return;
const root = process.cwd();
const pagesDir = path.resolve(root, 'src/pages');
// Obtenemos y ordenamos archivos (rutas estáticas primero, luego dinámicas)
const files = getFiles(pagesDir).sort((a, b) => {
const urlA = pathToUrl(pagesDir, a);
const urlB = pathToUrl(pagesDir, b);
if (urlA.includes(':') && !urlB.includes(':')) return 1;
if (!urlA.includes(':') && urlB.includes(':')) return -1;
return urlB.length - urlA.length;
});
let routeEntries = '';
files.forEach((fullPath) => {
const urlPath = pathToUrl(pagesDir, fullPath);
// Hacemos la ruta relativa al proyecto para que el import de Vite sea limpio
const relativeImport = './' + path.relative(root, fullPath).replace(/\\/g, '/');
routeEntries += ` { path: '${urlPath}', component: async () => (await import('/${relativeImport}')).default },\n`;
});
// Fallback 404 si no existe una ruta comodín
if (!routeEntries.includes("path: '*'")) {
routeEntries += ` { path: '*', component: () => document.createTextNode('404 - Not Found') },\n`;
}
return `export const routes = [\n${routeEntries}];`;
}
};
}
export { sigproRouter };