@cossackframework/renderer 0.8.1 → 0.8.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,12 +1,13 @@
1
1
  # Cossack Renderer Package
2
2
 
3
- Cossack Renderer is a Lit-compatible rendering engine designed for **Light DOM** and **SSR**. It provides a familiar API for building components but focuses on returning HTML strings directly for SSR and managing DOM updates without Shadow DOM isolation.
3
+ Cossack Renderer is a Lit-compatible rendering engine for **Light DOM** and
4
+ **SSR**. It returns HTML strings for SSR and updates the DOM without Shadow DOM
5
+ isolation.
4
6
 
5
7
  ## Installation
6
8
 
7
- This package is included by projects created with `cossack create`, but can
8
- also be used standalone in any project that needs a lightweight rendering
9
- solution.
9
+ Projects created with `cossack create` include this package. You can also use
10
+ it on its own in another project.
10
11
 
11
12
  ```bash
12
13
  pnpm add @cossackframework/renderer
@@ -1,4 +1,4 @@
1
- import { CossackElement } from './cossack-element';
1
+ import { CossackElement } from './cossack-element.js';
2
2
  export interface ComponentResult {
3
3
  _type: 'COMPONENT';
4
4
  clazz: new () => CossackElement;
package/dist/component.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./component.d.ts"
1
2
  //#region src/component.ts
2
3
  var e = (e) => typeof e == "object" && !!e && e._type === "COMPONENT";
3
4
  //#endregion
package/dist/context.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./context.d.ts"
1
2
  //#region src/context.ts
2
3
  function e(e) {
3
4
  return {
@@ -1,6 +1,6 @@
1
- import { TemplateResult } from './cossack-html';
2
- import { Context } from './context';
3
- import type { CSSResultGroup } from './css';
1
+ import { TemplateResult } from './cossack-html.js';
2
+ import { Context } from './context.js';
3
+ import type { CSSResultGroup } from './css.js';
4
4
  export type PropertyDeclaration = {
5
5
  type?: unknown;
6
6
  reflect?: boolean;
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./cossack-element.d.ts"
1
2
  import { getFinalizedStyles as e } from "./css.js";
2
3
  import { TemplateResult as t, html as n, hydrate as r, isTemplateResult as i, render as a } from "./cossack-html.js";
3
4
  //#region src/cossack-element.ts
@@ -1,4 +1,4 @@
1
- import { CossackElement } from './cossack-element';
1
+ import { CossackElement } from './cossack-element.js';
2
2
  export type TemplateResultType = 1 | 2;
3
3
  export declare class TemplateResult<T extends TemplateResultType = TemplateResultType> {
4
4
  readonly strings: TemplateStringsArray;
@@ -20,8 +20,10 @@ export type ValueSanitizer = (value: unknown) => unknown;
20
20
  export type SanitizerFactory = (node: Node, name: string, type: 'property' | 'attribute') => ValueSanitizer;
21
21
  export declare const component: <T extends CossackElement>(clazz: new () => T, props?: T['props'] & Record<string, unknown>, children?: unknown) => TemplateResult<1>;
22
22
  export declare const isTemplateResult: (value: unknown) => value is TemplateResult;
23
+ declare const UNSAFE_HTML_BRAND: unique symbol;
23
24
  export declare class UnsafeHTMLResult {
24
25
  readonly value: string;
26
+ readonly [UNSAFE_HTML_BRAND] = true;
25
27
  constructor(value: string);
26
28
  }
27
29
  export declare const unsafeHTML: (value: string) => UnsafeHTMLResult;
@@ -42,3 +44,4 @@ export declare const render: (result: TemplateResult, container: Node) => void;
42
44
  * back to a full `render()` so behaviour is always correct.
43
45
  */
44
46
  export declare const hydrate: (result: TemplateResult, container: Node) => void;
47
+ export {};
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./cossack-html.d.ts"
1
2
  import { isComponentResult as e } from "./component.js";
2
3
  import { CossackElement as t, popCurrentInstance as n, pushCurrentInstance as r } from "./cossack-element.js";
3
4
  import { BindResult as i, CacheResult as a, GuardResult as o, IfDefinedResult as s, KeyResult as c, LiveResult as l, PreventDefaultResult as u, RepeatResult as d, resolveField as f, setField as p } from "./directives.js";
@@ -24,39 +25,56 @@ var m = class {
24
25
  props: n ?? {},
25
26
  children: r,
26
27
  parent: t.currentRenderingInstance
27
- }}`, y = (e) => typeof e == "object" && !!e && e._cossack_template_result === !0, b = class {
28
+ }}`, y = (e) => typeof e == "object" && !!e && e._cossack_template_result === !0, b = Symbol.for("@cossackframework/renderer/unsafe-html"), x = class {
28
29
  value;
30
+ [b] = !0;
29
31
  constructor(e) {
30
32
  this.value = e;
31
33
  }
32
- }, x = (e) => new b(e), S = (e) => e instanceof b, C = (e) => String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"), w = (s, u = {}) => {
34
+ }, S = (e) => new x(e), C = (e) => typeof e == "object" && !!e && e[b] === !0, w = (e) => String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"), T = (s, u = {}) => {
33
35
  if (s === _ || s === "" || s == null || s === !1) return "";
34
- if (Array.isArray(s)) return u.hydrate ? s.map((e) => `<!--CSA-S-->${w(e, u)}<!--CSA-E-->`).join("") : s.map((e) => w(e, u)).join("");
35
- if (y(s)) return N(s, u);
36
- if (s instanceof l) return w(s.value, u);
37
- if (s instanceof d) return u.hydrate ? s.items.map((e, t) => `<!--CSA-S-->${w(s.templateFn(e, t), u)}<!--CSA-E-->`).join("") : s.items.map((e, t) => w(s.templateFn(e, t), u)).join("");
38
- if (s instanceof c) return w(s.template, u);
39
- if (s instanceof o) return w(s.factory(), u);
40
- if (s instanceof a) return w(s.value, u);
41
- if (s instanceof i) return w(f(s.component, s.fieldName), u);
36
+ if (Array.isArray(s)) return u.hydrate ? s.map((e) => `<!--CSA-S-->${T(e, u)}<!--CSA-E-->`).join("") : s.map((e) => T(e, u)).join("");
37
+ if (y(s)) return F(s, u);
38
+ if (s instanceof l) return T(s.value, u);
39
+ if (s instanceof d) return u.hydrate ? s.items.map((e, t) => `<!--CSA-S-->${T(s.templateFn(e, t), u)}<!--CSA-E-->`).join("") : s.items.map((e, t) => T(s.templateFn(e, t), u)).join("");
40
+ if (s instanceof c) return T(s.template, u);
41
+ if (s instanceof o) return T(s.factory(), u);
42
+ if (s instanceof a) return T(s.value, u);
43
+ if (s instanceof i) return T(f(s.component, s.fieldName), u);
42
44
  if (e(s)) {
43
45
  let e = new s.clazz();
44
46
  Object.assign(e, s.props), "props" in e && (e.props = s.props), e.children = s.children, e.__parent = s.parent || t.currentRenderingInstance, s.serviceScope && typeof e._setServiceScope == "function" && e._setServiceScope(s.serviceScope), e.__parent && (e._id = `${e.__parent._id}:${e.__parent._childCounter++}`), e.connectedCallback(), r(e), e.willUpdate(/* @__PURE__ */ new Map());
45
47
  let i = e._finalizeRenderOutput(e.render()), a = "";
46
- return i && (a = y(i) ? N(i, u) : N(h`${i}`, u)), n(), a;
48
+ return i && (a = y(i) ? F(i, u) : F(h`${i}`, u)), n(), a;
47
49
  }
48
- return S(s) ? s.value : typeof s == "function" || typeof s == "object" && s && "value" in s ? "" : C(s);
49
- }, T = /* @__PURE__ */ new Set([
50
+ return C(s) ? s.value : typeof s == "function" || typeof s == "object" && s && "value" in s ? "" : w(s);
51
+ }, E = /* @__PURE__ */ new Set([
52
+ "allowfullscreen",
53
+ "async",
54
+ "autofocus",
55
+ "autoplay",
50
56
  "checked",
57
+ "controls",
58
+ "default",
59
+ "defer",
51
60
  "disabled",
52
- "readonly",
53
- "required",
61
+ "formnovalidate",
54
62
  "hidden",
55
- "selected",
63
+ "inert",
64
+ "ismap",
65
+ "itemscope",
66
+ "loop",
56
67
  "multiple",
57
- "autofocus",
58
- "open"
59
- ]), E = (e, t) => {
68
+ "muted",
69
+ "nomodule",
70
+ "novalidate",
71
+ "open",
72
+ "playsinline",
73
+ "readonly",
74
+ "required",
75
+ "reversed",
76
+ "selected"
77
+ ]), D = (e, t) => E.has(e.toLowerCase()) ? t ? "" : null : String(t), O = (e, t) => {
60
78
  if (!(e === _ || typeof e != "object" || !e)) for (let [n, r] of Object.entries(e)) {
61
79
  if (n.startsWith("@")) continue;
62
80
  let e = n, a = r;
@@ -66,37 +84,41 @@ var m = class {
66
84
  }
67
85
  if (n.startsWith(".")) {
68
86
  if (e = n.slice(1), a instanceof i ? a = f(a.component, a.fieldName) : a instanceof l && (a = a.value), a === _) continue;
69
- if (T.has(e)) {
87
+ if (E.has(e)) {
70
88
  a && (t.result += ` ${e}`);
71
89
  continue;
72
90
  }
73
91
  }
74
92
  if ((e === "class" || e === "className") && typeof a == "string" && a) {
75
- let e = D(t.result, a);
93
+ let e = k(t.result, a);
76
94
  if (e !== null) {
77
95
  t.result = e;
78
96
  continue;
79
97
  }
80
98
  }
81
- a !== _ && (a instanceof s ? a.value !== void 0 && (t.result += ` ${e}="${C(String(a.value))}"`) : typeof a == "boolean" ? a && (t.result += ` ${e}`) : typeof a == "function" || a != null && (t.result += ` ${e}="${C(a)}"`));
99
+ if (a !== _) if (a instanceof s) a.value !== void 0 && (t.result += ` ${e}="${w(String(a.value))}"`);
100
+ else if (typeof a == "boolean") {
101
+ let n = D(e, a);
102
+ n === "" ? t.result += ` ${e}` : n !== null && (t.result += ` ${e}="${n}"`);
103
+ } else typeof a == "function" || a != null && (t.result += ` ${e}="${w(a)}"`);
82
104
  }
83
- }, D = (e, t) => {
105
+ }, k = (e, t) => {
84
106
  let n = e.lastIndexOf("<"), r = n >= 0 ? e.slice(n) : e, i = r.match(/(^|\s)class="([^"]*)"(\s|\/?>|$)/);
85
107
  if (!i) return null;
86
108
  let a = i[1], o = i[2], s = i[3], c = t.trim();
87
109
  if (!c) return e;
88
110
  let l = o ? `${o} ${c}` : c, u = r.replace(i[0], `${a}class="${l}"${s}`);
89
111
  return e.slice(0, n) + u;
90
- }, O = (e) => {
112
+ }, A = (e) => {
91
113
  let t = [], n = !1, r = null, i = /(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/;
92
114
  for (let a = 0; a < e.length - 1; a++) {
93
115
  let o = e[a];
94
- for (let e = 0; e < o.length; e++) r ? o[e] === r && (r = null) : o[e] === "\"" || o[e] === "'" ? e > 0 && o[e - 1] === "=" && (r = o[e]) : o[e] === "<" && o[e + 1] !== "!" && o[e + 1] !== "/" ? n = !0 : o[e] === ">" && (n = !1);
116
+ for (let e = 0; e < o.length; e++) r ? o[e] === r && (r = null) : n && (o[e] === "\"" || o[e] === "'") ? e > 0 && o[e - 1] === "=" && (r = o[e]) : o[e] === "<" && o[e + 1] !== "!" && o[e + 1] !== "/" ? n = !0 : o[e] === ">" && (n = !1);
95
117
  let s = o.match(i);
96
118
  t[a] = !(n && (s || r));
97
119
  }
98
120
  return t;
99
- }, k = (e) => {
121
+ }, j = (e) => {
100
122
  let t = 0, n;
101
123
  do
102
124
  n = `\uE000cossack:${t++}:`;
@@ -106,9 +128,9 @@ var m = class {
106
128
  marker: (e) => `${n}${e}${r}`,
107
129
  pattern: RegExp(`${n}(\\d+)${r}`, "g")
108
130
  };
109
- }, A = (e, t) => {
131
+ }, M = (e, t) => {
110
132
  if (!t) return e;
111
- let n = k(e), r = "";
133
+ let n = j(e), r = "";
112
134
  for (let t = 0; t < e.length; t++) r += e[t], t < e.length - 1 && (r += n.marker(t));
113
135
  let i = "", a = !1, o = null, s = "", c = "";
114
136
  for (let e = 0; e < r.length;) {
@@ -137,8 +159,8 @@ var m = class {
137
159
  let l = [], u = 0, d;
138
160
  for (; d = n.pattern.exec(i);) l.push(i.slice(u, d.index)), u = d.index + d[0].length;
139
161
  return l.push(i.slice(u)), l;
140
- }, j = (e, t) => {
141
- let n = k(e), r = "";
162
+ }, N = (e, t) => {
163
+ let n = j(e), r = "";
142
164
  for (let t = 0; t < e.length; t++) r += e[t], t < e.length - 1 && (r += n.marker(t));
143
165
  let i = /* @__PURE__ */ new Map(), a = /<(?![!/])(?:[^>"']|"[^"]*"|'[^']*')*>/g, o;
144
166
  for (; o = a.exec(r);) {
@@ -158,7 +180,7 @@ var m = class {
158
180
  }
159
181
  }
160
182
  return i;
161
- }, M = class {
183
+ }, P = class {
162
184
  resultObj;
163
185
  opts;
164
186
  result = "";
@@ -168,7 +190,7 @@ var m = class {
168
190
  strings;
169
191
  nothingAttributeGroups;
170
192
  constructor(e, t = {}) {
171
- this.resultObj = e, this.opts = t, this.strings = A(e.strings, e.__cossackScope), this.isNodePositions = O(this.strings), this.nothingAttributeGroups = j(this.strings, e.values);
193
+ this.resultObj = e, this.opts = t, this.strings = M(e.strings, e.__cossackScope), this.isNodePositions = A(this.strings), this.nothingAttributeGroups = N(this.strings, e.values);
172
194
  }
173
195
  scan() {
174
196
  let { values: e } = this.resultObj, t = this.strings;
@@ -180,14 +202,14 @@ var m = class {
180
202
  this.result.endsWith(a.prefix) && (this.result = this.result.slice(0, -a.prefix.length)), this.stringIdx = a.last, this.charIdxForNext = a.suffix.length, this.stringIdx++;
181
203
  continue;
182
204
  }
183
- if (r) {
205
+ if (r && !this.isNodePositions[this.stringIdx]) {
184
206
  let e = r[0], a = r[1];
185
207
  this.result = this.result.substring(0, this.result.length - e.length);
186
208
  let o = e.endsWith("\"") ? "\"" : e.endsWith("'") ? "'" : "", c = !0;
187
209
  if (a === "...") {
188
210
  this.result = this.result.trimEnd();
189
211
  let e = { result: this.result };
190
- E(n, e), this.result = e.result;
212
+ O(n, e), this.result = e.result;
191
213
  } else if (a === "ref") this.result = this.result.trimEnd();
192
214
  else if (a.startsWith("@")) this.result = this.result.trimEnd();
193
215
  else if (a.startsWith("?")) n ? (this.result = this.result.trimEnd(), this.result += ` ${a.slice(1)}`) : this.result = this.result.trimEnd();
@@ -195,29 +217,34 @@ var m = class {
195
217
  let e, t = n instanceof i;
196
218
  e = t ? f(n.component, n.fieldName) : n;
197
219
  let r = a.slice(1);
198
- t && T.has(r) ? (this.result = this.result.trimEnd(), e && (this.result += ` ${r}`)) : e != null && e !== !1 ? (this.result = this.result.trimEnd(), this.result += ` ${r}="${w(e, this.opts)}"`) : this.result = this.result.trimEnd();
199
- } else if (n instanceof s) n.value === void 0 ? this.result = this.result.trimEnd() : (this.result = this.result.trimEnd(), this.result += ` ${a}="${C(String(n.value))}"`);
200
- else {
220
+ t && E.has(r) ? (this.result = this.result.trimEnd(), e && (this.result += ` ${r}`)) : e != null && e !== !1 ? (this.result = this.result.trimEnd(), this.result += ` ${r}="${T(e, this.opts)}"`) : this.result = this.result.trimEnd();
221
+ } else if (n instanceof s) n.value === void 0 ? this.result = this.result.trimEnd() : (this.result = this.result.trimEnd(), this.result += ` ${a}="${w(String(n.value))}"`);
222
+ else if (n == null || n === _) this.result = this.result.trimEnd();
223
+ else if (typeof n == "boolean") {
224
+ this.result = this.result.trimEnd();
225
+ let e = D(a, n);
226
+ e === "" ? this.result += ` ${a}` : e !== null && (this.result += ` ${a}="${e}"`);
227
+ } else {
201
228
  this.result += e;
202
- let t = w(n, this.opts);
229
+ let t = T(n, this.opts);
203
230
  o ? (this.result += t, c = !1) : this.result += `"${t}"`;
204
231
  }
205
232
  if (o && c) {
206
233
  let e = t[this.stringIdx + 1];
207
234
  e && e.startsWith(o) && (this.charIdxForNext = 1);
208
235
  }
209
- } else this.opts.hydrate && this.isNodePositions[this.stringIdx] ? (this.result += `<!--CRP_${this.stringIdx}-->`, this.result += w(n, this.opts), this.result += "<!--/CRP-->") : this.result += w(n, this.opts);
236
+ } else this.opts.hydrate && this.isNodePositions[this.stringIdx] ? (this.result += `<!--CRP_${this.stringIdx}-->`, this.result += T(n, this.opts), this.result += "<!--/CRP-->") : this.result += T(n, this.opts);
210
237
  }
211
238
  this.stringIdx++;
212
239
  }
213
240
  return this.result;
214
241
  }
215
- }, N = (e, t = {}) => new M(e, t).scan(), P = /* @__PURE__ */ new WeakMap(), F = (e) => {
216
- let t = P.get(e.strings);
217
- t || (t = /* @__PURE__ */ new Map(), P.set(e.strings, t));
242
+ }, F = (e, t = {}) => new P(e, t).scan(), I = /* @__PURE__ */ new WeakMap(), L = (e) => {
243
+ let t = I.get(e.strings);
244
+ t || (t = /* @__PURE__ */ new Map(), I.set(e.strings, t));
218
245
  let n = `${e._$litType$}:${e.__cossackScope ?? ""}`, r = t.get(n);
219
246
  return r || (r = {}, t.set(n, r)), r;
220
- }, I = class n {
247
+ }, R = class n {
221
248
  startNode;
222
249
  endNode;
223
250
  componentInstance = null;
@@ -302,7 +329,7 @@ var m = class {
302
329
  if (t instanceof a) {
303
330
  let e = t.value;
304
331
  if (y(e)) {
305
- let t = F(e);
332
+ let t = L(e);
306
333
  this._cacheMap.has(t) ? this.updateCache(e) : (this._adoptTemplate(e), this._cacheCurrent = t);
307
334
  } else this._hydrateValue(e);
308
335
  return;
@@ -312,7 +339,7 @@ var m = class {
312
339
  return;
313
340
  }
314
341
  if (!(t instanceof Node)) {
315
- if (S(t)) {
342
+ if (C(t)) {
316
343
  if (this.startNode.nextSibling !== this.endNode) return;
317
344
  this.clear(), this._clearTemplateCache(), this.updateNode(t);
318
345
  return;
@@ -334,7 +361,7 @@ var m = class {
334
361
  if (t) if (t = !1, y(e)) try {
335
362
  this._adoptTemplate(e);
336
363
  } catch (t) {
337
- if (t instanceof U) this.clear(), this._clearTemplateCache(), this.updateNode(e);
364
+ if (t instanceof K) this.clear(), this._clearTemplateCache(), this.updateNode(e);
338
365
  else throw t;
339
366
  }
340
367
  else e == null ? this.clear() : this.updateNode(e);
@@ -345,8 +372,8 @@ var m = class {
345
372
  Object.assign(r, e.props), "props" in r && (r.props = e.props), r.children = e.children, r.requestUpdate();
346
373
  }
347
374
  _adoptSequence(e, t) {
348
- let r = K(this._nodesBetween());
349
- if (r.length !== e.length) throw new U(`sequence length mismatch: SSR has ${r.length} items, client has ${e.length}`);
375
+ let r = Y(this._nodesBetween());
376
+ if (r.length !== e.length) throw new K(`sequence length mismatch: SSR has ${r.length} items, client has ${e.length}`);
350
377
  this._childParts = [], this._partKeys = t ? [] : this._partKeys;
351
378
  for (let i = 0; i < e.length; i++) {
352
379
  let [a, o] = r[i], s = new n(a, o);
@@ -354,10 +381,10 @@ var m = class {
354
381
  }
355
382
  }
356
383
  _adoptTemplate(e) {
357
- let { fragment: t, parts: n } = V(e), r = this._nodesBetween(), i = /* @__PURE__ */ new Map();
358
- q(t.childNodes, r, i), J(n, i);
384
+ let { fragment: t, parts: n } = W(e), r = this._nodesBetween(), i = /* @__PURE__ */ new Map();
385
+ X(t.childNodes, r, i), Z(n, i);
359
386
  for (let t = 0; t < e.values.length; t++) n[t] && n[t].update(e.values[t]);
360
- this._cachedTemplateIdentity = F(e), this._cachedParts = n;
387
+ this._cachedTemplateIdentity = L(e), this._cachedParts = n;
361
388
  }
362
389
  _nodesBetween() {
363
390
  let e = [], t = this.startNode.nextSibling;
@@ -399,7 +426,7 @@ var m = class {
399
426
  this._keySet = !0, this._key = e.value, t && (this.componentInstance && this.disposeComponent(), this._clearTemplateCache(), this.clear()), this.updateNode(e.template);
400
427
  }
401
428
  updateCache(e) {
402
- let t = F(e);
429
+ let t = L(e);
403
430
  if (this._cacheCurrent === t && this._cachedParts) {
404
431
  this._cachedParts.forEach((t, n) => {
405
432
  t.update(e.values[n]);
@@ -467,24 +494,24 @@ var m = class {
467
494
  this._cacheCurrent = null, this.clearChildParts(), this.startNode.parentNode && this.startNode.parentNode.removeChild(this.startNode), this.endNode.parentNode && this.endNode.parentNode.removeChild(this.endNode), this.componentInstance &&= (this.teardownComponent(this.componentInstance), null);
468
495
  }
469
496
  updateNode(t) {
470
- if (this.startNode.parentNode) if (y(t)) if (this._cachedTemplateIdentity === F(t) && this._cachedParts) this._cachedParts.forEach((e, n) => {
497
+ if (this.startNode.parentNode) if (y(t)) if (this._cachedTemplateIdentity === L(t) && this._cachedParts) this._cachedParts.forEach((e, n) => {
471
498
  e.update(t.values[n]);
472
499
  });
473
500
  else {
474
501
  this._clearTemplateCache(), this.clear();
475
502
  let e = document.createDocumentFragment();
476
- H(t, e), this.startNode.parentNode.insertBefore(e, this.endNode);
477
- let n = B.get(e.firstChild?.childNodes[0] || e);
503
+ G(t, e), this.startNode.parentNode.insertBefore(e, this.endNode);
504
+ let n = U.get(e.firstChild?.childNodes[0] || e);
478
505
  n && (this._cachedTemplateIdentity = n.identity, this._cachedParts = n.parts);
479
506
  }
480
- else if (S(t)) {
507
+ else if (C(t)) {
481
508
  this._clearTemplateCache(), this.clear();
482
509
  let e = document.createElement("template");
483
510
  e.innerHTML = t.value, this.startNode.parentNode.insertBefore(e.content, this.endNode);
484
511
  } else if (e(t) || typeof t == "object" && t && !(t instanceof Node) && !Array.isArray(t)) {
485
512
  this._clearTemplateCache(), this.clear();
486
513
  let e = document.createDocumentFragment();
487
- H(h`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
514
+ G(h`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
488
515
  } else if (t instanceof Node) this._clearTemplateCache(), this.clear(), this.startNode.parentNode.insertBefore(t, this.endNode);
489
516
  else if (t === _ || t === "" || t == null || t === !1) this._clearTemplateCache(), this.clear();
490
517
  else {
@@ -508,7 +535,7 @@ var m = class {
508
535
  e.parentNode.removeChild(e), e = t;
509
536
  }
510
537
  }
511
- }, L = class {
538
+ }, z = class {
512
539
  element;
513
540
  previousValues = {};
514
541
  bindStates = /* @__PURE__ */ new Map();
@@ -558,7 +585,14 @@ var m = class {
558
585
  e.value !== t && (e.value = t);
559
586
  }
560
587
  } else n instanceof i ? this.element[t] = f(n.component, n.fieldName) : n instanceof l ? this.element[t] = n.value : this.element[t] = n;
561
- } else e.startsWith("?") ? n !== _ && n ? this.element.setAttribute(e.slice(1), "") : this.element.removeAttribute(e.slice(1)) : n === _ ? e === "class" || e === "className" ? this.applySpreadClass("") : this.element.removeAttribute(e) : n instanceof s ? n.value === void 0 ? this.element.removeAttribute(e) : this.element.setAttribute(e, String(n.value)) : typeof n == "boolean" ? n ? this.element.setAttribute(e, "") : this.element.removeAttribute(e) : (e === "class" || e === "className") && typeof n == "string" ? this.applySpreadClass(n) : n != null && this.element.setAttribute(e, String(n));
588
+ } else if (e.startsWith("?")) n !== _ && n ? this.element.setAttribute(e.slice(1), "") : this.element.removeAttribute(e.slice(1));
589
+ else if (n === _) e === "class" || e === "className" ? this.applySpreadClass("") : this.element.removeAttribute(e);
590
+ else if (n instanceof s) n.value === void 0 ? this.element.removeAttribute(e) : this.element.setAttribute(e, String(n.value));
591
+ else if (n == null) this.element.removeAttribute(e);
592
+ else if (typeof n == "boolean") {
593
+ let t = D(e, n);
594
+ t === null ? this.element.removeAttribute(e) : this.element.setAttribute(e, t);
595
+ } else (e === "class" || e === "className") && typeof n == "string" ? this.applySpreadClass(n) : this.element.setAttribute(e, String(n));
562
596
  this.previousValues = { ...t };
563
597
  }
564
598
  applySpreadClass(e) {
@@ -574,9 +608,9 @@ var m = class {
574
608
  (!o || o.lastKind !== "checked" || o.lastValue !== e) && (r.checked = e);
575
609
  } else {
576
610
  let e = a == null ? "" : String(a);
577
- (!o || o.lastKind !== "value" || String(o.lastValue) !== e) && (r.value = e);
611
+ (!o || o.lastKind !== "value" || String(o.lastValue) !== e || this.element instanceof HTMLSelectElement && r.value !== e) && (r.value = e);
578
612
  }
579
- let s = z(this.element, t), c = !!o && (o.boundComponent !== i || o.boundField !== n.fieldName || o.listener.__eventName !== s);
613
+ let s = H(this.element, t), c = !!o && (o.boundComponent !== i || o.boundField !== n.fieldName || o.listener.__eventName !== s);
580
614
  if (o && c && (this.element.removeEventListener(o.listener.__eventName, o.listener), this.bindStates.delete(e), o = void 0), o) o.lastKind = t, o.lastValue = t === "checked" ? !!a : a == null ? "" : String(a);
581
615
  else {
582
616
  let r = (e) => {
@@ -589,10 +623,10 @@ var m = class {
589
623
  lastValue: t === "checked" ? !!a : a == null ? "" : String(a),
590
624
  boundComponent: i,
591
625
  boundField: n.fieldName
592
- }, this.bindStates.set(e, o);
626
+ }, this.bindStates.set(e, o), t === "value" && V(this.element, () => this.bindStates.get(e) === o, () => f(o.boundComponent, o.boundField));
593
627
  }
594
628
  }
595
- }, R = class {
629
+ }, B = class {
596
630
  element;
597
631
  name;
598
632
  segments;
@@ -686,7 +720,12 @@ var m = class {
686
720
  } else if (this.name.startsWith("?")) {
687
721
  let t = this.name.slice(1);
688
722
  e ? this.element.setAttribute(t, "") : this.element.removeAttribute(t), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
689
- } else n ? e === void 0 ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]) : 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]);
723
+ } else if (n) e === void 0 ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]);
724
+ else if (e == null) this.element.removeAttribute(this.name);
725
+ else if (typeof e == "boolean") {
726
+ let t = D(this.name, e);
727
+ t === null ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t);
728
+ } else this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]);
690
729
  }
691
730
  updateBind(e) {
692
731
  let t = this.name.startsWith(".") ? this.name.slice(1) : this.name;
@@ -700,19 +739,28 @@ var m = class {
700
739
  (this.lastFormKind !== "checked" || this.lastFormValue !== e) && (n.checked = e, this.lastFormValue = e, this.lastFormKind = "checked");
701
740
  } else {
702
741
  let e = i == null ? "" : String(i);
703
- (this.lastFormKind !== "value" || String(this.lastFormValue) !== e) && (n.value = e, this.lastFormValue = e, this.lastFormKind = "value");
742
+ (this.lastFormKind !== "value" || String(this.lastFormValue) !== e || this.element instanceof HTMLSelectElement && n.value !== e) && (n.value = e, this.lastFormValue = e, this.lastFormKind = "value");
704
743
  }
705
- let a = z(this.element, t);
744
+ let a = H(this.element, t);
706
745
  if (this.bindListener && (this.boundPropName !== t || this.boundComponent !== r || this.boundFieldName !== e.fieldName || this.bindListener.__eventName !== a) && this._detachBindListener(), !this.bindListener) {
707
746
  let n = (n) => {
708
747
  let i = n.currentTarget, a = t === "checked" ? !!i[t] : i[t];
709
748
  r && p(r, e.fieldName, a);
710
749
  };
711
- n.__eventName = a, this.bindListener = n, this.boundPropName = t, this.boundComponent = r, this.boundFieldName = e.fieldName, this.element.addEventListener(a, n);
750
+ if (n.__eventName = a, this.bindListener = n, this.boundPropName = t, this.boundComponent = r, this.boundFieldName = e.fieldName, this.element.addEventListener(a, n), t === "value") {
751
+ let e = n;
752
+ V(this.element, () => this.bindListener === e, () => f(this.boundComponent, this.boundFieldName));
753
+ }
712
754
  }
713
755
  this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
714
756
  }
715
- }, z = (e, t) => {
757
+ }, V = (e, t, n) => {
758
+ e instanceof HTMLSelectElement && queueMicrotask(() => {
759
+ if (!t()) return;
760
+ let r = n(), i = r == null ? "" : String(r);
761
+ e.value !== i && (e.value = i);
762
+ });
763
+ }, H = (e, t) => {
716
764
  if (e instanceof HTMLSelectElement) return "change";
717
765
  if (e instanceof HTMLTextAreaElement) return "input";
718
766
  if (e instanceof HTMLInputElement) {
@@ -720,11 +768,11 @@ var m = class {
720
768
  return t === "checked" || n === "checkbox" || n === "radio" || n === "range" ? "change" : "input";
721
769
  }
722
770
  return "input";
723
- }, B = /* @__PURE__ */ new WeakMap(), V = (e) => {
724
- let t = [], n = A(e.strings, e.__cossackScope), r = "", i = !1, a = null, o = /(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/;
771
+ }, U = /* @__PURE__ */ new WeakMap(), W = (e) => {
772
+ let t = [], n = M(e.strings, e.__cossackScope), r = "", i = !1, a = null, o = /(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/;
725
773
  for (let e = 0; e < n.length - 1; e++) {
726
774
  let t = n[e];
727
- for (let e = 0; e < t.length; e++) a ? t[e] === a && (a = null) : t[e] === "\"" || t[e] === "'" ? e > 0 && t[e - 1] === "=" && (a = t[e]) : t[e] === "<" && t[e + 1] !== "!" && t[e + 1] !== "/" ? i = !0 : t[e] === ">" && (i = !1);
775
+ for (let e = 0; e < t.length; e++) a ? t[e] === a && (a = null) : i && (t[e] === "\"" || t[e] === "'") ? e > 0 && t[e - 1] === "=" && (a = t[e]) : t[e] === "<" && t[e + 1] !== "!" && t[e + 1] !== "/" ? i = !0 : t[e] === ">" && (i = !1);
728
776
  r += t;
729
777
  let s = t.match(o);
730
778
  if (i && (s || a)) {
@@ -752,7 +800,7 @@ var m = class {
752
800
  if (n) {
753
801
  let r = parseInt(n[1]), i = document.createComment("/CRP");
754
802
  e.parentNode.insertBefore(i, e.nextSibling);
755
- let a = new I(e, i);
803
+ let a = new R(e, i);
756
804
  t[r] = a;
757
805
  }
758
806
  } else if (e.nodeType === Node.ELEMENT_NODE) {
@@ -763,10 +811,10 @@ var m = class {
763
811
  if (r.length === 1) {
764
812
  let i = parseInt(r[0][1]);
765
813
  if (!t[i]) if (e.name === "...") {
766
- let e = new L(n);
814
+ let e = new z(n);
767
815
  t[i] = e, n.removeAttribute("...");
768
816
  } else {
769
- let r = new R(n, e.name, e.value);
817
+ let r = new B(n, e.name, e.value);
770
818
  t[i] = r;
771
819
  }
772
820
  return;
@@ -776,7 +824,7 @@ var m = class {
776
824
  for (let r = 0; r < i.length; r++) {
777
825
  let o = i[r];
778
826
  if (!t[o]) {
779
- let i = new R(n, e.name, e.value, {
827
+ let i = new B(n, e.name, e.value, {
780
828
  currentValues: a,
781
829
  position: r
782
830
  });
@@ -789,8 +837,8 @@ var m = class {
789
837
  fragment: l,
790
838
  parts: t
791
839
  };
792
- }, H = (e, t) => {
793
- let n = B.get(t), r = F(e);
840
+ }, G = (e, t) => {
841
+ let n = U.get(t), r = L(e);
794
842
  if (n && n.identity === r) {
795
843
  n.parts.forEach((t, n) => {
796
844
  t.update(e.values[n]);
@@ -798,22 +846,22 @@ var m = class {
798
846
  return;
799
847
  }
800
848
  if (n) for (let e of n.parts) e && typeof e.dispose == "function" && e.dispose();
801
- let { fragment: i, parts: a } = V(e), o = e.values;
849
+ let { fragment: i, parts: a } = W(e), o = e.values;
802
850
  for (let e = 0; e < o.length; e++) a[e] && a[e].update(o[e]);
803
851
  if (typeof HTMLElement < "u" && t instanceof HTMLElement || typeof ShadowRoot < "u" && t instanceof ShadowRoot) t.innerHTML = "";
804
852
  else for (; t.firstChild;) t.removeChild(t.firstChild);
805
- t.appendChild(i), B.set(t, {
853
+ t.appendChild(i), U.set(t, {
806
854
  identity: r,
807
855
  parts: a
808
856
  });
809
- }, U = class extends Error {}, W = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? `<${e.nodeName.toLowerCase()}>` : e.nodeType === Node.COMMENT_NODE ? `<!--${e.nodeValue}-->` : e.nodeType === Node.TEXT_NODE ? `text"${(e.nodeValue || "").slice(0, 30)}"` : `nodeType:${e.nodeType}` : "<none>", G = (e) => {
857
+ }, K = class extends Error {}, q = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? `<${e.nodeName.toLowerCase()}>` : e.nodeType === Node.COMMENT_NODE ? `<!--${e.nodeValue}-->` : e.nodeType === Node.TEXT_NODE ? `text"${(e.nodeValue || "").slice(0, 30)}"` : `nodeType:${e.nodeType}` : "<none>", J = (e) => {
810
858
  if (e.nodeType === Node.TEXT_NODE) return (e.nodeValue || "").trim() === "";
811
859
  if (e.nodeType === Node.COMMENT_NODE) {
812
860
  let t = e.nodeValue || "";
813
861
  return !/^CRP_\d+$/.test(t) && t !== "/CRP" && t !== "CSA-S" && t !== "CSA-E";
814
862
  }
815
863
  return !1;
816
- }, K = (e) => {
864
+ }, Y = (e) => {
817
865
  let t = [], n = [];
818
866
  for (let r of e) {
819
867
  if (r.nodeType !== Node.COMMENT_NODE) continue;
@@ -825,50 +873,50 @@ var m = class {
825
873
  }
826
874
  }
827
875
  return t;
828
- }, q = (e, t, n) => {
829
- let r = 0;
830
- for (let i = 0; i < e.length; i++) {
831
- let a = e[i];
832
- if (G(a)) continue;
833
- for (; r < t.length && G(t[r]);) r++;
834
- let o = t[r];
835
- if (!o) throw new U(`existing shorter than blueprint (expected ${W(a)})`);
836
- if (a.nodeType === Node.ELEMENT_NODE) {
837
- if (o.nodeType !== Node.ELEMENT_NODE || a.nodeName !== o.nodeName || a.namespaceURI !== o.namespaceURI) throw new U(`tag mismatch: blueprint ${W(a)} vs existing ${W(o)}`);
838
- n.set(a, o), q(a.childNodes, Array.from(o.childNodes), n);
876
+ }, X = (e, t, n, r = "root") => {
877
+ let i = 0;
878
+ for (let a = 0; a < e.length; a++) {
879
+ let o = e[a];
880
+ if (J(o)) continue;
881
+ for (; i < t.length && J(t[i]);) i++;
882
+ let s = t[i];
883
+ if (!s) throw new K(`existing shorter than blueprint at ${r} (expected ${q(o)})`);
884
+ if (o.nodeType === Node.ELEMENT_NODE) {
885
+ if (s.nodeType !== Node.ELEMENT_NODE || o.nodeName !== s.nodeName || o.namespaceURI !== s.namespaceURI) throw new K(`tag mismatch: blueprint ${q(o)} vs existing ${q(s)}`);
886
+ n.set(o, s), X(o.childNodes, Array.from(s.childNodes), n, `${r}/${o.nodeName.toLowerCase()}[${a}]`);
839
887
  } else {
840
- if (a.nodeType !== o.nodeType) throw new U(`type mismatch: blueprint ${W(a)} vs existing ${W(o)}`);
841
- n.set(a, o);
888
+ if (o.nodeType !== s.nodeType) throw new K(`type mismatch: blueprint ${q(o)} vs existing ${q(s)}`);
889
+ n.set(o, s);
842
890
  }
843
- if (r++, a.nodeType === Node.COMMENT_NODE && /^CRP_\d+$/.test(a.nodeValue || "")) {
891
+ if (i++, o.nodeType === Node.COMMENT_NODE && /^CRP_\d+$/.test(o.nodeValue || "")) {
844
892
  let e = 1;
845
- for (; r < t.length && e > 0;) {
846
- let n = t[r];
893
+ for (; i < t.length && e > 0;) {
894
+ let n = t[i];
847
895
  if (n.nodeType === Node.COMMENT_NODE) {
848
896
  if (/^CRP_\d+$/.test(n.nodeValue || "")) e++;
849
897
  else if (n.nodeValue === "/CRP" && (e--, e === 0)) break;
850
898
  }
851
- r++;
899
+ i++;
852
900
  }
853
901
  }
854
902
  }
855
- for (; r < t.length && G(t[r]);) r++;
856
- if (r < t.length) throw new U(`existing longer than blueprint (unexpected ${W(t[r])})`);
857
- }, J = (e, t) => {
903
+ for (; i < t.length && J(t[i]);) i++;
904
+ if (i < t.length) throw new K(`existing longer than blueprint (unexpected ${q(t[i])})`);
905
+ }, Z = (e, t) => {
858
906
  for (let n of e) if (n) {
859
- if (n instanceof I) {
907
+ if (n instanceof R) {
860
908
  let e = t.get(n.startNode), r = t.get(n.endNode);
861
- if (!e || !r) throw new U("node part anchors not found");
909
+ if (!e || !r) throw new K("node part anchors not found");
862
910
  n.startNode = e, n.endNode = r, n._beginHydration();
863
- } else if (n instanceof R || n instanceof L) {
911
+ } else if (n instanceof B || n instanceof z) {
864
912
  let e = t.get(n.element);
865
- if (!e) throw new U("attribute part element not found");
913
+ if (!e) throw new K("attribute part element not found");
866
914
  n.element = e;
867
915
  }
868
916
  }
869
- }, Y = (e, t) => {
870
- if (!t.hasChildNodes()) return H(e, t);
871
- let n = B.get(t), r = F(e);
917
+ }, Q = (e, t) => {
918
+ if (!t.hasChildNodes()) return G(e, t);
919
+ let n = U.get(t), r = L(e);
872
920
  if (n && n.identity === r) {
873
921
  n.parts.forEach((t, n) => t.update(e.values[n]));
874
922
  return;
@@ -876,19 +924,19 @@ var m = class {
876
924
  if (n) for (let e of n.parts) e && typeof e.dispose == "function" && e.dispose();
877
925
  let i;
878
926
  try {
879
- let { fragment: n, parts: r } = V(e);
927
+ let { fragment: n, parts: r } = W(e);
880
928
  i = r;
881
929
  let a = /* @__PURE__ */ new Map();
882
- q(n.childNodes, Array.from(t.childNodes), a), J(i, a);
930
+ X(n.childNodes, Array.from(t.childNodes), a), Z(i, a);
883
931
  for (let t = 0; t < e.values.length; t++) i[t] && i[t].update(e.values[t]);
884
932
  } catch (n) {
885
- if (n instanceof U) return console.warn("[cossack] hydration mismatch, falling back to render:", n.message), H(e, t);
933
+ if (n instanceof K) return console.warn("[cossack] hydration mismatch, falling back to render:", n.message), G(e, t);
886
934
  throw n;
887
935
  }
888
- B.set(t, {
936
+ U.set(t, {
889
937
  identity: r,
890
938
  parts: i
891
939
  });
892
940
  };
893
941
  //#endregion
894
- export { m as TemplateResult, b as UnsafeHTMLResult, v as component, C as escapeHtml, h as html, Y as hydrate, y as isTemplateResult, S as isUnsafeHTML, _ as nothing, H as render, N as renderToString, g as svg, x as unsafeHTML };
942
+ export { m as TemplateResult, x as UnsafeHTMLResult, v as component, w as escapeHtml, h as html, Q as hydrate, y as isTemplateResult, C as isUnsafeHTML, _ as nothing, G as render, F as renderToString, g as svg, S as unsafeHTML };
package/dist/css.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./css.d.ts"
1
2
  import e from "css-tree/parser";
2
3
  import t from "css-tree/generator";
3
4
  import n from "css-tree/walker";
@@ -2,11 +2,11 @@ export declare class LiveResult {
2
2
  readonly value: unknown;
3
3
  constructor(value: unknown);
4
4
  }
5
- export declare class RepeatResult {
6
- readonly items: unknown[];
7
- readonly keyFn: (item: any, index: number) => unknown;
8
- readonly templateFn: (item: any, index: number) => unknown;
9
- constructor(items: unknown[], keyFn: (item: any, index: number) => unknown, templateFn: (item: any, index: number) => unknown);
5
+ export declare class RepeatResult<T = unknown> {
6
+ readonly items: readonly T[];
7
+ readonly keyFn: (item: T, index: number) => unknown;
8
+ readonly templateFn: (item: T, index: number) => unknown;
9
+ constructor(items: readonly T[], keyFn: (item: T, index: number) => unknown, templateFn: (item: T, index: number) => unknown);
10
10
  }
11
11
  export declare class KeyResult {
12
12
  readonly value: unknown;
@@ -45,7 +45,8 @@ export declare const live: (value: unknown) => LiveResult;
45
45
  * Repeats a template for each item in an array, using a key to maintain state.
46
46
  * Usage: repeat(items, (item) => item.id, (item) => html`...`)
47
47
  */
48
- export declare const repeat: (items: unknown[], keyFnOrTemplate: (item: any, index: number) => unknown, template?: (item: any, index: number) => unknown) => RepeatResult;
48
+ export declare function repeat<T>(items: readonly T[], template: (item: T, index: number) => unknown): RepeatResult<T>;
49
+ export declare function repeat<T>(items: readonly T[], keyFn: (item: T, index: number) => unknown, template: (item: T, index: number) => unknown): RepeatResult<T>;
49
50
  /**
50
51
  * Generates a class string from an object.
51
52
  * Usage: class="${classMap({ active: isActive })}"
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./directives.d.ts"
1
2
  //#region src/directives.ts
2
3
  var e = class {
3
4
  value;
@@ -45,7 +46,11 @@ var e = class {
45
46
  constructor(e) {
46
47
  this.value = e;
47
48
  }
48
- }, c = (t) => new e(t), l = (e, n, r) => r === void 0 ? new t(e, (e, t) => t, n) : new t(e, n, r), u = (e) => Object.keys(e).filter((t) => e[t]).join(" "), d = (e) => Object.keys(e).filter((t) => e[t] != null).map((t) => `${t}:${e[t]}`).join(";"), f = (e, t) => new n(e, t), p = (e, t) => new r(e, t);
49
+ }, c = (t) => new e(t);
50
+ function l(e, n, r) {
51
+ return r === void 0 ? new t(e, (e, t) => t, n) : new t(e, n, r);
52
+ }
53
+ var u = (e) => Object.keys(e).filter((t) => e[t]).join(" "), d = (e) => Object.keys(e).filter((t) => e[t] != null).map((t) => `${t}:${e[t]}`).join(";"), f = (e, t) => new n(e, t), p = (e, t) => new r(e, t);
49
54
  function m(e, t) {
50
55
  let n = e;
51
56
  if (!t.includes(".")) return n?.[t];
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './cossack-html';
2
- export * from './cossack-element';
3
- export * from './component';
4
- export * from './context';
5
- export * from './directives';
6
- export { css, unsafeCSS, CSSResult } from './css';
7
- export type { CSSResultGroup } from './css';
1
+ export * from './cossack-html.js';
2
+ export * from './cossack-element.js';
3
+ export * from './component.js';
4
+ export * from './context.js';
5
+ export * from './directives.js';
6
+ export { css, unsafeCSS, CSSResult } from './css.js';
7
+ export type { CSSResultGroup } from './css.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./index.d.ts"
1
2
  import { isComponentResult as e } from "./component.js";
2
3
  import { CSSResult as t, css as n, unsafeCSS as r } from "./css.js";
3
4
  import { CossackElement as i, instanceStack as a, popCurrentInstance as o, pushCurrentInstance as s } from "./cossack-element.js";
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./minify-html.d.ts"
1
2
  //#region src/minify-html.ts
2
3
  var e = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, t = RegExp(`<(${[.../* @__PURE__ */ new Set([
3
4
  "area",
@@ -14,7 +15,7 @@ var e = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, t = RegExp(`<(${
14
15
  "source",
15
16
  "track",
16
17
  "wbr"
17
- ])].join("|")})(\\s[^>]*)?\\/\\s*>`, "gi"), n = /\s+type\s*=\s*["']text\/(javascript|css)["']/gi, r = /(\w[\w-]*)\s*=\s*["']([a-zA-Z0-9_.-]+)["'](?=\s|\/?>)/g;
18
+ ])].join("|")})(\\s[^>]*)?\\/\\s*>`, "gi"), n = /\s+type\s*=\s*["']text\/(javascript|css)["']/gi, r = /(\w[\w-]*)\s*=\s*["']([a-zA-Z0-9_.-]+)["'](?=(\s|\/?>))/g;
18
19
  function i(t) {
19
20
  let r = [];
20
21
  return {
@@ -30,7 +31,7 @@ function a(e, t) {
30
31
  }
31
32
  function o(e) {
32
33
  let { html: o, blocks: s } = i(e), c = o.replace(/<!--(?!\[if\s|\/?CRP|CSA-[SE])[\s\S]*?-->/g, "");
33
- return c = c.replace(n, ""), c = c.replace(/\s+/g, " "), c = c.replace(/>\s+</g, "><"), c = c.replace(r, (e, t, n) => `${t}=${n}`), c = c.replace(t, (e, t, n) => `<${t}${n ? n.trimEnd() : ""}>`), c = a(c, s), c = c.replace(/>\s+</g, "><"), c = c.trim(), c;
34
+ return c = c.replace(n, ""), c = c.replace(/\s+/g, " "), c = c.replace(/>\s+</g, "><"), c = c.replace(r, (e, t, n, r) => r === "/>" ? e : `${t}=${n}`), c = c.replace(t, (e, t, n) => `<${t}${n ? n.trimEnd() : ""}>`), c = a(c, s), c = c.replace(/>\s+</g, "><"), c = c.trim(), c;
34
35
  }
35
36
  //#endregion
36
37
  export { o as minifyHtml };
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { renderToString, escapeHtml } from './cossack-html';
2
- export { html, svg, nothing, TemplateResult } from './cossack-html';
3
- export type { SVGTemplateResult, ValueSanitizer, SanitizerFactory } from './cossack-html';
4
- export { css, unsafeCSS, CSSResult } from './css';
5
- export type { CSSResultGroup } from './css';
6
- export { minifyHtml } from './minify-html';
1
+ export { renderToString, escapeHtml } from './cossack-html.js';
2
+ export { html, svg, nothing, TemplateResult } from './cossack-html.js';
3
+ export type { SVGTemplateResult, ValueSanitizer, SanitizerFactory } from './cossack-html.js';
4
+ export { css, unsafeCSS, CSSResult } from './css.js';
5
+ export type { CSSResultGroup } from './css.js';
6
+ export { minifyHtml } from './minify-html.js';
package/dist/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-self-types="./server.d.ts"
1
2
  import { CSSResult as e, css as t, unsafeCSS as n } from "./css.js";
2
3
  import { TemplateResult as r, escapeHtml as i, html as a, nothing as o, renderToString as s, svg as c } from "./cossack-html.js";
3
4
  import { minifyHtml as l } from "./minify-html.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cossackframework/renderer",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "The rendering engine for Cossack Framework. Lit inspired, light dom, ssr",
@@ -18,12 +18,12 @@
18
18
  ],
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./dist/index.js",
22
- "types": "./dist/index.d.ts"
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
23
  },
24
24
  "./server": {
25
- "import": "./dist/server.js",
26
- "types": "./dist/server.d.ts"
25
+ "types": "./dist/server.d.ts",
26
+ "import": "./dist/server.js"
27
27
  }
28
28
  },
29
29
  "publishConfig": {
@@ -33,13 +33,14 @@
33
33
  "css-tree": "^3.2.1"
34
34
  },
35
35
  "devDependencies": {
36
+ "happy-dom": "^20.11.1",
36
37
  "oxlint": "^1.41.0",
37
38
  "typescript": "^7.0.2",
38
39
  "vite": "^8.1.4",
39
- "vitest": "^4.1.10"
40
+ "vitest": "^4.1.11"
40
41
  },
41
42
  "scripts": {
42
- "build": "vite build && tsc -p tsconfig.declarations.json",
43
+ "build": "vite build && tsc -p tsconfig.declarations.json && node ../../scripts/rewrite-declaration-imports.mjs dist",
43
44
  "test": "vitest",
44
45
  "lint": "oxlint"
45
46
  }