@inizioevoke/astro-core 1.6.5 → 2.0.0

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.
Files changed (32) hide show
  1. package/package.json +3 -5
  2. package/src/components/FlipCard/FlipCard.ts +15 -9
  3. package/src/components/ISI/{RightISI.astro → Right/RightISI.astro} +16 -9
  4. package/src/components/ISI/Right/RightISI.css +61 -0
  5. package/src/components/ISI/{RightISI.md → Right/RightISI.md} +0 -1
  6. package/src/components/ISI/Right/RightISI.ts +78 -0
  7. package/src/components/ISI/Right/index.ts +1 -0
  8. package/src/components/ISI/index.ts +5 -0
  9. package/src/components/Modal/Modal.astro +11 -5
  10. package/src/components/Modal/Modal.css +49 -39
  11. package/src/components/Modal/Modal.ts +186 -169
  12. package/src/components/PdfViewer/PdfViewer.astro +6 -3
  13. package/src/components/PdfViewer/PdfViewer.css +5 -3
  14. package/src/components/PdfViewer/PdfViewer.ts +226 -198
  15. package/src/components/ScrollContainer/ScrollContainer.ts +23 -2
  16. package/src/components/index.ts +1 -0
  17. package/src/lib/gestures/index.ts +2 -0
  18. package/src/lib/gestures/pinch.ts +66 -0
  19. package/src/lib/gestures/swipe.ts +153 -0
  20. package/src/lib/index.ts +2 -0
  21. package/src/components/ISI/RightISI.css +0 -31
  22. package/src/components/ISI/RightISI.ts +0 -27
  23. package/src/components/Modal/v2/Modal.astro +0 -42
  24. package/src/components/Modal/v2/Modal.css +0 -155
  25. package/src/components/Modal/v2/Modal.ts +0 -219
  26. package/src/components/Modal/v2/ModalOverlay.astro +0 -14
  27. package/src/components/Modal/v2/ModalTrigger.astro +0 -29
  28. package/src/components/Modal/v2/index.ts +0 -1
  29. package/src/components/ScrollContainer/archive-20260417.ts +0 -150
  30. package/src/components/v2.ts +0 -3
  31. package/src/lib/swipe.ts +0 -109
  32. package/src/lib/v2.ts +0 -1
@@ -1,150 +0,0 @@
1
-
2
- export interface IScrollContainer {
3
- container: HTMLElement;
4
- content: HTMLElement;
5
- track: HTMLElement;
6
- thumb: HTMLElement;
7
- isDragging: boolean;
8
- startY: number;
9
- startScrollTop: number;
10
- }
11
-
12
- export function resize(scrollContainer: IScrollContainer, { height }: { height?: number }) {
13
- if (typeof height == 'number') {
14
- scrollContainer.container.style.height = `${height}px`;
15
- refresh(scrollContainer);
16
- }
17
- }
18
-
19
- export function refresh(scrollContainer?: IScrollContainer) {
20
- if (scrollContainer) {
21
- updateThumbSize(scrollContainer);
22
- } else {
23
- [...scrollContainers.values()].forEach((scrollContainer) => {
24
- updateThumbSize(scrollContainer);
25
- });
26
- }
27
- }
28
-
29
- export function getScroll(scrollContainer: IScrollContainer): { left: number, top: number } {
30
- return {
31
- left: scrollContainer.content.scrollLeft,
32
- top: scrollContainer.content.scrollTop
33
- };
34
- }
35
- export function scroll(scrollContainer: IScrollContainer, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
36
- const current = getScroll(scrollContainer);
37
- scrollContainer.content.scroll({ left: left ?? current.left, top: top ?? current.top, behavior });
38
- }
39
-
40
- export function getScrollContainer(selector: string | HTMLElement): IScrollContainer | undefined {
41
- const key = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
42
- return key ? scrollContainers.get(key) : undefined;
43
- }
44
-
45
- function thumbMouseDown(scrollContainer: IScrollContainer, e: MouseEvent) {
46
- scrollContainer.isDragging = true;
47
- scrollContainer.startY = e.clientY;
48
- scrollContainer.startScrollTop = scrollContainer.content.scrollTop;
49
- scrollContainer.thumb.style.cursor = 'grabbing';
50
- }
51
-
52
- function updateThumbSize(scrollContainer: IScrollContainer) {
53
- const { container, content, thumb, track } = scrollContainer;
54
- const scrollHeight = content.scrollHeight - getPaddingY(content);
55
- const containerHeight = container.clientHeight - getPaddingY(container);
56
- const visibleRatio = containerHeight / scrollHeight;
57
- const thumbHeight = visibleRatio * containerHeight;
58
- thumb.style.height = `${thumbHeight > 20 ? thumbHeight : 20}px`;
59
- track.style.display = visibleRatio < 1 ? 'block' : 'none';
60
- }
61
-
62
- function scrollContent(scrollContainer: IScrollContainer) {
63
- const { container, content, thumb, track } = scrollContainer;
64
- const scrollHeight = content.scrollHeight - getPaddingY(content);
65
- const containerHeight = container.clientHeight - getPaddingY(container);
66
- const scrollRatio = content.scrollTop / (scrollHeight - containerHeight);
67
- const top = scrollRatio * (track.clientHeight - thumb.clientHeight);
68
- thumb.style.top = `${top}px`;
69
- }
70
-
71
- function getPaddingY(content: HTMLElement): number {
72
- const style = getComputedStyle(content);
73
- return parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
74
- }
75
-
76
- function getScrollContainerElement(element: HTMLElement) {
77
- let container = element;
78
- while (container && !container.classList.contains('scroll-container')) {
79
- container = container.parentElement as HTMLElement;
80
- }
81
- return container;
82
- }
83
-
84
- function createScrollContainer(container: HTMLElement): IScrollContainer {
85
- return {
86
- container: container,
87
- content: container.querySelector('.evo-scroll-content') as HTMLElement,
88
- track: container.querySelector('.evo-scroll-track') as HTMLElement,
89
- thumb: container.querySelector('.evo-scroll-thumb') as HTMLElement,
90
- isDragging: false,
91
- startY: 0,
92
- startScrollTop: 0
93
- };
94
- }
95
-
96
- const scrollContainers = new Map<HTMLElement, IScrollContainer>();
97
-
98
- const intersectionObserver = new IntersectionObserver((entries) => {
99
- entries.forEach((entry) => {
100
- if (entry.isIntersecting) {
101
- updateThumbSize(scrollContainers.get(entry.target as HTMLElement) as IScrollContainer);
102
- }
103
- });
104
- },
105
- { threshold: 0.1 }
106
- );
107
-
108
- const mutationObserver = new MutationObserver((mutations) => {
109
- const containers: IScrollContainer[] = [];
110
- mutations.forEach((mutation) => {
111
- const sc = scrollContainers.get(getScrollContainerElement(mutation.target as HTMLElement));
112
- if (sc && !containers.includes(sc)) {
113
- containers.push(sc);
114
- }
115
- });
116
- containers.forEach((container) => {
117
- updateThumbSize(container);
118
- });
119
- });
120
-
121
- document.querySelectorAll<HTMLElement>('.evo-scroll-container').forEach((container) => {
122
- const scrollContainer = createScrollContainer(container);
123
- scrollContainers.set(container, scrollContainer);
124
- scrollContainer.thumb.addEventListener('mousedown', (e) => { thumbMouseDown(scrollContainer, e); }, { passive: true });
125
- scrollContainer.content.addEventListener('scroll', (e) => { scrollContent(scrollContainer); }, { passive: true });
126
- intersectionObserver.observe(container);
127
- mutationObserver.observe(container, { childList: true, subtree: true });
128
- });
129
- document.addEventListener('mousemove', (e) => {
130
- [...scrollContainers.values()].forEach((scrollContainer) => {
131
- if (!scrollContainer.isDragging) return;
132
- const { container, content, thumb } = scrollContainer;
133
- const deltaY = e.clientY - scrollContainer.startY;
134
- const scrollRatio =
135
- (content.scrollHeight - container.clientHeight) /
136
- (container.clientHeight - thumb.clientHeight);
137
- scrollContainer.content.scrollTop = scrollContainer.startScrollTop + deltaY * scrollRatio;
138
- });
139
- });
140
- document.addEventListener('mouseup', () => {
141
- [...scrollContainers.values()].forEach((scrollContainer) => {
142
- scrollContainer.isDragging = false;
143
- scrollContainer.thumb.style.cursor = 'grab';
144
- });
145
- });
146
- window.addEventListener('resize', () => {
147
- [...scrollContainers.values()].forEach((scrollContainer) => {
148
- updateThumbSize(scrollContainer);
149
- });
150
- });
@@ -1,3 +0,0 @@
1
- export { default as Modal } from './Modal/v2/Modal.astro';
2
- export { default as ModalOverlay } from './Modal/v2/ModalOverlay.astro';
3
- export { default as ModalTrigger } from './Modal/v2/ModalTrigger.astro';
package/src/lib/swipe.ts DELETED
@@ -1,109 +0,0 @@
1
- export type SwipeDirection = 'left' | 'right' | 'up' | 'down';
2
- export type SwipeThreshold = '1/4' | '1/3' | '1/2' | number;
3
-
4
- export interface OnSwipeHandlerArgs {
5
- direction: SwipeDirection;
6
- threshold: number;
7
- distance: {
8
- x: number;
9
- y: number;
10
- },
11
- duration: number;
12
- }
13
- export type OnSwipeHandler = (args: OnSwipeHandlerArgs) => void;
14
-
15
- export interface SwipeController {
16
- enable: () => void;
17
- disable: () => void;
18
- dispose: () => void;
19
- }
20
-
21
- export default function onSwipe(direction: SwipeDirection, swipeThreshold: SwipeThreshold, handler: OnSwipeHandler): SwipeController {
22
- const threshold: number = typeof swipeThreshold == 'number' ? swipeThreshold : (() => {
23
- const ratios: Record<string, number> = { '1/4': 0.25, '1/3': 0.333, '1/2': 0.5 };
24
- switch (direction) {
25
- case 'up':
26
- case 'down':
27
- return Math.round(screen.height * (ratios[swipeThreshold] ?? ratios['1/3']));
28
- default:
29
- return Math.round(screen.width * (ratios[swipeThreshold] ?? ratios['1/3']));
30
- }
31
- })();
32
-
33
- let listening = false;
34
- let x: number = NaN;
35
- let y: number = NaN;
36
- let start: number = NaN;
37
-
38
- const handleSwipe = (deltaX: number, deltaY: number, duration: number) => {
39
- let flag = false;
40
- switch (direction) {
41
- case 'up':
42
- flag = Math.abs(deltaY) >= threshold && Math.abs(deltaX) < threshold && deltaY > 0;
43
- break;
44
- case 'down':
45
- flag = Math.abs(deltaY) >= threshold && Math.abs(deltaX) < threshold && deltaY < 0;
46
- break;
47
- case 'left':
48
- flag = Math.abs(deltaX) >= threshold && Math.abs(deltaY) < threshold && deltaX > 0;
49
- break;
50
- case 'right':
51
- flag = Math.abs(deltaX) >= threshold && Math.abs(deltaY) < threshold && deltaX < 0;
52
- break;
53
- }
54
- if (flag) {
55
- try {
56
- handler({ direction, threshold, distance: { x: deltaX, y: deltaY }, duration});
57
- } catch (err) {
58
- console.error(err);
59
- }
60
- }
61
- }
62
-
63
- const touchstart = (e: TouchEvent) => {
64
- if (!listening) return;
65
- if (e.touches.length === 1 && isNaN(x)) {
66
- start = performance.now();
67
- x = e.touches[0].clientX;
68
- y = e.touches[0].clientY;
69
- } else {
70
- start = NaN;
71
- x = NaN;
72
- y = NaN;
73
- }
74
- };
75
-
76
- const touchend = (e: TouchEvent) => {
77
- if (!listening) return;
78
- if (e.changedTouches.length === 1 && !isNaN(x) && !isNaN(y)) {
79
- const deltaX = x - e.changedTouches[0].clientX;
80
- const deltaY = y - e.changedTouches[0].clientY;
81
- handleSwipe(deltaX, deltaY, performance.now() - start);
82
- x = NaN;
83
- y = NaN;
84
- start = NaN;
85
- }
86
- };
87
-
88
- const enable = () => {
89
- if (!listening) {
90
- listening = true;
91
- window.addEventListener('touchstart', touchstart, { passive: true });
92
- window.addEventListener('touchend', touchend, { passive: true });
93
- }
94
- };
95
-
96
- const disable = () => {
97
- listening = false;
98
- window.removeEventListener('touchstart', touchstart);
99
- window.removeEventListener('touchend', touchend);
100
- };
101
-
102
- enable();
103
-
104
- return {
105
- enable,
106
- disable,
107
- dispose: disable
108
- };
109
- }
package/src/lib/v2.ts DELETED
@@ -1 +0,0 @@
1
- export * as Modal from '../components/Modal/v2/Modal';