@und-ui/richtext 0.0.0-stage → 0.3.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.
@@ -0,0 +1,301 @@
1
+ /* Visual design ported from Astryx (MIT, (c) Meta Platforms, Inc.); see THIRD_PARTY_NOTICES.md */
2
+ import { css } from 'lit';
3
+
4
+ /**
5
+ * Shadow styles for `und-rich-text-editor`: the bordered frame, the toolbar
6
+ * (32px buttons in groups split by hairlines) and the link form. The frame
7
+ * shows the focus ring when the editing area inside it has focus.
8
+ */
9
+ export const editorStyles = css`
10
+ @layer und.components {
11
+ :host {
12
+ display: block;
13
+ color: var(--und-fg-default, #23252c);
14
+ font-size: var(--und-text-body-md-size, 1rem);
15
+ line-height: var(--und-text-body-md-lh, 1.5);
16
+ }
17
+
18
+ :host([hidden]) {
19
+ display: none;
20
+ }
21
+
22
+ .frame {
23
+ --_border: var(--und-border-control, #898c96);
24
+
25
+ display: flex;
26
+ flex-direction: column;
27
+ border: var(--und-border-width, 1px) solid var(--_border);
28
+ border-radius: var(--und-shape-control, 0.375rem);
29
+ background: var(--und-bg-surface, #fff);
30
+ transition: border-color var(--und-motion-hover, 130ms) ease;
31
+ }
32
+
33
+ .frame:hover {
34
+ --_border: var(--und-border-control-hover, #7d808a);
35
+ }
36
+
37
+ .frame:focus-within {
38
+ outline: var(--und-focus-width, 2px) solid var(--und-focus-ring, #4b4dd5);
39
+ outline-offset: var(--und-focus-offset, 2px);
40
+ }
41
+
42
+ :host([disabled]) .frame,
43
+ :host([readonly]) .frame {
44
+ background: var(--und-bg-muted, #f1f2f6);
45
+ }
46
+
47
+ :host([disabled]) {
48
+ cursor: not-allowed;
49
+ opacity: var(--und-disabled-opacity, 0.55);
50
+ }
51
+
52
+ .toolbar {
53
+ display: flex;
54
+ flex-wrap: wrap;
55
+ align-items: center;
56
+ gap: var(--und-space-1, 0.25rem);
57
+ padding: var(--und-space-1, 0.25rem);
58
+ border-block-end: var(--und-border-width, 1px) solid var(--und-border-subtle, #dcdee5);
59
+ }
60
+
61
+ .sep {
62
+ inline-size: var(--und-border-width, 1px);
63
+ block-size: 1.25rem;
64
+ margin-inline: var(--und-space-1, 0.25rem);
65
+ background: var(--und-border-subtle, #dcdee5);
66
+ }
67
+
68
+ .tool {
69
+ display: inline-grid;
70
+ place-items: center;
71
+ inline-size: 2rem;
72
+ block-size: 2rem;
73
+ padding: 0;
74
+ border: 0;
75
+ border-radius: var(--und-radius-sm, 0.25rem);
76
+ background: transparent;
77
+ color: var(--und-fg-muted, #62646e);
78
+ cursor: pointer;
79
+ transition:
80
+ background-color var(--und-motion-hover, 130ms) ease,
81
+ color var(--und-motion-hover, 130ms) ease;
82
+ }
83
+
84
+ .tool svg {
85
+ inline-size: 1.125rem;
86
+ block-size: 1.125rem;
87
+ fill: none;
88
+ stroke: currentColor;
89
+ stroke-width: 2;
90
+ stroke-linecap: round;
91
+ stroke-linejoin: round;
92
+ }
93
+
94
+ .tool:hover:not(:disabled) {
95
+ background: var(--und-bg-muted-hover, #e6e8ee);
96
+ color: var(--und-fg-default, #23252c);
97
+ }
98
+
99
+ .tool[data-on] {
100
+ background: var(--und-bg-muted-active, #dcdee5);
101
+ color: var(--und-fg-default, #23252c);
102
+ }
103
+
104
+ .tool:focus-visible,
105
+ .text-button:focus-visible,
106
+ .link-input:focus-visible {
107
+ outline: var(--und-focus-width, 2px) solid var(--und-focus-ring, #4b4dd5);
108
+ outline-offset: calc(-1 * var(--und-focus-width, 2px));
109
+ }
110
+
111
+ .tool:disabled {
112
+ cursor: not-allowed;
113
+ }
114
+
115
+ .link-form {
116
+ display: flex;
117
+ flex-wrap: wrap;
118
+ align-items: center;
119
+ gap: var(--und-space-2, 0.5rem);
120
+ padding: var(--und-space-2, 0.5rem);
121
+ border-block-end: var(--und-border-width, 1px) solid var(--und-border-subtle, #dcdee5);
122
+ }
123
+
124
+ .link-input {
125
+ flex: 1 1 12rem;
126
+ min-inline-size: 0;
127
+ block-size: 2rem;
128
+ padding-inline: var(--und-space-2, 0.5rem);
129
+ border: var(--und-border-width, 1px) solid var(--und-border-control, #898c96);
130
+ border-radius: var(--und-radius-sm, 0.25rem);
131
+ background: var(--und-bg-surface, #fff);
132
+ color: inherit;
133
+ font: inherit;
134
+ font-size: var(--und-text-body-sm-size, 0.875rem);
135
+ }
136
+
137
+ .link-input[aria-invalid='true'] {
138
+ border-color: var(--und-status-danger-fg, #b81e27);
139
+ }
140
+
141
+ .text-button {
142
+ block-size: 2rem;
143
+ padding-inline: var(--und-space-3, 0.75rem);
144
+ border: var(--und-border-width, 1px) solid var(--und-border-default, #c4c7d0);
145
+ border-radius: var(--und-radius-sm, 0.25rem);
146
+ background: var(--und-bg-surface, #fff);
147
+ color: var(--und-fg-default, #23252c);
148
+ font: inherit;
149
+ font-size: var(--und-text-body-sm-size, 0.875rem);
150
+ cursor: pointer;
151
+ }
152
+
153
+ .text-button.primary {
154
+ border-color: transparent;
155
+ background: var(--und-accent-solid, #4b4dd5);
156
+ color: var(--und-fg-on-accent, #fff);
157
+ }
158
+
159
+ .link-error {
160
+ flex-basis: 100%;
161
+ margin: 0;
162
+ color: var(--und-status-danger-fg, #b81e27);
163
+ font-size: var(--und-text-body-sm-size, 0.875rem);
164
+ }
165
+
166
+ @media (prefers-reduced-motion: reduce) {
167
+ .frame,
168
+ .tool {
169
+ transition: none;
170
+ }
171
+ }
172
+
173
+ @media (forced-colors: active) {
174
+ .frame {
175
+ border-color: CanvasText;
176
+ }
177
+
178
+ .tool[data-on] {
179
+ outline: 1px solid Highlight;
180
+ color: Highlight;
181
+ }
182
+
183
+ .tool:disabled {
184
+ color: GrayText;
185
+ }
186
+ }
187
+ }
188
+ `;
189
+
190
+ /**
191
+ * Light-DOM styles for the label and the editable content (adopted once per
192
+ * tree). Under `@layer und.components` with `und-` classes, so page styles win.
193
+ */
194
+ export const contentStyles = css`
195
+ @layer und.components {
196
+ .und-rte__label {
197
+ display: block;
198
+ margin-block-end: var(--und-field-gap, 0.375rem);
199
+ color: var(--und-fg-default, #23252c);
200
+ font-size: var(--und-text-label-md-size, 0.875rem);
201
+ font-weight: var(--und-text-label-md-weight, 500);
202
+ line-height: var(--und-text-label-md-lh, 1.25rem);
203
+ }
204
+
205
+ .und-rte__label[hidden] {
206
+ display: none;
207
+ }
208
+
209
+ .und-rte__content {
210
+ box-sizing: border-box;
211
+ min-block-size: var(--und-rich-text-min-height, 8rem);
212
+ max-block-size: var(--und-rich-text-max-height, none);
213
+ overflow-y: auto;
214
+ padding-block: var(--und-space-2, 0.5rem);
215
+ padding-inline: var(--und-space-3, 0.75rem);
216
+ outline: none;
217
+ overflow-wrap: anywhere;
218
+ white-space: pre-wrap;
219
+ }
220
+
221
+ .und-rte__content > :first-child {
222
+ margin-block-start: 0;
223
+ }
224
+
225
+ .und-rte__content > :last-child {
226
+ margin-block-end: 0;
227
+ }
228
+
229
+ .und-rte__content :where(p, ul, ol, blockquote, pre) {
230
+ margin-block: 0 var(--und-space-2, 0.5rem);
231
+ }
232
+
233
+ .und-rte__content :where(h2) {
234
+ margin-block: var(--und-space-3, 0.75rem) var(--und-space-2, 0.5rem);
235
+ font-size: var(--und-text-heading-md-size, 1.25rem);
236
+ font-weight: var(--und-text-heading-md-weight, 600);
237
+ line-height: var(--und-text-heading-md-lh, 1.4);
238
+ }
239
+
240
+ .und-rte__content :where(h3) {
241
+ margin-block: var(--und-space-3, 0.75rem) var(--und-space-2, 0.5rem);
242
+ font-size: var(--und-text-heading-sm-size, 1.125rem);
243
+ font-weight: var(--und-text-heading-sm-weight, 600);
244
+ line-height: var(--und-text-heading-sm-lh, 1.4);
245
+ }
246
+
247
+ .und-rte__content :where(ul, ol) {
248
+ padding-inline-start: var(--und-space-6, 1.5rem);
249
+ }
250
+
251
+ .und-rte__content :where(li > p) {
252
+ margin: 0;
253
+ }
254
+
255
+ .und-rte__content :where(blockquote) {
256
+ margin-inline: 0;
257
+ padding-inline-start: var(--und-space-3, 0.75rem);
258
+ border-inline-start: var(--und-border-width-thick, 3px) solid
259
+ var(--und-border-default, #c4c7d0);
260
+ color: var(--und-fg-muted, #62646e);
261
+ }
262
+
263
+ .und-rte__content :where(code) {
264
+ padding-inline: var(--und-space-1, 0.25rem);
265
+ border-radius: var(--und-radius-xs, 0.125rem);
266
+ background: var(--und-code-bg, var(--und-bg-muted, #f1f2f6));
267
+ font-family: var(--und-typeface-code, ui-monospace, monospace);
268
+ font-size: 0.9em;
269
+ }
270
+
271
+ .und-rte__content :where(pre) {
272
+ padding: var(--und-space-3, 0.75rem);
273
+ border-radius: var(--und-radius-sm, 0.25rem);
274
+ background: var(--und-code-bg, var(--und-bg-muted, #f1f2f6));
275
+ font-family: var(--und-typeface-code, ui-monospace, monospace);
276
+ font-size: var(--und-text-body-sm-size, 0.875rem);
277
+ overflow-x: auto;
278
+ white-space: pre;
279
+ }
280
+
281
+ .und-rte__content :where(a) {
282
+ color: var(--und-link-default, #4b4dd5);
283
+ text-decoration: underline;
284
+ }
285
+
286
+ .und-rte__content[data-empty]::before {
287
+ content: attr(data-placeholder);
288
+ position: absolute;
289
+ color: var(--und-fg-muted, #62646e);
290
+ pointer-events: none;
291
+ }
292
+
293
+ .und-rte__content[data-empty] {
294
+ position: relative;
295
+ }
296
+
297
+ .und-rte__content[aria-disabled='true'] {
298
+ cursor: not-allowed;
299
+ }
300
+ }
301
+ `;