Skip to content

Commit

Permalink
feat: #3 图片展示优化-文档图片背景自动透明
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 5, 2023
1 parent c6905ef commit a431ab4
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 33 deletions.
2 changes: 1 addition & 1 deletion config/plugins/vite.cjs.config.zhi-demo-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ export default defineConfig({
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// minify: false,
// minify: "esbuild",
minify: "esbuild",
},
})
61 changes: 61 additions & 0 deletions config/plugins/vite.cjs.config.zhi-picture-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { defineConfig } from "vite"
import { commonConfig } from "../../vite.config"

const outputMap: any = {
ZhiPicturePlugin: {
file: "src/apps/zhi/zhi-plugins/zhi-picture-plugin/main.ts",
folder: "main.js",
},
}

// https://vitejs.dev/config/
export default defineConfig({
...commonConfig,
build: {
rollupOptions: {
input: {
ZhiPicturePlugin: outputMap["ZhiPicturePlugin"].file,
},
output: {
format: "cjs",
entryFileNames: (entry) => {
return outputMap[entry.name].folder
},
},
},

// 生成sourcemap
sourcemap: false,

// 设置为 false 可以禁用最小化混淆
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// minify: false,
minify: "esbuild",
},
})
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"build:cjs": "python script/cjs.py",
"build:esm": "python script/esm.py",
"build:css": "python script/css.py",
"build:plugin:zhi-demo-plugin": "python script/zhi-demo-plugin.py",
"build:plugin:zhi-picture-plugin": "python script/zhi-picture-plugin.py",
"build:plugin:zhi-publisher-plugin": "python script/zhi-publisher-plugin.py",
"preview": "vite preview",
"test": "vitest",
"coverage": "vitest run --coverage",
Expand Down
13 changes: 7 additions & 6 deletions script/cjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
scriptutils.rm_folder("dist-cjs/plugin-system/icons")

# zhi-demo-plugin/main.js
os.system("tsc && vite build -c config/plugins/vite.cjs.config.zhi-demo-plugin.ts --outDir "
"dist-cjs/zhi-plugins/zhi-demo-plugin")
scriptutils.cp_file("src/apps/zhi/zhi-plugins/zhi-demo-plugin/manifest.json", "dist-cjs/zhi-plugins/zhi-demo"
"-plugin/manifest.json")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-demo-plugin/fonts")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-demo-plugin/icons")
os.system("pnpm build:plugin:zhi-demo-plugin")

# zhi-picture-plugin/main.js
os.system("pnpm build:plugin:zhi-picture-plugin")

# zhi-publisher-plugin/main.js
os.system("pnpm build:plugin:zhi-publisher-plugin")

print("cjs构建完成.")
40 changes: 40 additions & 0 deletions script/zhi-demo-plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023, Terwer . All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Terwer designates this
# particular file as subject to the "Classpath" exception as provided
# by Terwer in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
# or visit www.terwer.space if you need additional information or have any
# questions.

import os

import scriptutils

if __name__ == "__main__":
# 切换工作空间
scriptutils.switch_workdir()

# zhi-demo-plugin/main.js
os.system("tsc && vite build -c config/plugins/vite.cjs.config.zhi-demo-plugin.ts "
"--outDir dist-cjs/zhi-plugins/zhi-demo-plugin")
scriptutils.cp_file("src/apps/zhi/zhi-plugins/zhi-demo-plugin/manifest.json",
"dist-cjs/zhi-plugins/zhi-demo-plugin/manifest.json")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-demo-plugin/fonts")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-demo-plugin/icons")

print("zhi-demo-plugin构建完成.")
40 changes: 40 additions & 0 deletions script/zhi-picture-plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023, Terwer . All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Terwer designates this
# particular file as subject to the "Classpath" exception as provided
# by Terwer in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
# or visit www.terwer.space if you need additional information or have any
# questions.

import os

import scriptutils

if __name__ == "__main__":
# 切换工作空间
scriptutils.switch_workdir()

# zhi-demo-plugin/main.js
os.system("tsc && vite build -c config/plugins/vite.cjs.config.zhi-picture-plugin.ts "
"--outDir dist-cjs/zhi-plugins/zhi-picture-plugin")
scriptutils.cp_file("src/apps/zhi/zhi-plugins/zhi-picture-plugin/manifest.json",
"dist-cjs/zhi-plugins/zhi-picture-plugin/manifest.json")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-picture-plugin/fonts")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-picture-plugin/icons")

print("zhi-picture-plugin构建完成.")
40 changes: 40 additions & 0 deletions script/zhi-publisher-plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023, Terwer . All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Terwer designates this
# particular file as subject to the "Classpath" exception as provided
# by Terwer in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
# or visit www.terwer.space if you need additional information or have any
# questions.

import os

import scriptutils

if __name__ == "__main__":
# 切换工作空间
scriptutils.switch_workdir()

# zhi-demo-plugin/main.js
os.system("tsc && vite build -c config/plugins/vite.cjs.config.zhi-publisher-plugin.ts "
"--outDir dist-cjs/zhi-plugins/zhi-publisher-plugin")
scriptutils.cp_file("src/apps/zhi/zhi-plugins/zhi-publisher-plugin/manifest.json",
"dist-cjs/zhi-plugins/zhi-publisher-plugin/manifest.json")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-publisher-plugin/fonts")
scriptutils.rm_folder("dist-cjs/zhi-plugins/zhi-publisher-plugin/icons")

print("zhi-publisher-plugin构建完成.")
26 changes: 1 addition & 25 deletions src/apps/zhi/zhi-plugins/zhi-demo-plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import logFactory from "~/src/utils/logUtil"
import cjsUtil from "~/src/utils/cjsUtil"
import Translucify from "~/src/apps/zhi/zhi-plugins/zhi-demo-plugin/translucify"

const siyuan = cjsUtil.nodeRequire("siyuan")
const Plugin = siyuan.Plugin
Expand All @@ -38,37 +37,14 @@ const Plugin = siyuan.Plugin
*/
class ZhiDemoPlugin extends Plugin {
private readonly logger = logFactory.getLogger("ZhiDemoPlugin")
private translucify

constructor() {
super()
this.translucify = new Translucify().init()
this.logger.info("ZhiDemoPlugin created")
}

onload() {
// this.logger.info("siyuan=>", siyuan)
const zhiDemoButton = document.createElement("button")
zhiDemoButton.classList.add("toolbar__item")

// 使用思源图标
// 图标地址:http://127.0.0.1:6806/appearance/icons/ant/icon.js?v=2.7.7
// zhiDemoButton.insertAdjacentHTML(
// "beforeend",
// '<svg><use xlink:href="#iconHand"></use></svg>'
// )
zhiDemoButton.addEventListener("click", (event) => {
this.translucify(document.querySelectorAll("img"), 0.05)
this.logger.info("Picture is transplanted.")
event.stopPropagation()
})

zhiDemoButton.insertAdjacentHTML(
"beforeend",
'<i class="fa-solid fa-lightbulb"></i>'
)

siyuan.clientApi.addToolbarRight(zhiDemoButton)
this.logger.info("siyuan=>", siyuan)
this.logger.info("ZhiDemoPlugin loaded")
}

Expand Down
2 changes: 1 addition & 1 deletion src/apps/zhi/zhi-plugins/zhi-demo-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"author": "terwer",
"url": "https://github.com/terwer/zhi",
"version": "1.0.0",
"forceUpdate": true
"forceUpdate": false
}
81 changes: 81 additions & 0 deletions src/apps/zhi/zhi-plugins/zhi-picture-plugin/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import logFactory from "~/src/utils/logUtil"
import cjsUtil from "~/src/utils/cjsUtil"
import Translucify from "~/src/apps/zhi/zhi-plugins/zhi-picture-plugin/translucify"

const siyuan = cjsUtil.nodeRequire("siyuan")
const Plugin = siyuan.Plugin

/**
* zhi picture plugin
*
* @author terwer
* @since 1.0.0
*/
class ZhiPicturePlugin extends Plugin {
private readonly logger = logFactory.getLogger("ZhiPicturePlugin")
private readonly translucify

constructor() {
super()
this.translucify = new Translucify().init()
this.logger.info("ZhiPicturePlugin created")
}

onload() {
const zhiDemoButton = document.createElement("button")
zhiDemoButton.classList.add("toolbar__item")

// 使用思源图标
// 图标地址:http://127.0.0.1:6806/appearance/icons/ant/icon.js?v=2.7.7
// zhiDemoButton.insertAdjacentHTML(
// "beforeend",
// '<svg><use xlink:href="#iconHand"></use></svg>'
// )
zhiDemoButton.addEventListener("click", (event) => {
this.translucify(document.querySelectorAll("img"), 0.05)
this.logger.info("Picture is transplanted.")
event.stopPropagation()
})

zhiDemoButton.insertAdjacentHTML(
"beforeend",
'<i class="fa-solid fa-lightbulb"></i>'
)

siyuan.clientApi.addToolbarRight(zhiDemoButton)
this.logger.info("ZhiPicturePlugin loaded")
}

onunload() {
this.logger.info("ZhiPicturePlugin unloaded")
}
}

module.exports = {
default: ZhiPicturePlugin,
}
7 changes: 7 additions & 0 deletions src/apps/zhi/zhi-plugins/zhi-picture-plugin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "zhiPicturePlugin",
"author": "terwer",
"url": "https://github.com/terwer/zhi",
"version": "1.0.0",
"forceUpdate": false
}

0 comments on commit a431ab4

Please sign in to comment.