@pandacss/generator 0.0.2 → 0.3.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/LICENSE.md +1 -1
- package/dist/index.d.ts +64 -85
- package/dist/index.js +832 -425
- package/dist/index.mjs +832 -419
- package/package.json +10 -9
package/dist/index.mjs
CHANGED
|
@@ -93,10 +93,56 @@ var getMessages = (ctx) => ({
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
// src/generator.ts
|
|
96
|
-
import { Obj as
|
|
96
|
+
import { Obj as Obj2, pipe as pipe3 } from "lil-fp";
|
|
97
97
|
|
|
98
98
|
// src/artifacts/index.ts
|
|
99
|
-
import
|
|
99
|
+
import { isObject } from "@pandacss/shared";
|
|
100
|
+
import outdent29 from "outdent";
|
|
101
|
+
|
|
102
|
+
// src/artifacts/css/global-css.ts
|
|
103
|
+
var generateGlobalCss = (ctx) => {
|
|
104
|
+
const { globalCss = {}, optimize = true } = ctx.config;
|
|
105
|
+
const sheet = ctx.createSheet();
|
|
106
|
+
sheet.processGlobalCss({
|
|
107
|
+
":root": {
|
|
108
|
+
"--made-with-panda": `'\u{1F43C}'`
|
|
109
|
+
},
|
|
110
|
+
"*, *::before, *::after, ::backdrop": {
|
|
111
|
+
"--blur": "/*!*/ /*!*/",
|
|
112
|
+
"--brightness": "/*!*/ /*!*/",
|
|
113
|
+
"--contrast": "/*!*/ /*!*/",
|
|
114
|
+
"--grayscale": "/*!*/ /*!*/",
|
|
115
|
+
"--hue-rotate": "/*!*/ /*!*/",
|
|
116
|
+
"--invert": "/*!*/ /*!*/",
|
|
117
|
+
"--saturate": "/*!*/ /*!*/",
|
|
118
|
+
"--sepia": "/*!*/ /*!*/",
|
|
119
|
+
"--drop-shadow": "/*!*/ /*!*/",
|
|
120
|
+
"--backdrop-blur": "/*!*/ /*!*/",
|
|
121
|
+
"--backdrop-brightness": "/*!*/ /*!*/",
|
|
122
|
+
"--backdrop-contrast": "/*!*/ /*!*/",
|
|
123
|
+
"--backdrop-grayscale": "/*!*/ /*!*/",
|
|
124
|
+
"--backdrop-hue-rotate": "/*!*/ /*!*/",
|
|
125
|
+
"--backdrop-invert": "/*!*/ /*!*/",
|
|
126
|
+
"--backdrop-opacity": "/*!*/ /*!*/",
|
|
127
|
+
"--backdrop-saturate": "/*!*/ /*!*/",
|
|
128
|
+
"--backdrop-sepia": "/*!*/ /*!*/",
|
|
129
|
+
"--scroll-snap-strictness": "proximity",
|
|
130
|
+
"--border-spacing-x": 0,
|
|
131
|
+
"--border-spacing-y": 0,
|
|
132
|
+
"--translate-x": 0,
|
|
133
|
+
"--translate-y": 0,
|
|
134
|
+
"--rotate": 0,
|
|
135
|
+
"--skew-x": 0,
|
|
136
|
+
"--skew-y": 0,
|
|
137
|
+
"--scale-x": 1,
|
|
138
|
+
"--scale-y": 1
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
sheet.processGlobalCss(globalCss);
|
|
142
|
+
const output = sheet.toCss({ optimize });
|
|
143
|
+
ctx.hooks.callHook("generator:css", "global.css", output);
|
|
144
|
+
return output;
|
|
145
|
+
};
|
|
100
146
|
|
|
101
147
|
// src/artifacts/css/keyframe-css.ts
|
|
102
148
|
import { toCss } from "@pandacss/core";
|
|
@@ -118,114 +164,240 @@ function generateKeyframeCss(ctx) {
|
|
|
118
164
|
params: "tokens",
|
|
119
165
|
nodes: root.nodes
|
|
120
166
|
});
|
|
121
|
-
|
|
167
|
+
const output = rule.toString();
|
|
168
|
+
ctx.hooks.callHook("generator:css", "keyframes.css", output);
|
|
169
|
+
return output;
|
|
122
170
|
}
|
|
123
171
|
|
|
124
172
|
// src/artifacts/css/reset-css.ts
|
|
125
173
|
var css = String.raw;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
174
|
+
function generateResetCss(ctx, scope = "") {
|
|
175
|
+
const selector = scope ? `${scope} ` : "";
|
|
176
|
+
const output = css`
|
|
177
|
+
@layer reset {
|
|
178
|
+
${selector}* {
|
|
179
|
+
margin: 0;
|
|
180
|
+
padding: 0;
|
|
181
|
+
font: inherit;
|
|
182
|
+
}
|
|
130
183
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
184
|
+
${selector}*,
|
|
185
|
+
${selector}*::before,
|
|
186
|
+
${selector}*::after {
|
|
187
|
+
box-sizing: border-box;
|
|
188
|
+
border-width: 0;
|
|
189
|
+
border-style: solid;
|
|
190
|
+
border-color: var(--global-color-border, currentColor);
|
|
191
|
+
}
|
|
138
192
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
193
|
+
${scope || "html"} {
|
|
194
|
+
line-height: 1.5;
|
|
195
|
+
--font-fallback: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
196
|
+
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
|
|
197
|
+
'Noto Color Emoji';
|
|
198
|
+
-webkit-text-size-adjust: 100%;
|
|
199
|
+
-webkit-text-size-adjust: 100%;
|
|
200
|
+
-webkit-font-smoothing: antialiased;
|
|
201
|
+
-moz-tab-size: 4;
|
|
202
|
+
tab-size: 4;
|
|
203
|
+
font-family: var(--global-font-body, var(--font-fallback));
|
|
204
|
+
}
|
|
143
205
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
206
|
+
${selector}hr {
|
|
207
|
+
height: 0;
|
|
208
|
+
color: inherit;
|
|
209
|
+
border-top-width: 1px;
|
|
210
|
+
}
|
|
149
211
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
212
|
+
body {
|
|
213
|
+
height: 100%;
|
|
214
|
+
line-height: inherit;
|
|
215
|
+
}
|
|
153
216
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
canvas,
|
|
158
|
-
svg {
|
|
159
|
-
display: block;
|
|
160
|
-
max-width: 100%;
|
|
161
|
-
}
|
|
217
|
+
${selector}img {
|
|
218
|
+
border-style: none;
|
|
219
|
+
}
|
|
162
220
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
221
|
+
${selector}img,
|
|
222
|
+
${selector}svg,
|
|
223
|
+
${selector}video,
|
|
224
|
+
${selector}canvas,
|
|
225
|
+
${selector}audio,
|
|
226
|
+
${selector}iframe,
|
|
227
|
+
${selector}embed,
|
|
228
|
+
${selector}object {
|
|
229
|
+
display: block;
|
|
230
|
+
vertical-align: middle;
|
|
231
|
+
}
|
|
169
232
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
h5,
|
|
176
|
-
h6 {
|
|
177
|
-
overflow-wrap: break-word;
|
|
178
|
-
}
|
|
233
|
+
${selector}img,
|
|
234
|
+
${selector}video {
|
|
235
|
+
max-width: 100%;
|
|
236
|
+
height: auto;
|
|
237
|
+
}
|
|
179
238
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
239
|
+
${selector}p,
|
|
240
|
+
${selector}h1,
|
|
241
|
+
${selector}h2,
|
|
242
|
+
${selector}h3,
|
|
243
|
+
${selector}h4,
|
|
244
|
+
${selector}h5,
|
|
245
|
+
${selector}h6 {
|
|
246
|
+
overflow-wrap: break-word;
|
|
247
|
+
}
|
|
184
248
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
249
|
+
${selector}ol,
|
|
250
|
+
${selector}ul {
|
|
251
|
+
list-style: none;
|
|
252
|
+
}
|
|
190
253
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
254
|
+
${selector}code,
|
|
255
|
+
${selector}kbd,
|
|
256
|
+
${selector}pre,
|
|
257
|
+
${selector}samp {
|
|
258
|
+
font-size: 1em;
|
|
259
|
+
}
|
|
195
260
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
261
|
+
${selector}button,
|
|
262
|
+
${selector}[type='button'],
|
|
263
|
+
${selector}[type='reset'],
|
|
264
|
+
${selector}[type='submit'] {
|
|
265
|
+
-webkit-appearance: button;
|
|
266
|
+
background-color: transparent;
|
|
267
|
+
background-image: none;
|
|
268
|
+
}
|
|
202
269
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
270
|
+
${selector}button,
|
|
271
|
+
${selector}select {
|
|
272
|
+
text-transform: none;
|
|
273
|
+
}
|
|
206
274
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
275
|
+
${selector}table {
|
|
276
|
+
text-indent: 0;
|
|
277
|
+
border-color: inherit;
|
|
278
|
+
border-collapse: collapse;
|
|
279
|
+
}
|
|
210
280
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
281
|
+
${selector}input::placeholder,
|
|
282
|
+
${selector}textarea::placeholder {
|
|
283
|
+
opacity: 1;
|
|
284
|
+
color: var(--global-color-placeholder, #9ca3af);
|
|
285
|
+
}
|
|
214
286
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
287
|
+
${selector}textarea {
|
|
288
|
+
resize: vertical;
|
|
289
|
+
}
|
|
218
290
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
291
|
+
${selector}summary {
|
|
292
|
+
display: list-item;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
${selector}small {
|
|
296
|
+
font-size: 80%;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
${selector}sub,
|
|
300
|
+
${selector}sup {
|
|
301
|
+
font-size: 75%;
|
|
302
|
+
line-height: 0;
|
|
303
|
+
position: relative;
|
|
304
|
+
vertical-align: baseline;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
${selector}sub {
|
|
308
|
+
bottom: -0.25em;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
${selector}sup {
|
|
312
|
+
top: -0.5em;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
${selector}dialog {
|
|
316
|
+
padding: 0;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
${selector}a {
|
|
320
|
+
color: inherit;
|
|
321
|
+
text-decoration: inherit;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
${selector}abbr:where([title]) {
|
|
325
|
+
text-decoration: underline dotted;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
${selector}b,
|
|
329
|
+
${selector}strong {
|
|
330
|
+
font-weight: bolder;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
${selector}code,
|
|
334
|
+
${selector}kbd,
|
|
335
|
+
${selector}samp,
|
|
336
|
+
${selector}pre {
|
|
337
|
+
font-size: 1em;
|
|
338
|
+
--font-mono-fallback: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New';
|
|
339
|
+
font-family: var(--global-font-mono, var(--font-fallback));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
${selector}[type='search'] {
|
|
343
|
+
-webkit-appearance: textfield;
|
|
344
|
+
outline-offset: -2px;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
${selector}::-webkit-search-decoration {
|
|
348
|
+
-webkit-appearance: none;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
${selector}::-webkit-file-upload-button {
|
|
352
|
+
-webkit-appearance: button;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
${selector}::-webkit-inner-spin-button,
|
|
356
|
+
${selector}::-webkit-outer-spin-button {
|
|
357
|
+
height: auto;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
${selector}:-moz-ui-invalid {
|
|
361
|
+
box-shadow: none;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
${selector}:-moz-focusring {
|
|
365
|
+
outline: auto;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
ctx.hooks.callHook("generator:css", "reset.css", output);
|
|
370
|
+
return output;
|
|
227
371
|
}
|
|
228
372
|
|
|
373
|
+
// src/artifacts/css/static-css.ts
|
|
374
|
+
import { getStaticCss } from "@pandacss/core";
|
|
375
|
+
var generateStaticCss = (ctx) => {
|
|
376
|
+
const { config, createSheet, utility, recipes } = ctx;
|
|
377
|
+
const { staticCss = {}, theme = {}, optimize = true } = config;
|
|
378
|
+
const sheet = createSheet();
|
|
379
|
+
const fn = getStaticCss(staticCss);
|
|
380
|
+
const results = fn({
|
|
381
|
+
breakpoints: Object.keys(theme.breakpoints ?? {}),
|
|
382
|
+
getPropertyKeys: utility.getPropertyKeys,
|
|
383
|
+
getRecipeKeys: (recipe) => recipes.details.find((detail) => detail.config.name === recipe)?.variantKeyMap ?? {}
|
|
384
|
+
});
|
|
385
|
+
results.css.forEach((css2) => {
|
|
386
|
+
sheet.processAtomic(css2);
|
|
387
|
+
});
|
|
388
|
+
results.recipes.forEach((result) => {
|
|
389
|
+
Object.entries(result).forEach(([name, value]) => {
|
|
390
|
+
const recipeConfig = recipes.getConfig(name);
|
|
391
|
+
if (!recipeConfig)
|
|
392
|
+
return;
|
|
393
|
+
sheet.processRecipe(recipeConfig, value);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
const output = sheet.toCss({ optimize });
|
|
397
|
+
ctx.hooks.callHook("generator:css", "static.css", output);
|
|
398
|
+
return output;
|
|
399
|
+
};
|
|
400
|
+
|
|
229
401
|
// src/artifacts/css/token-css.ts
|
|
230
402
|
import { expandNestedCss, extractParentSelectors, prettifyCss, toCss as toCss2 } from "@pandacss/core";
|
|
231
403
|
import postcss2 from "postcss";
|
|
@@ -259,10 +431,12 @@ function generateTokenCss(ctx) {
|
|
|
259
431
|
}
|
|
260
432
|
}
|
|
261
433
|
const css2 = results.join("\n\n");
|
|
262
|
-
|
|
434
|
+
const output = `@layer tokens {
|
|
263
435
|
${prettifyCss(cleanupSelectors(css2, root))}
|
|
264
436
|
}
|
|
265
437
|
`;
|
|
438
|
+
ctx.hooks.callHook("generator:css", "tokens.css", output);
|
|
439
|
+
return output;
|
|
266
440
|
}
|
|
267
441
|
function getDeepestRule(root, selectors) {
|
|
268
442
|
const rule = postcss2.rule({ selector: "" });
|
|
@@ -651,6 +825,7 @@ transform`)}
|
|
|
651
825
|
import { unionType as unionType2 } from "@pandacss/shared";
|
|
652
826
|
import { outdent as outdent8 } from "outdent";
|
|
653
827
|
var stringify3 = (value) => JSON.stringify(value, null, 2);
|
|
828
|
+
var isBooleanValue = (value) => value === "true" || value === "false";
|
|
654
829
|
function generateRecipes(ctx) {
|
|
655
830
|
const {
|
|
656
831
|
recipes,
|
|
@@ -713,21 +888,34 @@ function generateRecipes(ctx) {
|
|
|
713
888
|
${ctx.file.import("splitProps", "../helpers")}
|
|
714
889
|
${ctx.file.import("createRecipe", "./create-recipe")}
|
|
715
890
|
|
|
716
|
-
|
|
891
|
+
const ${name}Fn = createRecipe('${name}', ${stringify3(defaultVariants ?? {})}, ${stringify3(
|
|
717
892
|
compoundVariants ?? []
|
|
718
893
|
)})
|
|
719
894
|
|
|
720
|
-
${name}.variants = ${stringify3(variantKeyMap)}
|
|
721
|
-
|
|
722
895
|
const variantKeys = ${stringify3(Object.keys(variantKeyMap))}
|
|
723
|
-
|
|
896
|
+
|
|
897
|
+
function splitVariantProps(props) {
|
|
898
|
+
return splitProps(props, variantKeys)
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
export const ${name} = Object.assign(${name}Fn, {
|
|
902
|
+
__recipe__: true,
|
|
903
|
+
variantKeys,
|
|
904
|
+
variantMap: ${stringify3(variantKeyMap)},
|
|
905
|
+
splitVariantProps,
|
|
906
|
+
})
|
|
724
907
|
`,
|
|
725
908
|
dts: outdent8`
|
|
726
909
|
import type { ConditionalValue } from '../types'
|
|
727
910
|
import type { Pretty } from '../types/helpers'
|
|
728
911
|
|
|
729
912
|
type ${upperName}Variant = {
|
|
730
|
-
${Object.keys(variantKeyMap).map((key) =>
|
|
913
|
+
${Object.keys(variantKeyMap).map((key) => {
|
|
914
|
+
const values = variantKeyMap[key];
|
|
915
|
+
if (values.every(isBooleanValue))
|
|
916
|
+
return `${key}: boolean`;
|
|
917
|
+
return `${key}: ${unionType2(values)}`;
|
|
918
|
+
}).join("\n")}
|
|
731
919
|
}
|
|
732
920
|
|
|
733
921
|
type ${upperName}VariantMap = {
|
|
@@ -739,8 +927,10 @@ function generateRecipes(ctx) {
|
|
|
739
927
|
}
|
|
740
928
|
|
|
741
929
|
interface ${upperName}Recipe {
|
|
742
|
-
|
|
743
|
-
|
|
930
|
+
__type: ${upperName}VariantProps
|
|
931
|
+
(props?: ${upperName}VariantProps): string
|
|
932
|
+
variantMap: ${upperName}VariantMap
|
|
933
|
+
variantKeys: Array<keyof ${upperName}Variant>
|
|
744
934
|
splitVariantProps<Props extends ${upperName}VariantProps>(props: Props): [${upperName}VariantProps, Pretty<Omit<Props, keyof ${upperName}VariantProps>>]
|
|
745
935
|
}
|
|
746
936
|
|
|
@@ -803,23 +993,31 @@ function generatePreactJsxFactory(ctx) {
|
|
|
803
993
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
804
994
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
805
995
|
|
|
806
|
-
function
|
|
807
|
-
const cvaFn = configOrCva.__cva__ ? configOrCva : cva(configOrCva)
|
|
996
|
+
function styledFn(Dynamic, configOrCva = {}) {
|
|
997
|
+
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
808
998
|
|
|
809
999
|
const ${componentName} = forwardRef(function ${componentName}(props, ref) {
|
|
810
1000
|
const { as: Element = Dynamic, ...restProps } = props
|
|
811
1001
|
|
|
812
|
-
const [
|
|
813
|
-
return splitProps(restProps,
|
|
1002
|
+
const [variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1003
|
+
return splitProps(restProps, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
814
1004
|
}, [restProps])
|
|
815
1005
|
|
|
816
|
-
function
|
|
1006
|
+
function recipeClass() {
|
|
1007
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1008
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1009
|
+
return cx(cvaFn(variantProps), css(styles), elementProps.className, elementProps.class)
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
function cvaClass() {
|
|
817
1013
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
818
1014
|
const cvaStyles = cvaFn.resolve(variantProps)
|
|
819
1015
|
const styles = assignCss(cvaStyles, propStyles, cssStyles)
|
|
820
|
-
return cx(css(styles), elementProps.className)
|
|
1016
|
+
return cx(css(styles), elementProps.className, elementProps.class)
|
|
821
1017
|
}
|
|
822
1018
|
|
|
1019
|
+
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1020
|
+
|
|
823
1021
|
return h(Element, {
|
|
824
1022
|
...elementProps,
|
|
825
1023
|
...normalizeHTMLProps(htmlProps),
|
|
@@ -835,13 +1033,13 @@ function generatePreactJsxFactory(ctx) {
|
|
|
835
1033
|
function createJsxFactory() {
|
|
836
1034
|
const cache = new Map()
|
|
837
1035
|
|
|
838
|
-
return new Proxy(
|
|
1036
|
+
return new Proxy(styledFn, {
|
|
839
1037
|
apply(_, __, args) {
|
|
840
|
-
return
|
|
1038
|
+
return styledFn(...args)
|
|
841
1039
|
},
|
|
842
1040
|
get(_, el) {
|
|
843
1041
|
if (!cache.has(el)) {
|
|
844
|
-
cache.set(el,
|
|
1042
|
+
cache.set(el, styledFn(el))
|
|
845
1043
|
}
|
|
846
1044
|
return cache.get(el)
|
|
847
1045
|
},
|
|
@@ -873,7 +1071,8 @@ function generatePreactJsxPattern(ctx) {
|
|
|
873
1071
|
${match2(props.length).with(
|
|
874
1072
|
0,
|
|
875
1073
|
() => outdent11`
|
|
876
|
-
|
|
1074
|
+
const styleProps = ${styleFnName}()
|
|
1075
|
+
return h(${factoryName}.${jsxElement}, { ref, ...styleProps, ...props })
|
|
877
1076
|
`
|
|
878
1077
|
).otherwise(
|
|
879
1078
|
() => outdent11`
|
|
@@ -908,9 +1107,9 @@ import type { ${upperName} } from '../types/jsx'
|
|
|
908
1107
|
export declare const ${factoryName}: ${upperName}
|
|
909
1108
|
`,
|
|
910
1109
|
jsxType: outdent12`
|
|
911
|
-
import type {
|
|
912
|
-
import type { JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
913
|
-
import type { RecipeDefinition,
|
|
1110
|
+
import type { ComponentProps, JSX } from 'preact'
|
|
1111
|
+
import type { Assign, JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1112
|
+
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
|
|
914
1113
|
|
|
915
1114
|
type ElementType = keyof JSX.IntrinsicElements
|
|
916
1115
|
|
|
@@ -921,43 +1120,241 @@ export type ${componentName}<T extends ElementType, P extends Dict = {}> = {
|
|
|
921
1120
|
displayName?: string
|
|
922
1121
|
}
|
|
923
1122
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1123
|
+
type RecipeFn = { __type: any }
|
|
1124
|
+
|
|
1125
|
+
interface JsxFactory {
|
|
1126
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1127
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>): ${componentName}<
|
|
1128
|
+
T,
|
|
1129
|
+
RecipeSelection<P>
|
|
1130
|
+
>
|
|
1131
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1135
|
+
|
|
1136
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
927
1137
|
|
|
928
1138
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
929
1139
|
`
|
|
930
1140
|
};
|
|
931
1141
|
}
|
|
932
1142
|
|
|
933
|
-
// src/artifacts/
|
|
1143
|
+
// src/artifacts/qwik-jsx/jsx.ts
|
|
934
1144
|
import { outdent as outdent13 } from "outdent";
|
|
935
|
-
function
|
|
1145
|
+
function generateQwikJsxFactory(ctx) {
|
|
936
1146
|
const { factoryName, componentName } = ctx.jsx;
|
|
937
1147
|
return {
|
|
938
1148
|
js: outdent13`
|
|
1149
|
+
import { h } from '@builder.io/qwik'
|
|
1150
|
+
${ctx.file.import("css, cx, cva, assignCss", "../css/index")}
|
|
1151
|
+
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1152
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1153
|
+
|
|
1154
|
+
function styledFn(Dynamic, configOrCva = {}) {
|
|
1155
|
+
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1156
|
+
|
|
1157
|
+
const ${componentName} = function ${componentName}(props) {
|
|
1158
|
+
const { as: Element = Dynamic, ...restProps } = props
|
|
1159
|
+
|
|
1160
|
+
const [variantProps, styleProps, htmlProps, elementProps] =
|
|
1161
|
+
splitProps(restProps, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1162
|
+
|
|
1163
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1164
|
+
|
|
1165
|
+
function recipeClass() {
|
|
1166
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1167
|
+
return cx(cvaFn(variantProps), css(styles), elementProps.class)
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
function cvaClass() {
|
|
1171
|
+
const cvaStyles = cvaFn.resolve(variantProps)
|
|
1172
|
+
const styles = assignCss(cvaStyles, propStyles, cssStyles)
|
|
1173
|
+
return cx(css(styles), elementProps.class)
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1177
|
+
|
|
1178
|
+
return h(Element, {
|
|
1179
|
+
...elementProps,
|
|
1180
|
+
...normalizeHTMLProps(htmlProps),
|
|
1181
|
+
class: classes(),
|
|
1182
|
+
})
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
${componentName}.displayName = \`${factoryName}.\${Dynamic}\`
|
|
1186
|
+
return ${componentName}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function createJsxFactory() {
|
|
1190
|
+
const cache = new Map()
|
|
1191
|
+
|
|
1192
|
+
return new Proxy(styledFn, {
|
|
1193
|
+
apply(_, __, args) {
|
|
1194
|
+
return styledFn(...args)
|
|
1195
|
+
},
|
|
1196
|
+
get(_, el) {
|
|
1197
|
+
if (!cache.has(el)) {
|
|
1198
|
+
cache.set(el, styledFn(el))
|
|
1199
|
+
}
|
|
1200
|
+
return cache.get(el)
|
|
1201
|
+
},
|
|
1202
|
+
})
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
export const ${factoryName} = createJsxFactory()
|
|
1206
|
+
|
|
1207
|
+
`
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// src/artifacts/qwik-jsx/pattern.ts
|
|
1212
|
+
import { outdent as outdent14 } from "outdent";
|
|
1213
|
+
import { match as match3 } from "ts-pattern";
|
|
1214
|
+
function generateQwikJsxPattern(ctx) {
|
|
1215
|
+
const { typeName, factoryName } = ctx.jsx;
|
|
1216
|
+
return ctx.patterns.details.map((pattern) => {
|
|
1217
|
+
const { upperName, styleFnName, dashName, jsxName, props, blocklistType } = pattern;
|
|
1218
|
+
const { description, jsxElement = "div" } = pattern.config;
|
|
1219
|
+
return {
|
|
1220
|
+
name: dashName,
|
|
1221
|
+
js: outdent14`
|
|
1222
|
+
import { h } from '@builder.io/qwik'
|
|
1223
|
+
${ctx.file.import(factoryName, "./factory")}
|
|
1224
|
+
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1225
|
+
|
|
1226
|
+
export const ${jsxName} = function ${jsxName}(props) {
|
|
1227
|
+
${match3(props.length).with(
|
|
1228
|
+
0,
|
|
1229
|
+
() => outdent14`
|
|
1230
|
+
const styleProps = ${styleFnName}()
|
|
1231
|
+
return h(${factoryName}.${jsxElement}, { ...styleProps, ...props })
|
|
1232
|
+
`
|
|
1233
|
+
).otherwise(
|
|
1234
|
+
() => outdent14`
|
|
1235
|
+
const { ${props.join(", ")}, ...restProps } = props
|
|
1236
|
+
const styleProps = ${styleFnName}({${props.join(", ")}})
|
|
1237
|
+
return h(${factoryName}.${jsxElement}, { ...styleProps, ...restProps })
|
|
1238
|
+
`
|
|
1239
|
+
)}
|
|
1240
|
+
}
|
|
1241
|
+
`,
|
|
1242
|
+
dts: outdent14`
|
|
1243
|
+
import type { FunctionComponent } from '@builder.io/qwik'
|
|
1244
|
+
import type { ${upperName}Properties } from '../patterns/${dashName}'
|
|
1245
|
+
import type { ${typeName} } from '../types/jsx'
|
|
1246
|
+
|
|
1247
|
+
type Assign<T, U> = {
|
|
1248
|
+
[K in keyof T]?: K extends keyof T ? (K extends keyof U ? T[K] & U[K] : T[K]) : never
|
|
1249
|
+
} & U
|
|
1250
|
+
|
|
1251
|
+
export type ${upperName}Props = Assign<${typeName}<'${jsxElement}'>, Omit<${upperName}Properties, ${blocklistType || '""'}>>
|
|
1252
|
+
|
|
1253
|
+
${description ? `/** ${description} */` : ""}
|
|
1254
|
+
export declare const ${jsxName}: FunctionComponent<${upperName}Props>
|
|
1255
|
+
`
|
|
1256
|
+
};
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// src/artifacts/qwik-jsx/types.ts
|
|
1261
|
+
import { outdent as outdent15 } from "outdent";
|
|
1262
|
+
function generateQwikJsxTypes(ctx) {
|
|
1263
|
+
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1264
|
+
return {
|
|
1265
|
+
jsxFactory: outdent15`
|
|
1266
|
+
import { ${upperName} } from '../types/jsx'
|
|
1267
|
+
export declare const ${factoryName}: ${upperName}
|
|
1268
|
+
`,
|
|
1269
|
+
jsxType: outdent15`
|
|
1270
|
+
import type { FunctionComponent, QwikIntrinsicElements } from '@builder.io/qwik'
|
|
1271
|
+
import type { Assign as _Assign, JsxStyleProps, PatchedHTMLProps } from './system-types'
|
|
1272
|
+
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
|
|
1273
|
+
|
|
1274
|
+
type ElementType = keyof QwikIntrinsicElements | FunctionComponent<any>
|
|
1275
|
+
|
|
1276
|
+
type ComponentProps<T extends ElementType> = T extends keyof QwikIntrinsicElements
|
|
1277
|
+
? QwikIntrinsicElements[T]
|
|
1278
|
+
: T extends FunctionComponent<infer P>
|
|
1279
|
+
? P
|
|
1280
|
+
: never
|
|
1281
|
+
|
|
1282
|
+
type Dict = Record<string, unknown>
|
|
1283
|
+
|
|
1284
|
+
type Omitted = 'color' | 'translate' | 'transition' | 'width' | 'height' | 'size' | 'content'
|
|
1285
|
+
|
|
1286
|
+
// Patch due to Omit<T, K> not working with Qwik JSX Types
|
|
1287
|
+
|
|
1288
|
+
type Assign<T, U> = {
|
|
1289
|
+
[K in keyof T]?: K extends Omitted
|
|
1290
|
+
? K extends keyof U
|
|
1291
|
+
? U[K]
|
|
1292
|
+
: never
|
|
1293
|
+
: K extends keyof T
|
|
1294
|
+
? K extends keyof U
|
|
1295
|
+
? T[K] & U[K]
|
|
1296
|
+
: T[K]
|
|
1297
|
+
: never
|
|
1298
|
+
} & U & PatchedHTMLProps
|
|
1299
|
+
|
|
1300
|
+
export type ${componentName}<T extends ElementType, P extends Dict = {}> = FunctionComponent<Assign<ComponentProps<T>, _Assign<JsxStyleProps, P>>>
|
|
1301
|
+
|
|
1302
|
+
type RecipeFn = { __type: any }
|
|
1303
|
+
|
|
1304
|
+
interface JsxFactory {
|
|
1305
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1306
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>): ${componentName}<
|
|
1307
|
+
T,
|
|
1308
|
+
RecipeSelection<P>
|
|
1309
|
+
>
|
|
1310
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
type JsxElements = { [K in keyof QwikIntrinsicElements]: ${componentName}<K, {}> }
|
|
1314
|
+
|
|
1315
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1316
|
+
|
|
1317
|
+
export type ${typeName}<T extends ElementType> = Assign<ComponentProps<T>, JsxStyleProps>
|
|
1318
|
+
`
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// src/artifacts/react-jsx/jsx.ts
|
|
1323
|
+
import { outdent as outdent16 } from "outdent";
|
|
1324
|
+
function generateReactJsxFactory(ctx) {
|
|
1325
|
+
const { factoryName, componentName } = ctx.jsx;
|
|
1326
|
+
return {
|
|
1327
|
+
js: outdent16`
|
|
939
1328
|
import { createElement, forwardRef, useMemo } from 'react'
|
|
940
1329
|
${ctx.file.import("css, cx, cva, assignCss", "../css/index")}
|
|
941
1330
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
942
1331
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
943
1332
|
|
|
944
|
-
function
|
|
945
|
-
const cvaFn = configOrCva.__cva__ ? configOrCva : cva(configOrCva)
|
|
1333
|
+
function styledFn(Dynamic, configOrCva = {}) {
|
|
1334
|
+
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
946
1335
|
|
|
947
1336
|
const ${componentName} = forwardRef(function ${componentName}(props, ref) {
|
|
948
1337
|
const { as: Element = Dynamic, ...restProps } = props
|
|
949
1338
|
|
|
950
|
-
const [
|
|
951
|
-
return splitProps(restProps,
|
|
1339
|
+
const [variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1340
|
+
return splitProps(restProps, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
952
1341
|
}, [restProps])
|
|
953
|
-
|
|
954
|
-
function
|
|
1342
|
+
|
|
1343
|
+
function recipeClass() {
|
|
1344
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1345
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1346
|
+
return cx(cvaFn(variantProps), css(styles), elementProps.className)
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
function cvaClass() {
|
|
955
1350
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
956
1351
|
const cvaStyles = cvaFn.resolve(variantProps)
|
|
957
1352
|
const styles = assignCss(cvaStyles, propStyles, cssStyles)
|
|
958
1353
|
return cx(css(styles), elementProps.className)
|
|
959
1354
|
}
|
|
960
1355
|
|
|
1356
|
+
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1357
|
+
|
|
961
1358
|
return createElement(Element, {
|
|
962
1359
|
ref,
|
|
963
1360
|
...elementProps,
|
|
@@ -973,13 +1370,13 @@ function generateReactJsxFactory(ctx) {
|
|
|
973
1370
|
function createJsxFactory() {
|
|
974
1371
|
const cache = new Map()
|
|
975
1372
|
|
|
976
|
-
return new Proxy(
|
|
1373
|
+
return new Proxy(styledFn, {
|
|
977
1374
|
apply(_, __, args) {
|
|
978
|
-
return
|
|
1375
|
+
return styledFn(...args)
|
|
979
1376
|
},
|
|
980
1377
|
get(_, el) {
|
|
981
1378
|
if (!cache.has(el)) {
|
|
982
|
-
cache.set(el,
|
|
1379
|
+
cache.set(el, styledFn(el))
|
|
983
1380
|
}
|
|
984
1381
|
return cache.get(el)
|
|
985
1382
|
},
|
|
@@ -993,8 +1390,8 @@ function generateReactJsxFactory(ctx) {
|
|
|
993
1390
|
}
|
|
994
1391
|
|
|
995
1392
|
// src/artifacts/react-jsx/pattern.ts
|
|
996
|
-
import { outdent as
|
|
997
|
-
import { match as
|
|
1393
|
+
import { outdent as outdent17 } from "outdent";
|
|
1394
|
+
import { match as match4 } from "ts-pattern";
|
|
998
1395
|
function generateReactJsxPattern(ctx) {
|
|
999
1396
|
const { typeName, factoryName } = ctx.jsx;
|
|
1000
1397
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1002,19 +1399,20 @@ function generateReactJsxPattern(ctx) {
|
|
|
1002
1399
|
const { description, jsxElement = "div" } = pattern.config;
|
|
1003
1400
|
return {
|
|
1004
1401
|
name: dashName,
|
|
1005
|
-
js:
|
|
1402
|
+
js: outdent17`
|
|
1006
1403
|
import { createElement, forwardRef } from 'react'
|
|
1007
1404
|
${ctx.file.import(factoryName, "./factory")}
|
|
1008
1405
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1009
1406
|
|
|
1010
1407
|
export const ${jsxName} = forwardRef(function ${jsxName}(props, ref) {
|
|
1011
|
-
${
|
|
1408
|
+
${match4(props.length).with(
|
|
1012
1409
|
0,
|
|
1013
|
-
() =>
|
|
1014
|
-
|
|
1410
|
+
() => outdent17`
|
|
1411
|
+
const styleProps = ${styleFnName}()
|
|
1412
|
+
return createElement(${factoryName}.${jsxElement}, { ref, ...styleProps, ...props })
|
|
1015
1413
|
`
|
|
1016
1414
|
).otherwise(
|
|
1017
|
-
() =>
|
|
1415
|
+
() => outdent17`
|
|
1018
1416
|
const { ${props.join(", ")}, ...restProps } = props
|
|
1019
1417
|
const styleProps = ${styleFnName}({${props.join(", ")}})
|
|
1020
1418
|
return createElement(${factoryName}.${jsxElement}, { ref, ...styleProps, ...restProps })
|
|
@@ -1022,7 +1420,7 @@ function generateReactJsxPattern(ctx) {
|
|
|
1022
1420
|
)}
|
|
1023
1421
|
})
|
|
1024
1422
|
`,
|
|
1025
|
-
dts:
|
|
1423
|
+
dts: outdent17`
|
|
1026
1424
|
import type { FunctionComponent } from 'react'
|
|
1027
1425
|
import type { ${upperName}Properties } from '../patterns/${dashName}'
|
|
1028
1426
|
import type { ${typeName} } from '../types/jsx'
|
|
@@ -1037,18 +1435,18 @@ function generateReactJsxPattern(ctx) {
|
|
|
1037
1435
|
}
|
|
1038
1436
|
|
|
1039
1437
|
// src/artifacts/react-jsx/types.ts
|
|
1040
|
-
import { outdent as
|
|
1438
|
+
import { outdent as outdent18 } from "outdent";
|
|
1041
1439
|
function generateReactJsxTypes(ctx) {
|
|
1042
1440
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1043
1441
|
return {
|
|
1044
|
-
jsxFactory:
|
|
1442
|
+
jsxFactory: outdent18`
|
|
1045
1443
|
import { ${upperName} } from '../types/jsx'
|
|
1046
1444
|
export declare const ${factoryName}: ${upperName}
|
|
1047
1445
|
`,
|
|
1048
|
-
jsxType:
|
|
1049
|
-
import type {
|
|
1050
|
-
import type { JsxStyleProps, JsxHTMLProps
|
|
1051
|
-
import type { RecipeDefinition,
|
|
1446
|
+
jsxType: outdent18`
|
|
1447
|
+
import type { ComponentProps, ElementType } from 'react'
|
|
1448
|
+
import type { Assign, JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1449
|
+
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
|
|
1052
1450
|
|
|
1053
1451
|
type Dict = Record<string, unknown>
|
|
1054
1452
|
|
|
@@ -1057,9 +1455,20 @@ export type ${componentName}<T extends ElementType, P extends Dict = {}> = {
|
|
|
1057
1455
|
displayName?: string
|
|
1058
1456
|
}
|
|
1059
1457
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1458
|
+
type RecipeFn = { __type: any }
|
|
1459
|
+
|
|
1460
|
+
interface JsxFactory {
|
|
1461
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1462
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>): ${componentName}<
|
|
1463
|
+
T,
|
|
1464
|
+
RecipeSelection<P>
|
|
1465
|
+
>
|
|
1466
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1470
|
+
|
|
1471
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1063
1472
|
|
|
1064
1473
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
1065
1474
|
`
|
|
@@ -1067,11 +1476,11 @@ export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>,
|
|
|
1067
1476
|
}
|
|
1068
1477
|
|
|
1069
1478
|
// src/artifacts/solid-jsx/jsx.ts
|
|
1070
|
-
import { outdent as
|
|
1479
|
+
import { outdent as outdent19 } from "outdent";
|
|
1071
1480
|
function generateSolidJsxFactory(ctx) {
|
|
1072
1481
|
const { componentName, factoryName } = ctx.jsx;
|
|
1073
1482
|
return {
|
|
1074
|
-
js:
|
|
1483
|
+
js: outdent19`
|
|
1075
1484
|
import { Dynamic } from 'solid-js/web'
|
|
1076
1485
|
import { mergeProps, splitProps } from 'solid-js'
|
|
1077
1486
|
import { createComponent } from 'solid-js/web'
|
|
@@ -1079,27 +1488,35 @@ function generateSolidJsxFactory(ctx) {
|
|
|
1079
1488
|
${ctx.file.import("normalizeHTMLProps", "../helpers")}
|
|
1080
1489
|
${ctx.file.import("allCssProperties", "./is-valid-prop")}
|
|
1081
1490
|
|
|
1082
|
-
function
|
|
1491
|
+
function styledFn(element, configOrCva = {}) {
|
|
1083
1492
|
const cvaFn = configOrCva.__cva__ ? configOrCva : cva(configOrCva)
|
|
1084
1493
|
|
|
1085
1494
|
return function ${componentName}(props) {
|
|
1086
1495
|
const mergedProps = mergeProps({ as: element }, props)
|
|
1087
1496
|
|
|
1088
|
-
const [localProps,
|
|
1497
|
+
const [localProps, variantProps, styleProps, htmlProps, elementProps] = splitProps(
|
|
1089
1498
|
mergedProps,
|
|
1090
1499
|
['as', 'class'],
|
|
1091
|
-
allCssProperties,
|
|
1092
1500
|
cvaFn.variantKeys,
|
|
1501
|
+
allCssProperties,
|
|
1093
1502
|
normalizeHTMLProps.keys
|
|
1094
1503
|
)
|
|
1095
|
-
|
|
1096
|
-
|
|
1504
|
+
|
|
1505
|
+
function recipeClass() {
|
|
1506
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1507
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1508
|
+
return cx(cvaFn(variantProps), css(styles), localProps.class)
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
function cvaClass() {
|
|
1097
1512
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1098
1513
|
const cvaStyles = cvaFn.resolve(variantProps)
|
|
1099
1514
|
const styles = assignCss(cvaStyles, propStyles, cssStyles)
|
|
1100
1515
|
return cx(css(styles), localProps.class)
|
|
1101
1516
|
}
|
|
1102
1517
|
|
|
1518
|
+
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1519
|
+
|
|
1103
1520
|
return createComponent(
|
|
1104
1521
|
Dynamic,
|
|
1105
1522
|
mergeProps(
|
|
@@ -1121,13 +1538,13 @@ function generateSolidJsxFactory(ctx) {
|
|
|
1121
1538
|
function createJsxFactory() {
|
|
1122
1539
|
const cache = new Map()
|
|
1123
1540
|
|
|
1124
|
-
return new Proxy(
|
|
1541
|
+
return new Proxy(styledFn, {
|
|
1125
1542
|
apply(_, __, args) {
|
|
1126
|
-
return
|
|
1543
|
+
return styledFn(...args)
|
|
1127
1544
|
},
|
|
1128
1545
|
get(_, el) {
|
|
1129
1546
|
if (!cache.has(el)) {
|
|
1130
|
-
cache.set(el,
|
|
1547
|
+
cache.set(el, styledFn(el))
|
|
1131
1548
|
}
|
|
1132
1549
|
return cache.get(el)
|
|
1133
1550
|
},
|
|
@@ -1140,8 +1557,8 @@ function generateSolidJsxFactory(ctx) {
|
|
|
1140
1557
|
}
|
|
1141
1558
|
|
|
1142
1559
|
// src/artifacts/solid-jsx/pattern.ts
|
|
1143
|
-
import { outdent as
|
|
1144
|
-
import { match as
|
|
1560
|
+
import { outdent as outdent20 } from "outdent";
|
|
1561
|
+
import { match as match5 } from "ts-pattern";
|
|
1145
1562
|
function generateSolidJsxPattern(ctx) {
|
|
1146
1563
|
const { typeName, factoryName } = ctx.jsx;
|
|
1147
1564
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1149,20 +1566,21 @@ function generateSolidJsxPattern(ctx) {
|
|
|
1149
1566
|
const { description, jsxElement = "div" } = pattern.config;
|
|
1150
1567
|
return {
|
|
1151
1568
|
name: dashName,
|
|
1152
|
-
js:
|
|
1569
|
+
js: outdent20`
|
|
1153
1570
|
import { splitProps, mergeProps } from 'solid-js'
|
|
1154
1571
|
import { createComponent } from 'solid-js/web'
|
|
1155
1572
|
${ctx.file.import(factoryName, "./factory")}
|
|
1156
1573
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1157
1574
|
|
|
1158
1575
|
export function ${jsxName}(props) {
|
|
1159
|
-
${
|
|
1576
|
+
${match5(props.length).with(
|
|
1160
1577
|
0,
|
|
1161
|
-
() =>
|
|
1162
|
-
|
|
1578
|
+
() => outdent20`
|
|
1579
|
+
const styleProps = ${styleFnName}()
|
|
1580
|
+
return createComponent(${factoryName}.${jsxElement}, mergeProps(styleProps, props))
|
|
1163
1581
|
`
|
|
1164
1582
|
).otherwise(
|
|
1165
|
-
() =>
|
|
1583
|
+
() => outdent20`
|
|
1166
1584
|
const [patternProps, restProps] = splitProps(props, [${props.map((v) => JSON.stringify(v)).join(", ")}]);
|
|
1167
1585
|
const styleProps = ${styleFnName}(patternProps)
|
|
1168
1586
|
return createComponent(${factoryName}.${jsxElement}, mergeProps(styleProps, restProps))
|
|
@@ -1170,7 +1588,7 @@ function generateSolidJsxPattern(ctx) {
|
|
|
1170
1588
|
)}
|
|
1171
1589
|
}
|
|
1172
1590
|
`,
|
|
1173
|
-
dts:
|
|
1591
|
+
dts: outdent20`
|
|
1174
1592
|
import { Component } from 'solid-js'
|
|
1175
1593
|
import { ${upperName}Properties } from '../patterns/${dashName}'
|
|
1176
1594
|
import { ${typeName} } from '../types/jsx'
|
|
@@ -1185,18 +1603,18 @@ function generateSolidJsxPattern(ctx) {
|
|
|
1185
1603
|
}
|
|
1186
1604
|
|
|
1187
1605
|
// src/artifacts/solid-jsx/types.ts
|
|
1188
|
-
import { outdent as
|
|
1606
|
+
import { outdent as outdent21 } from "outdent";
|
|
1189
1607
|
function generateSolidJsxTypes(ctx) {
|
|
1190
1608
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1191
1609
|
return {
|
|
1192
|
-
jsxFactory:
|
|
1610
|
+
jsxFactory: outdent21`
|
|
1193
1611
|
import type { ${upperName} } from '../types/jsx'
|
|
1194
1612
|
export declare const ${factoryName}: ${upperName}
|
|
1195
1613
|
`,
|
|
1196
|
-
jsxType:
|
|
1197
|
-
import type {
|
|
1198
|
-
import type { JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1199
|
-
import type { RecipeDefinition,
|
|
1614
|
+
jsxType: outdent21`
|
|
1615
|
+
import type { ComponentProps, Component, JSX } from 'solid-js'
|
|
1616
|
+
import type { Assign, JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1617
|
+
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
|
|
1200
1618
|
|
|
1201
1619
|
type Dict = Record<string, unknown>
|
|
1202
1620
|
|
|
@@ -1207,9 +1625,20 @@ export type ${componentName}<T extends ElementType, P extends Dict = {}> = {
|
|
|
1207
1625
|
displayName?: string
|
|
1208
1626
|
}
|
|
1209
1627
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1628
|
+
type RecipeFn = { __type: any }
|
|
1629
|
+
|
|
1630
|
+
interface JsxFactory {
|
|
1631
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1632
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>): ${componentName}<
|
|
1633
|
+
T,
|
|
1634
|
+
RecipeSelection<P>
|
|
1635
|
+
>
|
|
1636
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1640
|
+
|
|
1641
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1213
1642
|
|
|
1214
1643
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
1215
1644
|
`
|
|
@@ -1217,18 +1646,18 @@ export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>,
|
|
|
1217
1646
|
}
|
|
1218
1647
|
|
|
1219
1648
|
// src/artifacts/vue-jsx/jsx.ts
|
|
1220
|
-
import { outdent as
|
|
1649
|
+
import { outdent as outdent22 } from "outdent";
|
|
1221
1650
|
function generateVueJsxFactory(ctx) {
|
|
1222
1651
|
const { factoryName } = ctx.jsx;
|
|
1223
1652
|
return {
|
|
1224
|
-
js:
|
|
1653
|
+
js: outdent22`
|
|
1225
1654
|
import { defineComponent, h, computed } from 'vue'
|
|
1226
1655
|
${ctx.file.import("css, cx, cva, assignCss", "../css/index")}
|
|
1227
1656
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1228
1657
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1229
1658
|
|
|
1230
|
-
function
|
|
1231
|
-
const cvaFn = configOrCva.__cva__ ? configOrCva : cva(configOrCva)
|
|
1659
|
+
function styledFn(Dynamic, configOrCva = {}) {
|
|
1660
|
+
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1232
1661
|
|
|
1233
1662
|
return defineComponent({
|
|
1234
1663
|
name: \`${factoryName}.\${Dynamic}\`,
|
|
@@ -1236,19 +1665,28 @@ function generateVueJsxFactory(ctx) {
|
|
|
1236
1665
|
props: { as: { type: [String, Object], default: Dynamic } },
|
|
1237
1666
|
setup(props, { slots, attrs }) {
|
|
1238
1667
|
const splittedProps = computed(() => {
|
|
1239
|
-
return splitProps(attrs,
|
|
1668
|
+
return splitProps(attrs, cvaFn.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1240
1669
|
})
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
const [
|
|
1670
|
+
|
|
1671
|
+
const recipeClass = computed(() => {
|
|
1672
|
+
const [variantProps, styleProps, _htmlProps, elementProps] = splittedProps.value
|
|
1673
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1674
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1675
|
+
return cx(cvaFn(variantProps), css(styles), elementProps.className)
|
|
1676
|
+
})
|
|
1677
|
+
|
|
1678
|
+
const cvaClass = computed(() => {
|
|
1679
|
+
const [variantProps, styleProps, _htmlProps, elementProps] = splittedProps.value
|
|
1244
1680
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
return cx(css(styles), elementProps.className)
|
|
1681
|
+
const styles = assignCss(propStyles, cssStyles)
|
|
1682
|
+
return cx(cvaFn(variantProps), css(styles), elementProps.className)
|
|
1248
1683
|
})
|
|
1684
|
+
|
|
1685
|
+
const classes = configOrCva.__recipe__ ? recipeClass : cvaClass
|
|
1249
1686
|
|
|
1250
1687
|
return () => {
|
|
1251
1688
|
const [_styleProps, _variantProps, htmlProps, elementProps] = splittedProps.value
|
|
1689
|
+
|
|
1252
1690
|
return h(
|
|
1253
1691
|
props.as,
|
|
1254
1692
|
{
|
|
@@ -1266,13 +1704,13 @@ function generateVueJsxFactory(ctx) {
|
|
|
1266
1704
|
function createJsxFactory() {
|
|
1267
1705
|
const cache = new Map()
|
|
1268
1706
|
|
|
1269
|
-
return new Proxy(
|
|
1707
|
+
return new Proxy(styledFn, {
|
|
1270
1708
|
apply(_, __, args) {
|
|
1271
|
-
return
|
|
1709
|
+
return styledFn(...args)
|
|
1272
1710
|
},
|
|
1273
1711
|
get(_, el) {
|
|
1274
1712
|
if (!cache.has(el)) {
|
|
1275
|
-
cache.set(el,
|
|
1713
|
+
cache.set(el, styledFn(el))
|
|
1276
1714
|
}
|
|
1277
1715
|
return cache.get(el)
|
|
1278
1716
|
},
|
|
@@ -1285,19 +1723,61 @@ function generateVueJsxFactory(ctx) {
|
|
|
1285
1723
|
};
|
|
1286
1724
|
}
|
|
1287
1725
|
|
|
1726
|
+
// src/artifacts/vue-jsx/pattern.ts
|
|
1727
|
+
import { outdent as outdent23 } from "outdent";
|
|
1728
|
+
function generateVueJsxPattern(ctx) {
|
|
1729
|
+
const { typeName, factoryName } = ctx.jsx;
|
|
1730
|
+
return ctx.patterns.details.map((pattern) => {
|
|
1731
|
+
const { upperName, styleFnName, dashName, jsxName, props, blocklistType } = pattern;
|
|
1732
|
+
const { description, jsxElement = "div" } = pattern.config;
|
|
1733
|
+
const propList = props.map((v) => JSON.stringify(v)).join(", ");
|
|
1734
|
+
return {
|
|
1735
|
+
name: dashName,
|
|
1736
|
+
js: outdent23`
|
|
1737
|
+
import { defineComponent, h, computed } from 'vue'
|
|
1738
|
+
${ctx.file.import(factoryName, "./factory")}
|
|
1739
|
+
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1740
|
+
|
|
1741
|
+
export const ${jsxName} = defineComponent({
|
|
1742
|
+
name: '${jsxName}',
|
|
1743
|
+
inheritAttrs: false,
|
|
1744
|
+
props: [${propList}],
|
|
1745
|
+
setup(props, { attrs, slots }) {
|
|
1746
|
+
const styleProps = computed(() => ${styleFnName}(props))
|
|
1747
|
+
return () => {
|
|
1748
|
+
const computedProps = { ...styleProps.value, ...attrs }
|
|
1749
|
+
return h(${factoryName}.${jsxElement}, computedProps, slots)
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
})
|
|
1753
|
+
`,
|
|
1754
|
+
dts: outdent23`
|
|
1755
|
+
import { FunctionalComponent } from 'vue'
|
|
1756
|
+
import { ${upperName}Properties } from '../patterns/${dashName}'
|
|
1757
|
+
import { ${typeName} } from '../types/jsx'
|
|
1758
|
+
|
|
1759
|
+
export type ${upperName}Props = ${upperName}Properties & Omit<${typeName}<'${jsxElement}'>, keyof ${upperName}Properties ${blocklistType}>
|
|
1760
|
+
|
|
1761
|
+
${description ? `/** ${description} */` : ""}
|
|
1762
|
+
export declare const ${jsxName}: FunctionalComponent<${upperName}Props>
|
|
1763
|
+
`
|
|
1764
|
+
};
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1288
1768
|
// src/artifacts/vue-jsx/types.ts
|
|
1289
|
-
import { outdent as
|
|
1769
|
+
import { outdent as outdent24 } from "outdent";
|
|
1290
1770
|
function generateVueJsxTypes(ctx) {
|
|
1291
1771
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1292
1772
|
return {
|
|
1293
|
-
jsxFactory:
|
|
1773
|
+
jsxFactory: outdent24`
|
|
1294
1774
|
import { ${upperName} } from '../types/jsx'
|
|
1295
1775
|
export declare const ${factoryName}: ${upperName}
|
|
1296
1776
|
`,
|
|
1297
|
-
jsxType:
|
|
1777
|
+
jsxType: outdent24`
|
|
1298
1778
|
import type { Component, FunctionalComponent } from 'vue'
|
|
1299
|
-
import type { JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1300
|
-
import type { RecipeDefinition,
|
|
1779
|
+
import type { Assign, JsxStyleProps, JsxHTMLProps } from './system-types'
|
|
1780
|
+
import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
|
|
1301
1781
|
|
|
1302
1782
|
type IntrinsicElement =
|
|
1303
1783
|
| 'a'
|
|
@@ -1430,9 +1910,20 @@ type IntrinsicElement =
|
|
|
1430
1910
|
JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>
|
|
1431
1911
|
>
|
|
1432
1912
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1913
|
+
type RecipeFn = { __type: any }
|
|
1914
|
+
|
|
1915
|
+
interface JsxFactory {
|
|
1916
|
+
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1917
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>): ${componentName}<
|
|
1918
|
+
T,
|
|
1919
|
+
RecipeSelection<P>
|
|
1920
|
+
>
|
|
1921
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P): ${componentName}<T, P['__type']>
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
type JsxElements = { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
1925
|
+
|
|
1926
|
+
export type ${upperName} = JsxFactory & JsxElements
|
|
1436
1927
|
|
|
1437
1928
|
export type ${typeName}<T extends ElementType> = JsxHTMLProps<ComponentProps<T>, JsxStyleProps>
|
|
1438
1929
|
`
|
|
@@ -1444,7 +1935,8 @@ var typesMap = {
|
|
|
1444
1935
|
react: generateReactJsxTypes,
|
|
1445
1936
|
preact: generatePreactJsxTypes,
|
|
1446
1937
|
solid: generateSolidJsxTypes,
|
|
1447
|
-
vue: generateVueJsxTypes
|
|
1938
|
+
vue: generateVueJsxTypes,
|
|
1939
|
+
qwik: generateQwikJsxTypes
|
|
1448
1940
|
};
|
|
1449
1941
|
function generateJsxTypes(ctx) {
|
|
1450
1942
|
if (!ctx.jsx.framework)
|
|
@@ -1455,7 +1947,8 @@ var factoryMap = {
|
|
|
1455
1947
|
react: generateReactJsxFactory,
|
|
1456
1948
|
solid: generateSolidJsxFactory,
|
|
1457
1949
|
preact: generatePreactJsxFactory,
|
|
1458
|
-
vue: generateVueJsxFactory
|
|
1950
|
+
vue: generateVueJsxFactory,
|
|
1951
|
+
qwik: generateQwikJsxFactory
|
|
1459
1952
|
};
|
|
1460
1953
|
function generateJsxFactory(ctx) {
|
|
1461
1954
|
if (!ctx.jsx.framework)
|
|
@@ -1466,7 +1959,8 @@ var patternMap = {
|
|
|
1466
1959
|
react: generateReactJsxPattern,
|
|
1467
1960
|
solid: generateSolidJsxPattern,
|
|
1468
1961
|
preact: generatePreactJsxPattern,
|
|
1469
|
-
vue:
|
|
1962
|
+
vue: generateVueJsxPattern,
|
|
1963
|
+
qwik: generateQwikJsxPattern
|
|
1470
1964
|
};
|
|
1471
1965
|
function generateJsxPatterns(ctx) {
|
|
1472
1966
|
if (ctx.patterns.isEmpty() && !ctx.jsx.framework)
|
|
@@ -1521,22 +2015,22 @@ var csstype_d_ts_default = {
|
|
|
1521
2015
|
|
|
1522
2016
|
// src/artifacts/generated/system-types.d.ts.json
|
|
1523
2017
|
var system_types_d_ts_default = {
|
|
1524
|
-
content: "import type { ConditionalValue, Conditions, Nested } from './conditions'\nimport type { PropertiesFallback } from './csstype'\nimport type { SystemProperties, CssVarProperties } from './style-props'\n\ntype String = string & {}\ntype Number = number & {}\n\n/* -----------------------------------------------------------------------------\n * Native css properties\n * -----------------------------------------------------------------------------*/\n\nexport type CssProperty = keyof PropertiesFallback\n\nexport type CssProperties = PropertiesFallback<String | Number> & CssVarProperties\n\nexport type CssKeyframes = {\n [name: string]: {\n [time: string]: CssProperties\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Conditional css properties\n * -----------------------------------------------------------------------------*/\n\ntype MinimalNested<P> = {\n [K in keyof Conditions]?: Nested<P>\n}\n\ntype GenericProperties = {\n [key: string]: ConditionalValue<String | Number | boolean>\n}\n\n/* -----------------------------------------------------------------------------\n * Native css props\n * -----------------------------------------------------------------------------*/\n\nexport type NestedCssProperties = Nested<CssProperties>\n\nexport type SystemStyleObject = Nested<
|
|
2018
|
+
content: "import type { ConditionalValue, Conditions, Nested } from './conditions'\nimport type { PropertiesFallback } from './csstype'\nimport type { SystemProperties, CssVarProperties } from './style-props'\n\ntype String = string & {}\ntype Number = number & {}\n\n/* -----------------------------------------------------------------------------\n * Native css properties\n * -----------------------------------------------------------------------------*/\n\nexport type CssProperty = keyof PropertiesFallback\n\nexport type CssProperties = PropertiesFallback<String | Number> & CssVarProperties\n\nexport type CssKeyframes = {\n [name: string]: {\n [time: string]: CssProperties\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Conditional css properties\n * -----------------------------------------------------------------------------*/\n\ntype MinimalNested<P> = {\n [K in keyof Conditions]?: Nested<P>\n}\n\ntype GenericProperties = {\n [key: string]: ConditionalValue<String | Number | boolean>\n}\n\n/* -----------------------------------------------------------------------------\n * Native css props\n * -----------------------------------------------------------------------------*/\n\nexport type NestedCssProperties = Nested<CssProperties>\n\nexport type SystemStyleObject = Nested<SystemProperties & CssVarProperties>\n\nexport type GlobalStyleObject = {\n [selector: string]: SystemStyleObject\n}\n\nexport type CompositionStyleObject<Property extends string> = Nested<{\n [K in Property]?: K extends keyof SystemStyleObject ? SystemStyleObject[K] : unknown\n}>\n\n/* -----------------------------------------------------------------------------\n * Jsx style props\n * -----------------------------------------------------------------------------*/\n\nexport type JsxStyleProps = SystemProperties &\n MinimalNested<SystemStyleObject> & {\n css?: SystemStyleObject\n }\n\ntype Assign<T, U> = Omit<T, keyof U> & U\n\nexport type PatchedHTMLProps = {\n htmlSize?: string | number\n htmlWidth?: string | number\n htmlHeight?: string | number\n htmlTranslate?: 'yes' | 'no' | undefined\n htmlContent?: string\n}\n\nexport type OmittedHTMLProps = 'color' | 'translate' | 'transition' | 'width' | 'height' | 'size' | 'content'\n\ntype WithHTMLProps<T> = Omit<T, OmittedHTMLProps> & PatchedHTMLProps\n\nexport type JsxHTMLProps<T extends Record<string, any>, P extends Record<string, any> = {}> = Assign<\n WithHTMLProps<T>,\n P\n>\n"
|
|
1525
2019
|
};
|
|
1526
2020
|
|
|
1527
2021
|
// src/artifacts/generated/composition.d.ts.json
|
|
1528
2022
|
var composition_d_ts_default = {
|
|
1529
|
-
content: "import type { CompositionStyleObject } from './system-types'\n\ntype Recursive<T> = {\n [key: string]: Recursive<T> | T\n}\n\nexport type Token<Value = any> = {\n value: Value\n description?: string\n}\n\n/* -----------------------------------------------------------------------------\n * Text styles\n * -----------------------------------------------------------------------------*/\n\ntype TextStyleProperty =\n | 'fontSize'\n | 'fontSizeAdjust'\n | 'fontVariationSettings'\n | 'fontVariantPosition'\n | 'fontVariantCaps'\n | 'fontVariantNumeric'\n | 'fontVariantAlternates'\n | 'fontVariantLigatures'\n | 'fontFamily'\n | 'fontWeight'\n | 'fontSynthesis'\n | 'fontStyle'\n | 'fontVariant'\n | 'lineHeight'\n | 'letterSpacing'\n | 'textDecoration'\n | 'textTransform'\n | 'textIndent'\n | 'textDecorationColor'\n | 'textDecorationLine'\n | 'textDecorationStyle'\n | 'textEmphasisColor'\n | 'textEmphasisPosition'\n | 'textEmphasisStyle'\n | 'hyphenateCharacter'\n | 'textOrientation'\n | 'textOverflow'\n | 'textRendering'\n\nexport type TextStyle = CompositionStyleObject<TextStyleProperty>\n\nexport type TextStyles = Recursive<Token<TextStyle>>\n\n/* -----------------------------------------------------------------------------\n * Layer styles\n * -----------------------------------------------------------------------------*/\n\ntype Placement =\n | 'Top'\n | 'Right'\n | 'Bottom'\n | 'Left'\n | 'Inline'\n | 'Block'\n | 'InlineStart'\n | 'InlineEnd'\n | 'BlockStart'\n | 'BlockEnd'\n\ntype Radius =\n | `Top${'Right' | 'Left'
|
|
2023
|
+
content: "import type { CompositionStyleObject } from './system-types'\n\ntype Recursive<T> = {\n [key: string]: Recursive<T> | T\n}\n\nexport type Token<Value = any> = {\n value: Value\n description?: string\n}\n\n/* -----------------------------------------------------------------------------\n * Text styles\n * -----------------------------------------------------------------------------*/\n\ntype TextStyleProperty =\n | 'fontSize'\n | 'fontSizeAdjust'\n | 'fontVariationSettings'\n | 'fontVariantPosition'\n | 'fontVariantCaps'\n | 'fontVariantNumeric'\n | 'fontVariantAlternates'\n | 'fontVariantLigatures'\n | 'fontFamily'\n | 'fontWeight'\n | 'fontSynthesis'\n | 'fontStyle'\n | 'fontVariant'\n | 'lineHeight'\n | 'letterSpacing'\n | 'textDecoration'\n | 'textTransform'\n | 'textIndent'\n | 'textDecorationColor'\n | 'textDecorationLine'\n | 'textDecorationStyle'\n | 'textEmphasisColor'\n | 'textEmphasisPosition'\n | 'textEmphasisStyle'\n | 'hyphenateCharacter'\n | 'textOrientation'\n | 'textOverflow'\n | 'textRendering'\n\nexport type TextStyle = CompositionStyleObject<TextStyleProperty>\n\nexport type TextStyles = Recursive<Token<TextStyle>>\n\n/* -----------------------------------------------------------------------------\n * Layer styles\n * -----------------------------------------------------------------------------*/\n\ntype Placement =\n | 'Top'\n | 'Right'\n | 'Bottom'\n | 'Left'\n | 'Inline'\n | 'Block'\n | 'InlineStart'\n | 'InlineEnd'\n | 'BlockStart'\n | 'BlockEnd'\n\ntype Radius =\n | `Top${'Right' | 'Left'}`\n | `Bottom${'Right' | 'Left'}`\n | `Start${'Start' | 'End'}`\n | `End${'Start' | 'End'}`\n\ntype LayerStyleProperty =\n | 'background'\n | 'backgroundColor'\n | 'backgroundImage'\n | 'borderRadius'\n | 'border'\n | 'borderWidth'\n | 'borderColor'\n | 'borderStyle'\n | 'boxShadow'\n | 'filter'\n | 'backdropFilter'\n | 'transform'\n | 'color'\n | 'opacity'\n | 'backgroundBlendMode'\n | 'backgroundAttachment'\n | 'backgroundClip'\n | 'backgroundOrigin'\n | 'backgroundPosition'\n | 'backgroundRepeat'\n | 'backgroundSize'\n | `border${Placement}`\n | `border${Placement}Width`\n | 'borderRadius'\n | `border${Radius}Radius`\n | `border${Placement}Color`\n | `border${Placement}Style`\n | 'padding'\n | `padding${Placement}`\n\nexport type LayerStyle = CompositionStyleObject<LayerStyleProperty>\n\nexport type LayerStyles = Recursive<Token<LayerStyle>>\n\nexport type CompositionStyles = {\n textStyles: TextStyles\n layerStyles: LayerStyles\n}\n"
|
|
1530
2024
|
};
|
|
1531
2025
|
|
|
1532
2026
|
// src/artifacts/generated/recipe.d.ts.json
|
|
1533
2027
|
var recipe_d_ts_default = {
|
|
1534
|
-
content: "import type { SystemStyleObject } from './system-types'\n\ntype Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<
|
|
2028
|
+
content: "import type { SystemStyleObject } from './system-types'\n\ntype Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>\n\nexport type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T\n ? {}\n : {\n [K in keyof T]?: StringToBoolean<keyof T[K]>\n }\n\nexport type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string\n\nexport type RecipeVariantProps<T extends RecipeVariantFn<RecipeVariantRecord>> = Pretty<Parameters<T>[0]>\n\ntype RecipeVariantMap<T extends RecipeVariantRecord> = {\n [K in keyof T]: Array<keyof T[K]>\n}\n\nexport type RecipeRuntimeFn<T extends RecipeVariantRecord> = RecipeVariantFn<T> & {\n __type: RecipeSelection<T>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n resolve: (props: RecipeSelection<T>) => SystemStyleObject\n config: RecipeConfig<T>\n splitVariantProps<Props extends RecipeSelection<T>>(\n props: Props,\n ): [RecipeSelection<T>, Pretty<Omit<Props, keyof RecipeVariantRecord>>]\n}\n\nexport type RecipeCompoundSelection<T extends RecipeVariantRecord> = {\n [K in keyof T]?: StringToBoolean<keyof T[K]> | Array<StringToBoolean<keyof T[K]>>\n}\n\nexport type RecipeCompoundVariant<T extends RecipeVariantRecord> = RecipeCompoundSelection<T> & {\n css: SystemStyleObject\n}\n\nexport type RecipeDefinition<T extends RecipeVariantRecord> = {\n /**\n * The base styles of the recipe.\n */\n base?: SystemStyleObject\n /**\n * The multi-variant styles of the recipe.\n */\n variants?: T | RecipeVariantRecord\n /**\n * The default variants of the recipe.\n */\n defaultVariants?: RecipeSelection<T>\n /**\n * The styles to apply when a combination of variants is selected.\n */\n compoundVariants?: Array<RecipeCompoundVariant<T>>\n}\n\nexport type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>\n\nexport type RecipeConfig<T extends RecipeVariantRecord = RecipeVariantRecord> = RecipeDefinition<T> & {\n /**\n * The name of the recipe.\n */\n name: string\n /**\n * The description of the recipe. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The jsx elements to track for this recipe. Can be string or Regexp.\n *\n * @default capitalize(recipe.name)\n * @example ['Button', 'Link', /Button$/]\n */\n jsx?: Array<string | RegExp>\n}\n"
|
|
1535
2029
|
};
|
|
1536
2030
|
|
|
1537
2031
|
// src/artifacts/generated/pattern.d.ts.json
|
|
1538
2032
|
var pattern_d_ts_default = {
|
|
1539
|
-
content: "import type { CssProperty, SystemStyleObject } from './system-types'\nimport type { TokenCategory } from '../tokens'\n\ntype Primitive = string | number | boolean | null | undefined\ntype LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)\n\nexport type PatternProperty =\n | { type: 'property'; value: CssProperty }\n | { type: 'enum'; value: string[] }\n | { type: 'token'; value: TokenCategory; property?: CssProperty }\n | { type: 'string' | 'boolean' | 'number' }\n\nexport type PatternHelpers = {\n map: (value: any, fn: (value: string) => string | undefined) => any\n}\n\nexport type PatternConfig<T> = {\n /**\n * The description of the pattern. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The JSX element rendered by the pattern\n * @default 'div'\n */\n jsxElement?: string\n /**\n * The properties of the pattern.\n */\n properties: T
|
|
2033
|
+
content: "import type { CssProperty, SystemStyleObject } from './system-types'\nimport type { TokenCategory } from '../tokens'\n\ntype Primitive = string | number | boolean | null | undefined\ntype LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)\n\nexport type PatternProperty =\n | { type: 'property'; value: CssProperty }\n | { type: 'enum'; value: string[] }\n | { type: 'token'; value: TokenCategory; property?: CssProperty }\n | { type: 'string' | 'boolean' | 'number' }\n\nexport type PatternHelpers = {\n map: (value: any, fn: (value: string) => string | undefined) => any\n}\n\ntype PatternProperties = Record<string, PatternProperty>\n\ntype Props<T> = Record<LiteralUnion<keyof T>, any>\n\nexport type PatternConfig<T extends PatternProperties = PatternProperties> = {\n /**\n * The description of the pattern. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The JSX element rendered by the pattern\n * @default 'div'\n */\n jsxElement?: string\n /**\n * The properties of the pattern.\n */\n properties: T\n /**\n * The css object this pattern will generate.\n */\n transform?: (props: Props<T>, helpers: PatternHelpers) => SystemStyleObject\n /**\n * The jsx element name this pattern will generate.\n */\n jsx?: string\n /**\n * Whether to only generate types for the specified properties.\n * This will disallow css properties\n */\n strict?: boolean\n /**\n * @experimental\n * Disallow certain css properties for this pattern\n */\n blocklist?: LiteralUnion<CssProperty>[]\n}\n"
|
|
1540
2034
|
};
|
|
1541
2035
|
|
|
1542
2036
|
// src/artifacts/generated/parts.d.ts.json
|
|
@@ -1563,38 +2057,38 @@ function getGeneratedTypes() {
|
|
|
1563
2057
|
}
|
|
1564
2058
|
|
|
1565
2059
|
// src/artifacts/types/main.ts
|
|
1566
|
-
import { outdent as
|
|
2060
|
+
import { outdent as outdent25 } from "outdent";
|
|
1567
2061
|
var generateTypesEntry = () => ({
|
|
1568
|
-
global:
|
|
1569
|
-
import {
|
|
2062
|
+
global: outdent25`
|
|
2063
|
+
import { RecipeVariantRecord, RecipeConfig } from './recipe'
|
|
1570
2064
|
import { Parts } from './parts'
|
|
1571
|
-
import {
|
|
2065
|
+
import { PatternConfig } from './pattern'
|
|
1572
2066
|
import { GlobalStyleObject, SystemStyleObject } from './system-types'
|
|
1573
2067
|
import { CompositionStyles } from './composition'
|
|
1574
2068
|
|
|
1575
2069
|
declare module '@pandacss/dev' {
|
|
1576
|
-
export function defineRecipe<V extends RecipeVariantRecord>(config: RecipeConfig<V>):
|
|
2070
|
+
export function defineRecipe<V extends RecipeVariantRecord>(config: RecipeConfig<V>): RecipeConfig
|
|
1577
2071
|
export function defineStyles(definition: SystemStyleObject): SystemStyleObject
|
|
1578
2072
|
export function defineGlobalStyles(definition: GlobalStyleObject): GlobalStyleObject
|
|
1579
2073
|
export function defineTextStyles(definition: CompositionStyles['textStyles']): CompositionStyles['textStyles']
|
|
1580
2074
|
export function defineLayerStyles(definition: CompositionStyles['layerStyles']): CompositionStyles['layerStyles']
|
|
1581
|
-
export function definePattern<
|
|
2075
|
+
export function definePattern<T>(config: PatternConfig<T>): PatternConfig
|
|
1582
2076
|
export function defineParts<T extends Parts>(parts: T): (config: Partial<Record<keyof T, SystemStyleObject>>) => Partial<Record<keyof T, SystemStyleObject>>;
|
|
1583
2077
|
}
|
|
1584
2078
|
`,
|
|
1585
|
-
index:
|
|
2079
|
+
index: outdent25`
|
|
1586
2080
|
import './global'
|
|
1587
2081
|
export { ConditionalValue } from './conditions'
|
|
1588
2082
|
export { GlobalStyleObject, JsxStyleProps, SystemStyleObject } from './system-types'
|
|
1589
2083
|
|
|
1590
2084
|
`,
|
|
1591
|
-
helpers:
|
|
2085
|
+
helpers: outdent25`
|
|
1592
2086
|
export type Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never
|
|
1593
2087
|
`
|
|
1594
2088
|
});
|
|
1595
2089
|
|
|
1596
2090
|
// src/artifacts/types/prop-types.ts
|
|
1597
|
-
import { outdent as
|
|
2091
|
+
import { outdent as outdent26 } from "outdent";
|
|
1598
2092
|
function generatePropTypes(ctx) {
|
|
1599
2093
|
const {
|
|
1600
2094
|
config: { strictTokens },
|
|
@@ -1602,7 +2096,7 @@ function generatePropTypes(ctx) {
|
|
|
1602
2096
|
} = ctx;
|
|
1603
2097
|
const strictText = `${strictTokens ? "" : " | CssValue<T>"}`;
|
|
1604
2098
|
const result = [
|
|
1605
|
-
|
|
2099
|
+
outdent26`
|
|
1606
2100
|
import type { ConditionalValue } from './conditions';
|
|
1607
2101
|
import type { CssProperties } from './system-types'
|
|
1608
2102
|
import type { Tokens } from '../tokens'
|
|
@@ -1625,7 +2119,7 @@ function generatePropTypes(ctx) {
|
|
|
1625
2119
|
result.push(` ${key}: Shorthand<${JSON.stringify(value)}>;`);
|
|
1626
2120
|
});
|
|
1627
2121
|
result.push("}");
|
|
1628
|
-
return
|
|
2122
|
+
return outdent26`
|
|
1629
2123
|
${result.join("\n")}
|
|
1630
2124
|
|
|
1631
2125
|
export type PropertyValue<T extends string> = T extends keyof PropertyTypes
|
|
@@ -1638,10 +2132,10 @@ function generatePropTypes(ctx) {
|
|
|
1638
2132
|
|
|
1639
2133
|
// src/artifacts/types/style-props.ts
|
|
1640
2134
|
import { allCssProperties } from "@pandacss/is-valid-prop";
|
|
1641
|
-
import
|
|
2135
|
+
import outdent27 from "outdent";
|
|
1642
2136
|
function generateStyleProps(ctx) {
|
|
1643
2137
|
const props = new Set(allCssProperties.concat(ctx.utility.keys()));
|
|
1644
|
-
return
|
|
2138
|
+
return outdent27`
|
|
1645
2139
|
import { ConditionalValue } from './conditions'
|
|
1646
2140
|
import { PropertyValue } from './prop-type'
|
|
1647
2141
|
import { Token } from '../tokens'
|
|
@@ -1658,7 +2152,7 @@ function generateStyleProps(ctx) {
|
|
|
1658
2152
|
|
|
1659
2153
|
// src/artifacts/types/token-types.ts
|
|
1660
2154
|
import { capitalize, unionType as unionType3 } from "@pandacss/shared";
|
|
1661
|
-
import { outdent as
|
|
2155
|
+
import { outdent as outdent28 } from "outdent";
|
|
1662
2156
|
import pluralize from "pluralize";
|
|
1663
2157
|
var categories = [
|
|
1664
2158
|
"zIndex",
|
|
@@ -1690,88 +2184,22 @@ function generateTokenTypes(ctx) {
|
|
|
1690
2184
|
if (tokens.isEmpty) {
|
|
1691
2185
|
result.add("[token: string]: string");
|
|
1692
2186
|
} else {
|
|
2187
|
+
const colorPaletteKeys = Object.keys(tokens.colorPalettes);
|
|
2188
|
+
if (colorPaletteKeys.length) {
|
|
2189
|
+
set.add(`export type ColorPalette = ${unionType3(Object.keys(tokens.colorPalettes))}`);
|
|
2190
|
+
}
|
|
1693
2191
|
for (const [key, value] of tokens.categoryMap.entries()) {
|
|
1694
2192
|
const typeName = capitalize(pluralize.singular(key));
|
|
1695
2193
|
set.add(`export type ${typeName}Token = ${unionType3(value.keys())}`);
|
|
1696
|
-
set.add(`export type ColorPalette = ${unionType3(Object.keys(tokens.colorPalettes))}`);
|
|
1697
2194
|
result.add(` ${key}: ${typeName}Token`);
|
|
1698
2195
|
}
|
|
1699
2196
|
}
|
|
1700
2197
|
result.add("} & { [token: string]: never }");
|
|
1701
2198
|
set.add(Array.from(result).join("\n"));
|
|
1702
2199
|
set.add(`export type TokenCategory = ${unionType3(categories)}`);
|
|
1703
|
-
return
|
|
2200
|
+
return outdent28.string(Array.from(set).join("\n\n"));
|
|
1704
2201
|
}
|
|
1705
2202
|
|
|
1706
|
-
// src/artifacts/css/global-css.ts
|
|
1707
|
-
var generateGlobalCss = (ctx) => {
|
|
1708
|
-
const { globalCss = {}, optimize = true } = ctx.config;
|
|
1709
|
-
const sheet = ctx.createSheet();
|
|
1710
|
-
sheet.processGlobalCss({
|
|
1711
|
-
":root": {
|
|
1712
|
-
"--made-with-panda": `'\u{1F43C}'`
|
|
1713
|
-
},
|
|
1714
|
-
"*, *::before, *::after, ::backdrop": {
|
|
1715
|
-
"--blur": "/*!*/ /*!*/",
|
|
1716
|
-
"--brightness": "/*!*/ /*!*/",
|
|
1717
|
-
"--contrast": "/*!*/ /*!*/",
|
|
1718
|
-
"--grayscale": "/*!*/ /*!*/",
|
|
1719
|
-
"--hue-rotate": "/*!*/ /*!*/",
|
|
1720
|
-
"--invert": "/*!*/ /*!*/",
|
|
1721
|
-
"--saturate": "/*!*/ /*!*/",
|
|
1722
|
-
"--sepia": "/*!*/ /*!*/",
|
|
1723
|
-
"--drop-shadow": "/*!*/ /*!*/",
|
|
1724
|
-
"--backdrop-blur": "/*!*/ /*!*/",
|
|
1725
|
-
"--backdrop-brightness": "/*!*/ /*!*/",
|
|
1726
|
-
"--backdrop-contrast": "/*!*/ /*!*/",
|
|
1727
|
-
"--backdrop-grayscale": "/*!*/ /*!*/",
|
|
1728
|
-
"--backdrop-hue-rotate": "/*!*/ /*!*/",
|
|
1729
|
-
"--backdrop-invert": "/*!*/ /*!*/",
|
|
1730
|
-
"--backdrop-opacity": "/*!*/ /*!*/",
|
|
1731
|
-
"--backdrop-saturate": "/*!*/ /*!*/",
|
|
1732
|
-
"--backdrop-sepia": "/*!*/ /*!*/",
|
|
1733
|
-
"--scroll-snap-strictness": "proximity",
|
|
1734
|
-
"--border-spacing-x": 0,
|
|
1735
|
-
"--border-spacing-y": 0,
|
|
1736
|
-
"--translate-x": 0,
|
|
1737
|
-
"--translate-y": 0,
|
|
1738
|
-
"--rotate": 0,
|
|
1739
|
-
"--skew-x": 0,
|
|
1740
|
-
"--skew-y": 0,
|
|
1741
|
-
"--scale-x": 1,
|
|
1742
|
-
"--scale-y": 1
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
sheet.processGlobalCss(globalCss);
|
|
1746
|
-
return sheet.toCss({ optimize });
|
|
1747
|
-
};
|
|
1748
|
-
|
|
1749
|
-
// src/artifacts/css/static-css.ts
|
|
1750
|
-
import { getStaticCss } from "@pandacss/core";
|
|
1751
|
-
var generateStaticCss = (ctx) => {
|
|
1752
|
-
const { config, createSheet, utility, recipes } = ctx;
|
|
1753
|
-
const { staticCss = {}, theme = {}, optimize = true } = config;
|
|
1754
|
-
const sheet = createSheet();
|
|
1755
|
-
const fn = getStaticCss(staticCss);
|
|
1756
|
-
const results = fn({
|
|
1757
|
-
breakpoints: Object.keys(theme.breakpoints ?? {}),
|
|
1758
|
-
getPropertyKeys: utility.getPropertyKeys,
|
|
1759
|
-
getRecipeKeys: (recipe) => recipes.details.find((detail) => detail.config.name === recipe)?.variantKeyMap ?? {}
|
|
1760
|
-
});
|
|
1761
|
-
results.css.forEach((css2) => {
|
|
1762
|
-
sheet.processAtomic(css2);
|
|
1763
|
-
});
|
|
1764
|
-
results.recipes.forEach((result) => {
|
|
1765
|
-
Object.entries(result).forEach(([name, value]) => {
|
|
1766
|
-
const recipeConfig = recipes.getConfig(name);
|
|
1767
|
-
if (!recipeConfig)
|
|
1768
|
-
return;
|
|
1769
|
-
sheet.processRecipe(recipeConfig, value);
|
|
1770
|
-
});
|
|
1771
|
-
});
|
|
1772
|
-
return sheet.toCss({ optimize });
|
|
1773
|
-
};
|
|
1774
|
-
|
|
1775
2203
|
// src/artifacts/index.ts
|
|
1776
2204
|
function setupHelpers(ctx) {
|
|
1777
2205
|
const code = generateHelpers();
|
|
@@ -1864,8 +2292,8 @@ function setupRecipes(ctx) {
|
|
|
1864
2292
|
return;
|
|
1865
2293
|
const indexFiles = files.filter((file) => !file.name.includes("create-recipe"));
|
|
1866
2294
|
const index = {
|
|
1867
|
-
js:
|
|
1868
|
-
dts:
|
|
2295
|
+
js: outdent29.string(indexFiles.map((file) => ctx.file.export(`./${file.name}`)).join("\n")),
|
|
2296
|
+
dts: outdent29.string(indexFiles.map((file) => `export * from './${file.name}'`).join("\n"))
|
|
1869
2297
|
};
|
|
1870
2298
|
return {
|
|
1871
2299
|
dir: ctx.paths.recipe,
|
|
@@ -1882,8 +2310,8 @@ function setupPatterns(ctx) {
|
|
|
1882
2310
|
if (!files)
|
|
1883
2311
|
return;
|
|
1884
2312
|
const index = {
|
|
1885
|
-
js:
|
|
1886
|
-
dts:
|
|
2313
|
+
js: outdent29.string(files.map((file) => ctx.file.export(`./${file.name}`)).join("\n")),
|
|
2314
|
+
dts: outdent29.string(files.map((file) => `export * from './${file.name}'`).join("\n"))
|
|
1887
2315
|
};
|
|
1888
2316
|
return {
|
|
1889
2317
|
dir: ctx.paths.pattern,
|
|
@@ -1903,13 +2331,13 @@ function setupJsx(ctx) {
|
|
|
1903
2331
|
const factory = generateJsxFactory(ctx);
|
|
1904
2332
|
const patterns = generateJsxPatterns(ctx);
|
|
1905
2333
|
const index = {
|
|
1906
|
-
js:
|
|
2334
|
+
js: outdent29`
|
|
1907
2335
|
${ctx.file.export("./factory")}
|
|
1908
|
-
${
|
|
2336
|
+
${outdent29.string(patterns.map((file) => ctx.file.export(`./${file.name}`)).join("\n"))}
|
|
1909
2337
|
`,
|
|
1910
|
-
dts:
|
|
2338
|
+
dts: outdent29`
|
|
1911
2339
|
export * from './factory'
|
|
1912
|
-
${
|
|
2340
|
+
${outdent29.string(patterns.map((file) => `export * from './${file.name}'`).join("\n"))}
|
|
1913
2341
|
export type { ${ctx.jsx.typeName} } from '../types/jsx'
|
|
1914
2342
|
`
|
|
1915
2343
|
};
|
|
@@ -1928,12 +2356,12 @@ function setupJsx(ctx) {
|
|
|
1928
2356
|
}
|
|
1929
2357
|
function setupCssIndex(ctx) {
|
|
1930
2358
|
const index = {
|
|
1931
|
-
js:
|
|
2359
|
+
js: outdent29`
|
|
1932
2360
|
${ctx.file.export("./css")}
|
|
1933
2361
|
${ctx.file.export("./cx")}
|
|
1934
2362
|
${ctx.file.export("./cva")}
|
|
1935
2363
|
`,
|
|
1936
|
-
dts:
|
|
2364
|
+
dts: outdent29`
|
|
1937
2365
|
export * from './css'
|
|
1938
2366
|
export * from './cx'
|
|
1939
2367
|
export * from './cva'
|
|
@@ -1948,9 +2376,11 @@ function setupCssIndex(ctx) {
|
|
|
1948
2376
|
};
|
|
1949
2377
|
}
|
|
1950
2378
|
function setupResetCss(ctx) {
|
|
1951
|
-
|
|
2379
|
+
const { preflight } = ctx.config;
|
|
2380
|
+
if (!preflight)
|
|
1952
2381
|
return;
|
|
1953
|
-
const
|
|
2382
|
+
const scope = isObject(preflight) ? preflight.scope : void 0;
|
|
2383
|
+
const code = generateResetCss(ctx, scope);
|
|
1954
2384
|
return { files: [{ file: "reset.css", code }] };
|
|
1955
2385
|
}
|
|
1956
2386
|
function setupGlobalCss(ctx) {
|
|
@@ -2006,10 +2436,10 @@ var generateFlattenedCss = (ctx) => (options) => {
|
|
|
2006
2436
|
const sheet = ctx.createSheet({
|
|
2007
2437
|
content: resolve ? [
|
|
2008
2438
|
generateGlobalCss(ctx),
|
|
2009
|
-
generateStaticCss(ctx),
|
|
2010
|
-
generateResetCss(),
|
|
2011
|
-
generateTokenCss(ctx),
|
|
2012
|
-
generateKeyframeCss(ctx)
|
|
2439
|
+
staticCss && generateStaticCss(ctx),
|
|
2440
|
+
preflight && generateResetCss(ctx),
|
|
2441
|
+
!ctx.tokens.isEmpty && generateTokenCss(ctx),
|
|
2442
|
+
keyframes && generateKeyframeCss(ctx)
|
|
2013
2443
|
].filter(Boolean).join("\n\n") : unresolved
|
|
2014
2444
|
});
|
|
2015
2445
|
sheet.append(...files);
|
|
@@ -2019,7 +2449,7 @@ var generateFlattenedCss = (ctx) => (options) => {
|
|
|
2019
2449
|
// src/artifacts/css/parser-css.ts
|
|
2020
2450
|
import { logger } from "@pandacss/logger";
|
|
2021
2451
|
import { pipe, tap, tryCatch } from "lil-fp/func";
|
|
2022
|
-
import { match as
|
|
2452
|
+
import { match as match6, P } from "ts-pattern";
|
|
2023
2453
|
var flattenStyles = (data) => Object.assign({}, data, { css: void 0 }, data.css ?? {});
|
|
2024
2454
|
var generateParserCss = (ctx) => (result) => pipe(
|
|
2025
2455
|
{ ...ctx, sheet: ctx.createSheet(), result },
|
|
@@ -2045,7 +2475,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
2045
2475
|
const recipeConfig = recipes.getConfig(name);
|
|
2046
2476
|
if (!recipeConfig)
|
|
2047
2477
|
continue;
|
|
2048
|
-
|
|
2478
|
+
match6(recipe).with({ type: "jsx-recipe", name: P.string }, ({ name: name2 }) => {
|
|
2049
2479
|
recipe.data.forEach((data) => {
|
|
2050
2480
|
const [recipeProps, styleProps] = recipes.splitProps(name2, flattenStyles(data));
|
|
2051
2481
|
sheet.processAtomic(styleProps);
|
|
@@ -2064,7 +2494,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
2064
2494
|
result2.pattern.forEach((patternSet, name) => {
|
|
2065
2495
|
try {
|
|
2066
2496
|
for (const pattern of patternSet) {
|
|
2067
|
-
|
|
2497
|
+
match6(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: name2 }) => {
|
|
2068
2498
|
pattern.data.forEach((data) => {
|
|
2069
2499
|
const fnName = patterns.getFnName(name2);
|
|
2070
2500
|
const styleProps = patterns.transform(fnName, flattenStyles(data));
|
|
@@ -2084,7 +2514,9 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
2084
2514
|
}),
|
|
2085
2515
|
tryCatch(
|
|
2086
2516
|
({ sheet, result: result2, config: { minify, optimize } }) => {
|
|
2087
|
-
|
|
2517
|
+
const css2 = !result2.isEmpty() ? sheet.toCss({ minify, optimize }) : void 0;
|
|
2518
|
+
ctx.hooks.callHook("parser:css", result2.filePath ?? "", css2);
|
|
2519
|
+
return css2;
|
|
2088
2520
|
},
|
|
2089
2521
|
(err) => {
|
|
2090
2522
|
logger.error("serializer:css", "Failed to serialize CSS: " + err);
|
|
@@ -2093,52 +2525,97 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
2093
2525
|
);
|
|
2094
2526
|
|
|
2095
2527
|
// src/engines/base.ts
|
|
2096
|
-
import {
|
|
2528
|
+
import {
|
|
2529
|
+
Conditions,
|
|
2530
|
+
Recipes,
|
|
2531
|
+
Stylesheet,
|
|
2532
|
+
Utility,
|
|
2533
|
+
assignCompositions
|
|
2534
|
+
} from "@pandacss/core";
|
|
2097
2535
|
import { isCssProperty } from "@pandacss/is-valid-prop";
|
|
2098
|
-
import { logger as logger2 } from "@pandacss/logger";
|
|
2099
2536
|
import { compact, mapObject, memo } from "@pandacss/shared";
|
|
2100
2537
|
import { TokenDictionary } from "@pandacss/token-dictionary";
|
|
2101
|
-
import {
|
|
2538
|
+
import { isBool, isStr } from "lil-fp";
|
|
2102
2539
|
import postcss3 from "postcss";
|
|
2103
|
-
var helpers = {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2540
|
+
var helpers = {
|
|
2541
|
+
map: mapObject
|
|
2542
|
+
};
|
|
2543
|
+
var getBaseEngine = (conf) => {
|
|
2544
|
+
const { config } = conf;
|
|
2545
|
+
const theme = config.theme ?? {};
|
|
2546
|
+
const hash = {
|
|
2547
|
+
tokens: isBool(config.hash) ? config.hash : config.hash?.cssVar,
|
|
2548
|
+
className: isBool(config.hash) ? config.hash : config.hash?.className
|
|
2549
|
+
};
|
|
2550
|
+
const prefix = {
|
|
2551
|
+
tokens: isStr(config.prefix) ? config.prefix : config.prefix?.cssVar,
|
|
2552
|
+
className: isStr(config.prefix) ? config.prefix : config.prefix?.className
|
|
2553
|
+
};
|
|
2554
|
+
const tokens = new TokenDictionary({
|
|
2555
|
+
breakpoints: theme.breakpoints,
|
|
2556
|
+
tokens: theme.tokens,
|
|
2557
|
+
semanticTokens: theme.semanticTokens,
|
|
2558
|
+
prefix: prefix.tokens,
|
|
2559
|
+
hash: hash.tokens
|
|
2560
|
+
});
|
|
2561
|
+
const utility = new Utility({
|
|
2562
|
+
prefix: prefix.className,
|
|
2563
|
+
tokens,
|
|
2564
|
+
config: config.utilities,
|
|
2565
|
+
separator: config.separator
|
|
2566
|
+
});
|
|
2567
|
+
const conditions = new Conditions({
|
|
2568
|
+
conditions: config.conditions,
|
|
2569
|
+
breakpoints: config.theme?.breakpoints
|
|
2570
|
+
});
|
|
2571
|
+
const { textStyles, layerStyles } = theme;
|
|
2572
|
+
const compositions = compact({
|
|
2573
|
+
textStyle: textStyles,
|
|
2574
|
+
layerStyle: layerStyles
|
|
2575
|
+
});
|
|
2576
|
+
const compositionContext = { conditions, utility };
|
|
2577
|
+
assignCompositions(compositions, compositionContext);
|
|
2578
|
+
const createSheetContext = () => ({
|
|
2579
|
+
root: postcss3.root(),
|
|
2580
|
+
conditions,
|
|
2581
|
+
utility,
|
|
2582
|
+
hash: hash.className,
|
|
2583
|
+
helpers
|
|
2584
|
+
});
|
|
2585
|
+
const createSheet = (options) => {
|
|
2586
|
+
const sheetContext = createSheetContext();
|
|
2587
|
+
return new Stylesheet(sheetContext, {
|
|
2588
|
+
content: options?.content,
|
|
2589
|
+
recipes: theme?.recipes
|
|
2139
2590
|
});
|
|
2140
|
-
}
|
|
2141
|
-
);
|
|
2591
|
+
};
|
|
2592
|
+
const recipeContext = createSheetContext();
|
|
2593
|
+
const recipes = new Recipes(theme?.recipes ?? {}, recipeContext);
|
|
2594
|
+
recipes.save();
|
|
2595
|
+
const properties = Array.from(/* @__PURE__ */ new Set(["css", ...utility.keys(), ...conditions.keys()]));
|
|
2596
|
+
const propertyMap = new Map(properties.map((prop) => [prop, true]));
|
|
2597
|
+
const isValidProperty = memo((key) => {
|
|
2598
|
+
return propertyMap.has(key) || isCssProperty(key);
|
|
2599
|
+
});
|
|
2600
|
+
const studio = {
|
|
2601
|
+
outdir: `${config.outdir}-studio`,
|
|
2602
|
+
...conf.config.studio
|
|
2603
|
+
};
|
|
2604
|
+
return {
|
|
2605
|
+
...conf,
|
|
2606
|
+
studio,
|
|
2607
|
+
hash,
|
|
2608
|
+
prefix,
|
|
2609
|
+
tokens,
|
|
2610
|
+
utility,
|
|
2611
|
+
properties,
|
|
2612
|
+
isValidProperty,
|
|
2613
|
+
recipes,
|
|
2614
|
+
conditions,
|
|
2615
|
+
createSheetContext,
|
|
2616
|
+
createSheet
|
|
2617
|
+
};
|
|
2618
|
+
};
|
|
2142
2619
|
|
|
2143
2620
|
// src/engines/jsx.ts
|
|
2144
2621
|
import { capitalize as capitalize2 } from "@pandacss/shared";
|
|
@@ -2172,20 +2649,20 @@ var getPathEngine = ({ cwd, emitPackage, outdir }) => {
|
|
|
2172
2649
|
|
|
2173
2650
|
// src/engines/pattern.ts
|
|
2174
2651
|
import { capitalize as capitalize3, dashCase, mapObject as mapObject2, uncapitalize } from "@pandacss/shared";
|
|
2175
|
-
import { Obj
|
|
2652
|
+
import { Obj, pipe as pipe2 } from "lil-fp";
|
|
2176
2653
|
var helpers2 = { map: mapObject2 };
|
|
2177
2654
|
var getPatternEngine = (config) => {
|
|
2178
|
-
return
|
|
2655
|
+
return pipe2(
|
|
2179
2656
|
{ patterns: config.patterns ?? {} },
|
|
2180
|
-
|
|
2657
|
+
Obj.bind("getConfig", ({ patterns }) => {
|
|
2181
2658
|
return (name) => patterns[name];
|
|
2182
2659
|
}),
|
|
2183
|
-
|
|
2660
|
+
Obj.bind("transform", ({ getConfig }) => {
|
|
2184
2661
|
return (name, data) => {
|
|
2185
2662
|
return getConfig(name)?.transform?.(data, helpers2) ?? {};
|
|
2186
2663
|
};
|
|
2187
2664
|
}),
|
|
2188
|
-
|
|
2665
|
+
Obj.bind("getNames", ({ getConfig }) => (name) => {
|
|
2189
2666
|
const upperName = capitalize3(name);
|
|
2190
2667
|
return {
|
|
2191
2668
|
name,
|
|
@@ -2195,7 +2672,7 @@ var getPatternEngine = (config) => {
|
|
|
2195
2672
|
jsxName: getConfig(name)?.jsx ?? upperName
|
|
2196
2673
|
};
|
|
2197
2674
|
}),
|
|
2198
|
-
|
|
2675
|
+
Obj.bind("details", ({ getNames, patterns }) => {
|
|
2199
2676
|
return Object.entries(patterns).map(([name, pattern]) => ({
|
|
2200
2677
|
...getNames(name),
|
|
2201
2678
|
props: Object.keys(pattern?.properties ?? {}),
|
|
@@ -2203,7 +2680,7 @@ var getPatternEngine = (config) => {
|
|
|
2203
2680
|
config: pattern
|
|
2204
2681
|
}));
|
|
2205
2682
|
}),
|
|
2206
|
-
|
|
2683
|
+
Obj.bind("nodes", ({ patterns }) => {
|
|
2207
2684
|
return Object.entries(patterns).map(([name, pattern]) => ({
|
|
2208
2685
|
type: "pattern",
|
|
2209
2686
|
name: pattern.jsx ?? capitalize3(name),
|
|
@@ -2211,83 +2688,19 @@ var getPatternEngine = (config) => {
|
|
|
2211
2688
|
baseName: name
|
|
2212
2689
|
}));
|
|
2213
2690
|
}),
|
|
2214
|
-
|
|
2691
|
+
Obj.bind("getFnName", ({ nodes }) => (jsx) => {
|
|
2215
2692
|
return nodes.find((node) => node.name === jsx)?.baseName ?? uncapitalize(jsx);
|
|
2216
2693
|
}),
|
|
2217
|
-
|
|
2694
|
+
Obj.bind("isEmpty", ({ patterns }) => {
|
|
2218
2695
|
return () => Object.keys(patterns).length === 0;
|
|
2219
2696
|
})
|
|
2220
2697
|
);
|
|
2221
2698
|
};
|
|
2222
2699
|
|
|
2223
|
-
// src/engines/recipe.ts
|
|
2224
|
-
import { capitalize as capitalize4, dashCase as dashCase2, splitProps, uncapitalize as uncapitalize2 } from "@pandacss/shared";
|
|
2225
|
-
import { Obj as Obj3, pipe as pipe4 } from "lil-fp";
|
|
2226
|
-
var mergeRegex = (item) => {
|
|
2227
|
-
const regex = item.map((item2) => typeof item2 === "string" ? item2 : item2.source).join("|");
|
|
2228
|
-
return new RegExp(`^${regex}$`);
|
|
2229
|
-
};
|
|
2230
|
-
var getRecipeEngine = (config) => {
|
|
2231
|
-
return pipe4(
|
|
2232
|
-
{ recipes: config.theme?.recipes ?? {} },
|
|
2233
|
-
Obj3.bind("getConfig", ({ recipes }) => {
|
|
2234
|
-
return (name) => recipes[name];
|
|
2235
|
-
}),
|
|
2236
|
-
Obj3.bind("getNames", () => {
|
|
2237
|
-
return (name) => ({
|
|
2238
|
-
upperName: capitalize4(name),
|
|
2239
|
-
dashName: dashCase2(name),
|
|
2240
|
-
jsxName: capitalize4(name)
|
|
2241
|
-
});
|
|
2242
|
-
}),
|
|
2243
|
-
Obj3.bind("nodes", ({ recipes }) => {
|
|
2244
|
-
return Object.entries(recipes).map(([name, recipe]) => {
|
|
2245
|
-
const jsx = recipe.jsx ?? [capitalize4(name)];
|
|
2246
|
-
const match6 = mergeRegex(jsx);
|
|
2247
|
-
return {
|
|
2248
|
-
type: "recipe",
|
|
2249
|
-
name: capitalize4(name),
|
|
2250
|
-
props: Object.keys(recipe.variants ?? {}),
|
|
2251
|
-
baseName: name,
|
|
2252
|
-
jsx,
|
|
2253
|
-
match: match6
|
|
2254
|
-
};
|
|
2255
|
-
});
|
|
2256
|
-
}),
|
|
2257
|
-
Obj3.bind("getFnName", ({ nodes }) => {
|
|
2258
|
-
return (jsx) => {
|
|
2259
|
-
const recipe = nodes.find((node) => node.match.test(jsx));
|
|
2260
|
-
return recipe?.baseName ?? uncapitalize2(jsx);
|
|
2261
|
-
};
|
|
2262
|
-
}),
|
|
2263
|
-
Obj3.bind("splitProps", ({ nodes }) => {
|
|
2264
|
-
return (name, props) => {
|
|
2265
|
-
const recipe = nodes.find((node) => node.match.test(name));
|
|
2266
|
-
if (!recipe)
|
|
2267
|
-
return [{}, props];
|
|
2268
|
-
return splitProps(props, recipe.props);
|
|
2269
|
-
};
|
|
2270
|
-
}),
|
|
2271
|
-
Obj3.bind("details", ({ getNames, recipes }) => {
|
|
2272
|
-
return Object.entries(recipes).map(([name, recipe]) => ({
|
|
2273
|
-
...getNames(name),
|
|
2274
|
-
config: recipe,
|
|
2275
|
-
variantKeyMap: Object.fromEntries(
|
|
2276
|
-
Object.entries(recipe.variants ?? {}).map(([key, value]) => [key, Object.keys(value)])
|
|
2277
|
-
)
|
|
2278
|
-
}));
|
|
2279
|
-
}),
|
|
2280
|
-
Obj3.bind("isEmpty", ({ recipes }) => {
|
|
2281
|
-
return () => Object.keys(recipes).length === 0;
|
|
2282
|
-
})
|
|
2283
|
-
);
|
|
2284
|
-
};
|
|
2285
|
-
|
|
2286
2700
|
// src/engines/index.ts
|
|
2287
2701
|
var getEngine = (conf) => ({
|
|
2288
2702
|
...getBaseEngine(conf),
|
|
2289
2703
|
patterns: getPatternEngine(conf.config),
|
|
2290
|
-
recipes: getRecipeEngine(conf.config),
|
|
2291
2704
|
jsx: getJsxEngine(conf.config),
|
|
2292
2705
|
paths: getPathEngine(conf.config),
|
|
2293
2706
|
file: {
|
|
@@ -2308,7 +2721,7 @@ var defaults = (conf) => ({
|
|
|
2308
2721
|
...conf,
|
|
2309
2722
|
config: {
|
|
2310
2723
|
cssVarRoot: ":where(:root, :host)",
|
|
2311
|
-
jsxFactory: "
|
|
2724
|
+
jsxFactory: "styled",
|
|
2312
2725
|
outExtension: "mjs",
|
|
2313
2726
|
...conf.config
|
|
2314
2727
|
}
|
|
@@ -2319,15 +2732,15 @@ var getImportMap = (outdir) => ({
|
|
|
2319
2732
|
pattern: `${outdir}/patterns`,
|
|
2320
2733
|
jsx: `${outdir}/jsx`
|
|
2321
2734
|
});
|
|
2322
|
-
var createGenerator = (conf) =>
|
|
2735
|
+
var createGenerator = (conf) => pipe3(
|
|
2323
2736
|
getEngine(defaults(conf)),
|
|
2324
|
-
|
|
2737
|
+
Obj2.assign((ctx) => ({
|
|
2325
2738
|
getArtifacts: generateArtifacts(ctx),
|
|
2326
2739
|
getCss: generateFlattenedCss(ctx),
|
|
2327
2740
|
getParserCss: generateParserCss(ctx),
|
|
2328
2741
|
messages: getMessages(ctx)
|
|
2329
2742
|
})),
|
|
2330
|
-
|
|
2743
|
+
Obj2.bind("parserOptions", ({ config: { outdir }, jsx, isValidProperty, patterns, recipes }) => ({
|
|
2331
2744
|
importMap: getImportMap(outdir),
|
|
2332
2745
|
jsx: {
|
|
2333
2746
|
factory: jsx.factoryName,
|