Ver código fonte

[create]Add UnoCSS template

杜府 3 anos atrás
pai
commit
6f8800ffea
23 arquivos alterados com 407 adições e 56 exclusões
  1. 3 3
      packages/create-stdf/package.json
  2. 46 43
      packages/create-stdf/src/index.js
  3. 4 2
      packages/create-stdf/src/lang.js
  4. 3 2
      packages/create-stdf/templates/vite-tailwind/index.html
  5. 1 0
      packages/create-stdf/templates/vite-tailwind/package.json
  6. 4 0
      packages/create-stdf/templates/vite-tailwind/public/stdf.svg
  7. 4 0
      packages/create-stdf/templates/vite-tailwind/public/stdf_dark.svg
  8. 27 6
      packages/create-stdf/templates/vite-tailwind/src/App.svelte
  9. 47 0
      packages/create-stdf/templates/vite-uno/README.md
  10. 14 0
      packages/create-stdf/templates/vite-uno/index.html
  11. 20 0
      packages/create-stdf/templates/vite-uno/package.json
  12. 4 0
      packages/create-stdf/templates/vite-uno/public/stdf.svg
  13. 4 0
      packages/create-stdf/templates/vite-uno/public/stdf_dark.svg
  14. 111 0
      packages/create-stdf/templates/vite-uno/src/App.svelte
  15. 3 0
      packages/create-stdf/templates/vite-uno/src/app.css
  16. 1 0
      packages/create-stdf/templates/vite-uno/src/assets/svelte.svg
  17. 6 0
      packages/create-stdf/templates/vite-uno/src/assets/tailwindcss.svg
  18. 1 0
      packages/create-stdf/templates/vite-uno/src/assets/vite.svg
  19. 9 0
      packages/create-stdf/templates/vite-uno/src/lib/Counter.svelte
  20. 10 0
      packages/create-stdf/templates/vite-uno/src/main.js
  21. 7 0
      packages/create-stdf/templates/vite-uno/svelte.config.js
  22. 50 0
      packages/create-stdf/templates/vite-uno/uno.config.js
  23. 28 0
      packages/create-stdf/templates/vite-uno/vite.config.js

+ 3 - 3
packages/create-stdf/package.json

@@ -1,6 +1,6 @@
 {
     "name": "create-stdf",
-    "version": "0.0.21",
+    "version": "0.0.22",
     "description": "A CLI for creating new STDF projects",
     "bin": {
         "create-stdf": "index.js"
@@ -22,8 +22,8 @@
         "kleur": "^4.1.5"
     },
     "devDependencies": {
-        "rollup": "^3.27.0",
-        "@rollup/plugin-terser": "^0.4.3"
+        "@rollup/plugin-terser": "^0.4.3",
+        "rollup": "^3.27.0"
     },
     "keywords": [
         "svelte",

+ 46 - 43
packages/create-stdf/src/index.js

@@ -2,6 +2,7 @@
 
 import fs from 'fs-extra';
 import path from 'node:path';
+import { fileURLToPath } from 'node:url';
 import * as p from '@clack/prompts';
 import { bold, cyan, grey, red, blue } from 'kleur/colors';
 
@@ -9,16 +10,6 @@ import * as langAll from './lang';
 
 const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
 
-// const templatePath = new URL('../templates/vite-tailwind/package.json', import.meta.url);
-// const templatePath2 = new URL('../templates/vite-tailwind', import.meta.url);
-// const templatePath3 = new URL('../templates/vite-tailwind/', import.meta.url);
-// // const sourceFilePath = path.join(__dirname, templatePath);
-
-// console.log(11, templatePath);
-// console.log(22, templatePath2);
-// console.log(33, templatePath3);
-// console.log(44, sourceFilePath);
-
 // 显示版本号
 // Display version number
 console.log(`
@@ -46,14 +37,14 @@ if (p.isCancel(languageType)) {
 }
 
 const templateOptions = [
-    { value: 'vt', label: 'Vite + Tailwind', template: '../templates/vite-tailwind/' },
-    { value: 'vu', label: `Vite + UnoCSS(${lang.hnay})`, template: '../templates/vite-uno' },
-    { value: 'skt', label: `SvelteKit + Tailwind(${lang.hnay})`, template: '../templates/sveltekit-tailwind' },
-    { value: 'sku', label: `SvelteKit + UnoCSS(${lang.hnay})`, template: '../templates/sveltekit-uno' },
-    { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: '../templates/vite-tailwind-typescript' },
-    { value: 'vut', label: `Vite + UnoCSS+TypeScript(${lang.hnay})`, template: '../templates/vite-uno-typescript' },
-    { value: 'sktt', label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`, template: '../templates/sveltekit-tailwind-typescript' },
-    { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: '../templates/sveltekit-uno-typescript' },
+    { value: 'vt', label: 'Vite + Tailwind', template: 'vite-tailwind', pcyt: lang.pcyt_vt },
+    { value: 'vu', label: `Vite + UnoCSS`, template: 'vite-uno', pcyt: lang.pcyt_vu },
+    { value: 'skt', label: `SvelteKit + Tailwind(${lang.hnay})`, template: 'sveltekit-tailwind' },
+    { value: 'sku', label: `SvelteKit + UnoCSS(${lang.hnay})`, template: 'sveltekit-uno' },
+    { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: 'vite-tailwind-typescript' },
+    { value: 'vut', label: `Vite + UnoCSS+TypeScript(${lang.hnay})`, template: 'vite-uno-typescript' },
+    { value: 'sktt', label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`, template: 'sveltekit-tailwind-typescript' },
+    { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: 'sveltekit-uno-typescript' },
 ];
 
 //  选择一个模板
@@ -63,9 +54,9 @@ let template = await p.select({
     options: templateOptions,
 });
 
-// 直到选择的 template 是 vt 为止,否则一直重新选择
+// 直到选择的 template 是 vt / vu 为止,否则一直重新选择
 // Until the selected template is vt or vu, otherwise keep reselecting
-while (template !== 'vt') {
+while (template !== 'vt' && template !== 'vu') {
     if (p.isCancel(template)) {
         p.cancel(red('⛔ ') + lang.oc);
         process.exit(0);
@@ -87,7 +78,7 @@ if (p.isCancel(template)) {
 // Enter the project name
 const projectName = await p.text({
     message: bold(lang.pn),
-    initialValue: 'stdf-project',
+    placeholder: 'stdf-project',
     validate: value => {
         if (!value) {
             // 判断是否为空,提示 “项目名称不能为空”
@@ -121,30 +112,19 @@ templateOptions.forEach(async item => {
 
         // 获取模板目录的绝对路径,考虑到 Windows 系统的兼容性, 使用 path.join
         // Get the absolute path of the template directory, considering the compatibility of the Windows system, use path.join
-        const templatePath = new URL(item.template, import.meta.url).pathname
-        // const sourceFilePath = templatePath;
+        const templatePath = path.resolve(fileURLToPath(import.meta.url), '../..', `templates/${item.template}`);
 
         // 将 templatePath 目录下的所有文件复制到 projectDir 目录下
         // Copy all files under the templatePath directory to the projectDir directory\
         fs.copy(templatePath, projectDir)
             .then(() => {
                 spinner.stop();
-                console.log(`🎉 ${lang.pcsucc}
-`);
+                p.outro(`${projectName}-${lang.pcsucc} 🎉`);
 
-                // 读取 package.json 文件,获得 vite svelte tailwind stdf 的版本号
-                // Read the package.json file to get the version number of vite svelte tailwind stdf
+                // 读取 package.json 文件
+                // Read the package.json file
                 const packageJson = JSON.parse(fs.readFileSync(`${projectDir}/package.json`, 'utf-8'));
 
-                // packageJson 中的 devDependencies 里面的版本号去除 ^ 符号
-                // The version number in devDependencies in packageJson removes the ^ symbol
-                const versions = {
-                    vite: packageJson.devDependencies.vite.replace('^', ''),
-                    svelte: packageJson.devDependencies.svelte.replace('^', ''),
-                    tailwindcss: packageJson.devDependencies.tailwindcss.replace('^', ''),
-                    stdf: packageJson.devDependencies.stdf.replace('^', ''),
-                };
-
                 // 将项目内的 package.json 中的 name 属性修改为 projectName
                 // Modify the name attribute in package.json in the project to projectName
                 packageJson.name = projectName;
@@ -153,14 +133,37 @@ templateOptions.forEach(async item => {
                 // Write the modified packageJson to the package.json file in the project
                 fs.writeFileSync(`${projectDir}/package.json`, JSON.stringify(packageJson, null, 4), 'utf-8');
 
+                // 获得依赖的版本号
+                // get the version number of the dependency
+                let versions = {};
+                if (template === 'vt') {
+                    versions = {
+                        vite: packageJson.devDependencies.vite.replace('^', ''),
+                        svelte: packageJson.devDependencies.svelte.replace('^', ''),
+                        tailwindcss: packageJson.devDependencies.tailwindcss.replace('^', ''),
+                        stdf: packageJson.devDependencies.stdf.replace('^', ''),
+                    };
+                }
+                if (template === 'vu') {
+                    versions = {
+                        vite: packageJson.devDependencies.vite.replace('^', ''),
+                        svelte: packageJson.devDependencies.svelte.replace('^', ''),
+                        unocss: packageJson.devDependencies.unocss.replace('^', ''),
+                        stdf: packageJson.devDependencies.stdf.replace('^', ''),
+                    };
+                }
+
+                // 将 versions 的键值拼接为 bold('Vite:') cyan(versions.vite) bold('Svelte:') cyan(versions.svelte) 的形式
+                // Splice the key value of versions into the form of bold('Vite:') cyan(versions.vite) bold('Svelte:') cyan(versions.svelte)
+                let versionsString = '';
+                for (const key in versions) {
+                    versionsString += bold(key) + ': ' + cyan(versions[key]) + ' ';
+                }
+
                 // 显示版本号
                 // Display version number
-                console.log(
-                    `📦 ${bold('Vite:')} ${cyan(versions.vite)} ${bold('Svelte:')} ${cyan(versions.svelte)} ${bold('Tailwind:')} ${cyan(
-                        versions.tailwindcss
-                    )} ${bold('STDF:')} ${cyan(versions.stdf)}
-    `
-                );
+                console.log(`📦 ${versionsString}
+                `);
 
                 // 显示提示信息
                 // Display prompt information
@@ -176,7 +179,7 @@ templateOptions.forEach(async item => {
                 // 显示配置主题色
                 // Display configuration theme color
                 console.log(
-                    `🎨 ${grey(lang.pcyt)}
+                    `🎨 ${grey(item.pcyt)}
     `
                 );
             })

+ 4 - 2
packages/create-stdf/src/lang.js

@@ -9,7 +9,8 @@ export const en_US = {
     cfsing: 'Creating file...',
     pcsucc: 'Project created successfully',
     tgs: 'To get started:',
-    pcyt: 'Tip: Please configure your color system in the tailwind.config.js file',
+    pcyt_vt: 'Tip: Please configure your color system in the tailwind.config.js file',
+    pcyt_vu: 'Tip: Please configure your color system in the uno.config.js file',
     cferror: 'Failed to create file',
 };
 
@@ -24,6 +25,7 @@ export const zh_CN = {
     cfsing: '正在创建文件...',
     pcsucc: '项目创建成功',
     tgs: '开始:',
-    pcyt: '提示:请到 tailwind.config.js 文件内配置你的颜色系统',
+    pcyt_vt: '提示:请到 tailwind.config.js 文件内配置你的颜色系统',
+    pcyt_vu: '提示:请到 uno.config.js 文件内配置你的颜色系统',
     cferror: '创建文件失败',
 };

+ 3 - 2
packages/create-stdf/templates/vite-tailwind/index.html

@@ -3,9 +3,10 @@
 
 <head>
   <meta charset="UTF-8" />
-  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
+  <link rel="icon" type="image/svg+xml" href="/stdf.svg" media="(prefers-color-scheme: light)" />
+  <link rel="icon" type="image/svg+xml" href="/stdf_dark.svg" media="(prefers-color-scheme: dark)" />
   <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
-  <title>Vite + Svelte</title>
+  <title>Vite + Svelte + Tailwind + STDF</title>
 </head>
 
 <body class="bg-gray9 dark:bg-gray3 text-black dark:text-white/90">

+ 1 - 0
packages/create-stdf/templates/vite-tailwind/package.json

@@ -8,6 +8,7 @@
         "autoprefixer": "^10.4.14",
         "postcss": "^8.4.27",
         "svelte": "^4.1.1",
+        "stdf": "^0.2.2",
         "tailwindcss": "^3.3.3",
         "vite": "^4.4.6"
     },

+ 4 - 0
packages/create-stdf/templates/vite-tailwind/public/stdf.svg

@@ -0,0 +1,4 @@
+<svg width="90" height="80" viewBox="0 0 90 80" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z" fill="#0B24FB"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M20 30V0L0 50H20V80L40 30H20Z" fill="#FFC043"/>
+</svg>

+ 4 - 0
packages/create-stdf/templates/vite-tailwind/public/stdf_dark.svg

@@ -0,0 +1,4 @@
+<svg width="90" height="80" viewBox="0 0 90 80" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z" fill="#FFC043"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M20 30V0L0 50H20V80L40 30H20Z" fill="#0B24FB"/>
+</svg>

+ 27 - 6
packages/create-stdf/templates/vite-tailwind/src/App.svelte

@@ -1,6 +1,8 @@
 <script>
     import { setContext } from 'svelte';
-    import { Button, Cell } from 'stdf';
+    import en_US from 'stdf/lang/en_US';
+    import zh_CN from 'stdf/lang/zh_CN';
+    import { Button, Cell, Calendar } from 'stdf';
     import Counter from './lib/Counter.svelte';
 
     import viteLogo from './assets/vite.svg';
@@ -8,25 +10,33 @@
     import tailwindLogo from './assets/tailwindcss.svg';
 
     //切换亮暗模式(toggle light or dark mode)
-    let theme = 'light';
+    let theme = sessionStorage.getItem('theme') === 'dark' ? 'dark' : 'light';
+    if (theme === 'dark') {
+        document.documentElement.classList.add('dark');
+    }
     const toggleModeFun = () => {
         if (theme === 'dark') {
             // 切换到(light switch to light)
             theme = 'light';
             document.documentElement.classList.remove('dark');
+            sessionStorage.setItem('theme', 'light');
         } else {
             // 切换到(dark switch to dark)
             theme = 'dark';
             document.documentElement.classList.add('dark');
+            sessionStorage.setItem('theme', 'dark');
         }
     };
 
     // 设置语言(setting language)
-    let lang = 'zh_CN';
+    let lang = sessionStorage.getItem('lang') === 'en_US' ? 'en_US' : 'zh_CN';
     $: isZh = lang === 'zh_CN';
+    setContext('STDF_lang', sessionStorage.getItem('lang') === 'en_US' ? en_US : zh_CN);
     const toggleLangFun = () => {
         lang = isZh ? 'en_US' : 'zh_CN';
-        setContext('STDF_lang', lang);
+        sessionStorage.setItem('lang', isZh ? 'en_US' : 'zh_CN');
+        // 刷新(refresh)
+        location.reload();
     };
 
     // 进度条(percent)
@@ -37,6 +47,9 @@
     const increaseFunc = () => {
         percent < 100 && (percent += 10);
     };
+
+    // 日历(calendar)
+    let visible = false;
 </script>
 
 <main>
@@ -70,7 +83,11 @@
         {/if}
     </div>
     <div class="my-8">
-        <Cell title={isZh ? '英文' : 'English'} right={{ type: 'switch' }} on:click={toggleLangFun} />
+        <Cell
+            title={isZh ? '暗模式' : 'Dark mode'}
+            right={{ type: 'switch', switch: { check: theme === 'dark' } }}
+            on:click={toggleModeFun}
+        />
     </div>
     <div class="my-8">
         <Counter bind:percent />
@@ -85,6 +102,10 @@
         </Button>
     </div>
     <div class="my-8">
-        <Button on:click={toggleModeFun}>{isZh ? '亮暗模式' : 'Light or dark mode'}</Button>
+        <Button fill="lineTheme" on:click={() => (visible = true)}>{isZh ? '日历' : 'Calendar'}</Button>
+    </div>
+    <Calendar bind:visible />
+    <div class="my-8">
+        <Button on:click={toggleLangFun}>{isZh ? '切换语言' : 'Toggle language'}</Button>
     </div>
 </main>

+ 47 - 0
packages/create-stdf/templates/vite-uno/README.md

@@ -0,0 +1,47 @@
+# Svelte + Vite
+
+This template should help get you started developing with Svelte in Vite.
+
+## Recommended IDE Setup
+
+[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
+
+## Need an official Svelte framework?
+
+Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
+
+## Technical considerations
+
+**Why use this over SvelteKit?**
+
+- It brings its own routing solution which might not be preferable for some users.
+- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
+
+This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
+
+Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
+
+**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
+
+Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
+
+**Why include `.vscode/extensions.json`?**
+
+Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
+
+**Why enable `checkJs` in the JS template?**
+
+It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration.
+
+**Why is HMR not preserving my local component state?**
+
+HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state).
+
+If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
+
+```js
+// store.js
+// An extremely simple external store
+import { writable } from 'svelte/store'
+export default writable(0)
+```

+ 14 - 0
packages/create-stdf/templates/vite-uno/index.html

@@ -0,0 +1,14 @@
+<head>
+  <meta charset="UTF-8" />
+  <link rel="icon" type="image/svg+xml" href="/stdf.svg" media="(prefers-color-scheme: light)" />
+  <link rel="icon" type="image/svg+xml" href="/stdf_dark.svg" media="(prefers-color-scheme: dark)" />
+  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
+  <title>Vite + Svelte + UnoCSS + STDF</title>
+</head>
+
+<body class="bg-gray9 dark:bg-gray3 text-black dark:text-white/90">
+  <div id="app"></div>
+  <script type="module" src="/src/main.js"></script>
+</body>
+
+</html>

+ 20 - 0
packages/create-stdf/templates/vite-uno/package.json

@@ -0,0 +1,20 @@
+{
+    "name": "stdf-project",
+    "private": true,
+    "version": "0.0.0",
+    "type": "module",
+    "devDependencies": {
+        "@sveltejs/vite-plugin-svelte": "^2.4.2",
+        "@unocss/extractor-svelte": "^0.54.2",
+        "@unocss/reset": "^0.54.2",
+        "stdf": "^0.2.2",
+        "svelte": "^4.1.1",
+        "unocss": "^0.53.6",
+        "vite": "^4.4.6"
+    },
+    "scripts": {
+        "dev": "vite",
+        "build": "vite build",
+        "preview": "vite preview"
+    }
+}

+ 4 - 0
packages/create-stdf/templates/vite-uno/public/stdf.svg

@@ -0,0 +1,4 @@
+<svg width="90" height="80" viewBox="0 0 90 80" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z" fill="#0B24FB"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M20 30V0L0 50H20V80L40 30H20Z" fill="#FFC043"/>
+</svg>

+ 4 - 0
packages/create-stdf/templates/vite-uno/public/stdf_dark.svg

@@ -0,0 +1,4 @@
+<svg width="90" height="80" viewBox="0 0 90 80" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z" fill="#FFC043"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M20 30V0L0 50H20V80L40 30H20Z" fill="#0B24FB"/>
+</svg>

+ 111 - 0
packages/create-stdf/templates/vite-uno/src/App.svelte

@@ -0,0 +1,111 @@
+<script>
+    import { setContext } from 'svelte';
+    import en_US from 'stdf/lang/en_US';
+    import zh_CN from 'stdf/lang/zh_CN';
+    import { Button, Cell, Calendar } from 'stdf';
+    import Counter from './lib/Counter.svelte';
+
+    import viteLogo from './assets/vite.svg';
+    import svelteLogo from './assets/svelte.svg';
+    import tailwindLogo from './assets/tailwindcss.svg';
+
+    //切换亮暗模式(toggle light or dark mode)
+    let theme = sessionStorage.getItem('theme') === 'dark' ? 'dark' : 'light';
+    if (theme === 'dark') {
+        document.documentElement.classList.add('dark');
+    }
+    const toggleModeFun = () => {
+        if (theme === 'dark') {
+            // 切换到(light switch to light)
+            theme = 'light';
+            document.documentElement.classList.remove('dark');
+            sessionStorage.setItem('theme', 'light');
+        } else {
+            // 切换到(dark switch to dark)
+            theme = 'dark';
+            document.documentElement.classList.add('dark');
+            sessionStorage.setItem('theme', 'dark');
+        }
+    };
+
+    // 设置语言(setting language)
+    let lang = sessionStorage.getItem('lang') === 'en_US' ? 'en_US' : 'zh_CN';
+    $: isZh = lang === 'zh_CN';
+    setContext('STDF_lang', sessionStorage.getItem('lang') === 'en_US' ? en_US : zh_CN);
+    const toggleLangFun = () => {
+        lang = isZh ? 'en_US' : 'zh_CN';
+        sessionStorage.setItem('lang', isZh ? 'en_US' : 'zh_CN');
+        // 刷新(refresh)
+        location.reload();
+    };
+
+    // 进度条(percent)
+    let percent = 20;
+    const reduceFunc = () => {
+        percent > 0 && (percent -= 10);
+    };
+    const increaseFunc = () => {
+        percent < 100 && (percent += 10);
+    };
+
+    // 日历(calendar)
+    let visible = false;
+</script>
+
+<main>
+    <div class="flex justify-center items-center text-center gap-4 pt-20">
+        <a class="flex flex-col items-center w-10" href="https://vitejs.dev" target="_blank" rel="noreferrer">
+            <img src={viteLogo} alt="Vite Logo" />
+        </a>+
+        <a class="flex flex-col items-center w-10" href="https://svelte.dev" target="_blank" rel="noreferrer">
+            <img src={svelteLogo} alt="Svelte Logo" />
+        </a>+
+        <a class="flex flex-col items-center w-10" href="https://tailwindcss.com" target="_blank" rel="noreferrer">
+            <img src={tailwindLogo} alt="Tailwind Logo" />
+        </a>+
+        <a class="flex flex-col items-center w-8" href="https://stdf.design" target="_blank" rel="noreferrer">
+            <svg viewBox="0 0 90 80" fill="currentColor">
+                <path
+                    class="text-primary dark:text-dark"
+                    d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z"
+                />
+                <path class="text-dark dark:text-primary" d="M20 30V0L0 50H20V80L40 30H20Z" />
+            </svg>
+        </a>
+    </div>
+    <div class="text-center my-8 text-xs">
+        {#if isZh}
+            <p>这是一个使用 Vite + Svelte + Tailwind + STDF 构建的模板。</p>
+            <p class="mt-2">点击上方 LOGO 了解更多。</p>
+        {:else}
+            <p>This is a template using Vite + Svelte + TailwindCSS + STDF.</p>
+            <p class="mt-2">Click the logo above to learn more.</p>
+        {/if}
+    </div>
+    <div class="my-8">
+        <Cell
+            title={isZh ? '暗模式' : 'Dark mode'}
+            right={{ type: 'switch', switch: { check: theme === 'dark' } }}
+            on:click={toggleModeFun}
+        />
+    </div>
+    <div class="my-8">
+        <Counter bind:percent />
+    </div>
+    <div class="my-8">
+        <Button heightIn="0" group fill="lineTheme">
+            <div class="flex divide-x">
+                <div class="flex-1 py-2 active:opacity-80" on:click={reduceFunc}>-10</div>
+                <div class="flex-1 py-2 active:opacity-80" on:click={increaseFunc}>+10</div>
+                <div class="flex-1 py-2 active:opacity-80" on:click={() => (percent = 20)}>{isZh ? '重置' : 'Reset'}</div>
+            </div>
+        </Button>
+    </div>
+    <div class="my-8">
+        <Button fill="lineTheme" on:click={() => (visible = true)}>{isZh ? '日历' : 'Calendar'}</Button>
+    </div>
+    <Calendar bind:visible />
+    <div class="my-8">
+        <Button on:click={toggleLangFun}>{isZh ? '切换语言' : 'Toggle language'}</Button>
+    </div>
+</main>

+ 3 - 0
packages/create-stdf/templates/vite-uno/src/app.css

@@ -0,0 +1,3 @@
+html {
+  -webkit-tap-highlight-color: transparent;
+}

+ 1 - 0
packages/create-stdf/templates/vite-uno/src/assets/svelte.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

+ 6 - 0
packages/create-stdf/templates/vite-uno/src/assets/tailwindcss.svg

@@ -0,0 +1,6 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+    <title>Tailwind CSS</title>
+    <path
+    fill="#06B6D4"
+        d="M12.001,4.8c-3.2,0-5.2,1.6-6,4.8c1.2-1.6,2.6-2.2,4.2-1.8c0.913,0.228,1.565,0.89,2.288,1.624 C13.666,10.618,15.027,12,18.001,12c3.2,0,5.2-1.6,6-4.8c-1.2,1.6-2.6,2.2-4.2,1.8c-0.913-0.228-1.565-0.89-2.288-1.624 C16.337,6.182,14.976,4.8,12.001,4.8z M6.001,12c-3.2,0-5.2,1.6-6,4.8c1.2-1.6,2.6-2.2,4.2-1.8c0.913,0.228,1.565,0.89,2.288,1.624 c1.177,1.194,2.538,2.576,5.512,2.576c3.2,0,5.2-1.6,6-4.8c-1.2,1.6-2.6,2.2-4.2,1.8c-0.913-0.228-1.565-0.89-2.288-1.624 C10.337,13.382,8.976,12,6.001,12z" />
+</svg>

+ 1 - 0
packages/create-stdf/templates/vite-uno/src/assets/vite.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

+ 9 - 0
packages/create-stdf/templates/vite-uno/src/lib/Counter.svelte

@@ -0,0 +1,9 @@
+<script>
+  import { Progress } from 'stdf';
+
+  export let percent = 20;
+</script>
+
+<div class="p-4">
+  <Progress {percent} />
+</div>

+ 10 - 0
packages/create-stdf/templates/vite-uno/src/main.js

@@ -0,0 +1,10 @@
+import './app.css';
+import App from './App.svelte';
+import 'uno.css';
+import '@unocss/reset/tailwind.css';
+
+const app = new App({
+    target: document.getElementById('app'),
+});
+
+export default app;

+ 7 - 0
packages/create-stdf/templates/vite-uno/svelte.config.js

@@ -0,0 +1,7 @@
+import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
+
+export default {
+  // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
+  // for more information about preprocessors
+  preprocess: vitePreprocess(),
+}

+ 50 - 0
packages/create-stdf/templates/vite-uno/uno.config.js

@@ -0,0 +1,50 @@
+// uno.config.js
+import { defineConfig, presetUno } from 'unocss';
+
+export default defineConfig({
+    // ...UnoCSS options
+    content: {
+        filesystem: ['./node_modules/stdf/src/**/*.svelte'],
+    },
+    presets: [presetUno()],
+    theme: {
+        colors: {
+            // 主题色
+            // Theme Color
+            primary: '#0B24FB',
+            dark: '#FFC043',
+            blue: '#0B24FB', // primary 别名 alias
+            yellow: '#FFC043', // dark 别名 alias
+
+            // 扩展色
+            // Extended Color
+            purple: '#7356BF',
+            green: '#05944F',
+            orange: '#FF6937',
+
+            // 功能色
+            // Functional Color
+            success: '#11BB8D',
+            warning: '#B95000',
+            error: '#DA1414',
+            info: '#2E5AAC',
+
+            // 中性色
+            // Neutral Color
+            black: '#000000',
+            white: '#fff',
+            gray1: '#23262B',
+            gray2: '#2A2B2F',
+            gray3: '#303239',
+            gray4: '#373940',
+            gray5: '#414249',
+            gray6: '#747B84',
+            gray7: '#DADEE3',
+            gray8: '#EBEEF2',
+            gray9: '#F4F6F9',
+            gray10: '#FAFAFB',
+            transparent: 'transparent',
+        },
+        extend: {},
+    },
+});

+ 28 - 0
packages/create-stdf/templates/vite-uno/vite.config.js

@@ -0,0 +1,28 @@
+import { defineConfig } from 'vite';
+import { svelte } from '@sveltejs/vite-plugin-svelte';
+import UnoCSS from 'unocss/vite';
+import extractorSvelte from '@unocss/extractor-svelte';
+
+// https://vitejs.dev/config/
+export default defineConfig({
+    plugins: [
+        UnoCSS({
+            extractors: [extractorSvelte()],
+        }),
+        svelte({
+            onwarn(warning, defaultHandler) {
+                const ignoredWarnings = [
+                    'a11y-distracting-elements',
+                    'a11y-no-static-element-interactions',
+                    'a11y-click-events-have-key-events',
+                ];
+                const { code } = warning;
+                // don't warn on <marquee> elements, cos they're cool
+                if (ignoredWarnings.includes(code)) return;
+
+                // handle all other warnings normally
+                defaultHandler(warning);
+            },
+        }),
+    ],
+});