├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── packages ├── canvas │ ├── canvas-canvaskit │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── canvas-miniapp │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── LeaferCanvas.ts │ │ │ └── index.ts │ ├── canvas-node │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── LeaferCanvas.ts │ │ │ └── index.ts │ ├── canvas-web │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── LeaferCanvas.ts │ │ │ └── index.ts │ ├── canvas-worker │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── LeaferCanvas.ts │ │ │ └── index.ts │ └── canvas │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ ├── Canvas.ts │ │ ├── CanvasManager.ts │ │ ├── LeaferCanvasBase.ts │ │ ├── index.ts │ │ └── patch │ │ ├── index.ts │ │ └── roundRect.ts ├── core │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ └── index.ts ├── debug │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── Debug.ts │ │ ├── Plugin.ts │ │ ├── Run.ts │ │ └── index.ts ├── decorator │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── class.ts │ │ ├── data.ts │ │ ├── define.ts │ │ ├── index.ts │ │ ├── object.ts │ │ └── rewrite.ts ├── display-module │ ├── data │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── DataHelper.ts │ │ │ ├── LeafData.ts │ │ │ └── index.ts │ ├── display-module │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── BranchRender.ts │ │ │ ├── LeafBounds.ts │ │ │ ├── LeafDataProxy.ts │ │ │ ├── LeafEventer.ts │ │ │ ├── LeafMatrix.ts │ │ │ ├── LeafRender.ts │ │ │ └── index.ts │ ├── helper │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── BranchHelper.ts │ │ │ ├── LeafBoundsHelper.ts │ │ │ ├── LeafHelper.ts │ │ │ ├── WaitHelper.ts │ │ │ └── index.ts │ └── layout │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ ├── LeafLayout.ts │ │ └── index.ts ├── display │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── Branch.ts │ │ ├── Leaf.ts │ │ └── index.ts ├── event │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── BoundsEvent.ts │ │ ├── ChildEvent.ts │ │ ├── Event.ts │ │ ├── Eventer.ts │ │ ├── ImageEvent.ts │ │ ├── LayoutEvent.ts │ │ ├── LeaferEvent.ts │ │ ├── PropertyEvent.ts │ │ ├── RenderEvent.ts │ │ ├── ResizeEvent.ts │ │ ├── WatchEvent.ts │ │ └── index.ts ├── file │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── FileHelper.ts │ │ ├── Resource.ts │ │ └── index.ts ├── image │ ├── image-canvaskit │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── image-miniapp │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── image-node │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── image-web │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── image-worker │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ └── image │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ ├── ImageManager.ts │ │ ├── LeaferImage.ts │ │ └── index.ts ├── interface │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── animate │ │ └── ITransition.ts │ │ ├── app │ │ ├── IApp.ts │ │ └── ILeafer.ts │ │ ├── canvas │ │ ├── ICanvas.ts │ │ ├── ICanvasManager.ts │ │ ├── IHitCanvasManager.ts │ │ ├── ILeaferCanvas.ts │ │ └── ISkiaCanvas.ts │ │ ├── control │ │ └── IControl.ts │ │ ├── data │ │ ├── IData.ts │ │ ├── ILeafData.ts │ │ └── IList.ts │ │ ├── display │ │ ├── IBranch.ts │ │ ├── ILeaf.ts │ │ ├── IView.ts │ │ └── module │ │ │ ├── IBranchRender.ts │ │ │ ├── ILeafBounds.ts │ │ │ ├── ILeafDataProxy.ts │ │ │ ├── ILeafEventer.ts │ │ │ ├── ILeafHit.ts │ │ │ ├── ILeafMatrix.ts │ │ │ └── ILeafRender.ts │ │ ├── event │ │ ├── IEvent.ts │ │ ├── IEventer.ts │ │ ├── IProgress.ts │ │ └── IUIEvent.ts │ │ ├── file │ │ ├── IExport.ts │ │ ├── IFileType.ts │ │ └── IResource.ts │ │ ├── function │ │ └── IFunction.ts │ │ ├── image │ │ ├── IImageManager.ts │ │ └── ILeaferImage.ts │ │ ├── index.ts │ │ ├── interaction │ │ ├── ICursor.ts │ │ ├── IInteraction.ts │ │ └── ITransformer.ts │ │ ├── layout │ │ └── ILeafLayout.ts │ │ ├── layouter │ │ └── ILayouter.ts │ │ ├── math │ │ └── IMath.ts │ │ ├── path │ │ ├── IPathCommand.ts │ │ ├── IPathData.ts │ │ └── IPathDrawer.ts │ │ ├── platform │ │ └── IPlatform.ts │ │ ├── plugin │ │ └── IPlugin.ts │ │ ├── renderer │ │ └── IRenderer.ts │ │ ├── selector │ │ └── ISelector.ts │ │ ├── task │ │ └── ITaskProcessor.ts │ │ └── watcher │ │ └── IWatcher.ts ├── list │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── LeafLevelList.ts │ │ ├── LeafList.ts │ │ └── index.ts ├── math │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── AlignHelper.ts │ │ ├── AroundHelper.ts │ │ ├── AutoBounds.ts │ │ ├── Bounds.ts │ │ ├── BoundsHelper.ts │ │ ├── Direction.ts │ │ ├── IncrementId.ts │ │ ├── MathHelper.ts │ │ ├── Matrix.ts │ │ ├── MatrixHelper.ts │ │ ├── Point.ts │ │ ├── PointHelper.ts │ │ ├── StringNumber.ts │ │ ├── TwoPointBoundsHelper.ts │ │ └── index.ts ├── partner │ ├── layouter │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── LayoutBlockData.ts │ │ │ ├── Layouter.ts │ │ │ ├── LayouterHelper.ts │ │ │ └── index.ts │ ├── partner │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── renderer │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── Renderer.ts │ │ │ └── index.ts │ ├── selector │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── Picker.ts │ │ │ ├── Selector.ts │ │ │ └── index.ts │ └── watcher │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ ├── Watcher.ts │ │ └── index.ts ├── path │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ │ ├── BezierHelper.ts │ │ ├── EllipseHelper.ts │ │ ├── PathBounds.ts │ │ ├── PathCommandDataHelper.ts │ │ ├── PathCommandMap.ts │ │ ├── PathConvert.ts │ │ ├── PathCorner.ts │ │ ├── PathCreator.ts │ │ ├── PathDrawer.ts │ │ ├── PathHelper.ts │ │ ├── RectHelper.ts │ │ └── index.ts ├── platform │ ├── canvaskit │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── miniapp │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── node │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── platform │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ ├── Platform.ts │ │ │ ├── creator │ │ │ ├── Creator.ts │ │ │ ├── EventCreator.ts │ │ │ └── UICreator.ts │ │ │ └── index.ts │ ├── web │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ └── worker │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ └── index.ts └── task │ ├── LICENSE │ ├── README.md │ ├── package.json │ └── src │ ├── TaskItem.ts │ ├── TaskProcessor.ts │ └── index.ts └── src └── index.ts /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | lib 3 | types 4 | node_modules 5 | 6 | .DS_Store 7 | 8 | .idea 9 | .vscode 10 | 11 | .eslintcache 12 | *.tsbuildinfo 13 | *.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leafer", 3 | "version": "1.6.7", 4 | "description": "leafer", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "dist/web.esm.min.js", 9 | "exports": { 10 | "import": "./dist/web.esm.min.js", 11 | "require": "./dist/web.min.cjs", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "types": "types/index.d.ts", 15 | "unpkg": "dist/web.min.js", 16 | "jsdelivr": "dist/web.min.js", 17 | "files": ["src","types","dist"], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/leaferjs/leafer" 21 | }, 22 | "homepage": "https://github.com/leaferjs/leafer", 23 | "bugs": "https://github.com/leaferjs/leafer/issues", 24 | "keywords": [ 25 | "leafer", 26 | "leaferjs", 27 | "html5", 28 | "canvas", 29 | "2d", 30 | "graphic", 31 | "renderer", 32 | "engine" 33 | ], 34 | "dependencies": { 35 | "leafer-ui": "1.6.7", 36 | "@leafer-ui/draw": "1.6.7", 37 | "@leafer-ui/core": "1.6.7", 38 | "@leafer/web": "1.6.7", 39 | "@leafer-in/editor": "1.6.7", 40 | "@leafer-in/text-editor": "1.6.7", 41 | "@leafer-in/viewport": "1.6.7", 42 | "@leafer-in/view": "1.6.7", 43 | "@leafer-in/scroll": "1.6.7", 44 | "@leafer-in/html": "1.6.7", 45 | "@leafer-in/arrow": "1.6.7", 46 | "@leafer-in/flow": "1.6.7", 47 | "@leafer-in/animate": "1.6.7", 48 | "@leafer-in/motion-path": "1.6.7", 49 | "@leafer-in/state": "1.6.7", 50 | "@leafer-in/robot": "1.6.7", 51 | "@leafer-in/find": "1.6.7", 52 | "@leafer-in/export": "1.6.7", 53 | "@leafer-in/filter": "1.6.7", 54 | "@leafer-in/color": "1.6.7", 55 | "@leafer-in/resize": "1.6.7", 56 | "@leafer-in/interface": "1.6.7" 57 | } 58 | } -------------------------------------------------------------------------------- /packages/canvas/canvas-canvaskit/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas-canvaskit/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas-canvaskit 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas-canvaskit/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas-canvaskit", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas-canvaskit", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas-canvaskit", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/canvas/canvas-canvaskit/src/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leaferjs/leafer/81ea1f3f07690782f3b6075275068cc5869c8eda/packages/canvas/canvas-canvaskit/src/index.ts -------------------------------------------------------------------------------- /packages/canvas/canvas-miniapp/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas-miniapp/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas-miniapp 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas-miniapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas-miniapp", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas-miniapp", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas-miniapp", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/canvas": "1.6.7", 22 | "@leafer/data": "1.6.7", 23 | "@leafer/event": "1.6.7", 24 | "@leafer/platform": "1.6.7", 25 | "@leafer/debug": "1.6.7" 26 | }, 27 | "devDependencies": { 28 | "@leafer/interface": "1.6.7" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/canvas/canvas-miniapp/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferCanvas } from './LeaferCanvas' -------------------------------------------------------------------------------- /packages/canvas/canvas-node/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas-node/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas-node 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas-node", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas-node", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas-node", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/canvas/canvas-node/src/LeaferCanvas.ts: -------------------------------------------------------------------------------- 1 | import { IObject, IScreenSizeData } from '@leafer/interface' 2 | import { LeaferCanvasBase, Platform, canvasPatch } from '@leafer/core' 3 | 4 | export class LeaferCanvas extends LeaferCanvasBase { 5 | 6 | public get allowBackgroundColor(): boolean { return true } 7 | 8 | public init(): void { 9 | 10 | this.__createView() 11 | this.__createContext() 12 | 13 | this.resize(this.config as IScreenSizeData) 14 | 15 | if (Platform.roundRectPatch) { 16 | (this.context as IObject).__proto__.roundRect = null 17 | canvasPatch((this.context as IObject).__proto__) 18 | } 19 | } 20 | 21 | protected __createView(): void { 22 | this.view = Platform.origin.createCanvas(1, 1) 23 | } 24 | 25 | public updateViewSize(): void { 26 | const { width, height, pixelRatio } = this 27 | 28 | this.view.width = Math.ceil(width * pixelRatio) 29 | this.view.height = Math.ceil(height * pixelRatio) 30 | 31 | this.clientBounds = this.bounds 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /packages/canvas/canvas-node/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferCanvas } from './LeaferCanvas' -------------------------------------------------------------------------------- /packages/canvas/canvas-web/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas-web/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas-web 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas-web", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas-web", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas-web", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/canvas/canvas-web/src/index.ts: -------------------------------------------------------------------------------- 1 | import { canvasPatch } from '@leafer/core' 2 | 3 | export { LeaferCanvas } from './LeaferCanvas' 4 | 5 | canvasPatch(CanvasRenderingContext2D.prototype) 6 | canvasPatch(Path2D.prototype) -------------------------------------------------------------------------------- /packages/canvas/canvas-worker/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas-worker/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas-worker 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas-worker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas-worker", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas-worker", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas-worker", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/canvas/canvas-worker/src/LeaferCanvas.ts: -------------------------------------------------------------------------------- 1 | import { IScreenSizeData } from '@leafer/interface' 2 | import { LeaferCanvasBase, Platform } from '@leafer/core' 3 | 4 | export class LeaferCanvas extends LeaferCanvasBase { 5 | 6 | declare public view: OffscreenCanvas 7 | 8 | public get allowBackgroundColor(): boolean { return true } 9 | 10 | public init(): void { 11 | 12 | this.__createView() 13 | this.__createContext() 14 | 15 | this.resize(this.config as IScreenSizeData) 16 | } 17 | 18 | protected __createView(): void { 19 | this.view = Platform.origin.createCanvas(1, 1) 20 | } 21 | 22 | public updateViewSize(): void { 23 | const { width, height, pixelRatio } = this 24 | 25 | this.view.width = Math.ceil(width * pixelRatio) 26 | this.view.height = Math.ceil(height * pixelRatio) 27 | 28 | this.clientBounds = this.bounds 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /packages/canvas/canvas-worker/src/index.ts: -------------------------------------------------------------------------------- 1 | import { canvasPatch } from '@leafer/core' 2 | 3 | export { LeaferCanvas } from './LeaferCanvas' 4 | 5 | canvasPatch(OffscreenCanvasRenderingContext2D.prototype) 6 | canvasPatch(Path2D.prototype) -------------------------------------------------------------------------------- /packages/canvas/canvas/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/canvas/canvas/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvas 2 | -------------------------------------------------------------------------------- /packages/canvas/canvas/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvas", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvas", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/file": "1.6.7", 22 | "@leafer/list": "1.6.7", 23 | "@leafer/math": "1.6.7", 24 | "@leafer/data": "1.6.7", 25 | "@leafer/path": "1.6.7", 26 | "@leafer/debug": "1.6.7", 27 | "@leafer/platform": "1.6.7" 28 | }, 29 | "devDependencies": { 30 | "@leafer/interface": "1.6.7" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/canvas/canvas/src/CanvasManager.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferCanvas, IScreenSizeData, ICanvasManager } from '@leafer/interface' 2 | import { Creator } from '@leafer/platform' 3 | 4 | export class CanvasManager implements ICanvasManager { 5 | 6 | public list: ILeaferCanvas[] = [] 7 | 8 | public add(canvas: ILeaferCanvas): void { 9 | canvas.manager = this 10 | this.list.push(canvas) 11 | } 12 | 13 | public get(size: IScreenSizeData): ILeaferCanvas { 14 | let old: ILeaferCanvas 15 | const { list } = this 16 | for (let i = 0, len = list.length; i < len; i++) { 17 | old = list[i] 18 | if (old.recycled && old.isSameSize(size)) { 19 | old.recycled = false 20 | old.manager || (old.manager = this) 21 | return old 22 | } 23 | } 24 | 25 | const canvas = Creator.canvas(size) 26 | this.add(canvas) 27 | return canvas 28 | } 29 | 30 | public recycle(old: ILeaferCanvas): void { 31 | old.recycled = true 32 | } 33 | 34 | public clearRecycled(): void { 35 | let canvas: ILeaferCanvas 36 | const filter: ILeaferCanvas[] = [] 37 | for (let i = 0, len = this.list.length; i < len; i++) { 38 | canvas = this.list[i] 39 | canvas.recycled ? canvas.destroy() : filter.push(canvas) 40 | } 41 | this.list = filter 42 | } 43 | 44 | public clear(): void { 45 | this.list.forEach(item => { item.destroy() }) 46 | this.list.length = 0 47 | } 48 | 49 | public destroy(): void { 50 | this.clear() 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /packages/canvas/canvas/src/index.ts: -------------------------------------------------------------------------------- 1 | export { CanvasManager } from './CanvasManager' 2 | export { LeaferCanvasBase, canvasSizeAttrs } from './LeaferCanvasBase' 3 | export { canvasPatch } from './patch' -------------------------------------------------------------------------------- /packages/canvas/canvas/src/patch/index.ts: -------------------------------------------------------------------------------- 1 | import { IPathDrawer } from '@leafer/interface' 2 | 3 | import { roundRect } from './roundRect' 4 | 5 | export function canvasPatch(drawer: IPathDrawer): void { 6 | roundRect(drawer) 7 | } -------------------------------------------------------------------------------- /packages/canvas/canvas/src/patch/roundRect.ts: -------------------------------------------------------------------------------- 1 | import { IPathDrawer } from '@leafer/interface' 2 | import { RectHelper } from '@leafer/path' 3 | 4 | 5 | const { drawRoundRect } = RectHelper 6 | 7 | export function roundRect(drawer: IPathDrawer): void { 8 | 9 | if (drawer && !drawer.roundRect) { 10 | 11 | drawer.roundRect = function (x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void { 12 | 13 | drawRoundRect(this as IPathDrawer, x, y, width, height, cornerRadius) 14 | } 15 | } 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /packages/core/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/core 2 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/core", 3 | "version": "1.6.7", 4 | "description": "@leafer/core", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "lib/core.esm.min.js", 9 | "exports": { 10 | "import": "./lib/core.esm.min.js", 11 | "require": "./lib/core.min.cjs", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "types": "types/index.d.ts", 15 | "files": ["src","types","lib"], 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/leaferjs/leafer.git" 19 | }, 20 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/core", 21 | "bugs": "https://github.com/leaferjs/leafer/issues", 22 | "keywords": [ 23 | "leafer core", 24 | "leafer", 25 | "leaferjs" 26 | ], 27 | "dependencies": { 28 | "@leafer/canvas": "1.6.7", 29 | "@leafer/image": "1.6.7", 30 | 31 | "@leafer/data": "1.6.7", 32 | "@leafer/debug": "1.6.7", 33 | "@leafer/decorator": "1.6.7", 34 | "@leafer/display": "1.6.7", 35 | "@leafer/display-module": "1.6.7", 36 | 37 | "@leafer/event": "1.6.7", 38 | 39 | "@leafer/file": "1.6.7", 40 | "@leafer/helper": "1.6.7", 41 | "@leafer/layout": "1.6.7", 42 | "@leafer/list": "1.6.7", 43 | "@leafer/math": "1.6.7", 44 | 45 | "@leafer/path": "1.6.7", 46 | "@leafer/platform": "1.6.7", 47 | 48 | "@leafer/task": "1.6.7" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/core/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@leafer/canvas' 2 | export * from '@leafer/image' 3 | 4 | export * from '@leafer/data' 5 | export * from '@leafer/debug' 6 | export * from '@leafer/decorator' 7 | export * from '@leafer/display' 8 | export * from '@leafer/display-module' 9 | 10 | export * from '@leafer/event' 11 | 12 | export * from '@leafer/file' 13 | export * from '@leafer/helper' 14 | export * from '@leafer/layout' 15 | export * from '@leafer/list' 16 | export * from '@leafer/math' 17 | 18 | export * from '@leafer/path' 19 | export * from '@leafer/platform' 20 | 21 | export * from '@leafer/task' 22 | 23 | export const version = "1.6.7" -------------------------------------------------------------------------------- /packages/debug/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/debug/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/debug 2 | -------------------------------------------------------------------------------- /packages/debug/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/debug", 3 | "version": "1.6.7", 4 | "description": "@leafer/debug", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/debug", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/debug/src/Debug.ts: -------------------------------------------------------------------------------- 1 | import { IBooleanMap, IBoundsData, ILeaferCanvas, IRenderOptions, ILeaf } from '@leafer/interface' 2 | import { MathHelper } from '@leafer/math' 3 | 4 | 5 | const { randColor } = MathHelper 6 | export class Debug { 7 | 8 | static enable: boolean 9 | 10 | static filterList: string[] = [] 11 | static excludeList: string[] = [] 12 | 13 | // other 14 | static showWarn = true 15 | static showRepaint: boolean | string 16 | static showBounds: boolean | string | 'hit' 17 | 18 | public name: string 19 | 20 | public repeatMap: IBooleanMap = {} 21 | 22 | constructor(name: string) { 23 | this.name = name 24 | } 25 | 26 | static get(name: string): Debug { 27 | return new Debug(name) 28 | } 29 | 30 | static set filter(name: string | string[]) { 31 | this.filterList = getNameList(name) 32 | } 33 | 34 | static set exclude(name: string | string[]) { 35 | this.excludeList = getNameList(name) 36 | } 37 | 38 | static drawRepaint(canvas: ILeaferCanvas, bounds: IBoundsData): void { 39 | const color = randColor() 40 | canvas.fillWorld(bounds, color.replace('1)', '.1)')) 41 | canvas.strokeWorld(bounds, color) 42 | } 43 | 44 | static drawBounds(leaf: ILeaf, canvas: ILeaferCanvas, _options: IRenderOptions): void { 45 | const showHit = Debug.showBounds === 'hit', w = leaf.__nowWorld, color = randColor() 46 | if (showHit) canvas.setWorld(w), leaf.__drawHitPath(canvas), canvas.fillStyle = color.replace('1)', '.2)'), canvas.fill() 47 | 48 | canvas.resetTransform() 49 | canvas.setStroke(color, 2) 50 | showHit ? canvas.stroke() : canvas.strokeWorld(w, color) 51 | } 52 | 53 | 54 | log(...messages: unknown[]): void { 55 | if (D.enable) { 56 | if (D.filterList.length && D.filterList.every(name => name !== this.name)) return 57 | if (D.excludeList.length && D.excludeList.some(name => name === this.name)) return 58 | console.log('%c' + this.name, 'color:#21ae62', ...messages) 59 | } 60 | } 61 | 62 | tip(...messages: unknown[]): void { 63 | if (D.enable) this.warn(...messages) 64 | } 65 | 66 | warn(...messages: unknown[]): void { 67 | if (D.showWarn) console.warn(this.name, ...messages) 68 | } 69 | 70 | repeat(name: string, ...messages: unknown[]) { 71 | if (!this.repeatMap[name]) { 72 | this.warn('repeat:' + name, ...messages) 73 | this.repeatMap[name] = true 74 | } 75 | } 76 | 77 | error(...messages: unknown[]): void { 78 | try { 79 | throw new Error() 80 | } catch (e) { 81 | console.error(this.name, ...messages, e) 82 | } 83 | } 84 | } 85 | 86 | function getNameList(name: string | string[]): string[] { 87 | if (!name) name = [] 88 | else if (typeof name === 'string') name = [name] 89 | return name 90 | } 91 | 92 | const D = Debug -------------------------------------------------------------------------------- /packages/debug/src/Plugin.ts: -------------------------------------------------------------------------------- 1 | import { IBooleanMap } from '@leafer/interface' 2 | 3 | 4 | const check = [] as string[] 5 | 6 | export const Plugin = { 7 | 8 | list: {} as IBooleanMap, 9 | 10 | add(name: string, ...needPlugins: string[]) { 11 | this.list[name] = true 12 | check.push(...needPlugins) 13 | }, 14 | 15 | has(name: string, tip?: boolean): boolean { 16 | const rs = this.list[name] 17 | if (!rs && tip) this.need(name) 18 | return rs 19 | }, 20 | 21 | need(name: string): any { 22 | console.error('please install and import plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name) 23 | } 24 | 25 | } 26 | 27 | setTimeout(() => check.forEach(name => Plugin.has(name, true))) -------------------------------------------------------------------------------- /packages/debug/src/Run.ts: -------------------------------------------------------------------------------- 1 | import { IncrementId } from '@leafer/math' 2 | import { Debug } from './Debug' 3 | 4 | 5 | interface ids { 6 | [name: string]: number 7 | } 8 | interface names { 9 | [name: string]: string 10 | } 11 | 12 | 13 | const debug = Debug.get('RunTime') 14 | 15 | export const Run = { 16 | 17 | currentId: 0, 18 | currentName: '', 19 | 20 | idMap: {} as ids, 21 | nameMap: {} as names, 22 | nameToIdMap: {} as ids, 23 | 24 | start(name: string, microsecond?: boolean): number { 25 | const id = IncrementId.create(IncrementId.RUNTIME) 26 | R.currentId = R.idMap[id] = microsecond ? performance.now() : Date.now() 27 | R.currentName = R.nameMap[id] = name 28 | R.nameToIdMap[name] = id 29 | return id 30 | }, 31 | 32 | end(id: number, microsecond?: boolean): void { 33 | const time = R.idMap[id], name = R.nameMap[id] 34 | const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time 35 | R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined 36 | debug.log(name, duration, 'ms') 37 | }, 38 | 39 | endOfName(name: string, microsecond?: boolean): void { 40 | const id = R.nameToIdMap[name] 41 | if (id !== undefined) R.end(id, microsecond) 42 | } 43 | } 44 | 45 | const R = Run -------------------------------------------------------------------------------- /packages/debug/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Run' 2 | export * from './Debug' 3 | export * from './Plugin' 4 | 5 | 6 | -------------------------------------------------------------------------------- /packages/decorator/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/decorator/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/decorator 2 | -------------------------------------------------------------------------------- /packages/decorator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/decorator", 3 | "version": "1.6.7", 4 | "description": "@leafer/decorator", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/decorator", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/platform": "1.6.7", 22 | "@leafer/data": "1.6.7", 23 | "@leafer/debug": "1.6.7" 24 | }, 25 | "devDependencies": { 26 | "@leafer/interface": "1.6.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/decorator/src/class.ts: -------------------------------------------------------------------------------- 1 | import { IObject } from '@leafer/interface' 2 | import { EventCreator, UICreator } from '@leafer/platform' 3 | 4 | export function registerUI() { 5 | return (target: IObject) => { 6 | UICreator.register(target) 7 | } 8 | } 9 | 10 | export function registerUIEvent() { 11 | return (target: IObject) => { 12 | EventCreator.register(target) 13 | } 14 | } -------------------------------------------------------------------------------- /packages/decorator/src/define.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, IObject } from '@leafer/interface' 2 | 3 | import * as types from './data' 4 | 5 | interface IDataTypeFunction { 6 | (target: ILeaf, key: string): void 7 | } 8 | 9 | interface IDataTypeDecorator { 10 | (...arg: any): IDataTypeFunction 11 | } 12 | 13 | interface IDataTypeDecoratorMap { 14 | [key: string]: IDataTypeDecorator 15 | } 16 | 17 | export const DataTypeDecorator = { 18 | 19 | list: {} as IDataTypeDecoratorMap, 20 | 21 | register(name: string, decorator: IDataTypeDecorator): void { 22 | this.list[name] = decorator 23 | }, 24 | 25 | get(name: string): IDataTypeDecorator { 26 | const decorator = this.list[name] 27 | return decorator 28 | } 29 | } 30 | 31 | Object.keys(types).forEach(key => { 32 | if (key.includes('Type')) { 33 | DataTypeDecorator.register(key, (types as IObject)[key] as IDataTypeDecorator) 34 | } 35 | }) -------------------------------------------------------------------------------- /packages/decorator/src/index.ts: -------------------------------------------------------------------------------- 1 | export { defineLeafAttr, decorateLeafAttr, attr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, hitType, pathType, pathInputType, cursorType, dataProcessor, layoutProcessor, defineDataProcessor } from './data' 2 | export { useModule, rewrite, rewriteAble } from './rewrite' 3 | export { defineKey, getDescriptor } from './object' 4 | export { registerUI, registerUIEvent } from './class' -------------------------------------------------------------------------------- /packages/decorator/src/object.ts: -------------------------------------------------------------------------------- 1 | import { IObject } from '@leafer/interface' 2 | 3 | export function defineKey(target: T, key: string, descriptor: IObject & ThisType, noConfigurable?: boolean): void { 4 | if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true 5 | Object.defineProperty(target, key, descriptor) 6 | } 7 | 8 | export function getDescriptor(object: IObject, name: string) { 9 | return Object.getOwnPropertyDescriptor(object, name) 10 | } 11 | 12 | export function getNames(object: IObject): string[] { 13 | return Object.getOwnPropertyNames(object) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /packages/decorator/src/rewrite.ts: -------------------------------------------------------------------------------- 1 | import { IObject, IFunction } from '@leafer/interface' 2 | import { Debug } from '@leafer/debug' 3 | import { getDescriptor, getNames } from './object' 4 | 5 | interface IRewriteItem { 6 | name: string 7 | run: IFunction 8 | } 9 | 10 | const debug = new Debug('rewrite') 11 | 12 | const list: IRewriteItem[] = [] 13 | const excludeNames = ['destroy', 'constructor'] 14 | 15 | 16 | // method 17 | 18 | export function rewrite(method: IFunction) { 19 | return (target: IObject, key: string) => { 20 | list.push({ name: target.constructor.name + '.' + key, run: () => { target[key] = method } }) 21 | } 22 | } 23 | 24 | export function rewriteAble() { 25 | return (_target: IObject) => { 26 | doRewrite() 27 | } 28 | } 29 | 30 | function doRewrite(error?: boolean): void { 31 | if (list.length) { 32 | list.forEach(item => { 33 | if (error) debug.error(item.name, '需在Class上装饰@rewriteAble()') 34 | item.run() 35 | }) 36 | list.length = 0 37 | } 38 | } 39 | 40 | setTimeout(() => doRewrite(true)) 41 | 42 | 43 | // class 44 | 45 | export function useModule(module: IObject, exclude?: string[]) { 46 | return (target: IObject) => { 47 | const names = module.prototype ? getNames(module.prototype) : Object.keys(module) 48 | names.forEach(name => { 49 | if (!excludeNames.includes(name) && (!exclude || !exclude.includes(name))) { 50 | if (module.prototype) { 51 | const d = getDescriptor(module.prototype, name) 52 | if (d.writable) target.prototype[name] = module.prototype[name] 53 | } else { 54 | target.prototype[name] = module[name] 55 | } 56 | } 57 | }) 58 | } 59 | } -------------------------------------------------------------------------------- /packages/display-module/data/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/display-module/data/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/data 2 | -------------------------------------------------------------------------------- /packages/display-module/data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/data", 3 | "version": "1.6.7", 4 | "description": "@leafer/data", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/data", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "devDependencies": { 21 | "@leafer/interface": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/display-module/data/src/DataHelper.ts: -------------------------------------------------------------------------------- 1 | import { IBooleanMap, IObject } from '@leafer/interface' 2 | 3 | 4 | export const DataHelper = { 5 | 6 | default(t: T, defaultData: IObject): T { 7 | assign(defaultData, t) 8 | assign(t, defaultData) 9 | return t 10 | }, 11 | 12 | assign(t: IObject, merge: IObject, exclude?: IObject): void { 13 | let value: unknown 14 | Object.keys(merge).forEach(key => { 15 | value = merge[key] 16 | if (value?.constructor === Object && t[key]?.constructor === Object) return assign(t[key], merge[key], exclude && exclude[key]) 17 | if (exclude && (key in exclude)) { 18 | if (exclude[key]?.constructor === Object) assign(t[key] = {}, merge[key], exclude[key]) 19 | return 20 | } 21 | t[key] = merge[key] 22 | }) 23 | }, 24 | 25 | copyAttrs(t: IObject, from: IObject, include: string[]): IObject { 26 | include.forEach(key => { 27 | if (from[key] !== undefined) t[key] = from[key] 28 | }) 29 | return t 30 | }, 31 | 32 | clone(data: unknown): IObject { 33 | return JSON.parse(JSON.stringify(data)) 34 | }, 35 | 36 | toMap(list: string[]): IBooleanMap { 37 | const map = {} as IBooleanMap 38 | for (let i = 0, len = list.length; i < len; i++) map[list[i]] = true 39 | return map 40 | }, 41 | 42 | stintSet(data: IObject, attrName: string, value: any): void { 43 | value || (value = undefined) 44 | data[attrName] !== value && (data[attrName] = value) // 只有值不一样时才设置,节省内存开销 45 | } 46 | 47 | } 48 | 49 | const { assign } = DataHelper -------------------------------------------------------------------------------- /packages/display-module/data/src/index.ts: -------------------------------------------------------------------------------- 1 | import { IObject } from '@leafer/interface' 2 | 3 | export { DataHelper } from './DataHelper' 4 | export { LeafData } from './LeafData' 5 | 6 | export enum Answer { 7 | No = 0, 8 | Yes = 1, 9 | NoAndSkip = 2, 10 | YesAndSkip = 3 11 | } 12 | 13 | export const emptyData: IObject = {} 14 | 15 | export function isNull(value: any): boolean { 16 | return value === undefined || value === null 17 | } 18 | 19 | export function isEmptyData(value: any): boolean { 20 | return JSON.stringify(value) === '{}' 21 | } -------------------------------------------------------------------------------- /packages/display-module/display-module/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/display-module/display-module/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/display-module 2 | -------------------------------------------------------------------------------- /packages/display-module/display-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/display-module", 3 | "version": "1.6.7", 4 | "description": "@leafer/display-module", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/display-module", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/helper": "1.6.7", 22 | "@leafer/event": "1.6.7", 23 | "@leafer/math": "1.6.7", 24 | "@leafer/debug": "1.6.7" 25 | }, 26 | "devDependencies": { 27 | "@leafer/interface": "1.6.7" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/display-module/display-module/src/BranchRender.ts: -------------------------------------------------------------------------------- 1 | import { LeafBoundsHelper } from '@leafer/helper' 2 | import { ILeaferCanvas, IRenderOptions, IBranchRenderModule } from '@leafer/interface' 3 | 4 | 5 | const { excludeRenderBounds } = LeafBoundsHelper 6 | 7 | export const BranchRender: IBranchRenderModule = { 8 | 9 | __updateChange(): void { 10 | const { __layout: layout } = this 11 | if (layout.childrenSortChanged) { 12 | this.__updateSortChildren() 13 | layout.childrenSortChanged = false 14 | } 15 | 16 | this.__.__checkSingle() 17 | }, 18 | 19 | 20 | __render(canvas: ILeaferCanvas, options: IRenderOptions): void { 21 | 22 | this.__nowWorld = this.__getNowWorld(options) 23 | 24 | if (this.__worldOpacity) { 25 | 26 | const data = this.__ 27 | 28 | if (data.dim) options.dimOpacity = data.dim === true ? 0.2 : data.dim 29 | else if (data.dimskip) options.dimOpacity && (options.dimOpacity = 0) 30 | 31 | if (data.__single) { 32 | 33 | if (data.eraser === 'path') return this.__renderEraser(canvas, options) 34 | 35 | const tempCanvas = canvas.getSameCanvas(false, true) 36 | 37 | this.__renderBranch(tempCanvas, options) 38 | 39 | const nowWorld = this.__nowWorld 40 | 41 | canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity 42 | canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true) 43 | 44 | tempCanvas.recycle(nowWorld) 45 | 46 | } else { 47 | 48 | this.__renderBranch(canvas, options) 49 | 50 | } 51 | 52 | } 53 | 54 | }, 55 | 56 | __renderBranch(canvas: ILeaferCanvas, options: IRenderOptions): void { 57 | if (this.__hasMask) { 58 | 59 | this.__renderMask(canvas, options) 60 | 61 | } else { 62 | 63 | const { children } = this 64 | for (let i = 0, len = children.length; i < len; i++) { 65 | if (excludeRenderBounds(children[i], options)) continue 66 | children[i].__render(canvas, options) 67 | } 68 | 69 | } 70 | }, 71 | 72 | 73 | __clip(canvas: ILeaferCanvas, options: IRenderOptions): void { 74 | if (this.__worldOpacity) { 75 | const { children } = this 76 | for (let i = 0, len = children.length; i < len; i++) { 77 | if (excludeRenderBounds(children[i], options)) continue 78 | children[i].__clip(canvas, options) 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /packages/display-module/display-module/src/LeafDataProxy.ts: -------------------------------------------------------------------------------- 1 | import { ILeafDataProxyModule, IObject, IValue } from '@leafer/interface' 2 | import { PropertyEvent } from '@leafer/event' 3 | import { Debug } from '@leafer/debug' 4 | 5 | 6 | const { isFinite } = Number 7 | const debug = Debug.get('setAttr') 8 | 9 | export const LeafDataProxy: ILeafDataProxyModule = { 10 | 11 | __setAttr(name: string, newValue: IValue, checkFiniteNumber?: boolean): boolean { 12 | if (this.leaferIsCreated) { 13 | 14 | const oldValue = this.__.__getInput(name) 15 | 16 | if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) { // 警告 NaN、Infinity、-Infinity、null、非有效数字 17 | debug.warn(this.innerName, name, newValue) 18 | newValue = undefined // must 19 | } 20 | 21 | if (typeof newValue === 'object' || oldValue !== newValue) { 22 | 23 | this.__realSetAttr(name, newValue) 24 | 25 | const { CHANGE } = PropertyEvent 26 | const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue) 27 | 28 | if (this.isLeafer) { 29 | this.emitEvent(new PropertyEvent(PropertyEvent.LEAFER_CHANGE, this, name, oldValue, newValue)) 30 | } else { 31 | if (this.hasEvent(CHANGE)) this.emitEvent(event) 32 | } 33 | 34 | this.leafer.emitEvent(event) 35 | 36 | return true 37 | } else { 38 | return false 39 | } 40 | 41 | } else { 42 | 43 | this.__realSetAttr(name, newValue) 44 | 45 | return true 46 | 47 | } 48 | }, 49 | 50 | __realSetAttr(name: string, newValue: IValue): void { 51 | const data = this.__ as IObject 52 | data[name] = newValue 53 | if (this.__proxyData) this.setProxyAttr(name, newValue) 54 | if (data.normalStyle) this.lockNormalStyle || data.normalStyle[name] === undefined || (data.normalStyle[name] = newValue) 55 | }, 56 | 57 | 58 | __getAttr(name: string): IValue { 59 | if (this.__proxyData) return this.getProxyAttr(name) 60 | return this.__.__get(name) 61 | } 62 | } -------------------------------------------------------------------------------- /packages/display-module/display-module/src/LeafEventer.ts: -------------------------------------------------------------------------------- 1 | import { ILeafEventerModule } from '@leafer/interface' 2 | import { Eventer } from '@leafer/event' 3 | 4 | const { on, on_, off, off_, once, emit, emitEvent, hasEvent, destroy } = Eventer.prototype 5 | 6 | export const LeafEventer: ILeafEventerModule = { on, on_, off, off_, once, emit, emitEvent, hasEvent, destroyEventer: destroy } -------------------------------------------------------------------------------- /packages/display-module/display-module/src/LeafMatrix.ts: -------------------------------------------------------------------------------- 1 | import { ILeafMatrixModule, ILayoutData, IScrollPointData } from '@leafer/interface' 2 | import { AroundHelper, MatrixHelper } from '@leafer/math' 3 | 4 | 5 | const { setLayout, multiplyParent, translateInner, defaultWorld } = MatrixHelper 6 | const { toPoint, tempPoint } = AroundHelper 7 | 8 | export const LeafMatrix: ILeafMatrixModule = { 9 | 10 | __updateWorldMatrix(): void { 11 | 12 | multiplyParent(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__ as ILayoutData, this.parent && this.parent.__ as IScrollPointData) 13 | 14 | }, 15 | 16 | __updateLocalMatrix(): void { 17 | 18 | if (this.__local) { 19 | 20 | const layout = this.__layout, local = this.__local, data = this.__ 21 | 22 | if (layout.affectScaleOrRotation) { 23 | 24 | if ((layout.scaleChanged && (layout.resized = 'scale')) || layout.rotationChanged) { 25 | setLayout(local, data as ILayoutData, null, null, layout.affectRotation) 26 | layout.scaleChanged = layout.rotationChanged = undefined 27 | } 28 | 29 | } 30 | 31 | local.e = data.x + data.offsetX 32 | local.f = data.y + data.offsetY 33 | 34 | if (data.around || data.origin) { 35 | toPoint(data.around || data.origin, layout.boxBounds, tempPoint) 36 | translateInner(local, -tempPoint.x, -tempPoint.y, !data.around) 37 | } 38 | 39 | } 40 | 41 | this.__layout.matrixChanged = undefined 42 | 43 | } 44 | 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /packages/display-module/display-module/src/LeafRender.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferCanvas, IRenderOptions, ILeafRenderModule } from '@leafer/interface' 2 | import { Debug } from '@leafer/debug' 3 | 4 | 5 | export const LeafRender: ILeafRenderModule = { 6 | 7 | __render(canvas: ILeaferCanvas, options: IRenderOptions): void { 8 | if (this.__worldOpacity) { 9 | 10 | const data = this.__ 11 | 12 | canvas.setWorld(this.__nowWorld = this.__getNowWorld(options)) 13 | canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity 14 | 15 | if (this.__.__single) { 16 | 17 | if (data.eraser === 'path') return this.__renderEraser(canvas, options) 18 | 19 | const tempCanvas = canvas.getSameCanvas(true, true) 20 | this.__draw(tempCanvas, options, canvas) 21 | 22 | if (this.__worldFlipped) { 23 | canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true) 24 | } else { 25 | canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode) 26 | } 27 | 28 | tempCanvas.recycle(this.__nowWorld) 29 | 30 | } else { 31 | 32 | this.__draw(canvas, options) 33 | 34 | } 35 | 36 | if (Debug.showBounds) Debug.drawBounds(this, canvas, options) 37 | 38 | } 39 | }, 40 | 41 | __clip(canvas: ILeaferCanvas, options: IRenderOptions): void { 42 | if (this.__worldOpacity) { 43 | canvas.setWorld(this.__nowWorld = this.__getNowWorld(options)) 44 | this.__drawRenderPath(canvas) 45 | canvas.clipUI(this) 46 | } 47 | }, 48 | 49 | __updateWorldOpacity(): void { 50 | this.__worldOpacity = this.__.visible ? (this.parent ? this.parent.__worldOpacity * this.__.opacity : this.__.opacity) : 0 51 | if (this.__layout.opacityChanged) this.__layout.opacityChanged = false 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /packages/display-module/display-module/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeafEventer } from './LeafEventer' 2 | export { LeafDataProxy } from './LeafDataProxy' 3 | export { LeafMatrix } from './LeafMatrix' 4 | export { LeafBounds } from './LeafBounds' 5 | export { LeafRender } from './LeafRender' 6 | 7 | export { BranchRender } from './BranchRender' -------------------------------------------------------------------------------- /packages/display-module/helper/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/display-module/helper/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/helper 2 | -------------------------------------------------------------------------------- /packages/display-module/helper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/helper", 3 | "version": "1.6.7", 4 | "description": "@leafer/helper", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/helper", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/display-module/helper/src/LeafBoundsHelper.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, IBoundsData, IRenderOptions } from '@leafer/interface' 2 | 3 | 4 | export const LeafBoundsHelper = { 5 | 6 | worldBounds(target: ILeaf): IBoundsData { 7 | return target.__world 8 | }, 9 | 10 | localBoxBounds(target: ILeaf): IBoundsData { 11 | return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout) 12 | }, 13 | 14 | localStrokeBounds(target: ILeaf): IBoundsData { 15 | return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds 16 | }, 17 | 18 | localRenderBounds(target: ILeaf): IBoundsData { 19 | return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds 20 | }, 21 | 22 | maskLocalBoxBounds(target: ILeaf): IBoundsData { 23 | return target.__.mask ? target.__localBoxBounds : null 24 | }, 25 | 26 | maskLocalStrokeBounds(target: ILeaf): IBoundsData { 27 | return target.__.mask ? target.__layout.localStrokeBounds : null 28 | }, 29 | 30 | maskLocalRenderBounds(target: ILeaf): IBoundsData { 31 | return target.__.mask ? target.__layout.localRenderBounds : null 32 | }, 33 | 34 | excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean { 35 | if (options.bounds && !options.bounds.hit(child.__world, options.matrix)) return true 36 | if (options.hideBounds && options.hideBounds.includes(child.__world, options.matrix)) return true 37 | return false 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /packages/display-module/helper/src/WaitHelper.ts: -------------------------------------------------------------------------------- 1 | import { IFunction } from '@leafer/interface' 2 | 3 | export const WaitHelper = { 4 | run(wait: IFunction[]): void { 5 | if (wait && wait.length) { 6 | const len = wait.length 7 | for (let i = 0; i < len; i++) { wait[i]() } 8 | wait.length === len ? wait.length = 0 : wait.splice(0, len) 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /packages/display-module/helper/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeafHelper } from './LeafHelper' 2 | export { LeafBoundsHelper } from './LeafBoundsHelper' 3 | export { BranchHelper } from './BranchHelper' 4 | export { WaitHelper } from './WaitHelper' 5 | -------------------------------------------------------------------------------- /packages/display-module/layout/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/display-module/layout/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/layout 2 | -------------------------------------------------------------------------------- /packages/display-module/layout/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/layout", 3 | "version": "1.6.7", 4 | "description": "@leafer/layout", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/layout", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7", 22 | "@leafer/helper": "1.6.7", 23 | "@leafer/platform": "1.6.7" 24 | }, 25 | "devDependencies": { 26 | "@leafer/interface": "1.6.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/display-module/layout/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeafLayout } from "./LeafLayout" 2 | -------------------------------------------------------------------------------- /packages/display/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/display/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/display 2 | -------------------------------------------------------------------------------- /packages/display/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/display", 3 | "version": "1.6.7", 4 | "description": "@leafer/display", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7", 22 | "@leafer/data": "1.6.7", 23 | "@leafer/layout": "1.6.7", 24 | "@leafer/display-module": "1.6.7", 25 | "@leafer/event": "1.6.7", 26 | "@leafer/decorator": "1.6.7", 27 | "@leafer/helper": "1.6.7", 28 | "@leafer/debug": "1.6.7", 29 | "@leafer/platform": "1.6.7" 30 | }, 31 | "devDependencies": { 32 | "@leafer/interface": "1.6.7" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/display/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Leaf } from './Leaf' 2 | export { Branch } from './Branch' 3 | 4 | -------------------------------------------------------------------------------- /packages/event/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/event/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/event 2 | -------------------------------------------------------------------------------- /packages/event/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/event", 3 | "version": "1.6.7", 4 | "description": "@leafer/event", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/event", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/decorator": "1.6.7", 22 | "@leafer/math": "1.6.7", 23 | "@leafer/platform": "1.6.7" 24 | }, 25 | "devDependencies": { 26 | "@leafer/interface": "1.6.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/event/src/BoundsEvent.ts: -------------------------------------------------------------------------------- 1 | import { IBoundsEvent, IEventTarget, ILeaf, IObject } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class BoundsEvent extends Event implements IBoundsEvent { 7 | 8 | static RESIZE = 'bounds.resize' 9 | 10 | static INNER = 'bounds.inner' 11 | 12 | static LOCAL = 'bounds.local' 13 | 14 | static WORLD = 'bounds.world' 15 | 16 | 17 | static checkHas(leaf: IEventTarget, type: string, mode: 'on' | 'off') { 18 | if (mode === 'on') { 19 | type === WORLD ? leaf.__hasWorldEvent = true : leaf.__hasLocalEvent = true 20 | } else { 21 | leaf.__hasLocalEvent = leaf.hasEvent(RESIZE) || leaf.hasEvent(INNER) || leaf.hasEvent(LOCAL) 22 | leaf.__hasWorldEvent = leaf.hasEvent(WORLD) 23 | } 24 | } 25 | 26 | static emitLocal(leaf: ILeaf) { 27 | if (leaf.leaferIsReady) { 28 | const { resized } = leaf.__layout 29 | if (resized !== 'local') { 30 | leaf.emit(RESIZE, leaf) 31 | if (resized === 'inner') leaf.emit(INNER, leaf) 32 | } 33 | leaf.emit(LOCAL, leaf) 34 | } 35 | } 36 | 37 | static emitWorld(leaf: ILeaf) { 38 | if (leaf.leaferIsReady) leaf.emit(WORLD, this) 39 | } 40 | 41 | } 42 | 43 | const { RESIZE, INNER, LOCAL, WORLD } = BoundsEvent 44 | 45 | 46 | export const boundsEventMap: IObject = {}; 47 | 48 | [RESIZE, INNER, LOCAL, WORLD].forEach(key => boundsEventMap[key] = 1) -------------------------------------------------------------------------------- /packages/event/src/ChildEvent.ts: -------------------------------------------------------------------------------- 1 | import { IChildEvent, ILeaf } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class ChildEvent extends Event implements IChildEvent { 7 | 8 | static ADD = 'child.add' 9 | static REMOVE = 'child.remove' 10 | 11 | static CREATED = 'created' 12 | static MOUNTED = 'mounted' 13 | static UNMOUNTED = 'unmounted' 14 | static DESTROY = 'destroy' 15 | 16 | readonly parent?: ILeaf 17 | readonly child?: ILeaf 18 | 19 | constructor(type: string, child?: ILeaf, parent?: ILeaf) { 20 | super(type, child) 21 | this.parent = parent 22 | this.child = child 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /packages/event/src/Event.ts: -------------------------------------------------------------------------------- 1 | import { IEvent, IEventTarget, IObject } from '@leafer/interface' 2 | import { Platform } from '@leafer/platform' 3 | 4 | 5 | export class Event implements IEvent { 6 | 7 | readonly origin: IObject 8 | 9 | readonly type: string 10 | readonly target: IEventTarget 11 | readonly current: IEventTarget 12 | 13 | readonly bubbles: boolean = false 14 | readonly phase: number 15 | 16 | public isStopDefault: boolean 17 | public isStop: boolean 18 | public isStopNow: boolean 19 | 20 | constructor(type: string, target?: IEventTarget) { 21 | this.type = type 22 | if (target) this.target = target 23 | } 24 | 25 | public stopDefault(): void { 26 | this.isStopDefault = true 27 | if (this.origin) Platform.event.stopDefault(this.origin) 28 | } 29 | 30 | public stopNow(): void { 31 | this.isStopNow = true 32 | this.isStop = true 33 | if (this.origin) Platform.event.stopNow(this.origin) 34 | } 35 | 36 | public stop(): void { 37 | this.isStop = true 38 | if (this.origin) Platform.event.stop(this.origin) 39 | } 40 | } -------------------------------------------------------------------------------- /packages/event/src/ImageEvent.ts: -------------------------------------------------------------------------------- 1 | import { IImageEvent, IObject, ILeaferImage } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | export class ImageEvent extends Event implements IImageEvent { 6 | 7 | static LOAD = 'image.load' 8 | static LOADED = 'image.loaded' 9 | static ERROR = 'image.error' 10 | 11 | readonly image: ILeaferImage 12 | readonly error: string | IObject 13 | 14 | readonly attrName: string 15 | readonly attrValue: IObject 16 | 17 | constructor(type: string, data: IImageEvent) { 18 | super(type) 19 | Object.assign(this, data) 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /packages/event/src/LayoutEvent.ts: -------------------------------------------------------------------------------- 1 | import { ILayoutEvent, ILayoutBlockData } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class LayoutEvent extends Event implements ILayoutEvent { 7 | 8 | static REQUEST = 'layout.request' 9 | 10 | static START = 'layout.start' 11 | 12 | static BEFORE = 'layout.before' 13 | static LAYOUT = 'layout' 14 | static AFTER = 'layout.after' 15 | 16 | static AGAIN = 'layout.again' 17 | 18 | static END = 'layout.end' 19 | 20 | readonly data: ILayoutBlockData[] 21 | readonly times: number 22 | 23 | constructor(type: string, data?: ILayoutBlockData[], times?: number) { 24 | super(type) 25 | if (data) { 26 | this.data = data 27 | this.times = times 28 | } 29 | 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /packages/event/src/LeaferEvent.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferEvent } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class LeaferEvent extends Event implements ILeaferEvent { 7 | 8 | static START = 'leafer.start' 9 | 10 | static BEFORE_READY = 'leafer.before_ready' 11 | static READY = 'leafer.ready' 12 | static AFTER_READY = 'leafer.after_ready' 13 | 14 | static VIEW_READY = 'leafer.view_ready' 15 | 16 | static VIEW_COMPLETED = 'leafer.view_completed' 17 | 18 | static STOP = 'leafer.stop' 19 | static RESTART = 'leafer.restart' 20 | 21 | static END = 'leafer.end' 22 | 23 | } -------------------------------------------------------------------------------- /packages/event/src/PropertyEvent.ts: -------------------------------------------------------------------------------- 1 | import { IPropertyEvent, IEventTarget } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class PropertyEvent extends Event implements IPropertyEvent { 7 | 8 | static CHANGE = 'property.change' 9 | static LEAFER_CHANGE = 'property.leafer_change' 10 | 11 | readonly attrName: string 12 | readonly oldValue: unknown 13 | readonly newValue: unknown 14 | 15 | constructor(type: string, target: IEventTarget, attrName: string, oldValue: unknown, newValue: unknown) { 16 | super(type, target) 17 | this.attrName = attrName 18 | this.oldValue = oldValue 19 | this.newValue = newValue 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /packages/event/src/RenderEvent.ts: -------------------------------------------------------------------------------- 1 | import { IBounds, IRenderEvent, IRenderOptions } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class RenderEvent extends Event implements IRenderEvent { 7 | 8 | static REQUEST = 'render.request' 9 | 10 | static CHILD_START = 'render.child_start' // app 专用 11 | static CHILD_END = 'render.child_end' 12 | 13 | static START = 'render.start' 14 | 15 | static BEFORE = 'render.before' 16 | static RENDER = 'render' 17 | static AFTER = 'render.after' 18 | 19 | static AGAIN = 'render.again' 20 | 21 | static END = 'render.end' 22 | 23 | static NEXT = 'render.next' 24 | 25 | readonly renderBounds: IBounds 26 | readonly renderOptions: IRenderOptions 27 | readonly times: number 28 | 29 | constructor(type: string, times?: number, bounds?: IBounds, options?: IRenderOptions) { 30 | super(type) 31 | if (times) this.times = times 32 | if (bounds) { 33 | this.renderBounds = bounds 34 | this.renderOptions = options 35 | } 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /packages/event/src/ResizeEvent.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, INumberMap, IResizeEvent, IScreenSizeData } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class ResizeEvent extends Event implements IResizeEvent { 7 | 8 | static RESIZE: string = 'resize' 9 | 10 | static resizingKeys: INumberMap // resize编辑中的元素 LeafList 键表 11 | 12 | readonly width: number 13 | readonly height: number 14 | readonly pixelRatio: number 15 | 16 | public get bigger(): boolean { 17 | if (!this.old) return true 18 | const { width, height } = this.old 19 | return this.width >= width && this.height >= height 20 | } 21 | 22 | public get smaller(): boolean { 23 | return !this.bigger 24 | } 25 | 26 | public get samePixelRatio(): boolean { 27 | if (!this.old) return true 28 | return this.pixelRatio === this.old.pixelRatio 29 | } 30 | 31 | readonly old: IScreenSizeData 32 | 33 | constructor(size: IScreenSizeData | string, oldSize?: IScreenSizeData) { 34 | if (typeof size === 'object') { 35 | super(ResizeEvent.RESIZE) 36 | Object.assign(this, size) 37 | } else { 38 | super(size) 39 | } 40 | this.old = oldSize 41 | } 42 | 43 | static isResizing(leaf: ILeaf): boolean { 44 | return this.resizingKeys && this.resizingKeys[leaf.innerId] !== undefined 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /packages/event/src/WatchEvent.ts: -------------------------------------------------------------------------------- 1 | import { IWatchEvent, IWatchEventData } from '@leafer/interface' 2 | 3 | import { Event } from './Event' 4 | 5 | 6 | export class WatchEvent extends Event implements IWatchEvent { 7 | 8 | static REQUEST = 'watch.request' 9 | static DATA = 'watch.data' 10 | 11 | readonly data: IWatchEventData 12 | 13 | constructor(type: string, data?: IWatchEventData) { 14 | super(type) 15 | this.data = data 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /packages/event/src/index.ts: -------------------------------------------------------------------------------- 1 | export { ChildEvent } from './ChildEvent' 2 | export { PropertyEvent } from './PropertyEvent' 3 | export { ImageEvent } from './ImageEvent' 4 | export { BoundsEvent } from './BoundsEvent' 5 | export { ResizeEvent } from './ResizeEvent' 6 | export { WatchEvent } from './WatchEvent' 7 | export { LayoutEvent } from './LayoutEvent' 8 | export { RenderEvent } from './RenderEvent' 9 | export { LeaferEvent } from './LeaferEvent' 10 | 11 | export { Event } from './Event' 12 | export { Eventer } from './Eventer' -------------------------------------------------------------------------------- /packages/file/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/file/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/file 2 | -------------------------------------------------------------------------------- /packages/file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/file", 3 | "version": "1.6.7", 4 | "description": "@leafer/file", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/file", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/debug": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/file/src/FileHelper.ts: -------------------------------------------------------------------------------- 1 | import { IExportFileType, IStringMap, IExportOptions } from '@leafer/interface' 2 | 3 | export const FileHelper = { 4 | 5 | alphaPixelTypes: ['png', 'webp', 'svg'] as IExportFileType[], 6 | 7 | upperCaseTypeMap: {} as IStringMap, 8 | 9 | mineType(type: string): string { 10 | if (!type || type.startsWith('image')) return type 11 | if (type === 'jpg') type = 'jpeg' 12 | return 'image/' + type 13 | }, 14 | 15 | fileType(filename: string): string { 16 | const l = filename.split('.') 17 | return l[l.length - 1] 18 | }, 19 | 20 | isOpaqueImage(filename: string): boolean { 21 | const type = F.fileType(filename) 22 | return ['jpg', 'jpeg'].some(item => item === type) 23 | }, 24 | 25 | getExportOptions(options?: IExportOptions | number | boolean): IExportOptions { 26 | switch (typeof options) { 27 | case 'object': return options 28 | case 'number': return { quality: options } 29 | case 'boolean': return { blob: options } 30 | default: return {} 31 | } 32 | } 33 | 34 | } 35 | 36 | const F = FileHelper 37 | 38 | F.alphaPixelTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase()) -------------------------------------------------------------------------------- /packages/file/src/Resource.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferImage, IResource, IObject, ILeaferCanvas, IExportFileType, ILeaferImageConfig } from '@leafer/interface' 2 | 3 | import { Creator } from '@leafer/platform' 4 | import { TaskProcessor } from '@leafer/task' 5 | import { Debug } from '@leafer/debug' 6 | 7 | 8 | const debug = Debug.get('Resource') 9 | 10 | export const Resource: IResource = { 11 | 12 | tasker: new TaskProcessor(), 13 | 14 | map: {}, 15 | 16 | get isComplete() { return R.tasker.isComplete }, 17 | 18 | // 通用 19 | 20 | set(key: string, value: any): void { 21 | if (R.map[key]) debug.repeat(key) 22 | R.map[key] = value 23 | }, 24 | 25 | get(key: string): any { 26 | return R.map[key] 27 | }, 28 | 29 | remove(key: string) { 30 | const r = R.map[key] 31 | if (r) { 32 | if (r.destroy) r.destroy() 33 | delete R.map[key] 34 | } 35 | }, 36 | 37 | // image 38 | 39 | loadImage(key: string, format?: IExportFileType): Promise { 40 | return new Promise((resolve, reject) => { 41 | const image = this.setImage(key, key, format) 42 | image.load(() => resolve(image), (e: any) => reject(e)) 43 | }) 44 | }, 45 | 46 | setImage(key: string, value: string | IObject | ILeaferImage | ILeaferCanvas, format?: IExportFileType): ILeaferImage { 47 | let config: ILeaferImageConfig 48 | if (typeof value === 'string') config = { url: value } 49 | else if (!value.url) config = { url: key, view: value } 50 | if (config) format && (config.format = format), value = Creator.image(config) 51 | R.set(key, value) 52 | return value as ILeaferImage 53 | }, 54 | 55 | 56 | destroy(): void { 57 | R.map = {} 58 | } 59 | 60 | } 61 | 62 | const R = Resource -------------------------------------------------------------------------------- /packages/file/src/index.ts: -------------------------------------------------------------------------------- 1 | export { FileHelper } from './FileHelper' 2 | export { Resource } from './Resource' -------------------------------------------------------------------------------- /packages/image/image-canvaskit/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image-canvaskit/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image-canvaskit 2 | -------------------------------------------------------------------------------- /packages/image/image-canvaskit/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image-canvaskit", 3 | "version": "1.6.7", 4 | "description": "@leafer/image-canvaskit", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image-canvaskit", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/image/image-canvaskit/src/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leaferjs/leafer/81ea1f3f07690782f3b6075275068cc5869c8eda/packages/image/image-canvaskit/src/index.ts -------------------------------------------------------------------------------- /packages/image/image-miniapp/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image-miniapp/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image-miniapp 2 | -------------------------------------------------------------------------------- /packages/image/image-miniapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image-miniapp", 3 | "version": "1.6.7", 4 | "description": "@leafer/image-miniapp", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image-miniapp", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/image/image-miniapp/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferImage } from '@leafer/core' -------------------------------------------------------------------------------- /packages/image/image-node/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image-node/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image-node 2 | -------------------------------------------------------------------------------- /packages/image/image-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image-node", 3 | "version": "1.6.7", 4 | "description": "@leafer/image-node", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image-node", 15 | "keywords": [ 16 | "leafer", 17 | "leaferjs" 18 | ], 19 | "dependencies": { 20 | "@leafer/core": "1.6.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/image/image-node/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferImage } from '@leafer/core' -------------------------------------------------------------------------------- /packages/image/image-web/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image-web/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image-web 2 | -------------------------------------------------------------------------------- /packages/image/image-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image-web", 3 | "version": "1.6.7", 4 | "description": "@leafer/image-web", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image-web", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/image/image-web/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferImage } from '@leafer/core' -------------------------------------------------------------------------------- /packages/image/image-worker/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image-worker/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image-worker 2 | -------------------------------------------------------------------------------- /packages/image/image-worker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image-worker", 3 | "version": "1.6.7", 4 | "description": "@leafer/image-worker", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image-worker", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/image/image-worker/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferImage } from '@leafer/core' -------------------------------------------------------------------------------- /packages/image/image/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/image/image/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/image 2 | -------------------------------------------------------------------------------- /packages/image/image/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/image", 3 | "version": "1.6.7", 4 | "description": "@leafer/image", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/image/image", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/task": "1.6.7", 22 | "@leafer/file": "1.6.7", 23 | "@leafer/platform": "1.6.7" 24 | }, 25 | "devDependencies": { 26 | "@leafer/interface": "1.6.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/image/image/src/ImageManager.ts: -------------------------------------------------------------------------------- 1 | import { IImageManager, ILeaferImageConfig, ILeaferImage, IExportFileType } from '@leafer/interface' 2 | import { Creator } from '@leafer/platform' 3 | import { FileHelper, Resource } from '@leafer/file' 4 | import { TaskProcessor } from '@leafer/task' 5 | 6 | 7 | export const ImageManager: IImageManager = { 8 | 9 | maxRecycled: 10, 10 | 11 | recycledList: [], 12 | 13 | patternTasker: new TaskProcessor(), 14 | 15 | get(config: ILeaferImageConfig): ILeaferImage { 16 | let image: ILeaferImage = Resource.get(config.url) 17 | if (!image) Resource.set(config.url, image = Creator.image(config)) 18 | image.use++ 19 | return image 20 | }, 21 | 22 | recycle(image: ILeaferImage): void { 23 | image.use-- 24 | setTimeout(() => { if (!image.use) I.recycledList.push(image) }) 25 | }, 26 | 27 | clearRecycled(): void { 28 | const list = I.recycledList 29 | if (list.length > I.maxRecycled) { 30 | list.forEach(image => (!image.use && image.url) && Resource.remove(image.url)) 31 | list.length = 0 32 | } 33 | }, 34 | 35 | hasAlphaPixel(config: ILeaferImageConfig): boolean { 36 | return FileHelper.alphaPixelTypes.some(item => I.isFormat(item, config)) 37 | }, 38 | 39 | isFormat(format: IExportFileType, config: ILeaferImageConfig): boolean { 40 | if (config.format === format) return true 41 | const { url } = config 42 | if (url.startsWith('data:')) { 43 | if (url.startsWith('data:' + FileHelper.mineType(format))) return true 44 | } else { 45 | if (url.includes('.' + format) || url.includes('.' + FileHelper.upperCaseTypeMap[format])) return true 46 | else if (format === 'png' && !url.includes('.')) return true // blob: 等无后缀名协议的图片无法分析类型,直接当透明图片处理 47 | } 48 | return false 49 | }, 50 | 51 | destroy(): void { 52 | I.recycledList = [] 53 | } 54 | 55 | } 56 | 57 | const I = ImageManager -------------------------------------------------------------------------------- /packages/image/image/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeaferImage } from './LeaferImage' 2 | export { ImageManager } from './ImageManager' -------------------------------------------------------------------------------- /packages/interface/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/interface/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/interface 2 | -------------------------------------------------------------------------------- /packages/interface/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/interface", 3 | "version": "1.6.7", 4 | "description": "@leafer/interface", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/interface", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/interface/src/animate/ITransition.ts: -------------------------------------------------------------------------------- 1 | import { IObject } from '../data/IData' 2 | 3 | export type ITransition = IAnimateOptions | IAnimateEasingName | number | boolean 4 | 5 | export interface IAnimateOptions { 6 | easing?: IAnimateEasing 7 | 8 | delay?: number 9 | duration?: number 10 | ending?: IAnimateEnding 11 | 12 | reverse?: boolean 13 | swing?: boolean | number 14 | 15 | loop?: boolean | number 16 | loopDelay?: number 17 | 18 | speed?: number 19 | 20 | join?: boolean 21 | autoplay?: boolean 22 | 23 | attrs?: string[] 24 | event?: IAnimateEvents 25 | } 26 | 27 | 28 | export interface IAnimateEasingFunction { 29 | (t: number): number 30 | } 31 | 32 | export interface ICustomEasingFunction { 33 | (...arg: any): IAnimateEasingFunction 34 | } 35 | 36 | 37 | export type IAnimateEasing = 38 | | IAnimateEasingName 39 | | ICubicBezierEasing 40 | | IStepsEasing 41 | | IObject 42 | 43 | export interface ICubicBezierEasing { 44 | name: 'cubic-bezier', 45 | value: [number, number, number, number] 46 | } 47 | 48 | export interface IStepsEasing { 49 | name: 'steps', 50 | value: number | [number, 'floor' | 'round' | 'ceil'] 51 | } 52 | 53 | 54 | export type IAnimateEasingName = 55 | | 'linear' 56 | | 'ease' 57 | | 'ease-in' | 'ease-out' | 'ease-in-out' 58 | | 'sine-in' | 'sine-out' | 'sine-in-out' 59 | | 'quad-in' | 'quad-out' | 'quad-in-out' 60 | | 'cubic-in' | 'cubic-out' | 'cubic-in-out' 61 | | 'quart-in' | 'quart-out' | 'quart-in-out' 62 | | 'quint-in' | 'quint-out' | 'quint-in-out' 63 | | 'expo-in' | 'expo-out' | 'expo-in-out' 64 | | 'circ-in' | 'circ-out' | 'circ-in-out' 65 | | 'back-in' | 'back-out' | 'back-in-out' 66 | | 'elastic-in' | 'elastic-out' | 'elastic-in-out' 67 | | 'bounce-in' | 'bounce-out' | 'bounce-in-out' 68 | 69 | 70 | export type IAnimateEnding = 'auto' | 'from' | 'to' 71 | 72 | export interface IAnimateEvents { 73 | created?: IAnimateEventFunction 74 | 75 | play?: IAnimateEventFunction 76 | pause?: IAnimateEventFunction 77 | stop?: IAnimateEventFunction 78 | seek?: IAnimateEventFunction 79 | 80 | update?: IAnimateEventFunction 81 | completed?: IAnimateEventFunction 82 | } 83 | 84 | export interface IAnimateEventFunction { 85 | (animate?: any): any 86 | } -------------------------------------------------------------------------------- /packages/interface/src/app/IApp.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferBase } from './ILeafer' 2 | 3 | export interface IAppBase extends ILeaferBase { 4 | children: ILeaferBase[] 5 | realCanvas: boolean 6 | } 7 | -------------------------------------------------------------------------------- /packages/interface/src/canvas/ICanvasManager.ts: -------------------------------------------------------------------------------- 1 | import { IScreenSizeData, ILeaferCanvas } from '@leafer/interface' 2 | 3 | export interface ICanvasManager { 4 | add(canvas: ILeaferCanvas): void 5 | get(size: IScreenSizeData): ILeaferCanvas 6 | recycle(old: ILeaferCanvas): void 7 | clearRecycled(): void 8 | clear(): void 9 | destroy(): void 10 | } -------------------------------------------------------------------------------- /packages/interface/src/canvas/IHitCanvasManager.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../display/ILeaf' 2 | import { ICanvasManager } from './ICanvasManager' 3 | import { IHitCanvas, ILeaferCanvasConfig } from './ILeaferCanvas' 4 | 5 | export interface IHitCanvasManager extends ICanvasManager { 6 | maxTotal: number // 最多缓存多少张画布 7 | getPathType(leaf: ILeaf): IHitCanvas 8 | getPixelType(leaf: ILeaf, config?: ILeaferCanvasConfig): IHitCanvas 9 | } -------------------------------------------------------------------------------- /packages/interface/src/canvas/ISkiaCanvas.ts: -------------------------------------------------------------------------------- 1 | import { IExportFileType, IExportImageType } from '../file/IFileType' 2 | 3 | export type ICanvasType = 'skia' | 'napi' | 'canvas' | 'miniapp' 4 | 5 | // skia 6 | export interface ISkiaCanvas { 7 | toBuffer(format: IExportFileType, config: ISkiaCanvasExportConfig): Promise 8 | toBufferSync(format: IExportFileType, config: ISkiaCanvasExportConfig): any 9 | toDataURL(format: IExportImageType, config: ISkiaCanvasExportConfig): Promise 10 | toDataURLSync(format: IExportImageType, config: ISkiaCanvasExportConfig): string 11 | saveAs(filename: string, config: ISkiaCanvasExportConfig): Promise 12 | saveAsSync(filename: string, config: ISkiaCanvasExportConfig): void 13 | } 14 | 15 | export interface ISkiaCanvasExportConfig { 16 | page?: number, 17 | matte?: string, 18 | density?: number, 19 | quality?: number, 20 | outline?: boolean 21 | } 22 | 23 | // skia-napi 24 | export interface ISkiaNAPICanvas { 25 | encodeSync(format: 'webp' | 'jpeg', quality?: number): any 26 | encodeSync(format: 'png'): any 27 | 28 | encode(format: 'webp' | 'jpeg' | string, quality?: number): Promise 29 | encode(format: 'png'): Promise 30 | 31 | toBuffer(mime: 'image/png'): any 32 | toBuffer(mime: 'image/jpeg' | 'image/webp' | string, quality?: number): any 33 | 34 | toDataURL(mime?: 'image/png'): string 35 | toDataURL(mime: 'image/jpeg' | 'image/webp' | string, quality?: number): string 36 | 37 | toDataURLAsync(mime?: 'image/png'): Promise 38 | toDataURLAsync(mime: 'image/jpeg' | 'image/webp' | string, quality?: number): Promise 39 | } -------------------------------------------------------------------------------- /packages/interface/src/control/IControl.ts: -------------------------------------------------------------------------------- 1 | export interface IControl { 2 | start(): void 3 | stop(): void 4 | destroy(): void 5 | } 6 | -------------------------------------------------------------------------------- /packages/interface/src/data/IData.ts: -------------------------------------------------------------------------------- 1 | import { IPointData } from '../math/IMath' 2 | import { IFunction } from '../function/IFunction' 3 | 4 | export type INumber = number // number | string will convert to number 5 | export type IBoolean = boolean // boolean | string will convert to boolean 6 | export type IString = string // string | other will convert to string 7 | export type IValue = INumber | IBoolean | IString | IObject 8 | export type ITimer = any 9 | 10 | export type IPathString = string 11 | 12 | export type IFourNumber = number | number[] 13 | 14 | export interface IObject { 15 | [name: string]: any 16 | } 17 | 18 | export interface IBooleanMap { 19 | [name: string]: boolean 20 | } 21 | 22 | export interface INumberMap { 23 | [name: string]: number 24 | } 25 | 26 | export interface IStringMap { 27 | [name: string]: string 28 | } 29 | 30 | export interface IFunctionMap { 31 | [name: string]: IFunction 32 | } 33 | 34 | 35 | export interface IPointDataMap { 36 | [name: string]: IPointData 37 | } 38 | 39 | export interface IDataTypeHandle { 40 | (target: any): void 41 | } -------------------------------------------------------------------------------- /packages/interface/src/data/ILeafData.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, ILeafComputedData } from '../display/ILeaf' 2 | import { IJSONOptions } from '../file/IExport' 3 | import { IObject } from './IData' 4 | 5 | export interface IDataProcessor { 6 | __leaf: ILeaf 7 | __input: IObject 8 | __middle: IObject 9 | 10 | __get(name: string): any 11 | __getData(): IObject 12 | 13 | __setInput(name: string, value: any): void 14 | __getInput(name: string): any 15 | __removeInput(name: string): void 16 | __getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject 17 | 18 | __setMiddle(name: string, value: any): void 19 | __getMiddle(name: string): any 20 | 21 | destroy(): void 22 | } 23 | 24 | export interface ILeafDataOptions { 25 | attrs?: 'all' | string[] 26 | children?: boolean 27 | } 28 | 29 | export interface ILeafData extends IDataProcessor, ILeafComputedData { 30 | __single?: boolean 31 | readonly __hasMultiPaint?: boolean // fill 、stroke 、shadow 等同时存在两次以上外观绘制的情况 32 | __checkSingle(): void 33 | __removeNaturalSize(): void 34 | } -------------------------------------------------------------------------------- /packages/interface/src/data/IList.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../display/ILeaf' 2 | import { INumberMap } from './IData' 3 | 4 | export interface ILeafMap { 5 | [name: string]: ILeaf 6 | } 7 | 8 | export interface ILeafArrayMap { 9 | [name: string]: ILeaf[] 10 | } 11 | 12 | export type ILeafListItemCallback = (item: ILeaf, index?: number) => void 13 | 14 | export interface ILeafList { 15 | list: ILeaf[] 16 | keys: INumberMap 17 | readonly length: number 18 | has(leaf: ILeaf): boolean 19 | indexAt(index: number): ILeaf 20 | indexOf(leaf: ILeaf): number 21 | 22 | add(leaf: ILeaf): void 23 | addAt(leaf: ILeaf, index: number): void 24 | addList(list: ILeaf[]): void 25 | remove(leaf: ILeaf): void 26 | 27 | forEach(itemCallback: ILeafListItemCallback): void 28 | sort(reverse?: boolean): void 29 | clone(): ILeafList 30 | update(): void 31 | reset(): void 32 | destroy(): void 33 | } 34 | 35 | export interface ILeafLevelList { 36 | levelMap: ILeafArrayMap 37 | keys: INumberMap 38 | levels: number[] 39 | readonly length: number 40 | has(leaf: ILeaf): boolean 41 | without(leaf: ILeaf): boolean 42 | sort(reverse?: boolean): void 43 | addList(list: ILeaf[]): void 44 | add(leaf: ILeaf): void 45 | forEach(itemCallback: ILeafListItemCallback): void 46 | reset(): void 47 | destroy(): void 48 | } -------------------------------------------------------------------------------- /packages/interface/src/display/IBranch.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, ILeafInputData } from './ILeaf' 2 | import { ILeaferCanvas } from '../canvas/ILeaferCanvas' 3 | import { IRenderOptions } from '../renderer/IRenderer' 4 | 5 | export interface IBranch extends ILeaf { 6 | children: ILeaf[] 7 | __renderBranch?(canvas: ILeaferCanvas, options: IRenderOptions): void 8 | addMany(...children: ILeaf[] | ILeafInputData[]): void 9 | removeAll(destroy?: boolean): void 10 | clear(): void 11 | } -------------------------------------------------------------------------------- /packages/interface/src/display/IView.ts: -------------------------------------------------------------------------------- 1 | import { IBranch } from './IBranch' 2 | 3 | 4 | export interface IZoomView extends IBranch { 5 | 6 | } -------------------------------------------------------------------------------- /packages/interface/src/display/module/IBranchRender.ts: -------------------------------------------------------------------------------- 1 | import { IBranch } from '../IBranch' 2 | import { ILeafRender } from './ILeafRender' 3 | import { ILeaferCanvas } from '../../canvas/ILeaferCanvas' 4 | import { IRenderOptions } from '../../renderer/IRenderer' 5 | 6 | export type IBranchRenderModule = IBranchRender & ThisType 7 | 8 | export interface IBranchRender extends ILeafRender { 9 | __renderBranch?(canvas: ILeaferCanvas, options: IRenderOptions): void 10 | } -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafBounds.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../ILeaf' 2 | 3 | export type ILeafBoundsModule = ILeafBounds & ThisType 4 | 5 | export interface ILeafBounds { 6 | __updateWorldBounds?(): void 7 | __updateLocalBounds?(): void 8 | 9 | __updateLocalBoxBounds?(): void 10 | __updateLocalStrokeBounds?(): void 11 | __updateLocalRenderBounds?(): void 12 | 13 | __updateBoxBounds?(secondLayout?: boolean): void 14 | __updateStrokeBounds?(): void 15 | __updateRenderBounds?(): void 16 | 17 | __updateAutoLayout?(): void 18 | __updateFlowLayout?(): void 19 | __updateNaturalSize?(): void 20 | 21 | __updateStrokeSpread?(): number 22 | __updateRenderSpread?(): number 23 | 24 | __onUpdateSize?(): void 25 | } 26 | 27 | -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafDataProxy.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../ILeaf' 2 | import { IValue } from '../../data/IData' 3 | 4 | export type ILeafDataProxyModule = ILeafDataProxy & ThisType 5 | 6 | export interface ILeafDataProxy { 7 | __setAttr?(name: string, newValue: IValue): boolean 8 | __getAttr?(name: string): IValue 9 | __realSetAttr?(name: string, newValue: IValue): void 10 | setProxyAttr?(name: string, newValue: IValue): void 11 | getProxyAttr?(name: string): IValue 12 | } 13 | 14 | -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafEventer.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../ILeaf' 2 | import { IEventListener, IEventListenerId, IEventListenerOptions, IEventParamsMap } from '../../event/IEventer' 3 | import { } from '@leafer/interface' 4 | import { IEvent } from '../../event/IEvent' 5 | import { IObject } from '../../data/IData' 6 | 7 | export type ILeafEventerModule = ILeafEventer & ThisType 8 | 9 | export interface ILeafEventer { 10 | on?(type: string | string[] | IEventParamsMap, listener?: IEventListener, options?: IEventListenerOptions | boolean): void 11 | off?(type?: string | string[], listener?: IEventListener, options?: IEventListenerOptions | boolean): void 12 | on_?(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId 13 | off_?(id: IEventListenerId | IEventListenerId[]): void 14 | once?(type: string | string[], listener: IEventListener, capture?: boolean): void 15 | emit?(type: string, event?: IEvent | IObject, capture?: boolean): void 16 | emitEvent?(event?: IEvent, capture?: boolean): void 17 | hasEvent?(type: string, capture?: boolean): boolean 18 | destroyEventer?(): void 19 | } 20 | -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafHit.ts: -------------------------------------------------------------------------------- 1 | import { IRadiusPointData } from '../../math/IMath' 2 | import { ILeaf } from '../ILeaf' 3 | import { ILeaferCanvas } from '../../canvas/ILeaferCanvas' 4 | 5 | export type ILeafHitModule = ILeafHit & ThisType 6 | 7 | export interface ILeafHit { 8 | __hitWorld?(point: IRadiusPointData): boolean 9 | __hit?(inner: IRadiusPointData): boolean 10 | __hitFill?(inner: IRadiusPointData): boolean 11 | __hitStroke?(inner: IRadiusPointData, strokeWidth: number): boolean 12 | __hitPixel(inner: IRadiusPointData): boolean 13 | __drawHitPath?(canvas: ILeaferCanvas): void 14 | __updateHitCanvas?(): void 15 | } -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafMatrix.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../ILeaf' 2 | 3 | export type ILeafMatrixModule = ILeafMatrix & ThisType 4 | 5 | export interface ILeafMatrix { 6 | __updateWorldMatrix?(): void 7 | __updateLocalMatrix?(): void 8 | } -------------------------------------------------------------------------------- /packages/interface/src/display/module/ILeafRender.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferCanvas } from '../../canvas/ILeaferCanvas' 2 | import { IRenderOptions } from '../../renderer/IRenderer' 3 | import { ILeaf } from '../ILeaf' 4 | 5 | export type ILeafRenderModule = ILeafRender & ThisType 6 | 7 | export interface ILeafRender { 8 | __render?(canvas: ILeaferCanvas, options: IRenderOptions): void 9 | __draw?(canvas: ILeaferCanvas, options: IRenderOptions, originCanvas?: ILeaferCanvas): void 10 | __drawFast?(canvas: ILeaferCanvas, options: IRenderOptions): void 11 | 12 | __clip?(_canvas: ILeaferCanvas, _options: IRenderOptions): void 13 | __renderShape?(canvas: ILeaferCanvas, options: IRenderOptions, ignoreFill?: boolean, ignoreStroke?: boolean): void 14 | 15 | __updateWorldOpacity?(): void 16 | __updateChange?(): void 17 | } -------------------------------------------------------------------------------- /packages/interface/src/event/IEvent.ts: -------------------------------------------------------------------------------- 1 | import { IEventer } from './IEventer' 2 | import { IWatchEventData } from '../watcher/IWatcher' 3 | import { ILayoutBlockData } from '../layouter/ILayouter' 4 | import { ILeaf } from '../display/ILeaf' 5 | import { IScreenSizeData, IPointData } from '../math/IMath' 6 | import { IObject } from '../data/IData' 7 | 8 | export interface IEvent { 9 | origin?: IObject 10 | 11 | type?: string 12 | target?: IEventTarget 13 | current?: IEventTarget 14 | 15 | bubbles?: boolean 16 | phase?: number 17 | 18 | isStopDefault?: boolean 19 | isStop?: boolean 20 | isStopNow?: boolean 21 | stopDefault?(): void 22 | stopNow?(): void 23 | stop?(): void 24 | } 25 | 26 | export interface IEventTarget extends IEventer { 27 | 28 | } 29 | 30 | export interface ILeaferEvent { 31 | 32 | } 33 | 34 | export interface IRenderEvent { 35 | 36 | } 37 | 38 | export interface IAnimateEvent { 39 | 40 | } 41 | 42 | export interface IChildEvent extends IEvent { 43 | parent?: ILeaf 44 | child?: ILeaf 45 | } 46 | 47 | export interface IBoundsEvent extends IEvent { 48 | 49 | } 50 | 51 | export interface IResizeEvent extends IEvent { 52 | readonly width: number 53 | readonly height: number 54 | readonly pixelRatio: number 55 | 56 | readonly bigger: boolean 57 | readonly smaller: boolean 58 | readonly samePixelRatio: boolean 59 | readonly old: IScreenSizeData 60 | } 61 | 62 | export interface IResizeEventListener { 63 | (event: IResizeEvent): void 64 | } 65 | 66 | export interface IUpdateEvent extends IEvent { 67 | 68 | } 69 | 70 | export interface IPropertyEvent extends IEvent { 71 | readonly attrName: string 72 | readonly oldValue: unknown 73 | readonly newValue: unknown 74 | } 75 | 76 | export interface ILayoutEvent extends IEvent { 77 | readonly data: ILayoutBlockData[] 78 | readonly times: number 79 | } 80 | 81 | export interface IWatchEvent extends IEvent { 82 | readonly data: IWatchEventData 83 | } 84 | 85 | export interface IMultiTouchData { 86 | move: IPointData, 87 | scale: number, 88 | rotation: number, 89 | center: IPointData 90 | } 91 | 92 | export interface IKeepTouchData { 93 | from: IPointData 94 | to: IPointData 95 | } -------------------------------------------------------------------------------- /packages/interface/src/event/IEventer.ts: -------------------------------------------------------------------------------- 1 | import { ILeafEventer } from '../display/module/ILeafEventer' 2 | import { ILeaf } from '../display/ILeaf' 3 | import { IFunction } from '../function/IFunction' 4 | import { IEvent } from './IEvent' 5 | import { IObject } from '../data/IData' 6 | 7 | 8 | export type IEventListener = IFunction 9 | 10 | export interface IEventListenerOptions { 11 | capture?: boolean 12 | once?: boolean 13 | } 14 | 15 | export type IEventOption = IEventListenerOptions | boolean | 'once' 16 | 17 | export interface IEventListenerItem extends IEventListenerOptions { 18 | listener: IEventListener 19 | } 20 | 21 | export interface IEventListenerMap { 22 | [name: string]: IEventListenerItem[] 23 | } 24 | 25 | export interface IEventParamsMap { 26 | [name: string]: IEventListener | [IEventListener, IEventOption] 27 | } 28 | 29 | export type IEventParams = any[] 30 | 31 | export interface IEventListenerId { 32 | type: string | string[] | IEventParams[] 33 | current: ILeaf 34 | listener?: IEventListener 35 | options?: IEventOption 36 | } 37 | 38 | export type InnerId = number 39 | 40 | export interface IEventer extends ILeafEventer { 41 | readonly innerId: InnerId 42 | __captureMap?: IEventListenerMap 43 | __bubbleMap?: IEventListenerMap 44 | __hasLocalEvent?: boolean 45 | __hasWorldEvent?: boolean 46 | syncEventer?: IEventer 47 | event?: IEventParamsMap 48 | 49 | on(type: string | string[] | IEventParams[] | IEventParamsMap, listener?: IEventListener, options?: IEventOption): void 50 | off(type?: string | string[], listener?: IEventListener, options?: IEventOption): void 51 | on_(type: string | string[] | IEventParams[], listener?: IEventListener, bind?: IObject, options?: IEventOption): IEventListenerId 52 | off_(id: IEventListenerId | IEventListenerId[]): void 53 | once(type: string | string[] | IEventParams[], listener?: IEventListener, captureOrBind?: boolean | IObject, capture?: boolean): void 54 | emit(type: string, event?: IEvent | IObject, capture?: boolean): void 55 | emitEvent(event?: IEvent, capture?: boolean): void 56 | hasEvent(type: string, capture?: boolean): boolean 57 | 58 | destroy(): void 59 | } -------------------------------------------------------------------------------- /packages/interface/src/event/IProgress.ts: -------------------------------------------------------------------------------- 1 | export interface IProgressData { 2 | value: number // 保留2位小数的 loaded / total 百分比值,如26.02 3 | loaded: number // 字节数 4 | total: number // 字节数 5 | } 6 | 7 | export interface IProgressFunction { 8 | (progress: IProgressData): void 9 | } -------------------------------------------------------------------------------- /packages/interface/src/file/IExport.ts: -------------------------------------------------------------------------------- 1 | import { IBlob, ILeaferCanvas } from '../canvas/ILeaferCanvas' 2 | import { ICanvasContext2DSettings } from '../canvas/ICanvas' 3 | import { ILeaf } from '../display/ILeaf' 4 | import { ILocationType } from '../layout/ILeafLayout' 5 | import { IBoundsData, IOptionSizeData, IPointData } from '../math/IMath' 6 | import { IFourNumber } from '../data/IData' 7 | 8 | export interface IExportOptions { 9 | quality?: number 10 | blob?: boolean 11 | scale?: number | IPointData 12 | size?: number | IOptionSizeData 13 | padding?: IFourNumber 14 | smooth?: boolean 15 | pixelRatio?: number 16 | clip?: IBoundsData 17 | slice?: boolean 18 | trim?: boolean 19 | fill?: string 20 | screenshot?: IBoundsData | boolean 21 | relative?: ILocationType | ILeaf 22 | json?: IJSONOptions 23 | contextSettings?: ICanvasContext2DSettings 24 | canvas?: ILeaferCanvas 25 | onCanvas?: IExportOnCanvasFunction 26 | } 27 | 28 | export interface IJSONOptions { 29 | matrix?: boolean 30 | } 31 | 32 | export interface IExportResult { 33 | data: ILeaferCanvas | IBlob | string | boolean 34 | width?: number 35 | height?: number 36 | renderBounds?: IBoundsData 37 | trimBounds?: IBoundsData 38 | } 39 | 40 | export interface IExportResultFunction { 41 | (data: IExportResult): void 42 | } 43 | 44 | export interface IExportOnCanvasFunction { 45 | (data: ILeaferCanvas): void 46 | } -------------------------------------------------------------------------------- /packages/interface/src/file/IFileType.ts: -------------------------------------------------------------------------------- 1 | export type IExportImageType = 'jpg' | 'png' | 'webp' | 'bmp' 2 | export type IExportFileType = IExportImageType | 'svg' | 'pdf' | 'json' 3 | -------------------------------------------------------------------------------- /packages/interface/src/file/IResource.ts: -------------------------------------------------------------------------------- 1 | import { ITaskProcessor } from '../task/ITaskProcessor' 2 | import { ILeaferImage } from '../image/ILeaferImage' 3 | import { IExportFileType } from './IFileType' 4 | import { IObject } from '../data/IData' 5 | import { ILeaferCanvas } from '../canvas/ILeaferCanvas' 6 | 7 | 8 | export interface IResource { 9 | map: any, 10 | tasker: ITaskProcessor 11 | readonly isComplete: boolean 12 | 13 | set(key: string, value: any): void 14 | get(key: string): any 15 | remove(key: string): void 16 | 17 | setImage(key: string, value: string | IObject | ILeaferImage | ILeaferCanvas, format?: IExportFileType): ILeaferImage 18 | loadImage(key: string, format?: IExportFileType): Promise 19 | 20 | destroy(): void 21 | } 22 | -------------------------------------------------------------------------------- /packages/interface/src/function/IFunction.ts: -------------------------------------------------------------------------------- 1 | import { IObject, IValue } from '../data/IData' 2 | import { IPointData } from '../math/IMath' 3 | 4 | export interface IFunction { 5 | (...arg: any): any 6 | } 7 | 8 | export interface INumberFunction { 9 | (...arg: any): number 10 | } 11 | 12 | export interface IStringFunction { 13 | (...arg: any): string 14 | } 15 | 16 | export interface IObjectFunction { 17 | (...arg: any): IObject 18 | } 19 | 20 | export interface IValueFunction { 21 | (leaf: any): IValue 22 | } 23 | 24 | export interface IPointDataFunction { 25 | (...arg: any): IPointData 26 | } 27 | 28 | 29 | export interface IAttrDecorator { 30 | (...arg: any): IAttrDecoratorInner 31 | } 32 | 33 | interface IAttrDecoratorInner { 34 | (target: any, key: string): any 35 | } -------------------------------------------------------------------------------- /packages/interface/src/image/IImageManager.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferImage, ILeaferImageConfig } from './ILeaferImage' 2 | import { ITaskProcessor } from '../task/ITaskProcessor' 3 | import { IExportFileType } from '../file/IFileType' 4 | 5 | 6 | export interface IImageManager { 7 | maxRecycled: number 8 | recycledList: ILeaferImage[] 9 | 10 | patternTasker: ITaskProcessor 11 | patternLocked?: boolean // 锁定pattern不更新, 一般用于创建碰撞位图 UIHit.ts 12 | 13 | get(config: ILeaferImageConfig): ILeaferImage 14 | recycle(image: ILeaferImage): void 15 | clearRecycled(): void 16 | hasAlphaPixel(config: ILeaferImageConfig): boolean // png / svg / webp 17 | isFormat(format: IExportFileType, config: ILeaferImageConfig): boolean 18 | 19 | destroy(): void 20 | } -------------------------------------------------------------------------------- /packages/interface/src/image/ILeaferImage.ts: -------------------------------------------------------------------------------- 1 | import { ICanvasPattern } from '../canvas/ICanvas' 2 | import { IObject } from '../data/IData' 3 | import { InnerId } from '../event/IEventer' 4 | import { IExportFileType } from '../file/IFileType' 5 | import { IMatrixData } from '../math/IMath' 6 | import { ILeaferCanvas } from '../canvas/ILeaferCanvas' 7 | import { IProgressData } from '../event/IProgress' 8 | 9 | export interface ILeaferImageConfig { 10 | url: string 11 | thumb?: string 12 | format?: IExportFileType 13 | showProgress?: boolean // 是否显示进度 14 | view?: IObject | ILeaferImage | ILeaferCanvas 15 | } 16 | 17 | export interface ILeaferImageOnLoaded { 18 | (image?: ILeaferImage): any 19 | } 20 | 21 | export interface ILeaferImageOnError { 22 | (error?: string | IObject, image?: ILeaferImage): any 23 | } 24 | 25 | export interface ILeaferImageCacheCanvas { 26 | data: IObject 27 | params: IArguments 28 | } 29 | 30 | export interface ILeaferImagePatternPaint { 31 | transform: IMatrixData 32 | } 33 | 34 | export interface ILeaferImage { 35 | readonly innerId: InnerId 36 | readonly url: string 37 | 38 | view: any 39 | width: number 40 | height: number 41 | 42 | isSVG: boolean 43 | hasAlphaPixel: boolean 44 | 45 | readonly completed: boolean 46 | ready: boolean 47 | error: IObject 48 | loading: boolean 49 | isPlacehold?: boolean // 是否显示占位符,一般在加载100ms后自动判断 50 | progress: IProgressData // 加载进度 51 | 52 | use: number 53 | config: ILeaferImageConfig 54 | 55 | load(onSuccess?: ILeaferImageOnLoaded, onError?: ILeaferImageOnError): number 56 | unload(index: number, stopEvent?: boolean): void 57 | getFull(filters?: IObject): any 58 | getCanvas(width: number, height: number, opacity?: number, filters?: IObject): any 59 | getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: IObject): ICanvasPattern 60 | destroy(): void 61 | } 62 | 63 | export type IImageStatus = 'wait' | 'thumb-loading' | 'thumb-success' | 'thumb-error' | 'loading' | 'success' | 'error' -------------------------------------------------------------------------------- /packages/interface/src/interaction/ICursor.ts: -------------------------------------------------------------------------------- 1 | import { ICursorType } from '../display/ILeaf' 2 | 3 | 4 | export interface ICursorTypeMap { 5 | [name: string]: ICursorType | ICursorType[] 6 | } 7 | 8 | 9 | export interface ICursorRotate { 10 | rotation?: number 11 | data?: string 12 | } 13 | 14 | export interface ICursorRotateMap { 15 | [name: string]: ICursorRotate 16 | } -------------------------------------------------------------------------------- /packages/interface/src/interaction/ITransformer.ts: -------------------------------------------------------------------------------- 1 | import { IMoveEvent, IZoomEvent, IRotateEvent } from '../event/IUIEvent' 2 | 3 | export interface ITransformer { 4 | readonly transforming: boolean 5 | move(data: IMoveEvent): void 6 | zoom(data: IZoomEvent): void 7 | rotate(data: IRotateEvent): void 8 | transformEnd(): void 9 | destroy(): void 10 | } -------------------------------------------------------------------------------- /packages/interface/src/layouter/ILayouter.ts: -------------------------------------------------------------------------------- 1 | import { IBounds } from '../math/IMath' 2 | import { ILeaf } from '../display/ILeaf' 3 | import { ILeafList } from '../data/IList' 4 | import { IControl } from '../control/IControl' 5 | 6 | export interface ILayoutChangedData { 7 | matrixList: ILeaf[] 8 | boundsList: ILeaf[] 9 | surfaceList: ILeaf[] 10 | } 11 | 12 | export interface ILayoutBlockData { 13 | updatedList: ILeafList 14 | updatedBounds: IBounds 15 | 16 | beforeBounds: IBounds 17 | afterBounds: IBounds 18 | 19 | setBefore?(): void 20 | setAfter?(): void 21 | merge?(data: ILayoutBlockData): void 22 | destroy(): void 23 | } 24 | 25 | export interface IPartLayoutConfig { 26 | maxBlocks?: number 27 | maxTimes?: number 28 | } 29 | 30 | export interface ILayouterConfig { 31 | partLayout?: IPartLayoutConfig 32 | } 33 | 34 | export interface ILayouter extends IControl { 35 | target: ILeaf 36 | layoutedBlocks: ILayoutBlockData[] 37 | extraBlock: ILayoutBlockData 38 | 39 | totalTimes: number 40 | times: number 41 | 42 | disabled: boolean 43 | running: boolean 44 | layouting: boolean 45 | 46 | waitAgain: boolean 47 | 48 | config: ILayouterConfig 49 | 50 | disable(): void 51 | 52 | layout(): void 53 | layoutAgain(): void 54 | layoutOnce(): void 55 | partLayout(): void 56 | fullLayout(): void 57 | 58 | addExtra(leaf: ILeaf): void 59 | 60 | createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData 61 | getBlocks(list: ILeafList): ILayoutBlockData[] 62 | addBlocks(current: ILayoutBlockData[]): void 63 | } -------------------------------------------------------------------------------- /packages/interface/src/path/IPathCommand.ts: -------------------------------------------------------------------------------- 1 | type Command = number 2 | type x = number 3 | type y = number 4 | type x1 = number 5 | type y1 = number 6 | type x2 = number 7 | type y2 = number 8 | type radiusX = number 9 | type radiusY = number 10 | type xAxisRotation = number 11 | type largeArcFlag = number 12 | type sweepFlag = number 13 | 14 | 15 | export type MCommandData = [Command, x, y] 16 | export type HCommandData = [Command, x] 17 | export type VCommandData = [Command, y] 18 | export type LCommandData = MCommandData 19 | 20 | export type CCommandData = [Command, x1, y1, x2, y2, x, y] 21 | export type SCommandData = [Command, x2, y2, x, y] 22 | 23 | export type QCommandData = [Command, x1, y1, x, y] 24 | export type TCommandData = [Command, x, y] 25 | 26 | export type ZCommandData = [Command] 27 | 28 | export type ACommandData = [Command, radiusX, radiusY, xAxisRotation, largeArcFlag, sweepFlag, x, y] 29 | 30 | 31 | // 非svg标准的canvas绘图命令 32 | type width = number 33 | type height = number 34 | type rotation = number 35 | type startAngle = number 36 | type endAngle = number 37 | type anticlockwise = boolean 38 | type cornerRadius = number | number[] 39 | type radius = number 40 | 41 | export type RectCommandData = [Command, x, y, width, height] 42 | export type RoundRectCommandData = [Command, x, y, width, height, cornerRadius] 43 | export type EllipseCommandData = [Command, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise] 44 | export type ArcCommandData = [Command, x, y, radius, startAngle, endAngle, anticlockwise] 45 | export type ArcToCommandData = [Command, x1, y1, x2, y2, radius] 46 | 47 | 48 | export type CanvasPathCommand = 1 | 2 | 5 | 7 | 11 // M | L | C | Q | Z canvas可以绘制的命令 49 | 50 | export type IPathCommandData = number[] // ...(MCommandData | LCommandData | CCommandData | QCommandData | ZCommandData) 51 | 52 | 53 | // 路径命令对象 54 | export interface MoveToCommandObject { 55 | name: 'M' 56 | x: number 57 | y: number 58 | } 59 | export interface LineToCommandObject { 60 | name: 'L' 61 | x: number 62 | y: number 63 | } 64 | 65 | export interface BezierCurveToCommandObject { 66 | name: 'C' 67 | x1: number 68 | y1: number 69 | x2: number 70 | y2: number 71 | x: number 72 | y: number 73 | } 74 | 75 | export interface QuadraticCurveToCommandObject { 76 | name: 'Q' 77 | x1: number 78 | y1: number 79 | x: number 80 | y: number 81 | } 82 | 83 | export interface ClosePathCommandObject { 84 | name: 'Z' 85 | } 86 | 87 | export type IPathCommandObject = MoveToCommandObject | LineToCommandObject | BezierCurveToCommandObject | QuadraticCurveToCommandObject | ClosePathCommandObject // M | L | C | Q | Z canvas可以绘制的命令 -------------------------------------------------------------------------------- /packages/interface/src/path/IPathData.ts: -------------------------------------------------------------------------------- 1 | import { IPathCommandData } from './IPathCommand' 2 | export interface IMotionPathData { 3 | total: number 4 | segments: number[] // 每个命令对应一个片段距离 5 | data: IPathCommandData // M L C Z 命令的路径数据 6 | } -------------------------------------------------------------------------------- /packages/interface/src/path/IPathDrawer.ts: -------------------------------------------------------------------------------- 1 | import { IPathCommandData } from './IPathCommand' 2 | import { IPointData } from '../math/IMath' 3 | export interface IPathDrawer { 4 | beginPath?(): void 5 | 6 | moveTo(x: number, y: number): void 7 | lineTo(x: number, y: number): void 8 | bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): void 9 | quadraticCurveTo(x1: number, y1: number, x: number, y: number): void 10 | closePath(): void 11 | 12 | arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void 13 | arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void 14 | ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void 15 | 16 | rect(x: number, y: number, width: number, height: number): void 17 | roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): void 18 | } 19 | 20 | export interface IPathCreator extends IPathDrawer { 21 | path: IPathCommandData 22 | __path: IPathCommandData 23 | 24 | beginPath(): IPathCreator 25 | 26 | moveTo(x: number, y: number): IPathCreator 27 | lineTo(x: number, y: number): IPathCreator 28 | bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): IPathCreator 29 | quadraticCurveTo(x1: number, y1: number, x: number, y: number): IPathCreator 30 | closePath(): IPathCreator 31 | 32 | arc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator 33 | arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): IPathCreator 34 | ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator 35 | 36 | rect(x: number, y: number, width: number, height: number): IPathCreator 37 | roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): IPathCreator 38 | 39 | // new 40 | drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator 41 | drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator 42 | drawPoints(points: number[] | IPointData[], curve?: boolean | number, close?: boolean): IPathCreator 43 | 44 | clearPath(): IPathCreator 45 | } -------------------------------------------------------------------------------- /packages/interface/src/plugin/IPlugin.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferBase } from '../app/ILeafer' 2 | import { IObject } from '../data/IData' 3 | 4 | export interface IPlugin extends IObject { 5 | name?: string 6 | importVersion: string 7 | import: string[] 8 | run(LeaferUI: IObject, config: IObject): void 9 | onLeafer?(leafer: ILeaferBase): void 10 | } -------------------------------------------------------------------------------- /packages/interface/src/renderer/IRenderer.ts: -------------------------------------------------------------------------------- 1 | import { ILeaferCanvas } from '../canvas/ILeaferCanvas' 2 | import { ILeaf } from '../display/ILeaf' 3 | import { IBounds, IMatrixWithScaleData } from '../math/IMath' 4 | import { IFunction } from '../function/IFunction' 5 | import { IControl } from '../control/IControl' 6 | 7 | export interface IRenderOptions { 8 | includes?: boolean, 9 | bounds?: IBounds, 10 | hideBounds?: IBounds, 11 | matrix?: IMatrixWithScaleData, 12 | inCamera?: boolean 13 | dimOpacity?: number 14 | exporting?: boolean // 是否通过 export() 导出渲染 15 | } 16 | 17 | export interface IRendererConfig { 18 | usePartRender?: boolean 19 | maxFPS?: number 20 | fill?: string 21 | } 22 | 23 | export interface IRenderer extends IControl { 24 | target: ILeaf 25 | canvas: ILeaferCanvas 26 | updateBlocks: IBounds[] 27 | 28 | FPS: number 29 | totalTimes: number 30 | times: number 31 | 32 | running: boolean 33 | rendering: boolean 34 | 35 | waitAgain: boolean 36 | changed: boolean 37 | ignore: boolean 38 | 39 | config: IRendererConfig 40 | 41 | update(change?: boolean): void 42 | 43 | requestLayout(): void 44 | 45 | checkRender(): void 46 | render(callback?: IFunction): void 47 | renderAgain(): void 48 | renderOnce(callback?: IFunction): void 49 | partRender(): void 50 | clipRender(bounds: IBounds): void 51 | fullRender(): void 52 | 53 | addBlock(block: IBounds): void 54 | mergeBlocks(): void 55 | } -------------------------------------------------------------------------------- /packages/interface/src/selector/ISelector.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../display/ILeaf' 2 | import { ILeafList } from '../data/IList' 3 | import { IPointData } from '../math/IMath' 4 | import { IBranch } from '../display/IBranch' 5 | 6 | export interface IPickResult { 7 | target: ILeaf 8 | path: ILeafList 9 | throughPath?: ILeafList 10 | } 11 | 12 | export interface IPickOptions { 13 | name?: string 14 | hitRadius?: number 15 | through?: boolean 16 | target?: IBranch 17 | findList?: ILeaf[] 18 | bottomList?: IPickBottom[] // 底部可拾取的虚拟元素 19 | exclude?: ILeafList 20 | ignoreHittable?: boolean 21 | } 22 | 23 | export interface IPickBottom { 24 | target: ILeaf 25 | proxy?: ILeaf 26 | } 27 | 28 | export interface ISelectorConfig { 29 | 30 | } 31 | 32 | export type IAnswer = 0 | 1 | 2 | 3 33 | 34 | export interface IFindCondition { 35 | id?: number | string, 36 | className?: string, 37 | tag?: string | string[] 38 | } 39 | 40 | export interface IFindMethod { 41 | (leaf: ILeaf, options?: any): IAnswer 42 | } 43 | 44 | export interface ISelectorProxy { 45 | list: ILeaf[] 46 | dragHoverExclude: ILeaf[] // drag hover 过程中需排除的元素列表 47 | } 48 | 49 | export interface ISelector { 50 | target?: ILeaf 51 | proxy?: ISelectorProxy 52 | 53 | config: ISelectorConfig 54 | 55 | picker: IPicker 56 | finder?: IFinder 57 | 58 | getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult 59 | getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] 60 | destroy(): void 61 | } 62 | 63 | 64 | export interface IPicker { 65 | getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult 66 | destroy(): void 67 | } 68 | 69 | export interface IFinder { 70 | getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] 71 | getByInnerId(innerId: number, branch?: ILeaf): ILeaf 72 | getById(id: string, branch?: ILeaf): ILeaf 73 | getByClassName(className: string, branch?: ILeaf): ILeaf[] 74 | getByTag(tag: string, branch?: ILeaf): ILeaf[] 75 | getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] 76 | destroy(): void 77 | } 78 | -------------------------------------------------------------------------------- /packages/interface/src/task/ITaskProcessor.ts: -------------------------------------------------------------------------------- 1 | import { IFunction } from '../function/IFunction' 2 | 3 | export interface ITaskProcessorConfig { 4 | onComplete?: IFunction 5 | onTask?: IFunction 6 | onError?: IFunction 7 | parallel?: number 8 | } 9 | 10 | export interface ITaskProcessor { 11 | config: ITaskProcessorConfig 12 | running: boolean 13 | isComplete: boolean 14 | percent: number 15 | total: number 16 | index: number 17 | finishedIndex: number 18 | remain: number 19 | start(): void 20 | pause(): void 21 | resume(): void 22 | skip(): void 23 | stop(): void 24 | add(taskCallback: IFunction, options?: ITaskOptions | number): ITaskItem 25 | destroy(): void 26 | } 27 | 28 | export interface ITaskItem { 29 | parent: ITaskProcessor 30 | parallel: boolean 31 | isComplete: boolean 32 | isCancel: boolean 33 | time: number 34 | run(): Promise 35 | complete(): void 36 | cancel(): void 37 | } 38 | 39 | export interface ITaskOptions { 40 | start?: boolean // default true 41 | time?: number // default 1 42 | parallel?: boolean // default true 43 | delay?: number // default 0 44 | } -------------------------------------------------------------------------------- /packages/interface/src/watcher/IWatcher.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf } from '../display/ILeaf' 2 | import { ILeafList } from '../data/IList' 3 | import { IControl } from '../control/IControl' 4 | 5 | export interface IWatchEventData { 6 | updatedList: ILeafList 7 | } 8 | 9 | export interface IWatcherConfig { 10 | 11 | } 12 | 13 | export interface IWatcher extends IControl { 14 | target: ILeaf 15 | 16 | totalTimes: number 17 | 18 | disabled: boolean 19 | running: boolean 20 | changed: boolean 21 | 22 | hasVisible: boolean 23 | hasAdd: boolean 24 | hasRemove: boolean 25 | readonly childrenChanged: boolean 26 | 27 | config: IWatcherConfig 28 | 29 | updatedList: ILeafList 30 | 31 | disable(): void 32 | 33 | update(): void 34 | } -------------------------------------------------------------------------------- /packages/list/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/list/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/list 2 | -------------------------------------------------------------------------------- /packages/list/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/list", 3 | "version": "1.6.7", 4 | "description": "@leafer/list", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/list", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "devDependencies": { 21 | "@leafer/interface": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/list/src/LeafLevelList.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, ILeafArrayMap, ILeafLevelList, ILeafListItemCallback, INumberMap } from '@leafer/interface' 2 | 3 | export class LeafLevelList implements ILeafLevelList { 4 | 5 | public levelMap: ILeafArrayMap 6 | public keys: INumberMap 7 | public levels: number[] 8 | 9 | public get length(): number { return this._length } 10 | private _length = 0 11 | 12 | constructor(item?: ILeaf | ILeaf[]) { 13 | this.reset() 14 | if (item) item instanceof Array ? this.addList(item) : this.add(item) 15 | } 16 | 17 | public has(leaf: ILeaf): boolean { 18 | return this.keys[leaf.innerId] !== undefined 19 | } 20 | 21 | public without(leaf: ILeaf): boolean { 22 | return this.keys[leaf.innerId] === undefined 23 | } 24 | 25 | public sort(reverse?: boolean): void { 26 | const { levels } = this 27 | if (reverse) { 28 | levels.sort((a, b) => b - a) // 倒序 29 | } else { 30 | levels.sort((a, b) => a - b) // 顺序 31 | } 32 | } 33 | 34 | public addList(list: ILeaf[]): void { 35 | list.forEach(leaf => { this.add(leaf) }) 36 | } 37 | 38 | public add(leaf: ILeaf): void { 39 | const { keys, levelMap } = this 40 | if (!keys[leaf.innerId]) { 41 | keys[leaf.innerId] = 1 42 | if (!levelMap[leaf.__level]) { 43 | levelMap[leaf.__level] = [leaf] 44 | this.levels.push(leaf.__level) 45 | } else { 46 | levelMap[leaf.__level].push(leaf) 47 | } 48 | this._length++ 49 | } 50 | } 51 | 52 | public forEach(itemCallback: ILeafListItemCallback): void { 53 | let list: ILeaf[] 54 | this.levels.forEach(level => { 55 | list = this.levelMap[level] 56 | for (let i = 0, len = list.length; i < len; i++) { 57 | itemCallback(list[i]) 58 | } 59 | }) 60 | } 61 | 62 | public reset(): void { 63 | this.levelMap = {} 64 | this.keys = {} 65 | this.levels = [] 66 | this._length = 0 67 | } 68 | 69 | public destroy(): void { 70 | this.levelMap = null 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /packages/list/src/index.ts: -------------------------------------------------------------------------------- 1 | export { LeafList } from './LeafList' 2 | export { LeafLevelList } from './LeafLevelList' 3 | -------------------------------------------------------------------------------- /packages/math/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/math/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/math 2 | -------------------------------------------------------------------------------- /packages/math/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/math", 3 | "version": "1.6.7", 4 | "description": "@leafer/math", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/math", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "devDependencies": { 21 | "@leafer/interface": "1.6.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/math/src/AlignHelper.ts: -------------------------------------------------------------------------------- 1 | import { IPointData, IBoundsData, IAlign } from '@leafer/interface' 2 | import { AroundHelper } from './AroundHelper' 3 | 4 | const { toPoint } = AroundHelper 5 | 6 | export const AlignHelper = { 7 | toPoint(align: IAlign, content: IBoundsData, box: IBoundsData, to: IPointData, onlyBoxSize?: boolean, onlyContentSize?: boolean): void { 8 | toPoint(align, box, to, onlyBoxSize, content, onlyContentSize) 9 | } 10 | } -------------------------------------------------------------------------------- /packages/math/src/AroundHelper.ts: -------------------------------------------------------------------------------- 1 | import { IAround, IPointData, IBoundsData, IUnitPointData } from '@leafer/interface' 2 | import { Direction9 } from './Direction' 3 | 4 | 5 | const directionData: IUnitPointData[] = [ 6 | { x: 0, y: 0 }, //topLeft 7 | { x: 0.5, y: 0 },//top 8 | { x: 1, y: 0 }, //topRight 9 | { x: 1, y: 0.5 },// right 10 | { x: 1, y: 1 }, //bottomRight 11 | { x: 0.5, y: 1 },//bottom 12 | { x: 0, y: 1 }, //bottomLeft 13 | { x: 0, y: 0.5 },//left 14 | { x: 0.5, y: 0.5 } // center 15 | ] 16 | directionData.forEach(item => item.type = 'percent') 17 | 18 | export const AroundHelper = { 19 | 20 | directionData, // index Direction9 21 | 22 | tempPoint: {} as IPointData, 23 | 24 | get, 25 | 26 | toPoint(around: IAround, box: IBoundsData, to: IPointData, onlyBoxSize?: boolean, content?: IBoundsData, onlyContentSize?: boolean) { 27 | const point = get(around) 28 | 29 | to.x = point.x 30 | to.y = point.y 31 | 32 | 33 | if (point.type === 'percent') { 34 | to.x *= box.width 35 | to.y *= box.height 36 | 37 | if (content) { // align 38 | if (!onlyContentSize) to.x -= content.x, to.y -= content.y 39 | if (point.x) to.x -= (point.x === 1) ? content.width : (point.x === 0.5 ? point.x * content.width : 0) 40 | if (point.y) to.y -= (point.y === 1) ? content.height : (point.y === 0.5 ? point.y * content.height : 0) 41 | } 42 | } 43 | 44 | if (!onlyBoxSize) to.x += box.x, to.y += box.y 45 | } 46 | } 47 | 48 | function get(around: IAround): IUnitPointData { 49 | return typeof around === 'string' ? directionData[Direction9[around]] : around 50 | } -------------------------------------------------------------------------------- /packages/math/src/AutoBounds.ts: -------------------------------------------------------------------------------- 1 | import { IAutoBounds, IAutoBoundsData, IBounds, ISizeData } from '@leafer/interface' 2 | import { Bounds } from './Bounds' 3 | 4 | 5 | export class AutoBounds implements IAutoBounds { 6 | 7 | public top: number 8 | public right: number 9 | public bottom: number 10 | public left: number 11 | 12 | public width: number 13 | public height: number 14 | 15 | constructor(top?: number | IAutoBoundsData, right?: number, bottom?: number, left?: number, width?: number, height?: number) { 16 | typeof top === 'object' ? this.copy(top) : this.set(top, right, bottom, left, width, height) 17 | } 18 | 19 | set(top = 0, right = 0, bottom = 0, left = 0, width = 0, height = 0): void { 20 | this.top = top 21 | this.right = right 22 | this.bottom = bottom 23 | this.left = left 24 | this.width = width 25 | this.height = height 26 | } 27 | 28 | copy(autoSize: IAutoBoundsData): void { 29 | const { top, right, bottom, left, width, height } = autoSize 30 | this.set(top, right, bottom, left, width, height) 31 | } 32 | 33 | getBoundsFrom(parent: ISizeData): IBounds { 34 | const { top, right, bottom, left, width, height } = this 35 | return new Bounds(left, top, width ? width : parent.width - left - right, height ? height : parent.height - top - bottom) 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /packages/math/src/Direction.ts: -------------------------------------------------------------------------------- 1 | export enum Direction4 { 2 | top, 3 | right, 4 | bottom, 5 | left 6 | } 7 | 8 | export enum Direction9 { 9 | topLeft, 10 | top, 11 | topRight, 12 | right, 13 | bottomRight, 14 | bottom, 15 | bottomLeft, 16 | left, 17 | center, 18 | 'top-left' = 0, 19 | 'top-right' = 2, 20 | 'bottom-right' = 4, 21 | 'bottom-left' = 6 22 | } -------------------------------------------------------------------------------- /packages/math/src/IncrementId.ts: -------------------------------------------------------------------------------- 1 | import { INumberMap } from '@leafer/interface' 2 | 3 | 4 | export const IncrementId = { 5 | 6 | RUNTIME: 'runtime', 7 | LEAF: 'leaf', 8 | TASK: 'task', 9 | CNAVAS: 'canvas', 10 | IMAGE: 'image', 11 | 12 | types: {} as INumberMap, 13 | 14 | create(typeName: string): number { 15 | const { types } = I 16 | if (types[typeName]) { 17 | return types[typeName]++ 18 | } else { 19 | types[typeName] = 1 20 | return 0 21 | } 22 | } 23 | } 24 | 25 | const I = IncrementId -------------------------------------------------------------------------------- /packages/math/src/Point.ts: -------------------------------------------------------------------------------- 1 | import { IPoint, IPointData, IMatrixData } from '@leafer/interface' 2 | import { PointHelper as P } from './PointHelper' 3 | 4 | export class Point implements IPoint { 5 | 6 | public x: number 7 | public y: number 8 | 9 | constructor(x?: number | IPointData, y?: number) { 10 | this.set(x, y) 11 | } 12 | 13 | public set(x?: number | IPointData, y?: number): IPoint { 14 | typeof x === 'object' ? P.copy(this, x) : P.set(this, x, y) 15 | return this 16 | } 17 | 18 | public get(): IPointData { 19 | const { x, y } = this 20 | return { x, y } 21 | } 22 | 23 | 24 | public clone(): IPoint { 25 | return new Point(this) 26 | } 27 | 28 | 29 | public move(x: number | IPointData, y?: number): IPoint { 30 | P.move(this, x, y) 31 | return this 32 | } 33 | 34 | public scale(scaleX: number, scaleY?: number): IPoint { 35 | P.scale(this, scaleX, scaleY) 36 | return this 37 | } 38 | 39 | public scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IPoint { 40 | P.scaleOf(this, origin, scaleX, scaleY) 41 | return this 42 | } 43 | 44 | public rotate(rotation: number, origin?: IPointData): IPoint { 45 | P.rotate(this, rotation, origin) 46 | return this 47 | } 48 | 49 | public rotateOf(origin: IPointData, rotation: number): IPoint { 50 | P.rotate(this, rotation, origin) 51 | return this 52 | } 53 | 54 | public getRotation(origin: IPointData, to: IPointData, toOrigin?: IPointData): number { 55 | return P.getRotation(this, origin, to, toOrigin) 56 | } 57 | 58 | 59 | public toInnerOf(matrix: IMatrixData, to?: IPointData): IPoint { 60 | P.toInnerOf(this, matrix, to) 61 | return this 62 | } 63 | 64 | public toOuterOf(matrix: IMatrixData, to?: IPointData): IPoint { 65 | P.toOuterOf(this, matrix, to) 66 | return this 67 | } 68 | 69 | 70 | public getCenter(to: IPointData): IPoint { 71 | return new Point(P.getCenter(this, to)) 72 | } 73 | 74 | public getDistance(to: IPointData): number { 75 | return P.getDistance(this, to) 76 | } 77 | 78 | public getDistancePoint(to: IPointData, distance: number, changeTo?: boolean): IPoint { 79 | return new Point(P.getDistancePoint(this, to, distance, changeTo)) 80 | } 81 | 82 | public getAngle(to: IPointData): number { 83 | return P.getAngle(this, to) 84 | } 85 | 86 | public getAtan2(to: IPointData): number { 87 | return P.getAtan2(this, to) 88 | } 89 | 90 | 91 | public reset(): IPoint { 92 | P.reset(this) 93 | return this 94 | } 95 | 96 | } 97 | 98 | export const tempPoint = new Point() -------------------------------------------------------------------------------- /packages/math/src/StringNumber.ts: -------------------------------------------------------------------------------- 1 | import { INumberMap } from '@leafer/interface' 2 | 3 | 4 | export const StringNumberMap: INumberMap = { 5 | '0': 1, 6 | '1': 1, 7 | '2': 1, 8 | '3': 1, 9 | '4': 1, 10 | '5': 1, 11 | '6': 1, 12 | '7': 1, 13 | '8': 1, 14 | '9': 1, 15 | '.': 1, 16 | 'e': 1, 17 | 'E': 1 18 | } -------------------------------------------------------------------------------- /packages/math/src/TwoPointBoundsHelper.ts: -------------------------------------------------------------------------------- 1 | import { ITwoPointBoundsData, IBoundsData } from '@leafer/interface' 2 | 3 | export const TwoPointBoundsHelper = { 4 | 5 | tempPointBounds: {} as ITwoPointBoundsData, 6 | 7 | setPoint(t: ITwoPointBoundsData, minX: number, minY: number): void { 8 | t.minX = t.maxX = minX 9 | t.minY = t.maxY = minY 10 | }, 11 | 12 | addPoint(t: ITwoPointBoundsData, x: number, y: number): void { 13 | t.minX = x < t.minX ? x : t.minX 14 | t.minY = y < t.minY ? y : t.minY 15 | t.maxX = x > t.maxX ? x : t.maxX 16 | t.maxY = y > t.maxY ? y : t.maxY 17 | }, 18 | 19 | addBounds(t: ITwoPointBoundsData, x: number, y: number, width: number, height: number): void { 20 | addPoint(t, x, y) 21 | addPoint(t, x + width, y + height) 22 | }, 23 | 24 | copy(t: ITwoPointBoundsData, pb: ITwoPointBoundsData): void { 25 | t.minX = pb.minX 26 | t.minY = pb.minY 27 | t.maxX = pb.maxX 28 | t.maxY = pb.maxY 29 | }, 30 | 31 | addPointBounds(t: ITwoPointBoundsData, pb: ITwoPointBoundsData): void { 32 | t.minX = pb.minX < t.minX ? pb.minX : t.minX 33 | t.minY = pb.minY < t.minY ? pb.minY : t.minY 34 | t.maxX = pb.maxX > t.maxX ? pb.maxX : t.maxX 35 | t.maxY = pb.maxY > t.maxY ? pb.maxY : t.maxY 36 | }, 37 | 38 | toBounds(t: ITwoPointBoundsData, setBounds: IBoundsData): void { 39 | setBounds.x = t.minX 40 | setBounds.y = t.minY 41 | setBounds.width = t.maxX - t.minX 42 | setBounds.height = t.maxY - t.minY 43 | } 44 | 45 | } 46 | 47 | const { addPoint } = TwoPointBoundsHelper -------------------------------------------------------------------------------- /packages/math/src/index.ts: -------------------------------------------------------------------------------- 1 | export { IncrementId } from './IncrementId' 2 | 3 | export { Point, tempPoint } from './Point' 4 | export { Bounds, tempBounds } from './Bounds' 5 | export { AutoBounds } from './AutoBounds' 6 | export { Matrix, tempMatrix } from './Matrix' 7 | 8 | export { PointHelper } from './PointHelper' 9 | export { AroundHelper } from './AroundHelper' 10 | export { AlignHelper } from './AlignHelper' 11 | export { BoundsHelper } from './BoundsHelper' 12 | export { TwoPointBoundsHelper } from './TwoPointBoundsHelper' 13 | export { MatrixHelper } from './MatrixHelper' 14 | export { MathHelper, OneRadian, PI2, PI_2, getPointData, getBoundsData, getMatrixData } from './MathHelper' 15 | 16 | export { StringNumberMap } from './StringNumber' 17 | export { Direction4, Direction9 } from './Direction' 18 | -------------------------------------------------------------------------------- /packages/partner/layouter/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/partner/layouter/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/layouter 2 | -------------------------------------------------------------------------------- /packages/partner/layouter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/layouter", 3 | "version": "1.6.7", 4 | "description": "@leafer/layouter", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/layouter", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } -------------------------------------------------------------------------------- /packages/partner/layouter/src/LayoutBlockData.ts: -------------------------------------------------------------------------------- 1 | import { IBounds, ILayoutBlockData, ILeafList, ILeaf } from '@leafer/interface' 2 | import { Bounds, LeafBoundsHelper, LeafList } from '@leafer/core' 3 | 4 | 5 | const { worldBounds } = LeafBoundsHelper 6 | 7 | export class LayoutBlockData implements ILayoutBlockData { 8 | 9 | public updatedList: ILeafList 10 | public updatedBounds: IBounds = new Bounds() 11 | 12 | public beforeBounds: IBounds = new Bounds() 13 | public afterBounds: IBounds = new Bounds() 14 | 15 | constructor(list: ILeafList | ILeaf[]) { 16 | if (list instanceof Array) list = new LeafList(list) 17 | this.updatedList = list 18 | } 19 | 20 | public setBefore(): void { 21 | this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds) 22 | } 23 | 24 | public setAfter(): void { 25 | this.afterBounds.setListWithFn(this.updatedList.list, worldBounds) 26 | this.updatedBounds.setList([this.beforeBounds, this.afterBounds]) 27 | } 28 | 29 | public merge(data: ILayoutBlockData): void { 30 | this.updatedList.addList(data.updatedList.list) 31 | this.beforeBounds.add(data.beforeBounds) 32 | this.afterBounds.add(data.afterBounds) 33 | this.updatedBounds.add(data.updatedBounds) 34 | } 35 | 36 | public destroy(): void { 37 | this.updatedList = null 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /packages/partner/layouter/src/LayouterHelper.ts: -------------------------------------------------------------------------------- 1 | import { ILeafLayout, ILeafLevelList, ILeafList, ILeaf } from '@leafer/interface' 2 | import { BranchHelper, LeafHelper } from '@leafer/core' 3 | 4 | 5 | const { updateAllMatrix, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper 6 | const { pushAllChildBranch, pushAllParent } = BranchHelper 7 | 8 | 9 | export function updateMatrix(updateList: ILeafList, levelList: ILeafLevelList): void { 10 | 11 | let layout: ILeafLayout 12 | updateList.list.forEach(leaf => { // 更新矩阵, 所有子元素,和父元素都需要更新bounds 13 | layout = leaf.__layout 14 | if (levelList.without(leaf) && !layout.proxyZoom) { // 防止重复, 子元素可能已经被父元素更新过 15 | 16 | if (layout.matrixChanged) { 17 | 18 | updateAllMatrix(leaf, true) 19 | 20 | levelList.add(leaf) 21 | if (leaf.isBranch) pushAllChildBranch(leaf, levelList) 22 | pushAllParent(leaf, levelList) 23 | 24 | } else if (layout.boundsChanged) { 25 | 26 | levelList.add(leaf) 27 | if (leaf.isBranch) leaf.__tempNumber = 0 // 标识需要更新子Leaf元素的WorldBounds分支, 0表示不需要更新 28 | pushAllParent(leaf, levelList) 29 | } 30 | } 31 | }) 32 | 33 | } 34 | 35 | export function updateBounds(boundsList: ILeafLevelList): void { 36 | let list: ILeaf[], branch: ILeaf, children: ILeaf[] 37 | boundsList.sort(true) 38 | boundsList.levels.forEach(level => { 39 | list = boundsList.levelMap[level] 40 | for (let i = 0, len = list.length; i < len; i++) { 41 | branch = list[i] 42 | 43 | // 标识了需要更新子元素 44 | if (branch.isBranch && branch.__tempNumber) { 45 | children = branch.children 46 | for (let j = 0, jLen = children.length; j < jLen; j++) { 47 | if (!children[j].isBranch) { 48 | updateOneBounds(children[j]) 49 | } 50 | } 51 | } 52 | updateOneBounds(branch) 53 | } 54 | }) 55 | } 56 | 57 | 58 | export function updateChange(updateList: ILeafList): void { 59 | updateList.list.forEach(updateOneChange) 60 | } -------------------------------------------------------------------------------- /packages/partner/layouter/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Layouter } from './Layouter' 2 | -------------------------------------------------------------------------------- /packages/partner/partner/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/partner/partner/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/partner 2 | -------------------------------------------------------------------------------- /packages/partner/partner/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/partner", 3 | "version": "1.6.7", 4 | "description": "@leafer/partner", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/partner", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7", 22 | "@leafer/watcher": "1.6.7", 23 | "@leafer/layouter": "1.6.7", 24 | "@leafer/renderer": "1.6.7", 25 | "@leafer/selector": "1.6.7" 26 | }, 27 | "devDependencies": { 28 | "@leafer/interface": "1.6.7" 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /packages/partner/partner/src/index.ts: -------------------------------------------------------------------------------- 1 | // leafer's partner, allow replace 2 | export * from '@leafer/watcher' 3 | export * from '@leafer/layouter' 4 | export * from '@leafer/renderer' 5 | export * from '@leafer/selector' 6 | 7 | import { ICreator } from '@leafer/interface' 8 | import { Creator, Platform } from '@leafer/core' 9 | 10 | import { Watcher } from '@leafer/watcher' 11 | import { Layouter } from '@leafer/layouter' 12 | import { Renderer } from '@leafer/renderer' 13 | import { Selector } from '@leafer/selector' 14 | 15 | 16 | Object.assign(Creator, { 17 | watcher: (target, options?) => new Watcher(target, options), 18 | layouter: (target, options?) => new Layouter(target, options), 19 | renderer: (target, canvas, options?) => new Renderer(target, canvas, options), 20 | selector: (target?, options?) => new Selector(target, options) 21 | } as ICreator) 22 | 23 | Platform.layout = Layouter.fullLayout -------------------------------------------------------------------------------- /packages/partner/renderer/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/partner/renderer/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/renderer 2 | -------------------------------------------------------------------------------- /packages/partner/renderer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/renderer", 3 | "version": "1.6.7", 4 | "description": "@leafer/renderer", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/renderer", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } -------------------------------------------------------------------------------- /packages/partner/renderer/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Renderer } from './Renderer' 2 | -------------------------------------------------------------------------------- /packages/partner/selector/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/partner/selector/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/selector 2 | -------------------------------------------------------------------------------- /packages/partner/selector/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/selector", 3 | "version": "1.6.7", 4 | "description": "@leafer/selector", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/selector", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/core": "1.6.7" 22 | }, 23 | "devDependencies": { 24 | "@leafer/interface": "1.6.7" 25 | } 26 | } -------------------------------------------------------------------------------- /packages/partner/selector/src/Selector.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, ISelector, ISelectorProxy, IPickResult, IPickOptions, IPointData, ISelectorConfig, IFinder, IFindMethod, IFindCondition, IPicker } from '@leafer/interface' 2 | import { Creator, DataHelper, Plugin, Platform } from '@leafer/core' 3 | 4 | import { Picker } from './Picker' 5 | 6 | 7 | export class Selector implements ISelector { 8 | 9 | public target?: ILeaf // target 不存在时,为临时选择器(不能缓存数据) 10 | public proxy?: ISelectorProxy // editor 11 | 12 | public config: ISelectorConfig = {} 13 | 14 | public picker: IPicker 15 | public finder?: IFinder 16 | 17 | constructor(target: ILeaf, userConfig?: ISelectorConfig) { 18 | if (userConfig) this.config = DataHelper.default(userConfig, this.config) 19 | this.picker = new Picker(this.target = target, this) 20 | this.finder = Creator.finder && Creator.finder() 21 | } 22 | 23 | public getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult { 24 | const { target, picker } = this 25 | if (Platform.backgrounder) target && target.updateLayout() 26 | return picker.getByPoint(hitPoint, hitRadius, options) 27 | } 28 | 29 | // @leafer-in/find will rewrite 30 | public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] { 31 | return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find') 32 | } 33 | 34 | public destroy(): void { 35 | this.picker.destroy() 36 | if (this.finder) this.finder.destroy() 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /packages/partner/selector/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Selector } from './Selector' 2 | export { Picker } from './Picker' 3 | -------------------------------------------------------------------------------- /packages/partner/watcher/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/partner/watcher/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/watcher 2 | -------------------------------------------------------------------------------- /packages/partner/watcher/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/watcher", 3 | "version": "1.6.7", 4 | "description": "@leafer/watcher", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/watcher", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/event": "1.6.7", 22 | "@leafer/data": "1.6.7", 23 | "@leafer/list": "1.6.7" 24 | }, 25 | "devDependencies": { 26 | "@leafer/interface": "1.6.7" 27 | } 28 | } -------------------------------------------------------------------------------- /packages/partner/watcher/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Watcher } from './Watcher' 2 | -------------------------------------------------------------------------------- /packages/path/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/path/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/path 2 | -------------------------------------------------------------------------------- /packages/path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/path", 3 | "version": "1.6.7", 4 | "description": "@leafer/path", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/path", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7", 22 | "@leafer/debug": "1.6.7" 23 | }, 24 | "devDependencies": { 25 | "@leafer/interface": "1.6.7" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/path/src/PathHelper.ts: -------------------------------------------------------------------------------- 1 | import { IPathCommandData, IPathCreator } from '@leafer/interface' 2 | 3 | export const PathHelper = { 4 | // index.ts rewrite 5 | creator: {} as IPathCreator, 6 | parse(_pathString: string, _curveMode?: boolean): IPathCommandData { return undefined }, 7 | convertToCanvasData(_old: IPathCommandData, _curveMode?: boolean): IPathCommandData { return undefined } 8 | } -------------------------------------------------------------------------------- /packages/path/src/RectHelper.ts: -------------------------------------------------------------------------------- 1 | import { IPathDrawer } from '@leafer/interface' 2 | import { MathHelper } from '@leafer/math' 3 | 4 | export const RectHelper = { 5 | 6 | drawRoundRect(drawer: IPathDrawer, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void { 7 | const data = MathHelper.fourNumber(cornerRadius, Math.min(width / 2, height / 2)) 8 | 9 | const right = x + width 10 | const bottom = y + height 11 | 12 | data[0] ? drawer.moveTo(x + data[0], y) : drawer.moveTo(x, y) 13 | data[1] ? drawer.arcTo(right, y, right, bottom, data[1]) : drawer.lineTo(right, y) 14 | data[2] ? drawer.arcTo(right, bottom, x, bottom, data[2]) : drawer.lineTo(right, bottom) 15 | data[3] ? drawer.arcTo(x, bottom, x, y, data[3]) : drawer.lineTo(x, bottom) 16 | data[0] ? drawer.arcTo(x, y, right, y, data[0]) : drawer.lineTo(x, y) 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /packages/path/src/index.ts: -------------------------------------------------------------------------------- 1 | export { PathHelper } from './PathHelper' 2 | export { PathConvert } from './PathConvert' 3 | export { PathCreator } from './PathCreator' 4 | export { PathCommandDataHelper } from './PathCommandDataHelper' 5 | export { PathDrawer } from './PathDrawer' 6 | export { PathBounds } from './PathBounds' 7 | export { PathCorner } from './PathCorner' 8 | export { BezierHelper } from './BezierHelper' 9 | export { EllipseHelper } from './EllipseHelper' 10 | export { RectHelper } from './RectHelper' 11 | export { PathCommandMap, NeedConvertToCanvasCommandMap, PathNumberCommandMap, PathNumberCommandLengthMap } from './PathCommandMap' 12 | 13 | // rewrite, prevent circular references 14 | 15 | import { PathConvert } from './PathConvert' 16 | import { PathCreator } from './PathCreator' 17 | import { PathHelper } from './PathHelper' 18 | 19 | PathHelper.creator = new PathCreator() 20 | PathHelper.parse = PathConvert.parse 21 | PathHelper.convertToCanvasData = PathConvert.toCanvasData 22 | 23 | export const pen = new PathCreator() -------------------------------------------------------------------------------- /packages/platform/canvaskit/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/canvaskit/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/canvaskit 2 | -------------------------------------------------------------------------------- /packages/platform/canvaskit/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/canvaskit", 3 | "version": "1.6.7", 4 | "description": "@leafer/canvaskit", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/canvaskit", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/platform/canvaskit/src/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leaferjs/leafer/81ea1f3f07690782f3b6075275068cc5869c8eda/packages/platform/canvaskit/src/index.ts -------------------------------------------------------------------------------- /packages/platform/miniapp/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/miniapp/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/miniapp 2 | -------------------------------------------------------------------------------- /packages/platform/miniapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/miniapp", 3 | "version": "1.6.7", 4 | "description": "@leafer/miniapp", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "dist/miniapp.esm.min.js", 9 | "exports": { 10 | "import": "./dist/miniapp.esm.min.js", 11 | "require": "./dist/miniapp.min.cjs", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "types": "types/index.d.ts", 15 | "unpkg": "dist/miniapp.esm.min.js", 16 | "jsdelivr": "dist/miniapp.esm.min.js", 17 | "files": ["src","types","dist"], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/leaferjs/leafer.git" 21 | }, 22 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/miniapp", 23 | "bugs": "https://github.com/leaferjs/leafer/issues", 24 | "keywords": [ 25 | "leafer", 26 | "leaferjs" 27 | ], 28 | "dependencies": { 29 | "@leafer-ui/miniapp": "1.6.7", 30 | "@leafer-ui/draw": "1.6.7", 31 | "@leafer-ui/core": "1.6.7", 32 | "@leafer-in/editor": "1.6.7", 33 | "@leafer-in/viewport": "1.6.7", 34 | "@leafer-in/view": "1.6.7", 35 | "@leafer-in/scroll": "1.6.7", 36 | "@leafer-in/arrow": "1.6.7", 37 | "@leafer-in/flow": "1.6.7", 38 | "@leafer-in/animate": "1.6.7", 39 | "@leafer-in/motion-path": "1.6.7", 40 | "@leafer-in/state": "1.6.7", 41 | "@leafer-in/robot": "1.6.7", 42 | "@leafer-in/find": "1.6.7", 43 | "@leafer-in/export": "1.6.7", 44 | "@leafer-in/filter": "1.6.7", 45 | "@leafer-in/color": "1.6.7", 46 | "@leafer-in/resize": "1.6.7", 47 | "@leafer-in/interface": "1.6.7" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/platform/miniapp/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@leafer-ui/miniapp' 2 | 3 | export * from '@leafer-in/editor' 4 | export * from '@leafer-in/viewport' 5 | export * from '@leafer-in/view' 6 | export * from '@leafer-in/scroll' 7 | 8 | export * from '@leafer-in/arrow' 9 | export * from '@leafer-in/flow' 10 | 11 | export * from '@leafer-in/animate' 12 | export * from '@leafer-in/motion-path' 13 | export * from '@leafer-in/state' 14 | export * from '@leafer-in/robot' 15 | 16 | export * from '@leafer-in/find' 17 | export * from '@leafer-in/export' 18 | 19 | export * from '@leafer-in/filter' 20 | 21 | export * from '@leafer-in/color' 22 | export * from '@leafer-in/resize' 23 | 24 | export * from '@leafer-in/interface' -------------------------------------------------------------------------------- /packages/platform/node/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/node/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/node 2 | -------------------------------------------------------------------------------- /packages/platform/node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/node", 3 | "version": "1.6.7", 4 | "description": "@leafer/node", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "dist/node.esm.min.js", 9 | "exports": { 10 | "import": "./dist/node.esm.min.js", 11 | "require": "./dist/node.min.cjs", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "types": "types/index.d.ts", 15 | "unpkg": "dist/node.esm.min.js", 16 | "jsdelivr": "dist/node.esm.min.js", 17 | "files": ["src","types","dist"], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/leaferjs/leafer.git" 21 | }, 22 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/node", 23 | "bugs": "https://github.com/leaferjs/leafer/issues", 24 | "keywords": [ 25 | "leafer", 26 | "leaferjs" 27 | ], 28 | "dependencies": { 29 | "@leafer-ui/node": "1.6.7", 30 | "@leafer-ui/draw": "1.6.7", 31 | "@leafer-ui/core": "1.6.7", 32 | "@leafer-in/editor": "1.6.7", 33 | "@leafer-in/viewport": "1.6.7", 34 | "@leafer-in/view": "1.6.7", 35 | "@leafer-in/scroll": "1.6.7", 36 | "@leafer-in/arrow": "1.6.7", 37 | "@leafer-in/flow": "1.6.7", 38 | "@leafer-in/animate": "1.6.7", 39 | "@leafer-in/motion-path": "1.6.7", 40 | "@leafer-in/state": "1.6.7", 41 | "@leafer-in/robot": "1.6.7", 42 | "@leafer-in/find": "1.6.7", 43 | "@leafer-in/export": "1.6.7", 44 | "@leafer-in/filter": "1.6.7", 45 | "@leafer-in/color": "1.6.7", 46 | "@leafer-in/resize": "1.6.7", 47 | "@leafer-in/interface": "1.6.7" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/platform/node/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@leafer-ui/node' 2 | 3 | export * from '@leafer-in/editor' 4 | export * from '@leafer-in/viewport' 5 | export * from '@leafer-in/view' 6 | export * from '@leafer-in/scroll' 7 | 8 | export * from '@leafer-in/arrow' 9 | export * from '@leafer-in/flow' 10 | 11 | export * from '@leafer-in/animate' 12 | export * from '@leafer-in/motion-path' 13 | export * from '@leafer-in/state' 14 | export * from '@leafer-in/robot' 15 | 16 | export * from '@leafer-in/find' 17 | export * from '@leafer-in/export' 18 | 19 | export * from '@leafer-in/filter' 20 | 21 | export * from '@leafer-in/color' 22 | export * from '@leafer-in/resize' 23 | 24 | export * from '@leafer-in/interface' -------------------------------------------------------------------------------- /packages/platform/platform/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/platform/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/platform 2 | -------------------------------------------------------------------------------- /packages/platform/platform/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/platform", 3 | "version": "1.6.7", 4 | "description": "@leafer/platform", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/platform", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/layouter": "1.6.7", 22 | "@leafer/debug": "1.6.7" 23 | }, 24 | "devDependencies": { 25 | "@leafer/interface": "1.6.7" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/platform/platform/src/Platform.ts: -------------------------------------------------------------------------------- 1 | import { IPlatform } from '@leafer/interface' 2 | 3 | 4 | export const Platform: IPlatform = { 5 | toURL(text: string, fileType?: 'text' | 'svg'): string { 6 | let url = encodeURIComponent(text) 7 | if (fileType === 'text') url = 'data:text/plain;charset=utf-8,' + url 8 | else if (fileType === 'svg') url = 'data:image/svg+xml,' + url 9 | return url 10 | }, 11 | image: { 12 | hitCanvasSize: 100, 13 | maxCacheSize: 2560 * 1600, // 2k 14 | maxPatternSize: 4096 * 2160, // 4k 15 | crossOrigin: 'anonymous', 16 | getRealURL(url: string): string { 17 | const { prefix, suffix } = Platform.image 18 | if (suffix && !url.startsWith('data:') && !url.startsWith('blob:')) url += (url.includes("?") ? "&" : "?") + suffix 19 | if (prefix && url[0] === '/') url = prefix + url 20 | return url 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /packages/platform/platform/src/creator/Creator.ts: -------------------------------------------------------------------------------- 1 | import { ICreator, IObject, ILeaf } from '@leafer/interface' 2 | import { Plugin } from '@leafer/debug' 3 | 4 | 5 | export const Creator: ICreator = { 6 | editor(_options?: IObject): ILeaf { 7 | return Plugin.need('editor') 8 | } 9 | } -------------------------------------------------------------------------------- /packages/platform/platform/src/creator/EventCreator.ts: -------------------------------------------------------------------------------- 1 | import { IEvent, IObject } from '@leafer/interface' 2 | import { Debug } from '@leafer/debug' 3 | 4 | 5 | const debug = Debug.get('EventCreator') 6 | 7 | export const EventCreator = { 8 | 9 | nameList: {} as IObject, 10 | 11 | register(Event: IObject): void { 12 | let name: string 13 | Object.keys(Event).forEach(key => { 14 | name = Event[key] 15 | if (typeof name === 'string') nameList[name] && debug.repeat(name), nameList[name] = Event 16 | }) 17 | }, 18 | 19 | changeName(oldName: string, newName: string): void { 20 | const Event = nameList[oldName] 21 | if (Event) { 22 | const constName = Object.keys(Event).find(key => Event[key] === oldName) 23 | if (constName) { 24 | Event[constName] = newName 25 | nameList[newName] = Event 26 | } 27 | } 28 | }, 29 | 30 | has(type: string): boolean { 31 | return !!this.nameList[type] 32 | }, 33 | 34 | get(type: string, ...params: unknown[]): IEvent { 35 | return new nameList[type](...params) 36 | } 37 | 38 | } 39 | 40 | const { nameList } = EventCreator -------------------------------------------------------------------------------- /packages/platform/platform/src/creator/UICreator.ts: -------------------------------------------------------------------------------- 1 | import { ILeaf, IObject } from '@leafer/interface' 2 | import { Debug } from '@leafer/debug' 3 | 4 | 5 | const debug = Debug.get('UICreator') 6 | 7 | export const UICreator = { 8 | 9 | list: {} as IObject, 10 | 11 | register(UI: IObject): void { 12 | const { __tag: tag } = UI.prototype as ILeaf 13 | if (list[tag]) debug.repeat(tag) 14 | list[tag] = UI 15 | }, 16 | 17 | get(tag: string, data?: IObject, x?: number, y?: number, width?: number, height?: number): ILeaf { 18 | if (!list[tag]) debug.error('not register ' + tag) 19 | const ui = new list[tag](data) 20 | if (x !== undefined) { 21 | ui.x = x 22 | if (y) ui.y = y 23 | if (width) ui.width = width 24 | if (height) ui.height = height 25 | } 26 | return ui 27 | } 28 | 29 | } 30 | 31 | const { list } = UICreator -------------------------------------------------------------------------------- /packages/platform/platform/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Platform } from './Platform' 2 | export { Creator } from './creator/Creator' 3 | export { UICreator } from './creator/UICreator' 4 | export { EventCreator } from './creator/EventCreator' 5 | 6 | -------------------------------------------------------------------------------- /packages/platform/web/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/web/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/web 2 | -------------------------------------------------------------------------------- /packages/platform/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/web", 3 | "version": "1.6.7", 4 | "description": "@leafer/web", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/web", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "leafer-ui": "1.6.7", 22 | "@leafer-ui/draw": "1.6.7", 23 | "@leafer-ui/core": "1.6.7", 24 | "@leafer-in/editor": "1.6.7", 25 | "@leafer-in/text-editor": "1.6.7", 26 | "@leafer-in/viewport": "1.6.7", 27 | "@leafer-in/view": "1.6.7", 28 | "@leafer-in/scroll": "1.6.7", 29 | "@leafer-in/html": "1.6.7", 30 | "@leafer-in/arrow": "1.6.7", 31 | "@leafer-in/flow": "1.6.7", 32 | "@leafer-in/animate": "1.6.7", 33 | "@leafer-in/motion-path": "1.6.7", 34 | "@leafer-in/state": "1.6.7", 35 | "@leafer-in/robot": "1.6.7", 36 | "@leafer-in/find": "1.6.7", 37 | "@leafer-in/export": "1.6.7", 38 | "@leafer-in/filter": "1.6.7", 39 | "@leafer-in/color": "1.6.7", 40 | "@leafer-in/resize": "1.6.7", 41 | "@leafer-in/interface": "1.6.7" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/platform/web/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from 'leafer-ui' 2 | 3 | export * from '@leafer-in/editor' 4 | export * from '@leafer-in/text-editor' 5 | export * from '@leafer-in/viewport' 6 | export * from '@leafer-in/view' 7 | export * from '@leafer-in/scroll' 8 | 9 | export * from '@leafer-in/html' 10 | export * from '@leafer-in/arrow' 11 | export * from '@leafer-in/flow' 12 | 13 | export * from '@leafer-in/animate' 14 | export * from '@leafer-in/motion-path' 15 | export * from '@leafer-in/state' 16 | export * from '@leafer-in/robot' 17 | 18 | export * from '@leafer-in/find' 19 | export * from '@leafer-in/export' 20 | 21 | export * from '@leafer-in/filter' 22 | 23 | export * from '@leafer-in/color' 24 | export * from '@leafer-in/resize' 25 | 26 | export * from '@leafer-in/interface' -------------------------------------------------------------------------------- /packages/platform/worker/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/platform/worker/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/worker 2 | -------------------------------------------------------------------------------- /packages/platform/worker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/worker", 3 | "version": "1.6.7", 4 | "description": "@leafer/worker", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "dist/worker.esm.min.js", 9 | "exports": { 10 | "import": "./dist/worker.esm.min.js", 11 | "require": "./dist/worker.min.cjs", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "types": "types/index.d.ts", 15 | "unpkg": "dist/worker.min.js", 16 | "jsdelivr": "dist/worker.min.js", 17 | "files": ["src","types","dist"], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/leaferjs/leafer.git" 21 | }, 22 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/platform/worker", 23 | "bugs": "https://github.com/leaferjs/leafer/issues", 24 | "keywords": [ 25 | "leafer", 26 | "leaferjs" 27 | ], 28 | "dependencies": { 29 | "@leafer-ui/worker": "1.6.7", 30 | "@leafer-ui/draw": "1.6.7", 31 | "@leafer-ui/core": "1.6.7", 32 | "@leafer-in/editor": "1.6.7", 33 | "@leafer-in/text-editor": "1.6.7", 34 | "@leafer-in/viewport": "1.6.7", 35 | "@leafer-in/view": "1.6.7", 36 | "@leafer-in/scroll": "1.6.7", 37 | "@leafer-in/html": "1.6.7", 38 | "@leafer-in/arrow": "1.6.7", 39 | "@leafer-in/flow": "1.6.7", 40 | "@leafer-in/animate": "1.6.7", 41 | "@leafer-in/motion-path": "1.6.7", 42 | "@leafer-in/state": "1.6.7", 43 | "@leafer-in/robot": "1.6.7", 44 | "@leafer-in/find": "1.6.7", 45 | "@leafer-in/export": "1.6.7", 46 | "@leafer-in/filter": "1.6.7", 47 | "@leafer-in/color": "1.6.7", 48 | "@leafer-in/resize": "1.6.7", 49 | "@leafer-in/interface": "1.6.7" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/platform/worker/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@leafer-ui/worker' 2 | 3 | export * from '@leafer-in/editor' 4 | export * from '@leafer-in/text-editor' 5 | export * from '@leafer-in/viewport' 6 | export * from '@leafer-in/view' 7 | export * from '@leafer-in/scroll' 8 | 9 | export * from '@leafer-in/html' 10 | export * from '@leafer-in/arrow' 11 | export * from '@leafer-in/flow' 12 | 13 | export * from '@leafer-in/animate' 14 | export * from '@leafer-in/motion-path' 15 | export * from '@leafer-in/state' 16 | export * from '@leafer-in/robot' 17 | 18 | export * from '@leafer-in/find' 19 | export * from '@leafer-in/export' 20 | 21 | export * from '@leafer-in/filter' 22 | 23 | export * from '@leafer-in/color' 24 | export * from '@leafer-in/resize' 25 | 26 | export * from '@leafer-in/interface' -------------------------------------------------------------------------------- /packages/task/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-present, Chao (Leafer) Wan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/task/README.md: -------------------------------------------------------------------------------- 1 | # @leafer/task 2 | -------------------------------------------------------------------------------- /packages/task/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@leafer/task", 3 | "version": "1.6.7", 4 | "description": "@leafer/task", 5 | "author": "Chao (Leafer) Wan", 6 | "license": "MIT", 7 | "main": "src/index.ts", 8 | "types": "types/index.d.ts", 9 | "files": ["src","types","dist"], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/leaferjs/leafer.git" 13 | }, 14 | "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/task", 15 | "bugs": "https://github.com/leaferjs/leafer/issues", 16 | "keywords": [ 17 | "leafer", 18 | "leaferjs" 19 | ], 20 | "dependencies": { 21 | "@leafer/math": "1.6.7", 22 | "@leafer/debug": "1.6.7" 23 | }, 24 | "devDependencies": { 25 | "@leafer/interface": "1.6.7" 26 | } 27 | } -------------------------------------------------------------------------------- /packages/task/src/TaskItem.ts: -------------------------------------------------------------------------------- 1 | import { IFunction, ITaskItem } from '@leafer/interface' 2 | import { IncrementId } from '@leafer/math' 3 | import { Debug } from '@leafer/debug' 4 | 5 | import { TaskProcessor } from './TaskProcessor' 6 | 7 | 8 | const debug = Debug.get('TaskProcessor') 9 | export class TaskItem implements ITaskItem { 10 | 11 | readonly id: number 12 | 13 | public parent: TaskProcessor 14 | 15 | public parallel = true 16 | public time = 1 // 预估任务需要运行的时间, 毫秒为单位 17 | 18 | public isComplete: boolean 19 | public isCancel: boolean 20 | 21 | private task: IFunction 22 | 23 | constructor(task?: IFunction) { 24 | this.id = IncrementId.create(IncrementId.TASK) 25 | this.task = task 26 | } 27 | 28 | async run(): Promise { 29 | try { 30 | if (this.task && !this.isComplete && this.parent.running) await this.task() 31 | } catch (error) { 32 | debug.error(error) 33 | } 34 | } 35 | 36 | public complete(): void { 37 | this.isComplete = true 38 | this.parent = null 39 | this.task = null 40 | } 41 | 42 | public cancel(): void { 43 | this.isCancel = true 44 | this.complete() 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /packages/task/src/index.ts: -------------------------------------------------------------------------------- 1 | export { TaskProcessor } from './TaskProcessor' 2 | export { TaskItem } from './TaskItem' 3 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@leafer/web' --------------------------------------------------------------------------------