milk-lib 0.0.2 → 0.0.4

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,15 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ let { children }: { children: Snippet } = $props();
4
+ </script>
5
+
6
+ <li class="SidebarGroupTitle">{@render children()}</li>
7
+
8
+ <style>
9
+ .SidebarGroupTitle {
10
+ font-size: 12px;
11
+ color: #333;
12
+ font-weight: 500;
13
+ margin-top: 1.5rem;
14
+ }
15
+ </style>
@@ -0,0 +1,7 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ };
5
+ declare const SidebarGroupTitle: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type SidebarGroupTitle = ReturnType<typeof SidebarGroupTitle>;
7
+ export default SidebarGroupTitle;
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ let { children, link }: { children: Snippet; link: string } = $props();
4
+ </script>
5
+
6
+ <li>
7
+ <a href={link} class="SidebarLink">
8
+ {@render children()}
9
+ </a>
10
+ </li>
11
+
12
+ <style>
13
+ .SidebarLink {
14
+ font-size: 12px;
15
+ color: #777;
16
+ }
17
+
18
+ .SidebarLink:hover {
19
+ text-decoration: underline;
20
+ }
21
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ link: string;
5
+ };
6
+ declare const SidebarLink: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type SidebarLink = ReturnType<typeof SidebarLink>;
8
+ export default SidebarLink;
@@ -0,0 +1,2 @@
1
+ export { default as SidebarGroupTitle } from './SidebarGroupTitle.svelte';
2
+ export { default as SidebarLink } from './SidebarLink.svelte';
@@ -0,0 +1,2 @@
1
+ export { default as SidebarGroupTitle } from './SidebarGroupTitle.svelte';
2
+ export { default as SidebarLink } from './SidebarLink.svelte';
@@ -0,0 +1,111 @@
1
+ <svelte:window bind:innerWidth bind:innerHeight bind:scrollY />
2
+
3
+ <script lang="ts">
4
+
5
+ import { onMount } from 'svelte';
6
+
7
+ let height = $state(0);
8
+ let stickyHeaderContent = $state<HTMLElement | null>(null);
9
+ let innerWidth = $state(0);
10
+ let innerHeight = $state(0);
11
+ let scrollY = $state(0);
12
+
13
+ // visibility state
14
+ let isVisible = $state(true);
15
+ let lastY = $state(0);
16
+ let downAccum = $state(0);
17
+ let upAccum = $state(0);
18
+
19
+ // настройки чувствительности
20
+ const SHOW_THRESHOLD = 12; // сколько пикселей нужно прокрутить вверх, чтобы показать
21
+ const HIDE_THRESHOLD = 24; // сколько пикселей нужно прокрутить вниз, чтобы спрятать
22
+ const AT_TOP_SHADOW_CUTOFF = 1; // когда ~в самом верху — без тени
23
+
24
+ let { children } = $props();
25
+
26
+ const updateWrapperSize = () => {
27
+ height = stickyHeaderContent?.getBoundingClientRect?.().height || 0;
28
+ }
29
+
30
+ $effect(() => {
31
+ if (innerWidth && innerHeight) { updateWrapperSize() }
32
+ });
33
+
34
+ onMount(() => {
35
+ updateWrapperSize();
36
+ });
37
+
38
+ $effect(() => {
39
+ const delta = scrollY - lastY;
40
+
41
+ // всегда показываем у самого верха
42
+ if (scrollY <= 0) {
43
+ isVisible = true;
44
+ downAccum = upAccum = 0;
45
+ lastY = scrollY;
46
+ return;
47
+ }
48
+
49
+ // avoid twitch
50
+ if (Math.abs(delta) < 2) {
51
+ lastY = scrollY;
52
+ return;
53
+ }
54
+
55
+ if (delta > 0) {
56
+ // scroll down
57
+ downAccum += delta;
58
+ upAccum = 0;
59
+ if (downAccum >= HIDE_THRESHOLD) isVisible = false;
60
+ } else {
61
+ // scroll up
62
+ upAccum += -delta;
63
+ downAccum = 0;
64
+ if (upAccum >= SHOW_THRESHOLD) isVisible = true;
65
+ }
66
+
67
+ lastY = scrollY;
68
+ });
69
+
70
+ </script>
71
+
72
+
73
+
74
+ <div class="StickyHeader">
75
+
76
+ <div
77
+ class="StickyHeaderPosition"
78
+ class:isVisible={isVisible}
79
+ class:StickyHeaderShadow={scrollY > 0}
80
+ id="StickyHeaderPosition"
81
+ >
82
+ <div class="StickyHeaderContent" bind:this={stickyHeaderContent}>
83
+ {@render children()}
84
+ </div>
85
+ </div>
86
+
87
+ <div class="StickyHeaderStub" style={`height: ${height}px`}></div>
88
+ </div>
89
+
90
+ <style>@charset "UTF-8";
91
+ .StickyHeader .StickyHeaderPosition {
92
+ position: fixed;
93
+ top: 0;
94
+ left: 0;
95
+ width: 100%;
96
+ z-index: var(--zindex-sticky);
97
+ background: white;
98
+ /* по умолчанию спрятан вверх */
99
+ transform: translateY(-100%);
100
+ transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
101
+ will-change: transform;
102
+ }
103
+ .StickyHeader .StickyHeaderPosition.isVisible {
104
+ transform: translateY(0);
105
+ }
106
+ .StickyHeader .StickyHeaderPosition.StickyHeaderShadow {
107
+ box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
108
+ }
109
+ .StickyHeader {
110
+ /* высота задаётся инлайном из скрипта */
111
+ }</style>
@@ -0,0 +1,5 @@
1
+ declare const StickyHeader: import("svelte").Component<{
2
+ children: any;
3
+ }, {}, "">;
4
+ type StickyHeader = ReturnType<typeof StickyHeader>;
5
+ export default StickyHeader;
@@ -0,0 +1 @@
1
+ export { default as StickyHeader } from './StickyHeader.svelte';
@@ -0,0 +1 @@
1
+ export { default as StickyHeader } from './StickyHeader.svelte';
@@ -1,2 +1,4 @@
1
1
  export * from './TestComponent';
2
2
  export * from './Menu';
3
+ export * from './StickyHeader';
4
+ export * from './Sidebar';
@@ -1,2 +1,4 @@
1
1
  export * from './TestComponent';
2
2
  export * from './Menu';
3
+ export * from './StickyHeader';
4
+ export * from './Sidebar';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "milk-lib",
3
3
  "license": "MIT",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && npm run prepack",