@flighthq/text 0.5.1-next.920.da8f530 → 0.6.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.
Files changed (69) hide show
  1. package/README.md +2 -2
  2. package/dist/.tsbuildinfo.contract +1 -0
  3. package/dist/.tsbuildinfo.runtime +1 -0
  4. package/dist/contract.d.ts +12 -10
  5. package/dist/contract.d.ts.map +1 -1
  6. package/dist/contract.js +13 -10
  7. package/dist/contract.js.map +1 -1
  8. package/dist/contract.text-types.d.ts +2 -0
  9. package/dist/contract.text-types.d.ts.map +1 -0
  10. package/dist/contract.text-types.js +2 -0
  11. package/dist/contract.text-types.js.map +1 -0
  12. package/dist/enableTextLabelGuards.d.ts +2 -1
  13. package/dist/enableTextLabelGuards.d.ts.map +1 -1
  14. package/dist/enableTextLabelGuards.js +6 -6
  15. package/dist/enableTextLabelGuards.js.map +1 -1
  16. package/dist/explainTextLabelContent.d.ts +1 -1
  17. package/dist/explainTextLabelContent.d.ts.map +1 -1
  18. package/dist/explainTextLabelContent.js.map +1 -1
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/nativeText.d.ts +10 -5
  24. package/dist/nativeText.d.ts.map +1 -1
  25. package/dist/nativeText.js +14 -14
  26. package/dist/nativeText.js.map +1 -1
  27. package/dist/richText.d.ts +11 -4
  28. package/dist/richText.d.ts.map +1 -1
  29. package/dist/richText.js +97 -30
  30. package/dist/richText.js.map +1 -1
  31. package/dist/richTextContent.d.ts +6 -0
  32. package/dist/richTextContent.d.ts.map +1 -0
  33. package/dist/richTextContent.js +311 -0
  34. package/dist/richTextContent.js.map +1 -0
  35. package/dist/richTextMetrics.d.ts +10 -0
  36. package/dist/richTextMetrics.d.ts.map +1 -0
  37. package/dist/richTextMetrics.js +53 -0
  38. package/dist/richTextMetrics.js.map +1 -0
  39. package/dist/textFormatFont.d.ts +2 -2
  40. package/dist/textFormatFont.d.ts.map +1 -1
  41. package/dist/textFormatFont.js +4 -2
  42. package/dist/textFormatFont.js.map +1 -1
  43. package/dist/textLabel.d.ts +11 -5
  44. package/dist/textLabel.d.ts.map +1 -1
  45. package/dist/textLabel.js +17 -16
  46. package/dist/textLabel.js.map +1 -1
  47. package/dist/textLabelLayout.d.ts +6 -4
  48. package/dist/textLabelLayout.d.ts.map +1 -1
  49. package/dist/textLabelLayout.js +16 -7
  50. package/dist/textLabelLayout.js.map +1 -1
  51. package/dist/textLayoutRuntime.d.ts +5 -0
  52. package/dist/textLayoutRuntime.d.ts.map +1 -0
  53. package/dist/textLayoutRuntime.js +11 -0
  54. package/dist/textLayoutRuntime.js.map +1 -0
  55. package/dist/types.d.ts +141 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/types.js +4 -0
  58. package/dist/types.js.map +1 -0
  59. package/package.json +12 -10
  60. package/src/enableTextLabelGuards.test.ts +13 -10
  61. package/src/explainTextLabelContent.test.ts +7 -4
  62. package/src/nativeText.test.ts +49 -16
  63. package/src/richText.test.ts +276 -70
  64. package/src/richTextContent.test.ts +154 -0
  65. package/src/richTextMetrics.test.ts +153 -0
  66. package/src/textFormatFont.test.ts +74 -16
  67. package/src/textLabel.test.ts +62 -20
  68. package/src/textLabelLayout.test.ts +31 -5
  69. package/src/textLayoutRuntime.test.ts +20 -0
@@ -0,0 +1,5 @@
1
+ import type { TextLayoutResult } from '@flighthq/textlayout/contract';
2
+ import type { TextLabelRuntime } from './types.ts';
3
+ export declare function clearTextLayoutResult(runtime: TextLabelRuntime): void;
4
+ export declare function getTextLayoutResult(runtime: TextLabelRuntime): TextLayoutResult;
5
+ //# sourceMappingURL=textLayoutRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textLayoutRuntime.d.ts","sourceRoot":"","sources":["../src/textLayoutRuntime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAErE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAK/E"}
@@ -0,0 +1,11 @@
1
+ import { createTextLayoutResult } from '@flighthq/textlayout/contract';
2
+ export function clearTextLayoutResult(runtime) {
3
+ runtime.textLayout = null;
4
+ }
5
+ export function getTextLayoutResult(runtime) {
6
+ if (runtime.textLayout === null) {
7
+ runtime.textLayout = createTextLayoutResult();
8
+ }
9
+ return runtime.textLayout;
10
+ }
11
+ //# sourceMappingURL=textLayoutRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textLayoutRuntime.js","sourceRoot":"","sources":["../src/textLayoutRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAKvE,MAAM,UAAU,qBAAqB,CAAC,OAAyB;IAC7D,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAChC,OAAO,CAAC,UAAU,GAAG,sBAAsB,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { EntityRaw } from '@flighthq/entity/contract';
2
+ import type { Node2D, Node2DData, Node2DRuntime } from '@flighthq/scene2d/contract';
3
+ import type { Signal } from '@flighthq/signals/contract';
4
+ import type { TextFormat, TextFormatAlign, TextFormatRangeRaw as TextFormatRange } from '@flighthq/textformat/contract';
5
+ import type { RichTextContent, TextAutoSize, TextLayoutParams, TextLayoutResult, TextMeasureFunction, TextVerticalAlign } from '@flighthq/textlayout/contract';
6
+ export interface TextLabelData extends Node2DData {
7
+ autoSize: TextAutoSize;
8
+ height: number;
9
+ text: string;
10
+ textFormat: TextFormat;
11
+ verticalAlign: TextVerticalAlign;
12
+ width: number;
13
+ }
14
+ export interface TextLabelRuntime extends Node2DRuntime {
15
+ buildTextLayoutParams: (source: Readonly<TextLabel>, measure: TextMeasureFunction) => TextLayoutParams;
16
+ textLayout: TextLayoutResult | null;
17
+ textLayoutUsingContentId: number;
18
+ textLayoutUsingText: string | null;
19
+ }
20
+ export interface TextLabel extends Node2D {
21
+ data: TextLabelData;
22
+ }
23
+ export declare const TextLabelKind = "TextLabel";
24
+ export interface NativeTextStyle {
25
+ align?: TextFormatAlign;
26
+ bold?: boolean;
27
+ color?: number;
28
+ font?: string;
29
+ italic?: boolean;
30
+ leading?: number;
31
+ size?: number;
32
+ }
33
+ export interface NativeTextData extends Node2DData {
34
+ autoSize: TextAutoSize;
35
+ height: number;
36
+ style: NativeTextStyle;
37
+ text: string;
38
+ verticalAlign: TextVerticalAlign;
39
+ width: number;
40
+ }
41
+ export interface NativeTextRuntime extends Node2DRuntime {
42
+ element: HTMLElement | null;
43
+ measuredHeight: number;
44
+ measuredWidth: number;
45
+ }
46
+ export interface NativeText extends Node2D {
47
+ data: NativeTextData;
48
+ }
49
+ export declare const NativeTextKind = "NativeText";
50
+ export interface TextInputHistoryEntry {
51
+ caretIndexAfter: number;
52
+ caretIndexBefore: number;
53
+ mergeKind: string | null;
54
+ selectionIndexAfter: number;
55
+ selectionIndexBefore: number;
56
+ textAfter: string;
57
+ textBefore: string;
58
+ }
59
+ export interface TextInputState {
60
+ alwaysShowSelection: boolean;
61
+ caretColor: number;
62
+ caretIndex: number;
63
+ caretWidth: number;
64
+ desiredCaretX: number;
65
+ displayAsPassword: boolean;
66
+ focused: boolean;
67
+ history: TextInputHistoryEntry[];
68
+ historyIndex: number;
69
+ historyLimit: number;
70
+ passwordCharacter: string;
71
+ restrict: string;
72
+ selectionAlpha: number;
73
+ selectionColor: number;
74
+ selectionIndex: number;
75
+ }
76
+ export interface TextInputOptions {
77
+ alwaysShowSelection?: boolean;
78
+ caretColor?: number;
79
+ caretWidth?: number;
80
+ displayAsPassword?: boolean;
81
+ historyLimit?: number;
82
+ passwordCharacter?: string;
83
+ restrict?: string;
84
+ selectionAlpha?: number;
85
+ selectionColor?: number;
86
+ }
87
+ export interface TextFieldChangeEvent {
88
+ previousText: string;
89
+ text: string;
90
+ }
91
+ export interface TextFieldLinkEvent {
92
+ url: string;
93
+ x: number;
94
+ y: number;
95
+ }
96
+ export interface TextFieldScrollEvent {
97
+ previousScrollH: number;
98
+ previousScrollV: number;
99
+ scrollH: number;
100
+ scrollV: number;
101
+ }
102
+ export interface TextFieldSignals extends EntityRaw {
103
+ onTextFieldChange: Signal<Readonly<TextFieldChangeEvent>>;
104
+ onTextFieldLink: Signal<Readonly<TextFieldLinkEvent>>;
105
+ onTextFieldScroll: Signal<Readonly<TextFieldScrollEvent>>;
106
+ }
107
+ export interface RichTextData extends TextLabelData {
108
+ background: boolean;
109
+ backgroundColor: number;
110
+ border: boolean;
111
+ borderColor: number;
112
+ condenseWhite: boolean;
113
+ defaultTextFormat: TextFormat;
114
+ maxChars: number;
115
+ mouseWheelEnabled: boolean;
116
+ multiline: boolean;
117
+ scrollH: number;
118
+ scrollV: number;
119
+ selectable: boolean;
120
+ textColor: number;
121
+ textFormatRanges: TextFormatRange[];
122
+ wordWrap: boolean;
123
+ }
124
+ export interface RichTextRuntime extends TextLabelRuntime {
125
+ input: TextInputState | null;
126
+ richTextContent: RichTextContent | undefined;
127
+ selectionBeginIndex: number;
128
+ selectionEndIndex: number;
129
+ textFieldSignals: TextFieldSignals | null;
130
+ }
131
+ export interface RichText extends TextLabel {
132
+ data: RichTextData;
133
+ }
134
+ export declare const RichTextKind = "RichText";
135
+ export interface TextLabelContentExplanation {
136
+ agreement: boolean;
137
+ liveString: string;
138
+ rasterizedString: string | null;
139
+ revision: number;
140
+ }
141
+ //# sourceMappingURL=types.d.ts.map
@@ -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EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,UAAU,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,eAAe,GAAG,SAAS,CAAC;IAC7C,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,QAAS,SAAQ,SAAS;IACzC,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ export const TextLabelKind = 'TextLabel';
2
+ export const NativeTextKind = 'NativeText';
3
+ export const RichTextKind = 'RichText';
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AA+BzC,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAgG3C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/text",
3
- "version": "0.5.1-next.920.da8f530",
3
+ "version": "0.6.0",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,23 +32,25 @@
32
32
  "scripts": {
33
33
  "build": "tsc -b",
34
34
  "clean": "tsc -b --clean",
35
+ "generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-text --package text --lenient",
36
+ "generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-text --package text --lenient --check",
35
37
  "test": "vitest run --config vitest.config.ts",
36
38
  "test:watch": "vitest --watch --config vitest.config.ts",
37
39
  "prepack": "npm run clean && npm run clean:dist && npm run build",
38
40
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
41
  },
40
42
  "dependencies": {
41
- "@flighthq/scene2d": "0.5.1-next.920.da8f530",
42
- "@flighthq/entity": "0.5.1-next.920.da8f530",
43
- "@flighthq/geometry": "0.5.1-next.920.da8f530",
44
- "@flighthq/log": "0.5.1-next.920.da8f530",
45
- "@flighthq/node": "0.5.1-next.920.da8f530",
46
- "@flighthq/signals": "0.5.1-next.920.da8f530",
47
- "@flighthq/textlayout": "0.5.1-next.920.da8f530",
48
- "@flighthq/types": "0.5.1-next.920.da8f530"
43
+ "@flighthq/scene2d": "0.6.0",
44
+ "@flighthq/entity": "0.6.0",
45
+ "@flighthq/geometry": "0.6.0",
46
+ "@flighthq/log": "0.6.0",
47
+ "@flighthq/node": "0.6.0",
48
+ "@flighthq/signals": "0.6.0",
49
+ "@flighthq/textformat": "0.6.0",
50
+ "@flighthq/textlayout": "0.6.0"
49
51
  },
50
52
  "devDependencies": {
51
- "typescript": "^5.3.0"
53
+ "typescript": "^7.0.2"
52
54
  },
53
55
  "description": "Text display objects: single-format TextLabel and multi-format RichText built on the text-layout spine",
54
56
  "sideEffects": false
@@ -1,24 +1,27 @@
1
- import { setLogSink } from '@flighthq/log/contract';
1
+ import type { LogState } from '@flighthq/log/contract';
2
+ import { createLogState, setLogSink } from '@flighthq/log/contract';
3
+ import type { LogEntry } from '@flighthq/log/contract';
2
4
  import { setTextLayoutMeasureProvider } from '@flighthq/textlayout/contract';
3
- import type { LogEntry } from '@flighthq/types/contract';
4
5
 
5
- import { disableTextLabelGuards, enableTextLabelGuards } from './enableTextLabelGuards';
6
- import { createTextLabel, setTextLabelString } from './textLabel';
7
- import { ensureTextLayout } from './textLabelLayout';
6
+ import { disableTextLabelGuards, enableTextLabelGuards } from './enableTextLabelGuards.ts';
7
+ import { createTextLabel, setTextLabelString } from './textLabel.ts';
8
+ import { ensureTextLayout } from './textLabelLayout.ts';
8
9
 
9
10
  const measure = (text: string) => text.length * 7;
10
11
 
11
12
  let entries: LogEntry[];
13
+ let logState: LogState;
12
14
 
13
15
  beforeEach(() => {
14
16
  entries = [];
15
- setLogSink((entry) => entries.push(entry));
17
+ logState = createLogState();
18
+ setLogSink(logState, (entry) => entries.push(entry));
16
19
  setTextLayoutMeasureProvider(measure);
17
20
  });
18
21
 
19
22
  afterEach(() => {
20
23
  disableTextLabelGuards();
21
- setLogSink(null);
24
+ setLogSink(logState, null);
22
25
  setTextLayoutMeasureProvider(null);
23
26
  });
24
27
 
@@ -28,7 +31,7 @@ function messages(): string {
28
31
 
29
32
  describe('disableTextLabelGuards', () => {
30
33
  it('stops the warning a previously-installed guard would emit', () => {
31
- enableTextLabelGuards();
34
+ enableTextLabelGuards(logState, () => 0);
32
35
  disableTextLabelGuards();
33
36
 
34
37
  const label = createTextLabel();
@@ -43,7 +46,7 @@ describe('disableTextLabelGuards', () => {
43
46
 
44
47
  describe('enableTextLabelGuards', () => {
45
48
  it('warns with both the live and rasterized strings when data.text is mutated directly', () => {
46
- enableTextLabelGuards();
49
+ enableTextLabelGuards(logState, () => 0);
47
50
 
48
51
  const label = createTextLabel();
49
52
  setTextLabelString(label, 'original text');
@@ -58,7 +61,7 @@ describe('enableTextLabelGuards', () => {
58
61
  });
59
62
 
60
63
  it('stays silent when text is changed via setTextLabelString', () => {
61
- enableTextLabelGuards();
64
+ enableTextLabelGuards(logState, () => 0);
62
65
 
63
66
  const label = createTextLabel();
64
67
  setTextLabelString(label, 'first');
@@ -1,8 +1,8 @@
1
1
  import { setTextLayoutMeasureProvider } from '@flighthq/textlayout/contract';
2
2
 
3
- import { explainTextLabelContent } from './explainTextLabelContent';
4
- import { createTextLabel, setTextLabelString } from './textLabel';
5
- import { ensureTextLayout } from './textLabelLayout';
3
+ import { explainTextLabelContent } from './explainTextLabelContent.ts';
4
+ import { createTextLabel, setTextLabelString } from './textLabel.ts';
5
+ import { ensureTextLayout } from './textLabelLayout.ts';
6
6
 
7
7
  const measure = (text: string) => text.length * 7;
8
8
 
@@ -12,7 +12,10 @@ afterEach(() => {
12
12
 
13
13
  describe('explainTextLabelContent', () => {
14
14
  it('reports agreement when no layout has been computed yet', () => {
15
- const label = createTextLabel({ data: { text: 'hello' } });
15
+ const label = ((created) => {
16
+ Object.assign(created.data, { text: 'hello' });
17
+ return created;
18
+ })(createTextLabel());
16
19
 
17
20
  const explanation = explainTextLabelContent(label);
18
21
  expect(explanation.agreement).toBe(true);
@@ -4,8 +4,7 @@ import {
4
4
  getNodeLocalContentRevision,
5
5
  getNodeLocalTransformRevision,
6
6
  } from '@flighthq/node/contract';
7
- import type { NativeText, NativeTextRuntime, Node, PartialNode } from '@flighthq/types/contract';
8
- import { NativeTextKind } from '@flighthq/types/contract';
7
+ import type { Node, PartialNode } from '@flighthq/node/contract';
9
8
 
10
9
  import {
11
10
  computeNativeTextLocalBoundsRectangle,
@@ -25,33 +24,44 @@ import {
25
24
  setNativeTextStyle,
26
25
  setNativeTextVerticalAlign,
27
26
  setNativeTextWidth,
28
- } from './nativeText';
27
+ } from './nativeText.ts';
28
+ import type { NativeText, NativeTextRuntime } from './types.ts';
29
+ import { NativeTextKind } from './types.ts';
29
30
 
30
31
  describe('computeNativeTextLocalBoundsRectangle', () => {
31
32
  it('sets out dimensions from data width and height when autoSize is none', () => {
32
- const native = createNativeText({ data: { width: 200, height: 50 } });
33
+ const native = ((created) => {
34
+ Object.assign(created.data, { width: 200, height: 50 });
35
+ return created;
36
+ })(createNativeText());
33
37
  const out = createRectangle();
34
- computeNativeTextLocalBoundsRectangle(out, native as unknown as Node);
38
+ computeNativeTextLocalBoundsRectangle(out, native);
35
39
  expect(out.x).toBe(0);
36
40
  expect(out.width).toBe(200);
37
41
  expect(out.height).toBe(50);
38
42
  });
39
43
 
40
44
  it('falls back to the fixed box under autoSize until the element has been measured', () => {
41
- const native = createNativeText({ data: { autoSize: 'left', width: 200, height: 50 } });
45
+ const native = ((created) => {
46
+ Object.assign(created.data, { autoSize: 'left', width: 200, height: 50 });
47
+ return created;
48
+ })(createNativeText());
42
49
  const out = createRectangle();
43
- computeNativeTextLocalBoundsRectangle(out, native as unknown as Node);
50
+ computeNativeTextLocalBoundsRectangle(out, native);
44
51
  expect(out.width).toBe(200);
45
52
  expect(out.height).toBe(50);
46
53
  });
47
54
 
48
55
  it('uses the measured size the platform renderer wrote back under autoSize', () => {
49
- const native = createNativeText({ data: { autoSize: 'left', width: 200, height: 50 } });
56
+ const native = ((created) => {
57
+ Object.assign(created.data, { autoSize: 'left', width: 200, height: 50 });
58
+ return created;
59
+ })(createNativeText());
50
60
  const runtime = getNativeTextRuntime(native) as NativeTextRuntime;
51
61
  runtime.measuredWidth = 80;
52
62
  runtime.measuredHeight = 24;
53
63
  const out = createRectangle();
54
- computeNativeTextLocalBoundsRectangle(out, native as unknown as Node);
64
+ computeNativeTextLocalBoundsRectangle(out, native);
55
65
  expect(out.width).toBe(80);
56
66
  expect(out.height).toBe(24);
57
67
  });
@@ -82,7 +92,15 @@ describe('createNativeText', () => {
82
92
  height: 40,
83
93
  },
84
94
  };
85
- const obj = createNativeText(base);
95
+ const obj = ((created, fields) => {
96
+ const entityData = created.data;
97
+ Object.assign(created, fields);
98
+ if (fields.data !== undefined) {
99
+ Object.assign(entityData, fields.data);
100
+ Object.assign(created, { data: entityData });
101
+ }
102
+ return created;
103
+ })(createNativeText(), base);
86
104
  expect(obj.data.autoSize).toStrictEqual(base.data!.autoSize);
87
105
  expect(obj.data.text).toStrictEqual(base.data!.text);
88
106
  expect(obj.data.width).toBe(300);
@@ -102,7 +120,7 @@ describe('createNativeTextData', () => {
102
120
  });
103
121
 
104
122
  it('allows pre-defined values', () => {
105
- const data = createNativeTextData({ autoSize: 'left', text: 'hello', width: 250, height: 30 });
123
+ const data = Object.assign(createNativeTextData(), { autoSize: 'left', text: 'hello', width: 250, height: 30 });
106
124
  expect(data.autoSize).toBe('left');
107
125
  expect(data.text).toBe('hello');
108
126
  expect(data.width).toBe(250);
@@ -161,7 +179,10 @@ describe('getNativeTextRuntime', () => {
161
179
 
162
180
  describe('getNativeTextString', () => {
163
181
  it('returns the text field', () => {
164
- const native = createNativeText({ data: { text: 'hello' } });
182
+ const native = ((created) => {
183
+ Object.assign(created.data, { text: 'hello' });
184
+ return created;
185
+ })(createNativeText());
165
186
  expect(getNativeTextString(native)).toBe('hello');
166
187
  });
167
188
  });
@@ -169,7 +190,10 @@ describe('getNativeTextString', () => {
169
190
  describe('getNativeTextStyle', () => {
170
191
  it('returns the style field', () => {
171
192
  const style = { size: 16, bold: true };
172
- const native = createNativeText({ data: { style } });
193
+ const native = ((created) => {
194
+ Object.assign(created.data, { style });
195
+ return created;
196
+ })(createNativeText());
173
197
  expect(getNativeTextStyle(native)).toBe(native.data.style);
174
198
  });
175
199
  });
@@ -182,7 +206,10 @@ describe('initializeNativeTextData', () => {
182
206
 
183
207
  describe('patchNativeTextStyle', () => {
184
208
  it('merges the patch into the existing style', () => {
185
- const native = createNativeText({ data: { style: { size: 14, bold: false } } });
209
+ const native = ((created) => {
210
+ Object.assign(created.data, { style: { size: 14, bold: false } });
211
+ return created;
212
+ })(createNativeText());
186
213
  patchNativeTextStyle(native, { bold: true, color: 0xff0000ff });
187
214
  expect(native.data.style.size).toBe(14);
188
215
  expect(native.data.style.bold).toBe(true);
@@ -238,7 +265,10 @@ describe('setNativeTextString', () => {
238
265
  });
239
266
 
240
267
  it('does not bump content when the value is unchanged', () => {
241
- const native = createNativeText({ data: { text: 'same' } });
268
+ const native = ((created) => {
269
+ Object.assign(created.data, { text: 'same' });
270
+ return created;
271
+ })(createNativeText());
242
272
  const content = getNodeLocalContentRevision(native);
243
273
  setNativeTextString(native, 'same');
244
274
  expect(getNodeLocalContentRevision(native)).toBe(content);
@@ -272,7 +302,10 @@ describe('setNativeTextVerticalAlign', () => {
272
302
  });
273
303
 
274
304
  it('does not bump content when the value is unchanged', () => {
275
- const native = createNativeText({ data: { verticalAlign: 'bottom' } });
305
+ const native = ((created) => {
306
+ Object.assign(created.data, { verticalAlign: 'bottom' });
307
+ return created;
308
+ })(createNativeText());
276
309
  const content = getNodeLocalContentRevision(native);
277
310
  setNativeTextVerticalAlign(native, 'bottom');
278
311
  expect(getNodeLocalContentRevision(native)).toBe(content);