1/* 2 * Copyright (c) 2023-2024 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 */ 15var NodeRenderType; 16(function (NodeRenderType) { 17 NodeRenderType[NodeRenderType["RENDER_TYPE_DISPLAY"] = 0] = "RENDER_TYPE_DISPLAY"; 18 NodeRenderType[NodeRenderType["RENDER_TYPE_TEXTURE"] = 1] = "RENDER_TYPE_TEXTURE"; 19})(NodeRenderType || (NodeRenderType = {})); 20 21class BaseNode extends __JSBaseNode__ { 22 constructor(uiContext, options) { 23 super(options); 24 if (uiContext === undefined) { 25 throw Error('Node constructor error, param uiContext error'); 26 } 27 else { 28 if (!(typeof uiContext === 'object') || !('instanceId_' in uiContext)) { 29 throw Error('Node constructor error, param uiContext is invalid'); 30 } 31 } 32 this.instanceId_ = uiContext.instanceId_; 33 } 34 getInstanceId() { 35 return this.instanceId_; 36 } 37 updateInstance(uiContext) { 38 this.instanceId_ = uiContext.instanceId_; 39 } 40} 41/* 42 * Copyright (c) 2023 Huawei Device Co., Ltd. 43 * Licensed under the Apache License, Version 2.0 (the "License"); 44 * you may not use this file except in compliance with the License. 45 * You may obtain a copy of the License at 46 * 47 * http://www.apache.org/licenses/LICENSE-2.0 48 * 49 * Unless required by applicable law or agreed to in writing, software 50 * distributed under the License is distributed on an "AS IS" BASIS, 51 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 * See the License for the specific language governing permissions and 53 * limitations under the License. 54 */ 55/// <reference path="../../state_mgmt/src/lib/common/ace_console.native.d.ts" /> 56/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" /> 57/// <reference path="../../state_mgmt/src/lib/puv2_common/puv2_viewstack_processor.d.ts" /> 58class BuilderNode { 59 constructor(uiContext, options) { 60 let jsBuilderNode = new JSBuilderNode(uiContext, options); 61 this._JSBuilderNode = jsBuilderNode; 62 let id = Symbol('BuilderRootFrameNode'); 63 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.set(id, jsBuilderNode); 64 BuilderNodeFinalizationRegisterProxy.register(this, { name: 'BuilderRootFrameNode', idOfNode: id }); 65 } 66 update(params) { 67 this._JSBuilderNode.update(params); 68 } 69 build(builder, params, options) { 70 this._JSBuilderNode.build(builder, params, options); 71 this.nodePtr_ = this._JSBuilderNode.getNodePtr(); 72 } 73 getNodePtr() { 74 return this._JSBuilderNode.getValidNodePtr(); 75 } 76 getFrameNode() { 77 return this._JSBuilderNode.getFrameNode(); 78 } 79 getFrameNodeWithoutCheck() { 80 return this._JSBuilderNode.getFrameNodeWithoutCheck(); 81 } 82 postTouchEvent(touchEvent) { 83 __JSScopeUtil__.syncInstanceId(this._JSBuilderNode.getInstanceId()); 84 let ret = this._JSBuilderNode.postTouchEvent(touchEvent); 85 __JSScopeUtil__.restoreInstanceId(); 86 return ret; 87 } 88 dispose() { 89 this._JSBuilderNode.dispose(); 90 } 91 reuse(param) { 92 this._JSBuilderNode.reuse(param); 93 } 94 recycle() { 95 this._JSBuilderNode.recycle(); 96 } 97 updateConfiguration() { 98 this._JSBuilderNode.updateConfiguration(); 99 } 100} 101class JSBuilderNode extends BaseNode { 102 constructor(uiContext, options) { 103 super(uiContext, options); 104 this.childrenWeakrefMap_ = new Map(); 105 this.uiContext_ = uiContext; 106 this.updateFuncByElmtId = new Map(); 107 this._supportNestingBuilder = false; 108 } 109 reuse(param) { 110 this.updateStart(); 111 this.childrenWeakrefMap_.forEach((weakRefChild) => { 112 const child = weakRefChild.deref(); 113 if (child) { 114 if (child instanceof ViewPU) { 115 child.aboutToReuseInternal(param); 116 } 117 else { 118 // FIXME fix for mixed V2 - V3 Hierarchies 119 throw new Error('aboutToReuseInternal: Recycle not implemented for ViewV2, yet'); 120 } 121 } // if child 122 }); 123 this.updateEnd(); 124 } 125 recycle() { 126 this.childrenWeakrefMap_.forEach((weakRefChild) => { 127 const child = weakRefChild.deref(); 128 if (child) { 129 if (child instanceof ViewPU) { 130 child.aboutToRecycleInternal(); 131 } 132 else { 133 // FIXME fix for mixed V2 - V3 Hierarchies 134 throw new Error('aboutToRecycleInternal: Recycle not yet implemented for ViewV2'); 135 } 136 } // if child 137 }); 138 } 139 getCardId() { 140 return -1; 141 } 142 addChild(child) { 143 if (this.childrenWeakrefMap_.has(child.id__())) { 144 return false; 145 } 146 this.childrenWeakrefMap_.set(child.id__(), new WeakRef(child)); 147 return true; 148 } 149 getChildById(id) { 150 const childWeakRef = this.childrenWeakrefMap_.get(id); 151 return childWeakRef ? childWeakRef.deref() : undefined; 152 } 153 updateStateVarsOfChildByElmtId(elmtId, params) { 154 if (elmtId < 0) { 155 return; 156 } 157 let child = this.getChildById(elmtId); 158 if (!child) { 159 return; 160 } 161 child.updateStateVars(params); 162 child.updateDirtyElements(); 163 } 164 createOrGetNode(elmtId, builder) { 165 const entry = this.updateFuncByElmtId.get(elmtId); 166 if (entry === undefined) { 167 aceConsole.warn(0, `BUILDER_NOD: fail to create node, elmtId is illegal`); 168 return builder(); 169 } 170 let updateFuncRecord = (typeof entry === 'object') ? entry : undefined; 171 if (updateFuncRecord === undefined) { 172 aceConsole.warn(0, `BUILDER_NOD: fail to create node, the api level of app does not supported`); 173 return builder(); 174 } 175 let nodeInfo = updateFuncRecord.node; 176 if (nodeInfo === undefined) { 177 nodeInfo = builder(); 178 updateFuncRecord.node = nodeInfo; 179 } 180 return nodeInfo; 181 } 182 isObject(param) { 183 const typeName = Object.prototype.toString.call(param); 184 const objectName = `[object Object]`; 185 if (typeName === objectName) { 186 return true; 187 } 188 else { 189 return false; 190 } 191 } 192 buildWithNestingBuilder(builder, supportLazyBuild) { 193 if (this._supportNestingBuilder && this.isObject(this.params_)) { 194 this._proxyObjectParam = new Proxy(this.params_, { 195 set(target, property, val) { 196 throw Error(`@Builder : Invalid attempt to set(write to) parameter '${property.toString()}' error!`); 197 }, 198 get: (target, property, receiver) => { return this.params_?.[property]; } 199 }); 200 this.nodePtr_ = super.create(builder.builder, this._proxyObjectParam, this.updateNodeFromNative, this.updateConfiguration, supportLazyBuild); 201 } 202 else { 203 this.nodePtr_ = super.create(builder.builder, this.params_, this.updateNodeFromNative, this.updateConfiguration, supportLazyBuild); 204 } 205 } 206 build(builder, params, options) { 207 __JSScopeUtil__.syncInstanceId(this.instanceId_); 208 this._supportNestingBuilder = options?.nestingBuilderSupported ? options.nestingBuilderSupported : false; 209 const supportLazyBuild = options?.lazyBuildSupported ? options.lazyBuildSupported : false; 210 this.params_ = params; 211 this.updateFuncByElmtId.clear(); 212 this.buildWithNestingBuilder(builder, supportLazyBuild); 213 this._nativeRef = getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_); 214 if (this.frameNode_ === undefined || this.frameNode_ === null) { 215 this.frameNode_ = new BuilderRootFrameNode(this.uiContext_); 216 } 217 this.frameNode_.setNodePtr(this._nativeRef, this.nodePtr_); 218 this.frameNode_.setRenderNode(this._nativeRef); 219 this.frameNode_.setBaseNode(this); 220 __JSScopeUtil__.restoreInstanceId(); 221 } 222 update(param) { 223 __JSScopeUtil__.syncInstanceId(this.instanceId_); 224 this.updateStart(); 225 this.purgeDeletedElmtIds(); 226 this.params_ = param; 227 Array.from(this.updateFuncByElmtId.keys()).sort((a, b) => { 228 return (a < b) ? -1 : (a > b) ? 1 : 0; 229 }).forEach(elmtId => this.UpdateElement(elmtId)); 230 this.updateEnd(); 231 __JSScopeUtil__.restoreInstanceId(); 232 } 233 updateConfiguration() { 234 __JSScopeUtil__.syncInstanceId(this.instanceId_); 235 this.updateStart(); 236 this.purgeDeletedElmtIds(); 237 Array.from(this.updateFuncByElmtId.keys()).sort((a, b) => { 238 return (a < b) ? -1 : (a > b) ? 1 : 0; 239 }).forEach(elmtId => this.UpdateElement(elmtId)); 240 for (const child of this.childrenWeakrefMap_.values()) { 241 const childView = child.deref(); 242 if (childView) { 243 childView.forceCompleteRerender(true); 244 } 245 } 246 this.updateEnd(); 247 __JSScopeUtil__.restoreInstanceId(); 248 } 249 UpdateElement(elmtId) { 250 // do not process an Element that has been marked to be deleted 251 const obj = this.updateFuncByElmtId.get(elmtId); 252 const updateFunc = (typeof obj === 'object') ? obj.updateFunc : null; 253 if (typeof updateFunc === 'function') { 254 updateFunc(elmtId, /* isFirstRender */ false); 255 this.finishUpdateFunc(); 256 } 257 } 258 purgeDeletedElmtIds() { 259 UINodeRegisterProxy.obtainDeletedElmtIds(); 260 UINodeRegisterProxy.unregisterElmtIdsFromIViews(); 261 } 262 purgeDeleteElmtId(rmElmtId) { 263 const result = this.updateFuncByElmtId.delete(rmElmtId); 264 if (result) { 265 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(rmElmtId); 266 } 267 return result; 268 } 269 getFrameNode() { 270 if (this.frameNode_ !== undefined && 271 this.frameNode_ !== null && 272 this.frameNode_.getNodePtr() !== null) { 273 return this.frameNode_; 274 } 275 return null; 276 } 277 getFrameNodeWithoutCheck() { 278 return this.frameNode_; 279 } 280 observeComponentCreation(func) { 281 let elmId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 282 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmId, new WeakRef(this)); 283 try { 284 func(elmId, true); 285 } 286 catch (error) { 287 // avoid the incompatible change that move set function before updateFunc. 288 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmId); 289 throw error; 290 } 291 } 292 observeComponentCreation2(compilerAssignedUpdateFunc, classObject) { 293 const _componentName = classObject && 'name' in classObject ? Reflect.get(classObject, 'name') : 'unspecified UINode'; 294 const _popFunc = classObject && 'pop' in classObject ? classObject.pop : () => { }; 295 const updateFunc = (elmtId, isFirstRender) => { 296 __JSScopeUtil__.syncInstanceId(this.instanceId_); 297 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 298 // if V2 @Observed/@Track used anywhere in the app (there is no more fine grained criteria), 299 // enable V2 object deep observation 300 // FIXME: A @Component should only use PU or V2 state, but ReactNative dynamic viewer uses both. 301 if (ConfigureStateMgmt.instance.needsV2Observe()) { 302 // FIXME: like in V2 setting bindId_ in ObserveV2 does not work with 'stacked' 303 // update + initial render calls, like in if and ForEach case, convert to stack as well 304 ObserveV2.getObserve().startRecordDependencies(this, elmtId, true); 305 } 306 if (this._supportNestingBuilder) { 307 compilerAssignedUpdateFunc(elmtId, isFirstRender); 308 } 309 else { 310 compilerAssignedUpdateFunc(elmtId, isFirstRender, this.params_); 311 } 312 if (!isFirstRender) { 313 _popFunc(); 314 } 315 if (ConfigureStateMgmt.instance.needsV2Observe()) { 316 ObserveV2.getObserve().stopRecordDependencies(); 317 } 318 ViewStackProcessor.StopGetAccessRecording(); 319 __JSScopeUtil__.restoreInstanceId(); 320 }; 321 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 322 // needs to move set before updateFunc. 323 // make sure the key and object value exist since it will add node in attributeModifier during updateFunc. 324 this.updateFuncByElmtId.set(elmtId, { 325 updateFunc: updateFunc, 326 componentName: _componentName, 327 }); 328 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmtId, new WeakRef(this)); 329 try { 330 updateFunc(elmtId, /* is first render */ true); 331 } 332 catch (error) { 333 // avoid the incompatible change that move set function before updateFunc. 334 this.updateFuncByElmtId.delete(elmtId); 335 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmtId); 336 throw error; 337 } 338 } 339 /** 340 Partial updates for ForEach. 341 * @param elmtId ID of element. 342 * @param itemArray Array of items for use of itemGenFunc. 343 * @param itemGenFunc Item generation function to generate new elements. If index parameter is 344 * given set itemGenFuncUsesIndex to true. 345 * @param idGenFunc ID generation function to generate unique ID for each element. If index parameter is 346 * given set idGenFuncUsesIndex to true. 347 * @param itemGenFuncUsesIndex itemGenFunc optional index parameter is given or not. 348 * @param idGenFuncUsesIndex idGenFunc optional index parameter is given or not. 349 */ 350 forEachUpdateFunction(elmtId, itemArray, itemGenFunc, idGenFunc, itemGenFuncUsesIndex = false, idGenFuncUsesIndex = false) { 351 if (itemArray === null || itemArray === undefined) { 352 return; 353 } 354 if (itemGenFunc === null || itemGenFunc === undefined) { 355 return; 356 } 357 if (idGenFunc === undefined) { 358 idGenFuncUsesIndex = true; 359 // catch possible error caused by Stringify and re-throw an Error with a meaningful (!) error message 360 idGenFunc = (item, index) => { 361 try { 362 return `${index}__${JSON.stringify(item)}`; 363 } 364 catch (e) { 365 throw new Error(` ForEach id ${elmtId}: use of default id generator function not possible on provided data structure. Need to specify id generator function (ForEach 3rd parameter). Application Error!`); 366 } 367 }; 368 } 369 let diffIndexArray = []; // New indexes compared to old one. 370 let newIdArray = []; 371 let idDuplicates = []; 372 const arr = itemArray; // just to trigger a 'get' onto the array 373 // ID gen is with index. 374 if (idGenFuncUsesIndex) { 375 // Create array of new ids. 376 arr.forEach((item, indx) => { 377 newIdArray.push(idGenFunc(item, indx)); 378 }); 379 } 380 else { 381 // Create array of new ids. 382 arr.forEach((item, index) => { 383 newIdArray.push(`${itemGenFuncUsesIndex ? index + '_' : ''}` + idGenFunc(item)); 384 }); 385 } 386 // removedChildElmtIds will be filled with the elmtIds of all children and their children will be deleted in response to foreach change 387 let removedChildElmtIds = []; 388 // Set new array on C++ side. 389 // C++ returns array of indexes of newly added array items. 390 // these are indexes in new child list. 391 ForEach.setIdArray(elmtId, newIdArray, diffIndexArray, idDuplicates, removedChildElmtIds); 392 // Item gen is with index. 393 diffIndexArray.forEach((indx) => { 394 ForEach.createNewChildStart(newIdArray[indx], this); 395 if (itemGenFuncUsesIndex) { 396 itemGenFunc(arr[indx], indx); 397 } 398 else { 399 itemGenFunc(arr[indx]); 400 } 401 ForEach.createNewChildFinish(newIdArray[indx], this); 402 }); 403 // un-registers the removed child elementIDs using proxy 404 UINodeRegisterProxy.unregisterRemovedElmtsFromViewPUs(removedChildElmtIds); 405 // purging these elmtIds from state mgmt will make sure no more update function on any deleted child will be executed 406 this.purgeDeletedElmtIds(); 407 } 408 ifElseBranchUpdateFunction(branchId, branchfunc) { 409 const oldBranchid = If.getBranchId(); 410 if (branchId === oldBranchid) { 411 return; 412 } 413 // branchId identifies uniquely the if .. <1> .. else if .<2>. else .<3>.branch 414 // ifElseNode stores the most recent branch, so we can compare 415 // removedChildElmtIds will be filled with the elmtIds of all children and their children will be deleted in response to if .. else change 416 let removedChildElmtIds = new Array(); 417 If.branchId(branchId, removedChildElmtIds); 418 //un-registers the removed child elementIDs using proxy 419 UINodeRegisterProxy.unregisterRemovedElmtsFromViewPUs(removedChildElmtIds); 420 this.purgeDeletedElmtIds(); 421 branchfunc(); 422 } 423 getNodePtr() { 424 return this.nodePtr_; 425 } 426 getValidNodePtr() { 427 return this._nativeRef?.getNativeHandle(); 428 } 429 dispose() { 430 this.frameNode_?.dispose(); 431 } 432 disposeNode() { 433 super.disposeNode(); 434 this.nodePtr_ = null; 435 this._nativeRef = null; 436 this.frameNode_?.resetNodePtr(); 437 } 438 updateInstance(uiContext) { 439 this.uiContext_ = uiContext; 440 this.instanceId_ = uiContext.instanceId_; 441 if (this.frameNode_ !== undefined && this.frameNode_ !== null) { 442 this.frameNode_.updateInstance(uiContext); 443 } 444 } 445 updateNodePtr(nodePtr) { 446 if (nodePtr != this.nodePtr_) { 447 this.dispose(); 448 this.nodePtr_ = nodePtr; 449 this._nativeRef = getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_); 450 this.frameNode_.setNodePtr(this._nativeRef, this.nodePtr_); 451 } 452 } 453 updateInstanceId(instanceId) { 454 this.instanceId_ = instanceId; 455 } 456 updateNodeFromNative(instanceId, nodePtr) { 457 this.updateNodePtr(nodePtr); 458 this.updateInstanceId(instanceId); 459 } 460 observeRecycleComponentCreation(name, recycleUpdateFunc) { 461 throw new Error('custom component in @Builder used by BuilderNode does not support @Reusable'); 462 } 463} 464/* 465 * Copyright (c) 2024 Huawei Device Co., Ltd. 466 * Licensed under the Apache License, Version 2.0 (the "License"); 467 * you may not use this file except in compliance with the License. 468 * You may obtain a copy of the License at 469 * 470 * http://www.apache.org/licenses/LICENSE-2.0 471 * 472 * Unless required by applicable law or agreed to in writing, software 473 * distributed under the License is distributed on an "AS IS" BASIS, 474 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 475 * See the License for the specific language governing permissions and 476 * limitations under the License. 477 */ 478class NodeAdapter { 479 constructor() { 480 this.nodeRefs_ = new Array(); 481 this.count_ = 0; 482 this.nativeRef_ = getUINativeModule().nodeAdapter.createAdapter(); 483 this.nativePtr_ = this.nativeRef_.getNativeHandle(); 484 getUINativeModule().nodeAdapter.setCallbacks(this.nativePtr_, this, this.onAttachToNodePtr, this.onDetachFromNodePtr, this.onGetChildId !== undefined ? this.onGetChildId : undefined, this.onCreateChild !== undefined ? this.onCreateNewNodePtr : undefined, this.onDisposeChild !== undefined ? this.onDisposeNodePtr : undefined, this.onUpdateChild !== undefined ? this.onUpdateNodePtr : undefined); 485 } 486 dispose() { 487 let hostNode = this.attachedNodeRef_.deref(); 488 if (hostNode !== undefined) { 489 NodeAdapter.detachNodeAdapter(hostNode); 490 } 491 this.nativeRef_.dispose(); 492 this.nativePtr_ = null; 493 } 494 set totalNodeCount(count) { 495 if (count < 0) { 496 return; 497 } 498 getUINativeModule().nodeAdapter.setTotalNodeCount(this.nativePtr_, count); 499 this.count_ = count; 500 } 501 get totalNodeCount() { 502 return this.count_; 503 } 504 reloadAllItems() { 505 getUINativeModule().nodeAdapter.notifyItemReloaded(this.nativePtr_); 506 } 507 reloadItem(start, count) { 508 if (start < 0 || count < 0) { 509 return; 510 } 511 getUINativeModule().nodeAdapter.notifyItemChanged(this.nativePtr_, start, count); 512 } 513 removeItem(start, count) { 514 if (start < 0 || count < 0) { 515 return; 516 } 517 getUINativeModule().nodeAdapter.notifyItemRemoved(this.nativePtr_, start, count); 518 } 519 insertItem(start, count) { 520 if (start < 0 || count < 0) { 521 return; 522 } 523 getUINativeModule().nodeAdapter.notifyItemInserted(this.nativePtr_, start, count); 524 } 525 moveItem(from, to) { 526 if (from < 0 || to < 0) { 527 return; 528 } 529 getUINativeModule().nodeAdapter.notifyItemMoved(this.nativePtr_, from, to); 530 } 531 getAllAvailableItems() { 532 let result = new Array(); 533 let nodes = getUINativeModule().nodeAdapter.getAllItems(this.nativePtr_); 534 if (nodes !== undefined) { 535 nodes.forEach(node => { 536 let nodeId = node.nodeId; 537 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 538 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 539 result.push(frameNode); 540 } 541 }); 542 } 543 return result; 544 } 545 onAttachToNodePtr(target) { 546 let nodeId = target.nodeId; 547 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 548 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 549 if (frameNode === undefined) { 550 return; 551 } 552 frameNode.setAdapterRef(this); 553 this.attachedNodeRef_ = new WeakRef(frameNode); 554 if (this.onAttachToNode !== undefined) { 555 this.onAttachToNode(frameNode); 556 } 557 } 558 } 559 onDetachFromNodePtr() { 560 if (this === undefined) { 561 return; 562 } 563 if (this.onDetachFromNode !== undefined) { 564 this.onDetachFromNode(); 565 } 566 let attachedNode = this.attachedNodeRef_.deref(); 567 if (attachedNode !== undefined) { 568 attachedNode.setAdapterRef(undefined); 569 } 570 this.nodeRefs_.splice(0, this.nodeRefs_.length); 571 } 572 onCreateNewNodePtr(index) { 573 if (this.onCreateChild !== undefined) { 574 let node = this.onCreateChild(index); 575 if (!this.nodeRefs_.includes(node)) { 576 this.nodeRefs_.push(node); 577 } 578 return node.getNodePtr(); 579 } 580 return null; 581 } 582 onDisposeNodePtr(id, node) { 583 let nodeId = node.nodeId; 584 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 585 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 586 if (this.onDisposeChild !== undefined && frameNode !== undefined) { 587 this.onDisposeChild(id, frameNode); 588 let index = this.nodeRefs_.indexOf(frameNode); 589 if (index > -1) { 590 this.nodeRefs_.splice(index, 1); 591 } 592 } 593 } 594 } 595 onUpdateNodePtr(id, node) { 596 let nodeId = node.nodeId; 597 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 598 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 599 if (this.onUpdateChild !== undefined && frameNode !== undefined) { 600 this.onUpdateChild(id, frameNode); 601 } 602 } 603 } 604 static attachNodeAdapter(adapter, node) { 605 if (node === null || node === undefined) { 606 return false; 607 } 608 if (!node.isModifiable()) { 609 return false; 610 } 611 const hasAttributeProperty = Object.prototype.hasOwnProperty.call(node, 'attribute_'); 612 if (hasAttributeProperty) { 613 let frameeNode = node; 614 if (frameeNode.attribute_.allowChildCount !== undefined) { 615 const allowCount = frameeNode.attribute_.allowChildCount(); 616 if (allowCount <= 1) { 617 return false; 618 } 619 } 620 } 621 return getUINativeModule().nodeAdapter.attachNodeAdapter(adapter.nativePtr_, node.getNodePtr()); 622 } 623 static detachNodeAdapter(node) { 624 if (node === null || node === undefined) { 625 return; 626 } 627 getUINativeModule().nodeAdapter.detachNodeAdapter(node.getNodePtr()); 628 } 629} 630/* 631 * Copyright (c) 2024 Huawei Device Co., Ltd. 632 * Licensed under the Apache License, Version 2.0 (the "License"); 633 * you may not use this file except in compliance with the License. 634 * You may obtain a copy of the License at 635 * 636 * http://www.apache.org/licenses/LICENSE-2.0 637 * 638 * Unless required by applicable law or agreed to in writing, software 639 * distributed under the License is distributed on an "AS IS" BASIS, 640 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 641 * See the License for the specific language governing permissions and 642 * limitations under the License. 643 */ 644class BuilderNodeFinalizationRegisterProxy { 645 constructor() { 646 this.finalizationRegistry_ = new FinalizationRegistry((heldValue) => { 647 if (heldValue.name === 'BuilderRootFrameNode') { 648 const builderNode = BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.get(heldValue.idOfNode); 649 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.delete(heldValue.idOfNode); 650 builderNode.dispose(); 651 } 652 }); 653 } 654 static register(target, heldValue) { 655 BuilderNodeFinalizationRegisterProxy.instance_.finalizationRegistry_.register(target, heldValue); 656 } 657} 658BuilderNodeFinalizationRegisterProxy.instance_ = new BuilderNodeFinalizationRegisterProxy(); 659BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_ = new Map(); 660class FrameNodeFinalizationRegisterProxy { 661 constructor() { 662 this.finalizationRegistry_ = new FinalizationRegistry((heldValue) => { 663 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(heldValue); 664 }); 665 } 666 static register(target, heldValue) { 667 FrameNodeFinalizationRegisterProxy.instance_.finalizationRegistry_.register(target, heldValue); 668 } 669} 670FrameNodeFinalizationRegisterProxy.instance_ = new FrameNodeFinalizationRegisterProxy(); 671FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_ = new Map(); 672FrameNodeFinalizationRegisterProxy.FrameNodeInMainTree_ = new Map(); 673class NodeControllerRegisterProxy { 674} 675NodeControllerRegisterProxy.instance_ = new NodeControllerRegisterProxy(); 676NodeControllerRegisterProxy.__NodeControllerMap__ = new Map(); 677globalThis.__AddToNodeControllerMap__ = function __AddToNodeControllerMap__(containerId, nodeController) { 678 NodeControllerRegisterProxy.__NodeControllerMap__.set(containerId, nodeController); 679}; 680globalThis.__RemoveFromNodeControllerMap__ = function __RemoveFromNodeControllerMap__(containerId) { 681 let nodeController = NodeControllerRegisterProxy.__NodeControllerMap__.get(containerId); 682 nodeController._nodeContainerId.__rootNodeOfNodeController__ = undefined; 683 NodeControllerRegisterProxy.__NodeControllerMap__.delete(containerId); 684}; 685/* 686 * Copyright (c) 2023 Huawei Device Co., Ltd. 687 * Licensed under the Apache License, Version 2.0 (the "License"); 688 * you may not use this file except in compliance with the License. 689 * You may obtain a copy of the License at 690 * 691 * http://www.apache.org/licenses/LICENSE-2.0 692 * 693 * Unless required by applicable law or agreed to in writing, software 694 * distributed under the License is distributed on an "AS IS" BASIS, 695 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 696 * See the License for the specific language governing permissions and 697 * limitations under the License. 698 */ 699class __InternalField__ { 700 constructor() { 701 this._value = -1; 702 } 703} 704class NodeController { 705 constructor() { 706 this._nodeContainerId = new __InternalField__(); 707 } 708 __makeNode__(UIContext) { 709 this._nodeContainerId.__rootNodeOfNodeController__ = this.makeNode(UIContext); 710 return this._nodeContainerId.__rootNodeOfNodeController__; 711 } 712 rebuild() { 713 if (this._nodeContainerId !== undefined && this._nodeContainerId !== null && this._nodeContainerId._value >= 0) { 714 getUINativeModule().nodeContainer.rebuild(this._nodeContainerId._value); 715 } 716 } 717} 718/* 719 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 720 * Licensed under the Apache License, Version 2.0 (the "License"); 721 * you may not use this file except in compliance with the License. 722 * You may obtain a copy of the License at 723 * 724 * http://www.apache.org/licenses/LICENSE-2.0 725 * 726 * Unless required by applicable law or agreed to in writing, software 727 * distributed under the License is distributed on an "AS IS" BASIS, 728 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 729 * See the License for the specific language governing permissions and 730 * limitations under the License. 731 */ 732var ExpandMode; 733(function (ExpandMode) { 734 ExpandMode[ExpandMode["NOT_EXPAND"] = 0] = "NOT_EXPAND"; 735 ExpandMode[ExpandMode["EXPAND"] = 1] = "EXPAND"; 736 ExpandMode[ExpandMode["LAZY_EXPAND"] = 2] = "LAZY_EXPAND"; 737})(ExpandMode || (ExpandMode = {})); 738class FrameNode { 739 constructor(uiContext, type, options) { 740 if (uiContext === undefined) { 741 throw Error('Node constructor error, param uiContext error'); 742 } 743 else { 744 if (!(typeof uiContext === "object") || !("instanceId_" in uiContext)) { 745 throw Error('Node constructor error, param uiContext is invalid'); 746 } 747 } 748 this.instanceId_ = uiContext.instanceId_; 749 this.uiContext_ = uiContext; 750 this._nodeId = -1; 751 this._childList = new Map(); 752 if (type === 'BuilderRootFrameNode') { 753 this.renderNode_ = new RenderNode(type); 754 this.renderNode_.setFrameNode(new WeakRef(this)); 755 return; 756 } 757 if (type === 'ProxyFrameNode') { 758 return; 759 } 760 let result; 761 __JSScopeUtil__.syncInstanceId(this.instanceId_); 762 if (type === undefined || type === "CustomFrameNode") { 763 this.renderNode_ = new RenderNode('CustomFrameNode'); 764 result = getUINativeModule().frameNode.createFrameNode(this); 765 } 766 else { 767 result = getUINativeModule().frameNode.createTypedFrameNode(this, type, options); 768 } 769 __JSScopeUtil__.restoreInstanceId(); 770 this._nativeRef = result?.nativeStrongRef; 771 this._nodeId = result?.nodeId; 772 this.nodePtr_ = this._nativeRef?.getNativeHandle(); 773 this.renderNode_?.setNodePtr(result?.nativeStrongRef); 774 this.renderNode_?.setFrameNode(new WeakRef(this)); 775 if (result === undefined || this._nodeId === -1) { 776 return; 777 } 778 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(this._nodeId, new WeakRef(this)); 779 FrameNodeFinalizationRegisterProxy.register(this, this._nodeId); 780 } 781 invalidate() { 782 if (this.nodePtr_ === undefined || this.nodePtr_ === null) { 783 return; 784 } 785 getUINativeModule().frameNode.invalidate(this.nodePtr_); 786 } 787 getType() { 788 return 'CustomFrameNode'; 789 } 790 setRenderNode(nativeRef) { 791 this.renderNode_?.setNodePtr(nativeRef); 792 } 793 getRenderNode() { 794 if (this.renderNode_ !== undefined && 795 this.renderNode_ !== null && 796 this.renderNode_.getNodePtr() !== null) { 797 return this.renderNode_; 798 } 799 return null; 800 } 801 setNodePtr(nativeRef, nodePtr) { 802 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 803 this._nativeRef = nativeRef; 804 this.nodePtr_ = nodePtr ? nodePtr : this._nativeRef?.getNativeHandle(); 805 __JSScopeUtil__.syncInstanceId(this.instanceId_); 806 this._nodeId = getUINativeModule().frameNode.getIdByNodePtr(this.nodePtr_); 807 __JSScopeUtil__.restoreInstanceId(); 808 if (this._nodeId === -1) { 809 return; 810 } 811 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(this._nodeId, new WeakRef(this)); 812 FrameNodeFinalizationRegisterProxy.register(this, this._nodeId); 813 } 814 resetNodePtr() { 815 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 816 this._nodeId = -1; 817 this._nativeRef = null; 818 this.nodePtr_ = null; 819 this.renderNode_?.resetNodePtr(); 820 } 821 setBaseNode(baseNode) { 822 this.baseNode_ = baseNode; 823 this.renderNode_?.setBaseNode(baseNode); 824 } 825 setAdapterRef(adapter) { 826 this.nodeAdapterRef_ = adapter; 827 } 828 getNodePtr() { 829 return this.nodePtr_; 830 } 831 getValidNodePtr() { 832 const node = this.getNodePtr(); 833 if (node === null) { 834 throw Error('The FrameNode has been disposed!'); 835 } else { 836 return node; 837 } 838 } 839 dispose() { 840 this.renderNode_?.dispose(); 841 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 842 this._nodeId = -1; 843 this._nativeRef = null; 844 this.nodePtr_ = null; 845 } 846 static disposeTreeRecursively(node) { 847 if (node === null) { 848 return; 849 } 850 let child = node.getFirstChildWithoutExpand(); 851 FrameNode.disposeTreeRecursively(child); 852 let sibling = node.getNextSiblingWithoutExpand(); 853 FrameNode.disposeTreeRecursively(sibling); 854 node.dispose(); 855 } 856 disposeTree() { 857 let parent = this.getParent(); 858 if (parent?.getNodeType() === "NodeContainer") { 859 getUINativeModule().nodeContainer.clean(parent?.getNodePtr()); 860 } 861 else { 862 parent?.removeChild(this); 863 } 864 FrameNode.disposeTreeRecursively(this); 865 } 866 checkType() { 867 if (!this.isModifiable()) { 868 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 869 } 870 } 871 isModifiable() { 872 return this._nativeRef !== undefined && this._nativeRef !== null; 873 } 874 convertToFrameNode(nodePtr, nodeId = -1) { 875 if (nodeId === -1) { 876 __JSScopeUtil__.syncInstanceId(this.instanceId_); 877 nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 878 __JSScopeUtil__.restoreInstanceId(); 879 } 880 if (nodeId !== -1 && !getUINativeModule().frameNode.isModifiable(nodePtr)) { 881 __JSScopeUtil__.syncInstanceId(this.instanceId_); 882 let frameNode = new ProxyFrameNode(this.uiContext_); 883 let node = getUINativeModule().nativeUtils.createNativeWeakRef(nodePtr); 884 __JSScopeUtil__.restoreInstanceId(); 885 frameNode.setNodePtr(node); 886 frameNode._nodeId = nodeId; 887 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(frameNode._nodeId, new WeakRef(frameNode)); 888 FrameNodeFinalizationRegisterProxy.register(frameNode, frameNode._nodeId); 889 return frameNode; 890 } 891 return null; 892 } 893 checkValid(node) { 894 return true; 895 } 896 appendChild(node) { 897 if (node === undefined || node === null) { 898 return; 899 } 900 if (node.getType() === 'ProxyFrameNode' || !this.checkValid(node)) { 901 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 902 } 903 __JSScopeUtil__.syncInstanceId(this.instanceId_); 904 let flag = getUINativeModule().frameNode.appendChild(this.nodePtr_, node.nodePtr_); 905 __JSScopeUtil__.restoreInstanceId(); 906 if (!flag) { 907 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 908 } 909 this._childList.set(node._nodeId, node); 910 } 911 addComponentContent(content) { 912 if (content === undefined || content === null || content.getNodePtr() === null || content.getNodePtr() == undefined) { 913 return; 914 } 915 if (!this.checkValid() || !this.isModifiable()) { 916 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 917 } 918 __JSScopeUtil__.syncInstanceId(this.instanceId_); 919 let flag = getUINativeModule().frameNode.appendChild(this.nodePtr_, content.getNodeWithoutProxy()); 920 __JSScopeUtil__.restoreInstanceId(); 921 if (!flag) { 922 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 923 } 924 else { 925 content.setAttachedParent(new WeakRef(this)); 926 } 927 } 928 removeComponentContent(content) { 929 if (content === undefined || content === null || content.getNodePtr() === null || content.getNodePtr() === undefined) { 930 return; 931 } 932 __JSScopeUtil__.syncInstanceId(this.instanceId_); 933 getUINativeModule().frameNode.removeChild(this.nodePtr_, content.getNodePtr()); 934 content.setAttachedParent(undefined); 935 __JSScopeUtil__.restoreInstanceId(); 936 } 937 insertChildAfter(child, sibling) { 938 if (child === undefined || child === null) { 939 return; 940 } 941 if (child.getType() === 'ProxyFrameNode' || !this.checkValid(child)) { 942 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 943 } 944 let flag = true; 945 __JSScopeUtil__.syncInstanceId(this.instanceId_); 946 if (sibling === undefined || sibling === null) { 947 flag = getUINativeModule().frameNode.insertChildAfter(this.nodePtr_, child.nodePtr_, null); 948 } 949 else { 950 flag = getUINativeModule().frameNode.insertChildAfter(this.nodePtr_, child.nodePtr_, sibling.getNodePtr()); 951 } 952 __JSScopeUtil__.restoreInstanceId(); 953 if (!flag) { 954 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 955 } 956 this._childList.set(child._nodeId, child); 957 } 958 removeChild(node) { 959 if (node === undefined || node === null) { 960 return; 961 } 962 __JSScopeUtil__.syncInstanceId(this.instanceId_); 963 getUINativeModule().frameNode.removeChild(this.nodePtr_, node.nodePtr_); 964 __JSScopeUtil__.restoreInstanceId(); 965 this._childList.delete(node._nodeId); 966 } 967 clearChildren() { 968 __JSScopeUtil__.syncInstanceId(this.instanceId_); 969 getUINativeModule().frameNode.clearChildren(this.nodePtr_); 970 __JSScopeUtil__.restoreInstanceId(); 971 this._childList.clear(); 972 } 973 getChild(index, expandMode) { 974 const result = getUINativeModule().frameNode.getChild(this.getNodePtr(), index, expandMode); 975 const nodeId = result?.nodeId; 976 if (nodeId === undefined || nodeId === -1) { 977 return null; 978 } 979 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 980 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 981 return frameNode === undefined ? null : frameNode; 982 } 983 return this.convertToFrameNode(result.nodePtr, result.nodeId); 984 } 985 getFirstChildIndexWithoutExpand() { 986 return getUINativeModule().frameNode.getFirstChildIndexWithoutExpand(this.getNodePtr()); 987 } 988 getLastChildIndexWithoutExpand() { 989 return getUINativeModule().frameNode.getLastChildIndexWithoutExpand(this.getNodePtr()); 990 } 991 getFirstChild(isExpanded) { 992 const result = getUINativeModule().frameNode.getFirst(this.getNodePtr(), isExpanded); 993 const nodeId = result?.nodeId; 994 if (nodeId === undefined || nodeId === -1) { 995 return null; 996 } 997 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 998 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 999 return frameNode === undefined ? null : frameNode; 1000 } 1001 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1002 } 1003 getFirstChildWithoutExpand() { 1004 const result = getUINativeModule().frameNode.getFirst(this.getNodePtr(), false); 1005 const nodeId = result?.nodeId; 1006 if (nodeId === undefined || nodeId === -1) { 1007 return null; 1008 } 1009 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1010 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1011 return frameNode === undefined ? null : frameNode; 1012 } 1013 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1014 } 1015 getNextSibling(isExpanded) { 1016 const result = getUINativeModule().frameNode.getNextSibling(this.getNodePtr(), isExpanded); 1017 const nodeId = result?.nodeId; 1018 if (nodeId === undefined || nodeId === -1) { 1019 return null; 1020 } 1021 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1022 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1023 return frameNode === undefined ? null : frameNode; 1024 } 1025 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1026 } 1027 getNextSiblingWithoutExpand() { 1028 const result = getUINativeModule().frameNode.getNextSibling(this.getNodePtr(), false); 1029 const nodeId = result?.nodeId; 1030 if (nodeId === undefined || nodeId === -1) { 1031 return null; 1032 } 1033 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1034 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1035 return frameNode === undefined ? null : frameNode; 1036 } 1037 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1038 } 1039 getPreviousSibling(isExpanded) { 1040 const result = getUINativeModule().frameNode.getPreviousSibling(this.getNodePtr(), isExpanded); 1041 const nodeId = result?.nodeId; 1042 if (nodeId === undefined || nodeId === -1) { 1043 return null; 1044 } 1045 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1046 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1047 return frameNode === undefined ? null : frameNode; 1048 } 1049 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1050 } 1051 getParent() { 1052 const result = getUINativeModule().frameNode.getParent(this.getNodePtr()); 1053 const nodeId = result?.nodeId; 1054 if (nodeId === undefined || nodeId === -1) { 1055 return null; 1056 } 1057 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1058 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1059 return frameNode === undefined ? null : frameNode; 1060 } 1061 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1062 } 1063 getChildrenCount(isExpanded) { 1064 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1065 const childrenCount = getUINativeModule().frameNode.getChildrenCount(this.nodePtr_, isExpanded); 1066 __JSScopeUtil__.restoreInstanceId(); 1067 return childrenCount; 1068 } 1069 getPositionToParent() { 1070 const position = getUINativeModule().frameNode.getPositionToParent(this.getNodePtr()); 1071 return { x: position[0], y: position[1] }; 1072 } 1073 getPositionToScreen() { 1074 const position = getUINativeModule().frameNode.getPositionToScreen(this.getNodePtr()); 1075 return { x: position[0], y: position[1] }; 1076 } 1077 getPositionToWindow() { 1078 const position = getUINativeModule().frameNode.getPositionToWindow(this.getNodePtr()); 1079 return { x: position[0], y: position[1] }; 1080 } 1081 getPositionToParentWithTransform() { 1082 const position = getUINativeModule().frameNode.getPositionToParentWithTransform(this.getNodePtr()); 1083 return { x: position[0], y: position[1] }; 1084 } 1085 getPositionToScreenWithTransform() { 1086 const position = getUINativeModule().frameNode.getPositionToScreenWithTransform(this.getNodePtr()); 1087 return { x: position[0], y: position[1] }; 1088 } 1089 getPositionToWindowWithTransform() { 1090 const position = getUINativeModule().frameNode.getPositionToWindowWithTransform(this.getNodePtr()); 1091 return { x: position[0], y: position[1] }; 1092 } 1093 getMeasuredSize() { 1094 const size = getUINativeModule().frameNode.getMeasuredSize(this.getValidNodePtr()); 1095 return { width: size[0], height: size[1] }; 1096 } 1097 getLayoutPosition() { 1098 const position = getUINativeModule().frameNode.getLayoutPosition(this.getValidNodePtr()); 1099 return { x: position[0], y: position[1] }; 1100 } 1101 getUserConfigBorderWidth() { 1102 const borderWidth = getUINativeModule().frameNode.getConfigBorderWidth(this.getNodePtr()); 1103 return { 1104 top: new LengthMetrics(borderWidth[0], borderWidth[1]), 1105 right: new LengthMetrics(borderWidth[2], borderWidth[3]), 1106 bottom: new LengthMetrics(borderWidth[4], borderWidth[5]), 1107 left: new LengthMetrics(borderWidth[6], borderWidth[7]) 1108 }; 1109 } 1110 getUserConfigPadding() { 1111 const borderWidth = getUINativeModule().frameNode.getConfigPadding(this.getNodePtr()); 1112 return { 1113 top: new LengthMetrics(borderWidth[0], borderWidth[1]), 1114 right: new LengthMetrics(borderWidth[2], borderWidth[3]), 1115 bottom: new LengthMetrics(borderWidth[4], borderWidth[5]), 1116 left: new LengthMetrics(borderWidth[6], borderWidth[7]) 1117 }; 1118 } 1119 getUserConfigMargin() { 1120 const margin = getUINativeModule().frameNode.getConfigMargin(this.getNodePtr()); 1121 return { 1122 top: new LengthMetrics(margin[0], margin[1]), 1123 right: new LengthMetrics(margin[2], margin[3]), 1124 bottom: new LengthMetrics(margin[4], margin[5]), 1125 left: new LengthMetrics(margin[6], margin[7]) 1126 }; 1127 } 1128 getUserConfigSize() { 1129 const size = getUINativeModule().frameNode.getConfigSize(this.getNodePtr()); 1130 return { 1131 width: new LengthMetrics(size[0], size[1]), 1132 height: new LengthMetrics(size[2], size[3]) 1133 }; 1134 } 1135 getId() { 1136 return getUINativeModule().frameNode.getId(this.getNodePtr()); 1137 } 1138 getUniqueId() { 1139 return getUINativeModule().frameNode.getIdByNodePtr(this.getNodePtr()); 1140 } 1141 getNodeType() { 1142 return getUINativeModule().frameNode.getNodeType(this.getNodePtr()); 1143 } 1144 getOpacity() { 1145 return getUINativeModule().frameNode.getOpacity(this.getNodePtr()); 1146 } 1147 isVisible() { 1148 return getUINativeModule().frameNode.isVisible(this.getNodePtr()); 1149 } 1150 isClipToFrame() { 1151 return getUINativeModule().frameNode.isClipToFrame(this.getNodePtr()); 1152 } 1153 isAttached() { 1154 return getUINativeModule().frameNode.isAttached(this.getNodePtr()); 1155 } 1156 getInspectorInfo() { 1157 const inspectorInfoStr = getUINativeModule().frameNode.getInspectorInfo(this.getNodePtr()); 1158 const inspectorInfo = JSON.parse(inspectorInfoStr); 1159 return inspectorInfo; 1160 } 1161 getCustomProperty(key) { 1162 if (key === undefined) { 1163 return undefined; 1164 } 1165 let value = __getCustomProperty__(this._nodeId, key); 1166 if (value === undefined) { 1167 const valueStr = getUINativeModule().frameNode.getCustomPropertyCapiByKey(this.getNodePtr(), key); 1168 value = valueStr === undefined ? undefined : valueStr; 1169 } 1170 return value; 1171 } 1172 setMeasuredSize(size) { 1173 getUINativeModule().frameNode.setMeasuredSize(this.getNodePtr(), Math.max(size.width, 0), Math.max(size.height, 0)); 1174 } 1175 setLayoutPosition(position) { 1176 getUINativeModule().frameNode.setLayoutPosition(this.getNodePtr(), position.x, position.y); 1177 } 1178 measure(constraint) { 1179 const minSize = constraint.minSize; 1180 const maxSize = constraint.maxSize; 1181 const percentReference = constraint.percentReference; 1182 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1183 getUINativeModule().frameNode.measureNode(this.getNodePtr(), minSize.width, minSize.height, maxSize.width, maxSize.height, percentReference.width, percentReference.height); 1184 __JSScopeUtil__.restoreInstanceId(); 1185 } 1186 layout(position) { 1187 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1188 getUINativeModule().frameNode.layoutNode(this.getNodePtr(), position.x, position.y); 1189 __JSScopeUtil__.restoreInstanceId(); 1190 } 1191 setNeedsLayout() { 1192 getUINativeModule().frameNode.setNeedsLayout(this.getNodePtr()); 1193 } 1194 setCrossLanguageOptions(options) { 1195 if (!this.isModifiable()) { 1196 throw { message: 'The FrameNode cannot be set whether to support cross-language common attribute setting.', code: 100022 }; 1197 } 1198 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1199 const result = getUINativeModule().frameNode.setCrossLanguageOptions(this.getNodePtr(), options.attributeSetting ?? false); 1200 __JSScopeUtil__.restoreInstanceId(); 1201 if (result !== 0) { 1202 throw { message: 'The FrameNode cannot be set whether to support cross-language common attribute setting.', code: 100022 }; 1203 } 1204 } 1205 getCrossLanguageOptions() { 1206 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1207 const attributeSetting = getUINativeModule().frameNode.getCrossLanguageOptions(this.getNodePtr()); 1208 __JSScopeUtil__.restoreInstanceId(); 1209 return { attributeSetting: attributeSetting ?? false }; 1210 } 1211 checkIfCanCrossLanguageAttributeSetting() { 1212 return this.isModifiable() || getUINativeModule().frameNode.checkIfCanCrossLanguageAttributeSetting(this.getNodePtr()); 1213 } 1214 get commonAttribute() { 1215 if (this._commonAttribute === undefined) { 1216 this._commonAttribute = new ArkComponent(this.nodePtr_, ModifierType.FRAME_NODE); 1217 } 1218 this._commonAttribute.setNodePtr(this.nodePtr_); 1219 this._commonAttribute.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1220 return this._commonAttribute; 1221 } 1222 get commonEvent() { 1223 let node = this.getNodePtr(); 1224 if (this._commonEvent === undefined) { 1225 this._commonEvent = new UICommonEvent(node); 1226 } 1227 this._commonEvent.setNodePtr(node); 1228 this._commonEvent.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1229 return this._commonEvent; 1230 } 1231 get gestureEvent() { 1232 if (this._gestureEvent === undefined) { 1233 this._gestureEvent = new UIGestureEvent(); 1234 this._gestureEvent.setNodePtr(this.nodePtr_); 1235 let weakPtr = getUINativeModule().nativeUtils.createNativeWeakRef(this.nodePtr_); 1236 this._gestureEvent.setWeakNodePtr(weakPtr); 1237 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1238 this._gestureEvent.registerFrameNodeDeletedCallback(this.nodePtr_); 1239 __JSScopeUtil__.restoreInstanceId(); 1240 } 1241 return this._gestureEvent; 1242 } 1243 updateInstance(uiContext) { 1244 this.uiContext_ = uiContext; 1245 this.instanceId_ = uiContext.instanceId_; 1246 } 1247} 1248class ImmutableFrameNode extends FrameNode { 1249 isModifiable() { 1250 return false; 1251 } 1252 invalidate() { 1253 return; 1254 } 1255 appendChild(node) { 1256 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1257 } 1258 insertChildAfter(child, sibling) { 1259 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1260 } 1261 removeChild(node) { 1262 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1263 } 1264 clearChildren() { 1265 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1266 } 1267 get commonAttribute() { 1268 if (this._commonAttribute === undefined) { 1269 this._commonAttribute = new ArkComponent(undefined, ModifierType.FRAME_NODE); 1270 } 1271 this._commonAttribute.setNodePtr(undefined); 1272 return this._commonAttribute; 1273 } 1274} 1275class BuilderRootFrameNode extends ImmutableFrameNode { 1276 constructor(uiContext, type = 'BuilderRootFrameNode') { 1277 super(uiContext, type); 1278 } 1279 getType() { 1280 return 'BuilderRootFrameNode'; 1281 } 1282} 1283class ProxyFrameNode extends ImmutableFrameNode { 1284 constructor(uiContext, type = 'ProxyFrameNode') { 1285 super(uiContext, type); 1286 } 1287 setNodePtr(nativeRef) { 1288 this._nativeRef = nativeRef; 1289 this.nodePtr_ = this._nativeRef.getNativeHandle(); 1290 } 1291 getType() { 1292 return 'ProxyFrameNode'; 1293 } 1294 getRenderNode() { 1295 return null; 1296 } 1297 getNodePtr() { 1298 if (this._nativeRef === undefined || this._nativeRef === null || this._nativeRef.invalid()) { 1299 return null; 1300 } 1301 return this.nodePtr_; 1302 } 1303 dispose() { 1304 this.renderNode_?.dispose(); 1305 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 1306 this._nodeId = -1; 1307 this._nativeRef = undefined; 1308 this.nodePtr_ = undefined; 1309 } 1310} 1311class FrameNodeUtils { 1312 static searchNodeInRegisterProxy(nodePtr) { 1313 let nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 1314 if (nodeId === -1) { 1315 return null; 1316 } 1317 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1318 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1319 return frameNode === undefined ? null : frameNode; 1320 } 1321 return null; 1322 } 1323 static createFrameNode(uiContext, nodePtr) { 1324 let nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 1325 if (nodeId !== -1 && !getUINativeModule().frameNode.isModifiable(nodePtr)) { 1326 let frameNode = new ProxyFrameNode(uiContext); 1327 let node = getUINativeModule().nativeUtils.createNativeWeakRef(nodePtr); 1328 frameNode.setNodePtr(node); 1329 frameNode._nodeId = nodeId; 1330 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(nodeId, new WeakRef(frameNode)); 1331 FrameNodeFinalizationRegisterProxy.register(frameNode, nodeId); 1332 return frameNode; 1333 } 1334 return null; 1335 } 1336} 1337class TypedFrameNode extends FrameNode { 1338 constructor(uiContext, type, attrCreator, options) { 1339 super(uiContext, type, options); 1340 this.attrCreator_ = attrCreator; 1341 } 1342 initialize(...args) { 1343 return this.attribute.initialize(args); 1344 } 1345 get attribute() { 1346 if (this.attribute_ === undefined) { 1347 this.attribute_ = this.attrCreator_(this.nodePtr_, ModifierType.FRAME_NODE); 1348 } 1349 this.attribute_.setNodePtr(this.nodePtr_); 1350 this.attribute_.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1351 return this.attribute_; 1352 } 1353 checkValid(node) { 1354 if (this.attribute_ === undefined) { 1355 this.attribute_ = this.attrCreator_(this.nodePtr_, ModifierType.FRAME_NODE); 1356 } 1357 if (this.attribute_.allowChildCount !== undefined) { 1358 const allowCount = this.attribute_.allowChildCount(); 1359 if (this.getChildrenCount() >= allowCount) { 1360 return false; 1361 } 1362 } 1363 if (this.attribute_.allowChildTypes !== undefined && node !== undefined) { 1364 const childType = node.getNodeType(); 1365 const allowTypes = this.attribute_.allowChildTypes(); 1366 let isValid = false; 1367 allowTypes.forEach((nodeType) => { 1368 if (nodeType === childType) { 1369 isValid = true; 1370 } 1371 }); 1372 return isValid; 1373 } 1374 return true; 1375 } 1376} 1377const __creatorMap__ = new Map([ 1378 ['Text', (context) => { 1379 return new TypedFrameNode(context, 'Text', (node, type) => { 1380 return new ArkTextComponent(node, type); 1381 }); 1382 }], 1383 ['Column', (context) => { 1384 return new TypedFrameNode(context, 'Column', (node, type) => { 1385 return new ArkColumnComponent(node, type); 1386 }); 1387 }], 1388 ['Row', (context) => { 1389 return new TypedFrameNode(context, 'Row', (node, type) => { 1390 return new ArkRowComponent(node, type); 1391 }); 1392 }], 1393 ['Stack', (context) => { 1394 return new TypedFrameNode(context, 'Stack', (node, type) => { 1395 return new ArkStackComponent(node, type); 1396 }); 1397 }], 1398 ['GridRow', (context) => { 1399 let node = new TypedFrameNode(context, 'GridRow', (node, type) => { 1400 return new ArkGridRowComponent(node, type); 1401 }); 1402 node.initialize(); 1403 return node; 1404 }], 1405 ['TextInput', (context) => { 1406 return new TypedFrameNode(context, 'TextInput', (node, type) => { 1407 return new ArkTextInputComponent(node, type); 1408 }); 1409 }], 1410 ['GridCol', (context) => { 1411 let node = new TypedFrameNode(context, 'GridCol', (node, type) => { 1412 return new ArkGridColComponent(node, type); 1413 }); 1414 node.initialize(); 1415 return node; 1416 }], 1417 ['Blank', (context) => { 1418 return new TypedFrameNode(context, 'Blank', (node, type) => { 1419 return new ArkBlankComponent(node, type); 1420 }); 1421 }], 1422 ['Image', (context) => { 1423 return new TypedFrameNode(context, 'Image', (node, type) => { 1424 return new ArkImageComponent(node, type); 1425 }); 1426 }], 1427 ['Flex', (context) => { 1428 return new TypedFrameNode(context, 'Flex', (node, type) => { 1429 return new ArkFlexComponent(node, type); 1430 }); 1431 }], 1432 ['Swiper', (context) => { 1433 return new TypedFrameNode(context, 'Swiper', (node, type) => { 1434 return new ArkSwiperComponent(node, type); 1435 }); 1436 }], 1437 ['Progress', (context) => { 1438 return new TypedFrameNode(context, 'Progress', (node, type) => { 1439 return new ArkProgressComponent(node, type); 1440 }); 1441 }], 1442 ['Scroll', (context) => { 1443 return new TypedFrameNode(context, 'Scroll', (node, type) => { 1444 return new ArkScrollComponent(node, type); 1445 }); 1446 }], 1447 ['RelativeContainer', (context) => { 1448 return new TypedFrameNode(context, 'RelativeContainer', (node, type) => { 1449 return new ArkRelativeContainerComponent(node, type); 1450 }); 1451 }], 1452 ['List', (context) => { 1453 return new TypedFrameNode(context, 'List', (node, type) => { 1454 return new ArkListComponent(node, type); 1455 }); 1456 }], 1457 ['ListItem', (context) => { 1458 return new TypedFrameNode(context, 'ListItem', (node, type) => { 1459 return new ArkListItemComponent(node, type); 1460 }); 1461 }], 1462 ['Divider', (context) => { 1463 return new TypedFrameNode(context, 'Divider', (node, type) => { 1464 return new ArkDividerComponent(node, type); 1465 }); 1466 }], 1467 ['LoadingProgress', (context) => { 1468 return new TypedFrameNode(context, 'LoadingProgress', (node, type) => { 1469 return new ArkLoadingProgressComponent(node, type); 1470 }); 1471 }], 1472 ['Search', (context) => { 1473 return new TypedFrameNode(context, 'Search', (node, type) => { 1474 return new ArkSearchComponent(node, type); 1475 }); 1476 }], 1477 ['Button', (context) => { 1478 return new TypedFrameNode(context, 'Button', (node, type) => { 1479 return new ArkButtonComponent(node, type); 1480 }); 1481 }], 1482 ['XComponent', (context, options) => { 1483 return new TypedFrameNode(context, 'XComponent', (node, type) => { 1484 return new ArkXComponentComponent(node, type); 1485 }, options); 1486 }], 1487 ['ListItemGroup', (context) => { 1488 return new TypedFrameNode(context, 'ListItemGroup', (node, type) => { 1489 return new ArkListItemGroupComponent(node, type); 1490 }); 1491 }], 1492 ['WaterFlow', (context) => { 1493 return new TypedFrameNode(context, 'WaterFlow', (node, type) => { 1494 return new ArkWaterFlowComponent(node, type); 1495 }); 1496 }], 1497 ['SymbolGlyph', (context)=> { 1498 return new TypedFrameNode(context, 'SymbolGlyph', (node, type) => { 1499 return new ArkSymbolGlyphComponent(node, type); 1500 }); 1501 }], 1502 ['FlowItem', (context) => { 1503 return new TypedFrameNode(context, 'FlowItem', (node, type) => { 1504 return new ArkFlowItemComponent(node, type); 1505 }); 1506 }], 1507 ['Marquee', (context) => { 1508 return new TypedFrameNode(context, 'Marquee', (node, type) => { 1509 return new ArkMarqueeComponent(node, type); 1510 }); 1511 }], 1512 ['TextArea', (context) => { 1513 return new TypedFrameNode(context, 'TextArea', (node, type) => { 1514 return new ArkTextAreaComponent(node, type); 1515 }); 1516 }], 1517 ['QRCode', (context) => { 1518 return new TypedFrameNode(context, 'QRCode', (node, type) => { 1519 return new ArkQRCodeComponent(node, type); 1520 }); 1521 }], 1522 ['Badge', (context) => { 1523 return new TypedFrameNode(context, 'Badge', (node, type) => { 1524 return new ArkBadgeComponent(node, type); 1525 }); 1526 }], 1527 ['Grid', (context) => { 1528 return new TypedFrameNode(context, 'Grid', (node, type) => { 1529 return new ArkGridComponent(node, type); 1530 }); 1531 }], 1532 ['GridItem', (context) => { 1533 return new TypedFrameNode(context, 'GridItem', (node, type) => { 1534 return new ArkGridItemComponent(node, type); 1535 }); 1536 }], 1537 ['TextClock', (context) => { 1538 return new TypedFrameNode(context, 'TextClock', (node, type) => { 1539 return new ArkTextClockComponent(node, type); 1540 }); 1541 }], 1542 ['TextTimer', (context) => { 1543 return new TypedFrameNode(context, 'TextTimer', (node, type) => { 1544 return new ArkTextTimerComponent(node, type); 1545 }); 1546 }], 1547]); 1548const __attributeMap__ = new Map([ 1549 ['Scroll', (node) => { 1550 if (node._componentAttribute) { 1551 return node._componentAttribute; 1552 } 1553 if (!node.getNodePtr()) { 1554 return undefined; 1555 } 1556 node._componentAttribute = new ArkScrollComponent(node.getNodePtr(), ModifierType.FRAME_NODE); 1557 return node._componentAttribute; 1558 }], 1559]); 1560class typeNode { 1561 static createNode(context, type, options) { 1562 let creator = __creatorMap__.get(type); 1563 if (creator === undefined) { 1564 return undefined; 1565 } 1566 return creator(context, options); 1567 } 1568 static getAttribute(node, nodeType) { 1569 if (node === undefined || node === null || node.getNodeType() !== nodeType) { 1570 return undefined; 1571 } 1572 if (!node.checkIfCanCrossLanguageAttributeSetting()) { 1573 return undefined; 1574 } 1575 let attribute = __attributeMap__.get(nodeType); 1576 if (attribute === undefined || attribute === null) { 1577 return undefined; 1578 } 1579 return attribute(node); 1580 } 1581 static bindController(node, controller, nodeType) { 1582 if (node === undefined || node === null || controller === undefined || controller === null || 1583 node.getNodeType() !== nodeType || node.getNodePtr() === null || node.getNodePtr() === undefined) { 1584 throw { message: 'Parameter error. Possible causes: 1. The type of the node is error; 2. The node is null or undefined.', code: 401 }; 1585 } 1586 if (!node.checkIfCanCrossLanguageAttributeSetting()) { 1587 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1588 } 1589 getUINativeModule().scroll.setScrollInitialize(node.getNodePtr(), controller); 1590 } 1591} 1592/* 1593 * Copyright (c) 2023 Huawei Device Co., Ltd. 1594 * Licensed under the Apache License, Version 2.0 (the "License"); 1595 * you may not use this file except in compliance with the License. 1596 * You may obtain a copy of the License at 1597 * 1598 * http://www.apache.org/licenses/LICENSE-2.0 1599 * 1600 * Unless required by applicable law or agreed to in writing, software 1601 * distributed under the License is distributed on an "AS IS" BASIS, 1602 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1603 * See the License for the specific language governing permissions and 1604 * limitations under the License. 1605 */ 1606var BorderStyle; 1607(function (BorderStyle) { 1608 BorderStyle[BorderStyle["SOLID"] = 0] = "SOLID"; 1609 BorderStyle[BorderStyle["DASHED"] = 1] = "DASHED"; 1610 BorderStyle[BorderStyle["DOTTED"] = 2] = "DOTTED"; 1611 BorderStyle[BorderStyle["NONE"] = 3] = "NONE"; 1612})(BorderStyle || (BorderStyle = {})); 1613var LengthUnit; 1614(function (LengthUnit) { 1615 LengthUnit[LengthUnit["PX"] = 0] = "PX"; 1616 LengthUnit[LengthUnit["VP"] = 1] = "VP"; 1617 LengthUnit[LengthUnit["FP"] = 2] = "FP"; 1618 LengthUnit[LengthUnit["PERCENT"] = 3] = "PERCENT"; 1619 LengthUnit[LengthUnit["LPX"] = 4] = "LPX"; 1620})(LengthUnit || (LengthUnit = {})); 1621var LengthMetricsUnit; 1622(function (LengthMetricsUnit) { 1623 LengthMetricsUnit[LengthMetricsUnit["DEFAULT"] = 0] = "DEFAULT"; 1624 LengthMetricsUnit[LengthMetricsUnit["PX"] = 1] = "PX"; 1625})(LengthMetricsUnit || (LengthMetricsUnit = {})); 1626class LengthMetrics { 1627 constructor(value, unit) { 1628 if (unit in LengthUnit) { 1629 this.unit = unit; 1630 this.value = value; 1631 } else { 1632 1633 this.unit = LengthUnit.VP; 1634 this.value = unit === undefined ? value : 0; 1635 } 1636 } 1637 static px(value) { 1638 return new LengthMetrics(value, LengthUnit.PX); 1639 } 1640 static vp(value) { 1641 return new LengthMetrics(value, LengthUnit.VP); 1642 } 1643 static fp(value) { 1644 return new LengthMetrics(value, LengthUnit.FP); 1645 } 1646 static percent(value) { 1647 return new LengthMetrics(value, LengthUnit.PERCENT); 1648 } 1649 static lpx(value) { 1650 return new LengthMetrics(value, LengthUnit.LPX); 1651 } 1652 static resource(res) { 1653 let length = getUINativeModule().nativeUtils.resoureToLengthMetrics(res); 1654 return new LengthMetrics(length[0], length[1]); 1655 } 1656} 1657const MAX_CHANNEL_VALUE = 0xFF; 1658const MAX_ALPHA_VALUE = 1; 1659const ERROR_CODE_RESOURCE_GET_FAILED = 180003; 1660const ERROR_CODE_COLOR_PARAMETER_INCORRECT = 401; 1661class ColorMetrics { 1662 constructor(red, green, blue, alpha = MAX_CHANNEL_VALUE) { 1663 this.red_ = ColorMetrics.clamp(red); 1664 this.green_ = ColorMetrics.clamp(green); 1665 this.blue_ = ColorMetrics.clamp(blue); 1666 this.alpha_ = ColorMetrics.clamp(alpha); 1667 } 1668 static clamp(value) { 1669 return Math.min(Math.max(value, 0), MAX_CHANNEL_VALUE); 1670 } 1671 toNumeric() { 1672 return (this.alpha_ << 24) + (this.red_ << 16) + (this.green_ << 8) + this.blue_; 1673 } 1674 static numeric(value) { 1675 const red = (value >> 16) & 0x000000FF; 1676 const green = (value >> 8) & 0x000000FF; 1677 const blue = value & 0x000000FF; 1678 const alpha = (value >> 24) & 0x000000FF; 1679 if (alpha === 0) { 1680 return new ColorMetrics(red, green, blue); 1681 } 1682 return new ColorMetrics(red, green, blue, alpha); 1683 } 1684 static rgba(red, green, blue, alpha = MAX_ALPHA_VALUE) { 1685 return new ColorMetrics(red, green, blue, alpha * MAX_CHANNEL_VALUE); 1686 } 1687 static rgbOrRGBA(format) { 1688 const rgbPattern = /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i; 1689 const rgbaPattern = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+(\.\d+)?)\s*\)$/i; 1690 const rgbMatch = rgbPattern.exec(format); 1691 const rgbaMatch = rgbaPattern.exec(format); 1692 if (rgbMatch) { 1693 const [, red, green, blue] = rgbMatch; 1694 return new ColorMetrics(Number.parseInt(red, 10), Number.parseInt(green, 10), Number.parseInt(blue, 10)); 1695 } 1696 else if (rgbaMatch) { 1697 const [, red, green, blue, alpha] = rgbaMatch; 1698 return new ColorMetrics(Number.parseInt(red, 10), Number.parseInt(green, 10), Number.parseInt(blue, 10), Number.parseFloat(alpha) * MAX_CHANNEL_VALUE); 1699 } 1700 else { 1701 const error = new Error('Parameter error. The format of the input color string is not RGB or RGBA.'); 1702 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1703 throw error; 1704 } 1705 } 1706 static resourceColor(color) { 1707 if (color === undefined || color === null) { 1708 const error = new Error('Parameter error. The type of the input color parameter is not ResourceColor.'); 1709 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1710 throw error; 1711 } 1712 let chanels = []; 1713 if (typeof color === 'object') { 1714 chanels = getUINativeModule().nativeUtils.parseResourceColor(color); 1715 if (chanels === undefined) { 1716 const error = new Error('Failed to obtain the color resource.'); 1717 error.code = ERROR_CODE_RESOURCE_GET_FAILED; 1718 throw error; 1719 } 1720 const red = chanels[0]; 1721 const green = chanels[1]; 1722 const blue = chanels[2]; 1723 const alpha = chanels[3]; 1724 return new ColorMetrics(red, green, blue, alpha); 1725 } 1726 else if (typeof color === 'number') { 1727 return ColorMetrics.numeric(color); 1728 } 1729 else if (typeof color === 'string') { 1730 if (ColorMetrics.isHexFormat(color)) { 1731 return ColorMetrics.hex(color); 1732 } 1733 else { 1734 return ColorMetrics.rgbOrRGBA(color); 1735 } 1736 } 1737 else { 1738 const error = new Error('Parameter error. The type of the input color parameter is not ResourceColor.'); 1739 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1740 throw error; 1741 } 1742 } 1743 static isHexFormat(format) { 1744 return /#(([0-9A-Fa-f]{3})|([0-9A-Fa-f]{6})|([0-9A-Fa-f]{4})|([0-9A-Fa-f]{8}))/.test(format); 1745 } 1746 static hex(hexFormat) { 1747 let r = 0; 1748 let g = 0; 1749 let b = 0; 1750 let a = 255; 1751 if (hexFormat.length === 4) { 1752 r = parseInt(hexFormat.slice(1, 2).repeat(2), 16); 1753 g = parseInt(hexFormat.slice(2, 3).repeat(2), 16); 1754 b = parseInt(hexFormat.slice(3).repeat(2), 16); 1755 } 1756 else if (hexFormat.length === 7) { 1757 r = parseInt(hexFormat.slice(1, 3), 16); 1758 g = parseInt(hexFormat.slice(3, 5), 16); 1759 b = parseInt(hexFormat.slice(5), 16); 1760 } 1761 else if (hexFormat.length === 5) { 1762 a = parseInt(hexFormat.slice(1, 2).repeat(2), 16); 1763 r = parseInt(hexFormat.slice(2, 3).repeat(2), 16); 1764 g = parseInt(hexFormat.slice(3, 4).repeat(2), 16); 1765 b = parseInt(hexFormat.slice(4).repeat(2), 16); 1766 } 1767 else if (hexFormat.length === 9) { 1768 a = parseInt(hexFormat.slice(1, 3), 16); 1769 r = parseInt(hexFormat.slice(3, 5), 16); 1770 g = parseInt(hexFormat.slice(5, 7), 16); 1771 b = parseInt(hexFormat.slice(7), 16); 1772 } 1773 return new ColorMetrics(r, g, b, a); 1774 } 1775 blendColor(overlayColor) { 1776 if (overlayColor === undefined || overlayColor === null) { 1777 const error = new Error('Parameter error. The type of the input parameter is not ColorMetrics.'); 1778 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1779 throw error; 1780 } 1781 const chanels = getUINativeModule().nativeUtils.blendColor(this.toNumeric(), overlayColor.toNumeric()); 1782 if (chanels === undefined) { 1783 const error = new Error('Parameter error. The type of the input parameter is not ColorMetrics.'); 1784 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1785 throw error; 1786 } 1787 const red = chanels[0]; 1788 const green = chanels[1]; 1789 const blue = chanels[2]; 1790 const alpha = chanels[3]; 1791 return new ColorMetrics(red, green, blue, alpha); 1792 } 1793 get color() { 1794 return `rgba(${this.red_}, ${this.green_}, ${this.blue_}, ${this.alpha_ / MAX_CHANNEL_VALUE})`; 1795 } 1796 get red() { 1797 return this.red_; 1798 } 1799 get green() { 1800 return this.green_; 1801 } 1802 get blue() { 1803 return this.blue_; 1804 } 1805 get alpha() { 1806 return this.alpha_; 1807 } 1808} 1809class BaseShape { 1810 constructor() { 1811 this.rect = null; 1812 this.roundRect = null; 1813 this.circle = null; 1814 this.oval = null; 1815 this.path = null; 1816 } 1817 setRectShape(rect) { 1818 this.rect = rect; 1819 this.roundRect = null; 1820 this.circle = null; 1821 this.oval = null; 1822 this.path = null; 1823 } 1824 setRoundRectShape(roundRect) { 1825 this.roundRect = roundRect; 1826 this.rect = null; 1827 this.circle = null; 1828 this.oval = null; 1829 this.path = null; 1830 } 1831 setCircleShape(circle) { 1832 this.circle = circle; 1833 this.rect = null; 1834 this.roundRect = null; 1835 this.oval = null; 1836 this.path = null; 1837 } 1838 setOvalShape(oval) { 1839 this.oval = oval; 1840 this.rect = null; 1841 this.circle = null; 1842 this.roundRect = null; 1843 this.path = null; 1844 } 1845 setCommandPath(path) { 1846 this.path = path; 1847 this.oval = null; 1848 this.rect = null; 1849 this.circle = null; 1850 this.roundRect = null; 1851 } 1852} 1853class ShapeClip extends BaseShape { 1854} 1855class ShapeMask extends BaseShape { 1856 constructor(...args) { 1857 super(...args); 1858 this.fillColor = 0XFF000000; 1859 this.strokeColor = 0XFF000000; 1860 this.strokeWidth = 0; 1861 } 1862} 1863class RenderNode { 1864 constructor(type) { 1865 this.nodePtr = null; 1866 this.childrenList = []; 1867 this.parentRenderNode = null; 1868 this.backgroundColorValue = 0; 1869 this.apiTargetVersion = getUINativeModule().common.getApiTargetVersion(); 1870 this.clipToFrameValue = true; 1871 if (this.apiTargetVersion && this.apiTargetVersion < 12) { 1872 this.clipToFrameValue = false; 1873 } 1874 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 1875 this.opacityValue = 1.0; 1876 this.pivotValue = { x: 0.5, y: 0.5 }; 1877 this.rotationValue = { x: 0, y: 0, z: 0 }; 1878 this.scaleValue = { x: 1.0, y: 1.0 }; 1879 this.shadowColorValue = 0; 1880 this.shadowOffsetValue = { x: 0, y: 0 }; 1881 this.labelValue = ''; 1882 this.shadowAlphaValue = 0; 1883 this.shadowElevationValue = 0; 1884 this.shadowRadiusValue = 0; 1885 this.transformValue = [1, 0, 0, 0, 1886 0, 1, 0, 0, 1887 0, 0, 1, 0, 1888 0, 0, 0, 1]; 1889 this.translationValue = { x: 0, y: 0 }; 1890 this.lengthMetricsUnitValue = LengthMetricsUnit.DEFAULT; 1891 this.markNodeGroupValue = false; 1892 if (type === 'BuilderRootFrameNode' || type === 'CustomFrameNode') { 1893 return; 1894 } 1895 this._nativeRef = getUINativeModule().renderNode.createRenderNode(this); 1896 this.nodePtr = this._nativeRef?.getNativeHandle(); 1897 if (this.apiTargetVersion && this.apiTargetVersion < 12) { 1898 this.clipToFrame = false; 1899 } else { 1900 this.clipToFrame = true; 1901 } 1902 } 1903 set backgroundColor(color) { 1904 this.backgroundColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 1905 getUINativeModule().renderNode.setBackgroundColor(this.nodePtr, this.backgroundColorValue); 1906 } 1907 set clipToFrame(useClip) { 1908 this.clipToFrameValue = this.checkUndefinedOrNullWithDefaultValue(useClip, true); 1909 getUINativeModule().renderNode.setClipToFrame(this.nodePtr, this.clipToFrameValue); 1910 } 1911 set frame(frame) { 1912 if (frame === undefined || frame === null) { 1913 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 1914 } 1915 else { 1916 this.size = { width: frame.width, height: frame.height }; 1917 this.position = { x: frame.x, y: frame.y }; 1918 } 1919 } 1920 set opacity(value) { 1921 this.opacityValue = this.checkUndefinedOrNullWithDefaultValue(value, 1.0); 1922 getUINativeModule().common.setOpacity(this.nodePtr, this.opacityValue); 1923 } 1924 set pivot(pivot) { 1925 if (pivot === undefined || pivot === null) { 1926 this.pivotValue = { x: 0.5, y: 0.5 }; 1927 } 1928 else { 1929 this.pivotValue.x = this.checkUndefinedOrNullWithDefaultValue(pivot.x, 0.5); 1930 this.pivotValue.y = this.checkUndefinedOrNullWithDefaultValue(pivot.y, 0.5); 1931 } 1932 getUINativeModule().renderNode.setPivot(this.nodePtr, this.pivotValue.x, this.pivotValue.y); 1933 } 1934 set position(position) { 1935 if (position === undefined || position === null) { 1936 this.frameValue.x = 0; 1937 this.frameValue.y = 0; 1938 } 1939 else { 1940 this.frameValue.x = this.checkUndefinedOrNullWithDefaultValue(position.x, 0); 1941 this.frameValue.y = this.checkUndefinedOrNullWithDefaultValue(position.y, 0); 1942 } 1943 getUINativeModule().renderNode.setPosition(this.nodePtr, this.frameValue.x, this.frameValue.y, this.lengthMetricsUnitValue); 1944 } 1945 set rotation(rotation) { 1946 if (rotation === undefined || rotation === null) { 1947 this.rotationValue = { x: 0, y: 0, z: 0 }; 1948 } 1949 else { 1950 this.rotationValue.x = this.checkUndefinedOrNullWithDefaultValue(rotation.x, 0); 1951 this.rotationValue.y = this.checkUndefinedOrNullWithDefaultValue(rotation.y, 0); 1952 this.rotationValue.z = this.checkUndefinedOrNullWithDefaultValue(rotation.z, 0); 1953 } 1954 getUINativeModule().renderNode.setRotation(this.nodePtr, this.rotationValue.x, this.rotationValue.y, this.rotationValue.z, this.lengthMetricsUnitValue); 1955 } 1956 set scale(scale) { 1957 if (scale === undefined || scale === null) { 1958 this.scaleValue = { x: 1.0, y: 1.0 }; 1959 } 1960 else { 1961 this.scaleValue.x = this.checkUndefinedOrNullWithDefaultValue(scale.x, 1.0); 1962 this.scaleValue.y = this.checkUndefinedOrNullWithDefaultValue(scale.y, 1.0); 1963 } 1964 getUINativeModule().renderNode.setScale(this.nodePtr, this.scaleValue.x, this.scaleValue.y); 1965 } 1966 set shadowColor(color) { 1967 this.shadowColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 1968 getUINativeModule().renderNode.setShadowColor(this.nodePtr, this.shadowColorValue); 1969 } 1970 set shadowOffset(offset) { 1971 if (offset === undefined || offset === null) { 1972 this.shadowOffsetValue = { x: 0, y: 0 }; 1973 } 1974 else { 1975 this.shadowOffsetValue.x = this.checkUndefinedOrNullWithDefaultValue(offset.x, 0); 1976 this.shadowOffsetValue.y = this.checkUndefinedOrNullWithDefaultValue(offset.y, 0); 1977 } 1978 getUINativeModule().renderNode.setShadowOffset(this.nodePtr, this.shadowOffsetValue.x, this.shadowOffsetValue.y, this.lengthMetricsUnitValue); 1979 } 1980 set label(label) { 1981 this.labelValue = this.checkUndefinedOrNullWithDefaultValue(label, ''); 1982 getUINativeModule().renderNode.setLabel(this.nodePtr, this.labelValue); 1983 } 1984 set shadowAlpha(alpha) { 1985 this.shadowAlphaValue = this.checkUndefinedOrNullWithDefaultValue(alpha, 0); 1986 getUINativeModule().renderNode.setShadowAlpha(this.nodePtr, this.shadowAlphaValue); 1987 } 1988 set shadowElevation(elevation) { 1989 this.shadowElevationValue = this.checkUndefinedOrNullWithDefaultValue(elevation, 0); 1990 getUINativeModule().renderNode.setShadowElevation(this.nodePtr, this.shadowElevationValue); 1991 } 1992 set shadowRadius(radius) { 1993 this.shadowRadiusValue = this.checkUndefinedOrNullWithDefaultValue(radius, 0); 1994 getUINativeModule().renderNode.setShadowRadius(this.nodePtr, this.shadowRadiusValue); 1995 } 1996 set size(size) { 1997 if (size === undefined || size === null) { 1998 this.frameValue.width = 0; 1999 this.frameValue.height = 0; 2000 } 2001 else { 2002 this.frameValue.width = this.checkUndefinedOrNullWithDefaultValue(size.width, 0); 2003 this.frameValue.height = this.checkUndefinedOrNullWithDefaultValue(size.height, 0); 2004 } 2005 getUINativeModule().renderNode.setSize(this.nodePtr, this.frameValue.width, this.frameValue.height, this.lengthMetricsUnitValue); 2006 } 2007 set transform(transform) { 2008 if (transform === undefined || transform === null) { 2009 this.transformValue = [1, 0, 0, 0, 2010 0, 1, 0, 0, 2011 0, 0, 1, 0, 2012 0, 0, 0, 1]; 2013 } 2014 else { 2015 let i = 0; 2016 while (i < transform.length && i < 16) { 2017 if (i % 5 === 0) { 2018 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 1); 2019 } 2020 else { 2021 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 0); 2022 } 2023 i = i + 1; 2024 } 2025 } 2026 getUINativeModule().common.setTransform(this.nodePtr, this.transformValue); 2027 } 2028 set translation(translation) { 2029 if (translation === undefined || translation === null) { 2030 this.translationValue = { x: 0, y: 0 }; 2031 } 2032 else { 2033 this.translationValue.x = this.checkUndefinedOrNullWithDefaultValue(translation.x, 0); 2034 this.translationValue.y = this.checkUndefinedOrNullWithDefaultValue(translation.y, 0); 2035 } 2036 getUINativeModule().renderNode.setTranslate(this.nodePtr, this.translationValue.x, this.translationValue.y, 0); 2037 } 2038 set lengthMetricsUnit(unit) { 2039 if (unit === undefined || unit == null) { 2040 this.lengthMetricsUnitValue = LengthMetricsUnit.DEFAULT; 2041 } 2042 else { 2043 this.lengthMetricsUnitValue = unit; 2044 } 2045 } 2046 set markNodeGroup(isNodeGroup) { 2047 if (isNodeGroup === undefined || isNodeGroup === null) { 2048 this.markNodeGroupValue = false; 2049 } 2050 else { 2051 this.markNodeGroupValue = isNodeGroup; 2052 } 2053 getUINativeModule().renderNode.setMarkNodeGroup(this.nodePtr, this.markNodeGroupValue); 2054 } 2055 get backgroundColor() { 2056 return this.backgroundColorValue; 2057 } 2058 get clipToFrame() { 2059 return this.clipToFrameValue; 2060 } 2061 get opacity() { 2062 return this.opacityValue; 2063 } 2064 get frame() { 2065 return this.frameValue; 2066 } 2067 get pivot() { 2068 return this.pivotValue; 2069 } 2070 get position() { 2071 return { x: this.frameValue.x, y: this.frameValue.y }; 2072 } 2073 get rotation() { 2074 return this.rotationValue; 2075 } 2076 get scale() { 2077 return this.scaleValue; 2078 } 2079 get shadowColor() { 2080 return this.shadowColorValue; 2081 } 2082 get shadowOffset() { 2083 return this.shadowOffsetValue; 2084 } 2085 get label() { 2086 return this.labelValue; 2087 } 2088 get shadowAlpha() { 2089 return this.shadowAlphaValue; 2090 } 2091 get shadowElevation() { 2092 return this.shadowElevationValue; 2093 } 2094 get shadowRadius() { 2095 return this.shadowRadiusValue; 2096 } 2097 get size() { 2098 return { width: this.frameValue.width, height: this.frameValue.height }; 2099 } 2100 get transform() { 2101 return this.transformValue; 2102 } 2103 get translation() { 2104 return this.translationValue; 2105 } 2106 get lengthMetricsUnit() { 2107 return this.lengthMetricsUnitValue; 2108 } 2109 get markNodeGroup() { 2110 return this.markNodeGroupValue; 2111 } 2112 checkUndefinedOrNullWithDefaultValue(arg, defaultValue) { 2113 if (arg === undefined || arg === null) { 2114 return defaultValue; 2115 } 2116 else { 2117 return arg; 2118 } 2119 } 2120 appendChild(node) { 2121 if (node === undefined || node === null) { 2122 return; 2123 } 2124 if (this.childrenList.findIndex(element => element === node) !== -1) { 2125 return; 2126 } 2127 this.childrenList.push(node); 2128 node.parentRenderNode = new WeakRef(this); 2129 getUINativeModule().renderNode.appendChild(this.nodePtr, node.nodePtr); 2130 } 2131 insertChildAfter(child, sibling) { 2132 if (child === undefined || child === null) { 2133 return; 2134 } 2135 let indexOfNode = this.childrenList.findIndex(element => element === child); 2136 if (indexOfNode !== -1) { 2137 return; 2138 } 2139 child.parentRenderNode = new WeakRef(this); 2140 let indexOfSibling = this.childrenList.findIndex(element => element === sibling); 2141 if (indexOfSibling === -1) { 2142 sibling === null; 2143 } 2144 if (sibling === undefined || sibling === null) { 2145 this.childrenList.splice(0, 0, child); 2146 getUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, null); 2147 } 2148 else { 2149 this.childrenList.splice(indexOfSibling + 1, 0, child); 2150 getUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, sibling.nodePtr); 2151 } 2152 } 2153 removeChild(node) { 2154 if (node === undefined || node === null) { 2155 return; 2156 } 2157 const index = this.childrenList.findIndex(element => element === node); 2158 if (index === -1) { 2159 return; 2160 } 2161 const child = this.childrenList[index]; 2162 child.parentRenderNode = null; 2163 this.childrenList.splice(index, 1); 2164 getUINativeModule().renderNode.removeChild(this.nodePtr, node.nodePtr); 2165 } 2166 clearChildren() { 2167 this.childrenList = new Array(); 2168 getUINativeModule().renderNode.clearChildren(this.nodePtr); 2169 } 2170 getChild(index) { 2171 if (this.childrenList.length > index && index >= 0) { 2172 return this.childrenList[index]; 2173 } 2174 return null; 2175 } 2176 getFirstChild() { 2177 if (this.childrenList.length > 0) { 2178 return this.childrenList[0]; 2179 } 2180 return null; 2181 } 2182 getNextSibling() { 2183 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 2184 return null; 2185 } 2186 let parent = this.parentRenderNode.deref(); 2187 if (parent === undefined || parent === null) { 2188 return null; 2189 } 2190 let siblingList = parent.childrenList; 2191 const index = siblingList.findIndex(element => element === this); 2192 if (index === -1) { 2193 return null; 2194 } 2195 return parent.getChild(index + 1); 2196 } 2197 getPreviousSibling() { 2198 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 2199 return null; 2200 } 2201 let parent = this.parentRenderNode.deref(); 2202 if (parent === undefined || parent === null) { 2203 return null; 2204 } 2205 let siblingList = parent.childrenList; 2206 const index = siblingList.findIndex(element => element === this); 2207 if (index === -1) { 2208 return null; 2209 } 2210 return parent.getChild(index - 1); 2211 } 2212 setFrameNode(frameNode) { 2213 this._frameNode = frameNode; 2214 } 2215 setNodePtr(nativeRef) { 2216 this._nativeRef = nativeRef; 2217 this.nodePtr = this._nativeRef?.getNativeHandle(); 2218 } 2219 setBaseNode(baseNode) { 2220 this.baseNode_ = baseNode; 2221 } 2222 resetNodePtr() { 2223 this.nodePtr = null; 2224 this._nativeRef = null; 2225 } 2226 dispose() { 2227 this._nativeRef?.dispose(); 2228 this.baseNode_?.disposeNode(); 2229 this._frameNode?.deref()?.resetNodePtr(); 2230 this._nativeRef = null; 2231 this.nodePtr = null; 2232 } 2233 getNodePtr() { 2234 return this.nodePtr; 2235 } 2236 invalidate() { 2237 getUINativeModule().renderNode.invalidate(this.nodePtr); 2238 } 2239 set borderStyle(style) { 2240 if (style === undefined || style === null) { 2241 this.borderStyleValue = { left: BorderStyle.NONE, top: BorderStyle.NONE, right: BorderStyle.NONE, bottom: BorderStyle.NONE }; 2242 } 2243 else { 2244 this.borderStyleValue = style; 2245 } 2246 getUINativeModule().renderNode.setBorderStyle(this.nodePtr, this.borderStyleValue.left, this.borderStyleValue.top, this.borderStyleValue.right, this.borderStyleValue.bottom); 2247 } 2248 get borderStyle() { 2249 return this.borderStyleValue; 2250 } 2251 set borderWidth(width) { 2252 if (width === undefined || width === null) { 2253 this.borderWidthValue = { left: 0, top: 0, right: 0, bottom: 0 }; 2254 } 2255 else { 2256 this.borderWidthValue = width; 2257 } 2258 getUINativeModule().renderNode.setBorderWidth(this.nodePtr, this.borderWidthValue.left, this.borderWidthValue.top, this.borderWidthValue.right, this.borderWidthValue.bottom, this.lengthMetricsUnitValue); 2259 } 2260 get borderWidth() { 2261 return this.borderWidthValue; 2262 } 2263 set borderColor(color) { 2264 if (color === undefined || color === null) { 2265 this.borderColorValue = { left: 0XFF000000, top: 0XFF000000, right: 0XFF000000, bottom: 0XFF000000 }; 2266 } 2267 else { 2268 this.borderColorValue = color; 2269 } 2270 getUINativeModule().renderNode.setBorderColor(this.nodePtr, this.borderColorValue.left, this.borderColorValue.top, this.borderColorValue.right, this.borderColorValue.bottom); 2271 } 2272 get borderColor() { 2273 return this.borderColorValue; 2274 } 2275 set borderRadius(radius) { 2276 if (radius === undefined || radius === null) { 2277 this.borderRadiusValue = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0 }; 2278 } 2279 else { 2280 this.borderRadiusValue = radius; 2281 } 2282 getUINativeModule().renderNode.setBorderRadius(this.nodePtr, this.borderRadiusValue.topLeft, this.borderRadiusValue.topRight, this.borderRadiusValue.bottomLeft, this.borderRadiusValue.bottomRight, this.lengthMetricsUnitValue); 2283 } 2284 get borderRadius() { 2285 return this.borderRadiusValue; 2286 } 2287 set shapeMask(shapeMask) { 2288 if (shapeMask === undefined || shapeMask === null) { 2289 this.shapeMaskValue = new ShapeMask(); 2290 } 2291 else { 2292 this.shapeMaskValue = shapeMask; 2293 } 2294 if (this.shapeMaskValue.rect !== null) { 2295 const rectMask = this.shapeMaskValue.rect; 2296 getUINativeModule().renderNode.setRectMask(this.nodePtr, rectMask.left, rectMask.top, rectMask.right, rectMask.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2297 } 2298 else if (this.shapeMaskValue.circle !== null) { 2299 const circle = this.shapeMaskValue.circle; 2300 getUINativeModule().renderNode.setCircleMask(this.nodePtr, circle.centerX, circle.centerY, circle.radius, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2301 } 2302 else if (this.shapeMaskValue.roundRect !== null) { 2303 const roundRect = this.shapeMask.roundRect; 2304 const corners = roundRect.corners; 2305 const rect = roundRect.rect; 2306 getUINativeModule().renderNode.setRoundRectMask(this.nodePtr, corners.topLeft.x, corners.topLeft.y, corners.topRight.x, corners.topRight.y, corners.bottomLeft.x, corners.bottomLeft.y, corners.bottomRight.x, corners.bottomRight.y, rect.left, rect.top, rect.right, rect.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2307 } 2308 else if (this.shapeMaskValue.oval !== null) { 2309 const oval = this.shapeMaskValue.oval; 2310 getUINativeModule().renderNode.setOvalMask(this.nodePtr, oval.left, oval.top, oval.right, oval.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2311 } 2312 else if (this.shapeMaskValue.path !== null) { 2313 const path = this.shapeMaskValue.path; 2314 getUINativeModule().renderNode.setPath(this.nodePtr, path.commands, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2315 } 2316 } 2317 get shapeMask() { 2318 return this.shapeMaskValue; 2319 } 2320 set shapeClip(shapeClip) { 2321 if (shapeClip === undefined || shapeClip === null) { 2322 this.shapeClipValue = new ShapeClip(); 2323 } 2324 else { 2325 this.shapeClipValue = shapeClip; 2326 } 2327 if (this.shapeClipValue.rect !== null) { 2328 const rectClip = this.shapeClipValue.rect; 2329 getUINativeModule().renderNode.setRectClip(this.nodePtr, rectClip.left, rectClip.top, rectClip.right, rectClip.bottom); 2330 } 2331 else if (this.shapeClipValue.circle !== null) { 2332 const circle = this.shapeClipValue.circle; 2333 getUINativeModule().renderNode.setCircleClip(this.nodePtr, circle.centerX, circle.centerY, circle.radius); 2334 } 2335 else if (this.shapeClipValue.roundRect !== null) { 2336 const roundRect = this.shapeClipValue.roundRect; 2337 const corners = roundRect.corners; 2338 const rect = roundRect.rect; 2339 getUINativeModule().renderNode.setRoundRectClip(this.nodePtr, corners.topLeft.x, corners.topLeft.y, corners.topRight.x, corners.topRight.y, corners.bottomLeft.x, corners.bottomLeft.y, corners.bottomRight.x, corners.bottomRight.y, rect.left, rect.top, rect.right, rect.bottom); 2340 } 2341 else if (this.shapeClipValue.oval !== null) { 2342 const oval = this.shapeClipValue.oval; 2343 getUINativeModule().renderNode.setOvalClip(this.nodePtr, oval.left, oval.top, oval.right, oval.bottom); 2344 } 2345 else if (this.shapeClipValue.path !== null) { 2346 const path = this.shapeClipValue.path; 2347 getUINativeModule().renderNode.setPathClip(this.nodePtr, path.commands); 2348 } 2349 } 2350 get shapeClip() { 2351 this.shapeClipValue = this.shapeClipValue ? this.shapeClipValue : new ShapeClip(); 2352 return this.shapeClipValue; 2353 } 2354} 2355function edgeColors(all) { 2356 return { left: all, top: all, right: all, bottom: all }; 2357} 2358function edgeWidths(all) { 2359 return { left: all, top: all, right: all, bottom: all }; 2360} 2361function borderStyles(all) { 2362 return { left: all, top: all, right: all, bottom: all }; 2363} 2364function borderRadiuses(all) { 2365 return { topLeft: all, topRight: all, bottomLeft: all, bottomRight: all }; 2366} 2367/* 2368 * Copyright (c) 2023 Huawei Device Co., Ltd. 2369 * Licensed under the Apache License, Version 2.0 (the "License"); 2370 * you may not use this file except in compliance with the License. 2371 * You may obtain a copy of the License at 2372 * 2373 * http://www.apache.org/licenses/LICENSE-2.0 2374 * 2375 * Unless required by applicable law or agreed to in writing, software 2376 * distributed under the License is distributed on an "AS IS" BASIS, 2377 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2378 * See the License for the specific language governing permissions and 2379 * limitations under the License. 2380 */ 2381class XComponentNode extends FrameNode { 2382 constructor(uiContext, options, id, type, libraryname, controller) { 2383 super(uiContext, 'XComponentNode'); 2384 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 2385 this.xcomponentNode_ = getUINativeModule().xcomponentNode; 2386 this.renderType_ = options.type; 2387 const surfaceId = options.surfaceId; 2388 const selfIdealWidth = options.selfIdealSize.width; 2389 const selfIdealHeight = options.selfIdealSize.height; 2390 this.nativeModule_ = this.xcomponentNode_.create(elmtId, id, type, this.renderType_, surfaceId, selfIdealWidth, selfIdealHeight, libraryname, controller); 2391 this.xcomponentNode_.registerOnCreateCallback(this.nativeModule_, this.onCreate); 2392 this.xcomponentNode_.registerOnDestroyCallback(this.nativeModule_, this.onDestroy); 2393 this.nodePtr_ = this.xcomponentNode_.getFrameNode(this.nativeModule_); 2394 this.setNodePtr(getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_), this.nodePtr_); 2395 } 2396 onCreate(event) { } 2397 onDestroy() { } 2398 changeRenderType(type) { 2399 if (this.renderType_ === type) { 2400 return true; 2401 } 2402 if (this.xcomponentNode_.changeRenderType(this.nativeModule_, type)) { 2403 this.renderType_ = type; 2404 return true; 2405 } 2406 return false; 2407 } 2408} 2409/* 2410 * Copyright (c) 2024 Huawei Device Co., Ltd. 2411 * Licensed under the Apache License, Version 2.0 (the "License"); 2412 * you may not use this file except in compliance with the License. 2413 * You may obtain a copy of the License at 2414 * 2415 * http://www.apache.org/licenses/LICENSE-2.0 2416 * 2417 * Unless required by applicable law or agreed to in writing, software 2418 * distributed under the License is distributed on an "AS IS" BASIS, 2419 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2420 * See the License for the specific language governing permissions and 2421 * limitations under the License. 2422 */ 2423class Content { 2424 constructor() { } 2425 onAttachToWindow() { } 2426 onDetachFromWindow() { } 2427} 2428/* 2429 * Copyright (c) 2024 Huawei Device Co., Ltd. 2430 * Licensed under the Apache License, Version 2.0 (the "License"); 2431 * you may not use this file except in compliance with the License. 2432 * You may obtain a copy of the License at 2433 * 2434 * http://www.apache.org/licenses/LICENSE-2.0 2435 * 2436 * Unless required by applicable law or agreed to in writing, software 2437 * distributed under the License is distributed on an "AS IS" BASIS, 2438 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2439 * See the License for the specific language governing permissions and 2440 * limitations under the License. 2441 */ 2442/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" /> 2443 2444class ComponentContent extends Content { 2445 constructor(uiContext, builder, params, options) { 2446 super(); 2447 let builderNode = new BuilderNode(uiContext, {}); 2448 this.builderNode_ = builderNode; 2449 this.builderNode_.build(builder, params ?? undefined, options); 2450 } 2451 update(params) { 2452 this.builderNode_.update(params); 2453 } 2454 getFrameNode() { 2455 return this.builderNode_.getFrameNodeWithoutCheck(); 2456 } 2457 setAttachedParent(parent) { 2458 this.parentWeak_ = parent; 2459 } 2460 getNodePtr() { 2461 if (this.attachNodeRef_ !== undefined) { 2462 return this.attachNodeRef_.getNativeHandle(); 2463 } 2464 return this.builderNode_.getNodePtr(); 2465 } 2466 reuse(param) { 2467 this.builderNode_.reuse(param); 2468 } 2469 recycle() { 2470 this.builderNode_.recycle(); 2471 } 2472 dispose() { 2473 this.detachFromParent(); 2474 this.attachNodeRef_?.dispose(); 2475 this.builderNode_?.dispose(); 2476 } 2477 detachFromParent() { 2478 if (this.parentWeak_ === undefined) { 2479 return; 2480 } 2481 let parent = this.parentWeak_.deref(); 2482 if (parent !== undefined) { 2483 parent.removeComponentContent(this); 2484 } 2485 } 2486 getNodeWithoutProxy() { 2487 const node = this.getNodePtr(); 2488 const nodeType = getUINativeModule().frameNode.getNodeType(node); 2489 if (nodeType === "BuilderProxyNode") { 2490 const result = getUINativeModule().frameNode.getFirstUINode(node); 2491 this.attachNodeRef_ = getUINativeModule().nativeUtils.createNativeStrongRef(result); 2492 getUINativeModule().frameNode.removeChild(node, result); 2493 return result; 2494 } 2495 return node; 2496 } 2497 updateConfiguration() { 2498 this.builderNode_.updateConfiguration(); 2499 } 2500} 2501/* 2502 * Copyright (c) 2024 Huawei Device Co., Ltd. 2503 * Licensed under the Apache License, Version 2.0 (the "License"); 2504 * you may not use this file except in compliance with the License. 2505 * You may obtain a copy of the License at 2506 * 2507 * http://www.apache.org/licenses/LICENSE-2.0 2508 * 2509 * Unless required by applicable law or agreed to in writing, software 2510 * distributed under the License is distributed on an "AS IS" BASIS, 2511 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2512 * See the License for the specific language governing permissions and 2513 * limitations under the License. 2514 */ 2515class NodeContent extends Content { 2516 constructor() { 2517 super(); 2518 this.nativeRef_ = getUINativeModule().frameNode.createNodeContent(); 2519 this.nativePtr_ = this.nativeRef_.getNativeHandle(); 2520 this.nodeArray_ = new Array(); 2521 } 2522 addFrameNode(node) { 2523 if (this.nodeArray_.includes(node)) { 2524 return; 2525 } 2526 if (getUINativeModule().frameNode.addFrameNodeToNodeContent(node.getNodePtr(), this.nativePtr_)) { 2527 this.nodeArray_.push(node); 2528 } 2529 } 2530 removeFrameNode(node) { 2531 if (!this.nodeArray_.includes(node)) { 2532 return; 2533 } 2534 if (getUINativeModule().frameNode.removeFrameNodeFromNodeContent(node.getNodePtr(), this.nativePtr_)) { 2535 let index = this.nodeArray_.indexOf(node); 2536 if (index > -1) { 2537 this.nodeArray_.splice(index, 1); 2538 } 2539 } 2540 } 2541} 2542 2543export default { 2544 NodeController, BuilderNode, BaseNode, RenderNode, FrameNode, FrameNodeUtils, 2545 NodeRenderType, XComponentNode, LengthMetrics, ColorMetrics, LengthUnit, LengthMetricsUnit, ShapeMask, ShapeClip, 2546 edgeColors, edgeWidths, borderStyles, borderRadiuses, Content, ComponentContent, NodeContent, typeNode, NodeAdapter, 2547 ExpandMode 2548}; 2549