ms-vite-plugin 1.4.78 → 1.4.80

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=o;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 r of e.exps)a(r);s(e.body.body);break;case"IfStat":for(const r of e.clauses)a(r.cond),s(r.body.body);e.elseBody&&s(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":c(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 o(t){s(t.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 +1 @@
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
+ "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 s of a.names)t.push(s.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 s of a.clauses)L(s.body.body,t);a.elseBody&&L(a.elseBody.body,t)}}function h(e,t,a,s){if(e.length===0)return t;const p=e.map(()=>x(a));for(let o=0;o<e.length;o+=1){const c=e[o];c.type==="LabelStat"&&a.userLabels.set(c.name,p[o])}for(let o=0;o<e.length;o+=1){const c=o+1<e.length?p[o+1]:t;I(a,p[o],e[o],c,s)}return p[0]}function I(e,t,a,s,p){switch(a.type){case"EmptyStat":case"LabelStat":r(e,t,u(e,s));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,t,a),r(e,t,u(e,s));return;case"LocalStat":a.exps&&a.exps.length>0&&r(e,t,b(a.names.map(o=>o.name),a.exps)),r(e,t,u(e,s));return;case"LocalFuncStat":r(e,t,b([a.name],[a.func])),r(e,t,u(e,s));return;case"ReturnStat":r(e,t,a);return;case"BreakStat":r(e,t,u(e,p));return;case"GotoStat":{const o=e.userLabels.get(a.name);if(o===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${a.name}::`);r(e,t,u(e,o));return}case"DoStat":r(e,t,u(e,h(a.body.body,s,e,p)));return;case"IfStat":{const o=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,s,e,p);let i=s;f?a.elseBody&&(i=h(a.elseBody.body,s,e,p)):i=x(e),r(e,c,b([o],[a.clauses[l].cond])),r(e,c,u(e,k(o,d,i))),f||(c=i)}a.clauses.length===0&&r(e,t,u(e,s));return}case"WhileStat":{const o=S(e),c=h(a.body.body,t,e,s);r(e,t,b([o],[a.cond])),r(e,t,u(e,k(o,c,s)));return}case"RepeatStat":{const o=S(e),c=x(e),l=h(a.body.body,c,e,s);r(e,t,u(e,l)),r(e,c,b([o],[a.cond])),r(e,c,u(e,k(o,s,l)));return}case"ForNumStat":{const o=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,s);r(e,t,b([o],[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(o),y(c))])),r(e,i,u(e,k(f,N,s))),r(e,F,b([f],[E(">=",y(o),y(c))])),r(e,F,u(e,k(f,N,s))),r(e,g,b([o],[E("+",y(o),y(l))])),r(e,g,u(e,d));return}case"ForInStat":{const o=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,s),g=a.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(e,t,b([o,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(o),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,s)));return}default:r(e,t,u(e,s))}}function v(e,t){const a=e.slice();let s=t>>>0||1;for(let p=a.length-1;p>0;p-=1){s=Math.imul(s,1664525)+1013904223>>>0;const o=s%(p+1),c=a[p];a[p]=a[o],a[o]=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},s=[];L(e,s);const p=h(e,0,a,0),o=[...new Set([...s,...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:o.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 n(e,t){switch(e.type){case"FuncExpr":B(e.body.body,t),e.body.body=w(e.body.body,t);break;case"UnaryExpr":n(e.arg,t);break;case"BinaryExpr":n(e.left,t),n(e.right,t);break;case"TableExpr":for(const a of e.fields)a.kind==="index"&&n(a.key,t),n(a.value,t);break;case"IndexExpr":n(e.object,t),n(e.index,t);break;case"MemberExpr":n(e.object,t);break;case"CallExpr":n(e.callee,t);for(const a of e.args)n(a,t);break;case"MethodCallExpr":n(e.object,t);for(const a of e.args)n(a,t);break;case"ParenExpr":n(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")&&n(a.cond,t),a.type==="ForNumStat"&&(n(a.start,t),n(a.end,t),a.step&&n(a.step,t)),a.type==="ForInStat")for(const s of a.exps)n(s,t);B(a.body.body,t);break;case"IfStat":for(const s of a.clauses)n(s.cond,t),B(s.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 s of a.exps)n(s,t);break;case"AssignStat":for(const s of a.vars)n(s,t);for(const s of a.exps)n(s,t);break;case"CallStat":n(a.exp,t);break;case"ReturnStat":for(const s of a.exps)n(s,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.shortName=o,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function o(r){let e=r,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(r){let e=0;const t=new Set;(0,d.collectAndRename)(r,(a,s)=>{if(a.newName!==a.original)return;let n=o(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=o(e),e+=1;a.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(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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(e,s){let n=e;for(;n;){const a=n.locals.get(s);if(a)return a;n=n.parent}}function c(e){return{parent:e,locals:new Map}}function f(e,s){const n=e.locals.get(s);if(n)return n;const a={original:s,newName:s};return e.locals.set(s,a),a}function x(e,s){const n=new Set,a={locals:new Map};d(e.body,a,n,s)}function u(e,s,n,a){d(e.body,s,n,a)}function d(e,s,n,a){for(const o of e)b(o,s,n,a)}function m(e,s,n,a){const o=c(s),r=e.params.slice();for(let l=0;l<r.length;l+=1){const p=f(o,r[l]);a(p,n),e.params[l]=p.newName}u(e.body,o,n,a)}function b(e,s,n,a){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(e.body,c(s),n,a);return;case"WhileStat":t(e.cond,s,n,a),u(e.body,c(s),n,a);return;case"RepeatStat":{const o=c(s);u(e.body,o,n,a),t(e.cond,o,n,a);return}case"IfStat":for(const o of e.clauses)t(o.cond,s,n,a),u(o.body,c(s),n,a);e.elseBody&&u(e.elseBody,c(s),n,a);return;case"ForNumStat":{t(e.start,s,n,a),t(e.end,s,n,a),e.step&&t(e.step,s,n,a);const o=c(s),r=f(o,e.name);a(r,n),e.name=r.newName,u(e.body,o,n,a);return}case"ForInStat":{for(const r of e.exps)t(r,s,n,a);const o=c(s);for(let r=0;r<e.names.length;r+=1){const l=f(o,e.names[r]);a(l,n),e.names[r]=l.newName}u(e.body,o,n,a);return}case"FuncStat":{const o=i(s,e.name.base);o&&(e.name.base=o.newName),m(e.func,s,n,a);return}case"LocalFuncStat":{const o=f(s,e.name);a(o,n),e.name=o.newName,m(e.func,s,n,a);return}case"LocalStat":if(e.exps)for(const o of e.exps)t(o,s,n,a);for(let o=0;o<e.names.length;o+=1){const r=f(s,e.names[o].name);a(r,n),e.names[o].name=r.newName}return;case"AssignStat":for(const o of e.vars)t(o,s,n,a);for(const o of e.exps)t(o,s,n,a);return;case"CallStat":t(e.exp,s,n,a);return;case"ReturnStat":for(const o of e.exps)t(o,s,n,a);return}}function t(e,s,n,a){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const o=i(s,e.name);o&&(e.name=o.newName);return}case"UnaryExpr":t(e.arg,s,n,a);return;case"BinaryExpr":t(e.left,s,n,a),t(e.right,s,n,a);return;case"FuncExpr":m(e,s,n,a);return;case"TableExpr":for(const o of e.fields)o.kind==="index"&&t(o.key,s,n,a),t(o.value,s,n,a);return;case"IndexExpr":t(e.object,s,n,a),t(e.index,s,n,a);return;case"MemberExpr":t(e.object,s,n,a);return;case"CallExpr":t(e.callee,s,n,a);for(const o of e.args)t(o,s,n,a);return;case"MethodCallExpr":t(e.object,s,n,a);for(const o of e.args)t(o,s,n,a);return;case"ParenExpr":t(e.exp,s,n,a);return}}
@@ -549,91 +549,6 @@ setExceptionCallback(() => {
549
549
  });
550
550
  ```
551
551
 
552
- ### loadDex
553
-
554
- 加载 dex、apk 文件 (仅安卓可用)。
555
-
556
- ```typescript
557
- function loadDex(path: string): boolean;
558
- ```
559
-
560
- **参数:**
561
-
562
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
563
- | ------ | ------ | -------- | ------ | ----------------- |
564
- | `path` | string | 是 | - | dex、apk 文件路径 |
565
-
566
- **返回值:**
567
-
568
- | 类型 | 描述 |
569
- | --------- | ------------ |
570
- | `boolean` | 是否加载成功 |
571
-
572
- **示例:**
573
-
574
- ```javascript
575
- const isLoaded = loadDex("/sdcard/classes.dex");
576
- if (isLoaded) {
577
- logi("dex 文件加载成功");
578
- } else {
579
- loge("dex 文件加载失败");
580
- }
581
- ```
582
-
583
- ### getContext
584
-
585
- 获取安卓上下文 (仅安卓可用)。
586
-
587
- ```typescript
588
- function getContext(): any;
589
- ```
590
-
591
- **返回值:**
592
-
593
- | 类型 | 描述 |
594
- | ----- | -------------- |
595
- | `any` | 当前安卓上下文 |
596
-
597
- **示例:**
598
-
599
- ```javascript
600
- const context = getContext();
601
- logi(`当前安卓上下文: ${context}`);
602
- ```
603
-
604
- ### importClass
605
-
606
- 导入 Java 类 (仅安卓可用)。
607
-
608
- ```typescript
609
- function importClass(className: string): any;
610
- ```
611
-
612
- **参数:**
613
-
614
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
615
- | ----------- | ------ | -------- | ------ | --------- |
616
- | `className` | string | 是 | - | Java 类名 |
617
-
618
- **返回值:**
619
-
620
- | 类型 | 描述 |
621
- | ----- | -------------- |
622
- | `any` | 导入的 Java 类 |
623
-
624
- **示例:**
625
-
626
- ```javascript
627
- // 大部分情况下,不需要导入 Java 类,直接使用即可
628
- const B = new com.a.B();
629
- logi(`B 类的实例: ${B}`);
630
-
631
- // 只有在无法直接使用类时,才需要导入 Java 类
632
- const C = importClass("xxx.a.C");
633
- const c = new C();
634
- logi(`创建了 C 类的实例: ${c}`);
635
- ```
636
-
637
552
  ## 全局日志函数
638
553
 
639
554
  全局日志函数是 `logger` 模块对应方法的便捷别名,可以直接调用而无需 `logger.` 前缀。
package/docs/api/image.md CHANGED
@@ -410,18 +410,18 @@ function countColor(
410
410
 
411
411
  **参数:**
412
412
 
413
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
414
- | ----------- | ------ | -------- | ------ | ------------------------------------------------------------------------------------ |
415
- | `imageId` | string | 是 | - | 图片 ID,支持 `"screen"`、图片文件路径、HTTP 图片地址或已加载的图片 ID |
413
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
414
+ | ----------- | ------ | -------- | ------ | --------------------------------------------------------------------------------- |
415
+ | `imageId` | string | 是 | - | 图片 ID,支持 `"screen"`、图片文件路径、HTTP 图片地址或已加载的图片 ID |
416
416
  | `colors` | string | 是 | - | 颜色列表,支持 `主色-偏色\|主色-偏色` 格式,如 `#0A0A0A-#101010\|#FFFFFF-#101010` |
417
- | `threshold` | number | 是 | - | 颜色匹配阈值 (0.0-1.0),数值越大匹配越严格 |
418
- | `x, y` | number | 是 | - | 统计区域左上角坐标 |
419
- | `ex, ey` | number | 是 | - | 统计区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
417
+ | `threshold` | number | 是 | - | 颜色匹配阈值 (0.0-1.0),数值越大匹配越严格 |
418
+ | `x, y` | number | 是 | - | 统计区域左上角坐标 |
419
+ | `ex, ey` | number | 是 | - | 统计区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
420
420
 
421
421
  **返回值:**
422
422
 
423
- | 类型 | 描述 |
424
- | -------- | ------------------------------------------------------------------------------------ |
423
+ | 类型 | 描述 |
424
+ | -------- | ---------------------------------------------------------------------------------- |
425
425
  | `number` | 命中目标颜色的像素数量;图片加载失败、颜色为空、颜色格式无效或区域不合法时返回 `0` |
426
426
 
427
427
  **示例:**
@@ -524,29 +524,29 @@ function findImage(
524
524
 
525
525
  **参数:**
526
526
 
527
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
528
- | ---------------------- | --------- | -------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
529
- | `imageId` | string | 是 | - | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取) |
530
- | `templateImageId` | string | 是 | - | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取)支持按\|分割,多个图片按顺序查找 |
531
- | `x, y` | number | 是 | - | 搜索区域左上角坐标 |
532
- | `ex, ey` | number | 是 | - | 搜索区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
533
- | `threshold` | number | 是 | - | 匹配阈值 (0.0-1.0)。method `0`/`99` 建议 `0.5`–`0.6`;普通模板匹配(`1`/`3`/`5`)建议 `0.9`–`0.995` |
534
- | `limit` | number | 是 | - | 最大查找数量,每个模板图片最多找 limit 个匹配结果 |
535
- | `method` | number | 是 | - | 匹配方法,见下方说明 |
536
- | `rgb` | boolean | 否 | `false` | 是否使用 RGB 找图,默认 `false` 会自动转灰度找图 |
537
- | `options` | object | 否 | - | 额外选项。`scaleFactors` 仅 method=`99` 生效;`orz` 用于按方向取结果 |
538
- | `options.scaleFactors` | number\[] | 否 | `[1.0, 0.9, 1.1, 0.8, 1.2]` | 仅 method=`99` 生效。模板相对当前图的缩放比列表(**不是** `device.getScreenScale()`)。应按 baseScale 动态计算,见下方详解;默认值只适合尺寸接近时的盲扫 |
527
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
528
+ | ---------------------- | --------- | -------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
529
+ | `imageId` | string | 是 | - | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取) |
530
+ | `templateImageId` | string | 是 | - | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取)支持按\|分割,多个图片按顺序查找 |
531
+ | `x, y` | number | 是 | - | 搜索区域左上角坐标 |
532
+ | `ex, ey` | number | 是 | - | 搜索区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
533
+ | `threshold` | number | 是 | - | 匹配阈值 (0.0-1.0)。method `0`/`99` 建议 `0.5`–`0.6`;普通模板匹配(`1`/`3`/`5`)建议 `0.9`–`0.995` |
534
+ | `limit` | number | 是 | - | 最大查找数量,每个模板图片最多找 limit 个匹配结果 |
535
+ | `method` | number | 是 | - | 匹配方法,见下方说明 |
536
+ | `rgb` | boolean | 否 | `false` | 是否使用 RGB 找图,默认 `false` 会自动转灰度找图 |
537
+ | `options` | object | 否 | - | 额外选项。`scaleFactors` 仅 method=`99` 生效;`orz` 用于按方向取结果 |
538
+ | `options.scaleFactors` | number\[] | 否 | `[1.0, 0.9, 1.1, 0.8, 1.2]` | 仅 method=`99` 生效。模板相对当前图的缩放比列表(**不是** `device.getScreenScale()`)。应按 baseScale 动态计算,见下方详解;默认值只适合尺寸接近时的盲扫 |
539
539
  | `options.orz` | number | 否 | 不传 | 查找方向(1-8),与找色 `orz` 相同。不传或非 1-8 时仍按相似度从高到低返回。传入 1-8 时按该方向取前 `limit` 个达标结果;`limit=1` 时只返回该方向第一个,不会把其余命中都找出来。method `0`(SIFT)会先完成匹配再按方向排序截取 |
540
540
 
541
541
  #### method 匹配方法说明
542
542
 
543
- | method | 名称 | 原理简述 | 适用场景 | 速度 |
544
- | ------ | ---------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------ | -------- |
545
- | `5` | TM_CCOEFF_NORMED | 标准模板匹配(归一化相关系数),模板必须与目标**像素尺寸一致** | 同分辨率、同尺寸截图模板,最常用 | 快 |
546
- | `3` | TM_CCORR_NORMED | 标准模板匹配(归一化相关) | 同尺寸模板;PNG 透明模板带 mask 时内部会优先用它 | 快 |
547
- | `1` | TM_SQDIFF_NORMED | 标准模板匹配(归一化平方差),分数越小越像,引擎已换算为越大越像 | 同尺寸模板 | 快 |
548
- | `0` | SIFT 全分辨率 | 提取 SIFT 特征点做匹配,对旋转、轻微形变更鲁棒,不要求模板与目标同尺寸 | 目标可能旋转/形变,或跨分辨率找图 | 较慢 |
549
- | `99` | 全分辨率缩放匹配法 | 把**模板**按多个比例缩放后,再做 `TM_CCOEFF_NORMED` 模板匹配(有透明通道时用 `TM_CCORR_NORMED`) | 目标与模板尺寸不完全一致,但形状相同 | 中等偏慢 |
543
+ | method | 名称 | 原理简述 | 适用场景 | 速度 |
544
+ | ------ | ------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------ | -------- |
545
+ | `5` | TM_CCOEFF_NORMED | 标准模板匹配(归一化相关系数),模板必须与目标**像素尺寸一致** | 同分辨率、同尺寸截图模板,最常用 | 快 |
546
+ | `3` | TM_CCORR_NORMED | 标准模板匹配(归一化相关) | 同尺寸模板;PNG 透明模板带 mask 时内部会优先用它 | 快 |
547
+ | `1` | TM_SQDIFF_NORMED | 标准模板匹配(归一化平方差),分数越小越像,引擎已换算为越大越像 | 同尺寸模板 | 快 |
548
+ | `0` | SIFT 全分辨率 | 提取 SIFT 特征点做匹配,对旋转、轻微形变更鲁棒,不要求模板与目标同尺寸 | 目标可能旋转/形变,或跨分辨率找图 | 较慢 |
549
+ | `99` | 全分辨率缩放匹配法 | 把**模板**按多个比例缩放后,再做 `TM_CCOEFF_NORMED` 模板匹配(有透明通道时用 `TM_CCORR_NORMED`) | 目标与模板尺寸不完全一致,但形状相同 | 中等偏慢 |
550
550
 
551
551
  #### 什么是「缩放」全分辨率找图(method = 99)
552
552
 
@@ -605,21 +605,20 @@ baseScale = 屏幕上目标高度(px) / 模板高度(px)
605
605
 
606
606
  **数值例子:**
607
607
 
608
- | 截模板设备 | 当前运行设备 | 计算 | baseScale |
609
- | -------------- | -------------- | ---------------------------- | --------- |
610
- | iPhone 8 750px | 同机 | 750 / 750 | `1.0` |
611
- | 750 宽 | 1170 宽 | 1170 / 750 | `1.56` |
612
- | 1170 宽 | 750 宽 | 750 / 1170 | `0.641` |
613
- | 1080 宽安卓 | 1440 宽安卓 | 1440 / 1080 | `1.333` |
614
- | 模板按钮 120px | 屏上按钮 96px | 96 / 120 | `0.8` |
608
+ | 截模板设备 | 当前运行设备 | 计算 | baseScale |
609
+ | -------------- | ------------- | ---------- | --------- |
610
+ | iPhone 8 750px | 同机 | 750 / 750 | `1.0` |
611
+ | 750 宽 | 1170 宽 | 1170 / 750 | `1.56` |
612
+ | 1170 宽 | 750 宽 | 750 / 1170 | `0.641` |
613
+ | 模板按钮 120px | 屏上按钮 96px | 96 / 120 | `0.8` |
615
614
 
616
615
  含义对照:
617
616
 
618
- | baseScale | 含义 | 引擎会对模板做什么 |
619
- | --------- | ------------------------------------------ | ----------------------- |
620
- | `1.0` | 当前目标与模板同尺寸 | 不缩放 |
621
- | `0.64` | 当前目标大约是模板的 64%(高分屏模板跑低分) | 缩到 64% 再匹配 |
622
- | `1.56` | 当前目标大约是模板的 156%(低分屏模板跑高分) | 放大到 156% 再匹配 |
617
+ | baseScale | 含义 | 引擎会对模板做什么 |
618
+ | --------- | --------------------------------------------- | ------------------ |
619
+ | `1.0` | 当前目标与模板同尺寸 | 不缩放 |
620
+ | `0.64` | 当前目标大约是模板的 64%(高分屏模板跑低分) | 缩到 64% 再匹配 |
621
+ | `1.56` | 当前目标大约是模板的 156%(低分屏模板跑高分) | 放大到 156% 再匹配 |
623
622
 
624
623
  ##### 2. 再围绕 baseScale 生成搜索列表
625
624
 
@@ -634,14 +633,14 @@ scaleFactors ≈ [ baseScale,
634
633
 
635
634
  推荐参数:
636
635
 
637
- | 项目 | 建议 | 原因 |
638
- | -------------- | ----------------------------------------- | ---- |
639
- | 中心值 | 算出来的 `baseScale` | 最可能命中,必须放第一位 |
640
- | 步进 `step` | `0.05`~`0.1` | 太疏容易跳过真实尺寸;太密浪费时间 |
641
- | 半宽度 | `±0.1`~`±0.2`(约 ±10%~20%) | 覆盖状态栏/安全区/轻微布局差 |
642
- | 总档数 | 3~7 个 | 每多一档就多跑一轮全图模板匹配 |
643
- | 阈值 threshold | `0.5`~`0.6` 起调 | 缩放插值会降低相关分数,别用 0.9+ |
644
- | 顺序 | **baseScale 最先**,再左右交替扩开 | 找满 limit 会提前结束 |
636
+ | 项目 | 建议 | 原因 |
637
+ | -------------- | ---------------------------------- | ---------------------------------- |
638
+ | 中心值 | 算出来的 `baseScale` | 最可能命中,必须放第一位 |
639
+ | 步进 `step` | `0.05`~`0.1` | 太疏容易跳过真实尺寸;太密浪费时间 |
640
+ | 半宽度 | `±0.1`~`±0.2`(约 ±10%~20%) | 覆盖状态栏/安全区/轻微布局差 |
641
+ | 总档数 | 3~7 个 | 每多一档就多跑一轮全图模板匹配 |
642
+ | 阈值 threshold | `0.5`~`0.6` 起调 | 缩放插值会降低相关分数,别用 0.9+ |
643
+ | 顺序 | **baseScale 最先**,再左右交替扩开 | 找满 limit 会提前结束 |
645
644
 
646
645
  生成示例(伪代码思路):
647
646
 
@@ -670,14 +669,14 @@ const scaleFactors = buildScaleFactors(baseScale);
670
669
 
671
670
  ##### 3. 按场景怎么选
672
671
 
673
- | 场景 | 怎么设 `scaleFactors` | threshold |
674
- | ---- | --------------------- | --------- |
675
- | 模板就是本机截的,尺寸确定一致 | 不必用 99,直接 method `5`;若坚持用 99 则 `[1.0]` | `0.9+` / `0.55` |
676
- | 已知截图机型与当前机型分辨率 | 算 `baseScale`,再 `±0.05`~`±0.1` 扩 3~5 档 | `0.5`~`0.6` |
677
- | 多机型跑同一套模板,分辨率跨度大 | 按每台设备运行时动态算 baseScale,不要写死默认那组 | `0.5`~`0.6` |
678
- | 完全不知道模板来源分辨率 | 先用 method `0`(SIFT);或宽范围粗扫(慢,如 0.5~2.0 步进 0.1) | `0.5` 左右 |
679
- | 只要微调(系统字体/显示缩放导致差几像素) | `[1.0, 0.95, 1.05, 0.9, 1.1]` | `0.55`~`0.65` |
680
- | 横竖屏切换 / 目标会旋转 | method `99` **不够**,改用 method `0` SIFT | `0.5`~`0.6` |
672
+ | 场景 | 怎么设 `scaleFactors` | threshold |
673
+ | ----------------------------------------- | ----------------------------------------------------------------- | --------------- |
674
+ | 模板就是本机截的,尺寸确定一致 | 不必用 99,直接 method `5`;若坚持用 99 则 `[1.0]` | `0.9+` / `0.55` |
675
+ | 已知截图机型与当前机型分辨率 | 算 `baseScale`,再 `±0.05`~`±0.1` 扩 3~5 档 | `0.5`~`0.6` |
676
+ | 多机型跑同一套模板,分辨率跨度大 | 按每台设备运行时动态算 baseScale,不要写死默认那组 | `0.5`~`0.6` |
677
+ | 完全不知道模板来源分辨率 | 先用 method `0`(SIFT);或宽范围粗扫(慢,如 0.5~2.0 步进 0.1) | `0.5` 左右 |
678
+ | 只要微调(系统字体/显示缩放导致差几像素) | `[1.0, 0.95, 1.05, 0.9, 1.1]` | `0.55`~`0.65` |
679
+ | 横竖屏切换 / 目标会旋转 | method `99` **不够**,改用 method `0` SIFT | `0.5`~`0.6` |
681
680
 
682
681
  默认值 `[1.0, 0.9, 1.1, 0.8, 1.2]` 的定位:
683
682
 
@@ -707,15 +706,15 @@ const scaleFactors = buildScaleFactors(baseScale);
707
706
 
708
707
  ##### 5. 与 method `0`(SIFT)怎么选
709
708
 
710
- | | method `99` 缩放匹配 | method `0` SIFT |
711
- | -------------- | ---------------------------------- | ---------------------------------- |
712
- | 尺寸变化 | 支持(靠你提供的比例穷举) | 支持(特征点,不靠固定比例) |
713
- | 你需要知道比例 | 最好先算 baseScale | 不需要 |
714
- | 旋转 / 形变 | 基本不支持 | 较鲁棒 |
715
- | 阈值建议 | `0.5`–`0.6` | `0.5`–`0.6` |
716
- | 透明 PNG 模板 | 支持(alpha 作权重 mask) | 支持(alpha 作特征掩码) |
717
- | 性能 | 与 factor 数量近似成正比,通常更快 | 特征提取重,通常更慢 |
718
- | 推荐 | 比例可估算的跨分辨率找图 | 比例未知、或有旋转/透视时 |
709
+ | | method `99` 缩放匹配 | method `0` SIFT |
710
+ | -------------- | ---------------------------------- | ---------------------------- |
711
+ | 尺寸变化 | 支持(靠你提供的比例穷举) | 支持(特征点,不靠固定比例) |
712
+ | 你需要知道比例 | 最好先算 baseScale | 不需要 |
713
+ | 旋转 / 形变 | 基本不支持 | 较鲁棒 |
714
+ | 阈值建议 | `0.5`–`0.6` | `0.5`–`0.6` |
715
+ | 透明 PNG 模板 | 支持(alpha 作权重 mask) | 支持(alpha 作特征掩码) |
716
+ | 性能 | 与 factor 数量近似成正比,通常更快 | 特征提取重,通常更慢 |
717
+ | 推荐 | 比例可估算的跨分辨率找图 | 比例未知、或有旋转/透视时 |
719
718
 
720
719
  **返回值:**
721
720
 
@@ -781,7 +780,9 @@ function buildScaleFactors(base, step = 0.05, halfRange = 2) {
781
780
 
782
781
  const scaleFactors = buildScaleFactors(baseScale);
783
782
  // 750 → 1170 时约等于 [1.56, 1.51, 1.61, 1.46, 1.66]
784
- logi(`baseScale=${baseScale.toFixed(3)} scaleFactors=${JSON.stringify(scaleFactors)}`);
783
+ logi(
784
+ `baseScale=${baseScale.toFixed(3)} scaleFactors=${JSON.stringify(scaleFactors)}`,
785
+ );
785
786
 
786
787
  const scaled = image.findImage(
787
788
  "screen",
@@ -836,15 +837,15 @@ function findImageEx(
836
837
 
837
838
  **参数:**
838
839
 
839
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
840
- | ----------- | ------ | -------- | ------ | -------------------------------------------------------------------------------------------- |
841
- | `imageId` | string | 是 | - | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `findImage` 相同 |
842
- | `kjstPath` | string | 是 | - | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
840
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
841
+ | ---------- | ------ | -------- | ------ | ------------------------------------------------------------------------------------- |
842
+ | `imageId` | string | 是 | - | `"screen"`-当前屏幕截图,或图片 ID / 路径,语义与 `findImage` 相同 |
843
+ | `kjstPath` | string | 是 | - | `res` 下的 kjst 文件名,例如 `"login.kjst"`。不要带 `res/` 前缀,也不要传手机绝对路径 |
843
844
 
844
845
  **返回值:**
845
846
 
846
- | 类型 | 描述 |
847
- | ------- | --------------------------------------------------------------------------------------------- |
847
+ | 类型 | 描述 |
848
+ | ------- | -------------------------------------------------------------------------------------------- |
848
849
  | `array` | 命中矩形数组,字段与 `findImage` 相同。OCR 命中额外含 `text`。未找到或 kjst 无效时返回空数组 |
849
850
 
850
851
  **说明:**
@@ -1153,43 +1154,3 @@ if (imageId) {
1153
1154
  image.release(imageId);
1154
1155
  }
1155
1156
  ```
1156
-
1157
- ## 安卓独有方法
1158
-
1159
- ### getBitmap - 获取安卓的Bitmap对象
1160
-
1161
- 此方法仅在安卓可用,用于获取图片的 Bitmap 对象。
1162
-
1163
- ```typescript
1164
- function getBitmap(imageId: string): any;
1165
- ```
1166
-
1167
- **参数:**
1168
-
1169
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
1170
- | --------- | ------ | -------- | ------ | --------- |
1171
- | `imageId` | string | 是 | - | 原图片 ID |
1172
-
1173
- **返回值:**
1174
-
1175
- | 类型 | 描述 |
1176
- | ----- | ---------------- |
1177
- | `any` | 安卓的Bitmap对象 |
1178
-
1179
- **示例:**
1180
-
1181
- ```javascript
1182
- const imageId = image.captureScreen();
1183
- if (imageId) {
1184
- const bitmap = image.getBitmap(imageId);
1185
- logi(`Bitmap 对象: ${bitmap}`);
1186
- // 注意:使用完 Bitmap 后,需要调用 recycle() 方法释放内存
1187
- bitmap.recycle();
1188
- image.release(imageId);
1189
- }
1190
-
1191
- // 快捷获取截屏bitmap
1192
- const bitmap = image.getBitmap("screen");
1193
- logi(`Bitmap 对象: ${bitmap}`);
1194
- bitmap.recycle();
1195
- ```
package/docs/api/ui.md CHANGED
@@ -74,7 +74,7 @@ UI 模块提供了 WebView 相关功能,支持事件通信和 JavaScript 交
74
74
 
75
75
  ```typescript
76
76
  function onEvent(
77
- onEvent: ((event: string, data: Record<string, any>) => void) | null
77
+ onEvent: ((event: string, data: Record<string, any>) => void) | null,
78
78
  ): void;
79
79
  ```
80
80
 
@@ -82,9 +82,9 @@ function onEvent(
82
82
 
83
83
  **参数:**
84
84
 
85
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
86
- | --------- | -------------------------------------------------- | -------- | ------ | ------------------------------------ |
87
- | `onEvent` | ((event: string, data: Record<string, any>) => void) 或 null | 是 | | 事件回调函数,用于处理来自网页的事件,传 `null` 取消监听 |
85
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
86
+ | --------- | ------------------------------------------------------------ | -------- | ------ | -------------------------------------------------------- |
87
+ | `onEvent` | ((event: string, data: Record<string, any>) => void) 或 null | 是 | | 事件回调函数,用于处理来自网页的事件,传 `null` 取消监听 |
88
88
 
89
89
  **示例:**
90
90
 
@@ -255,7 +255,7 @@ ui.alert("操作完成", "脚本执行完成,共处理了100个项目");
255
255
  ```typescript
256
256
  declare function registerUIFunc(
257
257
  name: string,
258
- func: (data: Record<string, any>) => void
258
+ func: (data: Record<string, any>) => void,
259
259
  ): void;
260
260
  ```
261
261
 
@@ -281,9 +281,8 @@ declare function registerUIFunc(
281
281
  <script>
282
282
  // 注册供主进程调用的函数
283
283
  ms.registerUIFunc("updateStatus", function (data) {
284
- document.getElementById(
285
- "status"
286
- ).textContent = `状态: ${data.status}, 进度: ${data.progress}%`;
284
+ document.getElementById("status").textContent =
285
+ `状态: ${data.status}, 进度: ${data.progress}%`;
287
286
  });
288
287
 
289
288
  ms.registerUIFunc("loadData", function (data) {
@@ -656,35 +655,6 @@ ms.getDeviceID()
656
655
  });
657
656
  ```
658
657
 
659
- #### getServerDeviceId - 获取服务器设备 ID
660
-
661
- ```typescript
662
- declare function getServerDeviceId(): Promise<string>;
663
- ```
664
-
665
- **返回值:**
666
-
667
- | 类型 | 描述 |
668
- | ----------------- | ------------- |
669
- | `Promise<string>` | 服务器设备 ID |
670
-
671
- **说明:**
672
-
673
- 获取当前运行脚本的服务器设备 ID。
674
-
675
- **网页端示例:**
676
-
677
- ```javascript
678
- // 获取服务器设备ID
679
- ms.getServerDeviceId()
680
- .then((deviceId) => {
681
- console.log("当前服务器设备ID:", deviceId);
682
- })
683
- .catch((error) => {
684
- console.error("获取服务器设备ID出错:", error);
685
- });
686
- ```
687
-
688
658
  #### getAuthCardNo - 获取缓存的授权卡密
689
659
 
690
660
  ```typescript
@@ -693,8 +663,8 @@ declare function getAuthCardNo(): Promise<string>;
693
663
 
694
664
  **返回值:**
695
665
 
696
- | 类型 | 描述 |
697
- | ----------------- | ------------------------------------ |
666
+ | 类型 | 描述 |
667
+ | ----------------- | -------------------------------------------------- |
698
668
  | `Promise<string>` | 有缓存的授权卡密时返回卡密字符串,否则返回空字符串 |
699
669
 
700
670
  **说明:**
@@ -576,60 +576,6 @@ if (是否加载成功) {
576
576
  }
577
577
  ```
578
578
 
579
- ### $获取上下文
580
-
581
- 获取安卓上下文 (仅安卓可用)。
582
-
583
- ```typescript
584
- declare function $获取上下文(): 任意类型;
585
- ```
586
-
587
- **返回值:**
588
-
589
- | 类型 | 描述 |
590
- | ------------ | -------------- |
591
- | `上下文对象` | 当前上下文对象 |
592
-
593
- **示例:**
594
-
595
- ```javascript
596
- const 上下文 = $获取上下文();
597
- $打印调试日志(`当前上下文: ${JSON.stringify(上下文)}`);
598
- ```
599
-
600
- ### $导入类
601
-
602
- 导入指定的类。
603
-
604
- ```typescript
605
- declare function $导入类(类名: 字符串): 任意类型;
606
- ```
607
-
608
- **参数:**
609
-
610
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
611
- | ------ | ------ | -------- | ------ | ------------ |
612
- | `类名` | 字符串 | 是 | - | 要导入的类名 |
613
-
614
- **返回值:**
615
-
616
- | 类型 | 描述 |
617
- | -------- | ------------ |
618
- | `类对象` | 导入的类对象 |
619
-
620
- **示例:**
621
-
622
- ```javascript
623
- // 大部分情况下,不需要导入 Java 类,直接使用即可
624
- const B = new com.a.B();
625
- logi(`B 类的实例: ${B}`);
626
-
627
- // 只有在无法直接使用类时,才需要导入 Java 类
628
- const C = $导入类("xxx.a.C");
629
- const c = new C();
630
- logi(`创建了 C 类的实例: ${c}`);
631
- ```
632
-
633
579
  ## 全局日志函数
634
580
 
635
581
  全局日志函数是 `logger` 模块对应方法的便捷别名,可以直接调用而无需 `logger.` 前缀。