@pandacss/generator 0.0.0-dev-20231020171339 → 0.0.0-dev-20231020173315
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.js +575 -303
- package/dist/index.mjs +575 -303
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -99,7 +99,7 @@ var getMessages = (ctx) => ({
|
|
|
99
99
|
|
|
100
100
|
// src/artifacts/index.ts
|
|
101
101
|
import { isObject } from "@pandacss/shared";
|
|
102
|
-
import
|
|
102
|
+
import outdent44 from "outdent";
|
|
103
103
|
|
|
104
104
|
// src/artifacts/css/global-css.ts
|
|
105
105
|
var generateGlobalCss = (ctx) => {
|
|
@@ -619,11 +619,7 @@ function generateStringLiteralConditions(ctx) {
|
|
|
619
619
|
// src/artifacts/js/css-fn.ts
|
|
620
620
|
import { outdent as outdent4 } from "outdent";
|
|
621
621
|
function generateCssFn(ctx) {
|
|
622
|
-
const {
|
|
623
|
-
utility,
|
|
624
|
-
config: { hash, prefix },
|
|
625
|
-
conditions
|
|
626
|
-
} = ctx;
|
|
622
|
+
const { utility, hash, prefix, conditions } = ctx;
|
|
627
623
|
const { separator, getPropShorthands } = utility;
|
|
628
624
|
return {
|
|
629
625
|
dts: outdent4`
|
|
@@ -678,14 +674,14 @@ function generateCssFn(ctx) {
|
|
|
678
674
|
`}
|
|
679
675
|
|
|
680
676
|
const context = {
|
|
681
|
-
${hash ? "hash: true," : ""}
|
|
677
|
+
${hash.className ? "hash: true," : ""}
|
|
682
678
|
conditions: {
|
|
683
679
|
shift: sortConditions,
|
|
684
680
|
finalize: finalizeConditions,
|
|
685
681
|
breakpoints: { keys: ${JSON.stringify(conditions.breakpoints.keys)} }
|
|
686
682
|
},
|
|
687
683
|
utility: {
|
|
688
|
-
${prefix ? "prefix: " + JSON.stringify(prefix) + "," : ""}
|
|
684
|
+
${prefix.className ? "prefix: " + JSON.stringify(prefix.className) + "," : ""}
|
|
689
685
|
transform: ${utility.hasShorthand ? `(prop, value) => {
|
|
690
686
|
const key = resolveShorthand(prop)
|
|
691
687
|
const propKey = classNameByProp.get(key) || hypenateProperty(key)
|
|
@@ -708,18 +704,15 @@ function generateCssFn(ctx) {
|
|
|
708
704
|
// src/artifacts/js/css-fn.string-literal.ts
|
|
709
705
|
import { outdent as outdent5 } from "outdent";
|
|
710
706
|
function generateStringLiteralCssFn(ctx) {
|
|
711
|
-
const {
|
|
712
|
-
utility,
|
|
713
|
-
config: { hash, prefix }
|
|
714
|
-
} = ctx;
|
|
707
|
+
const { utility, hash, prefix } = ctx;
|
|
715
708
|
const { separator } = utility;
|
|
716
709
|
return {
|
|
717
710
|
dts: outdent5`
|
|
718
711
|
export declare function css(template: { raw: readonly string[] | ArrayLike<string> }): string
|
|
719
712
|
`,
|
|
720
713
|
js: outdent5`
|
|
721
|
-
${ctx.file.import("astish, createCss, withoutSpace", "../helpers")}
|
|
722
|
-
${ctx.file.import("
|
|
714
|
+
${ctx.file.import("astish, createCss, isObject, mergeProps, withoutSpace", "../helpers")}
|
|
715
|
+
${ctx.file.import("finalizeConditions, sortConditions", "./conditions")}
|
|
723
716
|
|
|
724
717
|
function transform(prop, value) {
|
|
725
718
|
const className = \`$\{prop}${separator}$\{withoutSpace(value)}\`
|
|
@@ -727,14 +720,14 @@ function generateStringLiteralCssFn(ctx) {
|
|
|
727
720
|
}
|
|
728
721
|
|
|
729
722
|
const context = {
|
|
730
|
-
hash: ${hash ? "true" : "false"},
|
|
723
|
+
hash: ${hash.className ? "true" : "false"},
|
|
731
724
|
conditions: {
|
|
732
725
|
shift: sortConditions,
|
|
733
726
|
finalize: finalizeConditions,
|
|
734
727
|
breakpoints: { keys: [] },
|
|
735
728
|
},
|
|
736
729
|
utility: {
|
|
737
|
-
prefix: ${prefix ? JSON.stringify(prefix) : void 0},
|
|
730
|
+
prefix: ${prefix.className ? JSON.stringify(prefix.className) : void 0},
|
|
738
731
|
transform,
|
|
739
732
|
hasShorthand: false,
|
|
740
733
|
resolveShorthand(prop) {
|
|
@@ -745,9 +738,9 @@ function generateStringLiteralCssFn(ctx) {
|
|
|
745
738
|
|
|
746
739
|
const cssFn = createCss(context)
|
|
747
740
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
741
|
+
const fn = (style) => (isObject(style) ? style : astish(style[0]))
|
|
742
|
+
export const css = (...styles) => cssFn(mergeProps(...styles.filter(Boolean).map(fn)))
|
|
743
|
+
css.raw = (...styles) => mergeProps(...styles.filter(Boolean).map(fn))
|
|
751
744
|
`
|
|
752
745
|
};
|
|
753
746
|
}
|
|
@@ -757,11 +750,19 @@ import { outdent as outdent6 } from "outdent";
|
|
|
757
750
|
function generateCvaFn(ctx) {
|
|
758
751
|
return {
|
|
759
752
|
js: outdent6`
|
|
760
|
-
${ctx.file.import("compact, splitProps", "../helpers")}
|
|
753
|
+
${ctx.file.import("compact, mergeProps, splitProps, uniq", "../helpers")}
|
|
761
754
|
${ctx.file.import("css, mergeCss", "./css")}
|
|
762
755
|
|
|
756
|
+
const defaults = (conf) => ({
|
|
757
|
+
base: {},
|
|
758
|
+
variants: {},
|
|
759
|
+
defaultVariants: {},
|
|
760
|
+
compoundVariants: [],
|
|
761
|
+
...conf,
|
|
762
|
+
})
|
|
763
|
+
|
|
763
764
|
export function cva(config) {
|
|
764
|
-
const { base
|
|
765
|
+
const { base, variants, defaultVariants, compoundVariants } = defaults(config)
|
|
765
766
|
|
|
766
767
|
function resolve(props = {}) {
|
|
767
768
|
const computedVariants = { ...defaultVariants, ...compact(props) }
|
|
@@ -775,6 +776,19 @@ function generateCvaFn(ctx) {
|
|
|
775
776
|
return mergeCss(variantCss, compoundVariantCss)
|
|
776
777
|
}
|
|
777
778
|
|
|
779
|
+
function merge(cvaConfig) {
|
|
780
|
+
const override = defaults(cvaConfig)
|
|
781
|
+
const variantKeys = uniq(override.variantKeys, Object.keys(variants))
|
|
782
|
+
return cva({
|
|
783
|
+
base: mergeCss(base, override.base),
|
|
784
|
+
variants: Object.fromEntries(
|
|
785
|
+
variantKeys.map((key) => [key, mergeCss(variants[key], override.variants[key])]),
|
|
786
|
+
),
|
|
787
|
+
defaultVariants: mergeProps(defaultVariants, override.defaultVariants),
|
|
788
|
+
compoundVariants: [...compoundVariants, ...override.compoundVariants],
|
|
789
|
+
})
|
|
790
|
+
}
|
|
791
|
+
|
|
778
792
|
function cvaFn(props) {
|
|
779
793
|
return css(resolve(props))
|
|
780
794
|
}
|
|
@@ -793,6 +807,7 @@ function generateCvaFn(ctx) {
|
|
|
793
807
|
variantKeys,
|
|
794
808
|
raw: resolve,
|
|
795
809
|
config,
|
|
810
|
+
merge,
|
|
796
811
|
splitVariantProps,
|
|
797
812
|
})
|
|
798
813
|
}
|
|
@@ -867,7 +882,7 @@ import { outdent as outdent8 } from "outdent";
|
|
|
867
882
|
|
|
868
883
|
// src/artifacts/generated/helpers.mjs.json
|
|
869
884
|
var helpers_mjs_default = {
|
|
870
|
-
content: '// src/assert.ts\nfunction isObject(value) {\n return typeof value === "object" && value != null && !Array.isArray(value);\n}\n\n// src/compact.ts\nfunction compact(value) {\n return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));\n}\n\n// src/condition.ts\nvar isBaseCondition = (v) => v === "base";\nfunction filterBaseConditions(c) {\n return c.slice().filter((v) => !isBaseCondition(v));\n}\n\n// src/css-important.ts\nvar importantRegex = /!(important)?$/;\nfunction isImportant(value) {\n return typeof value === "string" ? importantRegex.test(value) : false;\n}\nfunction withoutImportant(value) {\n return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;\n}\nfunction withoutSpace(str) {\n return typeof str === "string" ? str.replaceAll(" ", "_") : str;\n}\n\n// src/hash.ts\nfunction toChar(code) {\n return String.fromCharCode(code + (code > 25 ? 39 : 97));\n}\nfunction toName(code) {\n let name = "";\n let x;\n for (x = Math.abs(code); x > 52; x = x / 52 | 0)\n name = toChar(x % 52) + name;\n return toChar(x % 52) + name;\n}\nfunction toPhash(h, x) {\n let i = x.length;\n while (i)\n h = h * 33 ^ x.charCodeAt(--i);\n return h;\n}\nfunction toHash(value) {\n return toName(toPhash(5381, value) >>> 0);\n}\n\n// src/merge-props.ts\nfunction mergeProps(...sources) {\n const result = {};\n for (const source of
|
|
885
|
+
content: '// src/assert.ts\nfunction isObject(value) {\n return typeof value === "object" && value != null && !Array.isArray(value);\n}\n\n// src/compact.ts\nfunction compact(value) {\n return Object.fromEntries(Object.entries(value ?? {}).filter(([_, value2]) => value2 !== void 0));\n}\n\n// src/condition.ts\nvar isBaseCondition = (v) => v === "base";\nfunction filterBaseConditions(c) {\n return c.slice().filter((v) => !isBaseCondition(v));\n}\n\n// src/css-important.ts\nvar importantRegex = /!(important)?$/;\nfunction isImportant(value) {\n return typeof value === "string" ? importantRegex.test(value) : false;\n}\nfunction withoutImportant(value) {\n return typeof value === "string" ? value.replace(importantRegex, "").trim() : value;\n}\nfunction withoutSpace(str) {\n return typeof str === "string" ? str.replaceAll(" ", "_") : str;\n}\n\n// src/hash.ts\nfunction toChar(code) {\n return String.fromCharCode(code + (code > 25 ? 39 : 97));\n}\nfunction toName(code) {\n let name = "";\n let x;\n for (x = Math.abs(code); x > 52; x = x / 52 | 0)\n name = toChar(x % 52) + name;\n return toChar(x % 52) + name;\n}\nfunction toPhash(h, x) {\n let i = x.length;\n while (i)\n h = h * 33 ^ x.charCodeAt(--i);\n return h;\n}\nfunction toHash(value) {\n return toName(toPhash(5381, value) >>> 0);\n}\n\n// src/merge-props.ts\nfunction mergeProps(...sources) {\n const __sources = sources.filter(Boolean);\n const result = {};\n for (const source of __sources) {\n for (const [key, value] of Object.entries(source)) {\n if (isObject(value)) {\n result[key] = mergeProps(result[key] || {}, value);\n } else {\n result[key] = value;\n }\n }\n }\n return result;\n}\n\n// src/walk-object.ts\nvar isNotNullish = (element) => element != null;\nfunction walkObject(target, predicate, options = {}) {\n const { stop, getKey } = options;\n function inner(value, path = []) {\n if (isObject(value) || Array.isArray(value)) {\n const result = {};\n for (const [prop, child] of Object.entries(value)) {\n const key = getKey?.(prop) ?? prop;\n const childPath = [...path, key];\n if (stop?.(value, childPath)) {\n return predicate(value, path);\n }\n const next = inner(child, childPath);\n if (isNotNullish(next)) {\n result[key] = next;\n }\n }\n return result;\n }\n return predicate(value, path);\n }\n return inner(target);\n}\nfunction mapObject(obj, fn) {\n if (!isObject(obj))\n return fn(obj);\n return walkObject(obj, (value) => fn(value));\n}\n\n// src/normalize-style-object.ts\nfunction toResponsiveObject(values, breakpoints) {\n return values.reduce((acc, current, index) => {\n const key = breakpoints[index];\n if (current != null) {\n acc[key] = current;\n }\n return acc;\n }, {});\n}\nfunction normalizeShorthand(styles, context) {\n const { hasShorthand, resolveShorthand } = context.utility;\n return walkObject(styles, (v) => v, {\n getKey: (prop) => {\n return hasShorthand ? resolveShorthand(prop) : prop;\n }\n });\n}\nfunction normalizeStyleObject(styles, context) {\n const { utility, conditions } = context;\n const { hasShorthand, resolveShorthand } = utility;\n return walkObject(\n styles,\n (value) => {\n return Array.isArray(value) ? toResponsiveObject(value, conditions.breakpoints.keys) : value;\n },\n {\n stop: (value) => Array.isArray(value),\n getKey: (prop) => {\n return hasShorthand ? resolveShorthand(prop) : prop;\n }\n }\n );\n}\n\n// src/classname.ts\nvar fallbackCondition = {\n shift: (v) => v,\n finalize: (v) => v,\n breakpoints: { keys: [] }\n};\nvar sanitize = (value) => typeof value === "string" ? value.replaceAll(/[\\n\\s]+/g, " ") : value;\nfunction createCss(context) {\n const { utility, hash, conditions: conds = fallbackCondition } = context;\n const formatClassName = (str) => [utility.prefix, str].filter(Boolean).join("-");\n const hashFn = (conditions, className) => {\n let result;\n if (hash) {\n const baseArray = [...conds.finalize(conditions), className];\n result = formatClassName(toHash(baseArray.join(":")));\n } else {\n const baseArray = [...conds.finalize(conditions), formatClassName(className)];\n result = baseArray.join(":");\n }\n return result;\n };\n return (styleObject = {}) => {\n const normalizedObject = normalizeStyleObject(styleObject, context);\n const classNames = /* @__PURE__ */ new Set();\n walkObject(normalizedObject, (value, paths) => {\n const important = isImportant(value);\n if (value == null)\n return;\n const [prop, ...allConditions] = conds.shift(paths);\n const conditions = filterBaseConditions(allConditions);\n const transformed = utility.transform(prop, withoutImportant(sanitize(value)));\n let className = hashFn(conditions, transformed.className);\n if (important)\n className = `${className}!`;\n classNames.add(className);\n });\n return Array.from(classNames).join(" ");\n };\n}\nfunction compactStyles(...styles) {\n return styles.filter((style) => isObject(style) && Object.keys(compact(style)).length > 0);\n}\nfunction createMergeCss(context) {\n function resolve(styles) {\n const allStyles = compactStyles(...styles);\n if (allStyles.length === 1)\n return allStyles;\n return allStyles.map((style) => normalizeShorthand(style, context));\n }\n function mergeCss(...styles) {\n return mergeProps(...resolve(styles));\n }\n function assignCss(...styles) {\n return Object.assign({}, ...resolve(styles));\n }\n return { mergeCss, assignCss };\n}\n\n// src/memo.ts\nvar memo = (fn) => {\n const cache = /* @__PURE__ */ new Map();\n const get = (...args) => {\n const key = JSON.stringify(args);\n if (cache.has(key)) {\n return cache.get(key);\n }\n const result = fn(...args);\n cache.set(key, result);\n return result;\n };\n return get;\n};\n\n// src/hypenate-property.ts\nvar wordRegex = /([A-Z])/g;\nvar msRegex = /^ms-/;\nvar hypenateProperty = memo((property) => {\n if (property.startsWith("--"))\n return property;\n return property.replace(wordRegex, "-$1").replace(msRegex, "-ms-").toLowerCase();\n});\n\n// src/slot.ts\nvar getSlotRecipes = (recipe = {}) => {\n const init = (slot) => ({\n className: [recipe.className, slot].filter(Boolean).join("__"),\n base: recipe.base?.[slot] ?? {},\n variants: {},\n defaultVariants: recipe.defaultVariants ?? {},\n compoundVariants: recipe.compoundVariants ? getSlotCompoundVariant(recipe.compoundVariants, slot) : []\n });\n const slots = recipe.slots ?? [];\n const recipeParts = slots.map((slot) => [slot, init(slot)]);\n for (const [variantsKey, variantsSpec] of Object.entries(recipe.variants ?? {})) {\n for (const [variantKey, variantSpec] of Object.entries(variantsSpec)) {\n recipeParts.forEach(([slot, slotRecipe]) => {\n slotRecipe.variants[variantsKey] ??= {};\n slotRecipe.variants[variantsKey][variantKey] = variantSpec[slot] ?? {};\n });\n }\n }\n return Object.fromEntries(recipeParts);\n};\nvar getSlotCompoundVariant = (compoundVariants, slotName) => compoundVariants.filter((compoundVariant) => compoundVariant.css[slotName]).map((compoundVariant) => ({ ...compoundVariant, css: compoundVariant.css[slotName] }));\n\n// src/split-props.ts\nfunction splitProps(props, ...keys) {\n const descriptors = Object.getOwnPropertyDescriptors(props);\n const dKeys = Object.keys(descriptors);\n const split = (k) => {\n const clone = {};\n for (let i = 0; i < k.length; i++) {\n const key = k[i];\n if (descriptors[key]) {\n Object.defineProperty(clone, key, descriptors[key]);\n delete descriptors[key];\n }\n }\n return clone;\n };\n const fn = (key) => split(Array.isArray(key) ? key : dKeys.filter(key));\n return keys.map(fn).concat(split(dKeys));\n}\n\n// src/uniq.ts\nvar uniq = (...items) => items.filter(Boolean).reduce((acc, item) => Array.from(/* @__PURE__ */ new Set([...acc, ...item])), []);\nexport {\n compact,\n createCss,\n createMergeCss,\n filterBaseConditions,\n getSlotCompoundVariant,\n getSlotRecipes,\n hypenateProperty,\n isBaseCondition,\n isObject,\n mapObject,\n memo,\n mergeProps,\n splitProps,\n toHash,\n uniq,\n walkObject,\n withoutSpace\n};\n'
|
|
871
886
|
};
|
|
872
887
|
|
|
873
888
|
// src/artifacts/generated/astish.mjs.json
|
|
@@ -935,11 +950,52 @@ function generateIsValidProp(ctx) {
|
|
|
935
950
|
};
|
|
936
951
|
}
|
|
937
952
|
|
|
953
|
+
// src/artifacts/js/jsx-helper.ts
|
|
954
|
+
import { outdent as outdent10 } from "outdent";
|
|
955
|
+
import { match as match2 } from "ts-pattern";
|
|
956
|
+
function generatedJsxHelpers(ctx) {
|
|
957
|
+
return {
|
|
958
|
+
js: match2(ctx.isTemplateLiteralSyntax).with(
|
|
959
|
+
true,
|
|
960
|
+
() => outdent10`
|
|
961
|
+
export const getDisplayName = (Component) => {
|
|
962
|
+
if (typeof Component === 'string') return Component
|
|
963
|
+
return Component?.displayName || Component?.name || 'Component'
|
|
964
|
+
}`
|
|
965
|
+
).otherwise(
|
|
966
|
+
() => outdent10`
|
|
967
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
968
|
+
|
|
969
|
+
export const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
970
|
+
|
|
971
|
+
export const composeShouldForwardProps = (tag, shouldForwardProp) =>
|
|
972
|
+
tag.__shouldForwardProps__ && shouldForwardProp
|
|
973
|
+
? (propName) => tag.__shouldForwardProps__(propName) && shouldForwardProp(propName)
|
|
974
|
+
: shouldForwardProp
|
|
975
|
+
|
|
976
|
+
export const composeCvaFn = (cvaA, cvaB) => {
|
|
977
|
+
if (cvaA && !cvaB) return cvaA
|
|
978
|
+
if (!cvaA && cvaB) return cvaB
|
|
979
|
+
if ((cvaA.__cva__ && cvaB.__cva__) || (cvaA.__recipe__ && cvaB.__recipe__)) return cvaA.merge(cvaB.config)
|
|
980
|
+
const error = new TypeError('Cannot merge cva with recipe. Please use either cva or recipe.')
|
|
981
|
+
TypeError.captureStackTrace?.(error)
|
|
982
|
+
throw error
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
export const getDisplayName = (Component) => {
|
|
986
|
+
if (typeof Component === 'string') return Component
|
|
987
|
+
return Component?.displayName || Component?.name || 'Component'
|
|
988
|
+
}
|
|
989
|
+
`
|
|
990
|
+
)
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
|
|
938
994
|
// src/artifacts/js/pattern.ts
|
|
939
995
|
import { unionType } from "@pandacss/shared";
|
|
940
996
|
import { stringify } from "javascript-stringify";
|
|
941
|
-
import { outdent as
|
|
942
|
-
import { match as
|
|
997
|
+
import { outdent as outdent11 } from "outdent";
|
|
998
|
+
import { match as match3 } from "ts-pattern";
|
|
943
999
|
function generatePattern(ctx) {
|
|
944
1000
|
if (ctx.patterns.isEmpty())
|
|
945
1001
|
return;
|
|
@@ -956,7 +1012,7 @@ function generatePattern(ctx) {
|
|
|
956
1012
|
}
|
|
957
1013
|
return {
|
|
958
1014
|
name: dashName,
|
|
959
|
-
dts:
|
|
1015
|
+
dts: outdent11`
|
|
960
1016
|
${ctx.file.importType("SystemStyleObject, ConditionalValue", "../types/index")}
|
|
961
1017
|
${ctx.file.importType("Properties", "../types/csstype")}
|
|
962
1018
|
${ctx.file.importType("PropertyValue", "../types/prop-type")}
|
|
@@ -966,7 +1022,7 @@ function generatePattern(ctx) {
|
|
|
966
1022
|
export interface ${upperName}Properties {
|
|
967
1023
|
${Object.keys(properties ?? {}).map((key) => {
|
|
968
1024
|
const value = properties[key];
|
|
969
|
-
return
|
|
1025
|
+
return match3(value).with({ type: "property" }, (value2) => {
|
|
970
1026
|
return `${key}?: PropertyValue<'${value2.value}'>`;
|
|
971
1027
|
}).with({ type: "token" }, (value2) => {
|
|
972
1028
|
if (value2.property) {
|
|
@@ -981,7 +1037,7 @@ function generatePattern(ctx) {
|
|
|
981
1037
|
}).join("\n ")}
|
|
982
1038
|
}
|
|
983
1039
|
|
|
984
|
-
${strict ?
|
|
1040
|
+
${strict ? outdent11`export declare function ${baseName}(styles: ${upperName}Properties): string` : outdent11`
|
|
985
1041
|
|
|
986
1042
|
interface ${upperName}Styles extends ${upperName}Properties, DistributiveOmit<SystemStyleObject, keyof ${upperName}Properties ${blocklistType}> {}
|
|
987
1043
|
|
|
@@ -995,7 +1051,7 @@ function generatePattern(ctx) {
|
|
|
995
1051
|
`}
|
|
996
1052
|
|
|
997
1053
|
`,
|
|
998
|
-
js:
|
|
1054
|
+
js: outdent11`
|
|
999
1055
|
${ctx.file.import(helperImports.join(", "), "../helpers")}
|
|
1000
1056
|
${ctx.file.import("css", "../css/index")}
|
|
1001
1057
|
|
|
@@ -1014,8 +1070,8 @@ transform`)}
|
|
|
1014
1070
|
// src/artifacts/js/recipe.ts
|
|
1015
1071
|
import { isSlotRecipe } from "@pandacss/core";
|
|
1016
1072
|
import { unionType as unionType2 } from "@pandacss/shared";
|
|
1017
|
-
import { outdent as
|
|
1018
|
-
import { match as
|
|
1073
|
+
import { outdent as outdent12 } from "outdent";
|
|
1074
|
+
import { match as match4 } from "ts-pattern";
|
|
1019
1075
|
var stringify2 = (value) => JSON.stringify(value, null, 2);
|
|
1020
1076
|
var isBooleanValue = (value) => value === "true" || value === "false";
|
|
1021
1077
|
function generateRecipes(ctx) {
|
|
@@ -1029,11 +1085,11 @@ function generateRecipes(ctx) {
|
|
|
1029
1085
|
const createRecipeFn = {
|
|
1030
1086
|
name: "create-recipe",
|
|
1031
1087
|
dts: "",
|
|
1032
|
-
js:
|
|
1088
|
+
js: outdent12`
|
|
1033
1089
|
${ctx.file.import("css", "../css/css")}
|
|
1034
1090
|
${ctx.file.import("assertCompoundVariant, getCompoundVariantCss", "../css/cva")}
|
|
1035
1091
|
${ctx.file.import("cx", "../css/cx")}
|
|
1036
|
-
${ctx.file.import("compact, createCss, withoutSpace", "../helpers")}
|
|
1092
|
+
${ctx.file.import("compact, createCss, splitProps, uniq, withoutSpace", "../helpers")}
|
|
1037
1093
|
|
|
1038
1094
|
export const createRecipe = (name, defaultVariants, compoundVariants) => {
|
|
1039
1095
|
const getRecipeStyles = (variants) => {
|
|
@@ -1080,6 +1136,30 @@ function generateRecipes(ctx) {
|
|
|
1080
1136
|
},
|
|
1081
1137
|
})
|
|
1082
1138
|
}
|
|
1139
|
+
|
|
1140
|
+
export const mergeRecipes = (recipeA, recipeB) => {
|
|
1141
|
+
if (recipeA && !recipeB) return recipeA
|
|
1142
|
+
if (!recipeA && recipeB) return recipeB
|
|
1143
|
+
|
|
1144
|
+
const recipeFn = (...args) => cx(recipeA(...args), recipeB(...args))
|
|
1145
|
+
const variantKeys = uniq(recipeA.variantKeys, recipeB.variantKeys)
|
|
1146
|
+
const variantMap = variantKeys.reduce((acc, key) => {
|
|
1147
|
+
acc[key] = uniq(recipeA.variantMap[key], recipeB.variantMap[key])
|
|
1148
|
+
return acc
|
|
1149
|
+
}, {})
|
|
1150
|
+
|
|
1151
|
+
return Object.assign(recipeFn, {
|
|
1152
|
+
__recipe__: true,
|
|
1153
|
+
__name__: \`$\{recipeA.__name__} \${recipeB.__name__}\`,
|
|
1154
|
+
raw: (props) => props,
|
|
1155
|
+
variantKeys,
|
|
1156
|
+
variantMap,
|
|
1157
|
+
splitVariantProps(props) {
|
|
1158
|
+
return splitProps(props, variantKeys)
|
|
1159
|
+
},
|
|
1160
|
+
})
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1083
1163
|
`
|
|
1084
1164
|
};
|
|
1085
1165
|
return [
|
|
@@ -1087,9 +1167,9 @@ function generateRecipes(ctx) {
|
|
|
1087
1167
|
...ctx.recipes.details.map((recipe) => {
|
|
1088
1168
|
const { baseName, config, upperName, variantKeyMap, dashName } = recipe;
|
|
1089
1169
|
const { description, defaultVariants, compoundVariants } = config;
|
|
1090
|
-
const jsCode =
|
|
1170
|
+
const jsCode = match4(config).when(
|
|
1091
1171
|
isSlotRecipe,
|
|
1092
|
-
(config2) =>
|
|
1172
|
+
(config2) => outdent12`
|
|
1093
1173
|
${ctx.file.import("splitProps, getSlotCompoundVariant", "../helpers")}
|
|
1094
1174
|
${ctx.file.import("createRecipe", "./create-recipe")}
|
|
1095
1175
|
|
|
@@ -1117,9 +1197,9 @@ function generateRecipes(ctx) {
|
|
|
1117
1197
|
})
|
|
1118
1198
|
`
|
|
1119
1199
|
).otherwise(
|
|
1120
|
-
(config2) =>
|
|
1200
|
+
(config2) => outdent12`
|
|
1121
1201
|
${ctx.file.import("splitProps", "../helpers")}
|
|
1122
|
-
${ctx.file.import("createRecipe", "./create-recipe")}
|
|
1202
|
+
${ctx.file.import("createRecipe, mergeRecipes", "./create-recipe")}
|
|
1123
1203
|
|
|
1124
1204
|
const ${baseName}Fn = /* @__PURE__ */ createRecipe('${config2.className}', ${stringify2(
|
|
1125
1205
|
defaultVariants ?? {}
|
|
@@ -1135,6 +1215,9 @@ function generateRecipes(ctx) {
|
|
|
1135
1215
|
raw: (props) => props,
|
|
1136
1216
|
variantKeys: ${baseName}VariantKeys,
|
|
1137
1217
|
variantMap: ${baseName}VariantMap,
|
|
1218
|
+
merge(recipe) {
|
|
1219
|
+
return mergeRecipes(this, recipe)
|
|
1220
|
+
},
|
|
1138
1221
|
splitVariantProps(props) {
|
|
1139
1222
|
return splitProps(props, ${baseName}VariantKeys)
|
|
1140
1223
|
},
|
|
@@ -1144,10 +1227,9 @@ function generateRecipes(ctx) {
|
|
|
1144
1227
|
return {
|
|
1145
1228
|
name: dashName,
|
|
1146
1229
|
js: jsCode,
|
|
1147
|
-
dts:
|
|
1230
|
+
dts: outdent12`
|
|
1148
1231
|
${ctx.file.importType("ConditionalValue", "../types/index")}
|
|
1149
|
-
${ctx.file.importType("Pretty", "../types/
|
|
1150
|
-
${ctx.file.importType("DistributiveOmit", "../types/system-types")}
|
|
1232
|
+
${ctx.file.importType("DistributiveOmit, Pretty", "../types/system-types")}
|
|
1151
1233
|
|
|
1152
1234
|
interface ${upperName}Variant {
|
|
1153
1235
|
${Object.keys(variantKeyMap).map((key) => {
|
|
@@ -1184,10 +1266,10 @@ function generateRecipes(ctx) {
|
|
|
1184
1266
|
}
|
|
1185
1267
|
|
|
1186
1268
|
// src/artifacts/js/sva.ts
|
|
1187
|
-
import { outdent as
|
|
1269
|
+
import { outdent as outdent13 } from "outdent";
|
|
1188
1270
|
function generateSvaFn(ctx) {
|
|
1189
1271
|
return {
|
|
1190
|
-
js:
|
|
1272
|
+
js: outdent13`
|
|
1191
1273
|
${ctx.file.import("getSlotRecipes, splitProps", "../helpers")}
|
|
1192
1274
|
${ctx.file.import("cva", "./cva")}
|
|
1193
1275
|
|
|
@@ -1224,7 +1306,7 @@ function generateSvaFn(ctx) {
|
|
|
1224
1306
|
})
|
|
1225
1307
|
}
|
|
1226
1308
|
`,
|
|
1227
|
-
dts:
|
|
1309
|
+
dts: outdent13`
|
|
1228
1310
|
${ctx.file.importType("SlotRecipeCreatorFn", "../types/recipe")}
|
|
1229
1311
|
|
|
1230
1312
|
export declare const sva: SlotRecipeCreatorFn
|
|
@@ -1233,7 +1315,7 @@ function generateSvaFn(ctx) {
|
|
|
1233
1315
|
}
|
|
1234
1316
|
|
|
1235
1317
|
// src/artifacts/js/token.ts
|
|
1236
|
-
import
|
|
1318
|
+
import outdent14 from "outdent";
|
|
1237
1319
|
function generateTokenJs(ctx) {
|
|
1238
1320
|
const { tokens } = ctx;
|
|
1239
1321
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -1244,7 +1326,7 @@ function generateTokenJs(ctx) {
|
|
|
1244
1326
|
});
|
|
1245
1327
|
const obj = Object.fromEntries(map);
|
|
1246
1328
|
return {
|
|
1247
|
-
js:
|
|
1329
|
+
js: outdent14`
|
|
1248
1330
|
const tokens = ${JSON.stringify(obj, null, 2)}
|
|
1249
1331
|
|
|
1250
1332
|
export function token(path, fallback) {
|
|
@@ -1257,7 +1339,7 @@ function generateTokenJs(ctx) {
|
|
|
1257
1339
|
|
|
1258
1340
|
token.var = tokenVar
|
|
1259
1341
|
`,
|
|
1260
|
-
dts:
|
|
1342
|
+
dts: outdent14`
|
|
1261
1343
|
${ctx.file.importType("Token", "./tokens")}
|
|
1262
1344
|
|
|
1263
1345
|
export declare const token: {
|
|
@@ -1271,19 +1353,21 @@ function generateTokenJs(ctx) {
|
|
|
1271
1353
|
}
|
|
1272
1354
|
|
|
1273
1355
|
// src/artifacts/preact-jsx/jsx.ts
|
|
1274
|
-
import { outdent as
|
|
1356
|
+
import { outdent as outdent15 } from "outdent";
|
|
1275
1357
|
function generatePreactJsxFactory(ctx) {
|
|
1276
1358
|
const { factoryName, componentName } = ctx.jsx;
|
|
1277
1359
|
return {
|
|
1278
|
-
js:
|
|
1360
|
+
js: outdent15`
|
|
1279
1361
|
import { h } from 'preact'
|
|
1280
1362
|
import { forwardRef } from 'preact/compat'
|
|
1281
1363
|
import { useMemo } from 'preact/hooks'
|
|
1364
|
+
${ctx.file.import(
|
|
1365
|
+
"defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName",
|
|
1366
|
+
"./factory-helper"
|
|
1367
|
+
)}
|
|
1368
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1282
1369
|
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1283
1370
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1284
|
-
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1285
|
-
|
|
1286
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1287
1371
|
|
|
1288
1372
|
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1289
1373
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
@@ -1297,23 +1381,26 @@ function generatePreactJsxFactory(ctx) {
|
|
|
1297
1381
|
)
|
|
1298
1382
|
|
|
1299
1383
|
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
1300
|
-
const { as: Element = Dynamic, children, ...restProps } = props
|
|
1384
|
+
const { as: Element = Dynamic.__base__ || Dynamic, children, ...restProps } = props
|
|
1385
|
+
|
|
1386
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
1387
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
1301
1388
|
|
|
1302
1389
|
const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
|
|
1303
1390
|
|
|
1304
1391
|
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1305
|
-
return splitProps(combinedProps,
|
|
1392
|
+
return splitProps(combinedProps, __shouldForwardProps__, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1306
1393
|
}, [combinedProps])
|
|
1307
1394
|
|
|
1308
1395
|
function recipeClass() {
|
|
1309
1396
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1310
|
-
const compoundVariantStyles =
|
|
1311
|
-
return cx(
|
|
1397
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps)
|
|
1398
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.class, combinedProps.className)
|
|
1312
1399
|
}
|
|
1313
1400
|
|
|
1314
1401
|
function cvaClass() {
|
|
1315
1402
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1316
|
-
const cvaStyles =
|
|
1403
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
1317
1404
|
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.class, combinedProps.className)
|
|
1318
1405
|
}
|
|
1319
1406
|
|
|
@@ -1329,8 +1416,13 @@ function generatePreactJsxFactory(ctx) {
|
|
|
1329
1416
|
})
|
|
1330
1417
|
})
|
|
1331
1418
|
|
|
1332
|
-
const name = (
|
|
1419
|
+
const name = getDisplayName(Dynamic)
|
|
1420
|
+
|
|
1333
1421
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
1422
|
+
${componentName}.__cva__ = cvaFn
|
|
1423
|
+
${componentName}.__base__ = Dynamic
|
|
1424
|
+
${componentName}.__shouldForwardProps__ = shouldForwardProp
|
|
1425
|
+
|
|
1334
1426
|
return ${componentName}
|
|
1335
1427
|
}
|
|
1336
1428
|
|
|
@@ -1356,8 +1448,8 @@ function generatePreactJsxFactory(ctx) {
|
|
|
1356
1448
|
}
|
|
1357
1449
|
|
|
1358
1450
|
// src/artifacts/preact-jsx/pattern.ts
|
|
1359
|
-
import { outdent as
|
|
1360
|
-
import { match as
|
|
1451
|
+
import { outdent as outdent16 } from "outdent";
|
|
1452
|
+
import { match as match5 } from "ts-pattern";
|
|
1361
1453
|
function generatePreactJsxPattern(ctx) {
|
|
1362
1454
|
const { typeName, factoryName } = ctx.jsx;
|
|
1363
1455
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1365,21 +1457,21 @@ function generatePreactJsxPattern(ctx) {
|
|
|
1365
1457
|
const { description, jsxElement = "div" } = pattern.config;
|
|
1366
1458
|
return {
|
|
1367
1459
|
name: dashName,
|
|
1368
|
-
js:
|
|
1460
|
+
js: outdent16`
|
|
1369
1461
|
import { h } from 'preact'
|
|
1370
1462
|
import { forwardRef } from 'preact/compat'
|
|
1371
1463
|
${ctx.file.import(factoryName, "./factory")}
|
|
1372
1464
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1373
1465
|
|
|
1374
1466
|
export const ${jsxName} = /* @__PURE__ */ forwardRef(function ${jsxName}(props, ref) {
|
|
1375
|
-
${
|
|
1467
|
+
${match5(props.length).with(
|
|
1376
1468
|
0,
|
|
1377
|
-
() =>
|
|
1469
|
+
() => outdent16`
|
|
1378
1470
|
const styleProps = ${styleFnName}()
|
|
1379
1471
|
return h(${factoryName}.${jsxElement}, { ref, ...styleProps, ...props })
|
|
1380
1472
|
`
|
|
1381
1473
|
).otherwise(
|
|
1382
|
-
() =>
|
|
1474
|
+
() => outdent16`
|
|
1383
1475
|
const { ${props.join(", ")}, ...restProps } = props
|
|
1384
1476
|
const styleProps = ${styleFnName}({${props.join(", ")}})
|
|
1385
1477
|
return h(${factoryName}.${jsxElement}, { ref, ...styleProps, ...restProps })
|
|
@@ -1387,7 +1479,7 @@ function generatePreactJsxPattern(ctx) {
|
|
|
1387
1479
|
)}
|
|
1388
1480
|
})
|
|
1389
1481
|
`,
|
|
1390
|
-
dts:
|
|
1482
|
+
dts: outdent16`
|
|
1391
1483
|
import type { FunctionComponent } from 'preact'
|
|
1392
1484
|
${ctx.file.importType(`${upperName}Properties`, `../patterns/${dashName}`)}
|
|
1393
1485
|
${ctx.file.importType("DistributiveOmit", "../types/system-types")}
|
|
@@ -1403,48 +1495,61 @@ function generatePreactJsxPattern(ctx) {
|
|
|
1403
1495
|
}
|
|
1404
1496
|
|
|
1405
1497
|
// src/artifacts/preact-jsx/types.ts
|
|
1406
|
-
import { outdent as
|
|
1498
|
+
import { outdent as outdent17 } from "outdent";
|
|
1407
1499
|
function generatePreactJsxTypes(ctx) {
|
|
1408
1500
|
const { factoryName, componentName, upperName, typeName, variantName } = ctx.jsx;
|
|
1409
1501
|
return {
|
|
1410
|
-
jsxFactory:
|
|
1502
|
+
jsxFactory: outdent17`
|
|
1411
1503
|
import type { ${upperName} } from '../types/jsx'
|
|
1412
1504
|
export declare const ${factoryName}: ${upperName}
|
|
1413
1505
|
`,
|
|
1414
|
-
jsxType:
|
|
1506
|
+
jsxType: outdent17`
|
|
1415
1507
|
import type { ComponentProps, JSX } from 'preact'
|
|
1416
|
-
${ctx.file.importType("Assign, JsxStyleProps, JsxHTMLProps", "./system-types")}
|
|
1417
1508
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
1509
|
+
${ctx.file.importType(
|
|
1510
|
+
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
1511
|
+
"./system-types"
|
|
1512
|
+
)}
|
|
1418
1513
|
|
|
1419
|
-
type ElementType =
|
|
1514
|
+
export type ElementType = JSX.ElementType
|
|
1420
1515
|
|
|
1421
|
-
|
|
1516
|
+
interface Dict {
|
|
1517
|
+
[k: string]: unknown
|
|
1518
|
+
}
|
|
1422
1519
|
|
|
1423
1520
|
export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
1424
1521
|
(props: JsxHTMLProps<ComponentProps<T>, P> & JsxStyleProps): JSX.Element
|
|
1425
1522
|
displayName?: string
|
|
1426
1523
|
}
|
|
1427
1524
|
|
|
1428
|
-
interface RecipeFn {
|
|
1525
|
+
interface RecipeFn {
|
|
1526
|
+
__type: any
|
|
1527
|
+
}
|
|
1429
1528
|
|
|
1430
|
-
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1529
|
+
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1431
1530
|
dataAttr?: boolean
|
|
1432
1531
|
defaultProps?: TProps
|
|
1433
1532
|
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
1434
1533
|
}
|
|
1435
1534
|
|
|
1436
|
-
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P
|
|
1535
|
+
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>
|
|
1536
|
+
|
|
1537
|
+
export type JsxElement<T extends ElementType, P> = T extends ${componentName}<infer A, infer B>
|
|
1538
|
+
? ${componentName}<A, Pretty<DistributiveUnion<P, B>>>
|
|
1539
|
+
: ${componentName}<T, P>
|
|
1437
1540
|
|
|
1438
|
-
interface JsxFactory {
|
|
1541
|
+
export interface JsxFactory {
|
|
1439
1542
|
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1440
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
1543
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
1441
1544
|
T,
|
|
1442
1545
|
RecipeSelection<P>
|
|
1443
1546
|
>
|
|
1444
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>):
|
|
1547
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
|
|
1445
1548
|
}
|
|
1446
1549
|
|
|
1447
|
-
type JsxElements = {
|
|
1550
|
+
export type JsxElements = {
|
|
1551
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}>
|
|
1552
|
+
}
|
|
1448
1553
|
|
|
1449
1554
|
export type ${upperName} = JsxFactory & JsxElements
|
|
1450
1555
|
|
|
@@ -1456,21 +1561,26 @@ export type ${variantName}<T extends ${componentName}<any, any>> = T extends ${c
|
|
|
1456
1561
|
}
|
|
1457
1562
|
|
|
1458
1563
|
// src/artifacts/preact-jsx/jsx.string-literal.ts
|
|
1459
|
-
import { outdent as
|
|
1564
|
+
import { outdent as outdent18 } from "outdent";
|
|
1460
1565
|
function generatePreactJsxStringLiteralFactory(ctx) {
|
|
1461
1566
|
const { factoryName, componentName } = ctx.jsx;
|
|
1462
1567
|
return {
|
|
1463
|
-
js:
|
|
1568
|
+
js: outdent18`
|
|
1464
1569
|
import { h } from 'preact'
|
|
1465
1570
|
import { forwardRef } from 'preact/compat'
|
|
1571
|
+
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
1466
1572
|
${ctx.file.import("css, cx", "../css/index")}
|
|
1467
1573
|
|
|
1468
1574
|
function createStyledFn(Dynamic) {
|
|
1469
1575
|
return function styledFn(template) {
|
|
1470
|
-
const
|
|
1576
|
+
const styles = css.raw(template)
|
|
1577
|
+
|
|
1471
1578
|
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
1472
|
-
const { as: Element = Dynamic, ...elementProps } = props
|
|
1473
|
-
|
|
1579
|
+
const { as: Element = Dynamic.__base__ || Dynamic, ...elementProps } = props
|
|
1580
|
+
|
|
1581
|
+
function classes() {
|
|
1582
|
+
return cx(css(Dynamic.__styles__, styles), elementProps.className)
|
|
1583
|
+
}
|
|
1474
1584
|
|
|
1475
1585
|
return h(Element, {
|
|
1476
1586
|
ref,
|
|
@@ -1479,8 +1589,12 @@ function generatePreactJsxStringLiteralFactory(ctx) {
|
|
|
1479
1589
|
})
|
|
1480
1590
|
})
|
|
1481
1591
|
|
|
1482
|
-
const name = (
|
|
1592
|
+
const name = getDisplayName(Dynamic)
|
|
1593
|
+
|
|
1483
1594
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
1595
|
+
${componentName}.__styles__ = styles
|
|
1596
|
+
${componentName}.__base__ = Dynamic
|
|
1597
|
+
|
|
1484
1598
|
return ${componentName}
|
|
1485
1599
|
}
|
|
1486
1600
|
}
|
|
@@ -1507,31 +1621,35 @@ function generatePreactJsxStringLiteralFactory(ctx) {
|
|
|
1507
1621
|
}
|
|
1508
1622
|
|
|
1509
1623
|
// src/artifacts/preact-jsx/types.string-literal.ts
|
|
1510
|
-
import { outdent as
|
|
1624
|
+
import { outdent as outdent19 } from "outdent";
|
|
1511
1625
|
function generatePreactJsxStringLiteralTypes(ctx) {
|
|
1512
1626
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1513
1627
|
return {
|
|
1514
|
-
jsxFactory:
|
|
1628
|
+
jsxFactory: outdent19`
|
|
1515
1629
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
1516
1630
|
export declare const ${factoryName}: ${upperName}
|
|
1517
1631
|
`,
|
|
1518
|
-
jsxType:
|
|
1632
|
+
jsxType: outdent19`
|
|
1519
1633
|
import type { ComponentProps, JSX } from 'preact'
|
|
1520
1634
|
|
|
1521
|
-
type ElementType =
|
|
1635
|
+
export type ElementType = JSX.ElementType
|
|
1522
1636
|
|
|
1523
|
-
|
|
1637
|
+
interface Dict {
|
|
1638
|
+
[k: string]: unknown
|
|
1639
|
+
}
|
|
1524
1640
|
|
|
1525
1641
|
export type ${componentName}<T extends ElementType> = {
|
|
1526
1642
|
(args: { raw: readonly string[] | ArrayLike<string> }): (props: ComponentProps<T>) => JSX.Element
|
|
1527
1643
|
displayName?: string
|
|
1528
1644
|
}
|
|
1529
1645
|
|
|
1530
|
-
interface JsxFactory {
|
|
1646
|
+
export interface JsxFactory {
|
|
1531
1647
|
<T extends ElementType>(component: T): ${componentName}<T>
|
|
1532
1648
|
}
|
|
1533
1649
|
|
|
1534
|
-
type JsxElements = {
|
|
1650
|
+
export type JsxElements = {
|
|
1651
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K>
|
|
1652
|
+
}
|
|
1535
1653
|
|
|
1536
1654
|
export type ${upperName} = JsxFactory & JsxElements
|
|
1537
1655
|
|
|
@@ -1541,18 +1659,20 @@ export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
|
1541
1659
|
}
|
|
1542
1660
|
|
|
1543
1661
|
// src/artifacts/qwik-jsx/jsx.ts
|
|
1544
|
-
import { outdent as
|
|
1662
|
+
import { outdent as outdent20 } from "outdent";
|
|
1545
1663
|
function generateQwikJsxFactory(ctx) {
|
|
1546
1664
|
const { factoryName, componentName } = ctx.jsx;
|
|
1547
1665
|
return {
|
|
1548
|
-
js:
|
|
1666
|
+
js: outdent20`
|
|
1549
1667
|
import { h } from '@builder.io/qwik'
|
|
1668
|
+
${ctx.file.import(
|
|
1669
|
+
"defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName",
|
|
1670
|
+
"./factory-helper"
|
|
1671
|
+
)}
|
|
1672
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1550
1673
|
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1551
1674
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1552
|
-
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1553
1675
|
|
|
1554
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1555
|
-
|
|
1556
1676
|
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1557
1677
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1558
1678
|
|
|
@@ -1565,22 +1685,25 @@ function generateQwikJsxFactory(ctx) {
|
|
|
1565
1685
|
)
|
|
1566
1686
|
|
|
1567
1687
|
const ${componentName} = function ${componentName}(props) {
|
|
1568
|
-
const { as: Element = Dynamic, children, className, ...restProps } = props
|
|
1688
|
+
const { as: Element = Dynamic.__base__ || Dynamic, children, className, ...restProps } = props
|
|
1689
|
+
|
|
1690
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
1691
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
1569
1692
|
|
|
1570
1693
|
const combinedProps = Object.assign({}, defaultProps, restProps)
|
|
1571
1694
|
|
|
1572
1695
|
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] =
|
|
1573
|
-
splitProps(combinedProps,
|
|
1574
|
-
|
|
1575
|
-
const { css: cssStyles, ...propStyles } = styleProps
|
|
1696
|
+
splitProps(combinedProps, __shouldForwardProps__, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1576
1697
|
|
|
1577
1698
|
function recipeClass() {
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1699
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1700
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps);
|
|
1701
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.class, className)
|
|
1580
1702
|
}
|
|
1581
|
-
|
|
1703
|
+
|
|
1582
1704
|
function cvaClass() {
|
|
1583
|
-
const
|
|
1705
|
+
const { css: cssStyles, ...propStyles } = styleProps
|
|
1706
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
1584
1707
|
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.class, className)
|
|
1585
1708
|
}
|
|
1586
1709
|
|
|
@@ -1595,8 +1718,13 @@ function generateQwikJsxFactory(ctx) {
|
|
|
1595
1718
|
})
|
|
1596
1719
|
}
|
|
1597
1720
|
|
|
1598
|
-
const name = (
|
|
1721
|
+
const name = getDisplayName(Dynamic)
|
|
1722
|
+
|
|
1599
1723
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
1724
|
+
${componentName}.__cva__ = cvaFn
|
|
1725
|
+
${componentName}.__base__ = Dynamic
|
|
1726
|
+
${componentName}.__shouldForwardProps__ = shouldForwardProp
|
|
1727
|
+
|
|
1600
1728
|
return ${componentName}
|
|
1601
1729
|
}
|
|
1602
1730
|
|
|
@@ -1623,8 +1751,8 @@ function generateQwikJsxFactory(ctx) {
|
|
|
1623
1751
|
}
|
|
1624
1752
|
|
|
1625
1753
|
// src/artifacts/qwik-jsx/pattern.ts
|
|
1626
|
-
import { outdent as
|
|
1627
|
-
import { match as
|
|
1754
|
+
import { outdent as outdent21 } from "outdent";
|
|
1755
|
+
import { match as match6 } from "ts-pattern";
|
|
1628
1756
|
function generateQwikJsxPattern(ctx) {
|
|
1629
1757
|
const { typeName, factoryName } = ctx.jsx;
|
|
1630
1758
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1632,20 +1760,20 @@ function generateQwikJsxPattern(ctx) {
|
|
|
1632
1760
|
const { description, jsxElement = "div" } = pattern.config;
|
|
1633
1761
|
return {
|
|
1634
1762
|
name: dashName,
|
|
1635
|
-
js:
|
|
1763
|
+
js: outdent21`
|
|
1636
1764
|
import { h } from '@builder.io/qwik'
|
|
1637
1765
|
${ctx.file.import(factoryName, "./factory")}
|
|
1638
1766
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1639
1767
|
|
|
1640
1768
|
export const ${jsxName} = function ${jsxName}(props) {
|
|
1641
|
-
${
|
|
1769
|
+
${match6(props.length).with(
|
|
1642
1770
|
0,
|
|
1643
|
-
() =>
|
|
1771
|
+
() => outdent21`
|
|
1644
1772
|
const styleProps = ${styleFnName}()
|
|
1645
1773
|
return h(${factoryName}.${jsxElement}, { ...styleProps, ...props })
|
|
1646
1774
|
`
|
|
1647
1775
|
).otherwise(
|
|
1648
|
-
() =>
|
|
1776
|
+
() => outdent21`
|
|
1649
1777
|
const { ${props.join(", ")}, ...restProps } = props
|
|
1650
1778
|
const styleProps = ${styleFnName}({${props.join(", ")}})
|
|
1651
1779
|
return h(${factoryName}.${jsxElement}, { ...styleProps, ...restProps })
|
|
@@ -1653,7 +1781,7 @@ function generateQwikJsxPattern(ctx) {
|
|
|
1653
1781
|
)}
|
|
1654
1782
|
}
|
|
1655
1783
|
`,
|
|
1656
|
-
dts:
|
|
1784
|
+
dts: outdent21`
|
|
1657
1785
|
import type { Component } from '@builder.io/qwik'
|
|
1658
1786
|
${ctx.file.importType(`${upperName}Properties`, `../patterns/${dashName}`)}
|
|
1659
1787
|
${ctx.file.importType(typeName, "../types/jsx")}
|
|
@@ -1669,20 +1797,23 @@ function generateQwikJsxPattern(ctx) {
|
|
|
1669
1797
|
}
|
|
1670
1798
|
|
|
1671
1799
|
// src/artifacts/qwik-jsx/types.ts
|
|
1672
|
-
import { outdent as
|
|
1800
|
+
import { outdent as outdent22 } from "outdent";
|
|
1673
1801
|
function generateQwikJsxTypes(ctx) {
|
|
1674
1802
|
const { factoryName, componentName, upperName, typeName, variantName } = ctx.jsx;
|
|
1675
1803
|
return {
|
|
1676
|
-
jsxFactory:
|
|
1804
|
+
jsxFactory: outdent22`
|
|
1677
1805
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
1678
1806
|
export declare const ${factoryName}: ${upperName}
|
|
1679
1807
|
`,
|
|
1680
|
-
jsxType:
|
|
1808
|
+
jsxType: outdent22`
|
|
1681
1809
|
import type { Component, QwikIntrinsicElements } from '@builder.io/qwik'
|
|
1682
|
-
|
|
1683
|
-
|
|
1810
|
+
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
1811
|
+
${ctx.file.importType(
|
|
1812
|
+
"Assign, DistributiveOmit, DistributiveUnion, JsxStyleProps, PatchedHTMLProps, Pretty",
|
|
1813
|
+
"./system-types"
|
|
1814
|
+
)}
|
|
1684
1815
|
|
|
1685
|
-
type ElementType = keyof QwikIntrinsicElements | Component<any>
|
|
1816
|
+
export type ElementType = keyof QwikIntrinsicElements | Component<any>
|
|
1686
1817
|
|
|
1687
1818
|
export type ComponentProps<T extends ElementType> = T extends keyof QwikIntrinsicElements
|
|
1688
1819
|
? QwikIntrinsicElements[T]
|
|
@@ -1690,13 +1821,17 @@ export type ComponentProps<T extends ElementType> = T extends keyof QwikIntrinsi
|
|
|
1690
1821
|
? P
|
|
1691
1822
|
: never
|
|
1692
1823
|
|
|
1693
|
-
|
|
1824
|
+
interface Dict {
|
|
1825
|
+
[k: string]: unknown
|
|
1826
|
+
}
|
|
1694
1827
|
|
|
1695
1828
|
export interface ${componentName}<T extends ElementType, P extends Dict = {}> extends Component<Assign<ComponentProps<T>, Assign<PatchedHTMLProps, Assign<JsxStyleProps, P>>>> {}
|
|
1696
1829
|
|
|
1697
|
-
interface RecipeFn {
|
|
1830
|
+
interface RecipeFn {
|
|
1831
|
+
__type: any
|
|
1832
|
+
}
|
|
1698
1833
|
|
|
1699
|
-
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1834
|
+
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1700
1835
|
dataAttr?: boolean
|
|
1701
1836
|
defaultProps?: TProps
|
|
1702
1837
|
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
@@ -1704,16 +1839,22 @@ interface JsxFactoryOptions<TProps extends Dict> {
|
|
|
1704
1839
|
|
|
1705
1840
|
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
1706
1841
|
|
|
1707
|
-
|
|
1842
|
+
export type JsxElement<T extends ElementType, P> = T extends ${componentName}<infer A, infer B>
|
|
1843
|
+
? ${componentName}<A, Pretty<DistributiveUnion<P, B>>>
|
|
1844
|
+
: ${componentName}<T, P>
|
|
1845
|
+
|
|
1846
|
+
export interface JsxFactory {
|
|
1708
1847
|
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1709
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
1848
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
1710
1849
|
T,
|
|
1711
1850
|
RecipeSelection<P>
|
|
1712
1851
|
>
|
|
1713
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>):
|
|
1852
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
|
|
1714
1853
|
}
|
|
1715
1854
|
|
|
1716
|
-
type JsxElements = {
|
|
1855
|
+
export type JsxElements = {
|
|
1856
|
+
[K in keyof QwikIntrinsicElements]: ${componentName}<K, {}>
|
|
1857
|
+
}
|
|
1717
1858
|
|
|
1718
1859
|
export type ${upperName} = JsxFactory & JsxElements
|
|
1719
1860
|
|
|
@@ -1725,29 +1866,38 @@ export type ${variantName}<T extends ${componentName}<any, any>> = T extends ${c
|
|
|
1725
1866
|
}
|
|
1726
1867
|
|
|
1727
1868
|
// src/artifacts/qwik-jsx/jsx.string-literal.ts
|
|
1728
|
-
import { outdent as
|
|
1869
|
+
import { outdent as outdent23 } from "outdent";
|
|
1729
1870
|
function generateQwikJsxStringLiteralFactory(ctx) {
|
|
1730
1871
|
const { factoryName, componentName } = ctx.jsx;
|
|
1731
1872
|
return {
|
|
1732
|
-
js:
|
|
1873
|
+
js: outdent23`
|
|
1733
1874
|
import { h } from '@builder.io/qwik'
|
|
1875
|
+
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
1734
1876
|
${ctx.file.import("css, cx", "../css/index")}
|
|
1735
1877
|
|
|
1736
1878
|
function createStyledFn(Dynamic) {
|
|
1737
1879
|
return function styledFn(template) {
|
|
1738
|
-
const
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1880
|
+
const styles = css.raw(template)
|
|
1881
|
+
|
|
1882
|
+
const ${componentName} = (props) => {
|
|
1883
|
+
const { as: Element = Dynamic.__base__ || Dynamic, ...elementProps } = props
|
|
1884
|
+
|
|
1885
|
+
function classes() {
|
|
1886
|
+
return cx(css(Dynamic.__styles__, styles), elementProps.className)
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
return h(Element, {
|
|
1890
|
+
...elementProps,
|
|
1891
|
+
className: classes(),
|
|
1892
|
+
})
|
|
1747
1893
|
}
|
|
1748
1894
|
|
|
1749
|
-
const name = (
|
|
1895
|
+
const name = getDisplayName(Dynamic)
|
|
1896
|
+
|
|
1750
1897
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
1898
|
+
${componentName}.__styles__ = styles
|
|
1899
|
+
${componentName}.__base__ = Dynamic
|
|
1900
|
+
|
|
1751
1901
|
return ${componentName}
|
|
1752
1902
|
}
|
|
1753
1903
|
}
|
|
@@ -1775,18 +1925,18 @@ function generateQwikJsxStringLiteralFactory(ctx) {
|
|
|
1775
1925
|
}
|
|
1776
1926
|
|
|
1777
1927
|
// src/artifacts/qwik-jsx/types.string-literal.ts
|
|
1778
|
-
import { outdent as
|
|
1928
|
+
import { outdent as outdent24 } from "outdent";
|
|
1779
1929
|
function generateQwikJsxStringLiteralTypes(ctx) {
|
|
1780
1930
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
1781
1931
|
return {
|
|
1782
|
-
jsxFactory:
|
|
1932
|
+
jsxFactory: outdent24`
|
|
1783
1933
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
1784
1934
|
export declare const ${factoryName}: ${upperName}
|
|
1785
1935
|
`,
|
|
1786
|
-
jsxType:
|
|
1936
|
+
jsxType: outdent24`
|
|
1787
1937
|
import type { Component, QwikIntrinsicElements } from '@builder.io/qwik'
|
|
1788
1938
|
|
|
1789
|
-
type ElementType = keyof QwikIntrinsicElements | Component<any>
|
|
1939
|
+
export type ElementType = keyof QwikIntrinsicElements | Component<any>
|
|
1790
1940
|
|
|
1791
1941
|
export type ComponentProps<T extends ElementType> = T extends keyof QwikIntrinsicElements
|
|
1792
1942
|
? QwikIntrinsicElements[T]
|
|
@@ -1794,17 +1944,21 @@ export type ComponentProps<T extends ElementType> = T extends keyof QwikIntrinsi
|
|
|
1794
1944
|
? P
|
|
1795
1945
|
: never
|
|
1796
1946
|
|
|
1797
|
-
|
|
1947
|
+
interface Dict {
|
|
1948
|
+
[k: string]: unknown
|
|
1949
|
+
}
|
|
1798
1950
|
|
|
1799
1951
|
export type ${componentName}<T extends ElementType> = {
|
|
1800
1952
|
(args: { raw: readonly string[] | ArrayLike<string> }): (props: ComponentProps<T>) => JSX.Element
|
|
1801
1953
|
}
|
|
1802
1954
|
|
|
1803
|
-
interface JsxFactory {
|
|
1955
|
+
export interface JsxFactory {
|
|
1804
1956
|
<T extends ElementType>(component: T): ${componentName}<T>
|
|
1805
1957
|
}
|
|
1806
1958
|
|
|
1807
|
-
type JsxElements = {
|
|
1959
|
+
export type JsxElements = {
|
|
1960
|
+
[K in keyof QwikIntrinsicElements]: ${componentName}<K>
|
|
1961
|
+
}
|
|
1808
1962
|
|
|
1809
1963
|
export type ${upperName} = JsxFactory & JsxElements
|
|
1810
1964
|
|
|
@@ -1814,18 +1968,20 @@ export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
|
1814
1968
|
}
|
|
1815
1969
|
|
|
1816
1970
|
// src/artifacts/react-jsx/jsx.ts
|
|
1817
|
-
import { outdent as
|
|
1971
|
+
import { outdent as outdent25 } from "outdent";
|
|
1818
1972
|
function generateReactJsxFactory(ctx) {
|
|
1819
1973
|
const { factoryName, componentName } = ctx.jsx;
|
|
1820
1974
|
return {
|
|
1821
|
-
js:
|
|
1975
|
+
js: outdent25`
|
|
1822
1976
|
import { createElement, forwardRef, useMemo } from 'react'
|
|
1823
1977
|
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
1978
|
+
${ctx.file.import(
|
|
1979
|
+
"defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName",
|
|
1980
|
+
"./factory-helper"
|
|
1981
|
+
)}
|
|
1824
1982
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
1825
1983
|
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
1826
1984
|
|
|
1827
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
1828
|
-
|
|
1829
1985
|
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
1830
1986
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
1831
1987
|
|
|
@@ -1838,23 +1994,26 @@ function generateReactJsxFactory(ctx) {
|
|
|
1838
1994
|
)
|
|
1839
1995
|
|
|
1840
1996
|
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
1841
|
-
const { as: Element = Dynamic, children, ...restProps } = props
|
|
1997
|
+
const { as: Element = Dynamic.__base__ || Dynamic, children, ...restProps } = props
|
|
1998
|
+
|
|
1999
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
2000
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
1842
2001
|
|
|
1843
2002
|
const combinedProps = useMemo(() => Object.assign({}, defaultProps, restProps), [restProps])
|
|
1844
2003
|
|
|
1845
2004
|
const [forwardedProps, variantProps, styleProps, htmlProps, elementProps] = useMemo(() => {
|
|
1846
|
-
return splitProps(combinedProps,
|
|
2005
|
+
return splitProps(combinedProps, __shouldForwardProps__, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
1847
2006
|
}, [combinedProps])
|
|
1848
2007
|
|
|
1849
2008
|
function recipeClass() {
|
|
1850
2009
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1851
|
-
const compoundVariantStyles =
|
|
1852
|
-
return cx(
|
|
2010
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps)
|
|
2011
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.className)
|
|
1853
2012
|
}
|
|
1854
2013
|
|
|
1855
2014
|
function cvaClass() {
|
|
1856
2015
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
1857
|
-
const cvaStyles =
|
|
2016
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
1858
2017
|
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.className)
|
|
1859
2018
|
}
|
|
1860
2019
|
|
|
@@ -1870,8 +2029,13 @@ function generateReactJsxFactory(ctx) {
|
|
|
1870
2029
|
})
|
|
1871
2030
|
})
|
|
1872
2031
|
|
|
1873
|
-
const name = (
|
|
2032
|
+
const name = getDisplayName(Dynamic)
|
|
2033
|
+
|
|
1874
2034
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
2035
|
+
${componentName}.__cva__ = cvaFn
|
|
2036
|
+
${componentName}.__base__ = Dynamic
|
|
2037
|
+
${componentName}.__shouldForwardProps__ = shouldForwardProp
|
|
2038
|
+
|
|
1875
2039
|
return ${componentName}
|
|
1876
2040
|
}
|
|
1877
2041
|
|
|
@@ -1898,8 +2062,8 @@ function generateReactJsxFactory(ctx) {
|
|
|
1898
2062
|
}
|
|
1899
2063
|
|
|
1900
2064
|
// src/artifacts/react-jsx/pattern.ts
|
|
1901
|
-
import { outdent as
|
|
1902
|
-
import { match as
|
|
2065
|
+
import { outdent as outdent26 } from "outdent";
|
|
2066
|
+
import { match as match7 } from "ts-pattern";
|
|
1903
2067
|
function generateReactJsxPattern(ctx) {
|
|
1904
2068
|
const { typeName, factoryName } = ctx.jsx;
|
|
1905
2069
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -1907,20 +2071,20 @@ function generateReactJsxPattern(ctx) {
|
|
|
1907
2071
|
const { description, jsxElement = "div" } = pattern.config;
|
|
1908
2072
|
return {
|
|
1909
2073
|
name: dashName,
|
|
1910
|
-
js:
|
|
2074
|
+
js: outdent26`
|
|
1911
2075
|
import { createElement, forwardRef } from 'react'
|
|
1912
2076
|
${ctx.file.import(factoryName, "./factory")}
|
|
1913
2077
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
1914
2078
|
|
|
1915
2079
|
export const ${jsxName} = /* @__PURE__ */ forwardRef(function ${jsxName}(props, ref) {
|
|
1916
|
-
${
|
|
2080
|
+
${match7(props.length).with(
|
|
1917
2081
|
0,
|
|
1918
|
-
() =>
|
|
2082
|
+
() => outdent26`
|
|
1919
2083
|
const styleProps = ${styleFnName}()
|
|
1920
2084
|
return createElement(${factoryName}.${jsxElement}, { ref, ...styleProps, ...props })
|
|
1921
2085
|
`
|
|
1922
2086
|
).otherwise(
|
|
1923
|
-
() =>
|
|
2087
|
+
() => outdent26`
|
|
1924
2088
|
const { ${props.join(", ")}, ...restProps } = props
|
|
1925
2089
|
const styleProps = ${styleFnName}({${props.join(", ")}})
|
|
1926
2090
|
return createElement(${factoryName}.${jsxElement}, { ref, ...styleProps, ...restProps })
|
|
@@ -1928,7 +2092,7 @@ function generateReactJsxPattern(ctx) {
|
|
|
1928
2092
|
)}
|
|
1929
2093
|
})
|
|
1930
2094
|
`,
|
|
1931
|
-
dts:
|
|
2095
|
+
dts: outdent26`
|
|
1932
2096
|
import type { FunctionComponent } from 'react'
|
|
1933
2097
|
${ctx.file.importType(`${upperName}Properties`, `../patterns/${dashName}`)}
|
|
1934
2098
|
${ctx.file.importType(typeName, "../types/jsx")}
|
|
@@ -1944,20 +2108,25 @@ function generateReactJsxPattern(ctx) {
|
|
|
1944
2108
|
}
|
|
1945
2109
|
|
|
1946
2110
|
// src/artifacts/react-jsx/types.ts
|
|
1947
|
-
import { outdent as
|
|
2111
|
+
import { outdent as outdent27 } from "outdent";
|
|
1948
2112
|
function generateReactJsxTypes(ctx) {
|
|
1949
2113
|
const { factoryName, componentName, upperName, typeName, variantName } = ctx.jsx;
|
|
1950
2114
|
return {
|
|
1951
|
-
jsxFactory:
|
|
2115
|
+
jsxFactory: outdent27`
|
|
1952
2116
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
1953
2117
|
export declare const ${factoryName}: ${upperName}
|
|
1954
2118
|
`,
|
|
1955
|
-
jsxType:
|
|
2119
|
+
jsxType: outdent27`
|
|
1956
2120
|
import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
|
|
1957
|
-
${ctx.file.importType("Assign, DistributiveOmit, JsxHTMLProps, JsxStyleProps", "./system-types")}
|
|
1958
2121
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
2122
|
+
${ctx.file.importType(
|
|
2123
|
+
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
2124
|
+
"./system-types"
|
|
2125
|
+
)}
|
|
1959
2126
|
|
|
1960
|
-
|
|
2127
|
+
interface Dict {
|
|
2128
|
+
[k: string]: unknown
|
|
2129
|
+
}
|
|
1961
2130
|
|
|
1962
2131
|
export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
|
|
1963
2132
|
ref?: Ref<ElementRef<T>>
|
|
@@ -1968,7 +2137,9 @@ export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
|
1968
2137
|
displayName?: string
|
|
1969
2138
|
}
|
|
1970
2139
|
|
|
1971
|
-
interface RecipeFn {
|
|
2140
|
+
interface RecipeFn {
|
|
2141
|
+
__type: any
|
|
2142
|
+
}
|
|
1972
2143
|
|
|
1973
2144
|
interface JsxFactoryOptions<TProps extends Dict> {
|
|
1974
2145
|
dataAttr?: boolean
|
|
@@ -1978,16 +2149,22 @@ interface JsxFactoryOptions<TProps extends Dict> {
|
|
|
1978
2149
|
|
|
1979
2150
|
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
1980
2151
|
|
|
1981
|
-
|
|
2152
|
+
export type JsxElement<T extends ElementType, P> = T extends ${componentName}<infer A, infer B>
|
|
2153
|
+
? ${componentName}<A, Pretty<DistributiveUnion<P, B>>>
|
|
2154
|
+
: ${componentName}<T, P>
|
|
2155
|
+
|
|
2156
|
+
export interface JsxFactory {
|
|
1982
2157
|
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
1983
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
2158
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
1984
2159
|
T,
|
|
1985
2160
|
RecipeSelection<P>
|
|
1986
2161
|
>
|
|
1987
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>):
|
|
2162
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
|
|
1988
2163
|
}
|
|
1989
2164
|
|
|
1990
|
-
type JsxElements = {
|
|
2165
|
+
export type JsxElements = {
|
|
2166
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}>
|
|
2167
|
+
}
|
|
1991
2168
|
|
|
1992
2169
|
export type ${upperName} = JsxFactory & JsxElements
|
|
1993
2170
|
|
|
@@ -1999,30 +2176,39 @@ export type ${variantName}<T extends ${componentName}<any, any>> = T extends ${c
|
|
|
1999
2176
|
}
|
|
2000
2177
|
|
|
2001
2178
|
// src/artifacts/react-jsx/jsx.string-literal.ts
|
|
2002
|
-
import { outdent as
|
|
2179
|
+
import { outdent as outdent28 } from "outdent";
|
|
2003
2180
|
function generateReactJsxStringLiteralFactory(ctx) {
|
|
2004
2181
|
const { factoryName, componentName } = ctx.jsx;
|
|
2005
2182
|
return {
|
|
2006
|
-
js:
|
|
2183
|
+
js: outdent28`
|
|
2007
2184
|
import { createElement, forwardRef } from 'react'
|
|
2185
|
+
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
2008
2186
|
${ctx.file.import("css, cx", "../css/index")}
|
|
2009
2187
|
|
|
2010
2188
|
function createStyledFn(Dynamic) {
|
|
2011
2189
|
return function styledFn(template) {
|
|
2012
|
-
const
|
|
2190
|
+
const styles = css.raw(template)
|
|
2191
|
+
|
|
2013
2192
|
const ${componentName} = /* @__PURE__ */ forwardRef(function ${componentName}(props, ref) {
|
|
2014
|
-
|
|
2015
|
-
|
|
2193
|
+
const { as: Element = Dynamic.__base__ || Dynamic, ...elementProps } = props
|
|
2194
|
+
|
|
2195
|
+
function classes() {
|
|
2196
|
+
return cx(css(Dynamic.__styles__, styles), elementProps.className)
|
|
2197
|
+
}
|
|
2016
2198
|
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2199
|
+
return createElement(Element, {
|
|
2200
|
+
ref,
|
|
2201
|
+
...elementProps,
|
|
2202
|
+
className: classes(),
|
|
2203
|
+
})
|
|
2022
2204
|
})
|
|
2023
2205
|
|
|
2024
|
-
const name = (
|
|
2206
|
+
const name = getDisplayName(Dynamic)
|
|
2207
|
+
|
|
2025
2208
|
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
2209
|
+
${componentName}.__styles__ = styles
|
|
2210
|
+
${componentName}.__base__ = Dynamic
|
|
2211
|
+
|
|
2026
2212
|
return ${componentName}
|
|
2027
2213
|
}
|
|
2028
2214
|
}
|
|
@@ -2050,19 +2236,21 @@ function generateReactJsxStringLiteralFactory(ctx) {
|
|
|
2050
2236
|
}
|
|
2051
2237
|
|
|
2052
2238
|
// src/artifacts/react-jsx/types.string-literal.ts
|
|
2053
|
-
import { outdent as
|
|
2239
|
+
import { outdent as outdent29 } from "outdent";
|
|
2054
2240
|
function generateReactJsxStringLiteralTypes(ctx) {
|
|
2055
2241
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2056
2242
|
return {
|
|
2057
|
-
jsxFactory:
|
|
2243
|
+
jsxFactory: outdent29`
|
|
2058
2244
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
2059
2245
|
export declare const ${factoryName}: ${upperName}
|
|
2060
2246
|
`,
|
|
2061
|
-
jsxType:
|
|
2247
|
+
jsxType: outdent29`
|
|
2062
2248
|
import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
|
|
2063
2249
|
${ctx.file.importType("DistributiveOmit", "../types/system-types")}
|
|
2064
2250
|
|
|
2065
|
-
|
|
2251
|
+
interface Dict {
|
|
2252
|
+
[k: string]: unknown
|
|
2253
|
+
}
|
|
2066
2254
|
|
|
2067
2255
|
export type ComponentProps<T extends ElementType> = DistributiveOmit<ComponentPropsWithoutRef<T>, 'ref'> & {
|
|
2068
2256
|
ref?: Ref<ElementRef<T>>
|
|
@@ -2073,11 +2261,13 @@ export type ${componentName}<T extends ElementType> = {
|
|
|
2073
2261
|
displayName?: string
|
|
2074
2262
|
}
|
|
2075
2263
|
|
|
2076
|
-
interface JsxFactory {
|
|
2264
|
+
export interface JsxFactory {
|
|
2077
2265
|
<T extends ElementType>(component: T): ${componentName}<T>
|
|
2078
2266
|
}
|
|
2079
2267
|
|
|
2080
|
-
type JsxElements = {
|
|
2268
|
+
export type JsxElements = {
|
|
2269
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K>
|
|
2270
|
+
}
|
|
2081
2271
|
|
|
2082
2272
|
export type ${upperName} = JsxFactory & JsxElements
|
|
2083
2273
|
|
|
@@ -2087,19 +2277,21 @@ export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
|
2087
2277
|
}
|
|
2088
2278
|
|
|
2089
2279
|
// src/artifacts/solid-jsx/jsx.ts
|
|
2090
|
-
import { outdent as
|
|
2280
|
+
import { outdent as outdent30 } from "outdent";
|
|
2091
2281
|
function generateSolidJsxFactory(ctx) {
|
|
2092
2282
|
const { componentName, factoryName } = ctx.jsx;
|
|
2093
2283
|
return {
|
|
2094
|
-
js:
|
|
2284
|
+
js: outdent30`
|
|
2095
2285
|
import { Dynamic } from 'solid-js/web'
|
|
2096
2286
|
import { createMemo, mergeProps, splitProps } from 'solid-js'
|
|
2097
2287
|
import { createComponent } from 'solid-js/web'
|
|
2288
|
+
${ctx.file.import(
|
|
2289
|
+
"defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName",
|
|
2290
|
+
"./factory-helper"
|
|
2291
|
+
)}
|
|
2292
|
+
${ctx.file.import("isCssProperty, allCssProperties", "./is-valid-prop")}
|
|
2098
2293
|
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
2099
2294
|
${ctx.file.import("normalizeHTMLProps", "../helpers")}
|
|
2100
|
-
${ctx.file.import("isCssProperty, allCssProperties", "./is-valid-prop")}
|
|
2101
|
-
|
|
2102
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
2103
2295
|
|
|
2104
2296
|
function styledFn(element, configOrCva = {}, options = {}) {
|
|
2105
2297
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
@@ -2112,28 +2304,32 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2112
2304
|
options.defaultProps,
|
|
2113
2305
|
)
|
|
2114
2306
|
|
|
2115
|
-
|
|
2116
|
-
const mergedProps = mergeProps({ as: element }, defaultProps, props)
|
|
2307
|
+
const ${componentName} = (props) => {
|
|
2308
|
+
const mergedProps = mergeProps({ as: element.__base__ || element }, defaultProps, props)
|
|
2309
|
+
|
|
2310
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
2311
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
2312
|
+
|
|
2117
2313
|
const forwardedKeys = createMemo(() => Object.keys(props).filter(shouldForwardProp))
|
|
2118
2314
|
|
|
2119
2315
|
const [localProps, forwardedProps, variantProps, styleProps, htmlProps, elementProps] = splitProps(
|
|
2120
2316
|
mergedProps,
|
|
2121
2317
|
['as', 'class', 'className'],
|
|
2122
2318
|
forwardedKeys(),
|
|
2123
|
-
|
|
2319
|
+
__cvaFn__.variantKeys,
|
|
2124
2320
|
allCssProperties,
|
|
2125
2321
|
normalizeHTMLProps.keys
|
|
2126
2322
|
)
|
|
2127
2323
|
|
|
2128
2324
|
function recipeClass() {
|
|
2129
2325
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2130
|
-
const compoundVariantStyles =
|
|
2131
|
-
return cx(
|
|
2326
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps);
|
|
2327
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), localProps.class, localProps.className)
|
|
2132
2328
|
}
|
|
2133
2329
|
|
|
2134
2330
|
function cvaClass() {
|
|
2135
2331
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2136
|
-
const cvaStyles =
|
|
2332
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
2137
2333
|
return cx(css(cvaStyles, propStyles, cssStyles), localProps.class, localProps.className)
|
|
2138
2334
|
}
|
|
2139
2335
|
|
|
@@ -2160,6 +2356,15 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2160
2356
|
)
|
|
2161
2357
|
)
|
|
2162
2358
|
}
|
|
2359
|
+
|
|
2360
|
+
const name = getDisplayName(element)
|
|
2361
|
+
|
|
2362
|
+
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
2363
|
+
${componentName}.__cva__ = cvaFn
|
|
2364
|
+
${componentName}.__base__ = element
|
|
2365
|
+
${componentName}.__shouldForwardProps__ = shouldForwardProp
|
|
2366
|
+
|
|
2367
|
+
return ${componentName}
|
|
2163
2368
|
}
|
|
2164
2369
|
|
|
2165
2370
|
function createJsxFactory() {
|
|
@@ -2184,8 +2389,8 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2184
2389
|
}
|
|
2185
2390
|
|
|
2186
2391
|
// src/artifacts/solid-jsx/pattern.ts
|
|
2187
|
-
import { outdent as
|
|
2188
|
-
import { match as
|
|
2392
|
+
import { outdent as outdent31 } from "outdent";
|
|
2393
|
+
import { match as match8 } from "ts-pattern";
|
|
2189
2394
|
function generateSolidJsxPattern(ctx) {
|
|
2190
2395
|
const { typeName, factoryName } = ctx.jsx;
|
|
2191
2396
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -2193,21 +2398,21 @@ function generateSolidJsxPattern(ctx) {
|
|
|
2193
2398
|
const { description, jsxElement = "div" } = pattern.config;
|
|
2194
2399
|
return {
|
|
2195
2400
|
name: dashName,
|
|
2196
|
-
js:
|
|
2401
|
+
js: outdent31`
|
|
2197
2402
|
import { splitProps, mergeProps } from 'solid-js'
|
|
2198
2403
|
import { createComponent } from 'solid-js/web'
|
|
2199
2404
|
${ctx.file.import(factoryName, "./factory")}
|
|
2200
2405
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
2201
2406
|
|
|
2202
2407
|
export function ${jsxName}(props) {
|
|
2203
|
-
${
|
|
2408
|
+
${match8(props.length).with(
|
|
2204
2409
|
0,
|
|
2205
|
-
() =>
|
|
2410
|
+
() => outdent31`
|
|
2206
2411
|
const styleProps = ${styleFnName}()
|
|
2207
2412
|
return createComponent(${factoryName}.${jsxElement}, mergeProps(styleProps, props))
|
|
2208
2413
|
`
|
|
2209
2414
|
).otherwise(
|
|
2210
|
-
() =>
|
|
2415
|
+
() => outdent31`
|
|
2211
2416
|
const [patternProps, restProps] = splitProps(props, [${props.map((v) => JSON.stringify(v)).join(", ")}]);
|
|
2212
2417
|
const styleProps = ${styleFnName}(patternProps)
|
|
2213
2418
|
return createComponent(${factoryName}.${jsxElement}, mergeProps(styleProps, restProps))
|
|
@@ -2215,7 +2420,7 @@ function generateSolidJsxPattern(ctx) {
|
|
|
2215
2420
|
)}
|
|
2216
2421
|
}
|
|
2217
2422
|
`,
|
|
2218
|
-
dts:
|
|
2423
|
+
dts: outdent31`
|
|
2219
2424
|
import type { Component } from 'solid-js'
|
|
2220
2425
|
${ctx.file.importType(`${upperName}Properties`, `../patterns/${dashName}`)}
|
|
2221
2426
|
${ctx.file.importType(typeName, "../types/jsx")}
|
|
@@ -2231,31 +2436,38 @@ function generateSolidJsxPattern(ctx) {
|
|
|
2231
2436
|
}
|
|
2232
2437
|
|
|
2233
2438
|
// src/artifacts/solid-jsx/types.ts
|
|
2234
|
-
import { outdent as
|
|
2439
|
+
import { outdent as outdent32 } from "outdent";
|
|
2235
2440
|
function generateSolidJsxTypes(ctx) {
|
|
2236
2441
|
const { factoryName, componentName, upperName, typeName, variantName } = ctx.jsx;
|
|
2237
2442
|
return {
|
|
2238
|
-
jsxFactory:
|
|
2443
|
+
jsxFactory: outdent32`
|
|
2239
2444
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
2240
2445
|
export declare const ${factoryName}: ${upperName}
|
|
2241
2446
|
`,
|
|
2242
|
-
jsxType:
|
|
2447
|
+
jsxType: outdent32`
|
|
2243
2448
|
import type { ComponentProps, Component, JSX } from 'solid-js'
|
|
2244
|
-
${ctx.file.importType("Assign, JsxStyleProps, JsxHTMLProps", "./system-types")}
|
|
2245
2449
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
2450
|
+
${ctx.file.importType(
|
|
2451
|
+
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
2452
|
+
"./system-types"
|
|
2453
|
+
)}
|
|
2246
2454
|
|
|
2247
|
-
|
|
2455
|
+
interface Dict {
|
|
2456
|
+
[k: string]: unknown
|
|
2457
|
+
}
|
|
2248
2458
|
|
|
2249
|
-
type ElementType<P = any> = keyof JSX.IntrinsicElements | Component<P>
|
|
2459
|
+
export type ElementType<P = any> = keyof JSX.IntrinsicElements | Component<P>
|
|
2250
2460
|
|
|
2251
2461
|
export interface ${componentName}<T extends ElementType, P extends Dict = {}> {
|
|
2252
2462
|
(props: JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>): JSX.Element
|
|
2253
2463
|
displayName?: string
|
|
2254
2464
|
}
|
|
2255
2465
|
|
|
2256
|
-
interface RecipeFn {
|
|
2466
|
+
interface RecipeFn {
|
|
2467
|
+
__type: any
|
|
2468
|
+
}
|
|
2257
2469
|
|
|
2258
|
-
interface JsxFactoryOptions<TProps extends Dict> {
|
|
2470
|
+
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2259
2471
|
dataAttr?: boolean
|
|
2260
2472
|
defaultProps?: TProps
|
|
2261
2473
|
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
@@ -2263,16 +2475,22 @@ interface JsxFactoryOptions<TProps extends Dict> {
|
|
|
2263
2475
|
|
|
2264
2476
|
export type JsxRecipeProps<T extends ElementType, P extends Dict> = JsxHTMLProps<ComponentProps<T>, P>;
|
|
2265
2477
|
|
|
2266
|
-
|
|
2478
|
+
export type JsxElement<T extends ElementType, P> = T extends ${componentName}<infer A, infer B>
|
|
2479
|
+
? ${componentName}<A, Pretty<DistributiveUnion<P, B>>>
|
|
2480
|
+
: ${componentName}<T, P>
|
|
2481
|
+
|
|
2482
|
+
export interface JsxFactory {
|
|
2267
2483
|
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
2268
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
2484
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
2269
2485
|
T,
|
|
2270
2486
|
RecipeSelection<P>
|
|
2271
2487
|
>
|
|
2272
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>):
|
|
2488
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>>): JsxElement<T, P['__type']>
|
|
2273
2489
|
}
|
|
2274
2490
|
|
|
2275
|
-
type JsxElements = {
|
|
2491
|
+
export type JsxElements = {
|
|
2492
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K, {}>
|
|
2493
|
+
}
|
|
2276
2494
|
|
|
2277
2495
|
export type ${upperName} = JsxFactory & JsxElements
|
|
2278
2496
|
|
|
@@ -2284,22 +2502,24 @@ export type ${variantName}<T extends ${componentName}<any, any>> = T extends ${c
|
|
|
2284
2502
|
}
|
|
2285
2503
|
|
|
2286
2504
|
// src/artifacts/solid-jsx/jsx.string-literal.ts
|
|
2287
|
-
import { outdent as
|
|
2505
|
+
import { outdent as outdent33 } from "outdent";
|
|
2288
2506
|
function generateSolidJsxStringLiteralFactory(ctx) {
|
|
2289
2507
|
const { componentName, factoryName } = ctx.jsx;
|
|
2290
2508
|
return {
|
|
2291
|
-
js:
|
|
2509
|
+
js: outdent33`
|
|
2292
2510
|
import { mergeProps, splitProps } from 'solid-js'
|
|
2293
2511
|
import { Dynamic, createComponent } from 'solid-js/web'
|
|
2512
|
+
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
2294
2513
|
${ctx.file.import("css, cx", "../css/index")}
|
|
2295
2514
|
|
|
2296
2515
|
function createStyled(element) {
|
|
2297
2516
|
return function styledFn(template) {
|
|
2298
|
-
const
|
|
2299
|
-
return function ${componentName}(props) {
|
|
2300
|
-
const mergedProps = mergeProps({ as: element }, props)
|
|
2301
|
-
const [localProps, elementProps] = splitProps(mergedProps, ['as', 'class'])
|
|
2517
|
+
const styles = css.raw(template)
|
|
2302
2518
|
|
|
2519
|
+
const ${componentName} = (props) => {
|
|
2520
|
+
const mergedProps = mergeProps({ as: element.__base__ || element }, props)
|
|
2521
|
+
const [localProps, elementProps] = splitProps(mergedProps, ['as', 'class'])
|
|
2522
|
+
|
|
2303
2523
|
return createComponent(
|
|
2304
2524
|
Dynamic,
|
|
2305
2525
|
mergeProps(
|
|
@@ -2308,13 +2528,21 @@ function createStyled(element) {
|
|
|
2308
2528
|
return localProps.as
|
|
2309
2529
|
},
|
|
2310
2530
|
get class() {
|
|
2311
|
-
return cx(
|
|
2531
|
+
return cx(css(element.__styles__, styles), localProps.class)
|
|
2312
2532
|
},
|
|
2313
2533
|
},
|
|
2314
2534
|
elementProps,
|
|
2315
2535
|
),
|
|
2316
2536
|
)
|
|
2317
2537
|
}
|
|
2538
|
+
|
|
2539
|
+
const name = getDisplayName(element)
|
|
2540
|
+
|
|
2541
|
+
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
2542
|
+
${componentName}.__styles__ = styles
|
|
2543
|
+
${componentName}.__base__ = element
|
|
2544
|
+
|
|
2545
|
+
return ${componentName}
|
|
2318
2546
|
}
|
|
2319
2547
|
}
|
|
2320
2548
|
|
|
@@ -2340,31 +2568,35 @@ export const ${factoryName} = /* @__PURE__ */ createJsxFactory()
|
|
|
2340
2568
|
}
|
|
2341
2569
|
|
|
2342
2570
|
// src/artifacts/solid-jsx/types.string-literal.ts
|
|
2343
|
-
import { outdent as
|
|
2571
|
+
import { outdent as outdent34 } from "outdent";
|
|
2344
2572
|
function generateSolidJsxStringLiteralTypes(ctx) {
|
|
2345
2573
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2346
2574
|
return {
|
|
2347
|
-
jsxFactory:
|
|
2575
|
+
jsxFactory: outdent34`
|
|
2348
2576
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
2349
2577
|
export declare const ${factoryName}: ${upperName}
|
|
2350
2578
|
`,
|
|
2351
|
-
jsxType:
|
|
2579
|
+
jsxType: outdent34`
|
|
2352
2580
|
import type { Component, ComponentProps, JSX } from 'solid-js'
|
|
2353
2581
|
|
|
2354
|
-
|
|
2582
|
+
interface Dict {
|
|
2583
|
+
[k: string]: unknown
|
|
2584
|
+
}
|
|
2355
2585
|
|
|
2356
|
-
type ElementType<P = any> = keyof JSX.IntrinsicElements | Component<P>
|
|
2586
|
+
export type ElementType<P = any> = keyof JSX.IntrinsicElements | Component<P>
|
|
2357
2587
|
|
|
2358
2588
|
export type ${componentName}<T extends ElementType> = {
|
|
2359
2589
|
(args: { raw: readonly string[] | ArrayLike<string> }): (props: ComponentProps<T>) => JSX.Element
|
|
2360
2590
|
displayName?: string
|
|
2361
2591
|
}
|
|
2362
2592
|
|
|
2363
|
-
interface JsxFactory {
|
|
2593
|
+
export interface JsxFactory {
|
|
2364
2594
|
<T extends ElementType>(component: T): ${componentName}<T>
|
|
2365
2595
|
}
|
|
2366
2596
|
|
|
2367
|
-
type JsxElements = {
|
|
2597
|
+
export type JsxElements = {
|
|
2598
|
+
[K in keyof JSX.IntrinsicElements]: ${componentName}<K>
|
|
2599
|
+
}
|
|
2368
2600
|
|
|
2369
2601
|
export type ${upperName} = JsxFactory & JsxElements
|
|
2370
2602
|
|
|
@@ -2374,18 +2606,20 @@ export type ${typeName}<T extends ElementType> = ComponentProps<T>
|
|
|
2374
2606
|
}
|
|
2375
2607
|
|
|
2376
2608
|
// src/artifacts/vue-jsx/jsx.ts
|
|
2377
|
-
import { outdent as
|
|
2609
|
+
import { outdent as outdent35 } from "outdent";
|
|
2378
2610
|
function generateVueJsxFactory(ctx) {
|
|
2379
|
-
const { factoryName } = ctx.jsx;
|
|
2611
|
+
const { factoryName, componentName } = ctx.jsx;
|
|
2380
2612
|
return {
|
|
2381
|
-
js:
|
|
2613
|
+
js: outdent35`
|
|
2382
2614
|
import { defineComponent, h, computed } from 'vue'
|
|
2615
|
+
${ctx.file.import(
|
|
2616
|
+
"defaultShouldForwardProp, composeShouldForwardProps, composeCvaFn, getDisplayName",
|
|
2617
|
+
"./factory-helper"
|
|
2618
|
+
)}
|
|
2619
|
+
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
2383
2620
|
${ctx.file.import("css, cx, cva", "../css/index")}
|
|
2384
2621
|
${ctx.file.import("splitProps, normalizeHTMLProps", "../helpers")}
|
|
2385
|
-
${ctx.file.import("isCssProperty", "./is-valid-prop")}
|
|
2386
2622
|
|
|
2387
|
-
const defaultShouldForwardProp = (prop, variantKeys) => !variantKeys.includes(prop) && !isCssProperty(prop)
|
|
2388
|
-
|
|
2389
2623
|
function styledFn(Dynamic, configOrCva = {}, options = {}) {
|
|
2390
2624
|
const cvaFn = configOrCva.__cva__ || configOrCva.__recipe__ ? configOrCva : cva(configOrCva)
|
|
2391
2625
|
|
|
@@ -2397,30 +2631,33 @@ function generateVueJsxFactory(ctx) {
|
|
|
2397
2631
|
options.defaultProps,
|
|
2398
2632
|
)
|
|
2399
2633
|
|
|
2400
|
-
const name = (
|
|
2634
|
+
const name = getDisplayName(Dynamic)
|
|
2401
2635
|
|
|
2402
|
-
|
|
2636
|
+
const ${componentName} = defineComponent({
|
|
2403
2637
|
name: \`${factoryName}.\${name}\`,
|
|
2404
2638
|
inheritAttrs: false,
|
|
2405
|
-
props: { as: { type: [String, Object], default: Dynamic } },
|
|
2639
|
+
props: { as: { type: [String, Object], default: Dynamic.__base__ || Dynamic } },
|
|
2406
2640
|
setup(props, { slots, attrs }) {
|
|
2641
|
+
const __cvaFn__ = composeCvaFn(Dynamic.__cva__, cvaFn)
|
|
2642
|
+
const __shouldForwardProps__ = composeShouldForwardProps(Dynamic, shouldForwardProp)
|
|
2643
|
+
|
|
2407
2644
|
const combinedProps = computed(() => Object.assign({}, defaultProps, attrs))
|
|
2408
2645
|
|
|
2409
2646
|
const splittedProps = computed(() => {
|
|
2410
|
-
return splitProps(combinedProps.value, shouldForwardProp,
|
|
2647
|
+
return splitProps(combinedProps.value, shouldForwardProp, __cvaFn__.variantKeys, isCssProperty, normalizeHTMLProps.keys)
|
|
2411
2648
|
})
|
|
2412
2649
|
|
|
2413
2650
|
const recipeClass = computed(() => {
|
|
2414
2651
|
const [_forwardedProps, variantProps, styleProps, _htmlProps, _elementProps] = splittedProps.value
|
|
2415
2652
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2416
|
-
const compoundVariantStyles =
|
|
2417
|
-
return cx(
|
|
2653
|
+
const compoundVariantStyles = __cvaFn__.__getCompoundVariantCss__?.(variantProps);
|
|
2654
|
+
return cx(__cvaFn__(variantProps, false), css(compoundVariantStyles, propStyles, cssStyles), combinedProps.value.className)
|
|
2418
2655
|
})
|
|
2419
2656
|
|
|
2420
2657
|
const cvaClass = computed(() => {
|
|
2421
2658
|
const [_forwardedProps, variantProps, styleProps, _htmlProps, _elementProps] = splittedProps.value
|
|
2422
2659
|
const { css: cssStyles, ...propStyles } = styleProps
|
|
2423
|
-
const cvaStyles =
|
|
2660
|
+
const cvaStyles = __cvaFn__.raw(variantProps)
|
|
2424
2661
|
return cx(css(cvaStyles, propStyles, cssStyles), combinedProps.value.className)
|
|
2425
2662
|
})
|
|
2426
2663
|
|
|
@@ -2441,6 +2678,13 @@ function generateVueJsxFactory(ctx) {
|
|
|
2441
2678
|
}
|
|
2442
2679
|
},
|
|
2443
2680
|
})
|
|
2681
|
+
|
|
2682
|
+
${componentName}.displayName = \`${factoryName}.\${name}\`
|
|
2683
|
+
${componentName}.__cva__ = cvaFn
|
|
2684
|
+
${componentName}.__base__ = Dynamic
|
|
2685
|
+
${componentName}.__shouldForwardProps__ = shouldForwardProp
|
|
2686
|
+
|
|
2687
|
+
return ${componentName}
|
|
2444
2688
|
}
|
|
2445
2689
|
|
|
2446
2690
|
function createJsxFactory() {
|
|
@@ -2461,25 +2705,30 @@ function generateVueJsxFactory(ctx) {
|
|
|
2461
2705
|
}
|
|
2462
2706
|
|
|
2463
2707
|
// src/artifacts/vue-jsx/jsx.string-literal.ts
|
|
2464
|
-
import { outdent as
|
|
2708
|
+
import { outdent as outdent36 } from "outdent";
|
|
2465
2709
|
function generateVueJsxStringLiteralFactory(ctx) {
|
|
2466
|
-
const { factoryName } = ctx.jsx;
|
|
2710
|
+
const { componentName, factoryName } = ctx.jsx;
|
|
2467
2711
|
return {
|
|
2468
|
-
js:
|
|
2712
|
+
js: outdent36`
|
|
2469
2713
|
import { defineComponent, h, computed } from 'vue'
|
|
2714
|
+
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
2470
2715
|
${ctx.file.import("css, cx", "../css/index")}
|
|
2471
2716
|
|
|
2472
2717
|
function createStyled(Dynamic) {
|
|
2473
|
-
const name = (
|
|
2718
|
+
const name = getDisplayName(Dynamic)
|
|
2474
2719
|
|
|
2475
2720
|
function styledFn(template) {
|
|
2476
|
-
const
|
|
2477
|
-
|
|
2721
|
+
const styles = css.raw(template)
|
|
2722
|
+
|
|
2723
|
+
const ${componentName} = defineComponent({
|
|
2478
2724
|
name: \`${factoryName}.\${name}\`,
|
|
2479
2725
|
inheritAttrs: false,
|
|
2480
2726
|
props: { as: { type: [String, Object], default: Dynamic } },
|
|
2481
2727
|
setup(props, { slots, attrs }) {
|
|
2482
|
-
const classes = computed(() =>
|
|
2728
|
+
const classes = computed(() => {
|
|
2729
|
+
return cx(css(Dynamic.__styles__, styles), elementProps.className)
|
|
2730
|
+
})
|
|
2731
|
+
|
|
2483
2732
|
return () => {
|
|
2484
2733
|
return h(
|
|
2485
2734
|
props.as,
|
|
@@ -2492,6 +2741,11 @@ function generateVueJsxStringLiteralFactory(ctx) {
|
|
|
2492
2741
|
}
|
|
2493
2742
|
},
|
|
2494
2743
|
})
|
|
2744
|
+
|
|
2745
|
+
${componentName}.__styles__ = styles
|
|
2746
|
+
${componentName}.__base__ = element
|
|
2747
|
+
|
|
2748
|
+
return ${componentName}
|
|
2495
2749
|
}
|
|
2496
2750
|
}
|
|
2497
2751
|
|
|
@@ -2517,7 +2771,7 @@ function generateVueJsxStringLiteralFactory(ctx) {
|
|
|
2517
2771
|
}
|
|
2518
2772
|
|
|
2519
2773
|
// src/artifacts/vue-jsx/pattern.ts
|
|
2520
|
-
import { outdent as
|
|
2774
|
+
import { outdent as outdent37 } from "outdent";
|
|
2521
2775
|
function generateVueJsxPattern(ctx) {
|
|
2522
2776
|
const { typeName, factoryName } = ctx.jsx;
|
|
2523
2777
|
return ctx.patterns.details.map((pattern) => {
|
|
@@ -2526,7 +2780,7 @@ function generateVueJsxPattern(ctx) {
|
|
|
2526
2780
|
const propList = props.map((v) => JSON.stringify(v)).join(", ");
|
|
2527
2781
|
return {
|
|
2528
2782
|
name: dashName,
|
|
2529
|
-
js:
|
|
2783
|
+
js: outdent37`
|
|
2530
2784
|
import { defineComponent, h, computed } from 'vue'
|
|
2531
2785
|
${ctx.file.import(factoryName, "./factory")}
|
|
2532
2786
|
${ctx.file.import(styleFnName, `../patterns/${dashName}`)}
|
|
@@ -2544,7 +2798,7 @@ function generateVueJsxPattern(ctx) {
|
|
|
2544
2798
|
}
|
|
2545
2799
|
})
|
|
2546
2800
|
`,
|
|
2547
|
-
dts:
|
|
2801
|
+
dts: outdent37`
|
|
2548
2802
|
import type { FunctionalComponent } from 'vue'
|
|
2549
2803
|
${ctx.file.importType(`${upperName}Properties`, `../patterns/${dashName}`)}
|
|
2550
2804
|
${ctx.file.importType(typeName, "../types/jsx")}
|
|
@@ -2560,23 +2814,27 @@ function generateVueJsxPattern(ctx) {
|
|
|
2560
2814
|
}
|
|
2561
2815
|
|
|
2562
2816
|
// src/artifacts/vue-jsx/types.ts
|
|
2563
|
-
import { outdent as
|
|
2817
|
+
import { outdent as outdent38 } from "outdent";
|
|
2564
2818
|
function generateVueJsxTypes(ctx) {
|
|
2565
2819
|
const { factoryName, componentName, upperName, typeName, variantName } = ctx.jsx;
|
|
2566
2820
|
return {
|
|
2567
|
-
jsxFactory:
|
|
2821
|
+
jsxFactory: outdent38`
|
|
2568
2822
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
2569
2823
|
|
|
2570
2824
|
export declare const ${factoryName}: ${upperName}
|
|
2571
2825
|
`,
|
|
2572
|
-
jsxType:
|
|
2826
|
+
jsxType: outdent38`
|
|
2573
2827
|
import type { Component, FunctionalComponent, NativeElements } from 'vue'
|
|
2574
2828
|
|
|
2575
2829
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
2576
|
-
${ctx.file.importType(
|
|
2830
|
+
${ctx.file.importType(
|
|
2831
|
+
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
2832
|
+
"./system-types"
|
|
2833
|
+
)}
|
|
2834
|
+
|
|
2835
|
+
export type IntrinsicElement = keyof NativeElements
|
|
2577
2836
|
|
|
2578
|
-
type
|
|
2579
|
-
type ElementType = IntrinsicElement | Component
|
|
2837
|
+
export type ElementType = IntrinsicElement | Component
|
|
2580
2838
|
|
|
2581
2839
|
export type ComponentProps<T extends ElementType> = T extends IntrinsicElement
|
|
2582
2840
|
? NativeElements[T]
|
|
@@ -2584,13 +2842,15 @@ export type ComponentProps<T extends ElementType> = T extends IntrinsicElement
|
|
|
2584
2842
|
? Props
|
|
2585
2843
|
: never
|
|
2586
2844
|
|
|
2587
|
-
|
|
2588
|
-
JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>
|
|
2845
|
+
export interface ${componentName}<T extends ElementType, P extends Dict = {}> extends FunctionalComponent<
|
|
2846
|
+
JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>
|
|
2589
2847
|
> {}
|
|
2590
2848
|
|
|
2591
|
-
interface RecipeFn {
|
|
2849
|
+
interface RecipeFn {
|
|
2850
|
+
__type: any
|
|
2851
|
+
}
|
|
2592
2852
|
|
|
2593
|
-
interface JsxFactoryOptions<TProps extends Dict> {
|
|
2853
|
+
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2594
2854
|
dataAttr?: boolean
|
|
2595
2855
|
defaultProps?: TProps
|
|
2596
2856
|
shouldForwardProp?(prop: string, variantKeys: string[]): boolean
|
|
@@ -2598,16 +2858,22 @@ interface JsxFactoryOptions<TProps extends Dict> {
|
|
|
2598
2858
|
|
|
2599
2859
|
export type JsxRecipeProps<T extends ElementType, P extends RecipeFn> = JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P['__type']>>;
|
|
2600
2860
|
|
|
2601
|
-
|
|
2861
|
+
export type JsxElement<T extends ElementType, P> = T extends ${componentName}<infer A, infer B>
|
|
2862
|
+
? ${componentName}<A, Pretty<DistributiveUnion<P, B>>>
|
|
2863
|
+
: ${componentName}<T, P>
|
|
2864
|
+
|
|
2865
|
+
export interface JsxFactory {
|
|
2602
2866
|
<T extends ElementType>(component: T): ${componentName}<T, {}>
|
|
2603
|
-
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>):
|
|
2867
|
+
<T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<JsxRecipeProps<T, RecipeSelection<P>>>): JsxElement<
|
|
2604
2868
|
T,
|
|
2605
2869
|
RecipeSelection<P>
|
|
2606
2870
|
>
|
|
2607
|
-
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>> ):
|
|
2871
|
+
<T extends ElementType, P extends RecipeFn>(component: T, recipeFn: P, options?: JsxFactoryOptions<JsxRecipeProps<T, P['__type']>> ): JsxElement<T, P['__type']>
|
|
2608
2872
|
}
|
|
2609
2873
|
|
|
2610
|
-
type JsxElements = {
|
|
2874
|
+
export type JsxElements = {
|
|
2875
|
+
[K in IntrinsicElement]: ${componentName}<K, {}>
|
|
2876
|
+
}
|
|
2611
2877
|
|
|
2612
2878
|
export type ${upperName} = JsxFactory & JsxElements
|
|
2613
2879
|
|
|
@@ -2619,20 +2885,21 @@ export type ${variantName}<T extends ${componentName}<any, any>> = T extends ${c
|
|
|
2619
2885
|
}
|
|
2620
2886
|
|
|
2621
2887
|
// src/artifacts/vue-jsx/types.string-literal.ts
|
|
2622
|
-
import { outdent as
|
|
2888
|
+
import { outdent as outdent39 } from "outdent";
|
|
2623
2889
|
function generateVueJsxStringLiteralTypes(ctx) {
|
|
2624
2890
|
const { factoryName, componentName, upperName, typeName } = ctx.jsx;
|
|
2625
2891
|
return {
|
|
2626
|
-
jsxFactory:
|
|
2892
|
+
jsxFactory: outdent39`
|
|
2627
2893
|
${ctx.file.importType(upperName, "../types/jsx")}
|
|
2628
2894
|
|
|
2629
2895
|
export declare const ${factoryName}: ${upperName}
|
|
2630
2896
|
`,
|
|
2631
|
-
jsxType:
|
|
2897
|
+
jsxType: outdent39`
|
|
2632
2898
|
import type { Component, FunctionalComponent, NativeElements } from 'vue'
|
|
2633
2899
|
|
|
2634
|
-
type IntrinsicElement = keyof NativeElements
|
|
2635
|
-
|
|
2900
|
+
export type IntrinsicElement = keyof NativeElements
|
|
2901
|
+
|
|
2902
|
+
export type ElementType = IntrinsicElement | Component
|
|
2636
2903
|
|
|
2637
2904
|
export type ComponentProps<T extends ElementType> = T extends IntrinsicElement
|
|
2638
2905
|
? NativeElements[T]
|
|
@@ -2640,14 +2907,16 @@ export type ComponentProps<T extends ElementType> = T extends IntrinsicElement
|
|
|
2640
2907
|
? Props
|
|
2641
2908
|
: never
|
|
2642
2909
|
|
|
2643
|
-
type ${componentName}<T extends ElementType> = FunctionalComponent<ComponentProps<T>>
|
|
2910
|
+
export type ${componentName}<T extends ElementType> = FunctionalComponent<ComponentProps<T>>
|
|
2644
2911
|
>
|
|
2645
2912
|
|
|
2646
|
-
interface JsxFactory {
|
|
2913
|
+
export interface JsxFactory {
|
|
2647
2914
|
<T extends ElementType>(component: T): ${componentName}<T>
|
|
2648
2915
|
}
|
|
2649
2916
|
|
|
2650
|
-
type JsxElements = {
|
|
2917
|
+
export type JsxElements = {
|
|
2918
|
+
[K in IntrinsicElement]: ${componentName}<K>
|
|
2919
|
+
}
|
|
2651
2920
|
|
|
2652
2921
|
export type ${upperName} = JsxFactory & JsxElements
|
|
2653
2922
|
|
|
@@ -2764,7 +3033,7 @@ var csstype_d_ts_default = {
|
|
|
2764
3033
|
|
|
2765
3034
|
// src/artifacts/generated/system-types.d.ts.json
|
|
2766
3035
|
var system_types_d_ts_default = {
|
|
2767
|
-
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 interface CssProperties extends PropertiesFallback<String | Number>, CssVarProperties {}\n\nexport interface 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\ninterface 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 interface GlobalStyleObject {\n [selector: string]: SystemStyleObject\n}\nexport interface ExtendableGlobalStyleObject {\n [selector: string]: SystemStyleObject | undefined\n extend?: GlobalStyleObject | undefined\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 * -----------------------------------------------------------------------------*/\ninterface WithCss {\n css?: SystemStyleObject\n}\ntype StyleProps = SystemProperties & MinimalNested<SystemStyleObject>\n\nexport type JsxStyleProps = StyleProps & WithCss\n\nexport
|
|
3036
|
+
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\nexport type Pretty<T> = { [K in keyof T]: T[K] } & {}\n\nexport type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never\n\nexport type DistributiveUnion<T, U> = {\n [K in keyof T]: K extends keyof U ? U[K] | T[K] : T[K]\n} & DistributiveOmit<U, keyof T>\n\nexport type Assign<T, U> = {\n [K in keyof T]: K extends keyof U ? U[K] : T[K]\n} & U\n\n/* -----------------------------------------------------------------------------\n * Native css properties\n * -----------------------------------------------------------------------------*/\n\nexport type CssProperty = keyof PropertiesFallback\n\nexport interface CssProperties extends PropertiesFallback<String | Number>, CssVarProperties {}\n\nexport interface 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\ninterface 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 interface GlobalStyleObject {\n [selector: string]: SystemStyleObject\n}\nexport interface ExtendableGlobalStyleObject {\n [selector: string]: SystemStyleObject | undefined\n extend?: GlobalStyleObject | undefined\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 * -----------------------------------------------------------------------------*/\ninterface WithCss {\n css?: SystemStyleObject\n}\ntype StyleProps = SystemProperties & MinimalNested<SystemStyleObject>\n\nexport type JsxStyleProps = StyleProps & WithCss\n\nexport interface PatchedHTMLProps {\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' | 'content'\n\ntype WithHTMLProps<T> = DistributiveOmit<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"
|
|
2768
3037
|
};
|
|
2769
3038
|
|
|
2770
3039
|
// src/artifacts/generated/composition.d.ts.json
|
|
@@ -2793,7 +3062,7 @@ var selectors_d_ts_default = {
|
|
|
2793
3062
|
};
|
|
2794
3063
|
|
|
2795
3064
|
// src/artifacts/types/generated.ts
|
|
2796
|
-
import { match as
|
|
3065
|
+
import { match as match9 } from "ts-pattern";
|
|
2797
3066
|
var jsxStyleProps = "export type JsxStyleProps = StyleProps & WithCss";
|
|
2798
3067
|
function getGeneratedTypes(ctx) {
|
|
2799
3068
|
const rewriteImports = (code) => code.replace(/import\s+type\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g, ctx.file.importType("$1", "$2"));
|
|
@@ -2805,15 +3074,15 @@ function getGeneratedTypes(ctx) {
|
|
|
2805
3074
|
composition: rewriteImports(composition_d_ts_default.content),
|
|
2806
3075
|
selectors: rewriteImports(selectors_d_ts_default.content),
|
|
2807
3076
|
system: rewriteImports(
|
|
2808
|
-
|
|
3077
|
+
match9(ctx.jsx.styleProps).with("all", () => system_types_d_ts_default.content).with("minimal", () => system_types_d_ts_default.content.replace(jsxStyleProps, "export type JsxStyleProps = WithCss")).with("none", () => system_types_d_ts_default.content.replace(jsxStyleProps, "export type JsxStyleProps = {}")).exhaustive()
|
|
2809
3078
|
)
|
|
2810
3079
|
};
|
|
2811
3080
|
}
|
|
2812
3081
|
|
|
2813
3082
|
// src/artifacts/types/main.ts
|
|
2814
|
-
import { outdent as
|
|
3083
|
+
import { outdent as outdent40 } from "outdent";
|
|
2815
3084
|
var generateTypesEntry = (ctx) => ({
|
|
2816
|
-
global:
|
|
3085
|
+
global: outdent40`
|
|
2817
3086
|
// @ts-nocheck
|
|
2818
3087
|
import type * as Panda from '@pandacss/dev'
|
|
2819
3088
|
${ctx.file.importType("RecipeVariantRecord, RecipeConfig, SlotRecipeVariantRecord, SlotRecipeConfig", "./recipe")}
|
|
@@ -2834,7 +3103,7 @@ var generateTypesEntry = (ctx) => ({
|
|
|
2834
3103
|
}
|
|
2835
3104
|
`,
|
|
2836
3105
|
// We need to export types used in the global.d.ts here to avoid TS errors such as `The inferred type of 'xxx' cannot be named without a reference to 'yyy'`
|
|
2837
|
-
index:
|
|
3106
|
+
index: outdent40`
|
|
2838
3107
|
import '${ctx.file.extDts("./global")}'
|
|
2839
3108
|
${ctx.file.exportTypeStar("./conditions")}
|
|
2840
3109
|
${ctx.file.exportTypeStar("./pattern")}
|
|
@@ -2844,13 +3113,13 @@ var generateTypesEntry = (ctx) => ({
|
|
|
2844
3113
|
${ctx.file.exportTypeStar("./style-props")}
|
|
2845
3114
|
|
|
2846
3115
|
`,
|
|
2847
|
-
helpers:
|
|
3116
|
+
helpers: outdent40`
|
|
2848
3117
|
export type Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never
|
|
2849
3118
|
`
|
|
2850
3119
|
});
|
|
2851
3120
|
|
|
2852
3121
|
// src/artifacts/types/prop-types.ts
|
|
2853
|
-
import { outdent as
|
|
3122
|
+
import { outdent as outdent41 } from "outdent";
|
|
2854
3123
|
function generatePropTypes(ctx) {
|
|
2855
3124
|
const {
|
|
2856
3125
|
config: { strictTokens },
|
|
@@ -2858,7 +3127,7 @@ function generatePropTypes(ctx) {
|
|
|
2858
3127
|
} = ctx;
|
|
2859
3128
|
const strictText = `${strictTokens ? "" : " | CssValue<T>"}`;
|
|
2860
3129
|
const result = [
|
|
2861
|
-
|
|
3130
|
+
outdent41`
|
|
2862
3131
|
${ctx.file.importType("ConditionalValue", "./conditions")}
|
|
2863
3132
|
${ctx.file.importType("CssProperties", "./system-types")}
|
|
2864
3133
|
${ctx.file.importType("Tokens", "../tokens/index")}
|
|
@@ -2881,7 +3150,7 @@ function generatePropTypes(ctx) {
|
|
|
2881
3150
|
result.push(` ${key}: Shorthand<${JSON.stringify(value)}>;`);
|
|
2882
3151
|
});
|
|
2883
3152
|
result.push("}");
|
|
2884
|
-
return
|
|
3153
|
+
return outdent41`
|
|
2885
3154
|
${result.join("\n")}
|
|
2886
3155
|
|
|
2887
3156
|
export type PropertyValue<T extends string> = T extends keyof PropertyTypes
|
|
@@ -2894,10 +3163,10 @@ function generatePropTypes(ctx) {
|
|
|
2894
3163
|
|
|
2895
3164
|
// src/artifacts/types/style-props.ts
|
|
2896
3165
|
import { allCssProperties } from "@pandacss/is-valid-prop";
|
|
2897
|
-
import
|
|
3166
|
+
import outdent42 from "outdent";
|
|
2898
3167
|
function generateStyleProps(ctx) {
|
|
2899
3168
|
const props = new Set(allCssProperties.concat(ctx.utility.keys()).filter(Boolean));
|
|
2900
|
-
return
|
|
3169
|
+
return outdent42`
|
|
2901
3170
|
${ctx.file.importType("ConditionalValue", "./conditions")}
|
|
2902
3171
|
${ctx.file.importType("PropertyValue", "./prop-type")}
|
|
2903
3172
|
${ctx.file.importType("Token", "../tokens/index")}
|
|
@@ -2914,7 +3183,7 @@ function generateStyleProps(ctx) {
|
|
|
2914
3183
|
|
|
2915
3184
|
// src/artifacts/types/token-types.ts
|
|
2916
3185
|
import { capitalize, unionType as unionType3 } from "@pandacss/shared";
|
|
2917
|
-
import { outdent as
|
|
3186
|
+
import { outdent as outdent43 } from "outdent";
|
|
2918
3187
|
import pluralize from "pluralize";
|
|
2919
3188
|
var categories = [
|
|
2920
3189
|
"zIndex",
|
|
@@ -2965,7 +3234,7 @@ function generateTokenTypes(ctx) {
|
|
|
2965
3234
|
result.add("} & { [token: string]: never }");
|
|
2966
3235
|
set.add(Array.from(result).join("\n"));
|
|
2967
3236
|
set.add(`export type TokenCategory = ${unionType3(categories)}`);
|
|
2968
|
-
return
|
|
3237
|
+
return outdent43.string(Array.from(set).join("\n\n"));
|
|
2969
3238
|
}
|
|
2970
3239
|
|
|
2971
3240
|
// src/artifacts/index.ts
|
|
@@ -3011,7 +3280,6 @@ function setupTypes(ctx) {
|
|
|
3011
3280
|
{ file: ctx.file.extDts("selectors"), code: gen.selectors },
|
|
3012
3281
|
{ file: ctx.file.extDts("composition"), code: gen.composition },
|
|
3013
3282
|
{ file: ctx.file.extDts("global"), code: entry.global },
|
|
3014
|
-
{ file: ctx.file.extDts("helpers"), code: entry.helpers },
|
|
3015
3283
|
{ file: ctx.file.extDts("recipe"), code: gen.recipe },
|
|
3016
3284
|
{ file: ctx.file.extDts("pattern"), code: gen.pattern },
|
|
3017
3285
|
{ file: ctx.file.extDts("parts"), code: gen.parts },
|
|
@@ -3074,8 +3342,8 @@ function setupRecipes(ctx) {
|
|
|
3074
3342
|
return;
|
|
3075
3343
|
const indexFiles = files.filter((file) => !file.name.includes("create-recipe"));
|
|
3076
3344
|
const index = {
|
|
3077
|
-
js:
|
|
3078
|
-
dts:
|
|
3345
|
+
js: outdent44.string(indexFiles.map((file) => ctx.file.exportStar(`./${file.name}`)).join("\n")),
|
|
3346
|
+
dts: outdent44.string(indexFiles.map((file) => ctx.file.exportTypeStar(`./${file.name}`)).join("\n"))
|
|
3079
3347
|
};
|
|
3080
3348
|
return {
|
|
3081
3349
|
dir: ctx.paths.recipe,
|
|
@@ -3094,8 +3362,8 @@ function setupPatterns(ctx) {
|
|
|
3094
3362
|
if (!files)
|
|
3095
3363
|
return;
|
|
3096
3364
|
const index = {
|
|
3097
|
-
js:
|
|
3098
|
-
dts:
|
|
3365
|
+
js: outdent44.string(files.map((file) => ctx.file.exportStar(`./${file.name}`)).join("\n")),
|
|
3366
|
+
dts: outdent44.string(files.map((file) => ctx.file.exportTypeStar(`./${file.name}`)).join("\n"))
|
|
3099
3367
|
};
|
|
3100
3368
|
return {
|
|
3101
3369
|
dir: ctx.paths.pattern,
|
|
@@ -3114,18 +3382,19 @@ function setupJsx(ctx) {
|
|
|
3114
3382
|
const types = generateJsxTypes(ctx);
|
|
3115
3383
|
const factory = generateJsxFactory(ctx);
|
|
3116
3384
|
const patterns = generateJsxPatterns(ctx);
|
|
3385
|
+
const helpers3 = generatedJsxHelpers(ctx);
|
|
3117
3386
|
const index = {
|
|
3118
|
-
js:
|
|
3387
|
+
js: outdent44`
|
|
3119
3388
|
${ctx.file.exportStar("./factory")}
|
|
3120
3389
|
${isValidProp?.js ? ctx.file.exportStar("./is-valid-prop") : ""}
|
|
3121
|
-
${
|
|
3390
|
+
${outdent44.string(patterns.map((file) => ctx.file.exportStar(`./${file.name}`)).join("\n"))}
|
|
3122
3391
|
`,
|
|
3123
|
-
dts:
|
|
3392
|
+
dts: outdent44`
|
|
3124
3393
|
${ctx.file.exportTypeStar("./factory")}
|
|
3125
3394
|
|
|
3126
3395
|
${isValidProp?.dts ? ctx.file.exportTypeStar("./is-valid-prop") : ""}
|
|
3127
3396
|
|
|
3128
|
-
${
|
|
3397
|
+
${outdent44.string(patterns.map((file) => ctx.file.exportTypeStar(`./${file.name}`)).join("\n"))}
|
|
3129
3398
|
|
|
3130
3399
|
${ctx.file.exportType([ctx.jsx.typeName, ctx.jsx.componentName].join(", "), "../types/jsx")}
|
|
3131
3400
|
`
|
|
@@ -3137,6 +3406,7 @@ function setupJsx(ctx) {
|
|
|
3137
3406
|
...patterns.map((file) => ({ file: ctx.file.extDts(file.name), code: file.dts })),
|
|
3138
3407
|
{ file: ctx.file.ext("is-valid-prop"), code: isValidProp?.js },
|
|
3139
3408
|
{ file: ctx.file.extDts("is-valid-prop"), code: isValidProp?.dts },
|
|
3409
|
+
{ file: ctx.file.ext("factory-helper"), code: helpers3.js },
|
|
3140
3410
|
{ file: ctx.file.ext("factory"), code: factory?.js },
|
|
3141
3411
|
{ file: ctx.file.extDts("factory"), code: types.jsxFactory },
|
|
3142
3412
|
{ file: ctx.file.ext("index"), code: index.js },
|
|
@@ -3146,13 +3416,13 @@ function setupJsx(ctx) {
|
|
|
3146
3416
|
}
|
|
3147
3417
|
function setupCssIndex(ctx) {
|
|
3148
3418
|
const index = {
|
|
3149
|
-
js:
|
|
3419
|
+
js: outdent44`
|
|
3150
3420
|
${ctx.file.exportStar("./css")}
|
|
3151
3421
|
${ctx.file.exportStar("./cx")}
|
|
3152
3422
|
${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./cva")}
|
|
3153
3423
|
${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./sva")}
|
|
3154
3424
|
`,
|
|
3155
|
-
dts:
|
|
3425
|
+
dts: outdent44`
|
|
3156
3426
|
${ctx.file.exportTypeStar("./css")}
|
|
3157
3427
|
${ctx.file.exportTypeStar("./cx")}
|
|
3158
3428
|
${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportTypeStar("./cva")}
|
|
@@ -3214,6 +3484,8 @@ var generateArtifacts = (ctx) => () => {
|
|
|
3214
3484
|
].filter(Boolean).map((artifact) => {
|
|
3215
3485
|
const files = artifact?.files ?? [];
|
|
3216
3486
|
files.forEach((file) => {
|
|
3487
|
+
if (!file)
|
|
3488
|
+
return;
|
|
3217
3489
|
if (ctx.file.isTypeFile(file.file)) {
|
|
3218
3490
|
file.code = `/* eslint-disable */
|
|
3219
3491
|
${file.code}`;
|
|
@@ -3253,7 +3525,7 @@ var generateFlattenedCss = (ctx) => (options) => {
|
|
|
3253
3525
|
// src/artifacts/css/parser-css.ts
|
|
3254
3526
|
import { logger } from "@pandacss/logger";
|
|
3255
3527
|
import { pipe, tap, tryCatch } from "lil-fp/func";
|
|
3256
|
-
import { P, match as
|
|
3528
|
+
import { P, match as match10 } from "ts-pattern";
|
|
3257
3529
|
var generateParserCss = (ctx) => (result) => pipe(
|
|
3258
3530
|
{ ...ctx, sheet: ctx.createSheet(), result },
|
|
3259
3531
|
tap(({ sheet, result: result2, patterns, recipes }) => {
|
|
@@ -3283,7 +3555,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
3283
3555
|
const recipeConfig = recipes.getConfig(recipeName);
|
|
3284
3556
|
if (!recipeConfig)
|
|
3285
3557
|
continue;
|
|
3286
|
-
|
|
3558
|
+
match10(recipe).with({ type: "jsx-recipe" }, () => {
|
|
3287
3559
|
recipe.data.forEach((data) => {
|
|
3288
3560
|
const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
|
|
3289
3561
|
sheet.processStyleProps(filterProps(ctx, styleProps));
|
|
@@ -3302,7 +3574,7 @@ var generateParserCss = (ctx) => (result) => pipe(
|
|
|
3302
3574
|
result2.pattern.forEach((patternSet, name) => {
|
|
3303
3575
|
try {
|
|
3304
3576
|
for (const pattern of patternSet) {
|
|
3305
|
-
|
|
3577
|
+
match10(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: jsxName }) => {
|
|
3306
3578
|
pattern.data.forEach((data) => {
|
|
3307
3579
|
const fnName = patterns.find(jsxName);
|
|
3308
3580
|
const styleProps = patterns.transform(fnName, data);
|