@cossackframework/renderer 0.5.0 → 0.5.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.
@@ -283,14 +283,14 @@ var e = (e) => typeof e == "object" && !!e && e._type === "COMPONENT", t = [], n
283
283
  let n = D.get(e.firstChild?.childNodes[0] || e);
284
284
  n && (this._cachedTemplateStrings = n.strings, this._cachedParts = n.parts);
285
285
  }
286
- else if (e(t) || typeof t == "object" && t && !(t instanceof Node) && !Array.isArray(t)) {
287
- this._clearTemplateCache(), this.clear();
288
- let e = document.createDocumentFragment();
289
- O(f`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
290
- } else if (v(t)) {
286
+ else if (v(t)) {
291
287
  this._clearTemplateCache(), this.clear();
292
288
  let e = document.createElement("template");
293
289
  e.innerHTML = t.value, this.startNode.parentNode.insertBefore(e.content, this.endNode);
290
+ } else if (e(t) || typeof t == "object" && t && !(t instanceof Node) && !Array.isArray(t)) {
291
+ this._clearTemplateCache(), this.clear();
292
+ let e = document.createDocumentFragment();
293
+ O(f`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
294
294
  } else if (t instanceof Node) this._clearTemplateCache(), this.clear(), this.startNode.parentNode.insertBefore(t, this.endNode);
295
295
  else if (t == null || t === !1) this._clearTemplateCache(), this.clear();
296
296
  else {
@@ -335,21 +335,33 @@ var e = (e) => typeof e == "object" && !!e && e._type === "COMPONENT", t = [], n
335
335
  }, E = class {
336
336
  element;
337
337
  name;
338
- prefix;
339
- suffix;
340
- constructor(e, t, n) {
338
+ segments;
339
+ isMulti;
340
+ multiState;
341
+ constructor(e, t, n, r) {
341
342
  this.element = e, this.name = t;
342
- let r = n.indexOf("__CRP_");
343
- if (r !== -1) {
344
- let e = r + 6, t = n.indexOf("__", e);
345
- this.prefix = n.substring(0, r), this.suffix = n.substring(t + 2);
346
- } else this.prefix = "", this.suffix = "";
343
+ let i = [...n.matchAll(/__CRP_(\d+)__/g)];
344
+ this.segments = [];
345
+ let a = 0;
346
+ for (let e of i) {
347
+ let t = e.index;
348
+ this.segments.push(n.substring(a, t)), a = t + e[0].length;
349
+ }
350
+ this.segments.push(n.substring(a)), this.isMulti = i.length > 1, this.multiState = r ?? null;
347
351
  }
348
352
  update(e) {
349
353
  if (e instanceof a && (e = e.value), this.name === "ref") {
350
354
  typeof e == "function" ? e(this.element) : e && typeof e == "object" && "value" in e && (e.value = this.element), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
351
355
  return;
352
356
  }
357
+ if (this.isMulti && this.multiState) {
358
+ let { currentValues: t, position: n } = this.multiState;
359
+ t[n] = e;
360
+ let r = this.segments[0];
361
+ for (let e = 0; e < t.length; e++) r += String(t[e]) + this.segments[e + 1];
362
+ this.element.setAttribute(this.name, r);
363
+ return;
364
+ }
353
365
  if (this.name.startsWith("@") && typeof e == "function") {
354
366
  let t = this.name.slice(1), n = `__crp_handler_${t}`, r = this.element[n];
355
367
  r && this.element.removeEventListener(t, r), this.element[n] = e, this.element.addEventListener(t, e), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
@@ -363,7 +375,7 @@ var e = (e) => typeof e == "object" && !!e && e._type === "COMPONENT", t = [], n
363
375
  else if (this.name === "checked" && this.element instanceof HTMLInputElement) {
364
376
  let t = !!e;
365
377
  this.element.checked !== t && (this.element.checked = t), t ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name);
366
- } else typeof e == "boolean" ? e ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.prefix + String(e) + this.suffix);
378
+ } else typeof e == "boolean" ? e ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]);
367
379
  }
368
380
  }, D = /* @__PURE__ */ new WeakMap(), O = (e, t) => {
369
381
  let n = D.get(t);
@@ -403,10 +415,21 @@ var e = (e) => typeof e == "object" && !!e && e._type === "COMPONENT", t = [], n
403
415
  } else if (e.nodeType === Node.ELEMENT_NODE) {
404
416
  let t = e;
405
417
  Array.from(t.attributes).forEach((e) => {
406
- let n = e.value.match(/__CRP_(\d+)__/);
407
- if (n) {
408
- let i = parseInt(n[1]);
418
+ let n = [...e.value.matchAll(/__CRP_(\d+)__/g)];
419
+ if (n.length === 0) return;
420
+ if (n.length === 1) {
421
+ let i = parseInt(n[0][1]);
409
422
  r[i] || (e.name === "..." ? (r[i] = new T(t), t.removeAttribute("...")) : r[i] = new E(t, e.name, e.value));
423
+ return;
424
+ }
425
+ if (e.name === "...") return;
426
+ let i = n.map((e) => parseInt(e[1])), a = Array(n.length).fill(void 0);
427
+ for (let n = 0; n < i.length; n++) {
428
+ let o = i[n];
429
+ r[o] || (r[o] = new E(t, e.name, e.value, {
430
+ currentValues: a,
431
+ position: n
432
+ }));
410
433
  }
411
434
  });
412
435
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as e, _ as t, a as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, x as b, y as x } from "./cossack-html-CCHKnNWv.js";
1
+ import { S as e, _ as t, a as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, x as b, y as x } from "./cossack-html-BUi5cuB1.js";
2
2
  //#region src/context.ts
3
3
  function S(e) {
4
4
  return {
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
- import { i as e, l as t } from "./cossack-html-CCHKnNWv.js";
1
+ import { i as e, l as t } from "./cossack-html-BUi5cuB1.js";
2
2
  //#region src/minify-html.ts
3
- var n = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, r = RegExp(`<(${[...new Set([
3
+ var n = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, r = RegExp(`<(${[.../* @__PURE__ */ new Set([
4
4
  "area",
5
5
  "base",
6
6
  "br",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cossackframework/renderer",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "Light DOM rendering engine for the Cossack Framework",
6
6
  "license": "MIT",
@@ -31,10 +31,10 @@
31
31
  "htmlparser2": "^10.0.0",
32
32
  "magic-string": "^0.30.21",
33
33
  "oxlint": "^1.41.0",
34
- "vite": "^8.0.0",
34
+ "vite": "^8.1.0",
35
35
  "vite-plugin-dts": "^3.9.1",
36
36
  "vite-tsconfig-paths": "^5.1.4",
37
- "vitest": "^3.2.4"
37
+ "vitest": "^4.1.9"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "vite build",