sigpro 1.1.20 → 2.0.3

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
@@ -1,10 +1,12 @@
1
- # `SigPro` ⚛️
1
+ # `SigPro`
2
2
 
3
- ### **The Atomic Reactivity Engine for the Modern Web.**
3
+ Blazing fast, zero-overhead, vanilla JS renderer with atomic reactivity.
4
4
 
5
- **SigPro** is an ultra-lightweight rendering engine designed for extreme performance. By eliminating the Virtual DOM and heavy compilers, it achieves **surgical reactivity** in less than 2KB.
5
+ [![npm version](https://img.shields.io/npm/v/sigpro.svg)](https://www.npmjs.com/package/sigpro)
6
+ ![js size](https://img.shields.io/badge/js_size-~4_kB_brotli-blue)
7
+ [![license](https://img.shields.io/npm/l/sigpro)](https://github.com/natxocc/sigpro/blob/main/LICENSE)
6
8
 
7
- [**Explore the Docs →**](https://natxocc.github.io/sigpro/) | [**View on GitHub**](https://github.com/natxocc/sigpro)
9
+ [**Explore the Docs →**](https://sigpro.natxocc.com/#/)
8
10
 
9
11
  ---
10
12
 
@@ -14,40 +16,14 @@ After years of building within closed ecosystems like **React, Vue, or Svelte**
14
16
 
15
17
  That extra development time and the cognitive load of "learning the framework" instead of "learning the language" is exactly what **SigPro** eliminates. If the final destination is always JS, why not use a Pure JS-based system that drastically simplifies coding with a readable, vanilla, and remarkably fast architecture?
16
18
 
17
- * 🎯 **Atomic Precision:** Powered by a *Signal-based* architecture. State is bound directly to DOM nodes—when a value changes, **only that specific node updates**.
18
- * 🚀 **Zero-Hydration Bottlenecks:** No 100KB bundles or complex build steps. SigPro is pure, optimized JavaScript tailored for the browser's native engine.
19
- * 🍦 **Pure Vanilla JS Performance:** High-octane performance without the need for transpilers or heavy transformations. It runs natively in the browser just as well as it does in complex build pipelines.
20
- * 🛠️ **Build-Tool Agnostic:** Total freedom. Use it with **Vite, Webpack, or Rollup** for enterprise projects, or simply import it via a **`<script>` tag** for rapid prototyping. No tooling required.
21
- * 🚀 **Vite-Powered DX:** First-class Vite support with **file-based routing** out of the box. The official `sigpro/vite` plugin automatically scans your `src/pages` directory and generates reactive routes—no manual route configuration needed.
22
- * 📈 **Zero-Scale Bloat:** Unlike other frameworks where the bundle grows exponentially, SigPro's footprint remains **flat and predictable**. You only pay for the code you write.
23
- * 💎 **Premium DX (Developer Experience):** Forget boilerplate imports. SigPro injects an elegant, functional syntax (`Div()`, `Button()`, `Span()`) directly into your scope for a **"Zero-Import"** workflow.
24
- * 📦 **Fully Loaded:** Built-in Hash Routing, native **`localStorage` persistence**, and automatic lifecycle management (cleanups) included in less than 2KB.
25
- * 🌳 **Tree-Shakable:** Optimized for modern bundlers. Import only what you use, or load the full engine for rapid prototyping.
26
-
27
- -----
28
-
29
- ## ⚡ Real-World Benchmarks
30
-
31
- SigPro isn't just "fast on paper." In the industry-standard **JS Framework Benchmark**, it consistently outperforms the most popular libraries by operating at near-native speeds with almost zero memory overhead.
32
-
33
- ### 🚀 Execution Speed (CPU)
34
- *Lower is better. Measured in milliseconds (ms).*
35
-
36
- | Benchmark Test | **SigPro** | SolidJS | Vue 3 | React 18 |
37
- | :--- | :--- | :--- | :--- | :--- |
38
- | **Surgical Update** (10th row) | **46.8ms** | ~48ms | ~75ms | ~158ms |
39
- | **Direct Selection** (on click) | **17.5ms** | ~18ms | ~32ms | ~65ms |
40
- | **Initial Render** (1k rows) | **~35ms** | ~32ms | ~45ms | ~70ms |
41
-
42
- ### 🧠 Memory Footprint
43
- *Lower is better. Measured in Megabytes (MB) after 1k rows.*
44
-
45
- | Metric | **SigPro** | Vanilla JS | Svelte | React |
46
- | :--- | :--- | :--- | :--- | :--- |
47
- | **Ready Memory** (Idle) | **1.05 MB** | 1.01 MB | ~2.8 MB | ~10.4 MB |
48
- | **Run Memory** (1k rows) | **4.90 MB** | 4.25 MB | ~10.2 MB | ~28.5 MB |
49
-
50
- > **The Verdict:** SigPro delivers **Vanilla-like memory consumption** while maintaining **Surgical reactivity** that rivals (and often beats) SolidJS in granular updates.
19
+ * **Atomic Precision:** Powered by an **alien-signals**-class push-pull reactive core. State is bound directly to DOM nodes—when a value changes, **only that specific node updates**. No diffing, no virtual tree, no wasted work.
20
+ * **Zero-Hydration Bottlenecks:** No 100KB bundles or complex build steps. SigPro is pure, optimized JavaScript tailored for the browser's native engine.
21
+ * **Lazy Computation:** `computed()` is lazy and verified with `checkDirty`. Effects don't re-run when a dependency's value didn't actually change.
22
+ * **Build-Tool Agnostic:** Total freedom. Use it with **Vite, Webpack, or Rollup** for enterprise projects, or simply import it via a **`<script>` tag** for rapid prototyping. No tooling required.
23
+ * **Zero-Scale Bloat:** Unlike other frameworks where the bundle grows exponentially, SigPro's footprint remains **flat and predictable**.
24
+ * **Premium DX:** Forget boilerplate imports. SigPro injects an elegant, functional syntax (`div()`, `button()`, `span()`) directly into your scope for a **"Zero-Import"** workflow.
25
+ * **Fully Loaded:** Built-in Hash Routing, native **`localStorage` persistence**, **`provide`/`inject`** dependency injection, **SVG support**, and automatic cleanup of listeners and scopes—all in a single file.
26
+ * **No Memory Leaks:** Scopes cascade idempotently. Event listeners are tracked and removed with the node. Computeds die with their owners.
51
27
 
52
28
  -----
53
29
 
@@ -60,77 +36,181 @@ Create reactive, persistent components with a syntax that feels like Vanilla JS,
60
36
  ```
61
37
 
62
38
  ```javascript
39
+ import { signal, computed, mount, exposeTags } from "sigpro";
40
+
41
+ exposeTags();
42
+
63
43
  const Counter = () => {
64
44
  // Simple signal
65
- const value = $(100);
45
+ const value = signal(100);
66
46
  // One-line persistence: state survives page reloads automatically
67
- const count = $(0, "user-counter-pref");
68
- // Computed: automatically updated when count() or value() changes
69
- const doubleValue = $(()=> value() * count());
70
-
71
- // Create fast HTML with pure JS
72
- return Div({ class: "card" }, [
73
- H1(`Count: ${count()}, Reference: ${value()}, Double x Ref: ${doubleValue()}`),
74
- P("Atomic updates. Zero re-renders of the parent tree."),
75
- Button({ onclick: () => count(c => c + 1)}, "Increment +1")
47
+ const count = local("user-counter-pref",0); // use local() for persistence
48
+ const ref = signal(100);
49
+ const doubleValue = computed(() => value() * ref());
50
+
51
+ return div({ class: "card" }, [
52
+ h1(() => `Count: ${count()}, Reference: ${value()}, Double: ${doubleValue()}`),
53
+ p("Atomic updates. Zero re-renders of the parent tree."),
54
+ button({ onclick: () => count(count() + 1) }, "Increment +1")
76
55
  ]);
77
56
  };
78
57
 
79
- $mount(Counter, "#app");
58
+ mount(Counter, "#app");
80
59
  ```
81
60
 
82
61
  -----
83
62
 
84
- ## Performance Without Compromise
63
+ ## Core API
85
64
 
86
- | Feature | **SigPro** | React / Vue | Svelte |
87
- | :--- | :--- | :--- | :--- |
88
- | **Payload (Gzipped)** | **< 1.8KB** | ~30KB - 50KB | ~5KB (Compiled Runtime) |
89
- | **State Logic** | **Atomic Signals** | Virtual DOM Diffing | Compiler Dirty Bits |
90
- | **Update Speed** | **Direct Node Access** | Component Re-render | Block Reconciliation |
91
- | **Native Persistence** | **Included ($)** | Requires Plugins | Manual |
92
- | **Dependencies** | **Zero** | Many | Build Toolchain |
93
- | **Lifecycle Mgmt** | **Automatic (Cleanup Root)** | Manual / Hook-based | Manual / Hook-based |
94
- | **Routing** | **Reactive Hash ($router) + File-based (Vite)** | Virtual Router (External) | File-based / External |
95
- | **Learning Curve** | **Zero (Vanilla JS)** | Steep (JSX/Templates) | Medium (Directives) |
65
+ ### Reactivity
96
66
 
97
- -----
67
+ ```javascript
68
+ import {
69
+ signal, computed, effect, effectScope,
70
+ batch, untrack, watch, local, provide, inject
71
+ } from "sigpro";
72
+
73
+ const count = signal(0);
74
+ count(); // read
75
+ count(1); // write
76
+
77
+ const double = computed(() => count() * 2);
78
+ double(); // → 2, lazily evaluated
79
+
80
+ // Effect with cleanup
81
+ const stop = effect(() => {
82
+ const v = count();
83
+ console.log(v);
84
+ return () => console.log("cleanup");
85
+ });
86
+
87
+ // Scoped effects (cascade cleanup for children)
88
+ const dispose = effectScope(() => {
89
+ effect(() => console.log(count()));
90
+ effect(() => console.log(double()));
91
+ });
92
+
93
+ // Batching: defer flush until the end
94
+ batch(() => {
95
+ count(1);
96
+ count(2);
97
+ });
98
+
99
+ // Watch: skip initial run, receive old/new values
100
+ watch(count, (newval, oldval) => console.log(oldval, "→", newval));
101
+
102
+ // Untrack: read without subscribing
103
+ untrack(() => count());
104
+
105
+ // Persistent signal (localStorage-backed, JSON)
106
+ const theme = local("theme", "light");
107
+ theme("dark"); // stored, survives reloads
108
+
109
+ // Dependency injection
110
+ provide("theme", signal("dark"));
111
+ const t = inject("theme"); // nearest provider
112
+ ```
113
+
114
+ ### Rendering
115
+
116
+ ```javascript
117
+ import { h, mount, exposeTags } from "sigpro";
118
+
119
+ exposeTags(); // → window.div, window.span, window.button, etc.
120
+
121
+ // Static
122
+ div({ class: "card" }, "Hello");
123
+
124
+ // Reactive props
125
+ div({ class: () => active() ? "card active" : "card" });
126
+
127
+ // Reactive style
128
+ div({ style: () => open() ? "" : "display:none" });
98
129
 
99
- ## Scalable Architecture with Vite
100
-
101
- SigPro scales from micro-widgets to full enterprise dashboards. With the official Vite plugin, routing becomes effortless:
102
-
103
- ```text
104
- src/
105
- ├── 📂 pages/ # File-based routing (auto-scanned)
106
- │ ├── index.js # → /
107
- │ ├── about.js # → /about
108
- │ ├── blog/
109
- │ │ ├── index.js # → /blog
110
- │ │ └── [slug].js # → /blog/:slug
111
- │ └── docs/
112
- │ └── [...all].js # → /docs/*
113
- ├── 📂 components/ # Reusable components
114
- └── 📄 main.js # App Entry & Mounting
130
+ // Reactive children
131
+ div({}, () => items().map(i => li({}, i.name)));
132
+
133
+ // Events
134
+ button({ onclick: () => count(count() + 1) }, "+1");
135
+
136
+ // ref
137
+ input({ ref: el => el.focus() });
138
+
139
+ // innerHTML (reactive)
140
+ div({ html: () => markdown(run().text) });
141
+
142
+ // Two-way binding
143
+ input({ value: () => username(), oninput: e => username(e.target.value)})
144
+ ```
145
+
146
+ ### SVG
147
+
148
+ ```javascript
149
+ svg({ viewBox: "0 0 24 24" }, [
150
+ path({ d: "M9 12l2 2 4-4", stroke: "currentColor", fill: "none" })
151
+ ]);
152
+ ```
153
+
154
+ SVG tags are detected automatically. `class`, `style`, and every attribute go through `setAttribute` correctly.
155
+
156
+ ### Router
157
+
158
+ ```javascript
159
+ import { router } from "sigpro";
160
+
161
+ const App = router([
162
+ { path: "/", component: Home },
163
+ { path: "/about", component: About },
164
+ { path: "/blog/:slug", component: BlogPost },
165
+ { path: "*", component: NotFound }
166
+ ]);
167
+
168
+ router.to("/about");
169
+ router.back();
170
+ router.path(); // current path
115
171
  ```
116
172
 
117
- **Vite Plugin Setup:**
173
+ ### i18n
174
+
118
175
  ```javascript
119
- // vite.config.js
120
- import { defineConfig } from 'vite';
121
- import { sigproRouter } from 'sigpro/vite';
176
+ import { addLang, setLocale, t, tt } from "sigpro";
122
177
 
123
- export default defineConfig({
124
- plugins: [sigproRouter()]
178
+ addLang({
179
+ en: { hello: "Hello" },
180
+ es: { hello: "Hola" }
125
181
  });
182
+
183
+ setLocale("es");
184
+ tt("hello"); // "Hola"
185
+ t("hello")(); // "Hola" (reactive getter)
186
+ ```
187
+
188
+ ### HTTP Helper
189
+
190
+ ```javascript
191
+ import { db } from "sigpro";
192
+
193
+ const loading = signal(false);
194
+ const data = await db("/api/users", null, loading);
195
+
196
+ // POST
197
+ await db("/api/save", { name: "Ada" });
126
198
  ```
127
199
 
128
- The plugin automatically:
129
- - Scans your `src/pages` directory recursively
130
- - Generates route definitions from file paths
131
- - Supports dynamic segments (`[param]`) and catch-all routes (`[...param]`)
132
- - Provides automatic 404 fallback
133
- - Enables lazy-loading out of the box
200
+ -----
201
+
202
+ ## Performance Without Compromise
203
+
204
+ | Feature | **SigPro** | React / Vue | Svelte |
205
+ | :--- | :--- | :--- | :--- |
206
+ | **Payload (Brotli)** | **~4KB** | ~30KB - 50KB | ~5KB (Compiled Runtime) |
207
+ | **State Logic** | **Push-pull Signals** | Virtual DOM Diffing | Compiler Dirty Bits |
208
+ | **Update Speed** | **Direct Node Access** | Component Re-render | Block Reconciliation |
209
+ | **Native Persistence** | **`local()`** | Requires Plugins | Manual |
210
+ | **Dependencies** | **Zero** | Many | Build Toolchain |
211
+ | **Lifecycle Mgmt** | **Automatic (Scopes + `_cln`)** | Manual / Hook-based | Manual / Hook-based |
212
+ | **Routing** | **Reactive Hash Router** | Virtual Router (External) | File-based / External |
213
+ | **Learning Curve** | **Zero (Vanilla JS)** | Steep (JSX/Templates) | Medium (Directives) |
134
214
 
135
215
  -----
136
216
 
@@ -140,7 +220,7 @@ The plugin automatically:
140
220
  npm install sigpro
141
221
  ```
142
222
 
143
- **With Vite (Recommended for larger apps):**
223
+ **With Vite:**
144
224
  ```bash
145
225
  npm create vite@latest my-app -- --template vanilla
146
226
  cd my-app
@@ -154,6 +234,18 @@ npm install sigpro
154
234
 
155
235
  -----
156
236
 
237
+ ## What SigPro Is Not
238
+
239
+ SigPro is **not** a framework with a custom compiler, virtual DOM, or JSX transform. It is:
240
+
241
+ - **Vanilla JS** with a reactive core.
242
+ - **Explicit**: `signal()`, `computed()`, `effect()` — no overloaded operators, no magic argument-type dispatch.
243
+ - **Minimal**: only the primitives needed to build UIs, not a kitchen sink.
244
+
245
+ If you want JSX, file-based routing with auto-generation, or a component lifecycle DSL, SigPro is not that. If you want **the rawest, smallest reactive renderer that stays out of your way**, it is.
246
+
247
+ -----
248
+
157
249
  ## License
158
250
 
159
251
  MIT © 2026 **SigPro Team**.
@@ -0,0 +1,34 @@
1
+ var{signal:x}=window.SigPro;function f(s,l="tags"){let a=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"]),p=(o)=>o.replace(/"/g,"\\\""),c=(o)=>{let t=[...o.attributes].map(({name:e,value:n})=>/^on/i.test(e)?`${e}: (e) => { ${n.replace(/\s+/g," ").trim()} }`:a.has(e.toLowerCase())&&(!n||n==e)?`${e}: true`:`${e}: "${p(n)}"`);return t.length?`{ ${t.join(", ")} }`:""},m=(o,t=0)=>{let e=" ".repeat(t);if(o.nodeType==3){let n=o.textContent;return n.trim()?`${e}"${p(n)}"`:""}if(o.nodeType==1){let n=o.tagName.toLowerCase(),d=c(o),i=l==="core"?`h('${n}'`:n,r=[...o.childNodes].map((h)=>m(h,t+1)).filter(Boolean),g=!!d;if(l==="core"){if(!r.length)return g?`${e}${i}, ${d})`:`${e}${i})`;if(r.length===1&&!r[0].includes(`
2
+ `))return g?`${e}${i}, ${d}, ${r[0].trim()})`:`${e}${i}, ${r[0].trim()})`;return g?`${e}${i}, ${d},
3
+ ${r.join(`,
4
+ `)}
5
+ ${e})`:`${e}${i},
6
+ ${r.join(`,
7
+ `)}
8
+ ${e})`}else{if(!r.length)return g?`${e}${i}(${d})`:`${e}${i}`;if(r.length===1&&!r[0].includes(`
9
+ `))return g?`${e}${i}(${d}, ${r[0].trim()})`:`${e}${i}(${r[0].trim()})`;return g?`${e}${i}(${d},
10
+ ${r.join(`,
11
+ `)}
12
+ ${e})`:`${e}${i}(
13
+ ${r.join(`,
14
+ `)}
15
+ ${e})`}}return""},u=[...new DOMParser().parseFromString(s,"text/html").body.childNodes].map((o)=>m(o)).filter(Boolean);return u.length==1?u[0].trim():`
16
+ ${u.join(`,
17
+ `)}
18
+ `}var b=()=>{let s=x(""),l=x(""),a=x("tags"),p=x(""),c=()=>{try{l(f(s(),a()))}catch(t){l("Error: "+t.message)}p(s())},m=()=>{s(""),l(""),a("tags"),p("")},u="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",o="padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-right:8px;font-size:14px";return div({style:"margin:20px auto;font-family:sans-serif"},h1("HTML → SigPro"),div({style:"margin-bottom:10px"},div({style:"display:flex;gap:20px;flex-wrap:wrap;margin-top:5px"},label({style:"display:flex;align-items:center;gap:6px"},"Core",input({type:"radio",name:"mode",value:"core",checked:()=>a()==="core",onchange:(t)=>{if(t.target.checked)a("core"),c()}}),span("core — h('tag', props, ...)")),label({style:"display:flex;align-items:center;gap:6px"},"Tags",input({type:"radio",name:"mode",value:"tags",checked:()=>a()==="tags",onchange:(t)=>{if(t.target.checked)a("tags"),c()}}),span("tags — tag({ props }, ...)")))),div({style:"margin-top:15px;display:flex;gap:10px"},button({style:"padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-right:8px;font-size:14px;background:#3b82f6;color:#fff",onclick:c},"Convert"),button({style:"padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-right:8px;font-size:14px;background:#d1d5db",onclick:m},"Clear")),div({style:"display:grid;grid-template-columns:1fr;gap:15px;margin-top:15px;width:100%"},div({style:"border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column"},label({style:"font-weight:bold;margin-bottom:8px"},"HTML Input"),textarea({style:"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",placeholder:"Paste your HTML here...",value:s,oninput:(t)=>{s(t.target.value),c()}})),div({style:"border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column"},div({style:"display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"},span({style:"font-weight:bold"},"SigPro Output"),button({style:"padding:4px 8px;background:#10b981;color:white;border:none;border-radius:4px;cursor:pointer;font-size:12px",onclick:()=>{navigator.clipboard.writeText(l()),alert("Copied!")}},"Copy")),textarea({style:"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;background:#f9fafb",readonly:!0,value:l,placeholder:"Converted code will appear here..."})),div({style:"border:1px solid #ccc;border-radius:8px;padding:10px;display:flex;flex-direction:column"},label({style:"font-weight:bold;margin-bottom:8px"},"Live Preview"),iframe({style:"width:100%;height:200px;border:1px solid #e2e8f0;border-radius:4px;background:white;",srcdoc:()=>{return`
19
+ <!DOCTYPE html>
20
+ <html>
21
+ <head>
22
+ <meta charset="UTF-8">
23
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
24
+ <link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
25
+ <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
26
+ <style>
27
+ body { padding: 10px; margin: 0; font-family: sans-serif; }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ ${p()||""}
32
+ </body>
33
+ </html>
34
+ `},sandbox:"allow-same-origin allow-scripts allow-popups allow-forms allow-modals"}))))};window.html2sigpro=f;window.converter=b;
@@ -0,0 +1 @@
1
+ function X({update:e,notify:t,unwatched:i}){return{link:o,unlink:c,propagate:b,checkDirty:T,shallowPropagate:d};function o(n,s,p){let g=s.depsTail;if(g!==void 0&&g.dep===n)return;let r=g!==void 0?g.nextDep:s.deps;if(r!==void 0&&r.dep===n){r.version=p,s.depsTail=r;return}let f=n.subsTail;if(f!==void 0&&f.version===p&&f.sub===s)return;let v=s.depsTail=n.subsTail={version:p,dep:n,sub:s,prevDep:g,nextDep:r,prevSub:f,nextSub:void 0};if(r!==void 0)r.prevDep=v;if(g!==void 0)g.nextDep=v;else s.deps=v;if(f!==void 0)f.nextSub=v;else n.subs=v}function c(n,s=n.sub){let{dep:p,prevDep:g,nextDep:r,nextSub:f,prevSub:v}=n;if(r!==void 0)r.prevDep=g;else s.depsTail=g;if(g!==void 0)g.nextDep=r;else s.deps=r;if(f!==void 0)f.prevSub=v;else p.subsTail=v;if(v!==void 0)v.nextSub=f;else if((p.subs=f)===void 0)i(p);return r}function b(n,s){let p=n.nextSub,g;e:do{let r=n.sub,f=r.flags;if(!(f&60)){if(r.flags=f|32,s)r.flags|=8}else if(!(f&12))f=0;else if(!(f&4))r.flags=f&-9|32;else if(!(f&48)&&u(n,r))r.flags=f|8|32,f&=1;else f=0;if(f&2)t(r);if(f&1){let v=r.subs;if(v!==void 0){let x=(n=v).nextSub;if(x!==void 0)g={value:p,prev:g},p=x;continue}}if((n=p)!==void 0){p=n.nextSub;continue}while(g!==void 0)if(n=g.value,g=g.prev,n!==void 0){p=n.nextSub;continue e}break}while(!0)}function T(n,s){let p,g=0,r=!1;e:do{let f=n.dep,v=f.flags;if(s.flags&16)r=!0;else if((v&17)===17){let x=f.subs;if(e(f)){if(x.nextSub!==void 0)d(x);r=!0}}else if((v&33)===33){p={value:n,prev:p},n=f.deps,s=f,++g;continue}if(!r){let x=n.nextDep;if(x!==void 0){n=x;continue}}while(g--){if(n=p.value,p=p.prev,r){let h=s.subs;if(e(s)){if(h.nextSub!==void 0)d(h);s=n.sub;continue}r=!1}else s.flags&=-33;s=n.sub;let x=n.nextDep;if(x!==void 0){n=x;continue e}}return r&&!!s.flags}while(!0)}function d(n){do{let s=n.sub,p=s.flags;if((p&48)===32){if(s.flags=p|16,(p&6)===2)t(s)}}while((n=n.nextSub)!==void 0)}function u(n,s){let p=s.depsTail;while(p!==void 0){if(p===n)return!0;p=p.prevDep}return!1}}var R=0,_=0,K=0,L=0,E=0,y,S=[],D=[];var{link:P,unlink:M,propagate:z,checkDirty:ee,shallowPropagate:te}=X({update(e){if("getter"in e)return ie(e);if("currentValue"in e)return I(e);return e.flags=1,!0},notify(e){let t=E,i=t;do if(S[t++]=e,e.flags&=-3,e=e.subs?.sub,e===void 0||!(e.flags&2))break;while(!0);E=t;while(i<--t){let o=S[i];S[i++]=S[t],S[t]=o}},unwatched(e){if("getter"in e){if(e.depsTail!==void 0)e.flags=17,F(e)}else if("currentValue"in e);else if("fn"in e)W.call(e);else Q.call(e)}});function k(e){return oe.bind({currentValue:e,pendingValue:e,subs:void 0,subsTail:void 0,flags:1})}function N(e){let t={fn:e,cleanup:void 0,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:6},i=y;if(y=t,i!==void 0)P(t,i,0),i.flags|=64;D.push(new Map);try{++_;let o=t.fn();t.cleanup=typeof o==="function"?o:void 0}finally{--_,y=i,D.pop(),t.flags&=-5}return W.bind(t)}function $(e){let t={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:1},i=y;if(y=t,i!==void 0)P(t,i,0),i.flags|=64;D.push(new Map);try{e()}finally{D.pop(),y=i}return Q.bind(t)}function ie(e){if(e.flags&64){let i=e.depsTail;while(i!==void 0){let{prevDep:o,dep:c}=i;if(!("getter"in c)&&!("currentValue"in c))M(i,e);i=o}}e.depsTail=void 0,e.flags=5;let t=y;y=e;try{++R;let i=e.value;return i!==(e.value=e.getter(i))}finally{y=t,e.flags&=-5,G(e)}}function I(e){return e.flags=1,e.currentValue!==(e.currentValue=e.pendingValue)}function ne(e){let t=e.flags;if(t&16||t&32&&ee(e.deps,e)){if(t&64){let o=e.depsTail;while(o!==void 0){let{prevDep:c,dep:b}=o;if(!("getter"in b)&&!("currentValue"in b))M(o,e);o=c}}if(e.cleanup){if(B(e),!e.flags)return}e.depsTail=void 0,e.flags=6;let i=y;y=e,D.push(new Map);try{++R,++_;let o=e.fn();e.cleanup=typeof o==="function"?o:void 0}finally{--_,y=i,D.pop(),e.flags&=-5,G(e)}}else if(e.deps!==void 0)e.flags=2|t&64}function le(){try{while(L<E){let e=S[L];S[L++]=void 0,ne(e)}}finally{while(L<E){let e=S[L];S[L++]=void 0,e.flags|=10}L=0,E=0}}function oe(...e){if(e.length){if(this.pendingValue!==(this.pendingValue=e[0])){this.flags=17;let t=this.subs;if(t!==void 0){if(z(t,!!_),!K)le()}}}else{if(this.flags&16){if(I(this)){let i=this.subs;if(i!==void 0)te(i)}}let t=y;if(t!==void 0)P(this,t,R);return this.currentValue}}function B(e){let t=e.cleanup;e.cleanup=void 0;let i=y;y=void 0;try{t()}finally{y=i}}function W(){if(Q.call(this),this.cleanup)B(this)}function Q(){this.flags=0,F(this);let e=this.subs;if(e!==void 0)M(e)}function F(e){let t=e.depsTail;while(t!==void 0){let i=t.prevDep;M(t,e),t=i}}function G(e){let t=e.depsTail,i=t!==void 0?t.nextDep:e.deps;while(i!==void 0)i=M(i,e)}var A=typeof document<"u"?document:null,re="http://www.w3.org/2000/svg",ae=new Set("svg path circle rect line polyline polygon g defs text textPath tspan use symbol image marker ellipse foreignObject clipPath mask linearGradient radialGradient pattern filter stop animate animateMotion animateTransform view desc metadata title switch feGaussianBlur feOffset feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feImage feMerge feMergeNode feMorphology fePointLight feSpecularLighting feSpotLight feTile feTurbulence".split(" "));function O(e,t,i,o){if(t==="class"||t==="className"){if(o)if(i==null||i===!1)e.removeAttribute("class");else e.setAttribute("class",i===!0?"":i);else e.className=i??"";return}if(i==null||i===!1){e.removeAttribute(t);return}if(t==="style"&&typeof i==="string"){e.setAttribute("style",i);return}if(o){e.setAttribute(t,i===!0?"":i);return}if(t in e&&typeof e[t]!=="function")e[t]=i;else e.setAttribute(t,i===!0?"":i)}function se(e){let t=[e];while(t.length){let i=t.pop();if(i._stopScope)i._stopScope(),i._stopScope=null;if(i._cln){for(let o of i._cln)o();i._cln=null}for(let o=0;o<i.childNodes.length;o++)t.push(i.childNodes[o])}}function U(e,t={},...i){if(typeof e==="function"){let d,u=$(()=>{d=e(t,i)}),n=(s)=>{if(s instanceof Node)s._stopScope=u;else if(Array.isArray(s))s.forEach(n)};return n(d),d}if(t instanceof Node||Array.isArray(t)||t!==null&&typeof t!=="object"||t===void 0)i=[t,...i],t={};let o=ae.has(e),c=o?A.createElementNS(re,e):A.createElement(e),b,T=!1;for(let d in t){let u=t[d];if(d==="ref"){if(typeof u==="function")u(c);else if(u!=null&&typeof u==="object")u.current=c;continue}if(e==="select"&&d==="value"){b=u;continue}if(d==="html"){if(T=!0,typeof u==="function")N(()=>{c.innerHTML=u()??""});else c.innerHTML=u??"";continue}if(d.startsWith("on")&&typeof u==="function"){let n=d.slice(2).toLowerCase();c.addEventListener(n,u),(c._cln||(c._cln=[])).push(()=>c.removeEventListener(n,u))}else if(typeof u==="function")N(()=>O(c,d,u(),o));else O(c,d,u,o)}if(!T){let d=(u)=>{if(Array.isArray(u)){for(let n of u)d(n);return}if(u==null||u===!1||u===!0)return;if(typeof u==="function"){let n=A.createComment("");c.appendChild(n),N(()=>{let s=u(),p=Array.isArray(s)?s:[s],g=[];for(let r of p){if(r==null||r===!1||r===!0)continue;g.push(r instanceof Node?r:A.createTextNode(String(r)))}for(let r of g)c.insertBefore(r,n);return()=>{for(let r of g)se(r),r.remove()}});return}c.appendChild(u instanceof Node?u:A.createTextNode(String(u)))};d(i)}if(b!==void 0)if(typeof b==="function")N(()=>O(c,"value",b(),o));else O(c,"value",b,o);return c}var fe="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 table tbody td template textarea tfoot th thead time tr u ul video",Z=(e=typeof window<"u"?window:null)=>{if(!e)return;for(let t of fe.split(" "))e[t]=(i,...o)=>U(t,i,...o)},V=k(typeof window<"u"?window.location.hash.slice(1)||"/":"/"),ue=k({});if(typeof window<"u")window.addEventListener("hashchange",()=>{V(window.location.hash.slice(1)||"/")});var q=(e)=>()=>{let t=U("div",{class:"router-hook"});return N(()=>{let i=V().split("/").filter(Boolean);return $(()=>{let o=e.find((d)=>{let u=d.path.split("/").filter(Boolean);return u.length===i.length&&u.every((n,s)=>n[0]===":"||n===i[s])})||e.find((d)=>d.path==="*");if(!o){t.replaceChildren();return}let c={};o.path.split("/").filter(Boolean).forEach((d,u)=>{if(d[0]===":")c[d.slice(1)]=i[u]}),ue(c);let b=typeof o.component==="function"?U(o.component,c):o.component,T=b==null?[]:Array.isArray(b)?b:[b];t.replaceChildren(...T)})}),t};q.to=(e)=>{if(typeof window<"u")window.location.hash=e.replace(/^#?\/?/,"#/")};q.back=()=>{if(typeof window<"u")window.history.back()};q.path=()=>V();var ce=k("en");Z();var Y=(e)=>typeof e==="function",ge=(e)=>{let{value:t,class:i}=e,o=k(0),c=k(""),b=k(0),T=k(0),d=k(0),u=()=>window.getSelection().rangeCount?window.getSelection().getRangeAt(0):0,n,s,p="\uD83D\uDE00 \uD83D\uDE0A \uD83D\uDE09 \uD83E\uDDD0 \uD83D\uDE2E \uD83E\uDD14 \uD83D\uDE05 \uD83D\uDE02 \uD83D\uDE0D \uD83D\uDE18 \uD83E\uDD70 \uD83D\uDC4D \uD83D\uDC4E \uD83D\uDC4C \uD83E\uDD1D \uD83E\uDD1E \uD83D\uDC4B \uD83D\uDC4F \uD83D\uDE4C \uD83D\uDE4F \uD83D\uDCAA ☝️ \uD83D\uDC47 \uD83D\uDC48 \uD83D\uDC49 \uD83D\uDD95 ✅ ⚠️ \uD83D\uDE80 \uD83D\uDCE2 ✉️ ❤️".split(" "),g=()=>{T(T()+1),n&&b(n.innerText.length)},r=()=>{if(n){let l=n.innerHTML;Y(t)?t(l):e.onchange?.(l),g()}},f=(l,w=null)=>{if(n?.focus(),s){let m=window.getSelection();m.removeAllRanges(),m.addRange(s)}document.execCommand(l,0,w),s=0,r()},v=(l,w=null)=>{if(T(),!n||o())return 0;try{if(l=="formatBlock"){let m=window.getSelection().getRangeAt(0).commonAncestorContainer;while(m&&m!==n){if(m.tagName===w)return 1;m=m.parentNode}return 0}return document.queryCommandState(l)}catch(m){return 0}},x=(l)=>{if(l){let w=new FileReader;w.onload=(m)=>{let j=l.type.startsWith("image/"),H=m.target.result;f("insertHTML",j?div({style:"display:inline-block;resize:both;overflow:hidden;vertical-align:bottom;width:200px;border:1px dashed #ccc;padding:2px;cursor:pointer",class:"resizable-img-container"},[img({src:H,style:"width:100%;height:100%;object-fit:contain;pointer-events:none"})]):a({href:H,download:l.name,contenteditable:"false",style:"display:inline-flex;align-items:center;gap:5px;padding:4px 8px;border:1px solid #ccc;border-radius:4px;background:#f9f9f9;text-decoration:none;color:#333;font-size:12px;margin:2px;cursor:pointer"},[span({class:"icon-[lucide--paperclip] w-3 h-3"}),l.name]))},w.readAsDataURL(l)}},h=(l,w,m)=>button({type:"button",class:()=>`btn btn-ghost btn-xs ${v(w,m)?"btn-active bg-primary/20":""}`,onclick:()=>typeof w=="function"?w():f(w,m)},[span({class:`icon-[lucide--${l}]`})]);return div({class:`border border-base-300 rounded-box bg-base-100 overflow-hidden flex flex-col ${i||""}`},[div({class:"flex flex-wrap items-center gap-1 p-2 border-b border-base-300 bg-base-200 sticky top-0 z-20"},[div({class:"flex flex-wrap gap-1 flex-1"},[h("bold","bold"),h("italic","italic"),h("underline","underline"),input({type:"color",class:"w-5 h-5 p-0 bg-transparent cursor-pointer",oninput:(l)=>f("foreColor",l.target.value)}),span({class:"w-px h-5 bg-base-300 mx-1"}),h("align-left","justifyLeft"),h("align-center","justifyCenter"),h("align-right","justifyRight"),span({class:"w-px h-5 bg-base-300 mx-1"}),h("list","insertUnorderedList"),h("list-ordered","insertOrderedList"),h("indent-decrease","outdent"),h("indent-increase","indent"),h("quote",()=>f("formatBlock",v("formatBlock","BLOCKQUOTE")?"P":"BLOCKQUOTE"),"BLOCKQUOTE"),span({class:"w-px h-5 bg-base-300 mx-1"}),h("link",()=>{let l=prompt("URL:");l&&f("createLink",l)}),h("paperclip",()=>{let l=document.createElement("input");l.type="file",l.onchange=(w)=>x(w.target.files[0]),l.click()}),div({class:"relative"},[h("smile",()=>{s=u(),d(!d())}),div({class:"absolute top-full left-0 mt-1 p-2 bg-base-100 border shadow-xl rounded-box w-52 z-50 flex flex-wrap gap-1",style:()=>d()?"":"display:none"},p.map((l)=>span({class:"cursor-pointer p-1 text-lg",onclick:()=>{f("insertText",l),d(0)}},l)))]),h("undo-2","undo"),h("redo-2","redo")]),h("code-2",()=>{if(!o())c(n?.innerHTML||"");else if(n)n.innerHTML=c(),r();o(!o())})]),div({class:"relative flex-1 flex flex-col",onclick:()=>d(0)},[div({ref:(l)=>{if(l&&!n)n=l,l.innerHTML=(Y(t)?t():t)||"",document.execCommand("defaultParagraphSeparator",0,"br"),l.onclick=(w)=>{let m=w.target.closest(".resizable-img-container");if(m){let j=m.querySelector("img");j&&((H)=>{let C=document.createElement("div");C.style="position:fixed;top:0;left:0;width:100%;height:100%;background:#000e;z-index:9999;display:flex;align-items:center;justify-content:center;cursor:zoom-out",C.onclick=()=>C.remove();let J=document.createElement("img");J.src=H,J.style="max-width:95%;max-height:95%",C.appendChild(J),document.body.appendChild(C)})(j.src)}}},style:()=>`min-height:22rem;${o()?"display:none":""}`,class:"p-4 outline-none text-base-content leading-relaxed [&>div]:m-0 [&>p]:m-0 [&>div]:min-h-[1em] [&_.resizable-img-container]:hover:border-primary [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_blockquote]:italic [&_ul]:list-disc [&_ul]:pl-8 [&_ol]:list-decimal [&_ol]:pl-8",contenteditable:"true",oninput:r,onkeydown:(l)=>l.key==="Tab"&&(l.preventDefault(),f("indent")),onkeyup:()=>{g(),s=u()},onmouseup:r,onpaste:(l)=>{l.preventDefault(),f("insertText",l.clipboardData.getData("text/plain"))},ondrop:(l)=>{l.preventDefault(),x(l.dataTransfer.files[0])},ondragover:(l)=>l.preventDefault()}),textarea({class:"w-full flex-1 min-h-[22rem] p-4 font-mono text-sm bg-base-200 border-0",style:()=>o()?"":"display:none",value:c,oninput:(l)=>{if(c(l.target.value),n)n.innerHTML=l.target.value;e.onchange?.(l.target.value)}})]),div({class:"px-3 py-1 border-t text-[10px] text-right opacity-60"},[span(()=>b())])])};export{ge as Editor};