ms-vite-plugin 1.4.62 → 1.4.64

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=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
+ "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 +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(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
+ "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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(n,e){let t=n;for(;t;){const a=t.locals.get(e);if(a)return a;t=t.parent}}function c(n){return{parent:n,locals:new Map}}function f(n,e){const t=n.locals.get(e);if(t)return t;const a={original:e,newName:e};return n.locals.set(e,a),a}function x(n,e){const t=new Set,a={locals:new Map};d(n.body,a,t,e)}function u(n,e,t,a){d(n.body,e,t,a)}function d(n,e,t,a){for(const r of n)b(r,e,t,a)}function m(n,e,t,a){const r=c(e),o=n.params.slice();for(let l=0;l<o.length;l+=1){const p=f(r,o[l]);a(p,t),n.params[l]=p.newName}u(n.body,r,t,a)}function b(n,e,t,a){switch(n.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(n.body,c(e),t,a);return;case"WhileStat":s(n.cond,e,t,a),u(n.body,c(e),t,a);return;case"RepeatStat":{const r=c(e);u(n.body,r,t,a),s(n.cond,r,t,a);return}case"IfStat":for(const r of n.clauses)s(r.cond,e,t,a),u(r.body,c(e),t,a);n.elseBody&&u(n.elseBody,c(e),t,a);return;case"ForNumStat":{s(n.start,e,t,a),s(n.end,e,t,a),n.step&&s(n.step,e,t,a);const r=c(e),o=f(r,n.name);a(o,t),n.name=o.newName,u(n.body,r,t,a);return}case"ForInStat":{for(const o of n.exps)s(o,e,t,a);const r=c(e);for(let o=0;o<n.names.length;o+=1){const l=f(r,n.names[o]);a(l,t),n.names[o]=l.newName}u(n.body,r,t,a);return}case"FuncStat":{const r=i(e,n.name.base);r&&(n.name.base=r.newName),m(n.func,e,t,a);return}case"LocalFuncStat":{const r=f(e,n.name);a(r,t),n.name=r.newName,m(n.func,e,t,a);return}case"LocalStat":if(n.exps)for(const r of n.exps)s(r,e,t,a);for(let r=0;r<n.names.length;r+=1){const o=f(e,n.names[r].name);a(o,t),n.names[r].name=o.newName}return;case"AssignStat":for(const r of n.vars)s(r,e,t,a);for(const r of n.exps)s(r,e,t,a);return;case"CallStat":s(n.exp,e,t,a);return;case"ReturnStat":for(const r of n.exps)s(r,e,t,a);return}}function s(n,e,t,a){switch(n.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const r=i(e,n.name);r&&(n.name=r.newName);return}case"UnaryExpr":s(n.arg,e,t,a);return;case"BinaryExpr":s(n.left,e,t,a),s(n.right,e,t,a);return;case"FuncExpr":m(n,e,t,a);return;case"TableExpr":for(const r of n.fields)r.kind==="index"&&s(r.key,e,t,a),s(r.value,e,t,a);return;case"IndexExpr":s(n.object,e,t,a),s(n.index,e,t,a);return;case"MemberExpr":s(n.object,e,t,a);return;case"CallExpr":s(n.callee,e,t,a);for(const r of n.args)s(r,e,t,a);return;case"MethodCallExpr":s(n.object,e,t,a);for(const r of n.args)s(r,e,t,a);return;case"ParenExpr":s(n.exp,e,t,a);return}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(n,s){let a=n;for(;a;){const e=a.locals.get(s);if(e)return e;a=a.parent}}function o(n){return{parent:n,locals:new Map}}function f(n,s){const a=n.locals.get(s);if(a)return a;const e={original:s,newName:s};return n.locals.set(s,e),e}function x(n,s){const a=new Set,e={locals:new Map};d(n.body,e,a,s)}function u(n,s,a,e){d(n.body,s,a,e)}function d(n,s,a,e){for(const t of n)b(t,s,a,e)}function m(n,s,a,e){const t=o(s),r=n.params.slice();for(let l=0;l<r.length;l+=1){const p=f(t,r[l]);e(p,a),n.params[l]=p.newName}u(n.body,t,a,e)}function b(n,s,a,e){switch(n.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(n.body,o(s),a,e);return;case"WhileStat":c(n.cond,s,a,e),u(n.body,o(s),a,e);return;case"RepeatStat":{const t=o(s);u(n.body,t,a,e),c(n.cond,t,a,e);return}case"IfStat":for(const t of n.clauses)c(t.cond,s,a,e),u(t.body,o(s),a,e);n.elseBody&&u(n.elseBody,o(s),a,e);return;case"ForNumStat":{c(n.start,s,a,e),c(n.end,s,a,e),n.step&&c(n.step,s,a,e);const t=o(s),r=f(t,n.name);e(r,a),n.name=r.newName,u(n.body,t,a,e);return}case"ForInStat":{for(const r of n.exps)c(r,s,a,e);const t=o(s);for(let r=0;r<n.names.length;r+=1){const l=f(t,n.names[r]);e(l,a),n.names[r]=l.newName}u(n.body,t,a,e);return}case"FuncStat":{const t=i(s,n.name.base);t&&(n.name.base=t.newName),m(n.func,s,a,e);return}case"LocalFuncStat":{const t=f(s,n.name);e(t,a),n.name=t.newName,m(n.func,s,a,e);return}case"LocalStat":if(n.exps)for(const t of n.exps)c(t,s,a,e);for(let t=0;t<n.names.length;t+=1){const r=f(s,n.names[t].name);e(r,a),n.names[t].name=r.newName}return;case"AssignStat":for(const t of n.vars)c(t,s,a,e);for(const t of n.exps)c(t,s,a,e);return;case"CallStat":c(n.exp,s,a,e);return;case"ReturnStat":for(const t of n.exps)c(t,s,a,e);return}}function c(n,s,a,e){switch(n.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const t=i(s,n.name);t&&(n.name=t.newName);return}case"UnaryExpr":c(n.arg,s,a,e);return;case"BinaryExpr":c(n.left,s,a,e),c(n.right,s,a,e);return;case"FuncExpr":m(n,s,a,e);return;case"TableExpr":for(const t of n.fields)t.kind==="index"&&c(t.key,s,a,e),c(t.value,s,a,e);return;case"IndexExpr":c(n.object,s,a,e),c(n.index,s,a,e);return;case"MemberExpr":c(n.object,s,a,e);return;case"CallExpr":c(n.callee,s,a,e);for(const t of n.args)c(t,s,a,e);return;case"MethodCallExpr":c(n.object,s,a,e);for(const t of n.args)c(t,s,a,e);return;case"ParenExpr":c(n.exp,s,a,e);return}}
@@ -405,6 +405,13 @@ const abs = cv.convertScaleAbs(sobel, { alpha: 1, beta: 0 });
405
405
 
406
406
  ```typescript
407
407
  function countNonZero(mat: Mat): number;
408
+ function minMaxLoc(mat: Mat, options?: { mask?: Mat }): MinMaxLocResult | null;
409
+ ```
410
+
411
+ `minMaxLoc` / `countNonZero` 需要单通道,先转灰度:
412
+
413
+ ```typescript
414
+ const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
408
415
  const mm = cv.minMaxLoc(gray);
409
416
  logi(`max=${mm.maxVal} at (${mm.maxLoc.x},${mm.maxLoc.y})`);
410
417
  const chans = cv.split(src);
@@ -159,8 +159,7 @@ cloud.report("cloud = status", {
159
159
  function onEvent(callback) end
160
160
  ```
161
161
 
162
- 监听服务器发送的 `scriptEvent` 协议帧。传入 `nil` 会取消主脚本监听。
163
- 此回调注册接口只能在主线程调用,不能在线程脚本中调用。
162
+ 监听服务器事件。传入 `nil` 取消监听。回调在 `Sleep` 时执行。
164
163
 
165
164
  **参数**
166
165
 
@@ -238,7 +238,7 @@ end
238
238
 
239
239
  ```lua
240
240
  ---@param path string
241
- ---@return string | nil
241
+ ---@return string
242
242
  function readFile(path) end
243
243
  ```
244
244
 
@@ -250,18 +250,18 @@ function readFile(path) end
250
250
 
251
251
  **返回值:**
252
252
 
253
- | 类型 | 描述 |
254
- | ---------------- | ------------------------------- |
255
- | `string \| nil` | 文件内容;失败或不存在返回 nil |
253
+ | 类型 | 描述 |
254
+ | -------- | ------------------------ |
255
+ | `string` | 文件内容;失败时为空字符串 |
256
256
 
257
257
  **示例:**
258
258
 
259
259
  ```lua
260
260
  local content = file.readFile("/path/to/file.txt")
261
- if content ~= nil then
262
- print("文件内容: " .. tostring(content))
261
+ if content ~= "" then
262
+ print("文件内容: " .. content)
263
263
  else
264
- print("文件不存在或读取失败")
264
+ print("读取失败")
265
265
  end
266
266
  ```
267
267
 
@@ -274,7 +274,7 @@ end
274
274
 
275
275
  ```lua
276
276
  ---@param fileName string
277
- ---@return string | nil
277
+ ---@return string
278
278
  function readResFile(fileName) end
279
279
  ```
280
280
 
@@ -286,9 +286,9 @@ function readResFile(fileName) end
286
286
 
287
287
  **返回值:**
288
288
 
289
- | 类型 | 描述 |
290
- | -------------- | --------------------------------------- |
291
- | `string\|nil` | 文件内容 文件不存在或读取失败 返回 nil |
289
+ | 类型 | 描述 |
290
+ | -------- | ------------------------ |
291
+ | `string` | 文件内容;失败时为空字符串 |
292
292
 
293
293
  **示例:**
294
294
 
@@ -409,7 +409,7 @@ end
409
409
  ```lua
410
410
  ---@param path string
411
411
  ---@param lineNo number
412
- ---@return string | nil
412
+ ---@return string
413
413
  function readLine(path, lineNo) end
414
414
  ```
415
415
 
@@ -422,18 +422,18 @@ function readLine(path, lineNo) end
422
422
 
423
423
  **返回值:**
424
424
 
425
- | 类型 | 描述 |
426
- | ---------------- | ----------------------------- |
427
- | `string \| nil` | 行内容;失败或不存在返回 nil |
425
+ | 类型 | 描述 |
426
+ | -------- | ---------------------- |
427
+ | `string` | 行内容;失败时为空字符串 |
428
428
 
429
429
  **示例:**
430
430
 
431
431
  ```lua
432
432
  local firstLine = file.readLine("/path/to/file.txt", 1)
433
- if firstLine ~= nil then
434
- print("第一行内容: " .. tostring(firstLine))
433
+ if firstLine ~= "" then
434
+ print("第一行内容: " .. firstLine)
435
435
  else
436
- print("读取失败或行不存在")
436
+ print("读取失败")
437
437
  end
438
438
  ```
439
439
 
@@ -441,7 +441,7 @@ end
441
441
 
442
442
  ```lua
443
443
  ---@param path string
444
- ---@return string[] | nil
444
+ ---@return string[]
445
445
  function readAllLines(path) end
446
446
  ```
447
447
 
@@ -453,20 +453,16 @@ function readAllLines(path) end
453
453
 
454
454
  **返回值:**
455
455
 
456
- | 类型 | 描述 |
457
- | --------- | ----- | ----------------------------- |
458
- | `string[] | nil` | 所有行内容数组;失败返回 nil |
456
+ | 类型 | 描述 |
457
+ | ---------- | -------------------- |
458
+ | `string[]` | 所有行;失败时为空表 |
459
459
 
460
460
  **示例:**
461
461
 
462
462
  ```lua
463
463
  local lines = file.readAllLines("/path/to/file.txt")
464
- if lines ~= nil then
465
- for index, line in ipairs(lines) do
466
- print("第" .. tostring(index + 1) .. "行: " .. tostring(line))
467
- end)
468
- else
469
- print("读取所有行失败或文件不存在")
464
+ for i, line in ipairs(lines) do
465
+ print(i, line)
470
466
  end
471
467
  ```
472
468
 
@@ -511,7 +507,7 @@ file.deleteLine("/path/to/file.txt", 5, "debug")
511
507
 
512
508
  ```lua
513
509
  ---@param path string
514
- ---@return string | nil
510
+ ---@return string
515
511
  function fileMD5(path) end
516
512
  ```
517
513
 
@@ -523,16 +519,16 @@ function fileMD5(path) end
523
519
 
524
520
  **返回值:**
525
521
 
526
- | 类型 | 描述 |
527
- | ---------------- | ------------------------- |
528
- | `string \| nil` | 文件 MD5 值 失败返回 nil |
522
+ | 类型 | 描述 |
523
+ | -------- | ----------------------- |
524
+ | `string` | 文件 MD5;失败时为空字符串 |
529
525
 
530
526
  **示例:**
531
527
 
532
528
  ```lua
533
529
  local md5 = file.fileMD5("/path/to/file.txt")
534
- if md5 then
535
- print("文件MD5 = " .. tostring(md5))
530
+ if md5 ~= "" then
531
+ print("文件MD5 = " .. md5)
536
532
  else
537
533
  print("获取MD5失败")
538
534
  end
@@ -4,10 +4,6 @@
4
4
 
5
5
  **全局模块无调用前缀,直接使用即可。不要 `require`。**
6
6
 
7
- `StartThread` 是同一 Lua VM 里的协作协程,不是操作系统线程;协程只在 `Sleep` 时被调度。
8
-
9
- 主脚本收到停止信号后,引擎会通过 instruction hook 和可中断的 `Sleep` 直接中断,不必在主循环里轮询 `ShouldInterruptThread`。
10
-
11
7
 
12
8
  ## 功能概览
13
9
 
@@ -170,7 +166,7 @@ end
170
166
 
171
167
  ### Sleep
172
168
 
173
- 使当前线程睡眠指定的毫秒数。
169
+ 等待指定的毫秒数。
174
170
 
175
171
  ```lua
176
172
  ---@param ms number
@@ -193,7 +189,7 @@ print("等待结束")
193
189
 
194
190
  ### Exit
195
191
 
196
- 退出当前脚本。Lua 只有一个 VM,效果与收到停止信号相同。
192
+ 退出当前脚本。
197
193
 
198
194
  ```lua
199
195
  function Exit() end
@@ -540,7 +536,7 @@ end)
540
536
 
541
537
  ### StartThread
542
538
 
543
- 启动协作协程,返回协程名。传入的函数在同一 Lua VM 中运行,不是操作系统线程;协程只在 `Sleep` 时被调度。
539
+ 启动协作协程,返回协程名。
544
540
 
545
541
  ```lua
546
542
  ---@param func function
@@ -571,7 +567,7 @@ local name = StartThread(function()
571
567
  end)
572
568
  ```
573
569
 
574
- `StopThread` 或整脚本停止后,协程会在下一次 `Sleep` / hook 处被中断,不必在协程里轮询。
570
+ 需要停掉某个协程时调用 `StopThread`。
575
571
 
576
572
  ### StopThread
577
573
 
@@ -596,11 +592,7 @@ StopThread(name)
596
592
 
597
593
  ### ShouldInterruptThread
598
594
 
599
- 当前协作协程是否应退出。
600
-
601
- 主脚本**不必**调用本函数:停止按钮、`Exit()`、引擎 stop 都会让 hook 和 `Sleep` 直接中断主程序。
602
-
603
- 仅当 `StartThread` 协程被 `StopThread` 之后还要自己做收尾(而不是靠抛错退出)时,才需要轮询。
595
+ 当前协程是否应退出。`StopThread` 之后可在循环里判断。
604
596
 
605
597
  ```lua
606
598
  ---@return boolean
@@ -651,6 +643,9 @@ function ToJsonString(data) end
651
643
 
652
644
  ```lua
653
645
  print(ToJsonString({ a = 1, b = 2 }))
646
+ print({ a = 1, b = 2 })
647
+ logi({ 1, 2, 3 })
648
+ logger.info("size", { width = 100, height = 200 })
654
649
  ```
655
650
 
656
651
  ## 全局日志函数
@@ -19,7 +19,7 @@ function request(params) end
19
19
  | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
20
20
  | ------------------- | ------- | -------- | -------- | --------------------------- |
21
21
  | `url` | string | 是 | - | 请求地址 |
22
- | `timeout` | number | 否 | 10000 | 请求超时时间(毫秒) |
22
+ | `timeout` | number | 否 | 30000 | 请求超时时间(毫秒) |
23
23
  | `method` | string | 否 | GET | 请求方法(GET、POST 等) |
24
24
  | `proxy` | table | 否 | - | 代理服务器配置 |
25
25
  | `followRedirects` | boolean | 否 | true | 是否跟随重定向 |
@@ -106,7 +106,7 @@ function httpGet(url, params, timeout, headers) end
106
106
  | --------- | ---------------------- | -------- | ------ | ---------------- |
107
107
  | `url` | string | 是 | - | 请求地址 |
108
108
  | `params` | table | 否 | - | URL 查询参数 |
109
- | `timeout` | number | 否 | 10000 | 超时时间(毫秒) |
109
+ | `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
110
110
  | `headers` | table | 否 | - | 请求头 |
111
111
 
112
112
  **返回值:**
@@ -150,7 +150,7 @@ function httpPost(url, params, files, timeout, headers) end
150
150
  | `url` | string | 是 | - | 请求地址 |
151
151
  | `params` | table | 否 | - | 表单参数 |
152
152
  | `files` | table | 否 | - | 文件参数 |
153
- | `timeout` | number | 否 | 10000 | 超时时间(毫秒) |
153
+ | `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
154
154
  | `headers` | table | 否 | - | 请求头 |
155
155
 
156
156
  **返回值:**
@@ -196,7 +196,7 @@ function postJSON(url, json, timeout, headers) end
196
196
  | --------- | ---------------------- | -------- | ------ | ---------------- |
197
197
  | `url` | string | 是 | - | 请求地址 |
198
198
  | `json` | table | 否 | - | JSON 数据 |
199
- | `timeout` | number | 否 | 10000 | 超时时间(毫秒) |
199
+ | `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
200
200
  | `headers` | table | 否 | - | 请求头 |
201
201
 
202
202
  **返回值:**
@@ -241,7 +241,7 @@ function downloadFile(url, file, timeout, headers) end
241
241
  | --------- | ---------------------- | -------- | ------ | -------------------- |
242
242
  | `url` | string | 是 | - | 文件下载地址 |
243
243
  | `file` | string | 是 | - | 本地保存路径 |
244
- | `timeout` | number | 否 | 10000 | 下载超时时间(毫秒) |
244
+ | `timeout` | number | 否 | 30000 | 下载超时时间(毫秒) |
245
245
  | `headers` | table | 否 | - | 请求头 |
246
246
 
247
247
  **返回值:**
@@ -344,6 +344,8 @@ function sendBinary(data) end
344
344
 
345
345
  #### 事件回调
346
346
 
347
+ 这些回调在 `Sleep` 时执行。
348
+
347
349
  ```lua
348
350
  ---@param callback function
349
351
  function onOpen(callback) end
@@ -513,7 +513,7 @@ end
513
513
  ---@param ey number
514
514
  ---@param threshold number
515
515
  ---@param limit number
516
- ---@param method number
516
+ ---@param method number?
517
517
  ---@param rgb boolean?
518
518
  ---@param options table?
519
519
  ---@return any
@@ -530,7 +530,7 @@ function findImage(imageId, templateImageId, x, y, ex, ey, threshold, limit, met
530
530
  | `ex, ey` | number | 是 | - | 搜索区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
531
531
  | `threshold` | number | 是 | - | 匹配阈值 (0.0-1.0)。method `0`/`99` 建议 `0.5`–`0.6`;普通模板匹配(`1`/`3`/`5`)建议 `0.9`–`0.995` |
532
532
  | `limit` | number | 是 | - | 最大查找数量,每个模板图片最多找 limit 个匹配结果 |
533
- | `method` | number | | - | 匹配方法,见下方说明 |
533
+ | `method` | number | | `5` | 匹配方法,见下方说明 |
534
534
  | `rgb` | boolean | 否 | `false` | 是否使用 RGB 找图,默认 `false` 会自动转灰度找图 |
535
535
  | `options` | table | 否 | - | 额外选项。`scaleFactors` 仅 method=`99` 生效;`orz` 用于按方向取结果 |
536
536
  | `options.scaleFactors` | number\[] | 否 | `[1.0, 0.9, 1.1, 0.8, 1.2]` | 仅 method=`99` 生效。模板相对当前图的缩放比列表(**不是** `device.getScreenScale()`)。应按 baseScale 动态计算,见下方详解;默认值只适合尺寸接近时的盲扫 |
@@ -214,8 +214,8 @@ function info(...args) end
214
214
  **示例:**
215
215
 
216
216
  ```lua
217
- ---@param settings any
218
- function saveSettings(settings) end
217
+ logger.info("应用程序启动成功")
218
+ logger.info("size", { width = 100, height = 200 })
219
219
  ```
220
220
 
221
221
  ### warn - 输出警告级别的日志。
@@ -90,7 +90,7 @@ local listPage = node.createNodeSelector({ mode = 2 })
90
90
  | `input(text)` | 追加输入,不清空原内容;不可见时会先自动滚到可见 |
91
91
  | `setValue(text)` | 设置值(见下方;不可见时会先自动滚到可见) |
92
92
  | `parent()` | 父节点 |
93
- | `child(index)` | 第 `index` 个子节点 |
93
+ | `child(index)` | 第 `index` 个子节点,`index` 从 0 开始 |
94
94
  | `allChildren()` | 全部子节点 |
95
95
  | `siblings()` | 全部兄弟节点 |
96
96
  | `previousSiblings()` | 前面的兄弟 |
@@ -406,6 +406,18 @@ local mask = cv.inRange(hsv, { lowerb = { 0, 80, 80 }, upperb = { 20, 255, 255 }
406
406
  ---@param mat Mat
407
407
  ---@return number
408
408
  function countNonZero(mat) end
409
+
410
+ ---@param mat Mat
411
+ ---@param options table?
412
+ ---@return table|nil
413
+ function minMaxLoc(mat, options) end
414
+ ```
415
+
416
+ `minMaxLoc` / `countNonZero` 需要单通道,先转灰度:
417
+
418
+ ```lua
419
+ local gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
420
+ local mm = cv.minMaxLoc(gray)
409
421
  ```
410
422
 
411
423
  ---
package/docs/apilua/ui.md CHANGED
@@ -86,6 +86,18 @@ function show() end
86
86
  ui.show()
87
87
  ```
88
88
 
89
+ ### hide - 隐藏 WebView。
90
+
91
+ ```lua
92
+ function hide() end
93
+ ```
94
+
95
+ **示例:**
96
+
97
+ ```lua
98
+ ui.hide()
99
+ ```
100
+
89
101
  ### eval - 在 WebView 中执行 JavaScript 代码。
90
102
 
91
103
  ```lua
@@ -113,7 +125,7 @@ ui.eval("document.title = 'KuaiJS'")
113
125
  function onEvent(onEvent) end
114
126
  ```
115
127
 
116
- 此回调注册接口只能在主线程调用,不能在线程脚本中调用。传入 `nil` 会取消监听。
128
+ 传入 `nil` 取消监听。回调在 `Sleep` 时执行。
117
129
 
118
130
  **参数:**
119
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.4.62",
3
+ "version": "1.4.64",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {