@jasonshimmy/custom-elements-runtime 1.1.2 → 1.2.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.
@@ -1,11 +1,12 @@
1
1
  import type { VNode } from "./runtime/types";
2
2
  export declare function when(cond: boolean, children: VNode | VNode[]): VNode;
3
+ export declare function when(cond: boolean, factory: () => VNode | VNode[]): VNode;
3
4
  export declare function each<T extends string | number | boolean | {
4
5
  id?: string | number;
5
6
  key?: string;
6
7
  }>(list: T[], render: (item: T, index: number) => VNode | VNode[]): VNode[];
7
8
  export declare function match(): {
8
- when(cond: any, content: VNode | VNode[]): /*elided*/ any;
9
+ when(cond: any, content: VNode | VNode[] | (() => VNode | VNode[])): /*elided*/ any;
9
10
  otherwise(content: VNode | VNode[]): /*elided*/ any;
10
11
  done(): VNode[];
11
12
  };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { useEmit, useOnConnected, useOnDisconnected, useOnAttributeChanged, useO
9
9
  export { ref, computed, watch } from "./runtime/reactive";
10
10
  export { html } from "./runtime/template-compiler";
11
11
  export { css } from "./runtime/style";
12
+ export { unsafeHTML, decodeEntities } from "./runtime/helpers";
12
13
  export { renderToString } from "./runtime/vdom";
13
14
  export type { VNode } from "./runtime/types";
14
15
  export * from "./directives";
@@ -23,6 +23,54 @@ export declare function getStringCacheStats(): {
23
23
  htmlEscapeCacheSize: number;
24
24
  };
25
25
  export declare function escapeHTML(str: string | number | boolean): string | number | boolean;
26
+ /**
27
+ * Decode HTML entities (named and numeric) into their character equivalents.
28
+ * - In browser: uses a DOM-based technique to decode entities while preserving
29
+ * existing raw tags.
30
+ * - In non-DOM (SSR) environments: handles numeric references and a conservative
31
+ * named-entity map for common entities.
32
+ *
33
+ * @param str - string containing HTML entities
34
+ * @returns decoded string
35
+ */
36
+ export declare function decodeEntities(str: string): string;
37
+ /**
38
+ * Dynamically load the full named-entity map (used in SSR). Exported for testing and
39
+ * to allow bundlers to exclude the JSON from client bundles when dynamic import
40
+ * is used behind a DOM check.
41
+ */
42
+ export declare function loadEntityMap(): Promise<Record<string, string>>;
43
+ /**
44
+ * Register a full named-entity map for SSR. Intended for server startup code to
45
+ * provide the authoritative HTML5 entity mapping. This keeps the client bundle
46
+ * small because the map is only injected on the server side.
47
+ *
48
+ * registerEntityMap should be called once at server startup prior to rendering.
49
+ */
50
+ export declare function registerEntityMap(map: Record<string, string>, options?: {
51
+ overwrite?: boolean;
52
+ }): void;
53
+ /**
54
+ * Clear any registered entity map. Useful for tests or restarting state.
55
+ */
56
+ export declare function clearRegisteredEntityMap(): void;
57
+ /**
58
+ * Wrap a string as raw HTML. This is intentionally unsafe — callers must
59
+ * sanitize untrusted input before using this. The returned object provides
60
+ * two property names to be compatible with different parts of the runtime.
61
+ */
62
+ export declare function unsafeHTML(html: string): {
63
+ __unsafeHTML: string;
64
+ __rawHTML: string;
65
+ };
66
+ /** Type-guard for unsafeHTML wrapper */
67
+ export declare function isUnsafeHTML(value: unknown): value is {
68
+ __unsafeHTML?: string;
69
+ __rawHTML?: string;
70
+ };
71
+ /**
72
+ * Get nested property value from object using dot notation
73
+ */
26
74
  export declare function getNestedValue(obj: any, path: string): any;
27
75
  /**
28
76
  * Set nested property value in object using dot notation
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Retrieve the stored node key for a Node.
3
+ *
4
+ * The lookup prefers a WeakMap-stored value. For compatibility it will also
5
+ * attempt to read legacy fallbacks: a `.key` property or the
6
+ * `data-anchor-key` attribute on Elements.
7
+ *
8
+ * @internal
9
+ */
10
+ export declare function getNodeKey(node: Node | null | undefined): string | undefined;
11
+ /**
12
+ * Store a node key on a Node.
13
+ *
14
+ * This sets a WeakMap entry and also writes defensive DOM fallbacks for
15
+ * compatibility with older consumers/tests. Errors are swallowed to avoid
16
+ * disrupting host environments that forbid property writes.
17
+ *
18
+ * @internal
19
+ */
20
+ export declare function setNodeKey(node: Node, key: string): void;
21
+ /**
22
+ * Retrieve transition-group metadata attached to an element.
23
+ *
24
+ * Prefers the WeakMap but falls back to a legacy `._transitionGroup` property
25
+ * if present.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function getElementTransition(el: HTMLElement | null | undefined): any;
30
+ /**
31
+ * Store transition-group metadata for an element.
32
+ *
33
+ * Writes to the WeakMap and a defensive legacy property for compatibility.
34
+ * Errors are swallowed to avoid breaking host environments.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare function setElementTransition(el: HTMLElement, val: any): void;
39
+ declare const _default: {
40
+ getNodeKey: typeof getNodeKey;
41
+ setNodeKey: typeof setNodeKey;
42
+ getElementTransition: typeof getElementTransition;
43
+ setElementTransition: typeof setElementTransition;
44
+ };
45
+ export default _default;
package/entities.json ADDED
@@ -0,0 +1,211 @@
1
+ {
2
+ "lt": "<",
3
+ "gt": ">",
4
+ "amp": "&",
5
+ "quot": "\"",
6
+ "apos": "'",
7
+ "nbsp": "\u00A0",
8
+
9
+ "iexcl": "¡",
10
+ "cent": "¢",
11
+ "pound": "£",
12
+ "curren": "¤",
13
+ "yen": "¥",
14
+ "brvbar": "¦",
15
+ "sect": "§",
16
+ "uml": "¨",
17
+ "copy": "©",
18
+ "ordf": "ª",
19
+ "laquo": "«",
20
+ "not": "¬",
21
+ "shy": "\u00AD",
22
+ "reg": "®",
23
+ "macr": "¯",
24
+ "deg": "°",
25
+ "plusmn": "±",
26
+ "sup2": "²",
27
+ "sup3": "³",
28
+ "acute": "´",
29
+ "micro": "µ",
30
+ "para": "¶",
31
+ "middot": "·",
32
+ "cedil": "¸",
33
+ "sup1": "¹",
34
+ "ordm": "º",
35
+ "raquo": "»",
36
+ "frac14": "¼",
37
+ "frac12": "½",
38
+ "frac34": "¾",
39
+ "iquest": "¿",
40
+
41
+ "Agrave": "À",
42
+ "Aacute": "Á",
43
+ "Acirc": "Â",
44
+ "Atilde": "Ã",
45
+ "Auml": "Ä",
46
+ "Aring": "Å",
47
+ "AElig": "Æ",
48
+ "Ccedil": "Ç",
49
+ "Egrave": "È",
50
+ "Eacute": "É",
51
+ "Ecirc": "Ê",
52
+ "Euml": "Ë",
53
+ "Igrave": "Ì",
54
+ "Iacute": "Í",
55
+ "Icirc": "Î",
56
+ "Iuml": "Ï",
57
+ "ETH": "Ð",
58
+ "Ntilde": "Ñ",
59
+ "Ograve": "Ò",
60
+ "Oacute": "Ó",
61
+ "Ocirc": "Ô",
62
+ "Otilde": "Õ",
63
+ "Ouml": "Ö",
64
+ "times": "×",
65
+ "Oslash": "Ø",
66
+ "Ugrave": "Ù",
67
+ "Uacute": "Ú",
68
+ "Ucirc": "Û",
69
+ "Uuml": "Ü",
70
+ "Yacute": "Ý",
71
+ "THORN": "Þ",
72
+ "szlig": "ß",
73
+ "agrave": "à",
74
+ "aacute": "á",
75
+ "acirc": "â",
76
+ "atilde": "ã",
77
+ "auml": "ä",
78
+ "aring": "å",
79
+ "aelig": "æ",
80
+ "ccedil": "ç",
81
+ "egrave": "è",
82
+ "eacute": "é",
83
+ "ecirc": "ê",
84
+ "euml": "ë",
85
+ "igrave": "ì",
86
+ "iacute": "í",
87
+ "icirc": "î",
88
+ "iuml": "ï",
89
+ "eth": "ð",
90
+ "ntilde": "ñ",
91
+ "ograve": "ò",
92
+ "oacute": "ó",
93
+ "ocirc": "ô",
94
+ "otilde": "õ",
95
+ "ouml": "ö",
96
+ "divide": "÷",
97
+ "oslash": "ø",
98
+ "ugrave": "ù",
99
+ "uacute": "ú",
100
+ "ucirc": "û",
101
+ "uuml": "ü",
102
+ "yacute": "ý",
103
+ "thorn": "þ",
104
+ "yuml": "ÿ",
105
+
106
+ "euro": "€",
107
+ "trade": "™",
108
+ "mdash": "—",
109
+ "ndash": "–",
110
+ "hellip": "…",
111
+ "bull": "•",
112
+ "prime": "′",
113
+ "Prime": "″",
114
+ "permil": "‰",
115
+ "dagger": "†",
116
+ "Dagger": "‡",
117
+ "cedilla": "¸",
118
+ "oelig": "œ",
119
+ "scaron": "š",
120
+ "Yuml": "Ÿ",
121
+
122
+ "lsquo": "‘",
123
+ "rsquo": "’",
124
+ "ldquo": "“",
125
+ "rdquo": "”",
126
+
127
+ "sterling": "£",
128
+
129
+ "pi": "π",
130
+ "Pi": "Π",
131
+ "alpha": "α",
132
+ "beta": "β",
133
+ "gamma": "γ",
134
+ "Gamma": "Γ",
135
+ "delta": "δ",
136
+ "Delta": "Δ",
137
+ "epsilon": "ϵ",
138
+ "epsiv": "ε",
139
+ "zeta": "ζ",
140
+ "eta": "η",
141
+ "theta": "θ",
142
+ "Theta": "Θ",
143
+ "iota": "ι",
144
+ "kappa": "κ",
145
+ "lambda": "λ",
146
+ "Lambda": "Λ",
147
+ "mu": "μ",
148
+ "nu": "ν",
149
+ "xi": "ξ",
150
+ "Xi": "Ξ",
151
+ "omicron": "ο",
152
+ "rho": "ρ",
153
+ "sigma": "σ",
154
+ "Sigma": "Σ",
155
+ "tau": "τ",
156
+ "upsilon": "υ",
157
+ "phi": "φ",
158
+ "Phi": "Φ",
159
+ "chi": "χ",
160
+ "psi": "ψ",
161
+ "omega": "ω",
162
+ "Omega": "Ω",
163
+
164
+ "infty": "∞",
165
+ "sub": "⊂",
166
+ "sup": "⊃",
167
+ "nsub": "⊄",
168
+ "sube": "⊆",
169
+ "supe": "⊇",
170
+ "ne": "≠",
171
+ "le": "≤",
172
+ "ge": "≥",
173
+ "approx": "≈",
174
+ "cong": "≅",
175
+ "there4": "∴",
176
+ "forall": "∀",
177
+ "exist": "∃",
178
+ "empty": "∅",
179
+ "nabla": "∇",
180
+ "partial": "∂",
181
+ "sum": "∑",
182
+ "prod": "∏",
183
+ "int": "∫",
184
+ "lowast": "∗",
185
+ "radic": "√",
186
+ "real": "ℜ",
187
+ "image": "ℑ",
188
+ "ang": "∠",
189
+ "oplus": "⊕",
190
+ "otimes": "⊗",
191
+ "perp": "⊥",
192
+
193
+ "larr": "←",
194
+ "rarr": "→",
195
+ "uarr": "↑",
196
+ "darr": "↓",
197
+ "harr": "↔",
198
+ "lArr": "⇐",
199
+ "rArr": "⇒",
200
+ "uArr": "⇑",
201
+ "dArr": "⇓",
202
+ "hArr": "⇔",
203
+ "lceil": "⌈",
204
+ "rceil": "⌉",
205
+ "lfloor": "⌊",
206
+ "rfloor": "⌋",
207
+
208
+ "ampersand": "&",
209
+ "caret": "^",
210
+ "tilde": "~"
211
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jasonshimmy/custom-elements-runtime",
3
3
  "description": "A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "web-components",
@@ -42,7 +42,8 @@
42
42
  "types": "dist/index.d.ts",
43
43
  "files": [
44
44
  "dist",
45
- "dist/index.d.ts"
45
+ "dist/index.d.ts",
46
+ "entities.json"
46
47
  ],
47
48
  "exports": {
48
49
  ".": {
@@ -50,7 +51,8 @@
50
51
  "import": "./dist/custom-elements-runtime.es.js",
51
52
  "require": "./dist/custom-elements-runtime.cjs.js",
52
53
  "default": "./dist/custom-elements-runtime.umd.js"
53
- }
54
+ },
55
+ "./entities.json": "./entities.json"
54
56
  },
55
57
  "publishConfig": {
56
58
  "access": "public"