@danielito1996/compose-svelted 0.2.7-alpha01 → 0.2.7-alpha03

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,25 +1,47 @@
1
1
  <script lang="ts">
2
2
  import { Modifier } from "../../core/modifier/Modifier";
3
- import type {BoxAlignment} from "./Alignment";
3
+ import type { BoxAlignment } from "./Alignment";
4
+ import {resolveBoxAlignment} from "./resolveAlignment";
4
5
 
5
6
  export let modifier: Modifier = Modifier.empty();
6
7
  export let contentAlignment: BoxAlignment | undefined = undefined;
7
8
 
8
- $: contentStyle = contentAlignment ? alignmentToFlexStyle(contentAlignment) : "";
9
+ /**
10
+ * Box-level alignment:
11
+ * Alinea TODOS los hijos (Compose Box behavior)
12
+ */
13
+ function contentAlignmentStyle(alignment: BoxAlignment): string {
14
+ const [h, v = h] = alignment.split(" ");
9
15
 
10
- function alignmentToFlexStyle(alignment: BoxAlignment): string {
11
- const parts = alignment.split(" ");
12
- const horiz = parts[0] === "flex-start" ? "flex-start" : parts[0] === "flex-end" ? "flex-end" : "center";
13
- const vert = parts[1] || parts[0];
14
- const v = vert === "flex-start" ? "flex-start" : vert === "flex-end" ? "flex-end" : "center";
16
+ const justify =
17
+ h === "flex-start" ? "flex-start" :
18
+ h === "flex-end" ? "flex-end" :
19
+ "center";
15
20
 
16
- return `display:flex; align-items:${v}; justify-content:${horiz};`;
21
+ const align =
22
+ v === "flex-start" ? "flex-start" :
23
+ v === "flex-end" ? "flex-end" :
24
+ "center";
25
+
26
+ return `
27
+ display:flex;
28
+ justify-content:${justify};
29
+ align-items:${align};
30
+ `;
17
31
  }
18
32
  </script>
19
33
 
20
34
  <div
21
- class="relative"
22
- style={`${contentStyle} ${modifier.toStyle()}`}
35
+ class="compose-box"
36
+ style={`
37
+ position:relative;
38
+ ${contentAlignment ? contentAlignmentStyle(contentAlignment) : ""}
39
+ ${modifier.toStyle()}
40
+ `}
23
41
  >
24
- <slot />
42
+ <!--
43
+ Slot con scope:
44
+ Cada hijo puede traer su propio Modifier
45
+ -->
46
+ style={`position:relative;${modifier.toStyle()}`}
25
47
  </div>
@@ -13,20 +13,11 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
13
13
  };
14
14
  z_$$bindings?: Bindings;
15
15
  }
16
- type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
17
- default: any;
18
- } ? Props extends Record<string, never> ? any : {
19
- children?: any;
20
- } : {});
21
- declare const Box: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
16
+ declare const Box: $$__sveltets_2_IsomorphicComponent<{
22
17
  modifier?: Modifier;
23
18
  contentAlignment?: BoxAlignment | undefined;
24
19
  }, {
25
- default: {};
26
- }>, {
27
20
  [evt: string]: CustomEvent<any>;
28
- }, {
29
- default: {};
30
- }, {}, string>;
21
+ }, {}, {}, string>;
31
22
  type Box = InstanceType<typeof Box>;
32
23
  export default Box;
@@ -4,20 +4,43 @@
4
4
  import { Arrangement } from "./Arrangement";
5
5
  import type { ArrangementValue } from "./Arrangement";
6
6
  import type { HorizontalAlignment } from "./Alignment";
7
+ import {resolveFlexAlignSelf} from "./resolveFlexAlignSelf";
7
8
 
8
9
  export let modifier: Modifier = Modifier.empty();
10
+
11
+ // Cross-axis (horizontal en Column)
9
12
  export let horizontalAlignment: HorizontalAlignment = Alignment.Start;
13
+
14
+ // Main-axis (vertical en Column)
10
15
  export let verticalArrangement: ArrangementValue = Arrangement.Start;
16
+
17
+ $: gapStyle =
18
+ verticalArrangement.type === "spaced"
19
+ ? `gap:${verticalArrangement.gap}px;`
20
+ : "";
11
21
  </script>
12
22
 
13
23
  <div
14
- class="flex flex-col"
24
+ class="compose-column"
15
25
  style={`
16
- align-items: ${horizontalAlignment};
17
- justify-content: ${verticalArrangement.justifyContent};
18
- ${verticalArrangement.type === "spaced" ? `gap:${verticalArrangement.gap}px;` : ""}
19
- ${modifier.toStyle()}
20
- `}
26
+ display: flex;
27
+ flex-direction: column;
28
+ align-items: ${horizontalAlignment};
29
+ justify-content: ${verticalArrangement.justifyContent};
30
+ ${gapStyle}
31
+ ${modifier.toStyle()}
32
+ `}
21
33
  >
22
- <slot />
34
+ <slot let:modifier>
35
+ <div
36
+ style={`
37
+ ${modifier?.getMeta().align
38
+ ? resolveFlexAlignSelf(modifier.getMeta().align)
39
+ : ""}
40
+ ${modifier?.toStyle()}
41
+ `}
42
+ >
43
+ <slot />
44
+ </div>
45
+ </slot>
23
46
  </div>
@@ -0,0 +1 @@
1
+ export type LayoutContext = "flex" | "box";
@@ -0,0 +1 @@
1
+ export {};
@@ -18,7 +18,7 @@
18
18
  let scrollTop = 0;
19
19
  let viewportHeight = 0;
20
20
 
21
- let estimatedItemHeight = 56; // fallback Material
21
+ let estimatedItemHeight = 56;
22
22
  let measured = false;
23
23
 
24
24
  const overscan = 3;
@@ -43,7 +43,7 @@
43
43
  scrollTop = (e.target as HTMLDivElement).scrollTop;
44
44
  }
45
45
 
46
- // --- Virtualization math ---
46
+ // --- Virtualization ---
47
47
  $: totalHeight = items.length * estimatedItemHeight;
48
48
 
49
49
  $: startIndex = Math.max(
@@ -55,13 +55,11 @@
55
55
  Math.ceil(viewportHeight / estimatedItemHeight) + overscan * 2;
56
56
 
57
57
  $: endIndex = Math.min(items.length, startIndex + visibleCount);
58
-
59
58
  $: visibleItems = items.slice(startIndex, endIndex);
60
59
 
61
- // --- Arrangement ---
62
- function resolveGap(arrangement: ArrangementValue): string {
63
- return arrangement.type === "spaced"
64
- ? `${arrangement.gap}px`
60
+ function resolveGap(): string {
61
+ return verticalArrangement.type === "spaced"
62
+ ? `${verticalArrangement.gap}px`
65
63
  : "0px";
66
64
  }
67
65
  </script>
@@ -69,15 +67,17 @@
69
67
  <div
70
68
  bind:this={container}
71
69
  on:scroll={onScroll}
70
+ class="compose-lazy-column"
72
71
  style={`
73
- overflow-y:auto;
74
- position:relative;
72
+ overflow-y: auto;
73
+ overflow-x: hidden;
74
+ position: relative;
75
75
  ${modifier.toStyle()}
76
76
  `}
77
77
  >
78
- <!-- Total scroll space -->
78
+ <!-- Espacio total -->
79
79
  <div style={`height:${totalHeight}px; position:relative;`}>
80
- <!-- Visible window -->
80
+ <!-- Ventana visible -->
81
81
  <div
82
82
  style={`
83
83
  position:absolute;
@@ -88,7 +88,7 @@
88
88
  display:flex;
89
89
  flex-direction:column;
90
90
  align-items:${horizontalAlignment};
91
- gap:${resolveGap(verticalArrangement)};
91
+ gap:${resolveGap()};
92
92
  `}
93
93
  >
94
94
  {#each visibleItems as item, i}
@@ -1,71 +1,107 @@
1
1
  <script lang="ts">
2
2
  import { Modifier } from "../../core/modifier/Modifier";
3
+ import { onMount, tick } from "svelte";
3
4
  import { Alignment } from "./Alignment";
4
5
  import { Arrangement } from "./Arrangement";
5
6
  import type { ArrangementValue } from "./Arrangement";
6
- import type { VerticalAlignment } from "./Alignment";
7
+ import type { HorizontalAlignment } from "./Alignment";
7
8
 
8
9
  export let items: any[] = [];
9
10
  export let modifier: Modifier = Modifier.empty();
10
11
 
11
- export let verticalAlignment: VerticalAlignment = Alignment.Top;
12
- export let horizontalArrangement: ArrangementValue = Arrangement.Start;
12
+ export let horizontalAlignment: HorizontalAlignment = Alignment.Start;
13
+ export let verticalArrangement: ArrangementValue = Arrangement.Start;
13
14
 
14
- export let scrollEnabled: boolean = true;
15
- export let hideScrollbar: boolean = false;
16
- export let horizontalSpacing: number | null = null;
15
+ let container: HTMLDivElement;
16
+ let probeItem: HTMLDivElement | null = null;
17
17
 
18
- function resolveGap(): string {
19
- if (horizontalSpacing !== null) {
20
- return `${horizontalSpacing}px`;
18
+ let scrollTop = 0;
19
+ let viewportHeight = 0;
20
+
21
+ let estimatedItemHeight = 56; // fallback Material
22
+ let measured = false;
23
+
24
+ const overscan = 3;
25
+
26
+ onMount(() => {
27
+ viewportHeight = container.clientHeight;
28
+ });
29
+
30
+ async function measure() {
31
+ await tick();
32
+ if (probeItem) {
33
+ estimatedItemHeight = probeItem.offsetHeight;
34
+ measured = true;
21
35
  }
36
+ }
22
37
 
23
- return horizontalArrangement.type === "spaced"
24
- ? `${horizontalArrangement.gap}px`
25
- : "0px";
38
+ $: if (probeItem && !measured) {
39
+ measure();
26
40
  }
27
41
 
28
- function resolveOverflowX(): string {
29
- return scrollEnabled ? "auto" : "hidden";
42
+ function onScroll(e: Event) {
43
+ scrollTop = (e.target as HTMLDivElement).scrollTop;
30
44
  }
31
45
 
32
- function resolveScrollbarStyle(): string {
33
- if (!hideScrollbar) return "";
46
+ // --- Virtualization math ---
47
+ $: totalHeight = items.length * estimatedItemHeight;
34
48
 
35
- return `
36
- scrollbar-width: none;
37
- -ms-overflow-style: none;
38
- `;
39
- }
40
- </script>
49
+ $: startIndex = Math.max(
50
+ 0,
51
+ Math.floor(scrollTop / estimatedItemHeight) - overscan
52
+ );
41
53
 
42
- <div
43
- class={hideScrollbar ? "lazy-row--hide-scrollbar" : ""}
44
- style={`
45
- display: flex;
46
- flex-direction: row;
54
+ $: visibleCount =
55
+ Math.ceil(viewportHeight / estimatedItemHeight) + overscan * 2;
47
56
 
48
- align-items: ${verticalAlignment};
49
- justify-content: ${horizontalArrangement.justifyContent};
50
- gap: ${resolveGap()};
57
+ $: endIndex = Math.min(items.length, startIndex + visibleCount);
51
58
 
52
- overflow-x: ${resolveOverflowX()};
53
- overflow-y: visible;
59
+ $: visibleItems = items.slice(startIndex, endIndex);
54
60
 
55
- height: fit-content;
56
- min-height: fit-content;
61
+ // --- Arrangement ---
62
+ function resolveGap(arrangement: ArrangementValue): string {
63
+ return arrangement.type === "spaced"
64
+ ? `${arrangement.gap}px`
65
+ : "0px";
66
+ }
67
+ </script>
57
68
 
58
- ${resolveScrollbarStyle()}
69
+ <div
70
+ bind:this={container}
71
+ on:scroll={onScroll}
72
+ style={`
73
+ overflow-y:auto;
74
+ position:relative;
59
75
  ${modifier.toStyle()}
60
76
  `}
61
77
  >
62
- {#each items as item}
63
- <slot {item} />
64
- {/each}
65
- </div>
66
-
67
- <style>
68
- .lazy-row--hide-scrollbar::-webkit-scrollbar {
69
- display: none;
70
- }
71
- </style>
78
+ <!-- Total scroll space -->
79
+ <div style={`height:${totalHeight}px; position:relative;`}>
80
+ <!-- Visible window -->
81
+ <div
82
+ style={`
83
+ position:absolute;
84
+ top:${startIndex * estimatedItemHeight}px;
85
+ left:0;
86
+ right:0;
87
+
88
+ display:flex;
89
+ flex-direction:column;
90
+ align-items:${horizontalAlignment};
91
+ gap:${resolveGap(verticalArrangement)};
92
+ `}
93
+ >
94
+ {#each visibleItems as item, i}
95
+ {#if i === 0 && !measured}
96
+ <div bind:this={probeItem}>
97
+ <slot {item} />
98
+ </div>
99
+ {:else}
100
+ <div>
101
+ <slot {item} />
102
+ </div>
103
+ {/if}
104
+ {/each}
105
+ </div>
106
+ </div>
107
+ </div>
@@ -1,6 +1,6 @@
1
1
  import { Modifier } from "../../core/modifier/Modifier";
2
2
  import type { ArrangementValue } from "./Arrangement";
3
- import type { VerticalAlignment } from "./Alignment";
3
+ import type { HorizontalAlignment } from "./Alignment";
4
4
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
5
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
6
  $$bindings?: Bindings;
@@ -22,11 +22,8 @@ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
22
22
  declare const LazyRow: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
23
23
  items?: any[];
24
24
  modifier?: Modifier;
25
- verticalAlignment?: VerticalAlignment;
26
- horizontalArrangement?: ArrangementValue;
27
- scrollEnabled?: boolean;
28
- hideScrollbar?: boolean;
29
- horizontalSpacing?: number | null;
25
+ horizontalAlignment?: HorizontalAlignment;
26
+ verticalArrangement?: ArrangementValue;
30
27
  }, {
31
28
  default: {
32
29
  item: any;
@@ -4,20 +4,43 @@
4
4
  import { Arrangement } from "./Arrangement";
5
5
  import type { ArrangementValue } from "./Arrangement";
6
6
  import type { VerticalAlignment } from "./Alignment";
7
+ import {resolveFlexAlignSelf} from "./resolveFlexAlignSelf";
7
8
 
8
9
  export let modifier: Modifier = Modifier.empty();
9
- export let verticalAlignment: VerticalAlignment = Alignment.Top;
10
+
11
+ // Cross-axis (vertical en Row)
12
+ export let verticalAlignment: VerticalAlignment = Alignment.CenterVertically;
13
+
14
+ // Main-axis (horizontal en Row)
10
15
  export let horizontalArrangement: ArrangementValue = Arrangement.Start;
16
+
17
+ $: gapStyle =
18
+ horizontalArrangement.type === "spaced"
19
+ ? `gap:${horizontalArrangement.gap}px;`
20
+ : "";
11
21
  </script>
12
22
 
13
23
  <div
14
- class="flex flex-row"
24
+ class="compose-row"
15
25
  style={`
16
- align-items: ${verticalAlignment};
17
- justify-content: ${horizontalArrangement.justifyContent};
18
- ${horizontalArrangement.type === "spaced" ? `gap:${horizontalArrangement.gap}px;` : ""}
19
- ${modifier.toStyle()}
20
- `}
26
+ display: flex;
27
+ flex-direction: row;
28
+ align-items: ${verticalAlignment};
29
+ justify-content: ${horizontalArrangement.justifyContent};
30
+ ${gapStyle}
31
+ ${modifier.toStyle()}
32
+ `}
21
33
  >
22
- <slot />
34
+ <slot let:modifier>
35
+ <div
36
+ style={`
37
+ ${modifier?.getMeta().align
38
+ ? resolveFlexAlignSelf(modifier.getMeta().align)
39
+ : ""}
40
+ ${modifier?.toStyle()}
41
+ `}
42
+ >
43
+ <slot />
44
+ </div>
45
+ </slot>
23
46
  </div>
@@ -1,70 +1,50 @@
1
1
  <script lang="ts">
2
2
  import { Modifier } from "../../core/modifier/Modifier";
3
+ import { resolveBoxAlignment } from "./resolveAlignment";
4
+ import {Alignment, BoxAlignment} from "./Alignment";
3
5
 
4
6
  export let modifier: Modifier = Modifier.empty();
5
-
6
- // Padding interno aplicado al content (como Scaffold paddingValues)
7
- export let contentPadding: number = 16;
8
-
9
- // Control del FAB
10
- export let fabAlignment:
11
- | "bottom-end"
12
- | "bottom-center"
13
- | "bottom-start" = "bottom-end";
7
+ export let contentPadding = 16;
8
+ export let fabAlignment: BoxAlignment = Alignment.BottomEnd;
14
9
  </script>
15
10
 
16
11
  <div
12
+ class="compose-relative"
17
13
  style={`
18
14
  display: flex;
19
15
  flex-direction: column;
20
- height: 100%;
21
16
  width: 100%;
22
- position: relative;
17
+ height: 100%;
23
18
  ${modifier.toStyle()}
24
19
  `}
25
20
  >
26
- <!-- Top Bar -->
27
- <div>
28
- <slot name="topBar" />
29
- </div>
21
+ <!-- Top bar -->
22
+ <slot name="topBar" />
30
23
 
31
24
  <!-- Content -->
32
25
  <div
33
- style={`
34
- flex: 1;
35
- position: relative;
36
- padding: ${contentPadding}px;
37
- overflow: auto;
38
- `}
26
+ class="compose-scaffold-content"
27
+ style={`padding:${contentPadding}px;`}
39
28
  >
40
29
  <slot />
41
30
  </div>
42
31
 
43
- <!-- Bottom Bar -->
44
- <div>
45
- <slot name="bottomBar" />
46
- </div>
32
+ <!-- Bottom bar -->
33
+ <slot name="bottomBar" />
47
34
 
48
- <!-- Floating Action Button -->
35
+ <!-- FAB overlay -->
49
36
  <div
50
37
  style={`
51
- position: absolute;
52
- pointer-events: none;
53
- inset: 0;
38
+ position:absolute;
39
+ inset:0;
40
+ pointer-events:none;
54
41
  `}
55
42
  >
56
43
  <div
57
44
  style={`
58
- position: absolute;
59
- pointer-events: auto;
60
-
61
- ${
62
- fabAlignment === "bottom-end"
63
- ? "right: 16px; bottom: 16px;"
64
- : fabAlignment === "bottom-center"
65
- ? "left: 50%; transform: translateX(-50%); bottom: 16px;"
66
- : "left: 16px; bottom: 16px;"
67
- }
45
+ ${resolveBoxAlignment(fabAlignment)}
46
+ pointer-events:auto;
47
+ margin:16px;
68
48
  `}
69
49
  >
70
50
  <slot name="floatingActionButton" />
@@ -1,4 +1,5 @@
1
1
  import { Modifier } from "../../core/modifier/Modifier";
2
+ import { BoxAlignment } from "./Alignment";
2
3
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
4
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
5
  $$bindings?: Bindings;
@@ -20,7 +21,7 @@ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
20
21
  declare const Scaffold: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
21
22
  modifier?: Modifier;
22
23
  contentPadding?: number;
23
- fabAlignment?: "bottom-end" | "bottom-center" | "bottom-start";
24
+ fabAlignment?: BoxAlignment;
24
25
  }, {
25
26
  topBar: {};
26
27
  default: {};
@@ -0,0 +1,4 @@
1
+ import { ModifierImpl } from "../../core/modifier/ModifierImpl";
2
+ import { BoxAlignment } from "./Alignment";
3
+ export declare function resolveBoxAlignment(alignment?: BoxAlignment): string;
4
+ export declare function resolveFlexAlignment(mod: ModifierImpl): string;
@@ -0,0 +1,44 @@
1
+ /* =========================
2
+ * Box (position:absolute)
3
+ * ========================= */
4
+ export function resolveBoxAlignment(alignment) {
5
+ var _a;
6
+ if (!alignment)
7
+ return "";
8
+ var parts = alignment.split(" ");
9
+ var h = parts[0];
10
+ var v = (_a = parts[1]) !== null && _a !== void 0 ? _a : parts[0];
11
+ var style = "position:absolute;";
12
+ // Vertical
13
+ if (v === "flex-start")
14
+ style += "top:0;";
15
+ else if (v === "flex-end")
16
+ style += "bottom:0;";
17
+ else
18
+ style += "top:50%;";
19
+ // Horizontal
20
+ if (h === "flex-start")
21
+ style += "left:0;";
22
+ else if (h === "flex-end")
23
+ style += "right:0;";
24
+ else
25
+ style += "left:50%;";
26
+ if (h === "center" || v === "center") {
27
+ style += "transform:translate(-50%,-50%);";
28
+ }
29
+ return style;
30
+ }
31
+ /* =========================
32
+ * Flex (Row / Column)
33
+ * ========================= */
34
+ export function resolveFlexAlignment(mod) {
35
+ var align = mod.getMeta().align;
36
+ if (!align)
37
+ return "";
38
+ var horizontal = align.split(" ")[0];
39
+ return "\n align-self:".concat(horizontal === "center"
40
+ ? "center"
41
+ : horizontal === "flex-end"
42
+ ? "flex-end"
43
+ : "flex-start", ";\n ");
44
+ }
@@ -0,0 +1,2 @@
1
+ import { BoxAlignment } from "./Alignment";
2
+ export declare function resolveFlexAlignSelf(alignment: BoxAlignment): string;
@@ -0,0 +1,10 @@
1
+ export function resolveFlexAlignSelf(alignment) {
2
+ var _a;
3
+ var parts = alignment.split(" ");
4
+ var vertical = (_a = parts[1]) !== null && _a !== void 0 ? _a : parts[0];
5
+ if (vertical === "flex-start")
6
+ return "align-self:flex-start;";
7
+ if (vertical === "flex-end")
8
+ return "align-self:flex-end;";
9
+ return "align-self:center;";
10
+ }
@@ -1,38 +1,32 @@
1
1
  import type { BoxAlignment } from "../../components/layouts/Alignment";
2
2
  import type { Shape } from "../shapes/Shape";
3
3
  import type { ColorToken } from "../theme/ColorScheme";
4
+ export type ModifierMeta = {
5
+ align?: BoxAlignment;
6
+ };
4
7
  export type ModifierEntry = {
5
8
  className?: string;
6
9
  style?: string;
10
+ meta?: ModifierMeta;
7
11
  };
8
12
  export declare class ModifierImpl {
9
13
  private readonly entries;
10
14
  constructor(entries?: ModifierEntry[]);
11
15
  then(other: ModifierImpl): ModifierImpl;
12
- paddingHorizontal(value: number): ModifierImpl;
13
- verticalScroll(enabled?: boolean): ModifierImpl;
14
- horizontalScroll(enabled?: boolean): ModifierImpl;
15
- paddingVertical(value: number): ModifierImpl;
16
16
  fillMaxWidth(): ModifierImpl;
17
17
  fillMaxHeight(): ModifierImpl;
18
18
  fillMaxSize(): ModifierImpl;
19
- background(color: ColorToken | string): ModifierImpl;
20
19
  weight(weight: number, fill?: boolean): ModifierImpl;
21
- align(alignment: BoxAlignment): ModifierImpl;
22
- padding(valueOrParams?: number | {
23
- top?: number;
24
- bottom?: number;
25
- start?: number;
26
- end?: number;
27
- }, unit?: string): ModifierImpl;
28
- width(value: number | string, unit?: string): ModifierImpl;
29
- height(value: number | string, unit?: string): ModifierImpl;
30
- marginTop(value: number, unit?: string): ModifierImpl;
31
- clip(shape: Shape): ModifierImpl;
32
- size(value: number | string, unit?: string): ModifierImpl;
33
- offset(x: number, y: number): ModifierImpl;
34
- clickable(onClick: () => void): ModifierImpl;
20
+ padding(value: number): ModifierImpl;
21
+ paddingHorizontal(value: number): ModifierImpl;
22
+ paddingVertical(value: number): ModifierImpl;
23
+ marginTop(value: number): ModifierImpl;
24
+ background(color: ColorToken | string): ModifierImpl;
35
25
  border(width: number, color: string, shape?: Shape): ModifierImpl;
26
+ clip(shape: Shape): ModifierImpl;
27
+ align(alignment: BoxAlignment): ModifierImpl;
28
+ clickable(): ModifierImpl;
36
29
  toStyle(): string;
37
30
  toClass(): string;
31
+ getMeta(): ModifierMeta;
38
32
  }
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
13
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
14
  if (ar || !(i in from)) {
@@ -8,40 +19,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
19
  return to.concat(ar || Array.prototype.slice.call(from));
9
20
  };
10
21
  import { resolveColor } from "../theme/resolve";
22
+ /* =========================
23
+ * ModifierImpl
24
+ * ========================= */
11
25
  var ModifierImpl = /** @class */ (function () {
12
26
  function ModifierImpl(entries) {
13
27
  if (entries === void 0) { entries = []; }
14
28
  this.entries = entries;
15
29
  }
30
+ /* -------- composición -------- */
16
31
  ModifierImpl.prototype.then = function (other) {
17
32
  return new ModifierImpl(__spreadArray(__spreadArray([], this.entries, true), other.entries, true));
18
33
  };
19
- ModifierImpl.prototype.paddingHorizontal = function (value) {
20
- return this.then(new ModifierImpl([
21
- { style: "padding-left:".concat(value, "px;padding-right:").concat(value, "px;") },
22
- ]));
23
- };
24
- ModifierImpl.prototype.verticalScroll = function (enabled) {
25
- if (enabled === void 0) { enabled = true; }
26
- return this.then(new ModifierImpl([{
27
- style: enabled
28
- ? "overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;"
29
- : ''
30
- }]));
31
- };
32
- ModifierImpl.prototype.horizontalScroll = function (enabled) {
33
- if (enabled === void 0) { enabled = true; }
34
- return this.then(new ModifierImpl([{
35
- style: enabled
36
- ? "overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;white-space:nowrap;"
37
- : ''
38
- }]));
39
- };
40
- ModifierImpl.prototype.paddingVertical = function (value) {
41
- return this.then(new ModifierImpl([
42
- { style: "padding-top:".concat(value, "px;padding-bottom:").concat(value, "px;") },
43
- ]));
44
- };
34
+ /* -------- layout size -------- */
45
35
  ModifierImpl.prototype.fillMaxWidth = function () {
46
36
  return this.then(new ModifierImpl([{ style: "width:100%;" }]));
47
37
  };
@@ -51,164 +41,86 @@ var ModifierImpl = /** @class */ (function () {
51
41
  ModifierImpl.prototype.fillMaxSize = function () {
52
42
  return this.then(new ModifierImpl([{ style: "width:100%;height:100%;" }]));
53
43
  };
54
- ModifierImpl.prototype.background = function (color) {
55
- var resolved;
56
- if (typeof color === "string" &&
57
- (color.startsWith("#") ||
58
- color.startsWith("rgb") ||
59
- color.startsWith("hsl") ||
60
- color === "transparent" ||
61
- color === "currentColor")) {
62
- // Color CSS directo
63
- resolved = color;
64
- }
65
- else {
66
- // Token de ComposeTheme
67
- resolved = resolveColor(color);
68
- }
69
- return this.then(new ModifierImpl([
70
- { style: "background:".concat(resolved, ";") }
71
- ]));
72
- };
73
44
  ModifierImpl.prototype.weight = function (weight, fill) {
74
45
  if (fill === void 0) { fill = true; }
75
- if (weight <= 0) {
76
- console.warn("Modifier.weight() debe ser > 0");
46
+ if (weight <= 0)
77
47
  return this;
78
- }
79
- var styleParts = [
80
- "flex-grow: ".concat(weight, ";"),
81
- "flex-shrink: ".concat(fill ? 1 : 0, ";"),
82
- "flex-basis: 0%;" // importante para que el peso funcione bien
83
- ];
84
- return this.then(new ModifierImpl([{ style: styleParts.join(" ") }]));
85
- };
86
- ModifierImpl.prototype.align = function (alignment) {
87
- var parts = alignment.split(' ');
88
- var horizontal = parts[0]; // flex-start, center, flex-end
89
- var vertical = parts[1] || parts[0]; // para casos simples como "center"
90
- var style = 'position: absolute;';
91
- // Vertical
92
- if (vertical === 'flex-start') {
93
- style += 'top: 0;';
94
- }
95
- else if (vertical === 'flex-end') {
96
- style += 'bottom: 0;';
97
- }
98
- else if (vertical === 'center') {
99
- style += 'top: 50%; transform: translateY(-50%);';
100
- }
101
- // Horizontal
102
- if (horizontal === 'flex-start') {
103
- style += 'left: 0;';
104
- }
105
- else if (horizontal === 'flex-end') {
106
- style += 'right: 0;';
107
- }
108
- else if (horizontal === 'center') {
109
- style += 'left: 50%;';
110
- // Combinar transform si ya hay translateY
111
- if (style.includes('translateY')) {
112
- style = style.replace('translateY(-50%)', 'translate(-50%, -50%)');
113
- }
114
- else {
115
- style += 'transform: translateX(-50%);';
116
- }
117
- }
118
- return this.then(new ModifierImpl([{ style: style }]));
119
- };
120
- ModifierImpl.prototype.padding = function (valueOrParams, unit) {
121
- if (valueOrParams === void 0) { valueOrParams = 0; }
122
- if (unit === void 0) { unit = 'px'; }
123
- var style = '';
124
- if (typeof valueOrParams === 'number') {
125
- // Padding uniforme
126
- style = "padding:".concat(valueOrParams).concat(unit, ";");
127
- }
128
- else {
129
- // Padding direccional
130
- var _a = valueOrParams.top, top = _a === void 0 ? 0 : _a, _b = valueOrParams.bottom, bottom = _b === void 0 ? 0 : _b, _c = valueOrParams.start, start = _c === void 0 ? 0 : _c, _d = valueOrParams.end, end = _d === void 0 ? 0 : _d;
131
- style = "\n padding-top:".concat(top).concat(unit, ";\n padding-bottom:").concat(bottom).concat(unit, ";\n padding-left:").concat(start).concat(unit, ";\n //padding-right:").concat(end).concat(unit, ";\n ").trim();
132
- }
133
- return this.then(new ModifierImpl([{ style: style }]));
134
- };
135
- ModifierImpl.prototype.width = function (value, unit) {
136
- if (unit === void 0) { unit = 'px'; }
137
- var size = typeof value === 'number' ? "".concat(value).concat(unit) : value;
138
- return this.then(new ModifierImpl([{ style: "width:".concat(size, ";") }]));
48
+ return this.then(new ModifierImpl([
49
+ {
50
+ style: "\n flex-grow:".concat(weight, ";\n flex-shrink:").concat(fill ? 1 : 0, ";\n flex-basis:0%;\n "),
51
+ },
52
+ ]));
139
53
  };
140
- ModifierImpl.prototype.height = function (value, unit) {
141
- if (unit === void 0) { unit = 'px'; }
142
- var size = typeof value === 'number' ? "".concat(value).concat(unit) : value;
143
- return this.then(new ModifierImpl([{ style: "height:".concat(size, ";") }]));
54
+ /* -------- padding / margin -------- */
55
+ ModifierImpl.prototype.padding = function (value) {
56
+ return this.then(new ModifierImpl([{ style: "padding:".concat(value, "px;") }]));
144
57
  };
145
- ModifierImpl.prototype.marginTop = function (value, unit) {
146
- if (unit === void 0) { unit = 'px'; }
147
- return this.then(new ModifierImpl([{ style: "margin-top:".concat(value).concat(unit, ";") }]));
58
+ ModifierImpl.prototype.paddingHorizontal = function (value) {
59
+ return this.then(new ModifierImpl([
60
+ { style: "padding-left:".concat(value, "px;padding-right:").concat(value, "px;") },
61
+ ]));
148
62
  };
149
- ModifierImpl.prototype.clip = function (shape) {
63
+ ModifierImpl.prototype.paddingVertical = function (value) {
150
64
  return this.then(new ModifierImpl([
151
- {
152
- style: "\n border-radius:".concat(shape.toCssBorderRadius(), ";\n overflow:hidden;\n ")
153
- }
65
+ { style: "padding-top:".concat(value, "px;padding-bottom:").concat(value, "px;") },
154
66
  ]));
155
67
  };
156
- ModifierImpl.prototype.size = function (value, unit) {
157
- if (unit === void 0) { unit = "px"; }
158
- if (value === null || value === undefined) {
68
+ ModifierImpl.prototype.marginTop = function (value) {
69
+ return this.then(new ModifierImpl([{ style: "margin-top:".concat(value, "px;") }]));
70
+ };
71
+ /* -------- background / border -------- */
72
+ ModifierImpl.prototype.background = function (color) {
73
+ var resolved = typeof color === "string"
74
+ ? color
75
+ : resolveColor(color);
76
+ return this.then(new ModifierImpl([{ style: "background:".concat(resolved, ";") }]));
77
+ };
78
+ ModifierImpl.prototype.border = function (width, color, shape) {
79
+ if (width <= 0)
159
80
  return this;
160
- }
161
- var resolved;
162
- if (typeof value === "number") {
163
- if (isNaN(value))
164
- return this;
165
- resolved = "".concat(value).concat(unit);
166
- }
167
- else {
168
- if (value.trim() === "")
169
- return this;
170
- resolved = value;
171
- }
172
81
  return this.then(new ModifierImpl([
173
82
  {
174
- style: "width:".concat(resolved, ";height:").concat(resolved, ";")
175
- }
83
+ style: "\n border:".concat(width, "px solid ").concat(color, ";\n ").concat(shape ? "border-radius:".concat(shape.toCssBorderRadius(), ";") : "", "\n "),
84
+ },
176
85
  ]));
177
86
  };
178
- ModifierImpl.prototype.offset = function (x, y) {
179
- if (isNaN(x) || isNaN(y))
180
- return this;
87
+ ModifierImpl.prototype.clip = function (shape) {
181
88
  return this.then(new ModifierImpl([
182
89
  {
183
- style: "transform: translate(".concat(x, "px, ").concat(y, "px);")
184
- }
90
+ style: "\n border-radius:".concat(shape.toCssBorderRadius(), ";\n overflow:hidden;\n "),
91
+ },
185
92
  ]));
186
93
  };
187
- ModifierImpl.prototype.clickable = function (onClick) {
94
+ /* -------- posicionamiento semántico -------- */
95
+ ModifierImpl.prototype.align = function (alignment) {
188
96
  return this.then(new ModifierImpl([
189
97
  {
190
- className: "compose-clickable",
191
- style: "\n cursor: pointer;\n user-select: none;\n "
98
+ meta: { align: alignment }
192
99
  }
193
100
  ]));
194
101
  };
195
- ModifierImpl.prototype.border = function (width, color, shape) {
196
- if (width <= 0)
197
- return this;
198
- var radius = shape ? shape.toCssBorderRadius() : undefined;
102
+ /* -------- interacción -------- */
103
+ ModifierImpl.prototype.clickable = function () {
199
104
  return this.then(new ModifierImpl([
200
105
  {
201
- style: "\n border:".concat(width, "px solid ").concat(color, ";\n ").concat(radius ? "border-radius:".concat(radius, ";") : "", "\n ")
202
- }
106
+ className: "compose-clickable",
107
+ style: "cursor:pointer;user-select:none;",
108
+ },
203
109
  ]));
204
110
  };
205
- // ---- consumo interno ----
111
+ /* -------- consumo interno -------- */
206
112
  ModifierImpl.prototype.toStyle = function () {
207
113
  return this.entries.map(function (e) { var _a; return (_a = e.style) !== null && _a !== void 0 ? _a : ""; }).join("");
208
114
  };
209
115
  ModifierImpl.prototype.toClass = function () {
210
116
  return this.entries.map(function (e) { var _a; return (_a = e.className) !== null && _a !== void 0 ? _a : ""; }).join(" ");
211
117
  };
118
+ ModifierImpl.prototype.getMeta = function () {
119
+ return this.entries.reduce(function (acc, e) {
120
+ var _a;
121
+ return (__assign(__assign({}, acc), ((_a = e.meta) !== null && _a !== void 0 ? _a : {})));
122
+ }, {});
123
+ };
212
124
  return ModifierImpl;
213
125
  }());
214
126
  export { ModifierImpl };
@@ -0,0 +1,49 @@
1
+ /* compose-svelted baseline.css */
2
+
3
+ /* 1. Modelo de caja consistente */
4
+ *, *::before, *::after {
5
+ box-sizing: border-box;
6
+ }
7
+
8
+ /* 2. Root layout estable */
9
+ html, body {
10
+ margin: 0;
11
+ padding: 0;
12
+ width: 100%;
13
+ height: 100%;
14
+ }
15
+
16
+ /* 3. Host de la app */
17
+ #app, body > div {
18
+ width: 100%;
19
+ height: 100%;
20
+ }
21
+
22
+ /* 4. Prevención de colapso en flex */
23
+ * {
24
+ min-width: 0;
25
+ min-height: 0;
26
+ }
27
+
28
+ /* 5. Soporte para absolute alignment */
29
+ .compose-relative {
30
+ position: relative;
31
+ }
32
+
33
+ /* 6. Clickable base */
34
+ .compose-clickable {
35
+ cursor: pointer;
36
+ user-select: none;
37
+ }
38
+
39
+ /* 7. Evitar interferencia de estilos externos */
40
+ img, svg, video, canvas {
41
+ display: block;
42
+ max-width: 100%;
43
+ }
44
+
45
+ .compose-lazy-row,
46
+ .compose-lazy-column {
47
+ min-width: 0;
48
+ min-height: 0;
49
+ }
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "./core/styles/baseline.css";
1
2
  // Root
2
3
  export { default as ComposeTheme } from "./core/theme/ComposeTheme.svelte";
3
4
  export { default as AppRoot } from "./components/AppRoot.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielito1996/compose-svelted",
3
- "version": "0.2.7-alpha01",
3
+ "version": "0.2.7-alpha03",
4
4
  "description": "Compose-like UI toolkit for Svelte, inspired by Jetpack Compose",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,7 +18,8 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "import": "./dist/index.js",
20
20
  "svelte": "./dist/index.js"
21
- }
21
+ },
22
+ "./baseline.css": "./dist/core/styles/baseline.css"
22
23
  },
23
24
  "files": [
24
25
  "dist"