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 16var j = (this && this.j) || function (t3, target, key, desc) { 17 var c = arguments.length, 18 r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 19 if (typeof Reflect === "object" && typeof Reflect.o1 === "function") { 20 r = Reflect.o1(t3, target, key, desc); 21 } else { 22 for (var u3 = t3.length - 1; u3 >= 0; u3--) { 23 if (d = t3[u3]) { 24 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 25 } 26 } 27 } 28 return c > 3 && r && Object.defineProperty(target, key, r), r; 29}; 30var m, o; 31if (!("finalizeConstruction" in ViewPU.prototype)) { 32 Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { 33 }); 34} 35const curves = globalThis.requireNativeModule('ohos.curves'); 36const KeyCode = globalThis.requireNapi('multimodalInput.keyCode').KeyCode; 37const util = globalThis.requireNapi('util'); 38const LengthMetrics = requireNapi('arkui.node').LengthMetrics; 39const t = requireNapi('i18n'); 40 41const u = 2; 42const a1 = 5; 43const e1 = { 44 q1: { 45 "id": -1, 46 "type": 10001, 47 params: ['sys.color.ohos_id_color_text_secondary'], 48 "bundleName": "__harDefaultBundleName__", 49 "moduleName": "__harDefaultModuleName__" 50 }, 51 s1: { 52 "id": -1, 53 "type": 10001, 54 params: ['sys.color.ohos_id_color_text_primary'], 55 "bundleName": "__harDefaultBundleName__", 56 "moduleName": "__harDefaultModuleName__" 57 }, 58 t1: { 59 "id": -1, 60 "type": 10001, 61 params: ['sys.color.ohos_id_color_foreground_contrary'], 62 "bundleName": "__harDefaultBundleName__", 63 "moduleName": "__harDefaultModuleName__" 64 }, 65 u1: { 66 "id": -1, 67 "type": 10002, 68 params: ['sys.float.ohos_id_text_size_body2'], 69 "bundleName": "__harDefaultBundleName__", 70 "moduleName": "__harDefaultModuleName__" 71 }, 72 v1: { 73 "id": -1, 74 "type": 10002, 75 params: ['sys.float.ohos_id_text_size_body2'], 76 "bundleName": "__harDefaultBundleName__", 77 "moduleName": "__harDefaultModuleName__" 78 }, 79 BACKGROUND_COLOR: { 80 "id": -1, 81 "type": 10001, 82 params: ['sys.color.ohos_id_color_button_normal'], 83 "bundleName": "__harDefaultBundleName__", 84 "moduleName": "__harDefaultModuleName__" 85 }, 86 w1: { 87 "id": -1, 88 "type": 10001, 89 params: ['sys.color.ohos_id_color_foreground_contrary'], 90 "bundleName": "__harDefaultBundleName__", 91 "moduleName": "__harDefaultModuleName__" 92 }, 93 z1: { 94 "id": -1, 95 "type": 10001, 96 params: ['sys.color.ohos_id_color_emphasize'], 97 "bundleName": "__harDefaultBundleName__", 98 "moduleName": "__harDefaultModuleName__" 99 }, 100 a2: { 101 "id": -1, 102 "type": 10001, 103 params: ['sys.color.ohos_id_color_focused_outline'], 104 "bundleName": "__harDefaultBundleName__", 105 "moduleName": "__harDefaultModuleName__" 106 }, 107 b2: { 108 "id": -1, 109 "type": 10001, 110 params: ['sys.color.ohos_id_color_hover'], 111 "bundleName": "__harDefaultBundleName__", 112 "moduleName": "__harDefaultModuleName__" 113 }, 114 c2: { 115 "id": -1, 116 "type": 10001, 117 params: ['sys.color.ohos_id_color_click_effect'], 118 "bundleName": "__harDefaultBundleName__", 119 "moduleName": "__harDefaultModuleName__" 120 }, 121 d2: BlurStyle.NONE 122}; 123 124function i(first, second) { 125 return Math.abs(first - second) < 0.001; 126} 127 128let SegmentButtonItemOptions = class SegmentButtonItemOptions { 129 constructor(options) { 130 this.icon = options.icon; 131 this.selectedIcon = options.selectedIcon; 132 this.text = options.text; 133 this.iconAccessibilityText = options.iconAccessibilityText; 134 this.selectedIconAccessibilityText = options.selectedIconAccessibilityText; 135 this.accessibilityLevel = options.accessibilityLevel; 136 this.accessibilityDescription = options.accessibilityDescription; 137 } 138}; 139SegmentButtonItemOptions = j([ 140 Observed 141], SegmentButtonItemOptions); 142let SegmentButtonItemOptionsArray = m = class SegmentButtonItemOptionsArray extends Array { 143 constructor(s3) { 144 super(typeof s3 === 'number' ? s3 : 0); 145 this.e2 = void 0; 146 this.deleteCount = void 0; 147 this.f2 = void 0; 148 if (typeof s3 !== 'number' && s3 !== void 0) { 149 super.push(...s3.map((element) => new SegmentButtonItemOptions(element))); 150 } 151 } 152 153 push(...items) { 154 if (this.length + items.length > a1) { 155 console.warn('Exceeded the maximum number of elements (5).'); 156 return this.length; 157 } 158 this.e2 = this.length; 159 this.deleteCount = 0; 160 this.f2 = items.length; 161 return super.push(...items.map((element) => new SegmentButtonItemOptions(element))); 162 } 163 164 pop() { 165 if (this.length <= u) { 166 console.warn('Below the minimum number of elements (2).'); 167 return void 0; 168 } 169 this.e2 = this.length - 1; 170 this.deleteCount = 1; 171 this.f2 = 0; 172 return super.pop(); 173 } 174 175 shift() { 176 if (this.length <= u) { 177 console.warn('Below the minimum number of elements (2).'); 178 return void 0; 179 } 180 this.e2 = 0; 181 this.deleteCount = 1; 182 this.f2 = 0; 183 return super.shift(); 184 } 185 186 unshift(...items) { 187 if (this.length + items.length > a1) { 188 console.warn('Exceeded the maximum number of elements (5).'); 189 return this.length; 190 } 191 if (items.length > 0) { 192 this.e2 = 0; 193 this.deleteCount = 0; 194 this.f2 = items.length; 195 } 196 return super.unshift(...items.map((element) => new SegmentButtonItemOptions(element))); 197 } 198 199 splice(start, deleteCount, ...items) { 200 let length = (this.length - deleteCount) < 0 ? 0 : (this.length - deleteCount); 201 length += items.length; 202 if (length < u) { 203 console.warn('Below the minimum number of elements (2).'); 204 return []; 205 } 206 if (length > a1) { 207 console.warn('Exceeded the maximum number of elements (5).'); 208 return []; 209 } 210 this.e2 = start; 211 this.deleteCount = deleteCount; 212 this.f2 = items.length; 213 return super.splice(start, deleteCount, ...items); 214 } 215 216 static create(elements) { 217 return new m(elements); 218 } 219}; 220SegmentButtonItemOptionsArray = m = j([ 221 Observed 222], SegmentButtonItemOptionsArray); 223 224export { SegmentButtonItemOptionsArray }; 225let SegmentButtonOptions = o = class SegmentButtonOptions { 226 get buttons() { 227 return this.g2; 228 } 229 230 set buttons(val) { 231 if (this.g2 !== void 0 && this.g2 !== val) { 232 this.h2?.(); 233 } 234 this.g2 = val; 235 } 236 237 constructor(options) { 238 this.multiply = false; 239 this.i2 = false; 240 this.showIcon = false; 241 this.g2 = void 0; 242 this.fontColor = options.fontColor ?? e1.q1; 243 this.selectedFontColor = options.selectedFontColor ?? e1.s1; 244 this.fontSize = options.fontSize ?? e1.u1; 245 this.selectedFontSize = options.selectedFontSize ?? e1.v1; 246 this.fontWeight = options.fontWeight ?? FontWeight.Regular; 247 this.selectedFontWeight = options.selectedFontWeight ?? FontWeight.Medium; 248 this.backgroundColor = options.backgroundColor ?? e1.BACKGROUND_COLOR; 249 this.selectedBackgroundColor = options.selectedBackgroundColor ?? e1.w1; 250 this.imageSize = options.imageSize ?? { width: 24, height: 24 }; 251 this.buttonPadding = options.buttonPadding; 252 this.textPadding = options.textPadding; 253 this.type = options.type; 254 this.backgroundBlurStyle = options.backgroundBlurStyle ?? e1.d2; 255 this.localizedTextPadding = options.localizedTextPadding; 256 this.localizedButtonPadding = options.localizedButtonPadding; 257 this.direction = options.direction ?? Direction.Auto; 258 this.buttons = new SegmentButtonItemOptionsArray(options.buttons); 259 if (this.type === 'capsule') { 260 this.multiply = options.multiply ?? false; 261 this.n2(); 262 this.selectedFontColor = options.selectedFontColor ?? e1.t1; 263 this.selectedBackgroundColor = options.selectedBackgroundColor ?? 264 e1.z1; 265 } else { 266 this.i2 = true; 267 } 268 this.m2 = this.multiply ? 0 : 2; 269 } 270 n2() { 271 this.buttons?.forEach(button => { 272 this.i2 ||= button.text !== void 0; 273 this.showIcon ||= button.icon !== void 0 || button.selectedIcon !== void 0; 274 }); 275 if (this.i2 && this.showIcon) { 276 this.j2 = 12; 277 this.l2 = 14; 278 } 279 } 280 281 static tab(options) { 282 return new o({ 283 type: 'tab', 284 buttons: options.buttons, 285 fontColor: options.fontColor, 286 selectedFontColor: options.selectedFontColor, 287 fontSize: options.fontSize, 288 selectedFontSize: options.selectedFontSize, 289 fontWeight: options.fontWeight, 290 selectedFontWeight: options.selectedFontWeight, 291 backgroundColor: options.backgroundColor, 292 selectedBackgroundColor: options.selectedBackgroundColor, 293 imageSize: options.imageSize, 294 buttonPadding: options.buttonPadding, 295 textPadding: options.textPadding, 296 localizedTextPadding: options.localizedTextPadding, 297 localizedButtonPadding: options.localizedButtonPadding, 298 backgroundBlurStyle: options.backgroundBlurStyle, 299 direction: options.direction 300 }); 301 } 302 303 static capsule(options) { 304 return new o({ 305 type: 'capsule', 306 buttons: options.buttons, 307 multiply: options.multiply, 308 fontColor: options.fontColor, 309 selectedFontColor: options.selectedFontColor, 310 fontSize: options.fontSize, 311 selectedFontSize: options.selectedFontSize, 312 fontWeight: options.fontWeight, 313 selectedFontWeight: options.selectedFontWeight, 314 backgroundColor: options.backgroundColor, 315 selectedBackgroundColor: options.selectedBackgroundColor, 316 imageSize: options.imageSize, 317 buttonPadding: options.buttonPadding, 318 textPadding: options.textPadding, 319 localizedTextPadding: options.localizedTextPadding, 320 localizedButtonPadding: options.localizedButtonPadding, 321 backgroundBlurStyle: options.backgroundBlurStyle, 322 direction: options.direction 323 }); 324 } 325}; 326SegmentButtonOptions = o = j([ 327 Observed 328], SegmentButtonOptions); 329 330export { SegmentButtonOptions }; 331 332class f1 extends ViewPU { 333 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 334 super(parent, __localStorage, elmtId, extraInfo); 335 if (typeof paramsLambda === "function") { 336 this.paramsGenerator_ = paramsLambda; 337 } 338 this.n2 = new SynchedPropertyNesedObjectPU(params.optionsArray, this, "optionsArray"); 339 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 340 this.q2 = this.initializeConsume("buttonBorderRadius", "buttonBorderRadius"); 341 this.s2 = this.initializeConsume("buttonItemsSize", "buttonItemsSize"); 342 this.setInitiallyProvidedValue(params); 343 this.finalizeConstruction(); 344 } 345 346 setInitiallyProvidedValue(params) { 347 this.n2.set(params.optionsArray); 348 this.o2.set(params.options); 349 } 350 351 updateStateVars(params) { 352 this.n2.set(params.optionsArray); 353 this.o2.set(params.options); 354 } 355 356 purgeVariableDependenciesOnElmtId(rmElmtId) { 357 this.n2.purgeDependencyOnElmtId(rmElmtId); 358 this.o2.purgeDependencyOnElmtId(rmElmtId); 359 this.q2.purgeDependencyOnElmtId(rmElmtId); 360 this.s2.purgeDependencyOnElmtId(rmElmtId); 361 } 362 363 aboutToBeDeleted() { 364 this.n2.aboutToBeDeleted(); 365 this.o2.aboutToBeDeleted(); 366 this.q2.aboutToBeDeleted(); 367 this.s2.aboutToBeDeleted(); 368 SubscriberManager.Get().delete(this.id__()); 369 this.aboutToBeDeletedInternal(); 370 } 371 372 get optionsArray() { 373 return this.n2.get(); 374 } 375 376 get options() { 377 return this.o2.get(); 378 } 379 380 get buttonBorderRadius() { 381 return this.q2.get(); 382 } 383 384 set buttonBorderRadius(newValue) { 385 this.q2.set(newValue); 386 } 387 388 get buttonItemsSize() { 389 return this.s2.get(); 390 } 391 392 set buttonItemsSize(newValue) { 393 this.s2.set(newValue); 394 } 395 396 initialRender() { 397 this.observeComponentCreation2((elmtId, isInitialRender) => { 398 Row.create({ space: 1 }); 399 Row.direction(this.options.direction); 400 Row.padding(this.options.m2); 401 }, Row); 402 this.observeComponentCreation2((elmtId, isInitialRender) => { 403 ForEach.create(); 404 const forEachItemGenFunction = (_item, index) => { 405 const r3 = _item; 406 this.observeComponentCreation2((elmtId, isInitialRender) => { 407 If.create(); 408 if (index < a1) { 409 this.ifElseBranchUpdateFunction(0, () => { 410 this.observeComponentCreation2((elmtId, isInitialRender) => { 411 Stack.create(); 412 Stack.direction(this.options.direction); 413 Stack.layoutWeight(1); 414 Stack.height(this.buttonItemsSize[index].height); 415 Stack.backgroundColor(this.options.backgroundColor ?? e1.BACKGROUND_COLOR); 416 Stack.borderRadius(this.buttonBorderRadius[index]); 417 Stack.backgroundBlurStyle(this.options.backgroundBlurStyle); 418 }, Stack); 419 Stack.pop(); 420 }); 421 } else { 422 this.ifElseBranchUpdateFunction(1, () => { 423 }); 424 } 425 }, If); 426 If.pop(); 427 }; 428 this.forEachUpdateFunction(elmtId, this.optionsArray, forEachItemGenFunction, undefined, true, false); 429 }, ForEach); 430 ForEach.pop(); 431 Row.pop(); 432 } 433 434 rerender() { 435 this.updateDirtyElements(); 436 } 437} 438 439class g1 extends ViewPU { 440 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 441 super(parent, __localStorage, elmtId, extraInfo); 442 if (typeof paramsLambda === "function") { 443 this.paramsGenerator_ = paramsLambda; 444 } 445 this.n2 = new SynchedPropertyNesedObjectPU(params.optionsArray, this, "optionsArray"); 446 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 447 this.t2 = new SynchedPropertyObjectTwoWayPU(params.selectedIndexes, this, "selectedIndexes"); 448 this.s2 = this.initializeConsume("buttonItemsSize", "buttonItemsSize"); 449 this.u2 = this.initializeConsume("selectedItemPosition", "selectedItemPosition"); 450 this.v2 = this.initializeConsume("zoomScaleArray", "zoomScaleArray"); 451 this.q2 = this.initializeConsume("buttonBorderRadius", "buttonBorderRadius"); 452 this.setInitiallyProvidedValue(params); 453 this.finalizeConstruction(); 454 } 455 456 setInitiallyProvidedValue(params) { 457 this.n2.set(params.optionsArray); 458 this.o2.set(params.options); 459 } 460 461 updateStateVars(params) { 462 this.n2.set(params.optionsArray); 463 this.o2.set(params.options); 464 } 465 466 purgeVariableDependenciesOnElmtId(rmElmtId) { 467 this.n2.purgeDependencyOnElmtId(rmElmtId); 468 this.o2.purgeDependencyOnElmtId(rmElmtId); 469 this.t2.purgeDependencyOnElmtId(rmElmtId); 470 this.s2.purgeDependencyOnElmtId(rmElmtId); 471 this.u2.purgeDependencyOnElmtId(rmElmtId); 472 this.v2.purgeDependencyOnElmtId(rmElmtId); 473 this.q2.purgeDependencyOnElmtId(rmElmtId); 474 } 475 476 aboutToBeDeleted() { 477 this.n2.aboutToBeDeleted(); 478 this.o2.aboutToBeDeleted(); 479 this.t2.aboutToBeDeleted(); 480 this.s2.aboutToBeDeleted(); 481 this.u2.aboutToBeDeleted(); 482 this.v2.aboutToBeDeleted(); 483 this.q2.aboutToBeDeleted(); 484 SubscriberManager.Get().delete(this.id__()); 485 this.aboutToBeDeletedInternal(); 486 } 487 488 get optionsArray() { 489 return this.n2.get(); 490 } 491 492 get options() { 493 return this.o2.get(); 494 } 495 496 get selectedIndexes() { 497 return this.t2.get(); 498 } 499 500 set selectedIndexes(newValue) { 501 this.t2.set(newValue); 502 } 503 504 get buttonItemsSize() { 505 return this.s2.get(); 506 } 507 508 set buttonItemsSize(newValue) { 509 this.s2.set(newValue); 510 } 511 512 get selectedItemPosition() { 513 return this.u2.get(); 514 } 515 516 set selectedItemPosition(newValue) { 517 this.u2.set(newValue); 518 } 519 520 get zoomScaleArray() { 521 return this.v2.get(); 522 } 523 524 set zoomScaleArray(newValue) { 525 this.v2.set(newValue); 526 } 527 528 get buttonBorderRadius() { 529 return this.q2.get(); 530 } 531 532 set buttonBorderRadius(newValue) { 533 this.q2.set(newValue); 534 } 535 536 initialRender() { 537 this.observeComponentCreation2((elmtId, isInitialRender) => { 538 If.create(); 539 if (this.selectedIndexes !== void 0 && this.selectedIndexes.length !== 0) { 540 this.ifElseBranchUpdateFunction(0, () => { 541 this.observeComponentCreation2((elmtId, isInitialRender) => { 542 Stack.create(); 543 Stack.direction(this.options.direction); 544 Stack.borderRadius(this.buttonBorderRadius[this.selectedIndexes[0]]); 545 Stack.size(this.buttonItemsSize[this.selectedIndexes[0]]); 546 Stack.backgroundColor(this.options.selectedBackgroundColor ?? 547 (this.options.type === 'tab' ? e1.w1 : 548 e1.z1)); 549 Stack.position(ObservedObject.GetRawObject(this.selectedItemPosition)); 550 Stack.scale({ 551 x: this.zoomScaleArray[this.selectedIndexes[0]], 552 y: this.zoomScaleArray[this.selectedIndexes[0]] 553 }); 554 Stack.shadow(ShadowStyle.OUTER_DEFAULT_XS); 555 }, Stack); 556 Stack.pop(); 557 }); 558 } else { 559 this.ifElseBranchUpdateFunction(1, () => { 560 }); 561 } 562 }, If); 563 If.pop(); 564 } 565 566 rerender() { 567 this.updateDirtyElements(); 568 } 569} 570 571class h1 extends ViewPU { 572 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 573 super(parent, __localStorage, elmtId, extraInfo); 574 if (typeof paramsLambda === "function") { 575 this.paramsGenerator_ = paramsLambda; 576 } 577 this.n2 = new SynchedPropertyNesedObjectPU(params.optionsArray, this, "optionsArray"); 578 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 579 this.t2 = new SynchedPropertyObjectTwoWayPU(params.selectedIndexes, this, "selectedIndexes"); 580 this.s2 = this.initializeConsume("buttonItemsSize", "buttonItemsSize"); 581 this.v2 = this.initializeConsume("zoomScaleArray", "zoomScaleArray"); 582 this.q2 = this.initializeConsume("buttonBorderRadius", "buttonBorderRadius"); 583 this.w2 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (q3, index) => Color.Transparent), this, 584 "multiColor"); 585 this.setInitiallyProvidedValue(params); 586 this.declareWatch("options", this.onOptionsChange); 587 this.declareWatch("selectedIndexes", this.onSelectedChange); 588 this.finalizeConstruction(); 589 } 590 591 setInitiallyProvidedValue(params) { 592 this.n2.set(params.optionsArray); 593 this.o2.set(params.options); 594 if (params.multiColor !== undefined) { 595 this.multiColor = params.multiColor; 596 } 597 } 598 599 updateStateVars(params) { 600 this.n2.set(params.optionsArray); 601 this.o2.set(params.options); 602 } 603 604 purgeVariableDependenciesOnElmtId(rmElmtId) { 605 this.n2.purgeDependencyOnElmtId(rmElmtId); 606 this.o2.purgeDependencyOnElmtId(rmElmtId); 607 this.t2.purgeDependencyOnElmtId(rmElmtId); 608 this.s2.purgeDependencyOnElmtId(rmElmtId); 609 this.v2.purgeDependencyOnElmtId(rmElmtId); 610 this.q2.purgeDependencyOnElmtId(rmElmtId); 611 this.w2.purgeDependencyOnElmtId(rmElmtId); 612 } 613 614 aboutToBeDeleted() { 615 this.n2.aboutToBeDeleted(); 616 this.o2.aboutToBeDeleted(); 617 this.t2.aboutToBeDeleted(); 618 this.s2.aboutToBeDeleted(); 619 this.v2.aboutToBeDeleted(); 620 this.q2.aboutToBeDeleted(); 621 this.w2.aboutToBeDeleted(); 622 SubscriberManager.Get().delete(this.id__()); 623 this.aboutToBeDeletedInternal(); 624 } 625 626 get optionsArray() { 627 return this.n2.get(); 628 } 629 630 get options() { 631 return this.o2.get(); 632 } 633 634 get selectedIndexes() { 635 return this.t2.get(); 636 } 637 638 set selectedIndexes(newValue) { 639 this.t2.set(newValue); 640 } 641 642 get buttonItemsSize() { 643 return this.s2.get(); 644 } 645 646 set buttonItemsSize(newValue) { 647 this.s2.set(newValue); 648 } 649 650 get zoomScaleArray() { 651 return this.v2.get(); 652 } 653 654 set zoomScaleArray(newValue) { 655 this.v2.set(newValue); 656 } 657 658 get buttonBorderRadius() { 659 return this.q2.get(); 660 } 661 662 set buttonBorderRadius(newValue) { 663 this.q2.set(newValue); 664 } 665 666 get multiColor() { 667 return this.w2.get(); 668 } 669 670 set multiColor(newValue) { 671 this.w2.set(newValue); 672 } 673 674 onOptionsChange() { 675 for (let p3 = 0; p3 < this.selectedIndexes.length; p3++) { 676 this.multiColor[this.selectedIndexes[p3]] = this.options.selectedBackgroundColor ?? 677 e1.z1; 678 } 679 } 680 681 onSelectedChange() { 682 for (let n3 = 0; n3 < a1; n3++) { 683 this.multiColor[n3] = Color.Transparent; 684 } 685 for (let m3 = 0; m3 < this.selectedIndexes.length; m3++) { 686 this.multiColor[this.selectedIndexes[m3]] = this.options.selectedBackgroundColor ?? 687 e1.z1; 688 } 689 } 690 691 aboutToAppear() { 692 for (let l3 = 0; l3 < this.selectedIndexes.length; l3++) { 693 this.multiColor[this.selectedIndexes[l3]] = this.options.selectedBackgroundColor ?? 694 e1.z1; 695 } 696 } 697 698 initialRender() { 699 this.observeComponentCreation2((elmtId, isInitialRender) => { 700 Row.create({ space: 1 }); 701 Row.direction(this.options.direction); 702 Row.padding(this.options.m2); 703 }, Row); 704 this.observeComponentCreation2((elmtId, isInitialRender) => { 705 ForEach.create(); 706 const forEachItemGenFunction = (_item, index) => { 707 const k3 = _item; 708 this.observeComponentCreation2((elmtId, isInitialRender) => { 709 If.create(); 710 if (index < a1) { 711 this.ifElseBranchUpdateFunction(0, () => { 712 this.observeComponentCreation2((elmtId, isInitialRender) => { 713 Stack.create(); 714 Stack.direction(this.options.direction); 715 Stack.width(this.buttonItemsSize[index].width); 716 Stack.height(this.buttonItemsSize[index].height); 717 Stack.backgroundColor(this.multiColor[index]); 718 Stack.borderRadius(this.buttonBorderRadius[index]); 719 }, Stack); 720 Stack.pop(); 721 }); 722 } else { 723 this.ifElseBranchUpdateFunction(1, () => { 724 }); 725 } 726 }, If); 727 If.pop(); 728 }; 729 this.forEachUpdateFunction(elmtId, this.optionsArray, forEachItemGenFunction, undefined, true, false); 730 }, ForEach); 731 ForEach.pop(); 732 Row.pop(); 733 } 734 735 rerender() { 736 this.updateDirtyElements(); 737 } 738} 739 740class i1 extends ViewPU { 741 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 742 super(parent, __localStorage, elmtId, extraInfo); 743 if (typeof paramsLambda === "function") { 744 this.paramsGenerator_ = paramsLambda; 745 } 746 this.t2 = new SynchedPropertyObjectTwoWayPU(params.selectedIndexes, this, "selectedIndexes"); 747 this.z2 = new SynchedPropertySimpleTwoWayPU(params.focusIndex, this, "focusIndex"); 748 this.b3 = new SynchedPropertyNesedObjectPU(params.itemOptions, this, "itemOptions"); 749 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 750 this.c3 = new SynchedPropertyNesedObjectPU(params.property, this, "property"); 751 this.d3 = new SynchedPropertySimpleOneWayPU(params.index, this, "index"); 752 this.groupId = ''; 753 this.setInitiallyProvidedValue(params); 754 this.finalizeConstruction(); 755 } 756 757 setInitiallyProvidedValue(params) { 758 this.b3.set(params.itemOptions); 759 this.o2.set(params.options); 760 this.c3.set(params.property); 761 if (params.groupId !== undefined) { 762 this.groupId = params.groupId; 763 } 764 } 765 766 updateStateVars(params) { 767 this.b3.set(params.itemOptions); 768 this.o2.set(params.options); 769 this.c3.set(params.property); 770 this.d3.reset(params.index); 771 } 772 773 purgeVariableDependenciesOnElmtId(rmElmtId) { 774 this.t2.purgeDependencyOnElmtId(rmElmtId); 775 this.z2.purgeDependencyOnElmtId(rmElmtId); 776 this.b3.purgeDependencyOnElmtId(rmElmtId); 777 this.o2.purgeDependencyOnElmtId(rmElmtId); 778 this.c3.purgeDependencyOnElmtId(rmElmtId); 779 this.d3.purgeDependencyOnElmtId(rmElmtId); 780 } 781 782 aboutToBeDeleted() { 783 this.t2.aboutToBeDeleted(); 784 this.z2.aboutToBeDeleted(); 785 this.b3.aboutToBeDeleted(); 786 this.o2.aboutToBeDeleted(); 787 this.c3.aboutToBeDeleted(); 788 this.d3.aboutToBeDeleted(); 789 SubscriberManager.Get().delete(this.id__()); 790 this.aboutToBeDeletedInternal(); 791 } 792 793 get selectedIndexes() { 794 return this.t2.get(); 795 } 796 797 set selectedIndexes(newValue) { 798 this.t2.set(newValue); 799 } 800 801 get focusIndex() { 802 return this.z2.get(); 803 } 804 805 set focusIndex(newValue) { 806 this.z2.set(newValue); 807 } 808 809 get itemOptions() { 810 return this.b3.get(); 811 } 812 813 get options() { 814 return this.o2.get(); 815 } 816 817 get property() { 818 return this.c3.get(); 819 } 820 821 get index() { 822 return this.d3.get(); 823 } 824 825 set index(newValue) { 826 this.d3.set(newValue); 827 } 828 829 getTextPadding() { 830 if (this.options.localizedTextPadding) { 831 return this.options.localizedTextPadding; 832 } 833 if (this.options.textPadding !== void (0)) { 834 return this.options.textPadding; 835 } 836 return 0; 837 } 838 839 getButtonPadding() { 840 if (this.options.localizedButtonPadding) { 841 return this.options.localizedButtonPadding; 842 } 843 if (this.options.buttonPadding !== void (0)) { 844 return this.options.buttonPadding; 845 } 846 if (this.options.type === 'capsule' && this.options.i2 && this.options.showIcon) { 847 return { 848 top: LengthMetrics.vp(6), 849 bottom: LengthMetrics.vp(6), 850 start: LengthMetrics.vp(8), 851 end: LengthMetrics.vp(8) 852 }; 853 } 854 return { 855 top: LengthMetrics.vp(4), 856 bottom: LengthMetrics.vp(4), 857 start: LengthMetrics.vp(8), 858 end: LengthMetrics.vp(8) 859 }; 860 } 861 862 getAccessibilityText() { 863 try { 864 if (this.selectedIndexes.includes(this.index) && this.itemOptions.selectedIconAccessibilityText) { 865 return (typeof this.itemOptions.selectedIconAccessibilityText === 'string') ? 866 this.itemOptions.selectedIconAccessibilityText : 867 getContext(this).resourceManager.getStringSync(this.itemOptions.selectedIconAccessibilityText.id); 868 } else if (this.itemOptions.iconAccessibilityText) { 869 return (typeof this.itemOptions.iconAccessibilityText === 'string') ? 870 this.itemOptions.iconAccessibilityText : 871 getContext(this).resourceManager.getStringSync(this.itemOptions.iconAccessibilityText.id); 872 } 873 } catch (error) { 874 console.error(`Ace SegmentButton getAccessibilityText, error: ${error.toString()}`); 875 } 876 return ''; 877 } 878 879 initialRender() { 880 this.observeComponentCreation2((elmtId, isInitialRender) => { 881 Column.create({ space: 2 }); 882 Column.direction(this.options.direction); 883 Column.focusScopePriority(this.groupId, 884 Math.min(...this.selectedIndexes) === this.index ? FocusPriority.PREVIOUS : FocusPriority.AUTO); 885 Column.justifyContent(FlexAlign.Center); 886 Column.padding(this.getButtonPadding()); 887 Column.constraintSize({ minHeight: 28 }); 888 }, Column); 889 this.observeComponentCreation2((elmtId, isInitialRender) => { 890 If.create(); 891 if (this.options.showIcon) { 892 this.ifElseBranchUpdateFunction(0, () => { 893 this.observeComponentCreation2((elmtId, isInitialRender) => { 894 Image.create(this.property.isSelected ? this.itemOptions.selectedIcon : this.itemOptions.icon); 895 Image.direction(this.options.direction); 896 Image.size(this.options.imageSize ?? { width: 24, height: 24 }); 897 Image.focusable(!this.options.i2); 898 Image.draggable(false); 899 Image.fillColor(this.property.isSelected ? (this.options.selectedFontColor ?? 900 e1.t1) : (this.options.fontColor ?? 901 e1.q1)); 902 Image.accessibilityText(this.getAccessibilityText()); 903 }, Image); 904 }); 905 } else { 906 this.ifElseBranchUpdateFunction(1, () => { 907 }); 908 } 909 }, If); 910 If.pop(); 911 this.observeComponentCreation2((elmtId, isInitialRender) => { 912 If.create(); 913 if (this.options.i2) { 914 this.ifElseBranchUpdateFunction(0, () => { 915 this.observeComponentCreation2((elmtId, isInitialRender) => { 916 Text.create(this.itemOptions.text); 917 Text.direction(this.options.direction); 918 Text.fontColor(this.property.fontColor); 919 Text.fontWeight(this.property.fontWeight); 920 Text.fontSize(this.property.fontSize); 921 Text.minFontSize(9); 922 Text.maxFontSize(this.property.fontSize); 923 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 924 Text.maxLines(1); 925 Text.textAlign(TextAlign.Center); 926 Text.focusable(true); 927 Text.padding(this.getTextPadding()); 928 }, Text); 929 Text.pop(); 930 }); 931 } else { 932 this.ifElseBranchUpdateFunction(1, () => { 933 }); 934 } 935 }, If); 936 If.pop(); 937 Column.pop(); 938 } 939 940 rerender() { 941 this.updateDirtyElements(); 942 } 943} 944 945let j1 = class HoverColorProperty { 946 constructor() { 947 this.e3 = Color.Transparent; 948 } 949}; 950j1 = j([ 951 Observed 952], j1); 953 954class l1 extends ViewPU { 955 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 956 super(parent, __localStorage, elmtId, extraInfo); 957 if (typeof paramsLambda === "function") { 958 this.paramsGenerator_ = paramsLambda; 959 } 960 this.s2 = this.initializeConsume("buttonItemsSize", "buttonItemsSize"); 961 this.f3 = new SynchedPropertySimpleOneWayPU(params.press, this, "press"); 962 this.g3 = new SynchedPropertySimpleOneWayPU(params.hover, this, "hover"); 963 this.h3 = new SynchedPropertyNesedObjectPU(params.colorProperty, this, "colorProperty"); 964 this.q2 = this.initializeConsume("buttonBorderRadius", "buttonBorderRadius"); 965 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 966 this.pressIndex = 0; 967 this.pressColor = e1.c2; 968 this.setInitiallyProvidedValue(params); 969 this.finalizeConstruction(); 970 } 971 972 setInitiallyProvidedValue(params) { 973 this.h3.set(params.colorProperty); 974 this.o2.set(params.options); 975 if (params.pressIndex !== undefined) { 976 this.pressIndex = params.pressIndex; 977 } 978 if (params.pressColor !== undefined) { 979 this.pressColor = params.pressColor; 980 } 981 } 982 983 updateStateVars(params) { 984 this.f3.reset(params.press); 985 this.g3.reset(params.hover); 986 this.h3.set(params.colorProperty); 987 this.o2.set(params.options); 988 } 989 990 purgeVariableDependenciesOnElmtId(rmElmtId) { 991 this.s2.purgeDependencyOnElmtId(rmElmtId); 992 this.f3.purgeDependencyOnElmtId(rmElmtId); 993 this.g3.purgeDependencyOnElmtId(rmElmtId); 994 this.h3.purgeDependencyOnElmtId(rmElmtId); 995 this.q2.purgeDependencyOnElmtId(rmElmtId); 996 this.o2.purgeDependencyOnElmtId(rmElmtId); 997 } 998 999 aboutToBeDeleted() { 1000 this.s2.aboutToBeDeleted(); 1001 this.f3.aboutToBeDeleted(); 1002 this.g3.aboutToBeDeleted(); 1003 this.h3.aboutToBeDeleted(); 1004 this.q2.aboutToBeDeleted(); 1005 this.o2.aboutToBeDeleted(); 1006 SubscriberManager.Get().delete(this.id__()); 1007 this.aboutToBeDeletedInternal(); 1008 } 1009 1010 get buttonItemsSize() { 1011 return this.s2.get(); 1012 } 1013 1014 set buttonItemsSize(newValue) { 1015 this.s2.set(newValue); 1016 } 1017 1018 get press() { 1019 return this.f3.get(); 1020 } 1021 1022 set press(newValue) { 1023 this.f3.set(newValue); 1024 } 1025 1026 get hover() { 1027 return this.g3.get(); 1028 } 1029 1030 set hover(newValue) { 1031 this.g3.set(newValue); 1032 } 1033 1034 get colorProperty() { 1035 return this.h3.get(); 1036 } 1037 1038 get buttonBorderRadius() { 1039 return this.q2.get(); 1040 } 1041 1042 set buttonBorderRadius(newValue) { 1043 this.q2.set(newValue); 1044 } 1045 1046 get options() { 1047 return this.o2.get(); 1048 } 1049 1050 initialRender() { 1051 this.observeComponentCreation2((elmtId, isInitialRender) => { 1052 Stack.create(); 1053 Stack.direction(this.options.direction); 1054 Stack.size(this.buttonItemsSize[this.pressIndex]); 1055 Stack.backgroundColor(this.press && this.hover ? this.pressColor : this.colorProperty.e3); 1056 Stack.borderRadius(this.buttonBorderRadius[this.pressIndex]); 1057 }, Stack); 1058 Stack.pop(); 1059 } 1060 1061 rerender() { 1062 this.updateDirtyElements(); 1063 } 1064} 1065 1066class m1 extends ViewPU { 1067 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 1068 super(parent, __localStorage, elmtId, extraInfo); 1069 if (typeof paramsLambda === "function") { 1070 this.paramsGenerator_ = paramsLambda; 1071 } 1072 this.n2 = new SynchedPropertyNesedObjectPU(params.optionsArray, this, "optionsArray"); 1073 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 1074 this.t2 = new SynchedPropertyObjectTwoWayPU(params.selectedIndexes, this, "selectedIndexes"); 1075 this.i3 = this.initializeConsume("componentSize", "componentSize"); 1076 this.q2 = this.initializeConsume("buttonBorderRadius", "buttonBorderRadius"); 1077 this.s2 = this.initializeConsume("buttonItemsSize", "buttonItemsSize"); 1078 this.j3 = this.initializeConsume("buttonItemsPosition", "buttonItemsPosition"); 1079 this.z2 = this.initializeConsume("focusIndex", "focusIndex"); 1080 this.v2 = this.initializeConsume("zoomScaleArray", "zoomScaleArray"); 1081 this.l3 = this.initializeConsume("buttonItemProperty", "buttonItemProperty"); 1082 this.m3 = this.initializeConsume("buttonItemsSelected", "buttonItemsSelected"); 1083 this.n3 = new SynchedPropertyObjectTwoWayPU(params.pressArray, this, "pressArray"); 1084 this.q3 = new SynchedPropertyObjectTwoWayPU(params.hoverArray, this, "hoverArray"); 1085 this.r3 = new SynchedPropertyObjectTwoWayPU(params.hoverColorArray, this, "hoverColorArray"); 1086 this.s3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (j3, index) => 0), this, "buttonWidth"); 1087 this.t3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (i3, index) => 0), this, "buttonHeight"); 1088 this.buttonItemsRealHeight = Array.from({ length: a1 }, (h3, index) => 0); 1089 this.groupId = util.generateRandomUUID(true); 1090 this.setInitiallyProvidedValue(params); 1091 this.declareWatch("optionsArray", this.onOptionsArrayChange); 1092 this.declareWatch("options", this.onOptionsChange); 1093 this.declareWatch("buttonItemsSize", this.onButtonItemsSizeChange); 1094 this.finalizeConstruction(); 1095 } 1096 1097 setInitiallyProvidedValue(params) { 1098 this.n2.set(params.optionsArray); 1099 this.o2.set(params.options); 1100 if (params.buttonWidth !== undefined) { 1101 this.buttonWidth = params.buttonWidth; 1102 } 1103 if (params.buttonHeight !== undefined) { 1104 this.buttonHeight = params.buttonHeight; 1105 } 1106 if (params.buttonItemsRealHeight !== undefined) { 1107 this.buttonItemsRealHeight = params.buttonItemsRealHeight; 1108 } 1109 if (params.groupId !== undefined) { 1110 this.groupId = params.groupId; 1111 } 1112 } 1113 1114 updateStateVars(params) { 1115 this.n2.set(params.optionsArray); 1116 this.o2.set(params.options); 1117 } 1118 1119 purgeVariableDependenciesOnElmtId(rmElmtId) { 1120 this.n2.purgeDependencyOnElmtId(rmElmtId); 1121 this.o2.purgeDependencyOnElmtId(rmElmtId); 1122 this.t2.purgeDependencyOnElmtId(rmElmtId); 1123 this.i3.purgeDependencyOnElmtId(rmElmtId); 1124 this.q2.purgeDependencyOnElmtId(rmElmtId); 1125 this.s2.purgeDependencyOnElmtId(rmElmtId); 1126 this.j3.purgeDependencyOnElmtId(rmElmtId); 1127 this.z2.purgeDependencyOnElmtId(rmElmtId); 1128 this.v2.purgeDependencyOnElmtId(rmElmtId); 1129 this.l3.purgeDependencyOnElmtId(rmElmtId); 1130 this.m3.purgeDependencyOnElmtId(rmElmtId); 1131 this.n3.purgeDependencyOnElmtId(rmElmtId); 1132 this.q3.purgeDependencyOnElmtId(rmElmtId); 1133 this.r3.purgeDependencyOnElmtId(rmElmtId); 1134 this.s3.purgeDependencyOnElmtId(rmElmtId); 1135 this.t3.purgeDependencyOnElmtId(rmElmtId); 1136 } 1137 1138 aboutToBeDeleted() { 1139 this.n2.aboutToBeDeleted(); 1140 this.o2.aboutToBeDeleted(); 1141 this.t2.aboutToBeDeleted(); 1142 this.i3.aboutToBeDeleted(); 1143 this.q2.aboutToBeDeleted(); 1144 this.s2.aboutToBeDeleted(); 1145 this.j3.aboutToBeDeleted(); 1146 this.z2.aboutToBeDeleted(); 1147 this.v2.aboutToBeDeleted(); 1148 this.l3.aboutToBeDeleted(); 1149 this.m3.aboutToBeDeleted(); 1150 this.n3.aboutToBeDeleted(); 1151 this.q3.aboutToBeDeleted(); 1152 this.r3.aboutToBeDeleted(); 1153 this.s3.aboutToBeDeleted(); 1154 this.t3.aboutToBeDeleted(); 1155 SubscriberManager.Get().delete(this.id__()); 1156 this.aboutToBeDeletedInternal(); 1157 } 1158 1159 get optionsArray() { 1160 return this.n2.get(); 1161 } 1162 1163 get options() { 1164 return this.o2.get(); 1165 } 1166 1167 get selectedIndexes() { 1168 return this.t2.get(); 1169 } 1170 1171 set selectedIndexes(newValue) { 1172 this.t2.set(newValue); 1173 } 1174 1175 get componentSize() { 1176 return this.i3.get(); 1177 } 1178 1179 set componentSize(newValue) { 1180 this.i3.set(newValue); 1181 } 1182 1183 get buttonBorderRadius() { 1184 return this.q2.get(); 1185 } 1186 1187 set buttonBorderRadius(newValue) { 1188 this.q2.set(newValue); 1189 } 1190 1191 get buttonItemsSize() { 1192 return this.s2.get(); 1193 } 1194 1195 set buttonItemsSize(newValue) { 1196 this.s2.set(newValue); 1197 } 1198 1199 get buttonItemsPosition() { 1200 return this.j3.get(); 1201 } 1202 1203 set buttonItemsPosition(newValue) { 1204 this.j3.set(newValue); 1205 } 1206 1207 get focusIndex() { 1208 return this.z2.get(); 1209 } 1210 1211 set focusIndex(newValue) { 1212 this.z2.set(newValue); 1213 } 1214 1215 get zoomScaleArray() { 1216 return this.v2.get(); 1217 } 1218 1219 set zoomScaleArray(newValue) { 1220 this.v2.set(newValue); 1221 } 1222 1223 get buttonItemProperty() { 1224 return this.l3.get(); 1225 } 1226 1227 set buttonItemProperty(newValue) { 1228 this.l3.set(newValue); 1229 } 1230 1231 get buttonItemsSelected() { 1232 return this.m3.get(); 1233 } 1234 1235 set buttonItemsSelected(newValue) { 1236 this.m3.set(newValue); 1237 } 1238 1239 get pressArray() { 1240 return this.n3.get(); 1241 } 1242 1243 set pressArray(newValue) { 1244 this.n3.set(newValue); 1245 } 1246 1247 get hoverArray() { 1248 return this.q3.get(); 1249 } 1250 1251 set hoverArray(newValue) { 1252 this.q3.set(newValue); 1253 } 1254 1255 get hoverColorArray() { 1256 return this.r3.get(); 1257 } 1258 1259 set hoverColorArray(newValue) { 1260 this.r3.set(newValue); 1261 } 1262 1263 get buttonWidth() { 1264 return this.s3.get(); 1265 } 1266 1267 set buttonWidth(newValue) { 1268 this.s3.set(newValue); 1269 } 1270 1271 get buttonHeight() { 1272 return this.t3.get(); 1273 } 1274 1275 set buttonHeight(newValue) { 1276 this.t3.set(newValue); 1277 } 1278 1279 onButtonItemsSizeChange() { 1280 this.buttonItemsSize.forEach((value, index) => { 1281 this.buttonWidth[index] = value.width; 1282 this.buttonHeight[index] = value.height; 1283 }); 1284 } 1285 1286 changeSelectedIndexes(c3) { 1287 if (this.optionsArray.e2 === void 0 || this.optionsArray.deleteCount === void 0 || 1288 this.optionsArray.f2 === void 0) { 1289 return; 1290 } 1291 if (!(this.options.multiply ?? false)) { 1292 if (this.selectedIndexes[0] === void 0) { 1293 return; 1294 } 1295 if (this.selectedIndexes[0] < this.optionsArray.e2) { 1296 return; 1297 } 1298 if (this.optionsArray.e2 + this.optionsArray.deleteCount > this.selectedIndexes[0]) { 1299 if (this.options.type === 'tab') { 1300 this.selectedIndexes[0] = 0; 1301 } else if (this.options.type === 'capsule') { 1302 this.selectedIndexes = []; 1303 } 1304 } else { 1305 this.selectedIndexes[0] = 1306 this.selectedIndexes[0] - this.optionsArray.deleteCount + this.optionsArray.f2; 1307 } 1308 } else { 1309 let d3 = this.selectedIndexes; 1310 for (let f3 = 0; f3 < this.optionsArray.deleteCount; f3++) { 1311 let g3 = d3.indexOf(this.optionsArray.e2); 1312 let indexes = d3.map(value => this.optionsArray.e2 && 1313 (value > this.optionsArray.e2) ? value - 1 : value); 1314 if (g3 !== -1) { 1315 indexes.splice(g3, 1); 1316 } 1317 d3 = indexes; 1318 } 1319 for (let e3 = 0; e3 < this.optionsArray.f2; e3++) { 1320 let indexes = d3.map(value => this.optionsArray.e2 && 1321 (value >= this.optionsArray.e2) ? value + 1 : value); 1322 d3 = indexes; 1323 } 1324 this.selectedIndexes = d3; 1325 } 1326 } 1327 1328 changeFocusIndex(b3) { 1329 if (this.optionsArray.e2 === void 0 || this.optionsArray.deleteCount === void 0 || 1330 this.optionsArray.f2 === void 0) { 1331 return; 1332 } 1333 if (this.focusIndex === -1) { 1334 return; 1335 } 1336 if (this.focusIndex < this.optionsArray.e2) { 1337 return; 1338 } 1339 if (this.optionsArray.e2 + this.optionsArray.deleteCount > this.focusIndex) { 1340 this.focusIndex = 0; 1341 } else { 1342 this.focusIndex = this.focusIndex - this.optionsArray.deleteCount + this.optionsArray.f2; 1343 } 1344 } 1345 1346 onOptionsArrayChange() { 1347 if (this.options === void 0 || this.options.buttons === void 0) { 1348 return; 1349 } 1350 let a3 = Math.min(this.options.buttons.length, this.buttonItemsSize.length); 1351 if (this.optionsArray.e2 !== void 0 && this.optionsArray.deleteCount !== void 0 && 1352 this.optionsArray.f2 !== void 0) { 1353 this.changeSelectedIndexes(a3); 1354 this.changeFocusIndex(a3); 1355 this.optionsArray.e2 = void 0; 1356 this.optionsArray.deleteCount = void 0; 1357 this.optionsArray.f2 = void 0; 1358 } 1359 } 1360 1361 onOptionsChange() { 1362 if (this.options === void 0 || this.options.buttons === void 0) { 1363 return; 1364 } 1365 this.calculateBorderRadius(); 1366 } 1367 1368 aboutToAppear() { 1369 for (let index = 0; index < this.buttonItemsRealHeight.length; index++) { 1370 this.buttonItemsRealHeight[index] = 0; 1371 } 1372 } 1373 1374 getBorderRadius(index) { 1375 let borderRadius = this.buttonBorderRadius[index]; 1376 if (this.options.type === 'capsule' && this.buttonItemsSelected[this.focusIndex]) { 1377 borderRadius.topStart = LengthMetrics.vp((borderRadius.topStart?.value ?? 0) + 4); 1378 borderRadius.topEnd = LengthMetrics.vp((borderRadius.topEnd?.value ?? 0) + 4); 1379 borderRadius.bottomStart = LengthMetrics.vp((borderRadius.bottomStart?.value ?? 0) + 4); 1380 borderRadius.bottomEnd = LengthMetrics.vp((borderRadius.bottomEnd?.value ?? 0) + 4); 1381 } 1382 return borderRadius; 1383 } 1384 1385 focusStack(index, parent = null) { 1386 this.observeComponentCreation2((elmtId, isInitialRender) => { 1387 Stack.create(); 1388 Stack.direction(this.options.direction); 1389 Stack.size({ width: 1, height: 1 }); 1390 Stack.align(Alignment.Center); 1391 }, Stack); 1392 this.observeComponentCreation2((elmtId, isInitialRender) => { 1393 Stack.create(); 1394 Stack.direction(this.options.direction); 1395 Stack.borderRadius(this.getBorderRadius(index)); 1396 Stack.size({ 1397 width: this.options.type === 'capsule' && this.buttonItemsSelected[this.focusIndex] ? 1398 this.buttonWidth[index] + 8 : this.buttonWidth[index], 1399 height: this.options.type === 'capsule' && this.buttonItemsSelected[this.focusIndex] ? 1400 this.buttonHeight[index] + 8 : this.buttonHeight[index] 1401 }); 1402 Stack.borderColor(e1.a2); 1403 Stack.borderWidth(2); 1404 }, Stack); 1405 Stack.pop(); 1406 Stack.pop(); 1407 } 1408 1409 calculateBorderRadius() { 1410 let v2 = Array.from({ 1411 length: a1 1412 }, (z2, index) => { 1413 return { 1414 topStart: LengthMetrics.vp(0), 1415 topEnd: LengthMetrics.vp(0), 1416 bottomStart: LengthMetrics.vp(0), 1417 bottomEnd: LengthMetrics.vp(0) 1418 }; 1419 }); 1420 for (let index = 0; index < this.buttonBorderRadius.length; index++) { 1421 let w2 = this.buttonItemsSize[index].height / 2; 1422 if (this.options.type === 'tab' || !(this.options.multiply ?? false)) { 1423 v2[index].topStart = LengthMetrics.vp(this.options.j2 ?? w2); 1424 v2[index].topEnd = LengthMetrics.vp(this.options.j2 ?? w2); 1425 v2[index].bottomStart = LengthMetrics.vp(this.options.j2 ?? w2); 1426 v2[index].bottomEnd = LengthMetrics.vp(this.options.j2 ?? w2); 1427 } else { 1428 if (index === 0) { 1429 v2[index].topStart = LengthMetrics.vp(this.options.j2 ?? w2); 1430 v2[index].topEnd = LengthMetrics.vp(0); 1431 v2[index].bottomStart = LengthMetrics.vp(this.options.j2 ?? w2); 1432 v2[index].bottomEnd = LengthMetrics.vp(0); 1433 } else if (this.options.buttons && 1434 index === Math.min(this.options.buttons.length, this.buttonItemsSize.length) - 1) { 1435 v2[index].topStart = LengthMetrics.vp(0); 1436 v2[index].topEnd = LengthMetrics.vp(this.options.j2 ?? w2); 1437 v2[index].bottomStart = LengthMetrics.vp(0); 1438 v2[index].bottomEnd = LengthMetrics.vp(this.options.j2 ?? w2); 1439 } else { 1440 v2[index].topStart = LengthMetrics.vp(0); 1441 v2[index].topEnd = LengthMetrics.vp(0); 1442 v2[index].bottomStart = LengthMetrics.vp(0); 1443 v2[index].bottomEnd = LengthMetrics.vp(0); 1444 } 1445 } 1446 } 1447 this.buttonBorderRadius = v2; 1448 } 1449 1450 getAccessibilityDescription(value) { 1451 if (value) { 1452 try { 1453 return (typeof value === 'string') ? value : 1454 getContext(this).resourceManager.getStringSync(value.id); 1455 } catch (error) { 1456 console.error(`Ace SegmentButton getAccessibilityDescription, error: ${error.toString()}`); 1457 } 1458 } 1459 return ''; 1460 } 1461 1462 initialRender() { 1463 this.observeComponentCreation2((elmtId, isInitialRender) => { 1464 If.create(); 1465 if (this.optionsArray !== void 0 && this.optionsArray.length > 1) { 1466 this.ifElseBranchUpdateFunction(0, () => { 1467 this.observeComponentCreation2((elmtId, isInitialRender) => { 1468 Row.create({ space: 1 }); 1469 Row.direction(this.options.direction); 1470 Row.focusScopeId(this.groupId, true); 1471 Row.padding(this.options.m2); 1472 Row.onSizeChange((u2, newValue) => { 1473 this.componentSize = { width: newValue.width, height: newValue.height }; 1474 }); 1475 }, Row); 1476 this.observeComponentCreation2((elmtId, isInitialRender) => { 1477 ForEach.create(); 1478 const forEachItemGenFunction = (_item, index) => { 1479 const item = _item; 1480 this.observeComponentCreation2((elmtId, isInitialRender) => { 1481 If.create(); 1482 if (index < a1) { 1483 this.ifElseBranchUpdateFunction(0, () => { 1484 this.observeComponentCreation2((elmtId, isInitialRender) => { 1485 Button.createWithChild(); 1486 Button.type(ButtonType.Normal); 1487 Button.stateEffect(false); 1488 Button.hoverEffect(HoverEffect.None); 1489 Button.backgroundColor(Color.Transparent); 1490 Button.accessibilityLevel(item.accessibilityLevel); 1491 Button.accessibilitySelected(this.options.multiply ? undefined : 1492 this.selectedIndexes.includes(index)); 1493 Button.accessibilityChecked(this.options.multiply ? 1494 this.selectedIndexes.includes(index) : undefined); 1495 Button.accessibilityDescription(this.getAccessibilityDescription(item.accessibilityDescription)); 1496 Button.direction(this.options.direction); 1497 Button.borderRadius(this.buttonBorderRadius[index]); 1498 Button.scale({ 1499 x: this.options.type === 'capsule' && (this.options.multiply ?? false) ? 1500 1 : this.zoomScaleArray[index], 1501 y: this.options.type === 'capsule' && (this.options.multiply ?? false) ? 1502 1 : this.zoomScaleArray[index] 1503 }); 1504 Button.layoutWeight(1); 1505 Button.padding(0); 1506 Button.onSizeChange((t2, newValue) => { 1507 this.buttonItemsSize[index] = { 1508 width: newValue.width, 1509 height: this.buttonItemsSize[index].height 1510 }; 1511 if (newValue.width) { 1512 this.buttonItemsPosition[index] = { 1513 start: LengthMetrics.vp(Number.parseFloat(this.options.m2.toString()) + 1514 (Number.parseFloat(newValue.width.toString()) + 1) * index), 1515 top: LengthMetrics.px(Math.floor(this.getUIContext() 1516 .vp2px(Number.parseFloat(this.options.m2.toString())))) 1517 }; 1518 } 1519 }); 1520 ViewStackProcessor.visualState("normal"); 1521 Button.overlay(undefined); 1522 ViewStackProcessor.visualState("focused"); 1523 Button.overlay({ 1524 builder: () => { 1525 this.focusStack.call(this, index); 1526 } 1527 }, { 1528 align: Alignment.Center 1529 }); 1530 ViewStackProcessor.visualState(); 1531 Button.onFocus(() => { 1532 this.focusIndex = index; 1533 }); 1534 Gesture.create(GesturePriority.Low); 1535 TapGesture.create(); 1536 TapGesture.onAction(() => { 1537 if (this.options.type === 'capsule' && 1538 (this.options.multiply ?? false)) { 1539 if (this.selectedIndexes.indexOf(index) === -1) { 1540 this.selectedIndexes.push(index); 1541 } else { 1542 this.selectedIndexes.splice(this.selectedIndexes.indexOf(index), 1543 1); 1544 } 1545 } else { 1546 this.selectedIndexes[0] = index; 1547 } 1548 }); 1549 TapGesture.pop(); 1550 Gesture.pop(); 1551 Button.onTouch((event) => { 1552 if (event.source !== SourceType.TouchScreen) { 1553 return; 1554 } 1555 if (event.type === TouchType.Down) { 1556 Context.animateTo({ 1557 curve: curves.interpolatingSpring(10, 1, 410, 38) 1558 }, () => { 1559 this.zoomScaleArray[index] = 0.95; 1560 }); 1561 } else if (event.type === TouchType.Up) { 1562 Context.animateTo({ 1563 curve: curves.interpolatingSpring(10, 1, 410, 38) 1564 }, () => { 1565 this.zoomScaleArray[index] = 1; 1566 }); 1567 } 1568 }); 1569 Button.onHover((isHover) => { 1570 this.hoverArray[index] = isHover; 1571 if (isHover) { 1572 Context.animateTo({ duration: 250, curve: Curve.Friction }, () => { 1573 this.hoverColorArray[index].e3 = (e1.b2); 1574 }); 1575 } else { 1576 Context.animateTo({ duration: 250, curve: Curve.Friction }, () => { 1577 this.hoverColorArray[index].e3 = Color.Transparent; 1578 }); 1579 } 1580 }); 1581 Button.onMouse((event) => { 1582 switch (event.action) { 1583 case MouseAction.Press: 1584 Context.animateTo({ curve: curves.springMotion(0.347, 0.99) }, 1585 () => { 1586 this.zoomScaleArray[index] = 0.95; 1587 }); 1588 Context.animateTo({ duration: 100, curve: Curve.Sharp }, () => { 1589 this.pressArray[index] = true; 1590 }); 1591 break; 1592 case MouseAction.Release: 1593 Context.animateTo({ curve: curves.springMotion(0.347, 0.99) }, 1594 () => { 1595 this.zoomScaleArray[index] = 1; 1596 }); 1597 Context.animateTo({ duration: 100, curve: Curve.Sharp }, () => { 1598 this.pressArray[index] = false; 1599 }); 1600 break; 1601 } 1602 }); 1603 }, Button); 1604 this.observeComponentCreation2((elmtId, isInitialRender) => { 1605 __Common__.create(); 1606 __Common__.onSizeChange((s2, newValue) => { 1607 this.buttonItemsRealHeight[index] = newValue.height; 1608 let maxHeight = Math.max(...this.buttonItemsRealHeight.slice(0, 1609 this.options.buttons ? 1610 this.options.buttons.length : 0)); 1611 for (let index = 0; index < this.buttonItemsSize.length; index++) { 1612 this.buttonItemsSize[index] = 1613 { width: this.buttonItemsSize[index].width, height: maxHeight }; 1614 } 1615 this.calculateBorderRadius(); 1616 }); 1617 }, __Common__); 1618 { 1619 this.observeComponentCreation2((elmtId, isInitialRender) => { 1620 if (isInitialRender) { 1621 let componentCall = new i1(this, { 1622 selectedIndexes: this.t2, 1623 focusIndex: this.z2, 1624 index: index, 1625 itemOptions: item, 1626 options: this.options, 1627 property: this.buttonItemProperty[index], 1628 groupId: this.groupId 1629 }, undefined, elmtId, () => { 1630 }, { 1631 page: "segmentbutton/src/main/ets/components/MainPage.ets", 1632 line: 811, 1633 u3: 15 1634 }); 1635 ViewPU.create(componentCall); 1636 let paramsLambda = () => { 1637 return { 1638 selectedIndexes: this.selectedIndexes, 1639 focusIndex: this.focusIndex, 1640 index: index, 1641 itemOptions: item, 1642 options: this.options, 1643 property: this.buttonItemProperty[index], 1644 groupId: this.groupId 1645 }; 1646 }; 1647 componentCall.paramsGenerator_ = paramsLambda; 1648 } else { 1649 this.updateStateVarsOfChildByElmtId(elmtId, { 1650 index: index, 1651 itemOptions: item, 1652 options: this.options, 1653 property: this.buttonItemProperty[index] 1654 }); 1655 } 1656 }, { name: "SegmentButtonItem" }); 1657 } 1658 __Common__.pop(); 1659 Button.pop(); 1660 }); 1661 } else { 1662 this.ifElseBranchUpdateFunction(1, () => { 1663 }); 1664 } 1665 }, If); 1666 If.pop(); 1667 }; 1668 this.forEachUpdateFunction(elmtId, this.optionsArray, forEachItemGenFunction, undefined, true, 1669 false); 1670 }, ForEach); 1671 ForEach.pop(); 1672 Row.pop(); 1673 }); 1674 } else { 1675 this.ifElseBranchUpdateFunction(1, () => { 1676 }); 1677 } 1678 }, If); 1679 If.pop(); 1680 } 1681 1682 rerender() { 1683 this.updateDirtyElements(); 1684 } 1685} 1686 1687let n1 = class ItemProperty { 1688 constructor() { 1689 this.fontColor = e1.q1; 1690 this.fontSize = e1.u1; 1691 this.fontWeight = FontWeight.Regular; 1692 this.isSelected = false; 1693 } 1694}; 1695n1 = j([ 1696 Observed 1697], n1); 1698 1699export class SegmentButton extends ViewPU { 1700 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 1701 super(parent, __localStorage, elmtId, extraInfo); 1702 if (typeof paramsLambda === "function") { 1703 this.paramsGenerator_ = paramsLambda; 1704 } 1705 this.o2 = new SynchedPropertyNesedObjectPU(params.options, this, "options"); 1706 this.t2 = new SynchedPropertyObjectTwoWayPU(params.selectedIndexes, this, "selectedIndexes"); 1707 this.onItemClicked = undefined; 1708 this.i3 = new ObservedPropertyObjectPU({ width: 0, height: 0 }, this, "componentSize"); 1709 this.addProvidedVar("componentSize", this.i3, false); 1710 this.q2 = new ObservedPropertyObjectPU(Array.from({ 1711 length: a1 1712 }, (r2, index) => { 1713 return { 1714 topStart: LengthMetrics.vp(0), 1715 topEnd: LengthMetrics.vp(0), 1716 bottomStart: LengthMetrics.vp(0), 1717 bottomEnd: LengthMetrics.vp(0) 1718 }; 1719 }), this, "buttonBorderRadius"); 1720 this.addProvidedVar("buttonBorderRadius", this.q2, false); 1721 this.s2 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (q2, index) => { 1722 return {}; 1723 }), this, "buttonItemsSize"); 1724 this.addProvidedVar("buttonItemsSize", this.s2, false); 1725 this.j3 = new ObservedPropertyObjectPU(Array.from({ 1726 length: a1 1727 }, (o2, index) => { 1728 return {}; 1729 }), this, "buttonItemsPosition"); 1730 this.addProvidedVar("buttonItemsPosition", this.j3, false); 1731 this.m3 = 1732 new ObservedPropertyObjectPU(Array.from({ length: a1 }, (n2, index) => false), this, "buttonItemsSelected"); 1733 this.addProvidedVar("buttonItemsSelected", this.m3, false); 1734 this.l3 = new ObservedPropertyObjectPU(Array.from({ 1735 length: a1 1736 }, (m2, index) => new n1()), this, "buttonItemProperty"); 1737 this.addProvidedVar("buttonItemProperty", this.l3, false); 1738 this.z2 = new ObservedPropertySimplePU(-1, this, "focusIndex"); 1739 this.addProvidedVar("focusIndex", this.z2, false); 1740 this.u2 = new ObservedPropertyObjectPU({}, this, "selectedItemPosition"); 1741 this.addProvidedVar("selectedItemPosition", this.u2, false); 1742 this.v2 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (l2, index) => 1.0), this, "zoomScaleArray"); 1743 this.addProvidedVar("zoomScaleArray", this.v2, false); 1744 this.n3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (k2, index) => false), this, "pressArray"); 1745 this.q3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (j2, index) => false), this, "hoverArray"); 1746 this.r3 = new ObservedPropertyObjectPU(Array.from({ 1747 length: a1 1748 }, (i2, index) => new j1()), this, "hoverColorArray"); 1749 this.doSelectedChangeAnimate = false; 1750 this.isCurrentPositionSelected = false; 1751 this.panGestureStartPoint = { x: 0, y: 0 }; 1752 this.isPanGestureMoved = false; 1753 this.v3 = new ObservedPropertySimplePU(false, this, "shouldMirror"); 1754 this.setInitiallyProvidedValue(params); 1755 this.declareWatch("options", this.onOptionsChange); 1756 this.declareWatch("selectedIndexes", this.onSelectedChange); 1757 this.declareWatch("buttonItemsPosition", this.onItemsPositionChange); 1758 this.finalizeConstruction(); 1759 } 1760 1761 setInitiallyProvidedValue(params) { 1762 this.o2.set(params.options); 1763 if (params.onItemClicked !== undefined) { 1764 this.onItemClicked = params.onItemClicked; 1765 } 1766 if (params.componentSize !== undefined) { 1767 this.componentSize = params.componentSize; 1768 } 1769 if (params.buttonBorderRadius !== undefined) { 1770 this.buttonBorderRadius = params.buttonBorderRadius; 1771 } 1772 if (params.buttonItemsSize !== undefined) { 1773 this.buttonItemsSize = params.buttonItemsSize; 1774 } 1775 if (params.buttonItemsPosition !== undefined) { 1776 this.buttonItemsPosition = params.buttonItemsPosition; 1777 } 1778 if (params.buttonItemsSelected !== undefined) { 1779 this.buttonItemsSelected = params.buttonItemsSelected; 1780 } 1781 if (params.buttonItemProperty !== undefined) { 1782 this.buttonItemProperty = params.buttonItemProperty; 1783 } 1784 if (params.focusIndex !== undefined) { 1785 this.focusIndex = params.focusIndex; 1786 } 1787 if (params.selectedItemPosition !== undefined) { 1788 this.selectedItemPosition = params.selectedItemPosition; 1789 } 1790 if (params.zoomScaleArray !== undefined) { 1791 this.zoomScaleArray = params.zoomScaleArray; 1792 } 1793 if (params.pressArray !== undefined) { 1794 this.pressArray = params.pressArray; 1795 } 1796 if (params.hoverArray !== undefined) { 1797 this.hoverArray = params.hoverArray; 1798 } 1799 if (params.hoverColorArray !== undefined) { 1800 this.hoverColorArray = params.hoverColorArray; 1801 } 1802 if (params.doSelectedChangeAnimate !== undefined) { 1803 this.doSelectedChangeAnimate = params.doSelectedChangeAnimate; 1804 } 1805 if (params.isCurrentPositionSelected !== undefined) { 1806 this.isCurrentPositionSelected = params.isCurrentPositionSelected; 1807 } 1808 if (params.panGestureStartPoint !== undefined) { 1809 this.panGestureStartPoint = params.panGestureStartPoint; 1810 } 1811 if (params.isPanGestureMoved !== undefined) { 1812 this.isPanGestureMoved = params.isPanGestureMoved; 1813 } 1814 if (params.shouldMirror !== undefined) { 1815 this.shouldMirror = params.shouldMirror; 1816 } 1817 } 1818 1819 updateStateVars(params) { 1820 this.o2.set(params.options); 1821 } 1822 1823 purgeVariableDependenciesOnElmtId(rmElmtId) { 1824 this.o2.purgeDependencyOnElmtId(rmElmtId); 1825 this.t2.purgeDependencyOnElmtId(rmElmtId); 1826 this.i3.purgeDependencyOnElmtId(rmElmtId); 1827 this.q2.purgeDependencyOnElmtId(rmElmtId); 1828 this.s2.purgeDependencyOnElmtId(rmElmtId); 1829 this.j3.purgeDependencyOnElmtId(rmElmtId); 1830 this.m3.purgeDependencyOnElmtId(rmElmtId); 1831 this.l3.purgeDependencyOnElmtId(rmElmtId); 1832 this.z2.purgeDependencyOnElmtId(rmElmtId); 1833 this.u2.purgeDependencyOnElmtId(rmElmtId); 1834 this.v2.purgeDependencyOnElmtId(rmElmtId); 1835 this.n3.purgeDependencyOnElmtId(rmElmtId); 1836 this.q3.purgeDependencyOnElmtId(rmElmtId); 1837 this.r3.purgeDependencyOnElmtId(rmElmtId); 1838 this.v3.purgeDependencyOnElmtId(rmElmtId); 1839 } 1840 1841 aboutToBeDeleted() { 1842 this.o2.aboutToBeDeleted(); 1843 this.t2.aboutToBeDeleted(); 1844 this.i3.aboutToBeDeleted(); 1845 this.q2.aboutToBeDeleted(); 1846 this.s2.aboutToBeDeleted(); 1847 this.j3.aboutToBeDeleted(); 1848 this.m3.aboutToBeDeleted(); 1849 this.l3.aboutToBeDeleted(); 1850 this.z2.aboutToBeDeleted(); 1851 this.u2.aboutToBeDeleted(); 1852 this.v2.aboutToBeDeleted(); 1853 this.n3.aboutToBeDeleted(); 1854 this.q3.aboutToBeDeleted(); 1855 this.r3.aboutToBeDeleted(); 1856 this.v3.aboutToBeDeleted(); 1857 SubscriberManager.Get().delete(this.id__()); 1858 this.aboutToBeDeletedInternal(); 1859 } 1860 1861 get options() { 1862 return this.o2.get(); 1863 } 1864 1865 get selectedIndexes() { 1866 return this.t2.get(); 1867 } 1868 1869 set selectedIndexes(newValue) { 1870 this.t2.set(newValue); 1871 } 1872 1873 get componentSize() { 1874 return this.i3.get(); 1875 } 1876 1877 set componentSize(newValue) { 1878 this.i3.set(newValue); 1879 } 1880 1881 get buttonBorderRadius() { 1882 return this.q2.get(); 1883 } 1884 1885 set buttonBorderRadius(newValue) { 1886 this.q2.set(newValue); 1887 } 1888 1889 get buttonItemsSize() { 1890 return this.s2.get(); 1891 } 1892 1893 set buttonItemsSize(newValue) { 1894 this.s2.set(newValue); 1895 } 1896 1897 get buttonItemsPosition() { 1898 return this.j3.get(); 1899 } 1900 1901 set buttonItemsPosition(newValue) { 1902 this.j3.set(newValue); 1903 } 1904 1905 get buttonItemsSelected() { 1906 return this.m3.get(); 1907 } 1908 1909 set buttonItemsSelected(newValue) { 1910 this.m3.set(newValue); 1911 } 1912 1913 get buttonItemProperty() { 1914 return this.l3.get(); 1915 } 1916 1917 set buttonItemProperty(newValue) { 1918 this.l3.set(newValue); 1919 } 1920 1921 get focusIndex() { 1922 return this.z2.get(); 1923 } 1924 1925 set focusIndex(newValue) { 1926 this.z2.set(newValue); 1927 } 1928 1929 get selectedItemPosition() { 1930 return this.u2.get(); 1931 } 1932 1933 set selectedItemPosition(newValue) { 1934 this.u2.set(newValue); 1935 } 1936 1937 get zoomScaleArray() { 1938 return this.v2.get(); 1939 } 1940 1941 set zoomScaleArray(newValue) { 1942 this.v2.set(newValue); 1943 } 1944 1945 get pressArray() { 1946 return this.n3.get(); 1947 } 1948 1949 set pressArray(newValue) { 1950 this.n3.set(newValue); 1951 } 1952 1953 get hoverArray() { 1954 return this.q3.get(); 1955 } 1956 1957 set hoverArray(newValue) { 1958 this.q3.set(newValue); 1959 } 1960 1961 get hoverColorArray() { 1962 return this.r3.get(); 1963 } 1964 1965 set hoverColorArray(newValue) { 1966 this.r3.set(newValue); 1967 } 1968 1969 get shouldMirror() { 1970 return this.v3.get(); 1971 } 1972 1973 set shouldMirror(newValue) { 1974 this.v3.set(newValue); 1975 } 1976 1977 onItemsPositionChange() { 1978 if (this.options === void 0 || this.options.buttons === void 0) { 1979 return; 1980 } 1981 if (this.options.type === 'capsule') { 1982 this.options.n2(); 1983 } 1984 if (this.doSelectedChangeAnimate) { 1985 this.updateAnimatedProperty(this.getSelectedChangeCurve()); 1986 } else { 1987 this.updateAnimatedProperty(null); 1988 } 1989 } 1990 1991 setItemsSelected() { 1992 this.buttonItemsSelected.forEach((h2, index) => { 1993 this.buttonItemsSelected[index] = false; 1994 }); 1995 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 1996 this.selectedIndexes.forEach(index => this.buttonItemsSelected[index] = true); 1997 } else { 1998 this.buttonItemsSelected[this.selectedIndexes[0]] = true; 1999 } 2000 } 2001 2002 updateSelectedIndexes() { 2003 if (this.selectedIndexes === void 0) { 2004 this.selectedIndexes = []; 2005 } 2006 if (this.options.type === 'tab' && this.selectedIndexes.length === 0) { 2007 this.selectedIndexes[0] = 0; 2008 } 2009 if (this.selectedIndexes.length > 1) { 2010 if (this.options.type === 'tab') { 2011 this.selectedIndexes = [0]; 2012 } 2013 if (this.options.type === 'capsule' && !(this.options.multiply ?? false)) { 2014 this.selectedIndexes = []; 2015 } 2016 } 2017 let g2 = this.selectedIndexes.some(index => { 2018 return (index === void 0 || index < 0 || (this.options.buttons && index >= this.options.buttons.length)); 2019 }); 2020 if (g2) { 2021 if (this.options.type === 'tab') { 2022 this.selectedIndexes = [0]; 2023 } else { 2024 this.selectedIndexes = []; 2025 } 2026 } 2027 } 2028 2029 onOptionsChange() { 2030 if (this.options === void 0 || this.options.buttons === void 0) { 2031 return; 2032 } 2033 this.shouldMirror = this.isShouldMirror(); 2034 this.updateSelectedIndexes(); 2035 this.setItemsSelected(); 2036 this.updateAnimatedProperty(null); 2037 } 2038 2039 onSelectedChange() { 2040 if (this.options === void 0 || this.options.buttons === void 0) { 2041 return; 2042 } 2043 this.updateSelectedIndexes(); 2044 this.setItemsSelected(); 2045 if (this.doSelectedChangeAnimate) { 2046 this.updateAnimatedProperty(this.getSelectedChangeCurve()); 2047 } else { 2048 this.updateAnimatedProperty(null); 2049 } 2050 } 2051 2052 aboutToAppear() { 2053 if (this.options === void 0 || this.options.buttons === void 0) { 2054 return; 2055 } 2056 this.options.h2 = () => { 2057 if (this.options.type === 'tab') { 2058 this.selectedIndexes = [0]; 2059 } else { 2060 this.selectedIndexes = []; 2061 } 2062 }; 2063 this.shouldMirror = this.isShouldMirror(); 2064 this.updateSelectedIndexes(); 2065 this.setItemsSelected(); 2066 this.updateAnimatedProperty(null); 2067 } 2068 2069 isMouseWheelScroll(event) { 2070 return event.source === SourceType.Mouse && !this.isPanGestureMoved; 2071 } 2072 2073 isMovedFromPanGestureStartPoint(x, y) { 2074 return !i(x, this.panGestureStartPoint.x) || !i(y, this.panGestureStartPoint.y); 2075 } 2076 2077 isShouldMirror() { 2078 if (this.options.direction == Direction.Rtl) { 2079 return true; 2080 } 2081 try { 2082 let f2 = t.System.getSystemLanguage(); 2083 if (f2 === 'ug' && this.options.direction != Direction.Ltr) { 2084 return true; 2085 } 2086 } catch (error) { 2087 console.error(`Ace SegmentButton getSystemLanguage, error: ${error.toString()}`); 2088 } 2089 return false; 2090 } 2091 2092 initialRender() { 2093 this.observeComponentCreation2((elmtId, isInitialRender) => { 2094 Stack.create(); 2095 Stack.direction(this.options ? this.options.direction : undefined); 2096 Stack.onBlur(() => { 2097 this.focusIndex = -1; 2098 }); 2099 Stack.onKeyEvent((event) => { 2100 if (this.options === void 0 || this.options.buttons === void 0) { 2101 return; 2102 } 2103 if (event.type === KeyType.Down) { 2104 if (event.keyCode === KeyCode.KEYCODE_SPACE || event.keyCode === KeyCode.KEYCODE_ENTER || 2105 event.keyCode === KeyCode.KEYCODE_NUMPAD_ENTER) { 2106 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2107 if (this.selectedIndexes.indexOf(this.focusIndex) === -1) { 2108 this.selectedIndexes.push(this.focusIndex); 2109 } else { 2110 this.selectedIndexes.splice(this.selectedIndexes.indexOf(this.focusIndex), 1); 2111 } 2112 } else { 2113 this.selectedIndexes[0] = this.focusIndex; 2114 } 2115 } 2116 } 2117 }); 2118 Stack.accessibilityLevel('no'); 2119 Gesture.create(GesturePriority.High); 2120 GestureGroup.create(GestureMode.Parallel); 2121 TapGesture.create(); 2122 TapGesture.onAction((event) => { 2123 this.focusIndex = -1; 2124 let a2 = event.fingerList.find(Boolean); 2125 if (a2 === void 0) { 2126 return; 2127 } 2128 if (this.options === void 0 || this.options.buttons === void 0) { 2129 return; 2130 } 2131 let b2 = a2.localX; 2132 let c2 = Math.min(this.options.buttons.length, this.buttonItemsSize.length); 2133 for (let d2 = 0; d2 < c2; d2++) { 2134 b2 = b2 - this.buttonItemsSize[d2].width; 2135 if (b2 >= 0) { 2136 continue; 2137 } 2138 this.doSelectedChangeAnimate = 2139 this.selectedIndexes[0] > Math.min(this.options.buttons.length, this.buttonItemsSize.length) ? 2140 false : true; 2141 let e2 = this.isShouldMirror() ? c2 - 1 - d2 : d2; 2142 if (this.onItemClicked) { 2143 this.onItemClicked(e2); 2144 } 2145 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2146 let selectedIndex = this.selectedIndexes.indexOf(e2); 2147 if (selectedIndex === -1) { 2148 this.selectedIndexes.push(e2); 2149 } else { 2150 this.selectedIndexes.splice(selectedIndex, 1); 2151 } 2152 } else { 2153 this.selectedIndexes[0] = e2; 2154 } 2155 this.doSelectedChangeAnimate = false; 2156 break; 2157 } 2158 }); 2159 TapGesture.pop(); 2160 SwipeGesture.create(); 2161 SwipeGesture.onAction((event) => { 2162 if (this.options === void 0 || this.options.buttons === void 0 || 2163 event.sourceTool === SourceTool.TOUCHPAD) { 2164 return; 2165 } 2166 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2167 return; 2168 } 2169 if (this.isCurrentPositionSelected) { 2170 return; 2171 } 2172 if (event.angle > 0 && this.selectedIndexes[0] !== 2173 Math.min(this.options.buttons.length, this.buttonItemsSize.length) - 1) { 2174 this.doSelectedChangeAnimate = true; 2175 this.selectedIndexes[0] = this.selectedIndexes[0] + 1; 2176 this.doSelectedChangeAnimate = false; 2177 } else if (event.angle < 0 && this.selectedIndexes[0] !== 0) { 2178 this.doSelectedChangeAnimate = true; 2179 this.selectedIndexes[0] = this.selectedIndexes[0] - 1; 2180 this.doSelectedChangeAnimate = false; 2181 } 2182 }); 2183 SwipeGesture.pop(); 2184 PanGesture.create(); 2185 PanGesture.onActionStart((event) => { 2186 if (this.options === void 0 || this.options.buttons === void 0) { 2187 return; 2188 } 2189 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2190 return; 2191 } 2192 let v1 = event.fingerList.find(Boolean); 2193 if (v1 === void 0) { 2194 return; 2195 } 2196 let w1 = v1.localX; 2197 this.panGestureStartPoint = { x: v1.globalX, y: v1.globalY }; 2198 this.isPanGestureMoved = false; 2199 for (let z1 = 0; z1 < Math.min(this.options.buttons.length, this.buttonItemsSize.length); z1++) { 2200 w1 = w1 - this.buttonItemsSize[z1].width; 2201 if (w1 < 0) { 2202 this.isCurrentPositionSelected = z1 === this.selectedIndexes[0] ? true : false; 2203 break; 2204 } 2205 } 2206 }); 2207 PanGesture.onActionUpdate((event) => { 2208 if (this.options === void 0 || this.options.buttons === void 0) { 2209 return; 2210 } 2211 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2212 return; 2213 } 2214 if (!this.isCurrentPositionSelected) { 2215 return; 2216 } 2217 let q1 = event.fingerList.find(Boolean); 2218 if (q1 === void 0) { 2219 return; 2220 } 2221 let s1 = q1.localX; 2222 if (!this.isPanGestureMoved && this.isMovedFromPanGestureStartPoint(q1.globalX, q1.globalY)) { 2223 this.isPanGestureMoved = true; 2224 } 2225 for (let u1 = 0; u1 < Math.min(this.options.buttons.length, this.buttonItemsSize.length); u1++) { 2226 s1 = s1 - this.buttonItemsSize[u1].width; 2227 if (s1 < 0) { 2228 this.doSelectedChangeAnimate = true; 2229 this.selectedIndexes[0] = u1; 2230 this.doSelectedChangeAnimate = false; 2231 break; 2232 } 2233 } 2234 this.zoomScaleArray.forEach((t1, index) => { 2235 if (index === this.selectedIndexes[0]) { 2236 Context.animateTo({ curve: curves.interpolatingSpring(10, 1, 410, 38) }, () => { 2237 this.zoomScaleArray[index] = 0.95; 2238 }); 2239 } else { 2240 Context.animateTo({ curve: curves.interpolatingSpring(10, 1, 410, 38) }, () => { 2241 this.zoomScaleArray[index] = 1; 2242 }); 2243 } 2244 }); 2245 }); 2246 PanGesture.onActionEnd((event) => { 2247 if (this.options === void 0 || this.options.buttons === void 0) { 2248 return; 2249 } 2250 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2251 return; 2252 } 2253 let p1 = event.fingerList.find(Boolean); 2254 if (p1 === void 0) { 2255 return; 2256 } 2257 if (!this.isPanGestureMoved && this.isMovedFromPanGestureStartPoint(p1.globalX, p1.globalY)) { 2258 this.isPanGestureMoved = true; 2259 } 2260 if (this.isMouseWheelScroll(event)) { 2261 let offset = event.offsetX !== 0 ? event.offsetX : event.offsetY; 2262 this.doSelectedChangeAnimate = true; 2263 if (offset > 0 && this.selectedIndexes[0] > 0) { 2264 this.selectedIndexes[0] -= 1; 2265 } else if (offset < 0 && this.selectedIndexes[0] < 2266 Math.min(this.options.buttons.length, this.buttonItemsSize.length) - 1) { 2267 this.selectedIndexes[0] += 1; 2268 } 2269 this.doSelectedChangeAnimate = false; 2270 } 2271 Context.animateTo({ curve: curves.interpolatingSpring(10, 1, 410, 38) }, () => { 2272 this.zoomScaleArray[this.selectedIndexes[0]] = 1; 2273 }); 2274 this.isCurrentPositionSelected = false; 2275 }); 2276 PanGesture.pop(); 2277 GestureGroup.pop(); 2278 Gesture.pop(); 2279 }, Stack); 2280 this.observeComponentCreation2((elmtId, isInitialRender) => { 2281 If.create(); 2282 if (this.options !== void 0 && this.options.buttons != void 0) { 2283 this.ifElseBranchUpdateFunction(0, () => { 2284 this.observeComponentCreation2((elmtId, isInitialRender) => { 2285 If.create(); 2286 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2287 this.ifElseBranchUpdateFunction(0, () => { 2288 { 2289 this.observeComponentCreation2((elmtId, isInitialRender) => { 2290 if (isInitialRender) { 2291 let componentCall = new f1(this, { 2292 optionsArray: this.options.buttons, 2293 options: this.options, 2294 }, undefined, elmtId, () => { 2295 }, { 2296 page: "segmentbutton/src/main/ets/components/MainPage.ets", 2297 line: 1113, 2298 u3: 11 2299 }); 2300 ViewPU.create(componentCall); 2301 let paramsLambda = () => { 2302 return { 2303 optionsArray: this.options.buttons, 2304 options: this.options 2305 }; 2306 }; 2307 componentCall.paramsGenerator_ = paramsLambda; 2308 } else { 2309 this.updateStateVarsOfChildByElmtId(elmtId, { 2310 optionsArray: this.options.buttons, 2311 options: this.options 2312 }); 2313 } 2314 }, { name: "MultiSelectBackground" }); 2315 } 2316 }); 2317 } else { 2318 this.ifElseBranchUpdateFunction(1, () => { 2319 this.observeComponentCreation2((elmtId, isInitialRender) => { 2320 Stack.create(); 2321 Stack.direction(this.options.direction); 2322 Stack.size(ObservedObject.GetRawObject(this.componentSize)); 2323 Stack.backgroundColor(this.options.backgroundColor ?? e1.BACKGROUND_COLOR); 2324 Stack.borderRadius(this.options.l2 ?? this.componentSize.height / 2); 2325 Stack.backgroundBlurStyle(this.options.backgroundBlurStyle); 2326 }, Stack); 2327 this.observeComponentCreation2((elmtId, isInitialRender) => { 2328 If.create(); 2329 if (this.options.buttons !== void 0 && this.options.buttons.length > 1) { 2330 this.ifElseBranchUpdateFunction(0, () => { 2331 this.observeComponentCreation2((elmtId, isInitialRender) => { 2332 Row.create({ space: 1 }); 2333 Row.direction(this.options.direction); 2334 }, Row); 2335 this.observeComponentCreation2((elmtId, isInitialRender) => { 2336 ForEach.create(); 2337 const forEachItemGenFunction = (_item, index) => { 2338 const item = _item; 2339 this.observeComponentCreation2((elmtId, isInitialRender) => { 2340 If.create(); 2341 if (index < a1) { 2342 this.ifElseBranchUpdateFunction(0, () => { 2343 this.observeComponentCreation2((elmtId, 2344 isInitialRender) => { 2345 Stack.create(); 2346 Stack.direction(this.options.direction); 2347 Stack.scale({ 2348 x: this.options.type === 'capsule' && 2349 (this.options.multiply ?? false) ? 1 : 2350 this.zoomScaleArray[index], 2351 y: this.options.type === 'capsule' && 2352 (this.options.multiply ?? false) ? 1 : 2353 this.zoomScaleArray[index] 2354 }); 2355 }, Stack); 2356 { 2357 this.observeComponentCreation2((elmtId, 2358 isInitialRender) => { 2359 if (isInitialRender) { 2360 let componentCall = new l1(this, { 2361 pressIndex: index, 2362 colorProperty: this.hoverColorArray[index], 2363 press: this.pressArray[index], 2364 hover: this.hoverArray[index], 2365 options: this.options, 2366 }, undefined, elmtId, () => { 2367 }, { 2368 page: "segmentbutton/src/main/ets/components/MainPage.ets", 2369 line: 1124, 2370 u3: 23 2371 }); 2372 ViewPU.create(componentCall); 2373 let paramsLambda = () => { 2374 return { 2375 pressIndex: index, 2376 colorProperty: this.hoverColorArray[index], 2377 press: this.pressArray[index], 2378 hover: this.hoverArray[index], 2379 options: this.options 2380 }; 2381 }; 2382 componentCall.paramsGenerator_ = 2383 paramsLambda; 2384 } else { 2385 this.updateStateVarsOfChildByElmtId(elmtId, 2386 { 2387 colorProperty: this.hoverColorArray[index], 2388 press: this.pressArray[index], 2389 hover: this.hoverArray[index], 2390 options: this.options 2391 }); 2392 } 2393 }, { name: "PressAndHoverEffect" }); 2394 } 2395 Stack.pop(); 2396 }); 2397 } else { 2398 this.ifElseBranchUpdateFunction(1, () => { 2399 }); 2400 } 2401 }, If); 2402 If.pop(); 2403 }; 2404 this.forEachUpdateFunction(elmtId, this.options.buttons, 2405 forEachItemGenFunction, undefined, true, false); 2406 }, ForEach); 2407 ForEach.pop(); 2408 Row.pop(); 2409 }); 2410 } else { 2411 this.ifElseBranchUpdateFunction(1, () => { 2412 }); 2413 } 2414 }, If); 2415 If.pop(); 2416 Stack.pop(); 2417 }); 2418 } 2419 }, If); 2420 If.pop(); 2421 this.observeComponentCreation2((elmtId, isInitialRender) => { 2422 Stack.create(); 2423 Context.animation({ duration: 0 }); 2424 Stack.direction(this.options.direction); 2425 Stack.size(ObservedObject.GetRawObject(this.componentSize)); 2426 Context.animation(null); 2427 Stack.borderRadius((this.options.type === 'capsule' && (this.options.multiply ?? false) ? 2428 this.options.j2 : this.options.l2) ?? 2429 this.componentSize.height / 2); 2430 Stack.clip(true); 2431 }, Stack); 2432 this.observeComponentCreation2((elmtId, isInitialRender) => { 2433 If.create(); 2434 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2435 this.ifElseBranchUpdateFunction(0, () => { 2436 { 2437 this.observeComponentCreation2((elmtId, isInitialRender) => { 2438 if (isInitialRender) { 2439 let componentCall = new h1(this, { 2440 optionsArray: this.options.buttons, 2441 options: this.options, 2442 selectedIndexes: this.t2 2443 }, undefined, elmtId, () => { 2444 }, { 2445 page: "segmentbutton/src/main/ets/components/MainPage.ets", 2446 line: 1150, 2447 u3: 13 2448 }); 2449 ViewPU.create(componentCall); 2450 let paramsLambda = () => { 2451 return { 2452 optionsArray: this.options.buttons, 2453 options: this.options, 2454 selectedIndexes: this.selectedIndexes 2455 }; 2456 }; 2457 componentCall.paramsGenerator_ = paramsLambda; 2458 } else { 2459 this.updateStateVarsOfChildByElmtId(elmtId, { 2460 optionsArray: this.options.buttons, 2461 options: this.options 2462 }); 2463 } 2464 }, { name: "MultiSelectItemArray" }); 2465 } 2466 }); 2467 } else { 2468 this.ifElseBranchUpdateFunction(1, () => { 2469 { 2470 this.observeComponentCreation2((elmtId, isInitialRender) => { 2471 if (isInitialRender) { 2472 let componentCall = new g1(this, { 2473 optionsArray: this.options.buttons, 2474 options: this.options, 2475 selectedIndexes: this.t2 2476 }, undefined, elmtId, () => { 2477 }, { 2478 page: "segmentbutton/src/main/ets/components/MainPage.ets", 2479 line: 1156, 2480 u3: 13 2481 }); 2482 ViewPU.create(componentCall); 2483 let paramsLambda = () => { 2484 return { 2485 optionsArray: this.options.buttons, 2486 options: this.options, 2487 selectedIndexes: this.selectedIndexes 2488 }; 2489 }; 2490 componentCall.paramsGenerator_ = paramsLambda; 2491 } else { 2492 this.updateStateVarsOfChildByElmtId(elmtId, { 2493 optionsArray: this.options.buttons, 2494 options: this.options 2495 }); 2496 } 2497 }, { name: "SelectItem" }); 2498 } 2499 }); 2500 } 2501 }, If); 2502 If.pop(); 2503 Stack.pop(); 2504 { 2505 this.observeComponentCreation2((elmtId, isInitialRender) => { 2506 if (isInitialRender) { 2507 let componentCall = new m1(this, { 2508 pressArray: this.n3, 2509 hoverArray: this.q3, 2510 hoverColorArray: this.r3, 2511 optionsArray: this.options.buttons, 2512 options: this.options, 2513 selectedIndexes: this.t2, 2514 }, undefined, elmtId, () => { 2515 }, { page: "segmentbutton/src/main/ets/components/MainPage.ets", line: 1171, u3: 9 }); 2516 ViewPU.create(componentCall); 2517 let paramsLambda = () => { 2518 return { 2519 pressArray: this.pressArray, 2520 hoverArray: this.hoverArray, 2521 hoverColorArray: this.hoverColorArray, 2522 optionsArray: this.options.buttons, 2523 options: this.options, 2524 selectedIndexes: this.selectedIndexes 2525 }; 2526 }; 2527 componentCall.paramsGenerator_ = paramsLambda; 2528 } else { 2529 this.updateStateVarsOfChildByElmtId(elmtId, { 2530 optionsArray: this.options.buttons, 2531 options: this.options 2532 }); 2533 } 2534 }, { name: "SegmentButtonItemArrayComponent" }); 2535 } 2536 }); 2537 } else { 2538 this.ifElseBranchUpdateFunction(1, () => { 2539 }); 2540 } 2541 }, If); 2542 If.pop(); 2543 Stack.pop(); 2544 } 2545 2546 getSelectedChangeCurve() { 2547 if (this.options.type === 'capsule' && (this.options.multiply ?? false)) { 2548 return null; 2549 } 2550 return curves.springMotion(0.347, 0.99); 2551 } 2552 2553 updateAnimatedProperty(curve) { 2554 let o1 = () => { 2555 this.selectedItemPosition = 2556 this.selectedIndexes.length === 0 ? {} : this.buttonItemsPosition[this.selectedIndexes[0]]; 2557 this.buttonItemsSelected.forEach((selected, index) => { 2558 this.buttonItemProperty[index].fontColor = selected ? 2559 this.options.selectedFontColor ?? (this.options.type === 'tab' ? 2560 e1.s1 : e1.t1) : 2561 this.options.fontColor ?? e1.q1; 2562 }); 2563 }; 2564 if (curve) { 2565 Context.animateTo({ curve: curve }, o1); 2566 } else { 2567 o1(); 2568 } 2569 this.buttonItemsSelected.forEach((selected, index) => { 2570 this.buttonItemProperty[index].fontSize = selected ? this.options.selectedFontSize ?? 2571 e1.v1 : this.options.fontSize ?? e1.u1; 2572 this.buttonItemProperty[index].fontWeight = 2573 selected ? this.options.selectedFontWeight ?? FontWeight.Medium : 2574 this.options.fontWeight ?? FontWeight.Regular; 2575 this.buttonItemProperty[index].isSelected = selected; 2576 }); 2577 } 2578 2579 rerender() { 2580 this.updateDirtyElements(); 2581 } 2582} 2583 2584export default { 2585 SegmentButton, 2586 SegmentButtonOptions, 2587 SegmentButtonItemOptionsArray, 2588 SegmentButtonItemOptions, 2589}; 2590