lapikit 0.0.0-insiders.835ce98 → 0.0.0-insiders.84cc107

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.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { promises as fs } from 'fs';
3
+ import path from 'path';
4
+ import presets from './presets.js';
5
+
6
+ export async function initConfiguration(options) {
7
+ console.log('initConfiguration called with:', options);
8
+ const { typescript, pathConfig } = options;
9
+ const ext = typescript ? 'ts' : 'js';
10
+ const targetDir = path.resolve(process.cwd(), pathConfig);
11
+ const targetFile = path.join(targetDir, `lapikit.${ext}`);
12
+
13
+ await fs.mkdir(targetDir, { recursive: true });
14
+
15
+ try {
16
+ console.log(`Trying to access ${targetFile}`);
17
+ await fs.access(targetFile);
18
+ console.log(`File ${targetFile} already exists.`);
19
+ } catch {
20
+ console.log(`Creating file: ${targetFile}`);
21
+ let content = presets();
22
+
23
+ await fs.writeFile(targetFile, content);
24
+ console.log(`File created : ${targetFile}`);
25
+ }
26
+ }
package/bin/helper.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+
1
4
  const color = {
2
5
  red: (text) => `\x1b[31m${text}\x1b[0m`,
3
6
  green: (text) => `\x1b[32m${text}\x1b[0m`,
@@ -63,6 +66,26 @@ export function getCssPathFromArgs() {
63
66
  return args[1] || 'src/app.css';
64
67
  }
65
68
 
69
+ export function getLapikitPathFromArgs() {
70
+ const args = process.argv.slice(2);
71
+ // Search argument after --plugin-path or -p
72
+ const pluginPathIndex = args.findIndex((arg) => arg === '--plugin-path' || arg === '-p');
73
+ if (pluginPathIndex !== -1 && args[pluginPathIndex + 1]) {
74
+ return args[pluginPathIndex + 1];
75
+ }
76
+ return 'src/plugin';
77
+ }
78
+
79
+ export function validatePluginPath(pluginPath) {
80
+ if (!pluginPath.startsWith('src/')) {
81
+ return {
82
+ valid: false,
83
+ error: 'The path must start with "src/"'
84
+ };
85
+ }
86
+ return { valid: true };
87
+ }
88
+
66
89
  export async function envTypescript() {
67
90
  const directory = process.cwd();
68
91
  try {
package/bin/index.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import { initConfiguration } from './configuration.js';
3
+ import { ansi, terminal } from './helper.js';
4
+ import { legacyConfiguration } from './legacy.js';
5
+ import { initPrompts } from './prompts.js';
6
+
7
+ async function run() {
8
+ console.log(' _ _ _ _ _ ');
9
+ console.log(' | | (_) | (_) | ');
10
+ console.log(' | | __ _ _ __ _| | ___| |_ ');
11
+ console.log(" | | / _` | '_ \\| | |/ / | __|");
12
+ console.log(' | |___| (_| | |_) | | <| | |_ ');
13
+ console.log(' |______\\__,_| .__/|_|_|\\_\\_|\\__|');
14
+ console.log(' | | ');
15
+ console.log(' |_| \n');
16
+
17
+ terminal('none', `${ansi.bold.blue('Lapikit')} - Component Library for Svelte\n\n`);
18
+
19
+ const promptsConfig = await initPrompts();
20
+
21
+ if (promptsConfig.env === 'current') {
22
+ await legacyConfiguration(promptsConfig);
23
+ }
24
+
25
+ if (promptsConfig.env === 'experimental') {
26
+ terminal('warn', `Experimental mode is not yet implemented.`);
27
+ await initConfiguration(promptsConfig);
28
+ }
29
+ }
30
+
31
+ run()
32
+ .then(() => {
33
+ console.log('Website: https://lapikit.dev');
34
+ console.log('Github: https://github.com/nycolaide/lapikit');
35
+ console.log('Support the developement: https://buymeacoffee.com/nycolaide');
36
+ process.exit(0);
37
+ })
38
+ .catch((error) => {
39
+ console.error(`\n${red('✖')} ${error}\n`);
40
+ process.exit(1);
41
+ });
package/bin/lapikit.js CHANGED
@@ -1,9 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import { promises as fs } from 'fs';
3
3
  import path from 'path';
4
- import { ansi, terminal, envTypescript } from './helper.js';
4
+ import {
5
+ ansi,
6
+ terminal,
7
+ envTypescript,
8
+ getLapikitPathFromArgs,
9
+ validatePluginPath
10
+ } from './helper.js';
5
11
  import { preset } from './modules/preset.js';
6
12
  import { adapterCSSConfig, adapterViteConfig } from './modules/adapter.js';
13
+ import { createPluginStructure, setupSvelteKitIntegration } from './modules/plugin.js';
7
14
 
8
15
  const [, , command] = process.argv;
9
16
  const typescriptEnabled = envTypescript();
@@ -11,8 +18,9 @@ const typescriptEnabled = envTypescript();
11
18
  if (process.argv.includes('--help') || process.argv.includes('-h')) {
12
19
  terminal(
13
20
  'info',
14
- `usage: ${ansi.color.yellow('npx lapikit init {cssPath}')}\n\n ${ansi.variant.bold('options:')}\n
15
- - {cssPath}: (${ansi.color.cyan('src/app.css')}) customize path on your origin css file.\n\n`
21
+ `usage: ${ansi.color.yellow('npx lapikit init {cssPath} [--plugin-path {pluginPath}]')}\n\n ${ansi.variant.bold('options:')}\n
22
+ - {cssPath}: (${ansi.color.cyan('src/app.css')}) customize path on your origin css file.
23
+ - --plugin-path, -p: (${ansi.color.cyan('src/plugin')}) customize path for the plugin directory.\n\n`
16
24
  );
17
25
  process.exit(0);
18
26
  } else if (command === 'init') {
@@ -27,6 +35,15 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
27
35
 
28
36
  terminal('none', `${ansi.bold.blue('LAPIKIT')} - Component Library for Svelte\n\n`);
29
37
 
38
+ // Get Path
39
+ const pluginPath = getLapikitPathFromArgs();
40
+ const pathValidation = validatePluginPath(pluginPath);
41
+
42
+ if (!pathValidation.valid) {
43
+ terminal('error', `Invalid path: ${pathValidation.error}`);
44
+ process.exit(1);
45
+ }
46
+
30
47
  const configPath = path.resolve(process.cwd(), 'lapikit.config.js');
31
48
  try {
32
49
  await fs.writeFile(configPath, preset.trim() + '\n', 'utf8');
@@ -39,6 +56,20 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
39
56
  );
40
57
  }
41
58
 
59
+ // Create plugin structure
60
+ try {
61
+ await createPluginStructure(pluginPath, typescriptEnabled);
62
+ } catch (error) {
63
+ terminal('error', `Create plugin structure not working : ${error.message}`);
64
+ }
65
+
66
+ // Setup SvelteKit integration
67
+ try {
68
+ await setupSvelteKitIntegration(pluginPath, typescriptEnabled);
69
+ } catch (error) {
70
+ terminal('error', `SvelteKit integration setup failed: ${error.message}`);
71
+ }
72
+
42
73
  await adapterViteConfig(typescriptEnabled);
43
74
  await adapterCSSConfig();
44
75
 
package/bin/legacy.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { promises as fs } from 'fs';
3
+ import path from 'path';
4
+ import { preset } from './modules/preset.js';
5
+ import { ansi, terminal, envTypescript } from './helper.js';
6
+ import { adapterCSSConfig, adapterViteConfig } from './modules/adapter.js';
7
+
8
+ export async function legacyConfiguration(options) {
9
+ const typescriptEnabled = envTypescript();
10
+ const configPath = path.resolve(process.cwd(), 'lapikit.config.js');
11
+
12
+ try {
13
+ await fs.writeFile(configPath, preset.trim() + '\n', 'utf8');
14
+ terminal('success', `has create lapikit.config.js on your project.`);
15
+ } catch (error) {
16
+ terminal('error', `failed to create configuration file:\n\n ${error}`);
17
+ terminal(
18
+ 'warn',
19
+ `you can create lapikit.config.js manually, please visite https://lapikit.dev/docs/getting-started for more information`
20
+ );
21
+ }
22
+
23
+ await adapterViteConfig(typescriptEnabled);
24
+ await adapterCSSConfig(options);
25
+
26
+ terminal(
27
+ 'info',
28
+ `${ansi.bold.blue('Thank to use lapikit, discover all posibility with lapikit on https://lapikit.dev')}\n\n`
29
+ );
30
+
31
+ console.log('Website: https://lapikit.dev');
32
+ console.log('Github: https://github.com/nycolaide/lapikit');
33
+ console.log('Support the developement: https://buymeacoffee.com/nycolaide');
34
+ }
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import path from 'path';
3
- import { getCssPathFromArgs, terminal } from '../helper.js';
3
+ import { terminal } from '../helper.js';
4
4
 
5
5
  const importLapikitVite = `import { lapikit } from 'lapikit/vite';`;
6
6
  const importLapikitCss = `@import 'lapikit/css';`;
@@ -33,8 +33,8 @@ export async function adapterViteConfig(typescript) {
33
33
  }
34
34
  }
35
35
 
36
- export async function adapterCSSConfig() {
37
- const cssPath = getCssPathFromArgs();
36
+ export async function adapterCSSConfig(options) {
37
+ const cssPath = options?.pathCSS || 'src/app.css';
38
38
  const resolvedPath = path.resolve(process.cwd(), cssPath);
39
39
  try {
40
40
  await fs.access(resolvedPath);
@@ -0,0 +1,223 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import { terminal } from '../helper.js';
4
+
5
+ const lapikitTsTemplate = `import type { Config } from 'lapikit';
6
+
7
+ /**
8
+ * Custom configuration for Lapikit
9
+ * @see https://lapikit.dev/docs/customize
10
+ */
11
+ const config: Config = {
12
+ theme: {
13
+ colorScheme: 'light',
14
+ colors: {
15
+ primary: '#3b82f6',
16
+ secondary: '#6b7280'
17
+ }
18
+ }
19
+ };
20
+
21
+ export default config;
22
+ `;
23
+
24
+ const lapikitJsTemplate = `/**
25
+ * Custom configuration for Lapikit
26
+ * @see https://lapikit.dev/docs/customize
27
+ * @type {import('lapikit').Config}
28
+ */
29
+ const config = {
30
+ theme: {
31
+ colorScheme: 'light',
32
+ colors: {
33
+ primary: '#3b82f6',
34
+ secondary: '#6b7280'
35
+ }
36
+ }
37
+ };
38
+
39
+ export default config;
40
+ `;
41
+
42
+ export async function createPluginStructure(pluginPath, isTypescript) {
43
+ const resolvedPluginPath = path.resolve(process.cwd(), pluginPath);
44
+ const lapikitFileName = isTypescript ? 'lapikit.ts' : 'lapikit.js';
45
+ const lapikitFilePath = path.join(resolvedPluginPath, lapikitFileName);
46
+
47
+ try {
48
+ // Verify plugin directory
49
+ try {
50
+ await fs.access(resolvedPluginPath);
51
+ terminal('info', `The folder ${pluginPath} already exists.`);
52
+ } catch {
53
+ await fs.mkdir(resolvedPluginPath, { recursive: true });
54
+ terminal('success', `Folder ${pluginPath} created successfully.`);
55
+ }
56
+
57
+ // Create lapikit.ts or lapikit.js
58
+ const template = isTypescript ? lapikitTsTemplate : lapikitJsTemplate;
59
+ await fs.writeFile(lapikitFilePath, template.trim() + '\n', 'utf8');
60
+
61
+ terminal('success', `File ${lapikitFileName} created in ${pluginPath}.`);
62
+ } catch (error) {
63
+ terminal('error', `Error creating plugin structure: ${error.message}`);
64
+ throw error;
65
+ }
66
+ }
67
+
68
+ export async function setupSvelteKitIntegration(pluginPath, isTypescript) {
69
+ const srcRoutesPath = path.resolve(process.cwd(), 'src/routes');
70
+
71
+ try {
72
+ // Check if the src/routes directory exists
73
+ await fs.access(srcRoutesPath);
74
+ terminal('info', 'Folder src/routes found, configuring SvelteKit...');
75
+ } catch {
76
+ terminal('info', 'Folder src/routes not found, no SvelteKit configuration needed.');
77
+ return;
78
+ }
79
+
80
+ const layoutPath = path.join(srcRoutesPath, '+layout.svelte');
81
+ const pagePath = path.join(srcRoutesPath, '+page.svelte');
82
+
83
+ let targetFile = null;
84
+ let targetFileName = '';
85
+
86
+ try {
87
+ await fs.access(layoutPath);
88
+ targetFile = layoutPath;
89
+ targetFileName = '+layout.svelte';
90
+ } catch {
91
+ try {
92
+ await fs.access(pagePath);
93
+ targetFile = pagePath;
94
+ targetFileName = '+page.svelte';
95
+ } catch {
96
+ terminal('warn', 'No +layout.svelte or +page.svelte file found in src/routes.');
97
+ return;
98
+ }
99
+ }
100
+
101
+ // Read content
102
+ let fileContent = await fs.readFile(targetFile, 'utf8');
103
+
104
+ // Get Path
105
+ const relativePath = path.relative(
106
+ path.dirname(targetFile),
107
+ path.resolve(process.cwd(), pluginPath)
108
+ );
109
+ const lapikitFileName = isTypescript ? 'lapikit' : 'lapikit.js';
110
+ const configImportPath = `${relativePath}/${lapikitFileName}`.replace(/\\/g, '/');
111
+
112
+ // Imports
113
+ const createLapikitImport = `\n\timport { createLapikit } from 'lapikit';`;
114
+ const configImport = `\timport config from '${configImportPath}';`;
115
+
116
+ const scriptLang = isTypescript ? ' lang="ts"' : '';
117
+ const effectCode = `\n\t$effect.pre(() => {\n\t\tcreateLapikit(config);\n\t});`;
118
+
119
+ // search balise
120
+ const scriptRegex = /<script(\s+lang="ts")?>([\s\S]*?)<\/script>/;
121
+ const scriptMatch = fileContent.match(scriptRegex);
122
+
123
+ if (scriptMatch) {
124
+ // If have script balise , add import
125
+ let scriptContent = scriptMatch[2];
126
+
127
+ // Add imports if they don't already exist
128
+ if (!scriptContent.includes('createLapikit')) {
129
+ scriptContent = `${createLapikitImport}\n${configImport}\n${scriptContent}`;
130
+ }
131
+
132
+ // Add effect
133
+ if (!scriptContent.includes('createLapikit(config)')) {
134
+ scriptContent += effectCode;
135
+ }
136
+
137
+ // Replace script balise
138
+ const newScript = `<script${scriptMatch[1] || scriptLang}>${scriptContent}\n</script>`;
139
+ fileContent = fileContent.replace(scriptRegex, newScript);
140
+ } else {
141
+ // If no script tag exists, create one
142
+ const newScript = `<script${scriptLang}>\n${createLapikitImport}\n${configImport}${effectCode}\n</script>\n\n`;
143
+ fileContent = newScript + fileContent;
144
+ }
145
+
146
+ // Write the modified file
147
+ await fs.writeFile(targetFile, fileContent, 'utf8');
148
+ terminal('success', `Config added ${targetFileName}.`);
149
+ }
150
+
151
+ const [, , command] = process.argv;
152
+ const typescriptEnabled = envTypescript();
153
+ const args = process.argv.slice(2);
154
+ const previewMode = args.includes('--preview');
155
+
156
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
157
+ terminal(
158
+ 'info',
159
+ `usage: ${ansi.color.yellow('npx lapikit init {cssPath} [--plugin-path {pluginPath}] [--preview]')}\n\n ${ansi.variant.bold('options:')}\n
160
+ - {cssPath}: (${ansi.color.cyan('src/app.css')}) customize path on your origin css file.
161
+ - --plugin-path, -p: (${ansi.color.cyan('src/plugin')}) customize path for the plugin directory.
162
+ - --preview: active preview mode (plugin + SvelteKit integration)\n\n`
163
+ );
164
+ process.exit(0);
165
+ } else if (command === 'init') {
166
+ console.log(' _ _ _ _ _ ');
167
+ console.log(' | | (_) | (_) | ');
168
+ console.log(' | | __ _ _ __ _| | ___| |_ ');
169
+ console.log(" | | / _` | '_ \\| | |/ / | __|");
170
+ console.log(' | |___| (_| | |_) | | <| | |_ ');
171
+ console.log(' |______\\__,_| .__/|_|_|\\_\\_|\\__|');
172
+ console.log(' | | ');
173
+ console.log(' |_| \n');
174
+
175
+ terminal('none', `${ansi.bold.blue('LAPIKIT')} - Component Library for Svelte\n\n`);
176
+
177
+ if (previewMode) {
178
+ // Mode preview
179
+ const pluginPath = getLapikitPathFromArgs();
180
+ const pathValidation = validatePluginPath(pluginPath);
181
+ if (!pathValidation.valid) {
182
+ terminal('error', `Invalid path: ${pathValidation.error}`);
183
+ process.exit(1);
184
+ }
185
+ try {
186
+ await createPluginStructure(pluginPath, typescriptEnabled);
187
+ } catch (error) {
188
+ terminal('error', `Create plugin structure not working : ${error.message}`);
189
+ }
190
+ try {
191
+ await setupSvelteKitIntegration(pluginPath, typescriptEnabled);
192
+ } catch (error) {
193
+ terminal('error', `SvelteKit integration setup failed: ${error.message}`);
194
+ }
195
+ } else {
196
+ // Mode classic
197
+ const configPath = path.resolve(process.cwd(), 'lapikit.config.js');
198
+ try {
199
+ await fs.writeFile(configPath, preset.trim() + '\n', 'utf8');
200
+ terminal('success', `has create lapikit.config.js on your project.`);
201
+ } catch (error) {
202
+ terminal('error', `failed to create configuration file:\n\n ${error}`);
203
+ terminal(
204
+ 'warn',
205
+ `you can create lapikit.config.js manually, please visite https://lapikit.dev/docs/getting-started for more information`
206
+ );
207
+ }
208
+ await adapterCSSConfig();
209
+ }
210
+
211
+ await adapterViteConfig(typescriptEnabled);
212
+
213
+ terminal(
214
+ 'info',
215
+ `${ansi.bold.blue('Thank to use lapikit, discover all posibility with lapikit on https://lapikit.dev')}\n\n`
216
+ );
217
+
218
+ console.log('Website: https://lapikit.dev');
219
+ console.log('Github: https://github.com/nycolaide/lapikit');
220
+ console.log('Support the developement: https://buymeacoffee.com/nycolaide');
221
+ } else {
222
+ terminal('error', `Command not recognized. Try 'npx lapikit -h'`);
223
+ }
package/bin/presets.js ADDED
@@ -0,0 +1,15 @@
1
+ function presets() {
2
+ let content = '';
3
+
4
+ content += `/**
5
+ * Lapikit
6
+ * Library documentation: https://lapikit.dev
7
+ */\n\n`;
8
+ content += `// Styles\n`;
9
+ content += `import 'lapikit/css'\n`;
10
+ content += `// https://lapikit.dev/docs/getting-started\n`;
11
+
12
+ return content;
13
+ }
14
+
15
+ export default presets;
package/bin/prompts.js ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import prompts from 'prompts';
3
+
4
+ export async function initPrompts() {
5
+ const { confirm } = await prompts({
6
+ type: 'toggle',
7
+ name: 'confirm',
8
+ message: 'Start install Lapikit on your app?',
9
+ initial: true,
10
+ active: 'Yes',
11
+ inactive: 'No'
12
+ });
13
+
14
+ if (!confirm) {
15
+ console.log('❌ Installation canceled. See you soon.');
16
+ process.exit(0);
17
+ }
18
+ // temps with legacy and new process install
19
+ const { type } = await prompts({
20
+ type: 'select',
21
+ name: 'type',
22
+ message: 'Select installation type:',
23
+ choices: [
24
+ { title: 'Classic install with lapikit.config.js', value: 'current' },
25
+ {
26
+ title: 'Preview install with new plugin/lapikit.(js|ts) <experimental>',
27
+ value: 'experimental'
28
+ }
29
+ ]
30
+ });
31
+
32
+ if (type === 'current') {
33
+ // Classic install
34
+ const settings = await prompts([
35
+ {
36
+ type: 'text',
37
+ name: 'pathCSS',
38
+ message: 'Where would you like to import the lapikit CSS files?',
39
+ initial: 'src/app.css',
40
+ validate: (value) =>
41
+ value.startsWith('src/') ? true : 'Please provide a valid path starting with src/'
42
+ }
43
+ ]);
44
+
45
+ return {
46
+ ...settings,
47
+ env: 'current'
48
+ };
49
+ } else if (type === 'experimental') {
50
+ // Preview install
51
+ let settings = await prompts([
52
+ {
53
+ type: 'text',
54
+ name: 'pathConfig',
55
+ message: 'Where would you like to install the lapikit configuration files?',
56
+ initial: 'src/plugins',
57
+ validate: (value) =>
58
+ value.startsWith('src/') ? true : 'Please provide a valid path starting with src/'
59
+ },
60
+ {
61
+ type: 'toggle',
62
+ name: 'typescript',
63
+ message: 'Use TypeScript?',
64
+ initial: true,
65
+ active: 'Yes',
66
+ inactive: 'No'
67
+ },
68
+ {
69
+ type: 'select',
70
+ name: 'formatCSS',
71
+ message: 'What is your CSS format used on your app?',
72
+ choices: [
73
+ { title: 'Common ( CSS / SASS / SCSS / LESS / other libs )', value: 'global' },
74
+ {
75
+ title: 'TailwindCSS (v4)',
76
+ value: 'tailwind-v4'
77
+ },
78
+ {
79
+ title: 'UnoCSS',
80
+ value: 'unocss'
81
+ }
82
+ ]
83
+ },
84
+ {
85
+ type: (prev) => (prev !== 'global' ? 'text' : null),
86
+ name: 'pathCSS',
87
+ message: 'Where would you like to import the lapikit CSS files?',
88
+ initial: 'src/app.css',
89
+ validate: (value) =>
90
+ value.startsWith('src/') ? true : 'Please provide a valid path starting with src/'
91
+ }
92
+ ]);
93
+
94
+ console.log('response config', settings);
95
+
96
+ return {
97
+ ...settings,
98
+ env: 'experimental'
99
+ };
100
+ }
101
+ }
@@ -1,23 +1,24 @@
1
+ /* root */
1
2
  .kit-alert {
2
3
  --alert-color: var(--on, var(--kit-on-container));
3
4
  --alert-background: var(--base, var(--kit-container));
4
5
  --alert-radius: var(--shape, var(--kit-radius-md));
6
+ }
5
7
 
8
+ .kit-alert {
6
9
  display: grid;
7
10
  flex: 1 1;
8
11
  grid-template-areas:
9
12
  'prepend content append close'
10
13
  '. content . .';
11
- /* grid-template-columns: max-content auto max-content max-content; */ /* bug */
14
+ grid-template-columns: max-content minmax(0, 1fr) max-content max-content;
12
15
  position: relative;
13
16
  padding: 1rem;
14
17
  overflow: hidden;
15
18
  color: var(--alert-color);
16
19
  background-color: var(--alert-background);
17
20
  border-radius: var(--alert-radius);
18
- /* transition:
19
- color 0.5s,
20
- background-color 0.5s; */
21
+ line-height: 0;
21
22
  }
22
23
 
23
24
  .kit-alert .kit-alert--underlay {
@@ -53,7 +54,7 @@
53
54
  padding-top: 0.75rem;
54
55
  }
55
56
 
56
- .kit-alert .kit-alert-prepend {
57
+ .kit-alert .kit-alert--prepend {
57
58
  align-self: flex-start;
58
59
  display: flex;
59
60
  align-items: center;
@@ -61,10 +62,11 @@
61
62
  margin-inline-end: 1rem;
62
63
  }
63
64
 
64
- .kit-alert .kit-alert-content {
65
- align-self: center;
65
+ .kit-alert .kit-alert--content {
66
+ align-self: flex-start;
66
67
  grid-area: content;
67
68
  overflow: hidden;
69
+ line-height: normal;
68
70
  }
69
71
 
70
72
  .kit-alert .kit-alert--close {
@@ -74,6 +76,14 @@
74
76
  grid-area: close;
75
77
  }
76
78
 
79
+ .kit-alert .kit-alert--append {
80
+ align-self: flex-start;
81
+ display: flex;
82
+ align-items: center;
83
+ grid-area: append;
84
+ margin-inline-start: 1rem;
85
+ }
86
+
77
87
  /* state */
78
88
  .kit-alert.kit-alert--info:not([class*='alert--variant-']) {
79
89
  --on: var(--kit-on-info);
@@ -147,8 +147,8 @@
147
147
  }
148
148
 
149
149
  .kit-button[breakpoint]kit-button--variant-outline {
150
- --button-color: var(--base, var(--kit-on-container));
151
- background-color: transparent;
150
+ --button-color: var(--on, var(--kit-on-container));
151
+ background-color: var(--button-background);
152
152
  }
153
153
  .kit-button[breakpoint]kit-button--variant-outline::before {
154
154
  content: '';
@@ -36,6 +36,7 @@
36
36
  white-space: nowrap;
37
37
  gap: calc(var(--kit-spacing) * var(--chip-multiplier-gap));
38
38
  font-size: calc(var(--kit-spacing) * var(--chip-multiplier-font-size));
39
+ line-height: 0;
39
40
  }
40
41
 
41
42
  .kit-chip:not(div):not(span)::after {
@@ -115,8 +116,8 @@
115
116
  }
116
117
 
117
118
  .kit-chip[breakpoint]kit-chip--variant-outline {
118
- --chip-color: var(--base, var(--kit-oncontainer));
119
- background-color: transparent;
119
+ --chip-color: var(--on, var(--kit-on-container));
120
+ background-color: var(--chip-background);
120
121
  }
121
122
  .kit-chip[breakpoint]kit-chip--variant-outline::before {
122
123
  content: '';
@@ -19,3 +19,4 @@ export { default as Card } from './card/card.svelte';
19
19
  export { default as Toolbar } from './toolbar/toolbar.svelte';
20
20
  export { default as Appbar } from './appbar/appbar.svelte';
21
21
  export { default as Spacer } from './spacer/spacer.svelte';
22
+ export { default as Textfield } from './textfield/textfield.svelte';
@@ -20,3 +20,4 @@ export { default as Card } from './card/card.svelte';
20
20
  export { default as Toolbar } from './toolbar/toolbar.svelte';
21
21
  export { default as Appbar } from './appbar/appbar.svelte';
22
22
  export { default as Spacer } from './spacer/spacer.svelte';
23
+ export { default as Textfield } from './textfield/textfield.svelte';
@@ -10,6 +10,7 @@
10
10
  .kit-modal {
11
11
  width: 100%;
12
12
  height: 100%;
13
+ position: absolute;
13
14
  }
14
15
 
15
16
  .kit-modal-container {
@@ -0,0 +1,305 @@
1
+ /* root */
2
+ .kit-textfield {
3
+ --textfield-color: var(--on, var(--kit-on-container));
4
+ --textfield-background: var(--base, var(--kit-container));
5
+ --textfield-radius: var(--shape, var(--kit-radius-md));
6
+ }
7
+
8
+ .kit-textfield {
9
+ flex: 1 1 auto;
10
+ font-size: 1rem;
11
+ display: grid;
12
+ grid-template-areas:
13
+ 'prepend control append'
14
+ 'a messages b';
15
+ grid-template-columns: max-content minmax(0, 1fr) max-content;
16
+ grid-template-rows: 1fr auto;
17
+ }
18
+
19
+ /* variant */
20
+ .kit-textfield[breakpoint]kit-textfield--variant-filled .kit-field {
21
+ --textfield-border-color: var(--textfield-background);
22
+ background-color: var(--textfield-background);
23
+ border-radius: var(--textfield-radius);
24
+ color: var(--textfield-color);
25
+ }
26
+
27
+ .kit-textfield[breakpoint]kit-textfield--variant-outline .kit-field {
28
+ --textfield-border-color: var(--textfield-color);
29
+ background-color: var(--textfield-background);
30
+ border-radius: var(--textfield-radius);
31
+ color: var(--textfield-color);
32
+ }
33
+
34
+ .kit-textfield[breakpoint]kit-textfield--variant-filled .kit-textfield-outline,
35
+ .kit-textfield[breakpoint]kit-textfield--variant-outline .kit-textfield-outline {
36
+ border-bottom: 1px solid var(--textfield-border-color);
37
+ border-top: 1px solid var(--textfield-border-color);
38
+ border-right: 1px solid var(--textfield-border-color);
39
+ border-left: 1px solid var(--textfield-border-color);
40
+ border-radius: var(--textfield-radius);
41
+ }
42
+
43
+ .kit-textfield[breakpoint]kit-textfield--variant-text .kit-field {
44
+ --textfield-border-color: var(--textfield-color);
45
+ background-color: transparent;
46
+ border-radius: 0;
47
+ color: var(--textfield-color);
48
+ }
49
+
50
+ .kit-textfield[breakpoint]kit-textfield--variant-text .kit-textfield-outline {
51
+ border-bottom: 1px solid var(--textfield-border-color);
52
+ border-top: 0;
53
+ border-right: 0;
54
+ border-left: 0;
55
+ border-radius: 0;
56
+ }
57
+
58
+ .kit-textfield--hide-spin-buttons input[type='number'] {
59
+ -moz-appearance: textfield;
60
+ appearance: textfield;
61
+ }
62
+ .kit-textfield--hide-spin-buttons input[type='number']::-webkit-inner-spin-button,
63
+ .kit-textfield--hide-spin-buttons input[type='number']::-webkit-outer-spin-button {
64
+ display: none;
65
+ -webkit-appearance: none;
66
+ }
67
+
68
+ .kit-textfield--disabled {
69
+ opacity: 0.5;
70
+ pointer-events: none;
71
+ }
72
+
73
+ .kit-textfield--readonly {
74
+ pointer-events: none;
75
+ }
76
+
77
+ .kit-textfield--error .kit-textfield-outline {
78
+ border: 1px solid var(--kit-error);
79
+ }
80
+
81
+ .kit-textfield-outline {
82
+ align-items: stretch;
83
+ contain: layout;
84
+ display: flex;
85
+ height: 100%;
86
+ left: 0;
87
+ pointer-events: none;
88
+ position: absolute;
89
+ right: 0;
90
+ width: 100%;
91
+ }
92
+
93
+ .kit-textfield .kit-textfield-prepend {
94
+ display: flex;
95
+ grid-area: prepend;
96
+ margin-inline-end: 16px;
97
+ align-items: center;
98
+ padding-top: 0;
99
+ }
100
+
101
+ .kit-textfield .kit-textfield-append {
102
+ display: flex;
103
+ grid-area: append;
104
+ margin-inline-start: 16px;
105
+ align-items: center;
106
+ padding-top: 0;
107
+ }
108
+
109
+ /* control */
110
+ .kit-textfield-control {
111
+ display: flex;
112
+ grid-area: control;
113
+ }
114
+
115
+ .kit-textfield-control .kit-textfield-prepend-inner {
116
+ grid-area: prepend-inner;
117
+ display: flex;
118
+ align-items: center;
119
+ padding-top: 0;
120
+ }
121
+ .kit-textfield-control .kit-textfield-clearable {
122
+ cursor: pointer;
123
+ display: flex;
124
+ align-items: center;
125
+ padding-top: 0;
126
+ overflow: hidden;
127
+ margin-inline: 4px;
128
+ grid-area: clear;
129
+ opacity: 0;
130
+ }
131
+
132
+ .kit-textfield-clearable.kit-textfield-clearable--visible {
133
+ opacity: 1;
134
+ }
135
+
136
+ .kit-textfield-control .kit-textfield-append-inner {
137
+ grid-area: append-inner;
138
+ display: flex;
139
+ align-items: center;
140
+ padding-top: 0;
141
+ }
142
+
143
+ /* field prefix suffix */
144
+ .kit-field .kit-field--field .kit-field--field-prefix,
145
+ .kit-field .kit-field--field .kit-field--field-suffix {
146
+ align-items: center;
147
+ cursor: default;
148
+ display: flex;
149
+ transition: inherit;
150
+ white-space: nowrap;
151
+ }
152
+
153
+ /* field */
154
+ .kit-textfield-control .kit-field {
155
+ display: grid;
156
+ grid-template-areas: 'prepend-inner field clear append-inner';
157
+ grid-template-columns: max-content minmax(0, 1fr) max-content max-content;
158
+ font-size: calc(var(--kit-spacing) * var(--textfield-multiplier-font-size));
159
+ max-width: 100%;
160
+ contain: layout;
161
+ flex: 1 0;
162
+ grid-area: control;
163
+ position: relative;
164
+ padding: calc(var(--kit-spacing) * var(--textfield-multiplier-x))
165
+ calc(var(--kit-spacing) * var(--textfield-multiplier-y));
166
+ gap: calc(var(--kit-spacing) * var(--textfield-multiplier-gap));
167
+ }
168
+
169
+ .kit-textfield-control .kit-field .kit-field--field {
170
+ flex: 1 0;
171
+ grid-area: field;
172
+ position: relative;
173
+ align-items: flex-start;
174
+ display: flex;
175
+ }
176
+
177
+ .kit-field .kit-field--field input {
178
+ font: inherit;
179
+ border-radius: 0;
180
+ color: inherit;
181
+ flex: 1;
182
+ min-width: 0;
183
+ align-items: center;
184
+ color: inherit;
185
+ column-gap: 2px;
186
+ display: flex;
187
+ flex-wrap: wrap;
188
+ position: relative;
189
+ width: 100%;
190
+ row-gap: 8px;
191
+ }
192
+
193
+ .kit-field .kit-field--field input:focus,
194
+ .kit-field .kit-field--field input:focus-visible,
195
+ .kit-field .kit-field--field input:active {
196
+ outline: none;
197
+ box-shadow: none;
198
+ }
199
+
200
+ /* message */
201
+ .kit-textfield-message {
202
+ padding-inline: var(--textfield-spacing-y);
203
+ align-items: flex-end;
204
+ display: flex;
205
+ font-size: 0.75rem;
206
+ grid-area: messages;
207
+ min-height: 22px;
208
+ padding-top: var(--textfield-spacing-x);
209
+ overflow: hidden;
210
+ justify-content: space-between;
211
+ opacity: 0;
212
+ }
213
+
214
+ .kit-textfield-message.kit-textfield-message--visible {
215
+ opacity: 1;
216
+ }
217
+
218
+ .kit-message {
219
+ flex: 1 1 auto;
220
+ font-size: 12px;
221
+ min-height: 14px;
222
+ min-width: 1px;
223
+ position: relative;
224
+ display: grid;
225
+ gap: calc(var(--kit-spacing) * var(--textfield-multiplier-gap));
226
+ grid-template-areas: 'message-prepend message message-append ';
227
+ grid-template-columns: max-content minmax(0, 1fr) max-content;
228
+ }
229
+
230
+ .kit-message.kit-message--message-error {
231
+ color: var(--kit-error);
232
+ }
233
+
234
+ .kit-message .kit-message--message {
235
+ line-height: 12px;
236
+ word-break: break-word;
237
+ overflow-wrap: break-word;
238
+ word-wrap: break-word;
239
+ hyphens: auto;
240
+ grid-area: message;
241
+ }
242
+
243
+ .kit-message .kit-message--prepend,
244
+ .kit-message .kit-message--append {
245
+ line-height: 12px;
246
+ }
247
+
248
+ .kit-message .kit-message--prepend {
249
+ grid-area: message-prepend;
250
+ }
251
+ .kit-message .kit-message--append {
252
+ grid-area: message-append;
253
+ }
254
+
255
+ /* size */
256
+ .kit-textfield[breakpoint]kit-textfield--size-xs {
257
+ --textfield-multiplier-x: 2;
258
+ --textfield-multiplier-y: 2;
259
+ --textfield-multiplier-gap: 1;
260
+ --textfield-multiplier-font-size: 6;
261
+ }
262
+
263
+ .kit-textfield[breakpoint]kit-textfield--size-sm {
264
+ --textfield-multiplier-x: 3;
265
+ --textfield-multiplier-y: 4;
266
+ --textfield-multiplier-gap: 2;
267
+ --textfield-multiplier-font-size: 7;
268
+ }
269
+
270
+ .kit-textfield[breakpoint]kit-textfield--size-md {
271
+ --textfield-multiplier-x: 4;
272
+ --textfield-multiplier-y: 6;
273
+ --textfield-multiplier-gap: 2;
274
+ --textfield-multiplier-font-size: 8;
275
+ }
276
+
277
+ .kit-textfield[breakpoint]kit-textfield--size-lg {
278
+ --textfield-multiplier-x: 5;
279
+ --textfield-multiplier-y: 6;
280
+ --textfield-multiplier-gap: 2;
281
+ --textfield-multiplier-font-size: 9;
282
+ }
283
+
284
+ .kit-textfield[breakpoint]kit-textfield--size-xl {
285
+ --textfield-multiplier-x: 6;
286
+ --textfield-multiplier-y: 8;
287
+ --textfield-multiplier-gap: 3;
288
+ --textfield-multiplier-font-size: 10;
289
+ }
290
+
291
+ /*density */
292
+ .kit-textfield[breakpoint]kit-textfield--density-default {
293
+ --textfield-spacing-x: 0;
294
+ --textfield-spacing-y: calc(var(--kit-spacing) * var(--textfield-multiplier-y));
295
+ }
296
+
297
+ .kit-textfield[breakpoint]kit-textfield--density-compact {
298
+ --textfield-spacing-x: calc(0 - 0.5rem);
299
+ --textfield-spacing-y: calc(var(--kit-spacing) * var(--textfield-multiplier-y) - 0.5rem);
300
+ }
301
+
302
+ .kit-textfield[breakpoint]kit-textfield--density-comfortable {
303
+ --textfield-spacing-x: calc(0 + 0.5rem);
304
+ --textfield-spacing-y: calc(var(--kit-spacing) * var(--textfield-multiplier-y) + 0.5rem);
305
+ }
@@ -0,0 +1,193 @@
1
+ <script lang="ts">
2
+ import { getAssets } from '../../internal/index.js';
3
+ import type { TextfieldProps } from './types.js';
4
+
5
+ //external
6
+ import { Icon } from '../index.js';
7
+
8
+ let {
9
+ ref = $bindable(),
10
+ prepend,
11
+ append,
12
+ prependInner,
13
+ appendInner,
14
+ value = $bindable(),
15
+ type = 'text',
16
+ density = 'default',
17
+ size = 'md',
18
+ variant = 'filled',
19
+ placeholder,
20
+ light,
21
+ dark,
22
+ counter,
23
+ min,
24
+ max,
25
+ prefix,
26
+ suffix,
27
+ message,
28
+ messagePrefix,
29
+ messageSuffix,
30
+ clearable,
31
+ persistentClear,
32
+ disabled,
33
+ error,
34
+ errorMessage,
35
+ persistentMessage,
36
+ hideSpinButtons, // only type="number"
37
+ readonly,
38
+ color,
39
+ background,
40
+ rounded,
41
+ ...rest
42
+ }: TextfieldProps = $props();
43
+
44
+ const assets = getAssets();
45
+
46
+ let counterValue: number = $state(0);
47
+ let displayMessage: boolean = $state(false);
48
+ let displayClear: boolean = $state(false);
49
+
50
+ const inputClear = () => {
51
+ value = undefined;
52
+ };
53
+
54
+ const handleFocus = () => {
55
+ if (!error && !persistentMessage) displayMessage = true;
56
+ };
57
+
58
+ const handleBlur = () => {
59
+ if (!error && !persistentMessage) displayMessage = false;
60
+ };
61
+
62
+ $effect(() => {
63
+ if (persistentClear) displayClear = true;
64
+ if (persistentMessage) displayMessage = true;
65
+ else if (error) displayMessage = true;
66
+ else if (!error) displayMessage = false;
67
+ });
68
+
69
+ $effect(() => {
70
+ const valueStr = value?.toString() || '';
71
+
72
+ if (valueStr && typeof max === 'number' && max > 0 && valueStr.length > max) {
73
+ const truncated = valueStr.slice(0, max);
74
+ if (typeof value === 'number') {
75
+ const numValue = Number(truncated);
76
+ value = isNaN(numValue) ? undefined : numValue;
77
+ } else {
78
+ value = truncated;
79
+ }
80
+ }
81
+
82
+ counterValue = valueStr.length;
83
+ });
84
+
85
+ $effect(() => {
86
+ if (!persistentClear) {
87
+ if (value) displayClear = true;
88
+ else displayClear = false;
89
+ }
90
+ });
91
+ </script>
92
+
93
+ <div
94
+ bind:this={ref}
95
+ {...rest}
96
+ class={[
97
+ 'kit-textfield',
98
+ light && 'light',
99
+ dark && 'dark',
100
+ size && assets.className('textfield', 'size', size),
101
+ variant && assets.className('textfield', 'variant', variant),
102
+ density && assets.className('textfield', 'density', density),
103
+ disabled && 'kit-textfield--disabled',
104
+ readonly && 'kit-textfield--readonly',
105
+ error && 'kit-textfield--error',
106
+ type === 'number' && hideSpinButtons && 'kit-textfield--hide-spin-buttons',
107
+ rest.class
108
+ ]}
109
+ style:--base={assets.color(background)}
110
+ style:--on={assets.color(color)}
111
+ style:--shape={assets.shape(rounded)}
112
+ >
113
+ {#if prepend}
114
+ <div class="kit-textfield-prepend">
115
+ {@render prepend?.()}
116
+ </div>
117
+ {/if}
118
+ <div class="kit-textfield-control">
119
+ <div class="kit-field">
120
+ {#if prependInner}
121
+ <div class="kit-textfield-prepend-inner">
122
+ {@render prependInner?.()}
123
+ </div>
124
+ {/if}
125
+ <div class="kit-field--field">
126
+ {#if prefix}
127
+ <span class="kit-field--field-prefix">
128
+ <span class="kit-textfield--field-prefix--text">{prefix}</span>
129
+ </span>
130
+ {/if}
131
+ <input
132
+ {type}
133
+ size="1"
134
+ {placeholder}
135
+ bind:value
136
+ onfocus={handleFocus}
137
+ onblur={handleBlur}
138
+ {...max && { maxlength: max }}
139
+ {...min && { minlength: min }}
140
+ {...disabled && { disabled: true }}
141
+ {...readonly && { readonly: true }}
142
+ />
143
+ {#if suffix}
144
+ <span class="kit-field--field-suffix">
145
+ <span class="kit-textfield--field-suffix--text">{suffix}</span>
146
+ </span>
147
+ {/if}
148
+ </div>
149
+ {#if clearable}
150
+ <div
151
+ class={['kit-textfield-clearable', displayClear && 'kit-textfield-clearable--visible']}
152
+ >
153
+ <Icon icon="mgc_close_circle_fill" onclick={() => inputClear()} />
154
+ </div>
155
+ {/if}
156
+
157
+ {#if appendInner}
158
+ <div class="kit-textfield-append-inner">
159
+ {@render appendInner?.()}
160
+ </div>
161
+ {/if}
162
+
163
+ <div class="kit-textfield-outline"></div>
164
+ </div>
165
+ </div>
166
+ {#if append}
167
+ <div class="kit-textfield-append">
168
+ {@render append?.()}
169
+ </div>
170
+ {/if}
171
+
172
+ <div class={['kit-textfield-message', displayMessage && 'kit-textfield-message--visible']}>
173
+ <div class={['kit-message', error && 'kit-message--message-error']}>
174
+ {#if messagePrefix}
175
+ <div class="kit-message--prepend">{messagePrefix}</div>
176
+ {/if}
177
+ {#if message || error}
178
+ <div class="kit-message--message">
179
+ {error ? errorMessage || message : message}
180
+ </div>
181
+ {/if}
182
+ {#if counter || messageSuffix}
183
+ <div class="kit-message--append">
184
+ {#if counter}
185
+ {counterValue}{max ? `/${max}` : ''}
186
+ {:else if messageSuffix}
187
+ {messageSuffix}
188
+ {/if}
189
+ </div>
190
+ {/if}
191
+ </div>
192
+ </div>
193
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { TextfieldProps } from './types.js';
2
+ declare const Textfield: import("svelte").Component<TextfieldProps, {}, "value" | "ref">;
3
+ type Textfield = ReturnType<typeof Textfield>;
4
+ export default Textfield;
@@ -0,0 +1,37 @@
1
+ import type { Component } from '../../internal/types.js';
2
+ import type { Snippet } from 'svelte';
3
+ export interface TextfieldProps extends Component {
4
+ ref?: HTMLElement | null;
5
+ dark?: boolean;
6
+ light?: boolean;
7
+ value?: string | number;
8
+ type?: 'text' | 'email' | 'password' | 'number';
9
+ placeholder?: string;
10
+ counter?: boolean;
11
+ min?: number;
12
+ max?: number;
13
+ variant?: 'outline' | 'text' | 'filled';
14
+ density?: 'compact' | 'comfortable' | 'default';
15
+ error?: boolean;
16
+ errorMessage?: string;
17
+ disabled?: boolean;
18
+ color?: string;
19
+ background?: string;
20
+ size?: string | {
21
+ [key: string]: string;
22
+ };
23
+ readonly?: boolean;
24
+ hideSpinButtons?: boolean;
25
+ persistentMessage?: boolean;
26
+ persistentClear?: boolean;
27
+ clearable?: boolean;
28
+ message?: string;
29
+ messagePrefix?: string;
30
+ messageSuffix?: string;
31
+ append?: Snippet;
32
+ prepend?: Snippet;
33
+ prependInner?: Snippet;
34
+ appendInner?: Snippet;
35
+ prefix?: string;
36
+ suffix?: string;
37
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@
5
5
 
6
6
  display: flex;
7
7
  align-items: center;
8
- min-width: max-content;
8
+ /* min-width: max-content; */
9
9
  border-style: solid;
10
10
  /* transition:
11
11
  color 0.5s,
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.0.0-insiders.835ce98",
3
+ "version": "0.0.0-insiders.84cc107",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "homepage": "https://lapikit.dev",
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "git+https://github.com/Nycolaide/lapikit.git",
@@ -35,7 +36,7 @@
35
36
  "**/*.css"
36
37
  ],
37
38
  "bin": {
38
- "lapikit": "bin/lapikit.js"
39
+ "lapikit": "bin/index.js"
39
40
  },
40
41
  "svelte": "./dist/index.js",
41
42
  "types": "./dist/index.d.ts",
@@ -89,5 +90,8 @@
89
90
  },
90
91
  "keywords": [
91
92
  "svelte"
92
- ]
93
+ ],
94
+ "dependencies": {
95
+ "prompts": "^2.4.2"
96
+ }
93
97
  }