@tableslayer/ui 0.1.22 → 0.1.23
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.
- package/dist/components/Toast/toastStore.svelte.js +79 -71
- package/dist/utils/rle.js +69 -82
- package/package.json +15 -16
|
@@ -1,81 +1,89 @@
|
|
|
1
1
|
const DEFAULT_DURATION = 5000;
|
|
2
2
|
class ToastManager {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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.
|
|
3
|
+
"version": "0.1.23",
|
|
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
|
|
56
|
+
"@magidoc/plugin-svelte-marked": "^6.4.3",
|
|
58
57
|
"@sveltejs/adapter-auto": "^7.0.1",
|
|
59
|
-
"@sveltejs/kit": "^2.
|
|
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.
|
|
64
|
+
"@types/node": "^25.9.1",
|
|
66
65
|
"@types/marked": "^6.0.0",
|
|
67
|
-
"marked": "^18.0.
|
|
68
|
-
"svelte": "5.55.
|
|
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.
|
|
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.
|
|
78
|
-
"@tiptap/extension-link": "^3.23.
|
|
79
|
-
"@tiptap/extension-typography": "^3.23.
|
|
80
|
-
"@tiptap/pm": "^3.23.
|
|
81
|
-
"@tiptap/starter-kit": "^3.23.
|
|
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
|
|
83
|
+
"shiki": "^4.1.0",
|
|
85
84
|
"uuid": "^14.0.0",
|
|
86
85
|
"zod": "^4.4.3"
|
|
87
86
|
},
|