UNPKG

@leafer-draw/worker

Version:
1 lines 174 kB
{"version":3,"file":"worker.min.cjs","sources":["../../../../../../../src/leafer/packages/canvas/canvas-worker/src/LeaferCanvas.ts","../../../../../../../src/leafer/packages/canvas/canvas-worker/src/index.ts","../../../../../../../src/draw/packages/platform/worker/src/core.ts","../../../../../../../src/leafer/packages/partner/watcher/src/Watcher.ts","../../../../../../../src/leafer/packages/partner/layouter/src/LayouterHelper.ts","../../../../../../../src/leafer/packages/partner/layouter/src/LayoutBlockData.ts","../../../../../../../src/leafer/packages/partner/layouter/src/Layouter.ts","../../../../../../../src/leafer/packages/partner/renderer/src/Renderer.ts","../../../../../../../src/ui/packages/partner/paint/src/FillText.ts","../../../../../../../src/ui/packages/partner/paint/src/Fill.ts","../../../../../../../src/ui/packages/partner/paint/src/StrokeText.ts","../../../../../../../src/ui/packages/partner/paint/src/Stroke.ts","../../../../../../../src/draw/packages/partner/src/index.ts","../../../../../../../src/ui/packages/partner/paint/src/Shape.ts","../../../../../../../src/ui/packages/partner/paint/src/Compute.ts","../../../../../../../src/ui/packages/partner/paint/src/index.ts","../../../../../../../src/ui/packages/partner/image/src/mode.ts","../../../../../../../src/ui/packages/partner/image/src/data.ts","../../../../../../../src/ui/packages/partner/image/src/image.ts","../../../../../../../src/ui/packages/partner/image/src/pattern.ts","../../../../../../node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.34.6_tslib@2.8.1_typescript@5.7.3/node_modules/tslib/tslib.es6.js","../../../../../../../src/ui/packages/partner/image/src/check.ts","../../../../../../../src/ui/packages/partner/image/src/index.ts","../../../../../../../src/ui/packages/partner/image/src/recycle.ts","../../../../../../../src/ui/packages/partner/gradient/src/linear.ts","../../../../../../../src/ui/packages/partner/gradient/src/radial.ts","../../../../../../../src/ui/packages/partner/gradient/src/conic.ts","../../../../../../../src/ui/packages/partner/gradient/src/index.ts","../../../../../../../src/ui/packages/partner/effect/src/Shadow.ts","../../../../../../../src/ui/packages/partner/effect/src/InnerShadow.ts","../../../../../../../src/ui/packages/partner/effect/src/index.ts","../../../../../../../src/ui/packages/partner/effect/src/Blur.ts","../../../../../../../src/ui/packages/partner/effect/src/BackgroundBlur.ts","../../../../../../../src/ui/packages/partner/mask/src/index.ts","../../../../../../../src/ui/packages/partner/text/src/CharType.ts","../../../../../../../src/ui/packages/partner/text/src/TextRowHelper.ts","../../../../../../../src/ui/packages/partner/text/src/TextCase.ts","../../../../../../../src/ui/packages/partner/text/src/TextRows.ts","../../../../../../../src/ui/packages/partner/text/src/TextConvert.ts","../../../../../../../src/ui/packages/partner/text/src/index.ts","../../../../../../../src/ui/packages/partner/text/src/TextLayout.ts","../../../../../../../src/ui/packages/partner/text/src/CharLayout.ts","../../../../../../../src/ui/packages/partner/text/src/TextClip.ts","../../../../../../../src/ui/packages/partner/text/src/TextDecoration.ts","../../../../../../../src/ui/packages/partner/color/src/index.ts","../../../../../../../src/ui/packages/partner/color/src/color.ts","../../../../../../../src/ui/packages/partner/partner/src/index.ts","../../../../../../../src/draw/packages/platform/worker/src/index.ts"],"sourcesContent":["import { IScreenSizeData } from '@leafer/interface'\nimport { LeaferCanvasBase, Platform } from '@leafer/core'\n\nexport class LeaferCanvas extends LeaferCanvasBase {\n\n declare public view: OffscreenCanvas\n\n public get allowBackgroundColor(): boolean { return true }\n\n public init(): void {\n\n this.__createView()\n this.__createContext()\n\n this.resize(this.config as IScreenSizeData)\n }\n\n protected __createView(): void {\n this.view = Platform.origin.createCanvas(1, 1)\n }\n\n public updateViewSize(): void {\n const { width, height, pixelRatio } = this\n\n this.view.width = Math.ceil(width * pixelRatio)\n this.view.height = Math.ceil(height * pixelRatio)\n\n this.clientBounds = this.bounds\n }\n\n}","import { canvasPatch } from '@leafer/core'\n\nexport { LeaferCanvas } from './LeaferCanvas'\n\ncanvasPatch(OffscreenCanvasRenderingContext2D.prototype)\ncanvasPatch(Path2D.prototype)","export * from '@leafer/core'\n\nexport * from '@leafer/canvas-worker'\nexport * from '@leafer/image-worker'\n\nimport { ICreator, IFunction, IExportImageType, IExportFileType, IObject, ICanvasType } from '@leafer/interface'\nimport { Platform, Creator, FileHelper, defineKey } from '@leafer/core'\n\nimport { LeaferCanvas } from '@leafer/canvas-worker'\nimport { LeaferImage } from '@leafer/image-worker'\n\nconst { mineType } = FileHelper\n\n\nObject.assign(Creator, {\n canvas: (options?, manager?) => new LeaferCanvas(options, manager),\n image: (options) => new LeaferImage(options)\n} as ICreator)\n\n\nexport function useCanvas(_canvasType: ICanvasType, _power?: IObject): void {\n Platform.origin = {\n createCanvas: (width: number, height: number): OffscreenCanvas => new OffscreenCanvas(width, height),\n canvasToDataURL: (canvas: OffscreenCanvas, type?: IExportImageType, quality?: number) => {\n return new Promise((resolve, reject) => {\n (canvas as any).convertToBlob({ type: mineType(type), quality }).then((blob: Blob) => {\n var reader = new FileReader()\n reader.onload = (e) => resolve(e.target.result as string)\n reader.onerror = (e) => reject(e)\n reader.readAsDataURL(blob)\n }).catch((e: any) => {\n reject(e)\n })\n })\n },\n canvasToBolb: (canvas: OffscreenCanvas, type?: IExportFileType, quality?: number) => (canvas as any).convertToBlob({ type: mineType(type), quality }),\n canvasSaveAs: (_canvas: OffscreenCanvas, _filename: string, _quality?: any) => new Promise((resolve) => resolve()),\n download(_url: string, _filename: string): Promise<void> { return undefined },\n loadImage(src: any): Promise<ImageBitmap> {\n return new Promise((resolve, reject) => {\n let req = new XMLHttpRequest()\n req.open('GET', Platform.image.getRealURL(src), true)\n req.responseType = \"blob\"\n req.onload = () => {\n createImageBitmap(req.response).then(img => {\n resolve(img)\n }).catch(e => {\n reject(e)\n })\n }\n req.onerror = (e) => reject(e)\n req.send()\n })\n }\n }\n\n Platform.canvas = Creator.canvas()\n Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient\n}\n\nPlatform.name = 'web'\nPlatform.isWorker = true\nPlatform.backgrounder = true\nPlatform.requestRender = function (render: IFunction): void { requestAnimationFrame(render) }\ndefineKey(Platform, 'devicePixelRatio', { get() { return 1 } })\n\n\n// same as web\n\nconst { userAgent } = navigator\n\nif (userAgent.indexOf(\"Firefox\") > -1) {\n Platform.conicGradientRotate90 = true\n Platform.intWheelDeltaY = true\n} else if (userAgent.indexOf(\"Safari\") > -1 && userAgent.indexOf(\"Chrome\") === -1) {\n Platform.fullImageShadow = true\n}\n\nif (userAgent.indexOf('Windows') > -1) {\n Platform.os = 'Windows'\n Platform.intWheelDeltaY = true\n} else if (userAgent.indexOf('Mac') > -1) {\n Platform.os = 'Mac'\n} else if (userAgent.indexOf('Linux') > -1) {\n Platform.os = 'Linux'\n}","import { ILeaf, IWatcher, IEventListenerId, ILeafList, IWatcherConfig } from '@leafer/interface'\nimport { PropertyEvent, ChildEvent, RenderEvent, WatchEvent, LeafList, DataHelper } from '@leafer/core'\n\n\nexport class Watcher implements IWatcher {\n\n public target: ILeaf\n\n public totalTimes: number = 0\n\n public disabled: boolean\n public running: boolean\n public changed: boolean\n\n public hasVisible: boolean\n public hasAdd: boolean\n public hasRemove: boolean\n public get childrenChanged() { return this.hasAdd || this.hasRemove || this.hasVisible }\n\n public config: IWatcherConfig = {}\n\n public get updatedList(): ILeafList {\n if (this.hasRemove) {\n const updatedList = new LeafList()\n this.__updatedList.list.forEach(item => { if (item.leafer) updatedList.add(item) })\n return updatedList\n } else {\n return this.__updatedList\n }\n }\n\n protected __eventIds: IEventListenerId[]\n protected __updatedList: ILeafList = new LeafList()\n\n constructor(target: ILeaf, userConfig?: IWatcherConfig) {\n this.target = target\n if (userConfig) this.config = DataHelper.default(userConfig, this.config)\n this.__listenEvents()\n }\n\n public start(): void {\n if (this.disabled) return\n this.running = true\n }\n\n public stop(): void {\n this.running = false\n }\n\n public disable(): void {\n this.stop()\n this.__removeListenEvents()\n this.disabled = true\n }\n\n public update(): void {\n this.changed = true\n if (this.running) this.target.emit(RenderEvent.REQUEST)\n }\n\n protected __onAttrChange(event: PropertyEvent): void {\n this.__updatedList.add(event.target as ILeaf)\n this.update()\n }\n\n protected __onChildEvent(event: ChildEvent): void {\n if (event.type === ChildEvent.ADD) {\n this.hasAdd = true\n this.__pushChild(event.child)\n } else {\n this.hasRemove = true\n this.__updatedList.add(event.parent)\n }\n this.update()\n }\n\n protected __pushChild(child: ILeaf): void {\n this.__updatedList.add(child)\n if (child.isBranch) this.__loopChildren(child)\n }\n\n protected __loopChildren(parent: ILeaf): void {\n const { children } = parent\n for (let i = 0, len = children.length; i < len; i++) this.__pushChild(children[i])\n }\n\n public __onRquestData(): void {\n this.target.emitEvent(new WatchEvent(WatchEvent.DATA, { updatedList: this.updatedList }))\n this.__updatedList = new LeafList()\n this.totalTimes++\n this.changed = false\n this.hasVisible = false\n this.hasRemove = false\n this.hasAdd = false\n }\n\n protected __listenEvents(): void {\n const { target } = this\n this.__eventIds = [\n target.on_(PropertyEvent.CHANGE, this.__onAttrChange, this),\n target.on_([ChildEvent.ADD, ChildEvent.REMOVE], this.__onChildEvent, this),\n target.on_(WatchEvent.REQUEST, this.__onRquestData, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n }\n\n public destroy(): void {\n if (this.target) {\n this.stop()\n this.__removeListenEvents()\n this.target = null\n this.__updatedList = null\n }\n }\n\n}","import { ILeafLayout, ILeafLevelList, ILeafList, ILeaf } from '@leafer/interface'\nimport { BranchHelper, LeafHelper } from '@leafer/core'\n\n\nconst { updateAllMatrix, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper\nconst { pushAllChildBranch, pushAllParent } = BranchHelper\n\n\nexport function updateMatrix(updateList: ILeafList, levelList: ILeafLevelList): void {\n\n let layout: ILeafLayout\n updateList.list.forEach(leaf => { // 更新矩阵, 所有子元素,和父元素都需要更新bounds\n layout = leaf.__layout\n if (levelList.without(leaf) && !layout.proxyZoom) { // 防止重复, 子元素可能已经被父元素更新过\n\n if (layout.matrixChanged) {\n\n updateAllMatrix(leaf, true)\n\n levelList.add(leaf)\n if (leaf.isBranch) pushAllChildBranch(leaf, levelList)\n pushAllParent(leaf, levelList)\n\n } else if (layout.boundsChanged) {\n\n levelList.add(leaf)\n if (leaf.isBranch) leaf.__tempNumber = 0 // 标识需要更新子Leaf元素的WorldBounds分支, 0表示不需要更新\n pushAllParent(leaf, levelList)\n }\n }\n })\n\n}\n\nexport function updateBounds(boundsList: ILeafLevelList): void {\n let list: ILeaf[], branch: ILeaf, children: ILeaf[]\n boundsList.sort(true)\n boundsList.levels.forEach(level => {\n list = boundsList.levelMap[level]\n for (let i = 0, len = list.length; i < len; i++) {\n branch = list[i]\n\n // 标识了需要更新子元素\n if (branch.isBranch && branch.__tempNumber) {\n children = branch.children\n for (let j = 0, jLen = children.length; j < jLen; j++) {\n if (!children[j].isBranch) {\n updateOneBounds(children[j])\n }\n }\n }\n updateOneBounds(branch)\n }\n })\n}\n\n\nexport function updateChange(updateList: ILeafList): void {\n updateList.list.forEach(updateOneChange)\n}","import { IBounds, ILayoutBlockData, ILeafList, ILeaf } from '@leafer/interface'\nimport { Bounds, LeafBoundsHelper, LeafList } from '@leafer/core'\n\n\nconst { worldBounds } = LeafBoundsHelper\n\nexport class LayoutBlockData implements ILayoutBlockData {\n\n public updatedList: ILeafList\n public updatedBounds: IBounds = new Bounds()\n\n public beforeBounds: IBounds = new Bounds()\n public afterBounds: IBounds = new Bounds()\n\n constructor(list: ILeafList | ILeaf[]) {\n if (list instanceof Array) list = new LeafList(list)\n this.updatedList = list\n }\n\n public setBefore(): void {\n this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds)\n }\n\n public setAfter(): void {\n this.afterBounds.setListWithFn(this.updatedList.list, worldBounds)\n this.updatedBounds.setList([this.beforeBounds, this.afterBounds])\n }\n\n public merge(data: ILayoutBlockData): void {\n this.updatedList.addList(data.updatedList.list)\n this.beforeBounds.add(data.beforeBounds)\n this.afterBounds.add(data.afterBounds)\n this.updatedBounds.add(data.updatedBounds)\n }\n\n public destroy(): void {\n this.updatedList = null\n }\n\n}","import { ILayouter, ILeaf, ILayoutBlockData, IEventListenerId, ILayouterConfig, ILeafList } from '@leafer/interface'\nimport { LayoutEvent, WatchEvent, LeafLevelList, LeafList, BranchHelper, LeafHelper, DataHelper, Run, Debug } from '@leafer/core'\n\nimport { updateMatrix, updateBounds, updateChange } from './LayouterHelper'\nimport { LayoutBlockData } from './LayoutBlockData'\n\n\nconst { updateAllMatrix, updateAllChange } = LeafHelper\n\nconst debug = Debug.get('Layouter')\n\nexport class Layouter implements ILayouter {\n\n public target: ILeaf\n public layoutedBlocks: ILayoutBlockData[]\n public extraBlock: ILayoutBlockData // around / autoLayout\n\n public totalTimes: number = 0\n public times: number\n\n public disabled: boolean\n public running: boolean\n public layouting: boolean\n\n public waitAgain: boolean\n\n public config: ILayouterConfig = {}\n\n protected __updatedList: ILeafList\n protected __levelList: LeafLevelList = new LeafLevelList()\n protected __eventIds: IEventListenerId[]\n\n constructor(target: ILeaf, userConfig?: ILayouterConfig) {\n this.target = target\n if (userConfig) this.config = DataHelper.default(userConfig, this.config)\n this.__listenEvents()\n }\n\n public start(): void {\n if (this.disabled) return\n this.running = true\n }\n\n public stop(): void {\n this.running = false\n }\n\n public disable(): void {\n this.stop()\n this.__removeListenEvents()\n this.disabled = true\n }\n\n public layout(): void {\n if (!this.running) return\n const { target } = this\n this.times = 0\n\n try {\n target.emit(LayoutEvent.START)\n this.layoutOnce()\n target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times))\n } catch (e) {\n debug.error(e)\n }\n\n this.layoutedBlocks = null\n }\n\n public layoutAgain(): void {\n if (this.layouting) {\n this.waitAgain = true\n } else {\n this.layoutOnce()\n }\n }\n\n public layoutOnce(): void {\n if (this.layouting) return debug.warn('layouting')\n if (this.times > 3) return debug.warn('layout max times')\n\n this.times++\n this.totalTimes++\n\n this.layouting = true\n\n this.target.emit(WatchEvent.REQUEST)\n\n if (this.totalTimes > 1) {\n this.partLayout()\n } else {\n this.fullLayout()\n }\n\n this.layouting = false\n\n if (this.waitAgain) {\n this.waitAgain = false\n this.layoutOnce()\n }\n }\n\n public partLayout(): void {\n if (!this.__updatedList?.length) return\n\n const t = Run.start('PartLayout')\n const { target, __updatedList: updateList } = this\n const { BEFORE, LAYOUT, AFTER } = LayoutEvent\n\n const blocks = this.getBlocks(updateList)\n blocks.forEach(item => item.setBefore())\n target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times))\n\n this.extraBlock = null\n updateList.sort()\n updateMatrix(updateList, this.__levelList)\n updateBounds(this.__levelList)\n updateChange(updateList)\n\n if (this.extraBlock) blocks.push(this.extraBlock)\n blocks.forEach(item => item.setAfter())\n\n target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times))\n target.emitEvent(new LayoutEvent(AFTER, blocks, this.times))\n\n this.addBlocks(blocks)\n\n this.__levelList.reset()\n this.__updatedList = null\n Run.end(t)\n }\n\n public fullLayout(): void {\n const t = Run.start('FullLayout')\n\n const { target } = this\n const { BEFORE, LAYOUT, AFTER } = LayoutEvent\n\n const blocks = this.getBlocks(new LeafList(target))\n target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times))\n\n Layouter.fullLayout(target)\n\n blocks.forEach(item => { item.setAfter() })\n target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times))\n target.emitEvent(new LayoutEvent(AFTER, blocks, this.times))\n\n this.addBlocks(blocks)\n\n Run.end(t)\n }\n\n static fullLayout(target: ILeaf): void {\n updateAllMatrix(target, true)\n\n if (target.isBranch) {\n BranchHelper.updateBounds(target)\n } else {\n LeafHelper.updateBounds(target)\n }\n\n updateAllChange(target)\n }\n\n public addExtra(leaf: ILeaf): void {\n if (!this.__updatedList.has(leaf)) {\n const { updatedList, beforeBounds } = this.extraBlock || (this.extraBlock = new LayoutBlockData([]))\n updatedList.length ? beforeBounds.add(leaf.__world) : beforeBounds.set(leaf.__world)\n updatedList.add(leaf)\n }\n }\n\n public createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData {\n return new LayoutBlockData(data)\n }\n\n public getBlocks(list: ILeafList): ILayoutBlockData[] {\n return [this.createBlock(list)]\n }\n\n public addBlocks(current: ILayoutBlockData[]) {\n this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current\n }\n\n protected __onReceiveWatchData(event: WatchEvent): void {\n this.__updatedList = event.data.updatedList\n }\n\n protected __listenEvents(): void {\n const { target } = this\n this.__eventIds = [\n target.on_(LayoutEvent.REQUEST, this.layout, this),\n target.on_(LayoutEvent.AGAIN, this.layoutAgain, this),\n target.on_(WatchEvent.DATA, this.__onReceiveWatchData, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n }\n\n public destroy(): void {\n if (this.target) {\n this.stop()\n this.__removeListenEvents()\n this.target = this.config = null\n }\n }\n\n}\n\n\n","import { ILeaf, ILeaferBase, ILeaferCanvas, IRenderer, IRendererConfig, IEventListenerId, IBounds, IFunction, IRenderOptions } from '@leafer/interface'\nimport { LayoutEvent, RenderEvent, ResizeEvent, ImageManager, Bounds, DataHelper, Platform, Debug, Run } from '@leafer/core'\n\n\nconst debug = Debug.get('Renderer')\n\nexport class Renderer implements IRenderer {\n\n public target: ILeaf\n public canvas: ILeaferCanvas\n public updateBlocks: IBounds[]\n\n public FPS = 60\n public totalTimes = 0\n public times: number = 0\n\n public running: boolean\n public rendering: boolean\n\n public waitAgain: boolean\n public changed: boolean\n public ignore: boolean\n\n public config: IRendererConfig = {\n usePartRender: true,\n maxFPS: 60\n }\n\n static clipSpread = 10\n\n protected renderBounds: IBounds\n protected renderOptions: IRenderOptions\n protected totalBounds: IBounds\n\n protected requestTime: number\n protected __eventIds: IEventListenerId[]\n\n protected get needFill(): boolean { return !!(!this.canvas.allowBackgroundColor && this.config.fill) }\n\n constructor(target: ILeaf, canvas: ILeaferCanvas, userConfig?: IRendererConfig) {\n this.target = target\n this.canvas = canvas\n if (userConfig) this.config = DataHelper.default(userConfig, this.config)\n this.__listenEvents()\n }\n\n public start(): void {\n this.running = true\n this.update(false)\n }\n\n public stop(): void {\n this.running = false\n }\n\n public update(change = true): void {\n if (!this.changed) this.changed = change\n this.__requestRender()\n }\n\n public requestLayout(): void {\n this.target.emit(LayoutEvent.REQUEST)\n }\n\n public checkRender(): void {\n if (this.running) {\n const { target } = this\n if (target.isApp) {\n target.emit(RenderEvent.CHILD_START, target);\n (target.children as ILeaferBase[]).forEach(leafer => {\n leafer.renderer.FPS = this.FPS\n leafer.renderer.checkRender()\n })\n target.emit(RenderEvent.CHILD_END, target)\n }\n\n if (this.changed && this.canvas.view) this.render()\n this.target.emit(RenderEvent.NEXT)\n }\n }\n\n public render(callback?: IFunction): void {\n if (!(this.running && this.canvas.view)) return this.update()\n\n const { target } = this\n this.times = 0\n this.totalBounds = new Bounds()\n\n debug.log(target.innerName, '--->')\n\n try {\n this.emitRender(RenderEvent.START)\n this.renderOnce(callback)\n this.emitRender(RenderEvent.END, this.totalBounds)\n\n ImageManager.clearRecycled()\n } catch (e) {\n this.rendering = false\n debug.error(e)\n }\n\n debug.log('-------------|')\n }\n\n public renderAgain(): void {\n if (this.rendering) {\n this.waitAgain = true\n } else {\n this.renderOnce()\n }\n }\n\n public renderOnce(callback?: IFunction): void {\n if (this.rendering) return debug.warn('rendering')\n if (this.times > 3) return debug.warn('render max times')\n\n this.times++\n this.totalTimes++\n\n this.rendering = true\n this.changed = false\n this.renderBounds = new Bounds()\n this.renderOptions = {}\n\n if (callback) {\n this.emitRender(RenderEvent.BEFORE)\n callback()\n } else {\n this.requestLayout()\n\n if (this.ignore) {\n this.ignore = this.rendering = false // 仍保留 updateBlocks 用于下次渲染\n return\n }\n\n this.emitRender(RenderEvent.BEFORE)\n\n if (this.config.usePartRender && this.totalTimes > 1) {\n this.partRender()\n } else {\n this.fullRender()\n }\n }\n\n this.emitRender(RenderEvent.RENDER, this.renderBounds, this.renderOptions)\n this.emitRender(RenderEvent.AFTER, this.renderBounds, this.renderOptions)\n\n this.updateBlocks = null\n this.rendering = false\n\n if (this.waitAgain) {\n this.waitAgain = false\n this.renderOnce()\n }\n }\n\n public partRender(): void {\n const { canvas, updateBlocks: list } = this\n if (!list) return // debug.warn('PartRender: need update attr')\n\n this.mergeBlocks()\n list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block) })\n }\n\n public clipRender(block: IBounds): void {\n const t = Run.start('PartRender')\n const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds)\n\n canvas.save()\n\n bounds.spread(Renderer.clipSpread).ceil()\n canvas.clearWorld(bounds, true)\n canvas.clipWorld(bounds, true)\n\n this.__render(bounds, realBounds)\n canvas.restore()\n\n Run.end(t)\n }\n\n public fullRender(): void {\n const t = Run.start('FullRender')\n const { canvas } = this\n\n canvas.save()\n canvas.clear()\n this.__render(canvas.bounds)\n canvas.restore()\n\n Run.end(t)\n }\n\n protected __render(bounds: IBounds, realBounds?: IBounds): void {\n const { canvas } = this, includes = bounds.includes(this.target.__world), options: IRenderOptions = includes ? { includes } : { bounds, includes }\n\n if (this.needFill) canvas.fillWorld(bounds, this.config.fill)\n if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds)\n\n this.target.__render(canvas, options)\n\n this.renderBounds = realBounds = realBounds || bounds\n this.renderOptions = options\n this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds)\n\n canvas.updateRender(realBounds)\n }\n\n public addBlock(block: IBounds): void {\n if (!this.updateBlocks) this.updateBlocks = []\n this.updateBlocks.push(block)\n }\n\n public mergeBlocks(): void {\n const { updateBlocks: list } = this\n if (list) {\n const bounds = new Bounds()\n bounds.setList(list)\n list.length = 0\n list.push(bounds)\n }\n }\n\n protected __requestRender(): void {\n const target = this.target as ILeaferBase\n if (this.requestTime || !target) return\n if (target.parentApp) return target.parentApp.requestRender(false) // App 模式下统一走 app 控制渲染帧\n\n const requestTime = this.requestTime = Date.now()\n Platform.requestRender(() => {\n\n this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)))\n this.requestTime = 0\n\n this.checkRender()\n\n })\n }\n\n protected __onResize(e: ResizeEvent): void {\n if (this.canvas.unreal) return\n if (e.bigger || !e.samePixelRatio) {\n const { width, height } = e.old\n const bounds = new Bounds(0, 0, width, height)\n if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {\n this.addBlock(this.canvas.bounds)\n this.target.forceUpdate('surface')\n return\n }\n }\n\n // 需要象征性派发一下渲染事件\n this.addBlock(new Bounds(0, 0, 1, 1))\n this.update()\n }\n\n protected __onLayoutEnd(event: LayoutEvent): void {\n if (event.data) event.data.map(item => {\n let empty: boolean\n if (item.updatedList) item.updatedList.list.some(leaf => {\n empty = (!leaf.__world.width || !leaf.__world.height)\n if (empty) {\n if (!leaf.isLeafer) debug.tip(leaf.innerName, ': empty')\n empty = (!leaf.isBranch || leaf.isBranchLeaf) // render object\n }\n return empty\n })\n this.addBlock(empty ? this.canvas.bounds : item.updatedBounds)\n })\n }\n\n protected emitRender(type: string, bounds?: IBounds, options?: IRenderOptions): void {\n this.target.emitEvent(new RenderEvent(type, this.times, bounds, options))\n }\n\n protected __listenEvents(): void {\n const { target } = this\n this.__eventIds = [\n target.on_(RenderEvent.REQUEST, this.update, this),\n target.on_(LayoutEvent.END, this.__onLayoutEnd, this),\n target.on_(RenderEvent.AGAIN, this.renderAgain, this),\n target.on_(ResizeEvent.RESIZE, this.__onResize, this)\n ]\n }\n\n protected __removeListenEvents(): void {\n this.target.off_(this.__eventIds)\n }\n\n public destroy(): void {\n if (this.target) {\n this.stop()\n this.__removeListenEvents()\n this.target = this.canvas = this.config = null\n }\n }\n}","import { ILeaferCanvas } from '@leafer/interface'\n\nimport { ITextRowData, IText } from '@leafer-ui/interface'\n\n\nexport function fillText(ui: IText, canvas: ILeaferCanvas): void {\n\n const data = ui.__, { rows, decorationY } = data.__textDrawData\n if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor\n\n let row: ITextRowData\n\n for (let i = 0, len = rows.length; i < len; i++) {\n row = rows[i]\n\n if (row.text) canvas.fillText(row.text, row.x, row.y)\n else if (row.data) row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y) })\n }\n\n if (decorationY) {\n const { decorationColor, decorationHeight } = data.__textDrawData\n if (decorationColor) canvas.fillStyle = decorationColor\n rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)))\n }\n\n}\n","import { ILeaferCanvas } from '@leafer/interface'\n\nimport { ILeafPaint, IUI } from '@leafer-ui/interface'\nimport { PaintImage } from \"@leafer-ui/draw\"\n\nimport { fillText } from './FillText'\n\n\nexport function fill(fill: string, ui: IUI, canvas: ILeaferCanvas): void {\n canvas.fillStyle = fill\n fillPathOrText(ui, canvas)\n}\n\n\nexport function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {\n let item: ILeafPaint\n for (let i = 0, len = fills.length; i < len; i++) {\n item = fills[i]\n\n if (item.image) {\n\n if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue\n\n if (!item.style) {\n if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image) // 图片加载中或加载失败\n continue\n }\n\n }\n\n canvas.fillStyle = item.style\n\n if (item.transform) {\n\n canvas.save()\n canvas.transform(item.transform)\n if (item.blendMode) canvas.blendMode = item.blendMode\n fillPathOrText(ui, canvas)\n canvas.restore()\n\n } else {\n\n if (item.blendMode) {\n\n canvas.saveBlendMode(item.blendMode)\n fillPathOrText(ui, canvas)\n canvas.restoreBlendMode()\n\n } else fillPathOrText(ui, canvas)\n\n }\n\n }\n}\n\n\nexport function fillPathOrText(ui: IUI, canvas: ILeaferCanvas): void {\n ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill())\n}","import { ILeaferCanvas } from '@leafer/interface'\n\nimport { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'\nimport { PaintImage } from \"@leafer-ui/draw\"\n\nimport { fillText } from './FillText'\n\n\nexport function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {\n const { strokeAlign } = ui.__\n const isStrokes = typeof stroke !== 'string'\n switch (strokeAlign) {\n case 'center':\n canvas.setStroke(isStrokes ? undefined : stroke, ui.__.strokeWidth, ui.__)\n isStrokes ? drawStrokesStyle(stroke as ILeafPaint[], true, ui, canvas) : drawTextStroke(ui, canvas)\n break\n case 'inside':\n drawAlignStroke('inside', stroke, isStrokes, ui, canvas)\n break\n case 'outside':\n drawAlignStroke('outside', stroke, isStrokes, ui, canvas)\n break\n }\n}\n\nfunction drawAlignStroke(align: IStrokeAlign, stroke: string | ILeafPaint[], isStrokes: boolean, ui: IUI, canvas: ILeaferCanvas): void {\n const { __strokeWidth, __font } = ui.__\n\n const out = canvas.getSameCanvas(true, true)\n out.setStroke(isStrokes ? undefined : stroke, __strokeWidth * 2, ui.__)\n\n out.font = __font\n isStrokes ? drawStrokesStyle(stroke as ILeafPaint[], true, ui, out) : drawTextStroke(ui, out)\n\n out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in'\n fillText(ui, out)\n out.blendMode = 'normal'\n\n if (ui.__worldFlipped) canvas.copyWorldByReset(out, ui.__nowWorld)\n else canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds)\n\n out.recycle(ui.__nowWorld)\n}\n\nexport function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {\n\n let row: ITextRowData, data = ui.__.__textDrawData\n const { rows, decorationY } = data\n\n for (let i = 0, len = rows.length; i < len; i++) {\n row = rows[i]\n\n if (row.text) canvas.strokeText(row.text, row.x, row.y)\n else if (row.data) row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y) })\n }\n\n if (decorationY) {\n const { decorationHeight } = data\n rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)))\n }\n\n}\n\nexport function drawStrokesStyle(strokes: ILeafStrokePaint[], isText: boolean, ui: IUI, canvas: ILeaferCanvas): void {\n let item: ILeafStrokePaint\n for (let i = 0, len = strokes.length; i < len; i++) {\n item = strokes[i]\n\n if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue\n\n if (item.style) {\n canvas.strokeStyle = item.style\n\n if (item.blendMode) {\n canvas.saveBlendMode(item.blendMode)\n isText ? drawTextStroke(ui, canvas) : canvas.stroke()\n canvas.restoreBlendMode()\n } else {\n isText ? drawTextStroke(ui, canvas) : canvas.stroke()\n }\n }\n }\n}","import { ILeaferCanvas } from '@leafer/interface'\n\nimport { IUI, ILeafPaint } from '@leafer-ui/interface'\n\nimport { strokeText, drawStrokesStyle } from './StrokeText'\n\n\nexport function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas): void {\n const options = ui.__\n const { __strokeWidth, strokeAlign, __font } = options\n if (!__strokeWidth) return\n\n if (__font) {\n\n strokeText(stroke, ui, canvas)\n\n } else {\n\n switch (strokeAlign) {\n\n case 'center':\n\n canvas.setStroke(stroke, __strokeWidth, options)\n canvas.stroke()\n\n if (options.__useArrow) strokeArrow(ui, canvas)\n\n break\n\n case 'inside':\n\n canvas.save()\n canvas.setStroke(stroke, __strokeWidth * 2, options)\n\n options.windingRule ? canvas.clip(options.windingRule) : canvas.clip()\n canvas.stroke()\n\n canvas.restore()\n\n break\n\n case 'outside':\n const out = canvas.getSameCanvas(true, true)\n out.setStroke(stroke, __strokeWidth * 2, options)\n\n ui.__drawRenderPath(out)\n\n out.stroke()\n\n options.windingRule ? out.clip(options.windingRule) : out.clip()\n out.clearWorld(ui.__layout.renderBounds)\n\n if (ui.__worldFlipped) canvas.copyWorldByReset(out, ui.__nowWorld)\n else canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds)\n\n out.recycle(ui.__nowWorld)\n break\n }\n\n }\n}\n\n\nexport function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {\n const options = ui.__\n const { __strokeWidth, strokeAlign, __font } = options\n if (!__strokeWidth) return\n\n if (__font) {\n\n strokeText(strokes, ui, canvas)\n\n } else {\n\n switch (strokeAlign) {\n\n case 'center':\n canvas.setStroke(undefined, __strokeWidth, options)\n drawStrokesStyle(strokes, false, ui, canvas)\n\n if (options.__useArrow) strokeArrow(ui, canvas)\n break\n\n case 'inside':\n canvas.save()\n canvas.setStroke(undefined, __strokeWidth * 2, options)\n options.windingRule ? canvas.clip(options.windingRule) : canvas.clip()\n\n drawStrokesStyle(strokes, false, ui, canvas)\n\n canvas.restore()\n break\n\n case 'outside':\n const { renderBounds } = ui.__layout\n const out = canvas.getSameCanvas(true, true)\n ui.__drawRenderPath(out)\n\n out.setStroke(undefined, __strokeWidth * 2, options)\n\n drawStrokesStyle(strokes, false, ui, out)\n\n options.windingRule ? out.clip(options.windingRule) : out.clip()\n out.clearWorld(renderBounds)\n\n if (ui.__worldFlipped) canvas.copyWorldByReset(out, ui.__nowWorld)\n else canvas.copyWorldToInner(out, ui.__nowWorld, renderBounds)\n\n out.recycle(ui.__nowWorld)\n break\n }\n\n }\n\n}\n\n\nfunction strokeArrow(ui: IUI, canvas: ILeaferCanvas): void {\n if (ui.__.dashPattern) { // fix: dashPattern Arrow\n canvas.beginPath()\n ui.__drawPathByData(canvas, ui.__.__pathForArrow)\n canvas.dashPattern = null\n canvas.stroke()\n }\n}","// leafer's partner, allow replace\nexport * from '@leafer/watcher'\nexport * from '@leafer/layouter'\nexport * from '@leafer/renderer'\n\nimport { ICreator } from '@leafer/interface'\nimport { Creator, Platform } from '@leafer/core'\n\nimport { Watcher } from '@leafer/watcher'\nimport { Layouter } from '@leafer/layouter'\nimport { Renderer } from '@leafer/renderer'\n\n\nObject.assign(Creator, {\n watcher: (target, options?) => new Watcher(target, options),\n layouter: (target, options?) => new Layouter(target, options),\n renderer: (target, canvas, options?) => new Renderer(target, canvas, options),\n selector: (_target, _options?) => undefined,\n interaction: (_target, _canvas, _selector, _options?) => undefined\n} as ICreator)\n\nPlatform.layout = Layouter.fullLayout","import { IBoundsData, ILeaferCanvas, IRenderOptions, IMatrix } from '@leafer/interface'\nimport { BoundsHelper } from '@leafer/core'\n\nimport { IUI, ICachedShape } from '@leafer-ui/interface'\n\n\nconst { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper\n\nexport function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions): ICachedShape {\n const canvas = current.getSameCanvas()\n const nowWorld = ui.__nowWorld\n\n let bounds: IBoundsData, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas\n\n let { scaleX, scaleY } = nowWorld\n if (scaleX < 0) scaleX = -scaleX\n if (scaleY < 0) scaleY = -scaleY\n\n if (current.bounds.includes(nowWorld)) {\n\n worldCanvas = canvas\n bounds = shapeBounds = nowWorld\n\n } else {\n\n const { renderShapeSpread: spread } = ui.__layout\n const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld)\n fitMatrix = current.bounds.getFitMatrix(worldClipBounds)\n let { a: fitScaleX, d: fitScaleY } = fitMatrix\n\n if (fitMatrix.a < 1) {\n worldCanvas = current.getSameCanvas()\n ui.__renderShape(worldCanvas, options)\n\n scaleX *= fitScaleX\n scaleY *= fitScaleY\n }\n\n shapeBounds = getOuterOf(nowWorld, fitMatrix)\n bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f)\n\n if (options.matrix) {\n const { matrix } = options\n fitMatrix.multiply(matrix)\n fitScaleX *= matrix.scaleX\n fitScaleY *= matrix.scaleY\n }\n\n options = { ...options, matrix: fitMatrix.withScale(fitScaleX, fitScaleY) }\n\n }\n\n ui.__renderShape(canvas, options)\n\n return {\n canvas, matrix: fitMatrix, bounds,\n worldCanvas, shapeBounds, scaleX, scaleY\n }\n}","import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IObject, IPaintAttr } from '@leafer-ui/interface'\nimport { ColorConvert, PaintImage, PaintGradient } from '@leafer-ui/draw'\n\n\nlet recycleMap: IBooleanMap\n\nexport function compute(attrName: IPaintAttr, ui: IUI): void {\n const data = ui.__, leafPaints: ILeafPaint[] = []\n\n let paints: IPaint[] = data.__input[attrName], hasOpacityPixel: boolean\n if (!(paints instanceof Array)) paints = [paints]\n\n recycleMap = PaintImage.recycleImage(attrName, data)\n\n for (let i = 0, len = paints.length, item: ILeafPaint; i < len; i++) {\n item = getLeafPaint(attrName, paints[i], ui)\n if (item) leafPaints.push(item)\n }\n\n (data as IObject)['_' + attrName] = leafPaints.length ? leafPaints : undefined\n\n if (leafPaints.length && leafPaints[0].image) hasOpacityPixel = leafPaints[0].image.hasOpacityPixel\n attrName === 'fill' ? data.__pixelFill = hasOpacityPixel : data.__pixelStroke = hasOpacityPixel\n}\n\n\nfunction getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {\n if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0) return undefined\n const { boxBounds } = ui.__layout\n\n switch (paint.type) {\n case 'solid':\n let { type, blendMode, color, opacity } = paint\n return { type, blendMode, style: ColorConvert.string(color, opacity) }\n case 'image':\n return PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url])\n case 'linear':\n return PaintGradient.linearGradient(paint, boxBounds)\n case 'radial':\n return PaintGradient.radialGradient(paint, boxBounds)\n case 'angular':\n return PaintGradient.conicGradient(paint, boxBounds)\n default:\n return (paint as IRGB).r !== undefined ? { type: 'solid', style: ColorConvert.string(paint) } : undefined\n }\n}","import { IPaintModule } from '@leafer-ui/interface'\n\nimport { fill, fills, fillPathOrText } from './Fill'\nimport { fillText } from './FillText'\nimport { stroke, strokes } from './Stroke'\nimport { strokeText, drawTextStroke } from './StrokeText'\nimport { shape } from './Shape'\nimport { compute } from './Compute'\n\n\nexport const PaintModule: IPaintModule = {\n compute,\n fill,\n fills,\n fillPathOrText,\n fillText,\n stroke,\n strokes,\n strokeText,\n drawTextStroke,\n shape\n}","import { IBoundsData, IPointData, IMatrixData, IAlign, } from '@leafer/interface'\nimport { MatrixHelper } from '@leafer/core'\n\nimport { ILeafPaintPatternData } from '@leafer-ui/interface'\n\n\nlet origin = {} as IPointData\nconst { get, rotateOfOuter, translate, scaleOfOuter, scale: scaleHelper, rotate } = MatrixHelper\n\nexport function fillOrFitMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {\n const transform: IMatrixData = get()\n translate(transform, box.x + x, box.y + y)\n scaleHelper(transform, scaleX, scaleY)\n if (rotation) rotateOfOuter(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation)\n data.transform = transform\n}\n\n\nexport function clipMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {\n const transform: IMatrixData = get()\n translate(transform, box.x + x, box.y + y)\n if (scaleX) scaleHelper(transform, scaleX, scaleY)\n if (rotation) rotate(transform, rotation)\n data.transform = transform\n}\n\n\nexport function repeatMode(data: ILeafPaintPatternData, box: IBoundsData, width: number, height: number, x: number, y: number, scaleX: number, scaleY: number, rotation: number, align: IAlign): void {\n const transform = get()\n if (rotation) {\n if (align === 'center') {\n rotateOfOuter(transform, { x: width / 2, y: height / 2 }, rotation)\n } else {\n rotate(transform, rotation)\n switch (rotation) {\n case 90:\n translate(transform, height, 0)\n break\n case 180:\n translate(transform, width, height)\n break\n case 270:\n translate(transform, 0, width)\n break\n }\n }\n }\n origin.x = box.x + x\n origin.y = box.y + y\n translate(transform, origin.x, origin.y)\n if (scaleX) scaleOfOuter(transform, origin, scaleX, scaleY)\n data.transform = transform\n}","import { IBoundsData, ILeaferImage, IPointData, IScaleData } from '@leafer/interface'\nimport { MatrixHelper, MathHelper, Bounds, AlignHelper } from '@leafer/core'\n\nimport { IImagePaint, ILeafPaint, ILeafPaintPatternData } from '@leafer-ui/interface'\n\nimport { clipMode, fillOrFitMode, repeatMode } from './mode'\n\n\nconst { get, translate } = MatrixHelper\nconst tempBox = new Bounds()\nconst tempPoint = {} as IPointData\nconst tempScaleData = {} as IScaleData\n\nexport function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {\n const { blendMode, changeful, sync } = paint\n if (blendMode) leafPaint.blendMode = blendMode\n if (changeful) leafPaint.changeful = changeful\n if (sync) leafPaint.sync = sync\n leafPaint.data = getPatternData(paint, box, image)\n}\n\nexport function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILeaferImage): ILeafPaintPatternData {\n let { width, height } = image\n if (paint.padding) box = tempBox.set(box).shrink(paint.padding)\n if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除\n\n const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint\n const sameBox = box.width === width && box.height === height\n\n const data: ILeafPaintPatternData = { mode }\n const swapSize = align !== 'center' && (rotation || 0) % 180 === 90\n const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height\n\n let x = 0, y = 0, scaleX: number, scaleY: number\n\n if (!mode || mode === 'cover' || mode === 'fit') {\n if (!sameBox || rotation) {\n const sw = box.width / swapWidth, sh = box.height / swapHeight\n scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh)\n x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2\n }\n } else if (scale || size) {\n MathHelper.getScaleData(scale, size, image, tempScaleData)\n scaleX = tempScaleData.scaleX\n scaleY = tempScaleData.scaleY\n }\n\n if (align) {\n const imageBounds = { x, y, width: swapWidth, height: swapHeight }\n if (scaleX) imageBounds.width *= scaleX, imageBounds.height *= scaleY\n AlignHelper.toPoint(align, imageBounds, box, tempPoint, true)\n x += tempPoint.x, y += tempPoint.y\n }\n\n if (offset) x += offset.x, y += offset.y\n\n switch (mode) {\n case 'stretch':\n if (!sameBox) width = box.width, height = box.height\n break\n case 'normal':\n case 'clip':\n if (x || y || scaleX || rotation) clipMode(data, box, x, y, scaleX, scaleY, rotation)\n break\n case 'repeat':\n if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align)\n if (!repeat) data.repeat = 'repeat'\n break\n case 'fit':\n case 'cover':\n default:\n if (scaleX) fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation)\n }\n\n if (!data.transform) {\n if (box.x || box.y) {\n data.transform = get()\n translate(data.transform, box.x, box.y)\n }\n }\n\n if (scaleX && mode !== 'stretch') {\n data.scal