@openreplay/tracker 7.0.2 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/cjs/app/index.js +2 -2
- package/cjs/index.js +1 -1
- package/cjs/modules/network.js +1 -1
- package/coverage/clover.xml +2461 -0
- package/coverage/coverage-final.json +38 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +176 -0
- package/coverage/lcov-report/main/app/guards.ts.html +229 -0
- package/coverage/lcov-report/main/app/index.html +206 -0
- package/coverage/lcov-report/main/app/index.ts.html +2053 -0
- package/coverage/lcov-report/main/app/logger.ts.html +277 -0
- package/coverage/lcov-report/main/app/messages.gen.ts.html +2752 -0
- package/coverage/lcov-report/main/app/nodes.ts.html +367 -0
- package/coverage/lcov-report/main/app/observer/iframe_observer.ts.html +148 -0
- package/coverage/lcov-report/main/app/observer/iframe_offsets.ts.html +289 -0
- package/coverage/lcov-report/main/app/observer/index.html +161 -0
- package/coverage/lcov-report/main/app/observer/observer.ts.html +1282 -0
- package/coverage/lcov-report/main/app/observer/shadow_root_observer.ts.html +142 -0
- package/coverage/lcov-report/main/app/observer/top_observer.ts.html +535 -0
- package/coverage/lcov-report/main/app/sanitizer.ts.html +394 -0
- package/coverage/lcov-report/main/app/session.ts.html +559 -0
- package/coverage/lcov-report/main/app/ticker.ts.html +250 -0
- package/coverage/lcov-report/main/index.html +131 -0
- package/coverage/lcov-report/main/index.ts.html +1012 -0
- package/coverage/lcov-report/main/modules/axiosSpy.ts.html +700 -0
- package/coverage/lcov-report/main/modules/connection.ts.html +160 -0
- package/coverage/lcov-report/main/modules/console.ts.html +508 -0
- package/coverage/lcov-report/main/modules/constructedStyleSheets.ts.html +559 -0
- package/coverage/lcov-report/main/modules/cssrules.ts.html +418 -0
- package/coverage/lcov-report/main/modules/exception.ts.html +385 -0
- package/coverage/lcov-report/main/modules/focus.ts.html +220 -0
- package/coverage/lcov-report/main/modules/fonts.ts.html +289 -0
- package/coverage/lcov-report/main/modules/img.ts.html +433 -0
- package/coverage/lcov-report/main/modules/index.html +371 -0
- package/coverage/lcov-report/main/modules/input.ts.html +811 -0
- package/coverage/lcov-report/main/modules/mouse.ts.html +826 -0
- package/coverage/lcov-report/main/modules/network.ts.html +1129 -0
- package/coverage/lcov-report/main/modules/performance.ts.html +367 -0
- package/coverage/lcov-report/main/modules/scroll.ts.html +364 -0
- package/coverage/lcov-report/main/modules/selection.ts.html +202 -0
- package/coverage/lcov-report/main/modules/tabs.ts.html +124 -0
- package/coverage/lcov-report/main/modules/timing.ts.html +841 -0
- package/coverage/lcov-report/main/modules/viewport.ts.html +250 -0
- package/coverage/lcov-report/main/utils.ts.html +406 -0
- package/coverage/lcov-report/main/vendors/finder/finder.ts.html +1381 -0
- package/coverage/lcov-report/main/vendors/finder/index.html +116 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/webworker/BatchWriter.ts.html +532 -0
- package/coverage/lcov-report/webworker/MessageEncoder.gen.ts.html +949 -0
- package/coverage/lcov-report/webworker/PrimitiveEncoder.ts.html +436 -0
- package/coverage/lcov-report/webworker/QueueSender.ts.html +475 -0
- package/coverage/lcov-report/webworker/StringDictionary.ts.html +124 -0
- package/coverage/lcov-report/webworker/index.html +191 -0
- package/coverage/lcov-report/webworker/index.ts.html +592 -0
- package/coverage/lcov.info +4882 -0
- package/jest.config.js +2 -0
- package/lib/app/index.js +2 -2
- package/lib/index.js +1 -1
- package/lib/modules/network.js +1 -1
- package/package.json +1 -1
- package/cjs/vendors/finder/finder.d.ts +0 -12
- package/cjs/vendors/finder/finder.js +0 -352
- package/lib/vendors/finder/finder.d.ts +0 -12
- package/lib/vendors/finder/finder.js +0 -348
package/jest.config.js
CHANGED
package/lib/app/index.js
CHANGED
|
@@ -31,7 +31,7 @@ export default class App {
|
|
|
31
31
|
this.stopCallbacks = [];
|
|
32
32
|
this.commitCallbacks = [];
|
|
33
33
|
this.activityState = ActivityState.NotActive;
|
|
34
|
-
this.version = '7.0.
|
|
34
|
+
this.version = '7.0.3'; // TODO: version compatability check inside each plugin.
|
|
35
35
|
this.compressionThreshold = 24 * 1000;
|
|
36
36
|
this.restartAttempts = 0;
|
|
37
37
|
this._usingOldFetchPlugin = false;
|
|
@@ -78,7 +78,7 @@ export default class App {
|
|
|
78
78
|
this.session.applySessionHash(sessionToken);
|
|
79
79
|
}
|
|
80
80
|
try {
|
|
81
|
-
this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";class t{constructor(t,i,s,e=10,n=1e3,h){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=h,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.isCompressing=!1,this.ingestURL=t+"/v1/web/i",void 0!==h&&(this.isCompressing=!0)}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){this.busy||!this.token?this.queue.push(t):(this.busy=!0,this.isCompressing&&this.onCompress?this.onCompress(t):this.sendBatch(t))}sendNext(){const t=this.queue.shift();t?(this.busy=!0,this.isCompressing&&this.onCompress?this.onCompress(t):this.sendBatch(t)):this.busy=!1}retry(t,i){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout(()=>this.sendBatch(t,i),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,i){this.busy=!0;const s={Authorization:"Bearer "+this.token};i&&(s["Content-Encoding"]="gzip"),null!==this.token?fetch(this.ingestURL,{body:t,method:"POST",headers:s,keepalive:t.length<65536}).then(s=>{if(401===s.status)return this.busy=!1,void this.onUnauthorised();s.status>=400?this.retry(t,i):(this.attemptsCount=0,this.sendNext())}).catch(s=>{console.warn("OpenReplay:",s),this.retry(t,i)}):setTimeout(()=>{this.sendBatch(t,i)},500)}sendCompressed(t){this.sendBatch(t,!0)}sendUncompressed(t){this.sendBatch(t,!1)}clean(){this.queue.length=0,this.token=null}}const i="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(let n=0,h=0,r=0;r!==i;){if(n=t.charCodeAt(r),r+=1,n>=55296&&n<=56319){if(r===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(h=t.charCodeAt(r),!(h>=56320&&h<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+h-56320+65536,r+=1,n>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class s extends class{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,i){this.data.set(t,i)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=i.encode(t),e=s.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(s,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}{encode(t){switch(t[0]){case 0:return this.uint(t[1]);case 4:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 11:return this.uint(t[1]);case 12:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 17:return this.uint(t[1])&&this.string(t[2]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 20:return this.uint(t[1])&&this.uint(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 24:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 27:return this.string(t[1])&&this.string(t[2]);case 28:case 29:return this.string(t[1]);case 30:return this.string(t[1])&&this.string(t[2]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 38:return this.uint(t[1])&&this.uint(t[2]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 41:return this.string(t[1])&&this.string(t[2]);case 42:return this.string(t[1]);case 44:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 45:case 46:return this.string(t[1])&&this.string(t[2]);case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 50:return this.uint(t[1])&&this.string(t[2]);case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 54:return this.uint(t[1])&&this.string(t[2]);case 55:return this.boolean(t[1]);case 57:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:return this.int(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 61:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 63:case 64:return this.string(t[1])&&this.string(t[2]);case 67:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 70:return this.uint(t[1])&&this.uint(t[2]);case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 79:return this.string(t[1])&&this.string(t[2]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 82:return this.uint(t[1])&&this.uint(t[2]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 114:case 115:return this.uint(t[1]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10])}}}class e{constructor(){this.idx=1,this.backDict={}}getKey(t){let i=!1;return this.backDict[t]||(i=!0,this.backDict[t]=this.idx++),[this.backDict[t],i]}}class n{constructor(t,i,n,h){this.pageNo=t,this.timestamp=i,this.url=n,this.onBatch=h,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new s(this.beaconSize),this.strDict=new e,this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,i){for(let i=0;i<3;i++)this.sizeBuffer[i]=t>>8*i;this.encoder.set(this.sizeBuffer,i)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url];this.writeType(t),this.writeFields(t),this.isEmpty=!0}writeWithSize(t){const i=this.encoder;if(!this.writeType(t)||!i.skip(3))return!1;const s=i.getCurrentOffset(),e=this.writeFields(t);if(e){const e=i.getCurrentOffset()-s;if(e>16777215)return console.warn("OpenReplay: max message size overflow."),!1;this.writeSizeAt(e,s-3),i.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}applyDict(t){const[i,s]=this.strDict.getKey(t);return s&&this.writeMessage([50,i,t]),i}writeMessage(t){0===t[0]&&(this.timestamp=t[1]),4===t[0]&&(this.url=t[1]),12===t[0]&&(t=[51,t[1],this.applyDict(t[2]),this.applyDict(t[3])]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new s(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn("OpenReplay: beacon size overflow. Skipping large message.",t,this),this.encoder=new s(this.beaconSize),this.prepare()))}finaliseBatch(){this.isEmpty||(this.onBatch(this.encoder.flush()),this.prepare())}clean(){this.encoder.reset()}}var h;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active"}(h||(h={}));let r=null,u=null;function a(){u&&u.finaliseBatch()}function o(){h.Stopping,null!==p&&(clearInterval(p),p=null),u&&(u.clean(),u=null),r&&(r.clean(),r=null),h.NotActive}function c(){postMessage("restart"),o()}h.NotActive;let g,p=null;self.onmessage=({data:i})=>{if(null!=i){if("stop"===i)return a(),void o();if(!Array.isArray(i)){if("compressed"===i.type){if(!r)return console.debug("WebWorker: sender not initialised. Compressed batch."),void c();r.sendCompressed(i.batch)}if("uncompressed"===i.type){if(!r)return console.debug("WebWorker: sender not initialised. Uncompressed batch."),void c();r.sendUncompressed(i.batch)}return"start"===i.type?(h.Starting,r=new t(i.ingestPoint,()=>{c()},t=>{!function(t){postMessage({type:"failure",reason:t}),o()}(t)},i.connAttemptCount,i.connAttemptGap,t=>{postMessage({type:"compress",batch:t},[t.buffer])}),u=new n(i.pageNo,i.timestamp,i.url,t=>r&&r.push(t)),null===p&&(p=setInterval(a,1e4)),h.Active):"auth"===i.type?r?u?(r.authorise(i.token),void(i.beaconSizeLimit&&u.setBeaconSizeLimit(i.beaconSizeLimit))):(console.debug("WebWorker: writer not initialised. Received auth."),void c()):(console.debug("WebWorker: sender not initialised. Received auth."),void c()):void 0}if(null!==u){const t=u;i.forEach(i=>{55===i[0]&&(i[1]?g=setTimeout(()=>c(),18e5):clearTimeout(g)),t.writeMessage(i)})}u||(postMessage("not_init"),c())}else a()};'], { type: 'text/javascript' })));
|
|
81
|
+
this.worker = new Worker(URL.createObjectURL(new Blob(['"use strict";class t{constructor(t,i,s,e=10,n=1e3,r){this.onUnauthorised=i,this.onFailure=s,this.MAX_ATTEMPTS_COUNT=e,this.ATTEMPT_TIMEOUT=n,this.onCompress=r,this.attemptsCount=0,this.busy=!1,this.queue=[],this.token=null,this.ingestURL=t+"/v1/web/i",this.isCompressing=void 0!==r}authorise(t){this.token=t,this.busy||this.sendNext()}push(t){this.busy||!this.token?this.queue.push(t):(this.busy=!0,this.isCompressing&&this.onCompress?this.onCompress(t):this.sendBatch(t))}sendNext(){const t=this.queue.shift();t?(this.busy=!0,this.isCompressing&&this.onCompress?this.onCompress(t):this.sendBatch(t)):this.busy=!1}retry(t,i){this.attemptsCount>=this.MAX_ATTEMPTS_COUNT?this.onFailure(`Failed to send batch after ${this.attemptsCount} attempts.`):(this.attemptsCount++,setTimeout(()=>this.sendBatch(t,i),this.ATTEMPT_TIMEOUT*this.attemptsCount))}sendBatch(t,i){this.busy=!0;const s={Authorization:"Bearer "+this.token};i&&(s["Content-Encoding"]="gzip"),null!==this.token?fetch(this.ingestURL,{body:t,method:"POST",headers:s,keepalive:t.length<65536}).then(s=>{if(401===s.status)return this.busy=!1,void this.onUnauthorised();s.status>=400?this.retry(t,i):(this.attemptsCount=0,this.sendNext())}).catch(s=>{console.warn("OpenReplay:",s),this.retry(t,i)}):setTimeout(()=>{this.sendBatch(t,i)},500)}sendCompressed(t){this.sendBatch(t,!0)}sendUncompressed(t){this.sendBatch(t,!1)}clean(){this.sendNext(),setTimeout(()=>{this.token=null,this.queue.length=0},100)}}const i="function"==typeof TextEncoder?new TextEncoder:{encode(t){const i=t.length,s=new Uint8Array(3*i);let e=-1;for(let n=0,r=0,h=0;h!==i;){if(n=t.charCodeAt(h),h+=1,n>=55296&&n<=56319){if(h===i){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;break}if(r=t.charCodeAt(h),!(r>=56320&&r<=57343)){s[e+=1]=239,s[e+=1]=191,s[e+=1]=189;continue}if(n=1024*(n-55296)+r-56320+65536,h+=1,n>65535){s[e+=1]=240|n>>>18,s[e+=1]=128|n>>>12&63,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n;continue}}n<=127?s[e+=1]=0|n:n<=2047?(s[e+=1]=192|n>>>6,s[e+=1]=128|63&n):(s[e+=1]=224|n>>>12,s[e+=1]=128|n>>>6&63,s[e+=1]=128|63&n)}return s.subarray(0,e+1)}};class s extends class{constructor(t){this.size=t,this.offset=0,this.checkpointOffset=0,this.data=new Uint8Array(t)}getCurrentOffset(){return this.offset}checkpoint(){this.checkpointOffset=this.offset}get isEmpty(){return 0===this.offset}skip(t){return this.offset+=t,this.offset<=this.size}set(t,i){this.data.set(t,i)}boolean(t){return this.data[this.offset++]=+t,this.offset<=this.size}uint(t){for((t<0||t>Number.MAX_SAFE_INTEGER)&&(t=0);t>=128;)this.data[this.offset++]=t%256|128,t=Math.floor(t/128);return this.data[this.offset++]=t,this.offset<=this.size}int(t){return t=Math.round(t),this.uint(t>=0?2*t:-2*t-1)}string(t){const s=i.encode(t),e=s.byteLength;return!(!this.uint(e)||this.offset+e>this.size)&&(this.data.set(s,this.offset),this.offset+=e,!0)}reset(){this.offset=0,this.checkpointOffset=0}flush(){const t=this.data.slice(0,this.checkpointOffset);return this.reset(),t}}{encode(t){switch(t[0]){case 0:return this.uint(t[1]);case 4:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 5:return this.uint(t[1])&&this.uint(t[2]);case 6:return this.int(t[1])&&this.int(t[2]);case 7:return!0;case 8:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.string(t[4])&&this.boolean(t[5]);case 9:case 10:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 11:return this.uint(t[1]);case 12:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 13:case 14:return this.uint(t[1])&&this.string(t[2]);case 16:return this.uint(t[1])&&this.int(t[2])&&this.int(t[3]);case 17:return this.uint(t[1])&&this.string(t[2]);case 18:return this.uint(t[1])&&this.string(t[2])&&this.int(t[3]);case 19:return this.uint(t[1])&&this.boolean(t[2]);case 20:return this.uint(t[1])&&this.uint(t[2]);case 21:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.string(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8]);case 22:return this.string(t[1])&&this.string(t[2]);case 23:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7])&&this.uint(t[8])&&this.uint(t[9]);case 24:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 27:return this.string(t[1])&&this.string(t[2]);case 28:case 29:return this.string(t[1]);case 30:return this.string(t[1])&&this.string(t[2]);case 37:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3]);case 38:return this.uint(t[1])&&this.uint(t[2]);case 39:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.uint(t[7]);case 40:return this.string(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 41:return this.string(t[1])&&this.string(t[2]);case 42:return this.string(t[1]);case 44:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 45:case 46:return this.string(t[1])&&this.string(t[2]);case 47:return this.string(t[1])&&this.string(t[2])&&this.uint(t[3]);case 48:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 49:return this.int(t[1])&&this.int(t[2])&&this.uint(t[3])&&this.uint(t[4]);case 50:return this.uint(t[1])&&this.string(t[2]);case 51:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3]);case 53:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8]);case 54:return this.uint(t[1])&&this.string(t[2]);case 55:return this.boolean(t[1]);case 57:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 58:return this.int(t[1]);case 59:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.string(t[5])&&this.string(t[6])&&this.string(t[7]);case 60:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 61:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 63:case 64:return this.string(t[1])&&this.string(t[2]);case 67:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 69:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3])&&this.string(t[4]);case 70:return this.uint(t[1])&&this.uint(t[2]);case 71:return this.uint(t[1])&&this.string(t[2])&&this.string(t[3]);case 73:return this.uint(t[1])&&this.string(t[2])&&this.uint(t[3])&&this.string(t[4]);case 75:case 76:case 77:return this.uint(t[1])&&this.uint(t[2]);case 78:return this.string(t[1])&&this.string(t[2])&&this.string(t[3])&&this.string(t[4]);case 79:return this.string(t[1])&&this.string(t[2]);case 81:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.int(t[4])&&this.string(t[5]);case 82:return this.uint(t[1])&&this.uint(t[2]);case 112:return this.uint(t[1])&&this.string(t[2])&&this.boolean(t[3])&&this.string(t[4])&&this.int(t[5])&&this.int(t[6]);case 113:return this.uint(t[1])&&this.uint(t[2])&&this.string(t[3]);case 114:case 115:return this.uint(t[1]);case 116:return this.uint(t[1])&&this.uint(t[2])&&this.uint(t[3])&&this.uint(t[4])&&this.uint(t[5])&&this.uint(t[6])&&this.string(t[7])&&this.string(t[8])&&this.uint(t[9])&&this.boolean(t[10])}}}class e{constructor(){this.idx=1,this.backDict={}}getKey(t){let i=!1;return this.backDict[t]||(i=!0,this.backDict[t]=this.idx++),[this.backDict[t],i]}}class n{constructor(t,i,n,r){this.pageNo=t,this.timestamp=i,this.url=n,this.onBatch=r,this.nextIndex=0,this.beaconSize=2e5,this.encoder=new s(this.beaconSize),this.strDict=new e,this.sizeBuffer=new Uint8Array(3),this.isEmpty=!0,this.beaconSizeLimit=1e6,this.prepare()}writeType(t){return this.encoder.uint(t[0])}writeFields(t){return this.encoder.encode(t)}writeSizeAt(t,i){for(let i=0;i<3;i++)this.sizeBuffer[i]=t>>8*i;this.encoder.set(this.sizeBuffer,i)}prepare(){if(!this.encoder.isEmpty)return;const t=[81,1,this.pageNo,this.nextIndex,this.timestamp,this.url];this.writeType(t),this.writeFields(t),this.isEmpty=!0}writeWithSize(t){const i=this.encoder;if(!this.writeType(t)||!i.skip(3))return!1;const s=i.getCurrentOffset(),e=this.writeFields(t);if(e){const e=i.getCurrentOffset()-s;if(e>16777215)return console.warn("OpenReplay: max message size overflow."),!1;this.writeSizeAt(e,s-3),i.checkpoint(),this.isEmpty=this.isEmpty&&0===t[0],this.nextIndex++}return e}setBeaconSizeLimit(t){this.beaconSizeLimit=t}applyDict(t){const[i,s]=this.strDict.getKey(t);return s&&this.writeMessage([50,i,t]),i}writeMessage(t){0===t[0]&&(this.timestamp=t[1]),4===t[0]&&(this.url=t[1]),12===t[0]&&(t=[51,t[1],this.applyDict(t[2]),this.applyDict(t[3])]),this.writeWithSize(t)||(this.finaliseBatch(),this.writeWithSize(t)||(this.encoder=new s(this.beaconSizeLimit),this.prepare(),this.writeWithSize(t)?this.finaliseBatch():console.warn("OpenReplay: beacon size overflow. Skipping large message.",t,this),this.encoder=new s(this.beaconSize),this.prepare()))}finaliseBatch(){if(this.isEmpty)return;const t=this.encoder.flush();this.onBatch(t),this.prepare()}clean(){this.encoder.reset()}}var r;!function(t){t[t.NotActive=0]="NotActive",t[t.Starting=1]="Starting",t[t.Stopping=2]="Stopping",t[t.Active=3]="Active",t[t.Stopped=4]="Stopped"}(r||(r={}));let h=null,u=null,a=r.NotActive;function o(){u&&u.finaliseBatch()}function c(){a=r.Stopping,null!==l&&(clearInterval(l),l=null),u&&(u.clean(),u=null),h&&(h.clean(),setTimeout(()=>{h=null},500)),a=r.NotActive}function g(){a!==r.Stopped&&(postMessage("restart"),c())}let p,l=null;self.onmessage=({data:i})=>{if(null!=i){if("stop"===i)return o(),c(),a=r.Stopped;if(!Array.isArray(i)){if("compressed"===i.type){if(!h)return console.debug("WebWorker: sender not initialised. Compressed batch."),void g();h.sendCompressed(i.batch)}if("uncompressed"===i.type){if(!h)return console.debug("WebWorker: sender not initialised. Uncompressed batch."),void g();h.sendUncompressed(i.batch)}return"start"===i.type?(a=r.Starting,h=new t(i.ingestPoint,()=>{g()},t=>{!function(t){postMessage({type:"failure",reason:t}),c()}(t)},i.connAttemptCount,i.connAttemptGap,t=>{postMessage({type:"compress",batch:t},[t.buffer])}),u=new n(i.pageNo,i.timestamp,i.url,t=>h&&h.push(t)),null===l&&(l=setInterval(o,1e4)),a=r.Active):"auth"===i.type?h?u?(h.authorise(i.token),void(i.beaconSizeLimit&&u.setBeaconSizeLimit(i.beaconSizeLimit))):(console.debug("WebWorker: writer not initialised. Received auth."),void g()):(console.debug("WebWorker: sender not initialised. Received auth."),void g()):void 0}if(null!==u){const t=u;i.forEach(i=>{55===i[0]&&(i[1]?p=setTimeout(()=>g(),18e5):clearTimeout(p)),t.writeMessage(i)})}u||(postMessage("not_init"),g())}else o()};'], { type: 'text/javascript' })));
|
|
82
82
|
this.worker.onerror = (e) => {
|
|
83
83
|
this._debug('webworker_error', e);
|
|
84
84
|
};
|
package/lib/index.js
CHANGED
|
@@ -137,7 +137,7 @@ export default class API {
|
|
|
137
137
|
// no-cors issue only with text/plain or not-set Content-Type
|
|
138
138
|
// req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
139
139
|
req.send(JSON.stringify({
|
|
140
|
-
trackerVersion: '7.0.
|
|
140
|
+
trackerVersion: '7.0.3',
|
|
141
141
|
projectKey: options.projectKey,
|
|
142
142
|
doNotTrack,
|
|
143
143
|
// TODO: add precise reason (an exact API missing)
|
package/lib/modules/network.js
CHANGED
|
@@ -158,7 +158,7 @@ export default function (app, opts = {}) {
|
|
|
158
158
|
xhr.addEventListener('load', app.safe((e) => {
|
|
159
159
|
const { headers: reqHs, body: reqBody } = getXHRRequestDataObject(xhr);
|
|
160
160
|
const duration = startTime > 0 ? e.timeStamp - startTime : 0;
|
|
161
|
-
const hString = xhr.getAllResponseHeaders() || ''; // might be null (
|
|
161
|
+
const hString = xhr.getAllResponseHeaders() || ''; // might be null (only if no response received though)
|
|
162
162
|
const headersArr = hString.trim().split(/[\r\n]+/);
|
|
163
163
|
const headerMap = {};
|
|
164
164
|
headersArr.forEach(function (line) {
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type Options = {
|
|
2
|
-
root: Element;
|
|
3
|
-
idName: (name: string) => boolean;
|
|
4
|
-
className: (name: string) => boolean;
|
|
5
|
-
tagName: (name: string) => boolean;
|
|
6
|
-
attr: (name: string, value: string) => boolean;
|
|
7
|
-
seedMinLength: number;
|
|
8
|
-
optimizedMinLength: number;
|
|
9
|
-
threshold: number;
|
|
10
|
-
maxNumberOfTries: number;
|
|
11
|
-
};
|
|
12
|
-
export declare function finder(input: Element, options?: Partial<Options>): string;
|
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.finder = void 0;
|
|
4
|
-
var Limit;
|
|
5
|
-
(function (Limit) {
|
|
6
|
-
Limit[Limit["All"] = 0] = "All";
|
|
7
|
-
Limit[Limit["Two"] = 1] = "Two";
|
|
8
|
-
Limit[Limit["One"] = 2] = "One";
|
|
9
|
-
})(Limit || (Limit = {}));
|
|
10
|
-
let config;
|
|
11
|
-
let rootDocument;
|
|
12
|
-
function finder(input, options) {
|
|
13
|
-
if (input.nodeType !== Node.ELEMENT_NODE) {
|
|
14
|
-
throw new Error("Can't generate CSS selector for non-element node type.");
|
|
15
|
-
}
|
|
16
|
-
if ('html' === input.tagName.toLowerCase()) {
|
|
17
|
-
return 'html';
|
|
18
|
-
}
|
|
19
|
-
const defaults = {
|
|
20
|
-
root: document.body,
|
|
21
|
-
idName: (name) => true,
|
|
22
|
-
className: (name) => true,
|
|
23
|
-
tagName: (name) => true,
|
|
24
|
-
attr: (name, value) => false,
|
|
25
|
-
seedMinLength: 1,
|
|
26
|
-
optimizedMinLength: 2,
|
|
27
|
-
threshold: 1000,
|
|
28
|
-
maxNumberOfTries: 10000,
|
|
29
|
-
};
|
|
30
|
-
config = Object.assign(Object.assign({}, defaults), options);
|
|
31
|
-
rootDocument = findRootDocument(config.root, defaults);
|
|
32
|
-
let path = bottomUpSearch(input, Limit.All, () => bottomUpSearch(input, Limit.Two, () => bottomUpSearch(input, Limit.One)));
|
|
33
|
-
if (path) {
|
|
34
|
-
const optimized = sort(optimize(path, input));
|
|
35
|
-
if (optimized.length > 0) {
|
|
36
|
-
path = optimized[0];
|
|
37
|
-
}
|
|
38
|
-
return selector(path);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new Error('Selector was not found.');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.finder = finder;
|
|
45
|
-
function findRootDocument(rootNode, defaults) {
|
|
46
|
-
if (rootNode.nodeType === Node.DOCUMENT_NODE) {
|
|
47
|
-
return rootNode;
|
|
48
|
-
}
|
|
49
|
-
if (rootNode === defaults.root) {
|
|
50
|
-
return rootNode.ownerDocument;
|
|
51
|
-
}
|
|
52
|
-
return rootNode;
|
|
53
|
-
}
|
|
54
|
-
function bottomUpSearch(input, limit, fallback) {
|
|
55
|
-
let path = null;
|
|
56
|
-
const stack = [];
|
|
57
|
-
let current = input;
|
|
58
|
-
let i = 0;
|
|
59
|
-
while (current && current !== config.root.parentElement) {
|
|
60
|
-
let level = maybe(id(current)) ||
|
|
61
|
-
maybe(...attr(current)) ||
|
|
62
|
-
maybe(...classNames(current)) ||
|
|
63
|
-
maybe(tagName(current)) || [any()];
|
|
64
|
-
const nth = index(current);
|
|
65
|
-
if (limit === Limit.All) {
|
|
66
|
-
if (nth) {
|
|
67
|
-
level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (limit === Limit.Two) {
|
|
71
|
-
level = level.slice(0, 1);
|
|
72
|
-
if (nth) {
|
|
73
|
-
level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if (limit === Limit.One) {
|
|
77
|
-
const [node] = (level = level.slice(0, 1));
|
|
78
|
-
if (nth && dispensableNth(node)) {
|
|
79
|
-
level = [nthChild(node, nth)];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (const node of level) {
|
|
83
|
-
node.level = i;
|
|
84
|
-
}
|
|
85
|
-
stack.push(level);
|
|
86
|
-
if (stack.length >= config.seedMinLength) {
|
|
87
|
-
path = findUniquePath(stack, fallback);
|
|
88
|
-
if (path) {
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
current = current.parentElement;
|
|
93
|
-
i++;
|
|
94
|
-
}
|
|
95
|
-
if (!path) {
|
|
96
|
-
path = findUniquePath(stack, fallback);
|
|
97
|
-
}
|
|
98
|
-
return path;
|
|
99
|
-
}
|
|
100
|
-
function findUniquePath(stack, fallback) {
|
|
101
|
-
const paths = sort(combinations(stack));
|
|
102
|
-
if (paths.length > config.threshold) {
|
|
103
|
-
return fallback ? fallback() : null;
|
|
104
|
-
}
|
|
105
|
-
for (const candidate of paths) {
|
|
106
|
-
if (unique(candidate)) {
|
|
107
|
-
return candidate;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
function selector(path) {
|
|
113
|
-
let node = path[0];
|
|
114
|
-
let query = node.name;
|
|
115
|
-
for (let i = 1; i < path.length; i++) {
|
|
116
|
-
const level = path[i].level || 0;
|
|
117
|
-
if (node.level === level - 1) {
|
|
118
|
-
query = `${path[i].name} > ${query}`;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
query = `${path[i].name} ${query}`;
|
|
122
|
-
}
|
|
123
|
-
node = path[i];
|
|
124
|
-
}
|
|
125
|
-
return query;
|
|
126
|
-
}
|
|
127
|
-
function penalty(path) {
|
|
128
|
-
return path.map((node) => node.penalty).reduce((acc, i) => acc + i, 0);
|
|
129
|
-
}
|
|
130
|
-
function unique(path) {
|
|
131
|
-
switch (rootDocument.querySelectorAll(selector(path)).length) {
|
|
132
|
-
case 0:
|
|
133
|
-
throw new Error(`Can't select any node with this selector: ${selector(path)}`);
|
|
134
|
-
case 1:
|
|
135
|
-
return true;
|
|
136
|
-
default:
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function id(input) {
|
|
141
|
-
const elementId = input.getAttribute('id');
|
|
142
|
-
if (elementId && config.idName(elementId)) {
|
|
143
|
-
return {
|
|
144
|
-
name: '#' + cssesc(elementId, { isIdentifier: true }),
|
|
145
|
-
penalty: 0,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
function attr(input) {
|
|
151
|
-
const attrs = Array.from(input.attributes).filter((attr) => config.attr(attr.name, attr.value));
|
|
152
|
-
return attrs.map((attr) => ({
|
|
153
|
-
name: '[' + cssesc(attr.name, { isIdentifier: true }) + '="' + cssesc(attr.value) + '"]',
|
|
154
|
-
penalty: 0.5,
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
function classNames(input) {
|
|
158
|
-
const names = Array.from(input.classList).filter(config.className);
|
|
159
|
-
return names.map((name) => ({
|
|
160
|
-
name: '.' + cssesc(name, { isIdentifier: true }),
|
|
161
|
-
penalty: 1,
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
function tagName(input) {
|
|
165
|
-
const name = input.tagName.toLowerCase();
|
|
166
|
-
if (config.tagName(name)) {
|
|
167
|
-
return {
|
|
168
|
-
name,
|
|
169
|
-
penalty: 2,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
function any() {
|
|
175
|
-
return {
|
|
176
|
-
name: '*',
|
|
177
|
-
penalty: 3,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function index(input) {
|
|
181
|
-
const parent = input.parentNode;
|
|
182
|
-
if (!parent) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
let child = parent.firstChild;
|
|
186
|
-
if (!child) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
let i = 0;
|
|
190
|
-
while (child) {
|
|
191
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
192
|
-
i++;
|
|
193
|
-
}
|
|
194
|
-
if (child === input) {
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
child = child.nextSibling;
|
|
198
|
-
}
|
|
199
|
-
return i;
|
|
200
|
-
}
|
|
201
|
-
function nthChild(node, i) {
|
|
202
|
-
return {
|
|
203
|
-
name: node.name + `:nth-child(${i})`,
|
|
204
|
-
penalty: node.penalty + 1,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function dispensableNth(node) {
|
|
208
|
-
return node.name !== 'html' && !node.name.startsWith('#');
|
|
209
|
-
}
|
|
210
|
-
function maybe(...level) {
|
|
211
|
-
const list = level.filter(notEmpty);
|
|
212
|
-
if (list.length > 0) {
|
|
213
|
-
return list;
|
|
214
|
-
}
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
function notEmpty(value) {
|
|
218
|
-
return value !== null && value !== undefined;
|
|
219
|
-
}
|
|
220
|
-
function combinations(stack, path = []) {
|
|
221
|
-
const paths = [];
|
|
222
|
-
if (stack.length > 0) {
|
|
223
|
-
for (const node of stack[0]) {
|
|
224
|
-
paths.push(...combinations(stack.slice(1, stack.length), path.concat(node)));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
paths.push(path);
|
|
229
|
-
}
|
|
230
|
-
return paths;
|
|
231
|
-
}
|
|
232
|
-
function sort(paths) {
|
|
233
|
-
return Array.from(paths).sort((a, b) => penalty(a) - penalty(b));
|
|
234
|
-
}
|
|
235
|
-
function optimize(path, input, scope = {
|
|
236
|
-
counter: 0,
|
|
237
|
-
visited: new Map(),
|
|
238
|
-
}) {
|
|
239
|
-
const paths = [];
|
|
240
|
-
if (path.length > 2 && path.length > config.optimizedMinLength) {
|
|
241
|
-
for (let i = 1; i < path.length - 1; i++) {
|
|
242
|
-
if (scope.counter > config.maxNumberOfTries) {
|
|
243
|
-
return paths; // Okay At least I tried!
|
|
244
|
-
}
|
|
245
|
-
scope.counter += 1;
|
|
246
|
-
const newPath = [...path];
|
|
247
|
-
newPath.splice(i, 1);
|
|
248
|
-
const newPathKey = selector(newPath);
|
|
249
|
-
if (scope.visited.has(newPathKey)) {
|
|
250
|
-
return paths;
|
|
251
|
-
}
|
|
252
|
-
if (unique(newPath) && same(newPath, input)) {
|
|
253
|
-
paths.push(newPath);
|
|
254
|
-
scope.visited.set(newPathKey, true);
|
|
255
|
-
paths.push(...optimize(newPath, input, scope));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return paths;
|
|
260
|
-
}
|
|
261
|
-
function same(path, input) {
|
|
262
|
-
return rootDocument.querySelector(selector(path)) === input;
|
|
263
|
-
}
|
|
264
|
-
const regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
|
|
265
|
-
const regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
|
|
266
|
-
const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
|
267
|
-
const defaultOptions = {
|
|
268
|
-
escapeEverything: false,
|
|
269
|
-
isIdentifier: false,
|
|
270
|
-
quotes: 'single',
|
|
271
|
-
wrap: false,
|
|
272
|
-
};
|
|
273
|
-
function cssesc(string, opt = {}) {
|
|
274
|
-
const options = Object.assign(Object.assign({}, defaultOptions), opt);
|
|
275
|
-
if (options.quotes != 'single' && options.quotes != 'double') {
|
|
276
|
-
options.quotes = 'single';
|
|
277
|
-
}
|
|
278
|
-
const quote = options.quotes == 'double' ? '"' : "'";
|
|
279
|
-
const isIdentifier = options.isIdentifier;
|
|
280
|
-
const firstChar = string.charAt(0);
|
|
281
|
-
let output = '';
|
|
282
|
-
let counter = 0;
|
|
283
|
-
const length = string.length;
|
|
284
|
-
while (counter < length) {
|
|
285
|
-
const character = string.charAt(counter++);
|
|
286
|
-
let codePoint = character.charCodeAt(0);
|
|
287
|
-
let value = void 0;
|
|
288
|
-
// If it’s not a printable ASCII character…
|
|
289
|
-
if (codePoint < 0x20 || codePoint > 0x7e) {
|
|
290
|
-
if (codePoint >= 0xd800 && codePoint <= 0xdbff && counter < length) {
|
|
291
|
-
// It’s a high surrogate, and there is a next character.
|
|
292
|
-
const extra = string.charCodeAt(counter++);
|
|
293
|
-
if ((extra & 0xfc00) == 0xdc00) {
|
|
294
|
-
// next character is low surrogate
|
|
295
|
-
codePoint = ((codePoint & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
// It’s an unmatched surrogate; only append this code unit, in case
|
|
299
|
-
// the next code unit is the high surrogate of a surrogate pair.
|
|
300
|
-
counter--;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
if (options.escapeEverything) {
|
|
307
|
-
if (regexAnySingleEscape.test(character)) {
|
|
308
|
-
value = '\\' + character;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
else if (/[\t\n\f\r\x0B]/.test(character)) {
|
|
315
|
-
value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
|
|
316
|
-
}
|
|
317
|
-
else if (character == '\\' ||
|
|
318
|
-
(!isIdentifier &&
|
|
319
|
-
((character == '"' && quote == character) || (character == "'" && quote == character))) ||
|
|
320
|
-
(isIdentifier && regexSingleEscape.test(character))) {
|
|
321
|
-
value = '\\' + character;
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
value = character;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
output += value;
|
|
328
|
-
}
|
|
329
|
-
if (isIdentifier) {
|
|
330
|
-
if (/^-[-\d]/.test(output)) {
|
|
331
|
-
output = '\\-' + output.slice(1);
|
|
332
|
-
}
|
|
333
|
-
else if (/\d/.test(firstChar)) {
|
|
334
|
-
output = '\\3' + firstChar + ' ' + output.slice(1);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
// Remove spaces after `\HEX` escapes that are not followed by a hex digit,
|
|
338
|
-
// since they’re redundant. Note that this is only possible if the escape
|
|
339
|
-
// sequence isn’t preceded by an odd number of backslashes.
|
|
340
|
-
output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
|
|
341
|
-
if ($1 && $1.length % 2) {
|
|
342
|
-
// It’s not safe to remove the space, so don’t.
|
|
343
|
-
return $0;
|
|
344
|
-
}
|
|
345
|
-
// Strip the space.
|
|
346
|
-
return ($1 || '') + $2;
|
|
347
|
-
});
|
|
348
|
-
if (!isIdentifier && options.wrap) {
|
|
349
|
-
return quote + output + quote;
|
|
350
|
-
}
|
|
351
|
-
return output;
|
|
352
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type Options = {
|
|
2
|
-
root: Element;
|
|
3
|
-
idName: (name: string) => boolean;
|
|
4
|
-
className: (name: string) => boolean;
|
|
5
|
-
tagName: (name: string) => boolean;
|
|
6
|
-
attr: (name: string, value: string) => boolean;
|
|
7
|
-
seedMinLength: number;
|
|
8
|
-
optimizedMinLength: number;
|
|
9
|
-
threshold: number;
|
|
10
|
-
maxNumberOfTries: number;
|
|
11
|
-
};
|
|
12
|
-
export declare function finder(input: Element, options?: Partial<Options>): string;
|