@mytools-all/mytools-ocr 0.1.0 → 0.2.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/README.md +26 -21
- package/THIRD_PARTY.md +3 -25
- package/app.mjs +93 -201
- package/history.mjs +13 -0
- package/index.html +5 -104
- package/package.json +38 -41
- package/plugin.json +33 -27
- package/tool.css +295 -295
- package/umi.mjs +34 -0
- package/common.mjs +0 -69
- package/md5.LICENSE +0 -20
- package/md5.mjs +0 -10
- package/utils.mjs +0 -201
package/common.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export const $ = (selector) => document.querySelector(selector);
|
|
2
|
-
export const $$ = (selector) => [...document.querySelectorAll(selector)];
|
|
3
|
-
export function status(text, error = false) {
|
|
4
|
-
const el = $("#status");
|
|
5
|
-
if (el) {
|
|
6
|
-
el.textContent = text;
|
|
7
|
-
el.dataset.error = String(error);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function action(fn) {
|
|
11
|
-
return async (...args) => {
|
|
12
|
-
try {
|
|
13
|
-
return await fn(...args);
|
|
14
|
-
} catch (e) {
|
|
15
|
-
status(e.message || String(e), true);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export async function call(id, args = {}) {
|
|
20
|
-
if (!window.mytools) throw Error("请从 MyTools 打开此工具");
|
|
21
|
-
return window.mytools.call(id, args);
|
|
22
|
-
}
|
|
23
|
-
export const copy = async (text) => {
|
|
24
|
-
await call("clipboard.write", { text: String(text) });
|
|
25
|
-
status("已复制到剪贴板");
|
|
26
|
-
};
|
|
27
|
-
export function ready(fn) {
|
|
28
|
-
if (window.mytools) window.mytools.onPluginReady(action(fn));
|
|
29
|
-
else status("预览模式:系统能力需从 MyTools 使用");
|
|
30
|
-
}
|
|
31
|
-
export const escapeHtml = (text) =>
|
|
32
|
-
String(text).replace(
|
|
33
|
-
/[&<>"']/g,
|
|
34
|
-
(c) =>
|
|
35
|
-
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[
|
|
36
|
-
c
|
|
37
|
-
],
|
|
38
|
-
);
|
|
39
|
-
export function download(name, text, type = "text/plain") {
|
|
40
|
-
const url = URL.createObjectURL(new Blob([text], { type }));
|
|
41
|
-
const a = document.createElement("a");
|
|
42
|
-
a.href = url;
|
|
43
|
-
a.download = name;
|
|
44
|
-
a.click();
|
|
45
|
-
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
46
|
-
}
|
|
47
|
-
export function debounce(fn, ms = 200) {
|
|
48
|
-
let timer;
|
|
49
|
-
return (...args) => {
|
|
50
|
-
clearTimeout(timer);
|
|
51
|
-
timer = setTimeout(() => fn(...args), ms);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export const formatBytes = (n) =>
|
|
55
|
-
n < 1024
|
|
56
|
-
? n + " B"
|
|
57
|
-
: n < 1048576
|
|
58
|
-
? (n / 1024).toFixed(1) + " KB"
|
|
59
|
-
: (n / 1048576).toFixed(1) + " MB";
|
|
60
|
-
const savedTheme = localStorage.getItem("tool-theme");
|
|
61
|
-
document.documentElement.dataset.theme =
|
|
62
|
-
savedTheme ||
|
|
63
|
-
(matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
64
|
-
$("#theme")?.addEventListener("click", () => {
|
|
65
|
-
const theme =
|
|
66
|
-
document.documentElement.dataset.theme === "dark" ? "light" : "dark";
|
|
67
|
-
document.documentElement.dataset.theme = theme;
|
|
68
|
-
localStorage.setItem("tool-theme", theme);
|
|
69
|
-
});
|
package/md5.LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright 2014-2026 Chen, Yi-Cyuan
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/md5.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r,e={exports:{}};
|
|
2
|
-
/**
|
|
3
|
-
* [js-md5]{@link https://github.com/emn178/js-md5}
|
|
4
|
-
*
|
|
5
|
-
* @namespace md5
|
|
6
|
-
* @version 0.9.2
|
|
7
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
8
|
-
* @copyright Chen, Yi-Cyuan 2014-2026
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/r=e,function(){var t="input is invalid type",e="object"==typeof window,i=e?window:{};i.JS_MD5_NO_WINDOW&&(e=!1),"undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof self&&self instanceof WorkerGlobalScope&&(i=self);var h=!i.JS_MD5_NO_COMMON_JS&&r.exports,s=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),n=[128,32768,8388608,-2147483648],o=[0,8,16,24],f=["hex","array","digest","arrayBuffer"];f.push("buffer"),f.push("base64");var u,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),y=[];if(s){var c=new ArrayBuffer(68);u=new Uint8Array(c),y=new Uint32Array(c)}var l=Array.isArray;!i.JS_MD5_NO_NODE_JS&&l||(l=function(t){return"[object Array]"===Object.prototype.toString.call(t)});var d=ArrayBuffer.isView;!s||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&d||(d=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var b=function(r){var e=typeof r;if("string"===e)return[r,!0];if("object"!==e||null===r)throw new Error(t);if(s&&r.constructor===ArrayBuffer)return[new Uint8Array(r),!1];if(!l(r)&&!d(r))throw new Error(t);return[r,!1]},v=function(t){return function(r){return new A(!0).update(r)[t]()}},w=function(t){return function(r,e){return new _(r,!0).update(e)[t]()}};function A(t){if(t)y[0]=y[16]=y[1]=y[2]=y[3]=y[4]=y[5]=y[6]=y[7]=y[8]=y[9]=y[10]=y[11]=y[12]=y[13]=y[14]=y[15]=0,this.blocks=y,this.buffer8=u;else if(s){var r=new ArrayBuffer(68);this.buffer8=new Uint8Array(r),this.blocks=new Uint32Array(r)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function _(t,r){var e,i=b(t);if(t=i[0],i[1]){var h,s=[],a=t.length,n=0;for(e=0;e<a;++e)(h=t.charCodeAt(e))<128?s[n++]=h:h<2048?(s[n++]=192|h>>>6,s[n++]=128|63&h):h<55296||h>=57344?(s[n++]=224|h>>>12,s[n++]=128|h>>>6&63,s[n++]=128|63&h):(h=65536+((1023&h)<<10|1023&t.charCodeAt(++e)),s[n++]=240|h>>>18,s[n++]=128|h>>>12&63,s[n++]=128|h>>>6&63,s[n++]=128|63&h);t=s}t.length>64&&(t=new A(!0).update(t).array());var o=[],f=[];for(e=0;e<64;++e){var u=t[e]||0;o[e]=92^u,f[e]=54^u}A.call(this,r),this.update(f),this.oKeyPad=o,this.inner=!0,this.sharedMemory=r}A.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var r=b(t);t=r[0];for(var e,i,h=r[1],a=0,n=t.length,f=this.blocks,u=this.buffer8;a<n;){if(this.hashed&&(this.hashed=!1,f[0]=f[16],f[16]=f[1]=f[2]=f[3]=f[4]=f[5]=f[6]=f[7]=f[8]=f[9]=f[10]=f[11]=f[12]=f[13]=f[14]=f[15]=0),h)if(s)for(i=this.start;a<n&&i<64;++a)(e=t.charCodeAt(a))<128?u[i++]=e:e<2048?(u[i++]=192|e>>>6,u[i++]=128|63&e):e<55296||e>=57344?(u[i++]=224|e>>>12,u[i++]=128|e>>>6&63,u[i++]=128|63&e):(e=65536+((1023&e)<<10|1023&t.charCodeAt(++a)),u[i++]=240|e>>>18,u[i++]=128|e>>>12&63,u[i++]=128|e>>>6&63,u[i++]=128|63&e);else for(i=this.start;a<n&&i<64;++a)(e=t.charCodeAt(a))<128?f[i>>>2]|=e<<o[3&i++]:e<2048?(f[i>>>2]|=(192|e>>>6)<<o[3&i++],f[i>>>2]|=(128|63&e)<<o[3&i++]):e<55296||e>=57344?(f[i>>>2]|=(224|e>>>12)<<o[3&i++],f[i>>>2]|=(128|e>>>6&63)<<o[3&i++],f[i>>>2]|=(128|63&e)<<o[3&i++]):(e=65536+((1023&e)<<10|1023&t.charCodeAt(++a)),f[i>>>2]|=(240|e>>>18)<<o[3&i++],f[i>>>2]|=(128|e>>>12&63)<<o[3&i++],f[i>>>2]|=(128|e>>>6&63)<<o[3&i++],f[i>>>2]|=(128|63&e)<<o[3&i++]);else if(s)for(i=this.start;a<n&&i<64;++a)u[i++]=t[a];else for(i=this.start;a<n&&i<64;++a)f[i>>>2]|=t[a]<<o[3&i++];this.lastByteIndex=i,this.bytes+=i-this.start,i>=64?(this.start=i-64,this.hash(),this.hashed=!0):this.start=i}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},A.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,r=this.lastByteIndex;t[r>>>2]|=n[3&r],r>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},A.prototype.hash=function(){var t,r,e,i,h,s,a=this.blocks;this.first?r=((r=((t=((t=a[0]-680876937)<<7|t>>>25)-271733879|0)^(e=((e=(-271733879^(i=((i=(-1732584194^2004318071&t)+a[1]-117830708)<<12|i>>>20)+t|0)&(-271733879^t))+a[2]-1126478375)<<17|e>>>15)+i|0)&(i^t))+a[3]-1316259209)<<22|r>>>10)+e|0:(t=this.h0,r=this.h1,e=this.h2,r=((r+=((t=((t+=((i=this.h3)^r&(e^i))+a[0]-680876936)<<7|t>>>25)+r|0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+a[1]-389564586)<<12|i>>>20)+t|0)&(t^r))+a[2]+606105819)<<17|e>>>15)+i|0)&(i^t))+a[3]-1044525330)<<22|r>>>10)+e|0),r=((r+=((t=((t+=(i^r&(e^i))+a[4]-176418897)<<7|t>>>25)+r|0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+a[5]+1200080426)<<12|i>>>20)+t|0)&(t^r))+a[6]-1473231341)<<17|e>>>15)+i|0)&(i^t))+a[7]-45705983)<<22|r>>>10)+e|0,r=((r+=((t=((t+=(i^r&(e^i))+a[8]+1770035416)<<7|t>>>25)+r|0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+a[9]-1958414417)<<12|i>>>20)+t|0)&(t^r))+a[10]-42063)<<17|e>>>15)+i|0)&(i^t))+a[11]-1990404162)<<22|r>>>10)+e|0,r=((r+=((t=((t+=(i^r&(e^i))+a[12]+1804603682)<<7|t>>>25)+r|0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+a[13]-40341101)<<12|i>>>20)+t|0)&(t^r))+a[14]-1502002290)<<17|e>>>15)+i|0)&(i^t))+a[15]+1236535329)<<22|r>>>10)+e|0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+a[1]-165796510)<<5|t>>>27)+r|0)^r))+a[6]-1069501632)<<9|i>>>23)+t|0)^t&((e=((e+=(t^r&(i^t))+a[11]+643717713)<<14|e>>>18)+i|0)^i))+a[0]-373897302)<<20|r>>>12)+e|0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+a[5]-701558691)<<5|t>>>27)+r|0)^r))+a[10]+38016083)<<9|i>>>23)+t|0)^t&((e=((e+=(t^r&(i^t))+a[15]-660478335)<<14|e>>>18)+i|0)^i))+a[4]-405537848)<<20|r>>>12)+e|0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+a[9]+568446438)<<5|t>>>27)+r|0)^r))+a[14]-1019803690)<<9|i>>>23)+t|0)^t&((e=((e+=(t^r&(i^t))+a[3]-187363961)<<14|e>>>18)+i|0)^i))+a[8]+1163531501)<<20|r>>>12)+e|0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+a[13]-1444681467)<<5|t>>>27)+r|0)^r))+a[2]-51403784)<<9|i>>>23)+t|0)^t&((e=((e+=(t^r&(i^t))+a[7]+1735328473)<<14|e>>>18)+i|0)^i))+a[12]-1926607734)<<20|r>>>12)+e|0,r=((r+=((s=(i=((i+=((h=r^e)^(t=((t+=(h^i)+a[5]-378558)<<4|t>>>28)+r|0))+a[8]-2022574463)<<11|i>>>21)+t|0)^t)^(e=((e+=(s^r)+a[11]+1839030562)<<16|e>>>16)+i|0))+a[14]-35309556)<<23|r>>>9)+e|0,r=((r+=((s=(i=((i+=((h=r^e)^(t=((t+=(h^i)+a[1]-1530992060)<<4|t>>>28)+r|0))+a[4]+1272893353)<<11|i>>>21)+t|0)^t)^(e=((e+=(s^r)+a[7]-155497632)<<16|e>>>16)+i|0))+a[10]-1094730640)<<23|r>>>9)+e|0,r=((r+=((s=(i=((i+=((h=r^e)^(t=((t+=(h^i)+a[13]+681279174)<<4|t>>>28)+r|0))+a[0]-358537222)<<11|i>>>21)+t|0)^t)^(e=((e+=(s^r)+a[3]-722521979)<<16|e>>>16)+i|0))+a[6]+76029189)<<23|r>>>9)+e|0,r=((r+=((s=(i=((i+=((h=r^e)^(t=((t+=(h^i)+a[9]-640364487)<<4|t>>>28)+r|0))+a[12]-421815835)<<11|i>>>21)+t|0)^t)^(e=((e+=(s^r)+a[15]+530742520)<<16|e>>>16)+i|0))+a[2]-995338651)<<23|r>>>9)+e|0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+a[0]-198630844)<<6|t>>>26)+r|0)|~e))+a[7]+1126891415)<<10|i>>>22)+t|0)^((e=((e+=(t^(i|~r))+a[14]-1416354905)<<15|e>>>17)+i|0)|~t))+a[5]-57434055)<<21|r>>>11)+e|0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+a[12]+1700485571)<<6|t>>>26)+r|0)|~e))+a[3]-1894986606)<<10|i>>>22)+t|0)^((e=((e+=(t^(i|~r))+a[10]-1051523)<<15|e>>>17)+i|0)|~t))+a[1]-2054922799)<<21|r>>>11)+e|0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+a[8]+1873313359)<<6|t>>>26)+r|0)|~e))+a[15]-30611744)<<10|i>>>22)+t|0)^((e=((e+=(t^(i|~r))+a[6]-1560198380)<<15|e>>>17)+i|0)|~t))+a[13]+1309151649)<<21|r>>>11)+e|0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+a[4]-145523070)<<6|t>>>26)+r|0)|~e))+a[11]-1120210379)<<10|i>>>22)+t|0)^((e=((e+=(t^(i|~r))+a[2]+718787259)<<15|e>>>17)+i|0)|~t))+a[9]-343485551)<<21|r>>>11)+e|0,this.first?(this.h0=t+1732584193|0,this.h1=r-271733879|0,this.h2=e-1732584194|0,this.h3=i+271733878|0,this.first=!1):(this.h0=this.h0+t|0,this.h1=this.h1+r|0,this.h2=this.h2+e|0,this.h3=this.h3+i|0)},A.prototype.hex=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return a[t>>>4&15]+a[15&t]+a[t>>>12&15]+a[t>>>8&15]+a[t>>>20&15]+a[t>>>16&15]+a[t>>>28&15]+a[t>>>24&15]+a[r>>>4&15]+a[15&r]+a[r>>>12&15]+a[r>>>8&15]+a[r>>>20&15]+a[r>>>16&15]+a[r>>>28&15]+a[r>>>24&15]+a[e>>>4&15]+a[15&e]+a[e>>>12&15]+a[e>>>8&15]+a[e>>>20&15]+a[e>>>16&15]+a[e>>>28&15]+a[e>>>24&15]+a[i>>>4&15]+a[15&i]+a[i>>>12&15]+a[i>>>8&15]+a[i>>>20&15]+a[i>>>16&15]+a[i>>>28&15]+a[i>>>24&15]},A.prototype.toString=A.prototype.hex,A.prototype.digest=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&r,r>>>8&255,r>>>16&255,r>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&i,i>>>8&255,i>>>16&255,i>>>24&255]},A.prototype.array=A.prototype.digest,A.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),r=new Uint32Array(t);return r[0]=this.h0,r[1]=this.h1,r[2]=this.h2,r[3]=this.h3,t},A.prototype.buffer=A.prototype.arrayBuffer,A.prototype.base64=function(){for(var t,r,e,i="",h=this.array(),s=0;s<15;)t=h[s++],r=h[s++],e=h[s++],i+=p[t>>>2]+p[63&(t<<4|r>>>4)]+p[63&(r<<2|e>>>6)]+p[63&e];return t=h[s],i+=p[t>>>2]+p[t<<4&63]+"=="},_.prototype=new A,_.prototype.finalize=function(){if(A.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();A.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(t),A.prototype.finalize.call(this)}};var B=function(){var t=v("hex");t.create=function(){return new A},t.update=function(r){return t.create().update(r)};for(var r=0;r<f.length;++r){var e=f[r];t[e]=v(e)}return t}();B.md5=B,B.md5.hmac=function(){var t=w("hex");t.create=function(t){return new _(t)},t.update=function(r,e){return t.create(r).update(e)};for(var r=0;r<f.length;++r){var e=f[r];t[e]=w(e)}return t}(),h?r.exports=B:i.md5=B}();var i=t(e.exports);export{i as default,i as md5};
|
package/utils.mjs
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
export function evaluate(source) {
|
|
2
|
-
const text = String(source)
|
|
3
|
-
.replace(/[,,\s]/g, "")
|
|
4
|
-
.replace(/×/g, "*")
|
|
5
|
-
.replace(/÷/g, "/");
|
|
6
|
-
let p = 0;
|
|
7
|
-
const eat = (c) => (text[p] === c ? (p++, true) : false);
|
|
8
|
-
function expr() {
|
|
9
|
-
let v = term();
|
|
10
|
-
for (;;) {
|
|
11
|
-
if (eat("+")) v += term();
|
|
12
|
-
else if (eat("-")) v -= term();
|
|
13
|
-
else return v;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function term() {
|
|
17
|
-
let v = unary();
|
|
18
|
-
for (;;) {
|
|
19
|
-
if (eat("*")) v *= unary();
|
|
20
|
-
else if (eat("/")) {
|
|
21
|
-
const d = unary();
|
|
22
|
-
if (d === 0) throw Error("不能除以零");
|
|
23
|
-
v /= d;
|
|
24
|
-
} else return v;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function unary() {
|
|
28
|
-
if (eat("+")) return unary();
|
|
29
|
-
if (eat("-")) return -unary();
|
|
30
|
-
return power();
|
|
31
|
-
}
|
|
32
|
-
function power() {
|
|
33
|
-
let v = primary();
|
|
34
|
-
while (eat("%")) v /= 100;
|
|
35
|
-
if (eat("^")) v = Math.pow(v, unary());
|
|
36
|
-
return v;
|
|
37
|
-
}
|
|
38
|
-
function primary() {
|
|
39
|
-
if (eat("(")) {
|
|
40
|
-
const v = expr();
|
|
41
|
-
if (!eat(")")) throw Error("缺少右括号");
|
|
42
|
-
return v;
|
|
43
|
-
}
|
|
44
|
-
const m = text.slice(p).match(/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?/i);
|
|
45
|
-
if (!m) throw Error("请输入有效的计算公式");
|
|
46
|
-
p += m[0].length;
|
|
47
|
-
return Number(m[0]);
|
|
48
|
-
}
|
|
49
|
-
if (!text) throw Error("表达式为空");
|
|
50
|
-
const v = expr();
|
|
51
|
-
if (p !== text.length || !Number.isFinite(v)) throw Error("计算公式不完整");
|
|
52
|
-
return Number(v.toPrecision(14));
|
|
53
|
-
}
|
|
54
|
-
export function renamePreview(files, rule) {
|
|
55
|
-
const targets = new Map();
|
|
56
|
-
const rows = files.map((file, i) => {
|
|
57
|
-
const dot = file.directory ? -1 : file.name.lastIndexOf(".");
|
|
58
|
-
const ext = dot > 0 ? file.name.slice(dot) : "";
|
|
59
|
-
let base = rule.extension
|
|
60
|
-
? file.name
|
|
61
|
-
: dot > 0
|
|
62
|
-
? file.name.slice(0, dot)
|
|
63
|
-
: file.name;
|
|
64
|
-
if (rule.mode === "replace") {
|
|
65
|
-
if (rule.find) {
|
|
66
|
-
base = rule.regex
|
|
67
|
-
? base.replace(new RegExp(rule.find, "g"), rule.replace)
|
|
68
|
-
: base.split(rule.find).join(rule.replace);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (rule.mode === "append") {
|
|
72
|
-
const seq = String(
|
|
73
|
-
(Number.isFinite(Number(rule.start)) ? Number(rule.start) : 1) +
|
|
74
|
-
i * (Number(rule.step) || 1),
|
|
75
|
-
).padStart(Number(rule.pad) || 1, "0");
|
|
76
|
-
const text = String(rule.text || "").replaceAll("{n}", seq);
|
|
77
|
-
base =
|
|
78
|
-
rule.position === "before"
|
|
79
|
-
? text + base
|
|
80
|
-
: rule.position === "at"
|
|
81
|
-
? base.slice(0, Number(rule.index) || 0) +
|
|
82
|
-
text +
|
|
83
|
-
base.slice(Number(rule.index) || 0)
|
|
84
|
-
: base + text;
|
|
85
|
-
}
|
|
86
|
-
if (rule.mode === "sequence")
|
|
87
|
-
base =
|
|
88
|
-
(rule.prefix || "") +
|
|
89
|
-
String(
|
|
90
|
-
(Number.isFinite(Number(rule.start)) ? Number(rule.start) : 1) +
|
|
91
|
-
i * (Number(rule.step) || 1),
|
|
92
|
-
).padStart(Number(rule.pad) || 1, "0") +
|
|
93
|
-
(rule.suffix || "");
|
|
94
|
-
if (rule.mode === "case")
|
|
95
|
-
base =
|
|
96
|
-
rule.case === "upper"
|
|
97
|
-
? base.toUpperCase()
|
|
98
|
-
: rule.case === "title"
|
|
99
|
-
? base.replace(/\b\p{L}/gu, (c) => c.toUpperCase())
|
|
100
|
-
: base.toLowerCase();
|
|
101
|
-
if (rule.mode === "manual")
|
|
102
|
-
base =
|
|
103
|
-
String(rule.lines || "")
|
|
104
|
-
.split("\n")
|
|
105
|
-
[i]?.trim() || base;
|
|
106
|
-
const name = base + (rule.extension ? "" : ext);
|
|
107
|
-
const stem = name.split(".")[0];
|
|
108
|
-
const invalid =
|
|
109
|
-
/[\\/:*?"<>|\x00-\x1f]/.test(name) ||
|
|
110
|
-
/[. ]$/.test(name) ||
|
|
111
|
-
!name ||
|
|
112
|
-
/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(stem);
|
|
113
|
-
const to = file.path.slice(0, file.path.length - file.name.length) + name;
|
|
114
|
-
const row = {
|
|
115
|
-
...file,
|
|
116
|
-
to,
|
|
117
|
-
newName: name,
|
|
118
|
-
error: invalid ? "文件名无效" : "",
|
|
119
|
-
changed: name !== file.name,
|
|
120
|
-
};
|
|
121
|
-
const key = to.toLowerCase();
|
|
122
|
-
if (targets.has(key)) {
|
|
123
|
-
row.error = "目标重名";
|
|
124
|
-
targets.get(key).error = "目标重名";
|
|
125
|
-
}
|
|
126
|
-
targets.set(key, row);
|
|
127
|
-
return row;
|
|
128
|
-
});
|
|
129
|
-
const existing = new Set(files.map((f) => f.path.toLowerCase()));
|
|
130
|
-
for (const row of rows)
|
|
131
|
-
if (row.changed && existing.has(row.to.toLowerCase()))
|
|
132
|
-
row.error = "目标已存在";
|
|
133
|
-
return rows;
|
|
134
|
-
}
|
|
135
|
-
export function jsonPath(value, path) {
|
|
136
|
-
const parts = String(path)
|
|
137
|
-
.trim()
|
|
138
|
-
.replace(/^\$\.?/, "")
|
|
139
|
-
.replace(/\[(\d+)\]/g, ".$1")
|
|
140
|
-
.split(".")
|
|
141
|
-
.filter(Boolean);
|
|
142
|
-
if (!parts.length) return value;
|
|
143
|
-
let values = [value];
|
|
144
|
-
let wildcard = false;
|
|
145
|
-
for (const part of parts) {
|
|
146
|
-
if (part === "*") {
|
|
147
|
-
wildcard = true;
|
|
148
|
-
values = values.flatMap((v) =>
|
|
149
|
-
v && typeof v === "object" ? Object.values(v) : [],
|
|
150
|
-
);
|
|
151
|
-
} else
|
|
152
|
-
values = values
|
|
153
|
-
.map((v) =>
|
|
154
|
-
v != null && Object.hasOwn(Object(v), part) ? v[part] : undefined,
|
|
155
|
-
)
|
|
156
|
-
.filter((v) => v !== undefined);
|
|
157
|
-
}
|
|
158
|
-
if (!values.length) throw Error("路径未匹配任何值");
|
|
159
|
-
return wildcard ? values : values[0];
|
|
160
|
-
}
|
|
161
|
-
export function toXml(value, name = "root") {
|
|
162
|
-
const esc = (s) =>
|
|
163
|
-
String(s ?? "").replace(
|
|
164
|
-
/[<>&"']/g,
|
|
165
|
-
(c) =>
|
|
166
|
-
({
|
|
167
|
-
"<": "<",
|
|
168
|
-
">": ">",
|
|
169
|
-
"&": "&",
|
|
170
|
-
'"': """,
|
|
171
|
-
"'": "'",
|
|
172
|
-
})[c],
|
|
173
|
-
);
|
|
174
|
-
const tag = /^[A-Za-z_][\w.-]*$/.test(name) ? name : "item";
|
|
175
|
-
if (Array.isArray(value))
|
|
176
|
-
return `<${tag}>${value.map((v) => toXml(v, "item")).join("")}</${tag}>`;
|
|
177
|
-
if (value && typeof value === "object")
|
|
178
|
-
return `<${tag}>${Object.entries(value)
|
|
179
|
-
.map(([k, v]) => toXml(v, k))
|
|
180
|
-
.join("")}</${tag}>`;
|
|
181
|
-
return `<${tag}>${esc(value)}</${tag}>`;
|
|
182
|
-
}
|
|
183
|
-
export function toTypescript(value) {
|
|
184
|
-
function type(v) {
|
|
185
|
-
if (v === null) return "null";
|
|
186
|
-
if (Array.isArray(v))
|
|
187
|
-
return v.length
|
|
188
|
-
? "(" + [...new Set(v.map(type))].join(" | ") + ")[]"
|
|
189
|
-
: "unknown[]";
|
|
190
|
-
if (typeof v === "object")
|
|
191
|
-
return (
|
|
192
|
-
"{\n" +
|
|
193
|
-
Object.entries(v)
|
|
194
|
-
.map(([k, x]) => " " + JSON.stringify(k) + ": " + type(x) + ";")
|
|
195
|
-
.join("\n") +
|
|
196
|
-
"\n}"
|
|
197
|
-
);
|
|
198
|
-
return typeof v;
|
|
199
|
-
}
|
|
200
|
-
return "type Root = " + type(value) + ";";
|
|
201
|
-
}
|