@flighthq/textlayout 0.5.1-next.1350.8ce488b → 0.5.1-next.1404.457d1da
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
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/textlayout`. The `@f
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/textlayout@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/textlayout@0.5.1-next.1404.457d1da](https://github.com/flighthq/flight/tree/457d1da918a60be5853b84eb6c25530a66662cef/packages/textlayout)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/457d1da918a60be5853b84eb6c25530a66662cef/LICENSE.md)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TextMeasureFunction } from '@flighthq/types/contract';
|
|
2
|
-
export declare function getTextLayoutMeasureProvider(): TextMeasureFunction | null;
|
|
1
|
+
import type { HostTextShaperCapability, TextMeasureFunction } from '@flighthq/types/contract';
|
|
2
|
+
export declare function getTextLayoutMeasureProvider(hostTextShaper?: Readonly<HostTextShaperCapability>): TextMeasureFunction | null;
|
|
3
3
|
export declare function setTextLayoutMeasureProvider(measure: TextMeasureFunction | null): void;
|
|
4
4
|
//# sourceMappingURL=textLayoutMeasure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textLayoutMeasure.d.ts","sourceRoot":"","sources":["../src/textLayoutMeasure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"textLayoutMeasure.d.ts","sourceRoot":"","sources":["../src/textLayoutMeasure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO9F,wBAAgB,4BAA4B,CAC1C,cAAc,CAAC,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAClD,mBAAmB,GAAG,IAAI,CAI5B;AAMD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAEtF"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// Resolves the text-measurement provider text-layout uses to turn characters into advances.
|
|
3
|
-
// is
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
// available.
|
|
9
|
-
export function getTextLayoutMeasureProvider() {
|
|
1
|
+
import { measureText } from '@flighthq/textshaper/contract';
|
|
2
|
+
// Resolves the text-measurement provider text-layout uses to turn characters into advances. When a
|
|
3
|
+
// HostTextShaperCapability is supplied, it returns a bound measure function that delegates to
|
|
4
|
+
// measureText. An explicitly set provider (setTextLayoutMeasureProvider) still takes precedence — it
|
|
5
|
+
// is the direct-injection escape hatch for tests and bespoke hosts. Null when neither exists,
|
|
6
|
+
// exactly as before, so ensureRichTextLayout leaves the layout stale until shaping is available.
|
|
7
|
+
export function getTextLayoutMeasureProvider(hostTextShaper) {
|
|
10
8
|
if (_measureProvider !== null)
|
|
11
9
|
return _measureProvider;
|
|
12
|
-
if (
|
|
13
|
-
return measureText;
|
|
10
|
+
if (hostTextShaper !== undefined)
|
|
11
|
+
return (text, format) => measureText(hostTextShaper, text, format);
|
|
14
12
|
return null;
|
|
15
13
|
}
|
|
16
14
|
// Installs an explicit measure provider, bypassing the shaper seam. Pass null to clear it and fall
|
|
17
|
-
// back to the
|
|
18
|
-
// for direct injection (tests, a host
|
|
15
|
+
// back to the host text shaper. Prefer passing a HostTextShaperCapability to
|
|
16
|
+
// getTextLayoutMeasureProvider for normal setup; this remains for direct injection (tests, a host
|
|
17
|
+
// wiring its own measure without a full HostTextShaperCapability).
|
|
19
18
|
export function setTextLayoutMeasureProvider(measure) {
|
|
20
19
|
_measureProvider = measure;
|
|
21
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textLayoutMeasure.js","sourceRoot":"","sources":["../src/textLayoutMeasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"textLayoutMeasure.js","sourceRoot":"","sources":["../src/textLayoutMeasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAG5D,mGAAmG;AACnG,8FAA8F;AAC9F,qGAAqG;AACrG,8FAA8F;AAC9F,iGAAiG;AACjG,MAAM,UAAU,4BAA4B,CAC1C,cAAmD;IAEnD,IAAI,gBAAgB,KAAK,IAAI;QAAE,OAAO,gBAAgB,CAAC;IACvD,IAAI,cAAc,KAAK,SAAS;QAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACrG,OAAO,IAAI,CAAC;AACd,CAAC;AAED,mGAAmG;AACnG,6EAA6E;AAC7E,kGAAkG;AAClG,mEAAmE;AACnE,MAAM,UAAU,4BAA4B,CAAC,OAAmC;IAC9E,gBAAgB,GAAG,OAAO,CAAC;AAC7B,CAAC;AAED,IAAI,gBAAgB,GAA+B,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/textlayout",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.1404.457d1da",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/textshaper": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.1404.457d1da",
|
|
42
|
+
"@flighthq/textshaper": "0.5.1-next.1404.457d1da",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.1404.457d1da"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HostTextShaperCapability } from '@flighthq/types/contract';
|
|
2
2
|
|
|
3
3
|
import { getTextLayoutMeasureProvider, setTextLayoutMeasureProvider } from './textLayoutMeasure';
|
|
4
4
|
|
|
5
5
|
afterEach(() => {
|
|
6
6
|
setTextLayoutMeasureProvider(null);
|
|
7
|
-
setTextShaperBackend(null);
|
|
8
7
|
});
|
|
9
8
|
|
|
10
9
|
describe('getTextLayoutMeasureProvider', () => {
|
|
11
|
-
it('returns null before a provider or shaper
|
|
10
|
+
it('returns null before a provider or host text shaper is supplied', () => {
|
|
12
11
|
expect(getTextLayoutMeasureProvider()).toBeNull();
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
it('
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
it('returns a bound measure function when a host text shaper is provided', () => {
|
|
15
|
+
const backend: HostTextShaperCapability = { measureText: (text) => text.length };
|
|
16
|
+
const measure = getTextLayoutMeasureProvider(backend);
|
|
17
|
+
expect(measure).not.toBeNull();
|
|
18
|
+
expect(measure!('abc', {})).toBe(3);
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
it('prefers an explicitly set provider over the shaper
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
setTextLayoutMeasureProvider(
|
|
24
|
-
expect(getTextLayoutMeasureProvider()).toBe(
|
|
21
|
+
it('prefers an explicitly set provider over the host text shaper', () => {
|
|
22
|
+
const explicit = (text: string) => text.length * 10;
|
|
23
|
+
const backend: HostTextShaperCapability = { measureText: () => 99 };
|
|
24
|
+
setTextLayoutMeasureProvider(explicit);
|
|
25
|
+
expect(getTextLayoutMeasureProvider(backend)).toBe(explicit);
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
28
|
|