(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 |
14 |
15 |
16 |
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 |
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