tangled
alpha
login
or
join now
sajidanwar.com
/
atcute
forked from
mary.my.id/atcute
0
fork
atom
a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
0
fork
atom
overview
issues
pulls
pipelines
refactor(bluesky-richtext-builder): faster UTF-8 encoding
mary.my.id
1 month ago
61ed153b
33f811ad
verified
This commit was signed with the committer's
known signature
.
mary.my.id
SSH Key Fingerprint:
SHA256:ZlTP/auFSGpGnaoDg4mCTG1g9OZvXp62jWR4c6H4O3c=
+15
-5
4 changed files
expand all
collapse all
unified
split
.changeset
stale-years-press.md
packages
bluesky
richtext-builder
lib
index.ts
package.json
pnpm-lock.yaml
+5
.changeset/stale-years-press.md
···
1
1
+
---
2
2
+
'@atcute/bluesky-richtext-builder': patch
3
3
+
---
4
4
+
5
5
+
faster UTF-8 encoding
+5
-4
packages/bluesky/richtext-builder/lib/index.ts
···
1
1
import type { AppBskyRichtextFacet } from '@atcute/bluesky';
2
2
import type { Did, GenericUri } from '@atcute/lexicons';
3
3
+
import { getUtf8Length } from '@atcute/uint8array';
3
4
4
5
type UnwrapArray<T> = T extends (infer V)[] ? V : never;
5
6
···
7
8
export type Facet = AppBskyRichtextFacet.Main;
8
9
/** Feature union type from Facet['features'] */
9
10
export type FacetFeature = UnwrapArray<Facet['features']>;
10
10
-
11
11
-
const encoder = new TextEncoder();
12
11
13
12
/** Resulting rich text */
14
13
export interface BakedRichtext {
···
88
87
// Calculate the starting index
89
88
let start = 0;
90
89
91
91
-
start += encoder.encode(segments[last] as string).byteLength;
90
90
+
start += getUtf8Length(segments[last] as string);
92
91
if (last !== 0) {
93
92
start += (segments[last - 1] as Facet).index.byteEnd;
94
93
}
95
94
95
95
+
const byteLength = getUtf8Length(substr);
96
96
+
96
97
const facet: Facet = {
97
98
index: {
98
99
byteStart: start,
99
99
-
byteEnd: start + encoder.encode(substr).byteLength,
100
100
+
byteEnd: start + byteLength,
100
101
},
101
102
features: [feature],
102
103
};
+2
-1
packages/bluesky/richtext-builder/package.json
···
30
30
},
31
31
"dependencies": {
32
32
"@atcute/bluesky": "workspace:^",
33
33
-
"@atcute/lexicons": "workspace:^"
33
33
+
"@atcute/lexicons": "workspace:^",
34
34
+
"@atcute/uint8array": "workspace:^"
34
35
}
35
36
}
+3
pnpm-lock.yaml
···
66
66
'@atcute/lexicons':
67
67
specifier: workspace:^
68
68
version: link:../../lexicons/lexicons
69
69
+
'@atcute/uint8array':
70
70
+
specifier: workspace:^
71
71
+
version: link:../../misc/uint8array
69
72
70
73
packages/bluesky/richtext-parser:
71
74
devDependencies: