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
1
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 0.2.2 to 0.2.3

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';

14

dist/y-textArea.es.js

@@ -953,9 +953,11 @@ import * as Y from "yjs";

}
const startPos = Y.createAbsolutePositionFromRelativePosition(relPosStart, doc);
const endPos = Y.createAbsolutePositionFromRelativePosition(relPosEnd, doc);
textField.value = yText.toString();
if (startPos !== null && endPos !== null) {
if (direction === null)
direction = "forward";
textField.setSelectionRange(startPos.index, endPos.index, direction);
if (textField.getRootNode().activeElement === textField) {
const startPos = Y.createAbsolutePositionFromRelativePosition(relPosStart, doc);
const endPos = Y.createAbsolutePositionFromRelativePosition(relPosEnd, doc);
if (startPos !== null && endPos !== null) {
if (direction === null)
direction = "forward";
textField.setSelectionRange(startPos.index, endPos.index, direction);
}
}

@@ -962,0 +964,0 @@ };

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

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

@@ -16,3 +16,3 @@ {

"types": "./dist/y-textArea.d.ts",
"version": "0.2.2",
"version": "0.2.3",
"scripts": {

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

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

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