ms-vite-plugin 1.4.70 → 1.4.72

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(o){o.vararg=!0,t(o.body.body)}function a(o){switch(o.type){case"FuncExpr":s(o);break;case"UnaryExpr":a(o.arg);break;case"BinaryExpr":a(o.left),a(o.right);break;case"TableExpr":for(const e of o.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(o.object),a(o.index);break;case"MemberExpr":a(o.object);break;case"CallExpr":a(o.callee);for(const e of o.args)a(e);break;case"MethodCallExpr":a(o.object);for(const e of o.args)a(e);break;case"ParenExpr":a(o.exp);break;default:break}}function t(o){for(const e of o)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const r of e.exps)a(r);t(e.body.body);break;case"IfStat":for(const r of e.clauses)a(r.cond),t(r.body.body);e.elseBody&&t(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(e.func);break;case"LocalStat":if(e.exps)for(const r of e.exps)a(r);break;case"AssignStat":for(const r of e.vars)a(r);for(const r of e.exps)a(r);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const r of e.exps)a(r);break;default:break}}function c(o){t(o.body)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=r;function c(t){t.vararg=!0,s(t.body.body)}function a(t){switch(t.type){case"FuncExpr":c(t);break;case"UnaryExpr":a(t.arg);break;case"BinaryExpr":a(t.left),a(t.right);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(t.object),a(t.index);break;case"MemberExpr":a(t.object);break;case"CallExpr":a(t.callee);for(const e of t.args)a(e);break;case"MethodCallExpr":a(t.object);for(const e of t.args)a(e);break;case"ParenExpr":a(t.exp);break;default:break}}function s(t){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const o of e.exps)a(o);s(e.body.body);break;case"IfStat":for(const o of e.clauses)a(o.cond),s(o.body.body);e.elseBody&&s(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":c(e.func);break;case"LocalStat":if(e.exps)for(const o of e.exps)a(o);break;case"AssignStat":for(const o of e.vars)a(o);for(const o of e.exps)a(o);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const o of e.exps)a(o);break;default:break}}function r(t){s(t.body)}
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const o=require("./parser");function r(n){return(n>>>0)%9e3+100}function s(n,c){const a=c>>>0,l=r(a),e=a%17+3,t=l*e,d=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const c=require("./parser");function r(n){return(n>>>0)%9e3+100}function s(n,o){const a=o>>>0,l=r(a),e=a%17+3,t=l*e,d=`
2
2
  do
3
3
  local valid = true
4
4
  local acc = ${l}
@@ -23,4 +23,4 @@ do
23
23
  error("Tamper Detected!")
24
24
  end
25
25
  end
26
- `,i=(0,o.parseLua)(d);n.body.unshift(...i.body)}
26
+ `,i=(0,c.parseLua)(d);n.body.unshift(...i.body)}
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=q,exports.foldDecrypt=g,exports.emitFoldDecoderLua=b;const d=35184372088832n,i=[3,5,6,7,10,12,14,19,20,24];function m(e){const n=e>>>0||1;return{mul45:n%15*4+1,add45:n%99991*2+1,mul8:i[n%i.length],secret8:n%256}}function f(e,n){e.p=(e.p*BigInt(n.mul45)+BigInt(n.add45))%d;do e.q=e.q*n.mul8%257;while(e.q===1);const l=Number(e.p%256n),o=Number(e.p/256n%256n),t=Number(e.p/65536n%256n);return(l+o*(e.q%13)+t+e.q)%256}function p(e,n){return{p:BigInt(n>>>0)%d,q:(n>>>0)%255+2}}function h(e){const n=[];for(let l=0;l<e.length;l+=1){const o=e.charCodeAt(l);if(o<=255)n.push(o);else{const t=Buffer.from(e[l],"utf8");for(const c of t)n.push(c)}}return Buffer.from(n)}function q(e,n,l){const o=h(e),t=p(n,l);let c=n.secret8,r="";for(let u=0;u<o.length;u+=1){const a=f(t,n),s=o[u];r+=String.fromCharCode((s-a-c+512)%256),c=s}return r}function g(e,n,l){const o=p(n,l);let t=n.secret8;const c=Buffer.alloc(e.length);for(let r=0;r<e.length;r+=1){const u=f(o,n),a=(e.charCodeAt(r)+u+t)%256;c[r]=a,t=a}return c.toString("latin1")}function b(e,n){return`local ${n}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=q,exports.foldDecrypt=g,exports.emitFoldDecoderLua=b;const d=35184372088832n,i=[3,5,6,7,10,12,14,19,20,24];function m(t){const e=t>>>0||1;return{mul45:e%15*4+1,add45:e%99991*2+1,mul8:i[e%i.length],secret8:e%256}}function f(t,e){t.p=(t.p*BigInt(e.mul45)+BigInt(e.add45))%d;do t.q=t.q*e.mul8%257;while(t.q===1);const o=Number(t.p%256n),l=Number(t.p/256n%256n),c=Number(t.p/65536n%256n);return(o+l*(t.q%13)+c+t.q)%256}function p(t,e){return{p:BigInt(e>>>0)%d,q:(e>>>0)%255+2}}function h(t){const e=[];for(let o=0;o<t.length;o+=1){const l=t.charCodeAt(o);if(l<=255)e.push(l);else{const c=Buffer.from(t[o],"utf8");for(const n of c)e.push(n)}}return Buffer.from(e)}function q(t,e,o){const l=h(t),c=p(e,o);let n=e.secret8,r="";for(let u=0;u<l.length;u+=1){const a=f(c,e),s=l[u];r+=String.fromCharCode((s-a-n+512)%256),n=s}return r}function g(t,e,o){const l=p(e,o);let c=e.secret8;const n=Buffer.alloc(t.length);for(let r=0;r<t.length;r+=1){const u=f(l,e),a=(t.charCodeAt(r)+u+c)%256;n[r]=a,c=a}return n.toString("latin1")}function b(t,e){return`local ${e}
2
2
  do
3
- local mul45=${e.mul45}
4
- local add45=${e.add45}
5
- local mul8=${e.mul8}
6
- local secret8=${e.secret8}
3
+ local mul45=${t.mul45}
4
+ local add45=${t.add45}
5
+ local mul8=${t.mul8}
6
+ local secret8=${t.secret8}
7
7
  local cache={}
8
- ${n}=function(s,seed)
8
+ ${e}=function(s,seed)
9
9
  local hit=cache[seed]
10
10
  if hit then return hit end
11
11
  local p=seed%35184372088832
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(r,e=0,o=0,s=0){return this.ops.push(r),this.code.push([0,e,o,s]),this.code.length-1}patch(r,e,o,s){const a=this.code[r];e!==void 0&&(a[1]=e),o!==void 0&&(a[2]=o),s!==void 0&&(a[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(r){return this.intern({t:"bool",v:r})}kNum(r,e){return this.intern({t:"num",v:r,raw:e})}kStr(r){return this.intern({t:"str",v:r})}intern(r){for(let e=0;e<this.consts.length;e+=1){const o=this.consts[e];if(o.t===r.t&&(o.t==="nil"||o.t==="bool"&&r.t==="bool"&&o.v===r.v||o.t==="num"&&r.t==="num"&&o.v===r.v||o.t==="str"&&r.t==="str"&&o.v===r.v))return e+1}return this.consts.push(r),this.consts.length}alloc(r=1){const e=this.top;return this.top+=r,this.top-1>this.maxStack&&(this.maxStack=this.top-1),e}freeTo(r){this.top=r}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(r,e=!1){const o=this.alloc(1);return this.currentLocals().push({name:r,reg:o,close:e}),o}findLocal(r){for(let e=this.frames.length-1;e>=0;e-=1){const o=this.frames[e].locals;for(let s=o.length-1;s>=0;s-=1)if(o[s].name===r)return o[s].reg}}findUpval(r){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===r)return s+1;if(!this.parent)return;const e=this.parent.findLocal(r);if(e!==void 0)return this.upvals.push({name:r,inStack:!0,index:e}),this.upvals.length;const o=this.parent.findUpval(r);if(o!==void 0)return this.upvals.push({name:r,inStack:!1,index:o}),this.upvals.length}finish(){for(const r of this.gotos){const e=this.labels.get(r.name);if(e===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${r.name}::`);this.patch(r.pc,0,e-(r.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(t){const r=new O;return r.isVararg=!0,r.pushFrame(),u(r,t.body),r.emit("RETURN",1,0),r.finish()}function d(t,r){const e=new O;e.parent=t,e.numparams=r.params.length,e.isVararg=r.vararg,e.pushFrame();for(const o of r.params)e.bind(o);return u(e,r.body.body),e.emit("RETURN",1,0),t.protos.push(e.finish()),t.protos.length}function u(t,r){for(const e of r)B(t,e)}function p(t,r){for(const e of r.locals)t.emit("CLOSE",e.reg);t.freeTo(r.savedTop)}function B(t,r){switch(r.type){case"EmptyStat":return;case"BreakStat":{if(t.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const e=t.emit("JMP",0,0);t.breaks[t.breaks.length-1].push(e);return}case"GotoStat":{const e=t.emit("JMP",0,0);t.gotos.push({name:r.name,pc:e});return}case"LabelStat":t.labels.set(r.name,t.code.length);return;case"DoStat":{t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop());return}case"WhileStat":{const e=t.code.length,o=n(t,r.cond);t.emit("TEST",o,0,0);const s=t.emit("JMP",0,0);t.freeTo(o),t.breaks.push([]),t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,e-(t.code.length+1)),t.patch(s,0,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length);return}case"RepeatStat":{const e=t.code.length;t.breaks.push([]),t.pushFrame(),u(t,r.body.body);const o=n(t,r.cond);t.emit("TEST",o,0,0),t.emit("JMP",0,e-(t.code.length+1)),p(t,t.frames.pop()),f(t,t.breaks.pop(),t.code.length);return}case"IfStat":{const e=[];for(let o=0;o<r.clauses.length;o+=1){const s=n(t,r.clauses[o].cond);t.emit("TEST",s,0,0);const a=t.emit("JMP",0,0);t.freeTo(s),t.pushFrame(),u(t,r.clauses[o].body.body),p(t,t.frames.pop()),(o<r.clauses.length-1||r.elseBody)&&e.push(t.emit("JMP",0,0)),t.patch(a,0,t.code.length-(a+1))}r.elseBody&&(t.pushFrame(),u(t,r.elseBody.body),p(t,t.frames.pop()));for(const o of e)t.patch(o,0,t.code.length-(o+1));return}case"ForNumStat":{const e=t.alloc(4);n(t,r.start,e),n(t,r.end,e+1),r.step?n(t,r.step,e+2):t.emit("LOADK",e+2,t.kNum(1,"1"));const o=t.emit("FORPREP",e,0);t.breaks.push([]),t.pushFrame();const s=t.bind(r.name);t.emit("MOVE",s,e+3),u(t,r.body.body),p(t,t.frames.pop());const a=t.emit("FORLOOP",e,0);t.patch(o,e,a-(o+1)),t.patch(a,e,o+1-(a+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"ForInStat":{const e=t.alloc(3);h(t,r.exps,e,3);const o=t.emit("TFORCALL",e,r.names.length),s=t.emit("TFORLOOP",e,0);t.breaks.push([]),t.pushFrame();for(let a=0;a<r.names.length;a+=1){const i=t.bind(r.names[a]);t.emit("MOVE",i,e+3+a)}u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,o-(t.code.length+1)),t.patch(s,e,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"FuncStat":{const e=d(t,r.func),o=t.alloc(1);t.emit("CLOSURE",o,e),w(t,r.name.base,r.name.fields,r.name.method,o),t.freeTo(o);return}case"LocalFuncStat":{const e=t.bind(r.name),o=d(t,r.func);t.emit("CLOSURE",e,o);return}case"LocalStat":{const e=r.names.length,o=[];if(r.exps&&r.exps.length>0){const s=t.top;h(t,r.exps,s,e);for(let a=0;a<e;a+=1){const i=t.bind(r.names[a].name,r.names[a].attr==="close");t.emit("MOVE",i,s+a),o.push(i)}t.freeTo(o[0]),t.top=o[e-1]+1}else for(const s of r.names){const a=t.bind(s.name,s.attr==="close");t.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const e=t.top;h(t,r.exps,e,r.vars.length);for(let o=0;o<r.vars.length;o+=1)F(t,r.vars[o],e+o);t.freeTo(e);return}case"CallStat":{const e=t.top;n(t,r.exp,void 0,0),t.freeTo(e);return}case"ReturnStat":{if(r.exps.length===0){t.emit("RETURN",1,0);return}const e=t.top;h(t,r.exps,e,-1);const o=r.exps[r.exps.length-1],s=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";t.emit("RETURN",e,s?-1:r.exps.length);return}}}function f(t,r,e){for(const o of r)t.patch(o,0,e-(o+1))}function w(t,r,e,o,s){if(e.length===0&&!o){S(t,r,s);return}let a=T(t,r);const i=o?[...e,o]:e;for(let c=0;c<i.length-1;c+=1){const l=t.alloc(1);t.emit("GETTABLE",l,a,-t.kStr(i[c])),a=l}t.emit("SETTABLE",a,-t.kStr(i[i.length-1]),s)}function S(t,r,e){const o=t.findLocal(r);if(o!==void 0){t.emit("MOVE",o,e);return}const s=t.findUpval(r);if(s!==void 0){t.emit("SETUPVAL",e,s);return}t.emit("SETGLOBAL",e,t.kStr(r))}function T(t,r,e){const o=e??t.alloc(1),s=t.findLocal(r);if(s!==void 0)return o!==s&&t.emit("MOVE",o,s),o;const a=t.findUpval(r);return a!==void 0?(t.emit("GETUPVAL",o,a),o):(t.emit("GETGLOBAL",o,t.kStr(r)),o)}function F(t,r,e){if(r.type==="NameExpr"){S(t,r.name,e);return}if(r.type==="MemberExpr"){const o=n(t,r.object);t.emit("SETTABLE",o,-t.kStr(r.field),e);return}if(r.type==="IndexExpr"){const o=n(t,r.object),s=n(t,r.index);t.emit("SETTABLE",o,s,e);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function n(t,r,e,o=1){const s=e??t.alloc(1);switch(r.type){case"NilLiteral":return t.emit("LOADNIL",s),s;case"BoolLiteral":return t.emit("LOADBOOL",s,r.value?1:0),s;case"NumberLiteral":return t.emit("LOADK",s,t.kNum(r.value,r.raw)),s;case"StringLiteral":return t.emit("LOADK",s,t.kStr(r.value)),s;case"VarargExpr":return t.emit("VARARG",s,o),s;case"NameExpr":return T(t,r.name,s);case"ParenExpr":return n(t,r.exp,s,1);case"UnaryExpr":{const a=n(t,r.arg);return t.emit(A[r.op],s,a),s}case"BinaryExpr":return M(t,r.op,r.left,r.right,s);case"FuncExpr":{const a=d(t,r);return t.emit("CLOSURE",s,a),s}case"TableExpr":return R(t,r.fields,s);case"IndexExpr":{const a=n(t,r.object),i=n(t,r.index);return t.emit("GETTABLE",s,a,i),s}case"MemberExpr":{const a=n(t,r.object);return t.emit("GETTABLE",s,a,-t.kStr(r.field)),s}case"CallExpr":return y(t,r.callee,r.args,s,o,!1);case"MethodCallExpr":return y(t,r.object,r.args,s,o,r.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${r.type}`)}}function M(t,r,e,o,s){if(r==="and"||r==="or"){n(t,e,s),t.emit("TEST",s,0,r==="and"?0:1);const l=t.emit("JMP",0,0);return n(t,o,s),t.patch(l,0,t.code.length-(l+1)),s}if(r==="=="||r==="~="||r==="<"||r===">"||r==="<="||r===">="){const l=n(t,e),b=n(t,o);let m="EQ",g=l,E=b;r==="<"||r===">="?m="LT":r==="<="||r===">"?m="LE":m="EQ",(r===">"||r===">=")&&(g=b,E=l);const x=r==="~=";t.emit(m,g,E,x?1:0);const L=t.emit("JMP",0,0);t.emit("LOADBOOL",s,1);const v=t.emit("JMP",0,0);return t.patch(L,0,t.code.length-(L+1)),t.emit("LOADBOOL",s,0),t.patch(v,0,t.code.length-(v+1)),s}const a=k[r];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${r}`);const i=n(t,e),c=n(t,o);return t.emit(a,s,i,c),s}function N(t){return t.type==="CallExpr"||t.type==="MethodCallExpr"||t.type==="VarargExpr"}function y(t,r,e,o,s,a){const i=o,c=e.length>0&&N(e[e.length-1]);if(a){const l=n(t,r,i);return t.emit("SELF",i,l,-t.kStr(a)),h(t,e,i+2,-1),t.emit("CALL",i,c?-1:e.length+1,s),i}return n(t,r,i),h(t,e,i+1,-1),t.emit("CALL",i,c?-1:e.length,s),i}function h(t,r,e,o){const s=o>0?o:Math.max(r.length,1);if(t.top<e+s&&(t.top=e+s,t.top-1>t.maxStack&&(t.maxStack=t.top-1)),r.length===0){if(o>0)for(let a=0;a<o;a+=1)t.emit("LOADNIL",e+a);return}for(let a=0;a<r.length;a+=1){const i=a===r.length-1,c=i&&(o<0||o>r.length)?o===-1?-1:o-a:1;n(t,r[a],e+a,i?c:1)}if(o>r.length)for(let a=r.length;a<o;a+=1)t.emit("LOADNIL",e+a)}function R(t,r,e){t.emit("NEWTABLE",e);const o=[];for(const s of r)if(s.kind==="list")o.push(s.value);else if(s.kind==="name"){const a=n(t,s.value);t.emit("SETTABLE",e,-t.kStr(s.key),a)}else{const a=n(t,s.key),i=n(t,s.value);t.emit("SETTABLE",e,a,i)}if(o.length>0){const s=t.top;h(t,o,s,-1),t.emit("SETLIST",e,s,o.length),t.freeTo(s)}return e}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(n,t=0,o=0,s=0){return this.ops.push(n),this.code.push([0,t,o,s]),this.code.length-1}patch(n,t,o,s){const a=this.code[n];t!==void 0&&(a[1]=t),o!==void 0&&(a[2]=o),s!==void 0&&(a[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(n){return this.intern({t:"bool",v:n})}kNum(n,t){return this.intern({t:"num",v:n,raw:t})}kStr(n){return this.intern({t:"str",v:n})}intern(n){for(let t=0;t<this.consts.length;t+=1){const o=this.consts[t];if(o.t===n.t&&(o.t==="nil"||o.t==="bool"&&n.t==="bool"&&o.v===n.v||o.t==="num"&&n.t==="num"&&o.v===n.v||o.t==="str"&&n.t==="str"&&o.v===n.v))return t+1}return this.consts.push(n),this.consts.length}alloc(n=1){const t=this.top;return this.top+=n,this.top-1>this.maxStack&&(this.maxStack=this.top-1),t}freeTo(n){this.top=n}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(n,t=!1){const o=this.alloc(1);return this.currentLocals().push({name:n,reg:o,close:t}),o}findLocal(n){for(let t=this.frames.length-1;t>=0;t-=1){const o=this.frames[t].locals;for(let s=o.length-1;s>=0;s-=1)if(o[s].name===n)return o[s].reg}}findUpval(n){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===n)return s+1;if(!this.parent)return;const t=this.parent.findLocal(n);if(t!==void 0)return this.upvals.push({name:n,inStack:!0,index:t}),this.upvals.length;const o=this.parent.findUpval(n);if(o!==void 0)return this.upvals.push({name:n,inStack:!1,index:o}),this.upvals.length}finish(){for(const n of this.gotos){const t=this.labels.get(n.name);if(t===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${n.name}::`);this.patch(n.pc,0,t-(n.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(e){const n=new O;return n.isVararg=!0,n.pushFrame(),u(n,e.body),n.emit("RETURN",1,0),n.finish()}function d(e,n){const t=new O;t.parent=e,t.numparams=n.params.length,t.isVararg=n.vararg,t.pushFrame();for(const o of n.params)t.bind(o);return u(t,n.body.body),t.emit("RETURN",1,0),e.protos.push(t.finish()),e.protos.length}function u(e,n){for(const t of n)B(e,t)}function p(e,n){for(const t of n.locals)e.emit("CLOSE",t.reg);e.freeTo(n.savedTop)}function B(e,n){switch(n.type){case"EmptyStat":return;case"BreakStat":{if(e.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const t=e.emit("JMP",0,0);e.breaks[e.breaks.length-1].push(t);return}case"GotoStat":{const t=e.emit("JMP",0,0);e.gotos.push({name:n.name,pc:t});return}case"LabelStat":e.labels.set(n.name,e.code.length);return;case"DoStat":{e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop());return}case"WhileStat":{const t=e.code.length,o=r(e,n.cond);e.emit("TEST",o,0,0);const s=e.emit("JMP",0,0);e.freeTo(o),e.breaks.push([]),e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,t-(e.code.length+1)),e.patch(s,0,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length);return}case"RepeatStat":{const t=e.code.length;e.breaks.push([]),e.pushFrame(),u(e,n.body.body);const o=r(e,n.cond);e.emit("TEST",o,0,0),e.emit("JMP",0,t-(e.code.length+1)),p(e,e.frames.pop()),f(e,e.breaks.pop(),e.code.length);return}case"IfStat":{const t=[];for(let o=0;o<n.clauses.length;o+=1){const s=r(e,n.clauses[o].cond);e.emit("TEST",s,0,0);const a=e.emit("JMP",0,0);e.freeTo(s),e.pushFrame(),u(e,n.clauses[o].body.body),p(e,e.frames.pop()),(o<n.clauses.length-1||n.elseBody)&&t.push(e.emit("JMP",0,0)),e.patch(a,0,e.code.length-(a+1))}n.elseBody&&(e.pushFrame(),u(e,n.elseBody.body),p(e,e.frames.pop()));for(const o of t)e.patch(o,0,e.code.length-(o+1));return}case"ForNumStat":{const t=e.alloc(4);r(e,n.start,t),r(e,n.end,t+1),n.step?r(e,n.step,t+2):e.emit("LOADK",t+2,e.kNum(1,"1"));const o=e.emit("FORPREP",t,0);e.breaks.push([]),e.pushFrame();const s=e.bind(n.name);e.emit("MOVE",s,t+3),u(e,n.body.body),p(e,e.frames.pop());const a=e.emit("FORLOOP",t,0);e.patch(o,t,a-(o+1)),e.patch(a,t,o+1-(a+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"ForInStat":{const t=e.alloc(3);h(e,n.exps,t,3);const o=e.emit("TFORCALL",t,n.names.length),s=e.emit("TFORLOOP",t,0);e.breaks.push([]),e.pushFrame();for(let a=0;a<n.names.length;a+=1){const i=e.bind(n.names[a]);e.emit("MOVE",i,t+3+a)}u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,o-(e.code.length+1)),e.patch(s,t,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"FuncStat":{const t=d(e,n.func),o=e.alloc(1);e.emit("CLOSURE",o,t),w(e,n.name.base,n.name.fields,n.name.method,o),e.freeTo(o);return}case"LocalFuncStat":{const t=e.bind(n.name),o=d(e,n.func);e.emit("CLOSURE",t,o);return}case"LocalStat":{const t=n.names.length,o=[];if(n.exps&&n.exps.length>0){const s=e.top;h(e,n.exps,s,t);for(let a=0;a<t;a+=1){const i=e.bind(n.names[a].name,n.names[a].attr==="close");e.emit("MOVE",i,s+a),o.push(i)}e.freeTo(o[0]),e.top=o[t-1]+1}else for(const s of n.names){const a=e.bind(s.name,s.attr==="close");e.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const t=e.top;h(e,n.exps,t,n.vars.length);for(let o=0;o<n.vars.length;o+=1)F(e,n.vars[o],t+o);e.freeTo(t);return}case"CallStat":{const t=e.top;r(e,n.exp,void 0,0),e.freeTo(t);return}case"ReturnStat":{if(n.exps.length===0){e.emit("RETURN",1,0);return}const t=e.top;h(e,n.exps,t,-1);const o=n.exps[n.exps.length-1],s=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";e.emit("RETURN",t,s?-1:n.exps.length);return}}}function f(e,n,t){for(const o of n)e.patch(o,0,t-(o+1))}function w(e,n,t,o,s){if(t.length===0&&!o){S(e,n,s);return}let a=T(e,n);const i=o?[...t,o]:t;for(let c=0;c<i.length-1;c+=1){const l=e.alloc(1);e.emit("GETTABLE",l,a,-e.kStr(i[c])),a=l}e.emit("SETTABLE",a,-e.kStr(i[i.length-1]),s)}function S(e,n,t){const o=e.findLocal(n);if(o!==void 0){e.emit("MOVE",o,t);return}const s=e.findUpval(n);if(s!==void 0){e.emit("SETUPVAL",t,s);return}e.emit("SETGLOBAL",t,e.kStr(n))}function T(e,n,t){const o=t??e.alloc(1),s=e.findLocal(n);if(s!==void 0)return o!==s&&e.emit("MOVE",o,s),o;const a=e.findUpval(n);return a!==void 0?(e.emit("GETUPVAL",o,a),o):(e.emit("GETGLOBAL",o,e.kStr(n)),o)}function F(e,n,t){if(n.type==="NameExpr"){S(e,n.name,t);return}if(n.type==="MemberExpr"){const o=r(e,n.object);e.emit("SETTABLE",o,-e.kStr(n.field),t);return}if(n.type==="IndexExpr"){const o=r(e,n.object),s=r(e,n.index);e.emit("SETTABLE",o,s,t);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function r(e,n,t,o=1){const s=t??e.alloc(1);switch(n.type){case"NilLiteral":return e.emit("LOADNIL",s),s;case"BoolLiteral":return e.emit("LOADBOOL",s,n.value?1:0),s;case"NumberLiteral":return e.emit("LOADK",s,e.kNum(n.value,n.raw)),s;case"StringLiteral":return e.emit("LOADK",s,e.kStr(n.value)),s;case"VarargExpr":return e.emit("VARARG",s,o),s;case"NameExpr":return T(e,n.name,s);case"ParenExpr":return r(e,n.exp,s,1);case"UnaryExpr":{const a=r(e,n.arg);return e.emit(A[n.op],s,a),s}case"BinaryExpr":return M(e,n.op,n.left,n.right,s);case"FuncExpr":{const a=d(e,n);return e.emit("CLOSURE",s,a),s}case"TableExpr":return R(e,n.fields,s);case"IndexExpr":{const a=r(e,n.object),i=r(e,n.index);return e.emit("GETTABLE",s,a,i),s}case"MemberExpr":{const a=r(e,n.object);return e.emit("GETTABLE",s,a,-e.kStr(n.field)),s}case"CallExpr":return y(e,n.callee,n.args,s,o,!1);case"MethodCallExpr":return y(e,n.object,n.args,s,o,n.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${n.type}`)}}function M(e,n,t,o,s){if(n==="and"||n==="or"){r(e,t,s),e.emit("TEST",s,0,n==="and"?0:1);const l=e.emit("JMP",0,0);return r(e,o,s),e.patch(l,0,e.code.length-(l+1)),s}if(n==="=="||n==="~="||n==="<"||n===">"||n==="<="||n===">="){const l=r(e,t),b=r(e,o);let m="EQ",g=l,E=b;n==="<"||n===">="?m="LT":n==="<="||n===">"?m="LE":m="EQ",(n===">"||n===">=")&&(g=b,E=l);const x=n==="~=";e.emit(m,g,E,x?1:0);const L=e.emit("JMP",0,0);e.emit("LOADBOOL",s,1);const v=e.emit("JMP",0,0);return e.patch(L,0,e.code.length-(L+1)),e.emit("LOADBOOL",s,0),e.patch(v,0,e.code.length-(v+1)),s}const a=k[n];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${n}`);const i=r(e,t),c=r(e,o);return e.emit(a,s,i,c),s}function N(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"||e.type==="VarargExpr"}function y(e,n,t,o,s,a){const i=o,c=t.length>0&&N(t[t.length-1]);if(a){const l=r(e,n,i);return e.emit("SELF",i,l,-e.kStr(a)),h(e,t,i+2,-1),e.emit("CALL",i,c?-1:t.length+1,s),i}return r(e,n,i),h(e,t,i+1,-1),e.emit("CALL",i,c?-1:t.length,s),i}function h(e,n,t,o){const s=o>0?o:Math.max(n.length,1);if(e.top<t+s&&(e.top=t+s,e.top-1>e.maxStack&&(e.maxStack=e.top-1)),n.length===0){if(o>0)for(let a=0;a<o;a+=1)e.emit("LOADNIL",t+a);return}for(let a=0;a<n.length;a+=1){const i=a===n.length-1,c=i&&(o<0||o>n.length)?o===-1?-1:o-a:1;r(e,n[a],t+a,i?c:1)}if(o>n.length)for(let a=n.length;a<o;a+=1)e.emit("LOADNIL",t+a)}function R(e,n,t){e.emit("NEWTABLE",t);const o=[];for(const s of n)if(s.kind==="list")o.push(s.value);else if(s.kind==="name"){const a=r(e,s.value);e.emit("SETTABLE",t,-e.kStr(s.key),a)}else{const a=r(e,s.key),i=r(e,s.value);e.emit("SETTABLE",t,a,i)}if(o.length>0){const s=e.top;h(e,o,s,-1),e.emit("SETLIST",t,s,o.length),e.freeTo(s)}return t}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const i=require("./visit"),o="__C",y="__G";function g(l,s){const a=l.slice();let n=s>>>0||1;for(let r=a.length-1;r>0;r-=1){n=Math.imul(n,1664525)+1013904223>>>0;const t=n%(r+1),p=a[r];a[r]=a[t],a[t]=p}return a}function h(l,s,a){const n=[],r=new Set;if((0,i.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),n.push(e.value)),e)),n.length===0)return;let t=a.shuffle?g(n,s):n.slice();const p=a.rotate?s%t.length:0;p>0&&(t=t.slice(p).concat(t.slice(0,p)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,i.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const m=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),d={type:"LocalStat",names:[{name:o}],exps:[{type:"TableExpr",fields:m}]},f={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:o},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const o=require("./visit"),s="__C",y="__G";function g(l,i){const n=l.slice();let a=i>>>0||1;for(let r=n.length-1;r>0;r-=1){a=Math.imul(a,1664525)+1013904223>>>0;const t=a%(r+1),p=n[r];n[r]=n[t],n[t]=p}return n}function h(l,i,n){const a=[],r=new Set;if((0,o.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),a.push(e.value)),e)),a.length===0)return;let t=n.shuffle?g(a,i):a.slice();const p=n.rotate?i%t.length:0;p>0&&(t=t.slice(p).concat(t.slice(0,p)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,o.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const m=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),d={type:"LocalStat",names:[{name:s}],exps:[{type:"TableExpr",fields:m}]},f={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:s},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,o){return{type:"AssignStat",vars:t.map(e=>p(e)),exps:o}}function u(t,o){return f([t.stateName],[typeof o=="number"?m(o):o])}function k(t,o,e){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(t),right:m(o)},right:m(e)}}function E(t,o,e){return{type:"BinaryExpr",op:t,left:o,right:e}}function S(t){const o=`__t${t.nextTemp}`;return t.nextTemp+=1,t.temps.push(o),o}function x(t){const o=t.nextState;return t.nextState+=1,t.states.set(o,[]),o}function s(t,o,e){t.states.get(o).push(e)}function F(t,o){for(const e of t)if(e.type==="LocalStat")for(const a of e.names)o.push(a.name);else if(e.type==="LocalFuncStat")o.push(e.name);else if(e.type==="ForNumStat")o.push(e.name),F(e.body.body,o);else if(e.type==="ForInStat")o.push(...e.names),F(e.body.body,o);else if(e.type==="DoStat"||e.type==="WhileStat"||e.type==="RepeatStat")F(e.body.body,o);else if(e.type==="IfStat"){for(const a of e.clauses)F(a.body.body,o);e.elseBody&&F(e.elseBody.body,o)}}function h(t,o,e,a){if(t.length===0)return o;const y=t.map(()=>x(e));for(let n=0;n<t.length;n+=1){const r=t[n];r.type==="LabelStat"&&e.userLabels.set(r.name,y[n])}for(let n=0;n<t.length;n+=1){const r=n+1<t.length?y[n+1]:o;I(e,y[n],t[n],r,a)}return y[0]}function I(t,o,e,a,y){switch(e.type){case"EmptyStat":case"LabelStat":s(t,o,u(t,a));return;case"AssignStat":case"CallStat":case"FuncStat":s(t,o,e),s(t,o,u(t,a));return;case"LocalStat":e.exps&&e.exps.length>0&&s(t,o,f(e.names.map(n=>n.name),e.exps)),s(t,o,u(t,a));return;case"LocalFuncStat":s(t,o,f([e.name],[e.func])),s(t,o,u(t,a));return;case"ReturnStat":s(t,o,e);return;case"BreakStat":s(t,o,u(t,y));return;case"GotoStat":{const n=t.userLabels.get(e.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${e.name}::`);s(t,o,u(t,n));return}case"DoStat":s(t,o,u(t,h(e.body.body,a,t,y)));return;case"IfStat":{const n=S(t);let r=o;for(let l=0;l<e.clauses.length;l+=1){const b=l===e.clauses.length-1,d=h(e.clauses[l].body.body,a,t,y);let i=a;b?e.elseBody&&(i=h(e.elseBody.body,a,t,y)):i=x(t),s(t,r,f([n],[e.clauses[l].cond])),s(t,r,u(t,k(n,d,i))),b||(r=i)}e.clauses.length===0&&s(t,o,u(t,a));return}case"WhileStat":{const n=S(t),r=h(e.body.body,o,t,a);s(t,o,f([n],[e.cond])),s(t,o,u(t,k(n,r,a)));return}case"RepeatStat":{const n=S(t),r=x(t),l=h(e.body.body,r,t,a);s(t,o,u(t,l)),s(t,r,f([n],[e.cond])),s(t,r,u(t,k(n,a,l)));return}case"ForNumStat":{const n=e.name,r=S(t),l=S(t),b=S(t),d=x(t),i=x(t),L=x(t),g=x(t),N=h(e.body.body,g,t,a);s(t,o,f([n],[e.start])),s(t,o,f([r],[e.end])),s(t,o,f([l],[e.step??m(1)])),s(t,o,u(t,d)),s(t,d,f([b],[E(">=",p(l),m(0))])),s(t,d,u(t,k(b,i,L))),s(t,i,f([b],[E("<=",p(n),p(r))])),s(t,i,u(t,k(b,N,a))),s(t,L,f([b],[E(">=",p(n),p(r))])),s(t,L,u(t,k(b,N,a))),s(t,g,f([n],[E("+",p(n),p(l))])),s(t,g,u(t,d));return}case"ForInStat":{const n=S(t),r=S(t),l=S(t),b=S(t),d=x(t),i=[f([l],[p(e.names[0])]),...e.body.body],L=h(i,d,t,a),g=e.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});s(t,o,f([n,r,l],g.slice(0,3))),s(t,o,u(t,d)),s(t,d,{type:"AssignStat",vars:e.names.map(N=>p(N)),exps:[{type:"CallExpr",callee:p(n),args:[p(r),p(l)]}]}),s(t,d,f([b],[E("~=",p(e.names[0]),{type:"NilLiteral"})])),s(t,d,u(t,k(b,L,a)));return}default:s(t,o,u(t,a))}}function v(t,o){const e=t.slice();let a=o>>>0||1;for(let y=e.length-1;y>0;y-=1){a=Math.imul(a,1664525)+1013904223>>>0;const n=a%(y+1),r=e[y];e[y]=e[n],e[n]=r}return e}function w(t,o){if(t.length===0)return t;const e={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},a=[];F(t,a);const y=h(t,0,e,0),n=[...new Set([...a,...e.temps,e.stateName])],r=v([...e.states.keys()],o).map(l=>({cond:E("==",p(e.stateName),m(l)),body:{type:"Block",body:e.states.get(l)}}));return[{type:"LocalStat",names:n.map(l=>({name:l}))},f([e.stateName],[m(y)]),{type:"WhileStat",cond:E("~=",p(e.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:r}]}}]}function c(t,o){switch(t.type){case"FuncExpr":B(t.body.body,o),t.body.body=w(t.body.body,o);break;case"UnaryExpr":c(t.arg,o);break;case"BinaryExpr":c(t.left,o),c(t.right,o);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&c(e.key,o),c(e.value,o);break;case"IndexExpr":c(t.object,o),c(t.index,o);break;case"MemberExpr":c(t.object,o);break;case"CallExpr":c(t.callee,o);for(const e of t.args)c(e,o);break;case"MethodCallExpr":c(t.object,o);for(const e of t.args)c(e,o);break;case"ParenExpr":c(t.exp,o);break;default:break}}function B(t,o){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((e.type==="WhileStat"||e.type==="RepeatStat")&&c(e.cond,o),e.type==="ForNumStat"&&(c(e.start,o),c(e.end,o),e.step&&c(e.step,o)),e.type==="ForInStat")for(const a of e.exps)c(a,o);B(e.body.body,o);break;case"IfStat":for(const a of e.clauses)c(a.cond,o),B(a.body.body,o);e.elseBody&&B(e.elseBody.body,o);break;case"FuncStat":case"LocalFuncStat":B(e.func.body.body,o),e.func.body.body=w(e.func.body.body,o);break;case"LocalStat":if(e.exps)for(const a of e.exps)c(a,o);break;case"AssignStat":for(const a of e.vars)c(a,o);for(const a of e.exps)c(a,o);break;case"CallStat":c(e.exp,o);break;case"ReturnStat":for(const a of e.exps)c(a,o);break;default:break}}function C(t,o){B(t.body,o),t.body=w(t.body,o)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(e){return{type:"NumberLiteral",raw:String(e),value:e}}function y(e){return{type:"NameExpr",name:e}}function b(e,t){return{type:"AssignStat",vars:e.map(a=>y(a)),exps:t}}function u(e,t){return b([e.stateName],[typeof t=="number"?m(t):t])}function k(e,t,a){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:y(e),right:m(t)},right:m(a)}}function E(e,t,a){return{type:"BinaryExpr",op:e,left:t,right:a}}function S(e){const t=`__t${e.nextTemp}`;return e.nextTemp+=1,e.temps.push(t),t}function x(e){const t=e.nextState;return e.nextState+=1,e.states.set(t,[]),t}function r(e,t,a){e.states.get(t).push(a)}function L(e,t){for(const a of e)if(a.type==="LocalStat")for(const o of a.names)t.push(o.name);else if(a.type==="LocalFuncStat")t.push(a.name);else if(a.type==="ForNumStat")t.push(a.name),L(a.body.body,t);else if(a.type==="ForInStat")t.push(...a.names),L(a.body.body,t);else if(a.type==="DoStat"||a.type==="WhileStat"||a.type==="RepeatStat")L(a.body.body,t);else if(a.type==="IfStat"){for(const o of a.clauses)L(o.body.body,t);a.elseBody&&L(a.elseBody.body,t)}}function h(e,t,a,o){if(e.length===0)return t;const p=e.map(()=>x(a));for(let n=0;n<e.length;n+=1){const c=e[n];c.type==="LabelStat"&&a.userLabels.set(c.name,p[n])}for(let n=0;n<e.length;n+=1){const c=n+1<e.length?p[n+1]:t;I(a,p[n],e[n],c,o)}return p[0]}function I(e,t,a,o,p){switch(a.type){case"EmptyStat":case"LabelStat":r(e,t,u(e,o));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,t,a),r(e,t,u(e,o));return;case"LocalStat":a.exps&&a.exps.length>0&&r(e,t,b(a.names.map(n=>n.name),a.exps)),r(e,t,u(e,o));return;case"LocalFuncStat":r(e,t,b([a.name],[a.func])),r(e,t,u(e,o));return;case"ReturnStat":r(e,t,a);return;case"BreakStat":r(e,t,u(e,p));return;case"GotoStat":{const n=e.userLabels.get(a.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${a.name}::`);r(e,t,u(e,n));return}case"DoStat":r(e,t,u(e,h(a.body.body,o,e,p)));return;case"IfStat":{const n=S(e);let c=t;for(let l=0;l<a.clauses.length;l+=1){const f=l===a.clauses.length-1,d=h(a.clauses[l].body.body,o,e,p);let i=o;f?a.elseBody&&(i=h(a.elseBody.body,o,e,p)):i=x(e),r(e,c,b([n],[a.clauses[l].cond])),r(e,c,u(e,k(n,d,i))),f||(c=i)}a.clauses.length===0&&r(e,t,u(e,o));return}case"WhileStat":{const n=S(e),c=h(a.body.body,t,e,o);r(e,t,b([n],[a.cond])),r(e,t,u(e,k(n,c,o)));return}case"RepeatStat":{const n=S(e),c=x(e),l=h(a.body.body,c,e,o);r(e,t,u(e,l)),r(e,c,b([n],[a.cond])),r(e,c,u(e,k(n,o,l)));return}case"ForNumStat":{const n=a.name,c=S(e),l=S(e),f=S(e),d=x(e),i=x(e),F=x(e),g=x(e),N=h(a.body.body,g,e,o);r(e,t,b([n],[a.start])),r(e,t,b([c],[a.end])),r(e,t,b([l],[a.step??m(1)])),r(e,t,u(e,d)),r(e,d,b([f],[E(">=",y(l),m(0))])),r(e,d,u(e,k(f,i,F))),r(e,i,b([f],[E("<=",y(n),y(c))])),r(e,i,u(e,k(f,N,o))),r(e,F,b([f],[E(">=",y(n),y(c))])),r(e,F,u(e,k(f,N,o))),r(e,g,b([n],[E("+",y(n),y(l))])),r(e,g,u(e,d));return}case"ForInStat":{const n=S(e),c=S(e),l=S(e),f=S(e),d=x(e),i=[b([l],[y(a.names[0])]),...a.body.body],F=h(i,d,e,o),g=a.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(e,t,b([n,c,l],g.slice(0,3))),r(e,t,u(e,d)),r(e,d,{type:"AssignStat",vars:a.names.map(N=>y(N)),exps:[{type:"CallExpr",callee:y(n),args:[y(c),y(l)]}]}),r(e,d,b([f],[E("~=",y(a.names[0]),{type:"NilLiteral"})])),r(e,d,u(e,k(f,F,o)));return}default:r(e,t,u(e,o))}}function v(e,t){const a=e.slice();let o=t>>>0||1;for(let p=a.length-1;p>0;p-=1){o=Math.imul(o,1664525)+1013904223>>>0;const n=o%(p+1),c=a[p];a[p]=a[n],a[n]=c}return a}function w(e,t){if(e.length===0)return e;const a={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},o=[];L(e,o);const p=h(e,0,a,0),n=[...new Set([...o,...a.temps,a.stateName])],c=v([...a.states.keys()],t).map(l=>({cond:E("==",y(a.stateName),m(l)),body:{type:"Block",body:a.states.get(l)}}));return[{type:"LocalStat",names:n.map(l=>({name:l}))},b([a.stateName],[m(p)]),{type:"WhileStat",cond:E("~=",y(a.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:c}]}}]}function s(e,t){switch(e.type){case"FuncExpr":B(e.body.body,t),e.body.body=w(e.body.body,t);break;case"UnaryExpr":s(e.arg,t);break;case"BinaryExpr":s(e.left,t),s(e.right,t);break;case"TableExpr":for(const a of e.fields)a.kind==="index"&&s(a.key,t),s(a.value,t);break;case"IndexExpr":s(e.object,t),s(e.index,t);break;case"MemberExpr":s(e.object,t);break;case"CallExpr":s(e.callee,t);for(const a of e.args)s(a,t);break;case"MethodCallExpr":s(e.object,t);for(const a of e.args)s(a,t);break;case"ParenExpr":s(e.exp,t);break;default:break}}function B(e,t){for(const a of e)switch(a.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((a.type==="WhileStat"||a.type==="RepeatStat")&&s(a.cond,t),a.type==="ForNumStat"&&(s(a.start,t),s(a.end,t),a.step&&s(a.step,t)),a.type==="ForInStat")for(const o of a.exps)s(o,t);B(a.body.body,t);break;case"IfStat":for(const o of a.clauses)s(o.cond,t),B(o.body.body,t);a.elseBody&&B(a.elseBody.body,t);break;case"FuncStat":case"LocalFuncStat":B(a.func.body.body,t),a.func.body.body=w(a.func.body.body,t);break;case"LocalStat":if(a.exps)for(const o of a.exps)s(o,t);break;case"AssignStat":for(const o of a.vars)s(o,t);for(const o of a.exps)s(o,t);break;case"CallStat":s(a.exp,t);break;case"ReturnStat":for(const o of a.exps)s(o,t);break;default:break}}function C(e,t){B(e.body,t),e.body=w(e.body,t)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=E;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),u=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(n){let t=2166136261;for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return t>>>0||1}function o(n){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(n)))}function i(n,t,r){(0,y.applyConstantArray)(n,t,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(n,(t^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(n);return(0,m.renameLocals)(n),(0,c.minifyLua)(n)}function E(n,t){const r=P(n);let e=(0,p.parseLua)(n);return(0,m.renameLocals)(e),t==="Minify"?(0,c.minifyLua)(e):t==="Weak"?((0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):t==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var O=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return O.LuaLexError}});var g=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return g.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=E;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),n=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(t){let u=2166136261;for(let r=0;r<t.length;r+=1)u=Math.imul(u^t.charCodeAt(r),16777619);return u>>>0||1}function o(t){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(t)))}function i(t,u,r){(0,y.applyConstantArray)(t,u,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(t,(u^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(t);return(0,m.renameLocals)(t),(0,c.minifyLua)(t)}function E(t,u){const r=P(t);let e=(0,p.parseLua)(t);return(0,m.renameLocals)(e),u==="Minify"?(0,c.minifyLua)(e):u==="Weak"?((0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):u==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,n.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var O=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return O.LuaLexError}});var g=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return g.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=y;const L=require("./reserved");class F extends Error{constructor(s,l,c){super(`${s} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function y(v){const s=v.replace(/^\uFEFF/,""),l=[];let c=0,m=1,d=1;const r=(u=0)=>s[c+u]??"",h=()=>c>=s.length,e=()=>{const u=s[c++];return u===`
2
- `?(m+=1,d=1):d+=1,u},a=u=>{throw new F(u,m,d)},b=u=>u>="A"&&u<="Z"||u>="a"&&u<="z"||u==="_",E=u=>u>="0"&&u<="9",p=u=>E(u)||u>="a"&&u<="f"||u>="A"&&u<="F",C=u=>{const t=Buffer.from(u,"utf8");let n="";for(const i of t)n+=String.fromCharCode(i);return n},g=u=>u===" "||u===" "||u==="\r"||u===`
3
- `||u==="\f"||u==="\v",B=u=>{if(s[u]!=="[")return-1;let t=0,n=u+1;for(;s[n]==="=";)t+=1,n+=1;return s[n]==="["?t:-1},k=u=>{e();for(let n=0;n<u;n+=1)e();e(),r()==="\r"&&e(),r()===`
4
- `&&e();let t="";for(;!h();){if(r()==="]"){let n=c+1,i=0;for(;s[n]==="=";)i+=1,n+=1;if(i===u&&s[n]==="]"){e();for(let o=0;o<u;o+=1)e();return e(),t}}t+=C(e())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&r()!==`
5
- `;)e()},A=u=>{e();let t="";for(;!h();){const n=r();if(n===u)return e(),t;if(n===`
6
- `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(n!=="\\"){t+=C(e());continue}e();const i=r();if(i==="a")e(),t+="\x07";else if(i==="b")e(),t+="\b";else if(i==="f")e(),t+="\f";else if(i==="n")e(),t+=`
7
- `;else if(i==="r")e(),t+="\r";else if(i==="t")e(),t+=" ";else if(i==="v")e(),t+="\v";else if(i==="\\"||i==='"'||i==="'"||i===`
8
- `)t+=e();else if(i==="\r")e(),r()===`
9
- `&&e(),t+=`
10
- `;else if(i==="x"){e();const o=r(),f=r(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");e(),e(),t+=String.fromCharCode(parseInt(o+f,16))}else if(i==="u"){if(e(),r()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");e();let o="";for(;p(r());)o+=e();if(r()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");e(),t+=C(String.fromCodePoint(parseInt(o,16)))}else if(i==="z")for(e();g(r());)e();else if(E(i)){let o="";for(;E(r())&&o.length<3;)o+=e();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");t+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${i}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},D=()=>{const u=m,t=d;let n="";if(r()==="0"&&(r(1)==="x"||r(1)==="X")){for(n+=e(),n+=e();p(r())||r()===".";)n+=e();if(r()==="p"||r()==="P")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}else{for(;E(r())||r()===".";)n+=e();if(r()==="e"||r()==="E")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}const i=Number(n);if(!Number.isFinite(i))throw new F(`\u65E0\u6548\u6570\u5B57 ${n}`,u,t);return{kind:"number",value:n,line:u,column:t,parsed:i}};for(;!h();){const u=r();if(g(u)){e();continue}if(u==="-"&&r(1)==="-"){const f=m,$=d;e(),e();const x=B(c);x>=0?k(x):w();continue}const t=m,n=d;if(u==="'"||u==='"'){const f=A(u);l.push({kind:"string",value:f,line:t,column:n,parsed:f});continue}const i=B(c);if(i>=0){const f=k(i);l.push({kind:"string",value:f,line:t,column:n,parsed:f});continue}if(E(u)||u==="."&&E(r(1))){l.push(D());continue}if(b(u)){let f="";for(;b(r())||E(r());)f+=e();l.push({kind:L.luaKeywords.has(f)?"keyword":"name",value:f,line:t,column:n});continue}const o=u+r(1);if(o+r(2)==="..."){e(),e(),e(),l.push({kind:"vararg",value:"...",line:t,column:n});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){e(),e(),l.push({kind:o,value:o,line:t,column:n});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(u)){e(),l.push({kind:u,value:u,line:t,column:n});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(u)}`)}return l.push({kind:"eof",value:"",line:m,column:d}),l}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=y;const L=require("./reserved");class F extends Error{constructor(s,l,c){super(`${s} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function y(v){const s=v.replace(/^\uFEFF/,""),l=[];let c=0,m=1,d=1;const n=(e=0)=>s[c+e]??"",h=()=>c>=s.length,u=()=>{const e=s[c++];return e===`
2
+ `?(m+=1,d=1):d+=1,e},a=e=>{throw new F(e,m,d)},b=e=>e>="A"&&e<="Z"||e>="a"&&e<="z"||e==="_",E=e=>e>="0"&&e<="9",p=e=>E(e)||e>="a"&&e<="f"||e>="A"&&e<="F",C=e=>{const t=Buffer.from(e,"utf8");let r="";for(const i of t)r+=String.fromCharCode(i);return r},g=e=>e===" "||e===" "||e==="\r"||e===`
3
+ `||e==="\f"||e==="\v",B=e=>{if(s[e]!=="[")return-1;let t=0,r=e+1;for(;s[r]==="=";)t+=1,r+=1;return s[r]==="["?t:-1},k=e=>{u();for(let r=0;r<e;r+=1)u();u(),n()==="\r"&&u(),n()===`
4
+ `&&u();let t="";for(;!h();){if(n()==="]"){let r=c+1,i=0;for(;s[r]==="=";)i+=1,r+=1;if(i===e&&s[r]==="]"){u();for(let o=0;o<e;o+=1)u();return u(),t}}t+=C(u())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&n()!==`
5
+ `;)u()},A=e=>{u();let t="";for(;!h();){const r=n();if(r===e)return u(),t;if(r===`
6
+ `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){t+=C(u());continue}u();const i=n();if(i==="a")u(),t+="\x07";else if(i==="b")u(),t+="\b";else if(i==="f")u(),t+="\f";else if(i==="n")u(),t+=`
7
+ `;else if(i==="r")u(),t+="\r";else if(i==="t")u(),t+=" ";else if(i==="v")u(),t+="\v";else if(i==="\\"||i==='"'||i==="'"||i===`
8
+ `)t+=u();else if(i==="\r")u(),n()===`
9
+ `&&u(),t+=`
10
+ `;else if(i==="x"){u();const o=n(),f=n(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");u(),u(),t+=String.fromCharCode(parseInt(o+f,16))}else if(i==="u"){if(u(),n()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");u();let o="";for(;p(n());)o+=u();if(n()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");u(),t+=C(String.fromCodePoint(parseInt(o,16)))}else if(i==="z")for(u();g(n());)u();else if(E(i)){let o="";for(;E(n())&&o.length<3;)o+=u();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");t+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${i}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},D=()=>{const e=m,t=d;let r="";if(n()==="0"&&(n(1)==="x"||n(1)==="X")){for(r+=u(),r+=u();p(n())||n()===".";)r+=u();if(n()==="p"||n()==="P")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}else{for(;E(n())||n()===".";)r+=u();if(n()==="e"||n()==="E")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}const i=Number(r);if(!Number.isFinite(i))throw new F(`\u65E0\u6548\u6570\u5B57 ${r}`,e,t);return{kind:"number",value:r,line:e,column:t,parsed:i}};for(;!h();){const e=n();if(g(e)){u();continue}if(e==="-"&&n(1)==="-"){const f=m,$=d;u(),u();const x=B(c);x>=0?k(x):w();continue}const t=m,r=d;if(e==="'"||e==='"'){const f=A(e);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}const i=B(c);if(i>=0){const f=k(i);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}if(E(e)||e==="."&&E(n(1))){l.push(D());continue}if(b(e)){let f="";for(;b(n())||E(n());)f+=u();l.push({kind:L.luaKeywords.has(f)?"keyword":"name",value:f,line:t,column:r});continue}const o=e+n(1);if(o+n(2)==="..."){u(),u(),u(),l.push({kind:"vararg",value:"...",line:t,column:r});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){u(),u(),l.push({kind:o,value:o,line:t,column:r});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(e)){u(),l.push({kind:e,value:e,line:t,column:r});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(e)}`)}return l.push({kind:"eof",value:"",line:m,column:d}),l}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=p,exports.minifyLua=w;const l=new Set(["and","or"]);function p(e){let n='"';for(let a=0;a<e.length;a+=1){const u=e.charCodeAt(a)&255;n+=`\\${String(u).padStart(3,"0")}`}return n+='"',n}class i{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="word"}num(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="num"}punct(n){n===".."&&this.last==="num"&&this.parts.push(" "),n==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(n),this.last="punct"}toString(){return this.parts.join("")}}function w(e){const n=new i;return d(n,e.body,!0),n.toString()}function r(e,n){d(e,n.body,!1)}function d(e,n,a){for(let u=0;u<n.length;u+=1)h(e,n[u]),u<n.length-1&&e.punct(";")}function h(e,n){switch(n.type){case"EmptyStat":e.punct(";");return;case"BreakStat":e.word("break");return;case"GotoStat":e.word("goto"),e.word(n.name);return;case"LabelStat":e.punct("::"),e.word(n.name),e.punct("::");return;case"DoStat":e.word("do"),r(e,n.body),e.word("end");return;case"WhileStat":e.word("while"),o(e,n.cond),e.word("do"),r(e,n.body),e.word("end");return;case"RepeatStat":e.word("repeat"),r(e,n.body),e.word("until"),o(e,n.cond);return;case"IfStat":for(let a=0;a<n.clauses.length;a+=1)e.word(a===0?"if":"elseif"),o(e,n.clauses[a].cond),e.word("then"),r(e,n.clauses[a].body);n.elseBody&&(e.word("else"),r(e,n.elseBody)),e.word("end");return;case"ForNumStat":e.word("for"),e.word(n.name),e.punct("="),o(e,n.start),e.punct(","),o(e,n.end),n.step&&(e.punct(","),o(e,n.step)),e.word("do"),r(e,n.body),e.word("end");return;case"ForInStat":e.word("for");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a]);e.word("in"),s(e,n.exps),e.word("do"),r(e,n.body),e.word("end");return;case"FuncStat":e.word("function"),e.word(n.name.base);for(const a of n.name.fields)e.punct("."),e.word(a);n.name.method&&(e.punct(":"),e.word(n.name.method)),c(e,n.func,!!n.name.method);return;case"LocalFuncStat":e.word("local"),e.word("function"),e.word(n.name),c(e,n.func,!1);return;case"LocalStat":e.word("local");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a].name),n.names[a].attr&&(e.punct("<"),e.word(n.names[a].attr),e.punct(">"));n.exps&&n.exps.length>0&&(e.punct("="),s(e,n.exps));return;case"AssignStat":s(e,n.vars),e.punct("="),s(e,n.exps);return;case"CallStat":o(e,n.exp);return;case"ReturnStat":e.word("return"),n.exps.length>0&&s(e,n.exps);return}}function c(e,n,a){e.punct("(");const u=a?n.params.filter(t=>t!=="self"):n.params;for(let t=0;t<u.length;t+=1)t>0&&e.punct(","),e.word(u[t]);n.vararg&&(u.length>0&&e.punct(","),e.punct("...")),e.punct(")"),r(e,n.body),e.word("end")}function s(e,n){for(let a=0;a<n.length;a+=1)a>0&&e.punct(","),o(e,n[a])}function o(e,n){switch(n.type){case"NilLiteral":e.word("nil");return;case"BoolLiteral":e.word(n.value?"true":"false");return;case"NumberLiteral":e.num(n.raw);return;case"StringLiteral":e.punct(p(n.value));return;case"VarargExpr":e.punct("...");return;case"NameExpr":e.word(n.name);return;case"UnaryExpr":n.op==="not"?e.word("not"):e.punct(n.op),o(e,n.arg);return;case"BinaryExpr":o(e,n.left),l.has(n.op)?e.word(n.op):e.punct(n.op),o(e,n.right);return;case"FuncExpr":e.word("function"),c(e,n,!1);return;case"TableExpr":e.punct("{");for(let a=0;a<n.fields.length;a+=1)a>0&&e.punct(","),f(e,n.fields[a]);e.punct("}");return;case"IndexExpr":o(e,n.object),e.punct("["),o(e,n.index),e.punct("]");return;case"MemberExpr":o(e,n.object),e.punct("."),e.word(n.field);return;case"CallExpr":o(e,n.callee),e.punct("("),s(e,n.args),e.punct(")");return;case"MethodCallExpr":o(e,n.object),e.punct(":"),e.word(n.method),e.punct("("),s(e,n.args),e.punct(")");return;case"ParenExpr":e.punct("("),o(e,n.exp),e.punct(")");return}}function f(e,n){if(n.kind==="index"){e.punct("["),o(e,n.key),e.punct("]"),e.punct("="),o(e,n.value);return}if(n.kind==="name"){e.word(n.key),e.punct("="),o(e,n.value);return}o(e,n.value)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=e,exports.minifyLua=w;const l=new Set(["and","or"]);function e(t){let r='"';for(let a=0;a<t.length;a+=1){const u=t.charCodeAt(a)&255;r+=`\\${String(u).padStart(3,"0")}`}return r+='"',r}class i{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="word"}num(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="num"}punct(r){r===".."&&this.last==="num"&&this.parts.push(" "),r==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(r),this.last="punct"}toString(){return this.parts.join("")}}function w(t){const r=new i;return d(r,t.body,!0),r.toString()}function s(t,r){d(t,r.body,!1)}function d(t,r,a){for(let u=0;u<r.length;u+=1)h(t,r[u]),u<r.length-1&&t.punct(";")}function h(t,r){switch(r.type){case"EmptyStat":t.punct(";");return;case"BreakStat":t.word("break");return;case"GotoStat":t.word("goto"),t.word(r.name);return;case"LabelStat":t.punct("::"),t.word(r.name),t.punct("::");return;case"DoStat":t.word("do"),s(t,r.body),t.word("end");return;case"WhileStat":t.word("while"),o(t,r.cond),t.word("do"),s(t,r.body),t.word("end");return;case"RepeatStat":t.word("repeat"),s(t,r.body),t.word("until"),o(t,r.cond);return;case"IfStat":for(let a=0;a<r.clauses.length;a+=1)t.word(a===0?"if":"elseif"),o(t,r.clauses[a].cond),t.word("then"),s(t,r.clauses[a].body);r.elseBody&&(t.word("else"),s(t,r.elseBody)),t.word("end");return;case"ForNumStat":t.word("for"),t.word(r.name),t.punct("="),o(t,r.start),t.punct(","),o(t,r.end),r.step&&(t.punct(","),o(t,r.step)),t.word("do"),s(t,r.body),t.word("end");return;case"ForInStat":t.word("for");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a]);t.word("in"),c(t,r.exps),t.word("do"),s(t,r.body),t.word("end");return;case"FuncStat":t.word("function"),t.word(r.name.base);for(const a of r.name.fields)t.punct("."),t.word(a);r.name.method&&(t.punct(":"),t.word(r.name.method)),p(t,r.func,!!r.name.method);return;case"LocalFuncStat":t.word("local"),t.word("function"),t.word(r.name),p(t,r.func,!1);return;case"LocalStat":t.word("local");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a].name),r.names[a].attr&&(t.punct("<"),t.word(r.names[a].attr),t.punct(">"));r.exps&&r.exps.length>0&&(t.punct("="),c(t,r.exps));return;case"AssignStat":c(t,r.vars),t.punct("="),c(t,r.exps);return;case"CallStat":o(t,r.exp);return;case"ReturnStat":t.word("return"),r.exps.length>0&&c(t,r.exps);return}}function p(t,r,a){t.punct("(");const u=a?r.params.filter(n=>n!=="self"):r.params;for(let n=0;n<u.length;n+=1)n>0&&t.punct(","),t.word(u[n]);r.vararg&&(u.length>0&&t.punct(","),t.punct("...")),t.punct(")"),s(t,r.body),t.word("end")}function c(t,r){for(let a=0;a<r.length;a+=1)a>0&&t.punct(","),o(t,r[a])}function o(t,r){switch(r.type){case"NilLiteral":t.word("nil");return;case"BoolLiteral":t.word(r.value?"true":"false");return;case"NumberLiteral":t.num(r.raw);return;case"StringLiteral":t.punct(e(r.value));return;case"VarargExpr":t.punct("...");return;case"NameExpr":t.word(r.name);return;case"UnaryExpr":r.op==="not"?t.word("not"):t.punct(r.op),o(t,r.arg);return;case"BinaryExpr":o(t,r.left),l.has(r.op)?t.word(r.op):t.punct(r.op),o(t,r.right);return;case"FuncExpr":t.word("function"),p(t,r,!1);return;case"TableExpr":t.punct("{");for(let a=0;a<r.fields.length;a+=1)a>0&&t.punct(","),f(t,r.fields[a]);t.punct("}");return;case"IndexExpr":o(t,r.object),t.punct("["),o(t,r.index),t.punct("]");return;case"MemberExpr":o(t,r.object),t.punct("."),t.word(r.field);return;case"CallExpr":o(t,r.callee),t.punct("("),c(t,r.args),t.punct(")");return;case"MethodCallExpr":o(t,r.object),t.punct(":"),t.word(r.method),t.punct("("),c(t,r.args),t.punct(")");return;case"ParenExpr":t.punct("("),o(t,r.exp),t.punct(")");return}}function f(t,r){if(r.kind==="index"){t.punct("["),o(t,r.key),t.punct("]"),t.punct("="),o(t,r.value);return}if(r.kind==="name"){t.word(r.key),t.punct("="),o(t,r.value);return}o(t,r.value)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=t,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function t(S){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=S>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),e=E[O];E[O]=E[L],E[L]=e}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=t,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function t(e){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=e>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),S=E[O];E[O]=E[L],E[L]=S}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,l,p){super(`${b} (${l}:${p})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:p}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let l=0;const p=()=>b[l],u=(e,t)=>{const n=p();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),m=e=>{const t=p();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=p();return n.kind!==e||t!==void 0&&n.value!==t?m(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(l+=1,n)},o=(e,t)=>{if(u(e,t)){const n=p();return l+=1,n}},a=e=>w(e)?(l+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(p().kind==="keyword"&&e.includes(p().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||p().kind==="keyword"&&["end","else","elseif","until"].includes(p().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const h=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:h,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&m(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:m("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=p(),h=d.kind==="keyword"?d.value:d.kind;if(!t.includes(h))break;l+=1;const g=e();n={type:"BinaryExpr",op:h,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(l+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(l+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:m("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[l+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,l,p){super(`${b} (${l}:${p})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:p}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let l=0;const p=()=>b[l],u=(e,t)=>{const n=p();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),h=e=>{const t=p();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=p();return n.kind!==e||t!==void 0&&n.value!==t?h(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(l+=1,n)},o=(e,t)=>{if(u(e,t)){const n=p();return l+=1,n}},a=e=>w(e)?(l+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(p().kind==="keyword"&&e.includes(p().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||p().kind==="keyword"&&["end","else","elseif","until"].includes(p().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const m=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:m,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&h(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:h("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=p(),m=d.kind==="keyword"?d.value:d.kind;if(!t.includes(m))break;l+=1;const g=e();n={type:"BinaryExpr",op:m,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(l+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(l+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:h("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[l+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=r,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function r(a){let e=a,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(a){let e=0;const t=new Set;(0,d.collectAndRename)(a,(o,s)=>{if(o.newName!==o.original)return;let n=r(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=r(e),e+=1;o.newName=n,t.add(n),s.add(n)})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=o,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function o(a){let e=a,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(a){let e=0;const t=new Set;(0,d.collectAndRename)(a,(r,s)=>{if(r.newName!==r.original)return;let n=o(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=o(e),e+=1;r.newName=n,t.add(n),s.add(n)})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(t,o){let r=t;for(;r;){const e=r.locals.get(o);if(e)return e;r=r.parent}}function s(t){return{parent:t,locals:new Map}}function f(t,o){const r=t.locals.get(o);if(r)return r;const e={original:o,newName:o};return t.locals.set(o,e),e}function x(t,o){const r=new Set,e={locals:new Map};d(t.body,e,r,o)}function l(t,o,r,e){d(t.body,o,r,e)}function d(t,o,r,e){for(const c of t)b(c,o,r,e)}function m(t,o,r,e){const c=s(o),a=t.params.slice();for(let u=0;u<a.length;u+=1){const p=f(c,a[u]);e(p,r),t.params[u]=p.newName}l(t.body,c,r,e)}function b(t,o,r,e){switch(t.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":l(t.body,s(o),r,e);return;case"WhileStat":n(t.cond,o,r,e),l(t.body,s(o),r,e);return;case"RepeatStat":{const c=s(o);l(t.body,c,r,e),n(t.cond,c,r,e);return}case"IfStat":for(const c of t.clauses)n(c.cond,o,r,e),l(c.body,s(o),r,e);t.elseBody&&l(t.elseBody,s(o),r,e);return;case"ForNumStat":{n(t.start,o,r,e),n(t.end,o,r,e),t.step&&n(t.step,o,r,e);const c=s(o),a=f(c,t.name);e(a,r),t.name=a.newName,l(t.body,c,r,e);return}case"ForInStat":{for(const a of t.exps)n(a,o,r,e);const c=s(o);for(let a=0;a<t.names.length;a+=1){const u=f(c,t.names[a]);e(u,r),t.names[a]=u.newName}l(t.body,c,r,e);return}case"FuncStat":{const c=i(o,t.name.base);c&&(t.name.base=c.newName),m(t.func,o,r,e);return}case"LocalFuncStat":{const c=f(o,t.name);e(c,r),t.name=c.newName,m(t.func,o,r,e);return}case"LocalStat":if(t.exps)for(const c of t.exps)n(c,o,r,e);for(let c=0;c<t.names.length;c+=1){const a=f(o,t.names[c].name);e(a,r),t.names[c].name=a.newName}return;case"AssignStat":for(const c of t.vars)n(c,o,r,e);for(const c of t.exps)n(c,o,r,e);return;case"CallStat":n(t.exp,o,r,e);return;case"ReturnStat":for(const c of t.exps)n(c,o,r,e);return}}function n(t,o,r,e){switch(t.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const c=i(o,t.name);c&&(t.name=c.newName);return}case"UnaryExpr":n(t.arg,o,r,e);return;case"BinaryExpr":n(t.left,o,r,e),n(t.right,o,r,e);return;case"FuncExpr":m(t,o,r,e);return;case"TableExpr":for(const c of t.fields)c.kind==="index"&&n(c.key,o,r,e),n(c.value,o,r,e);return;case"IndexExpr":n(t.object,o,r,e),n(t.index,o,r,e);return;case"MemberExpr":n(t.object,o,r,e);return;case"CallExpr":n(t.callee,o,r,e);for(const c of t.args)n(c,o,r,e);return;case"MethodCallExpr":n(t.object,o,r,e);for(const c of t.args)n(c,o,r,e);return;case"ParenExpr":n(t.exp,o,r,e);return}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(e,o){let n=e;for(;n;){const a=n.locals.get(o);if(a)return a;n=n.parent}}function s(e){return{parent:e,locals:new Map}}function f(e,o){const n=e.locals.get(o);if(n)return n;const a={original:o,newName:o};return e.locals.set(o,a),a}function x(e,o){const n=new Set,a={locals:new Map};d(e.body,a,n,o)}function u(e,o,n,a){d(e.body,o,n,a)}function d(e,o,n,a){for(const c of e)b(c,o,n,a)}function m(e,o,n,a){const c=s(o),r=e.params.slice();for(let l=0;l<r.length;l+=1){const p=f(c,r[l]);a(p,n),e.params[l]=p.newName}u(e.body,c,n,a)}function b(e,o,n,a){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(e.body,s(o),n,a);return;case"WhileStat":t(e.cond,o,n,a),u(e.body,s(o),n,a);return;case"RepeatStat":{const c=s(o);u(e.body,c,n,a),t(e.cond,c,n,a);return}case"IfStat":for(const c of e.clauses)t(c.cond,o,n,a),u(c.body,s(o),n,a);e.elseBody&&u(e.elseBody,s(o),n,a);return;case"ForNumStat":{t(e.start,o,n,a),t(e.end,o,n,a),e.step&&t(e.step,o,n,a);const c=s(o),r=f(c,e.name);a(r,n),e.name=r.newName,u(e.body,c,n,a);return}case"ForInStat":{for(const r of e.exps)t(r,o,n,a);const c=s(o);for(let r=0;r<e.names.length;r+=1){const l=f(c,e.names[r]);a(l,n),e.names[r]=l.newName}u(e.body,c,n,a);return}case"FuncStat":{const c=i(o,e.name.base);c&&(e.name.base=c.newName),m(e.func,o,n,a);return}case"LocalFuncStat":{const c=f(o,e.name);a(c,n),e.name=c.newName,m(e.func,o,n,a);return}case"LocalStat":if(e.exps)for(const c of e.exps)t(c,o,n,a);for(let c=0;c<e.names.length;c+=1){const r=f(o,e.names[c].name);a(r,n),e.names[c].name=r.newName}return;case"AssignStat":for(const c of e.vars)t(c,o,n,a);for(const c of e.exps)t(c,o,n,a);return;case"CallStat":t(e.exp,o,n,a);return;case"ReturnStat":for(const c of e.exps)t(c,o,n,a);return}}function t(e,o,n,a){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const c=i(o,e.name);c&&(e.name=c.newName);return}case"UnaryExpr":t(e.arg,o,n,a);return;case"BinaryExpr":t(e.left,o,n,a),t(e.right,o,n,a);return;case"FuncExpr":m(e,o,n,a);return;case"TableExpr":for(const c of e.fields)c.kind==="index"&&t(c.key,o,n,a),t(c.value,o,n,a);return;case"IndexExpr":t(e.object,o,n,a),t(e.index,o,n,a);return;case"MemberExpr":t(e.object,o,n,a);return;case"CallExpr":t(e.callee,o,n,a);for(const c of e.args)t(c,o,n,a);return;case"MethodCallExpr":t(e.object,o,n,a);for(const c of e.args)t(c,o,n,a);return;case"ParenExpr":t(e.exp,o,n,a);return}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const u=require("./parser"),i=require("./visit"),o="__d";function d(t,l){let e=2166136261^l;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,l,e){const r=(0,a.foldEncrypt)(t,l,e);return{type:"CallExpr",callee:{type:"NameExpr",name:o},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,l){const e=(0,a.createFoldMixParams)(l);let r=0;(0,i.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const c=(0,u.parseLua)((0,a.emitFoldDecoderLua)(e,o));t.body.unshift(...c.body)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const u=require("./parser"),i=require("./visit"),l="__d";function d(t,o){let e=2166136261^o;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,o,e){const r=(0,a.foldEncrypt)(t,o,e);return{type:"CallExpr",callee:{type:"NameExpr",name:l},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,o){const e=(0,a.createFoldMixParams)(o);let r=0;(0,i.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const c=(0,u.parseLua)((0,a.emitFoldDecoderLua)(e,l));t.body.unshift(...c.body)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(r,e){switch(r.type){case"UnaryExpr":r.arg=s(r.arg,e);break;case"BinaryExpr":r.left=s(r.left,e),r.right=s(r.right,e);break;case"FuncExpr":b(r,e);break;case"TableExpr":for(const a of r.fields)a.kind==="index"&&(a.key=s(a.key,e)),a.value=s(a.value,e);break;case"IndexExpr":r.object=s(r.object,e),r.index=s(r.index,e);break;case"MemberExpr":r.object=s(r.object,e);break;case"CallExpr":r.callee=s(r.callee,e),r.args=r.args.map(a=>s(a,e));break;case"MethodCallExpr":r.object=s(r.object,e),r.args=r.args.map(a=>s(a,e));break;case"ParenExpr":r.exp=s(r.exp,e);break;default:break}return e(r)}function b(r,e){o(r.body.body,e)}function o(r,e){for(const a of r)switch(a.type){case"DoStat":o(a.body.body,e);break;case"WhileStat":a.cond=s(a.cond,e),o(a.body.body,e);break;case"RepeatStat":o(a.body.body,e),a.cond=s(a.cond,e);break;case"IfStat":for(const c of a.clauses)c.cond=s(c.cond,e),o(c.body.body,e);a.elseBody&&o(a.elseBody.body,e);break;case"ForNumStat":a.start=s(a.start,e),a.end=s(a.end,e),a.step&&(a.step=s(a.step,e)),o(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(c=>s(c,e)),o(a.body.body,e);break;case"FuncStat":b(a.func,e);break;case"LocalFuncStat":b(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(c=>s(c,e)));break;case"AssignStat":a.vars=a.vars.map(c=>s(c,e)),a.exps=a.exps.map(c=>s(c,e));break;case"CallStat":a.exp=s(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(c=>s(c,e));break;default:break}}function p(r,e){o(r.body,e)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(t,e){switch(t.type){case"UnaryExpr":t.arg=s(t.arg,e);break;case"BinaryExpr":t.left=s(t.left,e),t.right=s(t.right,e);break;case"FuncExpr":b(t,e);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&(a.key=s(a.key,e)),a.value=s(a.value,e);break;case"IndexExpr":t.object=s(t.object,e),t.index=s(t.index,e);break;case"MemberExpr":t.object=s(t.object,e);break;case"CallExpr":t.callee=s(t.callee,e),t.args=t.args.map(a=>s(a,e));break;case"MethodCallExpr":t.object=s(t.object,e),t.args=t.args.map(a=>s(a,e));break;case"ParenExpr":t.exp=s(t.exp,e);break;default:break}return e(t)}function b(t,e){o(t.body.body,e)}function o(t,e){for(const a of t)switch(a.type){case"DoStat":o(a.body.body,e);break;case"WhileStat":a.cond=s(a.cond,e),o(a.body.body,e);break;case"RepeatStat":o(a.body.body,e),a.cond=s(a.cond,e);break;case"IfStat":for(const c of a.clauses)c.cond=s(c.cond,e),o(c.body.body,e);a.elseBody&&o(a.elseBody.body,e);break;case"ForNumStat":a.start=s(a.start,e),a.end=s(a.end,e),a.step&&(a.step=s(a.step,e)),o(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(c=>s(c,e)),o(a.body.body,e);break;case"FuncStat":b(a.func,e);break;case"LocalFuncStat":b(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(c=>s(c,e)));break;case"AssignStat":a.vars=a.vars.map(c=>s(c,e)),a.exps=a.exps.map(c=>s(c,e));break;case"CallStat":a.exp=s(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(c=>s(c,e));break;default:break}}function p(t,e){o(t.body,e)}
@@ -365,11 +365,6 @@ device.setVolume(0.5);
365
365
 
366
366
  ### getOrientation - 获取屏幕方向。
367
367
 
368
- **注意事项**
369
-
370
- - 该方法返回的方向,是靠截屏方法来更新的,如果没有截屏,该方法返回的方向可能是不准确的。
371
- - 该方法取到的方向可能不准,建议使用截屏,靠截屏的图片宽高来确定方向
372
-
373
368
  ```typescript
374
369
  function getOrientation(): "PORTRAIT" | "LANDSCAPE";
375
370
  ```
package/docs/api/hid.md CHANGED
@@ -310,6 +310,26 @@ hid.click(100, 200);
310
310
  hid.click(300, 400);
311
311
  ```
312
312
 
313
+ ### setMoveDelay - 设置移动延迟
314
+
315
+ 设置移动完成后的等待毫秒。不调用时固件默认 40ms。可设为 0 关闭等待。
316
+
317
+ ```typescript
318
+ function setMoveDelay(milliseconds: number): boolean;
319
+ ```
320
+
321
+ **参数:**
322
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
323
+ | ---- | ---- | ---- | ------ | ---- |
324
+ | `milliseconds` | number | 是 | `40` | `0` 关闭,`>0` 覆盖毫秒,`<0` 恢复默认 |
325
+
326
+ **示例:**
327
+
328
+ ```javascript
329
+ hid.setMoveDelay(0);
330
+ hid.move(100, 200);
331
+ ```
332
+
313
333
  ## 基础触摸操作
314
334
 
315
335
  ### click - 点击操作
package/docs/api/image.md CHANGED
@@ -809,6 +809,66 @@ if (scaled.length > 0) {
809
809
  // const baseScale = expectedTargetWidthPx / templateWidthPx;
810
810
  ```
811
811
 
812
+ ### findImageEx - 按 kjst 找图
813
+
814
+ 用图色工具 Ex 导出的 `.kjst` 在大图上查找目标。模板、预处理、搜索区域和工作分辨率都写在 kjst 里,脚本只传大图和文件名。
815
+
816
+ 适合跨机分辨率:kjst 保存了制作时的工作宽高,运行时把当前图先缩放到该尺寸再匹配,返回的坐标已经换算回传入图(`screen` 即屏幕)像素,可直接 `action.click`。
817
+
818
+ ```typescript
819
+ function findImageEx(
820
+ imageId: string,
821
+ kjstPath: string,
822
+ ): {
823
+ index: number;
824
+ x: number;
825
+ y: number;
826
+ width: number;
827
+ height: number;
828
+ confidence: number;
829
+ centerX: number;
830
+ centerY: number;
831
+ ex: number;
832
+ ey: number;
833
+ text?: string; // 仅 OCR 命中
834
+ }[];
835
+ ```
836
+
837
+ **参数:**
838
+
839
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
840
+ | ----------- | ------ | -------- | ------ | -------------------------------------------------------------------------------------------- |
841
+ | `imageId` | string | 是 | - | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `findImage` 相同 |
842
+ | `kjstPath` | string | 是 | - | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
843
+
844
+ **返回值:**
845
+
846
+ | 类型 | 描述 |
847
+ | ------- | --------------------------------------------------------------------------------------------- |
848
+ | `array` | 命中矩形数组,字段与 `findImage` 相同。OCR 命中额外含 `text`。未找到或 kjst 无效时返回空数组 |
849
+
850
+ **说明:**
851
+
852
+ - 在 VS Code 图色工具 Ex 里制作 kjst,保存到项目 `res`。
853
+ - kjst 内可包含灰度、二值化、颜色反转、区域过滤,以及模板匹配 / OCR。预处理按顺序作用在图上;遇到模板匹配或 OCR 时,有命中立刻返回,没有命中才继续后面的步骤。
854
+ - 不要把 kjst 当普通图片路径传给 `findImage`。
855
+
856
+ **示例:**
857
+
858
+ ```javascript
859
+ const hits = image.findImageEx("screen", "login.kjst");
860
+ if (hits.length > 0) {
861
+ const hit = hits[0];
862
+ logi(hit.x, hit.y, hit.confidence);
863
+ action.click(hit.centerX, hit.centerY, 100, false);
864
+ }
865
+
866
+ const ocrHits = image.findImageEx("screen", "code.kjst");
867
+ if (ocrHits.length > 0 && ocrHits[0].text) {
868
+ logi(ocrHits[0].text);
869
+ }
870
+ ```
871
+
812
872
  ## 图像处理
813
873
 
814
874
  ### clip - 裁剪图片。
package/docs/api/yolo.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # YOLO 目标检测模块 (YOLO)
2
2
 
3
- YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
3
+ YOLO 模块基于 YOLOV5/YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
4
4
 
5
5
  ## 数据标注
6
6
 
@@ -8,7 +8,7 @@ YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能
8
8
 
9
9
  ## 功能概览
10
10
 
11
- - **模型管理**: YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
11
+ - **模型管理**: YOLOV5/YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
12
12
  - **目标检测**: 实时物体检测和位置识别
13
13
  - **多源输入**: 支持屏幕截图、图片文件、URL 等多种输入源
14
14
  - **结果处理**: 完整的检测结果信息和坐标数据
@@ -59,7 +59,7 @@ interface YoloResult {
59
59
 
60
60
  ### 模型管理
61
61
 
62
- #### load - 加载 YOLO 模型(支持版本 8/11/26)
62
+ #### load - 加载 YOLO 模型(支持版本 5/8/11/26)
63
63
 
64
64
  加载模型是使用目标检测功能的前提。
65
65
 
@@ -80,7 +80,7 @@ function load(
80
80
  | `paramPath` | string | 是 | | NCNN 模型的 param 文件绝对路径 |
81
81
  | `binPath` | string | 是 | | NCNN 模型的 bin 文件绝对路径 |
82
82
  | `nc` | number | 否 | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空数组 |
83
- | `version` | number | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26|
83
+ | `version` | number | 否 | 11 | YOLO 模型版本号(仅支持 5/8/11/26)。`5` 为官方 YOLOv5 6.0/6.2/7.0,兼容官方 export 单输出和三头原始特征 |
84
84
  | `useGpu` | boolean | 否 | false | 是否启用 GPU 加速 |
85
85
 
86
86
  **返回值:**
package/docs/apicn/hid.md CHANGED
@@ -310,6 +310,26 @@ $HID.点击(100, 200);
310
310
  $HID.点击(300, 400);
311
311
  ```
312
312
 
313
+ ### 设置移动延迟
314
+
315
+ 设置移动完成后的等待毫秒。不调用时固件默认 40ms。可设为 0 关闭等待。
316
+
317
+ ```typescript
318
+ function 设置移动延迟(毫秒: 数字): 布尔值;
319
+ ```
320
+
321
+ **参数:**
322
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
323
+ | ---- | ---- | ---- | ------ | ---- |
324
+ | `毫秒` | 数字 | 是 | `40` | `0` 关闭,`>0` 覆盖毫秒,`<0` 恢复默认 |
325
+
326
+ **示例:**
327
+
328
+ ```javascript
329
+ $HID.设置移动延迟(0);
330
+ $HID.移动(100, 200);
331
+ ```
332
+
313
333
  ## 基础触摸操作
314
334
 
315
335
  ### 点击
@@ -820,6 +820,66 @@ if (缩放匹配.length > 0) {
820
820
  // const baseScale = 预期目标宽度px / 模板宽度px;
821
821
  ```
822
822
 
823
+ ### 找图Ex - 按 kjst 找图
824
+
825
+ 用图色工具 Ex 导出的 `.kjst` 在大图上查找目标。模板、预处理、搜索区域和工作分辨率都写在 kjst 里,脚本只传大图和文件名。
826
+
827
+ 适合跨机分辨率:kjst 保存了制作时的工作宽高,运行时把当前图先缩放到该尺寸再匹配,返回的坐标已经换算回传入图(`screen` 即屏幕)像素,可直接 `$动作.点击`。
828
+
829
+ ```typescript
830
+ function 找图Ex(
831
+ 图片ID: 字符串,
832
+ kjst路径: 字符串,
833
+ ): {
834
+ index: 数字;
835
+ x: 数字;
836
+ y: 数字;
837
+ width: 数字;
838
+ height: 数字;
839
+ confidence: 数字;
840
+ centerX: 数字;
841
+ centerY: 数字;
842
+ ex: 数字;
843
+ ey: 数字;
844
+ text?: 字符串; // 仅 OCR 命中
845
+ }[];
846
+ ```
847
+
848
+ **参数:**
849
+
850
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
851
+ | ---------- | ------ | -------- | ------ | ------------------------------------------------------------------------------------- |
852
+ | `图片ID` | 字符串 | 是 | - | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `找图` 相同 |
853
+ | `kjst路径` | 字符串 | 是 | - | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
854
+
855
+ **返回值:**
856
+
857
+ | 类型 | 描述 |
858
+ | ------ | ------------------------------------------------------------------------------------------ |
859
+ | `数组` | 命中矩形数组,字段与 `找图` 相同。OCR 命中额外含 `text`。未找到或 kjst 无效时返回空数组 |
860
+
861
+ **说明:**
862
+
863
+ - 在 VS Code 图色工具 Ex 里制作 kjst,保存到项目 `res`。
864
+ - kjst 内可包含灰度、二值化、颜色反转、区域过滤,以及模板匹配 / OCR。预处理按顺序作用在图上;遇到模板匹配或 OCR 时,有命中立刻返回,没有命中才继续后面的步骤。
865
+ - 不要把 kjst 当普通图片路径传给 `找图`。
866
+
867
+ **示例:**
868
+
869
+ ```javascript
870
+ const 命中 = $图片.找图Ex("screen", "login.kjst");
871
+ if (命中.length > 0) {
872
+ const hit = 命中[0];
873
+ $打印信息日志(hit.x, hit.y, hit.confidence);
874
+ $动作.点击(hit.centerX, hit.centerY, 100, false);
875
+ }
876
+
877
+ const ocr命中 = $图片.找图Ex("screen", "code.kjst");
878
+ if (ocr命中.length > 0 && ocr命中[0].text) {
879
+ $打印信息日志(ocr命中[0].text);
880
+ }
881
+ ```
882
+
823
883
  ## 图像处理
824
884
 
825
885
  ### 裁剪图片
@@ -1,6 +1,6 @@
1
1
  # YOLO 目标检测模块 ($YOLO)
2
2
 
3
- YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
3
+ YOLO 模块基于 YOLOV5/YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
4
4
 
5
5
  ## 数据标注
6
6
 
@@ -8,7 +8,7 @@ YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能
8
8
 
9
9
  ## 功能概览
10
10
 
11
- - **模型管理**: YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
11
+ - **模型管理**: YOLOV5/YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
12
12
  - **目标检测**: 实时物体检测和位置识别
13
13
  - **多源输入**: 支持屏幕截图、图片文件、URL 等多种输入源
14
14
  - **结果处理**: 完整的检测结果信息和坐标数据
@@ -59,7 +59,7 @@ interface Yolo检测结果 {
59
59
 
60
60
  ### 模型管理
61
61
 
62
- #### 加载模型 - 加载 YOLO 模型(支持版本 8/11/26)
62
+ #### 加载模型 - 加载 YOLO 模型(支持版本 5/8/11/26)
63
63
 
64
64
  加载模型是使用目标检测功能的前提。
65
65
 
@@ -80,7 +80,7 @@ function 加载模型(
80
80
  | `ncnn模型的param文件路径` | 字符串 | 是 | | NCNN 模型的 param 文件绝对路径 |
81
81
  | `ncnn模型的bin文件路径` | 字符串 | 是 | | NCNN 模型的 bin 文件绝对路径 |
82
82
  | `标签数量` | 数字 | 否 | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空数组 |
83
- | `模型版本` | 数字 | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26|
83
+ | `模型版本` | 数字 | 否 | 11 | YOLO 模型版本号(仅支持 5/8/11/26)。`5` 为官方 YOLOv5 6.0/6.2/7.0,兼容官方 export 单输出和三头原始特征 |
84
84
  | `useGpu` | 布尔值 | 否 | false | 是否启用 GPU 加速 |
85
85
 
86
86
  **返回值:**
@@ -371,11 +371,6 @@ device.setVolume(0.5)
371
371
 
372
372
  ### getOrientation - 获取屏幕方向。
373
373
 
374
- **注意事项**
375
-
376
- - 该方法返回的方向,是靠截屏方法来更新的,如果没有截屏,该方法返回的方向可能是不准确的。
377
- - 该方法取到的方向可能不准,建议使用截屏,靠截屏的图片宽高来确定方向
378
-
379
374
  ```lua
380
375
  ---@return string
381
376
  function getOrientation() end
@@ -281,6 +281,28 @@ hid.click(100, 200)
281
281
  hid.click(300, 400)
282
282
  ```
283
283
 
284
+ ### setMoveDelay - 设置移动延迟
285
+
286
+ 设置移动完成后的等待毫秒。不调用时固件默认 40ms。可设为 0 关闭等待。
287
+
288
+ ```lua
289
+ ---@param milliseconds number
290
+ ---@return boolean
291
+ function setMoveDelay(milliseconds) end
292
+ ```
293
+
294
+ **参数:**
295
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
296
+ | ---- | ---- | ---- | ------ | ---- |
297
+ | `milliseconds` | number | 是 | `40` | `0` 关闭,`>0` 覆盖毫秒,`<0` 恢复默认 |
298
+
299
+ **示例:**
300
+
301
+ ```lua
302
+ hid.setMoveDelay(0)
303
+ hid.move(100, 200)
304
+ ```
305
+
284
306
  ## 基础触摸操作
285
307
 
286
308
  ### click - 点击操作
@@ -819,6 +819,54 @@ end
819
819
  -- local baseScale = expectedTargetWidthPx / templateWidthPx
820
820
  ```
821
821
 
822
+ ### findImageEx - 按 kjst 找图
823
+
824
+ 用图色工具 Ex 导出的 `.kjst` 在大图上查找目标。模板、预处理、搜索区域和工作分辨率都写在 kjst 里,脚本只传大图和文件名。
825
+
826
+ 适合跨机分辨率:kjst 保存了制作时的工作宽高,运行时把当前图先缩放到该尺寸再匹配,返回的坐标已经换算回传入图(`screen` 即屏幕)像素,可直接 `action.click`。
827
+
828
+ ```lua
829
+ ---@param id string
830
+ ---@param kjstPath string
831
+ ---@return table
832
+ function findImageEx(id, kjstPath) end
833
+ ```
834
+
835
+ **参数:**
836
+
837
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
838
+ | ----------- | ------ | -------- | ------ | -------------------------------------------------------------------------------------------- |
839
+ | `id` | string | 是 | - | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `findImage` 相同 |
840
+ | `kjstPath` | string | 是 | - | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
841
+
842
+ **返回值:**
843
+
844
+ | 类型 | 描述 |
845
+ | ------ | --------------------------------------------------------------------------------------------- |
846
+ | `table` | 命中矩形数组,字段与 `findImage` 相同。OCR 命中额外含 `text`。未找到或 kjst 无效时返回空表。下标从 1 开始 |
847
+
848
+ **说明:**
849
+
850
+ - 在 VS Code 图色工具 Ex 里制作 kjst,保存到项目 `res`。
851
+ - kjst 内可包含灰度、二值化、颜色反转、区域过滤,以及模板匹配 / OCR。预处理按顺序作用在图上;遇到模板匹配或 OCR 时,有命中立刻返回,没有命中才继续后面的步骤。
852
+ - 不要把 kjst 当普通图片路径传给 `findImage`。
853
+
854
+ **示例:**
855
+
856
+ ```lua
857
+ local hits = image.findImageEx("screen", "login.kjst")
858
+ if #hits > 0 then
859
+ local hit = hits[1]
860
+ print(hit.x, hit.y, hit.confidence)
861
+ action.click(hit.centerX, hit.centerY, 100, false)
862
+ end
863
+
864
+ local ocrHits = image.findImageEx("screen", "code.kjst")
865
+ if #ocrHits > 0 and ocrHits[1].text then
866
+ print(ocrHits[1].text)
867
+ end
868
+ ```
869
+
822
870
  ## 图像处理
823
871
 
824
872
  ### clip - 裁剪图片。
@@ -2,7 +2,7 @@
2
2
 
3
3
  模块表是内置全局 `yolo`,直接调用即可。不要 `require` 宿主模块。
4
4
 
5
- YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
5
+ YOLO 模块基于 YOLOV5/YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
6
6
 
7
7
  ## 数据标注
8
8
 
@@ -10,7 +10,7 @@ YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能
10
10
 
11
11
  ## 功能概览
12
12
 
13
- - **模型管理**: YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
13
+ - **模型管理**: YOLOV5/YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
14
14
  - **目标检测**: 实时物体检测和位置识别
15
15
  - **多源输入**: 支持屏幕截图、图片文件、URL 等多种输入源
16
16
  - **结果处理**: 完整的检测结果信息和坐标数据
@@ -60,7 +60,7 @@ YOLO 检测结果接口,包含检测到的物体的完整信息。
60
60
 
61
61
  ### 模型管理
62
62
 
63
- #### load - 加载 YOLO 模型(支持版本 8/11/26)。
63
+ #### load - 加载 YOLO 模型(支持版本 5/8/11/26)。
64
64
 
65
65
  加载模型是使用目标检测功能的前提。
66
66
 
@@ -81,7 +81,7 @@ function load(paramPath, binPath, nc, version, useGpu) end
81
81
  | `paramPath` | string | 是 | | NCNN 模型的 param 文件绝对路径 |
82
82
  | `binPath` | string | 是 | | NCNN 模型的 bin 文件绝对路径 |
83
83
  | `nc` | number | 否 | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空数组 |
84
- | `version` | number | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26|
84
+ | `version` | number | 否 | 11 | YOLO 模型版本号(仅支持 5/8/11/26)。`5` 为官方 YOLOv5 6.0/6.2/7.0,兼容官方 export 单输出和三头原始特征 |
85
85
  | `useGpu` | boolean | 否 | false | 是否启用 GPU 加速 |
86
86
 
87
87
  **返回值:**
@@ -362,10 +362,6 @@ device.setVolume(0.5)
362
362
 
363
363
  ### getOrientation - 获取屏幕方向。
364
364
 
365
- **注意事项:**
366
-
367
- - 方向依赖截屏更新;若未截屏可能不准确。建议通过截屏宽高判断方向
368
-
369
365
  ```python
370
366
  from typing import Literal
371
367
 
@@ -320,6 +320,27 @@ hid.click(100, 200)
320
320
  hid.click(300, 400)
321
321
  ```
322
322
 
323
+ ### setMoveDelay - 设置移动延迟
324
+
325
+ 设置移动完成后的等待毫秒。不调用时固件默认 40ms。可设为 0 关闭等待。
326
+
327
+ ```python
328
+ def setMoveDelay(milliseconds: int) -> bool
329
+ ```
330
+
331
+ **参数:**
332
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
333
+ | ---- | ---- | ---- | ------ | ---- |
334
+ | `milliseconds` | int | 是 | `40` | `0` 关闭,`>0` 覆盖毫秒,`<0` 恢复默认 |
335
+
336
+ **示例:**
337
+
338
+ ```python
339
+ from kuaijs import hid
340
+ hid.setMoveDelay(0)
341
+ hid.move(100, 200)
342
+ ```
343
+
323
344
  ## 基础触摸操作
324
345
 
325
346
  ### click - 点击操作
@@ -752,6 +752,51 @@ if len(scaled) > 0:
752
752
  # base_scale = expected_target_width_px / template_width_px
753
753
  ```
754
754
 
755
+ ### findImageEx - 按 kjst 找图
756
+
757
+ 用图色工具 Ex 导出的 `.kjst` 在大图上查找目标。模板、预处理、搜索区域和工作分辨率都写在 kjst 里,脚本只传大图和文件名。
758
+
759
+ 适合跨机分辨率:kjst 保存了制作时的工作宽高,运行时把当前图先缩放到该尺寸再匹配,返回的坐标已经换算回传入图(`screen` 即屏幕)像素,可直接 `action.click`。
760
+
761
+ ```python
762
+ def findImageEx(id: str, kjstPath: str) -> List[Rect]
763
+ ```
764
+
765
+ **参数:**
766
+
767
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
768
+ | ----------- | ---- | -------- | ------ | -------------------------------------------------------------------------------------------- |
769
+ | `id` | str | 是 | <br /> | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `findImage` 相同 |
770
+ | `kjstPath` | str | 是 | <br /> | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
771
+
772
+ **返回值:**
773
+
774
+ | 类型 | 描述 |
775
+ | ------------ | --------------------------------------------------------------------------------------------- |
776
+ | `List[Rect]` | 命中矩形列表,字段与 `findImage` 相同。OCR 命中额外含 `text`。未找到或 kjst 无效时返回空列表 |
777
+
778
+ **说明:**
779
+
780
+ - 在 VS Code 图色工具 Ex 里制作 kjst,保存到项目 `res`。
781
+ - kjst 内可包含灰度、二值化、颜色反转、区域过滤,以及模板匹配 / OCR。预处理按顺序作用在图上;遇到模板匹配或 OCR 时,有命中立刻返回,没有命中才继续后面的步骤。
782
+ - 不要把 kjst 当普通图片路径传给 `findImage`。
783
+
784
+ **示例:**
785
+
786
+ ```python
787
+ from kuaijs import image, action
788
+
789
+ hits = image.findImageEx("screen", "login.kjst")
790
+ if hits:
791
+ hit = hits[0]
792
+ print(hit.x, hit.y, hit.confidence)
793
+ action.click(hit.centerX, hit.centerY, 100, False)
794
+
795
+ ocr_hits = image.findImageEx("screen", "code.kjst")
796
+ if ocr_hits and ocr_hits[0].text:
797
+ print(ocr_hits[0].text)
798
+ ```
799
+
755
800
  ## 图像处理
756
801
 
757
802
  ### clip - 裁剪图片。
@@ -1,6 +1,6 @@
1
1
  # YOLO 目标检测模块 (YOLO)
2
2
 
3
- YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
3
+ YOLO 模块基于 YOLOV5/YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能的实时目标检测功能,支持多种输入源和自定义模型,可用于物体识别、位置定位等应用场景。
4
4
 
5
5
  ## 数据标注
6
6
 
@@ -8,7 +8,7 @@ YOLO 模块基于 YOLOV8/YOLO11/YOLO26 算法和 NCNN 框架,提供高性能
8
8
 
9
9
  ## 功能概览
10
10
 
11
- - **模型管理**: YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
11
+ - **模型管理**: YOLOV5/YOLOV8/YOLOV11/YOLOV26 模型加载和资源管理
12
12
  - **目标检测**: 实时物体检测和位置识别
13
13
  - **多源输入**: 支持屏幕截图、图片文件、URL 等多种输入源
14
14
  - **结果处理**: 完整的检测结果信息和坐标数据
@@ -60,7 +60,7 @@ class YoloResult(KuaiJSNamespace):
60
60
 
61
61
  ### 模型管理
62
62
 
63
- #### load - 加载 YOLO 模型(支持版本 8/11/26)
63
+ #### load - 加载 YOLO 模型(支持版本 5/8/11/26)
64
64
 
65
65
  加载模型是使用目标检测功能的前提。
66
66
 
@@ -75,7 +75,7 @@ def load(paramPath: str, binPath: str, nc: int = 0, version: int = 11, useGpu: b
75
75
  | `paramPath` | str | 是 | - | NCNN 模型的 param 文件绝对路径 |
76
76
  | `binPath` | str | 是 | - | NCNN 模型的 bin 文件绝对路径 |
77
77
  | `nc` | int | 否 | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空列表 |
78
- | `version` | int | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26|
78
+ | `version` | int | 否 | 11 | YOLO 模型版本号(仅支持 5/8/11/26)。`5` 为官方 YOLOv5 6.0/6.2/7.0,兼容官方 export 单输出和三头原始特征 |
79
79
  | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
80
80
 
81
81
  **返回值:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.4.70",
3
+ "version": "1.4.72",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {