1/* 2 * Copyright (c) 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 */ 15 16var __decorate = this && this.__decorate || function (e, o, t, i) { 17 var n, r = arguments.length, l = r < 3 ? o : null === i ? i = Object.getOwnPropertyDescriptor(o, t) : i; 18 if ('object' === typeof Reflect && 'function' === typeof Reflect.decorate) { 19 l = Reflect.decorate(e, o, t, i); 20 } else { 21 for (var s = e.length - 1; s >= 0; s--) { 22 (n = e[s]) && (l = (r < 3 ? n(l) : r > 3 ? n(o, t, l) : n(o, t)) || l); 23 } 24 } 25 return r > 3 && l && Object.defineProperty(o, t, l), l; 26}; 27const fs = requireNapi('file.fs'); 28const fileUri = requireNapi('file.fileuri'); 29const bundleManager = requireNapi('bundle.bundleManager'); 30const LengthMetrics = requireNapi('arkui.node').LengthMetrics; 31const LengthUnit = requireNapi('arkui.node').LengthUnit; 32const photoAccessHelper = requireNapi('file.photoAccessHelper'); 33const PHOTO_VIEW_MIME_TYPE_MAP = new Map([ 34 ['*/*', 'FILTER_MEDIA_TYPE_ALL'], 35 ['image/*', 'FILTER_MEDIA_TYPE_IMAGE'], 36 ['video/*', 'FILTER_MEDIA_TYPE_VIDEO'], 37 ['image/movingPhoto', 'FILTER_MEDIA_TYPE_IMAGE_MOVING_PHOTO'] 38]); 39 40export class PhotoPickerComponent extends ViewPU { 41 constructor(e, o, t, i = -1, n = void 0) { 42 super(e, t, i); 43 'function' === typeof n && (this.paramsGenerator_ = n); 44 this.pickerOptions = void 0; 45 this.onSelect = void 0; 46 this.onDeselect = void 0; 47 this.onItemClicked = void 0; 48 this.onEnterPhotoBrowser = void 0; 49 this.onExitPhotoBrowser = void 0; 50 this.onPickerControllerReady = void 0; 51 this.onPhotoBrowserChanged = void 0; 52 this.onSelectedItemsDeleted = void 0; 53 this.onExceedMaxSelected = void 0; 54 this.onCurrentAlbumDeleted = void 0; 55 this.onVideoPlayStateChanged = void 0; 56 this.__pickerController = new SynchedPropertyNesedObjectPU(o.pickerController, this, 'pickerController'); 57 this.proxy = void 0; 58 this.__revokeIndex = new ObservedPropertySimplePU(0, this, 'revokeIndex'); 59 this.setInitiallyProvidedValue(o); 60 this.declareWatch('pickerController', this.onChanged); 61 } 62 63 setInitiallyProvidedValue(e) { 64 void 0 !== e.pickerOptions && (this.pickerOptions = e.pickerOptions); 65 void 0 !== e.onSelect && (this.onSelect = e.onSelect); 66 void 0 !== e.onDeselect && (this.onDeselect = e.onDeselect); 67 void 0 !== e.onItemClicked && (this.onItemClicked = e.onItemClicked); 68 void 0 !== e.onEnterPhotoBrowser && (this.onEnterPhotoBrowser = e.onEnterPhotoBrowser); 69 void 0 !== e.onExitPhotoBrowser && (this.onExitPhotoBrowser = e.onExitPhotoBrowser); 70 void 0 !== e.onPhotoBrowserChanged && (this.onPhotoBrowserChanged = e.onPhotoBrowserChanged); 71 void 0 !== e.onPickerControllerReady && (this.onPickerControllerReady = e.onPickerControllerReady); 72 void 0 !== e.onSelectedItemsDeleted && (this.onSelectedItemsDeleted = e.onSelectedItemsDeleted); 73 void 0 !== e.onExceedMaxSelected && (this.onExceedMaxSelected = e.onExceedMaxSelected); 74 void 0 !== e.onCurrentAlbumDeleted && (this.onCurrentAlbumDeleted = e.onCurrentAlbumDeleted); 75 void 0 !== e.onVideoPlayStateChanged && (this.onVideoPlayStateChanged = e.onVideoPlayStateChanged); 76 this.__pickerController.set(e.pickerController); 77 void 0 !== e.proxy && (this.proxy = e.proxy); 78 if (e.revokeIndex !== undefined) { 79 this.revokeIndex = e.revokeIndex; 80 } 81 } 82 83 updateStateVars(e) { 84 this.__pickerController.set(e.pickerController); 85 } 86 87 purgeVariableDependenciesOnElmtId(e) { 88 this.__pickerController.purgeDependencyOnElmtId(e); 89 this.__revokeIndex.purgeDependencyOnElmtId(e); 90 } 91 92 aboutToBeDeleted() { 93 this.__pickerController.aboutToBeDeleted(); 94 this.__revokeIndex.aboutToBeDeleted(); 95 SubscriberManager.Get().delete(this.id__()); 96 this.aboutToBeDeletedInternal(); 97 } 98 99 get pickerController() { 100 return this.__pickerController.get(); 101 } 102 103 get revokeIndex() { 104 return this.__revokeIndex.get(); 105 } 106 107 set revokeIndex(newValue) { 108 return this.__revokeIndex.set(); 109 } 110 111 onChanged() { 112 var e; 113 if (!this.proxy) { 114 return; 115 } 116 let o = null === (e = this.pickerController) || void 0 === e ? void 0 : e.data; 117 if (null == o ? void 0 : o.has('SET_SELECTED_URIS')) { 118 this.proxy.send({ selectUris: null == o ? void 0 : o.get('SET_SELECTED_URIS') }); 119 console.info('PhotoPickerComponent onChanged: SET_SELECTED_URIS'); 120 } else if (null == o ? void 0 : o.has('SET_ALBUM_URI')) { 121 this.proxy.send({ albumUri: null == o ? void 0 : o.get('SET_ALBUM_URI') }); 122 console.info('PhotoPickerComponent onChanged: SET_ALBUM_URI'); 123 } else if (null == o ? void 0 : o.has('SET_MAX_SELECT_COUNT')) { 124 this.onSetMaxSelectCount(o); 125 } else if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_ITEM')) { 126 this.onSetPhotoBrowserItem(o); 127 } else if (null == o ? void 0 : o.has('EXIT_PHOTO_BROWSER')) { 128 this.handleExitPhotoBrowser(); 129 } else { 130 this.otherOnChange(o); 131 } 132 } 133 134 otherOnChange(o) { 135 if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY')) { 136 this.onSetPhotoBrowserUIElementVisibility(o); 137 } else if (null == o ? void 0 : o.has('CREATE_URI')) { 138 this.onCreateUri(o); 139 console.info('PhotoPickerComponent onChanged: CREATE_URI'); 140 } else if (null == o ? void 0 : o.has('REPLACE_URI')) { 141 this.onReplaceUri(o); 142 console.info('PhotoPickerComponent onChanged: REPLACE_URI'); 143 } else if (null == o ? void 0 : o.has('SAVE_REPLACE_PHOTO_ASSETS')) { 144 this.onSaveTrustedPhotoAssets(o); 145 console.info('PhotoPickerComponent onChanged: SAVE_REPLACE_PHOTO_ASSETS'); 146 } else { 147 console.info('PhotoPickerComponent onChanged: other case'); 148 } 149 } 150 151 onSetMaxSelectCount(o) { 152 let e = null == o ? void 0 : o.get('SET_MAX_SELECT_COUNT'); 153 let t = null == e ? void 0 : e.data; 154 this.proxy.send({ 155 totalCount: null == t ? void 0 : t.get(MaxCountType.TOTAL_MAX_COUNT), 156 photoCount: null == t ? void 0 : t.get(MaxCountType.PHOTO_MAX_COUNT), 157 videoCount: null == t ? void 0 : t.get(MaxCountType.VIDEO_MAX_COUNT) 158 }); 159 console.info('PhotoPickerComponent onChanged: SET_MAX_SELECT_COUNT'); 160 } 161 162 onSetPhotoBrowserItem(o) { 163 let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_ITEM'); 164 this.proxy.send({ 165 itemUri: null == e ? void 0 : e.uri, 166 photoBrowserRange: null == e ? void 0 : e.photoBrowserRange 167 }); 168 console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_ITEM'); 169 } 170 171 handleExitPhotoBrowser() { 172 this.proxy.send({ exitPhotoBrowser: true }); 173 console.info('PhotoPickerComponent onChanged: EXIT_PHOTO_BROWSER'); 174 } 175 176 onSetPhotoBrowserUIElementVisibility(o) { 177 let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY'); 178 this.proxy.send({ 179 elements: null == e ? void 0 : e.elements, 180 isVisible: null == e ? void 0 : e.isVisible 181 }); 182 console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY'); 183 } 184 185 onCreateUri(o) { 186 let e = null == o ? void 0 : o.get('CREATE_URI'); 187 this.proxy.send({ 188 selectedMediaUri: null == e ? void 0 : e[0], 189 createUri: null == e ? void 0 : e[1], 190 date: null == e ? void 0 : e[2] 191 }); 192 console.info('PhotoPickerComponent onChanged CREATE_URI '); 193 } 194 195 onReplaceUri(o) { 196 let e = null == o ? void 0 : o.get('REPLACE_URI'); 197 this.proxy.send({ 198 oriUri: null == e ? void 0 : e[0], 199 replaceUri: null == e ? void 0 : e[1], 200 date: null == e ? void 0 : e[2] 201 }); 202 console.info('PhotoPickerComponent onChanged REPLACE_URI'); 203 } 204 205 onSaveTrustedPhotoAssets(o) { 206 let e = null == o ? void 0 : o.get('SAVE_REPLACE_PHOTO_ASSETS'); 207 this.proxy.send({ 208 replaceUris: null == e ? void 0 : e[0], 209 config: null == e ? void 0 : e[1], 210 saveMode: null == e ? void 0 : e[2], 211 appName: null == e ? void 0 : e[3], 212 date: null == e ? void 0 : e[4] 213 }); 214 console.info('PhotoPickerComponent onChanged SAVE_REPLACE_PHOTO_ASSETS'); 215 } 216 217 initialRender() { 218 this.observeComponentCreation2(((e, o) => { 219 Row.create(); 220 Row.height('100%'); 221 }), Row); 222 this.observeComponentCreation2(((e, o) => { 223 Column.create(); 224 Column.width('100%'); 225 }), Column); 226 this.observeComponentCreation2(((e, o) => { 227 var t, i, n, r, l, s, c, p, a, d, h, E, C, T, m, P, _, b, d, k, d, f; 228 SecurityUIExtensionComponent.create({ 229 parameters: { 230 errorRevokeIndex: this.revokeIndex, 231 'ability.want.params.uiExtensionTargetType': 'photoPicker', 232 uri: 'multipleselect', 233 targetPage: 'photoPage', 234 filterMediaType: this.convertMIMETypeToFilterType(null === (t = this.pickerOptions) || void 0 === t ? void 0 : t.MIMEType), 235 mimeTypeFilter: this.parseMimeTypeFilter(null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.mimeTypeFilter), 236 fileSizeFilter: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.fileSizeFilter, 237 videoDurationFilter: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.videoDurationFilter, 238 photoViewMimeTypeFileSizeFilters: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.photoViewMimeTypeFileSizeFilters, 239 maxSelectNumber: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.maxSelectNumber, 240 isPhotoTakingSupported: null === (n = this.pickerOptions) || void 0 === n ? void 0 : n.isPhotoTakingSupported, 241 isEditSupported: !1, 242 recommendationOptions: null === (r = this.pickerOptions) || void 0 === r ? void 0 : r.recommendationOptions, 243 preselectedUri: null === (l = this.pickerOptions) || void 0 === l ? void 0 : l.preselectedUris, 244 isFromPickerView: !0, 245 isNeedActionBar: !1, 246 isNeedSelectBar: !1, 247 isSearchSupported: null === (s = this.pickerOptions) || void 0 === s ? void 0 : s.isSearchSupported, 248 checkBoxColor: null === (c = this.pickerOptions) || void 0 === c ? void 0 : c.checkBoxColor, 249 backgroundColor: null === (p = this.pickerOptions) || void 0 === p ? void 0 : p.backgroundColor, 250 checkboxTextColor: null === (a = this.pickerOptions) || void 0 === a ? void 0 : a.checkboxTextColor, 251 photoBrowserBackgroundColorMode: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserBackgroundColorMode, 252 isRepeatSelectSupported: null === (h = this.pickerOptions) || void 0 === h ? void 0 : h.isRepeatSelectSupported, 253 maxSelectedReminderMode: null === (E = this.pickerOptions) || void 0 === E ? void 0 : E.maxSelectedReminderMode, 254 orientation: null === (C = this.pickerOptions) || void 0 === C ? void 0 : C.orientation, 255 selectMode: null === (T = this.pickerOptions) || void 0 === T ? void 0 : T.selectMode, 256 maxPhotoSelectNumber: null === (m = this.pickerOptions) || void 0 === m ? void 0 : m.maxPhotoSelectNumber, 257 maxVideoSelectNumber: null === (P = this.pickerOptions) || void 0 === P ? void 0 : P.maxVideoSelectNumber, 258 isOnItemClickedSet: !!this.onItemClicked, 259 isPreviewForSingleSelectionSupported: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.isPreviewForSingleSelectionSupported, 260 singleSelectionMode: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.singleSelectionMode, 261 isSlidingSelectionSupported: null === (b = this.pickerOptions) || void 0 === b ? void 0 : b.isSlidingSelectionSupported, 262 photoBrowserCheckboxPosition: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserCheckboxPosition, 263 gridMargin: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.gridMargin, 264 photoBrowserMargin: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.photoBrowserMargin, 265 gridStartOffset: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.gridStartOffset, 266 gridEndOffset: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.gridEndOffset, 267 singleLineConfig: null === (k = this.pickerOptions) || void 0 === k ? void 0 : this.getSingleLineConfig(k.singleLineConfig), 268 uiComponentColorMode: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.uiComponentColorMode, 269 combinedMediaTypeFilter: null === (f = this.pickerOptions) || void 0 === f ? void 0 : f.combinedMediaTypeFilter, 270 } 271 }); 272 SecurityUIExtensionComponent.height('100%'); 273 SecurityUIExtensionComponent.width('100%'); 274 SecurityUIExtensionComponent.onRemoteReady((e => { 275 this.proxy = e; 276 console.info('PhotoPickerComponent onRemoteReady'); 277 })); 278 SecurityUIExtensionComponent.onReceive((e => { 279 let o = e; 280 this.handleOnReceive(o); 281 })); 282 SecurityUIExtensionComponent.onError(((error) => { 283 console.info('PhotoPickerComponent onError: ' + JSON.stringify(error)); 284 console.info('PhotoPickerComponent revokeIndex: ' + this.revokeIndex); 285 if (error.code === 100014 && this.revokeIndex < 5) { 286 this.revokeIndex++; 287 } 288 })); 289 }), SecurityUIExtensionComponent); 290 Column.pop(); 291 Row.pop(); 292 } 293 294 handleOnReceive(e) { 295 let o = e.dataType; 296 console.info('PhotoPickerComponent onReceive: dataType = ' + o); 297 if ('selectOrDeselect' === o) { 298 this.handleSelectOrDeselect(e); 299 } else if ('itemClick' === o) { 300 this.handleItemClick(e); 301 } else if ('onPhotoBrowserStateChanged' === o) { 302 this.handleEnterOrExitPhotoBrowser(e); 303 } else if ('remoteReady' === o) { 304 if (this.onPickerControllerReady) { 305 this.onPickerControllerReady(); 306 console.info('PhotoPickerComponent onReceive: onPickerControllerReady'); 307 } 308 } else if ('replaceCallback' === o) { 309 this.handleReplaceCallback(e); 310 } else if ('createCallback' === o) { 311 this.handleCreateCallback(e); 312 } else if ('saveCallback' === o) { 313 this.handleSaveCallback(e); 314 } else if ('onPhotoBrowserChanged' === o) { 315 this.handlePhotoBrowserChange(e); 316 } else if ('onVideoPlayStateChanged' === o) { 317 this.handleVideoPlayStateChanged(e); 318 } else { 319 this.handleOtherOnReceive(e); 320 console.info('PhotoPickerComponent onReceive: other case'); 321 } 322 console.info('PhotoPickerComponent onReceive' + this.pickerController.encrypt(JSON.stringify(e))); 323 } 324 325 handleOtherOnReceive(e) { 326 let o = e.dataType; 327 if ('exceedMaxSelected' === o) { 328 if (this.onExceedMaxSelected) { 329 this.onExceedMaxSelected(e.maxCountType); 330 } 331 } else if ('selectedItemsDeleted' === o) { 332 if (this.onSelectedItemsDeleted) { 333 this.onSelectedItemsDeleted(e.selectedItemInfos); 334 } 335 } else if ('currentAlbumDeleted' === o) { 336 if (this.onCurrentAlbumDeleted) { 337 this.onCurrentAlbumDeleted(); 338 } 339 } else { 340 console.info('PhotoPickerComponent onReceive: other case'); 341 } 342 } 343 344 handleSelectOrDeselect(e) { 345 if (e.isSelect) { 346 if (this.onSelect) { 347 this.onSelect(e['select-item-list']); 348 console.info('PhotoPickerComponent onReceive: onSelect'); 349 } 350 } else if (this.onDeselect) { 351 this.onDeselect(e['select-item-list']); 352 console.info('PhotoPickerComponent onReceive: onDeselect'); 353 } 354 } 355 356 handleItemClick(e) { 357 if (this.onItemClicked) { 358 let o = ClickType.SELECTED; 359 let t = e.clickType; 360 'select' === t ? o = ClickType.SELECTED : 'deselect' === t ? o = ClickType.DESELECTED : console.info('PhotoPickerComponent onReceive: other clickType'); 361 let i = new ItemInfo; 362 let n = e.itemType; 363 'thumbnail' === n ? i.itemType = ItemType.THUMBNAIL : 'camera' === n ? i.itemType = ItemType.CAMERA : console.info('PhotoPickerComponent onReceive: other itemType'); 364 i.uri = e.uri; 365 i.mimeType = e.mimeType; 366 i.width = e.width; 367 i.height = e.height; 368 i.size = e.size; 369 i.duration = e.duration; 370 let r = this.onItemClicked(i, o); 371 console.info('PhotoPickerComponent onReceive: onItemClicked = ' + o); 372 if (this.proxy) { 373 if ('thumbnail' === n && o === ClickType.SELECTED) { 374 this.proxy.send({ clickConfirm: i.uri, isConfirm: r }); 375 console.info('PhotoPickerComponent onReceive: click confirm: uri = ' + 376 this.pickerController.encrypt(i.uri) + 'isConfirm = ' + r); 377 } 378 if ('camera' === n) { 379 this.proxy.send({ enterCamera: r }); 380 console.info('PhotoPickerComponent onReceive: enter camera ' + r); 381 } 382 } 383 } 384 } 385 386 handleEnterOrExitPhotoBrowser(e) { 387 let o = e.isEnter; 388 let t = new PhotoBrowserInfo; 389 t.animatorParams = new AnimatorParams; 390 t.animatorParams.duration = e.duration; 391 t.animatorParams.curve = e.curve; 392 o ? this.onEnterPhotoBrowser && this.onEnterPhotoBrowser(t) : this.onExitPhotoBrowser && this.onExitPhotoBrowser(t); 393 console.info('PhotoPickerComponent onReceive: onPhotoBrowserStateChanged = ' + o); 394 } 395 396 handlePhotoBrowserChange(e) { 397 let o = new BaseItemInfo(); 398 o.uri = e.uri; 399 if (this.onPhotoBrowserChanged) { 400 this.onPhotoBrowserChanged(o); 401 } 402 console.info('PhotoPickerComponent onReceive: onPhotoBrowserChanged = ' + this.pickerController.encrypt(o.uri)); 403 } 404 405 handleVideoPlayStateChanged(e) { 406 if (this.onVideoPlayStateChanged) { 407 this.onVideoPlayStateChanged(e.state); 408 console.info('PhotoPickerComponent onReceive: onVideoPlayStateChanged = ' + JSON.stringify(e)); 409 } 410 } 411 412 handleCreateCallback(e) { 413 this.pickerController.actionCreateCallback(e.grantUri, e.date, e.code, e.message); 414 console.info('PhotoPickerComponent onReceive: handleCreateCallback'); 415 } 416 417 handleReplaceCallback(e) { 418 this.pickerController.actionReplaceCallback(e.date, {'name': '', 'code': e.code, 'message': e.message}); 419 console.info('PhotoPickerComponent onReceive: handleReplaceCallback'); 420 } 421 422 handleSaveCallback(e) { 423 this.pickerController.actionSaveCallback(e.date, {'name': '', 'code': e.code, 'message': e.message}, e.data); 424 console.info('PhotoPickerComponent onReceive: handleSaveCallback'); 425 } 426 427 parseMimeTypeFilter(filter) { 428 if (!filter) { 429 return undefined; 430 } 431 let o = {}; 432 o.mimeTypeArray = []; 433 if (filter.mimeTypeArray) { 434 for (let mimeType of filter.mimeTypeArray) { 435 if (PHOTO_VIEW_MIME_TYPE_MAP.has(mimeType)) { 436 o.mimeTypeArray.push(PHOTO_VIEW_MIME_TYPE_MAP.get(mimeType)); 437 } else { 438 o.mimeTypeArray.push(mimeType); 439 } 440 } 441 } 442 return o; 443 } 444 445 convertMIMETypeToFilterType(e) { 446 let o; 447 if (PHOTO_VIEW_MIME_TYPE_MAP.has(e)) { 448 o = PHOTO_VIEW_MIME_TYPE_MAP.get(e); 449 } else { 450 o = PHOTO_VIEW_MIME_TYPE_MAP.get('*/*'); 451 } 452 console.info('PhotoPickerComponent convertMIMETypeToFilterType: ' + JSON.stringify(o)); 453 return o; 454 } 455 456 getSingleLineConfig(singleLineConfig) { 457 if (null === singleLineConfig || void 0 === singleLineConfig) { 458 return void 0; 459 } 460 singleLineConfig.itemDisplayRatio = 461 (null === singleLineConfig.itemDisplayRatio || void 0 === singleLineConfig.itemDisplayRatio) ? 462 ItemDisplayRatio.SQUARE_RATIO : singleLineConfig.itemDisplayRatio; 463 singleLineConfig.itemBorderRadius = 464 this.getSingleLineConfigItemBorderRadius(singleLineConfig.itemBorderRadius); 465 singleLineConfig.itemGap = this.getLength(singleLineConfig.itemGap); 466 return singleLineConfig; 467 } 468 469 getSingleLineConfigItemBorderRadius(itemBorderRadius) { 470 if (null === itemBorderRadius || void 0 === itemBorderRadius) { 471 return 0; 472 } 473 if (typeof itemBorderRadius === 'number' || typeof itemBorderRadius === 'string') { 474 return itemBorderRadius; 475 } 476 if (this.hasOwnProp(itemBorderRadius, ['topStart', 'topEnd', 'bottomStart', 'bottomEnd'])) { 477 const l2 = { 478 topStart: LengthMetrics.vp(0), 479 topEnd: LengthMetrics.vp(0), 480 bottomStart: LengthMetrics.vp(0), 481 bottomEnd: LengthMetrics.vp(0), 482 }; 483 const m2 = itemBorderRadius; 484 l2.topStart = m2.topStart ? m2.topStart : LengthMetrics.vp(0); 485 l2.topEnd = m2.topEnd ? m2.topEnd : LengthMetrics.vp(0); 486 l2.bottomStart = m2.bottomStart ? m2.bottomStart : LengthMetrics.vp(0); 487 l2.bottomEnd = m2.bottomEnd ? m2.bottomEnd : LengthMetrics.vp(0); 488 return l2; 489 } 490 if (this.hasOwnProp(itemBorderRadius, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'])) { 491 const borderRadiuses = { 492 topLeft: 0, 493 topRight: 0, 494 bottomLeft: 0, 495 bottomRight: 0 496 }; 497 const k2 = itemBorderRadius; 498 borderRadiuses.topLeft = this.getLength(k2.topLeft); 499 borderRadiuses.topRight = this.getLength(k2.topRight); 500 borderRadiuses.bottomLeft = this.getLength(k2.bottomLeft); 501 borderRadiuses.bottomRight = this.getLength(k2.bottomRight); 502 return borderRadiuses; 503 } 504 const j2 = itemBorderRadius; 505 const resource = LengthMetrics.resource(j2); 506 if (M.getInstance().isValid(resource)) { 507 return M.getInstance().stringify(resource); 508 } 509 return 0; 510 } 511 512 getLength(prop) { 513 if (null === prop || void 0 === prop) { 514 return 0; 515 } 516 if (typeof prop === 'number' || typeof prop === 'string') { 517 return prop; 518 } 519 const resource = LengthMetrics.resource(prop); 520 if (M.getInstance().isValid(resource)) { 521 return M.getInstance().stringify(resource); 522 } 523 return 0; 524 } 525 526 hasOwnProp(obj, props) { 527 for (const key of Object.keys(obj)) { 528 if (props.includes(key)) { 529 return true; 530 } 531 } 532 return false; 533 } 534 535 rerender() { 536 this.updateDirtyElements(); 537 } 538} 539 540class M { 541 constructor() { 542 } 543 544 static getInstance() { 545 if (!M.instance) { 546 M.instance = new M(); 547 } 548 return M.instance; 549 } 550 551 stringify(metrics) { 552 if (null === metrics || void 0 === metrics || typeof metrics !== 'object' || null === metrics.unit || 553 void 0 === metrics.unit || null === metrics.value || void 0 === metrics.value) { 554 return '0vp'; 555 } 556 switch (metrics.unit) { 557 case LengthUnit.PX: 558 return `${metrics.value}px`; 559 case LengthUnit.VP: 560 return `${metrics.value}vp`; 561 case LengthUnit.FP: 562 return `${metrics.value}fp`; 563 case LengthUnit.PERCENT: 564 return `${metrics.value}%`; 565 case LengthUnit.LPX: 566 return `${metrics.value}lpx`; 567 default: 568 return '0vp'; 569 } 570 } 571 572 isValid(metrics) { 573 if (null === metrics || void 0 === metrics || typeof metrics !== 'object' || 574 null === metrics.value || void 0 === metrics.value) { 575 return false; 576 } 577 return metrics.value > 0; 578 } 579} 580 581let PickerController = class { 582 constructor() { 583 this.replaceCallbackMap = new Map(); 584 this.saveCallbackMap = new Map(); 585 this.createCallbackMap = new Map(); 586 } 587 setData(e, o) { 588 if (o === undefined) { 589 return; 590 } 591 if (e === DataType.SET_SELECTED_URIS) { 592 if (o instanceof Array) { 593 let e = o; 594 if (e) { 595 this.data = new Map([['SET_SELECTED_URIS', [...e]]]); 596 console.info('PhotoPickerComponent SET_SELECTED_URIS' + this.encrypt(JSON.stringify(e))); 597 } 598 } 599 } else if (e === DataType.SET_ALBUM_URI) { 600 let e = o; 601 if (e !== undefined) { 602 this.data = new Map([['SET_ALBUM_URI', e]]); 603 console.info('PhotoPickerComponent SET_ALBUM_URI' + this.encrypt(JSON.stringify(e))); 604 } 605 } else { 606 console.info('PhotoPickerComponent setData: other case'); 607 } 608 } 609 610 setMaxSelected(e) { 611 if (e) { 612 this.data = new Map([['SET_MAX_SELECT_COUNT', e]]); 613 console.info('PhotoPickerComponent SET_MAX_SELECT_COUNT' + JSON.stringify(e)); 614 } 615 } 616 617 setPhotoBrowserItem(e, o) { 618 let l = new PhotoBrowserRangeInfo; 619 l.uri = e; 620 let m = o ? o : PhotoBrowserRange.ALL; 621 l.photoBrowserRange = m; 622 this.data = new Map([['SET_PHOTO_BROWSER_ITEM', l]]); 623 console.info('PhotoPickerComponent SET_PHOTO_BROWSER_ITEM ' + this.encrypt(JSON.stringify(l))); 624 } 625 626 exitPhotoBrowser() { 627 this.data = new Map([['EXIT_PHOTO_BROWSER', true]]); 628 console.info('PhotoPickerComponent EXIT_PHOTO_BROWSER '); 629 } 630 631 async getAppName() { 632 let flags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY | 633 bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | 634 bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 635 bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; 636 let c2 = bundleManager.getBundleInfoForSelfSync(flags); 637 let labelId = c2.appInfo.labelId; 638 let appName = ''; 639 let moduleName = ''; 640 for (let d2 of c2.hapModulesInfo) { 641 if (labelId === d2.labelId) { 642 moduleName = d2.name; 643 } 644 } 645 appName = await getContext(this).createModuleContext(moduleName).resourceManager.getStringValue(labelId); 646 return appName; 647 } 648 649 replacePhotoPickerPreview(e, o, callback) { 650 try { 651 let fd = fs.openSync(o).fd; 652 fs.close(fd); 653 } catch (err) { 654 callback({'code': 13900002, 'message': 'No such file', name: ''}); 655 return; 656 } 657 let date = Math.random(); 658 this.data = new Map([['CREATE_URI', [e, o, date]]]); 659 this.createCallbackMap.set(date, (grantUri, code, message)=>{ 660 if (code !== 0) { 661 callback({'code': code, 'message': message, name: ''}); 662 return; 663 } 664 let createFd = 0; 665 let replaceFd = 0; 666 try { 667 createFd = fs.openSync(grantUri, fs.OpenMode.READ_WRITE).fd; 668 replaceFd = fs.openSync(o, fs.OpenMode.READ_ONLY).fd; 669 fs.copyFileSync(replaceFd, createFd); 670 this.data = new Map([['REPLACE_URI', [e, grantUri, date]]]); 671 this.replaceCallbackMap.set(date, callback); 672 } catch (err) { 673 callback({'code': 14000011, 'message': 'System inner fail', name: ''}); 674 } finally { 675 fs.close(createFd); 676 fs.close(replaceFd); 677 } 678 }); 679 } 680 681 saveTrustedPhotoAssets(e, callback, config, saveMode) { 682 if (!e || e.length === 0) { 683 callback({'code': 14000002, 'message': 'Invalid URI', name: ''}, []); 684 return; 685 } 686 this.getAppName().then((appName) => { 687 let date = Math.random(); 688 this.data = new Map([['SAVE_REPLACE_PHOTO_ASSETS', [e, config, saveMode, appName, date]]]); 689 this.saveCallbackMap.set(date, callback); 690 console.info('PhotoPickerComponent SAVE_TRUSTED_PHOTO_ASSETS '); 691 }); 692 } 693 694 actionCreateCallback(grantUri, date, code, message) { 695 if (this.createCallbackMap.has(date)) { 696 let callback = this.createCallbackMap.get(date); 697 if (callback) { 698 callback(grantUri, code, message); 699 this.createCallbackMap.delete(date); 700 } 701 } 702 } 703 704 actionReplaceCallback(date, err) { 705 if (this.replaceCallbackMap.has(date)) { 706 let callback = this.replaceCallbackMap.get(date); 707 if (callback) { 708 callback(err); 709 this.replaceCallbackMap.delete(date); 710 } 711 } 712 } 713 714 actionSaveCallback(date, err, data) { 715 if (this.saveCallbackMap.has(date)) { 716 let callback = this.saveCallbackMap.get(date); 717 if (callback) { 718 callback(err, data); 719 this.saveCallbackMap.delete(date); 720 } 721 } 722 } 723 724 setPhotoBrowserUIElementVisibility(e, o) { 725 let m = new PhotoBrowserUIElementVisibility; 726 m.elements = e; 727 m.isVisible = o; 728 this.data = new Map([['SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY', m]]); 729 console.info('PhotoPickerComponent SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY ' + JSON.stringify(m)); 730 } 731 732 encrypt(data) { 733 if (!data || data?.indexOf('file:///data/storage/') !== -1) { 734 return ''; 735 } 736 return data.replace(/(\/\w+)\./g, '/******.'); 737 } 738}; 739PickerController = __decorate([Observed], PickerController); 740 741export class PickerOptions extends photoAccessHelper.BaseSelectOptions { 742} 743 744export class BaseItemInfo { 745} 746 747export class ItemInfo extends BaseItemInfo { 748} 749 750export class PhotoBrowserInfo { 751} 752 753export class AnimatorParams { 754} 755 756export class MaxSelected { 757} 758 759class PhotoBrowserRangeInfo { 760} 761 762class PhotoBrowserUIElementVisibility { 763} 764 765export class SingleLineConfig { 766 constructor() { 767 this.itemDisplayRatio = ItemDisplayRatio.SQUARE_RATIO; 768 this.itemBorderRadius = 0; 769 this.itemGap = 0; 770 } 771} 772 773export var DataType; 774!function(e) { 775 e[e.SET_SELECTED_URIS = 1] = 'SET_SELECTED_URIS'; 776 e[e.SET_ALBUM_URI = 2] = 'SET_ALBUM_URI'; 777}(DataType || (DataType = {})); 778 779export var ItemType; 780!function(e) { 781 e[e.THUMBNAIL = 0] = 'THUMBNAIL'; 782 e[e.CAMERA = 1] = 'CAMERA'; 783}(ItemType || (ItemType = {})); 784 785export var ClickType; 786!function(e) { 787 e[e.SELECTED = 0] = 'SELECTED'; 788 e[e.DESELECTED = 1] = 'DESELECTED'; 789}(ClickType || (ClickType = {})); 790 791export var PickerOrientation; 792!function(e) { 793 e[e.VERTICAL = 0] = 'VERTICAL'; 794 e[e.HORIZONTAL = 1] = 'HORIZONTAL'; 795}(PickerOrientation || (PickerOrientation = {})); 796 797export var SelectMode; 798!function(e) { 799 e[e.SINGLE_SELECT = 0] = 'SINGLE_SELECT'; 800 e[e.MULTI_SELECT = 1] = 'MULTI_SELECT'; 801}(SelectMode || (SelectMode = {})); 802 803export var PickerColorMode; 804!function(e) { 805 e[e.AUTO = 0] = 'AUTO'; 806 e[e.LIGHT = 1] = 'LIGHT'; 807 e[e.DARK = 2] = 'DARK'; 808}(PickerColorMode || (PickerColorMode = {})); 809 810export var ReminderMode; 811!function(e) { 812 e[e.NONE = 0] = 'NONE'; 813 e[e.TOAST = 1] = 'TOAST'; 814 e[e.MASK = 2] = 'MASK'; 815}(ReminderMode || (ReminderMode = {})); 816 817export var MaxCountType; 818!function(e) { 819 e[e.TOTAL_MAX_COUNT = 0] = 'TOTAL_MAX_COUNT'; 820 e[e.PHOTO_MAX_COUNT = 1] = 'PHOTO_MAX_COUNT'; 821 e[e.VIDEO_MAX_COUNT = 2] = 'VIDEO_MAX_COUNT'; 822}(MaxCountType || (MaxCountType = {})); 823 824export var PhotoBrowserRange; 825!function(e) { 826 e[e.ALL = 0] = 'ALL'; 827 e[e.SELECTED_ONLY = 1] = 'SELECTED_ONLY'; 828}(PhotoBrowserRange || (PhotoBrowserRange = {})); 829 830export var PhotoBrowserUIElement; 831!function(e) { 832 e[e.CHECKBOX = 0] = 'CHECKBOX'; 833 e[e.BACK_BUTTON = 1] = 'BACK_BUTTON'; 834}(PhotoBrowserUIElement || (PhotoBrowserUIElement = {})); 835 836export var VideoPlayerState; 837!function(e) { 838 e[e.PLAYING = 0] = 'PLAYING'; 839 e[e.PAUSED = 1] = 'PAUSED'; 840 e[e.STOPPED = 2] = 'STOPPED'; 841 e[e.SEEK_START = 3] = 'SEEK_START'; 842 e[e.SEEK_FINISH = 4] = 'SEEK_FINISH'; 843}(VideoPlayerState || (VideoPlayerState = {})); 844 845export var SaveMode; 846!function(e) { 847 e[e.SAVE_AS = 0] = 'SAVE_AS'; 848 e[e.OVERWRITE = 1] = 'OVERWRITE'; 849}(SaveMode || (SaveMode = {})); 850 851export var ItemDisplayRatio; 852!function(e) { 853 e[e.SQUARE_RATIO = 0] = 'SQUARE_RATIO'; 854 e[e.ORIGINAL_SIZE_RATIO = 1] = 'ORIGINAL_SIZE_RATIO'; 855}(ItemDisplayRatio || (ItemDisplayRatio = {})); 856 857export default { PhotoPickerComponent, PickerController, PickerOptions, DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams, 858 MaxSelected, ItemType, ClickType, PickerOrientation, SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange, PhotoBrowserUIElement, 859 VideoPlayerState, SaveMode, SingleLineConfig, ItemDisplayRatio };