1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/// <reference path='./import.ts' /> 17class TextEnableDataDetectorModifier extends ModifierWithKey<boolean> { 18 constructor(value: boolean) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('textEnableDataDetector'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().text.resetEnableDataDetector(node); 25 } else { 26 getUINativeModule().text.setEnableDataDetector(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return !isBaseOrResourceEqual(this.stageValue, this.value); 31 } 32} 33 34class FontColorModifier extends ModifierWithKey<ResourceColor> { 35 constructor(value: ResourceColor) { 36 super(value); 37 } 38 static identity: Symbol = Symbol('textFontColor'); 39 applyPeer(node: KNode, reset: boolean): void { 40 if (reset) { 41 getUINativeModule().text.resetFontColor(node); 42 } else { 43 getUINativeModule().text.setFontColor(node, this.value); 44 } 45 } 46 47 checkObjectDiff(): boolean { 48 return !isBaseOrResourceEqual(this.stageValue, this.value); 49 } 50} 51 52class TextForegroundColorModifier extends ModifierWithKey<ResourceColor | ColoringStrategy> { 53 constructor(value: ResourceColor | ColoringStrategy) { 54 super(value); 55 } 56 static identity: Symbol = Symbol('textForegroundColor'); 57 applyPeer(node: KNode, reset: boolean): void { 58 if (reset) { 59 getUINativeModule().text.resetTextForegroundColor(node); 60 } else { 61 getUINativeModule().text.setTextForegroundColor(node, this.value); 62 } 63 } 64 65 checkObjectDiff(): boolean { 66 return !isBaseOrResourceEqual(this.stageValue, this.value); 67 } 68} 69 70class FontSizeModifier extends ModifierWithKey<number | string | Resource> { 71 constructor(value: number | string | Resource) { 72 super(value); 73 } 74 static identity: Symbol = Symbol('textFontSize'); 75 applyPeer(node: KNode, reset: boolean): void { 76 if (reset) { 77 getUINativeModule().text.resetFontSize(node); 78 } else { 79 getUINativeModule().text.setFontSize(node, this.value); 80 } 81 } 82 83 checkObjectDiff(): boolean { 84 return !isBaseOrResourceEqual(this.stageValue, this.value); 85 } 86} 87 88class FontWeightModifier extends ModifierWithKey<string> { 89 constructor(value: string) { 90 super(value); 91 } 92 static identity: Symbol = Symbol('textFontWeight'); 93 applyPeer(node: KNode, reset: boolean): void { 94 if (reset) { 95 getUINativeModule().text.resetFontWeight(node); 96 } else { 97 getUINativeModule().text.setFontWeight(node, this.value); 98 } 99 } 100} 101 102class FontStyleModifier extends ModifierWithKey<number> { 103 constructor(value: number) { 104 super(value); 105 } 106 static identity: Symbol = Symbol('textFontStyle'); 107 applyPeer(node: KNode, reset: boolean): void { 108 if (reset) { 109 getUINativeModule().text.resetFontStyle(node); 110 } else { 111 getUINativeModule().text.setFontStyle(node, this.value); 112 } 113 } 114} 115 116class TextAlignModifier extends ModifierWithKey<number> { 117 constructor(value: number) { 118 super(value); 119 } 120 static identity: Symbol = Symbol('textAlign'); 121 applyPeer(node: KNode, reset: boolean): void { 122 if (reset) { 123 getUINativeModule().text.resetTextAlign(node); 124 } else { 125 getUINativeModule().text.setTextAlign(node, this.value); 126 } 127 } 128} 129 130class TextHeightAdaptivePolicyModifier extends ModifierWithKey<TextHeightAdaptivePolicy> { 131 constructor(value: TextHeightAdaptivePolicy) { 132 super(value); 133 } 134 static identity: Symbol = Symbol('textHeightAdaptivePolicy'); 135 applyPeer(node: KNode, reset: boolean): void { 136 if (reset) { 137 getUINativeModule().text.resetHeightAdaptivePolicy(node); 138 } else { 139 getUINativeModule().text.setHeightAdaptivePolicy(node, this.value!); 140 } 141 } 142 checkObjectDiff(): boolean { 143 return !isBaseOrResourceEqual(this.stageValue, this.value); 144 } 145} 146 147class TextDraggableModifier extends ModifierWithKey<boolean> { 148 constructor(value: boolean) { 149 super(value); 150 } 151 static identity: Symbol = Symbol('textDraggable'); 152 applyPeer(node: KNode, reset: boolean): void { 153 if (reset) { 154 getUINativeModule().text.resetDraggable(node); 155 } else { 156 getUINativeModule().text.setDraggable(node, this.value!); 157 } 158 } 159 checkObjectDiff(): boolean { 160 return !isBaseOrResourceEqual(this.stageValue, this.value); 161 } 162} 163 164class TextPrivacySensitiveModifier extends ModifierWithKey<boolean> { 165 constructor(value: boolean) { 166 super(value); 167 } 168 static identity: Symbol = Symbol('textPrivacySensitive'); 169 applyPeer(node: KNode, reset: boolean): void { 170 if (reset) { 171 getUINativeModule().text.resetPrivacySensitive(node); 172 } else { 173 getUINativeModule().text.setPrivacySensitive(node, this.value!); 174 } 175 } 176 checkObjectDiff(): boolean { 177 return !isBaseOrResourceEqual(this.stageValue, this.value); 178 } 179} 180 181class TextWordBreakModifier extends ModifierWithKey<WordBreak> { 182 constructor(value: WordBreak) { 183 super(value); 184 } 185 static identity: Symbol = Symbol('textWordBreak'); 186 applyPeer(node: KNode, reset: boolean): void { 187 if (reset) { 188 getUINativeModule().text.resetWordBreak(node); 189 } else { 190 getUINativeModule().text.setWordBreak(node, this.value!); 191 } 192 } 193 checkObjectDiff(): boolean { 194 return !isBaseOrResourceEqual(this.stageValue, this.value); 195 } 196} 197 198class TextLineBreakStrategyModifier extends ModifierWithKey<LineBreakStrategy> { 199 constructor(value: LineBreakStrategy) { 200 super(value); 201 } 202 static identity: Symbol = Symbol('textLineBreakStrategy'); 203 applyPeer(node: KNode, reset: boolean): void { 204 if (reset) { 205 getUINativeModule().text.resetLineBreakStrategy(node); 206 } else { 207 getUINativeModule().text.setLineBreakStrategy(node, this.value!); 208 } 209 } 210 checkObjectDiff(): boolean { 211 return !isBaseOrResourceEqual(this.stageValue, this.value); 212 } 213} 214class TextEllipsisModeModifier extends ModifierWithKey<EllipsisMode> { 215 constructor(value: EllipsisMode) { 216 super(value); 217 } 218 static identity: Symbol = Symbol('textEllipsisMode'); 219 applyPeer(node: KNode, reset: boolean): void { 220 if (reset) { 221 getUINativeModule().text.resetEllipsisMode(node); 222 } else { 223 getUINativeModule().text.setEllipsisMode(node, this.value!); 224 } 225 } 226 checkObjectDiff(): boolean { 227 return !isBaseOrResourceEqual(this.stageValue, this.value); 228 } 229} 230 231class TextMinFontSizeModifier extends ModifierWithKey<number | string | Resource> { 232 constructor(value: number | string | Resource) { 233 super(value); 234 } 235 static identity: Symbol = Symbol('textMinFontSize'); 236 applyPeer(node: KNode, reset: boolean): void { 237 if (reset) { 238 getUINativeModule().text.resetMinFontSize(node); 239 } else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { 240 getUINativeModule().text.resetMinFontSize(node); 241 } else { 242 getUINativeModule().text.setMinFontSize(node, this.value!); 243 } 244 } 245 246 checkObjectDiff(): boolean { 247 return !isBaseOrResourceEqual(this.stageValue, this.value); 248 } 249} 250 251class TextMaxFontSizeModifier extends ModifierWithKey<number | string | Resource> { 252 constructor(value: number | string | Resource) { 253 super(value); 254 } 255 static identity: Symbol = Symbol('textMaxFontSize'); 256 applyPeer(node: KNode, reset: boolean): void { 257 if (reset) { 258 getUINativeModule().text.resetMaxFontSize(node); 259 } else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { 260 getUINativeModule().text.resetMaxFontSize(node); 261 } else { 262 getUINativeModule().text.setMaxFontSize(node, this.value!); 263 } 264 } 265 266 checkObjectDiff(): boolean { 267 return !isBaseOrResourceEqual(this.stageValue, this.value); 268 } 269} 270 271class TextMinFontScaleModifier extends ModifierWithKey<number | Resource> { 272 constructor(value: number | Resource) { 273 super(value); 274 } 275 static identity: Symbol = Symbol('textMinFontScale'); 276 applyPeer(node: KNode, reset: boolean): void { 277 if (reset) { 278 getUINativeModule().text.resetMinFontScale(node); 279 } else if (!isNumber(this.value) && !isResource(this.value)) { 280 getUINativeModule().text.resetMinFontScale(node); 281 } else { 282 getUINativeModule().text.setMinFontScale(node, this.value!); 283 } 284 } 285 286 checkObjectDiff(): boolean { 287 return !isBaseOrResourceEqual(this.stageValue, this.value); 288 } 289} 290 291class TextMaxFontScaleModifier extends ModifierWithKey<number | Resource> { 292 constructor(value: number | Resource) { 293 super(value); 294 } 295 static identity: Symbol = Symbol('textMaxFontScale'); 296 applyPeer(node: KNode, reset: boolean): void { 297 if (reset) { 298 getUINativeModule().text.resetMaxFontScale(node); 299 } else if (!isNumber(this.value) && !isResource(this.value)) { 300 getUINativeModule().text.resetMaxFontScale(node); 301 } else { 302 getUINativeModule().text.setMaxFontScale(node, this.value!); 303 } 304 } 305 306 checkObjectDiff(): boolean { 307 return !isBaseOrResourceEqual(this.stageValue, this.value); 308 } 309} 310 311class TextLineHeightModifier extends ModifierWithKey<number | string | Resource> { 312 constructor(value: number | string | Resource) { 313 super(value); 314 } 315 static identity: Symbol = Symbol('textLineHeight'); 316 applyPeer(node: KNode, reset: boolean): void { 317 if (reset) { 318 getUINativeModule().text.resetLineHeight(node); 319 } else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { 320 getUINativeModule().text.resetLineHeight(node); 321 } else { 322 getUINativeModule().text.setLineHeight(node, this.value!); 323 } 324 } 325 326 checkObjectDiff(): boolean { 327 return !isBaseOrResourceEqual(this.stageValue, this.value); 328 } 329} 330 331class TextCopyOptionModifier extends ModifierWithKey<CopyOptions> { 332 constructor(value: CopyOptions) { 333 super(value); 334 } 335 static identity: Symbol = Symbol('textCopyOption'); 336 applyPeer(node: KNode, reset: boolean): void { 337 if (reset) { 338 getUINativeModule().text.resetCopyOption(node); 339 } else { 340 getUINativeModule().text.setCopyOption(node, this.value!); 341 } 342 } 343 checkObjectDiff(): boolean { 344 return !isBaseOrResourceEqual(this.stageValue, this.value); 345 } 346} 347 348class TextFontFamilyModifier extends ModifierWithKey<string | Resource> { 349 constructor(value: string | Resource) { 350 super(value); 351 } 352 static identity: Symbol = Symbol('textFontFamily'); 353 applyPeer(node: KNode, reset: boolean): void { 354 if (reset) { 355 getUINativeModule().text.resetFontFamily(node); 356 } else if (!isString(this.value) && !isResource(this.value)) { 357 getUINativeModule().text.resetFontFamily(node); 358 } else { 359 getUINativeModule().text.setFontFamily(node, this.value!); 360 } 361 } 362 363 checkObjectDiff(): boolean { 364 return !isBaseOrResourceEqual(this.stageValue, this.value); 365 } 366} 367 368class TextMaxLinesModifier extends ModifierWithKey<number> { 369 constructor(value: number) { 370 super(value); 371 } 372 static identity: Symbol = Symbol('textMaxLines'); 373 applyPeer(node: KNode, reset: boolean): void { 374 if (reset) { 375 getUINativeModule().text.resetMaxLines(node); 376 } else if (!isNumber(this.value)) { 377 getUINativeModule().text.resetMaxLines(node); 378 } else { 379 getUINativeModule().text.setMaxLines(node, this.value!); 380 } 381 } 382 checkObjectDiff(): boolean { 383 return !isBaseOrResourceEqual(this.stageValue, this.value); 384 } 385} 386 387class TextLetterSpacingModifier extends ModifierWithKey<number | string> { 388 constructor(value: number | string) { 389 super(value); 390 } 391 static identity: Symbol = Symbol('textLetterSpacing'); 392 applyPeer(node: KNode, reset: boolean): void { 393 if (reset) { 394 getUINativeModule().text.resetLetterSpacing(node); 395 } else if (!isNumber(this.value) && !isString(this.value)) { 396 getUINativeModule().text.resetLetterSpacing(node); 397 } else { 398 getUINativeModule().text.setLetterSpacing(node, this.value!); 399 } 400 } 401 checkObjectDiff(): boolean { 402 return !isBaseOrResourceEqual(this.stageValue, this.value); 403 } 404} 405 406class TextLineSpacingModifier extends ModifierWithKey<LengthMetrics> { 407 constructor(value: LengthMetrics) { 408 super(value); 409 } 410 static identity: Symbol = Symbol('textLineSpacing'); 411 applyPeer(node: KNode, reset: boolean): void { 412 if (reset) { 413 getUINativeModule().text.resetLineSpacing(node); 414 } else if (!isObject(this.value)) { 415 getUINativeModule().text.resetLineSpacing(node); 416 } else { 417 getUINativeModule().text.setLineSpacing(node, this.value.value, this.value.unit); 418 } 419 } 420 421 checkObjectDiff(): boolean { 422 return !isBaseOrResourceEqual(this.stageValue, this.value); 423 } 424} 425 426class TextTextOverflowModifier extends ModifierWithKey<{ overflow: TextOverflow }> { 427 constructor(value: { overflow: TextOverflow }) { 428 super(value); 429 } 430 static identity: Symbol = Symbol('textTextOverflow'); 431 applyPeer(node: KNode, reset: boolean): void { 432 if (reset) { 433 getUINativeModule().text.resetTextOverflow(node); 434 } else { 435 getUINativeModule().text.setTextOverflow(node, this.value.overflow); 436 } 437 } 438 checkObjectDiff(): boolean { 439 return !isBaseOrResourceEqual(this.stageValue.overflow, this.value.overflow); 440 } 441} 442 443class TextBaselineOffsetModifier extends ModifierWithKey<number | string> { 444 constructor(value: number | string) { 445 super(value); 446 } 447 static identity: symbol = Symbol('textBaselineOffset'); 448 applyPeer(node: KNode, reset: boolean): void { 449 if (reset) { 450 getUINativeModule().text.resetBaselineOffset(node); 451 } else if (!isNumber(this.value) && !isString(this.value)) { 452 getUINativeModule().text.resetBaselineOffset(node); 453 } else { 454 getUINativeModule().text.setBaselineOffset(node, this.value!); 455 } 456 } 457 checkObjectDiff(): boolean { 458 return !isBaseOrResourceEqual(this.stageValue, this.value); 459 } 460} 461 462class TextTextCaseModifier extends ModifierWithKey<TextCase> { 463 constructor(value: TextCase) { 464 super(value); 465 } 466 static identity: symbol = Symbol('textTextCase'); 467 applyPeer(node: KNode, reset: boolean): void { 468 if (reset) { 469 getUINativeModule().text.resetTextCase(node); 470 } else { 471 getUINativeModule().text.setTextCase(node, this.value!); 472 } 473 } 474 checkObjectDiff(): boolean { 475 return !isBaseOrResourceEqual(this.stageValue, this.value); 476 } 477} 478 479class TextTextIndentModifier extends ModifierWithKey<Length> { 480 constructor(value: Length) { 481 super(value); 482 } 483 static identity: symbol = Symbol('textTextIndent'); 484 applyPeer(node: KNode, reset: boolean): void { 485 if (reset) { 486 getUINativeModule().text.resetTextIndent(node); 487 } else if (!isNumber(this.value) && !isString(this.value) && !isResource(this.value)) { 488 getUINativeModule().text.resetTextIndent(node); 489 } else { 490 getUINativeModule().text.setTextIndent(node, this.value!); 491 } 492 } 493 494 checkObjectDiff(): boolean { 495 return !isBaseOrResourceEqual(this.stageValue, this.value); 496 } 497} 498 499class TextTextShadowModifier extends ModifierWithKey<ShadowOptions | Array<ShadowOptions>> { 500 constructor(value: ShadowOptions | Array<ShadowOptions>) { 501 super(value); 502 } 503 static identity: Symbol = Symbol('textTextShadow'); 504 applyPeer(node: KNode, reset: boolean): void { 505 if (reset) { 506 getUINativeModule().text.resetTextShadow(node); 507 } else { 508 let shadow: ArkShadowInfoToArray = new ArkShadowInfoToArray(); 509 if (!shadow.convertShadowOptions(this.value)) { 510 getUINativeModule().text.resetTextShadow(node); 511 } else { 512 getUINativeModule().text.setTextShadow(node, shadow.radius, 513 shadow.type, shadow.color, shadow.offsetX, shadow.offsetY, shadow.fill, shadow.radius.length); 514 } 515 } 516 } 517 518 checkObjectDiff(): boolean { 519 let checkDiff = true; 520 let arkShadow = new ArkShadowInfoToArray(); 521 if (Object.getPrototypeOf(this.stageValue).constructor === Object && 522 Object.getPrototypeOf(this.value).constructor === Object) { 523 checkDiff = arkShadow.checkDiff(<ShadowOptions> this.stageValue, <ShadowOptions> this.value); 524 } else if (Object.getPrototypeOf(this.stageValue).constructor === Array && 525 Object.getPrototypeOf(this.value).constructor === Array && 526 (<Array<ShadowOptions>> this.stageValue).length === (<Array<ShadowOptions>> this.value).length) { 527 let isDiffItem = false; 528 for (let i: number = 0; i < (<Array<ShadowOptions>> this.value).length; i++) { 529 if (arkShadow.checkDiff(this.stageValue[i], this.value[1])) { 530 isDiffItem = true; 531 break; 532 } 533 } 534 if (!isDiffItem) { 535 checkDiff = false; 536 } 537 } 538 return checkDiff; 539 } 540} 541 542class TextDecorationModifier extends ModifierWithKey<{ type: TextDecorationType; color?: ResourceColor; style?: TextDecorationStyle }> { 543 constructor(value: { type: TextDecorationType; color?: ResourceColor; style?: TextDecorationStyle }) { 544 super(value); 545 } 546 static identity: Symbol = Symbol('textDecoration'); 547 applyPeer(node: KNode, reset: boolean): void { 548 if (reset) { 549 getUINativeModule().text.resetDecoration(node); 550 } else { 551 getUINativeModule().text.setDecoration(node, this.value!.type, this.value!.color, this.value!.style); 552 } 553 } 554 555 checkObjectDiff(): boolean { 556 if (this.stageValue.type !== this.value.type || this.stageValue.style !== this.value.style) { 557 return true; 558 } 559 if (isResource(this.stageValue.color) && isResource(this.value.color)) { 560 return !isResourceEqual(this.stageValue.color, this.value.color); 561 } else if (!isResource(this.stageValue.color) && !isResource(this.value.color)) { 562 return !(this.stageValue.color === this.value.color); 563 } else { 564 return true; 565 } 566 } 567} 568 569class TextFontModifier extends ModifierWithKey<Font> { 570 constructor(value: Font) { 571 super(value); 572 } 573 static identity: Symbol = Symbol('textFont'); 574 applyPeer(node: KNode, reset: boolean): void { 575 if (reset) { 576 getUINativeModule().text.resetFont(node); 577 } else { 578 getUINativeModule().text.setFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 579 } 580 } 581 582 checkObjectDiff(): boolean { 583 if (this.stageValue.weight !== this.value.weight || this.stageValue.style !== this.value.style) { 584 return true; 585 } 586 if (((isResource(this.stageValue.size) && isResource(this.value.size) && 587 isResourceEqual(this.stageValue.size, this.value.size)) || 588 (!isResource(this.stageValue.size) && !isResource(this.value.size) && 589 this.stageValue.size === this.value.size)) && 590 ((isResource(this.stageValue.family) && isResource(this.value.family) && 591 isResourceEqual(this.stageValue.family, this.value.family)) || 592 (!isResource(this.stageValue.family) && !isResource(this.value.family) && 593 this.stageValue.family === this.value.family))) { 594 return false; 595 } else { 596 return true; 597 } 598 } 599} 600 601class TextClipModifier extends ModifierWithKey<boolean | object> { 602 constructor(value: boolean | object) { 603 super(value); 604 } 605 static identity: Symbol = Symbol('textClip'); 606 applyPeer(node: KNode, reset: boolean): void { 607 if (reset) { 608 getUINativeModule().common.resetClipWithEdge(node); 609 } else { 610 getUINativeModule().common.setClipWithEdge(node, this.value); 611 } 612 } 613 614 checkObjectDiff(): boolean { 615 return true; 616 } 617} 618 619class TextFontFeatureModifier extends ModifierWithKey<FontFeature> { 620 constructor(value: FontFeature) { 621 super(value); 622 } 623 static identity: Symbol = Symbol('textFontFeature'); 624 applyPeer(node: KNode, reset: boolean): void { 625 if (reset) { 626 getUINativeModule().text.resetFontFeature(node); 627 } else { 628 getUINativeModule().text.setFontFeature(node, this.value!); 629 } 630 } 631 checkObjectDiff(): boolean { 632 return !isBaseOrResourceEqual(this.stageValue, this.value); 633 } 634} 635 636class TextContentModifier extends ModifierWithKey<string | Resource> { 637 constructor(value: string | Resource) { 638 super(value); 639 } 640 static identity: Symbol = Symbol('textContent'); 641 applyPeer(node: KNode, reset: boolean): void { 642 if (reset) { 643 getUINativeModule().text.setContent(node, ''); 644 } 645 else { 646 getUINativeModule().text.setContent(node, this.value); 647 } 648 } 649} 650 651class TextSelectionModifier extends ModifierWithKey<ArkSelection> { 652 constructor(value: ArkSelection) { 653 super(value); 654 } 655 static identity: Symbol = Symbol('textSelection'); 656 applyPeer(node: KNode, reset: boolean): void { 657 if (reset) { 658 getUINativeModule().text.resetSelection(node); 659 } else { 660 getUINativeModule().text.setSelection(node, this.value.selectionStart, this.value.selectionEnd); 661 } 662 } 663 checkObjectDiff(): boolean { 664 return !isBaseOrResourceEqual(this.stageValue.selectionStart, this.value.selectionStart) || 665 !isBaseOrResourceEqual(this.stageValue.selectionEnd, this.value.selectionEnd); 666 } 667} 668 669class TextSelectableModifier extends ModifierWithKey<TextSelectableMode> { 670 constructor(value: TextSelectableMode) { 671 super(value); 672 } 673 static identity: Symbol = Symbol('textTextSelectable'); 674 applyPeer(node: KNode, reset: boolean): void { 675 if (reset) { 676 getUINativeModule().text.resetTextSelectableMode(node); 677 } else { 678 getUINativeModule().text.setTextSelectableMode(node, this.value!); 679 } 680 } 681 checkObjectDiff(): boolean { 682 return !isBaseOrResourceEqual(this.stageValue, this.value); 683 } 684} 685 686class TextCaretColorModifier extends ModifierWithKey<ResourceColor> { 687 constructor(value: ResourceColor) { 688 super(value); 689 } 690 static identity: Symbol = Symbol('textCaretColor'); 691 applyPeer(node: KNode, reset: boolean): void { 692 if (reset) { 693 getUINativeModule().text.resetCaretColor(node); 694 } else { 695 getUINativeModule().text.setCaretColor(node, this.value!); 696 } 697 } 698 checkObjectDiff(): boolean { 699 return !isBaseOrResourceEqual(this.stageValue, this.value); 700 } 701} 702 703class TextSelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 704 constructor(value: ResourceColor) { 705 super(value); 706 } 707 static identity: Symbol = Symbol('textSelectedBackgroundColor'); 708 applyPeer(node: KNode, reset: boolean): void { 709 if (reset) { 710 getUINativeModule().text.resetSelectedBackgroundColor(node); 711 } else { 712 getUINativeModule().text.setSelectedBackgroundColor(node, this.value!); 713 } 714 } 715 checkObjectDiff(): boolean { 716 return !isBaseOrResourceEqual(this.stageValue, this.value); 717 } 718} 719 720class TextDataDetectorConfigModifier extends ModifierWithKey<TextDataDetectorConfig> { 721 constructor(value: TextDataDetectorConfig) { 722 super(value); 723 } 724 static identity: Symbol = Symbol('textDataDetectorConfig'); 725 applyPeer(node: KNode, reset: boolean): void { 726 if (reset) { 727 getUINativeModule().text.resetDataDetectorConfig(node); 728 } else { 729 getUINativeModule().text.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate); 730 } 731 } 732 checkObjectDiff(): boolean { 733 return !isBaseOrResourceEqual(this.stageValue.types, this.value.types) || 734 !isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate); 735 } 736} 737 738class TextOnCopyModifier extends ModifierWithKey<(value: string) => void> { 739 constructor(value: (value: string) => void) { 740 super(value); 741 } 742 static identity: Symbol = Symbol('textOnCopy'); 743 applyPeer(node: KNode, reset: boolean): void { 744 if (reset) { 745 getUINativeModule().text.resetOnCopy(node); 746 } else { 747 getUINativeModule().text.setOnCopy(node, this.value); 748 } 749 } 750} 751 752class TextOnTextSelectionChangeModifier extends ModifierWithKey<(selectionStart: number, 753 selectionEnd: number) => void> { 754 constructor(value: (selectionStart: number, selectionEnd: number) => void) { 755 super(value); 756 } 757 static identity: Symbol = Symbol('textOnTextSelectionChange'); 758 applyPeer(node: KNode, reset: boolean): void { 759 if (reset) { 760 getUINativeModule().text.resetOnTextSelectionChange(node); 761 } else { 762 getUINativeModule().text.setOnTextSelectionChange(node, this.value); 763 } 764 } 765} 766 767class TextControllerModifier extends ModifierWithKey<TextOptions> { 768 constructor(value: TextOptions) { 769 super(value); 770 } 771 static identity: Symbol = Symbol('textController'); 772 applyPeer(node: KNode, reset: boolean): void { 773 if (reset) { 774 getUINativeModule().text.setTextController(node, ''); 775 } 776 else { 777 getUINativeModule().text.setTextController(node, this.value); 778 } 779 } 780} 781 782class TextEditMenuOptionsModifier extends ModifierWithKey<EditMenuOptions> { 783 constructor(value: EditMenuOptions) { 784 super(value); 785 } 786 static identity: Symbol = Symbol('textEditMenuOptions'); 787 applyPeer(node: KNode, reset: boolean): void { 788 if (reset) { 789 getUINativeModule().text.resetSelectionMenuOptions(node); 790 } else { 791 getUINativeModule().text.setSelectionMenuOptions(node, this.value); 792 } 793 } 794} 795 796class TextHalfLeadingModifier extends ModifierWithKey<boolean> { 797 constructor(value: boolean) { 798 super(value); 799 } 800 static identity: Symbol = Symbol('textHalfLeading'); 801 applyPeer(node: KNode, reset: boolean): void { 802 if (reset) { 803 getUINativeModule().text.resetHalfLeading(node); 804 } else { 805 getUINativeModule().text.setHalfLeading(node, this.value!); 806 } 807 } 808 checkObjectDiff(): boolean { 809 return !isBaseOrResourceEqual(this.stageValue, this.value); 810 } 811} 812 813class TextEnableHapticFeedbackModifier extends ModifierWithKey<boolean> { 814 constructor(value: boolean) { 815 super(value); 816 } 817 static identity: Symbol = Symbol('textEnableHapticFeedback'); 818 applyPeer(node: KNode, reset: boolean): void { 819 if (reset) { 820 getUINativeModule().text.resetEnableHapticFeedback(node); 821 } else { 822 getUINativeModule().text.setEnableHapticFeedback(node, this.value!); 823 } 824 } 825 checkObjectDiff(): boolean { 826 return !isBaseOrResourceEqual(this.stageValue, this.value); 827 } 828} 829 830class TextMarqueeOptionsModifier extends ModifierWithKey<MarqueeOptions> { 831 constructor(value: MarqueeOptions) { 832 super(value); 833 } 834 static identity: Symbol = Symbol('textMarqueeOptions'); 835 applyPeer(node: KNode, reset: boolean): void { 836 if (reset) { 837 getUINativeModule().text.resetMarqueeOptions(node); 838 } else { 839 getUINativeModule().text.setMarqueeOptions(node, this.value.start, this.value.fromStart, this.value.step, 840 this.value.loop, this.value.delay, this.value.fadeout, this.value.marqueeStartPolicy); 841 } 842 } 843 checkObjectDiff(): boolean { 844 return !isBaseOrResourceEqual(this.stageValue, this.value); 845 } 846} 847 848class TextOnMarqueeStateChangeModifier extends ModifierWithKey<(state: MarqueeState) => void> { 849 constructor(value: (state: MarqueeState) => void) { 850 super(value); 851 } 852 static identity: Symbol = Symbol('textOnMarqueeStateChange'); 853 applyPeer(node: KNode, reset: boolean): void { 854 if (reset) { 855 getUINativeModule().text.resetOnMarqueeStateChange(node); 856 } else { 857 getUINativeModule().text.setOnMarqueeStateChange(node, this.value); 858 } 859 } 860} 861 862class ArkTextComponent extends ArkComponent implements TextAttribute { 863 constructor(nativePtr: KNode, classType?: ModifierType) { 864 super(nativePtr, classType); 865 } 866 allowChildTypes(): string[] { 867 return ['Span', 'ImageSpan', 'SymbolSpan', 'ContainerSpan']; 868 } 869 initialize(value: Object[]): void { 870 modifierWithKey(this._modifiersWithKeys, TextContentModifier.identity, TextContentModifier, value[0]); 871 modifierWithKey(this._modifiersWithKeys, TextControllerModifier.identity, TextControllerModifier, value[1]); 872 return this; 873 } 874 enableDataDetector(value: boolean): this { 875 modifierWithKey(this._modifiersWithKeys, TextEnableDataDetectorModifier.identity, TextEnableDataDetectorModifier, value); 876 return this; 877 } 878 dataDetectorConfig(config: TextDataDetectorConfig): this { 879 let detectorConfig = new TextDataDetectorConfig(); 880 detectorConfig.types = config.types; 881 detectorConfig.onDetectResultUpdate = config.onDetectResultUpdate; 882 modifierWithKey(this._modifiersWithKeys, TextDataDetectorConfigModifier.identity, TextDataDetectorConfigModifier, detectorConfig); 883 return this; 884 } 885 font(value: Font): TextAttribute { 886 modifierWithKey(this._modifiersWithKeys, TextFontModifier.identity, TextFontModifier, value); 887 return this; 888 } 889 fontColor(value: ResourceColor): TextAttribute { 890 modifierWithKey(this._modifiersWithKeys, FontColorModifier.identity, FontColorModifier, value); 891 return this; 892 } 893 fontSize(value: number | string | Resource): TextAttribute { 894 modifierWithKey(this._modifiersWithKeys, FontSizeModifier.identity, FontSizeModifier, value); 895 return this; 896 } 897 minFontSize(value: number | string | Resource): TextAttribute { 898 modifierWithKey(this._modifiersWithKeys, TextMinFontSizeModifier.identity, TextMinFontSizeModifier, value); 899 return this; 900 } 901 maxFontSize(value: number | string | Resource): TextAttribute { 902 modifierWithKey(this._modifiersWithKeys, TextMaxFontSizeModifier.identity, TextMaxFontSizeModifier, value); 903 return this; 904 } 905 minFontScale(value: number | Resource): TextAttribute { 906 modifierWithKey(this._modifiersWithKeys, TextMinFontScaleModifier.identity, TextMinFontScaleModifier, value); 907 return this; 908 } 909 maxFontScale(value: number | Resource): TextAttribute { 910 modifierWithKey(this._modifiersWithKeys, TextMaxFontScaleModifier.identity, TextMaxFontScaleModifier, value); 911 return this; 912 } 913 fontStyle(value: FontStyle): TextAttribute { 914 modifierWithKey(this._modifiersWithKeys, FontStyleModifier.identity, FontStyleModifier, value); 915 return this; 916 } 917 fontWeight(value: number | FontWeight | string): TextAttribute { 918 let fontWeightStr: string = '400'; 919 if (isNumber(value)) { 920 fontWeightStr = value.toString(); 921 } else if (isString(value)) { 922 fontWeightStr = String(value); 923 } 924 modifierWithKey(this._modifiersWithKeys, FontWeightModifier.identity, FontWeightModifier, fontWeightStr); 925 return this; 926 } 927 textAlign(value: TextAlign): TextAttribute { 928 modifierWithKey(this._modifiersWithKeys, TextAlignModifier.identity, TextAlignModifier, value); 929 return this; 930 } 931 lineHeight(value: number | string | Resource): TextAttribute { 932 modifierWithKey(this._modifiersWithKeys, TextLineHeightModifier.identity, TextLineHeightModifier, value); 933 return this; 934 } 935 textOverflow(value: { overflow: TextOverflow }): TextAttribute { 936 modifierWithKey(this._modifiersWithKeys, TextTextOverflowModifier.identity, TextTextOverflowModifier, value); 937 return this; 938 } 939 fontFamily(value: string | Resource): TextAttribute { 940 modifierWithKey(this._modifiersWithKeys, TextFontFamilyModifier.identity, TextFontFamilyModifier, value); 941 return this; 942 } 943 maxLines(value: number): TextAttribute { 944 modifierWithKey(this._modifiersWithKeys, TextMaxLinesModifier.identity, TextMaxLinesModifier, value); 945 return this; 946 } 947 decoration(value: { type: TextDecorationType; color?: ResourceColor; style?: TextDecorationStyle }): TextAttribute { 948 modifierWithKey(this._modifiersWithKeys, TextDecorationModifier.identity, TextDecorationModifier, value); 949 return this; 950 } 951 letterSpacing(value: number | string): TextAttribute { 952 modifierWithKey(this._modifiersWithKeys, TextLetterSpacingModifier.identity, TextLetterSpacingModifier, value); 953 return this; 954 } 955 lineSpacing(value: LengthMetrics): TextAttribute { 956 modifierWithKey(this._modifiersWithKeys, TextLineSpacingModifier.identity, TextLineSpacingModifier, value); 957 return this; 958 } 959 textCase(value: TextCase): TextAttribute { 960 modifierWithKey(this._modifiersWithKeys, TextTextCaseModifier.identity, TextTextCaseModifier, value); 961 return this; 962 } 963 baselineOffset(value: number | string): TextAttribute { 964 modifierWithKey(this._modifiersWithKeys, TextBaselineOffsetModifier.identity, TextBaselineOffsetModifier, value); 965 return this; 966 } 967 copyOption(value: CopyOptions): TextAttribute { 968 modifierWithKey(this._modifiersWithKeys, TextCopyOptionModifier.identity, TextCopyOptionModifier, value); 969 return this; 970 } 971 draggable(value: boolean): this { 972 modifierWithKey(this._modifiersWithKeys, TextDraggableModifier.identity, TextDraggableModifier, value); 973 return this; 974 } 975 privacySensitive(value: boolean): this { 976 modifierWithKey(this._modifiersWithKeys, TextPrivacySensitiveModifier.identity, TextPrivacySensitiveModifier, value); 977 return this; 978 } 979 textShadow(value: ShadowOptions | Array<ShadowOptions>): TextAttribute { 980 modifierWithKey(this._modifiersWithKeys, TextTextShadowModifier.identity, TextTextShadowModifier, value); 981 return this; 982 } 983 heightAdaptivePolicy(value: TextHeightAdaptivePolicy): TextAttribute { 984 modifierWithKey(this._modifiersWithKeys, TextHeightAdaptivePolicyModifier.identity, TextHeightAdaptivePolicyModifier, value); 985 return this; 986 } 987 textIndent(value: Length): TextAttribute { 988 modifierWithKey(this._modifiersWithKeys, TextTextIndentModifier.identity, TextTextIndentModifier, value); 989 return this; 990 } 991 wordBreak(value: WordBreak): TextAttribute { 992 modifierWithKey(this._modifiersWithKeys, TextWordBreakModifier.identity, TextWordBreakModifier, value); 993 return this; 994 } 995 lineBreakStrategy(value: LineBreakStrategy): TextAttribute { 996 modifierWithKey(this._modifiersWithKeys, TextLineBreakStrategyModifier.identity, 997 TextLineBreakStrategyModifier, value); 998 return this; 999 } 1000 onCopy(callback: (value: string) => void): TextAttribute { 1001 modifierWithKey(this._modifiersWithKeys, TextOnCopyModifier.identity, 1002 TextOnCopyModifier, callback); 1003 return this; 1004 } 1005 selection(selectionStart: number, selectionEnd: number): TextAttribute { 1006 let arkSelection = new ArkSelection(); 1007 arkSelection.selectionStart = selectionStart; 1008 arkSelection.selectionEnd = selectionEnd; 1009 modifierWithKey(this._modifiersWithKeys, TextSelectionModifier.identity, TextSelectionModifier, arkSelection); 1010 return this; 1011 } 1012 textSelectable(value: TextSelectableMode): TextAttribute { 1013 modifierWithKey(this._modifiersWithKeys, TextSelectableModifier.identity, TextSelectableModifier, value); 1014 return this; 1015 } 1016 caretColor(value: ResourceColor): TextAttribute { 1017 modifierWithKey(this._modifiersWithKeys, TextCaretColorModifier.identity, TextCaretColorModifier, value); 1018 return this; 1019 } 1020 selectedBackgroundColor(value: ResourceColor): TextAttribute { 1021 modifierWithKey(this._modifiersWithKeys, TextSelectedBackgroundColorModifier.identity, 1022 TextSelectedBackgroundColorModifier, value); 1023 return this; 1024 } 1025 ellipsisMode(value: EllipsisMode): TextAttribute { 1026 modifierWithKey(this._modifiersWithKeys, TextEllipsisModeModifier.identity, TextEllipsisModeModifier, value); 1027 return this; 1028 } 1029 fontFeature(value: FontFeature): TextAttribute { 1030 modifierWithKey(this._modifiersWithKeys, TextFontFeatureModifier.identity, TextFontFeatureModifier, value); 1031 return this; 1032 } 1033 clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this { 1034 modifierWithKey(this._modifiersWithKeys, TextClipModifier.identity, TextClipModifier, value); 1035 return this; 1036 } 1037 foregroundColor(value: ResourceColor | ColoringStrategy): void { 1038 modifierWithKey( 1039 this._modifiersWithKeys, TextForegroundColorModifier.identity, TextForegroundColorModifier, value); 1040 return this; 1041 } 1042 onTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void) { 1043 modifierWithKey(this._modifiersWithKeys, TextOnTextSelectionChangeModifier.identity, 1044 TextOnTextSelectionChangeModifier, callback); 1045 return this; 1046 } 1047 editMenuOptions(value: EditMenuOptions): this { 1048 modifierWithKey(this._modifiersWithKeys, TextEditMenuOptionsModifier.identity, 1049 TextEditMenuOptionsModifier, value); 1050 return this; 1051 } 1052 halfLeading(value: boolean): TextAttribute { 1053 modifierWithKey(this._modifiersWithKeys, TextHalfLeadingModifier.identity, 1054 TextHalfLeadingModifier, value); 1055 return this; 1056 } 1057 enableHapticFeedback(value: boolean): this { 1058 modifierWithKey(this._modifiersWithKeys, TextEnableHapticFeedbackModifier.identity, TextEnableHapticFeedbackModifier, value); 1059 return this; 1060 } 1061 marqueeOptions(value: MarqueeOptions): this { 1062 modifierWithKey( 1063 this._modifiersWithKeys, TextMarqueeOptionsModifier.identity, TextMarqueeOptionsModifier, value); 1064 return this; 1065 } 1066 onMarqueeStateChange(callback: (state: MarqueeState) => void): this { 1067 modifierWithKey( 1068 this._modifiersWithKeys, TextOnMarqueeStateChangeModifier.identity, TextOnMarqueeStateChangeModifier, callback); 1069 return this; 1070 } 1071} 1072// @ts-ignore 1073globalThis.Text.attributeModifier = function (modifier: ArkComponent): void { 1074 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 1075 return new ArkTextComponent(nativePtr); 1076 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 1077 return new modifierJS.TextModifier(nativePtr, classType); 1078 }); 1079}; 1080