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