@simplysm/core-browser 13.0.11 → 13.0.13
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/README.md +39 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,17 +54,18 @@ Instance methods automatically added to `HTMLElement.prototype`.
|
|
|
54
54
|
| `pasteToElement(event)` | `void` | Paste clipboard content into element |
|
|
55
55
|
| `getBounds(els, timeout?)` | `Promise<ElementBounds[]>` | Query element bounds using IntersectionObserver |
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### Download Utilities
|
|
58
58
|
|
|
59
|
-
|
|
|
60
|
-
|
|
61
|
-
| `
|
|
59
|
+
| Function | Return Type | Description |
|
|
60
|
+
|------|-----------|------|
|
|
61
|
+
| `downloadBlob(blob, fileName)` | `void` | Download Blob as file |
|
|
62
|
+
| `fetchUrlBytes(url, options?)` | `Promise<Uint8Array>` | Download binary data from URL (with progress callback support) |
|
|
62
63
|
|
|
63
|
-
###
|
|
64
|
+
### File Dialog
|
|
64
65
|
|
|
65
66
|
| Function | Return Type | Description |
|
|
66
67
|
|------|-----------|------|
|
|
67
|
-
| `
|
|
68
|
+
| `openFileDialog(options?)` | `Promise<File[] \| undefined>` | Open file selection dialog (supports single/multiple file selection) |
|
|
68
69
|
|
|
69
70
|
### Types
|
|
70
71
|
|
|
@@ -173,30 +174,30 @@ const bounds2 = await getBounds([el1], 3000);
|
|
|
173
174
|
### Blob Download
|
|
174
175
|
|
|
175
176
|
```typescript
|
|
176
|
-
import {
|
|
177
|
+
import { downloadBlob } from "@simplysm/core-browser";
|
|
177
178
|
|
|
178
179
|
// Download Blob object as file
|
|
179
180
|
const blob = new Blob(["Hello, World!"], { type: "text/plain" });
|
|
180
|
-
|
|
181
|
+
downloadBlob(blob, "hello.txt");
|
|
181
182
|
|
|
182
183
|
// Download binary data such as Excel files
|
|
183
184
|
const excelBlob = new Blob([excelData], {
|
|
184
185
|
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
185
186
|
});
|
|
186
|
-
|
|
187
|
+
downloadBlob(excelBlob, "report.xlsx");
|
|
187
188
|
```
|
|
188
189
|
|
|
189
190
|
### Binary Download (with Progress Support)
|
|
190
191
|
|
|
191
192
|
```typescript
|
|
192
|
-
import {
|
|
193
|
+
import { fetchUrlBytes } from "@simplysm/core-browser";
|
|
193
194
|
import type { DownloadProgress } from "@simplysm/core-browser";
|
|
194
195
|
|
|
195
196
|
// Basic usage
|
|
196
|
-
const data: Uint8Array = await
|
|
197
|
+
const data: Uint8Array = await fetchUrlBytes("https://example.com/file.bin");
|
|
197
198
|
|
|
198
199
|
// Using progress callback
|
|
199
|
-
const data2 = await
|
|
200
|
+
const data2 = await fetchUrlBytes("https://example.com/large-file.zip", {
|
|
200
201
|
onProgress: (progress: DownloadProgress) => {
|
|
201
202
|
const percent = progress.contentLength > 0
|
|
202
203
|
? Math.round((progress.receivedLength / progress.contentLength) * 100)
|
|
@@ -206,6 +207,31 @@ const data2 = await downloadBytes("https://example.com/large-file.zip", {
|
|
|
206
207
|
});
|
|
207
208
|
```
|
|
208
209
|
|
|
210
|
+
### File Selection Dialog
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { openFileDialog } from "@simplysm/core-browser";
|
|
214
|
+
|
|
215
|
+
// Open file selection dialog (single file)
|
|
216
|
+
const files = await openFileDialog({
|
|
217
|
+
accept: "image/*", // Optional: specify accepted file types
|
|
218
|
+
});
|
|
219
|
+
if (files) {
|
|
220
|
+
console.log("Selected file:", files[0].name);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Open file selection dialog (multiple files)
|
|
224
|
+
const selectedFiles = await openFileDialog({
|
|
225
|
+
accept: ".pdf,.doc,.docx",
|
|
226
|
+
multiple: true,
|
|
227
|
+
});
|
|
228
|
+
if (selectedFiles) {
|
|
229
|
+
selectedFiles.forEach((file) => {
|
|
230
|
+
console.log("File:", file.name, "Size:", file.size);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
209
235
|
## Caveats
|
|
210
236
|
|
|
211
237
|
- This package is **browser-only**. It cannot be used in Node.js environments.
|
|
@@ -213,7 +239,7 @@ const data2 = await downloadBytes("https://example.com/large-file.zip", {
|
|
|
213
239
|
- The `getBounds()` function uses `IntersectionObserver` and works asynchronously. If all elements are not observed within the specified timeout (default 5000ms), a `TimeoutError` is thrown.
|
|
214
240
|
- The `getRelativeOffset()` method correctly handles elements with CSS `transform` applied. Border thickness and scroll position of intermediate elements are also included in the calculation.
|
|
215
241
|
- The `scrollIntoViewIfNeeded()` method only handles cases where the target is beyond the top/left boundaries. The bottom/right directions rely on the browser's default focus scrolling.
|
|
216
|
-
- The `
|
|
242
|
+
- The `fetchUrlBytes()` function improves memory efficiency by pre-allocating when the `Content-Length` header is available, and collects and merges chunks for chunked encoding.
|
|
217
243
|
- The `pasteToElement()` function replaces the entire value of the target input/textarea. It does not consider cursor position or selection range.
|
|
218
244
|
|
|
219
245
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/core-browser",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.13",
|
|
4
4
|
"description": "심플리즘 패키지 - 코어 모듈 (browser)",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"tabbable": "^6.4.0",
|
|
25
|
-
"@simplysm/core-common": "13.0.
|
|
25
|
+
"@simplysm/core-common": "13.0.13"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"happy-dom": "^20.6.1"
|