@mlightcad/mtext-input-box 0.2.4 → 0.2.5
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 +1 -1
- package/dist/model/document.js +3 -1
- package/dist/model/style.d.ts +1 -1
- package/dist/model/style.js +2 -1
- package/dist/ui/icons.js +1 -1
- package/dist/ui/toolbar.js +6 -2
- package/dist/viewer/viewer.d.ts +3 -1
- package/dist/viewer/viewer.js +86 -25
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/model/document.js
CHANGED
|
@@ -8,7 +8,9 @@ export class MTextDocument {
|
|
|
8
8
|
_selection = null;
|
|
9
9
|
constructor(astOrMText = { nodes: [] }) {
|
|
10
10
|
this._ast =
|
|
11
|
-
typeof astOrMText === 'string'
|
|
11
|
+
typeof astOrMText === 'string'
|
|
12
|
+
? parseMTextToAst(astOrMText)
|
|
13
|
+
: MTextDocument.cloneAst(astOrMText);
|
|
12
14
|
this._cursor = this._ast.nodes.length;
|
|
13
15
|
}
|
|
14
16
|
static fromMText(mtext, ctx) {
|
package/dist/model/style.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { MTextContext } from '@mlightcad/mtext-renderer';
|
|
|
2
2
|
import type { MTextAstCharNode, MTextAstColumnBreakNode, MTextAstNode, MTextAstParagraphBreakNode, MTextAstStackNode, MTextAstWrapAtDimLineNode, MTextStyle } from './types';
|
|
3
3
|
export declare function contextToStyle(ctx: MTextContext): MTextStyle;
|
|
4
4
|
export declare function cloneStyle(style: MTextStyle): MTextStyle;
|
|
5
|
-
export declare function hasNodeStyle(node: MTextAstNode): node is
|
|
5
|
+
export declare function hasNodeStyle(node: MTextAstNode): node is MTextAstCharNode | MTextAstStackNode | MTextAstParagraphBreakNode | MTextAstColumnBreakNode | MTextAstWrapAtDimLineNode;
|
|
6
6
|
export declare function serializeStyleDelta(prev: MTextStyle | null, next: MTextStyle): string;
|
package/dist/model/style.js
CHANGED
|
@@ -113,7 +113,8 @@ export function serializeStyleDelta(prev, next) {
|
|
|
113
113
|
if (from.align !== nextWithScript.align) {
|
|
114
114
|
out += `\\A${nextWithScript.align};`;
|
|
115
115
|
}
|
|
116
|
-
if (from.aci !== nextWithScript.aci ||
|
|
116
|
+
if (from.aci !== nextWithScript.aci ||
|
|
117
|
+
JSON.stringify(from.rgb) !== JSON.stringify(nextWithScript.rgb)) {
|
|
117
118
|
if (nextWithScript.rgb) {
|
|
118
119
|
out += `\\c${rgb2int(nextWithScript.rgb)};`;
|
|
119
120
|
}
|
package/dist/ui/icons.js
CHANGED
|
@@ -6,5 +6,5 @@ export const toolbarIcons = {
|
|
|
6
6
|
strike: '<svg viewBox="0 0 24 24"><g fill-rule="evenodd"><path d="M15.6 8.5c-.5-.7-1-1.1-1.3-1.3-.6-.4-1.3-.6-2-.6-2.7 0-2.8 1.7-2.8 2.1 0 1.6 1.8 2 3.2 2.3 4.4.9 4.6 2.8 4.6 3.9 0 1.4-.7 4.1-5 4.1A6.2 6.2 0 0 1 7 16.4l1.5-1.1c.4.6 1.6 2 3.7 2 1.6 0 2.5-.4 3-1.2.4-.8.3-2-.8-2.6-.7-.4-1.6-.7-2.9-1-1-.2-3.9-.8-3.9-3.6C7.6 6 10.3 5 12.4 5c2.9 0 4.2 1.6 4.7 2.4l-1.5 1.1Z"></path><path d="M5 11h14a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" fill-rule="nonzero"></path></g></svg>',
|
|
7
7
|
superscript: '<svg viewBox="0 0 24 24"><path d="M15 9.4 10.4 14l4.6 4.6-1.4 1.4L9 15.4 4.4 20 3 18.6 7.6 14 3 9.4 4.4 8 9 12.6 13.6 8 15 9.4Zm5.9 1.6h-5v-1l1-.8 1.7-1.6c.3-.5.5-.9.5-1.3 0-.3 0-.5-.2-.7-.2-.2-.5-.3-.9-.3l-.8.2-.7.4-.4-1.2c.2-.2.5-.4 1-.5.3-.2.8-.2 1.2-.2.8 0 1.4.2 1.8.6.4.4.6 1 .6 1.6 0 .5-.2 1-.5 1.5l-1.3 1.4-.6.5h2.6V11Z" fill-rule="nonzero"></path></svg>',
|
|
8
8
|
subscript: '<svg viewBox="0 0 24 24"><path d="m10.4 10 4.6 4.6-1.4 1.4L9 11.4 4.4 16 3 14.6 7.6 10 3 5.4 4.4 4 9 8.6 13.6 4 15 5.4 10.4 10ZM21 19h-5v-1l1-.8 1.7-1.6c.3-.4.5-.8.5-1.2 0-.3 0-.6-.2-.7-.2-.2-.5-.3-.9-.3a2 2 0 0 0-.8.2l-.7.3-.4-1.1 1-.6 1.2-.2c.8 0 1.4.3 1.8.7.4.4.6.9.6 1.5s-.2 1.1-.5 1.6a8 8 0 0 1-1.3 1.3l-.6.6h2.6V19Z" fill-rule="nonzero"></path></svg>',
|
|
9
|
-
stack: '<svg viewBox="0 0 24 24"><path d="M12.4065 5.44832C12.8151 5.44832 13.1994 5.56542 13.5595 5.7996C13.9265 6.0267 14.2208 6.36024 14.4424 6.80022C14.664 7.23312 14.7748 7.74407 14.7748 8.33309C14.7748 8.9292 14.664 9.44725 14.4424 9.88724C14.2208 10.3201 13.9265 10.6501 13.5595 10.8772C13.1994 11.1043 12.8151 11.2179 12.4065 11.2179C12.0464 11.2179 11.7037 11.1291 11.3782 10.9517C11.0527 10.7743 10.7931 10.5082 10.5992 10.1534C10.5715 10.4585 10.5507 10.7743 10.5368 11.1008H9.75781V3H10.6407V6.4383C10.8415 6.11185 11.0977 5.86702 11.4094 5.7038C11.721 5.53348 12.0534 5.44832 12.4065 5.44832ZM12.2923 10.3663C12.7631 10.3663 13.1405 10.1888 13.4245 9.83402C13.7084 9.47919 13.8503 8.97888 13.8503 8.33309C13.8503 7.69439 13.7084 7.19763 13.4245 6.8428C13.1405 6.48797 12.7631 6.31056 12.2923 6.31056C11.8422 6.31056 11.4544 6.47378 11.1289 6.80022C10.8034 7.12667 10.6407 7.63762 10.6407 8.33309C10.6407 8.80856 10.7203 9.19887 10.8796 9.50402C11.0389 9.80918 11.2432 10.0292 11.4925 10.164C11.7417 10.2988 12.0083 10.3663 12.2923 10.3663Z"></path><path d="M12.0949 14.9531C12.7043 14.9531 13.2029 15.1447 13.5906 15.5279C13.9784 15.9041 14.1723 16.4434 14.1723 17.146V20.6056H13.3933C13.3725 20.2436 13.3587 20.0094 13.3517 19.903C13.1856 20.1727 12.9605 20.3785 12.6766 20.5204C12.3996 20.6552 12.0811 20.7227 11.721 20.7227C11.3747 20.7227 11.0493 20.6588 10.7446 20.531C10.4468 20.3962 10.2079 20.2011 10.0279 19.9456C9.84783 19.683 9.75781 19.3708 9.75781 19.0088C9.75781 18.4624 9.97248 18.033 10.4018 17.7208C10.8381 17.4014 11.399 17.2418 12.0845 17.2418C12.4723 17.2418 12.8739 17.295 13.2894 17.4014V17.3056C13.2894 16.7876 13.1856 16.4044 12.9778 16.156C12.777 15.9005 12.4688 15.7728 12.0534 15.7728C11.721 15.7728 11.444 15.8437 11.2224 15.9857C11.0008 16.1276 10.8138 16.337 10.6615 16.6137L9.98633 16.2199C10.1525 15.8367 10.4226 15.5315 10.7965 15.3044C11.1774 15.0702 11.6102 14.9531 12.0949 14.9531ZM13.2894 18.1572C12.8532 18.0437 12.455 17.9869 12.0949 17.9869C11.6448 17.9869 11.2951 18.0756 11.0458 18.253C10.8034 18.4305 10.6823 18.6788 10.6823 18.9982C10.6823 19.2962 10.7861 19.5304 10.9939 19.7007C11.2016 19.864 11.4717 19.9456 11.8041 19.9456C12.2126 19.9456 12.5623 19.8249 12.8532 19.5836C13.144 19.3353 13.2894 18.9946 13.2894 18.5617V18.1572Z""></path><rect x="6.02344" y="12.7119" width="11.9532" height="0.747077"></rect></svg>'
|
|
9
|
+
stack: '<svg viewBox="0 0 24 24"><path d="M12.4065 5.44832C12.8151 5.44832 13.1994 5.56542 13.5595 5.7996C13.9265 6.0267 14.2208 6.36024 14.4424 6.80022C14.664 7.23312 14.7748 7.74407 14.7748 8.33309C14.7748 8.9292 14.664 9.44725 14.4424 9.88724C14.2208 10.3201 13.9265 10.6501 13.5595 10.8772C13.1994 11.1043 12.8151 11.2179 12.4065 11.2179C12.0464 11.2179 11.7037 11.1291 11.3782 10.9517C11.0527 10.7743 10.7931 10.5082 10.5992 10.1534C10.5715 10.4585 10.5507 10.7743 10.5368 11.1008H9.75781V3H10.6407V6.4383C10.8415 6.11185 11.0977 5.86702 11.4094 5.7038C11.721 5.53348 12.0534 5.44832 12.4065 5.44832ZM12.2923 10.3663C12.7631 10.3663 13.1405 10.1888 13.4245 9.83402C13.7084 9.47919 13.8503 8.97888 13.8503 8.33309C13.8503 7.69439 13.7084 7.19763 13.4245 6.8428C13.1405 6.48797 12.7631 6.31056 12.2923 6.31056C11.8422 6.31056 11.4544 6.47378 11.1289 6.80022C10.8034 7.12667 10.6407 7.63762 10.6407 8.33309C10.6407 8.80856 10.7203 9.19887 10.8796 9.50402C11.0389 9.80918 11.2432 10.0292 11.4925 10.164C11.7417 10.2988 12.0083 10.3663 12.2923 10.3663Z"></path><path d="M12.0949 14.9531C12.7043 14.9531 13.2029 15.1447 13.5906 15.5279C13.9784 15.9041 14.1723 16.4434 14.1723 17.146V20.6056H13.3933C13.3725 20.2436 13.3587 20.0094 13.3517 19.903C13.1856 20.1727 12.9605 20.3785 12.6766 20.5204C12.3996 20.6552 12.0811 20.7227 11.721 20.7227C11.3747 20.7227 11.0493 20.6588 10.7446 20.531C10.4468 20.3962 10.2079 20.2011 10.0279 19.9456C9.84783 19.683 9.75781 19.3708 9.75781 19.0088C9.75781 18.4624 9.97248 18.033 10.4018 17.7208C10.8381 17.4014 11.399 17.2418 12.0845 17.2418C12.4723 17.2418 12.8739 17.295 13.2894 17.4014V17.3056C13.2894 16.7876 13.1856 16.4044 12.9778 16.156C12.777 15.9005 12.4688 15.7728 12.0534 15.7728C11.721 15.7728 11.444 15.8437 11.2224 15.9857C11.0008 16.1276 10.8138 16.337 10.6615 16.6137L9.98633 16.2199C10.1525 15.8367 10.4226 15.5315 10.7965 15.3044C11.1774 15.0702 11.6102 14.9531 12.0949 14.9531ZM13.2894 18.1572C12.8532 18.0437 12.455 17.9869 12.0949 17.9869C11.6448 17.9869 11.2951 18.0756 11.0458 18.253C10.8034 18.4305 10.6823 18.6788 10.6823 18.9982C10.6823 19.2962 10.7861 19.5304 10.9939 19.7007C11.2016 19.864 11.4717 19.9456 11.8041 19.9456C12.2126 19.9456 12.5623 19.8249 12.8532 19.5836C13.144 19.3353 13.2894 18.9946 13.2894 18.5617V18.1572Z""></path><rect x="6.02344" y="12.7119" width="11.9532" height="0.747077"></rect></svg>'
|
|
10
10
|
};
|
package/dist/ui/toolbar.js
CHANGED
|
@@ -367,7 +367,9 @@ export class MTextToolbar {
|
|
|
367
367
|
this.onFormatChange({ italic: !this.controls.italicBtn.classList.contains('is-active') });
|
|
368
368
|
});
|
|
369
369
|
this.controls.underlineBtn.addEventListener('click', () => {
|
|
370
|
-
this.onFormatChange({
|
|
370
|
+
this.onFormatChange({
|
|
371
|
+
underline: !this.controls.underlineBtn.classList.contains('is-active')
|
|
372
|
+
});
|
|
371
373
|
});
|
|
372
374
|
this.controls.overlineBtn.addEventListener('click', () => {
|
|
373
375
|
this.onFormatChange({ overline: !this.controls.overlineBtn.classList.contains('is-active') });
|
|
@@ -425,7 +427,9 @@ export class MTextToolbar {
|
|
|
425
427
|
const host = document.createElement('div');
|
|
426
428
|
host.className = 'ml-mtext-toolbar__color';
|
|
427
429
|
host.dataset.mlMtextToolbarInteractive = 'true';
|
|
428
|
-
const initialColor = initialFormat
|
|
430
|
+
const initialColor = initialFormat
|
|
431
|
+
? formatToMTextColor(initialFormat)
|
|
432
|
+
: hexToMTextColor('#ffffff');
|
|
429
433
|
const instance = factory({
|
|
430
434
|
container: host,
|
|
431
435
|
theme: this.theme,
|
package/dist/viewer/viewer.d.ts
CHANGED
|
@@ -132,6 +132,8 @@ export declare class MTextInputBox {
|
|
|
132
132
|
setCurrentFormat(format: Partial<CharFormat>): void;
|
|
133
133
|
/** Returns current insertion format. */
|
|
134
134
|
getCurrentFormat(): CharFormat;
|
|
135
|
+
/** Toggles selected alphabetic text between upper and lower case. */
|
|
136
|
+
toggleCase(): void;
|
|
135
137
|
/** Returns renderer default text style defined by `textStyle`. */
|
|
136
138
|
getDefaultTextStyle(): TextStyle;
|
|
137
139
|
/** Keyboard event handler. Returns true when consumed. */
|
|
@@ -168,7 +170,7 @@ export declare class MTextInputBox {
|
|
|
168
170
|
y: number;
|
|
169
171
|
z: number;
|
|
170
172
|
};
|
|
171
|
-
/** Returns the MTEXT insertion point
|
|
173
|
+
/** Returns the MTEXT insertion point supplied when the editor was opened. */
|
|
172
174
|
getMTextInsertionPoint(): THREE.Vector3;
|
|
173
175
|
/** Returns current internal state snapshot. */
|
|
174
176
|
getState(): EditorState;
|
package/dist/viewer/viewer.js
CHANGED
|
@@ -246,7 +246,9 @@ export class MTextInputBox {
|
|
|
246
246
|
lastHeight,
|
|
247
247
|
widthFactor: Number.isFinite(textStyle.widthFactor) ? textStyle.widthFactor : 1,
|
|
248
248
|
obliqueAngle: Number.isFinite(textStyle.obliqueAngle) ? textStyle.obliqueAngle : 0,
|
|
249
|
-
textGenerationFlag: Number.isFinite(textStyle.textGenerationFlag)
|
|
249
|
+
textGenerationFlag: Number.isFinite(textStyle.textGenerationFlag)
|
|
250
|
+
? textStyle.textGenerationFlag
|
|
251
|
+
: 0,
|
|
250
252
|
standardFlag: Number.isFinite(textStyle.standardFlag) ? textStyle.standardFlag : 0,
|
|
251
253
|
font: textStyle.font || MTextInputBox.DEFAULT_TEXT_STYLE.font,
|
|
252
254
|
bigFont: textStyle.bigFont ?? ''
|
|
@@ -258,7 +260,7 @@ export class MTextInputBox {
|
|
|
258
260
|
this.mtextRenderer = new UnifiedRenderer('main', {
|
|
259
261
|
workerUrl: typeof options.workerUrl === 'string'
|
|
260
262
|
? options.workerUrl
|
|
261
|
-
: options.workerUrl?.toString() ?? './assets/mtext-renderer-worker.js'
|
|
263
|
+
: (options.workerUrl?.toString() ?? './assets/mtext-renderer-worker.js')
|
|
262
264
|
});
|
|
263
265
|
if (options.fontUrl) {
|
|
264
266
|
this.mtextRenderer.setFontUrl(options.fontUrl);
|
|
@@ -280,10 +282,17 @@ export class MTextInputBox {
|
|
|
280
282
|
selectionStyle: options.selectionStyle,
|
|
281
283
|
enableDebug: false,
|
|
282
284
|
enableSelection: true,
|
|
283
|
-
debugYAxisUp: this.camera instanceof THREE.OrthographicCamera
|
|
285
|
+
debugYAxisUp: this.camera instanceof THREE.OrthographicCamera
|
|
286
|
+
? this.camera.top >= this.camera.bottom
|
|
287
|
+
: true,
|
|
284
288
|
debugVisibility: this.debugVisibility
|
|
285
289
|
});
|
|
286
|
-
this.cursorRenderer.setViewTransform({
|
|
290
|
+
this.cursorRenderer.setViewTransform({
|
|
291
|
+
x: this.position.x,
|
|
292
|
+
y: this.position.y,
|
|
293
|
+
scaleX: 1,
|
|
294
|
+
scaleY: 1
|
|
295
|
+
});
|
|
287
296
|
this.createBoundingBox(options.showBoundingBox ?? true, options.boundingBoxStyle);
|
|
288
297
|
this.setText(options.initialText ?? '');
|
|
289
298
|
this.attachIme(options.imeTarget);
|
|
@@ -563,6 +572,47 @@ export class MTextInputBox {
|
|
|
563
572
|
getCurrentFormat() {
|
|
564
573
|
return { ...this.currentFormat };
|
|
565
574
|
}
|
|
575
|
+
/** Toggles selected alphabetic text between upper and lower case. */
|
|
576
|
+
toggleCase() {
|
|
577
|
+
const selection = this.getSelectionRange();
|
|
578
|
+
if (selection.isCollapsed)
|
|
579
|
+
return;
|
|
580
|
+
this.commitHistoryEdit(() => {
|
|
581
|
+
this.syncDocumentFromUiState();
|
|
582
|
+
const start = this.toDocumentIndexFromLogicalIndex(selection.start, true);
|
|
583
|
+
const end = this.toDocumentIndexFromLogicalIndex(selection.end, false);
|
|
584
|
+
if (end <= start)
|
|
585
|
+
return;
|
|
586
|
+
const selectedNodes = this.document.ast.nodes.slice(start, end);
|
|
587
|
+
const selectedText = selectedNodes
|
|
588
|
+
.map((node) => {
|
|
589
|
+
if (node.type === 'char')
|
|
590
|
+
return node.value;
|
|
591
|
+
if (node.type === 'stack')
|
|
592
|
+
return `${node.numerator}${node.denominator}`;
|
|
593
|
+
return '';
|
|
594
|
+
})
|
|
595
|
+
.join('');
|
|
596
|
+
if (!/[a-zA-Z]/.test(selectedText))
|
|
597
|
+
return;
|
|
598
|
+
const hasLowercase = /[a-z]/.test(selectedText);
|
|
599
|
+
const transform = (value) => hasLowercase ? value.toUpperCase() : value.toLowerCase();
|
|
600
|
+
this.document.transaction(() => {
|
|
601
|
+
for (const node of selectedNodes) {
|
|
602
|
+
if (node.type === 'char') {
|
|
603
|
+
node.value = transform(node.value);
|
|
604
|
+
}
|
|
605
|
+
else if (node.type === 'stack') {
|
|
606
|
+
node.numerator = transform(node.numerator);
|
|
607
|
+
node.denominator = transform(node.denominator);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
this.document.setSelection(start, end);
|
|
611
|
+
});
|
|
612
|
+
this.syncUiStateFromDocument();
|
|
613
|
+
this.relayout();
|
|
614
|
+
});
|
|
615
|
+
}
|
|
566
616
|
/** Returns renderer default text style defined by `textStyle`. */
|
|
567
617
|
getDefaultTextStyle() {
|
|
568
618
|
return { ...this.defaultTextStyle };
|
|
@@ -808,9 +858,9 @@ export class MTextInputBox {
|
|
|
808
858
|
z: this.position.z
|
|
809
859
|
};
|
|
810
860
|
}
|
|
811
|
-
/** Returns the MTEXT insertion point
|
|
861
|
+
/** Returns the MTEXT insertion point supplied when the editor was opened. */
|
|
812
862
|
getMTextInsertionPoint() {
|
|
813
|
-
return this.position.clone()
|
|
863
|
+
return this.position.clone();
|
|
814
864
|
}
|
|
815
865
|
/** Returns current internal state snapshot. */
|
|
816
866
|
getState() {
|
|
@@ -985,8 +1035,8 @@ export class MTextInputBox {
|
|
|
985
1035
|
let maxY = Number.NEGATIVE_INFINITY;
|
|
986
1036
|
for (const corner of corners) {
|
|
987
1037
|
const projected = corner.clone().project(this.camera);
|
|
988
|
-
const sx = rect.left + (
|
|
989
|
-
const sy = rect.top + (
|
|
1038
|
+
const sx = rect.left + (projected.x + 1) * 0.5 * rect.width;
|
|
1039
|
+
const sy = rect.top + (1 - projected.y) * 0.5 * rect.height;
|
|
990
1040
|
minX = Math.min(minX, sx);
|
|
991
1041
|
maxX = Math.max(maxX, sx);
|
|
992
1042
|
minY = Math.min(minY, sy);
|
|
@@ -1101,7 +1151,10 @@ export class MTextInputBox {
|
|
|
1101
1151
|
if (this.pendingFontLoad)
|
|
1102
1152
|
return;
|
|
1103
1153
|
const fonts = this.collectFontNamesForText();
|
|
1104
|
-
const key = fonts
|
|
1154
|
+
const key = fonts
|
|
1155
|
+
.map((font) => font.toLowerCase())
|
|
1156
|
+
.sort()
|
|
1157
|
+
.join('|');
|
|
1105
1158
|
if (!key || key === this.lastFontKey)
|
|
1106
1159
|
return;
|
|
1107
1160
|
this.lastFontKey = key;
|
|
@@ -1153,7 +1206,9 @@ export class MTextInputBox {
|
|
|
1153
1206
|
this.cursorLogic.updateData(this.layoutContainer, charBoxes, lineBreakIndices, lineLayouts);
|
|
1154
1207
|
const nextIndex = Math.min(this.cursorIndex, this.charCount());
|
|
1155
1208
|
const maxLineIndex = Math.max(0, this.cursorLogic.getLineCount() - 1);
|
|
1156
|
-
const pendingLineHint = this.pendingCursorLineHint === null
|
|
1209
|
+
const pendingLineHint = this.pendingCursorLineHint === null
|
|
1210
|
+
? null
|
|
1211
|
+
: Math.max(0, Math.min(this.pendingCursorLineHint, maxLineIndex));
|
|
1157
1212
|
this.pendingCursorLineHint = null;
|
|
1158
1213
|
this.cursorLogic.moveTo(nextIndex, pendingLineHint);
|
|
1159
1214
|
if (this.selectionStart !== this.selectionEnd) {
|
|
@@ -1352,13 +1407,13 @@ export class MTextInputBox {
|
|
|
1352
1407
|
: []);
|
|
1353
1408
|
for (const mat of materials) {
|
|
1354
1409
|
const m = mat;
|
|
1355
|
-
if (typeof m.side !==
|
|
1410
|
+
if (typeof m.side !== 'undefined')
|
|
1356
1411
|
m.side = THREE.DoubleSide;
|
|
1357
|
-
if (typeof m.depthTest !==
|
|
1412
|
+
if (typeof m.depthTest !== 'undefined')
|
|
1358
1413
|
m.depthTest = false;
|
|
1359
|
-
if (typeof m.depthWrite !==
|
|
1414
|
+
if (typeof m.depthWrite !== 'undefined')
|
|
1360
1415
|
m.depthWrite = false;
|
|
1361
|
-
if (typeof m.transparent !==
|
|
1416
|
+
if (typeof m.transparent !== 'undefined' && typeof m.opacity !== 'undefined') {
|
|
1362
1417
|
m.transparent = m.opacity < 1;
|
|
1363
1418
|
}
|
|
1364
1419
|
m.needsUpdate = true;
|
|
@@ -1485,8 +1540,8 @@ export class MTextInputBox {
|
|
|
1485
1540
|
const world = new THREE.Vector3(cursorWorld.x, cursorWorld.y, cursorWorld.z);
|
|
1486
1541
|
const projected = world.project(this.camera);
|
|
1487
1542
|
const rect = this.imeTarget.getBoundingClientRect();
|
|
1488
|
-
const x = rect.left + (
|
|
1489
|
-
const y = rect.top + (
|
|
1543
|
+
const x = rect.left + (projected.x + 1) * 0.5 * rect.width;
|
|
1544
|
+
const y = rect.top + (1 - projected.y) * 0.5 * rect.height;
|
|
1490
1545
|
this.imeInput.style.left = `${Math.round(x)}px`;
|
|
1491
1546
|
this.imeInput.style.top = `${Math.round(y)}px`;
|
|
1492
1547
|
}
|
|
@@ -1550,7 +1605,9 @@ export class MTextInputBox {
|
|
|
1550
1605
|
chars.push('');
|
|
1551
1606
|
continue;
|
|
1552
1607
|
}
|
|
1553
|
-
if (node.type === 'paragraphBreak' ||
|
|
1608
|
+
if (node.type === 'paragraphBreak' ||
|
|
1609
|
+
node.type === 'columnBreak' ||
|
|
1610
|
+
node.type === 'wrapAtDimLine') {
|
|
1554
1611
|
chars.push('\n');
|
|
1555
1612
|
}
|
|
1556
1613
|
}
|
|
@@ -1633,13 +1690,13 @@ export class MTextInputBox {
|
|
|
1633
1690
|
}
|
|
1634
1691
|
getNodeLogicalSpan(node) {
|
|
1635
1692
|
switch (node.type) {
|
|
1636
|
-
case
|
|
1693
|
+
case 'char':
|
|
1637
1694
|
return 1;
|
|
1638
|
-
case
|
|
1695
|
+
case 'stack':
|
|
1639
1696
|
return 1;
|
|
1640
|
-
case
|
|
1641
|
-
case
|
|
1642
|
-
case
|
|
1697
|
+
case 'paragraphBreak':
|
|
1698
|
+
case 'columnBreak':
|
|
1699
|
+
case 'wrapAtDimLine':
|
|
1643
1700
|
// Structural line-break nodes do not have a visual char box, so
|
|
1644
1701
|
// they must not consume logical cursor positions.
|
|
1645
1702
|
return 0;
|
|
@@ -1698,7 +1755,9 @@ export class MTextInputBox {
|
|
|
1698
1755
|
const minCandidateLine = candidates[0]?.lineIndex ?? 0;
|
|
1699
1756
|
const maxCandidateLine = candidates[candidates.length - 1]?.lineIndex ?? 0;
|
|
1700
1757
|
if (lineIndexHint < minCandidateLine || lineIndexHint > maxCandidateLine) {
|
|
1701
|
-
return preferAfterZeroSpan
|
|
1758
|
+
return preferAfterZeroSpan
|
|
1759
|
+
? candidates[candidates.length - 1].index
|
|
1760
|
+
: candidates[0].index;
|
|
1702
1761
|
}
|
|
1703
1762
|
let best = candidates[0];
|
|
1704
1763
|
let bestDist = Math.abs(best.lineIndex - lineIndexHint);
|
|
@@ -1879,7 +1938,8 @@ export class MTextInputBox {
|
|
|
1879
1938
|
return;
|
|
1880
1939
|
const scriptStyle = this.cloneDocumentStyle(first.style);
|
|
1881
1940
|
scriptStyle.script = script;
|
|
1882
|
-
scriptStyle.align =
|
|
1941
|
+
scriptStyle.align =
|
|
1942
|
+
script === 'superscript' ? MTextLineAlignment.TOP : MTextLineAlignment.BOTTOM;
|
|
1883
1943
|
const stackNode = {
|
|
1884
1944
|
type: 'stack',
|
|
1885
1945
|
numerator: script === 'superscript' ? plainText : '',
|
|
@@ -1943,7 +2003,8 @@ export class MTextInputBox {
|
|
|
1943
2003
|
if (!!snapshot.selection !== !!selection)
|
|
1944
2004
|
return false;
|
|
1945
2005
|
if (snapshot.selection && selection) {
|
|
1946
|
-
if (snapshot.selection.start !== selection.start ||
|
|
2006
|
+
if (snapshot.selection.start !== selection.start ||
|
|
2007
|
+
snapshot.selection.end !== selection.end) {
|
|
1947
2008
|
return false;
|
|
1948
2009
|
}
|
|
1949
2010
|
}
|