svelte-middle-ellipsis 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +141 -2
- package/dist/MiddleEllipsis.svelte +264 -0
- package/dist/MiddleEllipsis.svelte.d.ts +14 -0
- package/dist/cutText.d.ts +38 -0
- package/dist/cutText.js +128 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/probe.d.ts +33 -0
- package/dist/probe.js +57 -0
- package/dist/split.d.ts +93 -0
- package/dist/split.js +159 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.js +1 -0
- package/package.json +93 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `svelte-middle-ellipsis` are documented here. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). While the major version is `0`, a breaking change bumps the minor version.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-11-30
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `lines` prop, which lets the text wrap over up to that many lines before it is cut in the middle, such as `lines={2}` for a card title that keeps its date. The ellipsis goes on the last line, right before the end, or right after the head with `head`. With more than one line, the component is block-level, wraps paths and URLs anywhere they have no room, and ignores `ratio`. Defaults to `1`, which keeps the single-line behaviour.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- With a `ratio`, or a `head` with a `ratio` once the ellipsis has settled, each side of the ellipsis now keeps only what fits in its own share of the width. Before, the side before the ellipsis took whatever the other side left over, so a character more after the ellipsis could cost one before it, and the text shifted back and forth while the width grew. Now neither side loses a character as the space widens, for up to a character of unused space on each side.
|
|
16
|
+
|
|
17
|
+
## [0.1.0] - 2026-11-29
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `MiddleEllipsis`, a component that truncates text in the middle and keeps the end visible, with the ellipsis directly before it, without the gap `text-overflow: ellipsis` leaves after it. Shows the full text in the native tooltip while truncated, exposes whether it is truncated through `bind:truncated`, and gives screen readers the full text.
|
|
22
|
+
- `split` prop, which decides what stays visible, from the text itself. Defaults to `tail(6)`, the last six characters.
|
|
23
|
+
- `tail(count)` and `tail(delimiter)` helpers for `split`, to keep the last characters, or everything from the last delimiter on, such as the file name of a path, optionally with a few characters before it. Text no longer than what `tail` keeps keeps its end too: when it doesn't fit, it loses its beginning, such as `…tes.md` for `notes.md` with `tail(8)`.
|
|
24
|
+
- `head(count)` and `head(delimiter)` helpers, to keep the beginning instead. Everything after it is cut at its beginning first, and the head at its end once nothing else is left. With a `ratio`, such as `head("/", { ratio: 0.5 })`, the ellipsis settles at that fraction of the width once the head reaches it.
|
|
25
|
+
- `ratio(fraction)` helper, which keeps the ellipsis at a fraction of the width at every width, such as `ratio(1 / 3)` for after the first third.
|
|
26
|
+
- `fileName()` helper, to keep a file's extension, optionally with a few characters before it.
|
|
27
|
+
- `otherwise` option for the helpers that take a delimiter, which sets how text without the delimiter is split, such as `tail("/", { otherwise: tail(6) })`. Without it, that text is truncated at its end.
|
|
28
|
+
|
|
29
|
+
[Unreleased]: https://github.com/finn-vgtl/svelte-middle-ellipsis/compare/v0.2.0...HEAD
|
|
30
|
+
[0.2.0]: https://github.com/finn-vgtl/svelte-middle-ellipsis/compare/v0.1.0...v0.2.0
|
|
31
|
+
[0.1.0]: https://github.com/finn-vgtl/svelte-middle-ellipsis/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Finn Voigtländer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,142 @@
|
|
|
1
|
-
#
|
|
1
|
+
# svelte-middle-ellipsis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Middle ellipsis for Svelte 5. Truncates long text in the middle and keeps the end in view, so file names keep their extension and IDs keep their last digits.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
quarterly-report-final-version-2.pdf → quarterly-report-fi…-2.pdf
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The usual CSS approach puts the start in a flex item with `text-overflow: ellipsis` before an end that never shrinks, as the [`MiddleEllipsis` component in Proton's web clients](https://github.com/ProtonMail/WebClients/blob/main/packages/components/components/ellipsis/MiddleEllipsis.tsx) does. It leaves a gap: the ellipsis follows the last character that fits, and the rest of the start stays empty, up to almost a character wide. This component measures the text in its own font instead and cuts it to the most whole characters that fit together with the ellipsis and the end, so the ellipsis sits right against the end at any width.
|
|
10
|
+
|
|
11
|
+
**[Documentation and live demo →](https://middle-ellipsis.finn-vgtl.dev)**
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install svelte-middle-ellipsis
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Svelte `^5.7.0`.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { MiddleEllipsis, tail } from "svelte-middle-ellipsis";
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<div style="width: 12rem">
|
|
29
|
+
<MiddleEllipsis text="quarterly-report-final-version-2.pdf" split={tail(8)} />
|
|
30
|
+
</div>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The component is an inline flex box with `max-width: 100%`. Constrain its container, or give it a `max-width` of its own, and it truncates when the text runs out of room. Font, size and colour are inherited. To let it wrap over several lines first, see [Multiple lines](#multiple-lines).
|
|
34
|
+
|
|
35
|
+
- **Split** — `split` decides what stays visible: the last six characters by default. See [Split helpers](#split-helpers).
|
|
36
|
+
- **Tooltip** — while the text is truncated, the full text is shown in the native tooltip. Bring your own with a tooltip [attachment](#attachments) that reads `title`, or set `showTitle={false}` and read `bind:truncated`.
|
|
37
|
+
- **Accessibility** — screen readers read the full text once, as one word. The drawn text is hidden from them.
|
|
38
|
+
- **Selection** — truncated or not, the text is selected as a whole: dragging over any of it selects all of it, and copying gives exactly the full text.
|
|
39
|
+
- **Characters** — `head` and `tail` count grapheme clusters, so an emoji, a flag or a letter with an accent is never cut in half.
|
|
40
|
+
- **Direction** — `dir="auto"` by default, so right-to-left text keeps its end on the left, and left-to-right text stays left-to-right on a right-to-left page. Only pass a `dir` that matches the text: forcing `dir="rtl"` on Latin text puts its end on the left.
|
|
41
|
+
- **Long ends** — with `tail`, when the end and the ellipsis alone are wider than the space, the start disappears and the end loses its beginning, so the ellipsis stays in front of it: `…ge.svelte`.
|
|
42
|
+
- **SSR** — the server sends the full text, truncated at its end by `text-overflow: ellipsis`, or on its last line by `line-clamp` with `lines`. Cutting it in the middle and `truncated` wait for the browser to measure it.
|
|
43
|
+
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Default | Description |
|
|
47
|
+
| ----------- | --------------- | --------- | ----------------------------------------------------------------------------------- |
|
|
48
|
+
| `text` | `string` | — | The text to display, with whitespace preserved. Required. |
|
|
49
|
+
| `split` | `SplitFunction` | `tail(6)` | What stays visible: the end, a head, or where the ellipsis settles. See below. |
|
|
50
|
+
| `showTitle` | `boolean` | `true` | Shows the full text in the native tooltip while truncated. A `title` you pass wins. |
|
|
51
|
+
| `truncated` | `boolean` | `false` | Bindable, read-only. Whether the text is currently truncated. |
|
|
52
|
+
| `lines` | `number` | `1` | How many lines the text may wrap over before it is cut in the middle. |
|
|
53
|
+
|
|
54
|
+
All other attributes (`class`, `style`, `id`, `data-*`, event handlers) and [attachments](#attachments) are forwarded to the host `<span>`. Prop types are exported as `MiddleEllipsisProps`, `SplitFunction` and `SplitIndices`, and the helpers' options as `HeadOptions` and `TailOptions`.
|
|
55
|
+
|
|
56
|
+
## Split helpers
|
|
57
|
+
|
|
58
|
+
```svelte
|
|
59
|
+
<script lang="ts">
|
|
60
|
+
import { fileName, head, MiddleEllipsis, ratio, tail } from "svelte-middle-ellipsis";
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<!-- "quarterly-report-fin…sion-2.pdf": the last ten characters -->
|
|
64
|
+
<MiddleEllipsis text={file} split={tail(10)} />
|
|
65
|
+
|
|
66
|
+
<!-- "src/routes/settings/…/+page.svelte": the file name of a path -->
|
|
67
|
+
<MiddleEllipsis text={path} split={tail("/")} />
|
|
68
|
+
|
|
69
|
+
<!-- "quarterly-report…-2.pdf": the extension and two characters before it -->
|
|
70
|
+
<MiddleEllipsis text={file} split={fileName({ before: 2 })} />
|
|
71
|
+
|
|
72
|
+
<!-- "INV-…EXAMPLE-CORP": the prefix up to the first "-", kept as long as it fits -->
|
|
73
|
+
<MiddleEllipsis text={id} split={head("-")} />
|
|
74
|
+
|
|
75
|
+
<!-- "sha256:9f86d08…0f00a08": the ellipsis after the first two thirds, at every width -->
|
|
76
|
+
<MiddleEllipsis text={hash} split={ratio(2 / 3)} />
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- `tail(count)` keeps the last `count` characters, and `tail(delimiter, options)` everything from the last `delimiter` on, the delimiter included. The middle goes first, then the end, so the ellipsis sits right before the end. `tail(0)` truncates at the end.
|
|
80
|
+
- `fileName(options)` keeps the extension, from the last `.` of the file name. It looks past `/` and `\` in paths, keeps only the last extension of `backup.tar.gz`, and treats `.bashrc` as a name without one.
|
|
81
|
+
- `head(count, options)` keeps the first `count` characters, and `head(delimiter, options)` everything up to and including the first `delimiter`. Everything after the head is cut at its beginning, so the ellipsis sits right after the head. Once nothing else is left, the head is cut at its end, like plain `text-overflow: ellipsis`: `src/…+page.svelte`, `src/…`, `sr…`. Pass `ratio` to have the ellipsis settle at a fraction of the width instead, after which both sides shrink: `head("/", { ratio: 0.5 })` keeps the head until it reaches the middle. Do that when many texts share the head, as paths in one folder do, so they don't all narrow to the same `src/…`.
|
|
82
|
+
- `ratio(fraction)` keeps the ellipsis at `fraction` of the width, from the start of the text, at every width: `0.5` in the middle, `2 / 3` after the first two thirds. Both sides shrink as the space narrows. Clamped to `0`–`1`.
|
|
83
|
+
- `tail` with a delimiter and `fileName` take `before`, characters before the delimiter or extension that stay visible too.
|
|
84
|
+
- With a delimiter, `head`, `tail` and `fileName` take `otherwise`, the split for text without the delimiter or extension, such as `tail("/", { otherwise: tail(6) })`. Without it, that text is truncated at its end.
|
|
85
|
+
- Counts are in user-perceived characters, so an emoji or a flag counts as one.
|
|
86
|
+
|
|
87
|
+
### Your own split
|
|
88
|
+
|
|
89
|
+
`split` is a function of the text. It returns the UTF-16 offset where the end begins, as string methods like `lastIndexOf` do, or `{ head, end, ratio }`. An offset inside a character moves to its beginning. With a head or a ratio, the end is not kept. A missing, negative or non-finite end means no end, so `(text) => text.lastIndexOf("/")` truncates text without a `/` at its end.
|
|
90
|
+
|
|
91
|
+
```svelte
|
|
92
|
+
<MiddleEllipsis text={id} split={(text) => ({ head: text.indexOf(":") + 1, ratio: 0.4 })} />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Multiple lines
|
|
96
|
+
|
|
97
|
+
Pass `lines` to let the text wrap over that many lines before it is cut in the middle:
|
|
98
|
+
|
|
99
|
+
```svelte
|
|
100
|
+
<!-- A card title over up to two lines that keeps its date -->
|
|
101
|
+
<MiddleEllipsis text={title} split={tail(10)} lines={2} />
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- The ellipsis goes on the last line, right before the end, and stays on the end's line. When the end alone needs more than `lines` lines, it loses its beginning, as on one line.
|
|
105
|
+
- With `head`, the ellipsis goes right after the head, and what follows is cut at its beginning.
|
|
106
|
+
- The component is block-level and takes its width from its container. The text wraps at spaces, and anywhere else a line has no room, so paths and URLs wrap too.
|
|
107
|
+
- `ratio`, as a split of its own or as an option of `head`, is ignored.
|
|
108
|
+
- Before the browser measures it, as when rendered on the server, the text is clamped to `lines` lines with `line-clamp`, cut at its end.
|
|
109
|
+
|
|
110
|
+
## Attachments
|
|
111
|
+
|
|
112
|
+
Attachments (`{@attach}`, Svelte 5.29 or later) are forwarded to the host `<span>`, so tooltip, popover and observer attachments work on the component as on any element.
|
|
113
|
+
|
|
114
|
+
That makes the tooltip bring-your-own: while the text is truncated, the component sets `title` to the full text, and a tooltip attachment that reads `title` shows it in its own style. To keep the browser from showing its native tooltip as well, the attachment takes the `title` off while the element is hovered and puts it back afterwards:
|
|
115
|
+
|
|
116
|
+
```svelte
|
|
117
|
+
<script lang="ts">
|
|
118
|
+
import { MiddleEllipsis, tail } from "svelte-middle-ellipsis";
|
|
119
|
+
import { tooltip } from "./tooltip";
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<MiddleEllipsis text={file} split={tail(8)} {@attach tooltip} />
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
pnpm install
|
|
129
|
+
pnpm dev # demo site
|
|
130
|
+
pnpm test # browser tests via Vitest and Playwright
|
|
131
|
+
pnpm check # type-check
|
|
132
|
+
pnpm lint # Biome
|
|
133
|
+
pnpm package # build the library into dist/
|
|
134
|
+
pnpm check:svelte-floor # check dist/ against the lowest supported Svelte
|
|
135
|
+
pnpm changelog # draft the next version's changelog entries
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
See [CHANGELOG.md](CHANGELOG.md) for what changed in each release.
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Truncates text in the middle and keeps the end visible, with the ellipsis right up against it.
|
|
4
|
+
|
|
5
|
+
```svelte
|
|
6
|
+
<MiddleEllipsis text="quarterly-report-final-v2.pdf" split={tail(8)} />
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Give it a constrained width through its container or `style="max-width: …"`. See
|
|
10
|
+
https://github.com/finn-vgtl/svelte-middle-ellipsis for all props.
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts" module>
|
|
13
|
+
import { tail } from "./split";
|
|
14
|
+
|
|
15
|
+
const defaultSplit = tail(6);
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { type CutText, cutText, cutToFit } from "./cutText";
|
|
20
|
+
import {
|
|
21
|
+
breaksAfter,
|
|
22
|
+
breaksBefore,
|
|
23
|
+
ellipsisText,
|
|
24
|
+
fillProbe,
|
|
25
|
+
fitsWrapped,
|
|
26
|
+
type Glue,
|
|
27
|
+
} from "./probe";
|
|
28
|
+
import { splitText } from "./split";
|
|
29
|
+
import type { MiddleEllipsisProps } from "./types";
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
text,
|
|
33
|
+
split = defaultSplit,
|
|
34
|
+
showTitle = true,
|
|
35
|
+
truncated = $bindable(false),
|
|
36
|
+
lines: linesProp = 1,
|
|
37
|
+
title,
|
|
38
|
+
class: className,
|
|
39
|
+
...rest
|
|
40
|
+
}: MiddleEllipsisProps = $props();
|
|
41
|
+
|
|
42
|
+
const parts = $derived(splitText(text, split));
|
|
43
|
+
/** The line count as a whole number of at least `1`. */
|
|
44
|
+
const lines = $derived(
|
|
45
|
+
Number.isFinite(linesProp) ? Math.max(1, Math.floor(linesProp)) : 1,
|
|
46
|
+
);
|
|
47
|
+
/**
|
|
48
|
+
* What the ellipsis sticks to. Over several lines, there is no ratio: a head keeps the ellipsis
|
|
49
|
+
* after it, and without one, the ellipsis precedes the end.
|
|
50
|
+
*/
|
|
51
|
+
const glue: Glue = $derived(
|
|
52
|
+
lines === 1 ? "none" : parts.head ? "head" : "end",
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
let textElement = $state<HTMLSpanElement>();
|
|
56
|
+
let probeElement = $state<HTMLSpanElement>();
|
|
57
|
+
|
|
58
|
+
/** The truncated text drawn over the full text, or `undefined` while the full text shows. */
|
|
59
|
+
let cut = $state<CutText>();
|
|
60
|
+
/** Whether the selection includes the text, which then shows as selected as a whole. */
|
|
61
|
+
let selected = $state(false);
|
|
62
|
+
|
|
63
|
+
// The full text keeps its place in the layout, so its width only changes with the available
|
|
64
|
+
// width, which the observer sees, and drawing over it never feeds back into it. A new text or a
|
|
65
|
+
// font that finishes loading changes what fits without resizing it, so both re-measure.
|
|
66
|
+
$effect(() => {
|
|
67
|
+
const element = textElement;
|
|
68
|
+
const probe = probeElement;
|
|
69
|
+
if (!element || !probe) return;
|
|
70
|
+
const current = parts;
|
|
71
|
+
const currentGlue = glue;
|
|
72
|
+
const whole = current.head + current.start + current.end;
|
|
73
|
+
|
|
74
|
+
const measure = () => {
|
|
75
|
+
let next: CutText | undefined;
|
|
76
|
+
if (currentGlue === "none") {
|
|
77
|
+
probe.style.width = "";
|
|
78
|
+
next = cutText(
|
|
79
|
+
current,
|
|
80
|
+
element.getBoundingClientRect().width,
|
|
81
|
+
(value) => {
|
|
82
|
+
fillProbe(probe, whole, value, currentGlue);
|
|
83
|
+
return probe.getBoundingClientRect().width;
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
// Wraps at the width of the full text, which fills the space.
|
|
88
|
+
probe.style.width = `${element.getBoundingClientRect().width}px`;
|
|
89
|
+
// A ratio is not supported over several lines and is left out.
|
|
90
|
+
next = cutToFit(current, (value) => {
|
|
91
|
+
fillProbe(probe, whole, value, currentGlue);
|
|
92
|
+
return fitsWrapped(probe);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Left in the probe, the last candidate would end up in copied text in WebKit.
|
|
96
|
+
probe.textContent = "";
|
|
97
|
+
cut = next;
|
|
98
|
+
truncated = next !== undefined;
|
|
99
|
+
};
|
|
100
|
+
measure();
|
|
101
|
+
|
|
102
|
+
// Measuring inside the observer callback would apply its changes in the same rendering step,
|
|
103
|
+
// which browsers report as a ResizeObserver loop error. The next frame is soon enough.
|
|
104
|
+
let frame = 0;
|
|
105
|
+
const scheduleMeasure = () => {
|
|
106
|
+
cancelAnimationFrame(frame);
|
|
107
|
+
frame = requestAnimationFrame(measure);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const observer = new ResizeObserver(scheduleMeasure);
|
|
111
|
+
observer.observe(element);
|
|
112
|
+
document.fonts?.addEventListener("loadingdone", scheduleMeasure);
|
|
113
|
+
return () => {
|
|
114
|
+
cancelAnimationFrame(frame);
|
|
115
|
+
observer.disconnect();
|
|
116
|
+
document.fonts?.removeEventListener("loadingdone", scheduleMeasure);
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// The full text is selected as a whole, and is transparent while truncated, so the drawn text
|
|
121
|
+
// shows the selection instead.
|
|
122
|
+
$effect(() => {
|
|
123
|
+
const element = textElement;
|
|
124
|
+
if (!element || !cut) {
|
|
125
|
+
selected = false;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const update = () => {
|
|
129
|
+
const selection = document.getSelection();
|
|
130
|
+
selected =
|
|
131
|
+
!!selection &&
|
|
132
|
+
!selection.isCollapsed &&
|
|
133
|
+
selection.containsNode(element, true);
|
|
134
|
+
};
|
|
135
|
+
update();
|
|
136
|
+
document.addEventListener("selectionchange", update);
|
|
137
|
+
return () => document.removeEventListener("selectionchange", update);
|
|
138
|
+
});
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<!--
|
|
142
|
+
The full text sets the size, is what screen readers read and what selecting copies, and shows
|
|
143
|
+
until the browser has measured, as when rendered on the server, truncated at its end. Once
|
|
144
|
+
measured and too wide, it turns transparent and the text cut to fit is drawn over it. The drawn
|
|
145
|
+
text is generated content, which can't be selected, copied or found, and is hidden from screen
|
|
146
|
+
readers.
|
|
147
|
+
-->
|
|
148
|
+
<span
|
|
149
|
+
dir="auto"
|
|
150
|
+
{...rest}
|
|
151
|
+
class={className ? `middle-ellipsis ${className}` : "middle-ellipsis"}
|
|
152
|
+
class:multi-line={lines > 1}
|
|
153
|
+
style:--lines={lines > 1 ? lines : undefined}
|
|
154
|
+
title={title ?? (showTitle && truncated ? text : undefined)}
|
|
155
|
+
><span class="slot" class:cut class:selected
|
|
156
|
+
><span class="text" bind:this={textElement}>{text}</span
|
|
157
|
+
>{#if cut}<span class="drawn" aria-hidden="true"
|
|
158
|
+
><span class="line"
|
|
159
|
+
><bdi class="piece" data-text={cut.before}></bdi
|
|
160
|
+
>{#if breaksBefore(glue, cut)}<wbr />{/if}<span
|
|
161
|
+
class="piece"
|
|
162
|
+
data-text={ellipsisText(glue)}
|
|
163
|
+
></span
|
|
164
|
+
>{#if breaksAfter(glue, cut)}<wbr />{/if}<bdi
|
|
165
|
+
class="piece"
|
|
166
|
+
data-text={cut.after}
|
|
167
|
+
></bdi></span
|
|
168
|
+
></span
|
|
169
|
+
>{/if}</span
|
|
170
|
+
><span class="probe" aria-hidden="true" bind:this={probeElement}></span></span
|
|
171
|
+
>
|
|
172
|
+
|
|
173
|
+
<style>
|
|
174
|
+
.middle-ellipsis {
|
|
175
|
+
display: inline-flex;
|
|
176
|
+
max-width: 100%;
|
|
177
|
+
min-width: 0;
|
|
178
|
+
white-space: pre;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* Over several lines, takes its width from its container and wraps anywhere it must. */
|
|
182
|
+
.multi-line {
|
|
183
|
+
display: block;
|
|
184
|
+
white-space: pre-wrap;
|
|
185
|
+
overflow-wrap: anywhere;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
Holds the full text and the drawn text over it in one grid cell, so both are laid out alike
|
|
190
|
+
and share their baseline to the fraction of a pixel.
|
|
191
|
+
*/
|
|
192
|
+
.slot {
|
|
193
|
+
display: grid;
|
|
194
|
+
grid-template-columns: minmax(0, auto);
|
|
195
|
+
min-width: 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.text,
|
|
199
|
+
.drawn {
|
|
200
|
+
grid-area: 1 / 1;
|
|
201
|
+
min-width: 0;
|
|
202
|
+
overflow: hidden;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.text {
|
|
206
|
+
text-overflow: ellipsis;
|
|
207
|
+
-webkit-user-select: all;
|
|
208
|
+
user-select: all;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/*
|
|
212
|
+
Clamped to the line count, which also cuts the text at its end before the browser measures
|
|
213
|
+
it. The drawn text is clamped alike, so a cut left over from a wider space, which wraps over
|
|
214
|
+
more lines until the next measure, doesn't grow the box for a frame. The probe too, so a line
|
|
215
|
+
the clamp hides shows it doesn't fit.
|
|
216
|
+
*/
|
|
217
|
+
.multi-line .text,
|
|
218
|
+
.multi-line .drawn,
|
|
219
|
+
.multi-line > .probe {
|
|
220
|
+
display: -webkit-box;
|
|
221
|
+
-webkit-box-orient: vertical;
|
|
222
|
+
-webkit-line-clamp: var(--lines);
|
|
223
|
+
line-clamp: var(--lines);
|
|
224
|
+
overflow: hidden;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.cut > .text {
|
|
228
|
+
text-overflow: clip;
|
|
229
|
+
color: transparent;
|
|
230
|
+
-webkit-text-fill-color: transparent;
|
|
231
|
+
text-shadow: none;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.cut > .text::selection {
|
|
235
|
+
color: transparent;
|
|
236
|
+
-webkit-text-fill-color: transparent;
|
|
237
|
+
background: transparent;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* Comes after the full text, so it is painted over it. */
|
|
241
|
+
.drawn {
|
|
242
|
+
pointer-events: none;
|
|
243
|
+
-webkit-user-select: none;
|
|
244
|
+
user-select: none;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.selected .line {
|
|
248
|
+
background: Highlight;
|
|
249
|
+
color: HighlightText;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.piece::before {
|
|
253
|
+
content: attr(data-text);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* Measures candidate text in the inherited font. */
|
|
257
|
+
.probe {
|
|
258
|
+
position: absolute;
|
|
259
|
+
visibility: hidden;
|
|
260
|
+
pointer-events: none;
|
|
261
|
+
-webkit-user-select: none;
|
|
262
|
+
user-select: none;
|
|
263
|
+
}
|
|
264
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MiddleEllipsisProps } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Truncates text in the middle and keeps the end visible, with the ellipsis right up against it.
|
|
4
|
+
*
|
|
5
|
+
* ```svelte
|
|
6
|
+
* <MiddleEllipsis text="quarterly-report-final-v2.pdf" split={tail(8)} />
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Give it a constrained width through its container or `style="max-width: …"`. See
|
|
10
|
+
* https://github.com/finn-vgtl/svelte-middle-ellipsis for all props.
|
|
11
|
+
*/
|
|
12
|
+
declare const MiddleEllipsis: import("svelte").Component<MiddleEllipsisProps, {}, "truncated">;
|
|
13
|
+
type MiddleEllipsis = ReturnType<typeof MiddleEllipsis>;
|
|
14
|
+
export default MiddleEllipsis;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type SplitText } from "./split";
|
|
2
|
+
declare const ELLIPSIS = "\u2026";
|
|
3
|
+
/** Truncated text, drawn as `before`, an ellipsis, then `after`. */
|
|
4
|
+
interface CutText {
|
|
5
|
+
before: string;
|
|
6
|
+
after: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Cuts a text so that `fits` accepts it, or returns `undefined` when all of it fits. Without
|
|
10
|
+
* `cut`, `fits` checks the whole text. Needs no widths, so it works for any layout, such as text
|
|
11
|
+
* wrapped over several lines, as long as a text that fits still fits with a character less. Has no
|
|
12
|
+
* ratio: with a head, the ellipsis follows the head, and without one, it precedes the end.
|
|
13
|
+
*
|
|
14
|
+
* Without a head, the start is cut at its end, so the ellipsis sits right before the end. Once the
|
|
15
|
+
* start is gone, the end is cut at its beginning, so the ellipsis stays where it was. When not even
|
|
16
|
+
* the ellipsis fits, it is drawn alone and clipped.
|
|
17
|
+
*
|
|
18
|
+
* With a head, everything after the head is cut at its beginning, so the ellipsis sits right after
|
|
19
|
+
* the head. Once nothing follows it, the head is cut at its end.
|
|
20
|
+
*/
|
|
21
|
+
declare function cutToFit({ head, start, end }: Pick<SplitText, "head" | "start" | "end">, fits: (cut?: CutText) => boolean): CutText | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Cuts a text to fit in `available` pixels, or returns `undefined` when all of it fits. When not
|
|
24
|
+
* even the ellipsis fits, it is drawn alone and clipped.
|
|
25
|
+
*
|
|
26
|
+
* Without a ratio, the text is cut as `cutToFit` does.
|
|
27
|
+
*
|
|
28
|
+
* With a head, the head stays whole and everything after it is cut at its beginning, so the
|
|
29
|
+
* ellipsis sits right after the head. Once the ellipsis reaches `ratio` of the width, both sides
|
|
30
|
+
* shrink and it stays there; with a ratio of `1`, that means the head is cut at its end once
|
|
31
|
+
* nothing follows it. Without a head, the ellipsis is at the ratio at every width.
|
|
32
|
+
*
|
|
33
|
+
* `measure` gives the width of the text as drawn, so kerning, letters that change shape at the cut
|
|
34
|
+
* and mixed directions count as they look. Without `cut`, it measures the whole text.
|
|
35
|
+
*/
|
|
36
|
+
declare function cutText({ head, start, end, ratio }: SplitText, available: number, measure: (cut?: CutText) => number): CutText | undefined;
|
|
37
|
+
export type { CutText };
|
|
38
|
+
export { cutText, cutToFit, ELLIPSIS };
|
package/dist/cutText.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { characterEnds } from "./split";
|
|
2
|
+
const ELLIPSIS = "…";
|
|
3
|
+
/**
|
|
4
|
+
* Finds the most whole characters at the beginning of `text` that `fits` accepts, with spaces
|
|
5
|
+
* before the ellipsis dropped. Longer runs only get wider, so this is a binary search. All of
|
|
6
|
+
* `text` is a candidate only with `whole`. Returns `undefined` when not even no characters fit.
|
|
7
|
+
*/
|
|
8
|
+
function longestPrefix(text, fits, whole = false) {
|
|
9
|
+
if (!fits(""))
|
|
10
|
+
return undefined;
|
|
11
|
+
const ends = characterEnds(text);
|
|
12
|
+
let best = "";
|
|
13
|
+
let low = 0;
|
|
14
|
+
let high = ends.length - (whole ? 1 : 2);
|
|
15
|
+
while (low <= high) {
|
|
16
|
+
const middle = (low + high) >> 1;
|
|
17
|
+
const candidate = text.slice(0, ends[middle]).trimEnd();
|
|
18
|
+
if (fits(candidate)) {
|
|
19
|
+
best = candidate;
|
|
20
|
+
low = middle + 1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
high = middle - 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return best;
|
|
27
|
+
}
|
|
28
|
+
/** Like `longestPrefix`, for the end of `text`, with spaces after the ellipsis dropped. */
|
|
29
|
+
function longestSuffix(text, fits, whole = false) {
|
|
30
|
+
if (!fits(""))
|
|
31
|
+
return undefined;
|
|
32
|
+
// Where each character begins, from the second on, and the first too with `whole`.
|
|
33
|
+
const starts = [0, ...characterEnds(text).slice(0, -1)].slice(whole ? 0 : 1);
|
|
34
|
+
let best = "";
|
|
35
|
+
let low = 0;
|
|
36
|
+
let high = starts.length - 1;
|
|
37
|
+
while (low <= high) {
|
|
38
|
+
const middle = (low + high) >> 1;
|
|
39
|
+
const candidate = text.slice(starts[middle]).trimStart();
|
|
40
|
+
if (fits(candidate)) {
|
|
41
|
+
best = candidate;
|
|
42
|
+
high = middle - 1;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
low = middle + 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return best;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Cuts a text so that `fits` accepts it, or returns `undefined` when all of it fits. Without
|
|
52
|
+
* `cut`, `fits` checks the whole text. Needs no widths, so it works for any layout, such as text
|
|
53
|
+
* wrapped over several lines, as long as a text that fits still fits with a character less. Has no
|
|
54
|
+
* ratio: with a head, the ellipsis follows the head, and without one, it precedes the end.
|
|
55
|
+
*
|
|
56
|
+
* Without a head, the start is cut at its end, so the ellipsis sits right before the end. Once the
|
|
57
|
+
* start is gone, the end is cut at its beginning, so the ellipsis stays where it was. When not even
|
|
58
|
+
* the ellipsis fits, it is drawn alone and clipped.
|
|
59
|
+
*
|
|
60
|
+
* With a head, everything after the head is cut at its beginning, so the ellipsis sits right after
|
|
61
|
+
* the head. Once nothing follows it, the head is cut at its end.
|
|
62
|
+
*/
|
|
63
|
+
function cutToFit({ head, start, end }, fits) {
|
|
64
|
+
if (fits())
|
|
65
|
+
return undefined;
|
|
66
|
+
if (head) {
|
|
67
|
+
if (fits({ before: head, after: "" })) {
|
|
68
|
+
const after = longestSuffix(start, (suffix) => fits({ before: head, after: suffix })) ?? "";
|
|
69
|
+
return { before: head, after };
|
|
70
|
+
}
|
|
71
|
+
const before = longestPrefix(head, (prefix) => fits({ before: prefix, after: "" }), true) ?? "";
|
|
72
|
+
return { before, after: "" };
|
|
73
|
+
}
|
|
74
|
+
const before = longestPrefix(start, (prefix) => fits({ before: prefix, after: end }));
|
|
75
|
+
if (before !== undefined)
|
|
76
|
+
return { before, after: end };
|
|
77
|
+
// The ellipsis stays in front of the end, which loses its beginning instead.
|
|
78
|
+
const after = longestSuffix(end, (suffix) => fits({ before: "", after: suffix }));
|
|
79
|
+
return { before: "", after: after ?? "" };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Cuts a text to fit in `available` pixels, or returns `undefined` when all of it fits. When not
|
|
83
|
+
* even the ellipsis fits, it is drawn alone and clipped.
|
|
84
|
+
*
|
|
85
|
+
* Without a ratio, the text is cut as `cutToFit` does.
|
|
86
|
+
*
|
|
87
|
+
* With a head, the head stays whole and everything after it is cut at its beginning, so the
|
|
88
|
+
* ellipsis sits right after the head. Once the ellipsis reaches `ratio` of the width, both sides
|
|
89
|
+
* shrink and it stays there; with a ratio of `1`, that means the head is cut at its end once
|
|
90
|
+
* nothing follows it. Without a head, the ellipsis is at the ratio at every width.
|
|
91
|
+
*
|
|
92
|
+
* `measure` gives the width of the text as drawn, so kerning, letters that change shape at the cut
|
|
93
|
+
* and mixed directions count as they look. Without `cut`, it measures the whole text.
|
|
94
|
+
*/
|
|
95
|
+
function cutText({ head, start, end, ratio }, available, measure) {
|
|
96
|
+
const fits = (cut) => measure(cut) <= available + 0.01;
|
|
97
|
+
if (ratio === undefined)
|
|
98
|
+
return cutToFit({ head: "", start, end }, fits);
|
|
99
|
+
if (fits())
|
|
100
|
+
return undefined;
|
|
101
|
+
const nothing = { before: "", after: "" };
|
|
102
|
+
const ellipsis = measure(nothing);
|
|
103
|
+
if (ellipsis > available + 0.01)
|
|
104
|
+
return nothing;
|
|
105
|
+
// The parts are drawn isolated from each other, so their widths add up.
|
|
106
|
+
const widthOf = (cut) => measure(cut) - ellipsis;
|
|
107
|
+
const space = available - ellipsis;
|
|
108
|
+
const leading = ratio * space;
|
|
109
|
+
// Until the ellipsis reaches the ratio, only what follows the head is cut.
|
|
110
|
+
if (head && widthOf({ before: head, after: "" }) <= leading + 0.01) {
|
|
111
|
+
const after = longestSuffix(start, (suffix) => fits({ before: head, after: suffix }));
|
|
112
|
+
if (after !== undefined)
|
|
113
|
+
return { before: head, after };
|
|
114
|
+
}
|
|
115
|
+
// From then on, each side keeps what fits in its own share of the space, so the ellipsis stays
|
|
116
|
+
// at the ratio to within a character. Neither side takes what the other leaves over: that would
|
|
117
|
+
// tie them together, and a character more on one side would cost the other one, so the text
|
|
118
|
+
// would shift back and forth as the space widens. Each side only grows instead, for up to a
|
|
119
|
+
// character of space left over on each.
|
|
120
|
+
const after = longestSuffix(start, (suffix) => widthOf({ before: "", after: suffix }) <= space - leading + 0.01, true) ?? "";
|
|
121
|
+
// Without a head, both sides come from the same text, so the side before stops where the
|
|
122
|
+
// side after begins.
|
|
123
|
+
const source = head || start.slice(0, start.length - after.length);
|
|
124
|
+
const before = longestPrefix(source, (prefix) => widthOf({ before: prefix, after: "" }) <= leading + 0.01 &&
|
|
125
|
+
fits({ before: prefix, after }), true) ?? "";
|
|
126
|
+
return { before, after };
|
|
127
|
+
}
|
|
128
|
+
export { cutText, cutToFit, ELLIPSIS };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/probe.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CutText } from "./cutText";
|
|
2
|
+
/**
|
|
3
|
+
* What the ellipsis sticks to when the text wraps: the end after it, the head before it, or nothing
|
|
4
|
+
* on a single line. A word joiner keeps the ellipsis on that side's line, and a `<wbr>` on its
|
|
5
|
+
* other side lets the text break there instead. Without both, the last word before the ellipsis
|
|
6
|
+
* and the end wrap as one block, so one more character can push the block to the next line while a
|
|
7
|
+
* few more let it fit again, and the search for the longest cut that fits misses it.
|
|
8
|
+
*/
|
|
9
|
+
type Glue = "none" | "end" | "head";
|
|
10
|
+
/**
|
|
11
|
+
* Whether the text may break between the part before the ellipsis and the ellipsis glued to the
|
|
12
|
+
* end. Not with nothing before it: the break would leave an empty line, and the ellipsis and the
|
|
13
|
+
* end would wrap over the lines after it, so a shorter end could need more lines than a longer
|
|
14
|
+
* one, depending on where the browser breaks it.
|
|
15
|
+
*/
|
|
16
|
+
declare function breaksBefore(glue: Glue, cut: CutText): boolean;
|
|
17
|
+
/** Like `breaksBefore`, between the ellipsis glued to the head and the part after it. */
|
|
18
|
+
declare function breaksAfter(glue: Glue, cut: CutText): boolean;
|
|
19
|
+
/** The ellipsis as drawn, with the word joiner on the side it sticks to. */
|
|
20
|
+
declare function ellipsisText(glue: Glue): string;
|
|
21
|
+
/**
|
|
22
|
+
* Fills the probe like the drawn text: each part isolated, so text in another direction keeps to
|
|
23
|
+
* its side of the ellipsis, and the ellipsis glued as `glue` says. Without `cut`, the whole text.
|
|
24
|
+
*/
|
|
25
|
+
declare function fillProbe(probe: HTMLElement, whole: string, cut: CutText | undefined, glue: Glue): void;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the text in a probe that wraps it and clamps it to its line count fits: no line is
|
|
28
|
+
* hidden by the clamp and nothing sticks out at the side. Counting the lines through the clamp
|
|
29
|
+
* holds up where a fallback font, such as for emoji, makes some lines taller than others.
|
|
30
|
+
*/
|
|
31
|
+
declare function fitsWrapped(probe: HTMLElement): boolean;
|
|
32
|
+
export type { Glue };
|
|
33
|
+
export { breaksAfter, breaksBefore, ellipsisText, fillProbe, fitsWrapped };
|
package/dist/probe.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ELLIPSIS } from "./cutText";
|
|
2
|
+
const WORD_JOINER = "";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the text may break between the part before the ellipsis and the ellipsis glued to the
|
|
5
|
+
* end. Not with nothing before it: the break would leave an empty line, and the ellipsis and the
|
|
6
|
+
* end would wrap over the lines after it, so a shorter end could need more lines than a longer
|
|
7
|
+
* one, depending on where the browser breaks it.
|
|
8
|
+
*/
|
|
9
|
+
function breaksBefore(glue, cut) {
|
|
10
|
+
return glue === "end" && cut.before !== "";
|
|
11
|
+
}
|
|
12
|
+
/** Like `breaksBefore`, between the ellipsis glued to the head and the part after it. */
|
|
13
|
+
function breaksAfter(glue, cut) {
|
|
14
|
+
return glue === "head" && cut.after !== "";
|
|
15
|
+
}
|
|
16
|
+
/** The ellipsis as drawn, with the word joiner on the side it sticks to. */
|
|
17
|
+
function ellipsisText(glue) {
|
|
18
|
+
if (glue === "end")
|
|
19
|
+
return ELLIPSIS + WORD_JOINER;
|
|
20
|
+
if (glue === "head")
|
|
21
|
+
return WORD_JOINER + ELLIPSIS;
|
|
22
|
+
return ELLIPSIS;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fills the probe like the drawn text: each part isolated, so text in another direction keeps to
|
|
26
|
+
* its side of the ellipsis, and the ellipsis glued as `glue` says. Without `cut`, the whole text.
|
|
27
|
+
*/
|
|
28
|
+
function fillProbe(probe, whole, cut, glue) {
|
|
29
|
+
if (!cut) {
|
|
30
|
+
probe.textContent = whole;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const isolate = (content) => {
|
|
34
|
+
const element = document.createElement("bdi");
|
|
35
|
+
element.textContent = content;
|
|
36
|
+
return element;
|
|
37
|
+
};
|
|
38
|
+
const ellipsis = document.createElement("span");
|
|
39
|
+
ellipsis.textContent = ellipsisText(glue);
|
|
40
|
+
const pieces = [isolate(cut.before), ellipsis, isolate(cut.after)];
|
|
41
|
+
if (breaksBefore(glue, cut))
|
|
42
|
+
pieces.splice(1, 0, document.createElement("wbr"));
|
|
43
|
+
if (breaksAfter(glue, cut))
|
|
44
|
+
pieces.splice(2, 0, document.createElement("wbr"));
|
|
45
|
+
probe.replaceChildren(...pieces);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether the text in a probe that wraps it and clamps it to its line count fits: no line is
|
|
49
|
+
* hidden by the clamp and nothing sticks out at the side. Counting the lines through the clamp
|
|
50
|
+
* holds up where a fallback font, such as for emoji, makes some lines taller than others.
|
|
51
|
+
*/
|
|
52
|
+
function fitsWrapped(probe) {
|
|
53
|
+
// Both are whole pixels. A hidden line adds a whole line's height, so a pixel is to spare.
|
|
54
|
+
return (probe.scrollHeight <= probe.clientHeight + 1 &&
|
|
55
|
+
probe.scrollWidth <= probe.clientWidth + 1);
|
|
56
|
+
}
|
|
57
|
+
export { breaksAfter, breaksBefore, ellipsisText, fillProbe, fitsWrapped };
|
package/dist/split.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { SplitFunction } from "./types";
|
|
2
|
+
interface SplitText {
|
|
3
|
+
/** The part that always stays visible at the beginning. Empty when there is no head. */
|
|
4
|
+
head: string;
|
|
5
|
+
/** The part that shrinks first and gets the ellipsis. */
|
|
6
|
+
start: string;
|
|
7
|
+
/** The part that always stays visible. Empty when there is nothing to keep at the end. */
|
|
8
|
+
end: string;
|
|
9
|
+
/**
|
|
10
|
+
* Where the ellipsis settles, as a fraction of the width from the start of the text. Set with a
|
|
11
|
+
* head or a ratio, which keep no end; `undefined` keeps the end instead.
|
|
12
|
+
*/
|
|
13
|
+
ratio?: number;
|
|
14
|
+
}
|
|
15
|
+
/** The UTF-16 offsets in `text` where a user-perceived character ends, in ascending order. */
|
|
16
|
+
declare function characterEnds(text: string): number[];
|
|
17
|
+
/**
|
|
18
|
+
* Splits `text` into a head and an end that stay visible and a start between them that may be
|
|
19
|
+
* truncated, as `split` decides.
|
|
20
|
+
*
|
|
21
|
+
* `split` returns UTF-16 offsets into `text`, as string methods like `lastIndexOf` do. An offset
|
|
22
|
+
* inside a character moves to the beginning of that character. With a head or a ratio, the end is
|
|
23
|
+
* not kept. A missing, negative or non-finite end means no end, so the text is truncated at its
|
|
24
|
+
* end; an invalid head or ratio is ignored.
|
|
25
|
+
*
|
|
26
|
+
* An end at `0` keeps all of the text as the end, so text no longer than what a split keeps still
|
|
27
|
+
* keeps its end: when it doesn't fit, it loses its beginning and the ellipsis stays in front.
|
|
28
|
+
*/
|
|
29
|
+
declare function splitText(text: string, split: SplitFunction): SplitText;
|
|
30
|
+
interface HeadOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Where the ellipsis settles once the head takes up that much of the width, as a fraction from
|
|
33
|
+
* the start of the text, from `0` to `1`, so the head shrinks from then on along with what
|
|
34
|
+
* follows it. `0.5` keeps the ellipsis in the middle. By default, everything after the head goes
|
|
35
|
+
* first. See `ratio`.
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
ratio?: number;
|
|
39
|
+
/** How to split text without the delimiter. By default, it is truncated at its end. */
|
|
40
|
+
otherwise?: SplitFunction;
|
|
41
|
+
}
|
|
42
|
+
interface TailOptions {
|
|
43
|
+
/** Characters before the delimiter or extension that stay visible too. @default 0 */
|
|
44
|
+
before?: number;
|
|
45
|
+
/** How to split text without the delimiter or extension. By default, it is truncated at its end. */
|
|
46
|
+
otherwise?: SplitFunction;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Keeps the beginning of the text visible: the first `count` characters, or everything up to and
|
|
50
|
+
* including the first `delimiter`. Everything after it is cut at its beginning, so the ellipsis
|
|
51
|
+
* sits right after the head. Once nothing else is left, the head is cut at its end, like plain
|
|
52
|
+
* `text-overflow: ellipsis`. With `ratio`, the ellipsis settles at that fraction of the width
|
|
53
|
+
* instead, and both sides shrink from then on.
|
|
54
|
+
*
|
|
55
|
+
* ```svelte
|
|
56
|
+
* <MiddleEllipsis text={id} split={head("-")} />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function head(count: number, options?: Pick<HeadOptions, "ratio">): SplitFunction;
|
|
60
|
+
declare function head(delimiter: string, options?: HeadOptions): SplitFunction;
|
|
61
|
+
/**
|
|
62
|
+
* Keeps the end of the text visible: the last `count` characters, or everything from the last
|
|
63
|
+
* `delimiter` on, the delimiter included, such as the file name of a path with `tail("/")`. The
|
|
64
|
+
* ellipsis sits right before it.
|
|
65
|
+
*
|
|
66
|
+
* ```svelte
|
|
67
|
+
* <MiddleEllipsis text={path} split={tail("/")} />
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare function tail(count: number): SplitFunction;
|
|
71
|
+
declare function tail(delimiter: string, options?: TailOptions): SplitFunction;
|
|
72
|
+
/**
|
|
73
|
+
* Keeps the ellipsis at `fraction` of the width, from the start of the text, at every width: `0.5`
|
|
74
|
+
* in the middle, `2 / 3` after the first two thirds. Both sides shrink as the space narrows.
|
|
75
|
+
* Clamped to `0`–`1`.
|
|
76
|
+
*
|
|
77
|
+
* ```svelte
|
|
78
|
+
* <MiddleEllipsis text={hash} split={ratio(2 / 3)} />
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function ratio(fraction: number): SplitFunction;
|
|
82
|
+
/**
|
|
83
|
+
* Keeps the file extension visible, such as `.pdf`, and `before` characters of the name before
|
|
84
|
+
* it. Works on bare file names and on paths with `/` or `\` separators. A name that starts with a
|
|
85
|
+
* dot, like `.bashrc`, has no extension.
|
|
86
|
+
*
|
|
87
|
+
* ```svelte
|
|
88
|
+
* <MiddleEllipsis text="quarterly-report-v2.pdf" split={fileName({ before: 2 })} />
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function fileName({ before, otherwise, }?: TailOptions): SplitFunction;
|
|
92
|
+
export type { HeadOptions, SplitText, TailOptions };
|
|
93
|
+
export { characterEnds, fileName, head, ratio, splitText, tail };
|
package/dist/split.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
let segmenter;
|
|
2
|
+
/**
|
|
3
|
+
* The user-perceived characters of `text`. Splits by grapheme cluster where `Intl.Segmenter` is
|
|
4
|
+
* available, so flags, emoji ZWJ sequences and combining marks stay whole. Falls back to code
|
|
5
|
+
* points, which still keeps surrogate pairs together.
|
|
6
|
+
*/
|
|
7
|
+
function graphemes(text) {
|
|
8
|
+
if (segmenter === undefined) {
|
|
9
|
+
segmenter =
|
|
10
|
+
typeof Intl !== "undefined" && "Segmenter" in Intl
|
|
11
|
+
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
12
|
+
: null;
|
|
13
|
+
}
|
|
14
|
+
if (!segmenter)
|
|
15
|
+
return Array.from(text);
|
|
16
|
+
return Array.from(segmenter.segment(text), ({ segment }) => segment);
|
|
17
|
+
}
|
|
18
|
+
/** The UTF-16 offsets in `text` where a user-perceived character ends, in ascending order. */
|
|
19
|
+
function characterEnds(text) {
|
|
20
|
+
const ends = [];
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const character of graphemes(text)) {
|
|
23
|
+
offset += character.length;
|
|
24
|
+
ends.push(offset);
|
|
25
|
+
}
|
|
26
|
+
return ends;
|
|
27
|
+
}
|
|
28
|
+
/** The offset of the character boundary at or before `index`, so no character is cut in half. */
|
|
29
|
+
function snapToCharacter(text, index) {
|
|
30
|
+
let boundary = 0;
|
|
31
|
+
for (const end of characterEnds(text)) {
|
|
32
|
+
if (end > index)
|
|
33
|
+
break;
|
|
34
|
+
boundary = end;
|
|
35
|
+
}
|
|
36
|
+
return boundary;
|
|
37
|
+
}
|
|
38
|
+
/** Whether `value` is a usable index: a finite number that isn't negative. */
|
|
39
|
+
function isIndex(value) {
|
|
40
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
41
|
+
}
|
|
42
|
+
/** `value` as a whole number of characters: rounded down, and 0 when negative or not finite. */
|
|
43
|
+
function wholeCount(value) {
|
|
44
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
45
|
+
? Math.max(0, Math.floor(value))
|
|
46
|
+
: 0;
|
|
47
|
+
}
|
|
48
|
+
/** An index into `text`, rounded down, clamped to the text and moved to a character boundary. */
|
|
49
|
+
function toOffset(text, index) {
|
|
50
|
+
return snapToCharacter(text, Math.min(Math.floor(index), text.length));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Splits `text` into a head and an end that stay visible and a start between them that may be
|
|
54
|
+
* truncated, as `split` decides.
|
|
55
|
+
*
|
|
56
|
+
* `split` returns UTF-16 offsets into `text`, as string methods like `lastIndexOf` do. An offset
|
|
57
|
+
* inside a character moves to the beginning of that character. With a head or a ratio, the end is
|
|
58
|
+
* not kept. A missing, negative or non-finite end means no end, so the text is truncated at its
|
|
59
|
+
* end; an invalid head or ratio is ignored.
|
|
60
|
+
*
|
|
61
|
+
* An end at `0` keeps all of the text as the end, so text no longer than what a split keeps still
|
|
62
|
+
* keeps its end: when it doesn't fit, it loses its beginning and the ellipsis stays in front.
|
|
63
|
+
*/
|
|
64
|
+
function splitText(text, split) {
|
|
65
|
+
const result = split(text);
|
|
66
|
+
const indices = typeof result === "number" ? { end: result } : (result ?? {});
|
|
67
|
+
const head = isIndex(indices.head) ? toOffset(text, indices.head) : 0;
|
|
68
|
+
const ratio = typeof indices.ratio === "number" && Number.isFinite(indices.ratio)
|
|
69
|
+
? Math.min(1, Math.max(0, indices.ratio))
|
|
70
|
+
: undefined;
|
|
71
|
+
if (head > 0) {
|
|
72
|
+
return {
|
|
73
|
+
head: text.slice(0, head),
|
|
74
|
+
start: text.slice(head),
|
|
75
|
+
end: "",
|
|
76
|
+
ratio: ratio ?? 1,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (ratio !== undefined)
|
|
80
|
+
return { head: "", start: text, end: "", ratio };
|
|
81
|
+
const end = isIndex(indices.end) ? toOffset(text, indices.end) : text.length;
|
|
82
|
+
return { head: "", start: text.slice(0, end), end: text.slice(end) };
|
|
83
|
+
}
|
|
84
|
+
/** The offset after the first `count` characters of `text`. */
|
|
85
|
+
function firstCharacters(text, count) {
|
|
86
|
+
const whole = wholeCount(count);
|
|
87
|
+
if (whole === 0)
|
|
88
|
+
return 0;
|
|
89
|
+
const ends = characterEnds(text);
|
|
90
|
+
return ends[Math.min(whole, ends.length) - 1] ?? 0;
|
|
91
|
+
}
|
|
92
|
+
/** The offset where the last `count` characters of `text` begin, or `text.length` for none. */
|
|
93
|
+
function lastCharacters(text, count) {
|
|
94
|
+
const whole = wholeCount(count);
|
|
95
|
+
if (whole === 0)
|
|
96
|
+
return text.length;
|
|
97
|
+
const ends = characterEnds(text);
|
|
98
|
+
if (ends.length <= whole)
|
|
99
|
+
return 0;
|
|
100
|
+
return ends[ends.length - 1 - whole];
|
|
101
|
+
}
|
|
102
|
+
/** Moves `index` back by `count` characters, never before the beginning of the text. */
|
|
103
|
+
function backBy(text, index, count) {
|
|
104
|
+
const ends = [0, ...characterEnds(text)].filter((end) => end <= index);
|
|
105
|
+
return ends[Math.max(0, ends.length - 1 - wholeCount(count))];
|
|
106
|
+
}
|
|
107
|
+
/** No split: the text is truncated at its end. */
|
|
108
|
+
const none = (text) => text.length;
|
|
109
|
+
function head(keep, { ratio, otherwise = none } = {}) {
|
|
110
|
+
return (text) => {
|
|
111
|
+
if (typeof keep === "number")
|
|
112
|
+
return { head: firstCharacters(text, keep), ratio };
|
|
113
|
+
const index = keep === "" ? -1 : text.indexOf(keep);
|
|
114
|
+
if (index < 0)
|
|
115
|
+
return otherwise(text);
|
|
116
|
+
return { head: index + keep.length, ratio };
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function tail(keep, { before = 0, otherwise = none } = {}) {
|
|
120
|
+
return (text) => {
|
|
121
|
+
if (typeof keep === "number")
|
|
122
|
+
return lastCharacters(text, keep);
|
|
123
|
+
const index = keep === "" ? -1 : text.lastIndexOf(keep);
|
|
124
|
+
if (index < 0)
|
|
125
|
+
return otherwise(text);
|
|
126
|
+
return backBy(text, index, before);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Keeps the ellipsis at `fraction` of the width, from the start of the text, at every width: `0.5`
|
|
131
|
+
* in the middle, `2 / 3` after the first two thirds. Both sides shrink as the space narrows.
|
|
132
|
+
* Clamped to `0`–`1`.
|
|
133
|
+
*
|
|
134
|
+
* ```svelte
|
|
135
|
+
* <MiddleEllipsis text={hash} split={ratio(2 / 3)} />
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
function ratio(fraction) {
|
|
139
|
+
return () => ({ ratio: fraction });
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Keeps the file extension visible, such as `.pdf`, and `before` characters of the name before
|
|
143
|
+
* it. Works on bare file names and on paths with `/` or `\` separators. A name that starts with a
|
|
144
|
+
* dot, like `.bashrc`, has no extension.
|
|
145
|
+
*
|
|
146
|
+
* ```svelte
|
|
147
|
+
* <MiddleEllipsis text="quarterly-report-v2.pdf" split={fileName({ before: 2 })} />
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function fileName({ before = 0, otherwise = none, } = {}) {
|
|
151
|
+
return (text) => {
|
|
152
|
+
const nameStart = Math.max(text.lastIndexOf("/"), text.lastIndexOf("\\")) + 1;
|
|
153
|
+
const dot = text.lastIndexOf(".");
|
|
154
|
+
if (dot <= nameStart)
|
|
155
|
+
return otherwise(text);
|
|
156
|
+
return Math.max(nameStart, backBy(text, dot, before));
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export { characterEnds, fileName, head, ratio, splitText, tail };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
2
|
+
/**
|
|
3
|
+
* Where to split the text, as UTF-16 offsets into it, like the ones `indexOf` returns. An offset
|
|
4
|
+
* inside a character, such as the middle of an emoji, moves to the beginning of that character.
|
|
5
|
+
*/
|
|
6
|
+
interface SplitIndices {
|
|
7
|
+
/**
|
|
8
|
+
* Where the end begins. Everything from here on stays visible, with the ellipsis right before
|
|
9
|
+
* it. A missing, negative or non-finite value means no end, so the text is truncated at its end.
|
|
10
|
+
* Not kept with a head or a ratio.
|
|
11
|
+
*/
|
|
12
|
+
end?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Where the head ends. The head stays and everything after it is cut at its beginning. Once
|
|
15
|
+
* nothing else is left, the head is cut at its end. With a `ratio`, the ellipsis settles there
|
|
16
|
+
* instead, and both sides shrink. A missing, invalid or zero value means no head.
|
|
17
|
+
*/
|
|
18
|
+
head?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Where the ellipsis settles, as a fraction of the width from the start of the text, from `0`
|
|
21
|
+
* to `1`. With a head, once the head takes up that much; without one, at every width. Defaults
|
|
22
|
+
* to `1` with a head, so the head is kept as long as it fits. A non-finite value is ignored.
|
|
23
|
+
*/
|
|
24
|
+
ratio?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Decides where to split `text`. A number is the offset where the end begins. */
|
|
27
|
+
type SplitFunction = (text: string) => number | SplitIndices;
|
|
28
|
+
interface MiddleEllipsisProps extends Omit<HTMLAttributes<HTMLSpanElement>, "children"> {
|
|
29
|
+
/**
|
|
30
|
+
* The text to display, with whitespace preserved. Rendered on a single line, or wrapped over up
|
|
31
|
+
* to `lines` lines.
|
|
32
|
+
*/
|
|
33
|
+
text: string;
|
|
34
|
+
/**
|
|
35
|
+
* Decides what stays visible, from the text itself: the end, a head at the beginning, or where
|
|
36
|
+
* the ellipsis settles. Use the `head`, `tail`, `ratio` and `fileName` helpers, or a function
|
|
37
|
+
* that returns the offset where the end begins, or `{ head, end, ratio }`.
|
|
38
|
+
*
|
|
39
|
+
* @default tail(6)
|
|
40
|
+
*/
|
|
41
|
+
split?: SplitFunction;
|
|
42
|
+
/**
|
|
43
|
+
* Shows the full text in the browser's native tooltip while the text is truncated. A `title`
|
|
44
|
+
* attribute you pass takes precedence and is shown at all times.
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
showTitle?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the text is currently truncated. Read it with `bind:truncated`, for example to show
|
|
51
|
+
* a custom tooltip. Updates when the text, the available width or the fonts change. Always
|
|
52
|
+
* `false` during server-side rendering.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
truncated?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* How many lines the text may wrap over before it is cut in the middle. The ellipsis goes on
|
|
59
|
+
* the last line, right before the end, or right after the head with a `head` split. With more
|
|
60
|
+
* than one line, the component is block-level and takes its width from its container, the text
|
|
61
|
+
* wraps at spaces, and anywhere else a line has no room, and a `ratio` is ignored. A value
|
|
62
|
+
* that isn't a whole number of at least `1` is rounded down, or counts as `1`.
|
|
63
|
+
*
|
|
64
|
+
* @default 1
|
|
65
|
+
*/
|
|
66
|
+
lines?: number;
|
|
67
|
+
}
|
|
68
|
+
export type { MiddleEllipsisProps, SplitFunction, SplitIndices };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "svelte-middle-ellipsis",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Middle ellipsis for Svelte 5: truncates text in the middle with CSS, keeping the end visible and the ellipsis right up against it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Finn Voigtländer",
|
|
7
|
+
"homepage": "https://middle-ellipsis.finn-vgtl.dev/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/finn-vgtl/svelte-middle-ellipsis.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/finn-vgtl/svelte-middle-ellipsis/issues"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite dev",
|
|
17
|
+
"build": "vite build && npm run prepack",
|
|
18
|
+
"preview": "vite preview",
|
|
19
|
+
"prepare": "svelte-kit sync || echo ''",
|
|
20
|
+
"prepack": "svelte-kit sync && svelte-package && publint",
|
|
21
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
22
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
23
|
+
"check:svelte-floor": "node scripts/check-svelte-floor.js",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"lint": "biome check .",
|
|
28
|
+
"format": "biome check --write .",
|
|
29
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
30
|
+
"changelog": "git-cliff --unreleased --bump --strip all"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"CHANGELOG.md",
|
|
35
|
+
"!dist/**/*.test.*",
|
|
36
|
+
"!dist/**/*.spec.*"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": [
|
|
39
|
+
"**/*.css"
|
|
40
|
+
],
|
|
41
|
+
"svelte": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"type": "module",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"svelte": "./dist/index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"svelte": "^5.7.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@biomejs/biome": "2.6.3",
|
|
58
|
+
"@sveltejs/adapter-static": "^4.0.0",
|
|
59
|
+
"@sveltejs/kit": "^3.0.0",
|
|
60
|
+
"@sveltejs/package": "^2.5.8",
|
|
61
|
+
"@sveltejs/vite-plugin-svelte": "^7.2.0",
|
|
62
|
+
"@tanstack/highlight": "1.2.12",
|
|
63
|
+
"@types/node": "^22.20.5",
|
|
64
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
65
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
66
|
+
"git-cliff": "2.14.2",
|
|
67
|
+
"playwright": "1.64.1",
|
|
68
|
+
"publint": "^0.3.21",
|
|
69
|
+
"svelte": "^5.57.1",
|
|
70
|
+
"svelte-check": "^4.6.0",
|
|
71
|
+
"typescript": "^6.0.3",
|
|
72
|
+
"vite": "^8.3.0",
|
|
73
|
+
"vitest": "5.0.5",
|
|
74
|
+
"vitest-browser-svelte": "3.1.0"
|
|
75
|
+
},
|
|
76
|
+
"keywords": [
|
|
77
|
+
"component",
|
|
78
|
+
"ellipsis",
|
|
79
|
+
"filename",
|
|
80
|
+
"middle-ellipsis",
|
|
81
|
+
"overflow",
|
|
82
|
+
"svelte",
|
|
83
|
+
"svelte5",
|
|
84
|
+
"text-overflow",
|
|
85
|
+
"truncate",
|
|
86
|
+
"truncation",
|
|
87
|
+
"typescript"
|
|
88
|
+
],
|
|
89
|
+
"imports": {
|
|
90
|
+
"#lib": "./src/lib/index.js",
|
|
91
|
+
"#lib/*": "./src/lib/*"
|
|
92
|
+
},
|
|
93
|
+
"packageManager": "pnpm@10.5.2"
|
|
94
|
+
}
|