sibujs 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,332 @@
1
+ import {
2
+ bindAttribute,
3
+ isUrlAttribute,
4
+ sanitizeCSSValue,
5
+ sanitizeUrl
6
+ } from "./chunk-23VV7YD3.js";
7
+ import {
8
+ track
9
+ } from "./chunk-V2XTI523.js";
10
+ import {
11
+ devWarn,
12
+ isDev
13
+ } from "./chunk-UNXCEF6S.js";
14
+
15
+ // src/core/rendering/dispose.ts
16
+ var elementDisposers = /* @__PURE__ */ new WeakMap();
17
+ var _isDev = isDev();
18
+ var activeBindingCount = 0;
19
+ function registerDisposer(node, teardown) {
20
+ let disposers = elementDisposers.get(node);
21
+ if (!disposers) {
22
+ disposers = [];
23
+ elementDisposers.set(node, disposers);
24
+ }
25
+ disposers.push(teardown);
26
+ if (_isDev) activeBindingCount++;
27
+ }
28
+ function dispose(node) {
29
+ const stack = [node];
30
+ const order = [];
31
+ while (stack.length > 0) {
32
+ const current = stack.pop();
33
+ order.push(current);
34
+ const children = current.childNodes;
35
+ for (let i = 0; i < children.length; i++) {
36
+ stack.push(children[i]);
37
+ }
38
+ }
39
+ for (let i = order.length - 1; i >= 0; i--) {
40
+ const current = order[i];
41
+ const disposers = elementDisposers.get(current);
42
+ if (disposers) {
43
+ if (_isDev) activeBindingCount -= disposers.length;
44
+ for (const d of disposers) d();
45
+ elementDisposers.delete(current);
46
+ }
47
+ }
48
+ }
49
+ function checkLeaks(warnThreshold = 0) {
50
+ if (!_isDev) return 0;
51
+ if (warnThreshold > 0 && activeBindingCount > warnThreshold) {
52
+ devWarn(
53
+ `checkLeaks: ${activeBindingCount} active DOM bindings detected. Expected \u2264${warnThreshold}. This may indicate a component was removed from the DOM without calling dispose().`
54
+ );
55
+ }
56
+ return activeBindingCount;
57
+ }
58
+
59
+ // src/reactivity/bindChildNode.ts
60
+ var _isDev2 = isDev();
61
+ function bindChildNode(placeholder, getter) {
62
+ let lastNodes = [];
63
+ function commit() {
64
+ let result;
65
+ try {
66
+ result = getter();
67
+ } catch (err) {
68
+ if (_isDev2) devWarn(`bindChildNode: getter threw: ${err instanceof Error ? err.message : String(err)}`);
69
+ return;
70
+ }
71
+ if (result == null || typeof result === "boolean") {
72
+ for (let i = 0; i < lastNodes.length; i++) {
73
+ const node = lastNodes[i];
74
+ if (node.parentNode) node.parentNode.removeChild(node);
75
+ }
76
+ lastNodes.length = 0;
77
+ return;
78
+ }
79
+ const parent = placeholder.parentNode;
80
+ if (!parent) {
81
+ lastNodes.length = 0;
82
+ return;
83
+ }
84
+ let newNodes;
85
+ if (Array.isArray(result)) {
86
+ newNodes = [];
87
+ for (let i = 0; i < result.length; i++) {
88
+ const item = result[i];
89
+ if (item == null || typeof item === "boolean") continue;
90
+ newNodes.push(item instanceof Node ? item : document.createTextNode(String(item)));
91
+ }
92
+ } else {
93
+ const node = result instanceof Node ? result : document.createTextNode(String(result));
94
+ newNodes = [node];
95
+ }
96
+ const reused = lastNodes.length > 0 && newNodes.length > 0 ? /* @__PURE__ */ new Set() : void 0;
97
+ if (reused) {
98
+ for (let i = 0; i < newNodes.length; i++) {
99
+ for (let j = 0; j < lastNodes.length; j++) {
100
+ if (newNodes[i] === lastNodes[j]) {
101
+ reused.add(newNodes[i]);
102
+ break;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ for (let i = 0; i < lastNodes.length; i++) {
108
+ const node = lastNodes[i];
109
+ if (reused?.has(node)) continue;
110
+ if (node.parentNode) node.parentNode.removeChild(node);
111
+ }
112
+ const anchor = placeholder.nextSibling;
113
+ for (let i = 0; i < newNodes.length; i++) {
114
+ const node = newNodes[i];
115
+ if (reused?.has(node) && node.parentNode === parent) {
116
+ if (node.nextSibling !== anchor) {
117
+ parent.insertBefore(node, anchor);
118
+ }
119
+ } else {
120
+ parent.insertBefore(node, anchor);
121
+ }
122
+ }
123
+ lastNodes = newNodes;
124
+ }
125
+ return track(commit);
126
+ }
127
+
128
+ // src/core/rendering/tagFactory.ts
129
+ var SVG_NS = "http://www.w3.org/2000/svg";
130
+ var kebabCache = /* @__PURE__ */ new Map();
131
+ function toKebab(prop) {
132
+ let cached = kebabCache.get(prop);
133
+ if (cached !== void 0) return cached;
134
+ cached = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
135
+ kebabCache.set(prop, cached);
136
+ return cached;
137
+ }
138
+ function applyStyle(el, style) {
139
+ if (typeof style === "function") {
140
+ const teardown = track(() => {
141
+ el.setAttribute("style", style());
142
+ });
143
+ registerDisposer(el, teardown);
144
+ return;
145
+ }
146
+ if (typeof style === "string") {
147
+ el.setAttribute("style", style);
148
+ return;
149
+ }
150
+ const htmlEl = el;
151
+ for (const prop in style) {
152
+ const val = style[prop];
153
+ const name = toKebab(prop);
154
+ if (typeof val === "function") {
155
+ const getter = val;
156
+ const teardown = track(() => {
157
+ htmlEl.style.setProperty(name, sanitizeCSSValue(String(getter())));
158
+ });
159
+ registerDisposer(el, teardown);
160
+ } else {
161
+ htmlEl.style.setProperty(name, sanitizeCSSValue(String(val)));
162
+ }
163
+ }
164
+ }
165
+ function applyClass(el, cls) {
166
+ if (typeof cls === "string") {
167
+ el.setAttribute("class", cls);
168
+ return;
169
+ }
170
+ if (typeof cls === "function") {
171
+ const teardown = track(() => {
172
+ el.setAttribute("class", cls());
173
+ });
174
+ registerDisposer(el, teardown);
175
+ return;
176
+ }
177
+ const obj = cls;
178
+ let hasReactive = false;
179
+ let result = "";
180
+ for (const name in obj) {
181
+ const val = obj[name];
182
+ if (typeof val === "function") {
183
+ hasReactive = true;
184
+ break;
185
+ }
186
+ if (val) result = result ? `${result} ${name}` : name;
187
+ }
188
+ if (hasReactive) {
189
+ const update = () => {
190
+ let r = "";
191
+ for (const name in obj) {
192
+ const val = obj[name];
193
+ const active = typeof val === "function" ? val() : val;
194
+ if (active) r = r ? `${r} ${name}` : name;
195
+ }
196
+ el.setAttribute("class", r);
197
+ };
198
+ const teardown = track(update);
199
+ registerDisposer(el, teardown);
200
+ } else {
201
+ el.setAttribute("class", result);
202
+ }
203
+ }
204
+ function appendChildren(el, nodes) {
205
+ if (typeof nodes === "string") {
206
+ el.textContent = nodes;
207
+ return;
208
+ }
209
+ if (typeof nodes === "number") {
210
+ el.textContent = String(nodes);
211
+ return;
212
+ }
213
+ if (typeof nodes === "boolean" || nodes == null) {
214
+ return;
215
+ }
216
+ if (typeof nodes === "function") {
217
+ const ph = document.createComment("");
218
+ el.appendChild(ph);
219
+ registerDisposer(el, bindChildNode(ph, nodes));
220
+ return;
221
+ }
222
+ if (nodes instanceof Node) {
223
+ el.appendChild(nodes);
224
+ return;
225
+ }
226
+ if (Array.isArray(nodes)) {
227
+ for (let i = 0; i < nodes.length; i++) {
228
+ const c = nodes[i];
229
+ if (typeof c === "function") {
230
+ const ph = document.createComment("");
231
+ el.appendChild(ph);
232
+ registerDisposer(el, bindChildNode(ph, c));
233
+ } else if (c instanceof Node) {
234
+ el.appendChild(c);
235
+ } else if (Array.isArray(c)) {
236
+ for (let j = 0; j < c.length; j++) {
237
+ const inner = c[j];
238
+ if (typeof inner === "function") {
239
+ const ph = document.createComment("");
240
+ el.appendChild(ph);
241
+ registerDisposer(el, bindChildNode(ph, inner));
242
+ } else if (inner instanceof Node) {
243
+ el.appendChild(inner);
244
+ } else if (inner != null && typeof inner !== "boolean") {
245
+ el.appendChild(document.createTextNode(String(inner)));
246
+ }
247
+ }
248
+ } else if (c != null && typeof c !== "boolean") {
249
+ el.appendChild(document.createTextNode(String(c)));
250
+ }
251
+ }
252
+ }
253
+ }
254
+ var tagFactory = (tag, ns) => (first, second) => {
255
+ const el = ns ? document.createElementNS(ns, tag) : document.createElement(tag);
256
+ if (first === void 0) return el;
257
+ if (second === void 0 && typeof first === "string") {
258
+ el.textContent = first;
259
+ return el;
260
+ }
261
+ if (second !== void 0) {
262
+ el.setAttribute("class", first);
263
+ appendChildren(el, second);
264
+ return el;
265
+ }
266
+ if (Array.isArray(first) || first instanceof Node) {
267
+ appendChildren(el, first);
268
+ return el;
269
+ }
270
+ const props = first;
271
+ const pClass = props.class;
272
+ if (pClass != null) applyClass(el, pClass);
273
+ const pId = props.id;
274
+ if (pId != null) el.id = pId;
275
+ const pNodes = props.nodes;
276
+ if (pNodes != null) appendChildren(el, pNodes);
277
+ const pOn = props.on;
278
+ if (pOn) {
279
+ for (const ev in pOn) {
280
+ el.addEventListener(ev, pOn[ev]);
281
+ }
282
+ }
283
+ const pStyle = props.style;
284
+ if (pStyle != null) applyStyle(el, pStyle);
285
+ const pRef = props.ref;
286
+ if (pRef) pRef.current = el;
287
+ for (const key in props) {
288
+ switch (key) {
289
+ case "class":
290
+ case "id":
291
+ case "nodes":
292
+ case "on":
293
+ case "style":
294
+ case "ref":
295
+ case "onElement":
296
+ continue;
297
+ // already handled above / below
298
+ default: {
299
+ const value = props[key];
300
+ if (value == null) continue;
301
+ if (key[0] === "o" && key[1] === "n") continue;
302
+ if (typeof value === "function") {
303
+ registerDisposer(el, bindAttribute(el, key, value));
304
+ } else if (typeof value === "boolean") {
305
+ if (key in el && (key === "checked" || key === "disabled" || key === "selected")) {
306
+ el[key] = value;
307
+ } else if (value) {
308
+ el.setAttribute(key, "");
309
+ } else {
310
+ el.removeAttribute(key);
311
+ }
312
+ } else {
313
+ const str = String(value);
314
+ el.setAttribute(key, isUrlAttribute(key) ? sanitizeUrl(str) : str);
315
+ }
316
+ }
317
+ }
318
+ }
319
+ if (props.onElement && typeof props.onElement === "function") {
320
+ props.onElement(el);
321
+ }
322
+ return el;
323
+ };
324
+
325
+ export {
326
+ bindChildNode,
327
+ registerDisposer,
328
+ dispose,
329
+ checkLeaks,
330
+ SVG_NS,
331
+ tagFactory
332
+ };
@@ -0,0 +1,282 @@
1
+ import {
2
+ SVG_NS,
3
+ tagFactory
4
+ } from "./chunk-B7SWRFUT.js";
5
+
6
+ // src/core/rendering/html.ts
7
+ var html = tagFactory("html");
8
+ var head = tagFactory("head");
9
+ var body = tagFactory("body");
10
+ var title = tagFactory("title");
11
+ var div = tagFactory("div");
12
+ var span = tagFactory("span");
13
+ var section = tagFactory("section");
14
+ var article = tagFactory("article");
15
+ var header = tagFactory("header");
16
+ var footer = tagFactory("footer");
17
+ var nav = tagFactory("nav");
18
+ var main = tagFactory("main");
19
+ var aside = tagFactory("aside");
20
+ var address = tagFactory("address");
21
+ var p = tagFactory("p");
22
+ var h1 = tagFactory("h1");
23
+ var h2 = tagFactory("h2");
24
+ var h3 = tagFactory("h3");
25
+ var h4 = tagFactory("h4");
26
+ var h5 = tagFactory("h5");
27
+ var h6 = tagFactory("h6");
28
+ var blockquote = tagFactory("blockquote");
29
+ var dd = tagFactory("dd");
30
+ var dl = tagFactory("dl");
31
+ var dt = tagFactory("dt");
32
+ var figcaption = tagFactory("figcaption");
33
+ var figure = tagFactory("figure");
34
+ var hr = tagFactory("hr");
35
+ var li = tagFactory("li");
36
+ var ol = tagFactory("ol");
37
+ var ul = tagFactory("ul");
38
+ var pre = tagFactory("pre");
39
+ var a = tagFactory("a");
40
+ var abbr = tagFactory("abbr");
41
+ var b = tagFactory("b");
42
+ var bdi = tagFactory("bdi");
43
+ var bdo = tagFactory("bdo");
44
+ var br = tagFactory("br");
45
+ var cite = tagFactory("cite");
46
+ var code = tagFactory("code");
47
+ var data = tagFactory("data");
48
+ var dfn = tagFactory("dfn");
49
+ var em = tagFactory("em");
50
+ var i = tagFactory("i");
51
+ var kbd = tagFactory("kbd");
52
+ var mark = tagFactory("mark");
53
+ var q = tagFactory("q");
54
+ var rp = tagFactory("rp");
55
+ var rt = tagFactory("rt");
56
+ var ruby = tagFactory("ruby");
57
+ var s = tagFactory("s");
58
+ var samp = tagFactory("samp");
59
+ var small = tagFactory("small");
60
+ var strong = tagFactory("strong");
61
+ var sub = tagFactory("sub");
62
+ var sup = tagFactory("sup");
63
+ var time = tagFactory("time");
64
+ var u = tagFactory("u");
65
+ var var_ = tagFactory("var");
66
+ var area = tagFactory("area");
67
+ var audio = tagFactory("audio");
68
+ var img = tagFactory("img");
69
+ var map = tagFactory("map");
70
+ var track = tagFactory("track");
71
+ var video = tagFactory("video");
72
+ var embed = tagFactory("embed");
73
+ var iframe = tagFactory("iframe");
74
+ var object = tagFactory("object");
75
+ var param = tagFactory("param");
76
+ var picture = tagFactory("picture");
77
+ var portal = tagFactory("portal");
78
+ var source = tagFactory("source");
79
+ var svg = tagFactory("svg", SVG_NS);
80
+ var math = tagFactory("math");
81
+ var canvas = tagFactory("canvas");
82
+ var noscript = tagFactory("noscript");
83
+ var script = tagFactory("script");
84
+ var del = tagFactory("del");
85
+ var ins = tagFactory("ins");
86
+ var caption = tagFactory("caption");
87
+ var col = tagFactory("col");
88
+ var colgroup = tagFactory("colgroup");
89
+ var table = tagFactory("table");
90
+ var tbody = tagFactory("tbody");
91
+ var td = tagFactory("td");
92
+ var tfoot = tagFactory("tfoot");
93
+ var th = tagFactory("th");
94
+ var thead = tagFactory("thead");
95
+ var tr = tagFactory("tr");
96
+ var button = tagFactory("button");
97
+ var datalist = tagFactory("datalist");
98
+ var fieldset = tagFactory("fieldset");
99
+ var form = tagFactory("form");
100
+ var input = tagFactory("input");
101
+ var label = tagFactory("label");
102
+ var legend = tagFactory("legend");
103
+ var meter = tagFactory("meter");
104
+ var optgroup = tagFactory("optgroup");
105
+ var option = tagFactory("option");
106
+ var output = tagFactory("output");
107
+ var progress = tagFactory("progress");
108
+ var select = tagFactory("select");
109
+ var textarea = tagFactory("textarea");
110
+ var details = tagFactory("details");
111
+ var dialog = tagFactory("dialog");
112
+ var menu = tagFactory("menu");
113
+ var summary = tagFactory("summary");
114
+ var slot = tagFactory("slot");
115
+ var template = tagFactory("template");
116
+ var base = tagFactory("base");
117
+ var link = tagFactory("link");
118
+ var meta = tagFactory("meta");
119
+ var style = tagFactory("style");
120
+ var circle = tagFactory("circle", SVG_NS);
121
+ var ellipse = tagFactory("ellipse", SVG_NS);
122
+ var g = tagFactory("g", SVG_NS);
123
+ var line = tagFactory("line", SVG_NS);
124
+ var path = tagFactory("path", SVG_NS);
125
+ var polygon = tagFactory("polygon", SVG_NS);
126
+ var polyline = tagFactory("polyline", SVG_NS);
127
+ var rect = tagFactory("rect", SVG_NS);
128
+ var text = tagFactory("text", SVG_NS);
129
+ var tspan = tagFactory("tspan", SVG_NS);
130
+ var defs = tagFactory("defs", SVG_NS);
131
+ var clipPath = tagFactory("clipPath", SVG_NS);
132
+ var mask = tagFactory("mask", SVG_NS);
133
+ var pattern = tagFactory("pattern", SVG_NS);
134
+ var linearGradient = tagFactory("linearGradient", SVG_NS);
135
+ var radialGradient = tagFactory("radialGradient", SVG_NS);
136
+ var stop = tagFactory("stop", SVG_NS);
137
+ var use = tagFactory("use", SVG_NS);
138
+ var symbol = tagFactory("symbol", SVG_NS);
139
+ var marker = tagFactory("marker", SVG_NS);
140
+ var center = tagFactory("center");
141
+ var font = tagFactory("font");
142
+ var marquee = tagFactory("marquee");
143
+ var customElement = (tagName) => tagFactory(tagName);
144
+
145
+ export {
146
+ head,
147
+ body,
148
+ title,
149
+ div,
150
+ span,
151
+ section,
152
+ article,
153
+ header,
154
+ footer,
155
+ nav,
156
+ main,
157
+ aside,
158
+ address,
159
+ p,
160
+ h1,
161
+ h2,
162
+ h3,
163
+ h4,
164
+ h5,
165
+ h6,
166
+ blockquote,
167
+ dd,
168
+ dl,
169
+ dt,
170
+ figcaption,
171
+ figure,
172
+ hr,
173
+ li,
174
+ ol,
175
+ ul,
176
+ pre,
177
+ a,
178
+ abbr,
179
+ b,
180
+ bdi,
181
+ bdo,
182
+ br,
183
+ cite,
184
+ code,
185
+ data,
186
+ dfn,
187
+ em,
188
+ i,
189
+ kbd,
190
+ mark,
191
+ q,
192
+ rp,
193
+ rt,
194
+ ruby,
195
+ s,
196
+ samp,
197
+ small,
198
+ strong,
199
+ sub,
200
+ sup,
201
+ time,
202
+ u,
203
+ var_,
204
+ area,
205
+ audio,
206
+ img,
207
+ map,
208
+ track,
209
+ video,
210
+ embed,
211
+ iframe,
212
+ object,
213
+ param,
214
+ picture,
215
+ portal,
216
+ source,
217
+ svg,
218
+ math,
219
+ canvas,
220
+ noscript,
221
+ script,
222
+ del,
223
+ ins,
224
+ caption,
225
+ col,
226
+ colgroup,
227
+ table,
228
+ tbody,
229
+ td,
230
+ tfoot,
231
+ th,
232
+ thead,
233
+ tr,
234
+ button,
235
+ datalist,
236
+ fieldset,
237
+ form,
238
+ input,
239
+ label,
240
+ legend,
241
+ meter,
242
+ optgroup,
243
+ option,
244
+ output,
245
+ progress,
246
+ select,
247
+ textarea,
248
+ details,
249
+ dialog,
250
+ menu,
251
+ summary,
252
+ slot,
253
+ template,
254
+ base,
255
+ link,
256
+ meta,
257
+ style,
258
+ circle,
259
+ ellipse,
260
+ g,
261
+ line,
262
+ path,
263
+ polygon,
264
+ polyline,
265
+ rect,
266
+ text,
267
+ tspan,
268
+ defs,
269
+ clipPath,
270
+ mask,
271
+ pattern,
272
+ linearGradient,
273
+ radialGradient,
274
+ stop,
275
+ use,
276
+ symbol,
277
+ marker,
278
+ center,
279
+ font,
280
+ marquee,
281
+ customElement
282
+ };