reg-cli 0.18.0 → 0.18.2

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,1568 @@
1
- (()=>{"use strict";var t={"./node_modules/x-img-diff-js/package.json":t=>{t.exports={i8:"0.3.5"}}},e={};function n(s){if(e[s])return e[s].exports;var i=e[s]={exports:{}};return t[s](i,i.exports,n),i.exports}(()=>{function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===o(t)}function e(t){return"string"==typeof t}function s(t){return"number"==typeof t}function i(t){return"object"==typeof t}function r(t){return null!=t}function c(t){return!t.trim().length}function o(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const a=Object.prototype.hasOwnProperty;class h{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach((t=>{let n=l(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight})),this._keys.forEach((t=>{t.weight/=e}))}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function l(n){let s=null,i=null,r=null,c=1;if(e(n)||t(n))r=n,s=u(n),i=d(n);else{if(!a.call(n,"name"))throw new Error("Missing name property in key");const t=n.name;if(r=t,a.call(n,"weight")&&(c=n.weight,c<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));s=u(t),i=d(t)}return{path:s,id:i,weight:c,src:r}}function u(e){return t(e)?e:e.split(".")}function d(e){return t(e)?e.join("."):e}var g={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,useExtendedSearch:!1,getFn:function(n,c){let a=[],h=!1;const l=(n,c,u)=>{if(r(n))if(c[u]){const d=n[c[u]];if(!r(d))return;if(u===c.length-1&&(e(d)||s(d)||function(t){return!0===t||!1===t||function(t){return i(t)&&null!==t}(t)&&"[object Boolean]"==o(t)}(d)))a.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(d));else if(t(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)l(d[t],c,u+1)}else c.length&&l(d,c,u+1)}else a.push(n)};return l(n,e(c)?c.split("."):c,0),h?a:a[0]},ignoreLocation:!1,ignoreFieldNorm:!1};const f=/[^ ]+/g;class p{constructor({getFn:t=g.getFn}={}){this.norm=function(t=3){const e=new Map,n=Math.pow(10,t);return{get(t){const s=t.match(f).length;if(e.has(s))return e.get(s);const i=1/Math.sqrt(s),r=parseFloat(Math.round(i*n)/n);return e.set(s,r),r},clear(){e.clear()}}}(3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach(((t,e)=>{this._keysMap[t.id]=e}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(this.docs[0])?this.docs.forEach(((t,e)=>{this._addString(t,e)})):this.docs.forEach(((t,e)=>{this._addObject(t,e)})),this.norm.clear())}add(t){const n=this.size();e(t)?this._addString(t,n):this._addObject(t,n)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e<n;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!r(t)||c(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(n,s){let i={i:s,$:{}};this.keys.forEach(((s,o)=>{let a=this.getFn(n,s.path);if(r(a))if(t(a)){let n=[];const s=[{nestedArrIndex:-1,value:a}];for(;s.length;){const{nestedArrIndex:i,value:o}=s.pop();if(r(o))if(e(o)&&!c(o)){let t={v:o,i,n:this.norm.get(o)};n.push(t)}else t(o)&&o.forEach(((t,e)=>{s.push({nestedArrIndex:e,value:t})}))}i.$[o]=n}else if(!c(a)){let t={v:a,n:this.norm.get(a)};i.$[o]=t}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function m(t,e,{getFn:n=g.getFn}={}){const s=new p({getFn:n});return s.setKeys(t.map(l)),s.setSources(e),s.create(),s}function M(t,{errors:e=0,currentLocation:n=0,expectedLocation:s=0,distance:i=g.distance,ignoreLocation:r=g.ignoreLocation}={}){const c=e/t.length;if(r)return c;const o=Math.abs(s-n);return i?c+o/i:o?1:c}const y=32;function x(t){let e={};for(let n=0,s=t.length;n<s;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<s-n-1}return e}class w{constructor(t,{location:e=g.location,threshold:n=g.threshold,distance:s=g.distance,includeMatches:i=g.includeMatches,findAllMatches:r=g.findAllMatches,minMatchCharLength:c=g.minMatchCharLength,isCaseSensitive:o=g.isCaseSensitive,ignoreLocation:a=g.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:s,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a},this.pattern=o?t:t.toLowerCase(),this.chunks=[],!this.pattern.length)return;const h=(t,e)=>{this.chunks.push({pattern:t,alphabet:x(t),startIndex:e})},l=this.pattern.length;if(l>y){let t=0;const e=l%y,n=l-e;for(;t<n;)h(this.pattern.substr(t,y),t),t+=y;if(e){const t=l-y;h(this.pattern.substr(t),t)}}else h(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,includeMatches:n}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return n&&(e.indices=[[0,t.length-1]]),e}const{location:s,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,ignoreLocation:a}=this.options;let h=[],l=0,u=!1;this.chunks.forEach((({pattern:e,alphabet:d,startIndex:f})=>{const{isMatch:p,score:m,indices:x}=function(t,e,n,{location:s=g.location,distance:i=g.distance,threshold:r=g.threshold,findAllMatches:c=g.findAllMatches,minMatchCharLength:o=g.minMatchCharLength,includeMatches:a=g.includeMatches,ignoreLocation:h=g.ignoreLocation}={}){if(e.length>y)throw new Error("Pattern length exceeds max of 32.");const l=e.length,u=t.length,d=Math.max(0,Math.min(s,u));let f=r,p=d;const m=o>1||a,x=m?Array(u):[];let w;for(;(w=t.indexOf(e,p))>-1;){let t=M(e,{currentLocation:w,expectedLocation:d,distance:i,ignoreLocation:h});if(f=Math.min(t,f),p=w+l,m){let t=0;for(;t<l;)x[w+t]=1,t+=1}}p=-1;let _=[],L=1,S=l+u;const v=1<<l-1;for(let s=0;s<l;s+=1){let r=0,o=S;for(;r<o;)M(e,{errors:s,currentLocation:d+o,expectedLocation:d,distance:i,ignoreLocation:h})<=f?r=o:S=o,o=Math.floor((S-r)/2+r);S=o;let a=Math.max(1,d-o+1),g=c?u:Math.min(d+o,u)+l,y=Array(g+2);y[g+1]=(1<<s)-1;for(let r=g;r>=a;r-=1){let c=r-1,o=n[t.charAt(c)];if(m&&(x[c]=+!!o),y[r]=(y[r+1]<<1|1)&o,s&&(y[r]|=(_[r+1]|_[r])<<1|1|_[r+1]),y[r]&v&&(L=M(e,{errors:s,currentLocation:c,expectedLocation:d,distance:i,ignoreLocation:h}),L<=f)){if(f=L,p=c,p<=d)break;a=Math.max(1,2*d-p)}}if(M(e,{errors:s+1,currentLocation:d,expectedLocation:d,distance:i,ignoreLocation:h})>f)break;_=y}const I={isMatch:p>=0,score:Math.max(.001,L)};if(m){const t=function(t=[],e=g.minMatchCharLength){let n=[],s=-1,i=-1,r=0;for(let c=t.length;r<c;r+=1){let c=t[r];c&&-1===s?s=r:c||-1===s||(i=r-1,i-s+1>=e&&n.push([s,i]),s=-1)}return t[r-1]&&r-s>=e&&n.push([s,r-1]),n}(x,o);t.length?a&&(I.indices=t):I.isMatch=!1}return I}(t,e,d,{location:s+f,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,includeMatches:n,ignoreLocation:a});p&&(u=!0),l+=m,p&&x&&(h=[...h,...x])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&n&&(d.indices=h),d}}class _{constructor(t){this.pattern=t}static isMultiMatch(t){return L(t,this.multiRegex)}static isSingleMatch(t){return L(t,this.singleRegex)}search(){}}function L(t,e){const n=t.match(e);return n?n[1]:null}class S extends _{constructor(t,{location:e=g.location,threshold:n=g.threshold,distance:s=g.distance,includeMatches:i=g.includeMatches,findAllMatches:r=g.findAllMatches,minMatchCharLength:c=g.minMatchCharLength,isCaseSensitive:o=g.isCaseSensitive,ignoreLocation:a=g.ignoreLocation}={}){super(t),this._bitapSearch=new w(t,{location:e,threshold:n,distance:s,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class v extends _{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,n=0;const s=[],i=this.pattern.length;for(;(e=t.indexOf(this.pattern,n))>-1;)n=e+i,s.push([e,n-1]);const r=!!s.length;return{isMatch:r,score:r?0:1,indices:s}}}const I=[class extends _{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},v,class extends _{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends _{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends _{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends _{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends _{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},S],k=I.length,C=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/,E=new Set([S.type,v.type]);const b=[];function A(t,e){for(let n=0,s=b.length;n<s;n+=1){let s=b[n];if(s.condition(t,e))return new s(t,e)}return new w(t,e)}const R="$and",$=t=>!(!t.$and&&!t.$or),F=t=>({[R]:Object.keys(t).map((e=>({[e]:t[e]})))});function j(n,s,{auto:r=!0}={}){const c=n=>{let o=Object.keys(n);const a=(t=>!!t.$path)(n);if(!a&&o.length>1&&!$(n))return c(F(n));if((e=>!t(e)&&i(e)&&!$(e))(n)){const t=a?n.$path:o[0],i=a?n.$val:n[t];if(!e(i))throw new Error((t=>`Invalid value for key ${t}`)(t));const c={keyId:d(t),pattern:i};return r&&(c.searcher=A(i,s)),c}let h={children:[],operator:o[0]};return o.forEach((e=>{const s=n[e];t(s)&&s.forEach((t=>{h.children.push(c(t))}))})),h};return $(n)||(n=F(n)),c(n)}function O(t,e){const n=t.matches;e.matches=[],r(n)&&n.forEach((t=>{if(!r(t.indices)||!t.indices.length)return;const{indices:n,value:s}=t;let i={indices:n,value:s};t.key&&(i.key=t.key.src),t.idx>-1&&(i.refIndex=t.idx),e.matches.push(i)}))}function T(t,e){e.score=t.score}class U{constructor(t,e={},n){this.options={...g,...e},this.options.useExtendedSearch,this._keyStore=new h(this.options.keys),this.setCollection(t,n)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof p))throw new Error("Incorrect 'index' type");this._myIndex=e||m(this.options.keys,this._docs,{getFn:this.options.getFn})}add(t){r(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let n=0,s=this._docs.length;n<s;n+=1){const i=this._docs[n];t(i,n)&&(this.removeAt(n),n-=1,s-=1,e.push(i))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:n=-1}={}){const{includeMatches:i,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let h=e(t)?e(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return function(t,{ignoreFieldNorm:e=g.ignoreFieldNorm}){t.forEach((t=>{let n=1;t.matches.forEach((({key:t,norm:s,score:i})=>{const r=t?t.weight:null;n*=Math.pow(0===i&&r?Number.EPSILON:i,(r||1)*(e?1:s))})),t.score=n}))}(h,{ignoreFieldNorm:a}),c&&h.sort(o),s(n)&&n>-1&&(h=h.slice(0,n)),function(t,e,{includeMatches:n=g.includeMatches,includeScore:s=g.includeScore}={}){const i=[];return n&&i.push(O),s&&i.push(T),t.map((t=>{const{idx:n}=t,s={item:e[n],refIndex:n};return i.length&&i.forEach((e=>{e(t,s)})),s}))}(h,this._docs,{includeMatches:i,includeScore:r})}_searchStringList(t){const e=A(t,this.options),{records:n}=this._myIndex,s=[];return n.forEach((({v:t,i:n,n:i})=>{if(!r(t))return;const{isMatch:c,score:o,indices:a}=e.searchIn(t);c&&s.push({item:t,idx:n,matches:[{score:o,value:t,norm:i,indices:a}]})})),s}_searchLogical(t){const e=j(t,this.options),n=(t,e,s)=>{if(!t.children){const{keyId:n,searcher:i}=t,r=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(e,n),searcher:i});return r&&r.length?[{idx:s,item:e,matches:r}]:[]}switch(t.operator){case R:{const i=[];for(let r=0,c=t.children.length;r<c;r+=1){const c=t.children[r],o=n(c,e,s);if(!o.length)return[];i.push(...o)}return i}case"$or":{const i=[];for(let r=0,c=t.children.length;r<c;r+=1){const c=t.children[r],o=n(c,e,s);if(o.length){i.push(...o);break}}return i}}},s=this._myIndex.records,i={},c=[];return s.forEach((({$:t,i:s})=>{if(r(t)){let r=n(e,t,s);r.length&&(i[s]||(i[s]={idx:s,item:t,matches:[]},c.push(i[s])),r.forEach((({matches:t})=>{i[s].matches.push(...t)})))}})),c}_searchObjectList(t){const e=A(t,this.options),{keys:n,records:s}=this._myIndex,i=[];return s.forEach((({$:t,i:s})=>{if(!r(t))return;let c=[];n.forEach(((n,s)=>{c.push(...this._findMatches({key:n,value:t[s],searcher:e}))})),c.length&&i.push({idx:s,item:t,matches:c})})),i}_findMatches({key:e,value:n,searcher:s}){if(!r(n))return[];let i=[];if(t(n))n.forEach((({v:t,i:n,n:c})=>{if(!r(t))return;const{isMatch:o,score:a,indices:h}=s.searchIn(t);o&&i.push({score:a,key:e,value:t,idx:n,norm:c,indices:h})}));else{const{v:t,n:r}=n,{isMatch:c,score:o,indices:a}=s.searchIn(t);c&&i.push({score:o,key:e,value:t,norm:r,indices:a})}return i}}U.version="6.4.6",U.createIndex=m,U.parseIndex=function(t,{getFn:e=g.getFn}={}){const{keys:n,records:s}=t,i=new p({getFn:e});return i.setKeys(n),i.setIndexRecords(s),i},U.config=g,U.parseQuery=j,function(...t){b.push(...t)}(class{constructor(t,{isCaseSensitive:e=g.isCaseSensitive,includeMatches:n=g.includeMatches,minMatchCharLength:s=g.minMatchCharLength,ignoreLocation:i=g.ignoreLocation,findAllMatches:r=g.findAllMatches,location:c=g.location,threshold:o=g.threshold,distance:a=g.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:n,minMatchCharLength:s,findAllMatches:r,ignoreLocation:i,location:c,threshold:o,distance:a},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map((t=>{let n=t.trim().split(C).filter((t=>t&&!!t.trim())),s=[];for(let t=0,i=n.length;t<i;t+=1){const i=n[t];let r=!1,c=-1;for(;!r&&++c<k;){const t=I[c];let n=t.isMultiMatch(i);n&&(s.push(new t(n,e)),r=!0)}if(!r)for(c=-1;++c<k;){const t=I[c];let n=t.isSingleMatch(i);if(n){s.push(new t(n,e));break}}}return s}))}(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:s}=this.options;t=s?t:t.toLowerCase();let i=0,r=[],c=0;for(let s=0,o=e.length;s<o;s+=1){const o=e[s];r.length=0,i=0;for(let e=0,s=o.length;e<s;e+=1){const s=o[e],{isMatch:a,indices:h,score:l}=s.search(t);if(!a){c=0,i=0,r.length=0;break}if(i+=1,c+=l,n){const t=s.constructor.type;E.has(t)?r=[...r,...h]:r.push(h)}}if(i){let t={isMatch:!0,score:c/i};return n&&(t.indices=r),t}}return{isMatch:!1,score:1}}});const N=U;function q(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}let P;!function(t){t.INIT_CALC="init",t.REQUEST_CALC="req_calc",t.RESULT_CALC="res_calc",t.REQUEST_FILTER="req_filter",t.RESULT_FILTER="res_filter"}(P||(P={}));const W=n("./node_modules/x-img-diff-js/package.json").i8,z=self;let K=!1,Q=null;const V=({payload:{raw:t,img1:e,img2:n,actualSrc:s,expectedSrc:i,seq:r}})=>{const c=z.Module.detectDiff(z.Module,e,n,{});z.postMessage({type:P.RESULT_CALC,payload:{seq:r,raw:t,actualSrc:s,expectedSrc:i,result:{...c,images:[{width:e.width,height:e.height},{width:n.width,height:n.height}]}}})};z.Module=new class{constructor({init:t,version:e,wasmUrl:n}){q(this,"_init",void 0),q(this,"_version",void 0),q(this,"_wasmUrl",void 0),this._init=t,this._version=e,this._wasmUrl=n}locateFile(t){return self.location.pathname.replace(/\[^\/]*$/,"/")+t}instantiateWasm(t,e){return function(t,e,n){const s="wasm-cache";async function i(){const t=await fetch(e),s=await t.arrayBuffer();return await WebAssembly.instantiate(s,n)}return new Promise(((e,n)=>{const i=indexedDB.open("wasm-cache",t);i.onerror=n.bind(null,"Error opening wasm cache database"),i.onsuccess=()=>{e(i.result)},i.onupgradeneeded=t=>{const e=i.result;e.objectStoreNames.contains(s)&&(console.log("Clearing out version ".concat(t.oldVersion," wasm cache")),e.deleteObjectStore(s)),console.log("Creating version ".concat(t.newVersion," wasm cache")),e.createObjectStore(s)}})).then((t=>function(t){return new Promise(((n,i)=>{const r=t.transaction([s]).objectStore(s).get(e);r.onerror=i.bind(null,"Error getting wasm module ".concat(e)),r.onsuccess=()=>{r.result?n(r.result):i("Module ".concat(e," was not found in wasm cache"))}}))}(t).then((t=>(console.log("Found ".concat(e," in wasm cache")),WebAssembly.instantiate(t,n))),(n=>(console.log(n),i().then((n=>(setTimeout((()=>function(t,n){const i=t.transaction([s],"readwrite").objectStore(s);try{const t=i.put(n,e);t.onerror=t=>{console.log("Failed to store in wasm cache: ".concat(t))},t.onsuccess=()=>{console.log("Successfully stored ".concat(e," in wasm cache"))}}catch(t){console.warn("An error was thrown... in storing wasm cache..."),console.warn(t)}}(t,n.module)),0),n.instance))))))),(t=>(console.log(t),i().then((t=>t.instance)))))}(this._version,this._wasmUrl,t).then((t=>e(t))),{}}onInit(t){this._init=t}onRuntimeInitialized(){if(this._init)return this._init(this)}}({version:function(t){const[,e,n,s]=t.match(/^(\d*)\.(\d*)\.(\d*)/);return 1e4*+e+100*+n+ +s}(W),wasmUrl:z.wasmUrl,init:()=>{K=!0,null!=Q&&V(Q),z.postMessage({type:P.INIT_CALC})}}),z.addEventListener("message",(({data:t})=>{switch(console.log("Received: ",t),t.type){case P.REQUEST_CALC:K?V(t):Q=t;break;case P.REQUEST_FILTER:(({payload:{input:t,newItems:e,passedItems:n,failedItems:s,deletedItems:i}})=>{if(!t)return z.postMessage({type:P.RESULT_FILTER,payload:{newItems:e,passedItems:n,failedItems:s,deletedItems:i}});const r=e=>new N(e,{isCaseSensitive:!1,keys:["name"],threshold:.3}).search(t).map((({item:t})=>t));z.postMessage({type:P.RESULT_FILTER,payload:{newItems:r(e),passedItems:r(n),failedItems:r(s),deletedItems:r(i)}})})(t)}}))})()})();
1
+ (function() {
2
+ "use strict";
3
+ function isArray(value) {
4
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
5
+ }
6
+ const INFINITY = 1 / 0;
7
+ function baseToString(value) {
8
+ if (typeof value == "string") {
9
+ return value;
10
+ }
11
+ let result = value + "";
12
+ return result == "0" && 1 / value == -INFINITY ? "-0" : result;
13
+ }
14
+ function toString(value) {
15
+ return value == null ? "" : baseToString(value);
16
+ }
17
+ function isString(value) {
18
+ return typeof value === "string";
19
+ }
20
+ function isNumber(value) {
21
+ return typeof value === "number";
22
+ }
23
+ function isBoolean(value) {
24
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
25
+ }
26
+ function isObject(value) {
27
+ return typeof value === "object";
28
+ }
29
+ function isObjectLike(value) {
30
+ return isObject(value) && value !== null;
31
+ }
32
+ function isDefined(value) {
33
+ return value !== void 0 && value !== null;
34
+ }
35
+ function isBlank(value) {
36
+ return !value.trim().length;
37
+ }
38
+ function getTag(value) {
39
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
40
+ }
41
+ const EXTENDED_SEARCH_UNAVAILABLE = "Extended search is not available";
42
+ const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
43
+ const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
44
+ const PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
45
+ const MISSING_KEY_PROPERTY = (name2) => `Missing ${name2} property in key`;
46
+ const INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
47
+ const hasOwn = Object.prototype.hasOwnProperty;
48
+ class KeyStore {
49
+ constructor(keys) {
50
+ this._keys = [];
51
+ this._keyMap = {};
52
+ let totalWeight = 0;
53
+ keys.forEach((key) => {
54
+ let obj = createKey(key);
55
+ this._keys.push(obj);
56
+ this._keyMap[obj.id] = obj;
57
+ totalWeight += obj.weight;
58
+ });
59
+ this._keys.forEach((key) => {
60
+ key.weight /= totalWeight;
61
+ });
62
+ }
63
+ get(keyId) {
64
+ return this._keyMap[keyId];
65
+ }
66
+ keys() {
67
+ return this._keys;
68
+ }
69
+ toJSON() {
70
+ return JSON.stringify(this._keys);
71
+ }
72
+ }
73
+ function createKey(key) {
74
+ let path = null;
75
+ let id = null;
76
+ let src = null;
77
+ let weight = 1;
78
+ let getFn = null;
79
+ if (isString(key) || isArray(key)) {
80
+ src = key;
81
+ path = createKeyPath(key);
82
+ id = createKeyId(key);
83
+ } else {
84
+ if (!hasOwn.call(key, "name")) {
85
+ throw new Error(MISSING_KEY_PROPERTY("name"));
86
+ }
87
+ const name2 = key.name;
88
+ src = name2;
89
+ if (hasOwn.call(key, "weight")) {
90
+ weight = key.weight;
91
+ if (weight <= 0) {
92
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(name2));
93
+ }
94
+ }
95
+ path = createKeyPath(name2);
96
+ id = createKeyId(name2);
97
+ getFn = key.getFn;
98
+ }
99
+ return { path, id, weight, src, getFn };
100
+ }
101
+ function createKeyPath(key) {
102
+ return isArray(key) ? key : key.split(".");
103
+ }
104
+ function createKeyId(key) {
105
+ return isArray(key) ? key.join(".") : key;
106
+ }
107
+ function get(obj, path) {
108
+ let list = [];
109
+ let arr = false;
110
+ const deepGet = (obj2, path2, index) => {
111
+ if (!isDefined(obj2)) {
112
+ return;
113
+ }
114
+ if (!path2[index]) {
115
+ list.push(obj2);
116
+ } else {
117
+ let key = path2[index];
118
+ const value = obj2[key];
119
+ if (!isDefined(value)) {
120
+ return;
121
+ }
122
+ if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
123
+ list.push(toString(value));
124
+ } else if (isArray(value)) {
125
+ arr = true;
126
+ for (let i = 0, len = value.length; i < len; i += 1) {
127
+ deepGet(value[i], path2, index + 1);
128
+ }
129
+ } else if (path2.length) {
130
+ deepGet(value, path2, index + 1);
131
+ }
132
+ }
133
+ };
134
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
135
+ return arr ? list : list[0];
136
+ }
137
+ const MatchOptions = {
138
+ // Whether the matches should be included in the result set. When `true`, each record in the result
139
+ // set will include the indices of the matched characters.
140
+ // These can consequently be used for highlighting purposes.
141
+ includeMatches: false,
142
+ // When `true`, the matching function will continue to the end of a search pattern even if
143
+ // a perfect match has already been located in the string.
144
+ findAllMatches: false,
145
+ // Minimum number of characters that must be matched before a result is considered a match
146
+ minMatchCharLength: 1
147
+ };
148
+ const BasicOptions = {
149
+ // When `true`, the algorithm continues searching to the end of the input even if a perfect
150
+ // match is found before the end of the same input.
151
+ isCaseSensitive: false,
152
+ // When true, the matching function will continue to the end of a search pattern even if
153
+ includeScore: false,
154
+ // List of properties that will be searched. This also supports nested properties.
155
+ keys: [],
156
+ // Whether to sort the result list, by score
157
+ shouldSort: true,
158
+ // Default sort function: sort by ascending score, ascending index
159
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
160
+ };
161
+ const FuzzyOptions = {
162
+ // Approximately where in the text is the pattern expected to be found?
163
+ location: 0,
164
+ // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
165
+ // (of both letters and location), a threshold of '1.0' would match anything.
166
+ threshold: 0.6,
167
+ // Determines how close the match must be to the fuzzy location (specified above).
168
+ // An exact letter match which is 'distance' characters away from the fuzzy location
169
+ // would score as a complete mismatch. A distance of '0' requires the match be at
170
+ // the exact location specified, a threshold of '1000' would require a perfect match
171
+ // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
172
+ distance: 100
173
+ };
174
+ const AdvancedOptions = {
175
+ // When `true`, it enables the use of unix-like search commands
176
+ useExtendedSearch: false,
177
+ // The get function to use when fetching an object's properties.
178
+ // The default will search nested paths *ie foo.bar.baz*
179
+ getFn: get,
180
+ // When `true`, search will ignore `location` and `distance`, so it won't matter
181
+ // where in the string the pattern appears.
182
+ // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
183
+ ignoreLocation: false,
184
+ // When `true`, the calculation for the relevance score (used for sorting) will
185
+ // ignore the field-length norm.
186
+ // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
187
+ ignoreFieldNorm: false,
188
+ // The weight to determine how much field length norm effects scoring.
189
+ fieldNormWeight: 1
190
+ };
191
+ var Config = {
192
+ ...BasicOptions,
193
+ ...MatchOptions,
194
+ ...FuzzyOptions,
195
+ ...AdvancedOptions
196
+ };
197
+ const SPACE = /[^ ]+/g;
198
+ function norm(weight = 1, mantissa = 3) {
199
+ const cache = /* @__PURE__ */ new Map();
200
+ const m = Math.pow(10, mantissa);
201
+ return {
202
+ get(value) {
203
+ const numTokens = value.match(SPACE).length;
204
+ if (cache.has(numTokens)) {
205
+ return cache.get(numTokens);
206
+ }
207
+ const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
208
+ const n = parseFloat(Math.round(norm2 * m) / m);
209
+ cache.set(numTokens, n);
210
+ return n;
211
+ },
212
+ clear() {
213
+ cache.clear();
214
+ }
215
+ };
216
+ }
217
+ class FuseIndex {
218
+ constructor({
219
+ getFn = Config.getFn,
220
+ fieldNormWeight = Config.fieldNormWeight
221
+ } = {}) {
222
+ this.norm = norm(fieldNormWeight, 3);
223
+ this.getFn = getFn;
224
+ this.isCreated = false;
225
+ this.setIndexRecords();
226
+ }
227
+ setSources(docs = []) {
228
+ this.docs = docs;
229
+ }
230
+ setIndexRecords(records = []) {
231
+ this.records = records;
232
+ }
233
+ setKeys(keys = []) {
234
+ this.keys = keys;
235
+ this._keysMap = {};
236
+ keys.forEach((key, idx) => {
237
+ this._keysMap[key.id] = idx;
238
+ });
239
+ }
240
+ create() {
241
+ if (this.isCreated || !this.docs.length) {
242
+ return;
243
+ }
244
+ this.isCreated = true;
245
+ if (isString(this.docs[0])) {
246
+ this.docs.forEach((doc, docIndex) => {
247
+ this._addString(doc, docIndex);
248
+ });
249
+ } else {
250
+ this.docs.forEach((doc, docIndex) => {
251
+ this._addObject(doc, docIndex);
252
+ });
253
+ }
254
+ this.norm.clear();
255
+ }
256
+ // Adds a doc to the end of the index
257
+ add(doc) {
258
+ const idx = this.size();
259
+ if (isString(doc)) {
260
+ this._addString(doc, idx);
261
+ } else {
262
+ this._addObject(doc, idx);
263
+ }
264
+ }
265
+ // Removes the doc at the specified index of the index
266
+ removeAt(idx) {
267
+ this.records.splice(idx, 1);
268
+ for (let i = idx, len = this.size(); i < len; i += 1) {
269
+ this.records[i].i -= 1;
270
+ }
271
+ }
272
+ getValueForItemAtKeyId(item, keyId) {
273
+ return item[this._keysMap[keyId]];
274
+ }
275
+ size() {
276
+ return this.records.length;
277
+ }
278
+ _addString(doc, docIndex) {
279
+ if (!isDefined(doc) || isBlank(doc)) {
280
+ return;
281
+ }
282
+ let record = {
283
+ v: doc,
284
+ i: docIndex,
285
+ n: this.norm.get(doc)
286
+ };
287
+ this.records.push(record);
288
+ }
289
+ _addObject(doc, docIndex) {
290
+ let record = { i: docIndex, $: {} };
291
+ this.keys.forEach((key, keyIndex) => {
292
+ let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
293
+ if (!isDefined(value)) {
294
+ return;
295
+ }
296
+ if (isArray(value)) {
297
+ let subRecords = [];
298
+ const stack = [{ nestedArrIndex: -1, value }];
299
+ while (stack.length) {
300
+ const { nestedArrIndex, value: value2 } = stack.pop();
301
+ if (!isDefined(value2)) {
302
+ continue;
303
+ }
304
+ if (isString(value2) && !isBlank(value2)) {
305
+ let subRecord = {
306
+ v: value2,
307
+ i: nestedArrIndex,
308
+ n: this.norm.get(value2)
309
+ };
310
+ subRecords.push(subRecord);
311
+ } else if (isArray(value2)) {
312
+ value2.forEach((item, k) => {
313
+ stack.push({
314
+ nestedArrIndex: k,
315
+ value: item
316
+ });
317
+ });
318
+ } else
319
+ ;
320
+ }
321
+ record.$[keyIndex] = subRecords;
322
+ } else if (isString(value) && !isBlank(value)) {
323
+ let subRecord = {
324
+ v: value,
325
+ n: this.norm.get(value)
326
+ };
327
+ record.$[keyIndex] = subRecord;
328
+ }
329
+ });
330
+ this.records.push(record);
331
+ }
332
+ toJSON() {
333
+ return {
334
+ keys: this.keys,
335
+ records: this.records
336
+ };
337
+ }
338
+ }
339
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
340
+ const myIndex = new FuseIndex({ getFn, fieldNormWeight });
341
+ myIndex.setKeys(keys.map(createKey));
342
+ myIndex.setSources(docs);
343
+ myIndex.create();
344
+ return myIndex;
345
+ }
346
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
347
+ const { keys, records } = data;
348
+ const myIndex = new FuseIndex({ getFn, fieldNormWeight });
349
+ myIndex.setKeys(keys);
350
+ myIndex.setIndexRecords(records);
351
+ return myIndex;
352
+ }
353
+ function computeScore$1(pattern, {
354
+ errors = 0,
355
+ currentLocation = 0,
356
+ expectedLocation = 0,
357
+ distance = Config.distance,
358
+ ignoreLocation = Config.ignoreLocation
359
+ } = {}) {
360
+ const accuracy = errors / pattern.length;
361
+ if (ignoreLocation) {
362
+ return accuracy;
363
+ }
364
+ const proximity = Math.abs(expectedLocation - currentLocation);
365
+ if (!distance) {
366
+ return proximity ? 1 : accuracy;
367
+ }
368
+ return accuracy + proximity / distance;
369
+ }
370
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
371
+ let indices = [];
372
+ let start = -1;
373
+ let end = -1;
374
+ let i = 0;
375
+ for (let len = matchmask.length; i < len; i += 1) {
376
+ let match = matchmask[i];
377
+ if (match && start === -1) {
378
+ start = i;
379
+ } else if (!match && start !== -1) {
380
+ end = i - 1;
381
+ if (end - start + 1 >= minMatchCharLength) {
382
+ indices.push([start, end]);
383
+ }
384
+ start = -1;
385
+ }
386
+ }
387
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
388
+ indices.push([start, i - 1]);
389
+ }
390
+ return indices;
391
+ }
392
+ const MAX_BITS = 32;
393
+ function search(text, pattern, patternAlphabet, {
394
+ location = Config.location,
395
+ distance = Config.distance,
396
+ threshold = Config.threshold,
397
+ findAllMatches = Config.findAllMatches,
398
+ minMatchCharLength = Config.minMatchCharLength,
399
+ includeMatches = Config.includeMatches,
400
+ ignoreLocation = Config.ignoreLocation
401
+ } = {}) {
402
+ if (pattern.length > MAX_BITS) {
403
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
404
+ }
405
+ const patternLen = pattern.length;
406
+ const textLen = text.length;
407
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
408
+ let currentThreshold = threshold;
409
+ let bestLocation = expectedLocation;
410
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
411
+ const matchMask = computeMatches ? Array(textLen) : [];
412
+ let index;
413
+ while ((index = text.indexOf(pattern, bestLocation)) > -1) {
414
+ let score = computeScore$1(pattern, {
415
+ currentLocation: index,
416
+ expectedLocation,
417
+ distance,
418
+ ignoreLocation
419
+ });
420
+ currentThreshold = Math.min(score, currentThreshold);
421
+ bestLocation = index + patternLen;
422
+ if (computeMatches) {
423
+ let i = 0;
424
+ while (i < patternLen) {
425
+ matchMask[index + i] = 1;
426
+ i += 1;
427
+ }
428
+ }
429
+ }
430
+ bestLocation = -1;
431
+ let lastBitArr = [];
432
+ let finalScore = 1;
433
+ let binMax = patternLen + textLen;
434
+ const mask = 1 << patternLen - 1;
435
+ for (let i = 0; i < patternLen; i += 1) {
436
+ let binMin = 0;
437
+ let binMid = binMax;
438
+ while (binMin < binMid) {
439
+ const score2 = computeScore$1(pattern, {
440
+ errors: i,
441
+ currentLocation: expectedLocation + binMid,
442
+ expectedLocation,
443
+ distance,
444
+ ignoreLocation
445
+ });
446
+ if (score2 <= currentThreshold) {
447
+ binMin = binMid;
448
+ } else {
449
+ binMax = binMid;
450
+ }
451
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
452
+ }
453
+ binMax = binMid;
454
+ let start = Math.max(1, expectedLocation - binMid + 1);
455
+ let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
456
+ let bitArr = Array(finish + 2);
457
+ bitArr[finish + 1] = (1 << i) - 1;
458
+ for (let j = finish; j >= start; j -= 1) {
459
+ let currentLocation = j - 1;
460
+ let charMatch = patternAlphabet[text.charAt(currentLocation)];
461
+ if (computeMatches) {
462
+ matchMask[currentLocation] = +!!charMatch;
463
+ }
464
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
465
+ if (i) {
466
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
467
+ }
468
+ if (bitArr[j] & mask) {
469
+ finalScore = computeScore$1(pattern, {
470
+ errors: i,
471
+ currentLocation,
472
+ expectedLocation,
473
+ distance,
474
+ ignoreLocation
475
+ });
476
+ if (finalScore <= currentThreshold) {
477
+ currentThreshold = finalScore;
478
+ bestLocation = currentLocation;
479
+ if (bestLocation <= expectedLocation) {
480
+ break;
481
+ }
482
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
483
+ }
484
+ }
485
+ }
486
+ const score = computeScore$1(pattern, {
487
+ errors: i + 1,
488
+ currentLocation: expectedLocation,
489
+ expectedLocation,
490
+ distance,
491
+ ignoreLocation
492
+ });
493
+ if (score > currentThreshold) {
494
+ break;
495
+ }
496
+ lastBitArr = bitArr;
497
+ }
498
+ const result = {
499
+ isMatch: bestLocation >= 0,
500
+ // Count exact matches (those with a score of 0) to be "almost" exact
501
+ score: Math.max(1e-3, finalScore)
502
+ };
503
+ if (computeMatches) {
504
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
505
+ if (!indices.length) {
506
+ result.isMatch = false;
507
+ } else if (includeMatches) {
508
+ result.indices = indices;
509
+ }
510
+ }
511
+ return result;
512
+ }
513
+ function createPatternAlphabet(pattern) {
514
+ let mask = {};
515
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
516
+ const char = pattern.charAt(i);
517
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
518
+ }
519
+ return mask;
520
+ }
521
+ class BitapSearch {
522
+ constructor(pattern, {
523
+ location = Config.location,
524
+ threshold = Config.threshold,
525
+ distance = Config.distance,
526
+ includeMatches = Config.includeMatches,
527
+ findAllMatches = Config.findAllMatches,
528
+ minMatchCharLength = Config.minMatchCharLength,
529
+ isCaseSensitive = Config.isCaseSensitive,
530
+ ignoreLocation = Config.ignoreLocation
531
+ } = {}) {
532
+ this.options = {
533
+ location,
534
+ threshold,
535
+ distance,
536
+ includeMatches,
537
+ findAllMatches,
538
+ minMatchCharLength,
539
+ isCaseSensitive,
540
+ ignoreLocation
541
+ };
542
+ this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
543
+ this.chunks = [];
544
+ if (!this.pattern.length) {
545
+ return;
546
+ }
547
+ const addChunk = (pattern2, startIndex) => {
548
+ this.chunks.push({
549
+ pattern: pattern2,
550
+ alphabet: createPatternAlphabet(pattern2),
551
+ startIndex
552
+ });
553
+ };
554
+ const len = this.pattern.length;
555
+ if (len > MAX_BITS) {
556
+ let i = 0;
557
+ const remainder = len % MAX_BITS;
558
+ const end = len - remainder;
559
+ while (i < end) {
560
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
561
+ i += MAX_BITS;
562
+ }
563
+ if (remainder) {
564
+ const startIndex = len - MAX_BITS;
565
+ addChunk(this.pattern.substr(startIndex), startIndex);
566
+ }
567
+ } else {
568
+ addChunk(this.pattern, 0);
569
+ }
570
+ }
571
+ searchIn(text) {
572
+ const { isCaseSensitive, includeMatches } = this.options;
573
+ if (!isCaseSensitive) {
574
+ text = text.toLowerCase();
575
+ }
576
+ if (this.pattern === text) {
577
+ let result2 = {
578
+ isMatch: true,
579
+ score: 0
580
+ };
581
+ if (includeMatches) {
582
+ result2.indices = [[0, text.length - 1]];
583
+ }
584
+ return result2;
585
+ }
586
+ const {
587
+ location,
588
+ distance,
589
+ threshold,
590
+ findAllMatches,
591
+ minMatchCharLength,
592
+ ignoreLocation
593
+ } = this.options;
594
+ let allIndices = [];
595
+ let totalScore = 0;
596
+ let hasMatches = false;
597
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
598
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
599
+ location: location + startIndex,
600
+ distance,
601
+ threshold,
602
+ findAllMatches,
603
+ minMatchCharLength,
604
+ includeMatches,
605
+ ignoreLocation
606
+ });
607
+ if (isMatch) {
608
+ hasMatches = true;
609
+ }
610
+ totalScore += score;
611
+ if (isMatch && indices) {
612
+ allIndices = [...allIndices, ...indices];
613
+ }
614
+ });
615
+ let result = {
616
+ isMatch: hasMatches,
617
+ score: hasMatches ? totalScore / this.chunks.length : 1
618
+ };
619
+ if (hasMatches && includeMatches) {
620
+ result.indices = allIndices;
621
+ }
622
+ return result;
623
+ }
624
+ }
625
+ class BaseMatch {
626
+ constructor(pattern) {
627
+ this.pattern = pattern;
628
+ }
629
+ static isMultiMatch(pattern) {
630
+ return getMatch(pattern, this.multiRegex);
631
+ }
632
+ static isSingleMatch(pattern) {
633
+ return getMatch(pattern, this.singleRegex);
634
+ }
635
+ search() {
636
+ }
637
+ }
638
+ function getMatch(pattern, exp) {
639
+ const matches = pattern.match(exp);
640
+ return matches ? matches[1] : null;
641
+ }
642
+ class ExactMatch extends BaseMatch {
643
+ constructor(pattern) {
644
+ super(pattern);
645
+ }
646
+ static get type() {
647
+ return "exact";
648
+ }
649
+ static get multiRegex() {
650
+ return /^="(.*)"$/;
651
+ }
652
+ static get singleRegex() {
653
+ return /^=(.*)$/;
654
+ }
655
+ search(text) {
656
+ const isMatch = text === this.pattern;
657
+ return {
658
+ isMatch,
659
+ score: isMatch ? 0 : 1,
660
+ indices: [0, this.pattern.length - 1]
661
+ };
662
+ }
663
+ }
664
+ class InverseExactMatch extends BaseMatch {
665
+ constructor(pattern) {
666
+ super(pattern);
667
+ }
668
+ static get type() {
669
+ return "inverse-exact";
670
+ }
671
+ static get multiRegex() {
672
+ return /^!"(.*)"$/;
673
+ }
674
+ static get singleRegex() {
675
+ return /^!(.*)$/;
676
+ }
677
+ search(text) {
678
+ const index = text.indexOf(this.pattern);
679
+ const isMatch = index === -1;
680
+ return {
681
+ isMatch,
682
+ score: isMatch ? 0 : 1,
683
+ indices: [0, text.length - 1]
684
+ };
685
+ }
686
+ }
687
+ class PrefixExactMatch extends BaseMatch {
688
+ constructor(pattern) {
689
+ super(pattern);
690
+ }
691
+ static get type() {
692
+ return "prefix-exact";
693
+ }
694
+ static get multiRegex() {
695
+ return /^\^"(.*)"$/;
696
+ }
697
+ static get singleRegex() {
698
+ return /^\^(.*)$/;
699
+ }
700
+ search(text) {
701
+ const isMatch = text.startsWith(this.pattern);
702
+ return {
703
+ isMatch,
704
+ score: isMatch ? 0 : 1,
705
+ indices: [0, this.pattern.length - 1]
706
+ };
707
+ }
708
+ }
709
+ class InversePrefixExactMatch extends BaseMatch {
710
+ constructor(pattern) {
711
+ super(pattern);
712
+ }
713
+ static get type() {
714
+ return "inverse-prefix-exact";
715
+ }
716
+ static get multiRegex() {
717
+ return /^!\^"(.*)"$/;
718
+ }
719
+ static get singleRegex() {
720
+ return /^!\^(.*)$/;
721
+ }
722
+ search(text) {
723
+ const isMatch = !text.startsWith(this.pattern);
724
+ return {
725
+ isMatch,
726
+ score: isMatch ? 0 : 1,
727
+ indices: [0, text.length - 1]
728
+ };
729
+ }
730
+ }
731
+ class SuffixExactMatch extends BaseMatch {
732
+ constructor(pattern) {
733
+ super(pattern);
734
+ }
735
+ static get type() {
736
+ return "suffix-exact";
737
+ }
738
+ static get multiRegex() {
739
+ return /^"(.*)"\$$/;
740
+ }
741
+ static get singleRegex() {
742
+ return /^(.*)\$$/;
743
+ }
744
+ search(text) {
745
+ const isMatch = text.endsWith(this.pattern);
746
+ return {
747
+ isMatch,
748
+ score: isMatch ? 0 : 1,
749
+ indices: [text.length - this.pattern.length, text.length - 1]
750
+ };
751
+ }
752
+ }
753
+ class InverseSuffixExactMatch extends BaseMatch {
754
+ constructor(pattern) {
755
+ super(pattern);
756
+ }
757
+ static get type() {
758
+ return "inverse-suffix-exact";
759
+ }
760
+ static get multiRegex() {
761
+ return /^!"(.*)"\$$/;
762
+ }
763
+ static get singleRegex() {
764
+ return /^!(.*)\$$/;
765
+ }
766
+ search(text) {
767
+ const isMatch = !text.endsWith(this.pattern);
768
+ return {
769
+ isMatch,
770
+ score: isMatch ? 0 : 1,
771
+ indices: [0, text.length - 1]
772
+ };
773
+ }
774
+ }
775
+ class FuzzyMatch extends BaseMatch {
776
+ constructor(pattern, {
777
+ location = Config.location,
778
+ threshold = Config.threshold,
779
+ distance = Config.distance,
780
+ includeMatches = Config.includeMatches,
781
+ findAllMatches = Config.findAllMatches,
782
+ minMatchCharLength = Config.minMatchCharLength,
783
+ isCaseSensitive = Config.isCaseSensitive,
784
+ ignoreLocation = Config.ignoreLocation
785
+ } = {}) {
786
+ super(pattern);
787
+ this._bitapSearch = new BitapSearch(pattern, {
788
+ location,
789
+ threshold,
790
+ distance,
791
+ includeMatches,
792
+ findAllMatches,
793
+ minMatchCharLength,
794
+ isCaseSensitive,
795
+ ignoreLocation
796
+ });
797
+ }
798
+ static get type() {
799
+ return "fuzzy";
800
+ }
801
+ static get multiRegex() {
802
+ return /^"(.*)"$/;
803
+ }
804
+ static get singleRegex() {
805
+ return /^(.*)$/;
806
+ }
807
+ search(text) {
808
+ return this._bitapSearch.searchIn(text);
809
+ }
810
+ }
811
+ class IncludeMatch extends BaseMatch {
812
+ constructor(pattern) {
813
+ super(pattern);
814
+ }
815
+ static get type() {
816
+ return "include";
817
+ }
818
+ static get multiRegex() {
819
+ return /^'"(.*)"$/;
820
+ }
821
+ static get singleRegex() {
822
+ return /^'(.*)$/;
823
+ }
824
+ search(text) {
825
+ let location = 0;
826
+ let index;
827
+ const indices = [];
828
+ const patternLen = this.pattern.length;
829
+ while ((index = text.indexOf(this.pattern, location)) > -1) {
830
+ location = index + patternLen;
831
+ indices.push([index, location - 1]);
832
+ }
833
+ const isMatch = !!indices.length;
834
+ return {
835
+ isMatch,
836
+ score: isMatch ? 0 : 1,
837
+ indices
838
+ };
839
+ }
840
+ }
841
+ const searchers = [
842
+ ExactMatch,
843
+ IncludeMatch,
844
+ PrefixExactMatch,
845
+ InversePrefixExactMatch,
846
+ InverseSuffixExactMatch,
847
+ SuffixExactMatch,
848
+ InverseExactMatch,
849
+ FuzzyMatch
850
+ ];
851
+ const searchersLen = searchers.length;
852
+ const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
853
+ const OR_TOKEN = "|";
854
+ function parseQuery(pattern, options = {}) {
855
+ return pattern.split(OR_TOKEN).map((item) => {
856
+ let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
857
+ let results = [];
858
+ for (let i = 0, len = query.length; i < len; i += 1) {
859
+ const queryItem = query[i];
860
+ let found = false;
861
+ let idx = -1;
862
+ while (!found && ++idx < searchersLen) {
863
+ const searcher = searchers[idx];
864
+ let token = searcher.isMultiMatch(queryItem);
865
+ if (token) {
866
+ results.push(new searcher(token, options));
867
+ found = true;
868
+ }
869
+ }
870
+ if (found) {
871
+ continue;
872
+ }
873
+ idx = -1;
874
+ while (++idx < searchersLen) {
875
+ const searcher = searchers[idx];
876
+ let token = searcher.isSingleMatch(queryItem);
877
+ if (token) {
878
+ results.push(new searcher(token, options));
879
+ break;
880
+ }
881
+ }
882
+ }
883
+ return results;
884
+ });
885
+ }
886
+ const MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
887
+ class ExtendedSearch {
888
+ constructor(pattern, {
889
+ isCaseSensitive = Config.isCaseSensitive,
890
+ includeMatches = Config.includeMatches,
891
+ minMatchCharLength = Config.minMatchCharLength,
892
+ ignoreLocation = Config.ignoreLocation,
893
+ findAllMatches = Config.findAllMatches,
894
+ location = Config.location,
895
+ threshold = Config.threshold,
896
+ distance = Config.distance
897
+ } = {}) {
898
+ this.query = null;
899
+ this.options = {
900
+ isCaseSensitive,
901
+ includeMatches,
902
+ minMatchCharLength,
903
+ findAllMatches,
904
+ ignoreLocation,
905
+ location,
906
+ threshold,
907
+ distance
908
+ };
909
+ this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
910
+ this.query = parseQuery(this.pattern, this.options);
911
+ }
912
+ static condition(_, options) {
913
+ return options.useExtendedSearch;
914
+ }
915
+ searchIn(text) {
916
+ const query = this.query;
917
+ if (!query) {
918
+ return {
919
+ isMatch: false,
920
+ score: 1
921
+ };
922
+ }
923
+ const { includeMatches, isCaseSensitive } = this.options;
924
+ text = isCaseSensitive ? text : text.toLowerCase();
925
+ let numMatches = 0;
926
+ let allIndices = [];
927
+ let totalScore = 0;
928
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
929
+ const searchers2 = query[i];
930
+ allIndices.length = 0;
931
+ numMatches = 0;
932
+ for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
933
+ const searcher = searchers2[j];
934
+ const { isMatch, indices, score } = searcher.search(text);
935
+ if (isMatch) {
936
+ numMatches += 1;
937
+ totalScore += score;
938
+ if (includeMatches) {
939
+ const type = searcher.constructor.type;
940
+ if (MultiMatchSet.has(type)) {
941
+ allIndices = [...allIndices, ...indices];
942
+ } else {
943
+ allIndices.push(indices);
944
+ }
945
+ }
946
+ } else {
947
+ totalScore = 0;
948
+ numMatches = 0;
949
+ allIndices.length = 0;
950
+ break;
951
+ }
952
+ }
953
+ if (numMatches) {
954
+ let result = {
955
+ isMatch: true,
956
+ score: totalScore / numMatches
957
+ };
958
+ if (includeMatches) {
959
+ result.indices = allIndices;
960
+ }
961
+ return result;
962
+ }
963
+ }
964
+ return {
965
+ isMatch: false,
966
+ score: 1
967
+ };
968
+ }
969
+ }
970
+ const registeredSearchers = [];
971
+ function register(...args) {
972
+ registeredSearchers.push(...args);
973
+ }
974
+ function createSearcher(pattern, options) {
975
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
976
+ let searcherClass = registeredSearchers[i];
977
+ if (searcherClass.condition(pattern, options)) {
978
+ return new searcherClass(pattern, options);
979
+ }
980
+ }
981
+ return new BitapSearch(pattern, options);
982
+ }
983
+ const LogicalOperator = {
984
+ AND: "$and",
985
+ OR: "$or"
986
+ };
987
+ const KeyType = {
988
+ PATH: "$path",
989
+ PATTERN: "$val"
990
+ };
991
+ const isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
992
+ const isPath = (query) => !!query[KeyType.PATH];
993
+ const isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
994
+ const convertToExplicit = (query) => ({
995
+ [LogicalOperator.AND]: Object.keys(query).map((key) => ({
996
+ [key]: query[key]
997
+ }))
998
+ });
999
+ function parse(query, options, { auto = true } = {}) {
1000
+ const next = (query2) => {
1001
+ let keys = Object.keys(query2);
1002
+ const isQueryPath = isPath(query2);
1003
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
1004
+ return next(convertToExplicit(query2));
1005
+ }
1006
+ if (isLeaf(query2)) {
1007
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
1008
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
1009
+ if (!isString(pattern)) {
1010
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
1011
+ }
1012
+ const obj = {
1013
+ keyId: createKeyId(key),
1014
+ pattern
1015
+ };
1016
+ if (auto) {
1017
+ obj.searcher = createSearcher(pattern, options);
1018
+ }
1019
+ return obj;
1020
+ }
1021
+ let node = {
1022
+ children: [],
1023
+ operator: keys[0]
1024
+ };
1025
+ keys.forEach((key) => {
1026
+ const value = query2[key];
1027
+ if (isArray(value)) {
1028
+ value.forEach((item) => {
1029
+ node.children.push(next(item));
1030
+ });
1031
+ }
1032
+ });
1033
+ return node;
1034
+ };
1035
+ if (!isExpression(query)) {
1036
+ query = convertToExplicit(query);
1037
+ }
1038
+ return next(query);
1039
+ }
1040
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
1041
+ results.forEach((result) => {
1042
+ let totalScore = 1;
1043
+ result.matches.forEach(({ key, norm: norm2, score }) => {
1044
+ const weight = key ? key.weight : null;
1045
+ totalScore *= Math.pow(
1046
+ score === 0 && weight ? Number.EPSILON : score,
1047
+ (weight || 1) * (ignoreFieldNorm ? 1 : norm2)
1048
+ );
1049
+ });
1050
+ result.score = totalScore;
1051
+ });
1052
+ }
1053
+ function transformMatches(result, data) {
1054
+ const matches = result.matches;
1055
+ data.matches = [];
1056
+ if (!isDefined(matches)) {
1057
+ return;
1058
+ }
1059
+ matches.forEach((match) => {
1060
+ if (!isDefined(match.indices) || !match.indices.length) {
1061
+ return;
1062
+ }
1063
+ const { indices, value } = match;
1064
+ let obj = {
1065
+ indices,
1066
+ value
1067
+ };
1068
+ if (match.key) {
1069
+ obj.key = match.key.src;
1070
+ }
1071
+ if (match.idx > -1) {
1072
+ obj.refIndex = match.idx;
1073
+ }
1074
+ data.matches.push(obj);
1075
+ });
1076
+ }
1077
+ function transformScore(result, data) {
1078
+ data.score = result.score;
1079
+ }
1080
+ function format(results, docs, {
1081
+ includeMatches = Config.includeMatches,
1082
+ includeScore = Config.includeScore
1083
+ } = {}) {
1084
+ const transformers = [];
1085
+ if (includeMatches)
1086
+ transformers.push(transformMatches);
1087
+ if (includeScore)
1088
+ transformers.push(transformScore);
1089
+ return results.map((result) => {
1090
+ const { idx } = result;
1091
+ const data = {
1092
+ item: docs[idx],
1093
+ refIndex: idx
1094
+ };
1095
+ if (transformers.length) {
1096
+ transformers.forEach((transformer) => {
1097
+ transformer(result, data);
1098
+ });
1099
+ }
1100
+ return data;
1101
+ });
1102
+ }
1103
+ class Fuse {
1104
+ constructor(docs, options = {}, index) {
1105
+ this.options = { ...Config, ...options };
1106
+ if (this.options.useExtendedSearch && false) {
1107
+ throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
1108
+ }
1109
+ this._keyStore = new KeyStore(this.options.keys);
1110
+ this.setCollection(docs, index);
1111
+ }
1112
+ setCollection(docs, index) {
1113
+ this._docs = docs;
1114
+ if (index && !(index instanceof FuseIndex)) {
1115
+ throw new Error(INCORRECT_INDEX_TYPE);
1116
+ }
1117
+ this._myIndex = index || createIndex(this.options.keys, this._docs, {
1118
+ getFn: this.options.getFn,
1119
+ fieldNormWeight: this.options.fieldNormWeight
1120
+ });
1121
+ }
1122
+ add(doc) {
1123
+ if (!isDefined(doc)) {
1124
+ return;
1125
+ }
1126
+ this._docs.push(doc);
1127
+ this._myIndex.add(doc);
1128
+ }
1129
+ remove(predicate = () => false) {
1130
+ const results = [];
1131
+ for (let i = 0, len = this._docs.length; i < len; i += 1) {
1132
+ const doc = this._docs[i];
1133
+ if (predicate(doc, i)) {
1134
+ this.removeAt(i);
1135
+ i -= 1;
1136
+ len -= 1;
1137
+ results.push(doc);
1138
+ }
1139
+ }
1140
+ return results;
1141
+ }
1142
+ removeAt(idx) {
1143
+ this._docs.splice(idx, 1);
1144
+ this._myIndex.removeAt(idx);
1145
+ }
1146
+ getIndex() {
1147
+ return this._myIndex;
1148
+ }
1149
+ search(query, { limit = -1 } = {}) {
1150
+ const {
1151
+ includeMatches,
1152
+ includeScore,
1153
+ shouldSort,
1154
+ sortFn,
1155
+ ignoreFieldNorm
1156
+ } = this.options;
1157
+ let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
1158
+ computeScore(results, { ignoreFieldNorm });
1159
+ if (shouldSort) {
1160
+ results.sort(sortFn);
1161
+ }
1162
+ if (isNumber(limit) && limit > -1) {
1163
+ results = results.slice(0, limit);
1164
+ }
1165
+ return format(results, this._docs, {
1166
+ includeMatches,
1167
+ includeScore
1168
+ });
1169
+ }
1170
+ _searchStringList(query) {
1171
+ const searcher = createSearcher(query, this.options);
1172
+ const { records } = this._myIndex;
1173
+ const results = [];
1174
+ records.forEach(({ v: text, i: idx, n: norm2 }) => {
1175
+ if (!isDefined(text)) {
1176
+ return;
1177
+ }
1178
+ const { isMatch, score, indices } = searcher.searchIn(text);
1179
+ if (isMatch) {
1180
+ results.push({
1181
+ item: text,
1182
+ idx,
1183
+ matches: [{ score, value: text, norm: norm2, indices }]
1184
+ });
1185
+ }
1186
+ });
1187
+ return results;
1188
+ }
1189
+ _searchLogical(query) {
1190
+ const expression = parse(query, this.options);
1191
+ const evaluate = (node, item, idx) => {
1192
+ if (!node.children) {
1193
+ const { keyId, searcher } = node;
1194
+ const matches = this._findMatches({
1195
+ key: this._keyStore.get(keyId),
1196
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
1197
+ searcher
1198
+ });
1199
+ if (matches && matches.length) {
1200
+ return [
1201
+ {
1202
+ idx,
1203
+ item,
1204
+ matches
1205
+ }
1206
+ ];
1207
+ }
1208
+ return [];
1209
+ }
1210
+ const res = [];
1211
+ for (let i = 0, len = node.children.length; i < len; i += 1) {
1212
+ const child = node.children[i];
1213
+ const result = evaluate(child, item, idx);
1214
+ if (result.length) {
1215
+ res.push(...result);
1216
+ } else if (node.operator === LogicalOperator.AND) {
1217
+ return [];
1218
+ }
1219
+ }
1220
+ return res;
1221
+ };
1222
+ const records = this._myIndex.records;
1223
+ const resultMap = {};
1224
+ const results = [];
1225
+ records.forEach(({ $: item, i: idx }) => {
1226
+ if (isDefined(item)) {
1227
+ let expResults = evaluate(expression, item, idx);
1228
+ if (expResults.length) {
1229
+ if (!resultMap[idx]) {
1230
+ resultMap[idx] = { idx, item, matches: [] };
1231
+ results.push(resultMap[idx]);
1232
+ }
1233
+ expResults.forEach(({ matches }) => {
1234
+ resultMap[idx].matches.push(...matches);
1235
+ });
1236
+ }
1237
+ }
1238
+ });
1239
+ return results;
1240
+ }
1241
+ _searchObjectList(query) {
1242
+ const searcher = createSearcher(query, this.options);
1243
+ const { keys, records } = this._myIndex;
1244
+ const results = [];
1245
+ records.forEach(({ $: item, i: idx }) => {
1246
+ if (!isDefined(item)) {
1247
+ return;
1248
+ }
1249
+ let matches = [];
1250
+ keys.forEach((key, keyIndex) => {
1251
+ matches.push(
1252
+ ...this._findMatches({
1253
+ key,
1254
+ value: item[keyIndex],
1255
+ searcher
1256
+ })
1257
+ );
1258
+ });
1259
+ if (matches.length) {
1260
+ results.push({
1261
+ idx,
1262
+ item,
1263
+ matches
1264
+ });
1265
+ }
1266
+ });
1267
+ return results;
1268
+ }
1269
+ _findMatches({ key, value, searcher }) {
1270
+ if (!isDefined(value)) {
1271
+ return [];
1272
+ }
1273
+ let matches = [];
1274
+ if (isArray(value)) {
1275
+ value.forEach(({ v: text, i: idx, n: norm2 }) => {
1276
+ if (!isDefined(text)) {
1277
+ return;
1278
+ }
1279
+ const { isMatch, score, indices } = searcher.searchIn(text);
1280
+ if (isMatch) {
1281
+ matches.push({
1282
+ score,
1283
+ key,
1284
+ value: text,
1285
+ idx,
1286
+ norm: norm2,
1287
+ indices
1288
+ });
1289
+ }
1290
+ });
1291
+ } else {
1292
+ const { v: text, n: norm2 } = value;
1293
+ const { isMatch, score, indices } = searcher.searchIn(text);
1294
+ if (isMatch) {
1295
+ matches.push({ score, key, value: text, norm: norm2, indices });
1296
+ }
1297
+ }
1298
+ return matches;
1299
+ }
1300
+ }
1301
+ Fuse.version = "7.0.0";
1302
+ Fuse.createIndex = createIndex;
1303
+ Fuse.parseIndex = parseIndex;
1304
+ Fuse.config = Config;
1305
+ {
1306
+ Fuse.parseQuery = parse;
1307
+ }
1308
+ {
1309
+ register(ExtendedSearch);
1310
+ }
1311
+ const name = "x-img-diff-js";
1312
+ const version = "0.3.5";
1313
+ const main = "src/index.js";
1314
+ const description = "compare 2 images considering into translation";
1315
+ const scripts = {
1316
+ build: "docker-compose run --rm emcc && npm run build:demo",
1317
+ test: "node test/test_node.js",
1318
+ "build:demo": "cp -rf build demo",
1319
+ start: "cd demo; http-server -p 8000",
1320
+ "gen:postjs": "babel binding-gen/post.js > bindings/post.js",
1321
+ deploy: "npm run build:demo && gh-pages -d demo"
1322
+ };
1323
+ const repository = {
1324
+ type: "git",
1325
+ url: "git+https://github.com/reg-viz/x-img-diff-js.git"
1326
+ };
1327
+ const author = "Quramy";
1328
+ const license = "MIT";
1329
+ const bugs = {
1330
+ url: "https://github.com/reg-viz/x-img-diff-js/issues"
1331
+ };
1332
+ const homepage = "https://github.com/reg-viz/x-img-diff-js#readme";
1333
+ const devDependencies = {
1334
+ "babel-cli": "^6.26.0",
1335
+ "babel-core": "^6.26.0",
1336
+ "babel-preset-es2015": "^6.24.1",
1337
+ "gh-pages": "^1.0.0",
1338
+ "http-server": "^0.10.0",
1339
+ pngjs: "^3.3.0"
1340
+ };
1341
+ const packageJson = {
1342
+ name,
1343
+ version,
1344
+ main,
1345
+ description,
1346
+ scripts,
1347
+ repository,
1348
+ author,
1349
+ license,
1350
+ bugs,
1351
+ homepage,
1352
+ devDependencies
1353
+ };
1354
+ function instantiateCachedURL(dbVersion, url, importObject) {
1355
+ const dbName = "wasm-cache";
1356
+ const storeName = "wasm-cache";
1357
+ function openDatabase() {
1358
+ return new Promise((resolve, reject) => {
1359
+ const request = indexedDB.open(dbName, dbVersion);
1360
+ request.onerror = reject.bind(null, "Error opening wasm cache database");
1361
+ request.onsuccess = () => {
1362
+ resolve(request.result);
1363
+ };
1364
+ request.onupgradeneeded = (event) => {
1365
+ const db = request.result;
1366
+ if (db.objectStoreNames.contains(storeName)) {
1367
+ console.log(`Clearing out version ${event.oldVersion} wasm cache`);
1368
+ db.deleteObjectStore(storeName);
1369
+ }
1370
+ console.log(`Creating version ${event.newVersion} wasm cache`);
1371
+ db.createObjectStore(storeName);
1372
+ };
1373
+ });
1374
+ }
1375
+ function lookupInDatabase(db) {
1376
+ return new Promise((resolve, reject) => {
1377
+ const store = db.transaction([storeName]).objectStore(storeName);
1378
+ const request = store.get(url);
1379
+ request.onerror = reject.bind(null, `Error getting wasm module ${url}`);
1380
+ request.onsuccess = () => {
1381
+ if (request.result) {
1382
+ resolve(request.result);
1383
+ } else {
1384
+ reject(`Module ${url} was not found in wasm cache`);
1385
+ }
1386
+ };
1387
+ });
1388
+ }
1389
+ function storeInDatabase(db, module) {
1390
+ const store = db.transaction([storeName], "readwrite").objectStore(storeName);
1391
+ try {
1392
+ const request = store.put(module, url);
1393
+ request.onerror = (err) => {
1394
+ console.log(`Failed to store in wasm cache: ${err}`);
1395
+ };
1396
+ request.onsuccess = () => {
1397
+ console.log(`Successfully stored ${url} in wasm cache`);
1398
+ };
1399
+ } catch (e) {
1400
+ console.warn("An error was thrown... in storing wasm cache...");
1401
+ console.warn(e);
1402
+ }
1403
+ }
1404
+ async function fetchAndInstantiate() {
1405
+ const response = await fetch(url);
1406
+ const buffer = await response.arrayBuffer();
1407
+ return await WebAssembly.instantiate(buffer, importObject);
1408
+ }
1409
+ return openDatabase().then(
1410
+ (db) => {
1411
+ return lookupInDatabase(db).then(
1412
+ (module) => {
1413
+ console.log(`Found ${url} in wasm cache`);
1414
+ return WebAssembly.instantiate(module, importObject);
1415
+ },
1416
+ (errMsg) => {
1417
+ console.log(errMsg);
1418
+ return fetchAndInstantiate().then((results) => {
1419
+ setTimeout(() => storeInDatabase(db, results.module), 0);
1420
+ return results.instance;
1421
+ });
1422
+ }
1423
+ );
1424
+ },
1425
+ (errMsg) => {
1426
+ console.log(errMsg);
1427
+ return fetchAndInstantiate().then((results) => results.instance);
1428
+ }
1429
+ );
1430
+ }
1431
+ class ModuleClass {
1432
+ constructor({ init, version: version2, wasmUrl }) {
1433
+ this._init = init;
1434
+ this._version = version2;
1435
+ this._wasmUrl = wasmUrl;
1436
+ }
1437
+ locateFile(baseName) {
1438
+ return self.location.pathname.replace(/\[^\/]*$/, "/") + baseName;
1439
+ }
1440
+ instantiateWasm(imports, callback) {
1441
+ instantiateCachedURL(this._version, this._wasmUrl, imports).then(
1442
+ (instance) => callback(instance)
1443
+ );
1444
+ return {};
1445
+ }
1446
+ onInit(callback) {
1447
+ this._init = callback;
1448
+ }
1449
+ onRuntimeInitialized() {
1450
+ if (this._init) {
1451
+ return this._init(this);
1452
+ }
1453
+ }
1454
+ }
1455
+ var WorkerEventType = /* @__PURE__ */ ((WorkerEventType2) => {
1456
+ WorkerEventType2["INIT_CALC"] = "init";
1457
+ WorkerEventType2["REQUEST_CALC"] = "req_calc";
1458
+ WorkerEventType2["RESULT_CALC"] = "res_calc";
1459
+ WorkerEventType2["INIT_FILTER"] = "init_filter";
1460
+ WorkerEventType2["REQUEST_FILTER"] = "req_filter";
1461
+ WorkerEventType2["RESULT_FILTER"] = "res_filter";
1462
+ return WorkerEventType2;
1463
+ })(WorkerEventType || {});
1464
+ const ximgdiffVersionString = packageJson.version;
1465
+ const _self = self;
1466
+ function version2number(version2) {
1467
+ const [, major, minor, patch] = version2.match(/^(\d*)\.(\d*)\.(\d*)/);
1468
+ return +major * 1e4 + +minor * 100 + +patch;
1469
+ }
1470
+ let loaded = false;
1471
+ let lastCalcData = null;
1472
+ const cachedEntity = {
1473
+ new: [],
1474
+ passed: [],
1475
+ failed: [],
1476
+ deleted: []
1477
+ };
1478
+ const calc = ({
1479
+ payload: { raw, img1, img2, actualSrc, expectedSrc, seq }
1480
+ }) => {
1481
+ const diffResult = _self.Module.detectDiff(_self.Module, img1, img2, {});
1482
+ _self.postMessage({
1483
+ type: WorkerEventType.RESULT_CALC,
1484
+ payload: {
1485
+ seq,
1486
+ raw,
1487
+ actualSrc,
1488
+ expectedSrc,
1489
+ result: {
1490
+ ...diffResult,
1491
+ images: [
1492
+ { width: img1.width, height: img1.height },
1493
+ { width: img2.width, height: img2.height }
1494
+ ]
1495
+ }
1496
+ }
1497
+ });
1498
+ };
1499
+ const filter = ({
1500
+ payload: { input }
1501
+ }) => {
1502
+ if (!input) {
1503
+ return _self.postMessage({
1504
+ type: WorkerEventType.RESULT_FILTER,
1505
+ payload: {
1506
+ newItems: cachedEntity.new,
1507
+ passedItems: cachedEntity.passed,
1508
+ failedItems: cachedEntity.failed,
1509
+ deletedItems: cachedEntity.deleted
1510
+ }
1511
+ });
1512
+ }
1513
+ const search2 = (entities) => {
1514
+ const fuse = new Fuse(entities, {
1515
+ shouldSort: false,
1516
+ isCaseSensitive: false,
1517
+ findAllMatches: true,
1518
+ location: 0,
1519
+ distance: 100,
1520
+ minMatchCharLength: 1,
1521
+ threshold: 0.2,
1522
+ keys: ["name"]
1523
+ });
1524
+ return fuse.search(input).map(({ item }) => item);
1525
+ };
1526
+ _self.postMessage({
1527
+ type: WorkerEventType.RESULT_FILTER,
1528
+ payload: {
1529
+ newItems: search2(cachedEntity.new),
1530
+ passedItems: search2(cachedEntity.passed),
1531
+ failedItems: search2(cachedEntity.failed),
1532
+ deletedItems: search2(cachedEntity.deleted)
1533
+ }
1534
+ });
1535
+ };
1536
+ _self.Module = new ModuleClass({
1537
+ version: version2number(ximgdiffVersionString),
1538
+ wasmUrl: _self.wasmUrl,
1539
+ init: () => {
1540
+ loaded = true;
1541
+ if (lastCalcData != null) {
1542
+ calc(lastCalcData);
1543
+ }
1544
+ _self.postMessage({ type: WorkerEventType.INIT_CALC });
1545
+ }
1546
+ });
1547
+ _self.addEventListener("message", ({ data }) => {
1548
+ console.log("Received: ", data);
1549
+ switch (data.type) {
1550
+ case WorkerEventType.REQUEST_CALC:
1551
+ if (loaded) {
1552
+ calc(data);
1553
+ } else {
1554
+ lastCalcData = data;
1555
+ }
1556
+ break;
1557
+ case WorkerEventType.INIT_FILTER:
1558
+ cachedEntity.new = data.payload.newItems;
1559
+ cachedEntity.passed = data.payload.passedItems;
1560
+ cachedEntity.failed = data.payload.failedItems;
1561
+ cachedEntity.deleted = data.payload.deletedItems;
1562
+ break;
1563
+ case WorkerEventType.REQUEST_FILTER:
1564
+ filter(data);
1565
+ break;
1566
+ }
1567
+ });
1568
+ })();