shadcn-svelte 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5223,6 +5223,7 @@ var DEFAULT_COMPONENTS = "$lib/components";
5223
5223
  var DEFAULT_UTILS = "$lib/utils";
5224
5224
  var DEFAULT_TAILWIND_CSS = "src/app.pcss";
5225
5225
  var DEFAULT_TAILWIND_CONFIG = "tailwind.config.cjs";
5226
+ var DEFAULT_TYPESCRIPT = true;
5226
5227
  var rawConfigSchema = z.object({
5227
5228
  $schema: z.string().optional(),
5228
5229
  style: z.string(),
@@ -5235,7 +5236,8 @@ var rawConfigSchema = z.object({
5235
5236
  aliases: z.object({
5236
5237
  components: z.string().transform((v) => v.replace(/[\u{0080}-\u{FFFF}]/gu, "")),
5237
5238
  utils: z.string().transform((v) => v.replace(/[\u{0080}-\u{FFFF}]/gu, ""))
5238
- })
5239
+ }),
5240
+ typescript: z.boolean().default(true)
5239
5241
  }).strict();
5240
5242
  var configSchema = rawConfigSchema.extend({
5241
5243
  resolvedPaths: z.object({
@@ -5265,8 +5267,10 @@ async function resolveConfigPaths(cwd, config) {
5265
5267
  );
5266
5268
  }
5267
5269
  const tsconfigPath = await find(path8.resolve(cwd, "package.json"), { root: cwd });
5268
- if (tsconfigPath === null)
5269
- throw new Error(`Failed to find ${logger.highlight("tsconfig.json")}.`);
5270
+ if (tsconfigPath === null) {
5271
+ const configToFind = config.typescript ? "tsconfig.json" : "jsconfig.json";
5272
+ throw new Error(`Failed to find ${logger.highlight(configToFind)}.`);
5273
+ }
5270
5274
  const parsedConfig = await parseNative(tsconfigPath);
5271
5275
  const absoluteBaseUrl = parsedConfig.result.options.pathsBasePath;
5272
5276
  let paths = parsedConfig.result.options.paths;
@@ -5448,9 +5452,10 @@ async function resolveTree(index, names) {
5448
5452
  (component, index2, self2) => self2.findIndex((c2) => c2.name === component.name) === index2
5449
5453
  );
5450
5454
  }
5451
- async function fetchTree(style2, tree) {
5455
+ async function fetchTree(config, tree) {
5452
5456
  try {
5453
- const paths = tree.map((item2) => `styles/${style2}/${item2.name}.json`);
5457
+ const trueStyle = config.typescript ? config.style : `${config.style}-js`;
5458
+ const paths = tree.map((item2) => `styles/${trueStyle}/${item2.name}.json`);
5454
5459
  const result = await fetchRegistry(paths);
5455
5460
  return registryWithContentSchema.parse(result);
5456
5461
  } catch (error) {
@@ -6530,8 +6535,8 @@ var MagicString = class {
6530
6535
  }
6531
6536
  };
6532
6537
 
6533
- // src/utils/transformer.ts
6534
- function transformImport(content, config) {
6538
+ // src/utils/transformers.ts
6539
+ function transformImports(content, config) {
6535
6540
  const s = new MagicString(content);
6536
6541
  s.replaceAll(/@\/registry\/[^/]+/g, config.aliases.components);
6537
6542
  s.replaceAll(/\$lib\/utils/g, config.aliases.utils);
@@ -6607,7 +6612,7 @@ var add = new Command().command("add").description("add components to your proje
6607
6612
  return;
6608
6613
  }
6609
6614
  const tree = await resolveTree(registryIndex, selectedComponents);
6610
- const payload = await fetchTree(config.style, tree);
6615
+ const payload = await fetchTree(config, tree);
6611
6616
  const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);
6612
6617
  if (!payload.length) {
6613
6618
  logger.warn("Selected components not found. Exiting.");
@@ -6648,9 +6653,9 @@ ${highlight(selectedComponents)}`);
6648
6653
  process.cwd(),
6649
6654
  path10.resolve(targetDir, item2.name)
6650
6655
  );
6651
- const existingComponent = item2.files.filter(
6652
- (file) => existsSync2(path10.resolve(targetDir, item2.name, file.name))
6653
- );
6656
+ const existingComponent = item2.files.filter((file) => {
6657
+ return existsSync2(path10.resolve(targetDir, item2.name, file.name));
6658
+ });
6654
6659
  if (existingComponent.length && !options.overwrite) {
6655
6660
  if (selectedComponents.includes(item2.name)) {
6656
6661
  logger.warn(
@@ -6670,7 +6675,7 @@ Component ${highlight(
6670
6675
  for (const file of item2.files) {
6671
6676
  const componentDir = path10.resolve(targetDir, item2.name);
6672
6677
  let filePath = path10.resolve(targetDir, item2.name, file.name);
6673
- const content = transformImport(file.content, config);
6678
+ const content = transformImports(file.content, config);
6674
6679
  if (!existsSync2(componentDir)) {
6675
6680
  await fs6.mkdir(componentDir, { recursive: true });
6676
6681
  }
@@ -6787,6 +6792,54 @@ export const flyAndScale = (
6787
6792
  easing: cubicOut
6788
6793
  };
6789
6794
  };`;
6795
+ var UTILS_JS = `import { clsx } from "clsx";
6796
+ import { twMerge } from "tailwind-merge";
6797
+ import { cubicOut } from "svelte/easing";
6798
+
6799
+ export function cn(...inputs) {
6800
+ return twMerge(clsx(inputs));
6801
+ }
6802
+
6803
+ export const flyAndScale = (
6804
+ node,
6805
+ params = { y: -8, x: 0, start: 0.95, duration: 150 }
6806
+ ) => {
6807
+ const style = getComputedStyle(node);
6808
+ const transform = style.transform === "none" ? "" : style.transform;
6809
+
6810
+ const scaleConversion = (valueA, scaleA, scaleB) => {
6811
+ const [minA, maxA] = scaleA;
6812
+ const [minB, maxB] = scaleB;
6813
+
6814
+ const percentage = (valueA - minA) / (maxA - minA);
6815
+ const valueB = percentage * (maxB - minB) + minB;
6816
+
6817
+ return valueB;
6818
+ };
6819
+
6820
+ const styleToString = (style) => {
6821
+ return Object.keys(style).reduce((str, key) => {
6822
+ if (style[key] === undefined) return str;
6823
+ return str + \`\${key}:\${style[key]};\`;
6824
+ }, "");
6825
+ };
6826
+
6827
+ return {
6828
+ duration: params.duration ?? 200,
6829
+ delay: 0,
6830
+ css: (t) => {
6831
+ const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0]);
6832
+ const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0]);
6833
+ const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1]);
6834
+
6835
+ return styleToString({
6836
+ transform: \`\${transform} translate3d(\${x}px, \${y}px, 0) scale(\${scale})\`,
6837
+ opacity: t
6838
+ });
6839
+ },
6840
+ easing: cubicOut
6841
+ };
6842
+ };`;
6790
6843
  var TAILWIND_CONFIG_WITH_VARIABLES = `import { fontFamily } from "tailwindcss/defaultTheme";
6791
6844
 
6792
6845
  /** @type {import('tailwindcss').Config} */
@@ -6861,9 +6914,7 @@ var init2 = new Command2().command("init").description("Configure your SvelteKit
6861
6914
  process.cwd()
6862
6915
  ).action(async (options) => {
6863
6916
  const cwd = path11.resolve(options.cwd);
6864
- logger.warn(
6865
- "This command assumes a SvelteKit project with TypeScript and Tailwind CSS."
6866
- );
6917
+ logger.warn("This command assumes a SvelteKit project with Tailwind CSS.");
6867
6918
  logger.warn(
6868
6919
  "If you don't have these, follow the manual steps at https://shadcn-svelte.com/docs/installation."
6869
6920
  );
@@ -6907,6 +6958,14 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6907
6958
  const styles2 = await getRegistryStyles();
6908
6959
  const baseColors = await getRegistryBaseColors();
6909
6960
  const options = await prompts3([
6961
+ {
6962
+ type: "toggle",
6963
+ name: "typescript",
6964
+ message: `Would you like to use ${highlight("TypeScript")} (recommended)?`,
6965
+ initial: defaultConfig?.typescript ?? DEFAULT_TYPESCRIPT,
6966
+ active: "yes",
6967
+ inactive: "no"
6968
+ },
6910
6969
  {
6911
6970
  type: "select",
6912
6971
  name: "style",
@@ -6969,6 +7028,7 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6969
7028
  const config = rawConfigSchema.parse({
6970
7029
  $schema: "https://shadcn-svelte.com/schema.json",
6971
7030
  style: options.style,
7031
+ typescript: options.typescript,
6972
7032
  tailwind: {
6973
7033
  config: options.tailwindConfig,
6974
7034
  css: options.tailwindCss,
@@ -7030,7 +7090,9 @@ async function runInit(cwd, config) {
7030
7090
  "utf8"
7031
7091
  );
7032
7092
  }
7033
- await fs7.writeFile(`${config.resolvedPaths.utils}.ts`, UTILS, "utf8");
7093
+ const utilsPath = config.resolvedPaths.utils + (config.typescript ? ".ts" : ".js");
7094
+ const utilsTemplate = config.typescript ? UTILS : UTILS_JS;
7095
+ await fs7.writeFile(utilsPath, utilsTemplate, "utf8");
7034
7096
  spinner?.succeed();
7035
7097
  const dependenciesSpinner = ora2(`Installing dependencies...`)?.start();
7036
7098
  const packageManager = await getPackageManager(cwd);
@@ -7140,7 +7202,8 @@ var update = new Command3().command("update").description("update components in
7140
7202
  return;
7141
7203
  }
7142
7204
  if (selectedComponents.find((item2) => item2.name === "utils")) {
7143
- const utilsPath = config.resolvedPaths.utils + ".ts";
7205
+ const extension = config.typescript ? ".ts" : ".js";
7206
+ const utilsPath = config.resolvedPaths.utils + extension;
7144
7207
  if (!existsSync4(utilsPath)) {
7145
7208
  spinner.fail(
7146
7209
  `utils at ${logger.highlight(utilsPath)} does not exist.`
@@ -7154,7 +7217,7 @@ var update = new Command3().command("update").description("update components in
7154
7217
  registryIndex,
7155
7218
  selectedComponents.map((com) => com.name)
7156
7219
  );
7157
- const payload = await fetchTree(config.style, tree);
7220
+ const payload = await fetchTree(config, tree);
7158
7221
  for (const item2 of payload) {
7159
7222
  spinner.text = `Updating ${item2.name}...`;
7160
7223
  const targetDir = await getItemTargetPath(config, item2);
@@ -7167,7 +7230,7 @@ var update = new Command3().command("update").description("update components in
7167
7230
  for (const file of item2.files) {
7168
7231
  const componentDir2 = path12.resolve(targetDir, item2.name);
7169
7232
  let filePath = path12.resolve(targetDir, item2.name, file.name);
7170
- const content = transformImport(file.content, config);
7233
+ const content = transformImports(file.content, config);
7171
7234
  if (!existsSync4(componentDir2)) {
7172
7235
  await fs8.mkdir(componentDir2, { recursive: true });
7173
7236
  }