@simplysm/core-browser 13.0.100 → 14.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.
- package/README.md +183 -65
- package/dist/extensions/element-ext.d.ts +36 -36
- package/dist/extensions/element-ext.d.ts.map +1 -1
- package/dist/extensions/element-ext.js +132 -111
- package/dist/extensions/element-ext.js.map +1 -6
- package/dist/extensions/html-element-ext.d.ts +22 -22
- package/dist/extensions/html-element-ext.js +50 -45
- package/dist/extensions/html-element-ext.js.map +1 -6
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -6
- package/dist/utils/IndexedDbStore.js +115 -112
- package/dist/utils/IndexedDbStore.js.map +1 -6
- package/dist/utils/IndexedDbVirtualFs.js +81 -83
- package/dist/utils/IndexedDbVirtualFs.js.map +1 -6
- package/dist/utils/download.d.ts +3 -3
- package/dist/utils/download.js +18 -14
- package/dist/utils/download.js.map +1 -6
- package/dist/utils/fetch.d.ts +1 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +46 -36
- package/dist/utils/fetch.js.map +1 -6
- package/dist/utils/file-dialog.d.ts +1 -1
- package/dist/utils/file-dialog.js +19 -19
- package/dist/utils/file-dialog.js.map +1 -6
- package/package.json +7 -10
- package/src/extensions/element-ext.ts +40 -40
- package/src/extensions/html-element-ext.ts +24 -24
- package/src/index.ts +3 -3
- package/src/utils/IndexedDbStore.ts +3 -3
- package/src/utils/download.ts +3 -3
- package/src/utils/fetch.ts +17 -5
- package/src/utils/file-dialog.ts +1 -1
- package/docs/classes.md +0 -184
- package/docs/element-extensions.md +0 -134
- package/docs/html-element-extensions.md +0 -56
- package/docs/utilities.md +0 -71
- package/tests/extensions/element-ext.spec.ts +0 -693
- package/tests/extensions/html-element-ext.spec.ts +0 -175
- package/tests/utils/IndexedDbStore.spec.ts +0 -103
- package/tests/utils/IndexedDbVirtualFs.spec.ts +0 -171
- package/tests/utils/download.spec.ts +0 -66
- package/tests/utils/fetch.spec.ts +0 -154
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# Element Extensions
|
|
2
|
-
|
|
3
|
-
Extensions added to the `Element.prototype` via side-effect import. These methods are available on all `Element` instances when `@simplysm/core-browser` is imported.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import "@simplysm/core-browser";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## `ElementBounds`
|
|
10
|
-
|
|
11
|
-
Element bounds information type returned by `getBounds`.
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
interface ElementBounds {
|
|
15
|
-
/** Element to be measured */
|
|
16
|
-
target: Element;
|
|
17
|
-
/** Top position relative to viewport */
|
|
18
|
-
top: number;
|
|
19
|
-
/** Left position relative to viewport */
|
|
20
|
-
left: number;
|
|
21
|
-
/** Element width */
|
|
22
|
-
width: number;
|
|
23
|
-
/** Element height */
|
|
24
|
-
height: number;
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
| Field | Type | Description |
|
|
29
|
-
|-------|------|-------------|
|
|
30
|
-
| `target` | `Element` | Element to be measured |
|
|
31
|
-
| `top` | `number` | Top position relative to viewport |
|
|
32
|
-
| `left` | `number` | Left position relative to viewport |
|
|
33
|
-
| `width` | `number` | Element width |
|
|
34
|
-
| `height` | `number` | Element height |
|
|
35
|
-
|
|
36
|
-
## `Element.findAll`
|
|
37
|
-
|
|
38
|
-
Find all child elements matching a CSS selector.
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
findAll<TEl extends Element = Element>(selector: string): TEl[];
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Returns an empty array if the selector is empty.
|
|
45
|
-
|
|
46
|
-
## `Element.findFirst`
|
|
47
|
-
|
|
48
|
-
Find first element matching a CSS selector.
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
findFirst<TEl extends Element = Element>(selector: string): TEl | undefined;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Returns `undefined` if the selector is empty or no match is found.
|
|
55
|
-
|
|
56
|
-
## `Element.prependChild`
|
|
57
|
-
|
|
58
|
-
Insert element as first child.
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
prependChild<TEl extends Element>(child: TEl): TEl;
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## `Element.getParents`
|
|
65
|
-
|
|
66
|
-
Get all parent elements in order of proximity (from closest to farthest).
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
getParents(): Element[];
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## `Element.findFocusableParent`
|
|
73
|
-
|
|
74
|
-
Find first focusable parent element (using tabbable library).
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
findFocusableParent(): HTMLElement | undefined;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## `Element.findFirstFocusableChild`
|
|
81
|
-
|
|
82
|
-
Find first focusable child element (using tabbable library). Uses a TreeWalker for traversal.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
findFirstFocusableChild(): HTMLElement | undefined;
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## `Element.isOffsetElement`
|
|
89
|
-
|
|
90
|
-
Check if element is an offset parent (`position: relative | absolute | fixed | sticky`).
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
isOffsetElement(): boolean;
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## `Element.isVisible`
|
|
97
|
-
|
|
98
|
-
Check if element is visible on screen. Checks existence of clientRects, `visibility: hidden`, and `opacity: 0`.
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
isVisible(): boolean;
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## `copyElement`
|
|
105
|
-
|
|
106
|
-
Copy element content to clipboard. Use as a copy event handler. Finds the first `input`/`textarea` within the target element and copies its value.
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
function copyElement(event: ClipboardEvent): void;
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## `pasteToElement`
|
|
113
|
-
|
|
114
|
-
Paste clipboard content to element. Use as a paste event handler. Finds the first `input`/`textarea` within the target element and replaces its entire value with clipboard content. Does not consider cursor position or selection.
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
function pasteToElement(event: ClipboardEvent): void;
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## `getBounds`
|
|
121
|
-
|
|
122
|
-
Get bounds information for multiple elements using IntersectionObserver.
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
async function getBounds(els: Element[], timeout?: number): Promise<ElementBounds[]>;
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**Parameters:**
|
|
129
|
-
- `els` -- Array of target elements
|
|
130
|
-
- `timeout` -- Timeout in milliseconds (default: `5000`)
|
|
131
|
-
|
|
132
|
-
**Throws:** `TimeoutError` if no response within the timeout duration.
|
|
133
|
-
|
|
134
|
-
Results are returned sorted in input order, with duplicates removed.
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# HTMLElement Extensions
|
|
2
|
-
|
|
3
|
-
Extensions added to the `HTMLElement.prototype` via side-effect import. These methods are available on all `HTMLElement` instances when `@simplysm/core-browser` is imported.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import "@simplysm/core-browser";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## `HTMLElement.repaint`
|
|
10
|
-
|
|
11
|
-
Force repaint by triggering reflow. Internally accesses `offsetHeight` which triggers forced synchronous layout in the browser.
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
repaint(): void;
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## `HTMLElement.getRelativeOffset`
|
|
18
|
-
|
|
19
|
-
Calculate relative position based on a parent element for CSS positioning.
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
getRelativeOffset(parent: HTMLElement | string): { top: number; left: number };
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Returns document-based coordinates including `window.scrollX/Y` that can be directly used in CSS `top`/`left` properties.
|
|
26
|
-
|
|
27
|
-
**Parameters:**
|
|
28
|
-
- `parent` -- Parent element or CSS selector to use as reference (e.g., `document.body`, `".container"`)
|
|
29
|
-
|
|
30
|
-
**Throws:** `ArgumentError` if parent element cannot be found.
|
|
31
|
-
|
|
32
|
-
**Factors included in calculation:**
|
|
33
|
-
- Viewport-relative position (`getBoundingClientRect`)
|
|
34
|
-
- Document scroll position (`window.scrollX/Y`)
|
|
35
|
-
- Parent element internal scroll (`parentEl.scrollTop/Left`)
|
|
36
|
-
- Border thickness of intermediate elements
|
|
37
|
-
- CSS transform transformations
|
|
38
|
-
|
|
39
|
-
**Common use cases:**
|
|
40
|
-
- Position dropdowns, popups after appending to `document.body`
|
|
41
|
-
- Works correctly on scrolled pages
|
|
42
|
-
|
|
43
|
-
## `HTMLElement.scrollIntoViewIfNeeded`
|
|
44
|
-
|
|
45
|
-
Scroll to make target visible if hidden by offset area (e.g., fixed header/column). Only handles cases where target extends beyond top/left boundaries of the scroll area. For downward/rightward scrolling, relies on browser's default focus scroll behavior. Typically used with focus events on tables with fixed headers or columns.
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
scrollIntoViewIfNeeded(
|
|
49
|
-
target: { top: number; left: number },
|
|
50
|
-
offset?: { top: number; left: number },
|
|
51
|
-
): void;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Parameters:**
|
|
55
|
-
- `target` -- Target position within container (`offsetTop`, `offsetLeft`)
|
|
56
|
-
- `offset` -- Size of area that must not be obscured (e.g., fixed header height, fixed column width). Defaults to `{ top: 0, left: 0 }`.
|
package/docs/utilities.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# Utilities
|
|
2
|
-
|
|
3
|
-
Standalone utility functions for browser-side operations.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { downloadBlob, fetchUrlBytes, openFileDialog } from "@simplysm/core-browser";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## `downloadBlob`
|
|
10
|
-
|
|
11
|
-
Download a Blob as a file by creating a temporary object URL and clicking a hidden link.
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
function downloadBlob(blob: Blob, fileName: string): void;
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
**Parameters:**
|
|
18
|
-
- `blob` -- Blob object to download
|
|
19
|
-
- `fileName` -- File name to save as
|
|
20
|
-
|
|
21
|
-
## `DownloadProgress`
|
|
22
|
-
|
|
23
|
-
Download progress information used by `fetchUrlBytes`.
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
interface DownloadProgress {
|
|
27
|
-
receivedLength: number;
|
|
28
|
-
contentLength: number;
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
| Field | Type | Description |
|
|
33
|
-
|-------|------|-------------|
|
|
34
|
-
| `receivedLength` | `number` | Number of bytes received so far |
|
|
35
|
-
| `contentLength` | `number` | Total content length from `Content-Length` header |
|
|
36
|
-
|
|
37
|
-
## `fetchUrlBytes`
|
|
38
|
-
|
|
39
|
-
Download binary data from a URL with optional progress callback support.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
async function fetchUrlBytes(
|
|
43
|
-
url: string,
|
|
44
|
-
options?: { onProgress?: (progress: DownloadProgress) => void },
|
|
45
|
-
): Promise<Uint8Array>;
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
**Parameters:**
|
|
49
|
-
- `url` -- URL to download from
|
|
50
|
-
- `options.onProgress` -- Progress callback function
|
|
51
|
-
|
|
52
|
-
When `Content-Length` is known, pre-allocates memory for efficiency. For chunked encoding (unknown length), collects chunks and merges them.
|
|
53
|
-
|
|
54
|
-
**Throws:** `Error` if the download fails or the response body is not readable.
|
|
55
|
-
|
|
56
|
-
## `openFileDialog`
|
|
57
|
-
|
|
58
|
-
Programmatically open a file selection dialog.
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
function openFileDialog(options?: {
|
|
62
|
-
accept?: string;
|
|
63
|
-
multiple?: boolean;
|
|
64
|
-
}): Promise<File[] | undefined>;
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**Parameters:**
|
|
68
|
-
- `options.accept` -- File type filter (e.g., `".csv"`, `"image/*"`)
|
|
69
|
-
- `options.multiple` -- Allow multiple file selection (default: `false`)
|
|
70
|
-
|
|
71
|
-
**Returns:** Array of selected files, or `undefined` if the dialog is cancelled.
|