@pandacss/node 0.0.0-dev-20230106105402 → 0.0.0-dev-20230106183338
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/dist/index.d.ts +51 -9
- package/dist/index.js +260 -206
- package/dist/index.mjs +249 -195
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -122,6 +122,7 @@ function generateConditions(ctx) {
|
|
|
122
122
|
`,
|
|
123
123
|
dts: outdent`
|
|
124
124
|
export type Condition = ${unionType(keys)}
|
|
125
|
+
|
|
125
126
|
export type Conditions = Record<Condition, string>
|
|
126
127
|
`
|
|
127
128
|
};
|
|
@@ -283,20 +284,21 @@ function generateisValidProp(ctx) {
|
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
// src/generators/jsx/preact-jsx.ts
|
|
286
|
-
import { capitalize } from "@pandacss/shared";
|
|
287
287
|
import { outdent as outdent6 } from "outdent";
|
|
288
288
|
function generatePreactJsxFactory(ctx) {
|
|
289
|
-
const name = ctx.
|
|
290
|
-
const upperName = capitalize(name);
|
|
289
|
+
const { name, componentName } = ctx.jsxFactoryDetails;
|
|
291
290
|
return {
|
|
292
291
|
js: outdent6`
|
|
293
292
|
import { h } from 'preact'
|
|
294
293
|
import { forwardRef } from 'preact/compat'
|
|
294
|
+
import { useMemo } from 'preact/hooks'
|
|
295
295
|
import { isCssProperty } from './is-valid-prop'
|
|
296
|
-
import { css } from '../css'
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
import { css, cx } from '../css'
|
|
297
|
+
|
|
298
|
+
const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
|
|
299
|
+
|
|
300
|
+
function normalizeHtmlProp(key) {
|
|
301
|
+
return htmlProps.includes(key) ? key.replace('html', '').toLowerCase() : key
|
|
300
302
|
}
|
|
301
303
|
|
|
302
304
|
function splitProps(props) {
|
|
@@ -307,7 +309,7 @@ function generatePreactJsxFactory(ctx) {
|
|
|
307
309
|
if (isCssProperty(key)) {
|
|
308
310
|
styleProps[key] = value
|
|
309
311
|
} else {
|
|
310
|
-
elementProps[key] = value
|
|
312
|
+
elementProps[normalizeHtmlProp(key)] = value
|
|
311
313
|
}
|
|
312
314
|
}
|
|
313
315
|
|
|
@@ -315,12 +317,12 @@ function generatePreactJsxFactory(ctx) {
|
|
|
315
317
|
}
|
|
316
318
|
|
|
317
319
|
function styled(Dynamic) {
|
|
318
|
-
const ${
|
|
320
|
+
const ${componentName} = forwardRef(function ${componentName}(props, ref) {
|
|
319
321
|
const { as: Element = Dynamic, ...restProps } = props
|
|
320
322
|
|
|
321
|
-
const [styleProps, elementProps] = splitProps(restProps)
|
|
323
|
+
const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
|
|
322
324
|
|
|
323
|
-
|
|
325
|
+
function classes(){
|
|
324
326
|
const { css: cssStyles, ...otherStyles } = styleProps
|
|
325
327
|
const atomicClass = css({ ...otherStyles, ...cssStyles })
|
|
326
328
|
return cx(atomicClass, elementProps.className)
|
|
@@ -329,14 +331,17 @@ function generatePreactJsxFactory(ctx) {
|
|
|
329
331
|
return h(Element, { ...elementProps, ref, className: classes() })
|
|
330
332
|
})
|
|
331
333
|
|
|
332
|
-
${
|
|
333
|
-
return ${
|
|
334
|
+
${componentName}.displayName = \`${name}.\${Dynamic}\`
|
|
335
|
+
return ${componentName}
|
|
334
336
|
}
|
|
335
337
|
|
|
336
|
-
function
|
|
338
|
+
function createJsxFactory() {
|
|
337
339
|
const cache = new Map()
|
|
338
340
|
|
|
339
341
|
return new Proxy(Object.create(null), {
|
|
342
|
+
apply(_, __, args) {
|
|
343
|
+
return styled(...args)
|
|
344
|
+
},
|
|
340
345
|
get(_, el) {
|
|
341
346
|
if (!cache.has(el)) {
|
|
342
347
|
cache.set(el, styled(el))
|
|
@@ -346,7 +351,7 @@ function generatePreactJsxFactory(ctx) {
|
|
|
346
351
|
})
|
|
347
352
|
}
|
|
348
353
|
|
|
349
|
-
export const ${name} =
|
|
354
|
+
export const ${name} = createJsxFactory()
|
|
350
355
|
`
|
|
351
356
|
};
|
|
352
357
|
}
|
|
@@ -405,108 +410,112 @@ function generatePreactLayoutGrid() {
|
|
|
405
410
|
}
|
|
406
411
|
|
|
407
412
|
// src/generators/jsx/preact-pattern.ts
|
|
408
|
-
import { capitalize as capitalize2, dashCase } from "@pandacss/shared";
|
|
409
413
|
import { outdent as outdent8 } from "outdent";
|
|
410
414
|
import { match } from "ts-pattern";
|
|
411
|
-
function generate(name, pattern
|
|
412
|
-
const upperName =
|
|
413
|
-
const
|
|
414
|
-
const jsxName = pattern.jsx ?? upperName;
|
|
415
|
-
const keys = Object.keys(pattern.properties ?? {});
|
|
415
|
+
function generate(ctx, name, pattern) {
|
|
416
|
+
const { upperName, styleFn, dashName, jsxName, props } = ctx.getPatternDetails(name, pattern);
|
|
417
|
+
const { componentName } = ctx.jsxFactoryDetails;
|
|
416
418
|
return {
|
|
417
|
-
name:
|
|
419
|
+
name: dashName,
|
|
418
420
|
js: outdent8`
|
|
419
421
|
import { forwardRef } from 'preact/compat'
|
|
420
|
-
import { ${jsxFactory} } from './factory'
|
|
421
|
-
import { ${
|
|
422
|
+
import { ${ctx.jsxFactory} } from './factory'
|
|
423
|
+
import { ${styleFn} } from '../patterns/${dashName}'
|
|
422
424
|
|
|
423
425
|
export const ${jsxName} = forwardRef(function ${jsxName}(props, ref) {
|
|
424
|
-
${match(
|
|
426
|
+
${match(props.length).with(
|
|
425
427
|
0,
|
|
426
428
|
() => outdent8`
|
|
427
|
-
return <${jsxFactory}.div ref={ref} {...props} />
|
|
429
|
+
return <${ctx.jsxFactory}.div ref={ref} {...props} />
|
|
428
430
|
`
|
|
429
431
|
).otherwise(
|
|
430
432
|
() => outdent8`
|
|
431
|
-
const { ${
|
|
432
|
-
const styleProps = ${
|
|
433
|
-
return <${jsxFactory}.div ref={ref} {...styleProps} {...restProps} />
|
|
433
|
+
const { ${props.join(", ")}, ...restProps } = props
|
|
434
|
+
const styleProps = ${styleFn}({${props.join(", ")}})
|
|
435
|
+
return <${ctx.jsxFactory}.div ref={ref} {...styleProps} {...restProps} />
|
|
434
436
|
`
|
|
435
437
|
)}
|
|
436
438
|
})
|
|
437
439
|
`,
|
|
438
440
|
dts: outdent8`
|
|
439
|
-
import { ${upperName}Properties } from '../patterns/${
|
|
440
|
-
import {
|
|
441
|
+
import { ${upperName}Properties } from '../patterns/${dashName}'
|
|
442
|
+
import { ${componentName} } from '../types/jsx'
|
|
441
443
|
|
|
442
444
|
${pattern.description ? `/** ${pattern.description} */` : ""}
|
|
443
|
-
export declare const ${jsxName}:
|
|
445
|
+
export declare const ${jsxName}: ${componentName}<"div", ${upperName}Properties>
|
|
444
446
|
`
|
|
445
447
|
};
|
|
446
448
|
}
|
|
447
449
|
function generatePreactJsxPattern(ctx) {
|
|
448
|
-
return Object.entries(ctx.patterns).map(([name, pattern]) => generate(name, pattern
|
|
450
|
+
return Object.entries(ctx.patterns).map(([name, pattern]) => generate(ctx, name, pattern));
|
|
449
451
|
}
|
|
450
452
|
|
|
451
453
|
// src/generators/jsx/preact-types.ts
|
|
452
|
-
import { capitalize as capitalize3 } from "@pandacss/shared";
|
|
453
454
|
import { outdent as outdent9 } from "outdent";
|
|
454
455
|
function generatePreactJsxTypes(ctx) {
|
|
455
|
-
const name = ctx.
|
|
456
|
-
const upperName = capitalize3(name);
|
|
456
|
+
const { name, componentName, upperName, typeName } = ctx.jsxFactoryDetails;
|
|
457
457
|
return {
|
|
458
458
|
jsxFactory: outdent9`
|
|
459
|
-
import {
|
|
460
|
-
export declare const ${name}:
|
|
459
|
+
import { ${upperName} } from '../types/jsx'
|
|
460
|
+
export declare const ${name}: ${upperName}
|
|
461
461
|
`,
|
|
462
462
|
jsxType: outdent9`
|
|
463
|
-
import type { JSX,
|
|
463
|
+
import type { JSX, ElementType, ComponentProps } from 'preact'
|
|
464
464
|
import type { JsxStyleProps, Assign } from '.'
|
|
465
465
|
|
|
466
|
-
type
|
|
467
|
-
type As<P = any> = JSX.ElementType<P>
|
|
468
|
-
type Dict<T = unknown> = Record<string, T>
|
|
466
|
+
type Dict = Record<string, unknown>
|
|
469
467
|
|
|
470
|
-
type
|
|
468
|
+
type AdditionalHtmlProps = {
|
|
469
|
+
htmlSize?: string | number
|
|
470
|
+
htmlWidth?: string | number
|
|
471
|
+
htmlHeight?: string | number
|
|
472
|
+
htmlTranslate?: 'yes' | 'no' | undefined
|
|
473
|
+
}
|
|
471
474
|
|
|
472
|
-
type
|
|
473
|
-
ComponentProps
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
> = Assign<Clean<ComponentProps>, AdditionalProps> &
|
|
478
|
-
Assign<Clean<AsProps>, AdditionalProps> & {
|
|
479
|
-
as?: AsComponent
|
|
480
|
-
}
|
|
475
|
+
type Polyfill<ComponentProps> = Omit<
|
|
476
|
+
ComponentProps,
|
|
477
|
+
'color' | 'translate' | 'transition' | 'width' | 'height' | 'size'
|
|
478
|
+
> &
|
|
479
|
+
AdditionalHtmlProps
|
|
481
480
|
|
|
482
|
-
|
|
483
|
-
<
|
|
481
|
+
type Props<ComponentProps extends Dict, AdditionalProps extends Dict = {}> = Assign<
|
|
482
|
+
Polyfill<ComponentProps>,
|
|
483
|
+
AdditionalProps
|
|
484
|
+
>
|
|
485
|
+
|
|
486
|
+
export type ${componentName}<ComponentType extends ElementType, AdditionalProps extends Dict = {}> = {
|
|
487
|
+
(
|
|
488
|
+
props: Props<ComponentProps<ComponentType>, AdditionalProps> & JsxStyleProps<AdditionalProps>,
|
|
489
|
+
): JSX.Element
|
|
484
490
|
displayName?: string
|
|
485
491
|
}
|
|
486
492
|
|
|
487
|
-
export type
|
|
488
|
-
|
|
489
|
-
|
|
493
|
+
export type ${upperName} = {
|
|
494
|
+
<Component extends ElementType, AdditionalProps extends Dict = {}>(component: Component): ${componentName}<
|
|
495
|
+
Component,
|
|
496
|
+
AdditionalProps
|
|
497
|
+
>
|
|
498
|
+
} & { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
490
499
|
|
|
491
|
-
export type
|
|
500
|
+
export type ${typeName}<ComponentType extends ElementType> = Polyfill<ComponentProps<ComponentType>> & JsxStyleProps
|
|
492
501
|
`
|
|
493
502
|
};
|
|
494
503
|
}
|
|
495
504
|
|
|
496
505
|
// src/generators/jsx/react-jsx.ts
|
|
497
|
-
import { capitalize as capitalize4 } from "@pandacss/shared";
|
|
498
506
|
import { outdent as outdent10 } from "outdent";
|
|
499
507
|
function generateReactJsxFactory(ctx) {
|
|
500
|
-
const name = ctx.
|
|
501
|
-
const upperName = capitalize4(name);
|
|
508
|
+
const { name, componentName } = ctx.jsxFactoryDetails;
|
|
502
509
|
return {
|
|
503
510
|
js: outdent10`
|
|
504
|
-
import { forwardRef } from 'react'
|
|
511
|
+
import { forwardRef, useMemo } from 'react'
|
|
505
512
|
import { isCssProperty } from './is-valid-prop'
|
|
506
|
-
import { css } from '../css'
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
513
|
+
import { css, cx } from '../css'
|
|
514
|
+
|
|
515
|
+
const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
|
|
516
|
+
|
|
517
|
+
function normalizeHtmlProp(key) {
|
|
518
|
+
return htmlProps.includes(key) ? key.replace('html', '').toLowerCase() : key
|
|
510
519
|
}
|
|
511
520
|
|
|
512
521
|
function splitProps(props) {
|
|
@@ -517,7 +526,7 @@ function generateReactJsxFactory(ctx) {
|
|
|
517
526
|
if (isCssProperty(key)) {
|
|
518
527
|
styleProps[key] = value
|
|
519
528
|
} else {
|
|
520
|
-
elementProps[key] = value
|
|
529
|
+
elementProps[normalizeHtmlProp(key)] = value
|
|
521
530
|
}
|
|
522
531
|
}
|
|
523
532
|
|
|
@@ -525,12 +534,12 @@ function generateReactJsxFactory(ctx) {
|
|
|
525
534
|
}
|
|
526
535
|
|
|
527
536
|
function styled(Dynamic) {
|
|
528
|
-
const ${
|
|
537
|
+
const ${componentName} = forwardRef(function ${componentName}(props, ref) {
|
|
529
538
|
const { as: Element = Dynamic, ...restProps } = props
|
|
530
539
|
|
|
531
|
-
const [styleProps, elementProps] = splitProps(restProps)
|
|
540
|
+
const [styleProps, elementProps] = useMemo(() => splitProps(restProps), [restProps])
|
|
532
541
|
|
|
533
|
-
|
|
542
|
+
function classes(){
|
|
534
543
|
const { css: cssStyles, ...otherStyles } = styleProps
|
|
535
544
|
const atomicClass = css({ ...otherStyles, ...cssStyles })
|
|
536
545
|
return cx(atomicClass, elementProps.className)
|
|
@@ -539,14 +548,17 @@ function generateReactJsxFactory(ctx) {
|
|
|
539
548
|
return <Element ref={ref} {...elementProps} className={classes()} />
|
|
540
549
|
})
|
|
541
550
|
|
|
542
|
-
${
|
|
543
|
-
return ${
|
|
551
|
+
${componentName}.displayName = \`${name}.\${Dynamic}\`
|
|
552
|
+
return ${componentName}
|
|
544
553
|
}
|
|
545
554
|
|
|
546
|
-
function
|
|
555
|
+
function createJsxFactory() {
|
|
547
556
|
const cache = new Map()
|
|
548
557
|
|
|
549
558
|
return new Proxy(Object.create(null), {
|
|
559
|
+
apply(_, __, args) {
|
|
560
|
+
return styled(...args)
|
|
561
|
+
},
|
|
550
562
|
get(_, el) {
|
|
551
563
|
if (!cache.has(el)) {
|
|
552
564
|
cache.set(el, styled(el))
|
|
@@ -556,7 +568,8 @@ function generateReactJsxFactory(ctx) {
|
|
|
556
568
|
})
|
|
557
569
|
}
|
|
558
570
|
|
|
559
|
-
export const ${name} =
|
|
571
|
+
export const ${name} = createJsxFactory()
|
|
572
|
+
|
|
560
573
|
`
|
|
561
574
|
};
|
|
562
575
|
}
|
|
@@ -615,113 +628,132 @@ function generateReactLayoutGrid() {
|
|
|
615
628
|
}
|
|
616
629
|
|
|
617
630
|
// src/generators/jsx/react-pattern.ts
|
|
618
|
-
import { capitalize as capitalize5, dashCase as dashCase2 } from "@pandacss/shared";
|
|
619
631
|
import { outdent as outdent12 } from "outdent";
|
|
620
632
|
import { match as match2 } from "ts-pattern";
|
|
621
|
-
function generate2(name, pattern
|
|
622
|
-
const upperName =
|
|
623
|
-
const
|
|
624
|
-
const jsxName = pattern.jsx ?? upperName;
|
|
625
|
-
const keys = Object.keys(pattern.properties ?? {});
|
|
633
|
+
function generate2(ctx, name, pattern) {
|
|
634
|
+
const { upperName, styleFn, dashName, jsxName, props } = ctx.getPatternDetails(name, pattern);
|
|
635
|
+
const { componentName } = ctx.jsxFactoryDetails;
|
|
626
636
|
return {
|
|
627
|
-
name:
|
|
637
|
+
name: dashName,
|
|
628
638
|
js: outdent12`
|
|
629
639
|
import { forwardRef } from 'react'
|
|
630
|
-
import { ${jsxFactory} } from './factory'
|
|
631
|
-
import { ${
|
|
640
|
+
import { ${ctx.jsxFactory} } from './factory'
|
|
641
|
+
import { ${styleFn} } from '../patterns/${dashName}'
|
|
632
642
|
|
|
633
643
|
export const ${jsxName} = forwardRef(function ${jsxName}(props, ref) {
|
|
634
|
-
${match2(
|
|
644
|
+
${match2(props.length).with(
|
|
635
645
|
0,
|
|
636
646
|
() => outdent12`
|
|
637
|
-
return <${jsxFactory}.div ref={ref} {...props} />
|
|
647
|
+
return <${ctx.jsxFactory}.div ref={ref} {...props} />
|
|
638
648
|
`
|
|
639
649
|
).otherwise(
|
|
640
650
|
() => outdent12`
|
|
641
|
-
const { ${
|
|
642
|
-
const styleProps = ${
|
|
643
|
-
return <${jsxFactory}.div ref={ref} {...styleProps} {...restProps} />
|
|
651
|
+
const { ${props.join(", ")}, ...restProps } = props
|
|
652
|
+
const styleProps = ${styleFn}({${props.join(", ")}})
|
|
653
|
+
return <${ctx.jsxFactory}.div ref={ref} {...styleProps} {...restProps} />
|
|
644
654
|
`
|
|
645
655
|
)}
|
|
646
656
|
|
|
647
657
|
})
|
|
648
658
|
`,
|
|
649
659
|
dts: outdent12`
|
|
650
|
-
import { ${upperName}Properties } from '../patterns/${
|
|
651
|
-
import {
|
|
660
|
+
import { ${upperName}Properties } from '../patterns/${dashName}'
|
|
661
|
+
import { ${componentName} } from '../types/jsx'
|
|
652
662
|
|
|
653
663
|
${pattern.description ? `/** ${pattern.description} */` : ""}
|
|
654
|
-
export declare const ${jsxName}:
|
|
664
|
+
export declare const ${jsxName}: ${componentName}<'div', ${upperName}Properties>
|
|
655
665
|
`
|
|
656
666
|
};
|
|
657
667
|
}
|
|
658
668
|
function generateReactJsxPattern(ctx) {
|
|
659
|
-
return Object.entries(ctx.patterns).map(([name, pattern]) => generate2(name, pattern
|
|
669
|
+
return Object.entries(ctx.patterns).map(([name, pattern]) => generate2(ctx, name, pattern));
|
|
660
670
|
}
|
|
661
671
|
|
|
662
672
|
// src/generators/jsx/react-types.ts
|
|
663
|
-
import { capitalize as capitalize6 } from "@pandacss/shared";
|
|
664
673
|
import { outdent as outdent13 } from "outdent";
|
|
665
674
|
function generateReactJsxTypes(ctx) {
|
|
666
|
-
const name = ctx.
|
|
667
|
-
const upperName = capitalize6(name);
|
|
675
|
+
const { name, componentName, upperName, typeName } = ctx.jsxFactoryDetails;
|
|
668
676
|
return {
|
|
669
677
|
jsxFactory: outdent13`
|
|
670
|
-
import {
|
|
671
|
-
export declare const ${name}:
|
|
678
|
+
import { ${upperName} } from '../types/jsx'
|
|
679
|
+
export declare const ${name}: ${upperName}
|
|
672
680
|
`,
|
|
673
681
|
jsxType: outdent13`
|
|
674
682
|
import type { ElementType, ComponentProps } from 'react'
|
|
675
683
|
import type { JsxStyleProps, Assign } from '.'
|
|
676
684
|
|
|
677
|
-
type
|
|
678
|
-
type Dict<T = unknown> = Record<string, T>
|
|
685
|
+
type Dict = Record<string, unknown>
|
|
679
686
|
|
|
680
|
-
type
|
|
687
|
+
type AdditionalHtmlProps = {
|
|
688
|
+
htmlSize?: string | number
|
|
689
|
+
htmlWidth?: string | number
|
|
690
|
+
htmlHeight?: string | number
|
|
691
|
+
htmlTranslate?: 'yes' | 'no' | undefined
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
type Polyfill<ComponentProps> = Omit<
|
|
695
|
+
ComponentProps,
|
|
696
|
+
'color' | 'translate' | 'transition' | 'width' | 'height' | 'size'
|
|
697
|
+
> &
|
|
698
|
+
AdditionalHtmlProps
|
|
681
699
|
|
|
682
|
-
type
|
|
683
|
-
ComponentProps
|
|
684
|
-
AdditionalProps
|
|
685
|
-
>
|
|
700
|
+
type Props<ComponentProps extends Dict, AdditionalProps extends Dict = {}> = Assign<
|
|
701
|
+
Polyfill<ComponentProps>,
|
|
702
|
+
AdditionalProps
|
|
703
|
+
>
|
|
686
704
|
|
|
687
|
-
export type
|
|
688
|
-
(
|
|
705
|
+
export type ${componentName}<ComponentType extends ElementType, AdditionalProps extends Dict = {}> = {
|
|
706
|
+
(
|
|
707
|
+
props: Props<ComponentProps<ComponentType>, AdditionalProps> & JsxStyleProps<AdditionalProps>,
|
|
708
|
+
): JSX.Element
|
|
689
709
|
displayName?: string
|
|
690
710
|
}
|
|
691
711
|
|
|
692
|
-
export type
|
|
693
|
-
|
|
694
|
-
|
|
712
|
+
export type ${upperName} = {
|
|
713
|
+
<Component extends ElementType, AdditionalProps extends Dict = {}>(component: Component): ${componentName}<
|
|
714
|
+
Component,
|
|
715
|
+
AdditionalProps
|
|
716
|
+
>
|
|
717
|
+
} & { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
695
718
|
|
|
696
|
-
export type
|
|
719
|
+
export type ${typeName}<ComponentType extends ElementType> = Polyfill<ComponentProps<ComponentType>> & JsxStyleProps
|
|
697
720
|
`
|
|
698
721
|
};
|
|
699
722
|
}
|
|
700
723
|
|
|
701
724
|
// src/generators/jsx/solid-jsx.ts
|
|
702
|
-
import { capitalize as capitalize7 } from "@pandacss/shared";
|
|
703
725
|
import { outdent as outdent14 } from "outdent";
|
|
704
726
|
function generateSolidJsxFactory(ctx) {
|
|
705
|
-
const name = ctx.
|
|
706
|
-
const upperName = capitalize7(name);
|
|
727
|
+
const { componentName, name } = ctx.jsxFactoryDetails;
|
|
707
728
|
return {
|
|
708
729
|
js: outdent14`
|
|
709
730
|
import { Dynamic } from 'solid-js/web'
|
|
710
731
|
import { mergeProps, splitProps } from 'solid-js'
|
|
711
732
|
import { allCssProperties } from './is-valid-prop'
|
|
712
|
-
import { css } from '../css'
|
|
733
|
+
import { css, cx } from '../css'
|
|
713
734
|
|
|
714
|
-
|
|
715
|
-
|
|
735
|
+
const htmlProps = ['htmlSize', 'htmlTranslate', 'htmlWidth', 'htmlHeight']
|
|
736
|
+
|
|
737
|
+
function normalizeHtmlProp(key) {
|
|
738
|
+
return htmlProps.includes(key) ? key.replace('html', '').toLowerCase() : key
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function normalizeHtmlProps(props) {
|
|
742
|
+
const result = {}
|
|
743
|
+
for (const [key, value] of Object.entries(props)) {
|
|
744
|
+
result[normalizeHtmlProp(key)] = value
|
|
745
|
+
}
|
|
746
|
+
return result
|
|
716
747
|
}
|
|
717
748
|
|
|
718
749
|
function styled(element) {
|
|
719
|
-
return function ${
|
|
750
|
+
return function ${componentName}(props) {
|
|
720
751
|
const mergedProps = mergeProps({ as: element }, props)
|
|
721
752
|
|
|
722
|
-
const [localProps, styleProps, elementProps] = splitProps(
|
|
753
|
+
const [localProps, localHtmlProps, styleProps, elementProps] = splitProps(
|
|
723
754
|
mergedProps,
|
|
724
755
|
['as', 'class', 'className'],
|
|
756
|
+
htmlProps,
|
|
725
757
|
allCssProperties
|
|
726
758
|
)
|
|
727
759
|
|
|
@@ -731,14 +763,17 @@ function generateSolidJsxFactory(ctx) {
|
|
|
731
763
|
return cx(atomicClass, localProps.class, localProps.className)
|
|
732
764
|
}
|
|
733
765
|
|
|
734
|
-
return <Dynamic component={localProps.as} {...elementProps} class={classes()} />
|
|
766
|
+
return <Dynamic component={localProps.as} {...normalizeHtmlProps(localHtmlProps)} {...elementProps} class={classes()} />
|
|
735
767
|
}
|
|
736
768
|
}
|
|
737
769
|
|
|
738
|
-
function
|
|
770
|
+
function createJsxFactory() {
|
|
739
771
|
const cache = new Map()
|
|
740
772
|
|
|
741
773
|
return new Proxy(Object.create(null), {
|
|
774
|
+
apply(_, __, args) {
|
|
775
|
+
return styled(...args)
|
|
776
|
+
},
|
|
742
777
|
get(_, el) {
|
|
743
778
|
if (!cache.has(el)) {
|
|
744
779
|
cache.set(el, styled(el))
|
|
@@ -748,7 +783,7 @@ function generateSolidJsxFactory(ctx) {
|
|
|
748
783
|
})
|
|
749
784
|
}
|
|
750
785
|
|
|
751
|
-
export const ${name} =
|
|
786
|
+
export const ${name} = createJsxFactory()
|
|
752
787
|
`
|
|
753
788
|
};
|
|
754
789
|
}
|
|
@@ -758,6 +793,8 @@ import { outdent as outdent15 } from "outdent";
|
|
|
758
793
|
function generateSolidLayoutGrid() {
|
|
759
794
|
return {
|
|
760
795
|
dts: outdent15`
|
|
796
|
+
import { ParentProps } from 'solid-js'
|
|
797
|
+
|
|
761
798
|
export type LayoutGridProps = {
|
|
762
799
|
count?: number
|
|
763
800
|
gutter?: string
|
|
@@ -765,7 +802,7 @@ function generateSolidLayoutGrid() {
|
|
|
765
802
|
margin?: string
|
|
766
803
|
}
|
|
767
804
|
|
|
768
|
-
export declare const LayoutGrid:
|
|
805
|
+
export declare const LayoutGrid: ParentProps<LayoutGridProps>
|
|
769
806
|
`,
|
|
770
807
|
js: outdent15`
|
|
771
808
|
export function LayoutGrid(props) {
|
|
@@ -805,90 +842,97 @@ function generateSolidLayoutGrid() {
|
|
|
805
842
|
}
|
|
806
843
|
|
|
807
844
|
// src/generators/jsx/solid-pattern.ts
|
|
808
|
-
import { capitalize as capitalize8, dashCase as dashCase3 } from "@pandacss/shared";
|
|
809
845
|
import { outdent as outdent16 } from "outdent";
|
|
810
846
|
import { match as match3 } from "ts-pattern";
|
|
811
|
-
function generate3(name, pattern
|
|
812
|
-
const upperName =
|
|
813
|
-
const
|
|
814
|
-
const jsxName = pattern.jsx ?? upperName;
|
|
815
|
-
const keys = Object.keys(pattern.properties ?? {});
|
|
847
|
+
function generate3(ctx, name, pattern) {
|
|
848
|
+
const { upperName, styleFn, dashName, jsxName, props } = ctx.getPatternDetails(name, pattern);
|
|
849
|
+
const { componentName } = ctx.jsxFactoryDetails;
|
|
816
850
|
return {
|
|
817
|
-
name:
|
|
851
|
+
name: dashName,
|
|
818
852
|
js: outdent16`
|
|
819
853
|
import { splitProps } from 'solid-js'
|
|
820
|
-
import { ${jsxFactory} } from './factory'
|
|
821
|
-
import { ${
|
|
854
|
+
import { ${ctx.jsxFactory} } from './factory'
|
|
855
|
+
import { ${styleFn} } from '../patterns/${dashName}'
|
|
822
856
|
|
|
823
857
|
export function ${jsxName}(props) {
|
|
824
|
-
${match3(
|
|
858
|
+
${match3(props.length).with(
|
|
825
859
|
0,
|
|
826
860
|
() => outdent16`
|
|
827
|
-
return <${jsxFactory}.div {...props} />
|
|
861
|
+
return <${ctx.jsxFactory}.div {...props} />
|
|
828
862
|
`
|
|
829
863
|
).otherwise(
|
|
830
864
|
() => outdent16`
|
|
831
|
-
const [patternProps, restProps] = splitProps(props, [${
|
|
832
|
-
const styleProps = ${
|
|
833
|
-
return <${jsxFactory}.div {...styleProps} {...restProps} />
|
|
865
|
+
const [patternProps, restProps] = splitProps(props, [${props.map((v) => JSON.stringify(v)).join(", ")}]);
|
|
866
|
+
const styleProps = ${styleFn}(patternProps)
|
|
867
|
+
return <${ctx.jsxFactory}.div {...styleProps} {...restProps} />
|
|
834
868
|
`
|
|
835
869
|
)}
|
|
836
870
|
}
|
|
837
871
|
`,
|
|
838
872
|
dts: outdent16`
|
|
839
|
-
import { ${upperName}Properties } from '../patterns/${
|
|
840
|
-
import {
|
|
873
|
+
import { ${upperName}Properties } from '../patterns/${dashName}'
|
|
874
|
+
import { ${componentName} } from '../types/jsx'
|
|
841
875
|
|
|
842
876
|
${pattern.description ? `/** ${pattern.description} */` : ""}
|
|
843
|
-
export declare const ${jsxName}:
|
|
877
|
+
export declare const ${jsxName}: ${componentName}<"div", ${upperName}Properties>
|
|
844
878
|
`
|
|
845
879
|
};
|
|
846
880
|
}
|
|
847
881
|
function generateSolidJsxPattern(ctx) {
|
|
848
|
-
return Object.entries(ctx.patterns).map(([name, pattern]) => generate3(name, pattern
|
|
882
|
+
return Object.entries(ctx.patterns).map(([name, pattern]) => generate3(ctx, name, pattern));
|
|
849
883
|
}
|
|
850
884
|
|
|
851
885
|
// src/generators/jsx/solid-types.ts
|
|
852
|
-
import { capitalize as capitalize9 } from "@pandacss/shared";
|
|
853
886
|
import { outdent as outdent17 } from "outdent";
|
|
854
887
|
function generateSolidJsxTypes(ctx) {
|
|
855
|
-
const name = ctx.
|
|
856
|
-
const upperName = capitalize9(name);
|
|
888
|
+
const { name, componentName, upperName, typeName } = ctx.jsxFactoryDetails;
|
|
857
889
|
return {
|
|
858
890
|
jsxFactory: outdent17`
|
|
859
|
-
import {
|
|
860
|
-
export declare const ${name}:
|
|
891
|
+
import { ${upperName} } from '../types/jsx'
|
|
892
|
+
export declare const ${name}: ${upperName}
|
|
861
893
|
`,
|
|
862
894
|
jsxType: outdent17`
|
|
863
895
|
import type { JSX, ComponentProps, Component } from 'solid-js'
|
|
864
896
|
import type { JsxStyleProps, Assign } from '.'
|
|
865
897
|
|
|
866
|
-
type
|
|
867
|
-
type As<P = any> = Element | Component<P>;
|
|
868
|
-
type Dict<T = unknown> = Record<string, T>
|
|
898
|
+
type Dict = Record<string, unknown>
|
|
869
899
|
|
|
870
|
-
type
|
|
900
|
+
type ElementType<P = any> = keyof JSX.IntrinsicElements | Component<P>;
|
|
871
901
|
|
|
872
|
-
type
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
Assign<Clean<AsProps>, AdditionalProps> & {
|
|
879
|
-
as?: AsComponent
|
|
880
|
-
}
|
|
902
|
+
type AdditionalHtmlProps = {
|
|
903
|
+
htmlSize?: string | number
|
|
904
|
+
htmlWidth?: string | number
|
|
905
|
+
htmlHeight?: string | number
|
|
906
|
+
htmlTranslate?: 'yes' | 'no' | undefined
|
|
907
|
+
}
|
|
881
908
|
|
|
882
|
-
|
|
883
|
-
|
|
909
|
+
type Polyfill<ComponentProps> = Omit<
|
|
910
|
+
ComponentProps,
|
|
911
|
+
'color' | 'translate' | 'transition' | 'width' | 'height' | 'size'
|
|
912
|
+
> &
|
|
913
|
+
AdditionalHtmlProps
|
|
914
|
+
|
|
915
|
+
type Props<ComponentProps extends Dict, AdditionalProps extends Dict = {}> = Assign<
|
|
916
|
+
Polyfill<ComponentProps>,
|
|
917
|
+
AdditionalProps
|
|
918
|
+
>
|
|
919
|
+
|
|
920
|
+
export type ${componentName}<ComponentType extends ElementType, AdditionalProps extends Dict = {}> = {
|
|
921
|
+
(
|
|
922
|
+
props: Props<ComponentProps<ComponentType>, AdditionalProps> & JsxStyleProps<AdditionalProps>,
|
|
923
|
+
): JSX.Element
|
|
884
924
|
displayName?: string
|
|
885
925
|
}
|
|
886
926
|
|
|
887
|
-
export type PolymorphicComponents = {
|
|
888
|
-
[K in Element]: PolymorphicComponent<K, {}>
|
|
889
|
-
}
|
|
890
927
|
|
|
891
|
-
export type
|
|
928
|
+
export type ${upperName} = {
|
|
929
|
+
<Component extends ElementType, AdditionalProps extends Dict = {}>(component: Component): ${componentName}<
|
|
930
|
+
Component,
|
|
931
|
+
AdditionalProps
|
|
932
|
+
>
|
|
933
|
+
} & { [K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}> }
|
|
934
|
+
|
|
935
|
+
export type ${typeName}<ComponentType extends ElementType> = Polyfill<ComponentProps<ComponentType>> & JsxStyleProps
|
|
892
936
|
`
|
|
893
937
|
};
|
|
894
938
|
}
|
|
@@ -932,22 +976,22 @@ function generateLayoutGrid(ctx) {
|
|
|
932
976
|
}
|
|
933
977
|
|
|
934
978
|
// src/generators/pattern.ts
|
|
935
|
-
import { capitalize
|
|
979
|
+
import { capitalize, dashCase, unionType as unionType2 } from "@pandacss/shared";
|
|
936
980
|
import { outdent as outdent18 } from "outdent";
|
|
937
981
|
import { stringify as stringify2 } from "telejson";
|
|
938
982
|
import { match as match4 } from "ts-pattern";
|
|
939
983
|
function generate4(name, pattern) {
|
|
940
984
|
const { properties, transform, strict, description } = pattern;
|
|
941
|
-
const upperName =
|
|
985
|
+
const upperName = capitalize(name);
|
|
942
986
|
const upperFn = `get${upperName}Style`;
|
|
943
987
|
return {
|
|
944
|
-
name:
|
|
988
|
+
name: dashCase(name),
|
|
945
989
|
dts: outdent18`
|
|
946
990
|
import { SystemStyleObject, ConditionalValue } from "../types"
|
|
947
991
|
import { Properties } from "../types/csstype"
|
|
948
992
|
import { Tokens } from "../types/token"
|
|
949
993
|
|
|
950
|
-
export type ${
|
|
994
|
+
export type ${capitalize(name)}Properties = {
|
|
951
995
|
${Object.keys(properties ?? {}).map((key) => {
|
|
952
996
|
const value = properties[key];
|
|
953
997
|
return match4(value).with({ type: "property" }, (value2) => {
|
|
@@ -1022,7 +1066,7 @@ function generatePropTypes(utility) {
|
|
|
1022
1066
|
}
|
|
1023
1067
|
|
|
1024
1068
|
// src/generators/recipe.ts
|
|
1025
|
-
import { capitalize as
|
|
1069
|
+
import { capitalize as capitalize2, unionType as unionType3 } from "@pandacss/shared";
|
|
1026
1070
|
import { outdent as outdent20 } from "outdent";
|
|
1027
1071
|
function generateRecipes(ctx) {
|
|
1028
1072
|
const { recipes = {}, hash, hasRecipes, utility } = ctx;
|
|
@@ -1071,7 +1115,7 @@ function generateRecipes(ctx) {
|
|
|
1071
1115
|
dts.push(outdent20`
|
|
1072
1116
|
import { ConditionalValue } from "../types"
|
|
1073
1117
|
|
|
1074
|
-
export type ${
|
|
1118
|
+
export type ${capitalize2(name)}Variants = {
|
|
1075
1119
|
${Object.keys(variants ?? {}).map((key) => {
|
|
1076
1120
|
const value = variants[key];
|
|
1077
1121
|
const keys = Object.keys(value);
|
|
@@ -1080,7 +1124,7 @@ function generateRecipes(ctx) {
|
|
|
1080
1124
|
}
|
|
1081
1125
|
|
|
1082
1126
|
${description ? `/** ${description} */` : ""}
|
|
1083
|
-
export declare function ${name}(value?: ${
|
|
1127
|
+
export declare function ${name}(value?: ${capitalize2(name)}Variants): string
|
|
1084
1128
|
`);
|
|
1085
1129
|
});
|
|
1086
1130
|
return {
|
|
@@ -1263,7 +1307,7 @@ function cleanupSelectors(css2, varSelector) {
|
|
|
1263
1307
|
}
|
|
1264
1308
|
|
|
1265
1309
|
// src/generators/token-dts.ts
|
|
1266
|
-
import { unionType as unionType4, capitalize as
|
|
1310
|
+
import { unionType as unionType4, capitalize as capitalize3 } from "@pandacss/shared";
|
|
1267
1311
|
import { outdent as outdent21 } from "outdent";
|
|
1268
1312
|
import pluralize from "pluralize";
|
|
1269
1313
|
function generateTokenDts(dict) {
|
|
@@ -1274,7 +1318,7 @@ function generateTokenDts(dict) {
|
|
|
1274
1318
|
result.add("[token: string]: string");
|
|
1275
1319
|
} else {
|
|
1276
1320
|
for (const [key, value] of dict.categoryMap.entries()) {
|
|
1277
|
-
const typeName =
|
|
1321
|
+
const typeName = capitalize3(pluralize.singular(key));
|
|
1278
1322
|
set.add(`export type ${typeName} = ${unionType4(value.keys())}`);
|
|
1279
1323
|
set.add(`export type ColorPalette = ${unionType4(Object.keys(dict.colorPalettes))}`);
|
|
1280
1324
|
result.add(` ${key}: ${typeName}`);
|
|
@@ -1481,7 +1525,6 @@ function setupJsx(ctx) {
|
|
|
1481
1525
|
export * from './factory'
|
|
1482
1526
|
export * from './layout-grid'
|
|
1483
1527
|
${outdent24.string(patterns.map((file) => `export * from './${file.name}'`).join("\n"))}
|
|
1484
|
-
export type { HTML${ctx.jsxFactoryName}Props } from '../types/jsx'
|
|
1485
1528
|
`;
|
|
1486
1529
|
return {
|
|
1487
1530
|
dir: ctx.paths.jsx,
|
|
@@ -1493,7 +1536,13 @@ function setupJsx(ctx) {
|
|
|
1493
1536
|
{ file: "is-valid-prop.mjs", code: isValidProp.js },
|
|
1494
1537
|
{ file: "factory.d.ts", code: types.jsxFactory },
|
|
1495
1538
|
{ file: "factory.jsx", code: factory.js },
|
|
1496
|
-
{
|
|
1539
|
+
{
|
|
1540
|
+
file: "index.d.ts",
|
|
1541
|
+
code: outdent24`
|
|
1542
|
+
${indexCode}
|
|
1543
|
+
export type { ${ctx.jsxFactoryDetails.typeName} } from '../types/jsx'
|
|
1544
|
+
`
|
|
1545
|
+
},
|
|
1497
1546
|
{ file: "index.jsx", code: indexCode }
|
|
1498
1547
|
]
|
|
1499
1548
|
};
|
|
@@ -1660,7 +1709,7 @@ import {
|
|
|
1660
1709
|
import { isCssProperty } from "@pandacss/is-valid-prop";
|
|
1661
1710
|
import { logger as logger4 } from "@pandacss/logger";
|
|
1662
1711
|
import { createParser, createProject } from "@pandacss/parser";
|
|
1663
|
-
import { capitalize as
|
|
1712
|
+
import { capitalize as capitalize4, compact, mapObject, uncapitalize, splitObject, dashCase as dashCase2 } from "@pandacss/shared";
|
|
1664
1713
|
import { TokenDictionary } from "@pandacss/token-dictionary";
|
|
1665
1714
|
import glob from "fast-glob";
|
|
1666
1715
|
import { readdirSync, readFileSync as readFileSync4 } from "fs";
|
|
@@ -1684,18 +1733,6 @@ var fileSystem = {
|
|
|
1684
1733
|
return unlink(path);
|
|
1685
1734
|
}
|
|
1686
1735
|
};
|
|
1687
|
-
function splitProps(obj, keys) {
|
|
1688
|
-
const omitted = {};
|
|
1689
|
-
const picked = {};
|
|
1690
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1691
|
-
if (keys.includes(key)) {
|
|
1692
|
-
picked[key] = value;
|
|
1693
|
-
} else {
|
|
1694
|
-
omitted[key] = value;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
return [picked, omitted];
|
|
1698
|
-
}
|
|
1699
1736
|
function createContext(conf, io = fileSystem) {
|
|
1700
1737
|
const { config } = conf;
|
|
1701
1738
|
const {
|
|
@@ -1723,7 +1760,13 @@ function createContext(conf, io = fileSystem) {
|
|
|
1723
1760
|
textStyles,
|
|
1724
1761
|
layerStyles
|
|
1725
1762
|
} = theme;
|
|
1726
|
-
const
|
|
1763
|
+
const jsxFactoryDetails = {
|
|
1764
|
+
name: jsxFactory,
|
|
1765
|
+
upperName: capitalize4(jsxFactory),
|
|
1766
|
+
typeName: `HTML${capitalize4(jsxFactory)}Props`,
|
|
1767
|
+
componentName: `${capitalize4(jsxFactory)}Component`,
|
|
1768
|
+
framework: jsxFramework
|
|
1769
|
+
};
|
|
1727
1770
|
const cwd = resolve(cwdProp);
|
|
1728
1771
|
const exclude = [".git", "node_modules", "test-results"].concat(excludeProp);
|
|
1729
1772
|
const tokens = new TokenDictionary({
|
|
@@ -1764,9 +1807,20 @@ function createContext(conf, io = fileSystem) {
|
|
|
1764
1807
|
const pattern = getPattern(name);
|
|
1765
1808
|
return pattern?.transform?.(data, helpers) ?? {};
|
|
1766
1809
|
}
|
|
1810
|
+
function getPatternDetails(name, pattern) {
|
|
1811
|
+
const upperName = capitalize4(name);
|
|
1812
|
+
return {
|
|
1813
|
+
name,
|
|
1814
|
+
props: Object.keys(pattern?.properties ?? {}),
|
|
1815
|
+
dashName: dashCase2(name),
|
|
1816
|
+
upperName,
|
|
1817
|
+
styleFn: `get${upperName}Style`,
|
|
1818
|
+
jsxName: pattern?.jsx ?? upperName
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1767
1821
|
const patternNodes = Object.entries(patterns).map(([name, pattern]) => ({
|
|
1768
1822
|
type: "pattern",
|
|
1769
|
-
name: pattern.jsx ??
|
|
1823
|
+
name: pattern.jsx ?? capitalize4(name),
|
|
1770
1824
|
props: Object.keys(pattern.properties),
|
|
1771
1825
|
baseName: name
|
|
1772
1826
|
}));
|
|
@@ -1779,7 +1833,7 @@ function createContext(conf, io = fileSystem) {
|
|
|
1779
1833
|
}
|
|
1780
1834
|
const recipeNodes = Object.entries(recipes).map(([name, recipe]) => ({
|
|
1781
1835
|
type: "recipe",
|
|
1782
|
-
name: recipe.jsx ??
|
|
1836
|
+
name: recipe.jsx ?? capitalize4(name),
|
|
1783
1837
|
props: Object.keys(recipe.variants ?? {}),
|
|
1784
1838
|
baseName: name
|
|
1785
1839
|
}));
|
|
@@ -1790,7 +1844,7 @@ function createContext(conf, io = fileSystem) {
|
|
|
1790
1844
|
const recipe = recipeNodes.find((node) => node.name === name);
|
|
1791
1845
|
if (!recipe)
|
|
1792
1846
|
return [{}, props];
|
|
1793
|
-
return
|
|
1847
|
+
return splitObject(props, (key) => recipe.props.includes(key));
|
|
1794
1848
|
}
|
|
1795
1849
|
function getRecipeDetails() {
|
|
1796
1850
|
return Object.entries(recipes).map(([name, recipe]) => ({
|
|
@@ -2047,6 +2101,7 @@ function createContext(conf, io = fileSystem) {
|
|
|
2047
2101
|
write,
|
|
2048
2102
|
writeOutput,
|
|
2049
2103
|
cleanOutdir,
|
|
2104
|
+
cssVarRoot,
|
|
2050
2105
|
tokens,
|
|
2051
2106
|
hasTokens,
|
|
2052
2107
|
utility,
|
|
@@ -2059,14 +2114,13 @@ function createContext(conf, io = fileSystem) {
|
|
|
2059
2114
|
execPattern,
|
|
2060
2115
|
patternNodes,
|
|
2061
2116
|
getPatternFnName,
|
|
2117
|
+
getPatternDetails,
|
|
2062
2118
|
recipes,
|
|
2063
2119
|
getRecipe,
|
|
2064
2120
|
hasRecipes,
|
|
2065
2121
|
getRecipeDetails,
|
|
2066
|
-
jsxFramework,
|
|
2067
|
-
jsxFactoryName,
|
|
2068
2122
|
jsxFactory,
|
|
2069
|
-
|
|
2123
|
+
jsxFactoryDetails,
|
|
2070
2124
|
properties,
|
|
2071
2125
|
extract
|
|
2072
2126
|
};
|