@papyrus-sdk/ui-react-native 0.2.36 → 0.2.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papyrus-sdk/ui-react-native",
3
- "version": "0.2.36",
3
+ "version": "0.2.37",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "papyrus",
@@ -68,9 +68,9 @@
68
68
  "react-native-gesture-handler": "~2.28.0",
69
69
  "react-native-safe-area-context": "^5.6.2",
70
70
  "react-native-reanimated": "3.19.5",
71
- "@papyrus-sdk/core": "0.2.24",
72
71
  "@papyrus-sdk/engine-native": "0.2.23",
73
- "@papyrus-sdk/types": "0.2.17"
72
+ "@papyrus-sdk/types": "0.2.17",
73
+ "@papyrus-sdk/core": "0.2.24"
74
74
  },
75
75
  "scripts": {
76
76
  "build": "node runtime/syncComicRuntime.mjs && tsup",
@@ -140,16 +140,22 @@
140
140
  inkSvg.setAttribute('data-papyrus-ink-overlay','');
141
141
  inkSvg.style.cssText = 'position:absolute;left:0;top:0;overflow:visible;pointer-events:none;z-index:1';
142
142
  overlay.appendChild(inkSvg);
143
+ var previewSvg = doc.createElementNS('http://www.w3.org/2000/svg','svg');
144
+ previewSvg.setAttribute('data-papyrus-ink-preview-overlay','');
145
+ previewSvg.style.cssText = 'position:fixed;left:0;top:0;overflow:hidden;pointer-events:none;z-index:2147482999';
146
+ doc.documentElement.appendChild(previewSvg);
143
147
  var inkCanvas = doc.createElement('canvas');
144
148
  inkCanvas.dataset.papyrusInkCapture = '';
145
149
  inkCanvas.style.cssText = 'position:fixed;left:0;top:0;width:1px;height:1px;z-index:2147483000;background:transparent;pointer-events:none;touch-action:none';
146
- doc.body.appendChild(inkCanvas);
150
+ doc.documentElement.appendChild(inkCanvas);
147
151
  var inkContext = null; try { if(typeof win.CanvasRenderingContext2D==='function')inkContext = inkCanvas.getContext('2d'); } catch (_) {}
148
152
  function resizeCanvas() {
149
- var bodyRect=doc.body.getBoundingClientRect(), ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
150
- var width=Math.max(1,Math.min(4096,doc.body.clientWidth||bodyRect.width||Math.min(4096,win.innerWidth||1)));
151
- var height=Math.max(1,Math.min(4096,doc.body.clientHeight||bodyRect.height||Math.min(4096,win.innerHeight||1)));
153
+ var ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
154
+ var width=Math.max(1,Math.min(4096,win.innerWidth||1));
155
+ var height=Math.max(1,Math.min(4096,win.innerHeight||1));
152
156
  inkCanvas.style.width=width+'px';inkCanvas.style.height=height+'px';
157
+ previewSvg.setAttribute('width',String(width));previewSvg.setAttribute('height',String(height));
158
+ previewSvg.setAttribute('viewBox','0 0 '+width+' '+height);
153
159
  inkCanvas.width = Math.round(width*ratio); inkCanvas.height = Math.round(height*ratio);
154
160
  if (inkContext) { inkContext.setTransform(ratio,0,0,ratio,0,0); inkContext.clearRect(0,0,width,height); }
155
161
  }
@@ -240,25 +246,28 @@
240
246
  }
241
247
  function clearPreview() {
242
248
  if(inkContext)inkContext.clearRect(0,0,inkCanvas.width,inkCanvas.height);
243
- inkSvg.querySelectorAll('[data-papyrus-ink-preview]').forEach(function(path){path.remove();});
249
+ previewSvg.replaceChildren();
244
250
  }
245
251
  function createPreviewPath(x,y) {
246
252
  var path=doc.createElementNS('http://www.w3.org/2000/svg','path');
247
253
  path.setAttribute('data-papyrus-ink-preview','');path.setAttribute('d','M '+x.toFixed(1)+' '+y.toFixed(1));path.setAttribute('fill','none');
248
254
  path.setAttribute('stroke',inkConfig.color);path.setAttribute('stroke-width',String(inkStrokeWidthPx(inkConfig.strokeWidth,inkConfig.preset)));
249
255
  path.setAttribute('stroke-linecap','round');path.setAttribute('stroke-linejoin','round');path.setAttribute('opacity',String(inkConfig.opacity));
250
- path.style.pointerEvents='none';inkSvg.appendChild(path);return path;
256
+ path.style.pointerEvents='none';previewSvg.appendChild(path);return path;
251
257
  }
252
258
  function updatePreviewPath(clientX,clientY) {
253
- var bodyRect=doc.body.getBoundingClientRect(),x=clientX-bodyRect.left,y=clientY-bodyRect.top;
259
+ var x=clientX,y=clientY;
254
260
  var gesture=activeGesture;
255
- if(!gesture.previewPath||gesture.previewPathPoints>=32){
261
+ var startsSegment=!gesture.previewPath||gesture.previewPathPoints>=32;
262
+ if(startsSegment){
256
263
  gesture.previewPath=createPreviewPath(gesture.previewLast?gesture.previewLast.x:x,gesture.previewLast?gesture.previewLast.y:y);
257
264
  gesture.previewPathPoints=1;
258
265
  }
259
- var pathData=gesture.previewPath.getAttribute('d')||'';
260
- gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
261
- gesture.previewPathPoints++;
266
+ if(!startsSegment||gesture.previewLast){
267
+ var pathData=gesture.previewPath.getAttribute('d')||'';
268
+ gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
269
+ gesture.previewPathPoints++;
270
+ }
262
271
  gesture.previewLast={x:x,y:y};
263
272
  }
264
273
  function cancelGesture() {
@@ -313,7 +322,7 @@
313
322
  function pointerCancel(event) {if(activeGesture && (event.pointerId===undefined || activeGesture.pointerId===event.pointerId))cancelGesture();}
314
323
  resizeCanvas();rebuildSpatialIndex();
315
324
  inkCanvas.addEventListener('pointerdown',pointerDown);inkCanvas.addEventListener('pointermove',pointerMove);inkCanvas.addEventListener('pointerup',pointerUp);inkCanvas.addEventListener('pointercancel',pointerCancel);inkCanvas.addEventListener('lostpointercapture',pointerCancel);
316
- win.addEventListener('blur',pointerCancel);win.addEventListener('resize',resizeCanvas);
325
+ win.addEventListener('blur',pointerCancel);
317
326
  function render() {
318
327
  frame = 0; if (!alive || !options.isCurrent()) return;
319
328
  var keep = new Set(), keepInk = new Set(), noteGroups = new Map();
@@ -380,7 +389,7 @@
380
389
  win.addEventListener('resize',handleResize);win.addEventListener('scroll',schedule); doc.addEventListener('load',handleDocumentLoad,true);
381
390
  if (doc.fonts && doc.fonts.ready) doc.fonts.ready.then(function(){if(alive){rebuildSpatialIndex();schedule();}});
382
391
  schedule();
383
- return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
392
+ return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();previewSvg.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
384
393
  }
385
394
  return {validAnchor:validAnchor,simplifyPath:simplifyPath,compactGesturePoints:compactGesturePoints,densifyPath:densifyPath,createSpatialIndex:createSpatialIndex,queryNearestTextRect:queryNearestTextRect,recoverRange:recoverRange,resolveRange:resolveRange,selection:selection,install:install};
386
395
  });
@@ -20687,16 +20687,22 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20687
20687
  inkSvg.setAttribute('data-papyrus-ink-overlay','');
20688
20688
  inkSvg.style.cssText = 'position:absolute;left:0;top:0;overflow:visible;pointer-events:none;z-index:1';
20689
20689
  overlay.appendChild(inkSvg);
20690
+ var previewSvg = doc.createElementNS('http://www.w3.org/2000/svg','svg');
20691
+ previewSvg.setAttribute('data-papyrus-ink-preview-overlay','');
20692
+ previewSvg.style.cssText = 'position:fixed;left:0;top:0;overflow:hidden;pointer-events:none;z-index:2147482999';
20693
+ doc.documentElement.appendChild(previewSvg);
20690
20694
  var inkCanvas = doc.createElement('canvas');
20691
20695
  inkCanvas.dataset.papyrusInkCapture = '';
20692
20696
  inkCanvas.style.cssText = 'position:fixed;left:0;top:0;width:1px;height:1px;z-index:2147483000;background:transparent;pointer-events:none;touch-action:none';
20693
- doc.body.appendChild(inkCanvas);
20697
+ doc.documentElement.appendChild(inkCanvas);
20694
20698
  var inkContext = null; try { if(typeof win.CanvasRenderingContext2D==='function')inkContext = inkCanvas.getContext('2d'); } catch (_) {}
20695
20699
  function resizeCanvas() {
20696
- var bodyRect=doc.body.getBoundingClientRect(), ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
20697
- var width=Math.max(1,Math.min(4096,doc.body.clientWidth||bodyRect.width||Math.min(4096,win.innerWidth||1)));
20698
- var height=Math.max(1,Math.min(4096,doc.body.clientHeight||bodyRect.height||Math.min(4096,win.innerHeight||1)));
20700
+ var ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
20701
+ var width=Math.max(1,Math.min(4096,win.innerWidth||1));
20702
+ var height=Math.max(1,Math.min(4096,win.innerHeight||1));
20699
20703
  inkCanvas.style.width=width+'px';inkCanvas.style.height=height+'px';
20704
+ previewSvg.setAttribute('width',String(width));previewSvg.setAttribute('height',String(height));
20705
+ previewSvg.setAttribute('viewBox','0 0 '+width+' '+height);
20700
20706
  inkCanvas.width = Math.round(width*ratio); inkCanvas.height = Math.round(height*ratio);
20701
20707
  if (inkContext) { inkContext.setTransform(ratio,0,0,ratio,0,0); inkContext.clearRect(0,0,width,height); }
20702
20708
  }
@@ -20787,25 +20793,28 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20787
20793
  }
20788
20794
  function clearPreview() {
20789
20795
  if(inkContext)inkContext.clearRect(0,0,inkCanvas.width,inkCanvas.height);
20790
- inkSvg.querySelectorAll('[data-papyrus-ink-preview]').forEach(function(path){path.remove();});
20796
+ previewSvg.replaceChildren();
20791
20797
  }
20792
20798
  function createPreviewPath(x,y) {
20793
20799
  var path=doc.createElementNS('http://www.w3.org/2000/svg','path');
20794
20800
  path.setAttribute('data-papyrus-ink-preview','');path.setAttribute('d','M '+x.toFixed(1)+' '+y.toFixed(1));path.setAttribute('fill','none');
20795
20801
  path.setAttribute('stroke',inkConfig.color);path.setAttribute('stroke-width',String(inkStrokeWidthPx(inkConfig.strokeWidth,inkConfig.preset)));
20796
20802
  path.setAttribute('stroke-linecap','round');path.setAttribute('stroke-linejoin','round');path.setAttribute('opacity',String(inkConfig.opacity));
20797
- path.style.pointerEvents='none';inkSvg.appendChild(path);return path;
20803
+ path.style.pointerEvents='none';previewSvg.appendChild(path);return path;
20798
20804
  }
20799
20805
  function updatePreviewPath(clientX,clientY) {
20800
- var bodyRect=doc.body.getBoundingClientRect(),x=clientX-bodyRect.left,y=clientY-bodyRect.top;
20806
+ var x=clientX,y=clientY;
20801
20807
  var gesture=activeGesture;
20802
- if(!gesture.previewPath||gesture.previewPathPoints>=32){
20808
+ var startsSegment=!gesture.previewPath||gesture.previewPathPoints>=32;
20809
+ if(startsSegment){
20803
20810
  gesture.previewPath=createPreviewPath(gesture.previewLast?gesture.previewLast.x:x,gesture.previewLast?gesture.previewLast.y:y);
20804
20811
  gesture.previewPathPoints=1;
20805
20812
  }
20806
- var pathData=gesture.previewPath.getAttribute('d')||'';
20807
- gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
20808
- gesture.previewPathPoints++;
20813
+ if(!startsSegment||gesture.previewLast){
20814
+ var pathData=gesture.previewPath.getAttribute('d')||'';
20815
+ gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
20816
+ gesture.previewPathPoints++;
20817
+ }
20809
20818
  gesture.previewLast={x:x,y:y};
20810
20819
  }
20811
20820
  function cancelGesture() {
@@ -20860,7 +20869,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20860
20869
  function pointerCancel(event) {if(activeGesture && (event.pointerId===undefined || activeGesture.pointerId===event.pointerId))cancelGesture();}
20861
20870
  resizeCanvas();rebuildSpatialIndex();
20862
20871
  inkCanvas.addEventListener('pointerdown',pointerDown);inkCanvas.addEventListener('pointermove',pointerMove);inkCanvas.addEventListener('pointerup',pointerUp);inkCanvas.addEventListener('pointercancel',pointerCancel);inkCanvas.addEventListener('lostpointercapture',pointerCancel);
20863
- win.addEventListener('blur',pointerCancel);win.addEventListener('resize',resizeCanvas);
20872
+ win.addEventListener('blur',pointerCancel);
20864
20873
  function render() {
20865
20874
  frame = 0; if (!alive || !options.isCurrent()) return;
20866
20875
  var keep = new Set(), keepInk = new Set(), noteGroups = new Map();
@@ -20927,7 +20936,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20927
20936
  win.addEventListener('resize',handleResize);win.addEventListener('scroll',schedule); doc.addEventListener('load',handleDocumentLoad,true);
20928
20937
  if (doc.fonts && doc.fonts.ready) doc.fonts.ready.then(function(){if(alive){rebuildSpatialIndex();schedule();}});
20929
20938
  schedule();
20930
- return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
20939
+ return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();previewSvg.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
20931
20940
  }
20932
20941
  return {validAnchor:validAnchor,simplifyPath:simplifyPath,compactGesturePoints:compactGesturePoints,densifyPath:densifyPath,createSpatialIndex:createSpatialIndex,queryNearestTextRect:queryNearestTextRect,recoverRange:recoverRange,resolveRange:resolveRange,selection:selection,install:install};
20933
20942
  });
@@ -313,16 +313,22 @@
313
313
  inkSvg.setAttribute('data-papyrus-ink-overlay','');
314
314
  inkSvg.style.cssText = 'position:absolute;left:0;top:0;overflow:visible;pointer-events:none;z-index:1';
315
315
  overlay.appendChild(inkSvg);
316
+ var previewSvg = doc.createElementNS('http://www.w3.org/2000/svg','svg');
317
+ previewSvg.setAttribute('data-papyrus-ink-preview-overlay','');
318
+ previewSvg.style.cssText = 'position:fixed;left:0;top:0;overflow:hidden;pointer-events:none;z-index:2147482999';
319
+ doc.documentElement.appendChild(previewSvg);
316
320
  var inkCanvas = doc.createElement('canvas');
317
321
  inkCanvas.dataset.papyrusInkCapture = '';
318
322
  inkCanvas.style.cssText = 'position:fixed;left:0;top:0;width:1px;height:1px;z-index:2147483000;background:transparent;pointer-events:none;touch-action:none';
319
- doc.body.appendChild(inkCanvas);
323
+ doc.documentElement.appendChild(inkCanvas);
320
324
  var inkContext = null; try { if(typeof win.CanvasRenderingContext2D==='function')inkContext = inkCanvas.getContext('2d'); } catch (_) {}
321
325
  function resizeCanvas() {
322
- var bodyRect=doc.body.getBoundingClientRect(), ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
323
- var width=Math.max(1,Math.min(4096,doc.body.clientWidth||bodyRect.width||Math.min(4096,win.innerWidth||1)));
324
- var height=Math.max(1,Math.min(4096,doc.body.clientHeight||bodyRect.height||Math.min(4096,win.innerHeight||1)));
326
+ var ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
327
+ var width=Math.max(1,Math.min(4096,win.innerWidth||1));
328
+ var height=Math.max(1,Math.min(4096,win.innerHeight||1));
325
329
  inkCanvas.style.width=width+'px';inkCanvas.style.height=height+'px';
330
+ previewSvg.setAttribute('width',String(width));previewSvg.setAttribute('height',String(height));
331
+ previewSvg.setAttribute('viewBox','0 0 '+width+' '+height);
326
332
  inkCanvas.width = Math.round(width*ratio); inkCanvas.height = Math.round(height*ratio);
327
333
  if (inkContext) { inkContext.setTransform(ratio,0,0,ratio,0,0); inkContext.clearRect(0,0,width,height); }
328
334
  }
@@ -413,25 +419,28 @@
413
419
  }
414
420
  function clearPreview() {
415
421
  if(inkContext)inkContext.clearRect(0,0,inkCanvas.width,inkCanvas.height);
416
- inkSvg.querySelectorAll('[data-papyrus-ink-preview]').forEach(function(path){path.remove();});
422
+ previewSvg.replaceChildren();
417
423
  }
418
424
  function createPreviewPath(x,y) {
419
425
  var path=doc.createElementNS('http://www.w3.org/2000/svg','path');
420
426
  path.setAttribute('data-papyrus-ink-preview','');path.setAttribute('d','M '+x.toFixed(1)+' '+y.toFixed(1));path.setAttribute('fill','none');
421
427
  path.setAttribute('stroke',inkConfig.color);path.setAttribute('stroke-width',String(inkStrokeWidthPx(inkConfig.strokeWidth,inkConfig.preset)));
422
428
  path.setAttribute('stroke-linecap','round');path.setAttribute('stroke-linejoin','round');path.setAttribute('opacity',String(inkConfig.opacity));
423
- path.style.pointerEvents='none';inkSvg.appendChild(path);return path;
429
+ path.style.pointerEvents='none';previewSvg.appendChild(path);return path;
424
430
  }
425
431
  function updatePreviewPath(clientX,clientY) {
426
- var bodyRect=doc.body.getBoundingClientRect(),x=clientX-bodyRect.left,y=clientY-bodyRect.top;
432
+ var x=clientX,y=clientY;
427
433
  var gesture=activeGesture;
428
- if(!gesture.previewPath||gesture.previewPathPoints>=32){
434
+ var startsSegment=!gesture.previewPath||gesture.previewPathPoints>=32;
435
+ if(startsSegment){
429
436
  gesture.previewPath=createPreviewPath(gesture.previewLast?gesture.previewLast.x:x,gesture.previewLast?gesture.previewLast.y:y);
430
437
  gesture.previewPathPoints=1;
431
438
  }
432
- var pathData=gesture.previewPath.getAttribute('d')||'';
433
- gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
434
- gesture.previewPathPoints++;
439
+ if(!startsSegment||gesture.previewLast){
440
+ var pathData=gesture.previewPath.getAttribute('d')||'';
441
+ gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
442
+ gesture.previewPathPoints++;
443
+ }
435
444
  gesture.previewLast={x:x,y:y};
436
445
  }
437
446
  function cancelGesture() {
@@ -486,7 +495,7 @@
486
495
  function pointerCancel(event) {if(activeGesture && (event.pointerId===undefined || activeGesture.pointerId===event.pointerId))cancelGesture();}
487
496
  resizeCanvas();rebuildSpatialIndex();
488
497
  inkCanvas.addEventListener('pointerdown',pointerDown);inkCanvas.addEventListener('pointermove',pointerMove);inkCanvas.addEventListener('pointerup',pointerUp);inkCanvas.addEventListener('pointercancel',pointerCancel);inkCanvas.addEventListener('lostpointercapture',pointerCancel);
489
- win.addEventListener('blur',pointerCancel);win.addEventListener('resize',resizeCanvas);
498
+ win.addEventListener('blur',pointerCancel);
490
499
  function render() {
491
500
  frame = 0; if (!alive || !options.isCurrent()) return;
492
501
  var keep = new Set(), keepInk = new Set(), noteGroups = new Map();
@@ -553,7 +562,7 @@
553
562
  win.addEventListener('resize',handleResize);win.addEventListener('scroll',schedule); doc.addEventListener('load',handleDocumentLoad,true);
554
563
  if (doc.fonts && doc.fonts.ready) doc.fonts.ready.then(function(){if(alive){rebuildSpatialIndex();schedule();}});
555
564
  schedule();
556
- return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
565
+ return {schedule:schedule, setInkMode:function(config){var preset=['ink','highlight','underline'].indexOf(config?.preset)>=0?config.preset:'ink';inkConfig={enabled:!!config?.enabled,preset:preset,color:/^#[0-9a-f]{6}$/i.test(config?.color)?config.color:'#2563eb',opacity:Number.isFinite(config?.opacity)?Math.max(0,Math.min(1,config.opacity)):1,strokeWidth:Number.isFinite(config?.strokeWidth)?Math.max(0.0025,Math.min(0.02,config.strokeWidth)):0.006};inkCanvas.style.pointerEvents=inkConfig.enabled?'auto':'none';if(!inkConfig.enabled)cancelGesture();}, invalidateLayout:rebuildAndSchedule, hit:function(x,y){return hitRegions.some(function(item){return item.rects.some(function(r){return x>=r.left && x<=r.right && y>=r.top && y<=r.bottom;});});}, range:function(anchor){return resolveRange(contents,anchor);}, destroy:function(){alive=false;cancelGesture();if(frame)win.cancelAnimationFrame(frame);if(observer)observer.disconnect();win.removeEventListener('resize',handleResize);win.removeEventListener('scroll',schedule);win.removeEventListener('blur',pointerCancel);doc.removeEventListener('load',handleDocumentLoad,true);doc.removeEventListener('click',tapMarkup);inkCanvas.removeEventListener('pointerdown',pointerDown);inkCanvas.removeEventListener('pointermove',pointerMove);inkCanvas.removeEventListener('pointerup',pointerUp);inkCanvas.removeEventListener('pointercancel',pointerCancel);inkCanvas.removeEventListener('lostpointercapture',pointerCancel);inkCanvas.remove();previewSvg.remove();overlay.remove();doc.body.style.position=originalPosition;registry.clear();inkRegistry.clear();rangeCache.clear();}};
557
566
  }
558
567
  return {validAnchor:validAnchor,simplifyPath:simplifyPath,compactGesturePoints:compactGesturePoints,densifyPath:densifyPath,createSpatialIndex:createSpatialIndex,queryNearestTextRect:queryNearestTextRect,recoverRange:recoverRange,resolveRange:resolveRange,selection:selection,install:install};
559
568
  });