checkpoint-cli 0.3.6 → 0.3.7
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 +71 -1
- 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.7');
|
|
1610
1610
|
// ── checkpoint login ──
|
|
1611
1611
|
program
|
|
1612
1612
|
.command('login')
|
|
@@ -43,6 +43,49 @@ function buildMinimalTrackingScript() {
|
|
|
43
43
|
return String(value).replace(/\s+/g,' ').trim().slice(0,120);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function normalizedText(value){
|
|
47
|
+
return shortText(value).toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getNodeText(node){
|
|
51
|
+
try{
|
|
52
|
+
if(!node||!node.textContent) return '';
|
|
53
|
+
return normalizedText(node.textContent);
|
|
54
|
+
}catch(e){}
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getTextContext(target){
|
|
59
|
+
if(!target||target.nodeType!==1) return null;
|
|
60
|
+
var self=getNodeText(target);
|
|
61
|
+
var parent=getNodeText(target.parentElement);
|
|
62
|
+
var before=getNodeText(target.previousElementSibling);
|
|
63
|
+
var after=getNodeText(target.nextElementSibling);
|
|
64
|
+
|
|
65
|
+
// If clicked node has no text (e.g. image/icon), borrow nearest parent text.
|
|
66
|
+
if(!self){
|
|
67
|
+
var current=target.parentElement;
|
|
68
|
+
var depth=0;
|
|
69
|
+
while(current&&depth<4&&!self){
|
|
70
|
+
var candidate=getNodeText(current);
|
|
71
|
+
if(candidate&&candidate.length>=3){
|
|
72
|
+
self=candidate;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
current=current.parentElement;
|
|
76
|
+
depth++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(!self&&!parent&&!before&&!after) return null;
|
|
81
|
+
return {
|
|
82
|
+
self:self||undefined,
|
|
83
|
+
parent:parent||undefined,
|
|
84
|
+
before:before||undefined,
|
|
85
|
+
after:after||undefined
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
46
89
|
function cssEscape(value){
|
|
47
90
|
try{
|
|
48
91
|
if(window.CSS&&typeof window.CSS.escape==='function') return window.CSS.escape(value);
|
|
@@ -290,10 +333,11 @@ function buildMinimalTrackingScript() {
|
|
|
290
333
|
var metrics=getMetrics();
|
|
291
334
|
var sourceTarget=findBestAnchorableElement(el);
|
|
292
335
|
var anchorEl=sourceTarget.element||el;
|
|
336
|
+
var textContext=getTextContext(el)||getTextContext(anchorEl);
|
|
293
337
|
return {
|
|
294
338
|
selector_chain:[],
|
|
295
339
|
dom_fingerprint:null,
|
|
296
|
-
text_context:
|
|
340
|
+
text_context:textContext,
|
|
297
341
|
container_hint:null,
|
|
298
342
|
transient_context:null,
|
|
299
343
|
source_anchor:sourceTarget.sourceAnchor||getSourceAnchorFromElement(anchorEl),
|
|
@@ -301,6 +345,31 @@ function buildMinimalTrackingScript() {
|
|
|
301
345
|
};
|
|
302
346
|
}
|
|
303
347
|
|
|
348
|
+
function textMatchBonus(node,textContext){
|
|
349
|
+
if(!textContext||typeof textContext!=='object') return 0;
|
|
350
|
+
var score=0;
|
|
351
|
+
var self=getNodeText(node);
|
|
352
|
+
var parent=getNodeText(node&&node.parentElement);
|
|
353
|
+
if(textContext.self&&self){
|
|
354
|
+
if(self===textContext.self) score+=280;
|
|
355
|
+
else if(self.indexOf(textContext.self)>=0||textContext.self.indexOf(self)>=0) score+=130;
|
|
356
|
+
else score-=40;
|
|
357
|
+
}
|
|
358
|
+
if(textContext.parent&&parent){
|
|
359
|
+
if(parent===textContext.parent) score+=180;
|
|
360
|
+
else if(parent.indexOf(textContext.parent)>=0||textContext.parent.indexOf(parent)>=0) score+=90;
|
|
361
|
+
}
|
|
362
|
+
if(textContext.before){
|
|
363
|
+
var prev=getNodeText(node&&node.previousElementSibling);
|
|
364
|
+
if(prev&&prev===textContext.before) score+=55;
|
|
365
|
+
}
|
|
366
|
+
if(textContext.after){
|
|
367
|
+
var next=getNodeText(node&&node.nextElementSibling);
|
|
368
|
+
if(next&&next===textContext.after) score+=55;
|
|
369
|
+
}
|
|
370
|
+
return score;
|
|
371
|
+
}
|
|
372
|
+
|
|
304
373
|
function findBySource(sourceAnchor,payload,scope){
|
|
305
374
|
if(!sourceAnchor||typeof sourceAnchor!=='object') return null;
|
|
306
375
|
var searchScope=scope||document;
|
|
@@ -322,6 +391,7 @@ function buildMinimalTrackingScript() {
|
|
|
322
391
|
var node=nodes[i];
|
|
323
392
|
var score=sourceMatchScore(node,sourceAnchor);
|
|
324
393
|
if(score<=0) continue;
|
|
394
|
+
score+=textMatchBonus(node,payload&&payload.text_context);
|
|
325
395
|
if(targetDocPoint&&node.getBoundingClientRect){
|
|
326
396
|
var r=node.getBoundingClientRect();
|
|
327
397
|
var centerX=r.left+(r.width/2)+metrics.scrollX;
|