v0.3.1 - use modified pdfkit to generate PDF
This commit is contained in:
parent
53ae364a7a
commit
eb6c13ce60
4 changed files with 22012 additions and 64279 deletions
86243
dist/main.js
vendored
86243
dist/main.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "musescore-downloader",
|
"name": "musescore-downloader",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱",
|
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱",
|
||||||
"main": "dist/main.js",
|
"main": "dist/main.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -14,14 +14,15 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/Xmader/musescore-downloader#readme",
|
"homepage": "https://github.com/Xmader/musescore-downloader#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pdfmake": "^0.1.62"
|
"pdfkit": "git+https://github.com/Xmader/pdfkit.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-json": "^4.0.0",
|
"@rollup/plugin-json": "^4.0.0",
|
||||||
"@types/pdfmake": "^0.1.8",
|
"@types/pdfkit": "^0.10.4",
|
||||||
"rollup": "^1.26.3",
|
"rollup": "^1.26.3",
|
||||||
"rollup-plugin-commonjs": "^10.1.0",
|
"rollup-plugin-commonjs": "^10.1.0",
|
||||||
"rollup-plugin-node-builtins": "^2.1.2",
|
"rollup-plugin-node-builtins": "^2.1.2",
|
||||||
|
"rollup-plugin-node-globals": "^1.4.0",
|
||||||
"rollup-plugin-node-resolve": "^5.2.0",
|
"rollup-plugin-node-resolve": "^5.2.0",
|
||||||
"rollup-plugin-typescript": "^1.0.1",
|
"rollup-plugin-typescript": "^1.0.1",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
|
|
|
@ -2,6 +2,7 @@ import typescript from "rollup-plugin-typescript"
|
||||||
import resolve from "rollup-plugin-node-resolve"
|
import resolve from "rollup-plugin-node-resolve"
|
||||||
import commonjs from "rollup-plugin-commonjs"
|
import commonjs from "rollup-plugin-commonjs"
|
||||||
import builtins from "rollup-plugin-node-builtins"
|
import builtins from "rollup-plugin-node-builtins"
|
||||||
|
import nodeGlobals from "rollup-plugin-node-globals"
|
||||||
import json from "@rollup/plugin-json"
|
import json from "@rollup/plugin-json"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
|
|
||||||
|
@ -20,11 +21,13 @@ export default {
|
||||||
format: "iife",
|
format: "iife",
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
banner: getBannerText,
|
banner: getBannerText,
|
||||||
|
// intro: "const global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof commonjsGlobal === 'object' && commonjsGlobal.global === commonjsGlobal ? commonjsGlobal : void 0"
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
typescript({
|
typescript({
|
||||||
target: "ES6",
|
target: "ES6",
|
||||||
sourceMap: false,
|
sourceMap: false,
|
||||||
|
allowJs: true,
|
||||||
lib: [
|
lib: [
|
||||||
"ES6",
|
"ES6",
|
||||||
"dom"
|
"dom"
|
||||||
|
@ -40,5 +43,10 @@ export default {
|
||||||
}),
|
}),
|
||||||
json(),
|
json(),
|
||||||
builtins(),
|
builtins(),
|
||||||
|
nodeGlobals({
|
||||||
|
dirname: false,
|
||||||
|
filename: false,
|
||||||
|
baseDir: false,
|
||||||
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
33
src/main.ts
33
src/main.ts
|
@ -3,7 +3,7 @@ import "./meta"
|
||||||
import { ScorePlayerData } from "./types"
|
import { ScorePlayerData } from "./types"
|
||||||
import { waitForDocumentLoaded } from "./utils"
|
import { waitForDocumentLoaded } from "./utils"
|
||||||
|
|
||||||
import pdfmake from "pdfmake/build/pdfmake"
|
import PDFDocument from "pdfkit/lib/document"
|
||||||
|
|
||||||
const generatePDF = (name?: string) => {
|
const generatePDF = (name?: string) => {
|
||||||
const scoreImgs: NodeListOf<HTMLImageElement> = document.querySelectorAll("img[id^=score_]")
|
const scoreImgs: NodeListOf<HTMLImageElement> = document.querySelectorAll("img[id^=score_]")
|
||||||
|
@ -25,26 +25,25 @@ const generatePDF = (name?: string) => {
|
||||||
return canvas.toDataURL("image/png")
|
return canvas.toDataURL("image/png")
|
||||||
})
|
})
|
||||||
|
|
||||||
const pdf = pdfmake.createPdf({
|
// @ts-ignore
|
||||||
pageMargins: 0,
|
const pdf = new (PDFDocument as typeof import("pdfkit"))({
|
||||||
// @ts-ignore
|
|
||||||
pageOrientation: "PORTRAIT",
|
|
||||||
pageSize: { width, height },
|
|
||||||
// compress: true,
|
// compress: true,
|
||||||
content: [
|
size: [width, height],
|
||||||
...imgDataList.map((data) => {
|
autoFirstPage: false,
|
||||||
return {
|
margin: 0,
|
||||||
image: data,
|
layout: "portrait",
|
||||||
width,
|
|
||||||
height,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
imgDataList.forEach((data) => {
|
||||||
pdf.download(`${name}.pdf`, resolve)
|
pdf.addPage()
|
||||||
|
pdf.image(data,{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return pdf.download(`${name}.pdf`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTitle = (scorePlayerData: ScorePlayerData) => {
|
const getTitle = (scorePlayerData: ScorePlayerData) => {
|
||||||
|
|
Loading…
Reference in a new issue