@kohaku-ui/renderer-wc 0.1.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.
- package/LICENSE +201 -0
- package/README.md +18 -0
- package/dist/dom.d.ts +23 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +132 -0
- package/dist/dom.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/kohaku-surface.d.ts +42 -0
- package/dist/kohaku-surface.d.ts.map +1 -0
- package/dist/kohaku-surface.js +157 -0
- package/dist/kohaku-surface.js.map +1 -0
- package/dist/parts/action-button.d.ts +8 -0
- package/dist/parts/action-button.d.ts.map +1 -0
- package/dist/parts/action-button.js +38 -0
- package/dist/parts/action-button.js.map +1 -0
- package/dist/parts/chart-svg.d.ts +21 -0
- package/dist/parts/chart-svg.d.ts.map +1 -0
- package/dist/parts/chart-svg.js +181 -0
- package/dist/parts/chart-svg.js.map +1 -0
- package/dist/parts/chart.d.ts +9 -0
- package/dist/parts/chart.d.ts.map +1 -0
- package/dist/parts/chart.js +107 -0
- package/dist/parts/chart.js.map +1 -0
- package/dist/parts/control-select.d.ts +9 -0
- package/dist/parts/control-select.d.ts.map +1 -0
- package/dist/parts/control-select.js +56 -0
- package/dist/parts/control-select.js.map +1 -0
- package/dist/parts/form.d.ts +10 -0
- package/dist/parts/form.d.ts.map +1 -0
- package/dist/parts/form.js +346 -0
- package/dist/parts/form.js.map +1 -0
- package/dist/parts/kit.d.ts +25 -0
- package/dist/parts/kit.d.ts.map +1 -0
- package/dist/parts/kit.js +41 -0
- package/dist/parts/kit.js.map +1 -0
- package/dist/parts/layout.d.ts +6 -0
- package/dist/parts/layout.d.ts.map +1 -0
- package/dist/parts/layout.js +29 -0
- package/dist/parts/layout.js.map +1 -0
- package/dist/parts/list.d.ts +8 -0
- package/dist/parts/list.d.ts.map +1 -0
- package/dist/parts/list.js +60 -0
- package/dist/parts/list.js.map +1 -0
- package/dist/parts/loading.d.ts +7 -0
- package/dist/parts/loading.d.ts.map +1 -0
- package/dist/parts/loading.js +37 -0
- package/dist/parts/loading.js.map +1 -0
- package/dist/parts/metric.d.ts +11 -0
- package/dist/parts/metric.d.ts.map +1 -0
- package/dist/parts/metric.js +37 -0
- package/dist/parts/metric.js.map +1 -0
- package/dist/parts/overlay.d.ts +20 -0
- package/dist/parts/overlay.d.ts.map +1 -0
- package/dist/parts/overlay.js +131 -0
- package/dist/parts/overlay.js.map +1 -0
- package/dist/parts/spreadsheet.d.ts +11 -0
- package/dist/parts/spreadsheet.d.ts.map +1 -0
- package/dist/parts/spreadsheet.js +206 -0
- package/dist/parts/spreadsheet.js.map +1 -0
- package/dist/parts/tabs.d.ts +11 -0
- package/dist/parts/tabs.d.ts.map +1 -0
- package/dist/parts/tabs.js +109 -0
- package/dist/parts/tabs.js.map +1 -0
- package/dist/parts/text.d.ts +9 -0
- package/dist/parts/text.d.ts.map +1 -0
- package/dist/parts/text.js +72 -0
- package/dist/parts/text.js.map +1 -0
- package/dist/registry.d.ts +8 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +38 -0
- package/dist/registry.js.map +1 -0
- package/dist/sandbox-mount.d.ts +10 -0
- package/dist/sandbox-mount.d.ts.map +1 -0
- package/dist/sandbox-mount.js +73 -0
- package/dist/sandbox-mount.js.map +1 -0
- package/dist/tree.d.ts +24 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +156 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @kohaku-ui/renderer-wc
|
|
2
|
+
|
|
3
|
+
Web Components renderer for kohaku UI Specs: a single <kohaku-surface> custom element with Shadow DOM.
|
|
4
|
+
|
|
5
|
+
Part of [kohaku](https://github.com/yosuque/kohaku), a reference implementation of the
|
|
6
|
+
[Kohaku Protocol](https://github.com/yosuque/kohaku/blob/main/spec/SPEC.md): UI treated as data
|
|
7
|
+
(a declarative UI Spec), with generation separated from rendering.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kohaku-ui/renderer-wc
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The packages in this scope share a single version and are designed to be installed together.
|
|
14
|
+
|
|
15
|
+
- Documentation: https://github.com/yosuque/kohaku#readme
|
|
16
|
+
- Source: https://github.com/yosuque/kohaku/tree/main/packages/renderer-wc
|
|
17
|
+
|
|
18
|
+
Licensed under the Apache License, Version 2.0.
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A teardown function that does nothing. */
|
|
2
|
+
export declare const noop: () => void;
|
|
3
|
+
/** Combines multiple teardowns into one. */
|
|
4
|
+
export declare function combineTeardowns(teardowns: (() => void)[]): () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Sets a style object onto element.style (equivalent to React's inline-style expansion).
|
|
7
|
+
* Skips null / undefined values (consistent with React not emitting them as empty strings).
|
|
8
|
+
*/
|
|
9
|
+
export declare function setStyle(el: HTMLElement | SVGElement, style: Record<string, string | number | null | undefined>): void;
|
|
10
|
+
/** Creates an HTML element and sets attributes (string/boolean). Attributes whose value is null/undefined/false are omitted. */
|
|
11
|
+
export declare function el(tag: string, attrs?: Record<string, string | number | boolean | null | undefined>, style?: Record<string, string | number | null | undefined>): HTMLElement;
|
|
12
|
+
/** Batch attribute setting. Boolean attributes are added with no value when true (consistent with React's boolean attributes). */
|
|
13
|
+
export declare function setAttrs(node: Element, attrs: Record<string, string | number | boolean | null | undefined>): void;
|
|
14
|
+
/** Creates an SVG element (presentation attributes are given via setAttribute; consistent with React's SVG output). */
|
|
15
|
+
export declare function svgEl(tag: string, attrs?: Record<string, string | number | boolean | null | undefined>, style?: Record<string, string | number | null | undefined>): SVGElement;
|
|
16
|
+
/** Text node. Creates it even for the empty string (preserving Markdown's empty text segments keeps textContent matching). */
|
|
17
|
+
export declare function text(value: string): Text;
|
|
18
|
+
/**
|
|
19
|
+
* Generic placeholder for when a part cannot be rendered (unimplemented type / sandbox not injected / render failure).
|
|
20
|
+
* Same markup as renderer-react's NodeNotice (SpecView.tsx).
|
|
21
|
+
*/
|
|
22
|
+
export declare function nodeNotice(message: string, color: string): HTMLElement;
|
|
23
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAGA,6CAA6C;AAC7C,eAAO,MAAM,IAAI,QAAO,IAAU,CAAC;AAEnC,4CAA4C;AAC5C,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,MAAM,IAAI,CAKtE;AAmED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,EAAE,EAAE,WAAW,GAAG,UAAU,EAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACxD,IAAI,CAKN;AAED,gIAAgI;AAChI,wBAAgB,EAAE,CAChB,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,EACpE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACzD,WAAW,CAKb;AAED,kIAAkI;AAClI,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,GAClE,IAAI,CAKN;AAID,uHAAuH;AACvH,wBAAgB,KAAK,CACnB,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,EACpE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACzD,UAAU,CAKZ;AAED,8HAA8H;AAC9H,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAExC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CActE"}
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Groundwork for the raw-DOM builders. Generating strings equivalent to React's inline-style expansion is
|
|
2
|
+
// the mechanism behind pixel-match. The px-suffixing rules for style values follow React's dangerousStyleValue.
|
|
3
|
+
/** A teardown function that does nothing. */
|
|
4
|
+
export const noop = () => { };
|
|
5
|
+
/** Combines multiple teardowns into one. */
|
|
6
|
+
export function combineTeardowns(teardowns) {
|
|
7
|
+
return () => {
|
|
8
|
+
// Release in reverse order (the inverse of build order). Avoids order dependencies in unsubscribe / detach.
|
|
9
|
+
for (let i = teardowns.length - 1; i >= 0; i--)
|
|
10
|
+
teardowns[i]();
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The set of properties that React's CSSProperty treats as "unitless numbers" and does not suffix with px.
|
|
15
|
+
* Numbers not in this set (and not 0) get px appended; 0 is always "0" (no px).
|
|
16
|
+
* With this mapping, visuallyHiddenStyle's width:1 → "1px", margin:-1 → "-1px", fontWeight:700 → "700", etc.
|
|
17
|
+
* match React's output (a prerequisite for DOM semantic equivalence).
|
|
18
|
+
*/
|
|
19
|
+
const UNITLESS = new Set([
|
|
20
|
+
"animationIterationCount",
|
|
21
|
+
"aspectRatio",
|
|
22
|
+
"borderImageOutset",
|
|
23
|
+
"borderImageSlice",
|
|
24
|
+
"borderImageWidth",
|
|
25
|
+
"boxFlex",
|
|
26
|
+
"boxFlexGroup",
|
|
27
|
+
"boxOrdinalGroup",
|
|
28
|
+
"columnCount",
|
|
29
|
+
"columns",
|
|
30
|
+
"flex",
|
|
31
|
+
"flexGrow",
|
|
32
|
+
"flexPositive",
|
|
33
|
+
"flexShrink",
|
|
34
|
+
"flexNegative",
|
|
35
|
+
"flexOrder",
|
|
36
|
+
"gridArea",
|
|
37
|
+
"gridRow",
|
|
38
|
+
"gridRowEnd",
|
|
39
|
+
"gridRowSpan",
|
|
40
|
+
"gridRowStart",
|
|
41
|
+
"gridColumn",
|
|
42
|
+
"gridColumnEnd",
|
|
43
|
+
"gridColumnSpan",
|
|
44
|
+
"gridColumnStart",
|
|
45
|
+
"fontWeight",
|
|
46
|
+
"lineClamp",
|
|
47
|
+
"lineHeight",
|
|
48
|
+
"opacity",
|
|
49
|
+
"order",
|
|
50
|
+
"orphans",
|
|
51
|
+
"tabSize",
|
|
52
|
+
"widows",
|
|
53
|
+
"zIndex",
|
|
54
|
+
"zoom",
|
|
55
|
+
"fillOpacity",
|
|
56
|
+
"floodOpacity",
|
|
57
|
+
"stopOpacity",
|
|
58
|
+
"strokeDasharray",
|
|
59
|
+
"strokeDashoffset",
|
|
60
|
+
"strokeMiterlimit",
|
|
61
|
+
"strokeOpacity",
|
|
62
|
+
"strokeWidth",
|
|
63
|
+
]);
|
|
64
|
+
/** camelCase → kebab-case (CSS property name). */
|
|
65
|
+
function hyphenate(name) {
|
|
66
|
+
return name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
67
|
+
}
|
|
68
|
+
/** Identical to React's dangerousStyleValue: null/boolean/"" is empty, non-unitless numbers other than 0 get px, 0 is "0". */
|
|
69
|
+
function styleValue(name, value) {
|
|
70
|
+
if (typeof value === "number" && value !== 0 && !UNITLESS.has(name)) {
|
|
71
|
+
return `${value}px`;
|
|
72
|
+
}
|
|
73
|
+
return `${value}`.trim();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets a style object onto element.style (equivalent to React's inline-style expansion).
|
|
77
|
+
* Skips null / undefined values (consistent with React not emitting them as empty strings).
|
|
78
|
+
*/
|
|
79
|
+
export function setStyle(el, style) {
|
|
80
|
+
for (const [name, value] of Object.entries(style)) {
|
|
81
|
+
if (value == null || value === "")
|
|
82
|
+
continue;
|
|
83
|
+
el.style.setProperty(hyphenate(name), styleValue(name, value));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Creates an HTML element and sets attributes (string/boolean). Attributes whose value is null/undefined/false are omitted. */
|
|
87
|
+
export function el(tag, attrs, style) {
|
|
88
|
+
const node = document.createElement(tag);
|
|
89
|
+
if (attrs != null)
|
|
90
|
+
setAttrs(node, attrs);
|
|
91
|
+
if (style != null)
|
|
92
|
+
setStyle(node, style);
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
/** Batch attribute setting. Boolean attributes are added with no value when true (consistent with React's boolean attributes). */
|
|
96
|
+
export function setAttrs(node, attrs) {
|
|
97
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
98
|
+
if (value == null || value === false)
|
|
99
|
+
continue;
|
|
100
|
+
node.setAttribute(name, value === true ? "" : String(value));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
104
|
+
/** Creates an SVG element (presentation attributes are given via setAttribute; consistent with React's SVG output). */
|
|
105
|
+
export function svgEl(tag, attrs, style) {
|
|
106
|
+
const node = document.createElementNS(SVG_NS, tag);
|
|
107
|
+
if (attrs != null)
|
|
108
|
+
setAttrs(node, attrs);
|
|
109
|
+
if (style != null)
|
|
110
|
+
setStyle(node, style);
|
|
111
|
+
return node;
|
|
112
|
+
}
|
|
113
|
+
/** Text node. Creates it even for the empty string (preserving Markdown's empty text segments keeps textContent matching). */
|
|
114
|
+
export function text(value) {
|
|
115
|
+
return document.createTextNode(value);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generic placeholder for when a part cannot be rendered (unimplemented type / sandbox not injected / render failure).
|
|
119
|
+
* Same markup as renderer-react's NodeNotice (SpecView.tsx).
|
|
120
|
+
*/
|
|
121
|
+
export function nodeNotice(message, color) {
|
|
122
|
+
const node = el("div", { role: "note" }, {
|
|
123
|
+
border: `1px dashed ${color}`,
|
|
124
|
+
color,
|
|
125
|
+
borderRadius: 6,
|
|
126
|
+
padding: "8px 12px",
|
|
127
|
+
fontSize: 13,
|
|
128
|
+
});
|
|
129
|
+
node.appendChild(text(message));
|
|
130
|
+
return node;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,gHAAgH;AAEhH,6CAA6C;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAEnC,4CAA4C;AAC5C,MAAM,UAAU,gBAAgB,CAAC,SAAyB;IACxD,OAAO,GAAG,EAAE;QACV,4GAA4G;QAC5G,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAAE,SAAS,C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QAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,IAAI,KAAK,IAAI,IAAI;QAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,8HAA8H;AAC9H,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,KAAa;IACvD,MAAM,IAAI,GAAG,EAAE,CACb,KAAK,EACL,EAAE,IAAI,EAAE,MAAM,EAAE,EAChB;QACE,MAAM,EAAE,cAAc,KAAK,EAAE;QAC7B,KAAK;QACL,YAAY,EAAE,CAAC;QACf,OAAO,EAAE,UAAU;QACnB,QAAQ,EAAE,EAAE;KACb,CACF,CAAC;IACF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DEFAULT_MESSAGES, type RendererMessages } from "@kohaku-ui/renderer-core";
|
|
2
|
+
export { defineKohakuSurface, KOHAKU_EVENT, KohakuSurface } from "./kohaku-surface.js";
|
|
3
|
+
export { createCoreRenderRegistry } from "./registry.js";
|
|
4
|
+
export type { ActionPhase, PartBuilder, RenderRuntime, SurfaceContext, SurfaceEvent, Teardown, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,YAAY,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @kohaku-ui/renderer-wc — the non-React reference renderer (Custom Elements v1 + Shadow DOM).
|
|
2
|
+
// A single <kohaku-surface> builds the entire UI Spec tree into one shadow root. The shared core is renderer-core.
|
|
3
|
+
// Dependency direction: spec-core → {registry, data-binding} → renderer-core → renderer-wc (sandbox is imported directly).
|
|
4
|
+
// UI message type and defaults (the single source of truth is renderer-core). Used to override context.messages.
|
|
5
|
+
export { DEFAULT_MESSAGES } from "@kohaku-ui/renderer-core";
|
|
6
|
+
export { defineKohakuSurface, KOHAKU_EVENT, KohakuSurface } from "./kohaku-surface.js";
|
|
7
|
+
export { createCoreRenderRegistry } from "./registry.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,mHAAmH;AACnH,2HAA2H;AAE3H,iHAAiH;AACjH,OAAO,EAAE,gBAAgB,EAAyB,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RendererMessages } from "@kohaku-ui/renderer-core";
|
|
2
|
+
import { type ThemeTokens, type UISpec } from "@kohaku-ui/spec-core";
|
|
3
|
+
import type { SurfaceContext } from "./types.js";
|
|
4
|
+
/** Name of the forward event dispatched by <kohaku-surface> (detail is a SurfaceEvent). */
|
|
5
|
+
export declare const KOHAKU_EVENT = "kohaku-event";
|
|
6
|
+
/**
|
|
7
|
+
* The single host element <kohaku-surface> (Shadow DOM). It builds the entire UI Spec tree into one shadow root
|
|
8
|
+
* (rather than a Custom Element per part type — a single-element surface). Spec / context are received as properties.
|
|
9
|
+
*
|
|
10
|
+
* Lifecycle:
|
|
11
|
+
* - On every spec swap: store.resetForIntent(intent.hash) → rebuild the tree + reattach the BoundDataController.
|
|
12
|
+
* The same intent.hash retains state (patch / streaming swaps). Streaming is out of scope for v1.
|
|
13
|
+
* - Forward events are a CustomEvent("kohaku-event", { detail }) (bubbles+composed) + the onEvent property.
|
|
14
|
+
* - Themes are inline-expanded by each part via resolveToken (pixel-match). In addition, CSS variables are laid down on :host (the external override point).
|
|
15
|
+
*/
|
|
16
|
+
export declare class KohakuSurface extends HTMLElement {
|
|
17
|
+
#private;
|
|
18
|
+
constructor();
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
disconnectedCallback(): void;
|
|
21
|
+
/** UI Spec. Setting it triggers resetForIntent → rebuild the tree + reattach the controller. */
|
|
22
|
+
get spec(): UISpec | null;
|
|
23
|
+
set spec(next: UISpec | null);
|
|
24
|
+
/**
|
|
25
|
+
* Batch context assignment (binding / theme / messages / onEvent, etc.). It can also be set via individual
|
|
26
|
+
* properties, but passing it all at once means only one rebuild. Setting it before spec is recommended (minimizes rebuilds due to assignment order).
|
|
27
|
+
*/
|
|
28
|
+
get context(): SurfaceContext;
|
|
29
|
+
set context(next: SurfaceContext);
|
|
30
|
+
/** Individual context properties (sugar for partially updating context). */
|
|
31
|
+
set binding(v: SurfaceContext["binding"]);
|
|
32
|
+
set theme(v: ThemeTokens | undefined);
|
|
33
|
+
set locale(v: string | undefined);
|
|
34
|
+
set messages(v: Partial<RendererMessages> | undefined);
|
|
35
|
+
set onEvent(v: SurfaceContext["onEvent"]);
|
|
36
|
+
set onNodeError(v: SurfaceContext["onNodeError"]);
|
|
37
|
+
set onActionResult(v: SurfaceContext["onActionResult"]);
|
|
38
|
+
set sandbox(v: SurfaceContext["sandbox"]);
|
|
39
|
+
}
|
|
40
|
+
/** Registers <kohaku-surface> as a custom element (idempotent). */
|
|
41
|
+
export declare function defineKohakuSurface(tagName?: string): void;
|
|
42
|
+
//# sourceMappingURL=kohaku-surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kohaku-surface.d.ts","sourceRoot":"","sources":["../src/kohaku-surface.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,gBAAgB,EAItB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAIxF,OAAO,KAAK,EAAe,cAAc,EAAY,MAAM,YAAY,CAAC;AAExE,2FAA2F;AAC3F,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAW5C,cASC;IAED,iBAAiB,IAAI,IAAI,CAExB;IAED,oBAAoB,IAAI,IAAI,CAG3B;IAED,gGAAgG;IAChG,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IACD,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAK3B;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,cAAc,CAE5B;IACD,IAAI,OAAO,CAAC,IAAI,EAAE,cAAc,EAG/B;IAED,4EAA4E;IAC5E,IAAI,OAAO,CAAC,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,EAEvC;IACD,IAAI,KAAK,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,EAEnC;IACD,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAE/B;IACD,IAAI,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,SAAS,EAEpD;IACD,IAAI,OAAO,CAAC,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,EAEvC;IACD,IAAI,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,EAE/C;IACD,IAAI,cAAc,CAAC,CAAC,EAAE,cAAc,CAAC,gBAAgB,CAAC,EAErD;IACD,IAAI,OAAO,CAAC,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,EAEvC;CA+DF;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,OAAO,SAAmB,GAAG,IAAI,CAIpE"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createDataInvalidationBus, createSpecStateStore, DEFAULT_LOCALE, DEFAULT_MESSAGES, themeTokensToCssVars, } from "@kohaku-ui/renderer-core";
|
|
2
|
+
import { ROOT_COMPONENT_ID } from "@kohaku-ui/spec-core";
|
|
3
|
+
import { noop } from "./dom.js";
|
|
4
|
+
import { createCoreRenderRegistry } from "./registry.js";
|
|
5
|
+
import { createRuntime, mountTree } from "./tree.js";
|
|
6
|
+
/** Name of the forward event dispatched by <kohaku-surface> (detail is a SurfaceEvent). */
|
|
7
|
+
export const KOHAKU_EVENT = "kohaku-event";
|
|
8
|
+
/**
|
|
9
|
+
* The single host element <kohaku-surface> (Shadow DOM). It builds the entire UI Spec tree into one shadow root
|
|
10
|
+
* (rather than a Custom Element per part type — a single-element surface). Spec / context are received as properties.
|
|
11
|
+
*
|
|
12
|
+
* Lifecycle:
|
|
13
|
+
* - On every spec swap: store.resetForIntent(intent.hash) → rebuild the tree + reattach the BoundDataController.
|
|
14
|
+
* The same intent.hash retains state (patch / streaming swaps). Streaming is out of scope for v1.
|
|
15
|
+
* - Forward events are a CustomEvent("kohaku-event", { detail }) (bubbles+composed) + the onEvent property.
|
|
16
|
+
* - Themes are inline-expanded by each part via resolveToken (pixel-match). In addition, CSS variables are laid down on :host (the external override point).
|
|
17
|
+
*/
|
|
18
|
+
export class KohakuSurface extends HTMLElement {
|
|
19
|
+
#root;
|
|
20
|
+
#spec = null;
|
|
21
|
+
#context = {};
|
|
22
|
+
#registry = createCoreRenderRegistry();
|
|
23
|
+
// The store is retained by intent.hash; the bus stays the same for the surface's lifetime (equivalent to renderer-react's Provider useRef bus).
|
|
24
|
+
#store = null;
|
|
25
|
+
#bus = createDataInvalidationBus();
|
|
26
|
+
#teardown = noop;
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
30
|
+
const style = document.createElement("style");
|
|
31
|
+
// Minimal reset only (appearance is carried by each part's inline style = the pixel-match mechanism).
|
|
32
|
+
style.textContent = ":host{display:block}";
|
|
33
|
+
this.#root = document.createElement("div");
|
|
34
|
+
this.#root.className = "kohaku-root";
|
|
35
|
+
shadow.append(style, this.#root);
|
|
36
|
+
}
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
if (this.#spec != null)
|
|
39
|
+
this.#render();
|
|
40
|
+
}
|
|
41
|
+
disconnectedCallback() {
|
|
42
|
+
this.#teardown();
|
|
43
|
+
this.#teardown = noop;
|
|
44
|
+
}
|
|
45
|
+
/** UI Spec. Setting it triggers resetForIntent → rebuild the tree + reattach the controller. */
|
|
46
|
+
get spec() {
|
|
47
|
+
return this.#spec;
|
|
48
|
+
}
|
|
49
|
+
set spec(next) {
|
|
50
|
+
// No rebuild needed for the same reference (context updates are not missed because each setter runs #render separately).
|
|
51
|
+
if (next === this.#spec)
|
|
52
|
+
return;
|
|
53
|
+
this.#spec = next;
|
|
54
|
+
this.#render();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Batch context assignment (binding / theme / messages / onEvent, etc.). It can also be set via individual
|
|
58
|
+
* properties, but passing it all at once means only one rebuild. Setting it before spec is recommended (minimizes rebuilds due to assignment order).
|
|
59
|
+
*/
|
|
60
|
+
get context() {
|
|
61
|
+
return this.#context;
|
|
62
|
+
}
|
|
63
|
+
set context(next) {
|
|
64
|
+
this.#context = next ?? {};
|
|
65
|
+
if (this.#spec != null)
|
|
66
|
+
this.#render();
|
|
67
|
+
}
|
|
68
|
+
/** Individual context properties (sugar for partially updating context). */
|
|
69
|
+
set binding(v) {
|
|
70
|
+
this.#patchContext({ binding: v });
|
|
71
|
+
}
|
|
72
|
+
set theme(v) {
|
|
73
|
+
this.#patchContext({ theme: v });
|
|
74
|
+
}
|
|
75
|
+
set locale(v) {
|
|
76
|
+
this.#patchContext({ locale: v });
|
|
77
|
+
}
|
|
78
|
+
set messages(v) {
|
|
79
|
+
this.#patchContext({ messages: v });
|
|
80
|
+
}
|
|
81
|
+
set onEvent(v) {
|
|
82
|
+
this.#patchContext({ onEvent: v });
|
|
83
|
+
}
|
|
84
|
+
set onNodeError(v) {
|
|
85
|
+
this.#patchContext({ onNodeError: v });
|
|
86
|
+
}
|
|
87
|
+
set onActionResult(v) {
|
|
88
|
+
this.#patchContext({ onActionResult: v });
|
|
89
|
+
}
|
|
90
|
+
set sandbox(v) {
|
|
91
|
+
this.#patchContext({ sandbox: v });
|
|
92
|
+
}
|
|
93
|
+
#patchContext(patch) {
|
|
94
|
+
// Skip rebuild if there is no effective change after applying the patch (prevents a full rebuild when the same value is re-assigned to a setter).
|
|
95
|
+
// A shallow reference comparison suffices (binding/theme/messages, etc. are updated by swapping object references).
|
|
96
|
+
let changed = false;
|
|
97
|
+
for (const key of Object.keys(patch)) {
|
|
98
|
+
if (this.#context[key] !== patch[key]) {
|
|
99
|
+
changed = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!changed)
|
|
104
|
+
return;
|
|
105
|
+
this.#context = { ...this.#context, ...patch };
|
|
106
|
+
if (this.#spec != null)
|
|
107
|
+
this.#render();
|
|
108
|
+
}
|
|
109
|
+
#render() {
|
|
110
|
+
// Tear down the previous tree (controller detach / unsubscribe / sandbox destroy / anchor removal).
|
|
111
|
+
this.#teardown();
|
|
112
|
+
this.#teardown = noop;
|
|
113
|
+
this.#root.replaceChildren();
|
|
114
|
+
const spec = this.#spec;
|
|
115
|
+
if (spec == null)
|
|
116
|
+
return;
|
|
117
|
+
const theme = this.#context.theme ?? {};
|
|
118
|
+
const messages = { ...DEFAULT_MESSAGES, ...(this.#context.messages ?? {}) };
|
|
119
|
+
const locale = this.#context.locale ?? DEFAULT_LOCALE;
|
|
120
|
+
// Store: retained by intent.hash (same → keep state, different → reinitialize from spec.state). Call before building the tree.
|
|
121
|
+
const initialState = spec.state ?? {};
|
|
122
|
+
if (this.#store == null) {
|
|
123
|
+
this.#store = createSpecStateStore(spec.intent.hash, initialState);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.#store.resetForIntent(spec.intent.hash, initialState);
|
|
127
|
+
}
|
|
128
|
+
// CSS variables on :host (the theme override point from external CSS; the pixel-match itself uses inline tokens).
|
|
129
|
+
for (const [name, value] of Object.entries(themeTokensToCssVars(theme))) {
|
|
130
|
+
this.style.setProperty(name, value);
|
|
131
|
+
}
|
|
132
|
+
const rt = createRuntime({
|
|
133
|
+
spec,
|
|
134
|
+
store: this.#store,
|
|
135
|
+
bus: this.#bus,
|
|
136
|
+
theme,
|
|
137
|
+
locale,
|
|
138
|
+
messages,
|
|
139
|
+
ctx: this.#context,
|
|
140
|
+
registry: this.#registry,
|
|
141
|
+
dispatchForward: (event) => this.#dispatchForward(event),
|
|
142
|
+
});
|
|
143
|
+
this.#teardown = mountTree(rt, this.#root, ROOT_COMPONENT_ID);
|
|
144
|
+
}
|
|
145
|
+
#dispatchForward(event) {
|
|
146
|
+
// composed so it crosses the shadow boundary and reaches the host page. Flows to both paths regardless of whether a sink exists.
|
|
147
|
+
this.dispatchEvent(new CustomEvent(KOHAKU_EVENT, { detail: event, bubbles: true, composed: true }));
|
|
148
|
+
this.#context.onEvent?.(event);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Registers <kohaku-surface> as a custom element (idempotent). */
|
|
152
|
+
export function defineKohakuSurface(tagName = "kohaku-surface") {
|
|
153
|
+
if (customElements.get(tagName) == null) {
|
|
154
|
+
customElements.define(tagName, KohakuSurface);
|
|
155
|
+
}
|
|
156
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AAC;SACzD,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IAChE,CAAC;IAED,gBAAgB,CAAC,KAAmB;QAClC,iIAAiI;QACjI,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACpG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAG,gBAAgB;IAC5D,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;QACxC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PartBuilder } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* action.button — an action button (same as renderer-react's ActionButton). Fires press.
|
|
4
|
+
* If press has emit==="action.invoke" and binding is configured, it runs the write directly and, while running,
|
|
5
|
+
* is disabled + aria-busy. Otherwise it forwards via emit to onEvent (rt.invoke decides).
|
|
6
|
+
*/
|
|
7
|
+
export declare const actionButton: PartBuilder;
|
|
8
|
+
//# sourceMappingURL=action-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-button.d.ts","sourceRoot":"","sources":["../../src/parts/action-button.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,aAAa,CAAC;AAG5D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WA+B1B,CAAC"}
|