lapikit 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Reexport your entry components here
2
2
  export function helloWorld() {
3
- console.log('Hello world!');
3
+ console.log('Hello world, this is lapikit!');
4
4
  }
@@ -0,0 +1,41 @@
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;
41
+ export declare const sendConsole: (type: "info" | "error" | "warn" | "success" | undefined, msg: string) => void;
@@ -0,0 +1,55 @@
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
+ };
45
+ export const sendConsole = (type = 'info', msg) => {
46
+ const name = ansi.color.cyan('lapikit');
47
+ if (type === 'error')
48
+ console.error(name, ansi.bold.red('[error]'), msg);
49
+ else if (type === 'warn')
50
+ console.warn(name, ansi.bold.yellow('[warn]'), msg);
51
+ else if (type === 'success')
52
+ console.warn(name, ansi.bold.green('[success]'), msg);
53
+ else
54
+ console.log(name, ansi.bold.blue('[info]'), msg);
55
+ };
@@ -0,0 +1 @@
1
+ export declare const processCSS: (minified?: boolean, normalize?: boolean) => Promise<void>;
@@ -0,0 +1,137 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { dirname } from 'path';
3
+ import fs from 'fs';
4
+ import fsPromises from 'fs/promises';
5
+ import path from 'path';
6
+ import { ansi, sendConsole } from './ansi.js';
7
+ import { minify } from './minify.js';
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ const __components = path.resolve('src/components');
11
+ // temps
12
+ const breakpoints = {
13
+ _default: 0,
14
+ desktop: 1024,
15
+ tablet: '768vw',
16
+ mobile: 480
17
+ };
18
+ export const processCSS = async (minified, normalize) => {
19
+ console.log(ansi.bold.blue('Processing CSS...'));
20
+ const _normalize = fs.readFileSync(path.resolve(__dirname, '../../styles/normalize.css'), 'utf-8');
21
+ const _variables = fs.readFileSync(path.resolve(__dirname, '../../styles/variables.css'), 'utf-8');
22
+ let styles = `${_variables}\n`;
23
+ if (normalize)
24
+ styles += `${_normalize}\n`;
25
+ if (fs.existsSync(__components) && fs.statSync(__components).isDirectory()) {
26
+ const tresholds = {
27
+ _default: '',
28
+ static: '',
29
+ min: '',
30
+ max: '',
31
+ all: ''
32
+ };
33
+ function loadComponentCSS(directory) {
34
+ fs.readdirSync(directory).forEach((File) => {
35
+ const absolutePath = path.join(directory, File);
36
+ if (fs.statSync(absolutePath).isDirectory())
37
+ return loadComponentCSS(absolutePath);
38
+ else if (absolutePath.endsWith('.css') && !absolutePath.includes('/_')) {
39
+ const content = parser(fs.readFileSync(absolutePath, 'utf-8'));
40
+ tresholds._default += content.allExtracted
41
+ .replaceAll('[breakpoint|min]', '[breakpoint]')
42
+ .replaceAll('[breakpoint|max]', '[breakpoint]')
43
+ .replaceAll('[breakpoint|all]', '[breakpoint]');
44
+ tresholds.static += content.defaultExtracted;
45
+ tresholds.min += content.minExtracted.replaceAll('[breakpoint|min]', '[breakpoint]');
46
+ tresholds.max += content.maxExtracted.replaceAll('[breakpoint|max]', '[breakpoint]');
47
+ tresholds.all += content.allModifierExtracted.replaceAll('[breakpoint|all]', '[breakpoint]');
48
+ return (styles += `${content.cleaned}\n`);
49
+ }
50
+ });
51
+ }
52
+ loadComponentCSS(path.resolve(__dirname, '../../components'));
53
+ for (const property in breakpoints) {
54
+ if (property !== '_default') {
55
+ const name = `.${/^\d/.test(property) ? `\\3${property}` : property}\\:`;
56
+ const value = typeof breakpoints[property] === 'number'
57
+ ? `${breakpoints[property]}px`
58
+ : breakpoints[property];
59
+ if (tresholds.static !== '' || tresholds.all !== '' || tresholds.min !== '') {
60
+ styles += `@media screen and (min-width: ${value}) {\n`;
61
+ if (tresholds.static !== '')
62
+ styles += tresholds.static.replaceAll('[breakpoint]', name);
63
+ if (tresholds.all !== '')
64
+ styles += tresholds.all.replaceAll('[breakpoint]', name);
65
+ if (tresholds.min !== '')
66
+ styles += tresholds.min.replaceAll('[breakpoint]', name);
67
+ styles += `}\n`;
68
+ }
69
+ if (tresholds.max !== '' || tresholds.all !== '') {
70
+ styles += `@media screen and (max-width: ${value}) {\n`;
71
+ if (tresholds.max !== '')
72
+ styles += tresholds.max.replaceAll('[breakpoint]', name);
73
+ if (tresholds.all !== '')
74
+ styles += tresholds.all.replaceAll('[breakpoint]', name);
75
+ styles += `}\n`;
76
+ }
77
+ }
78
+ else {
79
+ styles += tresholds._default.replaceAll('[breakpoint]', '.');
80
+ }
81
+ }
82
+ }
83
+ if (minified) {
84
+ styles = minify(styles);
85
+ sendConsole('success', 'css minified');
86
+ }
87
+ fsPromises.writeFile(path.resolve(__dirname, '../../styles.css'), styles);
88
+ };
89
+ const parser = (css) => {
90
+ const regex = /([^{]+)\{([^}]+)\}/g;
91
+ let match;
92
+ const matchesToRemove = [];
93
+ const extractedByType = {
94
+ allExtracted: [],
95
+ defaultExtracted: [],
96
+ minExtracted: [],
97
+ maxExtracted: [],
98
+ allModifierExtracted: []
99
+ };
100
+ while ((match = regex.exec(css)) !== null) {
101
+ const fullMatch = match[0];
102
+ const selectors = match[1].trim();
103
+ const body = match[2].trim();
104
+ const selectorsArray = selectors.split(',').map((sel) => sel.trim());
105
+ let matchedType = null;
106
+ if (selectorsArray.some((sel) => sel.includes('[breakpoint|min]'))) {
107
+ matchedType = 'minExtracted';
108
+ }
109
+ else if (selectorsArray.some((sel) => sel.includes('[breakpoint|max]'))) {
110
+ matchedType = 'maxExtracted';
111
+ }
112
+ else if (selectorsArray.some((sel) => sel.includes('[breakpoint|all]'))) {
113
+ matchedType = 'allModifierExtracted';
114
+ }
115
+ else if (selectorsArray.some((sel) => sel.includes('[breakpoint]'))) {
116
+ matchedType = 'defaultExtracted';
117
+ }
118
+ if (matchedType) {
119
+ const rule = `${selectors} {\n${body}\n}`;
120
+ extractedByType.allExtracted.push(rule);
121
+ extractedByType[matchedType].push(rule);
122
+ matchesToRemove.push(fullMatch);
123
+ }
124
+ }
125
+ let cleaned = css;
126
+ for (const rule of matchesToRemove) {
127
+ cleaned = cleaned.replace(rule, '').replace(/\n{2,}/g, '\n\n');
128
+ }
129
+ return {
130
+ allExtracted: extractedByType.allExtracted.join('\n\n').trim(),
131
+ defaultExtracted: extractedByType.defaultExtracted.join('\n\n').trim(),
132
+ minExtracted: extractedByType.minExtracted.join('\n\n').trim(),
133
+ maxExtracted: extractedByType.maxExtracted.join('\n\n').trim(),
134
+ allModifierExtracted: extractedByType.allModifierExtracted.join('\n\n').trim(),
135
+ cleaned: cleaned.trim()
136
+ };
137
+ };
@@ -0,0 +1 @@
1
+ export declare const importer: () => Promise<any>;
@@ -0,0 +1,13 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { ansi } from './ansi.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
+ console.error(ansi.color.cyan('lapikit'), ansi.bold.red('[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 content = await import(pathConfig);
12
+ return content.default;
13
+ };
@@ -0,0 +1 @@
1
+ export declare const minify: (css: string) => string;
@@ -0,0 +1,10 @@
1
+ export const minify = (css) => {
2
+ const minified = css
3
+ .replace(/\s+/g, ' ')
4
+ .replace(/\/\*.*?\*\//g, '')
5
+ .replace(/;\s*}/g, '}')
6
+ .replace(/:\s+/g, ':')
7
+ .replace(/\s*([{};:])\s*/g, '$1')
8
+ .trim();
9
+ return minified;
10
+ };
@@ -0,0 +1,11 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ interface LapikitPlugin {
3
+ normalize?: boolean;
4
+ minify?: boolean;
5
+ }
6
+ export declare function lapikit(options?: LapikitPlugin): Promise<{
7
+ name: string;
8
+ configResolved(): Promise<void>;
9
+ configureServer(server: ViteDevServer): Promise<void>;
10
+ }>;
11
+ export {};
@@ -0,0 +1,17 @@
1
+ import { ansi } from './modules/ansi.js';
2
+ import { importer } from './modules/importer.js';
3
+ import { processCSS } from './modules/css.js';
4
+ export async function lapikit(options = {}) {
5
+ return {
6
+ name: 'lapikit/vite.js',
7
+ async configResolved() {
8
+ console.log(ansi.bold.blue('Vite plugin loaded'), options);
9
+ const config = await importer();
10
+ await processCSS(options.minify, options.normalize);
11
+ // console.log('config', config);
12
+ },
13
+ async configureServer(server) {
14
+ // console.log(ansi.inverse.red('Vite server configured'), server);
15
+ }
16
+ };
17
+ }
@@ -0,0 +1,123 @@
1
+ html {
2
+ -webkit-text-size-adjust: 100%;
3
+ tab-size: 4;
4
+ line-height: 1.5;
5
+ box-sizing: border-box;
6
+ font-family: var(--font-sans, var(--kit-font-family-sans));
7
+ }
8
+
9
+ pre,
10
+ code {
11
+ font-family: var(--font-mono, var(--kit-font-family-mono));
12
+ }
13
+
14
+ body {
15
+ margin: 0;
16
+ }
17
+
18
+ main {
19
+ display: block;
20
+ }
21
+
22
+ button,
23
+ input,
24
+ optgroup,
25
+ select,
26
+ textarea {
27
+ font: inherit;
28
+ }
29
+
30
+ button {
31
+ overflow: visible;
32
+ }
33
+
34
+ button,
35
+ [type='button'],
36
+ [type='reset'],
37
+ [type='submit'],
38
+ [role='button'] {
39
+ cursor: pointer;
40
+ color: inherit;
41
+ }
42
+
43
+ *:not(body) {
44
+ outline: none;
45
+ }
46
+
47
+ *,
48
+ ::after,
49
+ ::before,
50
+ ::backdrop {
51
+ box-sizing: border-box;
52
+ margin: 0;
53
+ padding: 0;
54
+ border: 0 solid;
55
+ }
56
+
57
+ *,
58
+ ::before,
59
+ ::after {
60
+ background-repeat: no-repeat;
61
+ box-sizing: inherit;
62
+ }
63
+
64
+ ::before,
65
+ ::after {
66
+ text-decoration: inherit;
67
+ vertical-align: inherit;
68
+ }
69
+
70
+ [type='search'] {
71
+ -webkit-appearance: textfield;
72
+ appearance: textfield;
73
+ outline-offset: -2px;
74
+ }
75
+
76
+ ol,
77
+ ul,
78
+ menu {
79
+ list-style: initial;
80
+ margin-left: calc(var(--kit-spacing) * 5);
81
+ }
82
+
83
+ ol ul,
84
+ ol ol,
85
+ ul ul,
86
+ ul ol {
87
+ padding-left: 1rem;
88
+ }
89
+
90
+ code {
91
+ border-radius: 0.25rem;
92
+ padding-block: 0.125rem;
93
+ padding-inline: 0.375rem;
94
+ position: relative;
95
+ }
96
+
97
+ sub,
98
+ sup {
99
+ font-size: 75%;
100
+ line-height: 0;
101
+ position: relative;
102
+ vertical-align: baseline;
103
+ }
104
+
105
+ sup {
106
+ top: -0.5em;
107
+ }
108
+
109
+ sub {
110
+ bottom: -0.25em;
111
+ }
112
+
113
+ img {
114
+ border-style: none;
115
+ }
116
+
117
+ button,
118
+ input,
119
+ select,
120
+ textarea {
121
+ background-color: transparent;
122
+ border-style: none;
123
+ }
@@ -0,0 +1,7 @@
1
+ :root {
2
+ --kit-font-family-sans:
3
+ system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
4
+ sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
5
+ --kit-font-family-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
6
+ --kit-spacing: 0.25rem;
7
+ }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",
@@ -32,7 +32,11 @@
32
32
  ".": {
33
33
  "types": "./dist/index.d.ts",
34
34
  "svelte": "./dist/index.js"
35
- }
35
+ },
36
+ "./vite": {
37
+ "default": "./dist/server/vite.js"
38
+ },
39
+ "./css": "./dist/styles.css"
36
40
  },
37
41
  "peerDependencies": {
38
42
  "svelte": "^5.0.0"