@telperion/elements 5.4.2 → 6.0.0

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.
Files changed (57) hide show
  1. package/.build-manifest.json +12 -1
  2. package/README.md +37 -0
  3. package/custom-elements.json +5272 -0
  4. package/fesm/elements.mjs +477 -2
  5. package/fesm/elements.mjs.map +1 -1
  6. package/iife/elements.js +24 -24
  7. package/iife/elements.js.map +1 -1
  8. package/iife/portal/index.js +2 -0
  9. package/iife/portal/index.js.map +1 -0
  10. package/iife/router/index.js +16 -16
  11. package/iife/router/index.js.map +1 -1
  12. package/iife/select/index.js.map +1 -1
  13. package/index.cjs +4 -0
  14. package/index.cjs.map +1 -1
  15. package/index.d.cts +1 -0
  16. package/index.d.ts +1 -0
  17. package/index.js +2 -0
  18. package/index.js.map +1 -1
  19. package/package.json +42 -17
  20. package/portal/dom-ops.cjs +81 -0
  21. package/portal/dom-ops.cjs.map +1 -0
  22. package/portal/dom-ops.js +72 -0
  23. package/portal/dom-ops.js.map +1 -0
  24. package/portal/index.cjs +10 -0
  25. package/portal/index.cjs.map +1 -0
  26. package/portal/index.d.cts +125 -0
  27. package/portal/index.d.ts +125 -0
  28. package/portal/index.js +3 -0
  29. package/portal/index.js.map +1 -0
  30. package/portal/internal-props.cjs +13 -0
  31. package/portal/internal-props.cjs.map +1 -0
  32. package/portal/internal-props.js +9 -0
  33. package/portal/internal-props.js.map +1 -0
  34. package/portal/portal-element.cjs +196 -0
  35. package/portal/portal-element.cjs.map +1 -0
  36. package/portal/portal-element.js +194 -0
  37. package/portal/portal-element.js.map +1 -0
  38. package/portal/portal-outlet-element.cjs +64 -0
  39. package/portal/portal-outlet-element.cjs.map +1 -0
  40. package/portal/portal-outlet-element.js +62 -0
  41. package/portal/portal-outlet-element.js.map +1 -0
  42. package/portal/portal-registry.cjs +61 -0
  43. package/portal/portal-registry.cjs.map +1 -0
  44. package/portal/portal-registry.js +59 -0
  45. package/portal/portal-registry.js.map +1 -0
  46. package/portal/projection.cjs +81 -0
  47. package/portal/projection.cjs.map +1 -0
  48. package/portal/projection.js +79 -0
  49. package/portal/projection.js.map +1 -0
  50. package/portal/styles.cjs +28 -0
  51. package/portal/styles.cjs.map +1 -0
  52. package/portal/styles.js +26 -0
  53. package/portal/styles.js.map +1 -0
  54. package/router/history-managed.cjs +3 -1
  55. package/router/history-managed.cjs.map +1 -1
  56. package/router/history-managed.js +3 -1
  57. package/router/history-managed.js.map +1 -1
@@ -0,0 +1,125 @@
1
+ /** Registry → portal: re-resolve the active outlet and (re)project into it. */
2
+ declare const SYNC_PORTAL: unique symbol;
3
+ /** Portal → outlet: a portal started projecting into the outlet. */
4
+ declare const ATTACH_PORTAL: unique symbol;
5
+ /** Portal → outlet: a portal stopped projecting into the outlet. */
6
+ declare const DETACH_PORTAL: unique symbol;
7
+
8
+ declare global {
9
+ interface HTMLElementTagNameMap {
10
+ /**
11
+ * Render target for `<tp-portal>` elements with the same `name`.
12
+ *
13
+ * Content of every matching portal is appended after the outlet's own
14
+ * children, in the order the portals connected. When several outlets share
15
+ * a name, the most recently connected one is active; if it disconnects,
16
+ * the previous one takes over and the content moves there.
17
+ *
18
+ * The outlet is `display: contents` by default, so projected content lays
19
+ * out as if it were a child of the outlet's parent.
20
+ *
21
+ * @example
22
+ * ```html
23
+ * <tp-portal-outlet name="toolbar"></tp-portal-outlet>
24
+ * ```
25
+ *
26
+ * @attr name - Name that `<tp-portal>` elements target.
27
+ * @attr active - Reflected (read-only) while at least one portal projects here.
28
+ */
29
+ "tp-portal-outlet": PortalOutletElement;
30
+ }
31
+ }
32
+ declare class PortalOutletElement extends HTMLElement {
33
+ #private;
34
+ static readonly observedAttributes: string[];
35
+ /** Name that `<tp-portal>` elements target. */
36
+ get name(): string;
37
+ set name(value: string);
38
+ /** Portals currently projecting into this outlet, in projection order. */
39
+ get portals(): readonly PortalElement[];
40
+ connectedCallback(): void;
41
+ disconnectedCallback(): void;
42
+ attributeChangedCallback(): void;
43
+ /** @internal */
44
+ [ATTACH_PORTAL](portal: PortalElement): void;
45
+ /** @internal */
46
+ [DETACH_PORTAL](portal: PortalElement): void;
47
+ }
48
+
49
+ declare global {
50
+ interface HTMLElementTagNameMap {
51
+ /**
52
+ * Renders its children inside the `<tp-portal-outlet>` with the same
53
+ * `name`, wherever that outlet is in the document.
54
+ *
55
+ * The child **nodes themselves** are moved (not cloned), so event
56
+ * listeners, element state and framework bindings stay intact. While no
57
+ * matching outlet is connected the children stay inside the portal, which
58
+ * is `display: none` by default.
59
+ *
60
+ * Framework-safe: frameworks (React, Angular, Vue, Lit, …) keep calling
61
+ * `appendChild` / `insertBefore` / `removeChild` / `replaceChild` /
62
+ * `textContent` / `innerHTML` on the portal; while projected, those calls
63
+ * are forwarded to the outlet, so no "node is not a child of this node"
64
+ * errors are thrown.
65
+ *
66
+ * Uses the state-preserving `moveBefore()` when the browser supports it
67
+ * (focus, iframes, CSS animations survive projection).
68
+ *
69
+ * @example
70
+ * ```html
71
+ * <tp-portal name="toolbar">
72
+ * <button>Save</button>
73
+ * </tp-portal>
74
+ *
75
+ * <header>
76
+ * <tp-portal-outlet name="toolbar"></tp-portal-outlet>
77
+ * </header>
78
+ * ```
79
+ *
80
+ * @attr name - Outlet name to project into.
81
+ * @attr projected - Reflected (read-only) while the content is in an outlet.
82
+ */
83
+ "tp-portal": PortalElement;
84
+ }
85
+ }
86
+ declare class PortalElement extends HTMLElement {
87
+ #private;
88
+ static readonly observedAttributes: string[];
89
+ /** Outlet name to project into. */
90
+ get name(): string;
91
+ set name(value: string);
92
+ /** The outlet currently hosting this portal's content, if any. */
93
+ get outlet(): PortalOutletElement | null;
94
+ /** The portal's content nodes, wherever they currently live. */
95
+ get projectedNodes(): Node[];
96
+ connectedCallback(): void;
97
+ disconnectedCallback(): void;
98
+ attributeChangedCallback(): void;
99
+ /** @internal */
100
+ [SYNC_PORTAL](): void;
101
+ /** @internal Forwarded to the outlet while projected. */
102
+ appendChild<T extends Node>(node: T): T;
103
+ /** @internal Forwarded to the outlet while projected. */
104
+ insertBefore<T extends Node>(node: T, ref: Node | null): T;
105
+ /** @internal Forwarded to the outlet while projected. */
106
+ removeChild<T extends Node>(child: T): T;
107
+ /** @internal Forwarded to the outlet while projected. */
108
+ replaceChild<T extends Node>(next: Node, prev: T): T;
109
+ /** @internal Forwarded to the outlet while projected. */
110
+ append(...nodes: Array<Node | string>): void;
111
+ /** @internal Forwarded to the outlet while projected. */
112
+ prepend(...nodes: Array<Node | string>): void;
113
+ /** @internal Forwarded to the outlet while projected. */
114
+ replaceChildren(...nodes: Array<Node | string>): void;
115
+ /** @internal Forwarded to the outlet while projected. */
116
+ get textContent(): string;
117
+ /** @internal */
118
+ set textContent(value: string | null);
119
+ /** @internal Forwarded to the outlet while projected. */
120
+ get innerHTML(): string;
121
+ /** @internal */
122
+ set innerHTML(value: string);
123
+ }
124
+
125
+ export { PortalElement, PortalOutletElement };
@@ -0,0 +1,3 @@
1
+ export { PortalElement } from './portal-element.js';
2
+ export { PortalOutletElement } from './portal-outlet-element.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ /** Registry → portal: re-resolve the active outlet and (re)project into it. */
4
+ const SYNC_PORTAL = Symbol("portal:sync");
5
+ /** Portal → outlet: a portal started projecting into the outlet. */
6
+ const ATTACH_PORTAL = Symbol("portal-outlet:attach");
7
+ /** Portal → outlet: a portal stopped projecting into the outlet. */
8
+ const DETACH_PORTAL = Symbol("portal-outlet:detach");
9
+
10
+ exports.ATTACH_PORTAL = ATTACH_PORTAL;
11
+ exports.DETACH_PORTAL = DETACH_PORTAL;
12
+ exports.SYNC_PORTAL = SYNC_PORTAL;
13
+ //# sourceMappingURL=internal-props.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-props.cjs","sources":["../../../../libs/elements/src/portal/internal-props.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;MACa,WAAW,GAAG,MAAM,CAAC,aAAa;AAC/C;MACa,aAAa,GAAG,MAAM,CAAC,sBAAsB;AAC1D;MACa,aAAa,GAAG,MAAM,CAAC,sBAAsB;;;;;;"}
@@ -0,0 +1,9 @@
1
+ /** Registry → portal: re-resolve the active outlet and (re)project into it. */
2
+ const SYNC_PORTAL = Symbol("portal:sync");
3
+ /** Portal → outlet: a portal started projecting into the outlet. */
4
+ const ATTACH_PORTAL = Symbol("portal-outlet:attach");
5
+ /** Portal → outlet: a portal stopped projecting into the outlet. */
6
+ const DETACH_PORTAL = Symbol("portal-outlet:detach");
7
+
8
+ export { ATTACH_PORTAL, DETACH_PORTAL, SYNC_PORTAL };
9
+ //# sourceMappingURL=internal-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-props.js","sources":["../../../../libs/elements/src/portal/internal-props.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;MACa,WAAW,GAAG,MAAM,CAAC,aAAa;AAC/C;MACa,aAAa,GAAG,MAAM,CAAC,sBAAsB;AAC1D;MACa,aAAa,GAAG,MAAM,CAAC,sBAAsB;;;;"}
@@ -0,0 +1,196 @@
1
+ 'use strict';
2
+
3
+ var domOps = require('./dom-ops.cjs');
4
+ var internalProps = require('./internal-props.cjs');
5
+ var portalRegistry = require('./portal-registry.cjs');
6
+ var projection = require('./projection.cjs');
7
+ var styles = require('./styles.cjs');
8
+
9
+ class PortalElement extends HTMLElement {
10
+ static { this.observedAttributes = ["name"]; }
11
+ #projection = new projection.Projection();
12
+ #observer = new MutationObserver(() => this.#projection.pull(this));
13
+ #outlet = null;
14
+ #registeredName = null;
15
+ /** Outlet name to project into. */
16
+ get name() {
17
+ return this.getAttribute("name") ?? "";
18
+ }
19
+ set name(value) {
20
+ this.setAttribute("name", value);
21
+ }
22
+ /** The outlet currently hosting this portal's content, if any. */
23
+ get outlet() {
24
+ return this.#outlet;
25
+ }
26
+ /** The portal's content nodes, wherever they currently live. */
27
+ get projectedNodes() {
28
+ return this.#projection.active ? this.#projection.nodes() : Array.from(this.childNodes);
29
+ }
30
+ connectedCallback() {
31
+ styles.injectPortalStyles();
32
+ // Catches children added behind our back (HTML parser, insertAdjacent*, …).
33
+ this.#observer.observe(this, { childList: true });
34
+ this.#register();
35
+ }
36
+ disconnectedCallback() {
37
+ this.#unregister();
38
+ this.#observer.disconnect();
39
+ }
40
+ attributeChangedCallback() {
41
+ if (!this.isConnected)
42
+ return;
43
+ this.#unregister();
44
+ this.#register();
45
+ }
46
+ /** @internal */
47
+ [internalProps.SYNC_PORTAL]() {
48
+ const next = this.#registeredName === null ? null : portalRegistry.portalRegistry.outletFor(this.#registeredName);
49
+ if (next === this.#outlet)
50
+ return;
51
+ this.#detach();
52
+ // Never project into an outlet nested in our own content (cycle).
53
+ if (next && !this.contains(next))
54
+ this.#attach(next);
55
+ }
56
+ // -- Registration ---------------------------------------------------------
57
+ #register() {
58
+ const name = this.name;
59
+ if (!name)
60
+ return;
61
+ this.#registeredName = name;
62
+ portalRegistry.portalRegistry.addPortal(name, this);
63
+ }
64
+ /** Unregisters and brings the content home (so it leaves the document with us). */
65
+ #unregister() {
66
+ if (this.#registeredName !== null) {
67
+ portalRegistry.portalRegistry.removePortal(this.#registeredName, this);
68
+ this.#registeredName = null;
69
+ }
70
+ this.#detach();
71
+ }
72
+ #attach(outlet) {
73
+ this.#outlet = outlet;
74
+ this.#projection.open(outlet, this);
75
+ outlet[internalProps.ATTACH_PORTAL](this);
76
+ this.toggleAttribute("projected", true);
77
+ }
78
+ #detach() {
79
+ const outlet = this.#outlet;
80
+ if (!outlet)
81
+ return;
82
+ this.#outlet = null;
83
+ this.#projection.close(this);
84
+ outlet[internalProps.DETACH_PORTAL](this);
85
+ this.toggleAttribute("projected", false);
86
+ }
87
+ // -- Forwarded DOM mutations ----------------------------------------------
88
+ // Frameworks hold a reference to the portal as the *parent* of the nodes
89
+ // they render. While projected, those nodes live in the outlet, so the
90
+ // native methods would throw; forward them into the projected range.
91
+ /** @internal Forwarded to the outlet while projected. */
92
+ appendChild(node) {
93
+ if (!this.#projection.active)
94
+ return super.appendChild(node);
95
+ this.#projection.insert(node, null);
96
+ return node;
97
+ }
98
+ /** @internal Forwarded to the outlet while projected. */
99
+ insertBefore(node, ref) {
100
+ if (!this.#projection.active || !this.#projection.owns(ref))
101
+ return super.insertBefore(node, ref);
102
+ this.#projection.insert(node, ref);
103
+ return node;
104
+ }
105
+ /** @internal Forwarded to the outlet while projected. */
106
+ removeChild(child) {
107
+ if (!this.#projection.active || !this.#projection.owns(child))
108
+ return super.removeChild(child);
109
+ this.#projection.remove(child);
110
+ return child;
111
+ }
112
+ /** @internal Forwarded to the outlet while projected. */
113
+ replaceChild(next, prev) {
114
+ if (!this.#projection.active || !this.#projection.owns(prev))
115
+ return super.replaceChild(next, prev);
116
+ this.#projection.replace(next, prev);
117
+ return prev;
118
+ }
119
+ // State-preserving `moveBefore()`, forwarded while projected. Only installed
120
+ // where the browser has it natively, so feature detection stays truthful.
121
+ static {
122
+ if (domOps.hasNativeMoveBefore()) {
123
+ Object.defineProperty(this.prototype, "moveBefore", {
124
+ configurable: true,
125
+ writable: true,
126
+ value(node, ref) {
127
+ const projected = this.#projection.active && this.#projection.owns(ref);
128
+ const parent = projected ? this.#projection.container : this;
129
+ domOps.nativeMove(parent, node, projected ? this.#projection.refFor(ref) : ref);
130
+ },
131
+ });
132
+ }
133
+ }
134
+ /** @internal Forwarded to the outlet while projected. */
135
+ append(...nodes) {
136
+ if (!this.#projection.active)
137
+ return super.append(...nodes);
138
+ for (const node of toNodes(nodes))
139
+ this.#projection.insert(node, null);
140
+ }
141
+ /** @internal Forwarded to the outlet while projected. */
142
+ prepend(...nodes) {
143
+ if (!this.#projection.active)
144
+ return super.prepend(...nodes);
145
+ for (const node of toNodes(nodes).reverse())
146
+ this.#projection.prepend(node);
147
+ }
148
+ /** @internal Forwarded to the outlet while projected. */
149
+ replaceChildren(...nodes) {
150
+ if (!this.#projection.active)
151
+ return super.replaceChildren(...nodes);
152
+ this.#projection.clear();
153
+ this.append(...nodes);
154
+ }
155
+ /** @internal Forwarded to the outlet while projected. */
156
+ get textContent() {
157
+ if (!this.#projection.active)
158
+ return super.textContent;
159
+ return this.#projection
160
+ .nodes()
161
+ .map((n) => (n.nodeType === Node.COMMENT_NODE ? "" : (n.textContent ?? "")))
162
+ .join("");
163
+ }
164
+ /** @internal */
165
+ set textContent(value) {
166
+ if (!this.#projection.active) {
167
+ super.textContent = value;
168
+ return;
169
+ }
170
+ this.#projection.clear();
171
+ if (value)
172
+ this.#projection.insert(document.createTextNode(value), null);
173
+ }
174
+ /** @internal Forwarded to the outlet while projected. */
175
+ get innerHTML() {
176
+ return this.#projection.active ? domOps.serializeNodes(this.#projection.nodes()) : super.innerHTML;
177
+ }
178
+ /** @internal */
179
+ set innerHTML(value) {
180
+ if (!this.#projection.active) {
181
+ super.innerHTML = value;
182
+ return;
183
+ }
184
+ this.#projection.clear();
185
+ super.innerHTML = value;
186
+ this.#projection.pull(this);
187
+ }
188
+ }
189
+ function toNodes(nodes) {
190
+ return nodes.map((n) => (typeof n === "string" ? document.createTextNode(n) : n));
191
+ }
192
+ if (!customElements.get("tp-portal"))
193
+ customElements.define("tp-portal", PortalElement);
194
+
195
+ exports.PortalElement = PortalElement;
196
+ //# sourceMappingURL=portal-element.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-element.cjs","sources":["../../../../libs/elements/src/portal/portal-element.ts"],"sourcesContent":[null],"names":["Projection","injectPortalStyles","SYNC_PORTAL","portalRegistry","ATTACH_PORTAL","DETACH_PORTAL","hasNativeMoveBefore","nativeMove","serializeNodes"],"mappings":";;;;;;;;AA6CM,MAAO,aAAc,SAAQ,WAAW,CAAA;AAC5B,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,WAAW,GAAG,IAAIA,qBAAU,EAAE;AAC9B,IA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IAC7B;;AAGF,SAAS,OAAO,CAAC,KAA2B,EAAA;AAC1C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnF;AAEA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;;;;"}
@@ -0,0 +1,194 @@
1
+ import { hasNativeMoveBefore, nativeMove, serializeNodes } from './dom-ops.js';
2
+ import { SYNC_PORTAL, ATTACH_PORTAL, DETACH_PORTAL } from './internal-props.js';
3
+ import { portalRegistry } from './portal-registry.js';
4
+ import { Projection } from './projection.js';
5
+ import { injectPortalStyles } from './styles.js';
6
+
7
+ class PortalElement extends HTMLElement {
8
+ static { this.observedAttributes = ["name"]; }
9
+ #projection = new Projection();
10
+ #observer = new MutationObserver(() => this.#projection.pull(this));
11
+ #outlet = null;
12
+ #registeredName = null;
13
+ /** Outlet name to project into. */
14
+ get name() {
15
+ return this.getAttribute("name") ?? "";
16
+ }
17
+ set name(value) {
18
+ this.setAttribute("name", value);
19
+ }
20
+ /** The outlet currently hosting this portal's content, if any. */
21
+ get outlet() {
22
+ return this.#outlet;
23
+ }
24
+ /** The portal's content nodes, wherever they currently live. */
25
+ get projectedNodes() {
26
+ return this.#projection.active ? this.#projection.nodes() : Array.from(this.childNodes);
27
+ }
28
+ connectedCallback() {
29
+ injectPortalStyles();
30
+ // Catches children added behind our back (HTML parser, insertAdjacent*, …).
31
+ this.#observer.observe(this, { childList: true });
32
+ this.#register();
33
+ }
34
+ disconnectedCallback() {
35
+ this.#unregister();
36
+ this.#observer.disconnect();
37
+ }
38
+ attributeChangedCallback() {
39
+ if (!this.isConnected)
40
+ return;
41
+ this.#unregister();
42
+ this.#register();
43
+ }
44
+ /** @internal */
45
+ [SYNC_PORTAL]() {
46
+ const next = this.#registeredName === null ? null : portalRegistry.outletFor(this.#registeredName);
47
+ if (next === this.#outlet)
48
+ return;
49
+ this.#detach();
50
+ // Never project into an outlet nested in our own content (cycle).
51
+ if (next && !this.contains(next))
52
+ this.#attach(next);
53
+ }
54
+ // -- Registration ---------------------------------------------------------
55
+ #register() {
56
+ const name = this.name;
57
+ if (!name)
58
+ return;
59
+ this.#registeredName = name;
60
+ portalRegistry.addPortal(name, this);
61
+ }
62
+ /** Unregisters and brings the content home (so it leaves the document with us). */
63
+ #unregister() {
64
+ if (this.#registeredName !== null) {
65
+ portalRegistry.removePortal(this.#registeredName, this);
66
+ this.#registeredName = null;
67
+ }
68
+ this.#detach();
69
+ }
70
+ #attach(outlet) {
71
+ this.#outlet = outlet;
72
+ this.#projection.open(outlet, this);
73
+ outlet[ATTACH_PORTAL](this);
74
+ this.toggleAttribute("projected", true);
75
+ }
76
+ #detach() {
77
+ const outlet = this.#outlet;
78
+ if (!outlet)
79
+ return;
80
+ this.#outlet = null;
81
+ this.#projection.close(this);
82
+ outlet[DETACH_PORTAL](this);
83
+ this.toggleAttribute("projected", false);
84
+ }
85
+ // -- Forwarded DOM mutations ----------------------------------------------
86
+ // Frameworks hold a reference to the portal as the *parent* of the nodes
87
+ // they render. While projected, those nodes live in the outlet, so the
88
+ // native methods would throw; forward them into the projected range.
89
+ /** @internal Forwarded to the outlet while projected. */
90
+ appendChild(node) {
91
+ if (!this.#projection.active)
92
+ return super.appendChild(node);
93
+ this.#projection.insert(node, null);
94
+ return node;
95
+ }
96
+ /** @internal Forwarded to the outlet while projected. */
97
+ insertBefore(node, ref) {
98
+ if (!this.#projection.active || !this.#projection.owns(ref))
99
+ return super.insertBefore(node, ref);
100
+ this.#projection.insert(node, ref);
101
+ return node;
102
+ }
103
+ /** @internal Forwarded to the outlet while projected. */
104
+ removeChild(child) {
105
+ if (!this.#projection.active || !this.#projection.owns(child))
106
+ return super.removeChild(child);
107
+ this.#projection.remove(child);
108
+ return child;
109
+ }
110
+ /** @internal Forwarded to the outlet while projected. */
111
+ replaceChild(next, prev) {
112
+ if (!this.#projection.active || !this.#projection.owns(prev))
113
+ return super.replaceChild(next, prev);
114
+ this.#projection.replace(next, prev);
115
+ return prev;
116
+ }
117
+ // State-preserving `moveBefore()`, forwarded while projected. Only installed
118
+ // where the browser has it natively, so feature detection stays truthful.
119
+ static {
120
+ if (hasNativeMoveBefore()) {
121
+ Object.defineProperty(this.prototype, "moveBefore", {
122
+ configurable: true,
123
+ writable: true,
124
+ value(node, ref) {
125
+ const projected = this.#projection.active && this.#projection.owns(ref);
126
+ const parent = projected ? this.#projection.container : this;
127
+ nativeMove(parent, node, projected ? this.#projection.refFor(ref) : ref);
128
+ },
129
+ });
130
+ }
131
+ }
132
+ /** @internal Forwarded to the outlet while projected. */
133
+ append(...nodes) {
134
+ if (!this.#projection.active)
135
+ return super.append(...nodes);
136
+ for (const node of toNodes(nodes))
137
+ this.#projection.insert(node, null);
138
+ }
139
+ /** @internal Forwarded to the outlet while projected. */
140
+ prepend(...nodes) {
141
+ if (!this.#projection.active)
142
+ return super.prepend(...nodes);
143
+ for (const node of toNodes(nodes).reverse())
144
+ this.#projection.prepend(node);
145
+ }
146
+ /** @internal Forwarded to the outlet while projected. */
147
+ replaceChildren(...nodes) {
148
+ if (!this.#projection.active)
149
+ return super.replaceChildren(...nodes);
150
+ this.#projection.clear();
151
+ this.append(...nodes);
152
+ }
153
+ /** @internal Forwarded to the outlet while projected. */
154
+ get textContent() {
155
+ if (!this.#projection.active)
156
+ return super.textContent;
157
+ return this.#projection
158
+ .nodes()
159
+ .map((n) => (n.nodeType === Node.COMMENT_NODE ? "" : (n.textContent ?? "")))
160
+ .join("");
161
+ }
162
+ /** @internal */
163
+ set textContent(value) {
164
+ if (!this.#projection.active) {
165
+ super.textContent = value;
166
+ return;
167
+ }
168
+ this.#projection.clear();
169
+ if (value)
170
+ this.#projection.insert(document.createTextNode(value), null);
171
+ }
172
+ /** @internal Forwarded to the outlet while projected. */
173
+ get innerHTML() {
174
+ return this.#projection.active ? serializeNodes(this.#projection.nodes()) : super.innerHTML;
175
+ }
176
+ /** @internal */
177
+ set innerHTML(value) {
178
+ if (!this.#projection.active) {
179
+ super.innerHTML = value;
180
+ return;
181
+ }
182
+ this.#projection.clear();
183
+ super.innerHTML = value;
184
+ this.#projection.pull(this);
185
+ }
186
+ }
187
+ function toNodes(nodes) {
188
+ return nodes.map((n) => (typeof n === "string" ? document.createTextNode(n) : n));
189
+ }
190
+ if (!customElements.get("tp-portal"))
191
+ customElements.define("tp-portal", PortalElement);
192
+
193
+ export { PortalElement };
194
+ //# sourceMappingURL=portal-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-element.js","sources":["../../../../libs/elements/src/portal/portal-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AA6CM,MAAO,aAAc,SAAQ,WAAW,CAAA;AAC5B,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,WAAW,GAAG,IAAI,UAAU,EAAE;AAC9B,IAAA,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,GAA+B,IAAI;IAC1C,eAAe,GAAkB,IAAI;;AAGrC,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE;IACxC;IAEA,IAAI,IAAI,CAAC,KAAa,EAAA;AACpB,QAAA,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAClC;;AAGA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;;AAGA,IAAA,IAAI,cAAc,GAAA;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,IA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AAK;YACzB;QACF;AACA,QAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,QAAA,IAAI,KAAK;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;IAC1E;;AAGA,IAAA,IAAa,SAAS,GAAA;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS;IAC7F;;IAGA,IAAa,SAAS,CAAC,KAAa,EAAA;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;AAC5B,YAAA,KAAK,CAAC,SAAS,GAAG,KAAK;YACvB;QACF;AACA,QAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,QAAA,KAAK,CAAC,SAAS,GAAG,KAAK;AACvB,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7B;;AAGF,SAAS,OAAO,CAAC,KAA2B,EAAA;AAC1C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnF;AAEA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;;;;"}
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ var internalProps = require('./internal-props.cjs');
4
+ var portalRegistry = require('./portal-registry.cjs');
5
+ var styles = require('./styles.cjs');
6
+
7
+ class PortalOutletElement extends HTMLElement {
8
+ static { this.observedAttributes = ["name"]; }
9
+ #portals = new Set();
10
+ #registeredName = null;
11
+ /** Name that `<tp-portal>` elements target. */
12
+ get name() {
13
+ return this.getAttribute("name") ?? "";
14
+ }
15
+ set name(value) {
16
+ this.setAttribute("name", value);
17
+ }
18
+ /** Portals currently projecting into this outlet, in projection order. */
19
+ get portals() {
20
+ return [...this.#portals];
21
+ }
22
+ connectedCallback() {
23
+ styles.injectPortalStyles();
24
+ this.#register();
25
+ }
26
+ disconnectedCallback() {
27
+ this.#unregister();
28
+ }
29
+ attributeChangedCallback() {
30
+ if (!this.isConnected)
31
+ return;
32
+ this.#unregister();
33
+ this.#register();
34
+ }
35
+ /** @internal */
36
+ [internalProps.ATTACH_PORTAL](portal) {
37
+ this.#portals.add(portal);
38
+ this.toggleAttribute("active", true);
39
+ }
40
+ /** @internal */
41
+ [internalProps.DETACH_PORTAL](portal) {
42
+ this.#portals.delete(portal);
43
+ this.toggleAttribute("active", this.#portals.size > 0);
44
+ }
45
+ #register() {
46
+ const name = this.name;
47
+ if (!name)
48
+ return;
49
+ this.#registeredName = name;
50
+ portalRegistry.portalRegistry.addOutlet(name, this);
51
+ }
52
+ #unregister() {
53
+ if (this.#registeredName === null)
54
+ return;
55
+ const name = this.#registeredName;
56
+ this.#registeredName = null;
57
+ portalRegistry.portalRegistry.removeOutlet(name, this);
58
+ }
59
+ }
60
+ if (!customElements.get("tp-portal-outlet"))
61
+ customElements.define("tp-portal-outlet", PortalOutletElement);
62
+
63
+ exports.PortalOutletElement = PortalOutletElement;
64
+ //# sourceMappingURL=portal-outlet-element.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-outlet-element.cjs","sources":["../../../../libs/elements/src/portal/portal-outlet-element.ts"],"sourcesContent":[null],"names":["injectPortalStyles","ATTACH_PORTAL","DETACH_PORTAL","portalRegistry"],"mappings":";;;;;;AA8BM,MAAO,mBAAoB,SAAQ,WAAW,CAAA;AAClC,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,QAAQ,GAAG,IAAI,GAAG,EAAiB;IAC5C,eAA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