@cossackframework/renderer 0.1.0 → 0.3.9
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 +309 -0
- package/dist/cossack-element.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/{server-BEO1YttH.js → server-BASPjT-s.js} +66 -66
- package/dist/server.js +1 -1
- package/package.json +7 -7
package/README.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# Cossack Renderer Package
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This package is intended to use with the Cossack Framework via `create-cossack-app`, but can also be used standalone in any project that needs a lightweight rendering solution.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @cossackframework/renderer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Defining Components
|
|
14
|
+
|
|
15
|
+
Components are classes that extend `CossackElement`. They manage their own state and render template results.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { CossackElement, html } from '@cossackframework/renderer';
|
|
19
|
+
|
|
20
|
+
export class MyCounter extends CossackElement {
|
|
21
|
+
// Define reactive properties
|
|
22
|
+
static properties = {
|
|
23
|
+
count: { state: true },
|
|
24
|
+
label: { state: true }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Declare fields for TypeScript
|
|
28
|
+
declare count: number;
|
|
29
|
+
declare label: string;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
this.count = 0;
|
|
34
|
+
this.label = 'Count';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
increment() {
|
|
38
|
+
this.count++;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
return html`
|
|
43
|
+
<div>
|
|
44
|
+
<span>${this.label}: ${this.count}</span>
|
|
45
|
+
<button @click="${() => this.increment()}">+</button>
|
|
46
|
+
</div>
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Rendering
|
|
53
|
+
|
|
54
|
+
### Client-Side Rendering (Hydration/Mounting)
|
|
55
|
+
|
|
56
|
+
To mount a component to the DOM:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { MyCounter } from './MyCounter';
|
|
60
|
+
|
|
61
|
+
const container = document.getElementById('app');
|
|
62
|
+
const app = new MyCounter();
|
|
63
|
+
app.mount(container); // Mounts and renders to the container
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Server-Side Rendering (SSR)
|
|
67
|
+
|
|
68
|
+
To render a component to an HTML string:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { renderToString } from '@cossackframework/renderer';
|
|
72
|
+
import { MyCounter } from './MyCounter';
|
|
73
|
+
|
|
74
|
+
const app = new MyCounter();
|
|
75
|
+
// Optional: Wait for async data or updates
|
|
76
|
+
const htmlString = renderToString(app.render());
|
|
77
|
+
console.log(htmlString);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Template Syntax
|
|
81
|
+
|
|
82
|
+
Cossack uses tagged template literals via `html`.
|
|
83
|
+
|
|
84
|
+
### Basic Expressions
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
html`<h1>Hello ${name}</h1>`
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Attributes
|
|
91
|
+
|
|
92
|
+
Boolean attributes are removed if `false/null/undefined`.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
html`<button ?disabled="${isDisabled}">Click</button>`
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Event Binding
|
|
99
|
+
|
|
100
|
+
Bind event listeners using Lit's `@` syntax.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
html`<button @click="${(e) => this.handleClick(e)}">Click Me</button>`
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Property Binding
|
|
107
|
+
|
|
108
|
+
For `<input>` elements, use `.` prefix to bind properties directly.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
html`<input type="text" .value="${this.inputValue}" @input="${this.handleInput}" />`
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Spread Attributes
|
|
115
|
+
|
|
116
|
+
You can spread an object into attributes using the `...` syntax.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const props = { id: 'btn', class: 'primary', 'data-type': 'action' };
|
|
120
|
+
html`<button ...=${props}>Click</button>`
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Unsafe HTML
|
|
124
|
+
|
|
125
|
+
To render raw HTML strings (careful!):
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { unsafeHTML } from '@cossackframework/renderer';
|
|
129
|
+
html`<div>${unsafeHTML('<script>...</script>')}</div>`
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Using Components in Templates
|
|
133
|
+
|
|
134
|
+
Use the `component` helper function to include child components in your templates.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { component } from '@cossackframework/renderer';
|
|
138
|
+
import { ChildComponent } from './ChildComponent';
|
|
139
|
+
|
|
140
|
+
html`
|
|
141
|
+
<div class="parent">
|
|
142
|
+
${component(ChildComponent, { someProp: 'value' })}
|
|
143
|
+
</div>
|
|
144
|
+
`
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
You can also pass children to components:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
html`
|
|
151
|
+
<div class="parent">
|
|
152
|
+
${component(ChildComponent, { someProp: 'value' }, html`
|
|
153
|
+
<span>Child content</span>
|
|
154
|
+
`)}
|
|
155
|
+
</div>
|
|
156
|
+
`
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Directives
|
|
160
|
+
|
|
161
|
+
Cossack includes standard Lit directives.
|
|
162
|
+
|
|
163
|
+
### `repeat` (Keyed Lists)
|
|
164
|
+
|
|
165
|
+
Efficiently renders lists by key.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { repeat } from '@cossackframework/renderer';
|
|
169
|
+
|
|
170
|
+
html`
|
|
171
|
+
<ul>
|
|
172
|
+
${repeat(items, (item) => item.id, (item) => html`
|
|
173
|
+
<li>${item.text}</li>
|
|
174
|
+
`)}
|
|
175
|
+
</ul>
|
|
176
|
+
`
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `classMap` & `styleMap`
|
|
180
|
+
|
|
181
|
+
Dynamic classes and styles.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { classMap, styleMap } from '@cossackframework/renderer';
|
|
185
|
+
|
|
186
|
+
const classes = { active: isActive, error: hasError };
|
|
187
|
+
const styles = { color: 'red', display: isVisible ? 'block' : 'none' };
|
|
188
|
+
|
|
189
|
+
html`<div class="${classMap(classes)}" style="${styleMap(styles)}">...</div>`
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `ref`
|
|
193
|
+
|
|
194
|
+
Get a reference to the DOM element.
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { ref } from '@cossackframework/renderer';
|
|
198
|
+
|
|
199
|
+
html`<input ref="${(el) => console.log(el)}" />`
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `live`
|
|
203
|
+
|
|
204
|
+
Check against the live DOM value (useful for inputs).
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { live } from '@cossackframework/renderer';
|
|
208
|
+
|
|
209
|
+
html`<input .value="${live(inputValue)}" />`
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Context API
|
|
213
|
+
|
|
214
|
+
Share state deep in the tree.
|
|
215
|
+
|
|
216
|
+
### 1. Create Context
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { createContext } from '@cossackframework/renderer';
|
|
220
|
+
|
|
221
|
+
export const ThemeContext = createContext('light'); // Default value
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 2. Provide Context
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
class App extends CossackElement {
|
|
228
|
+
render() {
|
|
229
|
+
this.provide(ThemeContext, 'dark');
|
|
230
|
+
return html`${component(Child)}`;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 3. Consume Context
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
class Child extends CossackElement {
|
|
239
|
+
render() {
|
|
240
|
+
const theme = this.consume(ThemeContext);
|
|
241
|
+
return html`<span>Theme is ${theme}</span>`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Reactive Controllers
|
|
247
|
+
|
|
248
|
+
Reuse logic across components using controllers.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { ReactiveController, ReactiveControllerHost } from '@cossackframework/renderer';
|
|
252
|
+
|
|
253
|
+
class ClockController implements ReactiveController {
|
|
254
|
+
host: ReactiveControllerHost;
|
|
255
|
+
value = new Date();
|
|
256
|
+
private timer?: number;
|
|
257
|
+
|
|
258
|
+
constructor(host: ReactiveControllerHost) {
|
|
259
|
+
this.host = host;
|
|
260
|
+
host.addController(this);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
hostConnected() {
|
|
264
|
+
this.timer = setInterval(() => {
|
|
265
|
+
this.value = new Date();
|
|
266
|
+
this.host.requestUpdate();
|
|
267
|
+
}, 1000);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
hostDisconnected() {
|
|
271
|
+
clearInterval(this.timer);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
class ClockElement extends CossackElement {
|
|
276
|
+
private clock = new ClockController(this);
|
|
277
|
+
|
|
278
|
+
render() {
|
|
279
|
+
return html`<time>${this.clock.value.toLocaleTimeString()}</time>`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Children Projection (Slots)
|
|
285
|
+
|
|
286
|
+
Cossack supports passing children to components.
|
|
287
|
+
|
|
288
|
+
**Parent:**
|
|
289
|
+
```typescript
|
|
290
|
+
html`
|
|
291
|
+
${component(Card, {}, html`
|
|
292
|
+
<h1>Title</h1>
|
|
293
|
+
<p>Content</p>
|
|
294
|
+
`)}
|
|
295
|
+
`
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**Child (Card):**
|
|
299
|
+
```typescript
|
|
300
|
+
class Card extends CossackElement {
|
|
301
|
+
render() {
|
|
302
|
+
return html`
|
|
303
|
+
<div class="card">
|
|
304
|
+
${this.children}
|
|
305
|
+
</div>
|
|
306
|
+
`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
@@ -28,6 +28,7 @@ export declare const popCurrentInstance: () => CossackElement | undefined;
|
|
|
28
28
|
export declare class CossackElement implements ReactiveControllerHost {
|
|
29
29
|
static properties: PropertyDeclarations;
|
|
30
30
|
static readonly _isCossackElement = true;
|
|
31
|
+
static components: Record<string, typeof CossackElement>;
|
|
31
32
|
children: unknown;
|
|
32
33
|
props: Record<string, unknown>;
|
|
33
34
|
__parent: CossackElement | null;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-BASPjT-s.js";
|
|
2
2
|
function e(s) {
|
|
3
3
|
return {
|
|
4
4
|
id: Math.random().toString(36).slice(2),
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
var F = Object.defineProperty;
|
|
2
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
|
|
4
|
-
const
|
|
5
|
-
class
|
|
3
|
+
var o = (n, e, s) => z(n, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
const T = (n) => typeof n == "object" && n !== null && n._type === "COMPONENT", g = [], W = (n) => g.push(n), x = () => g.pop();
|
|
5
|
+
class y {
|
|
6
6
|
constructor() {
|
|
7
7
|
// Holds content projected from the parent
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
o(this, "children", null);
|
|
9
|
+
o(this, "props", {});
|
|
10
10
|
// Context Support
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
o(this, "__parent", null);
|
|
12
|
+
o(this, "_id", "");
|
|
13
|
+
o(this, "_childCounter", 0);
|
|
14
|
+
o(this, "__providedContexts", /* @__PURE__ */ new Map());
|
|
15
|
+
o(this, "__properties", /* @__PURE__ */ new Map());
|
|
16
|
+
o(this, "__updatePromise", null);
|
|
17
|
+
o(this, "__changedProperties", /* @__PURE__ */ new Map());
|
|
18
|
+
o(this, "__renderListeners", /* @__PURE__ */ new Set());
|
|
19
19
|
// Controllers
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
o(this, "__controllers", /* @__PURE__ */ new Set());
|
|
21
|
+
o(this, "__hasConnected", !1);
|
|
22
|
+
o(this, "__eventListeners", /* @__PURE__ */ new Map());
|
|
23
23
|
this.initialize();
|
|
24
24
|
}
|
|
25
25
|
// --- Static Stack Access for cossack-html ---
|
|
@@ -78,7 +78,7 @@ class T {
|
|
|
78
78
|
let e = !1;
|
|
79
79
|
try {
|
|
80
80
|
if (e = this.shouldUpdate(this.__changedProperties), e) {
|
|
81
|
-
this.__controllers.forEach((t) => t.hostUpdate && t.hostUpdate()), this.willUpdate(this.__changedProperties), this.resetRenderState(),
|
|
81
|
+
this.__controllers.forEach((t) => t.hostUpdate && t.hostUpdate()), this.willUpdate(this.__changedProperties), this.resetRenderState(), W(this);
|
|
82
82
|
const s = this.render();
|
|
83
83
|
this.__notifyListeners(s), x(), this.updated(this.__changedProperties), this.__controllers.forEach((t) => t.hostUpdated && t.hostUpdated());
|
|
84
84
|
}
|
|
@@ -98,7 +98,7 @@ class T {
|
|
|
98
98
|
}
|
|
99
99
|
mount(e) {
|
|
100
100
|
this.addRenderListener((s) => {
|
|
101
|
-
s && (S(s) ? I(s, e) : I(
|
|
101
|
+
s && (S(s) ? I(s, e) : I(L`${s}`, e));
|
|
102
102
|
}), this.requestUpdate();
|
|
103
103
|
}
|
|
104
104
|
addEventListener(e, s, t) {
|
|
@@ -132,36 +132,36 @@ class T {
|
|
|
132
132
|
this.__hasConnected = !1, this.__controllers.forEach((e) => e.hostDisconnected && e.hostDisconnected());
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
o(y, "properties", {}), o(y, "_isCossackElement", !0), o(y, "components", {});
|
|
136
136
|
class R {
|
|
137
137
|
constructor(e) {
|
|
138
138
|
this.value = e;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
class
|
|
141
|
+
class E {
|
|
142
142
|
constructor(e, s, t) {
|
|
143
143
|
this.items = e, this.keyFn = s, this.templateFn = t;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
const Z = (n) => new R(n), X = (n, e, s) => s === void 0 ? new
|
|
146
|
+
const Z = (n) => new R(n), X = (n, e, s) => s === void 0 ? new E(n, (t, i) => i, e) : new E(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
147
|
class B {
|
|
148
148
|
constructor(e, s) {
|
|
149
|
-
|
|
149
|
+
o(this, "_cossack_template_result", !0);
|
|
150
150
|
this.strings = e, this.values = s;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
const
|
|
153
|
+
const L = (n, ...e) => new B(n, e), Q = L, Y = (n, e = {}, s) => L`${{
|
|
154
154
|
_type: "COMPONENT",
|
|
155
155
|
clazz: n,
|
|
156
156
|
props: e,
|
|
157
157
|
children: s
|
|
158
158
|
}}`, S = (n) => typeof n == "object" && n !== null && n._cossack_template_result === !0;
|
|
159
|
-
class
|
|
159
|
+
class k {
|
|
160
160
|
constructor(e) {
|
|
161
161
|
this.value = e;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
const ee = (n) => new
|
|
164
|
+
const ee = (n) => new k(n), U = (n) => n instanceof k, H = (n) => String(n).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), N = (n) => {
|
|
165
165
|
if (n == null || n === !1)
|
|
166
166
|
return "";
|
|
167
167
|
if (Array.isArray(n))
|
|
@@ -170,14 +170,14 @@ const ee = (n) => new W(n), U = (n) => n instanceof W, H = (n) => String(n).repl
|
|
|
170
170
|
return A(n);
|
|
171
171
|
if (n instanceof R)
|
|
172
172
|
return N(n.value);
|
|
173
|
-
if (n instanceof
|
|
173
|
+
if (n instanceof E)
|
|
174
174
|
return n.items.map((e, s) => N(n.templateFn(e, s))).join("");
|
|
175
|
-
if (
|
|
175
|
+
if (T(n)) {
|
|
176
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 =
|
|
177
|
+
Object.assign(e, n.props), "props" in e && (e.props = n.props), e.children = n.children, e.__parent = y.currentRenderingInstance, e.__parent && (e._id = `${e.__parent._id}:${e.__parent._childCounter++}`), e.connectedCallback(), W(e), e.willUpdate(/* @__PURE__ */ new Map());
|
|
178
178
|
const s = e.render();
|
|
179
179
|
let t = "";
|
|
180
|
-
return s && (S(s) ? t = A(s) : t = A(
|
|
180
|
+
return s && (S(s) ? t = A(s) : t = A(L`${s}`)), x(), t;
|
|
181
181
|
}
|
|
182
182
|
return U(n) ? n.value : typeof n == "function" || typeof n == "object" && n !== null && "value" in n ? "" : H(n);
|
|
183
183
|
}, V = (n) => {
|
|
@@ -196,9 +196,9 @@ const ee = (n) => new W(n), U = (n) => n instanceof W, H = (n) => String(n).repl
|
|
|
196
196
|
};
|
|
197
197
|
class D {
|
|
198
198
|
constructor(e) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
o(this, "result", "");
|
|
200
|
+
o(this, "stringIdx", 0);
|
|
201
|
+
o(this, "charIdxForNext", 0);
|
|
202
202
|
this.resultObj = e;
|
|
203
203
|
}
|
|
204
204
|
scan() {
|
|
@@ -227,23 +227,23 @@ class D {
|
|
|
227
227
|
const A = (n) => new D(n).scan();
|
|
228
228
|
class $ {
|
|
229
229
|
constructor(e, s) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
o(this, "componentInstance", null);
|
|
231
|
+
o(this, "renderListener", null);
|
|
232
|
+
o(this, "_childParts", []);
|
|
233
|
+
o(this, "_partKeys", []);
|
|
234
234
|
// Cache for nested template result updates
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
o(this, "_cachedTemplateStrings", null);
|
|
236
|
+
o(this, "_cachedParts", null);
|
|
237
237
|
this.startNode = e, this.endNode = s;
|
|
238
238
|
}
|
|
239
239
|
update(e) {
|
|
240
|
-
this.componentInstance && (!
|
|
240
|
+
this.componentInstance && (!T(e) || e.clazz !== this.componentInstance.constructor) && this.disposeComponent(), !(e instanceof E) && !Array.isArray(e) && this._childParts.length > 0 && this.clearChildParts(), T(e) ? this.updateComponent(e) : e instanceof E ? this.updateRepeat(e) : Array.isArray(e) ? this.updateArray(e) : this.updateNode(e);
|
|
241
241
|
}
|
|
242
242
|
disposeComponent() {
|
|
243
243
|
this.componentInstance && (this.renderListener && this.componentInstance.removeRenderListener(this.renderListener), this.componentInstance.disconnectedCallback(), this.componentInstance = null, this.renderListener = null, this._clearTemplateCache());
|
|
244
244
|
}
|
|
245
245
|
updateComponent(e) {
|
|
246
|
-
this.componentInstance || (this.componentInstance = new e.clazz(), this.componentInstance.__parent =
|
|
246
|
+
this.componentInstance || (this.componentInstance = new e.clazz(), this.componentInstance.__parent = y.currentRenderingInstance, this.componentInstance.__parent && (this.componentInstance._id = `${this.componentInstance.__parent._id}:${this.componentInstance.__parent._childCounter++}`), this.renderListener = (t) => {
|
|
247
247
|
this.updateNode(t);
|
|
248
248
|
}, this.componentInstance.addRenderListener(this.renderListener), this.componentInstance.connectedCallback());
|
|
249
249
|
const s = this.componentInstance;
|
|
@@ -314,10 +314,10 @@ class $ {
|
|
|
314
314
|
const i = M.get(((s = t.firstChild) == null ? void 0 : s.childNodes[0]) || t);
|
|
315
315
|
i && (this._cachedTemplateStrings = i.strings, this._cachedParts = i.parts);
|
|
316
316
|
}
|
|
317
|
-
else if (
|
|
317
|
+
else if (T(e) || typeof e == "object" && e !== null && !(e instanceof Node) && !Array.isArray(e)) {
|
|
318
318
|
this._clearTemplateCache(), this.clear();
|
|
319
319
|
const t = document.createDocumentFragment();
|
|
320
|
-
I(
|
|
320
|
+
I(L`${e}`, t), this.startNode.parentNode.insertBefore(t, this.endNode);
|
|
321
321
|
} else if (U(e)) {
|
|
322
322
|
this._clearTemplateCache(), this.clear();
|
|
323
323
|
const t = document.createElement("template");
|
|
@@ -350,7 +350,7 @@ class $ {
|
|
|
350
350
|
}
|
|
351
351
|
class q {
|
|
352
352
|
constructor(e) {
|
|
353
|
-
|
|
353
|
+
o(this, "previousValues", {});
|
|
354
354
|
this.element = e;
|
|
355
355
|
}
|
|
356
356
|
update(e) {
|
|
@@ -400,22 +400,22 @@ class v {
|
|
|
400
400
|
const M = /* @__PURE__ */ new WeakMap(), I = (n, e) => {
|
|
401
401
|
const s = M.get(e);
|
|
402
402
|
if (s && s.strings === n.strings) {
|
|
403
|
-
s.parts.forEach((
|
|
404
|
-
|
|
403
|
+
s.parts.forEach((h, l) => {
|
|
404
|
+
h.update(n.values[l]);
|
|
405
405
|
});
|
|
406
406
|
return;
|
|
407
407
|
}
|
|
408
408
|
const t = [], i = n.values;
|
|
409
409
|
let r = "", a = !1;
|
|
410
|
-
const c = (
|
|
411
|
-
for (let l = 0; l <
|
|
412
|
-
|
|
410
|
+
const c = (h) => {
|
|
411
|
+
for (let l = 0; l < h.length; l++)
|
|
412
|
+
h[l] === "<" && h[l + 1] !== "!" && h[l + 1] !== "/" ? a = !0 : h[l] === ">" && (a = !1);
|
|
413
413
|
}, d = /(\.\.\.|[.@?]?[a-zA-Z0-9_-]+)=["']?$/;
|
|
414
|
-
for (let
|
|
415
|
-
const l = n.strings[
|
|
414
|
+
for (let h = 0; h < n.strings.length - 1; h++) {
|
|
415
|
+
const l = n.strings[h];
|
|
416
416
|
c(l), r += l;
|
|
417
417
|
const u = l.match(d);
|
|
418
|
-
a && u ? r += `__CRP_${
|
|
418
|
+
a && u ? r += `__CRP_${h}__` : r += `<!--CRP_${h}-->`;
|
|
419
419
|
}
|
|
420
420
|
const p = n.strings[n.strings.length - 1];
|
|
421
421
|
c(p), r += p;
|
|
@@ -426,18 +426,18 @@ const M = /* @__PURE__ */ new WeakMap(), I = (n, e) => {
|
|
|
426
426
|
const j = [];
|
|
427
427
|
for (; O = _.nextNode(); )
|
|
428
428
|
j.push(O);
|
|
429
|
-
j.forEach((
|
|
429
|
+
j.forEach((h) => {
|
|
430
430
|
var l;
|
|
431
|
-
if (
|
|
432
|
-
const u = (l =
|
|
431
|
+
if (h.nodeType === Node.COMMENT_NODE) {
|
|
432
|
+
const u = (l = h.nodeValue) == null ? void 0 : l.match(/CRP_(\d+)/);
|
|
433
433
|
if (u) {
|
|
434
434
|
const C = parseInt(u[1]), P = document.createComment("/CRP");
|
|
435
|
-
|
|
436
|
-
const b = new $(
|
|
435
|
+
h.parentNode.insertBefore(P, h.nextSibling);
|
|
436
|
+
const b = new $(h, P);
|
|
437
437
|
t[C] = b;
|
|
438
438
|
}
|
|
439
|
-
} else if (
|
|
440
|
-
const u =
|
|
439
|
+
} else if (h.nodeType === Node.ELEMENT_NODE) {
|
|
440
|
+
const u = h;
|
|
441
441
|
Array.from(u.attributes).forEach((C) => {
|
|
442
442
|
const P = C.value.match(/__CRP_(\d+)__/);
|
|
443
443
|
if (P) {
|
|
@@ -454,8 +454,8 @@ const M = /* @__PURE__ */ new WeakMap(), I = (n, e) => {
|
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
456
|
});
|
|
457
|
-
for (let
|
|
458
|
-
t[
|
|
457
|
+
for (let h = 0; h < i.length; h++)
|
|
458
|
+
t[h] && t[h].update(i[h]);
|
|
459
459
|
if (e instanceof HTMLElement)
|
|
460
460
|
e.innerHTML = "", e.appendChild(f);
|
|
461
461
|
else if (e instanceof DocumentFragment) {
|
|
@@ -466,25 +466,25 @@ const M = /* @__PURE__ */ new WeakMap(), I = (n, e) => {
|
|
|
466
466
|
M.set(e, { strings: n.strings, parts: t });
|
|
467
467
|
};
|
|
468
468
|
export {
|
|
469
|
-
|
|
469
|
+
y as C,
|
|
470
470
|
R as L,
|
|
471
|
-
|
|
471
|
+
E as R,
|
|
472
472
|
B as T,
|
|
473
|
-
|
|
473
|
+
k as U,
|
|
474
474
|
U as a,
|
|
475
475
|
I as b,
|
|
476
476
|
Y as c,
|
|
477
477
|
g as d,
|
|
478
478
|
H as e,
|
|
479
479
|
x as f,
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
T as g,
|
|
481
|
+
L as h,
|
|
482
482
|
S as i,
|
|
483
483
|
X as j,
|
|
484
484
|
G as k,
|
|
485
485
|
Z as l,
|
|
486
486
|
J as m,
|
|
487
|
-
|
|
487
|
+
W as p,
|
|
488
488
|
A as r,
|
|
489
489
|
Q as s,
|
|
490
490
|
ee as u
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cossackframework/renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Light DOM rendering engine for the Cossack Framework",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,11 +27,6 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "vite build",
|
|
32
|
-
"test": "vitest",
|
|
33
|
-
"lint": "oxlint"
|
|
34
|
-
},
|
|
35
30
|
"devDependencies": {
|
|
36
31
|
"htmlparser2": "^10.0.0",
|
|
37
32
|
"magic-string": "^0.30.21",
|
|
@@ -40,5 +35,10 @@
|
|
|
40
35
|
"vite-plugin-dts": "^3.9.1",
|
|
41
36
|
"vite-tsconfig-paths": "^5.1.4",
|
|
42
37
|
"vitest": "^1.2.2"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"test": "vitest",
|
|
42
|
+
"lint": "oxlint"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|