├── type.d.ts ├── .prettierrc ├── src └── README.md ├── public └── image │ ├── arrows.png │ └── leafer.jpg ├── .gitignore ├── scripts ├── all.sh ├── update.sh ├── dts.sh └── clear.sh ├── index.ts ├── .eslintrc.js ├── .gitmodules ├── pnpm-workspace.yaml ├── LICENSE ├── README.md ├── package.json ├── tsconfig.json ├── vite.config.ts └── rollup.config.js /type.d.ts: -------------------------------------------------------------------------------- 1 | declare let wx: any 2 | declare let LeaferUI: any -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false 4 | } -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # 代码说明 2 | 3 | 当前目录下放置 leafer、ui、in、draw、editor 仓库代码 4 | -------------------------------------------------------------------------------- /public/image/arrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leaferjs/LeaferJS/HEAD/public/image/arrows.png -------------------------------------------------------------------------------- /public/image/leafer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leaferjs/LeaferJS/HEAD/public/image/leafer.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | types 3 | node_modules 4 | package-lock.json 5 | 6 | pnpm-lock.yaml 7 | 8 | .DS_Store 9 | 10 | .idea 11 | .vscode 12 | 13 | .eslintcache 14 | *.tsbuildinfo 15 | *.log -------------------------------------------------------------------------------- /scripts/all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | pnpm run clear 3 | pnpm run dts 4 | pnpm run core 5 | pnpm run web 6 | pnpm run worker 7 | pnpm run node 8 | pnpm run miniapp 9 | pnpm run draw 10 | pnpm run in -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { Leafer, Rect } from 'leafer-ui' 2 | 3 | const leafer = new Leafer({ view: window }) 4 | 5 | const rect = new Rect({ 6 | x: 100, 7 | y: 100, 8 | width: 100, 9 | height: 100, 10 | fill: '#32cd79', 11 | draggable: true 12 | }) 13 | 14 | leafer.add(rect) -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['plugin:@typescript-eslint/recommended'], 4 | plugins: ['@typescript-eslint'], 5 | env:{ 6 | browser: true, 7 | node: true 8 | } 9 | } -------------------------------------------------------------------------------- /scripts/update.sh: -------------------------------------------------------------------------------- 1 | cd src/leafer 2 | git pull origin main 3 | cd ../../ 4 | 5 | cd src/ui 6 | git pull origin main 7 | cd ../../ 8 | 9 | cd src/in 10 | git pull origin main 11 | cd ../../ 12 | 13 | cd src/draw 14 | git pull origin main 15 | cd ../../ 16 | 17 | cd src/game 18 | git pull origin main 19 | cd ../../ 20 | 21 | cd src/editor 22 | git pull origin main 23 | cd ../../ -------------------------------------------------------------------------------- /scripts/dts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | function loop() { 3 | filelist=`ls $1` 4 | 5 | for file in $filelist 6 | do 7 | if [ -d $1"/"$file ];then 8 | if [ $file != "node_modules" ];then 9 | loop $1/$file $file 10 | fi 11 | else 12 | if [ $file == "package.json" ];then 13 | cross-env DTS_PACKAGE=$1 rollup -c 14 | echo DTS_PACKAGE=$1 15 | fi 16 | fi 17 | done 18 | } 19 | 20 | loop src/leafer 21 | loop src/draw 22 | loop src/ui 23 | loop src/in 24 | 25 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/leafer"] 2 | path = src/leafer 3 | url = https://github.com/leaferjs/leafer.git 4 | [submodule "src/ui"] 5 | path = src/ui 6 | url = https://github.com/leaferjs/leafer-ui.git 7 | [submodule "src/in"] 8 | path = src/in 9 | url = https://github.com/leaferjs/leafer-in.git 10 | [submodule "src/draw"] 11 | path = src/draw 12 | url = https://github.com/leaferjs/leafer-draw.git 13 | [submodule "src/editor"] 14 | path = src/editor 15 | url = https://github.com/leaferjs/leafer-editor.git 16 | [submodule "src/game"] 17 | path = src/game 18 | url = https://github.com/leaferjs/leafer-game.git 19 | -------------------------------------------------------------------------------- /scripts/clear.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | function loop() { 3 | filelist=`ls $1` 4 | 5 | for file in $filelist 6 | do 7 | if [ -d $1"/"$file ];then 8 | if [ $file != "node_modules" ];then 9 | loop $1/$file 10 | fi 11 | else 12 | if [ $file == "package.json" ];then 13 | rm -rf $1/dist 14 | rm -rf $1/lib 15 | rm -rf $1/types 16 | rm -rf $1/node_modules 17 | echo $1 18 | fi 19 | fi 20 | done 21 | } 22 | 23 | loop src/leafer 24 | loop src/draw 25 | loop src/ui 26 | loop src/in -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'src/leafer' 3 | - 'src/leafer/packages/*' 4 | - 'src/leafer/packages/platform/*' 5 | - 'src/leafer/packages/display-module/*' 6 | - 'src/leafer/packages/canvas/*' 7 | - 'src/leafer/packages/image/*' 8 | - 'src/leafer/packages/partner/*' 9 | - 'src/ui' 10 | - 'src/ui/packages/*' 11 | - 'src/ui/packages/core/*' 12 | - 'src/ui/packages/platform/*' 13 | - 'src/ui/packages/display-module/*' 14 | - 'src/ui/packages/interaction/*' 15 | - 'src/ui/packages/partner/*' 16 | - 'src/in' 17 | - 'src/in/packages/*' 18 | - 'src/draw' 19 | - 'src/draw/packages/*' 20 | - 'src/draw/packages/platform/*' 21 | - 'src/editor' 22 | - 'src/editor/packages/*' 23 | - 'src/editor/packages/platform/*' 24 | - 'src/game' 25 | - 'src/game/packages/*' 26 | - 'src/game/packages/platform/*' 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LeaferJS 2 | 3 | 一款好用的 Canvas 渲染引擎,革新的体验。可用于高效绘图 、UI 交互(小游戏、互动应用、组态)、图形编辑,前端开发必备~ 4 | 5 | 能让你拥有瞬间创建 100 万个图形的超强能力,免费开源、易学易用、场景丰富。 6 | 7 | ## 运行 8 | 9 | LeaferJS 完全依赖于子仓库 [leafer](https://github.com/leaferjs/leafer)、[leafer-ui](https://github.com/leaferjs/leafer-ui)、[leafer-in](https://github.com/leaferjs/leafer-in)、[leafer-draw](https://github.com/leaferjs/leafer-draw)、[leafer-game](https://github.com/leaferjs/leafer-game)、[leafer-editor](https://github.com/leaferjs/leafer-editor) , 提供运行官网示例代码、自定义打包的能力。 10 | 11 | 复制以下命令并运行: 12 | 13 | ```sh 14 | 15 | git clone https://github.com/leaferjs/LeaferJS.git --recurse-submodules 16 | 17 | cd LeaferJS 18 | 19 | npm install 20 | npm run start 21 | 22 | ``` 23 | 24 | 将在本地创建一个 LeaferJS 项目,并自动下载 [leafer](https://github.com/leaferjs/leafer)、[leafer-ui](https://github.com/leaferjs/leafer-ui)、[leafer-in](https://github.com/leaferjs/leafer-in)、[leafer-draw](https://github.com/leaferjs/leafer-draw)、[leafer-game](https://github.com/leaferjs/leafer-game)、[leafer-editor](https://github.com/leaferjs/leafer-editor) 子仓库代码到 src 目录。 25 | 26 | 安装启动完成后,可在浏览器中访问:http://localhost:10101 27 | 28 | 复制 [官网](https://leaferjs.com) 示例代码到 index.ts 中,可以实时查看运行效果。 29 | 30 | ## 更新 31 | 32 | ```sh 33 | 34 | git pull --recurse-submodules 35 | 36 | ``` 37 | 38 | ## 打包 39 | 40 | ```sh 41 | 42 | npm run core # 打包核心代码,环境打包的依赖项 43 | 44 | npm run web # 仅打包web环境代码 45 | 46 | npm run all # 打包所有环境的代码 47 | 48 | npm run dts # 为所有包生成d.ts文件 49 | 50 | npm run clear # 清空所有打包内容 51 | 52 | 53 | ``` 54 | 55 | ## License 56 | 57 | LeaferJS 是采用 MIT 许可的开源项目,可以永久免费使用。 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaferjs", 3 | "version": "1.12.0", 4 | "author": "leafer ", 5 | "license": "MIT", 6 | "packageManager": "pnpm@8.7.6", 7 | "main": "index.ts", 8 | "type": "module", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/leaferjs/LeaferJS" 12 | }, 13 | "homepage": "https://github.com/leaferjs/LeaferJS", 14 | "bugs": "https://github.com/leaferjs/LeaferJS/issues", 15 | "scripts": { 16 | "start": "cross-env NODE_ENV=development rollup -c -w", 17 | "core": "cross-env PLATFORM=core rollup -c", 18 | "web": "cross-env PLATFORM=web rollup -c", 19 | "worker": "cross-env PLATFORM=worker rollup -c", 20 | "node": "cross-env PLATFORM=node rollup -c", 21 | "miniapp": "cross-env PLATFORM=miniapp rollup -c", 22 | "draw": "cross-env PLATFORM=draw rollup -c", 23 | "in": "cross-env PLATFORM=in rollup -c", 24 | "dts": "./scripts/dts.sh", 25 | "clear": "./scripts/clear.sh", 26 | "all": "./scripts/all.sh", 27 | "test": "vitest", 28 | "update": "./scripts/update.sh" 29 | }, 30 | "devDependencies": { 31 | "@rollup/plugin-commonjs": "^25.0.4", 32 | "@rollup/plugin-html": "^1.0.3", 33 | "@rollup/plugin-multi-entry": "^6.0.0", 34 | "@rollup/plugin-node-resolve": "^15.2.1", 35 | "@rollup/plugin-terser": "^0.4.3", 36 | "@rollup/plugin-typescript": "^11.1.3", 37 | "@typescript-eslint/eslint-plugin": "^5.54.1", 38 | "@typescript-eslint/parser": "^5.54.1", 39 | "@types/node":"^20.8.7", 40 | "rollup": "^3.29.2", 41 | "rollup-plugin-dts": "^6.0.2", 42 | "rollup-plugin-livereload": "^2.0.5", 43 | "rollup-plugin-serve": "^2.0.2", 44 | "rollup-plugin-string": "^3.0.0", 45 | "rollup-plugin-copy": "^3.5.0", 46 | "tslib": "^2.6.2", 47 | "typescript": "^5.2.2", 48 | "vite": "^4.4.9", 49 | "vitest": "^0.34.4", 50 | "jsdom": "^22.0.0", 51 | "cross-env": "^7.0.3", 52 | "eslint": "^8.49.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2015", 4 | "module": "ES2015", 5 | "lib": ["ESNext","DOM"], 6 | "experimentalDecorators": true, 7 | "allowJs": false, 8 | "sourceMap": true, 9 | "inlineSources": true, 10 | "removeComments": true, 11 | "strict": true, 12 | "noImplicitAny": true, 13 | "noUnusedLocals": true, 14 | "noUnusedParameters": true, 15 | "noImplicitReturns": true, 16 | "strictNullChecks": false, 17 | "allowSyntheticDefaultImports": true, 18 | "moduleResolution": "node", 19 | "resolveJsonModule": true, 20 | "baseUrl": "./", 21 | "outDir": "dist", 22 | "paths": { 23 | "leafer": ["src/leafer/src"], 24 | "@leafer/*": [ 25 | "src/leafer/packages/display-module/*/src", 26 | "src/leafer/packages/platform/*/src", 27 | "src/leafer/packages/canvas/*/src", 28 | "src/leafer/packages/image/*/src", 29 | "src/leafer/packages/partner/*/src", 30 | "src/leafer/packages/*/src", 31 | ], 32 | "leafer-ui": ["src/ui/src"], 33 | "@leafer-ui/*": [ 34 | "src/ui/packages/core/*/src", 35 | "src/ui/packages/platform/*/src", 36 | "src/ui/packages/display-module/*/src", 37 | "src/ui/packages/interaction/*/src", 38 | "src/ui/packages/partner/*/src", 39 | "src/ui/packages/*/src", 40 | ], 41 | "leafer-in": ["src/in/src"], 42 | "@leafer-in/*": [ 43 | "src/in/packages/*/src", 44 | ], 45 | "leafer-draw": ["src/draw/src"], 46 | "@leafer-draw/*": [ 47 | "src/draw/packages/platform/*/src", 48 | "src/draw/packages/*/src", 49 | ], 50 | "leafer-editor": ["src/editor/src"], 51 | "@leafer-editor/*": [ 52 | "src/editor/packages/platform/*/src", 53 | "src/editor/packages/*/src", 54 | ], 55 | "leafer-game": ["src/game/src"], 56 | "@leafer-game/*": [ 57 | "src/game/packages/platform/*/src", 58 | "src/game/packages/*/src", 59 | ] 60 | }, 61 | }, 62 | "exclude": [ 63 | "node_modules", 64 | "**/node_modules/**", 65 | "**/dist/**", 66 | "**/lib/**", 67 | "**/scripts/**", 68 | "**/types/**" 69 | ], 70 | "ts-node": { 71 | "files": true, 72 | "compilerOptions": { 73 | "esModuleInterop": true 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config' 2 | 3 | export default defineConfig({ 4 | test: { 5 | globals: true, 6 | environment: 'jsdom', 7 | alias: [ 8 | { 9 | find: 'leafer', 10 | replacement: 'src/leafer/src' 11 | }, 12 | { 13 | find: '@leafer/web', 14 | replacement: 'src/leafer/packages/platform/web/src' 15 | }, 16 | { 17 | find: '@leafer/node', 18 | replacement: 'src/leafer/packages/platform/node/src' 19 | }, 20 | { 21 | find: '@leafer/platform', 22 | replacement: 'src/leafer/packages/platform/platform/src' 23 | }, 24 | { 25 | find: /^@leafer\/canvas(.*)/, 26 | replacement: 'src/leafer/packages/canvas/canvas$1/src' 27 | }, 28 | { 29 | find: /^@leafer\/image(.*)/, 30 | replacement: 'src/leafer/packages/image/image$1/src' 31 | }, 32 | { 33 | find: /^@leafer\/(partner|layouter|watcher|renderer|selector)/, 34 | replacement: 'src/leafer/packages/partner/$1/src' 35 | }, 36 | { 37 | find: /^@leafer\/(display\-module|data|layout|helper)/, 38 | replacement: 'src/leafer/packages/display-module/$1/src' 39 | }, 40 | { 41 | find: /^@leafer\/(.*)/, 42 | replacement: 'src/leafer/packages/$1/src' 43 | }, 44 | { 45 | find: 'leafer-ui', 46 | replacement: 'src/ui/src' 47 | }, 48 | { 49 | find: '@leafer-ui/web', 50 | replacement: 'src/ui/packages/platform/web/src' 51 | }, 52 | { 53 | find: '@leafer-ui/node', 54 | replacement: 'src/ui/packages/platform/node/src' 55 | }, 56 | { 57 | find: '@leafer-ui/platform', 58 | replacement: 'src/ui/packages/platform/platform/src' 59 | }, 60 | { 61 | find: /^@leafer-ui\/(core|draw)/, 62 | replacement: 'src/ui/packages/core/$1/src' 63 | }, 64 | { 65 | find: /^@leafer-ui\/(display\-module|data|bounds|render)/, 66 | replacement: 'src/ui/packages/display-module/$1/src' 67 | }, 68 | { 69 | find: /^@leafer-ui\/interaction(.*)/, 70 | replacement: 'src/ui/packages/interaction/interaction$1/src' 71 | }, 72 | { 73 | find: /^@leafer-ui\/(partner|effect|paint|image|gradient|mask|text|color|export)/, 74 | replacement: 'src/ui/packages/partner/$1/src' 75 | }, 76 | { 77 | find: /^@leafer-ui\/(.*)/, 78 | replacement: 'src/ui/packages/$1/src' 79 | }, 80 | { 81 | find: /^@leafer-in\/(.*)/, 82 | replacement: '/src/in/packages/$1/src' 83 | } 84 | ], 85 | include: ['src/test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'src/ui/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'src/leafer/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'] 86 | } 87 | }) -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from '@rollup/plugin-typescript' 2 | import commonjs from '@rollup/plugin-commonjs' 3 | import { nodeResolve } from '@rollup/plugin-node-resolve' 4 | import terser from "@rollup/plugin-terser" 5 | import dts from "rollup-plugin-dts" 6 | 7 | import html from '@rollup/plugin-html' 8 | import copy from 'rollup-plugin-copy' 9 | import livereload from 'rollup-plugin-livereload' 10 | import serve from 'rollup-plugin-serve' 11 | 12 | const port = 10101 // visit http://localhost:10101 13 | 14 | const isDev = process.env.NODE_ENV === 'development' 15 | const platformName = process.env.PLATFORM 16 | const dtsPackage = process.env.DTS_PACKAGE 17 | 18 | const LeaferUI = 'LeaferUI' 19 | 20 | const external = { 21 | '@leafer/core': LeaferUI, 22 | '@leafer-ui/draw': LeaferUI, 23 | '@leafer-ui/core': LeaferUI, 24 | } 25 | 26 | const pluginExternal = { 27 | ...external, 28 | '@leafer-in/editor': 'LeaferIN.editor', 29 | '@leafer-in/text-editor': 'LeaferIN.textEditor', 30 | '@leafer-in/viewport': 'LeaferIN.viewport', 31 | '@leafer-in/view': 'LeaferIN.view', 32 | '@leafer-in/scroll': 'LeaferIN.scroll', 33 | '@leafer-in/arrow': 'LeaferIN.arrow', 34 | '@leafer-in/html': 'LeaferIN.html', 35 | '@leafer-in/flow': 'LeaferIN.flow', 36 | '@leafer-in/animate': 'LeaferIN.animate', 37 | '@leafer-in/motion-path': 'LeaferIN.motionPath', 38 | '@leafer-in/state': 'LeaferIN.state', 39 | '@leafer-in/robot': 'LeaferIN.robot', 40 | '@leafer-in/find': 'LeaferIN.find', 41 | '@leafer-in/export': 'LeaferIN.export', 42 | '@leafer-in/filter': 'LeaferIN.filter', 43 | '@leafer-in/color': 'LeaferIN.color', 44 | '@leafer-in/resize': 'LeaferIN.resize' 45 | } 46 | 47 | const LeaferUIExternal = { 48 | ...external, 49 | 'leafer-ui': LeaferUI, 50 | '@leafer-ui/worker': LeaferUI, 51 | '@leafer-ui/node': LeaferUI, 52 | '@leafer-ui/miniapp': LeaferUI, 53 | } 54 | 55 | const LeaferEditorExternal = { 56 | ...LeaferUIExternal, 57 | ...pluginExternal 58 | } 59 | 60 | const LeaferGameExternal = { 61 | ...LeaferUIExternal, 62 | ...pluginExternal 63 | } 64 | const inPath = 'src/in/packages' 65 | const platformPath = 'src/ui/packages/platform' 66 | const drawPlatformPath = 'src/draw/packages/platform' 67 | const editorPlatformPath = 'src/editor/packages/platform' 68 | const gamePlatformPath = 'src/game/packages/platform' 69 | 70 | const platform ={ 71 | 'core': [ 72 | { 73 | dist: 'lib', 74 | path: 'src/leafer/packages/core', 75 | withMin: 'min', 76 | withFormat: ['cjs'] 77 | }, 78 | { 79 | name: 'draw', 80 | dist: 'lib', 81 | path: 'src/ui/packages/core/draw', 82 | withMin: 'min', 83 | withFormat: ['cjs'], 84 | external: { '@leafer/core': LeaferUI} 85 | }, 86 | { 87 | dist: 'lib', 88 | path: 'src/ui/packages/core/core', 89 | withMin: 'min', 90 | withFormat: ['cjs'], 91 | external: { '@leafer-ui/draw': LeaferUI, '@leafer/core': LeaferUI } 92 | } 93 | ], 94 | 95 | 'draw': [ 96 | { 97 | name: 'web', 98 | path: 'src/draw', 99 | withGlobal: LeaferUI, 100 | withMin: 'min', 101 | fullGlobal: true, 102 | withModule: true, 103 | external 104 | }, 105 | { 106 | name: 'worker', 107 | path: drawPlatformPath + '/worker', 108 | withGlobal: LeaferUI, 109 | withMin: 'min', 110 | fullGlobal: true, 111 | withModule: true, 112 | external 113 | }, 114 | { 115 | name: 'node', 116 | path: drawPlatformPath + '/node', 117 | withMin: 'min', 118 | withFormat: ['cjs'], 119 | external: {...external, 'fs': 'fs'} 120 | }, 121 | { 122 | name: 'miniapp', 123 | path: drawPlatformPath + '/miniapp', 124 | withMin: 'min', 125 | withModule: true, 126 | external 127 | } 128 | ], 129 | 130 | 'editor': [ 131 | { 132 | name: 'web', 133 | path: 'src/editor', 134 | withGlobal: LeaferUI, 135 | withMin: 'min', 136 | external, 137 | fullGlobal: true, 138 | withModule: true 139 | }, 140 | { 141 | name: 'worker', 142 | path: editorPlatformPath + '/worker', 143 | withGlobal: LeaferUI, 144 | withMin: 'min', 145 | external, 146 | fullGlobal: true, 147 | withModule: true 148 | }, 149 | { 150 | name: 'node', 151 | path: editorPlatformPath + '/node', 152 | withMin: 'min', 153 | withFormat: ['cjs'], 154 | external: {...external, 'fs': 'fs'} 155 | }, 156 | { 157 | name: 'miniapp', 158 | path: editorPlatformPath + '/miniapp', 159 | withMin: 'min', 160 | external, 161 | withModule: true 162 | } 163 | ], 164 | 165 | 'editor': [ 166 | { 167 | name: 'web', 168 | path: 'src/editor', 169 | withGlobal: LeaferUI, 170 | withMin: 'min', 171 | fullGlobal: true, 172 | withModule: true, 173 | external: LeaferEditorExternal 174 | }, 175 | { 176 | name: 'worker', 177 | path: editorPlatformPath + '/worker', 178 | withGlobal: LeaferUI, 179 | withMin: 'min', 180 | fullGlobal: true, 181 | withModule: true, 182 | external: LeaferEditorExternal 183 | }, 184 | { 185 | name: 'node', 186 | path: editorPlatformPath + '/node', 187 | withMin: 'min', 188 | withFormat: ['cjs'], 189 | external: {...LeaferEditorExternal, 'fs': 'fs'} 190 | }, 191 | { 192 | name: 'miniapp', 193 | path: editorPlatformPath + '/miniapp', 194 | withMin: 'min', 195 | withModule: true, 196 | external: LeaferEditorExternal, 197 | } 198 | ], 199 | 200 | 'game': [ 201 | { 202 | name: 'web', 203 | path: 'src/game', 204 | withGlobal: LeaferUI, 205 | withMin: 'min', 206 | withFormat: ['cjs'], 207 | fullGlobal: true, 208 | withModule: true, 209 | external: LeaferGameExternal 210 | }, 211 | { 212 | name: 'worker', 213 | path: gamePlatformPath + '/worker', 214 | withGlobal: LeaferUI, 215 | withMin: 'min', 216 | withFormat: ['cjs'], 217 | fullGlobal: true, 218 | withModule: true, 219 | external: LeaferGameExternal 220 | }, 221 | { 222 | name: 'node', 223 | path: gamePlatformPath + '/node', 224 | withMin: 'min', 225 | withFormat: ['cjs'], 226 | external: {...LeaferGameExternal, 'fs': 'fs'} 227 | }, 228 | { 229 | name: 'miniapp', 230 | path: gamePlatformPath + '/miniapp', 231 | withMin: 'min', 232 | withFormat: ['cjs'], 233 | withModule: true, 234 | external: LeaferGameExternal, 235 | } 236 | ], 237 | 238 | 'web': { 239 | path: 'src/ui', 240 | withGlobal: LeaferUI, 241 | withMin: 'min', 242 | fullGlobal: true, 243 | withModule: true, 244 | external 245 | }, 246 | 'worker': { 247 | path: platformPath + '/worker', 248 | withGlobal: LeaferUI, 249 | withMin: 'min', 250 | fullGlobal: true, 251 | withModule: true, 252 | external 253 | }, 254 | 'node': { 255 | path: platformPath + '/node', 256 | withMin: 'min', 257 | withFormat: ['cjs'], 258 | external: {...external, 'fs': 'fs'} 259 | }, 260 | 'miniapp': { 261 | path: platformPath + '/miniapp', 262 | withMin: 'min', 263 | withModule: true, 264 | external 265 | }, 266 | 267 | 268 | 'in': [ 269 | { 270 | name: 'editor', 271 | path: inPath + '/editor', 272 | withGlobal: 'LeaferIN.editor', 273 | withMin: 'min', 274 | withFormat: ['cjs'], 275 | external: pluginExternal 276 | }, 277 | { 278 | name: 'resize', 279 | path: inPath + '/resize', 280 | withGlobal: 'LeaferIN.resize', 281 | withMin: 'min', 282 | withFormat: ['cjs'], 283 | external: pluginExternal 284 | }, 285 | { 286 | name: 'html', 287 | path: inPath + '/html', 288 | withGlobal: 'LeaferIN.html', 289 | withMin: 'min', 290 | withFormat: ['cjs'], 291 | external: pluginExternal 292 | }, 293 | { 294 | name: 'arrow', 295 | path: inPath + '/arrow', 296 | withGlobal: 'LeaferIN.arrow', 297 | withMin: 'min', 298 | withFormat: ['cjs'], 299 | external: pluginExternal 300 | }, 301 | { 302 | name: 'view', 303 | path: inPath + '/view', 304 | withGlobal: 'LeaferIN.view', 305 | withMin: 'min', 306 | withFormat: ['cjs'], 307 | external: pluginExternal 308 | }, 309 | { 310 | name: 'scroll', 311 | path: inPath + '/scroll', 312 | withGlobal: 'LeaferIN.scroll', 313 | withMin: 'min', 314 | withFormat: ['cjs'], 315 | external: pluginExternal 316 | }, 317 | { 318 | name: 'state', 319 | path: inPath + '/state', 320 | withGlobal: 'LeaferIN.state', 321 | withMin: 'min', 322 | withFormat: ['cjs'], 323 | external: pluginExternal 324 | }, 325 | { 326 | name: 'flow', 327 | path: inPath+ '/flow', 328 | withGlobal: 'LeaferIN.flow', 329 | withMin: 'min', 330 | withFormat: ['cjs'], 331 | external: pluginExternal 332 | }, 333 | { 334 | name: 'text-editor', 335 | path: inPath + '/text-editor', 336 | withGlobal: 'LeaferIN.textEditor', 337 | withMin: 'min', 338 | withFormat: ['cjs'], 339 | external: pluginExternal 340 | }, 341 | { 342 | name: 'animate', 343 | path: inPath+ '/animate', 344 | withGlobal: 'LeaferIN.animate', 345 | withMin: 'min', 346 | withFormat: ['cjs'], 347 | external: pluginExternal 348 | }, 349 | { 350 | name: 'robot', 351 | path: inPath+ '/robot', 352 | withGlobal: 'LeaferIN.robot', 353 | withMin: 'min', 354 | withFormat: ['cjs'], 355 | external: pluginExternal 356 | }, 357 | { 358 | name: 'color', 359 | path: inPath+ '/color', 360 | withGlobal: 'LeaferIN.color', 361 | withMin: 'min', 362 | withFormat: ['cjs'], 363 | external: pluginExternal 364 | }, 365 | { 366 | name: 'motion-path', 367 | path: inPath+ '/motion-path', 368 | withGlobal: 'LeaferIN.motionPath', 369 | withMin: 'min', 370 | withFormat: ['cjs'], 371 | external: pluginExternal 372 | }, 373 | { 374 | name: 'viewport', 375 | path: inPath+ '/viewport', 376 | withGlobal: 'LeaferIN.viewport', 377 | withMin: 'min', 378 | withFormat: ['cjs'], 379 | external: pluginExternal 380 | }, 381 | { 382 | name: 'filter', 383 | path: inPath+ '/filter', 384 | withGlobal: 'LeaferIN.filter', 385 | withMin: 'min', 386 | withFormat: ['cjs'], 387 | external: pluginExternal 388 | } 389 | ], 390 | } 391 | 392 | const plugins = [ 393 | nodeResolve({ 394 | browser: true, 395 | preferBuiltins: false, 396 | }), 397 | typescript({ 398 | tsconfig: './tsconfig.json' 399 | }), 400 | commonjs() 401 | ] 402 | 403 | 404 | let config 405 | 406 | 407 | if(isDev) { 408 | 409 | config = { 410 | input: 'index.ts', 411 | output: { 412 | sourcemap: true, 413 | file: 'dist/bundle.js', 414 | format: 'esm' 415 | }, 416 | watch: { exclude: ['node_modules/**'] }, 417 | plugins: [ 418 | ...plugins, 419 | html({ 420 | title: "LeaferJS", 421 | meta: [{charset: 'utf-8'}, {name: 'viewport', content: 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'}] 422 | }), 423 | copy({ targets: [{ src: 'public/*', dest: 'dist/' }]}), 424 | livereload(), 425 | serve({contentBase: ['dist/'], port}) 426 | ] 427 | } 428 | 429 | } else if(dtsPackage) { 430 | 431 | config = { 432 | input: dtsPackage + '/src/index.ts', 433 | output: { 434 | file: dtsPackage + '/types/index.d.ts' 435 | }, 436 | plugins: [ dts() ] 437 | } 438 | 439 | } else { 440 | 441 | config = [] 442 | 443 | let p = platform[platformName] 444 | if(!(p instanceof Array)) p = [p] 445 | 446 | const list = [] 447 | 448 | p.forEach(c =>{ 449 | 450 | if(c.input && c.output) { 451 | 452 | list.push(c) 453 | 454 | } else { 455 | 456 | const input = c.input || c.path + '/src/index.ts' 457 | const fileBase = c.path + '/dist/' + (c.name || platformName) 458 | 459 | const global = c.withGlobal 460 | const min = c.withMin 461 | let external = c.external 462 | 463 | list.push({external, input, output: fileBase + '.esm.js'}) 464 | if(c.withMin) list.push({ min, external, input, output: fileBase + '.esm.' + min + '.js'}) 465 | 466 | if(c.withFormat) { 467 | c.withFormat.forEach(format =>{ 468 | const cjs = format === 'cjs' 469 | list.push({external, input, output: fileBase + (cjs ? '.cjs' : '.' + format + '.js'), format}) 470 | if(c.withMin) list.push({ min, external, input, output: fileBase + (cjs ? '.' + min + '.cjs' :'.' + format + '.' + min + '.js'), format}) 471 | }) 472 | } 473 | 474 | if(global) { 475 | if(c.fullGlobal) external = null 476 | list.push({global, external, input, output: fileBase + '.js'}) 477 | if(c.withMin) list.push({ global, min, external, input, output: fileBase + '.' + min + '.js'}) 478 | } 479 | 480 | } 481 | }) 482 | 483 | list.forEach(c => { 484 | const item = { 485 | external: c.external ? Object.keys(c.external) : null, 486 | input: c.input, 487 | plugins: [...plugins] 488 | } 489 | 490 | if(c.global) { 491 | 492 | item.output = { 493 | file: c.output, 494 | name: c.global, 495 | format: c.format || 'iife', 496 | } 497 | 498 | if(c.external) item.output.globals = c.external 499 | 500 | } else { 501 | 502 | item.output = { 503 | file: c.output, 504 | format: c.format || 'esm' 505 | } 506 | 507 | } 508 | 509 | if(c.min) item.plugins.push(terser({ format: { comments: false} })) 510 | 511 | config.push(item) 512 | 513 | }) 514 | 515 | } 516 | 517 | export default config --------------------------------------------------------------------------------