Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 182x 26x 26x 156x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 1x 1x 1x 1x 25x 26x 22x 22x 26x 26x 26x 26x 26x 26x 26x 20x 20x 20x 20x 20x 20x 20x 20x | import { doubleCheckResize } from './doubleCheckResize'; import { filterInnerResizerHandles } from './filterInnerResizerHandles'; import { getGeneratedImageSize } from './generateImageSize'; import { ImageEditElementClass } from '../types/ImageEditElementClass'; import { toArray } from 'roosterjs-content-model-dom'; import { updateHandleCursor } from './updateHandleCursor'; import { updateSideHandlesVisibility } from '../Resizer/updateSideHandlesVisibility'; import type { ImageEditOptions } from '../types/ImageEditOptions'; import type { ImageMetadataFormat } from 'roosterjs-content-model-types'; import { getActualWrapperDimensions, getPx, isASmallImage, setFlipped, setSize, setWrapperSizeDimensions, } from './imageEditUtils'; /** * @internal */ export function updateWrapper( editInfo: ImageMetadataFormat, options: ImageEditOptions, image: HTMLImageElement, clonedImage: HTMLImageElement, wrapper: HTMLSpanElement, resizers?: HTMLDivElement[], croppers?: HTMLDivElement[], isRTL?: boolean, isRotating?: boolean ) { const { angleRad, bottomPercent, leftPercent, rightPercent, topPercent, flippedHorizontal, flippedVertical, } = editInfo; const generateImageSize = getGeneratedImageSize(editInfo, croppers && croppers?.length > 0); Iif (!generateImageSize) { return; } const { targetWidth, targetHeight, originalWidth, originalHeight, visibleWidth, visibleHeight, } = generateImageSize; const marginHorizontal = (targetWidth - visibleWidth) / 2; const marginVertical = (targetHeight - visibleHeight) / 2; const cropLeftPx = originalWidth * (leftPercent || 0); const cropRightPx = originalWidth * (rightPercent || 0); const cropTopPx = originalHeight * (topPercent || 0); const cropBottomPx = originalHeight * (bottomPercent || 0); // Update size and margin of the wrapper wrapper.style.marginTop = `${marginVertical}px`; wrapper.style.marginBottom = `${marginVertical + 5}px `; // 5px to adjust the image on top of the handles wrapper.style.marginLeft = `${marginHorizontal}px`; wrapper.style.marginRight = `${marginHorizontal}px`; wrapper.style.transform = `rotate(${angleRad}rad)`; setWrapperSizeDimensions(wrapper, image, visibleWidth, visibleHeight, !!isRotating); wrapper.style.verticalAlign = 'text-bottom'; // Update the text-alignment to avoid the image to overflow if the parent element have align center or right // or if the direction is Right To Left if (isRTL) { wrapper.style.textAlign = 'right'; Eif (!croppers) { clonedImage.style.left = getPx(cropLeftPx); clonedImage.style.right = getPx(-cropRightPx); } } else { wrapper.style.textAlign = 'left'; } if (!isRotating) { // Update size of the image clonedImage.style.width = getPx(originalWidth); clonedImage.style.height = getPx(originalHeight); } clonedImage.style.position = 'absolute'; //Update flip direction setFlipped(clonedImage.parentElement, flippedHorizontal, flippedVertical); const smallImage = isASmallImage(visibleWidth, visibleWidth); Eif (!croppers) { // For rotate/resize, set the margin of the image so that cropped part won't be visible clonedImage.style.margin = `${-cropTopPx}px 0 0 ${-cropLeftPx}px`; } Iif (croppers && croppers.length > 0) { const cropContainer = croppers[0]; const cropOverlays = croppers.filter( cropper => cropper.className === ImageEditElementClass.CropOverlay ); const cropHandles = toArray<HTMLElement>( cropContainer.querySelectorAll(`.${ImageEditElementClass.CropHandle}`) ); setSize( cropContainer, cropLeftPx, cropTopPx, cropRightPx, cropBottomPx, undefined, undefined ); setSize(cropOverlays[0], 0, 0, cropRightPx, undefined, undefined, cropTopPx); setSize(cropOverlays[1], undefined, 0, 0, cropBottomPx, cropRightPx, undefined); setSize(cropOverlays[2], cropLeftPx, undefined, 0, 0, undefined, cropBottomPx); setSize(cropOverlays[3], 0, cropTopPx, undefined, 0, cropLeftPx, undefined); if (angleRad !== undefined) { updateHandleCursor(cropHandles, angleRad); } } if (resizers && !isRotating) { const clientWidth = wrapper.clientWidth; const clientHeight = wrapper.clientHeight; const actualDimensions = getActualWrapperDimensions(image, clientWidth, clientHeight); doubleCheckResize( editInfo, options.preserveRatio || false, actualDimensions.width, actualDimensions.height ); const resizeHandles = filterInnerResizerHandles(resizers); Eif (angleRad !== undefined) { updateHandleCursor(resizeHandles, angleRad); } updateSideHandlesVisibility(resizeHandles, smallImage); } } |