lapikit 0.0.0-insiders.83afa82 → 0.0.0-insiders.a2a7a4d

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.
@@ -38,3 +38,4 @@ export declare const ansi: {
38
38
  };
39
39
  };
40
40
  export type Ansi = typeof ansi;
41
+ export declare const sendConsole: (type: "info" | "error" | "warn" | "success" | undefined, msg: string) => void;
@@ -42,3 +42,14 @@ export const ansi = {
42
42
  inverse,
43
43
  underline
44
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 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
+ };
@@ -1,6 +1,6 @@
1
1
  import type { ViteDevServer } from 'vite';
2
2
  interface LapikitPlugin {
3
- extends?: 'tailwindcss';
3
+ normalize?: boolean;
4
4
  minify?: boolean;
5
5
  }
6
6
  export declare function lapikit(options?: LapikitPlugin): Promise<{
@@ -1,15 +1,17 @@
1
1
  import { ansi } from './modules/ansi.js';
2
2
  import { importer } from './modules/importer.js';
3
+ import { processCSS } from './modules/css.js';
3
4
  export async function lapikit(options = {}) {
4
5
  return {
5
6
  name: 'lapikit/vite.js',
6
7
  async configResolved() {
7
8
  console.log(ansi.bold.blue('Vite plugin loaded'), options);
8
9
  const config = await importer();
9
- console.log('config', config);
10
+ await processCSS(options.minify, options.normalize);
11
+ // console.log('config', config);
10
12
  },
11
13
  async configureServer(server) {
12
- console.log(ansi.inverse.red('Vite server configured'), server);
14
+ // console.log(ansi.inverse.red('Vite server configured'), server);
13
15
  }
14
16
  };
15
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
+ }
package/dist/styles.css CHANGED
@@ -1,80 +0,0 @@
1
- html {
2
- -webkit-text-size-adjust: 100%;
3
- tab-size: 4;
4
- line-height: 1.5;
5
- box-sizing: border-box;
6
- }
7
-
8
- body {
9
- margin: 0;
10
- }
11
-
12
- main {
13
- display: block;
14
- }
15
-
16
- button,
17
- input,
18
- optgroup,
19
- select,
20
- textarea {
21
- font: inherit;
22
- }
23
-
24
- button {
25
- overflow: visible;
26
- }
27
-
28
- button,
29
- [type='button'],
30
- [type='reset'],
31
- [type='submit'],
32
- [role='button'] {
33
- cursor: pointer;
34
- color: inherit;
35
- }
36
-
37
- button,
38
- input,
39
- select,
40
- textarea {
41
- background-color: transparent;
42
- border-style: none;
43
- }
44
-
45
- *:not(body) {
46
- outline: none;
47
- }
48
-
49
- *,
50
- ::after,
51
- ::before,
52
- ::backdrop {
53
- box-sizing: border-box;
54
- margin: 0;
55
- padding: 0;
56
- border: 0 solid;
57
- }
58
-
59
- img {
60
- border-style: none;
61
- }
62
-
63
- *,
64
- ::before,
65
- ::after {
66
- background-repeat: no-repeat;
67
- box-sizing: inherit;
68
- }
69
-
70
- ::before,
71
- ::after {
72
- text-decoration: inherit;
73
- vertical-align: inherit;
74
- }
75
-
76
- [type='search'] {
77
- -webkit-appearance: textfield;
78
- appearance: textfield;
79
- outline-offset: -2px;
80
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.0.0-insiders.83afa82",
3
+ "version": "0.0.0-insiders.a2a7a4d",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",