@tableslayer/ui 0.1.22 → 0.1.24

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,7 +1,7 @@
1
1
  <script lang="ts">
2
- import { computePosition, offset, flip, shift, platform } from '@floating-ui/dom';
2
+ import { computePosition, offset, flip, shift, autoUpdate } from '@floating-ui/dom';
3
3
  import { Button, type ConfirmActionButtonProps } from './';
4
- import { tick, onDestroy } from 'svelte';
4
+ import { onDestroy } from 'svelte';
5
5
 
6
6
  let {
7
7
  trigger,
@@ -19,6 +19,7 @@
19
19
  let portalContainer: HTMLDivElement | null = null;
20
20
  let isShowingConfirm = $state(false);
21
21
  let floatingStyles = $state('');
22
+ let cleanupAutoUpdate: (() => void) | null = null;
22
23
 
23
24
  // Handle portal mounting
24
25
  $effect(() => {
@@ -36,16 +37,31 @@
36
37
  }
37
38
  });
38
39
 
40
+ // Set up autoUpdate when popover is shown
41
+ $effect(() => {
42
+ if (isShowingConfirm && triggerElement && popoverElement) {
43
+ cleanupAutoUpdate = autoUpdate(triggerElement, popoverElement, updatePosition);
44
+ }
45
+
46
+ return () => {
47
+ if (cleanupAutoUpdate) {
48
+ cleanupAutoUpdate();
49
+ cleanupAutoUpdate = null;
50
+ }
51
+ };
52
+ });
53
+
39
54
  onDestroy(() => {
40
55
  if (portalContainer?.parentNode) {
41
56
  portalContainer.parentNode.removeChild(portalContainer);
42
57
  }
58
+ if (cleanupAutoUpdate) {
59
+ cleanupAutoUpdate();
60
+ }
43
61
  });
44
62
 
45
63
  const toggleShowConfirm = async () => {
46
64
  isShowingConfirm = true;
47
- await tick();
48
- updatePosition();
49
65
  };
50
66
 
51
67
  const triggerProps = {
@@ -61,8 +77,11 @@
61
77
 
62
78
  computePosition(triggerElement, popoverElement, {
63
79
  placement: positioning?.placement,
64
- middleware: [offset(({ rects }) => -rects.reference.height / 2 - rects.floating.height / 2), flip(), shift()],
65
- platform
80
+ middleware: [
81
+ offset(({ rects }) => -rects.reference.height / 2 - rects.floating.height / 2),
82
+ flip({ boundary: document.body }),
83
+ shift({ padding: 8, crossAxis: true, boundary: document.body })
84
+ ]
66
85
  })
67
86
  .then(({ x, y, strategy }) => {
68
87
  floatingStyles = `position: ${strategy}; left: ${x}px; top: ${y}px;`;
@@ -1,81 +1,89 @@
1
1
  const DEFAULT_DURATION = 5000;
2
2
  class ToastManager {
3
- constructor() {
4
- this.toasts = $state([]);
5
- this.isPaused = $state(false);
6
- this.generateId = () => {
7
- return `toast-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
3
+ toasts = $state([]);
4
+ isPaused = $state(false);
5
+ generateId = () => {
6
+ return `toast-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
7
+ };
8
+ addToast = (input, duration = DEFAULT_DURATION) => {
9
+ // Handle backwards compatibility with old melt-ui format { data: { title, type, body } }
10
+ const data = 'data' in input && input.data && typeof input.data === 'object' && 'title' in input.data
11
+ ? input.data
12
+ : input;
13
+ const id = this.generateId();
14
+ const toast = {
15
+ id,
16
+ data,
17
+ timeout: null,
18
+ remainingTime: duration,
19
+ pausedAt: null
8
20
  };
9
- this.addToast = (input, duration = DEFAULT_DURATION) => {
10
- // Handle backwards compatibility with old melt-ui format { data: { title, type, body } }
11
- const data = 'data' in input && input.data && typeof input.data === 'object' && 'title' in input.data
12
- ? input.data
13
- : input;
14
- const id = this.generateId();
15
- const toast = {
16
- id,
17
- data,
18
- timeout: null,
19
- remainingTime: duration,
20
- pausedAt: null
21
- };
22
- if (data.type !== 'loading') {
23
- toast.timeout = setTimeout(() => {
24
- this.removeToast(id);
25
- }, duration);
26
- }
27
- this.toasts = [...this.toasts, toast];
28
- return id;
29
- };
30
- this.removeToast = (id) => {
31
- const toast = this.toasts.find((t) => t.id === id);
32
- if (toast === null || toast === void 0 ? void 0 : toast.timeout) {
21
+ if (data.type !== 'loading') {
22
+ toast.timeout = setTimeout(() => {
23
+ this.removeToast(id);
24
+ }, duration);
25
+ }
26
+ this.toasts = [...this.toasts, toast];
27
+ return id;
28
+ };
29
+ removeToast = (id) => {
30
+ const toast = this.toasts.find((t) => t.id === id);
31
+ if (toast?.timeout) {
32
+ clearTimeout(toast.timeout);
33
+ }
34
+ this.toasts = this.toasts.filter((t) => t.id !== id);
35
+ };
36
+ pauseAll = () => {
37
+ if (this.isPaused)
38
+ return;
39
+ this.isPaused = true;
40
+ this.toasts = this.toasts.map((toast) => {
41
+ if (toast.timeout) {
33
42
  clearTimeout(toast.timeout);
43
+ return {
44
+ ...toast,
45
+ timeout: null,
46
+ pausedAt: Date.now(),
47
+ remainingTime: toast.remainingTime - (toast.pausedAt ? 0 : Date.now() - (Date.now() - toast.remainingTime))
48
+ };
34
49
  }
35
- this.toasts = this.toasts.filter((t) => t.id !== id);
36
- };
37
- this.pauseAll = () => {
38
- if (this.isPaused)
39
- return;
40
- this.isPaused = true;
41
- this.toasts = this.toasts.map((toast) => {
42
- if (toast.timeout) {
43
- clearTimeout(toast.timeout);
44
- return Object.assign(Object.assign({}, toast), { timeout: null, pausedAt: Date.now(), remainingTime: toast.remainingTime - (toast.pausedAt ? 0 : Date.now() - (Date.now() - toast.remainingTime)) });
50
+ return { ...toast, pausedAt: Date.now() };
51
+ });
52
+ };
53
+ resumeAll = () => {
54
+ if (!this.isPaused)
55
+ return;
56
+ this.isPaused = false;
57
+ this.toasts = this.toasts.map((toast) => {
58
+ if (toast.data.type !== 'loading' && toast.pausedAt) {
59
+ const elapsed = Date.now() - toast.pausedAt;
60
+ const remaining = Math.max(0, toast.remainingTime - elapsed);
61
+ if (remaining > 0) {
62
+ return {
63
+ ...toast,
64
+ timeout: setTimeout(() => {
65
+ this.removeToast(toast.id);
66
+ }, remaining),
67
+ pausedAt: null,
68
+ remainingTime: remaining
69
+ };
45
70
  }
46
- return Object.assign(Object.assign({}, toast), { pausedAt: Date.now() });
47
- });
48
- };
49
- this.resumeAll = () => {
50
- if (!this.isPaused)
51
- return;
52
- this.isPaused = false;
53
- this.toasts = this.toasts.map((toast) => {
54
- if (toast.data.type !== 'loading' && toast.pausedAt) {
55
- const elapsed = Date.now() - toast.pausedAt;
56
- const remaining = Math.max(0, toast.remainingTime - elapsed);
57
- if (remaining > 0) {
58
- return Object.assign(Object.assign({}, toast), { timeout: setTimeout(() => {
59
- this.removeToast(toast.id);
60
- }, remaining), pausedAt: null, remainingTime: remaining });
61
- }
62
- else {
63
- setTimeout(() => this.removeToast(toast.id), 0);
64
- return toast;
65
- }
71
+ else {
72
+ setTimeout(() => this.removeToast(toast.id), 0);
73
+ return toast;
66
74
  }
67
- return Object.assign(Object.assign({}, toast), { pausedAt: null });
68
- });
69
- };
70
- this.updateToast = (id, data) => {
71
- this.toasts = this.toasts.map((toast) => {
72
- if (toast.id === id) {
73
- return Object.assign(Object.assign({}, toast), { data: Object.assign(Object.assign({}, toast.data), data) });
74
- }
75
- return toast;
76
- });
77
- };
78
- }
75
+ }
76
+ return { ...toast, pausedAt: null };
77
+ });
78
+ };
79
+ updateToast = (id, data) => {
80
+ this.toasts = this.toasts.map((toast) => {
81
+ if (toast.id === id) {
82
+ return { ...toast, data: { ...toast.data, ...data } };
83
+ }
84
+ return toast;
85
+ });
86
+ };
79
87
  }
80
88
  export const toastManager = new ToastManager();
81
89
  export const addToast = toastManager.addToast;
package/dist/utils/rle.js CHANGED
@@ -2,15 +2,6 @@
2
2
  * Run-Length Encoding utilities for binary mask compression
3
3
  * Optimized for fog and annotation layers
4
4
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  /**
15
6
  * Encodes a binary mask using Run-Length Encoding
16
7
  * @param data - Binary mask data (Uint8Array where each byte is 0 or 255)
@@ -102,43 +93,41 @@ function readVarint(array, index) {
102
93
  * @param height - Image height
103
94
  * @returns RLE encoded data
104
95
  */
105
- export function pngToRLE(blob, width, height) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- // Create an off-screen canvas
108
- const canvas = document.createElement('canvas');
109
- canvas.width = width;
110
- canvas.height = height;
111
- const ctx = canvas.getContext('2d');
112
- if (!ctx) {
113
- throw new Error('Failed to get canvas context');
114
- }
115
- // Load the image
116
- const img = new Image();
117
- const url = URL.createObjectURL(blob);
118
- try {
119
- yield new Promise((resolve, reject) => {
120
- img.onload = resolve;
121
- img.onerror = reject;
122
- img.src = url;
123
- });
124
- // Draw image to canvas
125
- ctx.drawImage(img, 0, 0, width, height);
126
- // Get image data
127
- const imageData = ctx.getImageData(0, 0, width, height);
128
- const pixels = imageData.data;
129
- // Convert RGBA to binary (using alpha channel)
130
- const binaryData = new Uint8Array(width * height);
131
- for (let i = 0; i < binaryData.length; i++) {
132
- // Use alpha channel (every 4th byte starting at index 3)
133
- binaryData[i] = pixels[i * 4 + 3] > 127 ? 255 : 0;
134
- }
135
- // Encode to RLE
136
- return encodeRLE(binaryData);
137
- }
138
- finally {
139
- URL.revokeObjectURL(url);
96
+ export async function pngToRLE(blob, width, height) {
97
+ // Create an off-screen canvas
98
+ const canvas = document.createElement('canvas');
99
+ canvas.width = width;
100
+ canvas.height = height;
101
+ const ctx = canvas.getContext('2d');
102
+ if (!ctx) {
103
+ throw new Error('Failed to get canvas context');
104
+ }
105
+ // Load the image
106
+ const img = new Image();
107
+ const url = URL.createObjectURL(blob);
108
+ try {
109
+ await new Promise((resolve, reject) => {
110
+ img.onload = resolve;
111
+ img.onerror = reject;
112
+ img.src = url;
113
+ });
114
+ // Draw image to canvas
115
+ ctx.drawImage(img, 0, 0, width, height);
116
+ // Get image data
117
+ const imageData = ctx.getImageData(0, 0, width, height);
118
+ const pixels = imageData.data;
119
+ // Convert RGBA to binary (using alpha channel)
120
+ const binaryData = new Uint8Array(width * height);
121
+ for (let i = 0; i < binaryData.length; i++) {
122
+ // Use alpha channel (every 4th byte starting at index 3)
123
+ binaryData[i] = pixels[i * 4 + 3] > 127 ? 255 : 0;
140
124
  }
141
- });
125
+ // Encode to RLE
126
+ return encodeRLE(binaryData);
127
+ }
128
+ finally {
129
+ URL.revokeObjectURL(url);
130
+ }
142
131
  }
143
132
  /**
144
133
  * Converts RLE encoded data to a PNG blob
@@ -147,43 +136,41 @@ export function pngToRLE(blob, width, height) {
147
136
  * @param height - Image height
148
137
  * @returns PNG image blob
149
138
  */
150
- export function rleToPng(rleData, width, height) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- // Decode RLE to binary
153
- const binaryData = decodeRLE(rleData, width * height);
154
- // Create canvas
155
- const canvas = document.createElement('canvas');
156
- canvas.width = width;
157
- canvas.height = height;
158
- const ctx = canvas.getContext('2d');
159
- if (!ctx) {
160
- throw new Error('Failed to get canvas context');
161
- }
162
- // Create image data
163
- const imageData = ctx.createImageData(width, height);
164
- const pixels = imageData.data;
165
- // Convert binary to RGBA
166
- for (let i = 0; i < binaryData.length; i++) {
167
- const idx = i * 4;
168
- const value = binaryData[i];
169
- pixels[idx] = 0; // R
170
- pixels[idx + 1] = 0; // G
171
- pixels[idx + 2] = 0; // B
172
- pixels[idx + 3] = value; // A (0 or 255)
173
- }
174
- // Put image data to canvas
175
- ctx.putImageData(imageData, 0, 0);
176
- // Convert to blob
177
- return new Promise((resolve, reject) => {
178
- canvas.toBlob((blob) => {
179
- if (blob) {
180
- resolve(blob);
181
- }
182
- else {
183
- reject(new Error('Failed to convert canvas to blob'));
184
- }
185
- }, 'image/png');
186
- });
139
+ export async function rleToPng(rleData, width, height) {
140
+ // Decode RLE to binary
141
+ const binaryData = decodeRLE(rleData, width * height);
142
+ // Create canvas
143
+ const canvas = document.createElement('canvas');
144
+ canvas.width = width;
145
+ canvas.height = height;
146
+ const ctx = canvas.getContext('2d');
147
+ if (!ctx) {
148
+ throw new Error('Failed to get canvas context');
149
+ }
150
+ // Create image data
151
+ const imageData = ctx.createImageData(width, height);
152
+ const pixels = imageData.data;
153
+ // Convert binary to RGBA
154
+ for (let i = 0; i < binaryData.length; i++) {
155
+ const idx = i * 4;
156
+ const value = binaryData[i];
157
+ pixels[idx] = 0; // R
158
+ pixels[idx + 1] = 0; // G
159
+ pixels[idx + 2] = 0; // B
160
+ pixels[idx + 3] = value; // A (0 or 255)
161
+ }
162
+ // Put image data to canvas
163
+ ctx.putImageData(imageData, 0, 0);
164
+ // Convert to blob
165
+ return new Promise((resolve, reject) => {
166
+ canvas.toBlob((blob) => {
167
+ if (blob) {
168
+ resolve(blob);
169
+ }
170
+ else {
171
+ reject(new Error('Failed to convert canvas to blob'));
172
+ }
173
+ }, 'image/png');
187
174
  });
188
175
  }
189
176
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tableslayer/ui",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "license": "FSL-1.1-ALv2",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,14 +20,13 @@
20
20
  "dev": "svelte-package --watch",
21
21
  "build": "svelte-kit sync && vite build && npm run package",
22
22
  "preview": "vite preview",
23
- "tsc": "tsc",
23
+ "tsc": "svelte-kit sync && tsc",
24
24
  "package": "svelte-kit sync && svelte-package && typedoc",
25
25
  "prepublishOnly": "npm run package",
26
26
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
27
27
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
28
28
  "lint": "eslint .",
29
- "typedoc": "typedoc",
30
- "postinstall": "svelte-kit sync && pnpm run package"
29
+ "typedoc": "typedoc"
31
30
  },
32
31
  "exports": {
33
32
  ".": {
@@ -54,34 +53,34 @@
54
53
  "svelte": "^5.19.0"
55
54
  },
56
55
  "devDependencies": {
57
- "@magidoc/plugin-svelte-marked": "^6.3.0",
56
+ "@magidoc/plugin-svelte-marked": "^6.4.3",
58
57
  "@sveltejs/adapter-auto": "^7.0.1",
59
- "@sveltejs/kit": "^2.59.1",
58
+ "@sveltejs/kit": "^2.61.1",
60
59
  "@sveltejs/package": "^2.5.7",
61
60
  "@sveltejs/vite-plugin-svelte": "^7.1.2",
62
61
  "@tableslayer/eslint-config": "workspace:*",
63
62
  "@tableslayer/tsconfig": "workspace:*",
64
63
  "@types/chroma-js": "^3.1.2",
65
- "@types/node": "^25.6.2",
64
+ "@types/node": "^25.9.1",
66
65
  "@types/marked": "^6.0.0",
67
- "marked": "^18.0.3",
68
- "svelte": "5.55.5",
66
+ "marked": "^18.0.4",
67
+ "svelte": "5.55.9",
69
68
  "svelte-check": "^4.4.8",
70
69
  "typedoc": "^0.28.19",
71
70
  "typescript": "^6.0.3",
72
- "vite": "^8.0.12"
71
+ "vite": "^8.0.14"
73
72
  },
74
73
  "dependencies": {
75
74
  "@floating-ui/dom": "^1.7.6",
76
75
  "@tabler/icons-svelte": "^3.44.0",
77
- "@tiptap/core": "^3.23.1",
78
- "@tiptap/extension-link": "^3.23.1",
79
- "@tiptap/extension-typography": "^3.23.1",
80
- "@tiptap/pm": "^3.23.1",
81
- "@tiptap/starter-kit": "^3.23.1",
76
+ "@tiptap/core": "^3.23.6",
77
+ "@tiptap/extension-link": "^3.23.6",
78
+ "@tiptap/extension-typography": "^3.23.6",
79
+ "@tiptap/pm": "^3.23.6",
80
+ "@tiptap/starter-kit": "^3.23.6",
82
81
  "chroma-js": "^3.2.0",
83
82
  "class-variance-authority": "^0.7.1",
84
- "shiki": "^4.0.2",
83
+ "shiki": "^4.1.0",
85
84
  "uuid": "^14.0.0",
86
85
  "zod": "^4.4.3"
87
86
  },