├── .changeset └── config.json ├── .eslintrc ├── .github └── workflows │ └── release.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierrc ├── LICENSE ├── README.md ├── package.json ├── packages ├── create-kiss │ └── .vscode │ │ └── tasks.json ├── kiss-config │ ├── .eslintrc.js │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── esbuild.ts │ │ ├── index.ts │ │ ├── rollup.ts │ │ ├── types.ts │ │ ├── util │ │ │ ├── abstractHandler.ts │ │ │ ├── clientParse.ts │ │ │ ├── configParser.ts │ │ │ └── logger.ts │ │ ├── vite.ts │ │ └── webpack.ts │ └── tsconfig.json ├── kiss-core │ ├── .eslintignore │ ├── .eslintrc.js │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── public │ │ └── icon.svg │ ├── script │ │ ├── clearType.ts │ │ ├── common.ts │ │ └── patchType.ts │ ├── src │ │ ├── index.ts │ │ ├── kiss.ts │ │ └── utils │ │ │ └── detect_platform.ts │ ├── test │ │ └── index.spec.ts │ ├── tsconfig.json │ ├── tsup.config.ts │ └── types │ │ ├── client │ │ ├── figma.d.ts │ │ ├── jsDesign.d.ts │ │ └── masterGo.d.ts │ │ └── index.ts └── kiss-msg │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .github │ └── workflows │ │ ├── ci.yml │ │ └── release.yml │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── pnpm-lock.yaml │ ├── src │ ├── cache.ts │ ├── index.ts │ └── utils.ts │ ├── test │ └── index.test.ts │ ├── tsconfig.json │ └── tsup.config.ts ├── playground └── rectangle-creator │ ├── .editorconfig │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── index.html │ ├── package.json │ ├── scripts │ ├── appScript │ │ ├── figma.applescript.sh │ │ ├── jsDesign.applescript.sh │ │ └── masterGo.applescript.sh │ ├── clearPlugin.ts │ ├── clientParse.ts │ ├── manifest.ts │ ├── prepare.ts │ ├── restartPlugin.ts │ ├── util │ │ ├── abstractHandler.ts │ │ └── configParser.ts │ └── utils.ts │ ├── src │ ├── App.tsx │ ├── code.ts │ └── main.tsx │ ├── tsconfig.json │ ├── types │ └── manifest.d.ts │ ├── vite.config.code.ts │ └── vite.config.ts ├── pnpm-lock.yaml ├── pnpm-workspace.yaml └── renovate.json5 /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json", 3 | "changelog": ["@changesets/changelog-github", { "repo": "leizhenpeng/design-toolkit-cn" }], 4 | "commit": true, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "public", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { 11 | "onlyUpdatePeerDependentsWhenOutOfRange": true 12 | }, 13 | "ignore": ["rectangle-creator"] 14 | } 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@antfu", 3 | "root": true, 4 | "ignorePatterns": [ 5 | "dist", 6 | "node_modules", 7 | "public", 8 | "tests", 9 | "vendor", 10 | "webpack.mix.js", 11 | "yarn.lock", 12 | "playground" 13 | ], 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | release: 10 | # prevents this action from running on forks 11 | if: github.repository == 'leizhenpeng/design-toolkit-cn' 12 | name: Release 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | matrix: 16 | # pseudo-matrix for convenience, NEVER use more than a single combination 17 | node: [14] 18 | os: [ubuntu-latest] 19 | steps: 20 | - name: checkout 21 | uses: actions/checkout@v3 22 | with: 23 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 24 | fetch-depth: 0 25 | - uses: pnpm/action-setup@v2 26 | - uses: actions/setup-node@v3 27 | with: 28 | node-version: ${{ matrix.node }} 29 | cache: 'pnpm' 30 | cache-dependency-path: '**/pnpm-lock.yaml' 31 | - name: install 32 | run: | 33 | pnpm install --frozen-lockfile --prefer-offline --ignore-scripts 34 | - name: Creating .npmrc 35 | run: | 36 | cat << EOF > "$HOME/.npmrc" 37 | //registry.npmjs.org/:_authToken=$NPM_TOKEN 38 | EOF 39 | env: 40 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 41 | - name: Create Release Pull Request or Publish to npm 42 | id: changesets 43 | uses: changesets/action@v1 44 | with: 45 | # This expects you to have a script called release which does a build for your packages and calls changeset publish 46 | publish: pnpm release 47 | env: 48 | GITHUB_TOKEN: ${{ secrets.NOW_GITHUB_TOKEN }} 49 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | 4 | .DS_Store 5 | 6 | .idea 7 | .fleet 8 | /.vscode/ 9 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | # pnpm test 5 | pnpm lint-staged --concurrent false 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false, 4 | "tabWidth": 4, 5 | "printWidth": 150, 6 | "bracketSpacing": true, 7 | "useTabs": false, 8 | "wrapAttributes": false, 9 | "trailingComma": "none", 10 | "arrowParens": "always" 11 | } 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present, Zhenpeng (River) Lei and Kiss contributors 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Design Toolkit For Cn 3 | > 一套专注效率的设计插件开发环境 4 | > 5 | > 🍺 Unified plugin system for figma, mastergo, jsDesign ,and pixso 6 | 7 |
8 | 9 | ## kiss 和他的朋友们 10 | 11 | - [kiss](packages/kiss-core) 🍶 同时支持masterGo、jsDesign、pixso以及Figma插件开发适配器 12 | - [create-kiss]() 🚀 创建Kiss项目的推荐方式 13 | - [kiss-msg](packages/kiss-msg) 🍭 帮助设计插件中的CODE与UI实现更优雅通信 Power By Kiss ~ 14 | - [kiss-pay]() 🎁 便捷开发者维护自己的商业订阅生态 15 | - [kiss-eye]() 🎯 插件运营数据埋点工具 16 | - [unplugin-kiss-config](packages/kiss-config) - 🍙 自动生成多个平台配置文件的打包插件 17 | 18 |
19 | 20 | ## Packages 21 | 22 | | Package | Version | 23 | | ----------------------------------------------- |:---------------------------------------------------------------------------------------------------------| 24 | | [kiss](packages/kiss-core) | NPM version| 25 | | [kiss-msg](packages/kiss-msg) |NPM version | 26 | | [unplugin-kiss-config](packages/kiss-config) |NPM version | 27 | 28 | 29 | ## [Awesome Kiss](https://github.com/Leizhenpeng/awesome-kiss) 30 | 31 | 32 | - [画矩形 (Rectangle Creator)](https://github.com/Leizhenpeng/awesome-kiss/tree/master/projects/rectangle-creator) - 🥱 应该没有比它更简单的上手项目了吧 33 | - [字高 (Text Lineheight)](https://github.com/Leizhenpeng/awesome-kiss/tree/master/projects/text-lineheight) - 🧘🏻‍♂️ 修改选区内文本层行高 34 | - [图标可大可小 (Icon Resize)](https://github.com/Leizhenpeng/awesome-kiss/tree/master/projects/icon-resize) - 🤾‍♂️ 规范图标尺寸 35 | 36 | ## License 37 | [MIT](./LICENSE) © [River](https://github.com/Leizhenpeng) 38 | 39 | 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "design-tooltik-cn", 3 | "version": "1.0.0", 4 | "description": "基于国人使用体验的设计软件开发工具包", 5 | "main": "index.js", 6 | "type": "module", 7 | "engines": { 8 | "pnpm": "^7.8.0", 9 | "yarn": "forbidden, use pnpm", 10 | "npm": "forbidden, use pnpm", 11 | "node": ">=16" 12 | }, 13 | "publishConfig": { 14 | "access": "public" 15 | }, 16 | "packageManager": "pnpm@7.16.1", 17 | "scripts": { 18 | "build": "pnpm --filter kiss-core --filter kiss-msg --filter unplugin-kiss-config run build ", 19 | "in:mode:beta": "pnpm changeset pre enter beta", 20 | "out:mode:beta": "pnpm changeset pre exit beta", 21 | "changeset": "changeset", 22 | "bump": "changeset version", 23 | "release": "pnpm build && pnpm release:only", 24 | "release:only": "changeset publish --registry=https://registry.npmjs.com/", 25 | "test": "pnpm -r --workspace-concurrency=1 test", 26 | "lint": "eslint --ignore-path .gitignore '**/*.{js,ts,html,md}'", 27 | "lint:fix": "pnpm run lint --fix", 28 | "prepare": "husky install" 29 | }, 30 | "keywords": [ 31 | "figma", 32 | "mastergo", 33 | "jsdesign", 34 | "tooltik" 35 | ], 36 | "author": "RiverRay", 37 | "license": "MIT", 38 | "devDependencies": { 39 | "@antfu/eslint-config": "^0.36.0", 40 | "@changesets/changelog-github": "^0.4.8", 41 | "@changesets/cli": "^2.26.1", 42 | "@mastergo/plugin-typings": "^1.16.2", 43 | "@types/fs-extra": "^9.0.13", 44 | "@types/lodash-es": "^4.17.7", 45 | "@types/node": "^18.15.11", 46 | "eslint": "^8.37.0", 47 | "husky": "^8.0.3", 48 | "lint-staged": "^13.2.0", 49 | "terser": "^5.16.8", 50 | "typescript": "^4.9.5", 51 | "vite": "^3.2.5", 52 | "vite-node": "^0.26.3", 53 | "vitest": "^0.26.3" 54 | }, 55 | "husky": { 56 | "hooks": { 57 | "pre-commit": "lint-staged" 58 | } 59 | }, 60 | "lint-staged": { 61 | "*.{js,ts,html,md}": "eslint --fix" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/create-kiss/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "test", 7 | "group": "test", 8 | "problemMatcher": [], 9 | "label": "npm: test", 10 | "detail": "vitest run" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/kiss-config/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('eslint-define-config').EslintConfig} 3 | */ 4 | module.exports = { 5 | ignorePatterns: ['README.md', 'src', '.eslintrc.js'], 6 | extends: '@antfu', 7 | plugins: ['@typescript-eslint'], 8 | root: true, 9 | rules: { 10 | // ts will check these rule 11 | 'no-undef': 'off', 12 | 'no-unused-vars': 'off', 13 | 14 | // replace 'no-redeclare' with @typescript-eslint 15 | 'no-redeclare': 'off', 16 | 'space-before-blocks': 'off', 17 | '@typescript-eslint/space-before-blocks': 'warn', 18 | '@typescript-eslint/no-redeclare': ['error'], 19 | // note you must disable the base rule as it can report incorrect errors 20 | 'no-use-before-define': 'off', 21 | '@typescript-eslint/no-use-before-define': ['error'], 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /packages/kiss-config/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # unplugin-kiss-config 2 | 3 | ## 0.1.1 4 | 5 | ### Patch Changes 6 | 7 | - [`6767b8e`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/6767b8e75f4f3bb1d3ac7d7845b71052a3a4c558) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - add github url 8 | 9 | ## 0.1.0 10 | 11 | ### Minor Changes 12 | 13 | - [#21](https://github.com/Leizhenpeng/design-toolkit-cn/pull/21) [`3dae7bd`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/3dae7bd2b54b7592a2cf47975ded9133dcd12ffd) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - finish base config generate 14 | -------------------------------------------------------------------------------- /packages/kiss-config/README.md: -------------------------------------------------------------------------------- 1 | 2 | # unplugin-kiss-config 3 | > 🍙 自动生成figma,masterGo,jsDesign多个平台manifest.json的打包插件 4 | 5 | 6 | 7 | ## Add config in package.json 8 | ```json 9 | ... 10 | "pluginInfo": { 11 | "name": "Rectangle Creator", 12 | "api": "1.0.0", 13 | "id": { 14 | "masterGo": "80090183159920", 15 | "figma": "1183407018802193143", 16 | "jsDesign": "_Cm929J-cu10cmqrzbnIS" 17 | }, 18 | "editorType": { 19 | "masterGo": [ 20 | "masterGo" 21 | ], 22 | "figma": [ 23 | "figma", 24 | "figjam" 25 | ], 26 | "jsDesign": [ 27 | "jsDesign" 28 | ] 29 | } 30 | }, 31 | ... 32 | ``` 33 | 34 | ## Install 35 | 36 | ```sh 37 | npm i unplugin-kiss-config 38 | ``` 39 | 40 | ## Option 41 | ``` 42 | { 43 | outDir:'string' //自动生成配置文件的目录名称,默认为'plugin' 44 | client:'figma' | 'masterGo' | 'jsDesign' //平台名称,建议通过环境变量来设置 process.env.CLIENT_ENV || 'figma' 45 | } 46 | ``` 47 | 48 | 49 |
50 | esbuild
51 | 52 | ```js 53 | // esbuild.config.js 54 | import { build } from 'esbuild' 55 | import { KissConfigPlugin } from 'unplugin-kiss-config/esbuild' 56 | 57 | build({ 58 | plugins: [ 59 | KissConfigPlugin(/* options */) 60 | ], 61 | }) 62 | ``` 63 | 64 |
65 | 66 |
67 | Rollup
68 | 69 | ```js 70 | // rollup.config.js 71 | import { KissConfigPlugin } from 'unplugin-kiss-config/rollup' 72 | 73 | export default { 74 | plugins: [ 75 | KissConfigPlugin(/* options */) 76 | ], 77 | } 78 | ``` 79 | 80 |
81 | 82 |
83 | Vite
84 | 85 | ```js 86 | // vite.config.ts 87 | import { KissConfigPlugin } from 'unplugin-kiss-config/vite' 88 | 89 | export default defineConfig({ 90 | plugins: [ 91 | KissConfigPlugin(/* options */) 92 | ], 93 | }) 94 | ``` 95 | 96 |
97 | 98 |
99 | Webpack
100 | 101 | ```js 102 | // webpack.config.js 103 | const { KissConfigPlugin } = require('unplugin-kiss-config/webpack') 104 | 105 | module.exports = { 106 | plugins: [ 107 | KissConfigPlugin(/* options */), 108 | ], 109 | } 110 | ``` 111 | 112 |
113 | -------------------------------------------------------------------------------- /packages/kiss-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unplugin-kiss-config", 3 | "description": "🍙 自动生成figma,masterGo,jsDesign多个平台manifest.json的打包插件", 4 | "version": "0.1.1", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/Leizhenpeng/design-tooltik-cn.git", 8 | "directory": "packages/kiss-config" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/Leizhenpeng/design-tooltik-cn/issues" 12 | }, 13 | "homepage": "https://github.com/Leizhenpeng/design-tooltik-cn/tree/main/packages/kiss-core#readme", 14 | "keywords": [ 15 | "unplugin", 16 | "esbuild", 17 | "rollup", 18 | "vite", 19 | "webpack" 20 | ], 21 | "exports": { 22 | ".": { 23 | "require": "./dist/index.js", 24 | "import": "./dist/index.mjs" 25 | }, 26 | "./types": { 27 | "require": "./dist/types.js", 28 | "import": "./dist/types.mjs" 29 | }, 30 | "./*": "./*", 31 | "./esbuild": { 32 | "require": "./dist/esbuild.js", 33 | "import": "./dist/esbuild.mjs" 34 | }, 35 | "./rollup": { 36 | "require": "./dist/rollup.js", 37 | "import": "./dist/rollup.mjs" 38 | }, 39 | "./vite": { 40 | "require": "./dist/vite.js", 41 | "import": "./dist/vite.mjs" 42 | }, 43 | "./webpack": { 44 | "require": "./dist/webpack.js", 45 | "import": "./dist/webpack.mjs" 46 | } 47 | }, 48 | "main": "dist/index.js", 49 | "module": "dist/index.mjs", 50 | "types": "index.d.ts", 51 | "typesVersions": { 52 | "*": { 53 | "*": [ 54 | "./dist/*", 55 | "./*" 56 | ] 57 | } 58 | }, 59 | "files": [ 60 | "dist" 61 | ], 62 | "scripts": { 63 | "build": "tsup", 64 | "dev": "tsup --watch src" 65 | }, 66 | "tsup": { 67 | "entryPoints": [ 68 | "src/*.ts" 69 | ], 70 | "clean": true, 71 | "format": [ 72 | "cjs", 73 | "esm" 74 | ], 75 | "dts": true 76 | }, 77 | "dependencies": { 78 | "fs-extra": "^11.1.1", 79 | "kolorist": "^1.7.0", 80 | "unplugin": "^1.3.1", 81 | "vue": "^3.2.47" 82 | }, 83 | "devDependencies": { 84 | "tsup": "^6.7.0", 85 | "typescript": "^4.9.5" 86 | } 87 | } -------------------------------------------------------------------------------- /packages/kiss-config/src/esbuild.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export const KissConfigPlugin = unplugin.esbuild 4 | -------------------------------------------------------------------------------- /packages/kiss-config/src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import { createUnplugin } from 'unplugin' 3 | import fs, { access, mkdir } from 'fs-extra' 4 | import type PkgType from '../package.json' 5 | import type { Options } from './types' 6 | 7 | import { log, r } from './util/logger' 8 | import { setClient } from './util/clientParse' 9 | import { apiHandler, customHandler, editorTypeHandler, idHandler, nameHandler } from './util/configParser' 10 | 11 | export async function genManifest() { 12 | const pkg = (await fs.readJSON(r('package.json'))) as typeof PkgType 13 | const customManifest = customHandler.handle(pkg) 14 | const manifest = { 15 | name: nameHandler.handle(pkg), 16 | id: idHandler.handle(pkg), 17 | api: apiHandler.handle(pkg), 18 | main: 'code/index.js', 19 | ui: 'ui/index.html', 20 | editorType: editorTypeHandler.handle(pkg) as any, 21 | ...customManifest, 22 | } 23 | return manifest 24 | } 25 | 26 | export async function writeManifest(outDir: string, clientName = 'figma') { 27 | const clientPath = r(`${outDir}/${clientName}`) 28 | const manifestPath = r(`${outDir}/${clientName}/manifest.json`) 29 | 30 | await access(r(outDir)).catch(() => mkdir(r(outDir))) 31 | await access(clientPath).catch(() => mkdir(clientPath)) 32 | console.log('manifestPath', manifestPath) 33 | await fs.writeJSON(manifestPath, await genManifest(), { spaces: 2 }) 34 | log('manifest', 'update manifest.json') 35 | } 36 | 37 | export default createUnplugin(options => ({ 38 | name: 'unplugin-kiss-config', 39 | buildStart(): void { 40 | const outDir = options.outDir || 'plugin' 41 | const clientName = options.client || 'figma' 42 | setClient(clientName) 43 | writeManifest(outDir, clientName) 44 | }, 45 | })) 46 | -------------------------------------------------------------------------------- /packages/kiss-config/src/rollup.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export const KissConfigPlugin = unplugin.rollup 4 | -------------------------------------------------------------------------------- /packages/kiss-config/src/types.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Options { 3 | outDir?: string 4 | client?: clientType 5 | } 6 | 7 | export type clientType = 'figma' | 'masterGo' | 'jsDesign' 8 | -------------------------------------------------------------------------------- /packages/kiss-config/src/util/abstractHandler.ts: -------------------------------------------------------------------------------- 1 | interface Handler { 2 | setNext(handler: Handler): Handler 3 | handle(request: string): string 4 | } 5 | 6 | export abstract class AbstractHandler implements Handler { 7 | private nextHandler: Handler 8 | 9 | public setNext(handler: Handler): Handler { 10 | this.nextHandler = handler 11 | return handler 12 | } 13 | 14 | public handle(request: string): any { 15 | if (this.nextHandler) 16 | return this.nextHandler.handle(request) 17 | 18 | return '' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/kiss-config/src/util/clientParse.ts: -------------------------------------------------------------------------------- 1 | import { ref } from 'vue' 2 | import { log, warn } from './logger' 3 | 4 | class ClientParser { 5 | client: string 6 | static instance: ClientParser 7 | availableClients = ['figma', 'masterGo', 'jsDesign'] 8 | 9 | private constructor(client: string) { 10 | this.client = client || 'figma' 11 | } 12 | 13 | static initInstance(client: string) { 14 | this.instance = new ClientParser(client) 15 | } 16 | 17 | static getInstance() { 18 | return this.instance 19 | } 20 | 21 | get defaultClient() { 22 | return this.availableClients[0] 23 | } 24 | 25 | get formatClient() { 26 | const client = this.client 27 | const clientName = client.toLowerCase() 28 | const formatName = this.availableClients.find((item) => { 29 | return item.toLowerCase() === clientName 30 | }) 31 | 32 | if (!formatName) { 33 | warn('client', `client ${client} is not available, use ${this.defaultClient} instead`) 34 | return this.defaultClient 35 | } 36 | 37 | log('client', `use ${formatName} client`) 38 | return formatName 39 | } 40 | } 41 | 42 | export default ClientParser 43 | 44 | export const clientParse = ref('figma') 45 | 46 | export const setClient = (client: string) => { 47 | ClientParser.initInstance(client) 48 | clientParse.value = ClientParser.getInstance().formatClient 49 | } 50 | -------------------------------------------------------------------------------- /packages/kiss-config/src/util/configParser.ts: -------------------------------------------------------------------------------- 1 | import { clientParse } from './clientParse' 2 | import { AbstractHandler } from './abstractHandler' 3 | 4 | const clientNow = clientParse.value 5 | 6 | class NameHandlerMeta extends AbstractHandler { 7 | public handle(pkg: any): string { 8 | if (pkg && pkg.pluginInfo && pkg.pluginInfo.name) { 9 | const namePool = pkg.pluginInfo.name 10 | const name = namePool[clientNow] 11 | if (name) 12 | return name 13 | } 14 | return super.handle(pkg) 15 | } 16 | } 17 | 18 | export class NameHandlerDefault extends AbstractHandler { 19 | public handle(pkg: any): string { 20 | return pkg.name 21 | } 22 | } 23 | 24 | export const nameHandler = new NameHandlerMeta() 25 | nameHandler.setNext(new NameHandlerDefault()) 26 | 27 | class ApiHandlerMeta extends AbstractHandler { 28 | public handle(pkg: any): string { 29 | if (pkg && pkg.pluginInfo && pkg.pluginInfo.api) 30 | return pkg.pluginInfo.api 31 | 32 | return super.handle(pkg) 33 | } 34 | } 35 | 36 | class ApiHandlerDefault extends AbstractHandler { 37 | public handle(pkg: any): string { 38 | return pkg.version 39 | } 40 | } 41 | 42 | 43 | 44 | 45 | export const apiHandler = new ApiHandlerMeta() 46 | apiHandler.setNext(new ApiHandlerDefault()) 47 | 48 | class IdHandlerMeta extends AbstractHandler { 49 | public handle(pkg: any): string { 50 | if (pkg && pkg.pluginInfo && pkg.pluginInfo.id) { 51 | const idPool = pkg.pluginInfo.id 52 | const id = idPool[clientNow] 53 | if (id) 54 | return id 55 | } 56 | return super.handle(pkg) 57 | } 58 | } 59 | 60 | class IdHandlerDefault extends AbstractHandler { 61 | public handle(): string { 62 | return Date.now().toString() 63 | } 64 | } 65 | 66 | export const idHandler = new IdHandlerMeta() 67 | idHandler.setNext(new IdHandlerDefault()) 68 | 69 | class EditorTypeHandlerMeta extends AbstractHandler { 70 | public handle(pkg: any): string[] { 71 | if (pkg && pkg.pluginInfo && pkg.pluginInfo.editorType) { 72 | const editorTypePool = pkg.pluginInfo.editorType 73 | const editorType = editorTypePool[clientNow] 74 | if (editorType) 75 | return editorType 76 | } 77 | return super.handle(pkg) 78 | } 79 | } 80 | 81 | class EditorTypeHandlerDefault extends AbstractHandler { 82 | public handle(): any { 83 | return [clientNow] 84 | } 85 | } 86 | 87 | export const editorTypeHandler = new EditorTypeHandlerMeta() 88 | editorTypeHandler.setNext(new EditorTypeHandlerDefault()) 89 | 90 | class CustomHandleMeta extends AbstractHandler { 91 | public handle(pkg: any): any { 92 | if (pkg && pkg.pluginInfo && pkg.pluginInfo.custom) { 93 | const customPool = pkg.pluginInfo.custom 94 | const custom = customPool[clientNow] 95 | if (custom) 96 | return custom 97 | } 98 | return super.handle(pkg) 99 | } 100 | } 101 | 102 | class CustomHandleDefault extends AbstractHandler { 103 | public handle(): any { 104 | return {} 105 | } 106 | } 107 | 108 | export const customHandler = new CustomHandleMeta() 109 | customHandler.setNext(new CustomHandleDefault()) -------------------------------------------------------------------------------- /packages/kiss-config/src/util/logger.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { resolve } from 'path' 4 | import { bgBlue, bgYellow, black } from 'kolorist' 5 | 6 | export const port = parseInt(process.env.PORT || '') || 3303 7 | export const baseDir = process.cwd() 8 | export const r = (...args: string[]) => resolve(baseDir, '.', ...args) 9 | export const isDev = process.env.NODE_ENV === 'development' 10 | 11 | // new line 12 | console.log('') 13 | export function log(name: string, message: string) { 14 | console.log(black(bgBlue(` ${name} `)), message) 15 | } 16 | 17 | export function warn(name: string, message: string) { 18 | console.log(black(bgYellow(` ${name} `)), message) 19 | } 20 | -------------------------------------------------------------------------------- /packages/kiss-config/src/vite.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export const KissConfigPlugin = unplugin.vite 4 | -------------------------------------------------------------------------------- /packages/kiss-config/src/webpack.ts: -------------------------------------------------------------------------------- 1 | import unplugin from '.' 2 | 3 | export const KissConfigPlugin = unplugin.webpack 4 | -------------------------------------------------------------------------------- /packages/kiss-config/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "esnext", 5 | "lib": [ 6 | "esnext", 7 | "DOM" 8 | ], 9 | "moduleResolution": "node", 10 | "esModuleInterop": true, 11 | "strictPropertyInitialization": false, 12 | "strict": true, 13 | "strictNullChecks": true, 14 | "resolveJsonModule": true 15 | } 16 | } -------------------------------------------------------------------------------- /packages/kiss-core/.eslintignore : -------------------------------------------------------------------------------- 1 | script/**/*. 2 | -------------------------------------------------------------------------------- /packages/kiss-core/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('eslint-define-config').EslintConfig} 3 | */ 4 | module.exports = { 5 | ignorePatterns: ['README.md', 'src', '.eslintrc.js'], 6 | extends: '@antfu', 7 | plugins: ['@typescript-eslint'], 8 | root: true, 9 | rules: { 10 | // ts will check these rule 11 | 'no-undef': 'off', 12 | 'no-unused-vars': 'off', 13 | 14 | // replace 'no-redeclare' with @typescript-eslint 15 | 'no-redeclare': 'off', 16 | 'space-before-blocks': 'off', 17 | '@typescript-eslint/space-before-blocks': 'off', 18 | '@typescript-eslint/no-redeclare': ['error'], 19 | // note you must disable the base rule as it can report incorrect errors 20 | 'no-use-before-define': 'off', 21 | '@typescript-eslint/no-use-before-define': ['error'], 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /packages/kiss-core/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # kiss-core 2 | 3 | ## 0.2.4 4 | 5 | ### Patch Changes 6 | 7 | - [`ce5b0f2`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/ce5b0f215300ca08c3c66cdcf92ed79cd78c24a5) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - update dependence 8 | 9 | ## 0.2.3 10 | 11 | ### Patch Changes 12 | 13 | - [`0fad37c`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/0fad37c49dfc76031126464b1d32a0cd62882eeb) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - update mg type dev 14 | 15 | ## 0.2.2 16 | 17 | ### Patch Changes 18 | 19 | - [`abd71e5`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/abd71e5d39a2685d67f540ada5a86ebc25a6db4a) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - refactor type export 20 | 21 | ## 0.2.1 22 | 23 | ### Patch Changes 24 | 25 | - update mg dev 26 | 27 | ## 0.2.0 28 | 29 | ### Minor Changes 30 | 31 | - [#2](https://github.com/Leizhenpeng/design-toolkit-cn/pull/2) [`d44759e`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/d44759e386cdda424e0154f9deb62dec557d5a21) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - refactor type export 32 | 33 | ### Patch Changes 34 | 35 | - [#2](https://github.com/Leizhenpeng/design-toolkit-cn/pull/2) [`304d14c`](https://github.com/Leizhenpeng/design-toolkit-cn/commit/304d14c8eb09fc94607b51e904624922b155571d) Thanks [@Leizhenpeng](https://github.com/Leizhenpeng)! - add badge 36 | 37 | ## 0.1.2 38 | 39 | ### Patch Changes 40 | 41 | - change readme 42 | 43 | ## 0.1.1 44 | 45 | ### Patch Changes 46 | 47 | - first publish 48 | 49 | ## 0.1.1-beta.0 50 | 51 | ### Patch Changes 52 | 53 | - first publish 54 | -------------------------------------------------------------------------------- /packages/kiss-core/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present, Zhenpeng (River) Lei and Kiss contributors 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/kiss-core/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | 5 |

6 | 7 |

Kiss

8 |

9 | 🍶一套兼容masterGo、jsDesign以及Figma的插件开发环境 10 |

11 | 12 |

13 | Build Status 14 | NPM version 15 | 16 | downloads 17 | 18 |

19 | 20 | ## Feature 21 | 22 | - 🎁 专心业务逻辑,一套代码即可支持masterGo、jsDesign和Figma 23 | - ⛽️ ts类型友好,支持自动补全 24 | - ⭐️ 主动监测代码运行时环境,自由切换所处上下文 25 | - 🍺 根据常用场景二次封装基础命令,加速开发 26 | 27 | 28 | 29 | 30 | ## Api Reference 31 | - [Figma](https://www.figma.com/plugin-docs/api/api-reference) 32 | - [JsDesign](https://js.design/developer-doc/plugin/api/reference/intro) 33 | - [MasterGo](https://developers.mastergo.com/apis/) 34 | 35 | 36 | ## License 37 | [MIT](./LICENSE) © [River](https://github.com/Leizhenpeng) 38 | 39 | -------------------------------------------------------------------------------- /packages/kiss-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kiss-core", 3 | "version": "0.2.4", 4 | "description": "🍶一套兼容masterGo、jsDesign以及Figma的插件开发环境", 5 | "main": "dist/index.js", 6 | "author": "RiverRay", 7 | "license": "MIT", 8 | "module": "dist/index.mjs", 9 | "types": "dist/index.d.ts", 10 | "files": [ 11 | "dist", 12 | "types" 13 | ], 14 | "exports": { 15 | ".": { 16 | "import": "./dist/index.mjs", 17 | "require": "./dist/index.js" 18 | }, 19 | "./types/*": "./types/*", 20 | "./package.json": "./package.json" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/Leizhenpeng/design-tooltik-cn.git", 25 | "directory": "packages/kiss-core" 26 | }, 27 | "bugs": { 28 | "url": "https://github.com/Leizhenpeng/design-tooltik-cn/issues" 29 | }, 30 | "homepage": "https://github.com/Leizhenpeng/design-tooltik-cn/tree/main/packages/kiss-core#readme", 31 | "scripts": { 32 | "dev": "tsup-node --watch src", 33 | "build": "npm run refresh:type && tsup-node --dts", 34 | "test": "vitest", 35 | "lint": "eslint \"**/*.{js,ts}\"", 36 | "lint:fix": "eslint \"**/*.{js,ts}\" --fix", 37 | "test:coverage": "vitest --coverage", 38 | "patch:type": "esno script/patchType.ts", 39 | "clear:type": "rimraf types/client/*.d.ts", 40 | "refresh:type": "npm run clear:type && npm run patch:type", 41 | "release": "bump --commit --push --tag && pnpm publish", 42 | "preinstall": "npx only-allow pnpm" 43 | }, 44 | "keywords": [ 45 | "figma", 46 | "mastergo", 47 | "jsdesign", 48 | "toolkit", 49 | "kiss", 50 | "plugin" 51 | ], 52 | "devDependencies": { 53 | "@figma/plugin-typings": "^1.62.0", 54 | "@jsdesigndeveloper/plugin-typings": "^1.0.10", 55 | "@mastergo/plugin-typings": "^1.16.2", 56 | "@types/node": "^18.15.11", 57 | "@types/rimraf": "^3.0.2", 58 | "esno": "0.16.3", 59 | "figmaio": "^0.2.10", 60 | "fs-extra": "^10.1.0", 61 | "kolorist": "^1.7.0", 62 | "rimraf": "^3.0.2", 63 | "ts-node": "^10.9.1", 64 | "tsup": "^6.7.0", 65 | "typescript": "^4.9.5" 66 | }, 67 | "publishConfig": { 68 | "access": "public", 69 | "registry": "https://registry.npmjs.org/" 70 | } 71 | } -------------------------------------------------------------------------------- /packages/kiss-core/public/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /packages/kiss-core/script/clearType.ts: -------------------------------------------------------------------------------- 1 | import rimraf from 'rimraf' 2 | import { r } from './common' 3 | 4 | const clearClientTypesDir = async () => { 5 | // delete all files in src/types/client 6 | const path = r('types', 'client/**') 7 | rimraf.sync(path) 8 | } 9 | 10 | clearClientTypesDir() 11 | -------------------------------------------------------------------------------- /packages/kiss-core/script/common.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import { resolve } from 'node:path' 3 | import { bgBlue, bgYellow, black } from 'kolorist' 4 | export const port = parseInt(process.env.PORT || '') || 3303 5 | export const r = (...args: string[]) => resolve(__dirname, '..', ...args) 6 | export const isDev = process.env.NODE_ENV === 'development' 7 | 8 | // new line 9 | console.log('') 10 | export function log(name: string, message: string) { 11 | console.log(black(bgBlue(` ${name} `)), message) 12 | } 13 | 14 | export function warn(name: string, message: string) { 15 | console.log(black(bgYellow(` ${name} `)), message) 16 | } 17 | -------------------------------------------------------------------------------- /packages/kiss-core/script/patchType.ts: -------------------------------------------------------------------------------- 1 | import { execSync } from 'node:child_process' 2 | import fs, { access } from 'fs-extra' 3 | import { log, r } from './common' 4 | 5 | // check if node_modules target package exists 6 | export const checkNodeModules = async (target: string) => { 7 | const path = r('node_modules', target) 8 | await access(path).catch(() => { 9 | log('kiss', `node_modules/${target} not found, installing...`) 10 | execSync(`pnpm add ${target} -D`, { stdio: 'inherit' }) 11 | }) 12 | } 13 | 14 | export const checkPluginTypes = async () => { 15 | const pluginTypes = [ 16 | '@figma/plugin-typings', 17 | '@mastergo/plugin-typings', 18 | '@jsdesigndeveloper/plugin-typings', 19 | ] 20 | for (const type of pluginTypes) 21 | await checkNodeModules(type) 22 | } 23 | 24 | const checkClientTypesDir = async () => { 25 | const path = r('types', 'client') 26 | await access(path).catch(() => { 27 | log('kiss', 'types/client not found, creating...') 28 | fs.mkdirSync(path) 29 | }) 30 | } 31 | 32 | const genTypeMasterGo = async () => { 33 | const mgPath = r('node_modules', '@mastergo/plugin-typings/dist/index.d.ts') 34 | const content = await fs.readFile(mgPath, 'utf-8') 35 | const newContent = content.replace( 36 | 'declare global {', 37 | 'export declare namespace masterGoClinet {') 38 | await fs.writeFile( 39 | r('types/client', 'masterGo.d.ts'), newContent, 'utf-8') 40 | } 41 | 42 | const genTypeFigma = async () => { 43 | const figmaPath = r('node_modules', '@figma/plugin-typings/plugin-api.d.ts') 44 | const content = await fs.readFile(figmaPath, 'utf-8') 45 | const newContent = `export declare namespace figmaClient {\n${content}\n}` 46 | await fs.writeFile( 47 | r('types', 'client', 'figma.d.ts'), newContent, 'utf-8') 48 | } 49 | 50 | const genTypeJsDesign = async () => { 51 | const jsDesignPath = r('node_modules', '@jsdesigndeveloper/plugin-typings/plugin-api.d.ts') 52 | const content = await fs.readFile(jsDesignPath, 'utf-8') 53 | const newContent = `export declare namespace jsDesignClient {\n${content}\n}` 54 | await fs.writeFile( 55 | r('types', 'client', 'jsDesign.d.ts'), newContent, 'utf-8') 56 | } 57 | 58 | checkPluginTypes().then(() => { 59 | checkClientTypesDir() 60 | }).then(() => { 61 | genTypeMasterGo() 62 | genTypeFigma() 63 | genTypeJsDesign() 64 | }) 65 | -------------------------------------------------------------------------------- /packages/kiss-core/src/index.ts: -------------------------------------------------------------------------------- 1 | // test add 2 | import type { IClient } from '../types' 3 | import { Kiss } from '~/kiss' 4 | 5 | const kiss = new Kiss() 6 | const _client = kiss.inUi ? {} : kiss.client as any 7 | const client = Object.create(_client) as IClient 8 | 9 | client.mg = kiss.inMg ? mg : _client as any 10 | client.figma = kiss.inFigma ? figma : _client as any 11 | client.jsDesign = kiss.inJsDesign ? jsDesign : _client as any 12 | 13 | const env = { 14 | platform: kiss.platform, 15 | ui_client: kiss.ui_client, 16 | inUi: kiss.inUi, 17 | inMgUi: kiss.inMgUi, 18 | inMg: kiss.inMg, 19 | uiClient: kiss.uiClient, 20 | } 21 | 22 | export { 23 | kiss, 24 | client, 25 | env, 26 | } 27 | 28 | export * from '../types/client/masterGo.d' 29 | export * from '../types/client/figma.d' 30 | export * from '../types/client/jsDesign.d' 31 | -------------------------------------------------------------------------------- /packages/kiss-core/src/kiss.ts: -------------------------------------------------------------------------------- 1 | import type { masterGoClinet } from '../types/client/masterGo' 2 | import type { figmaClient } from '../types/client/figma' 3 | import type { jsDesignClient } from '../types/client/jsDesign' 4 | import type { Platform } from '../types' 5 | import { UiClientEnum } from '../types' 6 | import { Detect_platform } from '~/utils/detect_platform' 7 | 8 | export class Kiss { 9 | platform: Platform = 'unknown' 10 | ui_client: UiClientEnum = UiClientEnum.unknown 11 | private _client: masterGoClinet.PluginAPI | figmaClient.PluginAPI | jsDesignClient.PluginAPI | any 12 | constructor() { 13 | this.parsePlatForm() 14 | this.initClient() 15 | } 16 | 17 | get client() { 18 | return this._client 19 | } 20 | 21 | parsePlatForm() { 22 | const detect = new Detect_platform() 23 | this.platform = detect.platform as Platform 24 | this.ui_client = detect.ui_client 25 | if (detect.if_unknown_platform) 26 | throw new Error('unknown platform,only support figma,mg,jsDesign') 27 | } 28 | 29 | initClient() { 30 | switch (this.platform) { 31 | case 'figma': 32 | this._client = figma 33 | break 34 | case 'mg': 35 | this._client = mg 36 | break 37 | case 'jsDesign': 38 | this._client = jsDesign 39 | break 40 | case 'ui': 41 | this._client = {} 42 | break 43 | } 44 | } 45 | 46 | get inUi() { 47 | return this.platform === 'ui' 48 | } 49 | 50 | get inMg() { 51 | return this.platform === 'mg' 52 | } 53 | 54 | get inFigma() { 55 | return this.platform === 'figma' 56 | } 57 | 58 | get inJsDesign() { 59 | return this.platform === 'jsDesign' 60 | } 61 | 62 | get inMgUi() { 63 | return this.ui_client === UiClientEnum.mg 64 | } 65 | 66 | get uiClient() { 67 | return this.ui_client 68 | } 69 | 70 | showUI(args: any) { 71 | if (this.inUi) 72 | return 73 | this._client.showUI(args as any) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /packages/kiss-core/src/utils/detect_platform.ts: -------------------------------------------------------------------------------- 1 | import { UiClientEnum } from '../../types' 2 | 3 | export class Detect_platform { 4 | platform = 'unknown' 5 | constructor() { 6 | this.platform = this.parse_platform() 7 | } 8 | 9 | get if_unknown_platform() { 10 | return this.platform === 'unknown' 11 | } 12 | 13 | if_ui() { 14 | // windows if exist 15 | // console.log('window', location.ancestorOrigins[0]) 16 | let result = false 17 | try { 18 | if (window) 19 | result = true 20 | } 21 | catch (e) { 22 | result = false 23 | } 24 | return result 25 | } 26 | 27 | if_js_design() { 28 | let result = false 29 | try { 30 | if (jsDesign) 31 | result = true 32 | } 33 | catch (e) { 34 | result = false 35 | } 36 | return result 37 | } 38 | 39 | if_figma() { 40 | let result = false 41 | try { 42 | if (figma) 43 | result = true 44 | } 45 | catch (e) { 46 | result = false 47 | } 48 | return result 49 | } 50 | 51 | if_mg() { 52 | let result = false 53 | try { 54 | if (mg) 55 | result = true 56 | } 57 | catch (e) { 58 | result = false 59 | } 60 | return result 61 | } 62 | 63 | get host() { 64 | if (!this.parse_platform().match(/ui/)) 65 | return '' 66 | return location.ancestorOrigins[0] ?? '' 67 | } 68 | 69 | get ui_client() { 70 | if (!this.if_ui()) 71 | return UiClientEnum.unknown 72 | else if (this.host.match(/mastergo\.com/)) 73 | return UiClientEnum.mg 74 | else if (this.host.match(/figma\.com/)) 75 | return UiClientEnum.figma 76 | else if (this.host.match(/js\.design/)) 77 | return UiClientEnum.jsDesign 78 | else 79 | return UiClientEnum.unknown 80 | } 81 | 82 | parse_platform() { 83 | let result 84 | if (this.if_mg()) 85 | result = 'mg' 86 | else if (this.if_js_design()) 87 | result = 'jsDesign' 88 | else if (this.if_figma()) 89 | result = 'figma' 90 | else if (this.if_ui()) 91 | result = 'ui' 92 | else 93 | result = 'unknown' 94 | return result 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /packages/kiss-core/test/index.spec.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leizhenpeng/design-toolkit-cn/f81f913d4a91c38f7bd841c82d079f4002f48e9a/packages/kiss-core/test/index.spec.ts -------------------------------------------------------------------------------- /packages/kiss-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "outDir": "dist", 5 | "useDefineForClassFields": true, 6 | "allowSyntheticDefaultImports": true, 7 | "experimentalDecorators": true, 8 | "strictPropertyInitialization": false, 9 | "module": "ESNext", 10 | "moduleResolution": "node", 11 | "strict": true, 12 | "jsx": "preserve", 13 | "sourceMap": true, 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "esModuleInterop": true, 17 | "lib": ["esnext", "dom"], 18 | "skipLibCheck": true, 19 | "allowJs": true, 20 | "typeRoots": ["./node_modules/@types"], 21 | "types": [ 22 | "vite/client", 23 | "vitest/importMeta", 24 | ], 25 | "baseUrl": ".", 26 | "paths": { 27 | "~/*": ["src/*"] 28 | } 29 | }, 30 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "script/**/*.ts", "*.d.ts"], 31 | "exclude": ["**/*.spec.ts"], 32 | "ts-node": { 33 | "esm": true, 34 | // "experimentalSpecifierResolution": "node" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/kiss-core/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup' 2 | 3 | export default defineConfig({ 4 | entry: ['src/index.ts'], 5 | format: ['esm', 'cjs'], 6 | splitting: false, 7 | clean: true, 8 | dts: true, 9 | outDir: 'dist', 10 | }) 11 | -------------------------------------------------------------------------------- /packages/kiss-core/types/client/figma.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace figmaClient { 2 | type ArgFreeEventType = 3 | | 'selectionchange' 4 | | 'currentpagechange' 5 | | 'close' 6 | | 'timerstart' 7 | | 'timerstop' 8 | | 'timerpause' 9 | | 'timerresume' 10 | | 'timeradjust' 11 | | 'timerdone' 12 | 13 | interface PluginAPI { 14 | readonly apiVersion: '1.0.0' 15 | readonly command: string 16 | readonly editorType: 'figma' | 'figjam' 17 | readonly pluginId?: string 18 | readonly widgetId?: string 19 | 20 | readonly fileKey: string | undefined 21 | 22 | skipInvisibleInstanceChildren: boolean 23 | 24 | readonly timer?: TimerAPI 25 | readonly viewport: ViewportAPI 26 | 27 | readonly currentUser: User | null 28 | readonly activeUsers: ActiveUser[] 29 | 30 | readonly textreview?: TextReviewAPI 31 | 32 | closePlugin(message?: string): void 33 | 34 | notify(message: string, options?: NotificationOptions): NotificationHandler 35 | 36 | commitUndo(): void 37 | triggerUndo(): void 38 | 39 | saveVersionHistoryAsync(title: string, description?: string): Promise 40 | 41 | showUI(html: string, options?: ShowUIOptions): void 42 | readonly ui: UIAPI 43 | 44 | readonly clientStorage: ClientStorageAPI 45 | 46 | readonly parameters: ParametersAPI 47 | 48 | getNodeById(id: string): BaseNode | null 49 | getStyleById(id: string): BaseStyle | null 50 | 51 | readonly root: DocumentNode 52 | currentPage: PageNode 53 | 54 | on(type: ArgFreeEventType, callback: () => void): void 55 | on(type: 'run', callback: (event: RunEvent) => void): void 56 | on(type: 'drop', callback: (event: DropEvent) => boolean): void 57 | on(type: 'documentchange', callback: (event: DocumentChangeEvent) => void): void 58 | on( 59 | type: 'textreview', 60 | callback: (event: TextReviewEvent) => Promise | TextReviewRange[], 61 | ): void 62 | 63 | once(type: ArgFreeEventType, callback: () => void): void 64 | once(type: 'run', callback: (event: RunEvent) => void): void 65 | once(type: 'drop', callback: (event: DropEvent) => boolean): void 66 | once(type: 'documentchange', callback: (event: DocumentChangeEvent) => void): void 67 | once( 68 | type: 'textreview', 69 | callback: (event: TextReviewEvent) => Promise | TextReviewRange[], 70 | ): void 71 | 72 | off(type: ArgFreeEventType, callback: () => void): void 73 | off(type: 'run', callback: (event: RunEvent) => void): void 74 | off(type: 'drop', callback: (event: DropEvent) => boolean): void 75 | off(type: 'documentchange', callback: (event: DocumentChangeEvent) => void): void 76 | off( 77 | type: 'textreview', 78 | callback: (event: TextReviewEvent) => Promise | TextReviewRange[], 79 | ): void 80 | 81 | readonly mixed: unique symbol 82 | 83 | createRectangle(): RectangleNode 84 | createLine(): LineNode 85 | createEllipse(): EllipseNode 86 | createPolygon(): PolygonNode 87 | createStar(): StarNode 88 | createVector(): VectorNode 89 | createText(): TextNode 90 | createFrame(): FrameNode 91 | createComponent(): ComponentNode 92 | createPage(): PageNode 93 | createSlice(): SliceNode 94 | createSticky(): StickyNode 95 | createConnector(): ConnectorNode 96 | createShapeWithText(): ShapeWithTextNode 97 | createCodeBlock(): CodeBlockNode 98 | createSection(): SectionNode 99 | createNodeFromJSXAsync(jsx: any): Promise 100 | 101 | /** 102 | * [DEPRECATED]: This API often fails to create a valid boolean operation. Use figma.union, figma.subtract, figma.intersect and figma.exclude instead. 103 | */ 104 | createBooleanOperation(): BooleanOperationNode 105 | 106 | createPaintStyle(): PaintStyle 107 | createTextStyle(): TextStyle 108 | createEffectStyle(): EffectStyle 109 | createGridStyle(): GridStyle 110 | 111 | // The styles are returned in the same order as displayed in the UI. Only 112 | // local styles are returned. Never styles from team library. 113 | getLocalPaintStyles(): PaintStyle[] 114 | getLocalTextStyles(): TextStyle[] 115 | getLocalEffectStyles(): EffectStyle[] 116 | getLocalGridStyles(): GridStyle[] 117 | 118 | moveLocalPaintStyleAfter(targetNode: PaintStyle, reference: PaintStyle | null): void 119 | moveLocalTextStyleAfter(targetNode: TextStyle, reference: TextStyle | null): void 120 | moveLocalEffectStyleAfter(targetNode: EffectStyle, reference: EffectStyle | null): void 121 | moveLocalGridStyleAfter(targetNode: GridStyle, reference: GridStyle | null): void 122 | 123 | moveLocalPaintFolderAfter(targetFolder: string, reference: string | null): void 124 | moveLocalTextFolderAfter(targetFolder: string, reference: string | null): void 125 | moveLocalEffectFolderAfter(targetFolder: string, reference: string | null): void 126 | moveLocalGridFolderAfter(targetFolder: string, reference: string | null): void 127 | 128 | importComponentByKeyAsync(key: string): Promise 129 | importComponentSetByKeyAsync(key: string): Promise 130 | importStyleByKeyAsync(key: string): Promise 131 | 132 | listAvailableFontsAsync(): Promise 133 | loadFontAsync(fontName: FontName): Promise 134 | readonly hasMissingFont: boolean 135 | 136 | createNodeFromSvg(svg: string): FrameNode 137 | 138 | createImage(data: Uint8Array): Image 139 | getImageByHash(hash: string): Image | null 140 | 141 | createVideoAsync(data: Uint8Array): Promise