@cossackframework/renderer 0.8.3 → 0.9.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.
- package/README.md +171 -29
- package/agent-docs.json +121 -0
- package/dist/attributes.d.ts +824 -0
- package/dist/attributes.js +1 -0
- package/dist/browser-ssr.d.ts +5 -0
- package/dist/browser-ssr.js +7 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +11 -0
- package/dist/component-tags.d.ts +69 -0
- package/dist/component-tags.js +106 -0
- package/dist/cossack-element.d.ts +36 -2
- package/dist/cossack-element.js +26 -28
- package/dist/cossack-html.d.ts +23 -5
- package/dist/cossack-html.js +1059 -551
- package/dist/css-result.d.ts +9 -0
- package/dist/css-result.js +14 -0
- package/dist/css-scoping.d.ts +4 -0
- package/dist/css-scoping.js +95 -0
- package/dist/css.d.ts +3 -16
- package/dist/css.js +13 -111
- package/dist/diagnostics.d.ts +85 -0
- package/dist/diagnostics.js +465 -0
- package/dist/directives.d.ts +13 -7
- package/dist/directives.js +7 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -7
- package/dist/minify-html.d.ts +22 -0
- package/dist/minify-html.js +123 -18
- package/dist/server.d.ts +3 -1
- package/dist/server.js +6 -4
- package/dist/ssr-form-values.d.ts +2 -0
- package/dist/ssr-form-values.js +72 -0
- package/dist/style-registry.d.ts +42 -0
- package/dist/style-registry.js +73 -0
- package/dist/style-runtime.d.ts +47 -0
- package/dist/style-runtime.js +43 -0
- package/dist/template-analysis.d.ts +224 -0
- package/dist/template-analysis.js +321 -0
- package/dist/template-parse.d.ts +157 -0
- package/dist/template-parse.js +526 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.js +3 -0
- package/package.json +26 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @ts-self-types="./attributes.d.ts"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @ts-self-types="./browser-ssr.d.ts"
|
|
2
|
+
//#region src/browser-ssr.ts
|
|
3
|
+
var e = (e, t = {}) => {
|
|
4
|
+
throw Error("Browser HTML serialization requires @cossackframework/renderer/server. Use render() or hydrate() for DOM updates.");
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as renderToString };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-self-types="./browser.d.ts"
|
|
2
|
+
import { collectComponentStyles as e, renderComponentStyles as t } from "./style-runtime.js";
|
|
3
|
+
import { isComponentResult as n } from "./component.js";
|
|
4
|
+
import { COMPONENT_RANGE as r, CossackElement as i, getComponentRange as a, instanceStack as o, popCurrentInstance as s, pushCurrentInstance as c, setComponentRange as l } from "./cossack-element.js";
|
|
5
|
+
import { BindResult as u, CacheResult as d, GuardResult as f, IfDefinedResult as p, KeyResult as m, LiveResult as h, PreventDefaultResult as g, RepeatResult as _, bind as v, cache as y, choose as b, classMap as x, guard as S, ifDefined as C, join as w, key as T, live as E, map as D, preventDefault as O, range as k, repeat as A, resolveField as j, setField as M, styleMap as N, when as P } from "./directives.js";
|
|
6
|
+
import { TemplateResult as F, UnsafeHTMLResult as I, captureRenderDrafts as L, component as R, escapeHtml as z, html as B, hydrate as V, isTemplateResult as H, isUnsafeHTML as U, nothing as W, render as G, svg as K, unsafeHTML as q } from "./cossack-html.js";
|
|
7
|
+
import { createContext as J } from "./context.js";
|
|
8
|
+
import { CSSResult as Y } from "./css-result.js";
|
|
9
|
+
import { css as X, unsafeCSS as Z } from "./css.js";
|
|
10
|
+
import { renderToString as Q } from "./browser-ssr.js";
|
|
11
|
+
export { u as BindResult, r as COMPONENT_RANGE, Y as CSSResult, d as CacheResult, i as CossackElement, f as GuardResult, p as IfDefinedResult, m as KeyResult, h as LiveResult, g as PreventDefaultResult, _ as RepeatResult, F as TemplateResult, I as UnsafeHTMLResult, v as bind, y as cache, L as captureRenderDrafts, b as choose, x as classMap, e as collectComponentStyles, R as component, J as createContext, X as css, z as escapeHtml, a as getComponentRange, S as guard, B as html, V as hydrate, C as ifDefined, o as instanceStack, n as isComponentResult, H as isTemplateResult, U as isUnsafeHTML, w as join, T as key, E as live, D as map, W as nothing, s as popCurrentInstance, O as preventDefault, c as pushCurrentInstance, k as range, G as render, t as renderComponentStyles, Q as renderToString, A as repeat, j as resolveField, l as setComponentRange, M as setField, N as styleMap, K as svg, Z as unsafeCSS, q as unsafeHTML, P as when };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** One prop, in source order: later props and spreads override earlier ones. */
|
|
2
|
+
export type ComponentPropPlan =
|
|
3
|
+
/** `name="text"` (entities decoded) or a bare `name` (true). */
|
|
4
|
+
{
|
|
5
|
+
readonly kind: 'static';
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly value: string | true;
|
|
8
|
+
}
|
|
9
|
+
/** `name=${value}`: the value as is. */
|
|
10
|
+
| {
|
|
11
|
+
readonly kind: 'value';
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly binding: number;
|
|
14
|
+
}
|
|
15
|
+
/** `name="a ${b}"`: text, the same as an interpolated attribute. */
|
|
16
|
+
| {
|
|
17
|
+
readonly kind: 'text';
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly segments: readonly string[];
|
|
20
|
+
readonly bindings: readonly number[];
|
|
21
|
+
}
|
|
22
|
+
/** `...=${props}`. */
|
|
23
|
+
| {
|
|
24
|
+
readonly kind: 'spread';
|
|
25
|
+
readonly binding: number;
|
|
26
|
+
};
|
|
27
|
+
export type ComponentChildrenPlan = {
|
|
28
|
+
readonly kind: 'none';
|
|
29
|
+
}
|
|
30
|
+
/** Static text without markup or entities. */
|
|
31
|
+
| {
|
|
32
|
+
readonly kind: 'text';
|
|
33
|
+
readonly text: string;
|
|
34
|
+
}
|
|
35
|
+
/** One binding or component tag with only whitespace around it. */
|
|
36
|
+
| {
|
|
37
|
+
readonly kind: 'slot';
|
|
38
|
+
readonly slot: TemplateSlot;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: 'template';
|
|
41
|
+
readonly plan: TemplatePlan;
|
|
42
|
+
};
|
|
43
|
+
export interface ComponentPlan {
|
|
44
|
+
/** The binding that holds the component class. */
|
|
45
|
+
readonly binding: number;
|
|
46
|
+
/** The binding of the closing tag, which must hold the same class. */
|
|
47
|
+
readonly closeBinding: number | null;
|
|
48
|
+
readonly props: readonly ComponentPropPlan[];
|
|
49
|
+
readonly children: ComponentChildrenPlan;
|
|
50
|
+
}
|
|
51
|
+
/** A value of the compiled template: an original binding, or a component. */
|
|
52
|
+
export type TemplateSlot = number | ComponentPlan;
|
|
53
|
+
export interface TemplatePlan {
|
|
54
|
+
/** Identity-stable strings, so the compiled template is cached like any other. */
|
|
55
|
+
readonly strings: TemplateStringsArray;
|
|
56
|
+
readonly slots: readonly TemplateSlot[];
|
|
57
|
+
}
|
|
58
|
+
/** Decode the character references a static attribute value commonly uses. */
|
|
59
|
+
export declare const decodeEntities: (text: string) => string;
|
|
60
|
+
/** True when a template might contain component tags; the parse decides. */
|
|
61
|
+
export declare const mayContainComponentTags: (strings: readonly string[]) => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Compile the component tags of a template. Returns null when it has none.
|
|
64
|
+
* Throws for a component tag that is never closed or a closing tag without
|
|
65
|
+
* an opening one: the template has no meaning then.
|
|
66
|
+
*/
|
|
67
|
+
export declare const compileComponentTags: (input: readonly string[], options?: {
|
|
68
|
+
svg?: boolean;
|
|
69
|
+
}) => TemplatePlan | null;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// @ts-self-types="./component-tags.d.ts"
|
|
2
|
+
import { parseTemplate as e } from "./template-parse.js";
|
|
3
|
+
//#region src/component-tags.ts
|
|
4
|
+
var t = {
|
|
5
|
+
amp: "&",
|
|
6
|
+
lt: "<",
|
|
7
|
+
gt: ">",
|
|
8
|
+
quot: "\"",
|
|
9
|
+
apos: "'",
|
|
10
|
+
nbsp: "\xA0"
|
|
11
|
+
}, n = (e) => e.includes("&") ? e.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (e, n) => {
|
|
12
|
+
if (n[0] !== "#") return t[n.toLowerCase()] ?? e;
|
|
13
|
+
let r = n[1] === "x" || n[1] === "X" ? parseInt(n.slice(2), 16) : parseInt(n.slice(1), 10);
|
|
14
|
+
return r > 0 && r <= 1114111 ? String.fromCodePoint(r) : e;
|
|
15
|
+
}) : e, r = (e) => Object.freeze(Object.assign(e, { raw: Object.freeze([...e]) })), i = (e) => {
|
|
16
|
+
for (let t = 0; t < e.length - 1; t++) {
|
|
17
|
+
let n = e[t];
|
|
18
|
+
if (n.charCodeAt(n.length - 1) === 60 || n.endsWith("</")) return !0;
|
|
19
|
+
}
|
|
20
|
+
return !1;
|
|
21
|
+
}, a = (e, t = []) => {
|
|
22
|
+
for (let n of e) n.type === "component" ? t.push(n) : n.type === "element" && a(n.children, t);
|
|
23
|
+
return t;
|
|
24
|
+
}, o = (e) => e.trim() === "", s = (t, i = {}) => {
|
|
25
|
+
let s = e(t, i), c = s.problems.find((e) => e.code === "COSSACK_TEMPLATE_UNCLOSED_COMPONENT" || e.code === "COSSACK_TEMPLATE_UNEXPECTED_COMPONENT_END");
|
|
26
|
+
if (c) throw Error(`[cossack/renderer] ${c.message}`);
|
|
27
|
+
if (a(s.nodes).length === 0) return null;
|
|
28
|
+
let l = (e, n, i) => {
|
|
29
|
+
let o = a(i), s = [], c = [], l = "", d = e.string, f = e.offset, p = 0;
|
|
30
|
+
for (;;) {
|
|
31
|
+
let e = o[p];
|
|
32
|
+
if (e && e.startTag.start.string === d) {
|
|
33
|
+
s.push(l + t[d].slice(f, e.startTag.start.offset)), l = "", c.push(u(e)), d = e.range.end.string, f = e.range.end.offset, p++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (d === n.string) {
|
|
37
|
+
s.push(l + t[d].slice(f, n.offset));
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
s.push(l + t[d].slice(f)), l = "", c.push(d), d++, f = 0;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
strings: r(s),
|
|
44
|
+
slots: c
|
|
45
|
+
};
|
|
46
|
+
}, u = (e) => {
|
|
47
|
+
let t = [];
|
|
48
|
+
for (let r of e.attributes) {
|
|
49
|
+
let { name: e, bindings: i, segments: a } = r;
|
|
50
|
+
e === "..." ? i.length === 1 && t.push({
|
|
51
|
+
kind: "spread",
|
|
52
|
+
binding: i[0]
|
|
53
|
+
}) : r.hasValue ? i.length === 0 ? t.push({
|
|
54
|
+
kind: "static",
|
|
55
|
+
name: e,
|
|
56
|
+
value: n(a[0])
|
|
57
|
+
}) : i.length === 1 && a[0] === "" && a[1] === "" ? t.push({
|
|
58
|
+
kind: "value",
|
|
59
|
+
name: e,
|
|
60
|
+
binding: i[0]
|
|
61
|
+
}) : t.push({
|
|
62
|
+
kind: "text",
|
|
63
|
+
name: e,
|
|
64
|
+
segments: a.map(n),
|
|
65
|
+
bindings: i
|
|
66
|
+
}) : t.push({
|
|
67
|
+
kind: "static",
|
|
68
|
+
name: e,
|
|
69
|
+
value: !0
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
binding: e.binding,
|
|
74
|
+
closeBinding: e.closeBinding,
|
|
75
|
+
props: t,
|
|
76
|
+
children: d(e)
|
|
77
|
+
};
|
|
78
|
+
}, d = (e) => {
|
|
79
|
+
if (e.closeStart === null) return { kind: "none" };
|
|
80
|
+
let t = l(e.startTag.end, e.closeStart, e.children), { strings: n, slots: r } = t;
|
|
81
|
+
if (r.length === 0) {
|
|
82
|
+
let e = n[0];
|
|
83
|
+
if (o(e)) return { kind: "none" };
|
|
84
|
+
if (!e.includes("<") && !e.includes("&")) return {
|
|
85
|
+
kind: "text",
|
|
86
|
+
text: e
|
|
87
|
+
};
|
|
88
|
+
} else if (r.length === 1 && o(n[0]) && o(n[1])) return {
|
|
89
|
+
kind: "slot",
|
|
90
|
+
slot: r[0]
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
kind: "template",
|
|
94
|
+
plan: t
|
|
95
|
+
};
|
|
96
|
+
}, f = t.length - 1;
|
|
97
|
+
return l({
|
|
98
|
+
string: 0,
|
|
99
|
+
offset: 0
|
|
100
|
+
}, {
|
|
101
|
+
string: f,
|
|
102
|
+
offset: t[f].length
|
|
103
|
+
}, s.nodes);
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { s as compileComponentTags, n as decodeEntities, i as mayContainComponentTags };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TemplateResult } from './cossack-html.js';
|
|
1
|
+
import { TemplateResult, type HydrationDiagnosticMetadata } from './cossack-html.js';
|
|
2
2
|
import { Context } from './context.js';
|
|
3
|
-
import type { CSSResultGroup } from './css.js';
|
|
3
|
+
import type { CSSResultGroup } from './css-result.js';
|
|
4
4
|
export type PropertyDeclaration = {
|
|
5
5
|
type?: unknown;
|
|
6
6
|
reflect?: boolean;
|
|
@@ -10,6 +10,30 @@ export interface PropertyDeclarations {
|
|
|
10
10
|
[key: string]: PropertyDeclaration;
|
|
11
11
|
}
|
|
12
12
|
export type PropertyValues = Map<string | number | symbol, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* @internal Framework-only. The comment markers that bracket a `component()`
|
|
15
|
+
* child's rendered output. Children have no host element, so this is how the
|
|
16
|
+
* framework scopes DOM work (such as `@On` delegation) to exactly their nodes.
|
|
17
|
+
* `start` and `end` always reflect the renderer's current markers.
|
|
18
|
+
*/
|
|
19
|
+
export interface ComponentRange {
|
|
20
|
+
readonly start: Comment;
|
|
21
|
+
readonly end: Comment;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @internal Framework-only. Registered-symbol key under which the client
|
|
25
|
+
* renderer stores a component instance's {@link ComponentRange}. A symbol key
|
|
26
|
+
* (instead of a declared field) keeps DOM types out of the component's
|
|
27
|
+
* public field types, and `Symbol.for` lets core read it without importing.
|
|
28
|
+
*/
|
|
29
|
+
export declare const COMPONENT_RANGE: unique symbol;
|
|
30
|
+
/**
|
|
31
|
+
* @internal Framework-only. The DOM range of a client-rendered `component()`
|
|
32
|
+
* child; undefined for root-mounted components and on the server.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getComponentRange: (instance: object) => ComponentRange | undefined;
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare const setComponentRange: (instance: object, range: ComponentRange | undefined) => void;
|
|
13
37
|
export interface ReactiveController {
|
|
14
38
|
hostConnected?(): void;
|
|
15
39
|
hostDisconnected?(): void;
|
|
@@ -26,6 +50,8 @@ export declare const instanceStack: CossackElement[];
|
|
|
26
50
|
export declare const pushCurrentInstance: (instance: CossackElement) => number;
|
|
27
51
|
export declare const popCurrentInstance: () => CossackElement | undefined;
|
|
28
52
|
export declare class CossackElement implements ReactiveControllerHost {
|
|
53
|
+
/** Development-only boundary hints; override to mark intentional client differences. */
|
|
54
|
+
get hydrationMetadata(): HydrationDiagnosticMetadata | undefined;
|
|
29
55
|
static properties: PropertyDeclarations;
|
|
30
56
|
static readonly _isCossackElement = true;
|
|
31
57
|
static components: Record<string, typeof CossackElement>;
|
|
@@ -35,6 +61,12 @@ export declare class CossackElement implements ReactiveControllerHost {
|
|
|
35
61
|
__parent: CossackElement | null;
|
|
36
62
|
_id: string;
|
|
37
63
|
_childCounter: number;
|
|
64
|
+
/**
|
|
65
|
+
* @internal Live client-rendered children by `_id`. The counter restarts
|
|
66
|
+
* every render while retained children keep their ids, so a newly created
|
|
67
|
+
* child skips any id a live sibling still holds.
|
|
68
|
+
*/
|
|
69
|
+
_liveChildIds: Map<string, CossackElement>;
|
|
38
70
|
private __providedContexts;
|
|
39
71
|
private __properties;
|
|
40
72
|
private __updatePromise;
|
|
@@ -67,6 +99,8 @@ export declare class CossackElement implements ReactiveControllerHost {
|
|
|
67
99
|
_finalizeRenderOutput(value: TemplateResult | unknown | null): TemplateResult | unknown | null;
|
|
68
100
|
private _claimTemplateOwnership;
|
|
69
101
|
mount(container: HTMLElement, hydrateFirst?: boolean): void;
|
|
102
|
+
/** @internal Attach an owned root without scheduling an unowned initial render. */
|
|
103
|
+
_frameworkAttachRenderRoot(container: HTMLElement, isCurrent: () => boolean, hydrateFirst?: boolean): () => void;
|
|
70
104
|
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, _options?: boolean | AddEventListenerOptions): void;
|
|
71
105
|
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, _options?: boolean | EventListenerOptions): void;
|
|
72
106
|
dispatchEvent(event: Event): boolean;
|
package/dist/cossack-element.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
// @ts-self-types="./cossack-element.d.ts"
|
|
2
|
-
import { getFinalizedStyles as e } from "./
|
|
3
|
-
import { TemplateResult as t, html as n, hydrate as r, isTemplateResult as i,
|
|
2
|
+
import { getFinalizedStyles as e } from "./style-runtime.js";
|
|
3
|
+
import { TemplateResult as t, html as n, hydrate as r, isTemplateResult as i, nothing as a, render as o } from "./cossack-html.js";
|
|
4
4
|
//#region src/cossack-element.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let n = l.get(e);
|
|
10
|
-
if (!n) {
|
|
11
|
-
let r = t.cssText.replace(/<\/style/gi, "<\\/style");
|
|
12
|
-
n = u(`<style data-cossack-style="${t.scopeId}">${r}</style>`), l.set(e, n);
|
|
13
|
-
}
|
|
14
|
-
return n;
|
|
15
|
-
}, f = (e, t) => n`${e}${t}`, p = class {
|
|
5
|
+
var s = Symbol.for("@cossackframework/renderer/component-range"), c = (e) => e[s], l = (e, t) => {
|
|
6
|
+
e[s] = t;
|
|
7
|
+
}, u = [], d = (e) => u.push(e), f = () => u.pop(), p = Object.assign(["", ""], { raw: ["", ""] }), m = (e) => e == null || e === !1 || e === "" || e === a, h = class {
|
|
8
|
+
get hydrationMetadata() {}
|
|
16
9
|
static properties = {};
|
|
17
10
|
static _isCossackElement = !0;
|
|
18
11
|
static components = {};
|
|
@@ -22,6 +15,7 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
22
15
|
__parent = null;
|
|
23
16
|
_id = "";
|
|
24
17
|
_childCounter = 0;
|
|
18
|
+
_liveChildIds = /* @__PURE__ */ new Map();
|
|
25
19
|
__providedContexts = /* @__PURE__ */ new Map();
|
|
26
20
|
__properties = /* @__PURE__ */ new Map();
|
|
27
21
|
__updatePromise = null;
|
|
@@ -34,7 +28,7 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
34
28
|
this.initialize();
|
|
35
29
|
}
|
|
36
30
|
static get currentRenderingInstance() {
|
|
37
|
-
return
|
|
31
|
+
return u.length > 0 ? u[u.length - 1] : null;
|
|
38
32
|
}
|
|
39
33
|
resetRenderState() {
|
|
40
34
|
this._childCounter = 0;
|
|
@@ -84,12 +78,12 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
84
78
|
let e = !1;
|
|
85
79
|
try {
|
|
86
80
|
if (e = this.shouldUpdate(this.__changedProperties), e) {
|
|
87
|
-
this.__controllers.forEach((e) => e.hostUpdate && e.hostUpdate()), this.willUpdate(this.__changedProperties), this.resetRenderState(),
|
|
81
|
+
this.__controllers.forEach((e) => e.hostUpdate && e.hostUpdate()), this.willUpdate(this.__changedProperties), this.resetRenderState(), d(this);
|
|
88
82
|
let e = this._finalizeRenderOutput(this.render());
|
|
89
|
-
this.__notifyListeners(e),
|
|
83
|
+
this.__notifyListeners(e), f(), this.updated(this.__changedProperties), this.__controllers.forEach((e) => e.hostUpdated && e.hostUpdated());
|
|
90
84
|
}
|
|
91
85
|
} catch (e) {
|
|
92
|
-
console.error("Error during update:", e),
|
|
86
|
+
console.error("Error during update:", e), u[u.length - 1] === this && f();
|
|
93
87
|
}
|
|
94
88
|
return this.__changedProperties = /* @__PURE__ */ new Map(), this.__updatePromise = null, e;
|
|
95
89
|
}
|
|
@@ -105,9 +99,11 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
105
99
|
_getStyleScopeId() {
|
|
106
100
|
return e(this.constructor)?.scopeId;
|
|
107
101
|
}
|
|
108
|
-
_finalizeRenderOutput(
|
|
109
|
-
let
|
|
110
|
-
|
|
102
|
+
_finalizeRenderOutput(n) {
|
|
103
|
+
let r = e(this.constructor);
|
|
104
|
+
if (this._claimTemplateOwnership(n, r?.scopeId), !r || r.cssText === "" || m(n) || i(n) && n.__cossackOwner === this) return n;
|
|
105
|
+
let a = new t(p, [n]);
|
|
106
|
+
return a.__cossackOwner = this, a.__cossackScope = r.scopeId, a;
|
|
111
107
|
}
|
|
112
108
|
_claimTemplateOwnership(e, t) {
|
|
113
109
|
if (!(!e || typeof e != "object")) {
|
|
@@ -126,13 +122,15 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
126
122
|
}
|
|
127
123
|
}
|
|
128
124
|
mount(e, t = !1) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
125
|
+
this._frameworkAttachRenderRoot(e, () => !0, t), this.requestUpdate();
|
|
126
|
+
}
|
|
127
|
+
_frameworkAttachRenderRoot(e, t, a = !1) {
|
|
128
|
+
let s = a, c = (a) => {
|
|
129
|
+
if (!t()) return;
|
|
130
|
+
let c = i(a) ? a : n`${a}`;
|
|
131
|
+
s ? (s = !1, r(c, e, import.meta.env?.DEV ? this.hydrationMetadata : void 0)) : o(c, e);
|
|
132
|
+
};
|
|
133
|
+
return this.addRenderListener(c), () => this.removeRenderListener(c);
|
|
136
134
|
}
|
|
137
135
|
addEventListener(e, t, n) {
|
|
138
136
|
t && (this.__eventListeners.has(e) || this.__eventListeners.set(e, /* @__PURE__ */ new Set()), this.__eventListeners.get(e).add(t));
|
|
@@ -164,4 +162,4 @@ var o = [], s = (e) => o.push(e), c = () => o.pop(), l = /* @__PURE__ */ new Wea
|
|
|
164
162
|
}
|
|
165
163
|
};
|
|
166
164
|
//#endregion
|
|
167
|
-
export {
|
|
165
|
+
export { s as COMPONENT_RANGE, h as CossackElement, c as getComponentRange, u as instanceStack, f as popCurrentInstance, d as pushCurrentInstance, l as setComponentRange };
|
package/dist/cossack-html.d.ts
CHANGED
|
@@ -12,13 +12,14 @@ export declare class TemplateResult<T extends TemplateResultType = TemplateResul
|
|
|
12
12
|
__cossackScope?: string;
|
|
13
13
|
}
|
|
14
14
|
export type SVGTemplateResult = TemplateResult<2>;
|
|
15
|
+
/** The types template diagnostics check bindings against; see attributes.ts. */
|
|
16
|
+
export type { TemplateTypeMap } from './attributes.js';
|
|
15
17
|
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult<1>;
|
|
16
18
|
export declare const svg: (strings: TemplateStringsArray, ...values: unknown[]) => SVGTemplateResult;
|
|
17
19
|
/** Lit-compatible sentinel that removes the value in its binding context. */
|
|
18
20
|
export declare const nothing: unique symbol;
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export declare const component: <T extends CossackElement>(clazz: new () => T, props?: T['props'] & Record<string, unknown>, children?: unknown) => TemplateResult<1>;
|
|
21
|
+
export declare function component<T extends CossackElement>(clazz: new () => T, props: T['props'], children?: unknown): TemplateResult<1>;
|
|
22
|
+
export declare function component<T extends CossackElement>(clazz: new () => T, props?: T['props'], children?: unknown): TemplateResult<1>;
|
|
22
23
|
export declare const isTemplateResult: (value: unknown) => value is TemplateResult;
|
|
23
24
|
declare const UNSAFE_HTML_BRAND: unique symbol;
|
|
24
25
|
export declare class UnsafeHTMLResult {
|
|
@@ -32,6 +33,24 @@ export declare const escapeHtml: (unsafe: unknown) => string;
|
|
|
32
33
|
export declare const renderToString: (result: TemplateResult, opts?: {
|
|
33
34
|
hydrate?: boolean;
|
|
34
35
|
}) => string;
|
|
36
|
+
/** Development-only context; source files must be project-relative. Values are never captured. */
|
|
37
|
+
export interface HydrationDiagnosticMetadata {
|
|
38
|
+
component?: string;
|
|
39
|
+
source?: {
|
|
40
|
+
file: string;
|
|
41
|
+
line?: number;
|
|
42
|
+
column?: number;
|
|
43
|
+
};
|
|
44
|
+
statePath?: string;
|
|
45
|
+
fields?: Record<number, string>;
|
|
46
|
+
/** Suppress expected differences at this boundary while still reconciling DOM. */
|
|
47
|
+
expectedClientOnly?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** @internal Local, one-use draft checkpoint. Contains no serializable state or live DOM restoration. */
|
|
50
|
+
export declare const captureRenderDrafts: (container: Node) => {
|
|
51
|
+
restore(current: () => boolean, owners?: Iterable<readonly [CossackElement, CossackElement]>): void;
|
|
52
|
+
discard(): void;
|
|
53
|
+
};
|
|
35
54
|
export declare const render: (result: TemplateResult, container: Node) => void;
|
|
36
55
|
/**
|
|
37
56
|
* Hydrate an existing container whose children were produced by SSR
|
|
@@ -43,5 +62,4 @@ export declare const render: (result: TemplateResult, container: Node) => void;
|
|
|
43
62
|
* If the existing DOM cannot be confidently matched to the template, falls
|
|
44
63
|
* back to a full `render()` so behaviour is always correct.
|
|
45
64
|
*/
|
|
46
|
-
export declare const hydrate: (result: TemplateResult, container: Node) => void;
|
|
47
|
-
export {};
|
|
65
|
+
export declare const hydrate: (result: TemplateResult, container: Node, metadata?: HydrationDiagnosticMetadata) => void;
|