lapikit 0.5.0 → 0.5.2
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/bin/{helper.js → helpers.js} +41 -0
- package/bin/hooks.js +68 -0
- package/bin/index.js +30 -6
- package/dist/components/accordion/accordion.svelte +6 -19
- package/dist/components/accordion/accordion.types.d.ts +0 -4
- package/dist/components/accordion/modules/accordion-item.svelte +8 -24
- package/dist/components/alert/alert.svelte +3 -10
- package/dist/components/app/app.svelte +4 -51
- package/dist/components/appbar/appbar.svelte +12 -27
- package/dist/components/appbar/appbar.types.d.ts +1 -3
- package/dist/components/avatar/avatar.svelte +22 -12
- package/dist/components/btn/btn.svelte +71 -89
- package/dist/components/card/card.svelte +31 -44
- package/dist/components/chip/chip.svelte +57 -66
- package/dist/components/dropdown/dropdown.svelte +8 -23
- package/dist/components/dropdown/dropdown.types.d.ts +0 -2
- package/dist/components/list/list.svelte +44 -24
- package/dist/components/list/modules/list-item.svelte +10 -10
- package/dist/components/popover/popover.svelte +8 -23
- package/dist/components/popover/popover.types.d.ts +0 -2
- package/dist/components/separator/separator.svelte +0 -12
- package/dist/components/separator/separator.types.d.ts +0 -2
- package/dist/components/textfield/textfield.svelte +10 -25
- package/dist/components/textfield/textfield.types.d.ts +0 -2
- package/dist/components/toolbar/toolbar.svelte +12 -27
- package/dist/components/toolbar/toolbar.types.d.ts +0 -2
- package/dist/components/tooltip/tooltip.svelte +12 -27
- package/dist/components/tooltip/tooltip.types.d.ts +0 -2
- package/package.json +2 -5
- package/bin/configuration.js +0 -303
- package/bin/presets.js +0 -26
- package/bin/prompts.js +0 -67
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
size = 'md',
|
|
17
17
|
variant = 'filled',
|
|
18
18
|
placeholder,
|
|
19
|
-
light = false,
|
|
20
|
-
dark = false,
|
|
21
19
|
counter = false,
|
|
22
20
|
min,
|
|
23
21
|
max,
|
|
@@ -88,8 +86,8 @@
|
|
|
88
86
|
let mergedStyle = $derived(
|
|
89
87
|
[
|
|
90
88
|
componentStyle,
|
|
91
|
-
background ? `--kit-textfield-
|
|
92
|
-
color ? `--kit-textfield-
|
|
89
|
+
background ? `--kit-textfield-bg:${background}` : '',
|
|
90
|
+
color ? `--kit-textfield-fg:${color}` : '',
|
|
93
91
|
typeof rounded === 'string' && rounded.includes('px')
|
|
94
92
|
? `--kit-textfield-radius:${rounded}`
|
|
95
93
|
: ''
|
|
@@ -153,8 +151,6 @@
|
|
|
153
151
|
data-size={safeSize}
|
|
154
152
|
data-variant={safeVariant}
|
|
155
153
|
data-density={safeDensity}
|
|
156
|
-
data-light={light || undefined}
|
|
157
|
-
data-dark={dark || undefined}
|
|
158
154
|
data-disabled={disabled}
|
|
159
155
|
data-readonly={readonly}
|
|
160
156
|
data-error={error}
|
|
@@ -288,9 +284,9 @@
|
|
|
288
284
|
}
|
|
289
285
|
|
|
290
286
|
.kit-textfield {
|
|
291
|
-
--kit-textfield-
|
|
292
|
-
--kit-textfield-
|
|
293
|
-
--kit-textfield-
|
|
287
|
+
--kit-textfield-bg: var(--kit-surface-2);
|
|
288
|
+
--kit-textfield-fg: var(--kit-fg);
|
|
289
|
+
--kit-textfield-bd: color-mix(in oklab, var(--kit-textfield-fg), transparent 84%);
|
|
294
290
|
--kit-textfield-radius: 8px;
|
|
295
291
|
--kit-textfield-font-size: 14px;
|
|
296
292
|
--kit-textfield-gap-base: 8px;
|
|
@@ -372,11 +368,11 @@
|
|
|
372
368
|
}
|
|
373
369
|
|
|
374
370
|
.kit-textfield[data-variant='filled'] .kit-textfield__field {
|
|
375
|
-
background: var(--kit-textfield-
|
|
371
|
+
background: var(--kit-textfield-bg);
|
|
376
372
|
}
|
|
377
373
|
|
|
378
374
|
.kit-textfield[data-variant='outline'] .kit-textfield__field {
|
|
379
|
-
background: color-mix(in oklab, var(--kit-textfield-
|
|
375
|
+
background: color-mix(in oklab, var(--kit-textfield-bg), transparent 90%);
|
|
380
376
|
}
|
|
381
377
|
|
|
382
378
|
.kit-textfield[data-variant='text'] .kit-textfield__field {
|
|
@@ -384,17 +380,6 @@
|
|
|
384
380
|
border-radius: 0;
|
|
385
381
|
}
|
|
386
382
|
|
|
387
|
-
.kit-textfield[data-light='true'] {
|
|
388
|
-
--kit-textfield-background: color-mix(in oklab, white 88%, var(--kit-surface-1));
|
|
389
|
-
--kit-textfield-color: var(--kit-fg);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
.kit-textfield[data-dark='true'] {
|
|
393
|
-
--kit-textfield-background: color-mix(in oklab, black 72%, var(--kit-surface-3));
|
|
394
|
-
--kit-textfield-color: white;
|
|
395
|
-
--kit-textfield-border: color-mix(in oklab, white, transparent 74%);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
383
|
.kit-textfield[data-disabled='true'] {
|
|
399
384
|
opacity: var(--kit-disabled-opacity, 0.55);
|
|
400
385
|
pointer-events: none;
|
|
@@ -469,7 +454,7 @@
|
|
|
469
454
|
min-width: 0;
|
|
470
455
|
padding: var(--kit-textfield-py) var(--kit-textfield-px);
|
|
471
456
|
border-radius: var(--kit-textfield-radius);
|
|
472
|
-
color: var(--kit-textfield-
|
|
457
|
+
color: var(--kit-textfield-fg);
|
|
473
458
|
}
|
|
474
459
|
|
|
475
460
|
.kit-textfield__prepend-inner,
|
|
@@ -532,7 +517,7 @@
|
|
|
532
517
|
}
|
|
533
518
|
|
|
534
519
|
.kit-textfield .outline {
|
|
535
|
-
--outline-color: var(--kit-textfield-
|
|
520
|
+
--outline-color: var(--kit-textfield-bd);
|
|
536
521
|
top: 0;
|
|
537
522
|
bottom: 0;
|
|
538
523
|
}
|
|
@@ -540,7 +525,7 @@
|
|
|
540
525
|
.kit-textfield .line {
|
|
541
526
|
bottom: 0;
|
|
542
527
|
height: 1px;
|
|
543
|
-
background: var(--kit-textfield-
|
|
528
|
+
background: var(--kit-textfield-bd);
|
|
544
529
|
}
|
|
545
530
|
|
|
546
531
|
.kit-textfield[data-error='true'] .outline {
|
|
@@ -3,8 +3,6 @@ import type { Snippet } from 'svelte';
|
|
|
3
3
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
4
4
|
export interface TextfieldProps extends Component {
|
|
5
5
|
ref?: HTMLElement | null;
|
|
6
|
-
dark?: boolean;
|
|
7
|
-
light?: boolean;
|
|
8
6
|
value?: string | number;
|
|
9
7
|
type?: 'text' | 'email' | 'password' | 'number';
|
|
10
8
|
placeholder?: string;
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
's-class': sClass,
|
|
13
13
|
's-style': sStyle,
|
|
14
14
|
classContent,
|
|
15
|
-
light = false,
|
|
16
|
-
dark = false,
|
|
17
15
|
variant = 'text',
|
|
18
16
|
rounded,
|
|
19
17
|
background,
|
|
@@ -85,8 +83,8 @@
|
|
|
85
83
|
let mergedStyle = $derived(
|
|
86
84
|
[
|
|
87
85
|
componentStyle,
|
|
88
|
-
background ? `--kit-toolbar-
|
|
89
|
-
color ? `--kit-toolbar-
|
|
86
|
+
background ? `--kit-toolbar-bg:${background}` : '',
|
|
87
|
+
color ? `--kit-toolbar-fg:${color}` : '',
|
|
90
88
|
typeof rounded === 'string' && rounded.includes('px') ? `--kit-toolbar-radius:${rounded}` : ''
|
|
91
89
|
]
|
|
92
90
|
.filter(Boolean)
|
|
@@ -105,8 +103,6 @@
|
|
|
105
103
|
data-density={safeDensity}
|
|
106
104
|
data-orientation={safeOrientation}
|
|
107
105
|
data-location={safeLocation}
|
|
108
|
-
data-light={light || undefined}
|
|
109
|
-
data-dark={dark || undefined}
|
|
110
106
|
data-rounded={rounded}
|
|
111
107
|
>
|
|
112
108
|
{#if safeVariant === 'outline'}
|
|
@@ -120,9 +116,9 @@
|
|
|
120
116
|
|
|
121
117
|
<style>
|
|
122
118
|
.kit-toolbar {
|
|
123
|
-
--kit-toolbar-
|
|
124
|
-
--kit-toolbar-
|
|
125
|
-
--kit-toolbar-
|
|
119
|
+
--kit-toolbar-bg: var(--kit-surface-2);
|
|
120
|
+
--kit-toolbar-fg: var(--kit-fg);
|
|
121
|
+
--kit-toolbar-bd: color-mix(in oklab, var(--kit-toolbar-fg), transparent 82%);
|
|
126
122
|
--kit-toolbar-radius: 1rem;
|
|
127
123
|
--kit-toolbar-gap: 0.5rem;
|
|
128
124
|
--kit-toolbar-padding-x: 0.75rem;
|
|
@@ -134,9 +130,9 @@
|
|
|
134
130
|
max-width: 100%;
|
|
135
131
|
box-sizing: border-box;
|
|
136
132
|
border-radius: var(--kit-toolbar-radius);
|
|
137
|
-
background: var(--kit-toolbar-
|
|
138
|
-
color: var(--kit-toolbar-
|
|
139
|
-
border: 1px solid var(--kit-toolbar-
|
|
133
|
+
background: var(--kit-toolbar-bg);
|
|
134
|
+
color: var(--kit-toolbar-fg);
|
|
135
|
+
border: 1px solid var(--kit-toolbar-bg);
|
|
140
136
|
}
|
|
141
137
|
|
|
142
138
|
.kit-toolbar[data-density='compact'] {
|
|
@@ -158,31 +154,20 @@
|
|
|
158
154
|
}
|
|
159
155
|
|
|
160
156
|
.kit-toolbar[data-variant='dash'] {
|
|
161
|
-
border: 1px dashed var(--kit-toolbar-
|
|
157
|
+
border: 1px dashed var(--kit-toolbar-bd);
|
|
162
158
|
}
|
|
163
159
|
|
|
164
160
|
.kit-toolbar[data-variant='text'],
|
|
165
161
|
.kit-toolbar[data-variant='outline'],
|
|
166
162
|
.kit-toolbar[data-variant='dash'] {
|
|
167
|
-
--kit-toolbar-
|
|
168
|
-
--kit-toolbar-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
.kit-toolbar[data-light='true'] {
|
|
172
|
-
--kit-toolbar-background: color-mix(in oklab, white 88%, var(--kit-surface-1));
|
|
173
|
-
--kit-toolbar-color: var(--kit-fg);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.kit-toolbar[data-dark='true'] {
|
|
177
|
-
--kit-toolbar-background: color-mix(in oklab, black 72%, var(--kit-surface-3));
|
|
178
|
-
--kit-toolbar-color: white;
|
|
179
|
-
--kit-toolbar-border: color-mix(in oklab, white, transparent 72%);
|
|
163
|
+
--kit-toolbar-bg: transparent;
|
|
164
|
+
--kit-toolbar-fg: var(--kit-accent);
|
|
180
165
|
}
|
|
181
166
|
|
|
182
167
|
.kit-toolbar .outline {
|
|
183
168
|
position: absolute;
|
|
184
169
|
inset: 0;
|
|
185
|
-
border: 1px solid var(--kit-toolbar-
|
|
170
|
+
border: 1px solid var(--kit-toolbar-bd);
|
|
186
171
|
border-radius: inherit;
|
|
187
172
|
pointer-events: none;
|
|
188
173
|
}
|
|
@@ -9,8 +9,6 @@ export interface ToolbarProps extends Component {
|
|
|
9
9
|
variant?: Variant | Record<string, Variant>;
|
|
10
10
|
rounded?: RoundedType | string;
|
|
11
11
|
density?: Density | Record<string, Density>;
|
|
12
|
-
dark?: boolean;
|
|
13
|
-
light?: boolean;
|
|
14
12
|
color?: string;
|
|
15
13
|
orientation?: Orientation | Record<string, Orientation>;
|
|
16
14
|
background?: string;
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
open = $bindable(false),
|
|
13
13
|
forceMount = false,
|
|
14
14
|
label,
|
|
15
|
-
dark = false,
|
|
16
|
-
light = false,
|
|
17
15
|
rounded,
|
|
18
16
|
color,
|
|
19
17
|
background,
|
|
@@ -73,8 +71,8 @@
|
|
|
73
71
|
let mergedStyle = $derived(
|
|
74
72
|
[
|
|
75
73
|
componentStyle,
|
|
76
|
-
background ? `--kit-tooltip-
|
|
77
|
-
color ? `--kit-tooltip-
|
|
74
|
+
background ? `--kit-tooltip-bg:${background}` : '',
|
|
75
|
+
color ? `--kit-tooltip-fg:${color}` : '',
|
|
78
76
|
typeof rounded === 'string' && rounded.includes('px') ? `--kit-tooltip-radius:${rounded}` : ''
|
|
79
77
|
]
|
|
80
78
|
.filter(Boolean)
|
|
@@ -204,8 +202,6 @@
|
|
|
204
202
|
data-density={safeDensity}
|
|
205
203
|
data-location={axis.location ?? safeLocation}
|
|
206
204
|
data-variant={safeVariant}
|
|
207
|
-
data-light={light || undefined}
|
|
208
|
-
data-dark={dark || undefined}
|
|
209
205
|
data-rounded={rounded}
|
|
210
206
|
{...restProps}
|
|
211
207
|
>
|
|
@@ -241,10 +237,10 @@
|
|
|
241
237
|
}
|
|
242
238
|
|
|
243
239
|
.kit-tooltip__content {
|
|
244
|
-
--kit-tooltip-
|
|
245
|
-
--kit-tooltip-
|
|
240
|
+
--kit-tooltip-bg: var(--kit-surface-3);
|
|
241
|
+
--kit-tooltip-fg: var(--kit-fg);
|
|
246
242
|
--kit-tooltip-radius: 8px;
|
|
247
|
-
--kit-tooltip-
|
|
243
|
+
--kit-tooltip-bd: color-mix(in oklab, var(--kit-tooltip-bg), black 8%);
|
|
248
244
|
--kit-tooltip-py: 0.15rem;
|
|
249
245
|
--kit-tooltip-px: 0.625rem;
|
|
250
246
|
|
|
@@ -253,10 +249,10 @@
|
|
|
253
249
|
width: max-content;
|
|
254
250
|
max-width: min(20rem, calc(100vw - 1rem));
|
|
255
251
|
padding: var(--kit-tooltip-py) var(--kit-tooltip-px);
|
|
256
|
-
border: 1px solid var(--kit-tooltip-
|
|
252
|
+
border: 1px solid var(--kit-tooltip-bd);
|
|
257
253
|
border-radius: var(--kit-tooltip-radius);
|
|
258
|
-
background: var(--kit-tooltip-
|
|
259
|
-
color: var(--kit-tooltip-
|
|
254
|
+
background: var(--kit-tooltip-bg);
|
|
255
|
+
color: var(--kit-tooltip-fg);
|
|
260
256
|
font-size: 0.875rem;
|
|
261
257
|
overflow-wrap: break-word;
|
|
262
258
|
box-shadow: 0 16px 29px -10px color-mix(in oklab, black 18%, transparent);
|
|
@@ -273,17 +269,6 @@
|
|
|
273
269
|
--kit-tooltip-px: 0.75rem;
|
|
274
270
|
}
|
|
275
271
|
|
|
276
|
-
.kit-tooltip__content[data-light='true'] {
|
|
277
|
-
--kit-tooltip-background: color-mix(in oklab, white 92%, var(--kit-surface-1));
|
|
278
|
-
--kit-tooltip-color: var(--kit-fg);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
.kit-tooltip__content[data-dark='true'] {
|
|
282
|
-
--kit-tooltip-background: color-mix(in oklab, black 76%, var(--kit-surface-3));
|
|
283
|
-
--kit-tooltip-color: white;
|
|
284
|
-
--kit-tooltip-border: color-mix(in oklab, white, transparent 78%);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
272
|
.kit-tooltip__content[data-rounded='0'] {
|
|
288
273
|
--kit-tooltip-radius: 0;
|
|
289
274
|
}
|
|
@@ -318,12 +303,12 @@
|
|
|
318
303
|
|
|
319
304
|
.kit-tooltip__content[data-variant='arrow'][data-location='bottom']::after {
|
|
320
305
|
bottom: 100%;
|
|
321
|
-
border-color: transparent transparent var(--kit-tooltip-
|
|
306
|
+
border-color: transparent transparent var(--kit-tooltip-bg) transparent;
|
|
322
307
|
}
|
|
323
308
|
|
|
324
309
|
.kit-tooltip__content[data-variant='arrow'][data-location='top']::after {
|
|
325
310
|
top: 100%;
|
|
326
|
-
border-color: var(--kit-tooltip-
|
|
311
|
+
border-color: var(--kit-tooltip-bg) transparent transparent transparent;
|
|
327
312
|
}
|
|
328
313
|
|
|
329
314
|
.kit-tooltip__content[data-variant='arrow'][data-location='left']::after,
|
|
@@ -335,12 +320,12 @@
|
|
|
335
320
|
|
|
336
321
|
.kit-tooltip__content[data-variant='arrow'][data-location='right']::after {
|
|
337
322
|
right: 100%;
|
|
338
|
-
border-color: transparent var(--kit-tooltip-
|
|
323
|
+
border-color: transparent var(--kit-tooltip-bg) transparent transparent;
|
|
339
324
|
}
|
|
340
325
|
|
|
341
326
|
.kit-tooltip__content[data-variant='arrow'][data-location='left']::after {
|
|
342
327
|
left: 100%;
|
|
343
|
-
border-color: transparent transparent transparent var(--kit-tooltip-
|
|
328
|
+
border-color: transparent transparent transparent var(--kit-tooltip-bg);
|
|
344
329
|
}
|
|
345
330
|
|
|
346
331
|
.kit-tooltip__content[data-location='top'] {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapikit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -138,8 +138,5 @@
|
|
|
138
138
|
"theme",
|
|
139
139
|
"css",
|
|
140
140
|
"typescript"
|
|
141
|
-
]
|
|
142
|
-
"dependencies": {
|
|
143
|
-
"prompts": "^2.4.2"
|
|
144
|
-
}
|
|
141
|
+
]
|
|
145
142
|
}
|
package/bin/configuration.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { promises as fs } from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { terminal } from './helper.js';
|
|
5
|
-
import presets from './presets.js';
|
|
6
|
-
|
|
7
|
-
async function findReferenceFile(projectPath) {
|
|
8
|
-
const routesPath = path.join(projectPath, 'src', 'routes');
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
await fs.access(routesPath);
|
|
12
|
-
} catch {
|
|
13
|
-
terminal('error', `Lapikit cannot find the routes/ directory.`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const layoutFile = path.join(routesPath, '+layout.svelte');
|
|
17
|
-
try {
|
|
18
|
-
await fs.access(layoutFile);
|
|
19
|
-
return layoutFile;
|
|
20
|
-
} catch {
|
|
21
|
-
// +layout.svelte not found in routes/
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const pageFile = path.join(routesPath, '+page.svelte');
|
|
25
|
-
try {
|
|
26
|
-
await fs.access(pageFile);
|
|
27
|
-
return pageFile;
|
|
28
|
-
} catch {
|
|
29
|
-
// +page.svelte not found in routes/
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const entries = await fs.readdir(routesPath, { withFileTypes: true });
|
|
34
|
-
const subDirectories = entries.filter((entry) => entry.isDirectory());
|
|
35
|
-
|
|
36
|
-
for (const dir of subDirectories) {
|
|
37
|
-
const subDirPath = path.join(routesPath, dir.name);
|
|
38
|
-
|
|
39
|
-
const subLayoutFile = path.join(subDirPath, '+layout.svelte');
|
|
40
|
-
try {
|
|
41
|
-
await fs.access(subLayoutFile);
|
|
42
|
-
return subLayoutFile;
|
|
43
|
-
} catch {
|
|
44
|
-
// +layout.svelte not found in subdirectory
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const subPageFile = path.join(subDirPath, '+page.svelte');
|
|
48
|
-
try {
|
|
49
|
-
await fs.access(subPageFile);
|
|
50
|
-
return subPageFile;
|
|
51
|
-
} catch {
|
|
52
|
-
// +page.svelte not found in subdirectory
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} catch {
|
|
56
|
-
// Error reading routes directory
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
throw new Error('Not found +layout or +page main on your project.');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function addImportToReferenceFile(targetFile, referenceFile) {
|
|
63
|
-
try {
|
|
64
|
-
const content = await fs.readFile(referenceFile, 'utf-8');
|
|
65
|
-
const relativePath = path.relative(path.dirname(referenceFile), targetFile);
|
|
66
|
-
const importStatement = `import "${relativePath.startsWith('.') ? relativePath : './' + relativePath}";\n`;
|
|
67
|
-
|
|
68
|
-
if (content.includes(`import "${relativePath}"`)) {
|
|
69
|
-
terminal('info', `Import statement already exists in ${referenceFile}`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const lines = content.split('\n');
|
|
74
|
-
let insertIndex = -1;
|
|
75
|
-
|
|
76
|
-
for (let i = 0; i < lines.length; i++) {
|
|
77
|
-
const line = lines[i].trim();
|
|
78
|
-
if (line.startsWith('<script>') || line.startsWith('<script lang="ts">')) {
|
|
79
|
-
insertIndex = i + 1;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (insertIndex === -1) {
|
|
85
|
-
throw new Error(`No found balise <script> ou <script lang="ts"> ${referenceFile}`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let finalInsertIndex = insertIndex;
|
|
89
|
-
for (let i = insertIndex; i < lines.length; i++) {
|
|
90
|
-
const line = lines[i].trim();
|
|
91
|
-
|
|
92
|
-
if (line === '</script>') {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (line === '' || line.startsWith('import ') || line.startsWith('//')) {
|
|
97
|
-
finalInsertIndex = i + 1;
|
|
98
|
-
} else {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
lines.splice(finalInsertIndex, 0, `\t${importStatement.trim()}`);
|
|
104
|
-
const newContent = lines.join('\n');
|
|
105
|
-
|
|
106
|
-
await fs.writeFile(referenceFile, newContent);
|
|
107
|
-
terminal('info', `Import has been added to ${referenceFile}`);
|
|
108
|
-
} catch (error) {
|
|
109
|
-
terminal('error', `Error adding import: ${error.message}`);
|
|
110
|
-
throw error;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function findViteConfigFile(projectPath, typescript) {
|
|
115
|
-
const ext = typescript ? 'ts' : 'js';
|
|
116
|
-
const viteConfigFile = path.join(projectPath, `vite.config.${ext}`);
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
await fs.access(viteConfigFile);
|
|
120
|
-
return viteConfigFile;
|
|
121
|
-
} catch {
|
|
122
|
-
// Try the other extension if the preferred one doesn't exist
|
|
123
|
-
const alternativeExt = typescript ? 'js' : 'ts';
|
|
124
|
-
const alternativeFile = path.join(projectPath, `vite.config.${alternativeExt}`);
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
await fs.access(alternativeFile);
|
|
128
|
-
return alternativeFile;
|
|
129
|
-
} catch {
|
|
130
|
-
throw new Error(`No vite.config.js or vite.config.ts file found in ${projectPath}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function addLapikitToViteConfig(viteConfigFile, pathConfig, typescript) {
|
|
136
|
-
try {
|
|
137
|
-
const content = await fs.readFile(viteConfigFile, 'utf-8');
|
|
138
|
-
const lapikitImport = `import { lapikit } from 'lapikit/vite';`;
|
|
139
|
-
const configPath = `${pathConfig}/lapikit.${typescript ? 'ts' : 'js'}`;
|
|
140
|
-
const lapikitPlugin = `lapikit({ config: '${configPath}' })`;
|
|
141
|
-
|
|
142
|
-
// Check if lapikit import already exists
|
|
143
|
-
if (content.includes(lapikitImport) || content.includes(`from 'lapikit/vite'`)) {
|
|
144
|
-
terminal('info', `Lapikit import already exists in ${viteConfigFile}`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const lines = content.split('\n');
|
|
149
|
-
let importInsertIndex = -1;
|
|
150
|
-
let pluginAdded = false;
|
|
151
|
-
|
|
152
|
-
// Find where to insert the import (after other imports)
|
|
153
|
-
for (let i = 0; i < lines.length; i++) {
|
|
154
|
-
const line = lines[i].trim();
|
|
155
|
-
|
|
156
|
-
if (line.startsWith('import ') && !line.includes('type ')) {
|
|
157
|
-
importInsertIndex = i + 1;
|
|
158
|
-
} else if (
|
|
159
|
-
line === '' &&
|
|
160
|
-
importInsertIndex !== -1 &&
|
|
161
|
-
lines[i + 1] &&
|
|
162
|
-
!lines[i + 1].trim().startsWith('import ')
|
|
163
|
-
) {
|
|
164
|
-
importInsertIndex = i;
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// If no imports found, insert at the beginning
|
|
170
|
-
if (importInsertIndex === -1) {
|
|
171
|
-
importInsertIndex = 0;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Insert the lapikit import
|
|
175
|
-
lines.splice(importInsertIndex, 0, lapikitImport);
|
|
176
|
-
|
|
177
|
-
// Find and update the plugins array
|
|
178
|
-
for (let i = 0; i < lines.length; i++) {
|
|
179
|
-
const line = lines[i].trim();
|
|
180
|
-
|
|
181
|
-
if (line.includes('plugins:') && line.includes('[') && line.includes(']')) {
|
|
182
|
-
// Single line plugins array
|
|
183
|
-
if (line.includes('sveltekit()')) {
|
|
184
|
-
const pluginMatch = line.match(/plugins:\s*\[(.*)\]/);
|
|
185
|
-
if (pluginMatch) {
|
|
186
|
-
const pluginsContent = pluginMatch[1];
|
|
187
|
-
if (!pluginsContent.includes('lapikit')) {
|
|
188
|
-
const newPluginsContent = pluginsContent.replace(
|
|
189
|
-
/sveltekit\(\)/,
|
|
190
|
-
`sveltekit(), ${lapikitPlugin}`
|
|
191
|
-
);
|
|
192
|
-
lines[i] = line.replace(pluginsContent, newPluginsContent);
|
|
193
|
-
pluginAdded = true;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
break;
|
|
198
|
-
} else if (line.includes('plugins:') && line.includes('[') && !line.includes(']')) {
|
|
199
|
-
// Multi-line plugins array start
|
|
200
|
-
for (let j = i; j < lines.length; j++) {
|
|
201
|
-
const pluginLine = lines[j].trim();
|
|
202
|
-
|
|
203
|
-
if (pluginLine.includes('sveltekit()') && !pluginAdded) {
|
|
204
|
-
// Check if lapikit is not already present
|
|
205
|
-
let hasLapikit = false;
|
|
206
|
-
for (let k = i; k < lines.length && !lines[k].includes(']'); k++) {
|
|
207
|
-
if (lines[k].includes('lapikit')) {
|
|
208
|
-
hasLapikit = true;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (!hasLapikit) {
|
|
214
|
-
// Add lapikit after sveltekit()
|
|
215
|
-
if (pluginLine.includes(',')) {
|
|
216
|
-
lines[j] = lines[j].replace('sveltekit()', `sveltekit(), ${lapikitPlugin}`);
|
|
217
|
-
} else {
|
|
218
|
-
lines[j] = lines[j].replace('sveltekit()', 'sveltekit(),');
|
|
219
|
-
// Insert lapikit on the next line with proper indentation
|
|
220
|
-
const indentation = lines[j].match(/^\s*/)[0];
|
|
221
|
-
lines.splice(j + 1, 0, `${indentation}${lapikitPlugin}`);
|
|
222
|
-
}
|
|
223
|
-
pluginAdded = true;
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (pluginLine.includes(']')) {
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (!pluginAdded) {
|
|
237
|
-
terminal('warn', `Could not find sveltekit() in plugins array to add lapikit() after it`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const newContent = lines.join('\n');
|
|
241
|
-
await fs.writeFile(viteConfigFile, newContent);
|
|
242
|
-
terminal('info', `Lapikit import and plugin added to ${viteConfigFile}`);
|
|
243
|
-
} catch (error) {
|
|
244
|
-
terminal('error', `Error adding lapikit to vite config: ${error.message}`);
|
|
245
|
-
throw error;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export async function initConfiguration(options) {
|
|
250
|
-
const { typescript, pathConfig, formatCSS, pathCSS } = options;
|
|
251
|
-
const ext = typescript ? 'ts' : 'js';
|
|
252
|
-
const targetDir = path.resolve(process.cwd(), pathConfig);
|
|
253
|
-
const targetFile = path.join(targetDir, `lapikit.${ext}`);
|
|
254
|
-
|
|
255
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
256
|
-
|
|
257
|
-
let fileCreated = false;
|
|
258
|
-
|
|
259
|
-
// Create Lapikit config
|
|
260
|
-
try {
|
|
261
|
-
await fs.access(targetFile);
|
|
262
|
-
terminal('info', `File ${targetFile} already exists.`);
|
|
263
|
-
} catch {
|
|
264
|
-
terminal('info', `Creating file: ${targetFile}`);
|
|
265
|
-
const content = presets({
|
|
266
|
-
adapterCSS: formatCSS
|
|
267
|
-
});
|
|
268
|
-
await fs.writeFile(targetFile, content);
|
|
269
|
-
terminal('info', `File created: ${targetFile}`);
|
|
270
|
-
fileCreated = true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Add Import Lapikit plugin
|
|
274
|
-
try {
|
|
275
|
-
const referenceFile = await findReferenceFile(process.cwd());
|
|
276
|
-
await addImportToReferenceFile(targetFile, referenceFile);
|
|
277
|
-
} catch (error) {
|
|
278
|
-
terminal('error', `Error adding import: ${error.message}`);
|
|
279
|
-
|
|
280
|
-
if (fileCreated) {
|
|
281
|
-
try {
|
|
282
|
-
await fs.unlink(targetFile);
|
|
283
|
-
terminal('info', `File ${targetFile} deleted due to error.`);
|
|
284
|
-
} catch {
|
|
285
|
-
// Ignore deletion error
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Add Import Lapikit css
|
|
292
|
-
if (formatCSS !== 'css') {
|
|
293
|
-
console.log('need custom import (Preview)', pathCSS);
|
|
294
|
-
}
|
|
295
|
-
// Add lapikit to vite.config file
|
|
296
|
-
try {
|
|
297
|
-
const viteConfigFile = await findViteConfigFile(process.cwd(), typescript);
|
|
298
|
-
await addLapikitToViteConfig(viteConfigFile, pathConfig, typescript);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
terminal('warn', `Warning: Could not update vite.config file: ${error.message}`);
|
|
301
|
-
terminal('error', `Error adding lapikit to vite config: ${error.message}`);
|
|
302
|
-
}
|
|
303
|
-
}
|
package/bin/presets.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
function presets({ adapterCSS }) {
|
|
2
|
-
let content = '';
|
|
3
|
-
|
|
4
|
-
content += `/**\n`;
|
|
5
|
-
content += ` * Lapikit\n`;
|
|
6
|
-
content += ` * Library documentation: https://lapikit.dev\n`;
|
|
7
|
-
content += ` */\n\n`;
|
|
8
|
-
|
|
9
|
-
if (adapterCSS === 'css') {
|
|
10
|
-
content += `// Styles\n`;
|
|
11
|
-
content += `import 'lapikit/styles';\n`;
|
|
12
|
-
content += `import 'lapikit/themes';\n\n`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
content += `// Composables\n`;
|
|
16
|
-
content += `import createLapikit from 'lapikit';\n\n`;
|
|
17
|
-
|
|
18
|
-
content += `// https://lapikit.dev/docs/getting-started\n`;
|
|
19
|
-
content += `export default createLapikit({\n`;
|
|
20
|
-
content += `\tadapterCSS: "${adapterCSS}",\n`;
|
|
21
|
-
content += `\n});`;
|
|
22
|
-
|
|
23
|
-
return content;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default presets;
|