nv-basic-bw 1.0.23 → 1.0.25

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.
Files changed (3) hide show
  1. package/impt.js +9 -6
  2. package/package.json +1 -1
  3. package/util.js +8 -1
package/impt.js CHANGED
@@ -55,13 +55,16 @@ const loadcss = (code_str,T="link")=>{
55
55
  <!-- Base64 编码的代码 -->
56
56
  <script src="data:text/javascript;base64,Y29uc29sZS5sb2coJ0hlbGxvIEJhc2U2NCcpOw=="></script>
57
57
  */
58
-
58
+ const {to_base64_uri} = require("./util");
59
59
  const code2hscript = (id, code_str) => {
60
- return `<script id=${JSON.stringify(id)} src=${JSON.stringify("data:text/javascript,"+code_str)}></script>`;
61
- }
60
+ const uri = to_base64_uri("text/javascript", code_str);
61
+ return `<script id=${JSON.stringify(id)} src=${JSON.stringify(uri)}></script>`;
62
+ };
63
+
62
64
  const css2hlink = (id, code_str) => {
63
- return `<link id=${JSON.stringify(id)} ref="stylesheet" href=${JSON.stringify("data:text/css,"+code_str)}></script>`;
64
- }
65
+ const uri = to_base64_uri("text/css", code_str);
66
+ return `<link id=${JSON.stringify(id)} rel="stylesheet" href=${JSON.stringify(uri)}>`;
67
+ };
65
68
 
66
69
  module.exports = {
67
70
  loadjs,
@@ -69,5 +72,5 @@ module.exports = {
69
72
  loadcss,
70
73
  ////
71
74
  code2hscript,
72
- css2hlink
75
+ css2hlink,
73
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-basic-bw",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/util.js CHANGED
@@ -66,10 +66,17 @@ const get_ck = (s=document.cookie)=>{
66
66
  return d;
67
67
  }
68
68
 
69
+ const to_base64_uri = (mime, code) => {
70
+ // 如果是在纯浏览器环境,请使用:
71
+ const b64 = btoa(unescape(encodeURIComponent(code.trim())));
72
+ return `data:${mime};base64,${b64}`;
73
+ };
74
+
69
75
  module.exports = {
70
76
  is_async,
71
77
  is_url,
72
78
  fullfill_url,
73
79
  creat_dt_prefix,
74
- get_ck
80
+ get_ck,
81
+ to_base64_uri
75
82
  }