lapikit 0.3.6 → 0.3.7

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.
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { useClassName, useStyles } from './btn.svelte.js';
3
+ import { splitSyntheticProps } from '../../utils/index.js';
4
+
5
+ let {
6
+ class: className,
7
+ style: styleAttr,
8
+ children,
9
+ 's-class': sClass,
10
+ 's-style': sStyle,
11
+ ...rest
12
+ } = $props();
13
+
14
+ let { classDirectiveProps, styleDirectiveProps, regularProps } = $derived(
15
+ splitSyntheticProps(rest as Record<string, unknown>)
16
+ );
17
+
18
+ let finalClass = $derived(
19
+ useClassName({
20
+ baseClass: 'kit-button',
21
+ className,
22
+ sClass,
23
+ classDirectiveProps
24
+ }).value
25
+ );
26
+
27
+ let finalStyle = $derived(
28
+ useStyles({
29
+ styleAttr,
30
+ sStyle,
31
+ styleDirectiveProps
32
+ }).value
33
+ );
34
+ </script>
35
+
36
+ <button class={finalClass} style={finalStyle} {...regularProps}>
37
+ {@render children()}
38
+ </button>
39
+
40
+ <style>
41
+ .kit-btn {
42
+ border: 1px solid rgb(0, 0, 0);
43
+ }
44
+ </style>
@@ -0,0 +1,7 @@
1
+ declare const Btn: import("svelte").Component<{
2
+ class: any;
3
+ style: any;
4
+ children: any;
5
+ } & Record<string, any>, {}, "">;
6
+ type Btn = ReturnType<typeof Btn>;
7
+ export default Btn;
@@ -0,0 +1,71 @@
1
+ export function useClassName({ baseClass = '', className, sClass, classDirectiveProps } = {}) {
2
+ return {
3
+ get value() {
4
+ const classes = [];
5
+ if (baseClass) {
6
+ classes.push(baseClass);
7
+ }
8
+ if (typeof sClass === 'string' && sClass) {
9
+ classes.push(sClass);
10
+ }
11
+ if (Array.isArray(sClass)) {
12
+ for (const value of sClass) {
13
+ if (typeof value === 'string' && value) {
14
+ classes.push(value);
15
+ }
16
+ }
17
+ }
18
+ if (sClass && typeof sClass === 'object' && !Array.isArray(sClass)) {
19
+ Object.entries(sClass).forEach(([key, value]) => {
20
+ if (value === true) {
21
+ classes.push(key);
22
+ }
23
+ else if (typeof value === 'string' && value) {
24
+ classes.push(value);
25
+ }
26
+ });
27
+ }
28
+ if (classDirectiveProps) {
29
+ Object.entries(classDirectiveProps).forEach(([key, value]) => {
30
+ const base = key.replace('s-class_', '');
31
+ if (value === true) {
32
+ classes.push(base);
33
+ }
34
+ else if (typeof value === 'string' && value) {
35
+ classes.push(`${base}${value}`);
36
+ }
37
+ });
38
+ }
39
+ if (className) {
40
+ classes.push(className);
41
+ }
42
+ return classes.filter(Boolean).join(' ');
43
+ }
44
+ };
45
+ }
46
+ export function useStyles({ styleAttr, sStyle, styleDirectiveProps } = {}) {
47
+ return {
48
+ get value() {
49
+ const styles = [];
50
+ if (sStyle && typeof sStyle === 'object') {
51
+ Object.entries(sStyle).forEach(([key, value]) => {
52
+ if (value) {
53
+ styles.push(`${key}: ${value}`);
54
+ }
55
+ });
56
+ }
57
+ if (styleDirectiveProps) {
58
+ Object.entries(styleDirectiveProps).forEach(([key, value]) => {
59
+ const base = key.replace('s-style_', '');
60
+ if (value) {
61
+ styles.push(`${base}: ${value}`);
62
+ }
63
+ });
64
+ }
65
+ if (styleAttr) {
66
+ styles.push(styleAttr);
67
+ }
68
+ return styles.filter(Boolean).join('; ');
69
+ }
70
+ };
71
+ }
@@ -1 +1 @@
1
- export { default as KitBtn } from './button/button.svelte';
1
+ export { default as KitBtn } from './btn/btn.svelte';
@@ -1,2 +1,2 @@
1
1
  // components
2
- export { default as KitBtn } from './button/button.svelte';
2
+ export { default as KitBtn } from './btn/btn.svelte';
@@ -0,0 +1 @@
1
+ export * from './props.js';
@@ -0,0 +1 @@
1
+ export * from './props.js';
@@ -0,0 +1,15 @@
1
+ export type SClassProp = string | string[] | Record<string, boolean | string> | undefined;
2
+ export type SStyleProp = Record<string, boolean | string> | undefined;
3
+ export declare function splitSyntheticProps(allProps: Record<string, unknown>): {
4
+ classDirectiveProps: {
5
+ [k: string]: unknown;
6
+ };
7
+ styleDirectiveProps: {
8
+ [k: string]: unknown;
9
+ };
10
+ regularProps: {
11
+ [k: string]: unknown;
12
+ };
13
+ };
14
+ export declare function computeSClasses(sClass: SClassProp, classDirectiveProps: Record<string, unknown>): string;
15
+ export declare function computeSStyles(sStyle: SStyleProp, styleDirectiveProps: Record<string, unknown>): string;
@@ -0,0 +1,60 @@
1
+ export function splitSyntheticProps(allProps) {
2
+ const classDirectiveProps = Object.fromEntries(Object.entries(allProps).filter(([key]) => key.startsWith('s-class_')));
3
+ const styleDirectiveProps = Object.fromEntries(Object.entries(allProps).filter(([key]) => key.startsWith('s-style_')));
4
+ const regularProps = Object.fromEntries(Object.entries(allProps).filter(([key]) => !key.startsWith('s-class') && !key.startsWith('s-style')));
5
+ return { classDirectiveProps, styleDirectiveProps, regularProps };
6
+ }
7
+ export function computeSClasses(sClass, classDirectiveProps) {
8
+ const classes = [];
9
+ // s-class string
10
+ if (typeof sClass === 'string' && sClass) {
11
+ classes.push(sClass);
12
+ }
13
+ // s-class array
14
+ if (Array.isArray(sClass)) {
15
+ for (const value of sClass) {
16
+ if (typeof value === 'string' && value) {
17
+ classes.push(value);
18
+ }
19
+ }
20
+ }
21
+ // s-class object
22
+ if (sClass && typeof sClass === 'object' && !Array.isArray(sClass)) {
23
+ Object.entries(sClass).forEach(([key, value]) => {
24
+ if (value === true) {
25
+ classes.push(key);
26
+ }
27
+ else if (typeof value === 'string' && value) {
28
+ classes.push(value);
29
+ }
30
+ });
31
+ }
32
+ // s-class_xxx
33
+ Object.entries(classDirectiveProps).forEach(([key, value]) => {
34
+ const base = key.replace('s-class_', '');
35
+ if (value === true) {
36
+ classes.push(base);
37
+ }
38
+ else if (typeof value === 'string' && value) {
39
+ classes.push(`${base}${value}`);
40
+ }
41
+ });
42
+ return classes.join(' ');
43
+ }
44
+ export function computeSStyles(sStyle, styleDirectiveProps) {
45
+ const styles = [];
46
+ if (sStyle && typeof sStyle === 'object') {
47
+ Object.entries(sStyle).forEach(([key, value]) => {
48
+ if (value) {
49
+ styles.push(`${key}: ${value}`);
50
+ }
51
+ });
52
+ }
53
+ Object.entries(styleDirectiveProps).forEach(([key, value]) => {
54
+ const base = key.replace('s-style_', '');
55
+ if (value) {
56
+ styles.push(`${base}: ${value}`);
57
+ }
58
+ });
59
+ return styles.join('; ');
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,24 +0,0 @@
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>
@@ -1,5 +0,0 @@
1
- declare const Button: import("svelte").Component<{
2
- children: any;
3
- } & Record<string, any>, {}, "">;
4
- type Button = ReturnType<typeof Button>;
5
- export default Button;