checkpoint-cli 0.3.4 → 0.3.6
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/dist/index.js +1 -1
- package/dist/tracking-script-minimal.js +85 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1606,7 +1606,7 @@ const program = new commander_1.Command();
|
|
|
1606
1606
|
program
|
|
1607
1607
|
.name('checkpoint')
|
|
1608
1608
|
.description('Share your localhost with reviewers — get visual feedback directly on the page')
|
|
1609
|
-
.version('0.3.
|
|
1609
|
+
.version('0.3.6');
|
|
1610
1610
|
// ── checkpoint login ──
|
|
1611
1611
|
program
|
|
1612
1612
|
.command('login')
|
|
@@ -15,6 +15,7 @@ function buildMinimalTrackingScript() {
|
|
|
15
15
|
var lastMouseY=0;
|
|
16
16
|
var inspectBox=null;
|
|
17
17
|
var inspectLabel=null;
|
|
18
|
+
var pickShield=null;
|
|
18
19
|
var lastPath='';
|
|
19
20
|
var mutationTick=false;
|
|
20
21
|
var pendingPickCommit=false;
|
|
@@ -208,13 +209,49 @@ function buildMinimalTrackingScript() {
|
|
|
208
209
|
return score;
|
|
209
210
|
}
|
|
210
211
|
|
|
212
|
+
function getTargetDocPoint(payload,metrics){
|
|
213
|
+
var fallback=payload&&payload.coord_fallback;
|
|
214
|
+
if(!fallback||typeof fallback!=='object') return null;
|
|
215
|
+
var docW=(typeof fallback.doc_width==='number'&&fallback.doc_width>0)
|
|
216
|
+
? fallback.doc_width
|
|
217
|
+
: (metrics.docWidth||metrics.viewWidth||1);
|
|
218
|
+
var docH=(typeof fallback.doc_height==='number'&&fallback.doc_height>0)
|
|
219
|
+
? fallback.doc_height
|
|
220
|
+
: (metrics.docHeight||metrics.viewHeight||1);
|
|
221
|
+
if(typeof fallback.doc_x_percent==='number'&&typeof fallback.doc_y_percent==='number'){
|
|
222
|
+
return {
|
|
223
|
+
x:(fallback.doc_x_percent/100)*docW,
|
|
224
|
+
y:(fallback.doc_y_percent/100)*docH
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if(typeof fallback.x_percent==='number'&&typeof fallback.y_percent==='number'){
|
|
228
|
+
var viewW=(typeof fallback.viewport_width==='number'&&fallback.viewport_width>0)
|
|
229
|
+
? fallback.viewport_width
|
|
230
|
+
: (metrics.viewWidth||1);
|
|
231
|
+
var viewH=(typeof fallback.viewport_height==='number'&&fallback.viewport_height>0)
|
|
232
|
+
? fallback.viewport_height
|
|
233
|
+
: (metrics.viewHeight||1);
|
|
234
|
+
var scrollX=typeof fallback.scroll_x==='number'?fallback.scroll_x:metrics.scrollX;
|
|
235
|
+
var scrollY=typeof fallback.scroll_y==='number'?fallback.scroll_y:metrics.scrollY;
|
|
236
|
+
return {
|
|
237
|
+
x:(fallback.x_percent/100)*viewW+scrollX,
|
|
238
|
+
y:(fallback.y_percent/100)*viewH+scrollY
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
211
244
|
function getElementAtPoint(x,y){
|
|
212
245
|
try{
|
|
246
|
+
if(pickShield) pickShield.style.pointerEvents='none';
|
|
213
247
|
if(typeof x==='number'&&typeof y==='number'&&document.elementFromPoint){
|
|
214
248
|
var node=document.elementFromPoint(x,y);
|
|
215
249
|
if(node&&node.nodeType===1) return node;
|
|
216
250
|
}
|
|
217
251
|
}catch(e){}
|
|
252
|
+
finally{
|
|
253
|
+
if(pickShield) pickShield.style.pointerEvents='auto';
|
|
254
|
+
}
|
|
218
255
|
return null;
|
|
219
256
|
}
|
|
220
257
|
|
|
@@ -264,7 +301,7 @@ function buildMinimalTrackingScript() {
|
|
|
264
301
|
};
|
|
265
302
|
}
|
|
266
303
|
|
|
267
|
-
function findBySource(sourceAnchor,scope){
|
|
304
|
+
function findBySource(sourceAnchor,payload,scope){
|
|
268
305
|
if(!sourceAnchor||typeof sourceAnchor!=='object') return null;
|
|
269
306
|
var searchScope=scope||document;
|
|
270
307
|
if(sourceAnchor.explicit_id){
|
|
@@ -278,10 +315,22 @@ function buildMinimalTrackingScript() {
|
|
|
278
315
|
}catch(e){ nodes=[]; }
|
|
279
316
|
if(nodes.length>1800) nodes=nodes.slice(0,1800);
|
|
280
317
|
var best=null;
|
|
281
|
-
var bestScore
|
|
318
|
+
var bestScore=-Infinity;
|
|
319
|
+
var metrics=getMetrics();
|
|
320
|
+
var targetDocPoint=getTargetDocPoint(payload,metrics);
|
|
282
321
|
for(var i=0;i<nodes.length;i++){
|
|
283
322
|
var node=nodes[i];
|
|
284
323
|
var score=sourceMatchScore(node,sourceAnchor);
|
|
324
|
+
if(score<=0) continue;
|
|
325
|
+
if(targetDocPoint&&node.getBoundingClientRect){
|
|
326
|
+
var r=node.getBoundingClientRect();
|
|
327
|
+
var centerX=r.left+(r.width/2)+metrics.scrollX;
|
|
328
|
+
var centerY=r.top+(r.height/2)+metrics.scrollY;
|
|
329
|
+
var dx=centerX-targetDocPoint.x;
|
|
330
|
+
var dy=centerY-targetDocPoint.y;
|
|
331
|
+
var distance=Math.sqrt(dx*dx+dy*dy);
|
|
332
|
+
score-=Math.min(280,distance*0.85);
|
|
333
|
+
}
|
|
285
334
|
if(score>bestScore){
|
|
286
335
|
best=node;
|
|
287
336
|
bestScore=score;
|
|
@@ -295,7 +344,7 @@ function buildMinimalTrackingScript() {
|
|
|
295
344
|
return { coordFallback:null, strategy:'none', matchedSelector:null, status:'none' };
|
|
296
345
|
}
|
|
297
346
|
if(payload.source_anchor){
|
|
298
|
-
var match=findBySource(payload.source_anchor,document);
|
|
347
|
+
var match=findBySource(payload.source_anchor,payload,document);
|
|
299
348
|
if(match&&match.getBoundingClientRect){
|
|
300
349
|
var rect=match.getBoundingClientRect();
|
|
301
350
|
var clientX=rect.left+Math.max(1,Math.min(Math.max(2,rect.width)-1,rect.width/2));
|
|
@@ -388,6 +437,28 @@ function buildMinimalTrackingScript() {
|
|
|
388
437
|
if(inspectLabel) inspectLabel.style.display='none';
|
|
389
438
|
}
|
|
390
439
|
|
|
440
|
+
function ensurePickShield(){
|
|
441
|
+
if(!document.body) return;
|
|
442
|
+
if(pickShield) return;
|
|
443
|
+
pickShield=document.createElement('div');
|
|
444
|
+
pickShield.style.position='fixed';
|
|
445
|
+
pickShield.style.left='0';
|
|
446
|
+
pickShield.style.top='0';
|
|
447
|
+
pickShield.style.right='0';
|
|
448
|
+
pickShield.style.bottom='0';
|
|
449
|
+
pickShield.style.background='transparent';
|
|
450
|
+
pickShield.style.cursor='crosshair';
|
|
451
|
+
pickShield.style.pointerEvents='auto';
|
|
452
|
+
pickShield.style.zIndex='2147483645';
|
|
453
|
+
document.body.appendChild(pickShield);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function removePickShield(){
|
|
457
|
+
if(!pickShield) return;
|
|
458
|
+
try{ pickShield.remove(); }catch(e){}
|
|
459
|
+
pickShield=null;
|
|
460
|
+
}
|
|
461
|
+
|
|
391
462
|
function renderInspectAt(x,y){
|
|
392
463
|
ensureInspectUi();
|
|
393
464
|
if(!inspectBox||!inspectLabel){
|
|
@@ -445,9 +516,9 @@ function buildMinimalTrackingScript() {
|
|
|
445
516
|
if(document.body) document.body.style.cursor=pickMode?'crosshair':'';
|
|
446
517
|
|
|
447
518
|
if(!pickMode){
|
|
448
|
-
if(pickMoveHandler)
|
|
449
|
-
if(pickPointerDownHandler)
|
|
450
|
-
if(pickClickHandler)
|
|
519
|
+
if(pickMoveHandler&&pickShield) pickShield.removeEventListener('mousemove',pickMoveHandler,true);
|
|
520
|
+
if(pickPointerDownHandler&&pickShield) pickShield.removeEventListener('pointerdown',pickPointerDownHandler,true);
|
|
521
|
+
if(pickClickHandler&&pickShield) pickShield.removeEventListener('click',pickClickHandler,true);
|
|
451
522
|
if(pickEscHandler) window.removeEventListener('keydown',pickEscHandler,true);
|
|
452
523
|
if(pickKeydownHandler) window.removeEventListener('keydown',pickKeydownHandler,true);
|
|
453
524
|
if(pickBlockHandler){
|
|
@@ -473,9 +544,13 @@ function buildMinimalTrackingScript() {
|
|
|
473
544
|
hoverRaf=0;
|
|
474
545
|
}
|
|
475
546
|
hideInspectUi();
|
|
547
|
+
removePickShield();
|
|
476
548
|
return;
|
|
477
549
|
}
|
|
478
550
|
|
|
551
|
+
ensurePickShield();
|
|
552
|
+
if(!pickShield) return;
|
|
553
|
+
|
|
479
554
|
pickMoveHandler=function(ev){
|
|
480
555
|
if(!pickMode) return;
|
|
481
556
|
lastMouseX=ev.clientX;
|
|
@@ -496,19 +571,13 @@ function buildMinimalTrackingScript() {
|
|
|
496
571
|
try{
|
|
497
572
|
postPickResult(target,ev.clientX,ev.clientY);
|
|
498
573
|
}catch(e){}
|
|
499
|
-
|
|
500
|
-
// otherwise link/tab navigation can still fire.
|
|
501
|
-
pendingPickCommit=true;
|
|
574
|
+
setPickMode(false);
|
|
502
575
|
};
|
|
503
576
|
pickClickHandler=function(ev){
|
|
504
577
|
if(!pickMode) return;
|
|
505
578
|
ev.preventDefault();
|
|
506
579
|
ev.stopPropagation();
|
|
507
580
|
if(typeof ev.stopImmediatePropagation==='function') ev.stopImmediatePropagation();
|
|
508
|
-
if(pendingPickCommit){
|
|
509
|
-
pendingPickCommit=false;
|
|
510
|
-
setPickMode(false);
|
|
511
|
-
}
|
|
512
581
|
};
|
|
513
582
|
pickEscHandler=function(ev){
|
|
514
583
|
if(ev.key==='Escape') setPickMode(false);
|
|
@@ -529,9 +598,9 @@ function buildMinimalTrackingScript() {
|
|
|
529
598
|
if(typeof ev.stopImmediatePropagation==='function') ev.stopImmediatePropagation();
|
|
530
599
|
};
|
|
531
600
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
601
|
+
pickShield.addEventListener('mousemove',pickMoveHandler,true);
|
|
602
|
+
pickShield.addEventListener('pointerdown',pickPointerDownHandler,true);
|
|
603
|
+
pickShield.addEventListener('click',pickClickHandler,true);
|
|
535
604
|
window.addEventListener('keydown',pickEscHandler,true);
|
|
536
605
|
window.addEventListener('keydown',pickKeydownHandler,true);
|
|
537
606
|
window.addEventListener('mousedown',pickBlockHandler,true);
|