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