New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

y-textarea

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-textarea - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

0

dist/y-textArea-Cursors.d.ts

@@ -0,0 +0,0 @@ import { options } from './y-textarea-options';

@@ -0,0 +0,0 @@ import * as awarenessProtocol from 'y-protocols/awareness.js';

@@ -0,0 +0,0 @@ import { options } from './y-textarea-options';

22

dist/y-textArea.es.js

@@ -928,13 +928,15 @@ var __defProp = Object.defineProperty;

let pos = 0;
for (let i = 0; i < diffs.length; i++) {
let d = diffs[i];
if (d[0] === 0) {
pos += d[1].length;
} else if (d[0] === -1) {
yText.delete(pos, d[1].length);
} else {
yText.insert(pos, d[1]);
pos += d[1].length;
doc.transact((_) => {
for (let i = 0; i < diffs.length; i++) {
let d = diffs[i];
if (d[0] === 0) {
pos += d[1].length;
} else if (d[0] === -1) {
yText.delete(pos, d[1].length);
} else {
yText.insert(pos, d[1]);
pos += d[1].length;
}
}
}
});
};

@@ -941,0 +943,0 @@ textField.addEventListener("input", onTextFieldInput);

@@ -1,1 +0,1 @@

var se=Object.defineProperty;var oe=(D,P,O)=>P in D?se(D,P,{enumerable:!0,configurable:!0,writable:!0,value:O}):D[P]=O;var E=(D,P,O)=>(oe(D,typeof P!="symbol"?P+"":P,O),O);(function(D,P){typeof exports=="object"&&typeof module!="undefined"?P(exports,require("yjs")):typeof define=="function"&&define.amd?define(["exports","yjs"],P):(D=typeof globalThis!="undefined"?globalThis:D||self,P(D["y-textArea"]={},D.Y))})(this,function(D,P){"use strict";function O(n){if(n&&n.__esModule)return n;var t={__proto__:null,[Symbol.toStringTag]:"Module"};return n&&Object.keys(n).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return n[e]}})}}),t.default=n,Object.freeze(t)}var L=O(P),F={exports:{}};(function(n){(function(){var t=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],e=typeof window!="undefined",i=e&&window.mozInnerScreenX!=null;function s(r,o,a){if(!e)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");var l=a&&a.debug||!1;if(l){var h=document.querySelector("#input-textarea-caret-position-mirror-div");h&&h.parentNode.removeChild(h)}var u=document.createElement("div");u.id="input-textarea-caret-position-mirror-div",document.body.appendChild(u);var c=u.style,v=window.getComputedStyle?window.getComputedStyle(r):r.currentStyle,_=r.nodeName==="INPUT";c.whiteSpace="pre-wrap",_||(c.wordWrap="break-word"),c.position="absolute",l||(c.visibility="hidden"),t.forEach(function(p){_&&p==="lineHeight"?c.lineHeight=v.height:c[p]=v[p]}),i?r.scrollHeight>parseInt(v.height)&&(c.overflowY="scroll"):c.overflow="hidden",u.textContent=r.value.substring(0,o),_&&(u.textContent=u.textContent.replace(/\s/g,"\xA0"));var d=document.createElement("span");d.textContent=r.value.substring(o)||".",u.appendChild(d);var m={top:d.offsetTop+parseInt(v.borderTopWidth),left:d.offsetLeft+parseInt(v.borderLeftWidth),height:parseInt(v.lineHeight)};return l?d.style.backgroundColor="#aaa":document.body.removeChild(u),m}n.exports=s})()})(F);var N=F.exports;function Q(n,t){const e=Math.max(n.x,t.x),i=Math.min(n.x+n.width,t.x+t.width);if(i<e)return null;const s=Math.max(n.y,t.y),r=Math.min(n.y+n.height,t.y+t.height);return r<s?null:new V(e,s,i-e,r-s)}class V{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}get area(){return this.width*this.height}}var G=Q;const K=["keyup","mouseup","touchstart","paste","cut","selectend"];class Z{constructor(t,e,i,s){E(this,"_div");E(this,"_nameDiv");E(this,"_color");E(this,"_fontSize");E(this,"_selectedIndex");E(this,"_name");E(this,"_parent");this._selectedIndex={start:-1,end:-1},this._fontSize=t,this._parent=i.offsetParent||document.body,this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.height=t,this._div.style.width="1px",this._div.style.display="none",this._div.classList.add("selectedText"),this._parent.appendChild(this._div),s!==void 0&&this.updateCursor(s,e)}show(){this._div.style.display="block",this._nameDiv&&(this._nameDiv.style.display="block")}hide(){this._div.style.display="none",this._nameDiv&&(this._nameDiv.style.display="none")}updateCursor(t,e){this._name===t&&this._color.r===e.r&&this._color.g===e.g&&this._color.b===e.b||(this._color=e,this._name=t,this._nameDiv||(this._nameDiv=document.createElement("div"),this._nameDiv.style.position="absolute",this._nameDiv.style.display="none",this._nameDiv.classList.add("nameTag"),this._parent.appendChild(this._nameDiv)),this._nameDiv.innerText=t,this._nameDiv.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`,this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`)}setPosition(t,e){this._selectedIndex={start:t,end:e}}setWidth(t){this._div.style.width=t+"px",t===1?this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`:this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`}rePosition(t){if(this._selectedIndex.start===-1||this._selectedIndex.end===-1)return;const e=N(t,this._selectedIndex.start),i=t.offsetTop-t.scrollTop+e.top,s=t.offsetLeft-t.scrollLeft+e.left;let r=1,o=0;if(this._selectedIndex.start!==this._selectedIndex.end){let u=N(t,this._selectedIndex.end);r=u.left-e.left,o=u.top-e.top,o!==0&&(r=1)}const a={x:t.offsetLeft,y:t.offsetTop,width:t.clientWidth,height:t.clientHeight},l={x:s,y:i,width:r,height:parseInt(this._fontSize)},h=G(a,l);if(!h){this.hide();return}this._div.style.top=h.y+"px",this._div.style.left=h.x+"px",this.setWidth(h.width),this.show(),this._nameDiv&&(this._nameDiv.style.top=h.y+parseInt(this._fontSize)+"px",this._nameDiv.style.left=h.x+"px")}destroy(){this._parent.removeChild(this._div),this._nameDiv&&this._parent.removeChild(this._nameDiv)}}class q{constructor(t,e,i){E(this,"_unobserveFns",[]);E(this,"_cursors",new Map);E(this,"_areaID","");E(this,"_textField");if(this._areaID=e.id,this._textField=e,e.id==="")throw new Error("ID attribute is required on textarea/field if using cursors");if(e.selectionStart===null||e.selectionEnd===null)throw new Error("unSupported Input type");const s=t.doc;if(s===null)throw new Error("Missing doc on yText");const r=h=>{if(h.removed.length!=0){for(const v of h.removed)if(this._cursors.has(v)){const _=this._cursors.get(v);_==null||_.destroy(),this._cursors.delete(v)}}const u=getComputedStyle(e).getPropertyValue("font-size"),c=i.awareness.getStates();for(const[v,_]of c.entries()){if(v===i.awareness.clientID)continue;const d=_[this._areaID];if(d===void 0)continue;const m=d.start,p=d.end,b=d.name,f=d.color,w=d.selection;if(!this._cursors.has(v)&&!w)continue;this._cursors.has(v)||this._cursors.set(v,new Z(u,f,e,b));const g=this._cursors.get(v);if(!w){g==null||g.setPosition(-1,-1),g==null||g.hide();continue}if(g==null||g.updateCursor(b,f),m===void 0||p===void 0)continue;const S=L.createAbsolutePositionFromRelativePosition(JSON.parse(m),s),y=L.createAbsolutePositionFromRelativePosition(JSON.parse(p),s);if(S===null||y===null){g==null||g.hide();continue}g==null||g.setPosition(S.index,y.index),g==null||g.rePosition(e)}};i.awareness.on("update",r),this._unobserveFns.push(()=>i.awareness.off("update",r));const o=()=>{const h=e.selectionStart,u=e.selectionEnd,c=L.createRelativePositionFromTypeIndex(t,h),v=L.createRelativePositionFromTypeIndex(t,u);i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!0,start:JSON.stringify(c),end:JSON.stringify(v),name:i.clientName,color:i.color||{r:45,g:80,b:237}})};for(const h of K)e.addEventListener(h,o),this._unobserveFns.push(()=>{e.removeEventListener(h,o)});const a=()=>{i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!1})};e.addEventListener("focusout",a),this._unobserveFns.push(()=>{e.removeEventListener("focusout",a)});const l=()=>{this.rePositionCursors()};e.addEventListener("scroll",l),this._unobserveFns.push(()=>{e.removeEventListener("scroll",l)})}rePositionCursors(){if(this._textField)for(const[t,e]of this._cursors)e.rePosition(this._textField)}destroy(){for(const t of this._unobserveFns)t();this._unobserveFns=[];for(const[t,e]of this._cursors)e.destroy();this._cursors.clear()}}var A=-1,R=1,I=0;function z(n,t,e,i){if(n===t)return n?[[I,n]]:[];if(e!=null){var s=te(n,t,e);if(s)return s}var r=$(n,t),o=n.substring(0,r);n=n.substring(r),t=t.substring(r),r=W(n,t);var a=n.substring(n.length-r);n=n.substring(0,n.length-r),t=t.substring(0,t.length-r);var l=k(n,t);return o&&l.unshift([I,o]),a&&l.push([I,a]),Y(l,i),l}function k(n,t){var e;if(!n)return[[R,t]];if(!t)return[[A,n]];var i=n.length>t.length?n:t,s=n.length>t.length?t:n,r=i.indexOf(s);if(r!==-1)return e=[[R,i.substring(0,r)],[I,s],[R,i.substring(r+s.length)]],n.length>t.length&&(e[0][0]=e[2][0]=A),e;if(s.length===1)return[[A,n],[R,t]];var o=ee(n,t);if(o){var a=o[0],l=o[1],h=o[2],u=o[3],c=o[4],v=z(a,h),_=z(l,u);return v.concat([[I,c]],_)}return x(n,t)}function x(n,t){for(var e=n.length,i=t.length,s=Math.ceil((e+i)/2),r=s,o=2*s,a=new Array(o),l=new Array(o),h=0;h<o;h++)a[h]=-1,l[h]=-1;a[r+1]=0,l[r+1]=0;for(var u=e-i,c=u%2!==0,v=0,_=0,d=0,m=0,p=0;p<s;p++){for(var b=-p+v;b<=p-_;b+=2){var f=r+b,w;b===-p||b!==p&&a[f-1]<a[f+1]?w=a[f+1]:w=a[f-1]+1;for(var g=w-b;w<e&&g<i&&n.charAt(w)===t.charAt(g);)w++,g++;if(a[f]=w,w>e)_+=2;else if(g>i)v+=2;else if(c){var S=r+u-b;if(S>=0&&S<o&&l[S]!==-1){var y=e-l[S];if(w>=y)return H(n,t,w,g)}}}for(var C=-p+d;C<=p-m;C+=2){var S=r+C,y;C===-p||C!==p&&l[S-1]<l[S+1]?y=l[S+1]:y=l[S-1]+1;for(var M=y-C;y<e&&M<i&&n.charAt(e-y-1)===t.charAt(i-M-1);)y++,M++;if(l[S]=y,y>e)m+=2;else if(M>i)d+=2;else if(!c){var f=r+u-C;if(f>=0&&f<o&&a[f]!==-1){var w=a[f],g=r+w-f;if(y=e-y,w>=y)return H(n,t,w,g)}}}}return[[A,n],[R,t]]}function H(n,t,e,i){var s=n.substring(0,e),r=t.substring(0,i),o=n.substring(e),a=t.substring(i),l=z(s,r),h=z(o,a);return l.concat(h)}function $(n,t){if(!n||!t||n.charAt(0)!==t.charAt(0))return 0;for(var e=0,i=Math.min(n.length,t.length),s=i,r=0;e<s;)n.substring(r,s)==t.substring(r,s)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return B(n.charCodeAt(s-1))&&s--,s}function W(n,t){if(!n||!t||n.slice(-1)!==t.slice(-1))return 0;for(var e=0,i=Math.min(n.length,t.length),s=i,r=0;e<s;)n.substring(n.length-s,n.length-r)==t.substring(t.length-s,t.length-r)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return J(n.charCodeAt(n.length-s))&&s--,s}function ee(n,t){var e=n.length>t.length?n:t,i=n.length>t.length?t:n;if(e.length<4||i.length*2<e.length)return null;function s(_,d,m){for(var p=_.substring(m,m+Math.floor(_.length/4)),b=-1,f="",w,g,S,y;(b=d.indexOf(p,b+1))!==-1;){var C=$(_.substring(m),d.substring(b)),M=W(_.substring(0,m),d.substring(0,b));f.length<M+C&&(f=d.substring(b-M,b)+d.substring(b,b+C),w=_.substring(0,m-M),g=_.substring(m+C),S=d.substring(0,b-M),y=d.substring(b+C))}return f.length*2>=_.length?[w,g,S,y,f]:null}var r=s(e,i,Math.ceil(e.length/4)),o=s(e,i,Math.ceil(e.length/2)),a;if(!r&&!o)return null;o?r?a=r[4].length>o[4].length?r:o:a=o:a=r;var l,h,u,c;n.length>t.length?(l=a[0],h=a[1],u=a[2],c=a[3]):(u=a[0],c=a[1],l=a[2],h=a[3]);var v=a[4];return[l,h,u,c,v]}function Y(n,t){n.push([I,""]);for(var e=0,i=0,s=0,r="",o="",a;e<n.length;){if(e<n.length-1&&!n[e][1]){n.splice(e,1);continue}switch(n[e][0]){case R:s++,o+=n[e][1],e++;break;case A:i++,r+=n[e][1],e++;break;case I:var l=e-s-i-1;if(t){if(l>=0&&X(n[l][1])){var h=n[l][1].slice(-1);if(n[l][1]=n[l][1].slice(0,-1),r=h+r,o=h+o,!n[l][1]){n.splice(l,1),e--;var u=l-1;n[u]&&n[u][0]===R&&(s++,o=n[u][1]+o,u--),n[u]&&n[u][0]===A&&(i++,r=n[u][1]+r,u--),l=u}}if(U(n[e][1])){var h=n[e][1].charAt(0);n[e][1]=n[e][1].slice(1),r+=h,o+=h}}if(e<n.length-1&&!n[e][1]){n.splice(e,1);break}if(r.length>0||o.length>0){r.length>0&&o.length>0&&(a=$(o,r),a!==0&&(l>=0?n[l][1]+=o.substring(0,a):(n.splice(0,0,[I,o.substring(0,a)]),e++),o=o.substring(a),r=r.substring(a)),a=W(o,r),a!==0&&(n[e][1]=o.substring(o.length-a)+n[e][1],o=o.substring(0,o.length-a),r=r.substring(0,r.length-a)));var c=s+i;r.length===0&&o.length===0?(n.splice(e-c,c),e=e-c):r.length===0?(n.splice(e-c,c,[R,o]),e=e-c+1):o.length===0?(n.splice(e-c,c,[A,r]),e=e-c+1):(n.splice(e-c,c,[A,r],[R,o]),e=e-c+2)}e!==0&&n[e-1][0]===I?(n[e-1][1]+=n[e][1],n.splice(e,1)):e++,s=0,i=0,r="",o="";break}}n[n.length-1][1]===""&&n.pop();var v=!1;for(e=1;e<n.length-1;)n[e-1][0]===I&&n[e+1][0]===I&&(n[e][1].substring(n[e][1].length-n[e-1][1].length)===n[e-1][1]?(n[e][1]=n[e-1][1]+n[e][1].substring(0,n[e][1].length-n[e-1][1].length),n[e+1][1]=n[e-1][1]+n[e+1][1],n.splice(e-1,1),v=!0):n[e][1].substring(0,n[e+1][1].length)==n[e+1][1]&&(n[e-1][1]+=n[e+1][1],n[e][1]=n[e][1].substring(n[e+1][1].length)+n[e+1][1],n.splice(e+1,1),v=!0)),e++;v&&Y(n,t)}function B(n){return n>=55296&&n<=56319}function J(n){return n>=56320&&n<=57343}function U(n){return J(n.charCodeAt(0))}function X(n){return B(n.charCodeAt(n.length-1))}function ne(n){for(var t=[],e=0;e<n.length;e++)n[e][1].length>0&&t.push(n[e]);return t}function j(n,t,e,i){return X(n)||U(i)?null:ne([[I,n],[A,t],[R,e],[I,i]])}function te(n,t,e){var i=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,r=n.length,o=t.length;if(i.length===0&&(s===null||s.length===0)){var a=i.index,l=n.slice(0,a),h=n.slice(a),u=s?s.index:null;e:{var c=a+o-r;if(u!==null&&u!==c||c<0||c>o)break e;var v=t.slice(0,c),_=t.slice(c);if(_!==h)break e;var d=Math.min(a,c),m=l.slice(0,d),p=v.slice(0,d);if(m!==p)break e;var b=l.slice(d),f=v.slice(d);return j(m,b,f,h)}e:{if(u!==null&&u!==a)break e;var w=a,v=t.slice(0,w),_=t.slice(w);if(v!==l)break e;var g=Math.min(r-w,o-w),S=h.slice(h.length-g),y=_.slice(_.length-g);if(S!==y)break e;var b=h.slice(0,h.length-g),f=_.slice(0,_.length-g);return j(l,b,f,S)}}if(i.length>0&&s&&s.length===0){e:{var m=n.slice(0,i.index),S=n.slice(i.index+i.length),d=m.length,g=S.length;if(o<d+g)break e;var p=t.slice(0,d),y=t.slice(o-g);if(m!==p||S!==y)break e;var b=n.slice(d,r-g),f=t.slice(d,o-g);return j(m,b,f,S)}}return null}function T(n,t,e){return z(n,t,e,!0)}T.INSERT=R,T.DELETE=A,T.EQUAL=I;var re=T;class ie{constructor(t,e,i){E(this,"_cursors");E(this,"_unobserveFns",[]);let s=t.doc;if(s===null)throw new Error("Missing doc on yText");if(e.selectionStart===void 0||e.selectionEnd===void 0)throw new Error("textField argument doesn't look like a text field");i&&(this._cursors=new q(t,e,i)),e.value=t.toString();let r,o,a;const l=()=>{a=e.selectionDirection;const v=this.createRange(e);r=L.createRelativePositionFromTypeIndex(t,v.left),o=L.createRelativePositionFromTypeIndex(t,v.right)};s.on("beforeTransaction",l),this._unobserveFns.push(()=>s.off("beforeTransaction",l));let h=!1;const u=(v,_)=>{if(_.local&&h){h=!1;return}if(e.value=t.toString(),e.getRootNode().activeElement===e){const d=L.createAbsolutePositionFromRelativePosition(r,s),m=L.createAbsolutePositionFromRelativePosition(o,s);d!==null&&m!==null&&(a===null&&(a="forward"),e.setSelectionRange(d.index,m.index,a))}};t.observe(u),this._unobserveFns.push(()=>t.unobserve(u));const c=()=>{h=!0;const v=this.createRange(e);let _=t.toString(),d=e.value,m=re(_,d,v.left),p=0;for(let b=0;b<m.length;b++){let f=m[b];f[0]===0?p+=f[1].length:f[0]===-1?t.delete(p,f[1].length):(t.insert(p,f[1]),p+=f[1].length)}};e.addEventListener("input",c),this._unobserveFns.push(()=>e.removeEventListener("input",c))}createRange(t){const e=t.selectionStart,i=t.selectionEnd;return{left:e,right:i}}rePositionCursors(){var t;(t=this._cursors)==null||t.rePositionCursors()}destroy(){for(const t of this._unobserveFns)t();this._unobserveFns=[],this._cursors&&this._cursors.destroy()}}D.TextAreaBinding=ie,Object.defineProperty(D,"__esModule",{value:!0}),D[Symbol.toStringTag]="Module"});
var se=Object.defineProperty;var oe=(D,P,O)=>P in D?se(D,P,{enumerable:!0,configurable:!0,writable:!0,value:O}):D[P]=O;var E=(D,P,O)=>(oe(D,typeof P!="symbol"?P+"":P,O),O);(function(D,P){typeof exports=="object"&&typeof module!="undefined"?P(exports,require("yjs")):typeof define=="function"&&define.amd?define(["exports","yjs"],P):(D=typeof globalThis!="undefined"?globalThis:D||self,P(D["y-textArea"]={},D.Y))})(this,function(D,P){"use strict";function O(n){if(n&&n.__esModule)return n;var t={__proto__:null,[Symbol.toStringTag]:"Module"};return n&&Object.keys(n).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return n[e]}})}}),t.default=n,Object.freeze(t)}var L=O(P),F={exports:{}};(function(n){(function(){var t=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],e=typeof window!="undefined",i=e&&window.mozInnerScreenX!=null;function s(r,o,a){if(!e)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");var l=a&&a.debug||!1;if(l){var h=document.querySelector("#input-textarea-caret-position-mirror-div");h&&h.parentNode.removeChild(h)}var u=document.createElement("div");u.id="input-textarea-caret-position-mirror-div",document.body.appendChild(u);var c=u.style,v=window.getComputedStyle?window.getComputedStyle(r):r.currentStyle,_=r.nodeName==="INPUT";c.whiteSpace="pre-wrap",_||(c.wordWrap="break-word"),c.position="absolute",l||(c.visibility="hidden"),t.forEach(function(p){_&&p==="lineHeight"?c.lineHeight=v.height:c[p]=v[p]}),i?r.scrollHeight>parseInt(v.height)&&(c.overflowY="scroll"):c.overflow="hidden",u.textContent=r.value.substring(0,o),_&&(u.textContent=u.textContent.replace(/\s/g,"\xA0"));var d=document.createElement("span");d.textContent=r.value.substring(o)||".",u.appendChild(d);var w={top:d.offsetTop+parseInt(v.borderTopWidth),left:d.offsetLeft+parseInt(v.borderLeftWidth),height:parseInt(v.lineHeight)};return l?d.style.backgroundColor="#aaa":document.body.removeChild(u),w}n.exports=s})()})(F);var N=F.exports;function Q(n,t){const e=Math.max(n.x,t.x),i=Math.min(n.x+n.width,t.x+t.width);if(i<e)return null;const s=Math.max(n.y,t.y),r=Math.min(n.y+n.height,t.y+t.height);return r<s?null:new V(e,s,i-e,r-s)}class V{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}get area(){return this.width*this.height}}var G=Q;const K=["keyup","mouseup","touchstart","paste","cut","selectend"];class Z{constructor(t,e,i,s){E(this,"_div");E(this,"_nameDiv");E(this,"_color");E(this,"_fontSize");E(this,"_selectedIndex");E(this,"_name");E(this,"_parent");this._selectedIndex={start:-1,end:-1},this._fontSize=t,this._parent=i.offsetParent||document.body,this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.height=t,this._div.style.width="1px",this._div.style.display="none",this._div.classList.add("selectedText"),this._parent.appendChild(this._div),s!==void 0&&this.updateCursor(s,e)}show(){this._div.style.display="block",this._nameDiv&&(this._nameDiv.style.display="block")}hide(){this._div.style.display="none",this._nameDiv&&(this._nameDiv.style.display="none")}updateCursor(t,e){this._name===t&&this._color.r===e.r&&this._color.g===e.g&&this._color.b===e.b||(this._color=e,this._name=t,this._nameDiv||(this._nameDiv=document.createElement("div"),this._nameDiv.style.position="absolute",this._nameDiv.style.display="none",this._nameDiv.classList.add("nameTag"),this._parent.appendChild(this._nameDiv)),this._nameDiv.innerText=t,this._nameDiv.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`,this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`)}setPosition(t,e){this._selectedIndex={start:t,end:e}}setWidth(t){this._div.style.width=t+"px",t===1?this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`:this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`}rePosition(t){if(this._selectedIndex.start===-1||this._selectedIndex.end===-1)return;const e=N(t,this._selectedIndex.start),i=t.offsetTop-t.scrollTop+e.top,s=t.offsetLeft-t.scrollLeft+e.left;let r=1,o=0;if(this._selectedIndex.start!==this._selectedIndex.end){let u=N(t,this._selectedIndex.end);r=u.left-e.left,o=u.top-e.top,o!==0&&(r=1)}const a={x:t.offsetLeft,y:t.offsetTop,width:t.clientWidth,height:t.clientHeight},l={x:s,y:i,width:r,height:parseInt(this._fontSize)},h=G(a,l);if(!h){this.hide();return}this._div.style.top=h.y+"px",this._div.style.left=h.x+"px",this.setWidth(h.width),this.show(),this._nameDiv&&(this._nameDiv.style.top=h.y+parseInt(this._fontSize)+"px",this._nameDiv.style.left=h.x+"px")}destroy(){this._parent.removeChild(this._div),this._nameDiv&&this._parent.removeChild(this._nameDiv)}}class q{constructor(t,e,i){E(this,"_unobserveFns",[]);E(this,"_cursors",new Map);E(this,"_areaID","");E(this,"_textField");if(this._areaID=e.id,this._textField=e,e.id==="")throw new Error("ID attribute is required on textarea/field if using cursors");if(e.selectionStart===null||e.selectionEnd===null)throw new Error("unSupported Input type");const s=t.doc;if(s===null)throw new Error("Missing doc on yText");const r=h=>{if(h.removed.length!=0){for(const v of h.removed)if(this._cursors.has(v)){const _=this._cursors.get(v);_==null||_.destroy(),this._cursors.delete(v)}}const u=getComputedStyle(e).getPropertyValue("font-size"),c=i.awareness.getStates();for(const[v,_]of c.entries()){if(v===i.awareness.clientID)continue;const d=_[this._areaID];if(d===void 0)continue;const w=d.start,p=d.end,m=d.name,b=d.color,f=d.selection;if(!this._cursors.has(v)&&!f)continue;this._cursors.has(v)||this._cursors.set(v,new Z(u,b,e,m));const g=this._cursors.get(v);if(!f){g==null||g.setPosition(-1,-1),g==null||g.hide();continue}if(g==null||g.updateCursor(m,b),w===void 0||p===void 0)continue;const S=L.createAbsolutePositionFromRelativePosition(JSON.parse(w),s),y=L.createAbsolutePositionFromRelativePosition(JSON.parse(p),s);if(S===null||y===null){g==null||g.hide();continue}g==null||g.setPosition(S.index,y.index),g==null||g.rePosition(e)}};i.awareness.on("update",r),this._unobserveFns.push(()=>i.awareness.off("update",r));const o=()=>{const h=e.selectionStart,u=e.selectionEnd,c=L.createRelativePositionFromTypeIndex(t,h),v=L.createRelativePositionFromTypeIndex(t,u);i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!0,start:JSON.stringify(c),end:JSON.stringify(v),name:i.clientName,color:i.color||{r:45,g:80,b:237}})};for(const h of K)e.addEventListener(h,o),this._unobserveFns.push(()=>{e.removeEventListener(h,o)});const a=()=>{i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!1})};e.addEventListener("focusout",a),this._unobserveFns.push(()=>{e.removeEventListener("focusout",a)});const l=()=>{this.rePositionCursors()};e.addEventListener("scroll",l),this._unobserveFns.push(()=>{e.removeEventListener("scroll",l)})}rePositionCursors(){if(this._textField)for(const[t,e]of this._cursors)e.rePosition(this._textField)}destroy(){for(const t of this._unobserveFns)t();this._unobserveFns=[];for(const[t,e]of this._cursors)e.destroy();this._cursors.clear()}}var A=-1,R=1,I=0;function z(n,t,e,i){if(n===t)return n?[[I,n]]:[];if(e!=null){var s=te(n,t,e);if(s)return s}var r=$(n,t),o=n.substring(0,r);n=n.substring(r),t=t.substring(r),r=W(n,t);var a=n.substring(n.length-r);n=n.substring(0,n.length-r),t=t.substring(0,t.length-r);var l=k(n,t);return o&&l.unshift([I,o]),a&&l.push([I,a]),Y(l,i),l}function k(n,t){var e;if(!n)return[[R,t]];if(!t)return[[A,n]];var i=n.length>t.length?n:t,s=n.length>t.length?t:n,r=i.indexOf(s);if(r!==-1)return e=[[R,i.substring(0,r)],[I,s],[R,i.substring(r+s.length)]],n.length>t.length&&(e[0][0]=e[2][0]=A),e;if(s.length===1)return[[A,n],[R,t]];var o=ee(n,t);if(o){var a=o[0],l=o[1],h=o[2],u=o[3],c=o[4],v=z(a,h),_=z(l,u);return v.concat([[I,c]],_)}return x(n,t)}function x(n,t){for(var e=n.length,i=t.length,s=Math.ceil((e+i)/2),r=s,o=2*s,a=new Array(o),l=new Array(o),h=0;h<o;h++)a[h]=-1,l[h]=-1;a[r+1]=0,l[r+1]=0;for(var u=e-i,c=u%2!==0,v=0,_=0,d=0,w=0,p=0;p<s;p++){for(var m=-p+v;m<=p-_;m+=2){var b=r+m,f;m===-p||m!==p&&a[b-1]<a[b+1]?f=a[b+1]:f=a[b-1]+1;for(var g=f-m;f<e&&g<i&&n.charAt(f)===t.charAt(g);)f++,g++;if(a[b]=f,f>e)_+=2;else if(g>i)v+=2;else if(c){var S=r+u-m;if(S>=0&&S<o&&l[S]!==-1){var y=e-l[S];if(f>=y)return H(n,t,f,g)}}}for(var C=-p+d;C<=p-w;C+=2){var S=r+C,y;C===-p||C!==p&&l[S-1]<l[S+1]?y=l[S+1]:y=l[S-1]+1;for(var M=y-C;y<e&&M<i&&n.charAt(e-y-1)===t.charAt(i-M-1);)y++,M++;if(l[S]=y,y>e)w+=2;else if(M>i)d+=2;else if(!c){var b=r+u-C;if(b>=0&&b<o&&a[b]!==-1){var f=a[b],g=r+f-b;if(y=e-y,f>=y)return H(n,t,f,g)}}}}return[[A,n],[R,t]]}function H(n,t,e,i){var s=n.substring(0,e),r=t.substring(0,i),o=n.substring(e),a=t.substring(i),l=z(s,r),h=z(o,a);return l.concat(h)}function $(n,t){if(!n||!t||n.charAt(0)!==t.charAt(0))return 0;for(var e=0,i=Math.min(n.length,t.length),s=i,r=0;e<s;)n.substring(r,s)==t.substring(r,s)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return B(n.charCodeAt(s-1))&&s--,s}function W(n,t){if(!n||!t||n.slice(-1)!==t.slice(-1))return 0;for(var e=0,i=Math.min(n.length,t.length),s=i,r=0;e<s;)n.substring(n.length-s,n.length-r)==t.substring(t.length-s,t.length-r)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return J(n.charCodeAt(n.length-s))&&s--,s}function ee(n,t){var e=n.length>t.length?n:t,i=n.length>t.length?t:n;if(e.length<4||i.length*2<e.length)return null;function s(_,d,w){for(var p=_.substring(w,w+Math.floor(_.length/4)),m=-1,b="",f,g,S,y;(m=d.indexOf(p,m+1))!==-1;){var C=$(_.substring(w),d.substring(m)),M=W(_.substring(0,w),d.substring(0,m));b.length<M+C&&(b=d.substring(m-M,m)+d.substring(m,m+C),f=_.substring(0,w-M),g=_.substring(w+C),S=d.substring(0,m-M),y=d.substring(m+C))}return b.length*2>=_.length?[f,g,S,y,b]:null}var r=s(e,i,Math.ceil(e.length/4)),o=s(e,i,Math.ceil(e.length/2)),a;if(!r&&!o)return null;o?r?a=r[4].length>o[4].length?r:o:a=o:a=r;var l,h,u,c;n.length>t.length?(l=a[0],h=a[1],u=a[2],c=a[3]):(u=a[0],c=a[1],l=a[2],h=a[3]);var v=a[4];return[l,h,u,c,v]}function Y(n,t){n.push([I,""]);for(var e=0,i=0,s=0,r="",o="",a;e<n.length;){if(e<n.length-1&&!n[e][1]){n.splice(e,1);continue}switch(n[e][0]){case R:s++,o+=n[e][1],e++;break;case A:i++,r+=n[e][1],e++;break;case I:var l=e-s-i-1;if(t){if(l>=0&&X(n[l][1])){var h=n[l][1].slice(-1);if(n[l][1]=n[l][1].slice(0,-1),r=h+r,o=h+o,!n[l][1]){n.splice(l,1),e--;var u=l-1;n[u]&&n[u][0]===R&&(s++,o=n[u][1]+o,u--),n[u]&&n[u][0]===A&&(i++,r=n[u][1]+r,u--),l=u}}if(U(n[e][1])){var h=n[e][1].charAt(0);n[e][1]=n[e][1].slice(1),r+=h,o+=h}}if(e<n.length-1&&!n[e][1]){n.splice(e,1);break}if(r.length>0||o.length>0){r.length>0&&o.length>0&&(a=$(o,r),a!==0&&(l>=0?n[l][1]+=o.substring(0,a):(n.splice(0,0,[I,o.substring(0,a)]),e++),o=o.substring(a),r=r.substring(a)),a=W(o,r),a!==0&&(n[e][1]=o.substring(o.length-a)+n[e][1],o=o.substring(0,o.length-a),r=r.substring(0,r.length-a)));var c=s+i;r.length===0&&o.length===0?(n.splice(e-c,c),e=e-c):r.length===0?(n.splice(e-c,c,[R,o]),e=e-c+1):o.length===0?(n.splice(e-c,c,[A,r]),e=e-c+1):(n.splice(e-c,c,[A,r],[R,o]),e=e-c+2)}e!==0&&n[e-1][0]===I?(n[e-1][1]+=n[e][1],n.splice(e,1)):e++,s=0,i=0,r="",o="";break}}n[n.length-1][1]===""&&n.pop();var v=!1;for(e=1;e<n.length-1;)n[e-1][0]===I&&n[e+1][0]===I&&(n[e][1].substring(n[e][1].length-n[e-1][1].length)===n[e-1][1]?(n[e][1]=n[e-1][1]+n[e][1].substring(0,n[e][1].length-n[e-1][1].length),n[e+1][1]=n[e-1][1]+n[e+1][1],n.splice(e-1,1),v=!0):n[e][1].substring(0,n[e+1][1].length)==n[e+1][1]&&(n[e-1][1]+=n[e+1][1],n[e][1]=n[e][1].substring(n[e+1][1].length)+n[e+1][1],n.splice(e+1,1),v=!0)),e++;v&&Y(n,t)}function B(n){return n>=55296&&n<=56319}function J(n){return n>=56320&&n<=57343}function U(n){return J(n.charCodeAt(0))}function X(n){return B(n.charCodeAt(n.length-1))}function ne(n){for(var t=[],e=0;e<n.length;e++)n[e][1].length>0&&t.push(n[e]);return t}function j(n,t,e,i){return X(n)||U(i)?null:ne([[I,n],[A,t],[R,e],[I,i]])}function te(n,t,e){var i=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,r=n.length,o=t.length;if(i.length===0&&(s===null||s.length===0)){var a=i.index,l=n.slice(0,a),h=n.slice(a),u=s?s.index:null;e:{var c=a+o-r;if(u!==null&&u!==c||c<0||c>o)break e;var v=t.slice(0,c),_=t.slice(c);if(_!==h)break e;var d=Math.min(a,c),w=l.slice(0,d),p=v.slice(0,d);if(w!==p)break e;var m=l.slice(d),b=v.slice(d);return j(w,m,b,h)}e:{if(u!==null&&u!==a)break e;var f=a,v=t.slice(0,f),_=t.slice(f);if(v!==l)break e;var g=Math.min(r-f,o-f),S=h.slice(h.length-g),y=_.slice(_.length-g);if(S!==y)break e;var m=h.slice(0,h.length-g),b=_.slice(0,_.length-g);return j(l,m,b,S)}}if(i.length>0&&s&&s.length===0){e:{var w=n.slice(0,i.index),S=n.slice(i.index+i.length),d=w.length,g=S.length;if(o<d+g)break e;var p=t.slice(0,d),y=t.slice(o-g);if(w!==p||S!==y)break e;var m=n.slice(d,r-g),b=t.slice(d,o-g);return j(w,m,b,S)}}return null}function T(n,t,e){return z(n,t,e,!0)}T.INSERT=R,T.DELETE=A,T.EQUAL=I;var re=T;class ie{constructor(t,e,i){E(this,"_cursors");E(this,"_unobserveFns",[]);let s=t.doc;if(s===null)throw new Error("Missing doc on yText");if(e.selectionStart===void 0||e.selectionEnd===void 0)throw new Error("textField argument doesn't look like a text field");i&&(this._cursors=new q(t,e,i)),e.value=t.toString();let r,o,a;const l=()=>{a=e.selectionDirection;const v=this.createRange(e);r=L.createRelativePositionFromTypeIndex(t,v.left),o=L.createRelativePositionFromTypeIndex(t,v.right)};s.on("beforeTransaction",l),this._unobserveFns.push(()=>s.off("beforeTransaction",l));let h=!1;const u=(v,_)=>{if(_.local&&h){h=!1;return}if(e.value=t.toString(),e.getRootNode().activeElement===e){const d=L.createAbsolutePositionFromRelativePosition(r,s),w=L.createAbsolutePositionFromRelativePosition(o,s);d!==null&&w!==null&&(a===null&&(a="forward"),e.setSelectionRange(d.index,w.index,a))}};t.observe(u),this._unobserveFns.push(()=>t.unobserve(u));const c=()=>{h=!0;const v=this.createRange(e);let _=t.toString(),d=e.value,w=re(_,d,v.left),p=0;s.transact(m=>{for(let b=0;b<w.length;b++){let f=w[b];f[0]===0?p+=f[1].length:f[0]===-1?t.delete(p,f[1].length):(t.insert(p,f[1]),p+=f[1].length)}})};e.addEventListener("input",c),this._unobserveFns.push(()=>e.removeEventListener("input",c))}createRange(t){const e=t.selectionStart,i=t.selectionEnd;return{left:e,right:i}}rePositionCursors(){var t;(t=this._cursors)==null||t.rePositionCursors()}destroy(){for(const t of this._unobserveFns)t();this._unobserveFns=[],this._cursors&&this._cursors.destroy()}}D.TextAreaBinding=ie,Object.defineProperty(D,"__esModule",{value:!0}),D[Symbol.toStringTag]="Module"});

@@ -22,3 +22,3 @@ {

"types": "./dist/y-textArea.d.ts",
"version": "1.0.1",
"version": "1.0.2",
"scripts": {

@@ -25,0 +25,0 @@ "dev": "vite --host",

@@ -0,0 +0,0 @@ # y-TextArea

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc