@openelement/ui 1.0.0-alpha.14 → 1.0.0-alpha.16

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 (43) hide show
  1. package/CUSTOMIZATION.md +106 -112
  2. package/README.md +19 -39
  3. package/custom-elements.json +369 -0
  4. package/package.json +3 -2
  5. package/src/button-machine.js +54 -0
  6. package/src/component-config.js +7 -0
  7. package/src/component-recipes.js +2 -24
  8. package/src/copy-feedback.js +32 -0
  9. package/src/dialog-machine.js +104 -0
  10. package/src/dropdown-machine.js +253 -0
  11. package/src/generated-manifest.json +135 -87
  12. package/src/index.d.ts +7 -8
  13. package/src/index.js +7 -8
  14. package/src/input-machine.js +33 -0
  15. package/src/open-button.css +119 -108
  16. package/src/open-button.d.ts +34 -342
  17. package/src/open-button.generated.js +592 -0
  18. package/src/open-button.js +115 -1140
  19. package/src/open-code-block.css +24 -44
  20. package/src/open-code-block.d.ts +15 -175
  21. package/src/open-code-block.generated.js +293 -0
  22. package/src/open-code-block.js +112 -224
  23. package/src/open-dialog.css +114 -127
  24. package/src/open-dialog.d.ts +22 -261
  25. package/src/open-dialog.generated.js +501 -0
  26. package/src/open-dialog.js +137 -632
  27. package/src/open-dropdown.css +26 -26
  28. package/src/open-dropdown.d.ts +15 -218
  29. package/src/open-dropdown.generated.js +211 -0
  30. package/src/open-dropdown.js +74 -355
  31. package/src/open-input.css +69 -74
  32. package/src/open-input.d.ts +34 -461
  33. package/src/open-input.generated.js +685 -0
  34. package/src/open-input.js +161 -1802
  35. package/src/open-theme-toggle.css +37 -47
  36. package/src/open-theme-toggle.d.ts +19 -190
  37. package/src/open-theme-toggle.generated.js +564 -0
  38. package/src/open-theme-toggle.js +209 -509
  39. package/src/theme-contract.js +40 -0
  40. package/src/theme.css +26 -8
  41. package/src/control-recipe.css +0 -21
  42. package/src/register.d.ts +0 -4
  43. package/src/register.js +0 -22
@@ -1,230 +1,118 @@
1
- import { CODE_BLOCK_CONSTANTS, log } from "./component-recipes.js";
2
- import { OpenElement } from "@openelement/element";
3
- import openCodeBlockStyles from "./open-code-block.css";
1
+ import { defineComponentConfig } from "./component-config.js";
2
+ import { log } from "./component-recipes.js";
3
+ import { cancelCopyReset, scheduleCopyReset } from "./copy-feedback.js";
4
+ import { jsx, jsxs } from "@openelement/element/jsx-runtime";
5
+ import { onConnect, onDispose, onPropertyChange } from "@openelement/element/lifecycle";
6
+ import { computed, signal } from "@openelement/element";
4
7
  //#region src/open-code-block.tsx
5
- const __partProgram = {
6
- "version": 1,
7
- "tag": "open-code-block",
8
- "root": {
9
- "id": "root",
10
- "kind": "shadow-open",
11
- "nodes": ["e0"]
12
- },
13
- "template": [{
14
- "k": "el",
15
- "id": "e0",
16
- "tag": "div",
17
- "attrs": [["style", "display:contents"]],
18
- "children": [{
19
- "k": "el",
20
- "id": "e1",
21
- "tag": "slot",
22
- "attrs": [],
23
- "children": []
24
- }, {
25
- "k": "el",
26
- "id": "e2",
27
- "tag": "button",
28
- "attrs": [
29
- ["type", "button"],
30
- ["class", "copy-btn"],
31
- ["part", "copy"]
32
- ],
33
- "children": [{
34
- "k": "part",
35
- "id": "p1",
36
- "index": 1
37
- }]
38
- }]
39
- }],
40
- "parts": [{
41
- "k": "event",
42
- "event": "click",
43
- "handler": "copy",
44
- "action": {
45
- "kind": "method",
46
- "name": "copy"
47
- },
48
- "path": [0, 1],
49
- "index": 0,
50
- "location": {
51
- "id": "p0",
52
- "kind": "sink",
53
- "path": [0, 1],
54
- "node": "e2"
8
+ /**
9
+ * @openelement/ui - open-code-block
10
+ *
11
+ * Code block with a copy button.
12
+ *
13
+ * Contract (shrunk in #1552): the component owns the copy interaction only —
14
+ * it does NOT bundle, load, or invoke a tokenizer. Syntax highlighting is the
15
+ * host page's build-time concern: fences are compiled to token-span HTML by
16
+ * the site's markdown pipeline (e.g., Shiki) and project through the slot
17
+ * untouched. The projected content stays light DOM, so the host's stylesheet
18
+ * owns the code surface and token inks; this component only paints its chip.
19
+ *
20
+ * Generated authoring: the shell (slot + copy button) is the compiled
21
+ * template; the copy label is a compiled text sink driven by the `copyLabel`
22
+ * property, and the copy feedback's custom state (`:state(copied)` /
23
+ * `:state(failed)`) is driven from the property-change channel.
24
+ *
25
+ * @csspart copy - The copy button
26
+ *
27
+ * Usage:
28
+ * ```html
29
+ * <open-code-block>
30
+ * <pre><code>const x = 1;</code></pre>
31
+ * </open-code-block>
32
+ * ```
33
+ */
34
+ /**
35
+ * Platform facts for the generated element: shadow root, the authored
36
+ * component stylesheet, and the `copyLabel` property (property-only, no
37
+ * attribute form).
38
+ */
39
+ const openElement = /* @__PURE__ */ defineComponentConfig({
40
+ root: "shadow",
41
+ styles: ["./open-code-block.css"],
42
+ properties: { copyLabel: {
43
+ default: "Copy",
44
+ attribute: false
45
+ } }
46
+ });
47
+ /** Code block with a copy button. */
48
+ function OpenCodeBlock(props) {
49
+ const chinese = signal(false);
50
+ const translatedLabel = computed(() => !chinese.value ? props.copyLabel : props.copyLabel === "Copy" ? "复制" : props.copyLabel === "Copied!" ? "已复制" : props.copyLabel === "Failed" ? "复制失败" : props.copyLabel);
51
+ onConnect((env) => {
52
+ globalThis.queueMicrotask(() => {
53
+ if (env.signal.aborted) return;
54
+ const language = env.host.closest("[lang]")?.getAttribute("lang") ?? env.host.ownerDocument.documentElement.lang;
55
+ chinese.value = /^zh(?:-|$)/i.test(language);
56
+ });
57
+ });
58
+ /**
59
+ * Copy the slotted light DOM: token spans (if the host highlighted at build
60
+ * time) concatenate to the exact source text. The clipboard promise chain
61
+ * writes the declared `copyLabel`; the change channel below owns state and
62
+ * timer bookkeeping, so the click path never touches internals.
63
+ */
64
+ const copy = (host) => {
65
+ const text = host.textContent || "";
66
+ try {
67
+ globalThis.navigator.clipboard.writeText(text).then(() => {
68
+ host.copyLabel = "Copied!";
69
+ }, (error) => {
70
+ log.warn("Clipboard write failed:", error);
71
+ host.copyLabel = "Failed";
72
+ });
73
+ } catch (error) {
74
+ log.warn("Clipboard write failed:", error);
75
+ host.copyLabel = "Failed";
55
76
  }
56
- }, {
57
- "k": "text",
58
- "signal": "copyLabel",
59
- "index": 1,
60
- "location": {
61
- "id": "p1",
62
- "kind": "anchor",
63
- "path": [
64
- 0,
65
- 1,
66
- 0
67
- ]
77
+ };
78
+ onPropertyChange((env) => {
79
+ if (env.name !== "copyLabel") return;
80
+ if (env.value === "Copied!") {
81
+ env.states.add("copied");
82
+ env.states.delete("failed");
83
+ scheduleCopyReset(env.host);
84
+ return;
68
85
  }
69
- }],
70
- "regions": [],
71
- "dependencies": [{
72
- "signal": "copyLabel",
73
- "owner": {
74
- "kind": "part",
75
- "index": 1
76
- },
77
- "location": "p1"
78
- }],
79
- "locations": [
80
- {
81
- "id": "e0",
82
- "kind": "element",
83
- "tag": "div",
84
- "path": [0]
85
- },
86
- {
87
- "id": "e1",
88
- "kind": "element",
89
- "tag": "slot",
90
- "path": [0, 0]
91
- },
92
- {
93
- "id": "e2",
94
- "kind": "element",
95
- "tag": "button",
96
- "path": [0, 1]
97
- },
98
- {
99
- "id": "p0",
100
- "kind": "sink",
101
- "part": 0,
102
- "node": "e2",
103
- "path": [0, 1]
104
- },
105
- {
106
- "id": "p1",
107
- "kind": "anchor",
108
- "part": 1,
109
- "path": [
110
- 0,
111
- 1,
112
- 0
113
- ]
86
+ if (env.value === "Failed") {
87
+ env.states.add("failed");
88
+ env.states.delete("copied");
89
+ scheduleCopyReset(env.host);
90
+ return;
114
91
  }
115
- ],
116
- "metadata": {
117
- "tag": "open-code-block",
118
- "className": "OpenCodeBlock",
119
- "sourceFile": "open-code-block.tsx",
120
- "properties": [{
121
- "name": "copyLabel",
122
- "attribute": null,
123
- "type": "string",
124
- "converter": "string",
125
- "reflect": false,
126
- "default": "Copy"
127
- }],
128
- "observedAttributes": [],
129
- "cem": {
130
- "tagName": "open-code-block",
131
- "className": "OpenCodeBlock",
132
- "declaration": {
133
- "name": "OpenCodeBlock",
134
- "module": "open-code-block.tsx"
92
+ env.states.delete("copied");
93
+ env.states.delete("failed");
94
+ cancelCopyReset(env.host);
95
+ });
96
+ onDispose((env) => {
97
+ cancelCopyReset(env.host);
98
+ });
99
+ return /* @__PURE__ */ jsxs("div", {
100
+ style: "display:contents",
101
+ children: [/* @__PURE__ */ jsx("slot", {}), /* @__PURE__ */ jsx("button", {
102
+ type: "button",
103
+ class: "copy-btn absolute top-2 right-2 z-10 cursor-pointer rounded-md border-[0.5px] border-transparent bg-primary/14 px-3 py-1 font-sans text-xs font-semibold tracking-wider text-foreground transition-all duration-150 ease-in-out hover:border-primary hover:bg-primary/23",
104
+ part: "copy",
105
+ onClick: (event) => {
106
+ const target = event.currentTarget;
107
+ copy(target.getRootNode().host);
135
108
  },
136
- "attributes": [],
137
- "members": [{
138
- "name": "copyLabel",
139
- "fieldName": "copyLabel",
140
- "type": "string",
141
- "attribute": null,
142
- "reflect": false
143
- }]
144
- }
145
- }
146
- };
147
- const __compiledProperties = [{
148
- "name": "copyLabel",
149
- "attribute": null,
150
- "type": "string",
151
- "converter": "string",
152
- "reflect": false,
153
- "default": "Copy"
154
- }];
155
- const __elementMetadata = {
156
- "tag": "open-code-block",
157
- "className": "OpenCodeBlock",
158
- "sourceFile": "open-code-block.tsx",
159
- "properties": [{
160
- "name": "copyLabel",
161
- "attribute": null,
162
- "type": "string",
163
- "converter": "string",
164
- "reflect": false,
165
- "default": "Copy"
166
- }],
167
- "observedAttributes": [],
168
- "cem": {
169
- "tagName": "open-code-block",
170
- "className": "OpenCodeBlock",
171
- "declaration": {
172
- "name": "OpenCodeBlock",
173
- "module": "open-code-block.tsx"
174
- },
175
- "attributes": [],
176
- "members": [{
177
- "name": "copyLabel",
178
- "fieldName": "copyLabel",
179
- "type": "string",
180
- "attribute": null,
181
- "reflect": false
182
- }]
183
- }
184
- };
185
- const __observedAttributes = [];
186
- const __compiledProps = { copyLabel: {
187
- type: String,
188
- default: "Copy",
189
- reflect: false,
190
- attribute: false
191
- } };
192
- var OpenCodeBlock = class extends OpenElement {
193
- static __partProgram = __partProgram;
194
- static __compiledProperties = __compiledProperties;
195
- static __elementMetadata = __elementMetadata;
196
- static props = __compiledProps;
197
- static observedAttributes = __observedAttributes;
198
- static styles = [openCodeBlockStyles];
199
- copyLabel = "Copy";
200
- getCodeText() {
201
- return this.textContent || "";
202
- }
203
- async copy() {
204
- try {
205
- const text = this.getCodeText();
206
- await navigator.clipboard.writeText(text);
207
- this.copyLabel = "Copied!";
208
- this._internals?.states.add("copied");
209
- this._internals?.states.delete("failed");
210
- this._setTimeout(() => {
211
- this.copyLabel = "Copy";
212
- this._internals?.states.delete("copied");
213
- }, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
214
- } catch (e) {
215
- log.warn("Clipboard write failed:", e);
216
- this.copyLabel = "Failed";
217
- this._internals?.states.add("failed");
218
- this._internals?.states.delete("copied");
219
- this._setTimeout(() => {
220
- this.copyLabel = "Copy";
221
- this._internals?.states.delete("failed");
222
- }, CODE_BLOCK_CONSTANTS.copyFeedbackMs);
223
- }
224
- }
225
- render() {
226
- throw new Error("[open:compiled-element] open-code-block is compiled to a Part Program; the runtime JSX render path is not available.");
227
- }
228
- };
109
+ children: translatedLabel.value
110
+ })]
111
+ });
112
+ }
229
113
  //#endregion
230
- export { OpenCodeBlock, __elementMetadata, __partProgram };
114
+ export { OpenCodeBlock as default, openElement };
115
+
116
+ export { OpenCodeBlockElement, OpenCodeBlock__ssrHost } from './open-code-block.generated.js';
117
+
118
+ // openElement:class-candidates ["absolute","bg-primary/14","border-[0.5px]","border-transparent","copy-btn","cursor-pointer","duration-150","ease-in-out","font-sans","font-semibold","hover:bg-primary/23","hover:border-primary","px-3","py-1","right-2","rounded-md","text-foreground","text-xs","top-2","tracking-wider","transition-all","z-10"]
@@ -1,137 +1,124 @@
1
- /* open-dialog — authored component styles, ported verbatim from the pre-#1558
2
- * recipe() sheet (the alpha.9 design system). The #1558 migration had
3
- * replaced this with a placeholder shell under the false note that the
4
- * component "carried no authored styles"; it did — this is that sheet. */
5
- :host {
6
- display: inline-block;
7
- }
1
+ /* open-dialog — the irreducible authored rules (alpha15 S lane).
2
+ *
3
+ * The dialog box (padding, radius, width bound, font) and the header / title /
4
+ * close / body / footer presentation are authored as Tailwind utilities in
5
+ * open-dialog.tsx: the compiler admits those static tokens and the build's
6
+ * component stylesheet carries the generated rules into this shadow root.
7
+ *
8
+ * What stays here, and why (CUSTOMIZATION.md → "Why the residue is CSS"): the
9
+ * residue is either a structural limit of the platform or one owned rule that
10
+ * reads better than its utility spelling.
11
+ * - the host box;
12
+ * - the trigger slot's cursor (`::slotted`);
13
+ * - the dialog's DERIVED surface: the foreground/border/primary triple mix of
14
+ * its frame, the popover mix of its background, the inset highlight plus
15
+ * the `--shadow-2xl` scale value, and the close button's primary-mixed hover
16
+ * background — each one formula over role pairs rather than a repeated
17
+ * escaped arbitrary value;
18
+ * - the NATIVE top-layer presentation: `::backdrop` and its scrim, and the
19
+ * entry/exit transitions. The transition configuration IS expressible
20
+ * (`starting:opacity-0` compiles into `@starting-style`,
21
+ * `transition-discrete` into `transition-behavior: allow-discrete`); the
22
+ * sheet keeps it because the whole top-layer choreography — backdrop,
23
+ * scrim, starting style, discrete behavior and its forced-colors /
24
+ * reduced-motion degradations — reads as one owned block;
25
+ * - the forced-colors and reduced-motion degradations of those transitions;
26
+ * - `:host(:state(open))`, the host's attached state.
27
+ * One owner per property: nothing here is also authored as a utility.
28
+ */
29
+ :host {
30
+ display: inline-block;
31
+ }
8
32
 
9
- ::slotted([slot='trigger']) {
10
- cursor: pointer;
11
- }
33
+ ::slotted([slot='trigger']) {
34
+ cursor: pointer;
35
+ }
12
36
 
13
- dialog {
14
- border: calc(var(--spacing) * 0.25) solid color-mix(in srgb, color-mix(in srgb, var(--color-foreground) 25%, var(--color-border)) 62%, var(--color-primary));
15
- border-radius: var(--radius-xl);
16
- background: color-mix(in srgb, var(--color-popover) 92%, transparent);
17
- color: var(--color-foreground);
18
- padding: calc(var(--spacing) * 6);
19
- max-width: min(90vw, 480px);
20
- box-shadow: inset 0 1px 0 color-mix(in srgb, var(--color-white) 8%, transparent), var(--shadow-2xl);
21
- font-family: var(--font-sans);
22
- }
37
+ dialog {
38
+ border: calc(var(--spacing) * 0.25) solid
39
+ color-mix(
40
+ in srgb,
41
+ color-mix(in srgb, var(--color-foreground) 25%, var(--color-border)) 62%,
42
+ var(--color-primary)
43
+ );
44
+ background: color-mix(in srgb, var(--color-popover) 92%, transparent);
45
+ color: var(--color-foreground);
46
+ box-shadow:
47
+ inset 0 1px 0 color-mix(in srgb, var(--color-white) 8%, transparent),
48
+ var(--shadow-2xl);
49
+ }
23
50
 
24
- dialog::backdrop {
25
- /* Closed base: transparent. The [open] rule carries the zinc-950 scrim
26
- and starts from transparent, so the scrim fades in on entry and back
27
- out on exit instead of snapping. */
28
- background: transparent;
29
- backdrop-filter: blur(8px);
30
- /* Exit visibility: with allow-discrete the top-layer membership and the
31
- display flip wait for the transition, so the scrim fades out instead
32
- of snapping (the allow-discrete recipe, cf. upstream #591 — open
33
- upstream, does not gate this landing). */
34
- transition:
35
- background-color 0.2s ease-out,
36
- overlay 0.2s ease-out allow-discrete,
37
- display 0.2s ease-out allow-discrete;
38
- }
51
+ dialog::backdrop {
52
+ /* Closed base: transparent. The [open] rule carries the zinc-950 scrim
53
+ and starts from transparent, so the scrim fades in on entry and back
54
+ out on exit instead of snapping. */
55
+ background: transparent;
56
+ backdrop-filter: blur(8px);
57
+ /* Exit visibility: with allow-discrete the top-layer membership and the
58
+ display flip wait for the transition, so the scrim fades out instead
59
+ of snapping (the allow-discrete recipe, cf. upstream #591 — open
60
+ upstream, does not gate this landing). */
61
+ transition:
62
+ background-color 0.2s ease-out,
63
+ overlay 0.2s ease-out allow-discrete,
64
+ display 0.2s ease-out allow-discrete;
65
+ }
39
66
 
40
- dialog[open]::backdrop {
41
- background: color-mix(in srgb, var(--color-zinc-950) 68%, transparent);
42
- @starting-style {
43
- background: transparent;
44
- }
45
- }
67
+ dialog[open]::backdrop {
68
+ background: color-mix(in srgb, var(--color-zinc-950) 68%, transparent);
69
+ @starting-style {
70
+ background: transparent;
71
+ }
72
+ }
46
73
 
47
- /* Entry AND exit: the closed state is the base rule (opacity 0, lifted);
48
- opening transitions to the [open] values from the @starting-style
49
- starting point, closing transitions back to the base — the display and
50
- overlay legs carry allow-discrete so the dialog stays rendered and in
51
- the top layer until the exit transition finishes. */
52
- dialog {
53
- opacity: 0;
54
- transform: translateY(-8px);
55
- transition:
56
- opacity 0.2s ease-out,
57
- transform 0.2s ease-out,
58
- overlay 0.2s ease-out allow-discrete,
59
- display 0.2s ease-out allow-discrete;
60
- }
74
+ /* Entry AND exit: the closed state is the base rule (opacity 0, lifted);
75
+ opening transitions to the [open] values from the @starting-style
76
+ starting point, closing transitions back to the base — the display and
77
+ overlay legs carry allow-discrete so the dialog stays rendered and in
78
+ the top layer until the exit transition finishes. */
79
+ dialog {
80
+ opacity: 0;
81
+ transform: translateY(-8px);
82
+ transition:
83
+ opacity 0.2s ease-out,
84
+ transform 0.2s ease-out,
85
+ overlay 0.2s ease-out allow-discrete,
86
+ display 0.2s ease-out allow-discrete;
87
+ }
61
88
 
62
- dialog[open] {
63
- opacity: 1;
64
- transform: translateY(0);
65
- @starting-style {
66
- opacity: 0;
67
- transform: translateY(-8px);
68
- }
69
- }
89
+ dialog[open] {
90
+ opacity: 1;
91
+ transform: translateY(0);
92
+ @starting-style {
93
+ opacity: 0;
94
+ transform: translateY(-8px);
95
+ }
96
+ }
70
97
 
71
- /* Forced colors: the system owns the palette, so half-opacity frames and
72
- moving text would fight the forced rendering — the dialog appears and
73
- dismisses immediately instead (the display leg loses its deferral with
74
- the transition, which is the graceful degradation). Reduced motion
75
- collapses the same way. */
76
- @media (forced-colors: active) {
77
- dialog,
78
- dialog::backdrop {
79
- transition: none;
80
- }
81
- }
98
+ /* Forced colors: the system owns the palette, so half-opacity frames and
99
+ moving text would fight the forced rendering — the dialog appears and
100
+ dismisses immediately instead (the display leg loses its deferral with
101
+ the transition, which is the graceful degradation). Reduced motion
102
+ collapses the same way. */
103
+ @media (forced-colors: active) {
104
+ dialog,
105
+ dialog::backdrop {
106
+ transition: none;
107
+ }
108
+ }
82
109
 
83
- @media (prefers-reduced-motion: reduce) {
84
- dialog,
85
- dialog::backdrop {
86
- transition-duration: 0s;
87
- }
88
- }
110
+ @media (prefers-reduced-motion: reduce) {
111
+ dialog,
112
+ dialog::backdrop {
113
+ transition-duration: 0s;
114
+ }
115
+ }
89
116
 
90
- .dialog-header {
91
- display: flex;
92
- justify-content: space-between;
93
- align-items: center;
94
- margin-bottom: calc(var(--spacing) * 4);
95
- }
117
+ .dialog-close:hover {
118
+ color: var(--color-foreground);
119
+ background: color-mix(in srgb, var(--color-primary) 14%, transparent);
120
+ }
96
121
 
97
- .dialog-title {
98
- font-size: var(--text-xl);
99
- font-weight: var(--font-weight-semibold);
100
- color: var(--color-foreground);
101
- margin: 0;
102
- }
103
-
104
- .dialog-close {
105
- background: none;
106
- border: none;
107
- cursor: pointer;
108
- color: var(--color-muted-foreground);
109
- font-size: var(--text-xl);
110
- line-height: var(--leading-tight);
111
- padding: calc(var(--spacing) * 1);
112
- border-radius: var(--radius-md);
113
- transition: color 0.15s ease;
114
- }
115
-
116
- .dialog-close:hover {
117
- color: var(--color-foreground);
118
- background: color-mix(in srgb, var(--color-primary) 14%, transparent);
119
- }
120
-
121
- .dialog-body {
122
- font-size: var(--text-base);
123
- color: var(--color-muted-foreground);
124
- line-height: var(--leading-normal);
125
- }
126
-
127
- .dialog-footer {
128
- margin-top: calc(var(--spacing) * 5);
129
- display: flex;
130
- justify-content: flex-end;
131
- gap: calc(var(--spacing) * 2);
132
- }
133
-
134
- :host(:state(open)) dialog {
135
- display: block;
136
- }
137
-
122
+ :host(:state(open)) dialog {
123
+ display: block;
124
+ }