@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/dist/index.js CHANGED
@@ -20721,16 +20721,22 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20721
20721
  inkSvg.setAttribute('data-papyrus-ink-overlay','');
20722
20722
  inkSvg.style.cssText = 'position:absolute;left:0;top:0;overflow:visible;pointer-events:none;z-index:1';
20723
20723
  overlay.appendChild(inkSvg);
20724
+ var previewSvg = doc.createElementNS('http://www.w3.org/2000/svg','svg');
20725
+ previewSvg.setAttribute('data-papyrus-ink-preview-overlay','');
20726
+ previewSvg.style.cssText = 'position:fixed;left:0;top:0;overflow:hidden;pointer-events:none;z-index:2147482999';
20727
+ doc.documentElement.appendChild(previewSvg);
20724
20728
  var inkCanvas = doc.createElement('canvas');
20725
20729
  inkCanvas.dataset.papyrusInkCapture = '';
20726
20730
  inkCanvas.style.cssText = 'position:fixed;left:0;top:0;width:1px;height:1px;z-index:2147483000;background:transparent;pointer-events:none;touch-action:none';
20727
- doc.body.appendChild(inkCanvas);
20731
+ doc.documentElement.appendChild(inkCanvas);
20728
20732
  var inkContext = null; try { if(typeof win.CanvasRenderingContext2D==='function')inkContext = inkCanvas.getContext('2d'); } catch (_) {}
20729
20733
  function resizeCanvas() {
20730
- var bodyRect=doc.body.getBoundingClientRect(), ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
20731
- var width=Math.max(1,Math.min(4096,doc.body.clientWidth||bodyRect.width||Math.min(4096,win.innerWidth||1)));
20732
- var height=Math.max(1,Math.min(4096,doc.body.clientHeight||bodyRect.height||Math.min(4096,win.innerHeight||1)));
20734
+ var ratio = Math.max(1,Math.min(3,win.devicePixelRatio || 1));
20735
+ var width=Math.max(1,Math.min(4096,win.innerWidth||1));
20736
+ var height=Math.max(1,Math.min(4096,win.innerHeight||1));
20733
20737
  inkCanvas.style.width=width+'px';inkCanvas.style.height=height+'px';
20738
+ previewSvg.setAttribute('width',String(width));previewSvg.setAttribute('height',String(height));
20739
+ previewSvg.setAttribute('viewBox','0 0 '+width+' '+height);
20734
20740
  inkCanvas.width = Math.round(width*ratio); inkCanvas.height = Math.round(height*ratio);
20735
20741
  if (inkContext) { inkContext.setTransform(ratio,0,0,ratio,0,0); inkContext.clearRect(0,0,width,height); }
20736
20742
  }
@@ -20821,25 +20827,28 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20821
20827
  }
20822
20828
  function clearPreview() {
20823
20829
  if(inkContext)inkContext.clearRect(0,0,inkCanvas.width,inkCanvas.height);
20824
- inkSvg.querySelectorAll('[data-papyrus-ink-preview]').forEach(function(path){path.remove();});
20830
+ previewSvg.replaceChildren();
20825
20831
  }
20826
20832
  function createPreviewPath(x,y) {
20827
20833
  var path=doc.createElementNS('http://www.w3.org/2000/svg','path');
20828
20834
  path.setAttribute('data-papyrus-ink-preview','');path.setAttribute('d','M '+x.toFixed(1)+' '+y.toFixed(1));path.setAttribute('fill','none');
20829
20835
  path.setAttribute('stroke',inkConfig.color);path.setAttribute('stroke-width',String(inkStrokeWidthPx(inkConfig.strokeWidth,inkConfig.preset)));
20830
20836
  path.setAttribute('stroke-linecap','round');path.setAttribute('stroke-linejoin','round');path.setAttribute('opacity',String(inkConfig.opacity));
20831
- path.style.pointerEvents='none';inkSvg.appendChild(path);return path;
20837
+ path.style.pointerEvents='none';previewSvg.appendChild(path);return path;
20832
20838
  }
20833
20839
  function updatePreviewPath(clientX,clientY) {
20834
- var bodyRect=doc.body.getBoundingClientRect(),x=clientX-bodyRect.left,y=clientY-bodyRect.top;
20840
+ var x=clientX,y=clientY;
20835
20841
  var gesture=activeGesture;
20836
- if(!gesture.previewPath||gesture.previewPathPoints>=32){
20842
+ var startsSegment=!gesture.previewPath||gesture.previewPathPoints>=32;
20843
+ if(startsSegment){
20837
20844
  gesture.previewPath=createPreviewPath(gesture.previewLast?gesture.previewLast.x:x,gesture.previewLast?gesture.previewLast.y:y);
20838
20845
  gesture.previewPathPoints=1;
20839
20846
  }
20840
- var pathData=gesture.previewPath.getAttribute('d')||'';
20841
- gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
20842
- gesture.previewPathPoints++;
20847
+ if(!startsSegment||gesture.previewLast){
20848
+ var pathData=gesture.previewPath.getAttribute('d')||'';
20849
+ gesture.previewPath.setAttribute('d',pathData+' L '+x.toFixed(1)+' '+y.toFixed(1));
20850
+ gesture.previewPathPoints++;
20851
+ }
20843
20852
  gesture.previewLast={x:x,y:y};
20844
20853
  }
20845
20854
  function cancelGesture() {
@@ -20894,7 +20903,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20894
20903
  function pointerCancel(event) {if(activeGesture && (event.pointerId===undefined || activeGesture.pointerId===event.pointerId))cancelGesture();}
20895
20904
  resizeCanvas();rebuildSpatialIndex();
20896
20905
  inkCanvas.addEventListener('pointerdown',pointerDown);inkCanvas.addEventListener('pointermove',pointerMove);inkCanvas.addEventListener('pointerup',pointerUp);inkCanvas.addEventListener('pointercancel',pointerCancel);inkCanvas.addEventListener('lostpointercapture',pointerCancel);
20897
- win.addEventListener('blur',pointerCancel);win.addEventListener('resize',resizeCanvas);
20906
+ win.addEventListener('blur',pointerCancel);
20898
20907
  function render() {
20899
20908
  frame = 0; if (!alive || !options.isCurrent()) return;
20900
20909
  var keep = new Set(), keepInk = new Set(), noteGroups = new Map();
@@ -20961,7 +20970,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
20961
20970
  win.addEventListener('resize',handleResize);win.addEventListener('scroll',schedule); doc.addEventListener('load',handleDocumentLoad,true);
20962
20971
  if (doc.fonts && doc.fonts.ready) doc.fonts.ready.then(function(){if(alive){rebuildSpatialIndex();schedule();}});
20963
20972
  schedule();
20964
- 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();}};
20973
+ 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();}};
20965
20974
  }
20966
20975
  return {validAnchor:validAnchor,simplifyPath:simplifyPath,compactGesturePoints:compactGesturePoints,densifyPath:densifyPath,createSpatialIndex:createSpatialIndex,queryNearestTextRect:queryNearestTextRect,recoverRange:recoverRange,resolveRange:resolveRange,selection:selection,install:install};
20967
20976
  });