lapikit 0.3.2 → 0.3.3

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.
@@ -1,2 +1,9 @@
1
- declare function lili(): void;
2
- export { lili };
1
+ declare function lapikitPreprocess(): {
2
+ markup({ content }: {
3
+ content: string;
4
+ filename?: string;
5
+ }): {
6
+ code: string;
7
+ } | undefined;
8
+ };
9
+ export { lapikitPreprocess };
@@ -1,4 +1,64 @@
1
- function lili() {
2
- console.log('Lapikit preprocess running...');
1
+ import { components } from './labs/components/index.js';
2
+ function componentName(shortName) {
3
+ return 'Kit' + shortName.charAt(0).toUpperCase() + shortName.slice(1);
3
4
  }
4
- export { lili };
5
+ function lapikitPreprocess() {
6
+ return {
7
+ markup({ content }) {
8
+ const hasComponent = components.some((comp) => content.includes(`<lpk:${comp}`));
9
+ if (!hasComponent)
10
+ return;
11
+ let processedContent = content;
12
+ const importedComponents = new Set();
13
+ let hasChanges = true;
14
+ while (hasChanges) {
15
+ hasChanges = false;
16
+ for (const shortName of components) {
17
+ const componentNameStr = componentName(shortName);
18
+ const regex = new RegExp(`<lpk:${shortName}([\\s\\S]*?)>([\\s\\S]*?)<\\/lpk:${shortName}\\s*>`, 'g');
19
+ const newContent = processedContent.replace(regex, (fullMatch, attrs, children) => {
20
+ hasChanges = true;
21
+ importedComponents.add(componentNameStr);
22
+ return `<${componentNameStr}${attrs}>${children}</${componentNameStr}>`;
23
+ });
24
+ if (newContent !== processedContent) {
25
+ processedContent = newContent;
26
+ }
27
+ }
28
+ }
29
+ if (processedContent === content)
30
+ return;
31
+ if (importedComponents.size > 0) {
32
+ const imports = Array.from(importedComponents).join(', ');
33
+ const scriptRegex = /<script(?![^>]*\bmodule\b)([^>]*)>/;
34
+ const scriptMatch = processedContent.match(scriptRegex);
35
+ if (scriptMatch && scriptMatch.index !== undefined) {
36
+ const insertPos = scriptMatch.index + scriptMatch[0].length;
37
+ processedContent =
38
+ processedContent.slice(0, insertPos) +
39
+ `\n\timport { ${imports} } from 'lapikit/labs/components';` +
40
+ processedContent.slice(insertPos);
41
+ }
42
+ else {
43
+ const moduleScriptMatch = processedContent.match(/<script[^>]*\bmodule\b[^>]*>/);
44
+ if (moduleScriptMatch && moduleScriptMatch.index !== undefined) {
45
+ const moduleScriptEnd = processedContent.indexOf('</script>', moduleScriptMatch.index) + '</script>'.length;
46
+ processedContent =
47
+ processedContent.slice(0, moduleScriptEnd) +
48
+ `\n\n<script>\n\timport { ${imports} } from 'lapikit/labs/components';\n</script>` +
49
+ processedContent.slice(moduleScriptEnd);
50
+ }
51
+ else {
52
+ processedContent =
53
+ `<script>\n\timport { ${imports} } from 'lapikit/labs/components';\n</script>\n\n` +
54
+ processedContent;
55
+ }
56
+ }
57
+ }
58
+ return {
59
+ code: processedContent
60
+ };
61
+ }
62
+ };
63
+ }
64
+ export { lapikitPreprocess };
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ let { children, ...rest } = $props();
3
+ </script>
4
+
5
+ <button {...rest}>
6
+ {@render children()}
7
+ </button>
8
+
9
+ <style>
10
+ button {
11
+ padding: 0.5em 1em;
12
+ border: none;
13
+ border-radius: 4px;
14
+ background-color: #007bff;
15
+ color: white;
16
+ cursor: pointer;
17
+ font-size: 1em;
18
+ transition: background-color 0.3s ease;
19
+ }
20
+
21
+ button:hover {
22
+ background-color: #0056b3;
23
+ }
24
+ </style>
@@ -0,0 +1,5 @@
1
+ declare const Button: import("svelte").Component<{
2
+ children: any;
3
+ } & Record<string, any>, {}, "">;
4
+ type Button = ReturnType<typeof Button>;
5
+ export default Button;
@@ -0,0 +1,2 @@
1
+ export declare const components: readonly string[];
2
+ export { default as KitBtn } from './button/button.svelte';
@@ -0,0 +1,3 @@
1
+ export const components = ['btn'];
2
+ // components
3
+ export { default as KitBtn } from './button/button.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -78,6 +78,10 @@
78
78
  },
79
79
  "./labs/preprocess": {
80
80
  "default": "./dist/entry-bundler.js"
81
+ },
82
+ "./labs/components": {
83
+ "svelte": "./dist/labs/components/index.js",
84
+ "default": "./dist/labs/components/index.js"
81
85
  }
82
86
  },
83
87
  "peerDependencies": {
@@ -89,7 +93,7 @@
89
93
  "@sveltejs/adapter-auto": "^4.0.0",
90
94
  "@sveltejs/kit": "^2.16.0",
91
95
  "@sveltejs/package": "^2.0.0",
92
- "@sveltejs/vite-plugin-svelte": "^5.0.0",
96
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
93
97
  "@testing-library/jest-dom": "^6.6.3",
94
98
  "@testing-library/svelte": "^5.2.4",
95
99
  "eslint": "^9.18.0",
@@ -104,7 +108,7 @@
104
108
  "svelte-check": "^4.0.0",
105
109
  "typescript": "^5.0.0",
106
110
  "typescript-eslint": "^8.20.0",
107
- "vite": "^6.2.5",
111
+ "vite": "^7.2.2",
108
112
  "vitest": "^3.0.0"
109
113
  },
110
114
  "keywords": [