w-data-html-minify 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/README.md +36 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +15 -0
- package/dist/w-data-html-minify.umd.js +7 -0
- package/dist/w-data-html-minify.umd.js.map +1 -0
- package/docs/WDataHtmlMinify.mjs.html +134 -0
- package/docs/examples/ex-html-minify.html +94 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/global.html +459 -0
- package/docs/htmlminifier.js.html +26278 -0
- package/docs/importHtmlminify.mjs.html +107 -0
- package/docs/index.html +84 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/examples/ex-html-minify.html +94 -0
- package/g.test.minify.mjs +15 -0
- package/package.json +31 -0
- package/src/WDataHtmlMinify.mjs +62 -0
- package/src/_convertHtmlminifierCode.mjs +24 -0
- package/src/_htmlminifierCoreBrowser.mjs +1 -0
- package/src/_importHtmlminifierBrowser.mjs +46 -0
- package/src/_importHtmlminifierNode.mjs +7 -0
- package/src/htmlminifier.js +26206 -0
- package/src/htmlminifier.min.js +7 -0
- package/src/importHtmlminify.mjs +35 -0
- package/src/rq.js +3 -0
- package/test/all.test.mjs +20 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +46 -0
- package/toolg/gDocsExams.mjs +48 -0
- package/toolg/modifyReadme.mjs +4 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.pln {
|
|
2
|
+
color: #ddd;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* string content */
|
|
6
|
+
.str {
|
|
7
|
+
color: #61ce3c;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* a keyword */
|
|
11
|
+
.kwd {
|
|
12
|
+
color: #fbde2d;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* a comment */
|
|
16
|
+
.com {
|
|
17
|
+
color: #aeaeae;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* a type name */
|
|
21
|
+
.typ {
|
|
22
|
+
color: #8da6ce;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* a literal value */
|
|
26
|
+
.lit {
|
|
27
|
+
color: #fbde2d;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* punctuation */
|
|
31
|
+
.pun {
|
|
32
|
+
color: #ddd;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* lisp open bracket */
|
|
36
|
+
.opn {
|
|
37
|
+
color: #000000;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* lisp close bracket */
|
|
41
|
+
.clo {
|
|
42
|
+
color: #000000;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* a markup tag name */
|
|
46
|
+
.tag {
|
|
47
|
+
color: #8da6ce;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* a markup attribute name */
|
|
51
|
+
.atn {
|
|
52
|
+
color: #fbde2d;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* a markup attribute value */
|
|
56
|
+
.atv {
|
|
57
|
+
color: #ddd;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* a declaration */
|
|
61
|
+
.dec {
|
|
62
|
+
color: #EF5050;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* a variable name */
|
|
66
|
+
.var {
|
|
67
|
+
color: #c82829;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* a function name */
|
|
71
|
+
.fun {
|
|
72
|
+
color: #4271ae;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Specify class=linenums on a pre to get line numbering */
|
|
76
|
+
ol.linenums {
|
|
77
|
+
margin-top: 0;
|
|
78
|
+
margin-bottom: 0;
|
|
79
|
+
padding-bottom: 2px;
|
|
80
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta http-equiv="content-type" content="text/html charset=UTF-8" />
|
|
6
|
+
<title>html-minify</title>
|
|
7
|
+
|
|
8
|
+
<!-- @babel/polyfill已廢棄 -->
|
|
9
|
+
<script nomodule src="https://cdn.jsdelivr.net/npm/@babel/polyfill@7.12.1/dist/polyfill.min.js"></script>
|
|
10
|
+
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/wsemi/dist/wsemi.umd.js"></script>
|
|
12
|
+
|
|
13
|
+
<script _src="../src/htmlminifier.min.js"></script>
|
|
14
|
+
<script src="../dist/w-data-html-minify.umd.js"></script>
|
|
15
|
+
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body style="margin:0px; padding:20px;">
|
|
19
|
+
|
|
20
|
+
<div style="display:flex; align-items:center;">
|
|
21
|
+
|
|
22
|
+
<div style="width:100%;">
|
|
23
|
+
|
|
24
|
+
<div>input:</div>
|
|
25
|
+
|
|
26
|
+
<textarea id="src" style="width:100%; height:calc( 100vh - 50px );"></textarea>
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<div style="padding:0px 15px 0px 20px;">
|
|
31
|
+
|
|
32
|
+
<div style="padding:5px;">
|
|
33
|
+
<button onclick="cv('minify')">minify</button>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div style="padding:5px;">
|
|
37
|
+
<button onclick="cv('minify+base64')">minify+base64</button>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div style="width:100%;">
|
|
43
|
+
|
|
44
|
+
<div>output:</div>
|
|
45
|
+
|
|
46
|
+
<textarea id="tar" style="width:100%; height:calc( 100vh - 50px );"></textarea>
|
|
47
|
+
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
|
|
54
|
+
document.querySelector('#src').value = `<html>
|
|
55
|
+
<head></head>
|
|
56
|
+
<body>abc</body>
|
|
57
|
+
</html>
|
|
58
|
+
`
|
|
59
|
+
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<script>
|
|
63
|
+
|
|
64
|
+
// let minify = require('html-minifier').minify
|
|
65
|
+
// console.log('minify',minify)
|
|
66
|
+
|
|
67
|
+
let wdhm = window['w-data-html-minify']
|
|
68
|
+
// console.log(wdhm)
|
|
69
|
+
|
|
70
|
+
function cv(mode){
|
|
71
|
+
// console.log(mode)
|
|
72
|
+
|
|
73
|
+
let hin = document.querySelector('#src').value
|
|
74
|
+
|
|
75
|
+
let hout = ''
|
|
76
|
+
|
|
77
|
+
if(mode.indexOf('minify')>=0){
|
|
78
|
+
hout = wdhm(hin)
|
|
79
|
+
// console.log('wdhm',hout)
|
|
80
|
+
}
|
|
81
|
+
if(mode.indexOf('base64')>=0){
|
|
82
|
+
hout = window.btoa(hout)
|
|
83
|
+
// console.log('str2b64',hout)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
document.querySelector('#tar').value = hout
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
</body>
|
|
93
|
+
|
|
94
|
+
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import wdhm from './src/WDataHtmlMinify.mjs'
|
|
2
|
+
// import wdhm from './dist/w-data-html-minify.umd.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
let hin = `
|
|
6
|
+
<html>
|
|
7
|
+
<head></head>
|
|
8
|
+
<body>abc</body>
|
|
9
|
+
</html>
|
|
10
|
+
`
|
|
11
|
+
let hout = wdhm(hin)
|
|
12
|
+
console.log(hout)
|
|
13
|
+
// => <html><head></head><body>abc</body></html>
|
|
14
|
+
|
|
15
|
+
//node --experimental-modules --es-module-specifier-resolution=node g.test.minify.mjs
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "w-data-html-minify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/w-data-html-minify.umd.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"html-minifier": "^4.0.0",
|
|
7
|
+
"lodash": "^4.17.21",
|
|
8
|
+
"wsemi": "^1.7.38"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"w-package-tools": "^1.0.70"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
|
|
15
|
+
"deploy": "gh-pages -d docs"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/yuda-lyu/w-data-html-minify.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"package",
|
|
23
|
+
"tool",
|
|
24
|
+
"html",
|
|
25
|
+
"minify",
|
|
26
|
+
"borwser",
|
|
27
|
+
"nodejs"
|
|
28
|
+
],
|
|
29
|
+
"author": "yuda-lyu(semisphere)",
|
|
30
|
+
"license": "MIT"
|
|
31
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
2
|
+
// import htmlminify from 'html-minifier'
|
|
3
|
+
import htmlminify from './importHtmlminify.mjs' //html-minifier於npm上未提供dist, 故須於github自行下載
|
|
4
|
+
// console.log(htmlminify)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 壓縮HTML
|
|
9
|
+
*
|
|
10
|
+
* @param {String} h 輸入HTML字串
|
|
11
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
12
|
+
* @return {String} 回傳Promise,resolve回傳ltdt(各數據列為物件陣列),reject回傳錯誤訊息
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* let hin = `
|
|
16
|
+
* <html>
|
|
17
|
+
* <head></head>
|
|
18
|
+
* <body>abc</body>
|
|
19
|
+
* </html>
|
|
20
|
+
* `
|
|
21
|
+
* let hout = wdhm(hin)
|
|
22
|
+
* console.log(hout)
|
|
23
|
+
* // => <html><head></head><body>abc</body></html>
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
function WDataHtmlMinify(h, opt = {}) {
|
|
27
|
+
|
|
28
|
+
//check
|
|
29
|
+
if (!isestr(h)) {
|
|
30
|
+
return ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let optDef = {
|
|
34
|
+
includeAutoGeneratedTags: true,
|
|
35
|
+
removeAttributeQuotes: false, //因要將svg視為html處理, 故不能使用移除雙引號
|
|
36
|
+
removeComments: true,
|
|
37
|
+
removeRedundantAttributes: true,
|
|
38
|
+
removeScriptTypeAttributes: true,
|
|
39
|
+
removeStyleLinkTypeAttributes: true,
|
|
40
|
+
sortClassName: true,
|
|
41
|
+
useShortDoctype: true,
|
|
42
|
+
collapseWhitespace: true
|
|
43
|
+
}
|
|
44
|
+
let optUse = {
|
|
45
|
+
...optDef,
|
|
46
|
+
...opt,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//htmlminify
|
|
50
|
+
let hh = ''
|
|
51
|
+
try {
|
|
52
|
+
hh = htmlminify(h, optUse)
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
hh = err.toString()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return hh
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export default WDataHtmlMinify
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import w from 'wsemi'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
//提取htmlminifier前端js轉base64
|
|
6
|
+
let c = fs.readFileSync('./src/htmlminifier.min.js', 'utf8')
|
|
7
|
+
c = `
|
|
8
|
+
|
|
9
|
+
${c}
|
|
10
|
+
|
|
11
|
+
let htmlminifier = require('html-minifier').minify
|
|
12
|
+
|
|
13
|
+
window['html-minifier']=htmlminifier
|
|
14
|
+
|
|
15
|
+
`
|
|
16
|
+
let b64 = w.str2b64(c)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
//輸出json
|
|
20
|
+
let j = `let b64='${b64}'; export default b64`
|
|
21
|
+
fs.writeFileSync('./src/_htmlminifierCoreBrowser.mjs', j, 'utf8')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
//node --experimental-modules --es-module-specifier-resolution=node src/_convertHtmlminifierCode.mjs
|