@civitai/blocks-react 0.11.2 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -3
- package/dist/ui/Alert.d.ts +29 -0
- package/dist/ui/Alert.d.ts.map +1 -0
- package/dist/ui/Alert.js +16 -0
- package/dist/ui/Alert.js.map +1 -0
- package/dist/ui/Badge.d.ts +18 -0
- package/dist/ui/Badge.d.ts.map +1 -0
- package/dist/ui/Badge.js +25 -0
- package/dist/ui/Badge.js.map +1 -0
- package/dist/ui/Button.d.ts +35 -0
- package/dist/ui/Button.d.ts.map +1 -0
- package/dist/ui/Button.js +44 -0
- package/dist/ui/Button.js.map +1 -0
- package/dist/ui/Card.d.ts +14 -0
- package/dist/ui/Card.d.ts.map +1 -0
- package/dist/ui/Card.js +11 -0
- package/dist/ui/Card.js.map +1 -0
- package/dist/ui/Group.d.ts +15 -0
- package/dist/ui/Group.d.ts.map +1 -0
- package/dist/ui/Group.js +22 -0
- package/dist/ui/Group.js.map +1 -0
- package/dist/ui/Loader.d.ts +18 -0
- package/dist/ui/Loader.d.ts.map +1 -0
- package/dist/ui/Loader.js +14 -0
- package/dist/ui/Loader.js.map +1 -0
- package/dist/ui/Modal.d.ts +46 -0
- package/dist/ui/Modal.d.ts.map +1 -0
- package/dist/ui/Modal.js +67 -0
- package/dist/ui/Modal.js.map +1 -0
- package/dist/ui/Stack.d.ts +13 -0
- package/dist/ui/Stack.d.ts.map +1 -0
- package/dist/ui/Stack.js +21 -0
- package/dist/ui/Stack.js.map +1 -0
- package/dist/ui/TextInput.d.ts +26 -0
- package/dist/ui/TextInput.d.ts.map +1 -0
- package/dist/ui/TextInput.js +23 -0
- package/dist/ui/TextInput.js.map +1 -0
- package/dist/ui/Textarea.d.ts +32 -0
- package/dist/ui/Textarea.d.ts.map +1 -0
- package/dist/ui/Textarea.js +23 -0
- package/dist/ui/Textarea.js.map +1 -0
- package/dist/ui/index.d.ts +33 -4
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +26 -4
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/styles.d.ts +19 -0
- package/dist/ui/styles.d.ts.map +1 -0
- package/dist/ui/styles.js +416 -0
- package/dist/ui/styles.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* W6 component pack — runtime style injection.
|
|
4
|
+
*
|
|
5
|
+
* The package builds with `tsc` only — there is no bundler and no CSS
|
|
6
|
+
* pipeline (verified: `dist/` emits no `.css`). To give block authors a
|
|
7
|
+
* zero-setup, auto-themed pack we ship the CSS as a TS string constant and
|
|
8
|
+
* inject it into the block document's `<head>` once, idempotently. Every
|
|
9
|
+
* component calls `useBlocksStyles()` (a `useEffect` that calls
|
|
10
|
+
* `injectBlocksStyles()`), so simply rendering any `/ui` component is enough
|
|
11
|
+
* to get the styling — no CSS import, no setup step.
|
|
12
|
+
*
|
|
13
|
+
* Theming (gotcha #60): a block sets `data-theme={theme}` on its OWN root
|
|
14
|
+
* (from `BLOCK_INIT.theme`); the host can't reach across the iframe boundary.
|
|
15
|
+
* These rules theme via an ancestor `[data-theme='dark']` selector. The
|
|
16
|
+
* default (no `data-theme`, i.e. light) matches the palette in
|
|
17
|
+
* `starters/examples/hello-world/src/index.css`.
|
|
18
|
+
*/
|
|
19
|
+
/** Marker attribute on the injected `<style>` so injection is idempotent. */
|
|
20
|
+
const STYLE_MARKER = 'data-civitai-blocks-ui';
|
|
21
|
+
/**
|
|
22
|
+
* Design tokens. CSS custom properties under `:root` (light defaults),
|
|
23
|
+
* overridden under `[data-theme='dark']`. Palette mirrors Civitai's Mantine
|
|
24
|
+
* design language (8px radius, blue primary `#228be6`, the dark/light
|
|
25
|
+
* surfaces already used by the hello-world example).
|
|
26
|
+
*/
|
|
27
|
+
const TOKENS = `
|
|
28
|
+
:root {
|
|
29
|
+
--ci-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
30
|
+
--ci-radius: 8px;
|
|
31
|
+
--ci-color-text: #1a1a1a;
|
|
32
|
+
--ci-color-text-dimmed: #6b7280;
|
|
33
|
+
--ci-color-surface: #ffffff;
|
|
34
|
+
--ci-color-surface-2: #f4f4f5;
|
|
35
|
+
--ci-color-border: #e0e0e3;
|
|
36
|
+
--ci-color-primary: #228be6;
|
|
37
|
+
--ci-color-primary-hover: #1c7ed6;
|
|
38
|
+
--ci-color-primary-fg: #ffffff;
|
|
39
|
+
--ci-color-error: #e03131;
|
|
40
|
+
--ci-color-success: #2f9e44;
|
|
41
|
+
--ci-color-warning: #f08c00;
|
|
42
|
+
--ci-color-info: #1971c2;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[data-theme='light'] {
|
|
46
|
+
--ci-color-text: #1a1a1a;
|
|
47
|
+
--ci-color-text-dimmed: #6b7280;
|
|
48
|
+
--ci-color-surface: #ffffff;
|
|
49
|
+
--ci-color-surface-2: #f4f4f5;
|
|
50
|
+
--ci-color-border: #e0e0e3;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
[data-theme='dark'] {
|
|
54
|
+
--ci-color-text: #e6e6e6;
|
|
55
|
+
--ci-color-text-dimmed: #909296;
|
|
56
|
+
--ci-color-surface: #1a1b1e;
|
|
57
|
+
--ci-color-surface-2: #25262b;
|
|
58
|
+
--ci-color-border: #2c2e33;
|
|
59
|
+
--ci-color-primary: #228be6;
|
|
60
|
+
--ci-color-primary-hover: #339af0;
|
|
61
|
+
--ci-color-primary-fg: #ffffff;
|
|
62
|
+
--ci-color-error: #ff6b6b;
|
|
63
|
+
--ci-color-success: #51cf66;
|
|
64
|
+
--ci-color-warning: #ffa94d;
|
|
65
|
+
--ci-color-info: #4dabf7;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
/**
|
|
69
|
+
* Component CSS. All selectors hang off the `data-civitai-ui="<name>"`
|
|
70
|
+
* attribute each component renders, so the pack never leaks styles onto the
|
|
71
|
+
* author's own markup.
|
|
72
|
+
*/
|
|
73
|
+
const COMPONENT_CSS = `
|
|
74
|
+
[data-civitai-ui] {
|
|
75
|
+
box-sizing: border-box;
|
|
76
|
+
font-family: var(--ci-font);
|
|
77
|
+
}
|
|
78
|
+
[data-civitai-ui] *,
|
|
79
|
+
[data-civitai-ui] *::before,
|
|
80
|
+
[data-civitai-ui] *::after {
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ----- Button ----- */
|
|
85
|
+
[data-civitai-ui='button'] {
|
|
86
|
+
display: inline-flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
justify-content: center;
|
|
89
|
+
gap: 8px;
|
|
90
|
+
border: 1px solid transparent;
|
|
91
|
+
border-radius: var(--ci-radius);
|
|
92
|
+
font-family: var(--ci-font);
|
|
93
|
+
font-weight: 600;
|
|
94
|
+
line-height: 1;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
user-select: none;
|
|
97
|
+
text-decoration: none;
|
|
98
|
+
transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
|
|
99
|
+
background: var(--ci-color-primary);
|
|
100
|
+
color: var(--ci-color-primary-fg);
|
|
101
|
+
}
|
|
102
|
+
[data-civitai-ui='button'][data-size='sm'] { height: 30px; padding: 0 14px; font-size: 13px; }
|
|
103
|
+
[data-civitai-ui='button'][data-size='md'] { height: 36px; padding: 0 18px; font-size: 14px; }
|
|
104
|
+
[data-civitai-ui='button'][data-size='lg'] { height: 44px; padding: 0 22px; font-size: 16px; }
|
|
105
|
+
[data-civitai-ui='button'][data-full-width='true'] { width: 100%; }
|
|
106
|
+
[data-civitai-ui='button'][data-variant='filled'] {
|
|
107
|
+
background: var(--ci-color-primary);
|
|
108
|
+
color: var(--ci-color-primary-fg);
|
|
109
|
+
border-color: var(--ci-color-primary);
|
|
110
|
+
}
|
|
111
|
+
[data-civitai-ui='button'][data-variant='filled']:hover:not(:disabled) {
|
|
112
|
+
background: var(--ci-color-primary-hover);
|
|
113
|
+
border-color: var(--ci-color-primary-hover);
|
|
114
|
+
}
|
|
115
|
+
[data-civitai-ui='button'][data-variant='light'] {
|
|
116
|
+
background: color-mix(in srgb, var(--ci-color-primary) 12%, transparent);
|
|
117
|
+
color: var(--ci-color-primary);
|
|
118
|
+
border-color: transparent;
|
|
119
|
+
}
|
|
120
|
+
[data-civitai-ui='button'][data-variant='light']:hover:not(:disabled) {
|
|
121
|
+
background: color-mix(in srgb, var(--ci-color-primary) 22%, transparent);
|
|
122
|
+
}
|
|
123
|
+
[data-civitai-ui='button'][data-variant='outline'] {
|
|
124
|
+
background: transparent;
|
|
125
|
+
color: var(--ci-color-primary);
|
|
126
|
+
border-color: var(--ci-color-primary);
|
|
127
|
+
}
|
|
128
|
+
[data-civitai-ui='button'][data-variant='outline']:hover:not(:disabled) {
|
|
129
|
+
background: color-mix(in srgb, var(--ci-color-primary) 10%, transparent);
|
|
130
|
+
}
|
|
131
|
+
[data-civitai-ui='button'][data-variant='subtle'] {
|
|
132
|
+
background: transparent;
|
|
133
|
+
color: var(--ci-color-primary);
|
|
134
|
+
border-color: transparent;
|
|
135
|
+
}
|
|
136
|
+
[data-civitai-ui='button'][data-variant='subtle']:hover:not(:disabled) {
|
|
137
|
+
background: color-mix(in srgb, var(--ci-color-primary) 10%, transparent);
|
|
138
|
+
}
|
|
139
|
+
[data-civitai-ui='button']:disabled,
|
|
140
|
+
[data-civitai-ui='button'][aria-busy='true'] {
|
|
141
|
+
opacity: 0.6;
|
|
142
|
+
cursor: not-allowed;
|
|
143
|
+
}
|
|
144
|
+
[data-civitai-ui='button'] [data-civitai-ui-section] {
|
|
145
|
+
display: inline-flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* ----- TextInput / Textarea ----- */
|
|
150
|
+
[data-civitai-ui='text-input'],
|
|
151
|
+
[data-civitai-ui='textarea'] {
|
|
152
|
+
display: flex;
|
|
153
|
+
flex-direction: column;
|
|
154
|
+
gap: 4px;
|
|
155
|
+
}
|
|
156
|
+
[data-civitai-ui-label] {
|
|
157
|
+
font-size: 14px;
|
|
158
|
+
font-weight: 600;
|
|
159
|
+
color: var(--ci-color-text);
|
|
160
|
+
}
|
|
161
|
+
[data-civitai-ui-required] {
|
|
162
|
+
color: var(--ci-color-error);
|
|
163
|
+
margin-left: 2px;
|
|
164
|
+
}
|
|
165
|
+
[data-civitai-ui-description] {
|
|
166
|
+
font-size: 12px;
|
|
167
|
+
color: var(--ci-color-text-dimmed);
|
|
168
|
+
}
|
|
169
|
+
[data-civitai-ui-error] {
|
|
170
|
+
font-size: 12px;
|
|
171
|
+
color: var(--ci-color-error);
|
|
172
|
+
}
|
|
173
|
+
[data-civitai-ui-control] {
|
|
174
|
+
width: 100%;
|
|
175
|
+
font-family: var(--ci-font);
|
|
176
|
+
font-size: 14px;
|
|
177
|
+
color: var(--ci-color-text);
|
|
178
|
+
background: var(--ci-color-surface);
|
|
179
|
+
border: 1px solid var(--ci-color-border);
|
|
180
|
+
border-radius: var(--ci-radius);
|
|
181
|
+
padding: 8px 12px;
|
|
182
|
+
transition: border-color 120ms ease;
|
|
183
|
+
}
|
|
184
|
+
[data-civitai-ui-control]:focus {
|
|
185
|
+
outline: none;
|
|
186
|
+
border-color: var(--ci-color-primary);
|
|
187
|
+
}
|
|
188
|
+
[data-civitai-ui-control][aria-invalid='true'] {
|
|
189
|
+
border-color: var(--ci-color-error);
|
|
190
|
+
}
|
|
191
|
+
[data-civitai-ui-control]:disabled {
|
|
192
|
+
opacity: 0.6;
|
|
193
|
+
cursor: not-allowed;
|
|
194
|
+
}
|
|
195
|
+
textarea[data-civitai-ui-control] {
|
|
196
|
+
resize: vertical;
|
|
197
|
+
line-height: 1.5;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* ----- Card ----- */
|
|
201
|
+
[data-civitai-ui='card'] {
|
|
202
|
+
background: var(--ci-color-surface);
|
|
203
|
+
border-radius: var(--ci-radius);
|
|
204
|
+
color: var(--ci-color-text);
|
|
205
|
+
}
|
|
206
|
+
[data-civitai-ui='card'][data-with-border='true'] {
|
|
207
|
+
border: 1px solid var(--ci-color-border);
|
|
208
|
+
}
|
|
209
|
+
[data-civitai-ui='card'][data-padding='sm'] { padding: 10px; }
|
|
210
|
+
[data-civitai-ui='card'][data-padding='md'] { padding: 16px; }
|
|
211
|
+
[data-civitai-ui='card'][data-padding='lg'] { padding: 24px; }
|
|
212
|
+
|
|
213
|
+
/* ----- Stack / Group ----- */
|
|
214
|
+
[data-civitai-ui='stack'] {
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
}
|
|
218
|
+
[data-civitai-ui='group'] {
|
|
219
|
+
display: flex;
|
|
220
|
+
flex-direction: row;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* ----- Alert ----- */
|
|
224
|
+
[data-civitai-ui='alert'] {
|
|
225
|
+
display: flex;
|
|
226
|
+
gap: 10px;
|
|
227
|
+
align-items: flex-start;
|
|
228
|
+
padding: 12px 14px;
|
|
229
|
+
border-radius: var(--ci-radius);
|
|
230
|
+
border: 1px solid transparent;
|
|
231
|
+
font-size: 14px;
|
|
232
|
+
color: var(--ci-color-text);
|
|
233
|
+
}
|
|
234
|
+
[data-civitai-ui='alert'][data-color='info'] {
|
|
235
|
+
background: color-mix(in srgb, var(--ci-color-info) 12%, transparent);
|
|
236
|
+
border-color: color-mix(in srgb, var(--ci-color-info) 35%, transparent);
|
|
237
|
+
}
|
|
238
|
+
[data-civitai-ui='alert'][data-color='success'] {
|
|
239
|
+
background: color-mix(in srgb, var(--ci-color-success) 12%, transparent);
|
|
240
|
+
border-color: color-mix(in srgb, var(--ci-color-success) 35%, transparent);
|
|
241
|
+
}
|
|
242
|
+
[data-civitai-ui='alert'][data-color='warning'] {
|
|
243
|
+
background: color-mix(in srgb, var(--ci-color-warning) 14%, transparent);
|
|
244
|
+
border-color: color-mix(in srgb, var(--ci-color-warning) 35%, transparent);
|
|
245
|
+
}
|
|
246
|
+
[data-civitai-ui='alert'][data-color='error'] {
|
|
247
|
+
background: color-mix(in srgb, var(--ci-color-error) 12%, transparent);
|
|
248
|
+
border-color: color-mix(in srgb, var(--ci-color-error) 35%, transparent);
|
|
249
|
+
}
|
|
250
|
+
[data-civitai-ui='alert'] [data-civitai-ui-alert-body] {
|
|
251
|
+
flex: 1;
|
|
252
|
+
min-width: 0;
|
|
253
|
+
}
|
|
254
|
+
[data-civitai-ui='alert'] [data-civitai-ui-alert-title] {
|
|
255
|
+
font-weight: 600;
|
|
256
|
+
margin-bottom: 2px;
|
|
257
|
+
}
|
|
258
|
+
[data-civitai-ui='alert'] [data-civitai-ui-alert-close] {
|
|
259
|
+
background: transparent;
|
|
260
|
+
border: none;
|
|
261
|
+
cursor: pointer;
|
|
262
|
+
color: inherit;
|
|
263
|
+
font-size: 16px;
|
|
264
|
+
line-height: 1;
|
|
265
|
+
padding: 0;
|
|
266
|
+
opacity: 0.7;
|
|
267
|
+
}
|
|
268
|
+
[data-civitai-ui='alert'] [data-civitai-ui-alert-close]:hover {
|
|
269
|
+
opacity: 1;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* ----- Loader ----- */
|
|
273
|
+
[data-civitai-ui='loader'] {
|
|
274
|
+
display: inline-block;
|
|
275
|
+
border-radius: 50%;
|
|
276
|
+
border-style: solid;
|
|
277
|
+
border-color: color-mix(in srgb, currentColor 25%, transparent);
|
|
278
|
+
border-top-color: currentColor;
|
|
279
|
+
color: var(--ci-color-primary);
|
|
280
|
+
animation: civitai-ui-spin 0.7s linear infinite;
|
|
281
|
+
}
|
|
282
|
+
[data-civitai-ui='loader'][data-size='sm'] { width: 16px; height: 16px; border-width: 2px; }
|
|
283
|
+
[data-civitai-ui='loader'][data-size='md'] { width: 22px; height: 22px; border-width: 3px; }
|
|
284
|
+
[data-civitai-ui='loader'][data-size='lg'] { width: 32px; height: 32px; border-width: 4px; }
|
|
285
|
+
@keyframes civitai-ui-spin {
|
|
286
|
+
to { transform: rotate(360deg); }
|
|
287
|
+
}
|
|
288
|
+
[data-civitai-ui='button'] [data-civitai-ui='loader'] {
|
|
289
|
+
color: currentColor;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* ----- Badge ----- */
|
|
293
|
+
[data-civitai-ui='badge'] {
|
|
294
|
+
display: inline-flex;
|
|
295
|
+
align-items: center;
|
|
296
|
+
border: 1px solid transparent;
|
|
297
|
+
border-radius: 999px;
|
|
298
|
+
font-weight: 600;
|
|
299
|
+
line-height: 1;
|
|
300
|
+
white-space: nowrap;
|
|
301
|
+
text-transform: uppercase;
|
|
302
|
+
letter-spacing: 0.02em;
|
|
303
|
+
}
|
|
304
|
+
[data-civitai-ui='badge'][data-size='sm'] { height: 18px; padding: 0 8px; font-size: 10px; }
|
|
305
|
+
[data-civitai-ui='badge'][data-size='md'] { height: 22px; padding: 0 10px; font-size: 11px; }
|
|
306
|
+
[data-civitai-ui='badge'][data-size='lg'] { height: 26px; padding: 0 12px; font-size: 13px; }
|
|
307
|
+
[data-civitai-ui='badge'][data-variant='filled'] {
|
|
308
|
+
background: var(--ci-color-primary);
|
|
309
|
+
color: var(--ci-color-primary-fg);
|
|
310
|
+
border-color: var(--ci-color-primary);
|
|
311
|
+
}
|
|
312
|
+
[data-civitai-ui='badge'][data-variant='light'] {
|
|
313
|
+
background: color-mix(in srgb, var(--ci-color-primary) 14%, transparent);
|
|
314
|
+
color: var(--ci-color-primary);
|
|
315
|
+
}
|
|
316
|
+
[data-civitai-ui='badge'][data-variant='outline'] {
|
|
317
|
+
background: transparent;
|
|
318
|
+
color: var(--ci-color-primary);
|
|
319
|
+
border-color: var(--ci-color-primary);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* ----- Modal ----- */
|
|
323
|
+
[data-civitai-ui='modal-overlay'] {
|
|
324
|
+
position: fixed;
|
|
325
|
+
inset: 0;
|
|
326
|
+
background: rgba(0, 0, 0, 0.55);
|
|
327
|
+
display: flex;
|
|
328
|
+
align-items: flex-start;
|
|
329
|
+
justify-content: center;
|
|
330
|
+
padding: 32px 16px;
|
|
331
|
+
overflow-y: auto;
|
|
332
|
+
z-index: 1000;
|
|
333
|
+
}
|
|
334
|
+
[data-civitai-ui='modal'] {
|
|
335
|
+
background: var(--ci-color-surface);
|
|
336
|
+
color: var(--ci-color-text);
|
|
337
|
+
border: 1px solid var(--ci-color-border);
|
|
338
|
+
border-radius: var(--ci-radius);
|
|
339
|
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
|
|
340
|
+
width: 100%;
|
|
341
|
+
max-width: 440px;
|
|
342
|
+
outline: none;
|
|
343
|
+
}
|
|
344
|
+
[data-civitai-ui='modal'][data-size='sm'] { max-width: 340px; }
|
|
345
|
+
[data-civitai-ui='modal'][data-size='md'] { max-width: 440px; }
|
|
346
|
+
[data-civitai-ui='modal'][data-size='lg'] { max-width: 620px; }
|
|
347
|
+
[data-civitai-ui='modal'] [data-civitai-ui-modal-header] {
|
|
348
|
+
display: flex;
|
|
349
|
+
align-items: center;
|
|
350
|
+
justify-content: space-between;
|
|
351
|
+
gap: 12px;
|
|
352
|
+
padding: 16px 18px;
|
|
353
|
+
border-bottom: 1px solid var(--ci-color-border);
|
|
354
|
+
}
|
|
355
|
+
[data-civitai-ui='modal'] [data-civitai-ui-modal-title] {
|
|
356
|
+
font-size: 16px;
|
|
357
|
+
font-weight: 700;
|
|
358
|
+
margin: 0;
|
|
359
|
+
}
|
|
360
|
+
[data-civitai-ui='modal'] [data-civitai-ui-modal-close] {
|
|
361
|
+
background: transparent;
|
|
362
|
+
border: none;
|
|
363
|
+
cursor: pointer;
|
|
364
|
+
color: var(--ci-color-text-dimmed);
|
|
365
|
+
font-size: 20px;
|
|
366
|
+
line-height: 1;
|
|
367
|
+
padding: 0;
|
|
368
|
+
}
|
|
369
|
+
[data-civitai-ui='modal'] [data-civitai-ui-modal-close]:hover {
|
|
370
|
+
color: var(--ci-color-text);
|
|
371
|
+
}
|
|
372
|
+
[data-civitai-ui='modal'] [data-civitai-ui-modal-body] {
|
|
373
|
+
padding: 18px;
|
|
374
|
+
}
|
|
375
|
+
`;
|
|
376
|
+
/** The full stylesheet shipped by the pack. Exported for SSR/manual use. */
|
|
377
|
+
export const BLOCKS_UI_STYLES = `${TOKENS}\n${COMPONENT_CSS}`;
|
|
378
|
+
/**
|
|
379
|
+
* Inject the pack's stylesheet into a document's `<head>` exactly once.
|
|
380
|
+
* Idempotent: subsequent calls (including from other components) detect the
|
|
381
|
+
* marker `<style>` and no-op. Safe to call from any component's effect.
|
|
382
|
+
*
|
|
383
|
+
* @param doc Target document. Defaults to the ambient `document`. No-op when
|
|
384
|
+
* no document is available (e.g. SSR) — callers in the browser get styling,
|
|
385
|
+
* server renders fall back to the unstyled-but-functional markup.
|
|
386
|
+
*/
|
|
387
|
+
export function injectBlocksStyles(doc) {
|
|
388
|
+
const target = doc ?? (typeof document !== 'undefined' ? document : undefined);
|
|
389
|
+
if (!target)
|
|
390
|
+
return;
|
|
391
|
+
// Already injected → no-op (idempotent).
|
|
392
|
+
if (target.querySelector(`style[${STYLE_MARKER}]`))
|
|
393
|
+
return;
|
|
394
|
+
const style = target.createElement('style');
|
|
395
|
+
style.setAttribute(STYLE_MARKER, 'true');
|
|
396
|
+
style.textContent = BLOCKS_UI_STYLES;
|
|
397
|
+
const head = target.head ?? target.getElementsByTagName('head')[0];
|
|
398
|
+
if (head) {
|
|
399
|
+
head.appendChild(style);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
// Degenerate document with no <head>; fall back to documentElement.
|
|
403
|
+
target.documentElement.appendChild(style);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Hook that injects the pack's styles once on mount. Every `/ui` component
|
|
408
|
+
* calls this so rendering any of them is enough to get the styling — the
|
|
409
|
+
* author never imports CSS or runs a setup step.
|
|
410
|
+
*/
|
|
411
|
+
export function useBlocksStyles() {
|
|
412
|
+
useEffect(() => {
|
|
413
|
+
injectBlocksStyles();
|
|
414
|
+
}, []);
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/ui/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AAEH,6EAA6E;AAC7E,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCd,CAAC;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8SrB,CAAC;AAEF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,MAAM,KAAK,aAAa,EAAE,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAc;IAC/C,MAAM,MAAM,GACV,GAAG,IAAI,CAAC,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAClE,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,yCAAyC;IACzC,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,YAAY,GAAG,CAAC;QAAE,OAAO;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5C,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACzC,KAAK,CAAC,WAAW,GAAG,gBAAgB,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,oEAAoE;QACpE,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,SAAS,CAAC,GAAG,EAAE;QACb,kBAAkB,EAAE,CAAC;IACvB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|