sigpro 2.0.10 → 2.1.2

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 CHANGED
@@ -149,7 +149,7 @@ SVG tags are detected automatically. `class`, `style`, and every attribute go th
149
149
  ### Router
150
150
 
151
151
  ```javascript
152
- import { router } from "sigpro";
152
+ import { router } from "sigpro/router";
153
153
 
154
154
  const App = router([
155
155
  { path: "/", component: Home },
@@ -166,7 +166,7 @@ router.path(); // current path
166
166
  ### i18n
167
167
 
168
168
  ```javascript
169
- import { addLang, setLocale, t } from "sigpro";
169
+ import { addLang, setLocale, t } from "sigpro/lang";
170
170
 
171
171
  addLang({
172
172
  en: { hello: "Hello" },
@@ -181,7 +181,7 @@ h1(t("hello")); // "Hola" (reactive, updates when locale changes)
181
181
  ### HTTP Helper
182
182
 
183
183
  ```javascript
184
- import { db } from "sigpro";
184
+ import { db } from "sigpro/db";
185
185
 
186
186
  const loading = signal(false);
187
187
  const data = await db("/api/users", null, loading);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigpro",
3
- "version": "2.0.10",
3
+ "version": "2.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -8,57 +8,50 @@
8
8
  "email": "sigpro@natxocc.com",
9
9
  "url": "https://sigpro.natxocc.com"
10
10
  },
11
- "main": "./dist/sigpro.js",
12
- "module": "./dist/sigpro.js",
13
- "unpkg": "./dist/sigpro.js",
14
- "jsdelivr": "./dist/sigpro.js",
11
+ "main": "./src/sigpro.js",
12
+ "module": "./src/sigpro.js",
15
13
  "types": "./sigpro.d.ts",
16
14
  "exports": {
17
15
  ".": {
18
16
  "types": "./sigpro.d.ts",
19
- "import": "./dist/sigpro.js",
20
- "default": "./dist/sigpro.js"
17
+ "import": "./src/sigpro.js",
18
+ "default": "./src/sigpro.js"
21
19
  },
22
- "./grid": {
23
- "import": "./dist/sigpro.grid.js",
24
- "default": "./dist/sigpro.grid.js"
25
- },
26
- "./editor": {
27
- "import": "./dist/sigpro.editor.js",
28
- "default": "./dist/sigpro.editor.js"
20
+ "./router": {
21
+ "types": "./sigpro.d.ts",
22
+ "import": "./src/sigpro.router.js",
23
+ "default": "./src/sigpro.router.js"
29
24
  },
30
- "./chart": {
31
- "import": "./dist/sigpro.chart.js",
32
- "default": "./dist/sigpro.chart.js"
25
+ "./lang": {
26
+ "types": "./sigpro.d.ts",
27
+ "import": "./src/sigpro.lang.js",
28
+ "default": "./src/sigpro.lang.js"
33
29
  },
34
- "./calendar": {
35
- "import": "./dist/sigpro.calendar.js",
36
- "default": "./dist/sigpro.calendar.js"
30
+ "./db": {
31
+ "types": "./sigpro.d.ts",
32
+ "import": "./src/sigpro.db.js",
33
+ "default": "./src/sigpro.db.js"
37
34
  },
38
35
  "./vite": {
39
- "import": "./dist/sigpro.vite.js",
40
- "default": "./dist/sigpro.vite.js"
36
+ "types": "./sigpro.d.ts",
37
+ "import": "./src/sigpro.vite.js",
38
+ "default": "./src/sigpro.vite.js"
41
39
  },
42
40
  "./hmr": {
43
- "import": "./dist/sigpro.hmr.js",
44
- "default": "./dist/sigpro.hmr.js"
45
- },
46
- "./utils": {
47
- "import": "./dist/sigpro.utils.js",
48
- "default": "./dist/sigpro.utils.js"
49
- },
50
- "./pdf": {
51
- "import": "./dist/sigpro.pdf.js",
52
- "default": "./dist/sigpro.pdf.js"
41
+ "types": "./sigpro.d.ts",
42
+ "import": "./src/sigpro.hmr.js",
43
+ "default": "./src/sigpro.hmr.js"
53
44
  }
54
45
  },
55
46
  "files": [
56
- "dist/",
57
- "README.md",
58
- "LICENSE",
47
+ "src/",
59
48
  "sigpro.d.ts"
60
49
  ],
61
50
  "homepage": "https://sigpro.natxocc.com/#/",
51
+ "sideEffects": false,
52
+ "engines": {
53
+ "node": ">=18"
54
+ },
62
55
  "repository": {
63
56
  "type": "git",
64
57
  "url": "https://github.com/natxocc/sigpro"
@@ -68,39 +61,8 @@
68
61
  "email": "sigpro@natxocc.com"
69
62
  },
70
63
  "scripts": {
71
- "del": "bun pm cache rm && rm -f bun.lockb && rm -f bun.lock",
72
- "clean": "rm -rf dist docs/*.js",
73
- "prebuild": "bun run clean",
74
- "build:core": "bun build ./src/sigpro.js --bundle --outfile=./dist/sigpro.js --format=esm --minify",
75
- "build:utils": "bun build ./src/sigpro.utils.js --bundle --outfile=./dist/sigpro.utils.js --format=esm --minify",
76
- "build:grid": "bun build ./src/sigpro.grid.js --bundle --outfile=./dist/sigpro.grid.js --format=esm --minify",
77
- "build:chart": "bun build ./src/sigpro.chart.js --bundle --outfile=./dist/sigpro.chart.js --format=esm --minify",
78
- "build:calendar": "bun build ./src/sigpro.calendar.js --bundle --outfile=./dist/sigpro.calendar.js --format=esm --minify",
79
- "build:editor": "bun build ./src/sigpro.editor.js --bundle --outfile=./dist/sigpro.editor.js --format=esm --minify",
80
- "build:ui": "bun build ./src/sigpro.ui.js --bundle --outfile=./dist/sigpro.ui.js --format=esm --external ./src/sigpro.js --minify",
81
- "build:vite": "bun build ./src/sigpro.vite.js --bundle --outfile=./dist/sigpro.vite.js --format=esm --external fs --external path --minify",
82
- "build:hmr": "bun build ./src/sigpro.hmr.js --bundle --outfile=./dist/sigpro.hmr.js --format=esm --external fs --external path --minify",
83
- "build:convert": "bun build ./src/sigpro.convert.js --bundle --outfile=./dist/sigpro.convert.js --format=esm --minify",
84
- "build:pdf": "bun build ./src/sigpro.pdf.js --bundle --outfile=./dist/sigpro.pdf.js --format=esm --minify",
85
- "build": "mkdir -p docs && bun run build:core && bun run build:utils && bun run build:grid && bun run build:chart && bun run build:calendar && bun run build:editor && bun run build:ui && bun run build:vite && bun run build:convert && bun run build:pdf && cp ./dist/*.js ./docs/",
86
- "docs": "bun x serve docs"
87
- },
88
- "devDependencies": {
89
- "@fullcalendar/core": "^6.1.22",
90
- "@fullcalendar/daygrid": "^6.1.22",
91
- "@fullcalendar/interaction": "^6.1.22",
92
- "@fullcalendar/list": "^6.1.22",
93
- "@fullcalendar/timegrid": "^6.1.22",
94
- "@iconify/json": "^2.2.557",
95
- "@iconify/tailwind4": "^1.2.3",
96
- "@tailwindcss/cli": "^4.3.5",
97
- "ag-grid-community": "^35.3.1",
98
- "ag-grid-enterprise": "^35.3.1",
99
- "daisyui": "^5.8.1",
100
- "highcharts": "^13.1.1",
101
- "jspdf": "^4.2.1",
102
- "jspdf-autotable": "^5.0.9",
103
- "tailwindcss": "^4.3.5"
64
+ "docs:sync": "mkdir -p docs/src && cp src/*.js docs/src/",
65
+ "docs": "bun run docs:sync && bun x serve docs"
104
66
  },
105
67
  "keywords": [
106
68
  "signals",
@@ -117,4 +79,4 @@
117
79
  "lightweight",
118
80
  "sigpro"
119
81
  ]
120
- }
82
+ }
package/sigpro.d.ts CHANGED
@@ -64,6 +64,18 @@ export function watch<T>(
64
64
  */
65
65
  export function local<T>(key: string, initial: T): Signal<T>;
66
66
 
67
+ /**
68
+ * Groups effects/`computed` under one disposable scope. Calling the returned
69
+ * function stops everything created within `fn`.
70
+ */
71
+ export function effectScope<T>(fn: () => T): T;
72
+
73
+ /**
74
+ * Reports an error thrown inside an `effect` or component to the handler set by
75
+ * `onError`. Called internally; rarely used directly.
76
+ */
77
+ export function reportError(err: unknown, where?: unknown): void;
78
+
67
79
  // ============================================================================
68
80
  // DOM Creation
69
81
  // ============================================================================
@@ -109,6 +121,15 @@ export type Child =
109
121
  | (() => Child | Child[])
110
122
  | Child[];
111
123
 
124
+ /**
125
+ * A slot: a function that returns the rendered content when called.
126
+ * Named slots are keyed by name; the fallback slot is keyed as `default`.
127
+ */
128
+ export type Slot = () => Child | Child[];
129
+
130
+ /** A map of slot names to slot functions. */
131
+ export type Slots = Record<string, Slot>;
132
+
112
133
  /**
113
134
  * Creates an HTML/SVG element (tag: string) or renders a component
114
135
  * (tag: function). The first arg after `tag` may be children when it is not
@@ -126,6 +147,29 @@ export function h<P extends object>(
126
147
  ...children: Child[]
127
148
  ): Node | Node[] | null;
128
149
 
150
+ /**
151
+ * Normalizes a component's `children` into a `Slots` map.
152
+ *
153
+ * - A single object argument (not an array, not a `Node`) is returned as-is,
154
+ * so you can pass a named-slots object directly.
155
+ * - Otherwise the children are wrapped as `{ default: () => children }`.
156
+ *
157
+ * @example
158
+ * const Card = (props) => {
159
+ * const { default: body, footer } = props.slots || {};
160
+ * return div({}, body && body());
161
+ * };
162
+ * Card({}, slots([p({}, 'body'), p({}, 'other')]));
163
+ *
164
+ * @example
165
+ * const Card = (props) => {
166
+ * const { header } = props.slots;
167
+ * return div({}, header && header());
168
+ * };
169
+ * Card({}, slots({ header: () => h('h1', {}, 'Title') }));
170
+ */
171
+ export function slots(children: Child | Child[] | Slots): Slots;
172
+
129
173
  /**
130
174
  * Registers all standard HTML tag names as globals on `target` (default
131
175
  * `window`). Call once at startup.
@@ -151,14 +195,48 @@ export function mount(
151
195
  */
152
196
  export function unmount(node: Node): void;
153
197
 
154
- /**
155
- * Recursively disposes scopes, removes tracked listeners, and clears
156
- * `_cln` / `_stopScope` on the node and its descendants.
157
- */
158
- export function cleanupNode(node: Node): void;
159
198
 
160
199
  // ============================================================================
161
- // Router
200
+ // Event helpers
201
+ // ============================================================================
202
+
203
+ export type EventListener<T extends Event = Event> = (event: T) => void;
204
+
205
+ /** Wraps a handler to `preventDefault()` before calling it. */
206
+ export function onPrevent<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
207
+
208
+ /** Wraps a handler to `stopPropagation()` before calling it. */
209
+ export function onStop<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
210
+
211
+ /** Only invokes `fn` when the event target equals the current target. */
212
+ export function onSelf<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
213
+
214
+ /** Wraps a handler so it runs only once, then detaches itself. */
215
+ export function onOnce<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
216
+
217
+ /** Wraps a handler with a leading-trailing debounce of `ms` milliseconds. */
218
+ export function onDebounce<T extends Event = Event>(ms: number, fn: EventListener<T>): EventListener<T>;
219
+
220
+ /** Invokes `fn` only when `e.key` matches `key`. */
221
+ export function onKey<T extends Event = Event>(key: string, fn: EventListener<T>): EventListener<T>;
222
+
223
+ /** Invokes `fn` when the pressed key is `Enter`. */
224
+ export function onEnter<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
225
+
226
+ /** Invokes `fn` when the pressed key is `Escape`. */
227
+ export function onEscape<T extends Event = Event>(fn: EventListener<T>): EventListener<T>;
228
+
229
+ /** Binds an input's value to a signal: `{ value, oninput }` props for `h`. */
230
+ export function bindvalue<T>(s: () => T): { value: () => T; oninput: (e: Event) => void };
231
+
232
+ /** Binds a checkbox's checked state to a signal: `{ checked, onchange }` props for `h`. */
233
+ export function bindcheck<T>(s: () => T): { checked: () => boolean; onchange: (e: Event) => void };
234
+
235
+
236
+ // ============================================================================
237
+ // Router (sigpro/router)
238
+ // ============================================================================
239
+ // Router (sigpro/router)
162
240
  // ============================================================================
163
241
 
164
242
  export interface RouteDefinition {
@@ -188,11 +266,8 @@ export const currentPath: Signal<string>;
188
266
  /** Current route params as a reactive signal. */
189
267
  export const routerParams: Signal<Record<string, string>>;
190
268
 
191
- /** Increments on HMR page registration; read to force route refresh. */
192
- export const hmrTick: Signal<number>;
193
-
194
269
  // ============================================================================
195
- // i18n
270
+ // i18n (sigpro/lang)
196
271
  // ============================================================================
197
272
 
198
273
  /** Active locale. Reactive. */
@@ -213,7 +288,7 @@ export function setLocale(locale: string): void;
213
288
  export function t(key: string): () => string;
214
289
 
215
290
  // ============================================================================
216
- // HTTP Helper
291
+ // HTTP Helper (sigpro/http)
217
292
  // ============================================================================
218
293
 
219
294
  /**
@@ -258,16 +333,12 @@ declare const SigPro: {
258
333
  watch: typeof watch;
259
334
  local: typeof local;
260
335
  h: typeof h;
336
+ slots: typeof slots;
261
337
  mount: typeof mount;
262
338
  unmount: typeof unmount;
263
339
  onMount: typeof onMount;
264
340
  onError: typeof onError;
265
- cleanupNode: typeof cleanupNode;
266
341
  exposeTags: typeof exposeTags;
267
- router: typeof router;
268
- currentPath: typeof currentPath;
269
- routerParams: typeof routerParams;
270
- hmrTick: typeof hmrTick;
271
342
  currentLocale: typeof currentLocale;
272
343
  addLang: typeof addLang;
273
344
  setLocale: typeof setLocale;
@@ -293,16 +364,12 @@ declare global {
293
364
  watch: typeof watch;
294
365
  local: typeof local;
295
366
  h: typeof h;
367
+ slots: typeof slots;
296
368
  mount: typeof mount;
297
369
  unmount: typeof unmount;
298
370
  onMount: typeof onMount;
299
371
  onError: typeof onError;
300
- cleanupNode: typeof cleanupNode;
301
372
  exposeTags: typeof exposeTags;
302
- router: typeof router;
303
- currentPath: typeof currentPath;
304
- routerParams: typeof routerParams;
305
- hmrTick: typeof hmrTick;
306
373
  currentLocale: typeof currentLocale;
307
374
  addLang: typeof addLang;
308
375
  setLocale: typeof setLocale;
@@ -0,0 +1,151 @@
1
+ // sigpro.convert.js
2
+
3
+ function html2sigpro(h, mode = "tags") {
4
+ const B = new Set(["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "ismap", "itemscope", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected", "truespeed"]);
5
+ const esc = v => v.replace(/"/g, '\\"');
6
+
7
+ const bP = el => {
8
+ let a = [...el.attributes].map(({ name: n, value: v }) =>
9
+ /^on/i.test(n) ? `${n}: (e) => { ${v.replace(/\s+/g, " ").trim()} }` :
10
+ (B.has(n.toLowerCase()) && (!v || v == n)) ? `${n}: true` : `${n}: "${esc(v)}"`
11
+ );
12
+ return a.length ? `{ ${a.join(", ")} }` : "";
13
+ };
14
+
15
+ const cN = (n, d = 0) => {
16
+ let s = " ".repeat(d);
17
+ if (n.nodeType == 3) {
18
+ let t = n.textContent;
19
+ return t.trim() ? `${s}"${esc(t)}"` : "";
20
+ }
21
+ if (n.nodeType == 1) {
22
+ let tag = n.tagName.toLowerCase();
23
+ let props = bP(n);
24
+ let prefix = mode === "core" ? `h('${tag}'` : tag;
25
+
26
+ let children = [...n.childNodes].map(i => cN(i, d + 1)).filter(Boolean);
27
+ const hasProps = !!props;
28
+
29
+ if (mode === "core") {
30
+ if (!children.length) return hasProps ? `${s}${prefix}, ${props})` : `${s}${prefix})`;
31
+ if (children.length === 1 && !children[0].includes("\n"))
32
+ return hasProps ? `${s}${prefix}, ${props}, ${children[0].trim()})` : `${s}${prefix}, ${children[0].trim()})`;
33
+ return hasProps
34
+ ? `${s}${prefix}, ${props},\n${children.join(",\n")}\n${s})`
35
+ : `${s}${prefix},\n${children.join(",\n")}\n${s})`;
36
+ } else {
37
+ if (!children.length) return hasProps ? `${s}${prefix}(${props})` : `${s}${prefix}`;
38
+ if (children.length === 1 && !children[0].includes("\n"))
39
+ return hasProps ? `${s}${prefix}(${props}, ${children[0].trim()})` : `${s}${prefix}(${children[0].trim()})`;
40
+ return hasProps
41
+ ? `${s}${prefix}(${props},\n${children.join(",\n")}\n${s})`
42
+ : `${s}${prefix}(\n${children.join(",\n")}\n${s})`;
43
+ }
44
+ }
45
+ return "";
46
+ };
47
+
48
+ const r = [...new DOMParser().parseFromString(h, "text/html").body.childNodes].map(n => cN(n)).filter(Boolean);
49
+ return r.length == 1 ? r[0].trim() : `\n${r.join(",\n")}\n`;
50
+ }
51
+
52
+ const converter = () => {
53
+ const { signal, effect } = window.SigPro;
54
+
55
+ const inH = signal("");
56
+ const outS = signal("");
57
+ const mode = signal("tags");
58
+ const previewHtml = signal("");
59
+
60
+ const cnv = () => {
61
+ try {
62
+ outS(html2sigpro(inH(), mode()));
63
+ } catch (e) {
64
+ outS("Error: " + e.message);
65
+ }
66
+ previewHtml(inH());
67
+ };
68
+
69
+ const clearAll = () => {
70
+ inH("");
71
+ outS("");
72
+ mode("tags");
73
+ previewHtml("");
74
+ };
75
+
76
+ const txS = "width:100%;height:200px;padding:10px;border:1px solid #ccc;border-radius:4px;font-family:monospace;font-size:14px;box-sizing:border-box;resize:vertical";
77
+ const btS = "padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-right:8px;font-size:14px";
78
+
79
+ return div({ style: "margin:20px auto;font-family:sans-serif" },
80
+ h1("HTML → SigPro"),
81
+ div({ style: "margin-bottom:10px" },
82
+ div({ style: "display:flex;gap:20px;flex-wrap:wrap;margin-top:5px" },
83
+ label({ style: "display:flex;align-items:center;gap:6px" },
84
+ "Core",
85
+ input({ type: "radio", name: "mode", value: "core", checked: () => mode() === "core", onchange: e => { if (e.target.checked) { mode("core"); cnv(); } } }),
86
+ span("core — h('tag', props, ...)")
87
+ ),
88
+ label({ style: "display:flex;align-items:center;gap:6px" },
89
+ "Tags",
90
+ input({ type: "radio", name: "mode", value: "tags", checked: () => mode() === "tags", onchange: e => { if (e.target.checked) { mode("tags"); cnv(); } } }),
91
+ span("tags — tag({ props }, ...)")
92
+ )
93
+ )
94
+ ),
95
+ div({ style: "margin-top:15px;display:flex;gap:10px" },
96
+ button({ style: btS + ";background:#3b82f6;color:#fff", onclick: cnv }, "Convert"),
97
+ button({ style: btS + ";background:#d1d5db", onclick: clearAll }, "Clear")
98
+ ),
99
+ div({ style: "display:grid;grid-template-columns:1fr;gap:15px;margin-top:15px;width:100%" },
100
+ div({ style: "border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column" },
101
+ label({ style: "font-weight:bold;margin-bottom:8px" }, "HTML Input"),
102
+ textarea({
103
+ style: txS,
104
+ placeholder: "Paste your HTML here...",
105
+ value: inH,
106
+ oninput: e => { inH(e.target.value); cnv(); }
107
+ })
108
+ ),
109
+ div({ style: "border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column" },
110
+ div({ style: "display:flex;justify-content:space-between;align-items:center;margin-bottom:8px" },
111
+ span({ style: "font-weight:bold" }, "SigPro Output"),
112
+ button({
113
+ style: "padding:4px 8px;background:#10b981;color:white;border:none;border-radius:4px;cursor:pointer;font-size:12px",
114
+ onclick: () => { navigator.clipboard.writeText(outS()); alert("Copied!"); }
115
+ }, "Copy")
116
+ ),
117
+ textarea({ style: txS + ";background:#f9fafb", readonly: true, value: outS, placeholder: "Converted code will appear here..." })
118
+ ),
119
+ div({ style: "border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column" },
120
+ label({ style: "font-weight:bold;margin-bottom:8px" }, "Live Preview"),
121
+ iframe({
122
+ style: "width:100%;height:200px;border:1px solid #e2e8f0;border-radius:4px;background:white;",
123
+ ref: el => effect(() => {
124
+ const html = previewHtml() || "";
125
+ el.srcdoc = `
126
+ <!DOCTYPE html>
127
+ <html>
128
+ <head>
129
+ <meta charset="UTF-8">
130
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
131
+ <link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
132
+ <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"><\/script>
133
+ <style>
134
+ body { padding: 10px; margin: 0; font-family: sans-serif; }
135
+ </style>
136
+ </head>
137
+ <body>
138
+ ${html}
139
+ </body>
140
+ </html>
141
+ `;
142
+ }),
143
+ sandbox: "allow-same-origin allow-scripts allow-popups allow-forms allow-modals"
144
+ })
145
+ )
146
+ )
147
+ );
148
+ };
149
+
150
+ window.html2sigpro = html2sigpro;
151
+ window.converter = converter;