1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/// <reference path='./import.ts' /> 17class ImageSpanObjectFitModifier extends ModifierWithKey<number> { 18 constructor(value: number) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('imageSpanObjectFit'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().imageSpan.resetObjectFit(node); 25 } else { 26 getUINativeModule().imageSpan.setObjectFit(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return this.stageValue !== this.value; 31 } 32} 33class ImageSpanVerticalAlignModifier extends ModifierWithKey<number> { 34 constructor(value: number) { 35 super(value); 36 } 37 static identity: Symbol = Symbol('imageSpanVerticalAlign'); 38 applyPeer(node: KNode, reset: boolean): void { 39 if (reset) { 40 getUINativeModule().imageSpan.resetVerticalAlign(node); 41 } else { 42 getUINativeModule().imageSpan.setVerticalAlign(node, this.value!); 43 } 44 } 45 checkObjectDiff(): boolean { 46 return this.stageValue !== this.value; 47 } 48} 49class ImageSpanTextBackgroundStyleModifier extends ModifierWithKey<TextBackgroundStyle> { 50 constructor(value: TextBackgroundStyle) { 51 super(value); 52 } 53 static identity: Symbol = Symbol('imageSpanTextBackgroundStyle'); 54 applyPeer(node: KNode, reset: boolean): void { 55 if (reset) { 56 getUINativeModule().imageSpan.resetTextBackgroundStyle(node); 57 } 58 else { 59 let textBackgroundStyle = new ArkTextBackGroundStyle(); 60 if (!textBackgroundStyle.convertTextBackGroundStyleOptions(this.value)) { 61 getUINativeModule().imageSpan.resetTextBackgroundStyle(node); 62 } 63 else { 64 getUINativeModule().imageSpan.setTextBackgroundStyle( 65 node, textBackgroundStyle.color, textBackgroundStyle.radius.topLeft, 66 textBackgroundStyle.radius.topRight, textBackgroundStyle.radius.bottomLeft, textBackgroundStyle.radius.bottomRight); 67 } 68 } 69 } 70 checkObjectDiff(): boolean { 71 let textBackgroundStyle = new ArkTextBackGroundStyle(); 72 let stageTextBackGroundStyle = new ArkTextBackGroundStyle(); 73 if (!textBackgroundStyle.convertTextBackGroundStyleOptions(this.value) || !stageTextBackGroundStyle.convertTextBackGroundStyleOptions(this.stageValue)) { 74 return false; 75 } 76 else { 77 return textBackgroundStyle.checkObjectDiff(stageTextBackGroundStyle); 78 } 79 } 80} 81class ImageSpanBaselineOffsetModifier extends ModifierWithKey<LengthMetrics> { 82 constructor(value: LengthMetrics) { 83 super(value); 84 } 85 static identity = Symbol('imageSpanBaselineOffset'); 86 applyPeer(node: KNode, reset: boolean): void { 87 if (reset) { 88 getUINativeModule().imageSpan.resetBaselineOffset(node); 89 } else { 90 getUINativeModule().imageSpan.setBaselineOffset(node, this.value!); 91 } 92 } 93} 94class ImageSpanAltModifier extends ModifierWithKey<PixelMap> { 95 constructor(value: PixelMap) { 96 super(value); 97 } 98 static identity = Symbol('imageSpanAlt'); 99 applyPeer(node: KNode, reset: boolean): void { 100 if (reset) { 101 getUINativeModule().imageSpan.resetAlt(node); 102 } else { 103 getUINativeModule().imageSpan.setAlt(node, this.value!); 104 } 105 } 106} 107class ImageSpanOnCompleteModifier extends ModifierWithKey<(event?: {width: number; height: number; componentWidth: number; componentHeight: number; loadingStatus: number; contentWidth: number; contentHeight: number; contentOffsetX: number; contentOffsetY: number;}) => void> { 108 constructor(value: (event?: {width: number; height: number; componentWidth: number; componentHeight: number; loadingStatus: number; contentWidth: number; contentHeight: number; contentOffsetX: number; contentOffsetY: number;}) => void) { 109 super(value); 110 } 111 static identity = Symbol('imageSpanOnComplete'); 112 applyPeer(node: KNode, reset: boolean): void { 113 if (reset) { 114 getUINativeModule().imageSpan.resetOnComplete(node); 115 } else { 116 getUINativeModule().imageSpan.setOnComplete(node, this.value); 117 } 118 } 119} 120class ImageSpanOnErrorModifier extends ModifierWithKey<(result: {componentWidth: number; componentHeight: number; message: string}) => void> { 121 constructor(value: (event: {componentWidth: number; componentHeight: number; message: string}) => void) { 122 super(value); 123 } 124 static identity = Symbol('imageSpanOnError'); 125 applyPeer(node: KNode, reset: boolean): void { 126 if (reset) { 127 getUINativeModule().imageSpan.resetOnError(node); 128 } else { 129 getUINativeModule().imageSpan.setOnError(node, this.value); 130 } 131 } 132} 133class ImageSpanColorFilterModifier extends ModifierWithKey<ColorFilter | DrawingColorFilter> { 134 constructor(value: ColorFilter) { 135 super(value); 136 } 137 static identity: Symbol = Symbol('imageSpanColorFilter'); 138 applyPeer(node: KNode, reset: boolean): void { 139 if (reset) { 140 getUINativeModule().imageSpan.resetColorFilter(node); 141 } else { 142 getUINativeModule().imageSpan.setColorFilter(node, this.value!); 143 } 144 } 145 checkObjectDiff(): boolean { 146 return true; 147 } 148} 149class ArkImageSpanComponent extends ArkComponent implements ImageSpanAttribute { 150 constructor(nativePtr: KNode, classType?: ModifierType) { 151 super(nativePtr, classType); 152 } 153 objectFit(value: ImageFit): ImageSpanAttribute { 154 modifierWithKey(this._modifiersWithKeys, ImageSpanObjectFitModifier.identity, ImageSpanObjectFitModifier, value); 155 return this; 156 } 157 verticalAlign(value: ImageSpanAlignment): ImageSpanAttribute { 158 modifierWithKey(this._modifiersWithKeys, ImageSpanVerticalAlignModifier.identity, ImageSpanVerticalAlignModifier, value); 159 return this; 160 } 161 textBackgroundStyle(value: TextBackgroundStyle): ImageSpanAttribute { 162 modifierWithKey(this._modifiersWithKeys, ImageSpanTextBackgroundStyleModifier.identity, ImageSpanTextBackgroundStyleModifier, value); 163 return this; 164 } 165 baselineOffset(value: LengthMetrics): ImageSpanAttribute { 166 modifierWithKey(this._modifiersWithKeys, ImageSpanBaselineOffsetModifier.identity, ImageSpanBaselineOffsetModifier, value); 167 return this; 168 } 169 alt(value: PixelMap): ImageSpanAttribute { 170 modifierWithKey(this._modifiersWithKeys, ImageSpanAltModifier.identity, ImageSpanAltModifier, value); 171 return this; 172 } 173 colorFilter(value: ColorFilter | DrawingColorFilter): ImageSpanAttribute { 174 modifierWithKey(this._modifiersWithKeys, ImageSpanColorFilterModifier.identity, 175 ImageSpanColorFilterModifier, value); 176 return this; 177 } 178 onComplete( 179 callback: (result: { 180 width: number; 181 height: number; 182 componentWidth: number; 183 componentHeight: number; 184 loadingStatus: number; 185 contentWidth: number; 186 contentHeight: number; 187 contentOffsetX: number; 188 contentOffsetY: number; 189 }) => void, 190 ): ImageSpanAttribute { 191 modifierWithKey(this._modifiersWithKeys, ImageSpanOnCompleteModifier.identity, ImageSpanOnCompleteModifier, callback); 192 return this; 193 } 194 onError(callback: (error: { 195 componentWidth: number; 196 componentHeight: number; 197 message: string 198 }) => void): ImageSpanAttribute { 199 modifierWithKey(this._modifiersWithKeys, ImageSpanOnErrorModifier.identity, ImageSpanOnErrorModifier, callback); 200 return this; 201 } 202} 203// @ts-ignore 204globalThis.ImageSpan.attributeModifier = function (modifier: ArkComponent): void { 205 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 206 return new ArkImageSpanComponent(nativePtr); 207 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 208 return new modifierJS.ImageSpanModifier(nativePtr, classType); 209 }); 210}; 211