sigpro 1.2.40 → 2.0.4

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,9 +1,9 @@
1
- Blazing fast, zero-overhead, vanilla JS renderer with atomic reactivity.
2
-
3
1
  # `SigPro`
4
2
 
3
+ Blazing fast, zero-overhead, vanilla JS renderer with atomic reactivity.
4
+
5
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-2.8_kB_brotli-blue)
6
+ ![js size](https://img.shields.io/badge/js_size-~4_kB_brotli-blue)
7
7
  [![license](https://img.shields.io/npm/l/sigpro)](https://github.com/natxocc/sigpro/blob/main/LICENSE)
8
8
 
9
9
  [**Explore the Docs →**](https://sigpro.natxocc.com/#/)
@@ -16,40 +16,14 @@ After years of building within closed ecosystems like **React, Vue, or Svelte**
16
16
 
17
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?
18
18
 
19
- * **Atomic Precision:** Powered by a *Signal-based* architecture. State is bound directly to DOM nodes—when a value changes, **only that specific node 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
20
  * **Zero-Hydration Bottlenecks:** No 100KB bundles or complex build steps. SigPro is pure, optimized JavaScript tailored for the browser's native engine.
21
- * **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.
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
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
- * **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.
24
- * **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.
25
- * **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.
26
- * **Fully Loaded:** Built-in Hash Routing, native **`localStorage` persistence**, and automatic lifecycle management (cleanups) included in less than 2KB.
27
- * **Tree-Shakable:** Optimized for modern bundlers. Import only what you use, or load the full engine for rapid prototyping.
28
-
29
- -----
30
-
31
- ## Real-World Benchmarks
32
-
33
- 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.
34
-
35
- ### Execution Speed (CPU)
36
- *Lower is better. Measured in milliseconds (ms).*
37
-
38
- | Benchmark Test | **SigPro** | SolidJS | Vue 3 | React 18 |
39
- | :--- | :--- | :--- | :--- | :--- |
40
- | **Surgical Update** (10th row) | **46.8ms** | ~48ms | ~75ms | ~158ms |
41
- | **Direct Selection** (on click) | **17.5ms** | ~18ms | ~32ms | ~65ms |
42
- | **Initial Render** (1k rows) | **~35ms** | ~32ms | ~45ms | ~70ms |
43
-
44
- ### Memory Footprint
45
- *Lower is better. Measured in Megabytes (MB) after 1k rows.*
46
-
47
- | Metric | **SigPro** | Vanilla JS | Svelte | React |
48
- | :--- | :--- | :--- | :--- | :--- |
49
- | **Ready Memory** (Idle) | **1.05 MB** | 1.01 MB | ~2.8 MB | ~10.4 MB |
50
- | **Run Memory** (1k rows) | **4.90 MB** | 4.25 MB | ~10.2 MB | ~28.5 MB |
51
-
52
- > **The Verdict:** SigPro delivers **Vanilla-like memory consumption** while maintaining **Surgical reactivity** that rivals (and often beats) SolidJS in granular updates.
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.
53
27
 
54
28
  -----
55
29
 
@@ -62,21 +36,22 @@ Create reactive, persistent components with a syntax that feels like Vanilla JS,
62
36
  ```
63
37
 
64
38
  ```javascript
65
- import { $, mount } from "sigpro";
39
+ import { signal, computed, mount, exposeTags } from "sigpro";
40
+
41
+ exposeTags();
66
42
 
67
43
  const Counter = () => {
68
44
  // Simple signal
69
- const value = $(100);
45
+ const value = signal(100);
70
46
  // One-line persistence: state survives page reloads automatically
71
- const count = $(0, "user-counter-pref");
72
- // Computed: automatically updated when count() or value() changes
73
- const doubleValue = $(()=> value() * count());
47
+ const count = local("user-counter-pref",0); // use local() for persistence
48
+ const ref = signal(100);
49
+ const doubleValue = computed(() => value() * ref());
74
50
 
75
- // Create fast HTML with pure JS
76
51
  return div({ class: "card" }, [
77
- h1(() => `Count: ${count()}, Reference: ${value()}, Double x Ref: ${doubleValue()}`),
52
+ h1(() => `Count: ${count()}, Reference: ${value()}, Double: ${doubleValue()}`),
78
53
  p("Atomic updates. Zero re-renders of the parent tree."),
79
- button({ onclick: () => count(c => c + 1)}, "Increment +1")
54
+ button({ onclick: () => count(count() + 1) }, "Increment +1")
80
55
  ]);
81
56
  };
82
57
 
@@ -85,56 +60,157 @@ mount(Counter, "#app");
85
60
 
86
61
  -----
87
62
 
88
- ## Performance Without Compromise
63
+ ## Core API
89
64
 
90
- | Feature | **SigPro** | React / Vue | Svelte |
91
- | :--- | :--- | :--- | :--- |
92
- | **Payload (Gzipped)** | **<3KB** | ~30KB - 50KB | ~5KB (Compiled Runtime) |
93
- | **State Logic** | **Atomic Signals** | Virtual DOM Diffing | Compiler Dirty Bits |
94
- | **Update Speed** | **Direct Node Access** | Component Re-render | Block Reconciliation |
95
- | **Native Persistence** | **Included ($)** | Requires Plugins | Manual |
96
- | **Dependencies** | **Zero** | Many | Build Toolchain |
97
- | **Lifecycle Mgmt** | **Automatic (Cleanup Root)** | Manual / Hook-based | Manual / Hook-based |
98
- | **Routing** | **Reactive Hash (Router) + File-based (Vite)** | Virtual Router (External) | File-based / External |
99
- | **Learning Curve** | **Zero (Vanilla JS)** | Steep (JSX/Templates) | Medium (Directives) |
65
+ ### Reactivity
100
66
 
101
- -----
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());
102
104
 
103
- ## Scalable Architecture with Vite
104
-
105
- SigPro scales from micro-widgets to full enterprise dashboards. With the official Vite plugin, routing becomes effortless:
106
-
107
- ```text
108
- src/
109
- ├── 📂 pages/ # File-based routing (auto-scanned)
110
- │ ├── index.js # → /
111
- │ ├── about.js # → /about
112
- │ ├── blog/
113
- │ │ ├── index.js # → /blog
114
- │ │ └── [slug].js # → /blog/:slug
115
- │ └── docs/
116
- │ └── [...all].js # → /docs/*
117
- ├── 📂 components/ # Reusable components
118
- └── 📄 main.js # App Entry & Mounting
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
119
112
  ```
120
113
 
121
- **Vite Plugin Setup:**
114
+ ### Rendering
115
+
122
116
  ```javascript
123
- // vite.config.js
124
- import { defineConfig } from 'vite';
125
- import { sigproRouter } from 'sigpro/router';
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" });
129
+
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() });
126
138
 
127
- export default defineConfig({
128
- plugins: [sigproRouter()]
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
171
+ ```
172
+
173
+ ### i18n
174
+
175
+ ```javascript
176
+ import { addLang, setLocale, t, tt } from "sigpro";
177
+
178
+ addLang({
179
+ en: { hello: "Hello" },
180
+ es: { hello: "Hola" }
129
181
  });
182
+
183
+ setLocale("es");
184
+ tt("hello"); // "Hola"
185
+ t("hello")(); // "Hola" (reactive getter)
130
186
  ```
131
187
 
132
- The plugin automatically:
133
- - Scans your `src/pages` directory recursively
134
- - Generates route definitions from file paths
135
- - Supports dynamic segments (`[param]`) and catch-all routes (`[...param]`)
136
- - Provides automatic 404 fallback
137
- - Enables lazy-loading out of the box
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" });
198
+ ```
199
+
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) |
138
214
 
139
215
  -----
140
216
 
@@ -144,7 +220,7 @@ The plugin automatically:
144
220
  npm install sigpro
145
221
  ```
146
222
 
147
- **With Vite (Recommended for larger apps):**
223
+ **With Vite:**
148
224
  ```bash
149
225
  npm create vite@latest my-app -- --template vanilla
150
226
  cd my-app
@@ -158,6 +234,18 @@ npm install sigpro
158
234
 
159
235
  -----
160
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
+
161
249
  ## License
162
250
 
163
251
  MIT © 2026 **SigPro Team**.
@@ -0,0 +1,34 @@
1
+ function x(p,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"]),i=(r)=>r.replace(/"/g,"\\\""),m=(r)=>{let c=[...r.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}: "${i(n)}"`);return c.length?`{ ${c.join(", ")} }`:""},s=(r,c=0)=>{let e=" ".repeat(c);if(r.nodeType==3){let n=r.textContent;return n.trim()?`${e}"${i(n)}"`:""}if(r.nodeType==1){let n=r.tagName.toLowerCase(),d=m(r),o=l==="core"?`h('${n}'`:n,t=[...r.childNodes].map((f)=>s(f,c+1)).filter(Boolean),g=!!d;if(l==="core"){if(!t.length)return g?`${e}${o}, ${d})`:`${e}${o})`;if(t.length===1&&!t[0].includes(`
2
+ `))return g?`${e}${o}, ${d}, ${t[0].trim()})`:`${e}${o}, ${t[0].trim()})`;return g?`${e}${o}, ${d},
3
+ ${t.join(`,
4
+ `)}
5
+ ${e})`:`${e}${o},
6
+ ${t.join(`,
7
+ `)}
8
+ ${e})`}else{if(!t.length)return g?`${e}${o}(${d})`:`${e}${o}`;if(t.length===1&&!t[0].includes(`
9
+ `))return g?`${e}${o}(${d}, ${t[0].trim()})`:`${e}${o}(${t[0].trim()})`;return g?`${e}${o}(${d},
10
+ ${t.join(`,
11
+ `)}
12
+ ${e})`:`${e}${o}(
13
+ ${t.join(`,
14
+ `)}
15
+ ${e})`}}return""},u=[...new DOMParser().parseFromString(p,"text/html").body.childNodes].map((r)=>s(r)).filter(Boolean);return u.length==1?u[0].trim():`
16
+ ${u.join(`,
17
+ `)}
18
+ `}var h=()=>{let{signal:p}=window.SigPro,l=p(""),a=p(""),i=p("tags"),m=p(""),s=()=>{try{a(x(l(),i()))}catch(e){a("Error: "+e.message)}m(l())},u=()=>{l(""),a(""),i("tags"),m("")},r="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",c="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:()=>i()==="core",onchange:(e)=>{if(e.target.checked)i("core"),s()}}),span("core — h('tag', props, ...)")),label({style:"display:flex;align-items:center;gap:6px"},"Tags",input({type:"radio",name:"mode",value:"tags",checked:()=>i()==="tags",onchange:(e)=>{if(e.target.checked)i("tags"),s()}}),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:s},"Convert"),button({style:"padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-right:8px;font-size:14px;background:#d1d5db",onclick:u},"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:l,oninput:(e)=>{l(e.target.value),s()}})),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(a()),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:a,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
+ ${m()||""}
32
+ </body>
33
+ </html>
34
+ `},sandbox:"allow-same-origin allow-scripts allow-popups allow-forms allow-modals"}))))};window.html2sigpro=x;window.converter=h;
@@ -1 +1 @@
1
- var{$:u,isF:C}=window.SigPro,S=(x)=>{let{value:s,class:z}=x,l=u(0),g=u(""),v=u(0),h=u(0),c=u(0),w=()=>window.getSelection().rangeCount?window.getSelection().getRangeAt(0):0,o,d,R="\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(" "),k=()=>{h(h()+1),o&&v(o.innerText.length)},b=()=>{if(o){let e=o.innerHTML;C(s)?s(e):x.onchange?.(e),k()}},r=(e,i=null)=>{if(o?.focus(),d){let n=window.getSelection();n.removeAllRanges(),n.addRange(d)}document.execCommand(e,0,i),d=0,b()},L=(e,i=null)=>{if(h(),!o||l())return 0;try{if(e=="formatBlock"){let n=window.getSelection().getRangeAt(0).commonAncestorContainer;while(n&&n!==o){if(n.tagName===i)return 1;n=n.parentNode}return 0}return document.queryCommandState(e)}catch(n){return 0}},T=(e)=>{if(e){let i=new FileReader;i.onload=(n)=>{let f=e.type.startsWith("image/"),m=n.target.result;r("insertHTML",f?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:m,style:"width:100%;height:100%;object-fit:contain;pointer-events:none"})]):a({href:m,download:e.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"}),e.name]))},i.readAsDataURL(e)}},t=(e,i,n)=>button({type:"button",class:()=>`btn btn-ghost btn-xs ${L(i,n)?"btn-active bg-primary/20":""}`,onclick:()=>typeof i=="function"?i():r(i,n)},[span({class:`icon-[lucide--${e}]`})]);return div({class:`border border-base-300 rounded-box bg-base-100 overflow-hidden flex flex-col ${z||""}`},[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"},[t("bold","bold"),t("italic","italic"),t("underline","underline"),input({type:"color",class:"w-5 h-5 p-0 bg-transparent cursor-pointer",oninput:(e)=>r("foreColor",e.target.value)}),span({class:"w-px h-5 bg-base-300 mx-1"}),t("align-left","justifyLeft"),t("align-center","justifyCenter"),t("align-right","justifyRight"),span({class:"w-px h-5 bg-base-300 mx-1"}),t("list","insertUnorderedList"),t("list-ordered","insertOrderedList"),t("indent-decrease","outdent"),t("indent-increase","indent"),t("quote",()=>r("formatBlock",L("formatBlock","BLOCKQUOTE")?"P":"BLOCKQUOTE"),"BLOCKQUOTE"),span({class:"w-px h-5 bg-base-300 mx-1"}),t("link",()=>{let e=prompt("URL:");e&&r("createLink",e)}),t("paperclip",()=>{let e=document.createElement("input");e.type="file",e.onchange=(i)=>T(i.target.files[0]),e.click()}),div({class:"relative"},[t("smile",()=>{d=w(),c(!c())}),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:()=>c()?"":"display:none"},R.map((e)=>span({class:"cursor-pointer p-1 text-lg",onclick:()=>{r("insertText",e),c(0)}},e)))]),t("undo-2","undo"),t("redo-2","redo")]),t("code-2",()=>{if(!l())g(o?.innerHTML||"");else if(o)o.innerHTML=g(),b();l(!l())})]),div({class:"relative flex-1 flex flex-col",onclick:()=>c(0)},[div({ref:(e)=>{if(e&&!o)o=e,e.innerHTML=(C(s)?s():s)||"",document.execCommand("defaultParagraphSeparator",0,"br"),e.onclick=(i)=>{let n=i.target.closest(".resizable-img-container");if(n){let f=n.querySelector("img");f&&((m)=>{let p=document.createElement("div");p.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",p.onclick=()=>p.remove();let y=document.createElement("img");y.src=m,y.style="max-width:95%;max-height:95%",p.appendChild(y),document.body.appendChild(p)})(f.src)}}},style:()=>`min-height:22rem;${l()?"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:b,onkeydown:(e)=>e.key==="Tab"&&(e.preventDefault(),r("indent")),onkeyup:()=>{k(),d=w()},onmouseup:b,onpaste:(e)=>{e.preventDefault(),r("insertText",e.clipboardData.getData("text/plain"))},ondrop:(e)=>{e.preventDefault(),T(e.dataTransfer.files[0])},ondragover:(e)=>e.preventDefault()}),textarea({class:"w-full flex-1 min-h-[22rem] p-4 font-mono text-sm bg-base-200 border-0",style:()=>l()?"":"display:none",value:g,oninput:(e)=>{if(g(e.target.value),o)o.innerHTML=e.target.value;x.onchange?.(e.target.value)}})]),div({class:"px-3 py-1 border-t text-[10px] text-right opacity-60"},[span(()=>v())])])};export{S as Editor};
1
+ function W({update:e,notify:t,unwatched:i}){return{link:o,unlink:d,propagate:b,checkDirty:T,shallowPropagate:c};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 d(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 w=(n=v).nextSub;if(w!==void 0)g={value:p,prev:g},p=w;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 w=f.subs;if(e(f)){if(w.nextSub!==void 0)c(w);r=!0}}else if((v&33)===33){p={value:n,prev:p},n=f.deps,s=f,++g;continue}if(!r){let w=n.nextDep;if(w!==void 0){n=w;continue}}while(g--){if(n=p.value,p=p.prev,r){let h=s.subs;if(e(s)){if(h.nextSub!==void 0)c(h);s=n.sub;continue}r=!1}else s.flags&=-33;s=n.sub;let w=n.nextDep;if(w!==void 0){n=w;continue e}}return r&&!!s.flags}while(!0)}function c(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 q=0,E=0,X=0,L=0,N=0,y,S=[],{link:z,unlink:_,propagate:Y,checkDirty:Z,shallowPropagate:ee}=W({update(e){if("getter"in e)return te(e);if("currentValue"in e)return F(e);return e.flags=1,!0},notify(e){let t=N,i=t;do if(S[t++]=e,e.flags&=-3,e=e.subs?.sub,e===void 0||!(e.flags&2))break;while(!0);N=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,G(e)}else if("currentValue"in e);else if("fn"in e)$.call(e);else P.call(e)}});function k(e){return le.bind({currentValue:e,pendingValue:e,subs:void 0,subsTail:void 0,flags:1})}function A(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)z(t,i,0),i.flags|=64;try{++E;let o=t.fn();t.cleanup=typeof o==="function"?o:void 0}finally{--E,y=i,t.flags&=-5}return $.bind(t)}function U(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)z(t,i,0),i.flags|=64;try{e()}finally{y=i}return P.bind(t)}function te(e){if(e.flags&64){let i=e.depsTail;while(i!==void 0){let{prevDep:o,dep:d}=i;if(!("getter"in d)&&!("currentValue"in d))_(i,e);i=o}}e.depsTail=void 0,e.flags=5;let t=y;y=e;try{++q;let i=e.value;return i!==(e.value=e.getter(i))}finally{y=t,e.flags&=-5,J(e)}}function F(e){return e.flags=1,e.currentValue!==(e.currentValue=e.pendingValue)}function ie(e){let t=e.flags;if(t&16||t&32&&Z(e.deps,e)){if(t&64){let o=e.depsTail;while(o!==void 0){let{prevDep:d,dep:b}=o;if(!("getter"in b)&&!("currentValue"in b))_(o,e);o=d}}if(e.cleanup){if(I(e),!e.flags)return}e.depsTail=void 0,e.flags=6;let i=y;y=e;try{++q,++E;let o=e.fn();e.cleanup=typeof o==="function"?o:void 0}finally{--E,y=i,e.flags&=-5,J(e)}}else if(e.deps!==void 0)e.flags=2|t&64}function ne(){try{while(L<N){let e=S[L];S[L++]=void 0,ie(e)}}finally{while(L<N){let e=S[L];S[L++]=void 0,e.flags|=10}L=0,N=0}}function le(...e){if(e.length){if(this.pendingValue!==(this.pendingValue=e[0])){this.flags=17;let t=this.subs;if(t!==void 0){if(Y(t,!!E),!X)ne()}}}else{if(this.flags&16){if(F(this)){let i=this.subs;if(i!==void 0)ee(i)}}let t=y;if(t!==void 0)z(this,t,q);return this.currentValue}}function I(e){let t=e.cleanup;e.cleanup=void 0;let i=y;y=void 0;try{t()}finally{y=i}}function $(){if(P.call(this),this.cleanup)I(this)}function P(){this.flags=0,G(this);let e=this.subs;if(e!==void 0)_(e)}function G(e){let t=e.depsTail;while(t!==void 0){let i=t.prevDep;_(t,e),t=i}}function J(e){let t=e.depsTail,i=t!==void 0?t.nextDep:e.deps;while(i!==void 0)i=_(i,e)}var C=typeof document<"u"?document:null,oe="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 B(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 re(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 V(e,t={},...i){if(typeof e==="function"){let c,u=U(()=>{c=e(t,i)}),n=(s)=>{if(s instanceof Node)s._stopScope=u;else if(Array.isArray(s))s.forEach(n)};return n(c),c}if(t instanceof Node||Array.isArray(t)||t!==null&&typeof t!=="object"||t===void 0)i=[t,...i],t={};let o=ae.has(e),d=o?C.createElementNS(oe,e):C.createElement(e),b,T=!1;for(let c in t){let u=t[c];if(c==="ref"){if(typeof u==="function")u(d);else if(u!=null&&typeof u==="object")u.current=d;continue}if(e==="select"&&c==="value"){b=u;continue}if(c==="html"){if(T=!0,typeof u==="function")A(()=>{d.innerHTML=u()??""});else d.innerHTML=u??"";continue}if(c.startsWith("on")&&typeof u==="function"){let n=c.slice(2).toLowerCase();d.addEventListener(n,u),(d._cln||(d._cln=[])).push(()=>d.removeEventListener(n,u))}else if(typeof u==="function")A(()=>B(d,c,u(),o));else B(d,c,u,o)}if(!T){let c=(u)=>{if(Array.isArray(u)){for(let n of u)c(n);return}if(u==null||u===!1||u===!0)return;if(typeof u==="function"){let n=C.createComment("");d.appendChild(n),A(()=>{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:C.createTextNode(String(r)))}for(let r of g)d.insertBefore(r,n);return()=>{for(let r of g)re(r),r.remove()}});return}d.appendChild(u instanceof Node?u:C.createTextNode(String(u)))};c(i)}if(b!==void 0)if(typeof b==="function")A(()=>B(d,"value",b(),o));else B(d,"value",b,o);return d}var se="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",K=(e=typeof window<"u"?window:null)=>{if(!e)return;for(let t of se.split(" "))e[t]=(i,...o)=>V(t,i,...o)},R=k(typeof window<"u"?window.location.hash.slice(1)||"/":"/"),fe=k({});if(typeof window<"u")window.addEventListener("hashchange",()=>{R(window.location.hash.slice(1)||"/")});var H=(e)=>()=>{let t=V("div",{class:"router-hook"});return A(()=>{let i=R().split("/").filter(Boolean);return U(()=>{let o=e.find((c)=>{let u=c.path.split("/").filter(Boolean);return u.length===i.length&&u.every((n,s)=>n[0]===":"||n===i[s])})||e.find((c)=>c.path==="*");if(!o){t.replaceChildren();return}let d={};o.path.split("/").filter(Boolean).forEach((c,u)=>{if(c[0]===":")d[c.slice(1)]=i[u]}),fe(d);let b=typeof o.component==="function"?V(o.component,d):o.component,T=b==null?[]:Array.isArray(b)?b:[b];t.replaceChildren(...T)})}),t};H.to=(e)=>{if(typeof window<"u")window.location.hash=e.replace(/^#?\/?/,"#/")};H.back=()=>{if(typeof window<"u")window.history.back()};H.path=()=>R();var ue=k("en");K();var Q=(e)=>typeof e==="function",pe=(e)=>{let{value:t,class:i}=e,o=k(0),d=k(""),b=k(0),T=k(0),c=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;Q(t)?t(l):e.onchange?.(l),g()}},f=(l,x=null)=>{if(n?.focus(),s){let m=window.getSelection();m.removeAllRanges(),m.addRange(s)}document.execCommand(l,0,x),s=0,r()},v=(l,x=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===x)return 1;m=m.parentNode}return 0}return document.queryCommandState(l)}catch(m){return 0}},w=(l)=>{if(l){let x=new FileReader;x.onload=(m)=>{let M=l.type.startsWith("image/"),O=m.target.result;f("insertHTML",M?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:O,style:"width:100%;height:100%;object-fit:contain;pointer-events:none"})]):a({href:O,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]))},x.readAsDataURL(l)}},h=(l,x,m)=>button({type:"button",class:()=>`btn btn-ghost btn-xs ${v(x,m)?"btn-active bg-primary/20":""}`,onclick:()=>typeof x=="function"?x():f(x,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=(x)=>w(x.target.files[0]),l.click()}),div({class:"relative"},[h("smile",()=>{s=u(),c(!c())}),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:()=>c()?"":"display:none"},p.map((l)=>span({class:"cursor-pointer p-1 text-lg",onclick:()=>{f("insertText",l),c(0)}},l)))]),h("undo-2","undo"),h("redo-2","redo")]),h("code-2",()=>{if(!o())d(n?.innerHTML||"");else if(n)n.innerHTML=d(),r();o(!o())})]),div({class:"relative flex-1 flex flex-col",onclick:()=>c(0)},[div({ref:(l)=>{if(l&&!n)n=l,l.innerHTML=(Q(t)?t():t)||"",document.execCommand("defaultParagraphSeparator",0,"br"),l.onclick=(x)=>{let m=x.target.closest(".resizable-img-container");if(m){let M=m.querySelector("img");M&&((O)=>{let D=document.createElement("div");D.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",D.onclick=()=>D.remove();let j=document.createElement("img");j.src=O,j.style="max-width:95%;max-height:95%",D.appendChild(j),document.body.appendChild(D)})(M.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(),w(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:d,oninput:(l)=>{if(d(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{pe as Editor};