checkpoint-cli 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +383 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -84,7 +84,286 @@ function trackingScript() {
84
84
  <script data-checkpoint>
85
85
  (function(){
86
86
  var lastPath='';
87
- function report(){
87
+ var pickMode=false;
88
+ var pickClickHandler=null;
89
+ var pickEscHandler=null;
90
+
91
+ function getMetrics(){
92
+ var de=document.documentElement;
93
+ return {
94
+ scrollX:window.scrollX||window.pageXOffset||0,
95
+ scrollY:window.scrollY||window.pageYOffset||0,
96
+ docWidth:de.scrollWidth||0,
97
+ docHeight:de.scrollHeight||0,
98
+ viewWidth:de.clientWidth||window.innerWidth||0,
99
+ viewHeight:de.clientHeight||window.innerHeight||0
100
+ };
101
+ }
102
+
103
+ function clampPercent(v){
104
+ if(v<0) return 0;
105
+ if(v>100) return 100;
106
+ return v;
107
+ }
108
+
109
+ function cssEscape(value){
110
+ try{
111
+ if(window.CSS&&typeof window.CSS.escape==='function'){
112
+ return window.CSS.escape(value);
113
+ }
114
+ }catch(e){}
115
+ return String(value).replace(/[^a-zA-Z0-9_-]/g,'\\\\$&');
116
+ }
117
+
118
+ function shortText(value){
119
+ if(!value) return '';
120
+ return String(value).replace(/\\s+/g,' ').trim().slice(0,120);
121
+ }
122
+
123
+ function elementSelector(el){
124
+ if(!el||!el.tagName) return '';
125
+ var tag=el.tagName.toLowerCase();
126
+ if(el.id) return '#'+cssEscape(el.id);
127
+ var cls=(el.className&&typeof el.className==='string')
128
+ ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0,3)
129
+ : [];
130
+ if(cls.length>0) return tag+'.'+cls.map(cssEscape).join('.');
131
+ return tag;
132
+ }
133
+
134
+ function getSelectorChain(el){
135
+ var out=[];
136
+ var seen={};
137
+ function push(selector,score){
138
+ if(!selector||seen[selector]) return;
139
+ seen[selector]=true;
140
+ out.push({selector:selector,score:score});
141
+ }
142
+ var current=el;
143
+ var depth=0;
144
+ while(current&&current.nodeType===1&&depth<5){
145
+ var sel=elementSelector(current);
146
+ if(sel){
147
+ var score=Math.max(0.2,1-(depth*0.18));
148
+ push(sel,score);
149
+ }
150
+ if(current.parentElement){
151
+ var parentSel=elementSelector(current.parentElement);
152
+ if(parentSel&&sel){
153
+ push(parentSel+' > '+sel,Math.max(0.2,0.88-(depth*0.15)));
154
+ }
155
+ }
156
+ current=current.parentElement;
157
+ depth++;
158
+ }
159
+ return out.slice(0,10);
160
+ }
161
+
162
+ function getSiblingPath(el){
163
+ var path=[];
164
+ var current=el;
165
+ var steps=0;
166
+ while(current&&current.parentElement&&steps<8){
167
+ var parent=current.parentElement;
168
+ var index=0;
169
+ var children=parent.children;
170
+ for(var i=0;i<children.length;i++){
171
+ if(children[i]===current){
172
+ index=i;
173
+ break;
174
+ }
175
+ }
176
+ path.unshift(index);
177
+ current=parent;
178
+ steps++;
179
+ }
180
+ return path;
181
+ }
182
+
183
+ function getDomFingerprint(el){
184
+ if(!el||!el.tagName) return null;
185
+ var classes=(el.className&&typeof el.className==='string')
186
+ ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0,6)
187
+ : [];
188
+ return {
189
+ tag:el.tagName.toLowerCase(),
190
+ id:el.id||null,
191
+ classes:classes,
192
+ sibling_path:getSiblingPath(el)
193
+ };
194
+ }
195
+
196
+ function getContainerHint(el){
197
+ if(!el||typeof el.closest!=='function') return null;
198
+ var container=el.closest('main,article,section,form,nav,[role="main"],[data-testid],[id]');
199
+ if(!container||!container.tagName) return null;
200
+ var classes=(container.className&&typeof container.className==='string')
201
+ ? container.className.trim().split(/\\s+/).filter(Boolean).slice(0,4)
202
+ : [];
203
+ return {
204
+ selector:elementSelector(container),
205
+ tag:container.tagName.toLowerCase(),
206
+ id:container.id||null,
207
+ classes:classes
208
+ };
209
+ }
210
+
211
+ function buildCoordFallback(clientX,clientY,metrics){
212
+ var safeViewW=metrics.viewWidth||1;
213
+ var safeViewH=metrics.viewHeight||1;
214
+ var docX=clientX+metrics.scrollX;
215
+ var docY=clientY+metrics.scrollY;
216
+ return {
217
+ x_percent:clampPercent((clientX/safeViewW)*100),
218
+ y_percent:clampPercent((clientY/safeViewH)*100),
219
+ scroll_x:metrics.scrollX,
220
+ scroll_y:metrics.scrollY,
221
+ viewport_width:safeViewW,
222
+ viewport_height:safeViewH,
223
+ doc_width:metrics.docWidth||safeViewW,
224
+ doc_height:metrics.docHeight||safeViewH,
225
+ doc_x_percent:clampPercent((docX/(metrics.docWidth||safeViewW))*100),
226
+ doc_y_percent:clampPercent((docY/(metrics.docHeight||safeViewH))*100)
227
+ };
228
+ }
229
+
230
+ function buildAnchorPayload(el,clientX,clientY){
231
+ var metrics=getMetrics();
232
+ var textSelf='';
233
+ var textParent='';
234
+ try{
235
+ textSelf=shortText(el&&el.textContent);
236
+ textParent=shortText(el&&el.parentElement&&el.parentElement.textContent);
237
+ }catch(e){}
238
+ return {
239
+ selector_chain:getSelectorChain(el),
240
+ dom_fingerprint:getDomFingerprint(el),
241
+ text_context:{
242
+ self:textSelf,
243
+ parent:textParent
244
+ },
245
+ container_hint:getContainerHint(el),
246
+ coord_fallback:buildCoordFallback(clientX,clientY,metrics)
247
+ };
248
+ }
249
+
250
+ function resolveFromFingerprint(fingerprint){
251
+ if(!fingerprint) return null;
252
+ if(fingerprint.id){
253
+ var byId=document.getElementById(fingerprint.id);
254
+ if(byId) return byId;
255
+ }
256
+ var tag=fingerprint.tag||'*';
257
+ var selector=tag;
258
+ if(Array.isArray(fingerprint.classes)&&fingerprint.classes.length>0){
259
+ selector+= '.'+fingerprint.classes.map(cssEscape).join('.');
260
+ }
261
+ try{
262
+ var nodes=document.querySelectorAll(selector);
263
+ if(nodes&&nodes.length>0) return nodes[0];
264
+ }catch(e){}
265
+ return null;
266
+ }
267
+
268
+ function resolveAnchor(payload){
269
+ if(!payload||typeof payload!=='object') return {coordFallback:null,strategy:'none',matchedSelector:null};
270
+ var element=null;
271
+ var strategy='none';
272
+ var matchedSelector=null;
273
+ if(Array.isArray(payload.selector_chain)){
274
+ for(var i=0;i<payload.selector_chain.length;i++){
275
+ var candidate=payload.selector_chain[i];
276
+ if(!candidate||typeof candidate.selector!=='string') continue;
277
+ try{
278
+ var found=document.querySelector(candidate.selector);
279
+ if(found){
280
+ element=found;
281
+ strategy='selector';
282
+ matchedSelector=candidate.selector;
283
+ break;
284
+ }
285
+ }catch(e){}
286
+ }
287
+ }
288
+ if(!element&&payload.container_hint&&typeof payload.container_hint.selector==='string'){
289
+ try{
290
+ var containerEl=document.querySelector(payload.container_hint.selector);
291
+ if(containerEl){
292
+ element=containerEl;
293
+ strategy='container';
294
+ matchedSelector=payload.container_hint.selector;
295
+ }
296
+ }catch(e){}
297
+ }
298
+ if(!element){
299
+ var fpEl=resolveFromFingerprint(payload.dom_fingerprint);
300
+ if(fpEl){
301
+ element=fpEl;
302
+ strategy='fingerprint';
303
+ }
304
+ }
305
+ if(!element) return {coordFallback:null,strategy:'none',matchedSelector:null};
306
+ var rect=element.getBoundingClientRect();
307
+ var clientX=rect.left+Math.max(1,Math.min(rect.width-1,rect.width*0.5));
308
+ var clientY=rect.top+Math.max(1,Math.min(rect.height-1,rect.height*0.5));
309
+ var metrics=getMetrics();
310
+ return {coordFallback:buildCoordFallback(clientX,clientY,metrics),strategy:strategy,matchedSelector:matchedSelector};
311
+ }
312
+
313
+ function setPickMode(enabled){
314
+ var next=!!enabled;
315
+ if(pickMode===next) return;
316
+ pickMode=next;
317
+ document.documentElement.style.cursor=pickMode?'crosshair':'';
318
+ if(document.body){
319
+ document.body.style.cursor=pickMode?'crosshair':'';
320
+ }
321
+ if(!pickMode){
322
+ if(pickClickHandler){
323
+ window.removeEventListener('click',pickClickHandler,true);
324
+ pickClickHandler=null;
325
+ }
326
+ if(pickEscHandler){
327
+ window.removeEventListener('keydown',pickEscHandler,true);
328
+ pickEscHandler=null;
329
+ }
330
+ return;
331
+ }
332
+ pickClickHandler=function(ev){
333
+ try{
334
+ if(!pickMode) return;
335
+ ev.preventDefault();
336
+ ev.stopPropagation();
337
+ if(typeof ev.stopImmediatePropagation==='function'){
338
+ ev.stopImmediatePropagation();
339
+ }
340
+ var target=ev.target&&ev.target.nodeType===1?ev.target:null;
341
+ if(!target) return;
342
+ var payload=buildAnchorPayload(target,ev.clientX,ev.clientY);
343
+ window.parent.postMessage({
344
+ type:'checkpoint:pickResult',
345
+ path:location.pathname+location.search+location.hash,
346
+ anchorPayload:payload,
347
+ point:{
348
+ xPercent:payload.coord_fallback&&typeof payload.coord_fallback.x_percent==='number'?payload.coord_fallback.x_percent:50,
349
+ yPercent:payload.coord_fallback&&typeof payload.coord_fallback.y_percent==='number'?payload.coord_fallback.y_percent:50,
350
+ scrollY:payload.coord_fallback&&typeof payload.coord_fallback.scroll_y==='number'?payload.coord_fallback.scroll_y:0,
351
+ viewHeight:payload.coord_fallback&&typeof payload.coord_fallback.viewport_height==='number'?payload.coord_fallback.viewport_height:0
352
+ }
353
+ },'*');
354
+ }catch(e){}
355
+ setPickMode(false);
356
+ };
357
+ pickEscHandler=function(ev){
358
+ if(ev.key==='Escape'){
359
+ setPickMode(false);
360
+ }
361
+ };
362
+ window.addEventListener('click',pickClickHandler,true);
363
+ window.addEventListener('keydown',pickEscHandler,true);
364
+ }
365
+
366
+ function reportNav(){
88
367
  try{
89
368
  var p=location.pathname+location.search+location.hash;
90
369
  if(p!==lastPath){
@@ -93,16 +372,84 @@ function trackingScript() {
93
372
  type:'checkpoint:navigate',
94
373
  path:p
95
374
  },'*');
375
+ reportScroll();
96
376
  }
97
377
  }catch(e){}
98
378
  }
99
- report();
379
+ var scrollTick=false;
380
+ function reportScroll(){
381
+ try{
382
+ var metrics=getMetrics();
383
+ window.parent.postMessage({
384
+ type:'checkpoint:scroll',
385
+ scrollX:metrics.scrollX,
386
+ scrollY:metrics.scrollY,
387
+ docWidth:metrics.docWidth,
388
+ docHeight:metrics.docHeight,
389
+ viewWidth:metrics.viewWidth,
390
+ viewHeight:metrics.viewHeight
391
+ },'*');
392
+ }catch(e){}
393
+ }
394
+ function onScroll(){
395
+ if(!scrollTick){
396
+ scrollTick=true;
397
+ requestAnimationFrame(function(){
398
+ reportScroll();
399
+ scrollTick=false;
400
+ });
401
+ }
402
+ }
403
+ reportNav();
404
+ reportScroll();
100
405
  var _ps=history.pushState,_rs=history.replaceState;
101
- history.pushState=function(){_ps.apply(this,arguments);report();};
102
- history.replaceState=function(){_rs.apply(this,arguments);report();};
103
- window.addEventListener('popstate',report);
104
- window.addEventListener('hashchange',report);
105
- setInterval(report,500);
406
+ history.pushState=function(){_ps.apply(this,arguments);reportNav();};
407
+ history.replaceState=function(){_rs.apply(this,arguments);reportNav();};
408
+ window.addEventListener('popstate',reportNav);
409
+ window.addEventListener('hashchange',reportNav);
410
+ window.addEventListener('scroll',onScroll,{passive:true});
411
+ window.addEventListener('resize',reportScroll);
412
+ window.addEventListener('message',function(e){
413
+ try{
414
+ if(e.data&&e.data.type==='checkpoint:scrollTo'&&typeof e.data.y==='number'){
415
+ window.scrollTo({top:e.data.y,behavior:'smooth'});
416
+ }
417
+ if(e.data&&e.data.type==='checkpoint:pickMode'){
418
+ setPickMode(!!e.data.enabled);
419
+ }
420
+ if(e.data&&e.data.type==='checkpoint:resolveAnchors'&&Array.isArray(e.data.items)){
421
+ var positions=[];
422
+ for(var i=0;i<e.data.items.length;i++){
423
+ var item=e.data.items[i];
424
+ if(!item||typeof item.id!=='string') continue;
425
+ var result=resolveAnchor(item.anchorPayload);
426
+ if(result.coordFallback){
427
+ positions.push({
428
+ id:item.id,
429
+ found:true,
430
+ strategy:result.strategy,
431
+ matchedSelector:result.matchedSelector,
432
+ coordFallback:result.coordFallback
433
+ });
434
+ } else {
435
+ positions.push({
436
+ id:item.id,
437
+ found:false,
438
+ strategy:'fallback',
439
+ matchedSelector:null,
440
+ coordFallback:null
441
+ });
442
+ }
443
+ }
444
+ window.parent.postMessage({
445
+ type:'checkpoint:anchorsResolved',
446
+ path:location.pathname+location.search+location.hash,
447
+ positions:positions
448
+ },'*');
449
+ }
450
+ }catch(ex){}
451
+ });
452
+ setInterval(reportNav,500);
106
453
  })();
107
454
  </script>`.trim();
108
455
  }
@@ -366,13 +713,22 @@ function loginWithBrowser() {
366
713
  const refresh_token = url.searchParams.get('refresh_token');
367
714
  if (access_token && refresh_token) {
368
715
  // Success page
369
- res.writeHead(200, { 'Content-Type': 'text/html' });
716
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
370
717
  res.end(`
371
718
  <html>
372
- <body style="font-family: system-ui; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #0a0e17; color: #f1f3f5;">
373
- <div style="text-align: center;">
374
- <h1 style="font-size: 24px;">✓ Logged in to Checkpoint</h1>
375
- <p style="color: #9ca3af;">You can close this tab and return to your terminal.</p>
719
+ <body style="font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #13120A; color: #f0ede6;">
720
+ <div style="text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px;">
721
+ <svg width="32" height="32" viewBox="0 0 256 256" fill="none">
722
+ <circle cx="128" cy="128" r="112" fill="#22c55e"/>
723
+ <polyline points="88,136 112,160 168,104" stroke="#13120A" stroke-width="16" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
724
+ </svg>
725
+ <h1 style="font-size: 20px; font-weight: 500; margin: 0; color: #f0ede6;">Logged in to Checkpoint</h1>
726
+ <p style="color: #9e9889; margin: 0; font-size: 14px;">You can close this tab and return to your terminal.</p>
727
+ <div style="margin-top: 8px; padding-top: 24px; border-top: 1px dashed rgba(73,67,58,0.3);">
728
+ <p style="color: #9e9889; margin: 0px 0 24px; font-size: 13px;">Start sharing your localhost for feedback:</p>
729
+ <code style="padding: 8px 12px; background: #1D1B15; border: 1px solid rgba(73,67,58,0.4); border-radius: 6px; font-family: 'JetBrains Mono','Fira Code','SF Mono',monospace; font-size: 13px; color: #9e9889;">checkpoint start -p <span style="color: #ff5700;">&lt;port&gt;</span></code>
730
+ <p style="text-align: center; margin-top: 24px; font-size: 13px; color: #9e9889;">or <a href="${(0, config_js_1.getAppUrl)()}" style="color: #ff5700; text-decoration: none;">Go to Dashboard</a></p>
731
+ </div>
376
732
  </div>
377
733
  </body>
378
734
  </html>
@@ -381,13 +737,18 @@ function loginWithBrowser() {
381
737
  resolve({ access_token, refresh_token });
382
738
  }
383
739
  else {
384
- res.writeHead(400, { 'Content-Type': 'text/html' });
740
+ res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
385
741
  res.end(`
386
742
  <html>
387
- <body style="font-family: system-ui; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #0a0e17; color: #f1f3f5;">
388
- <div style="text-align: center;">
389
- <h1 style="font-size: 24px; color: #ef4444;">Login failed</h1>
390
- <p style="color: #9ca3af;">Missing tokens. Please try again.</p>
743
+ <body style="font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #13120A; color: #f0ede6;">
744
+ <div style="text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px;">
745
+ <svg width="48" height="48" viewBox="0 0 256 256" fill="none">
746
+ <circle cx="128" cy="128" r="112" fill="#ef4444"/>
747
+ <line x1="96" y1="96" x2="160" y2="160" stroke="#13120A" stroke-width="16" stroke-linecap="round"/>
748
+ <line x1="160" y1="96" x2="96" y2="160" stroke="#13120A" stroke-width="16" stroke-linecap="round"/>
749
+ </svg>
750
+ <h1 style="font-size: 20px; font-weight: 500; margin: 0; color: #f0ede6;">Login failed</h1>
751
+ <p style="color: #9e9889; margin: 0; font-size: 14px;">Missing tokens. Please try again.</p>
391
752
  </div>
392
753
  </body>
393
754
  </html>
@@ -410,10 +771,13 @@ function loginWithBrowser() {
410
771
  const callbackUrl = `http://localhost:${addr.port}/callback`;
411
772
  const APP_URL = (0, config_js_1.getAppUrl)();
412
773
  const loginUrl = `${APP_URL}/cli/auth?callback=${encodeURIComponent(callbackUrl)}`;
413
- console.log(chalk_1.default.gray(` Opening browser...`));
414
774
  console.log(` ${chalk_1.default.cyan(loginUrl)}`);
415
775
  console.log('');
416
- openBrowser(loginUrl);
776
+ const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
777
+ rl.question(chalk_1.default.gray(' Press ENTER to open the browser...'), () => {
778
+ rl.close();
779
+ openBrowser(loginUrl);
780
+ });
417
781
  });
418
782
  // Timeout after 5 minutes
419
783
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkpoint-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Share your localhost with reviewers — get visual feedback directly on the page",
5
5
  "keywords": [
6
6
  "checkpoint",