@cossackframework/renderer 0.7.5 → 0.7.7

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/dist/css.js ADDED
@@ -0,0 +1,115 @@
1
+ import e from "css-tree/parser";
2
+ import t from "css-tree/generator";
3
+ import n from "css-tree/walker";
4
+ //#region src/css.ts
5
+ var r = Symbol("cossack-css-result"), i = class {
6
+ cssText;
7
+ constructor(e, t) {
8
+ if (t !== r) throw Error("[cossack/renderer] CSSResult cannot be constructed directly. Use css`` or unsafeCSS().");
9
+ this.cssText = e;
10
+ }
11
+ toString() {
12
+ return this.cssText;
13
+ }
14
+ }, a = (e) => new i(e, r), o = (e, ...t) => {
15
+ let n = e[0];
16
+ for (let r = 0; r < t.length; r++) {
17
+ let a = t[r];
18
+ if (typeof a == "number") n += String(a);
19
+ else if (a instanceof i) n += a.cssText;
20
+ else throw Error("[cossack/renderer] css`` interpolations must be numbers or CSSResult values. Use unsafeCSS() only for explicitly trusted raw CSS.");
21
+ n += e[r + 1];
22
+ }
23
+ return a(n);
24
+ }, s = (e) => a(String(e)), c = /* @__PURE__ */ new WeakMap(), l = (e, t) => {
25
+ if (Array.isArray(e)) {
26
+ for (let n of e) l(n, t);
27
+ return;
28
+ }
29
+ if (e instanceof i) {
30
+ t.push(e);
31
+ return;
32
+ }
33
+ throw TypeError("[cossack/renderer] static styles must contain only CSSResult values returned by css`` or unsafeCSS().");
34
+ }, u = (e) => {
35
+ let t = /* @__PURE__ */ new Set(), n = [];
36
+ for (let r = e.length - 1; r >= 0; r--) {
37
+ let i = e[r];
38
+ t.has(i) || (t.add(i), n.push(i));
39
+ }
40
+ return n.reverse(), n;
41
+ }, d = (e) => {
42
+ let t = 2166136261, n = new TextEncoder().encode(e);
43
+ for (let e of n) t ^= e, t = Math.imul(t, 16777619) >>> 0;
44
+ return t.toString(36);
45
+ }, f = (t) => e(`[data-cossack-scope="${t}"]`, { context: "selector" }).children.first, p = (e) => {
46
+ if (e?.type === "AttributeSelector") return typeof e.name == "string" ? e.name : e.name?.name;
47
+ }, m = (e, t) => {
48
+ let n = e.children;
49
+ if (!n) return;
50
+ n.forEach((e) => {
51
+ if (e.type === "PseudoClassSelector") {
52
+ let n = String(e.name).toLowerCase();
53
+ if (n === "host" || n === "host-context") throw Error(`[cossack/renderer] Shadow DOM selector :${n} is not supported by Light DOM scoped styles.`);
54
+ e.children && e.children.forEach((e) => {
55
+ e.type === "SelectorList" && e.children.forEach((e) => m(e, t));
56
+ });
57
+ } else if (e.type === "PseudoElementSelector" && String(e.name).toLowerCase() === "slotted") throw Error("[cossack/renderer] Shadow DOM selector ::slotted is not supported by Light DOM scoped styles.");
58
+ });
59
+ let r = n.head, i = n.head;
60
+ for (; i;) {
61
+ let e = i.next;
62
+ i.data.type === "Combinator" && (h(n, r, i, t), r = e), i = e;
63
+ }
64
+ h(n, r, null, t);
65
+ }, h = (e, t, n, r) => {
66
+ if (!t || t === n) return;
67
+ let i = t, a = n, o = !1;
68
+ for (; i && i !== n;) p(i.data) === "data-cossack-scope" && (o = !0), (i.data.type === "PseudoClassSelector" || i.data.type === "PseudoElementSelector") && a === n && (a = i), i = i.next;
69
+ o || e.insertData(f(r), a);
70
+ }, g = (e, r) => {
71
+ let i = /* @__PURE__ */ new Map();
72
+ return n(e, {
73
+ visit: "Atrule",
74
+ enter(e) {
75
+ let t = String(e.name).toLowerCase();
76
+ if (t !== "keyframes" && t !== "-webkit-keyframes") return;
77
+ let n = e.prelude?.children?.first, a = n?.name ?? n?.value;
78
+ if (typeof a != "string") return;
79
+ let o = `${r}-${a}`;
80
+ i.set(a, o), "name" in n ? n.name = o : n.value = o;
81
+ }
82
+ }), n(e, {
83
+ visit: "Rule",
84
+ enter(e) {
85
+ let t = String(this.atrule?.name ?? "").toLowerCase();
86
+ t === "keyframes" || t === "-webkit-keyframes" || e.prelude?.type === "SelectorList" && e.prelude.children.forEach((e) => m(e, r));
87
+ }
88
+ }), i.size > 0 && n(e, {
89
+ visit: "Declaration",
90
+ enter(e) {
91
+ let t = String(e.property).toLowerCase();
92
+ t !== "animation" && t !== "animation-name" && t !== "-webkit-animation" && t !== "-webkit-animation-name" || n(e.value, (e) => {
93
+ if (e.type !== "Identifier" && e.type !== "String") return;
94
+ let t = e.name ?? e.value, n = i.get(t);
95
+ n && ("name" in e ? e.name = n : e.value = n);
96
+ });
97
+ }
98
+ }), t(e);
99
+ }, _ = (n) => {
100
+ if (c.has(n)) return c.get(n);
101
+ let r = n.styles;
102
+ if (r === void 0) return c.set(n, null), null;
103
+ let i = [];
104
+ l(r, i);
105
+ let a = e(u(i).map((e) => e.cssText).join("\n"), {
106
+ context: "stylesheet",
107
+ parseCustomProperty: !0
108
+ }), o = `c${d(t(a))}`, s = {
109
+ cssText: g(a, o),
110
+ scopeId: o
111
+ };
112
+ return c.set(n, s), s;
113
+ };
114
+ //#endregion
115
+ export { i as CSSResult, o as css, _ as getFinalizedStyles, s as unsafeCSS };
@@ -0,0 +1,93 @@
1
+ //#region src/directives.ts
2
+ var e = class {
3
+ value;
4
+ constructor(e) {
5
+ this.value = e;
6
+ }
7
+ }, t = class {
8
+ items;
9
+ keyFn;
10
+ templateFn;
11
+ constructor(e, t, n) {
12
+ this.items = e, this.keyFn = t, this.templateFn = n;
13
+ }
14
+ }, n = class {
15
+ value;
16
+ template;
17
+ constructor(e, t) {
18
+ this.value = e, this.template = t;
19
+ }
20
+ }, r = class {
21
+ component;
22
+ fieldName;
23
+ constructor(e, t) {
24
+ this.component = e, this.fieldName = t;
25
+ }
26
+ }, i = class {
27
+ handler;
28
+ novalidate;
29
+ constructor(e, t) {
30
+ this.handler = e, this.novalidate = t;
31
+ }
32
+ }, a = class {
33
+ value;
34
+ constructor(e) {
35
+ this.value = e;
36
+ }
37
+ }, o = class {
38
+ deps;
39
+ factory;
40
+ constructor(e, t) {
41
+ this.deps = e, this.factory = t;
42
+ }
43
+ }, s = class {
44
+ value;
45
+ constructor(e) {
46
+ this.value = e;
47
+ }
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
+ function m(e, t) {
50
+ let n = e;
51
+ if (!t.includes(".")) return n?.[t];
52
+ let r = t.split("."), i = n?.[r[0]];
53
+ for (let e = 1; e < r.length; e++) {
54
+ if (i == null) return;
55
+ i = i[r[e]];
56
+ }
57
+ return i;
58
+ }
59
+ function h(e, t, n) {
60
+ let r = e;
61
+ if (!r) return;
62
+ if (!t.includes(".")) {
63
+ r[t] = n;
64
+ return;
65
+ }
66
+ let i = t.split(".");
67
+ r[i[0]] ?? (r[i[0]] = {});
68
+ let a = r[i[0]];
69
+ for (let e = 1; e < i.length - 1; e++) {
70
+ if (typeof a != "object" || !a) return;
71
+ (a[i[e]] == null || typeof a[i[e]] != "object") && (a[i[e]] = {}), a = a[i[e]];
72
+ }
73
+ typeof a == "object" && a && (a[i[i.length - 1]] = n);
74
+ }
75
+ var g = (e, t) => new i(e, t?.novalidate ?? !0), _ = (e) => new a(e), v = (e, t) => new o(e, t), y = (e) => new s(e), b = (e, t, n) => e ? t(e) : n?.(e), x = (e, t, n) => {
76
+ for (let n = 0; n < t.length; n++) {
77
+ let [r, i] = t[n];
78
+ if (r === e) return i(e, n);
79
+ }
80
+ return n?.();
81
+ }, S = (e, t) => Array.from(e, t), C = (e, t, n) => {
82
+ let r = Array.from(e), i = [], a = typeof n == "function" ? n : () => n;
83
+ for (let e = 0; e < r.length; e++) i.push(t(r[e], e)), e < r.length - 1 && i.push(a(e));
84
+ return i;
85
+ }, w = (e, t, n = 1) => {
86
+ let r = t === void 0 ? 0 : e, i = t === void 0 ? e : t, a = [];
87
+ if (n === 0) return a;
88
+ if (n > 0) for (let e = r; e < i; e += n) a.push(e);
89
+ else for (let e = r; e > i; e += n) a.push(e);
90
+ return a;
91
+ };
92
+ //#endregion
93
+ export { r as BindResult, s as CacheResult, o as GuardResult, a as IfDefinedResult, n as KeyResult, e as LiveResult, i as PreventDefaultResult, t as RepeatResult, p as bind, y as cache, x as choose, u as classMap, v as guard, _ as ifDefined, C as join, f as key, c as live, S as map, g as preventDefault, w as range, l as repeat, m as resolveField, h as setField, d as styleMap, b as when };
package/dist/index.js CHANGED
@@ -1,10 +1,7 @@
1
- import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, K as l, L as u, M as d, N as f, O as p, P as m, R as h, S as g, T as _, U as v, V as y, W as b, _ as x, a as S, b as C, c as w, d as T, f as E, g as D, h as O, i as k, j as A, k as j, l as M, m as N, n as P, o as F, p as I, r as L, s as R, t as z, u as B, v as V, w as H, x as U, y as W, z as G } from "./cossack-html-CnATUTdE.js";
2
- //#region src/context.ts
3
- function K(e) {
4
- return {
5
- id: Math.random().toString(36).slice(2),
6
- defaultValue: e
7
- };
8
- }
9
- //#endregion
10
- export { N as BindResult, v as CSSResult, O as CacheResult, G as CossackElement, D as GuardResult, x as IfDefinedResult, V as KeyResult, W as LiveResult, C as PreventDefaultResult, U as RepeatResult, z as TemplateResult, P as UnsafeHTMLResult, g as bind, n as cache, H as choose, _ as classMap, L as component, K as createContext, b as css, k as escapeHtml, i as guard, S as html, F as hydrate, r as ifDefined, t as instanceStack, l as isComponentResult, R as isTemplateResult, w as isUnsafeHTML, p as join, j as key, e as live, A as map, M as nothing, y as popCurrentInstance, d as preventDefault, s as pushCurrentInstance, f as range, B as render, T as renderToString, m as repeat, a as resolveField, c as setField, u as styleMap, E as svg, o as unsafeCSS, I as unsafeHTML, h as when };
1
+ import { isComponentResult as e } from "./component.js";
2
+ import { CSSResult as t, css as n, unsafeCSS as r } from "./css.js";
3
+ import { CossackElement as i, instanceStack as a, popCurrentInstance as o, pushCurrentInstance as s } from "./cossack-element.js";
4
+ import { BindResult as c, CacheResult as l, GuardResult as u, IfDefinedResult as d, KeyResult as f, LiveResult as p, PreventDefaultResult as m, RepeatResult as h, bind as g, cache as _, choose as v, classMap as y, guard as b, ifDefined as x, join as S, key as C, live as w, map as T, preventDefault as E, range as D, repeat as O, resolveField as k, setField as A, styleMap as j, when as M } from "./directives.js";
5
+ import { TemplateResult as N, UnsafeHTMLResult as P, component as F, escapeHtml as I, html as L, hydrate as R, isTemplateResult as z, isUnsafeHTML as B, nothing as V, render as H, renderToString as U, svg as W, unsafeHTML as G } from "./cossack-html.js";
6
+ import { createContext as K } from "./context.js";
7
+ export { c as BindResult, t as CSSResult, l as CacheResult, i as CossackElement, u as GuardResult, d as IfDefinedResult, f as KeyResult, p as LiveResult, m as PreventDefaultResult, h as RepeatResult, N as TemplateResult, P as UnsafeHTMLResult, g as bind, _ as cache, v as choose, y as classMap, F as component, K as createContext, n as css, I as escapeHtml, b as guard, L as html, R as hydrate, x as ifDefined, a as instanceStack, e as isComponentResult, z as isTemplateResult, B as isUnsafeHTML, S as join, C as key, w as live, T as map, V as nothing, o as popCurrentInstance, E as preventDefault, s as pushCurrentInstance, D as range, H as render, U as renderToString, O as repeat, k as resolveField, A as setField, j as styleMap, W as svg, r as unsafeCSS, G as unsafeHTML, M as when };
@@ -0,0 +1,36 @@
1
+ //#region src/minify-html.ts
2
+ var e = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, t = RegExp(`<(${[.../* @__PURE__ */ new Set([
3
+ "area",
4
+ "base",
5
+ "br",
6
+ "col",
7
+ "embed",
8
+ "hr",
9
+ "img",
10
+ "input",
11
+ "link",
12
+ "meta",
13
+ "param",
14
+ "source",
15
+ "track",
16
+ "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
+ function i(t) {
19
+ let r = [];
20
+ return {
21
+ html: t.replace(e, (e) => {
22
+ let t = e.replace(n, "");
23
+ return r.push(t), `\x00PRESERVE_${r.length - 1}\x00`;
24
+ }),
25
+ blocks: r
26
+ };
27
+ }
28
+ function a(e, t) {
29
+ return e.replace(/\x00PRESERVE_(\d+)\x00/g, (e, n) => t[parseInt(n, 10)]);
30
+ }
31
+ function o(e) {
32
+ 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
+ }
35
+ //#endregion
36
+ export { o as minifyHtml };
package/dist/server.js CHANGED
@@ -1,37 +1,4 @@
1
- import { G as e, U as t, W as n, a as r, d as i, f as a, i as o, l as s, t as c } from "./cossack-html-CnATUTdE.js";
2
- //#region src/minify-html.ts
3
- var l = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, u = RegExp(`<(${[.../* @__PURE__ */ new Set([
4
- "area",
5
- "base",
6
- "br",
7
- "col",
8
- "embed",
9
- "hr",
10
- "img",
11
- "input",
12
- "link",
13
- "meta",
14
- "param",
15
- "source",
16
- "track",
17
- "wbr"
18
- ])].join("|")})(\\s[^>]*)?\\/\\s*>`, "gi"), d = /\s+type\s*=\s*["']text\/(javascript|css)["']/gi, f = /(\w[\w-]*)\s*=\s*["']([a-zA-Z0-9_.-]+)["'](?=\s|\/?>)/g;
19
- function p(e) {
20
- let t = [];
21
- return {
22
- html: e.replace(l, (e) => {
23
- let n = e.replace(d, "");
24
- return t.push(n), `\x00PRESERVE_${t.length - 1}\x00`;
25
- }),
26
- blocks: t
27
- };
28
- }
29
- function m(e, t) {
30
- return e.replace(/\x00PRESERVE_(\d+)\x00/g, (e, n) => t[parseInt(n, 10)]);
31
- }
32
- function h(e) {
33
- let { html: t, blocks: n } = p(e), r = t.replace(/<!--(?!\[if\s|\/?CRP|CSA-[SE])[\s\S]*?-->/g, "");
34
- return r = r.replace(d, ""), r = r.replace(/\s+/g, " "), r = r.replace(/>\s+</g, "><"), r = r.replace(f, (e, t, n) => `${t}=${n}`), r = r.replace(u, (e, t, n) => `<${t}${n ? n.trimEnd() : ""}>`), r = m(r, n), r = r.replace(/>\s+</g, "><"), r = r.trim(), r;
35
- }
36
- //#endregion
37
- export { t as CSSResult, c as TemplateResult, n as css, o as escapeHtml, r as html, h as minifyHtml, s as nothing, i as renderToString, a as svg, e as unsafeCSS };
1
+ import { CSSResult as e, css as t, unsafeCSS as n } from "./css.js";
2
+ import { TemplateResult as r, escapeHtml as i, html as a, nothing as o, renderToString as s, svg as c } from "./cossack-html.js";
3
+ import { minifyHtml as l } from "./minify-html.js";
4
+ export { e as CSSResult, r as TemplateResult, t as css, i as escapeHtml, a as html, l as minifyHtml, o as nothing, s as renderToString, c as svg, n as unsafeCSS };
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@cossackframework/renderer",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "type": "module",
5
+ "sideEffects": false,
5
6
  "description": "The rendering engine for Cossack Framework. Lit inspired, light dom, ssr",
6
7
  "license": "MIT",
7
8
  "repository": {