@mlightcad/mtext-input-box 0.2.6 → 0.2.8
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/dist/viewer/format.js +11 -2
- package/dist/viewer/types.d.ts +17 -1
- package/dist/viewer/viewer.d.ts +42 -0
- package/dist/viewer/viewer.js +222 -17
- package/package.json +3 -2
package/dist/viewer/format.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MTextParagraphAlignment } from '@mlightcad/mtext-renderer';
|
|
1
2
|
export const DEFAULT_FONT_FAMILY = 'simkai';
|
|
2
3
|
/** Returns default character format. */
|
|
3
4
|
export function defaultCharFormat() {
|
|
@@ -11,7 +12,11 @@ export function defaultCharFormat() {
|
|
|
11
12
|
strike: false,
|
|
12
13
|
script: 'normal',
|
|
13
14
|
aci: null,
|
|
14
|
-
rgb: 0xffffff
|
|
15
|
+
rgb: 0xffffff,
|
|
16
|
+
obliqueAngle: 0,
|
|
17
|
+
widthFactor: 1,
|
|
18
|
+
tracking: 1,
|
|
19
|
+
paragraphAlignment: MTextParagraphAlignment.DEFAULT
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
22
|
/** Compares two formats. */
|
|
@@ -25,5 +30,9 @@ export function sameFormat(a, b) {
|
|
|
25
30
|
a.strike === b.strike &&
|
|
26
31
|
a.script === b.script &&
|
|
27
32
|
a.aci === b.aci &&
|
|
28
|
-
a.rgb === b.rgb
|
|
33
|
+
a.rgb === b.rgb &&
|
|
34
|
+
a.obliqueAngle === b.obliqueAngle &&
|
|
35
|
+
a.widthFactor === b.widthFactor &&
|
|
36
|
+
a.tracking === b.tracking &&
|
|
37
|
+
a.paragraphAlignment === b.paragraphAlignment);
|
|
29
38
|
}
|
package/dist/viewer/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Box, CursorStyle, SelectionStyle } from '@mlightcad/text-box-cursor';
|
|
2
|
-
import type { ColorSettings, MTextColor, TextStyle } from '@mlightcad/mtext-renderer';
|
|
2
|
+
import type { ColorSettings, MTextColor, MTextParagraphAlignment, TextStyle } from '@mlightcad/mtext-renderer';
|
|
3
3
|
import type * as THREE from 'three';
|
|
4
4
|
/** Vertical script style for a character run. */
|
|
5
5
|
export type CharScript = 'normal' | 'superscript' | 'subscript';
|
|
@@ -25,6 +25,22 @@ export interface CharFormat {
|
|
|
25
25
|
aci: number | null;
|
|
26
26
|
/** Explicit RGB color packed as `0xRRGGBB`. */
|
|
27
27
|
rgb: number | null;
|
|
28
|
+
/**
|
|
29
|
+
* Character slant in degrees (AutoCAD oblique; negative leans the other way).
|
|
30
|
+
* Serialized to MTEXT as `\Qangle;`.
|
|
31
|
+
*/
|
|
32
|
+
obliqueAngle: number;
|
|
33
|
+
/** Horizontal scale of characters (width factor). Serialized as `\Wvalue;`. */
|
|
34
|
+
widthFactor: number;
|
|
35
|
+
/**
|
|
36
|
+
* Inter-character spacing factor (MTEXT `\T` tracking). `1` is the default spacing.
|
|
37
|
+
*/
|
|
38
|
+
tracking: number;
|
|
39
|
+
/**
|
|
40
|
+
* Paragraph horizontal alignment for the active paragraph (cursor or selection).
|
|
41
|
+
* Uses {@link MTextParagraphAlignment} from the shared MTEXT stack (parser / renderer).
|
|
42
|
+
*/
|
|
43
|
+
paragraphAlignment: MTextParagraphAlignment;
|
|
28
44
|
}
|
|
29
45
|
/** Internal editor state snapshot used for updates and history-like operations. */
|
|
30
46
|
export interface EditorState {
|
package/dist/viewer/viewer.d.ts
CHANGED
|
@@ -25,6 +25,18 @@ export declare class MTextInputBox {
|
|
|
25
25
|
private mtextInsertionOffset;
|
|
26
26
|
private enableWordWrap;
|
|
27
27
|
private mtextString;
|
|
28
|
+
/**
|
|
29
|
+
* Optional line spacing factor forwarded to {@link MTextData.lineSpaceFactor}.
|
|
30
|
+
* When `null`, the renderer default (same as {@link MTextInputBox.DEFAULT_LINE_SPACE_FACTOR}) is used.
|
|
31
|
+
*/
|
|
32
|
+
private editorLineSpaceFactor;
|
|
33
|
+
/**
|
|
34
|
+
* MTEXT attachment (DXF group 71) for the editor box relative to
|
|
35
|
+
* {@link position}. Drives {@link createMTextData} and contextual ribbon
|
|
36
|
+
* "Justify" / attachment controls.
|
|
37
|
+
*/
|
|
38
|
+
private editorAttachmentPoint;
|
|
39
|
+
private static readonly DEFAULT_LINE_SPACE_FACTOR;
|
|
28
40
|
private cursorIndex;
|
|
29
41
|
private selectionStart;
|
|
30
42
|
private selectionEnd;
|
|
@@ -132,6 +144,19 @@ export declare class MTextInputBox {
|
|
|
132
144
|
setCurrentFormat(format: Partial<CharFormat>): void;
|
|
133
145
|
/** Returns current insertion format. */
|
|
134
146
|
getCurrentFormat(): CharFormat;
|
|
147
|
+
/**
|
|
148
|
+
* Sets horizontal alignment for every paragraph that overlaps the current
|
|
149
|
+
* selection or cursor, using the same ids as the contextual ribbon
|
|
150
|
+
* (`default`, `left`, `center`, `right`, `justified`, `distributed`).
|
|
151
|
+
*/
|
|
152
|
+
setParagraphAlignment(alignment: string): void;
|
|
153
|
+
/**
|
|
154
|
+
* Sets the MTEXT attachment point using contextual ribbon codes (`TL`, `MC`,
|
|
155
|
+
* `BR`, etc.), matching AutoCAD nine-point attachment.
|
|
156
|
+
*/
|
|
157
|
+
setAttachmentPoint(attachmentPoint: string): void;
|
|
158
|
+
/** Returns the current attachment as a two-letter ribbon / DXF-style code. */
|
|
159
|
+
getAttachmentPointCode(): string;
|
|
135
160
|
/** Toggles selected alphabetic text between upper and lower case. */
|
|
136
161
|
toggleCase(): void;
|
|
137
162
|
/** Returns renderer default text style defined by `textStyle`. */
|
|
@@ -213,6 +238,20 @@ export declare class MTextInputBox {
|
|
|
213
238
|
private resolveBaseFormatColor;
|
|
214
239
|
private createBaseFormatFromTextStyle;
|
|
215
240
|
private createMTextData;
|
|
241
|
+
/**
|
|
242
|
+
* Line spacing factor used for layout and returned when the host commits the editor.
|
|
243
|
+
* Matches the ribbon / `AcEdMTextEditor` default when no override is set.
|
|
244
|
+
*/
|
|
245
|
+
getLineSpacingFactor(): number;
|
|
246
|
+
/**
|
|
247
|
+
* Applies paragraph line spacing from ribbon-style multiples (`1` = default /
|
|
248
|
+
* single, `2` = default plus one text-line height of extra gap, etc.).
|
|
249
|
+
* Values in `(0, 1)` are still treated as raw renderer `lineSpaceFactor`
|
|
250
|
+
* for callers that set CAD factors directly.
|
|
251
|
+
*/
|
|
252
|
+
setLineSpacingFactor(factor: number): void;
|
|
253
|
+
/** Clears the explicit line spacing override and uses the renderer default. */
|
|
254
|
+
clearLineSpacing(): void;
|
|
216
255
|
private getFallbackLineAdvance;
|
|
217
256
|
private createTextStyle;
|
|
218
257
|
private resolveRenderColorSettings;
|
|
@@ -257,6 +296,9 @@ export declare class MTextInputBox {
|
|
|
257
296
|
private toScriptFromStyle;
|
|
258
297
|
private createDefaultParseContext;
|
|
259
298
|
private createNormalizedDocument;
|
|
299
|
+
private mapRibbonParagraphAlignment;
|
|
300
|
+
private mapRibbonAttachmentCode;
|
|
301
|
+
private attachmentPointToRibbonCode;
|
|
260
302
|
private mergeCharFormat;
|
|
261
303
|
private cloneDocumentStyle;
|
|
262
304
|
private toDocumentStyle;
|
package/dist/viewer/viewer.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CursorRenderer, TextBoxCursor, ThreeJsRendererAdapter } from '@mlightcad/text-box-cursor';
|
|
2
|
-
import { getColorByIndex,
|
|
2
|
+
import { getColorByIndex, LINE_SPACING_SCALE_FACTOR, MText, MTextAttachmentPoint, MTextColor, MTextContext, MTextFlowDirection, MTextLineAlignment, MTextParagraphAlignment, UnifiedRenderer } from '@mlightcad/mtext-renderer';
|
|
3
3
|
import * as THREE from 'three';
|
|
4
|
-
import { MTextContext, MTextLineAlignment } from '@mlightcad/mtext-renderer';
|
|
5
4
|
import { DEFAULT_FONT_FAMILY, defaultCharFormat, sameFormat } from './format';
|
|
6
|
-
import { MTextDocument } from '../model';
|
|
5
|
+
import { hasNodeStyle, MTextDocument } from '../model';
|
|
7
6
|
import { EditorUiAdapter } from '../controller';
|
|
8
7
|
import { MTextToolbar } from '../ui/toolbar';
|
|
9
8
|
/**
|
|
@@ -37,6 +36,18 @@ export class MTextInputBox {
|
|
|
37
36
|
mtextInsertionOffset = new THREE.Vector3(0, 0, 0);
|
|
38
37
|
enableWordWrap;
|
|
39
38
|
mtextString = '';
|
|
39
|
+
/**
|
|
40
|
+
* Optional line spacing factor forwarded to {@link MTextData.lineSpaceFactor}.
|
|
41
|
+
* When `null`, the renderer default (same as {@link MTextInputBox.DEFAULT_LINE_SPACE_FACTOR}) is used.
|
|
42
|
+
*/
|
|
43
|
+
editorLineSpaceFactor = null;
|
|
44
|
+
/**
|
|
45
|
+
* MTEXT attachment (DXF group 71) for the editor box relative to
|
|
46
|
+
* {@link position}. Drives {@link createMTextData} and contextual ribbon
|
|
47
|
+
* "Justify" / attachment controls.
|
|
48
|
+
*/
|
|
49
|
+
editorAttachmentPoint = MTextAttachmentPoint.TopLeft;
|
|
50
|
+
static DEFAULT_LINE_SPACE_FACTOR = 0.3;
|
|
40
51
|
cursorIndex = 0;
|
|
41
52
|
selectionStart = 0;
|
|
42
53
|
selectionEnd = 0;
|
|
@@ -545,7 +556,6 @@ export class MTextInputBox {
|
|
|
545
556
|
if (this.latestCursorLayoutData.lineLayouts) {
|
|
546
557
|
snapshot.lineLayouts = this.latestCursorLayoutData.lineLayouts.map((line) => ({ ...line }));
|
|
547
558
|
}
|
|
548
|
-
console.log(snapshot);
|
|
549
559
|
return snapshot;
|
|
550
560
|
}
|
|
551
561
|
/** Sets current insertion format. */
|
|
@@ -560,7 +570,7 @@ export class MTextInputBox {
|
|
|
560
570
|
for (const node of nodesToUpdate) {
|
|
561
571
|
const nodeFormat = this.toCharFormat(node.style);
|
|
562
572
|
const mergedNodeFormat = this.mergeCharFormat(nodeFormat, format);
|
|
563
|
-
node.style = this.toDocumentStyle(mergedNodeFormat);
|
|
573
|
+
node.style = this.toDocumentStyle(mergedNodeFormat, node.style);
|
|
564
574
|
}
|
|
565
575
|
this.syncUiStateFromDocument();
|
|
566
576
|
this.relayout();
|
|
@@ -572,6 +582,76 @@ export class MTextInputBox {
|
|
|
572
582
|
getCurrentFormat() {
|
|
573
583
|
return { ...this.currentFormat };
|
|
574
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* Sets horizontal alignment for every paragraph that overlaps the current
|
|
587
|
+
* selection or cursor, using the same ids as the contextual ribbon
|
|
588
|
+
* (`default`, `left`, `center`, `right`, `justified`, `distributed`).
|
|
589
|
+
*/
|
|
590
|
+
setParagraphAlignment(alignment) {
|
|
591
|
+
const align = this.mapRibbonParagraphAlignment(alignment);
|
|
592
|
+
if (align === undefined)
|
|
593
|
+
return;
|
|
594
|
+
this.commitHistoryEdit(() => {
|
|
595
|
+
this.syncDocumentFromUiState();
|
|
596
|
+
const selection = this.getSelectionRange();
|
|
597
|
+
const docStart = this.toDocumentIndexFromLogicalIndex(Math.min(selection.start, selection.end), true);
|
|
598
|
+
const docEnd = this.toDocumentIndexFromLogicalIndex(Math.max(selection.start, selection.end), false);
|
|
599
|
+
const nodes = this.document.ast.nodes;
|
|
600
|
+
if (nodes.length === 0)
|
|
601
|
+
return;
|
|
602
|
+
const normalizeDocIndex = (idx) => {
|
|
603
|
+
const clamped = Math.max(0, Math.min(idx, nodes.length - 1));
|
|
604
|
+
if (nodes[clamped]?.type === 'paragraphBreak') {
|
|
605
|
+
return Math.min(clamped + 1, nodes.length);
|
|
606
|
+
}
|
|
607
|
+
return Math.min(idx, nodes.length - 1);
|
|
608
|
+
};
|
|
609
|
+
const findParagraphStart = (docIdx) => {
|
|
610
|
+
const i = normalizeDocIndex(docIdx);
|
|
611
|
+
for (let j = i; j >= 0; j--) {
|
|
612
|
+
if (nodes[j]?.type === 'paragraphBreak')
|
|
613
|
+
return j + 1;
|
|
614
|
+
}
|
|
615
|
+
return 0;
|
|
616
|
+
};
|
|
617
|
+
const findParagraphEndExclusive = (docIdx) => {
|
|
618
|
+
const i = Math.min(Math.max(0, docIdx), nodes.length - 1);
|
|
619
|
+
for (let j = i; j < nodes.length; j++) {
|
|
620
|
+
if (nodes[j]?.type === 'paragraphBreak')
|
|
621
|
+
return j;
|
|
622
|
+
}
|
|
623
|
+
return nodes.length;
|
|
624
|
+
};
|
|
625
|
+
const rangeStart = findParagraphStart(Math.min(docStart, docEnd));
|
|
626
|
+
const rangeEnd = findParagraphEndExclusive(Math.max(docStart, docEnd));
|
|
627
|
+
if (rangeStart >= rangeEnd)
|
|
628
|
+
return;
|
|
629
|
+
for (let i = rangeStart; i < rangeEnd; i++) {
|
|
630
|
+
const node = nodes[i];
|
|
631
|
+
if (node && hasNodeStyle(node)) {
|
|
632
|
+
node.style.paragraph.align = align;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
this.syncUiStateFromDocument();
|
|
636
|
+
this.relayout();
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Sets the MTEXT attachment point using contextual ribbon codes (`TL`, `MC`,
|
|
641
|
+
* `BR`, etc.), matching AutoCAD nine-point attachment.
|
|
642
|
+
*/
|
|
643
|
+
setAttachmentPoint(attachmentPoint) {
|
|
644
|
+
const next = this.mapRibbonAttachmentCode(attachmentPoint);
|
|
645
|
+
if (next === undefined || next === this.editorAttachmentPoint)
|
|
646
|
+
return;
|
|
647
|
+
this.editorAttachmentPoint = next;
|
|
648
|
+
this.relayout();
|
|
649
|
+
this.emit('change');
|
|
650
|
+
}
|
|
651
|
+
/** Returns the current attachment as a two-letter ribbon / DXF-style code. */
|
|
652
|
+
getAttachmentPointCode() {
|
|
653
|
+
return this.attachmentPointToRibbonCode(this.editorAttachmentPoint);
|
|
654
|
+
}
|
|
575
655
|
/** Toggles selected alphabetic text between upper and lower case. */
|
|
576
656
|
toggleCase() {
|
|
577
657
|
const selection = this.getSelectionRange();
|
|
@@ -1486,10 +1566,15 @@ export class MTextInputBox {
|
|
|
1486
1566
|
const color = this.resolveBaseFormatColor(colorSettings);
|
|
1487
1567
|
base.aci = color.aci;
|
|
1488
1568
|
base.rgb = color.rgb;
|
|
1569
|
+
const wf = style.widthFactor;
|
|
1570
|
+
base.widthFactor = typeof wf === 'number' && Number.isFinite(wf) ? Math.max(0.01, wf) : 1;
|
|
1571
|
+
const obl = style.obliqueAngle;
|
|
1572
|
+
base.obliqueAngle = typeof obl === 'number' && Number.isFinite(obl) ? obl : 0;
|
|
1573
|
+
base.tracking = 1;
|
|
1489
1574
|
return base;
|
|
1490
1575
|
}
|
|
1491
1576
|
createMTextData() {
|
|
1492
|
-
|
|
1577
|
+
const data = {
|
|
1493
1578
|
text: this.mtextString,
|
|
1494
1579
|
height: Math.max(1, this.defaultTextStyle.fixedTextHeight),
|
|
1495
1580
|
width: this.width,
|
|
@@ -1498,11 +1583,43 @@ export class MTextInputBox {
|
|
|
1498
1583
|
y: this.position.y,
|
|
1499
1584
|
z: this.position.z
|
|
1500
1585
|
},
|
|
1501
|
-
attachmentPoint:
|
|
1586
|
+
attachmentPoint: this.editorAttachmentPoint,
|
|
1502
1587
|
drawingDirection: MTextFlowDirection.LEFT_TO_RIGHT,
|
|
1503
1588
|
widthFactor: 1,
|
|
1504
1589
|
collectCharBoxes: true
|
|
1505
1590
|
};
|
|
1591
|
+
if (this.editorLineSpaceFactor != null && Number.isFinite(this.editorLineSpaceFactor)) {
|
|
1592
|
+
data.lineSpaceFactor = this.editorLineSpaceFactor;
|
|
1593
|
+
}
|
|
1594
|
+
return data;
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Line spacing factor used for layout and returned when the host commits the editor.
|
|
1598
|
+
* Matches the ribbon / `AcEdMTextEditor` default when no override is set.
|
|
1599
|
+
*/
|
|
1600
|
+
getLineSpacingFactor() {
|
|
1601
|
+
return this.editorLineSpaceFactor ?? MTextInputBox.DEFAULT_LINE_SPACE_FACTOR;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Applies paragraph line spacing from ribbon-style multiples (`1` = default /
|
|
1605
|
+
* single, `2` = default plus one text-line height of extra gap, etc.).
|
|
1606
|
+
* Values in `(0, 1)` are still treated as raw renderer `lineSpaceFactor`
|
|
1607
|
+
* for callers that set CAD factors directly.
|
|
1608
|
+
*/
|
|
1609
|
+
setLineSpacingFactor(factor) {
|
|
1610
|
+
if (!Number.isFinite(factor) || factor <= 0)
|
|
1611
|
+
return;
|
|
1612
|
+
const defaultF = MTextInputBox.DEFAULT_LINE_SPACE_FACTOR;
|
|
1613
|
+
const rendererFactor = factor >= 1 ? Math.max(0.01, defaultF + (factor - 1) / LINE_SPACING_SCALE_FACTOR) : factor;
|
|
1614
|
+
this.editorLineSpaceFactor = rendererFactor;
|
|
1615
|
+
this.relayout();
|
|
1616
|
+
this.emit('change');
|
|
1617
|
+
}
|
|
1618
|
+
/** Clears the explicit line spacing override and uses the renderer default. */
|
|
1619
|
+
clearLineSpacing() {
|
|
1620
|
+
this.editorLineSpaceFactor = null;
|
|
1621
|
+
this.relayout();
|
|
1622
|
+
this.emit('change');
|
|
1506
1623
|
}
|
|
1507
1624
|
getFallbackLineAdvance() {
|
|
1508
1625
|
return Math.max(1, this.currentFormat.fontSize * MTextInputBox.FALLBACK_LINE_ADVANCE_RATIO);
|
|
@@ -2181,6 +2298,11 @@ export class MTextInputBox {
|
|
|
2181
2298
|
const reducedThreshold = Math.max(1, baseSize) * 0.9;
|
|
2182
2299
|
const isReducedScriptCapHeight = capHeight <= reducedThreshold;
|
|
2183
2300
|
const logicalFontSize = script === 'normal' ? capHeight : isReducedScriptCapHeight ? capHeight / 0.7 : capHeight;
|
|
2301
|
+
const wf = style.widthFactor?.value;
|
|
2302
|
+
const widthFactor = typeof wf === 'number' && Number.isFinite(wf) ? Math.max(0.01, wf) : 1;
|
|
2303
|
+
const tr = style.charTrackingFactor?.value;
|
|
2304
|
+
const tracking = typeof tr === 'number' && Number.isFinite(tr) ? Math.max(0.01, tr) : 1;
|
|
2305
|
+
const oblique = typeof style.oblique === 'number' && Number.isFinite(style.oblique) ? style.oblique : 0;
|
|
2184
2306
|
return {
|
|
2185
2307
|
fontFamily: style.fontFace.family || defaultFontFamily,
|
|
2186
2308
|
fontSize: Math.max(1, logicalFontSize || baseSize),
|
|
@@ -2191,7 +2313,11 @@ export class MTextInputBox {
|
|
|
2191
2313
|
strike: style.strikeThrough,
|
|
2192
2314
|
script,
|
|
2193
2315
|
aci: resolvedAci,
|
|
2194
|
-
rgb: resolvedColor
|
|
2316
|
+
rgb: resolvedColor,
|
|
2317
|
+
obliqueAngle: oblique,
|
|
2318
|
+
widthFactor,
|
|
2319
|
+
tracking,
|
|
2320
|
+
paragraphAlignment: style.paragraph.align
|
|
2195
2321
|
};
|
|
2196
2322
|
}
|
|
2197
2323
|
toScriptFromStyle(style, baseSize, capHeight) {
|
|
@@ -2273,6 +2399,75 @@ export class MTextInputBox {
|
|
|
2273
2399
|
}
|
|
2274
2400
|
return new MTextDocument(normalizedAst);
|
|
2275
2401
|
}
|
|
2402
|
+
mapRibbonParagraphAlignment(alignment) {
|
|
2403
|
+
switch (alignment) {
|
|
2404
|
+
case 'default':
|
|
2405
|
+
return MTextParagraphAlignment.DEFAULT;
|
|
2406
|
+
case 'left':
|
|
2407
|
+
return MTextParagraphAlignment.LEFT;
|
|
2408
|
+
case 'center':
|
|
2409
|
+
return MTextParagraphAlignment.CENTER;
|
|
2410
|
+
case 'right':
|
|
2411
|
+
return MTextParagraphAlignment.RIGHT;
|
|
2412
|
+
case 'justified':
|
|
2413
|
+
return MTextParagraphAlignment.JUSTIFIED;
|
|
2414
|
+
case 'distributed':
|
|
2415
|
+
return MTextParagraphAlignment.DISTRIBUTED;
|
|
2416
|
+
default:
|
|
2417
|
+
return undefined;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
mapRibbonAttachmentCode(code) {
|
|
2421
|
+
switch (code.trim().toUpperCase()) {
|
|
2422
|
+
case 'TL':
|
|
2423
|
+
return MTextAttachmentPoint.TopLeft;
|
|
2424
|
+
case 'TC':
|
|
2425
|
+
return MTextAttachmentPoint.TopCenter;
|
|
2426
|
+
case 'TR':
|
|
2427
|
+
return MTextAttachmentPoint.TopRight;
|
|
2428
|
+
case 'ML':
|
|
2429
|
+
return MTextAttachmentPoint.MiddleLeft;
|
|
2430
|
+
case 'MC':
|
|
2431
|
+
return MTextAttachmentPoint.MiddleCenter;
|
|
2432
|
+
case 'MR':
|
|
2433
|
+
return MTextAttachmentPoint.MiddleRight;
|
|
2434
|
+
case 'BL':
|
|
2435
|
+
return MTextAttachmentPoint.BottomLeft;
|
|
2436
|
+
case 'BC':
|
|
2437
|
+
return MTextAttachmentPoint.BottomCenter;
|
|
2438
|
+
case 'BR':
|
|
2439
|
+
return MTextAttachmentPoint.BottomRight;
|
|
2440
|
+
default:
|
|
2441
|
+
return undefined;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
attachmentPointToRibbonCode(point) {
|
|
2445
|
+
switch (point) {
|
|
2446
|
+
case MTextAttachmentPoint.TopLeft:
|
|
2447
|
+
return 'TL';
|
|
2448
|
+
case MTextAttachmentPoint.TopCenter:
|
|
2449
|
+
return 'TC';
|
|
2450
|
+
case MTextAttachmentPoint.TopRight:
|
|
2451
|
+
return 'TR';
|
|
2452
|
+
case MTextAttachmentPoint.MiddleLeft:
|
|
2453
|
+
return 'ML';
|
|
2454
|
+
case MTextAttachmentPoint.MiddleCenter:
|
|
2455
|
+
return 'MC';
|
|
2456
|
+
case MTextAttachmentPoint.MiddleRight:
|
|
2457
|
+
return 'MR';
|
|
2458
|
+
case MTextAttachmentPoint.BottomLeft:
|
|
2459
|
+
case MTextAttachmentPoint.BaselineLeft:
|
|
2460
|
+
return 'BL';
|
|
2461
|
+
case MTextAttachmentPoint.BottomCenter:
|
|
2462
|
+
case MTextAttachmentPoint.BaselineCenter:
|
|
2463
|
+
return 'BC';
|
|
2464
|
+
case MTextAttachmentPoint.BottomRight:
|
|
2465
|
+
case MTextAttachmentPoint.BaselineRight:
|
|
2466
|
+
return 'BR';
|
|
2467
|
+
default:
|
|
2468
|
+
return 'TL';
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2276
2471
|
mergeCharFormat(base, patch) {
|
|
2277
2472
|
const next = { ...base, ...patch };
|
|
2278
2473
|
if (patch.aci !== undefined) {
|
|
@@ -2295,6 +2490,9 @@ export class MTextInputBox {
|
|
|
2295
2490
|
next.aci = null;
|
|
2296
2491
|
}
|
|
2297
2492
|
}
|
|
2493
|
+
if (patch.paragraphAlignment !== undefined) {
|
|
2494
|
+
next.paragraphAlignment = patch.paragraphAlignment;
|
|
2495
|
+
}
|
|
2298
2496
|
return next;
|
|
2299
2497
|
}
|
|
2300
2498
|
cloneDocumentStyle(style) {
|
|
@@ -2320,7 +2518,7 @@ export class MTextInputBox {
|
|
|
2320
2518
|
}
|
|
2321
2519
|
};
|
|
2322
2520
|
}
|
|
2323
|
-
toDocumentStyle(format) {
|
|
2521
|
+
toDocumentStyle(format, existing) {
|
|
2324
2522
|
const explicitAci = this.isExplicitAci(format.aci) ? format.aci : null;
|
|
2325
2523
|
const rgbColor = explicitAci !== null
|
|
2326
2524
|
? null
|
|
@@ -2332,6 +2530,7 @@ export class MTextInputBox {
|
|
|
2332
2530
|
: format.script === 'subscript'
|
|
2333
2531
|
? MTextLineAlignment.BOTTOM
|
|
2334
2532
|
: MTextLineAlignment.MIDDLE;
|
|
2533
|
+
const paragraphAlign = format.paragraphAlignment;
|
|
2335
2534
|
return {
|
|
2336
2535
|
underline: format.underline,
|
|
2337
2536
|
overline: format.overline,
|
|
@@ -2346,15 +2545,21 @@ export class MTextInputBox {
|
|
|
2346
2545
|
weight: format.bold ? 700 : 400
|
|
2347
2546
|
},
|
|
2348
2547
|
capHeight: { value: capHeight, isRelative: false },
|
|
2349
|
-
widthFactor: {
|
|
2350
|
-
|
|
2351
|
-
|
|
2548
|
+
widthFactor: {
|
|
2549
|
+
value: Math.max(0.01, format.widthFactor),
|
|
2550
|
+
isRelative: false
|
|
2551
|
+
},
|
|
2552
|
+
charTrackingFactor: {
|
|
2553
|
+
value: Math.max(0.01, format.tracking),
|
|
2554
|
+
isRelative: false
|
|
2555
|
+
},
|
|
2556
|
+
oblique: format.obliqueAngle,
|
|
2352
2557
|
paragraph: {
|
|
2353
|
-
indent: 0,
|
|
2354
|
-
left: 0,
|
|
2355
|
-
right: 0,
|
|
2356
|
-
align:
|
|
2357
|
-
tabs: []
|
|
2558
|
+
indent: existing?.paragraph.indent ?? 0,
|
|
2559
|
+
left: existing?.paragraph.left ?? 0,
|
|
2560
|
+
right: existing?.paragraph.right ?? 0,
|
|
2561
|
+
align: paragraphAlign,
|
|
2562
|
+
tabs: existing?.paragraph.tabs ? [...existing.paragraph.tabs] : []
|
|
2358
2563
|
}
|
|
2359
2564
|
};
|
|
2360
2565
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-input-box",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"@mlightcad/text-box-cursor": "0.1.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@mlightcad/mtext-renderer": "^0.10.
|
|
20
|
+
"@mlightcad/mtext-renderer": "^0.10.13",
|
|
21
21
|
"three": "^0.172.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@eslint/js": "^9.34.0",
|
|
24
25
|
"@types/node": "^24.4.0",
|
|
25
26
|
"@types/three": "^0.172.0",
|
|
26
27
|
"@typescript-eslint/eslint-plugin": "^8.41.0",
|