@cossackframework/renderer 0.0.1

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 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { CossackElement } from './cossack-element';
2
+
3
+ export interface ComponentResult {
4
+ _type: 'COMPONENT';
5
+ clazz: new () => CossackElement;
6
+ props: Record<string, unknown>;
7
+ children: unknown;
8
+ }
9
+ export declare const isComponentResult: (value: unknown) => value is ComponentResult;
@@ -0,0 +1,5 @@
1
+ export interface Context<T> {
2
+ id: string;
3
+ defaultValue?: T;
4
+ }
5
+ export declare function createContext<T>(defaultValue?: T): Context<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ import { TemplateResult } from './cossack-html';
2
+ import { Context } from './context';
3
+
4
+ export type PropertyDeclaration = {
5
+ type?: unknown;
6
+ reflect?: boolean;
7
+ state?: boolean;
8
+ };
9
+ export interface PropertyDeclarations {
10
+ [key: string]: PropertyDeclaration;
11
+ }
12
+ export type PropertyValues = Map<string | number | symbol, unknown>;
13
+ export interface ReactiveController {
14
+ hostConnected?(): void;
15
+ hostDisconnected?(): void;
16
+ hostUpdate?(): void;
17
+ hostUpdated?(): void;
18
+ }
19
+ export interface ReactiveControllerHost {
20
+ requestUpdate(): void;
21
+ addController(controller: ReactiveController): void;
22
+ removeController(controller: ReactiveController): void;
23
+ readonly updateComplete: Promise<boolean>;
24
+ }
25
+ export declare const instanceStack: CossackElement[];
26
+ export declare const pushCurrentInstance: (instance: CossackElement) => number;
27
+ export declare const popCurrentInstance: () => CossackElement | undefined;
28
+ export declare class CossackElement implements ReactiveControllerHost {
29
+ static properties: PropertyDeclarations;
30
+ static readonly _isCossackElement = true;
31
+ children: unknown;
32
+ props: Record<string, unknown>;
33
+ __parent: CossackElement | null;
34
+ _id: string;
35
+ _childCounter: number;
36
+ private __providedContexts;
37
+ private __properties;
38
+ private __updatePromise;
39
+ private __changedProperties;
40
+ private __renderListeners;
41
+ private __controllers;
42
+ private __hasConnected;
43
+ private __eventListeners;
44
+ constructor();
45
+ static get currentRenderingInstance(): CossackElement | null;
46
+ resetRenderState(): void;
47
+ addController(controller: ReactiveController): void;
48
+ removeController(controller: ReactiveController): void;
49
+ get updateComplete(): Promise<boolean>;
50
+ private initialize;
51
+ private createProperty;
52
+ provide<T>(context: Context<T>, value: T): void;
53
+ consume<T>(context: Context<T>): T | undefined;
54
+ requestUpdate(name?: string, oldValue?: unknown): Promise<boolean>;
55
+ protected performUpdate(): Promise<boolean>;
56
+ private __notifyListeners;
57
+ addRenderListener(listener: (template: TemplateResult | unknown | null) => void): void;
58
+ removeRenderListener(listener: (template: TemplateResult | unknown | null) => void): void;
59
+ mount(container: HTMLElement): void;
60
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, _options?: boolean | AddEventListenerOptions): void;
61
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, _options?: boolean | EventListenerOptions): void;
62
+ dispatchEvent(event: Event): boolean;
63
+ shouldUpdate(_changedProperties: PropertyValues): boolean;
64
+ willUpdate(_changedProperties: PropertyValues): void;
65
+ render(): TemplateResult | null;
66
+ updated(_changedProperties: PropertyValues): void;
67
+ connectedCallback(): void;
68
+ disconnectedCallback(): void;
69
+ }
@@ -0,0 +1,21 @@
1
+ import { CossackElement } from './cossack-element';
2
+
3
+ export declare class TemplateResult {
4
+ readonly strings: TemplateStringsArray;
5
+ readonly values: unknown[];
6
+ readonly _cossack_template_result = true;
7
+ constructor(strings: TemplateStringsArray, values: unknown[]);
8
+ }
9
+ export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
10
+ export declare const svg: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
11
+ export declare const component: <T extends CossackElement>(clazz: new () => T, props?: Record<string, unknown>, children?: unknown) => TemplateResult;
12
+ export declare const isTemplateResult: (value: unknown) => value is TemplateResult;
13
+ export declare class UnsafeHTMLResult {
14
+ readonly value: string;
15
+ constructor(value: string);
16
+ }
17
+ export declare const unsafeHTML: (value: string) => UnsafeHTMLResult;
18
+ export declare const isUnsafeHTML: (value: unknown) => value is UnsafeHTMLResult;
19
+ export declare const escapeHtml: (unsafe: unknown) => string;
20
+ export declare const renderToString: (result: TemplateResult) => string;
21
+ export declare const render: (result: TemplateResult, container: Node) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ export declare class LiveResult {
2
+ readonly value: unknown;
3
+ constructor(value: unknown);
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);
10
+ }
11
+ /**
12
+ * Checks against the DOM value instead of the previous rendered value.
13
+ * Usage: <input .value=${live(x)}>
14
+ */
15
+ export declare const live: (value: unknown) => LiveResult;
16
+ /**
17
+ * Repeats a template for each item in an array, using a key to maintain state.
18
+ * Usage: repeat(items, (item) => item.id, (item) => html`...`)
19
+ */
20
+ export declare const repeat: (items: unknown[], keyFnOrTemplate: (item: any, index: number) => unknown, template?: (item: any, index: number) => unknown) => RepeatResult;
21
+ /**
22
+ * Generates a class string from an object.
23
+ * Usage: class="${classMap({ active: isActive })}"
24
+ */
25
+ export declare const classMap: (classInfo: Record<string, string | boolean | number>) => string;
26
+ /**
27
+ * Generates a style string from an object.
28
+ * Usage: style="${styleMap({ color: 'red' })}"
29
+ */
30
+ export declare const styleMap: (styleInfo: Record<string, string | undefined | null>) => string;
31
+ export type RefCallback = (el: Element | undefined) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './cossack-html';
2
+ export * from './cossack-element';
3
+ export * from './component';
4
+ export * from './context';
5
+ export * from './directives';
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ import { C as n, L as r, R as l, T as p, U as o, k as u, c, e as i, h as m, d as R, g as T, i as f, a as C, l as M, f as d, p as L, b as g, r as h, j as H, m as k, s as v, u as x } from "./server-BEO1YttH.js";
2
+ function e(s) {
3
+ return {
4
+ id: Math.random().toString(36).slice(2),
5
+ defaultValue: s
6
+ };
7
+ }
8
+ export {
9
+ n as CossackElement,
10
+ r as LiveResult,
11
+ l as RepeatResult,
12
+ p as TemplateResult,
13
+ o as UnsafeHTMLResult,
14
+ u as classMap,
15
+ c as component,
16
+ e as createContext,
17
+ i as escapeHtml,
18
+ m as html,
19
+ R as instanceStack,
20
+ T as isComponentResult,
21
+ f as isTemplateResult,
22
+ C as isUnsafeHTML,
23
+ M as live,
24
+ d as popCurrentInstance,
25
+ L as pushCurrentInstance,
26
+ g as render,
27
+ h as renderToString,
28
+ H as repeat,
29
+ k as styleMap,
30
+ v as svg,
31
+ x as unsafeHTML
32
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,491 @@
1
+ var F = Object.defineProperty;
2
+ var z = (n, e, s) => e in n ? F(n, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[e] = s;
3
+ var h = (n, e, s) => z(n, typeof e != "symbol" ? e + "" : e, s);
4
+ const L = (n) => typeof n == "object" && n !== null && n._type === "COMPONENT", g = [], k = (n) => g.push(n), x = () => g.pop();
5
+ class T {
6
+ constructor() {
7
+ // Holds content projected from the parent
8
+ h(this, "children", null);
9
+ h(this, "props", {});
10
+ // Context Support
11
+ h(this, "__parent", null);
12
+ h(this, "_id", "");
13
+ h(this, "_childCounter", 0);
14
+ h(this, "__providedContexts", /* @__PURE__ */ new Map());
15
+ h(this, "__properties", /* @__PURE__ */ new Map());
16
+ h(this, "__updatePromise", null);
17
+ h(this, "__changedProperties", /* @__PURE__ */ new Map());
18
+ h(this, "__renderListeners", /* @__PURE__ */ new Set());
19
+ // Controllers
20
+ h(this, "__controllers", /* @__PURE__ */ new Set());
21
+ h(this, "__hasConnected", !1);
22
+ h(this, "__eventListeners", /* @__PURE__ */ new Map());
23
+ this.initialize();
24
+ }
25
+ // --- Static Stack Access for cossack-html ---
26
+ static get currentRenderingInstance() {
27
+ return g.length > 0 ? g[g.length - 1] : null;
28
+ }
29
+ resetRenderState() {
30
+ this._childCounter = 0;
31
+ }
32
+ // --- Controller API ---
33
+ addController(e) {
34
+ this.__controllers.add(e), this.__hasConnected && e.hostConnected && e.hostConnected();
35
+ }
36
+ removeController(e) {
37
+ this.__controllers.delete(e);
38
+ }
39
+ get updateComplete() {
40
+ return this.__updatePromise || Promise.resolve(!0);
41
+ }
42
+ initialize() {
43
+ const s = this.constructor.properties;
44
+ if (s)
45
+ for (const [t, i] of Object.entries(s))
46
+ this.createProperty(t, i);
47
+ }
48
+ createProperty(e, s) {
49
+ Object.prototype.hasOwnProperty.call(this, e) && this.__properties.set(e, this[e]), Object.defineProperty(this, e, {
50
+ get() {
51
+ return this.__properties.get(e);
52
+ },
53
+ set(t) {
54
+ const i = this.__properties.get(e);
55
+ i !== t && (this.__properties.set(e, t), this.requestUpdate(e, i));
56
+ },
57
+ configurable: !0,
58
+ enumerable: !0
59
+ });
60
+ }
61
+ provide(e, s) {
62
+ this.__providedContexts.set(e, s);
63
+ }
64
+ consume(e) {
65
+ let s = this.__parent;
66
+ for (; s; ) {
67
+ if (s.__providedContexts.has(e))
68
+ return s.__providedContexts.get(e);
69
+ s = s.__parent;
70
+ }
71
+ return e.defaultValue;
72
+ }
73
+ requestUpdate(e, s) {
74
+ return e !== void 0 && (this.__changedProperties.has(e) || this.__changedProperties.set(e, s)), this.__updatePromise || (this.__updatePromise = this.performUpdate()), this.__updatePromise;
75
+ }
76
+ async performUpdate() {
77
+ await Promise.resolve();
78
+ let e = !1;
79
+ try {
80
+ if (e = this.shouldUpdate(this.__changedProperties), e) {
81
+ this.__controllers.forEach((t) => t.hostUpdate && t.hostUpdate()), this.willUpdate(this.__changedProperties), this.resetRenderState(), k(this);
82
+ const s = this.render();
83
+ this.__notifyListeners(s), x(), this.updated(this.__changedProperties), this.__controllers.forEach((t) => t.hostUpdated && t.hostUpdated());
84
+ }
85
+ } catch (s) {
86
+ console.error("Error during update:", s), g[g.length - 1] === this && x();
87
+ }
88
+ return this.__changedProperties = /* @__PURE__ */ new Map(), this.__updatePromise = null, e;
89
+ }
90
+ __notifyListeners(e) {
91
+ this.__renderListeners.forEach((s) => s(e));
92
+ }
93
+ addRenderListener(e) {
94
+ this.__renderListeners.add(e);
95
+ }
96
+ removeRenderListener(e) {
97
+ this.__renderListeners.delete(e);
98
+ }
99
+ mount(e) {
100
+ this.addRenderListener((s) => {
101
+ s && (S(s) ? I(s, e) : I(E`${s}`, e));
102
+ }), this.requestUpdate();
103
+ }
104
+ addEventListener(e, s, t) {
105
+ s && (this.__eventListeners.has(e) || this.__eventListeners.set(e, /* @__PURE__ */ new Set()), this.__eventListeners.get(e).add(s));
106
+ }
107
+ removeEventListener(e, s, t) {
108
+ if (!s) return;
109
+ const i = this.__eventListeners.get(e);
110
+ i && i.delete(s);
111
+ }
112
+ dispatchEvent(e) {
113
+ const s = this.__eventListeners.get(e.type);
114
+ return s && s.forEach((t) => {
115
+ typeof t == "function" ? t.call(this, e) : t.handleEvent(e);
116
+ }), !e.defaultPrevented;
117
+ }
118
+ shouldUpdate(e) {
119
+ return !0;
120
+ }
121
+ willUpdate(e) {
122
+ }
123
+ render() {
124
+ return null;
125
+ }
126
+ updated(e) {
127
+ }
128
+ connectedCallback() {
129
+ this.__hasConnected = !0, this.__controllers.forEach((e) => e.hostConnected && e.hostConnected());
130
+ }
131
+ disconnectedCallback() {
132
+ this.__hasConnected = !1, this.__controllers.forEach((e) => e.hostDisconnected && e.hostDisconnected());
133
+ }
134
+ }
135
+ h(T, "properties", {}), h(T, "_isCossackElement", !0);
136
+ class R {
137
+ constructor(e) {
138
+ this.value = e;
139
+ }
140
+ }
141
+ class y {
142
+ constructor(e, s, t) {
143
+ this.items = e, this.keyFn = s, this.templateFn = t;
144
+ }
145
+ }
146
+ const Z = (n) => new R(n), X = (n, e, s) => s === void 0 ? new y(n, (t, i) => i, e) : new y(n, e, s), G = (n) => Object.keys(n).filter((e) => n[e]).join(" "), J = (n) => Object.keys(n).filter((e) => n[e] != null).map((e) => `${e}:${n[e]}`).join(";");
147
+ class B {
148
+ constructor(e, s) {
149
+ h(this, "_cossack_template_result", !0);
150
+ this.strings = e, this.values = s;
151
+ }
152
+ }
153
+ const E = (n, ...e) => new B(n, e), Q = E, Y = (n, e = {}, s) => E`${{
154
+ _type: "COMPONENT",
155
+ clazz: n,
156
+ props: e,
157
+ children: s
158
+ }}`, S = (n) => typeof n == "object" && n !== null && n._cossack_template_result === !0;
159
+ class W {
160
+ constructor(e) {
161
+ this.value = e;
162
+ }
163
+ }
164
+ const ee = (n) => new W(n), U = (n) => n instanceof W, H = (n) => String(n).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"), N = (n) => {
165
+ if (n == null || n === !1)
166
+ return "";
167
+ if (Array.isArray(n))
168
+ return n.map(N).join("");
169
+ if (S(n))
170
+ return A(n);
171
+ if (n instanceof R)
172
+ return N(n.value);
173
+ if (n instanceof y)
174
+ return n.items.map((e, s) => N(n.templateFn(e, s))).join("");
175
+ if (L(n)) {
176
+ const e = new n.clazz();
177
+ Object.assign(e, n.props), "props" in e && (e.props = n.props), e.children = n.children, e.__parent = T.currentRenderingInstance, e.__parent && (e._id = `${e.__parent._id}:${e.__parent._childCounter++}`), e.connectedCallback(), k(e), e.willUpdate(/* @__PURE__ */ new Map());
178
+ const s = e.render();
179
+ let t = "";
180
+ return s && (S(s) ? t = A(s) : t = A(E`${s}`)), x(), t;
181
+ }
182
+ return U(n) ? n.value : typeof n == "function" || typeof n == "object" && n !== null && "value" in n ? "" : H(n);
183
+ }, V = (n) => {
184
+ let e = "";
185
+ if (typeof n == "object" && n !== null)
186
+ for (const [s, t] of Object.entries(n)) {
187
+ if (s.startsWith("@")) continue;
188
+ let i = s, r = t;
189
+ if (s.startsWith("?")) {
190
+ t && (e += ` ${s.slice(1)}`);
191
+ continue;
192
+ }
193
+ s.startsWith(".") && (i = s.slice(1)), typeof r == "boolean" ? r && (e += ` ${i}`) : typeof r == "function" || r != null && (e += ` ${i}="${H(r)}"`);
194
+ }
195
+ return e;
196
+ };
197
+ class D {
198
+ constructor(e) {
199
+ h(this, "result", "");
200
+ h(this, "stringIdx", 0);
201
+ h(this, "charIdxForNext", 0);
202
+ this.resultObj = e;
203
+ }
204
+ scan() {
205
+ const { strings: e, values: s } = this.resultObj;
206
+ for (; this.stringIdx < e.length; ) {
207
+ const i = e[this.stringIdx].substring(this.charIdxForNext || 0), r = i.match(/(\.\.\.|[.@?]?[a-zA-Z0-9_-]+)=["']?$/);
208
+ if (this.result += i, this.charIdxForNext = 0, this.stringIdx < e.length - 1) {
209
+ const a = s[this.stringIdx];
210
+ if (r) {
211
+ const c = r[0], d = r[1];
212
+ this.result = this.result.substring(0, this.result.length - c.length);
213
+ const p = c.endsWith('"') ? '"' : c.endsWith("'") ? "'" : "";
214
+ let m = !0;
215
+ if (d === "..." ? (this.result = this.result.trimEnd(), this.result += V(a)) : d.startsWith("@") ? this.result = this.result.trimEnd() : d.startsWith("?") ? a ? (this.result = this.result.trimEnd(), this.result += ` ${d.slice(1)}`) : this.result = this.result.trimEnd() : d.startsWith(".") ? a != null && a !== !1 ? (this.result = this.result.trimEnd(), this.result += ` ${d.slice(1)}="${N(a)}"`) : this.result = this.result.trimEnd() : (this.result += c, this.result += N(a), m = !1), p && m) {
216
+ const f = e[this.stringIdx + 1];
217
+ f && f.startsWith(p) && (this.charIdxForNext = 1);
218
+ }
219
+ } else
220
+ this.result += N(a);
221
+ }
222
+ this.stringIdx++;
223
+ }
224
+ return this.result;
225
+ }
226
+ }
227
+ const A = (n) => new D(n).scan();
228
+ class $ {
229
+ constructor(e, s) {
230
+ h(this, "componentInstance", null);
231
+ h(this, "renderListener", null);
232
+ h(this, "_childParts", []);
233
+ h(this, "_partKeys", []);
234
+ // Cache for nested template result updates
235
+ h(this, "_cachedTemplateStrings", null);
236
+ h(this, "_cachedParts", null);
237
+ this.startNode = e, this.endNode = s;
238
+ }
239
+ update(e) {
240
+ this.componentInstance && (!L(e) || e.clazz !== this.componentInstance.constructor) && this.disposeComponent(), !(e instanceof y) && !Array.isArray(e) && this._childParts.length > 0 && this.clearChildParts(), L(e) ? this.updateComponent(e) : e instanceof y ? this.updateRepeat(e) : Array.isArray(e) ? this.updateArray(e) : this.updateNode(e);
241
+ }
242
+ disposeComponent() {
243
+ this.componentInstance && (this.renderListener && this.componentInstance.removeRenderListener(this.renderListener), this.componentInstance.disconnectedCallback(), this.componentInstance = null, this.renderListener = null, this._clearTemplateCache());
244
+ }
245
+ updateComponent(e) {
246
+ this.componentInstance || (this.componentInstance = new e.clazz(), this.componentInstance.__parent = T.currentRenderingInstance, this.componentInstance.__parent && (this.componentInstance._id = `${this.componentInstance.__parent._id}:${this.componentInstance.__parent._childCounter++}`), this.renderListener = (t) => {
247
+ this.updateNode(t);
248
+ }, this.componentInstance.addRenderListener(this.renderListener), this.componentInstance.connectedCallback());
249
+ const s = this.componentInstance;
250
+ Object.assign(s, e.props), "props" in s && (s.props = e.props), s.children = e.children, s.requestUpdate();
251
+ }
252
+ updateRepeat(e) {
253
+ const { items: s, keyFn: t, templateFn: i } = e, r = /* @__PURE__ */ new Map();
254
+ this._childParts.forEach((p, m) => {
255
+ const f = this._partKeys[m];
256
+ f !== void 0 && r.set(f, p);
257
+ });
258
+ const a = [], c = [];
259
+ let d = this.startNode;
260
+ s.forEach((p, m) => {
261
+ const f = t(p, m);
262
+ c.push(f);
263
+ let _ = r.get(f);
264
+ _ ? (r.delete(f), _.startNode.previousSibling !== d && this.movePart(_, d), _.update(i(p, m))) : (_ = this.createChildPart(d), _.update(i(p, m))), a.push(_), d = _.endNode;
265
+ }), r.forEach((p) => p.dispose()), this._childParts = a, this._partKeys = c;
266
+ }
267
+ updateArray(e) {
268
+ this._partKeys = [];
269
+ const s = Math.min(e.length, this._childParts.length);
270
+ for (let t = 0; t < s; t++)
271
+ this._childParts[t].update(e[t]);
272
+ if (e.length > this._childParts.length) {
273
+ let t = this._childParts.length > 0 ? this._childParts[this._childParts.length - 1].endNode : this.startNode;
274
+ for (let i = s; i < e.length; i++) {
275
+ const r = this.createChildPart(t);
276
+ this._childParts.push(r), r.update(e[i]), t = r.endNode;
277
+ }
278
+ }
279
+ if (e.length < this._childParts.length)
280
+ for (let t = this._childParts.length - 1; t >= e.length; t--)
281
+ this._childParts[t].dispose(), this._childParts.pop();
282
+ }
283
+ createChildPart(e) {
284
+ const s = document.createComment("CRP-Item"), t = document.createComment("/CRP-Item"), i = e.nextSibling;
285
+ return e.parentNode.insertBefore(s, i), e.parentNode.insertBefore(t, i), new $(s, t);
286
+ }
287
+ movePart(e, s) {
288
+ const t = s.parentNode, i = [];
289
+ let r = e.startNode;
290
+ for (; r && r !== e.endNode; )
291
+ i.push(r), r = r.nextSibling;
292
+ i.push(e.endNode);
293
+ const a = s.nextSibling;
294
+ i.forEach((c) => t.insertBefore(c, a));
295
+ }
296
+ clearChildParts() {
297
+ this._childParts.forEach((e) => e.dispose()), this._childParts = [], this._partKeys = [];
298
+ }
299
+ dispose() {
300
+ this.clear(), this._clearTemplateCache(), this.clearChildParts(), this.startNode.parentNode && this.startNode.parentNode.removeChild(this.startNode), this.endNode.parentNode && this.endNode.parentNode.removeChild(this.endNode), this.componentInstance && (this.renderListener && this.componentInstance.removeRenderListener(this.renderListener), this.componentInstance.disconnectedCallback());
301
+ }
302
+ updateNode(e) {
303
+ var s;
304
+ if (this.startNode.parentNode)
305
+ if (S(e))
306
+ if (this._cachedTemplateStrings === e.strings && this._cachedParts)
307
+ this._cachedParts.forEach((t, i) => {
308
+ t.update(e.values[i]);
309
+ });
310
+ else {
311
+ this._clearTemplateCache(), this.clear();
312
+ const t = document.createDocumentFragment();
313
+ I(e, t), this.startNode.parentNode.insertBefore(t, this.endNode);
314
+ const i = M.get(((s = t.firstChild) == null ? void 0 : s.childNodes[0]) || t);
315
+ i && (this._cachedTemplateStrings = i.strings, this._cachedParts = i.parts);
316
+ }
317
+ else if (L(e) || typeof e == "object" && e !== null && !(e instanceof Node) && !Array.isArray(e)) {
318
+ this._clearTemplateCache(), this.clear();
319
+ const t = document.createDocumentFragment();
320
+ I(E`${e}`, t), this.startNode.parentNode.insertBefore(t, this.endNode);
321
+ } else if (U(e)) {
322
+ this._clearTemplateCache(), this.clear();
323
+ const t = document.createElement("template");
324
+ t.innerHTML = e.value, this.startNode.parentNode.insertBefore(t.content, this.endNode);
325
+ } else if (e instanceof Node)
326
+ this._clearTemplateCache(), this.clear(), this.startNode.parentNode.insertBefore(e, this.endNode);
327
+ else if (e == null || e === !1)
328
+ this._clearTemplateCache(), this.clear();
329
+ else {
330
+ const t = String(e), i = this.startNode.nextSibling;
331
+ if (i && i.nodeType === Node.TEXT_NODE && i.nextSibling === this.endNode)
332
+ i.nodeValue !== t && (i.nodeValue = t);
333
+ else {
334
+ this._clearTemplateCache(), this.clear();
335
+ const r = document.createTextNode(t);
336
+ this.startNode.parentNode.insertBefore(r, this.endNode);
337
+ }
338
+ }
339
+ }
340
+ _clearTemplateCache() {
341
+ this._cachedTemplateStrings = null, this._cachedParts = null;
342
+ }
343
+ clear() {
344
+ let e = this.startNode.nextSibling;
345
+ for (; e && e !== this.endNode; ) {
346
+ const s = e.nextSibling;
347
+ e.parentNode.removeChild(e), e = s;
348
+ }
349
+ }
350
+ }
351
+ class q {
352
+ constructor(e) {
353
+ h(this, "previousValues", {});
354
+ this.element = e;
355
+ }
356
+ update(e) {
357
+ if (typeof e != "object" || e === null) return;
358
+ const s = e;
359
+ for (const t of Object.keys(this.previousValues))
360
+ if (!(t in s))
361
+ if (t.startsWith("@")) {
362
+ const i = t.slice(1), r = `__crp_handler_${i}`, a = this.element[r];
363
+ a && this.element.removeEventListener(i, a);
364
+ } else t.startsWith(".") || (t.startsWith("?") ? this.element.removeAttribute(t.slice(1)) : this.element.removeAttribute(t));
365
+ for (const [t, i] of Object.entries(s))
366
+ if (t.startsWith("@") && typeof i == "function") {
367
+ const r = t.slice(1), a = `__crp_handler_${r}`, c = this.element[a];
368
+ c && this.element.removeEventListener(r, c), this.element[a] = i, this.element.addEventListener(r, i);
369
+ } else t.startsWith(".") ? this.element[t.slice(1)] = i : t.startsWith("?") ? i ? this.element.setAttribute(t.slice(1), "") : this.element.removeAttribute(t.slice(1)) : typeof i == "boolean" ? i ? this.element.setAttribute(t, "") : this.element.removeAttribute(t) : i != null && this.element.setAttribute(t, String(i));
370
+ this.previousValues = { ...s };
371
+ }
372
+ }
373
+ class v {
374
+ constructor(e, s) {
375
+ this.element = e, this.name = s;
376
+ }
377
+ update(e) {
378
+ let s = !1;
379
+ if (e instanceof R && (s = !0, e = e.value), this.name === "ref") {
380
+ 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);
381
+ return;
382
+ }
383
+ if (this.name.startsWith("@") && typeof e == "function") {
384
+ const t = this.name.slice(1), i = `__crp_handler_${t}`, r = this.element[i];
385
+ r && this.element.removeEventListener(t, r), this.element[i] = e, this.element.addEventListener(t, e), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
386
+ } else if (this.name.startsWith(".")) {
387
+ const t = this.name.slice(1);
388
+ this.element[t] = e, this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
389
+ } else if (this.name.startsWith("?")) {
390
+ const t = this.name.slice(1);
391
+ e ? this.element.setAttribute(t, "") : this.element.removeAttribute(t), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
392
+ } else if (this.name === "value" && (this.element instanceof HTMLInputElement || this.element instanceof HTMLTextAreaElement))
393
+ s ? this.element.value !== String(e) && (this.element.value = String(e)) : this.element.value !== String(e) && (this.element.value = String(e)), this.element.setAttribute(this.name, String(e));
394
+ else if (this.name === "checked" && this.element instanceof HTMLInputElement) {
395
+ const t = !!e;
396
+ this.element.checked !== t && (this.element.checked = t), t ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name);
397
+ } else typeof e == "boolean" ? e ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, String(e));
398
+ }
399
+ }
400
+ const M = /* @__PURE__ */ new WeakMap(), I = (n, e) => {
401
+ const s = M.get(e);
402
+ if (s && s.strings === n.strings) {
403
+ s.parts.forEach((o, l) => {
404
+ o.update(n.values[l]);
405
+ });
406
+ return;
407
+ }
408
+ const t = [], i = n.values;
409
+ let r = "", a = !1;
410
+ const c = (o) => {
411
+ for (let l = 0; l < o.length; l++)
412
+ o[l] === "<" && o[l + 1] !== "!" && o[l + 1] !== "/" ? a = !0 : o[l] === ">" && (a = !1);
413
+ }, d = /(\.\.\.|[.@?]?[a-zA-Z0-9_-]+)=["']?$/;
414
+ for (let o = 0; o < n.strings.length - 1; o++) {
415
+ const l = n.strings[o];
416
+ c(l), r += l;
417
+ const u = l.match(d);
418
+ a && u ? r += `__CRP_${o}__` : r += `<!--CRP_${o}-->`;
419
+ }
420
+ const p = n.strings[n.strings.length - 1];
421
+ c(p), r += p;
422
+ const m = document.createElement("template");
423
+ m.innerHTML = r;
424
+ const f = m.content.cloneNode(!0), _ = document.createTreeWalker(f, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
425
+ let O;
426
+ const j = [];
427
+ for (; O = _.nextNode(); )
428
+ j.push(O);
429
+ j.forEach((o) => {
430
+ var l;
431
+ if (o.nodeType === Node.COMMENT_NODE) {
432
+ const u = (l = o.nodeValue) == null ? void 0 : l.match(/CRP_(\d+)/);
433
+ if (u) {
434
+ const C = parseInt(u[1]), P = document.createComment("/CRP");
435
+ o.parentNode.insertBefore(P, o.nextSibling);
436
+ const b = new $(o, P);
437
+ t[C] = b;
438
+ }
439
+ } else if (o.nodeType === Node.ELEMENT_NODE) {
440
+ const u = o;
441
+ Array.from(u.attributes).forEach((C) => {
442
+ const P = C.value.match(/__CRP_(\d+)__/);
443
+ if (P) {
444
+ const b = parseInt(P[1]);
445
+ if (!t[b])
446
+ if (C.name === "...") {
447
+ const w = new q(u);
448
+ t[b] = w, u.removeAttribute("...");
449
+ } else {
450
+ const w = new v(u, C.name);
451
+ t[b] = w;
452
+ }
453
+ }
454
+ });
455
+ }
456
+ });
457
+ for (let o = 0; o < i.length; o++)
458
+ t[o] && t[o].update(i[o]);
459
+ if (e instanceof HTMLElement)
460
+ e.innerHTML = "", e.appendChild(f);
461
+ else if (e instanceof DocumentFragment) {
462
+ for (; e.firstChild; )
463
+ e.removeChild(e.firstChild);
464
+ e.appendChild(f);
465
+ }
466
+ M.set(e, { strings: n.strings, parts: t });
467
+ };
468
+ export {
469
+ T as C,
470
+ R as L,
471
+ y as R,
472
+ B as T,
473
+ W as U,
474
+ U as a,
475
+ I as b,
476
+ Y as c,
477
+ g as d,
478
+ H as e,
479
+ x as f,
480
+ L as g,
481
+ E as h,
482
+ S as i,
483
+ X as j,
484
+ G as k,
485
+ Z as l,
486
+ J as m,
487
+ k as p,
488
+ A as r,
489
+ Q as s,
490
+ ee as u
491
+ };
@@ -0,0 +1 @@
1
+ export { renderToString, escapeHtml } from './cossack-html';
package/dist/server.js ADDED
@@ -0,0 +1,5 @@
1
+ import { e as a, r as o } from "./server-BEO1YttH.js";
2
+ export {
3
+ a as escapeHtml,
4
+ o as renderToString
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@cossackframework/renderer",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "Light DOM rendering engine for the Cossack Framework",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/cossackframework/cossack",
10
+ "directory": "packages/renderer"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./server": {
23
+ "import": "./dist/server.js",
24
+ "types": "./dist/server.d.ts"
25
+ }
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "vite build",
32
+ "test": "vitest",
33
+ "lint": "oxlint"
34
+ },
35
+ "devDependencies": {
36
+ "htmlparser2": "^10.0.0",
37
+ "magic-string": "^0.30.21",
38
+ "oxlint": "^1.41.0",
39
+ "vite": "^5.3.5",
40
+ "vite-plugin-dts": "^3.9.1",
41
+ "vite-tsconfig-paths": "^5.1.4",
42
+ "vitest": "^1.2.2"
43
+ }
44
+ }