lapikit 0.0.0-insiders.1609831
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/LICENSE +21 -0
- package/README.md +1 -0
- package/bin/helper.js +74 -0
- package/bin/lapikit.js +54 -0
- package/bin/modules/adapter.js +52 -0
- package/bin/modules/preset.js +11 -0
- package/dist/app.d.ts +13 -0
- package/dist/app.html +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/internal/ansi.d.ts +40 -0
- package/dist/internal/ansi.js +44 -0
- package/dist/internal/colors.d.ts +1 -0
- package/dist/internal/colors.js +50 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +2 -0
- package/dist/internal/minify.d.ts +1 -0
- package/dist/internal/minify.js +10 -0
- package/dist/internal/terminal.d.ts +1 -0
- package/dist/internal/terminal.js +12 -0
- package/dist/internal/types.d.ts +44 -0
- package/dist/internal/types.js +1 -0
- package/dist/plugin/modules/config.d.ts +2 -0
- package/dist/plugin/modules/config.js +54 -0
- package/dist/plugin/modules/importer.d.ts +1 -0
- package/dist/plugin/modules/importer.js +15 -0
- package/dist/plugin/vitejs.d.ts +6 -0
- package/dist/plugin/vitejs.js +26 -0
- package/dist/preset.d.ts +2 -0
- package/dist/preset.js +80 -0
- package/dist/style/css.d.ts +2 -0
- package/dist/style/css.js +31 -0
- package/dist/style/normalize.css +123 -0
- package/dist/style/parser/color.d.ts +5 -0
- package/dist/style/parser/color.js +77 -0
- package/dist/style/parser/component.d.ts +2 -0
- package/dist/style/parser/component.js +115 -0
- package/dist/style/parser/device.d.ts +2 -0
- package/dist/style/parser/device.js +28 -0
- package/dist/style/parser/index.d.ts +4 -0
- package/dist/style/parser/index.js +4 -0
- package/dist/style/parser/variable.d.ts +2 -0
- package/dist/style/parser/variable.js +25 -0
- package/dist/styles.css +0 -0
- package/dist/utils/x11.d.ts +4 -0
- package/dist/utils/x11.js +151 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Nycolaide <https://github.com/Nycolaide>.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Lapikit
|
package/bin/helper.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const color = {
|
|
2
|
+
red: (text) => `\x1b[31m${text}\x1b[0m`,
|
|
3
|
+
green: (text) => `\x1b[32m${text}\x1b[0m`,
|
|
4
|
+
yellow: (text) => `\x1b[33m${text}\x1b[0m`,
|
|
5
|
+
blue: (text) => `\x1b[34m${text}\x1b[0m`,
|
|
6
|
+
purple: (text) => `\x1b[35m${text}\x1b[0m`,
|
|
7
|
+
cyan: (text) => `\x1b[36m${text}\x1b[0m`
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const variant = {
|
|
11
|
+
bold: (text) => `\x1b[1m${text}\x1b[0m`,
|
|
12
|
+
underline: (text) => `\x1b[4m${text}\x1b[0m`,
|
|
13
|
+
inverse: (text) => `\x1b[7m${text}\x1b[0m`
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const bold = {
|
|
17
|
+
red: (text) => `\x1b[1m\x1b[31m${text}\x1b[0m`,
|
|
18
|
+
green: (text) => `\x1b[1m\x1b[32m${text}\x1b[0m`,
|
|
19
|
+
yellow: (text) => `\x1b[1m\x1b[33m${text}\x1b[0m`,
|
|
20
|
+
blue: (text) => `\x1b[1m\x1b[34m${text}\x1b[0m`,
|
|
21
|
+
purple: (text) => `\x1b[1m\x1b[35m${text}\x1b[0m`,
|
|
22
|
+
cyan: (text) => `\x1b[1m\x1b[36m${text}\x1b[0m`
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const inverse = {
|
|
26
|
+
red: (text) => `\x1b[7m\x1b[31m${text}\x1b[0m`,
|
|
27
|
+
green: (text) => `\x1b[7m\x1b[32m${text}\x1b[0m`,
|
|
28
|
+
yellow: (text) => `\x1b[7m\x1b[33m${text}\x1b[0m`,
|
|
29
|
+
blue: (text) => `\x1b[7m\x1b[34m${text}\x1b[0m`,
|
|
30
|
+
purple: (text) => `\x1b[7m\x1b[35m${text}\x1b[0m`,
|
|
31
|
+
cyan: (text) => `\x1b[7m\x1b[36m${text}\x1b[0m`
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const underline = {
|
|
35
|
+
red: (text) => `\x1b[4m\x1b[31m${text}\x1b[0m`,
|
|
36
|
+
green: (text) => `\x1b[4m\x1b[32m${text}\x1b[0m`,
|
|
37
|
+
yellow: (text) => `\x1b[4m\x1b[33m${text}\x1b[0m`,
|
|
38
|
+
blue: (text) => `\x1b[4m\x1b[34m${text}\x1b[0m`,
|
|
39
|
+
purple: (text) => `\x1b[4m\x1b[35m${text}\x1b[0m`,
|
|
40
|
+
cyan: (text) => `\x1b[4m\x1b[36m${text}\x1b[0m`
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const ansi = {
|
|
44
|
+
color,
|
|
45
|
+
variant,
|
|
46
|
+
bold,
|
|
47
|
+
inverse,
|
|
48
|
+
underline
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const terminal = (type = 'info', msg) => {
|
|
52
|
+
const name = ansi.color.cyan('lapikit');
|
|
53
|
+
|
|
54
|
+
if (type === 'error') console.error(name, ansi.bold.red('[error]'), msg);
|
|
55
|
+
else if (type === 'warn') console.warn(name, ansi.bold.yellow('[warn]'), msg);
|
|
56
|
+
else if (type === 'success') console.warn(name, ansi.bold.green('[success]'), msg);
|
|
57
|
+
else if (type === 'none') console.log(msg);
|
|
58
|
+
else console.log(name, ansi.bold.blue('[info]'), msg);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function getCssPathFromArgs() {
|
|
62
|
+
const args = process.argv.slice(2);
|
|
63
|
+
return args[1] || 'src/app.css';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function envTypescript() {
|
|
67
|
+
const directory = process.cwd();
|
|
68
|
+
try {
|
|
69
|
+
await fs.readFile(path.resolve(directory, 'tsconfig.json'), 'utf-8');
|
|
70
|
+
return true;
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/bin/lapikit.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { ansi, terminal, envTypescript } from './helper.js';
|
|
5
|
+
import { preset } from './modules/preset.js';
|
|
6
|
+
import { adapterCSSConfig, adapterViteConfig } from './modules/adapter.js';
|
|
7
|
+
|
|
8
|
+
const [, , command] = process.argv;
|
|
9
|
+
const typescriptEnabled = envTypescript();
|
|
10
|
+
|
|
11
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
12
|
+
terminal(
|
|
13
|
+
'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`
|
|
16
|
+
);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
} else if (command === 'init') {
|
|
19
|
+
console.log(' _ _ _ _ _ ');
|
|
20
|
+
console.log(' | | (_) | (_) | ');
|
|
21
|
+
console.log(' | | __ _ _ __ _| | ___| |_ ');
|
|
22
|
+
console.log(" | | / _` | '_ \\| | |/ / | __|");
|
|
23
|
+
console.log(' | |___| (_| | |_) | | <| | |_ ');
|
|
24
|
+
console.log(' |______\\__,_| .__/|_|_|\\_\\_|\\__|');
|
|
25
|
+
console.log(' | | ');
|
|
26
|
+
console.log(' |_| \n');
|
|
27
|
+
|
|
28
|
+
terminal('none', `${ansi.bold.blue('LAPIKIT')} - Component Library for Svelte\n\n`);
|
|
29
|
+
|
|
30
|
+
const configPath = path.resolve(process.cwd(), 'lapikit.config.js');
|
|
31
|
+
try {
|
|
32
|
+
await fs.writeFile(configPath, preset.trim() + '\n', 'utf8');
|
|
33
|
+
terminal('success', `has create lapikit.config.js on your project.`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
terminal('error', `failed to create configuration file:\n\n ${error}`);
|
|
36
|
+
terminal(
|
|
37
|
+
'warn',
|
|
38
|
+
`you can create lapikit.config.js manually, please visite https://localhost:3000/docs for more information`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await adapterViteConfig(typescriptEnabled);
|
|
43
|
+
await adapterCSSConfig();
|
|
44
|
+
|
|
45
|
+
terminal(
|
|
46
|
+
'info',
|
|
47
|
+
`${ansi.bold.blue('Thank to use lapikit, discover all posibility with lapikit on https://localhost:3000/docs')}\n\n`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
console.log('Github: https://github.com/nycolaide/lapikit');
|
|
51
|
+
console.log('Support the developement: https://buymeacoffee.com/nycolaide');
|
|
52
|
+
} else {
|
|
53
|
+
terminal('error', `Command not recognized. Try 'npx lapikit -h'`);
|
|
54
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getCssPathFromArgs, terminal } from '../helper.js';
|
|
4
|
+
|
|
5
|
+
const importLapikitVite = `import { lapikit } from 'lapikit/vite';`;
|
|
6
|
+
const importLapikitCss = `@import 'lapikit/css';`;
|
|
7
|
+
|
|
8
|
+
export async function adapterViteConfig(typescript) {
|
|
9
|
+
const viteConfigPath = path.resolve(process.cwd(), `vite.config.${typescript ? 'ts' : 'js'}`);
|
|
10
|
+
try {
|
|
11
|
+
let viteConfig = await fs.readFile(viteConfigPath, 'utf8');
|
|
12
|
+
|
|
13
|
+
if (!viteConfig.includes(`${importLapikitVite}`))
|
|
14
|
+
viteConfig = `${importLapikitVite}\n` + viteConfig;
|
|
15
|
+
|
|
16
|
+
const pluginsRegex = /plugins:\s*\[([^\]]*)\]/;
|
|
17
|
+
const match = viteConfig.match(pluginsRegex);
|
|
18
|
+
|
|
19
|
+
if (match && !match[1].includes('lapikit()')) {
|
|
20
|
+
const updatedPlugins = match[1].trim() ? `${match[1].trim()}, lapikit()` : `lapikit()`;
|
|
21
|
+
|
|
22
|
+
viteConfig = viteConfig.replace(pluginsRegex, `plugins: [${updatedPlugins}]`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await fs.writeFile(viteConfigPath, viteConfig, 'utf8');
|
|
26
|
+
|
|
27
|
+
terminal('success', 'lapikit() has added on vite.config.(js|ts) successfully');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
terminal(
|
|
30
|
+
'error',
|
|
31
|
+
`lapikit() encountered a problem while editing vite.config.(js|ts):\n ${error}.\n\n`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function adapterCSSConfig() {
|
|
37
|
+
const cssPath = getCssPathFromArgs();
|
|
38
|
+
const resolvedPath = path.resolve(process.cwd(), cssPath);
|
|
39
|
+
try {
|
|
40
|
+
await fs.access(resolvedPath);
|
|
41
|
+
let appCssContent = await fs.readFile(resolvedPath, 'utf8');
|
|
42
|
+
appCssContent = `${importLapikitCss}\n\n` + appCssContent;
|
|
43
|
+
await fs.writeFile(resolvedPath, appCssContent, 'utf8');
|
|
44
|
+
|
|
45
|
+
terminal('success', `lapikit/css has added on ${cssPath}.`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
terminal(
|
|
48
|
+
'error',
|
|
49
|
+
`lapikit/css encountered a problem while editing ${cssPath}:\n ${error.message}.\n\n`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// See https://svelte.dev/docs/kit/types#app.d.ts
|
|
2
|
+
// for information about these interfaces
|
|
3
|
+
declare global {
|
|
4
|
+
namespace App {
|
|
5
|
+
// interface Error {}
|
|
6
|
+
// interface Locals {}
|
|
7
|
+
// interface PageData {}
|
|
8
|
+
// interface PageState {}
|
|
9
|
+
// interface Platform {}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {};
|
package/dist/app.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
%sveltekit.head%
|
|
8
|
+
</head>
|
|
9
|
+
<body data-sveltekit-preload-data="hover">
|
|
10
|
+
<div>%sveltekit.body%</div>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function helloWorld(): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const ansi: {
|
|
2
|
+
color: {
|
|
3
|
+
red: (text: string) => string;
|
|
4
|
+
green: (text: string) => string;
|
|
5
|
+
yellow: (text: string) => string;
|
|
6
|
+
blue: (text: string) => string;
|
|
7
|
+
purple: (text: string) => string;
|
|
8
|
+
cyan: (text: string) => string;
|
|
9
|
+
};
|
|
10
|
+
variant: {
|
|
11
|
+
bold: (text: string) => string;
|
|
12
|
+
underline: (text: string) => string;
|
|
13
|
+
inverse: (text: string) => string;
|
|
14
|
+
};
|
|
15
|
+
bold: {
|
|
16
|
+
red: (text: string) => string;
|
|
17
|
+
green: (text: string) => string;
|
|
18
|
+
yellow: (text: string) => string;
|
|
19
|
+
blue: (text: string) => string;
|
|
20
|
+
purple: (text: string) => string;
|
|
21
|
+
cyan: (text: string) => string;
|
|
22
|
+
};
|
|
23
|
+
inverse: {
|
|
24
|
+
red: (text: string) => string;
|
|
25
|
+
green: (text: string) => string;
|
|
26
|
+
yellow: (text: string) => string;
|
|
27
|
+
blue: (text: string) => string;
|
|
28
|
+
purple: (text: string) => string;
|
|
29
|
+
cyan: (text: string) => string;
|
|
30
|
+
};
|
|
31
|
+
underline: {
|
|
32
|
+
red: (text: string) => string;
|
|
33
|
+
green: (text: string) => string;
|
|
34
|
+
yellow: (text: string) => string;
|
|
35
|
+
blue: (text: string) => string;
|
|
36
|
+
purple: (text: string) => string;
|
|
37
|
+
cyan: (text: string) => string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export type Ansi = typeof ansi;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const color = {
|
|
2
|
+
red: (text) => `\x1b[31m${text}\x1b[0m`,
|
|
3
|
+
green: (text) => `\x1b[32m${text}\x1b[0m`,
|
|
4
|
+
yellow: (text) => `\x1b[33m${text}\x1b[0m`,
|
|
5
|
+
blue: (text) => `\x1b[34m${text}\x1b[0m`,
|
|
6
|
+
purple: (text) => `\x1b[35m${text}\x1b[0m`,
|
|
7
|
+
cyan: (text) => `\x1b[36m${text}\x1b[0m`
|
|
8
|
+
};
|
|
9
|
+
const variant = {
|
|
10
|
+
bold: (text) => `\x1b[1m${text}\x1b[0m`,
|
|
11
|
+
underline: (text) => `\x1b[4m${text}\x1b[0m`,
|
|
12
|
+
inverse: (text) => `\x1b[7m${text}\x1b[0m`
|
|
13
|
+
};
|
|
14
|
+
const bold = {
|
|
15
|
+
red: (text) => `\x1b[1m\x1b[31m${text}\x1b[0m`,
|
|
16
|
+
green: (text) => `\x1b[1m\x1b[32m${text}\x1b[0m`,
|
|
17
|
+
yellow: (text) => `\x1b[1m\x1b[33m${text}\x1b[0m`,
|
|
18
|
+
blue: (text) => `\x1b[1m\x1b[34m${text}\x1b[0m`,
|
|
19
|
+
purple: (text) => `\x1b[1m\x1b[35m${text}\x1b[0m`,
|
|
20
|
+
cyan: (text) => `\x1b[1m\x1b[36m${text}\x1b[0m`
|
|
21
|
+
};
|
|
22
|
+
const inverse = {
|
|
23
|
+
red: (text) => `\x1b[7m\x1b[31m${text}\x1b[0m`,
|
|
24
|
+
green: (text) => `\x1b[7m\x1b[32m${text}\x1b[0m`,
|
|
25
|
+
yellow: (text) => `\x1b[7m\x1b[33m${text}\x1b[0m`,
|
|
26
|
+
blue: (text) => `\x1b[7m\x1b[34m${text}\x1b[0m`,
|
|
27
|
+
purple: (text) => `\x1b[7m\x1b[35m${text}\x1b[0m`,
|
|
28
|
+
cyan: (text) => `\x1b[7m\x1b[36m${text}\x1b[0m`
|
|
29
|
+
};
|
|
30
|
+
const underline = {
|
|
31
|
+
red: (text) => `\x1b[4m\x1b[31m${text}\x1b[0m`,
|
|
32
|
+
green: (text) => `\x1b[4m\x1b[32m${text}\x1b[0m`,
|
|
33
|
+
yellow: (text) => `\x1b[4m\x1b[33m${text}\x1b[0m`,
|
|
34
|
+
blue: (text) => `\x1b[4m\x1b[34m${text}\x1b[0m`,
|
|
35
|
+
purple: (text) => `\x1b[4m\x1b[35m${text}\x1b[0m`,
|
|
36
|
+
cyan: (text) => `\x1b[4m\x1b[36m${text}\x1b[0m`
|
|
37
|
+
};
|
|
38
|
+
export const ansi = {
|
|
39
|
+
color,
|
|
40
|
+
variant,
|
|
41
|
+
bold,
|
|
42
|
+
inverse,
|
|
43
|
+
underline
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseColor: (input: string) => string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { x11Colors } from '../utils/x11.js';
|
|
2
|
+
export const parseColor = (input) => {
|
|
3
|
+
input = input.trim();
|
|
4
|
+
if (input.startsWith('#')) {
|
|
5
|
+
const rgb = hexToRgb(input);
|
|
6
|
+
return rgbToOklch(rgb.r, rgb.g, rgb.b);
|
|
7
|
+
}
|
|
8
|
+
if (input.startsWith('rgb')) {
|
|
9
|
+
const parts = input
|
|
10
|
+
.replace(/rgba?|\(|\)|\s+/g, '')
|
|
11
|
+
.split(',')
|
|
12
|
+
.map(Number);
|
|
13
|
+
return rgbToOklch(parts[0], parts[1], parts[2]);
|
|
14
|
+
}
|
|
15
|
+
if (input.startsWith('oklch('))
|
|
16
|
+
return input;
|
|
17
|
+
if (x11Colors[input]) {
|
|
18
|
+
const hex = x11Colors[input];
|
|
19
|
+
const rgb = hexToRgb(hex);
|
|
20
|
+
return rgbToOklch(rgb.r, rgb.g, rgb.b);
|
|
21
|
+
}
|
|
22
|
+
return input;
|
|
23
|
+
};
|
|
24
|
+
const hexToRgb = (hex) => {
|
|
25
|
+
const clean = hex.replace('#', '');
|
|
26
|
+
const bigint = parseInt(clean, 16);
|
|
27
|
+
return {
|
|
28
|
+
r: (bigint >> 16) & 255,
|
|
29
|
+
g: (bigint >> 8) & 255,
|
|
30
|
+
b: bigint & 255
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const srgbToLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
34
|
+
const rgbToOklch = (r, g, b) => {
|
|
35
|
+
r = srgbToLinear(r / 255);
|
|
36
|
+
g = srgbToLinear(g / 255);
|
|
37
|
+
b = srgbToLinear(b / 255);
|
|
38
|
+
const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
|
|
39
|
+
const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
|
|
40
|
+
const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
|
|
41
|
+
const l_ = Math.cbrt(l);
|
|
42
|
+
const m_ = Math.cbrt(m);
|
|
43
|
+
const s_ = Math.cbrt(s);
|
|
44
|
+
const L = 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_;
|
|
45
|
+
const a = 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_;
|
|
46
|
+
const b_ = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_;
|
|
47
|
+
const C = Math.sqrt(a * a + b_ * b_);
|
|
48
|
+
const h = (Math.atan2(b_, a) * 180) / Math.PI;
|
|
49
|
+
return `oklch(${(L * 100).toFixed(3)}% ${C.toFixed(4)} ${((h + 360) % 360).toFixed(2)})`;
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const minify: (css: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const terminal: (type: "info" | "error" | "warn" | "success" | undefined, msg: string) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ansi } from './ansi.js';
|
|
2
|
+
export const terminal = (type = 'info', msg) => {
|
|
3
|
+
const name = ansi.color.cyan('lapikit');
|
|
4
|
+
if (type === 'error')
|
|
5
|
+
console.error(name, ansi.bold.red('[error]'), msg);
|
|
6
|
+
else if (type === 'warn')
|
|
7
|
+
console.warn(name, ansi.bold.yellow('[warn]'), msg);
|
|
8
|
+
else if (type === 'success')
|
|
9
|
+
console.warn(name, ansi.bold.green('[success]'), msg);
|
|
10
|
+
else
|
|
11
|
+
console.log(name, ansi.bold.blue('[info]'), msg);
|
|
12
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type FontFamily = {
|
|
2
|
+
[key: string]: string | string[];
|
|
3
|
+
};
|
|
4
|
+
export type Colors = {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
light: string;
|
|
7
|
+
dark: string;
|
|
8
|
+
} | string;
|
|
9
|
+
};
|
|
10
|
+
export type Thresholds = {
|
|
11
|
+
[key: string]: number | string;
|
|
12
|
+
};
|
|
13
|
+
export type Radius = {
|
|
14
|
+
[key: string]: number | string;
|
|
15
|
+
};
|
|
16
|
+
export interface Lapikit {
|
|
17
|
+
options: {
|
|
18
|
+
normalize: boolean;
|
|
19
|
+
minify: boolean;
|
|
20
|
+
};
|
|
21
|
+
theme: {
|
|
22
|
+
colorScheme: string;
|
|
23
|
+
colors: Colors;
|
|
24
|
+
};
|
|
25
|
+
breakpoints: {
|
|
26
|
+
mobileBreakpoint: string;
|
|
27
|
+
tabletBreakpoint: string;
|
|
28
|
+
laptopBreakpoint: string;
|
|
29
|
+
thresholds: Thresholds;
|
|
30
|
+
};
|
|
31
|
+
styles: {
|
|
32
|
+
spacing: string;
|
|
33
|
+
corner: {
|
|
34
|
+
active: boolean;
|
|
35
|
+
radius: Radius;
|
|
36
|
+
};
|
|
37
|
+
font: FontFamily;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type DeepOptional<T> = {
|
|
41
|
+
[P in keyof T]?: T[P] extends (infer U)[] ? DeepOptional<U>[] : T[P] extends object ? DeepOptional<T[P]> : T[P];
|
|
42
|
+
};
|
|
43
|
+
export type LapikitConfig = DeepOptional<Lapikit>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { config } from '../../preset.js';
|
|
2
|
+
export const parseConfig = (props) => {
|
|
3
|
+
if (!props)
|
|
4
|
+
return config;
|
|
5
|
+
const newConfig = { ...config };
|
|
6
|
+
if (props?.options) {
|
|
7
|
+
if (props.options.normalize !== undefined)
|
|
8
|
+
newConfig.options.normalize = props.options.normalize;
|
|
9
|
+
if (props.options.minify !== undefined)
|
|
10
|
+
newConfig.options.minify = props.options.minify;
|
|
11
|
+
}
|
|
12
|
+
if (props?.theme) {
|
|
13
|
+
if (props.theme.colorScheme !== undefined)
|
|
14
|
+
newConfig.theme.colorScheme = props.theme.colorScheme;
|
|
15
|
+
if (props.theme.colors) {
|
|
16
|
+
newConfig.theme.colors = {
|
|
17
|
+
...newConfig.theme.colors,
|
|
18
|
+
...props.theme.colors
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (props?.breakpoints) {
|
|
23
|
+
if (props.breakpoints.mobileBreakpoint !== undefined)
|
|
24
|
+
newConfig.breakpoints.mobileBreakpoint = props.breakpoints.mobileBreakpoint;
|
|
25
|
+
if (props.breakpoints.tabletBreakpoint !== undefined)
|
|
26
|
+
newConfig.breakpoints.tabletBreakpoint = props.breakpoints.tabletBreakpoint;
|
|
27
|
+
if (props.breakpoints.laptopBreakpoint !== undefined)
|
|
28
|
+
newConfig.breakpoints.laptopBreakpoint = props.breakpoints.laptopBreakpoint;
|
|
29
|
+
if (props.breakpoints.thresholds)
|
|
30
|
+
newConfig.breakpoints.thresholds = {
|
|
31
|
+
...newConfig.breakpoints.thresholds,
|
|
32
|
+
...props.breakpoints.thresholds
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (props?.styles) {
|
|
36
|
+
if (props.styles.spacing !== undefined)
|
|
37
|
+
newConfig.styles.spacing = props.styles.spacing;
|
|
38
|
+
if (props.styles.corner !== undefined) {
|
|
39
|
+
if (props.styles.corner.active !== undefined)
|
|
40
|
+
newConfig.styles.corner.active = props.styles.corner.active;
|
|
41
|
+
if (props.styles.corner.radius)
|
|
42
|
+
newConfig.styles.corner.radius = {
|
|
43
|
+
...newConfig.styles.corner.radius,
|
|
44
|
+
...props.styles.corner.radius
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (props.styles.font)
|
|
48
|
+
newConfig.styles.font = {
|
|
49
|
+
...newConfig.styles.font,
|
|
50
|
+
...props.styles.font
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return newConfig;
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const importer: () => Promise<any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { terminal, ansi } from '../../internal/index.js';
|
|
4
|
+
const app = process.cwd();
|
|
5
|
+
const pathConfig = path.resolve(app, 'lapikit.config.js');
|
|
6
|
+
export const importer = async () => {
|
|
7
|
+
if (!fs.existsSync(pathConfig)) {
|
|
8
|
+
terminal('error', `config file not found\n ${ansi.color.yellow('Could not find lapikit.config.js. See https://localhost/docs/kit/vite to learn more about the configuration file.')}\n\n${ansi.color.blue('for initializing a new lapikit config, run:')}\n ${ansi.variant.bold('npx lapikit init')} ${ansi.bold.yellow('(preview)')}\n\n`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
const timestamp = Date.now();
|
|
12
|
+
const fileUrl = `file://${pathConfig}?t=${timestamp}`;
|
|
13
|
+
const content = await import(fileUrl);
|
|
14
|
+
return content.default;
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { importer } from './modules/importer.js';
|
|
2
|
+
import { processCSS } from '../style/css.js';
|
|
3
|
+
import { parseConfig } from './modules/config.js';
|
|
4
|
+
import { terminal } from '../internal/terminal.js';
|
|
5
|
+
export async function lapikit() {
|
|
6
|
+
return {
|
|
7
|
+
name: 'lapikit/vite.js',
|
|
8
|
+
async configResolved() {
|
|
9
|
+
const config = await importer();
|
|
10
|
+
const result = await parseConfig(config);
|
|
11
|
+
await processCSS(result);
|
|
12
|
+
terminal('info', 'lapikit is up!');
|
|
13
|
+
},
|
|
14
|
+
async configureServer(server) {
|
|
15
|
+
server.watcher.add('./lapikit.config.js');
|
|
16
|
+
server.watcher.on('change', async (filePath) => {
|
|
17
|
+
if (String(filePath).includes('lapikit.config.js')) {
|
|
18
|
+
const config = await importer();
|
|
19
|
+
const result = await parseConfig(config);
|
|
20
|
+
await processCSS(result);
|
|
21
|
+
terminal('info', 'lapikit config reloaded');
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/preset.d.ts
ADDED