@datagrok/helm 3.0.1 → 3.0.3

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/CLAUDE.md +78 -92
  3. package/dist/489.js +2 -0
  4. package/dist/489.js.map +1 -0
  5. package/dist/package-test.js +1 -1
  6. package/dist/package-test.js.map +1 -1
  7. package/dist/package.js +1 -1
  8. package/dist/package.js.map +1 -1
  9. package/files/samples/helm-showcase.csv +7 -9
  10. package/package.json +12 -9
  11. package/src/helm-helper.ts +3 -0
  12. package/src/package-api.ts +1 -0
  13. package/src/package-test.ts +0 -4
  14. package/src/package.g.ts +2 -0
  15. package/src/package.ts +4 -1
  16. package/src/tests/helm-input-tests.ts +3 -3
  17. package/src/utils/helm-grid-cell-renderer.ts +3 -0
  18. package/test-console-output-1.log +344 -0
  19. package/test-playwright-report.json +118 -0
  20. package/test-record-1.mp4 +0 -0
  21. package/test-report-playwright.csv +1 -0
  22. package/tsconfig.json +2 -1
  23. package/dist/137.js +0 -2
  24. package/dist/137.js.map +0 -1
  25. package/dist/323.js +0 -2
  26. package/dist/323.js.map +0 -1
  27. package/dist/455.js +0 -2
  28. package/dist/455.js.map +0 -1
  29. package/dist/657.js +0 -2
  30. package/dist/657.js.map +0 -1
  31. package/dist/782.js +0 -2
  32. package/dist/782.js.map +0 -1
  33. package/dist/884.js +0 -2
  34. package/dist/884.js.map +0 -1
  35. package/dist/94.js +0 -2
  36. package/dist/94.js.map +0 -1
  37. package/dist/libraries_bio_src_monomer-works_seq-to-molfile-worker_ts.js +0 -16420
  38. package/dist/libraries_bio_src_monomer-works_seq-to-molfile-worker_ts.js.map +0 -1
  39. package/dist/package-dojo.js +0 -2
  40. package/dist/package-dojo.js.map +0 -1
  41. package/dist/vendors-HELM_node_modules_lru-cache_dist_esm_index_js.js +0 -1560
  42. package/dist/vendors-HELM_node_modules_lru-cache_dist_esm_index_js.js.map +0 -1
package/dist/94.js DELETED
@@ -1,2 +0,0 @@
1
- var helm;(()=>{"use strict";var t,e,i={94(t,e,i){i.d(e,{kC:()=>l,oE:()=>r}),i(782);Error;new Map([[123,"lbrace"],[125,"rbrace"],[40,"lparen"],[41,"rparen"],[93,"rbracket"],[124,"pipe"],[46,"dot"],[44,"comma"],[43,"plus"],[58,"colon"],[45,"dash"],[36,"dollar"],[62,"gt"],[63,"question"],[42,"asterisk"],[95,"underscore"],[39,"apos"]]);new Map;var r={AA:"HELM_AA",SUGAR:"HELM_SUGAR",BASE:"HELM_BASE",LINKER:"HELM_LINKER",CHEM:"HELM_CHEM",BLOB:"HELM_BLOB",NUCLEOTIDE:"HELM_NUCLEOTIDE"},l={PEPTIDE:"PEPTIDE",RNA:"RNA",CHEM:"CHEM",BLOB:"BLOB",G:"G"};var s=class{constructor(){this._listeners=new Set,this._completed=!1}subscribe(t){return this._completed?()=>{}:(this._listeners.add(t),()=>{this._listeners.delete(t)})}next(t){if(!this._completed)for(let e of[...this._listeners])e(t)}complete(){this._completed=!0,this._listeners.clear()}get observerCount(){return this._listeners.size}};function o(t){return{line:"#202020",text:"#000000",background:t}}function n(t){return{line:"#e0e0e0",text:"#ffffff",background:g(t,.25)}}function a(t){let e=/^#([0-9a-fA-F]{6})$/.exec(t),i=/^#([0-9a-fA-F]{3})$/.exec(t);if(null!==e){let t=e[1];return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}if(null!==i){let t=i[1];return[parseInt(t[0]+t[0],16),parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16)]}return null}function h(t){return t.toString(16).padStart(2,"0")}function d(t,e,i){return`#${h(t)}${h(e)}${h(i)}`}function u(t,e,i){let r=t/255,l=e/255,s=i/255,o=Math.max(r,l,s),n=Math.min(r,l,s),a=(o+n)/2;if(o===n)return[0,0,a];let h,d=o-n;return h=o===r?60*((l-s)/d+(l<s?6:0)):o===l?60*((s-r)/d+2):60*((r-l)/d+4),[h,a>.5?d/(2-o-n):d/(o+n),a]}function p(t,e,i){let r=i;return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}function c(t,e,i){if(0===e){let t=Math.round(255*i);return[t,t,t]}let r=i<.5?i*(1+e):i+e-i*e,l=2*i-r,s=t/360;return[Math.round(255*p(l,r,s+1/3)),Math.round(255*p(l,r,s)),Math.round(255*p(l,r,s-1/3))]}function _(t,e=.3,i=.1){let r=a(t);if(null===r)return t;let[l,s,o]=u(r[0],r[1],r[2]),n=Math.max(0,Math.min(1,s*(1-e))),h=Math.max(0,Math.min(.95,o+i*(1-o))),[p,_,b]=c(l,n,h);return d(p,_,b)}function b(t){let e=a(t);if(null===e)return 0;let i=t=>{let e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)};return.2126*i(e[0])+.7152*i(e[1])+.0722*i(e[2])}function f(t){let e=a(t);if(null===e)return"#1f2937";let[i,r,l]=u(e[0],e[1],e[2]);if(l>.85||r<.15&&l>.7)return"#1f2937";let s=Math.max(.08,l-.3);return function(t){let e=(t.h%360+360)%360,i=Math.max(0,Math.min(1,t.s)),r=Math.max(0,Math.min(1,t.l)),[l,s,o]=c(e,i,r);return d(l,s,o)}({h:i,s:Math.min(1,r+.1),l:s})}function v(t){let e=function(t){let e=a(t);return null===e?null:{r:e[0]/255,g:e[1]/255,b:e[2]/255}}(t);if(null===e)return"#1f2937";let i=t=>t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4),r=.2126*i(e.r)+.7152*i(e.g)+.0722*i(e.b);return 1.05/(r+.05)>(r+.05)/.05?"#ffffff":"#1f2937"}function g(t,e){let i=a(t);if(null===i)return t;let r=1-e;return d(Math.max(0,Math.min(255,Math.round(i[0]*r))),Math.max(0,Math.min(255,Math.round(i[1]*r))),Math.max(0,Math.min(255,Math.round(i[2]*r))))}var m={A:o("#A0A0FF"),G:o("#FF7070"),T:o("#A0FFA0"),C:o("#FF8C4B"),U:o("#FF8080")},y={R:o("#7a85c1"),r:o("#7a85c1")},w={P:o("#9aa5e1"),p:o("#9aa5e1")},k={A:o("#C8C8C8"),R:o("#145AFF"),N:o("#00DCDC"),D:o("#E60A0A"),C:o("#E6E600"),E:o("#00DCDC"),Q:o("#E60A0A"),G:o("#EBEBEB"),H:o("#8282D2"),I:o("#0F820F"),L:o("#0F820F"),K:o("#145AFF"),M:o("#E6E600"),F:o("#3232AA"),P:o("#DC9682"),S:o("#FA9600"),T:o("#FA9600"),W:o("#B45AB4"),Y:o("#3232AA"),V:o("#0F820F")},A={R:o("#eeeeee")},S={B:o("#999999"),G:o("#e2e2e2")},C={P:o("#9aa5e1")},T={name:"light",fallback:{line:"#202020",text:"#000000",background:"#eeeeee"},errorTriple:{line:"#cc0000",text:"#000000",background:"#FFFF00"},palette:{[r.BASE]:m,[r.SUGAR]:y,[r.LINKER]:w,[r.AA]:k,[r.CHEM]:A,[r.BLOB]:S,[r.NUCLEOTIDE]:C}};function E(t){let e={};for(let[i,r]of Object.entries(t))e[i]=n(r.background);return e}var x={name:"dark",fallback:{line:"#e0e0e0",text:"#ffffff",background:g("#eeeeee",.5)},errorTriple:{line:"#ff5050",text:"#ffffff",background:g("#FFFF00",.4)},palette:{[r.BASE]:E(m),[r.SUGAR]:E(y),[r.LINKER]:E(w),[r.AA]:E(k),[r.CHEM]:E(A),[r.BLOB]:E(S),[r.NUCLEOTIDE]:E(C)}};function M(t,e,i=T){if(null===t)return{...i.errorTriple};let r=t.meta?.colors;if(void 0!==r){let t="light"===i.name?r.light:"dark"===i.name?r.dark:void 0;if(void 0!==t)return{...t,line:f(t.background)};if(void 0!==r.default)return{...r.default,line:f(r.default.background)}}let l=t.naturalAnalog;if(void 0!==l&&""!==l){let t=i.palette[e];if(void 0!==t){let e=t[l];if(void 0!==e)return{...e,line:f(e.background),text:v(e.background)}}}return{...i.fallback,line:f(i.fallback.background),text:v(i.fallback.background)}}function $(t){switch(t.polymerType){case l.PEPTIDE:return r.AA;case l.CHEM:return r.CHEM;case l.BLOB:return r.BLOB;case l.RNA:if("Branch"===t.monomerType)return r.BASE;if("Backbone"===t.monomerType){let e=t.naturalAnalog;return"P"===e||"p"===e?r.LINKER:r.SUGAR}return null;default:return null}}new Set(["PEPTIDE","RNA","CHEM","BLOB"]),new Set(["Backbone","Branch","Terminal","Undefined"]);new Set(["?","*","_","X","N"]);Math.PI;function B(t,e){let i=Math.min(t.x,e.x),r=Math.min(t.y,e.y);return{x:i,y:r,width:Math.max(t.x+t.width,e.x+e.width)-i,height:Math.max(t.y+t.height,e.y+e.height)-r}}function F(t){if(Number.isInteger(t))return 0===t?"0":t.toString();if(!Number.isFinite(t)||Object.is(t,-0))return"0";let e=Math.round(1e3*t)/1e3;return 0===e?"0":e.toString()}function L(t){if(0===t.length)return"";let e=t[0],i=`M ${F(e.x)} ${F(e.y)}`;for(let e=1;e<t.length;e++){let r=t[e];i+=` L ${F(r.x)} ${F(r.y)}`}return i+=` L ${F(e.x)} ${F(e.y)} Z`,i}function R(t,e,i,r){let l=[],s=360/e;for(let o=0;o<e;o++){let e=(r+o*s)*Math.PI/180;l.push({x:t.x+i*Math.cos(e),y:t.y+i*Math.sin(e)})}return l}function P(t,e,i,r){let l=Math.abs(e)/2,s=Math.abs(i)/2,o=Math.max(0,Math.min(r,l,s)),n=t.x-l,a=t.y-s,h=n+2*l,d=a+2*s,u=`M ${F(n+o)} ${F(a)}`;return u+=` L ${F(h-o)} ${F(a)}`,u+=` A ${F(o)} ${F(o)} 0 0 1 ${F(h)} ${F(a+o)}`,u+=` L ${F(h)} ${F(d-o)}`,u+=` A ${F(o)} ${F(o)} 0 0 1 ${F(h-o)} ${F(d)}`,u+=` L ${F(n+o)} ${F(d)}`,u+=` A ${F(o)} ${F(o)} 0 0 1 ${F(n)} ${F(d-o)}`,u+=` L ${F(n)} ${F(a+o)}`,u+=` A ${F(o)} ${F(o)} 0 0 1 ${F(n+o)} ${F(a)}`,u+=" Z",u}function I(t,e,i){let r=Math.abs(e),l=Math.abs(i);return`M ${F(t.x-r)} ${F(t.y)} A ${F(r)} ${F(l)} 0 1 0 ${F(t.x+r)} ${F(t.y)} A ${F(r)} ${F(l)} 0 1 0 ${F(t.x-r)} ${F(t.y)} Z`}function N(t,e,i,r){switch(t){case"hexagon":{let t=i*Math.sqrt(3)/2,r=i;return{x:e.x-t,y:e.y-r,width:2*t,height:2*r}}case"diamond":return{x:e.x-i,y:e.y-i,width:2*i,height:2*i};case"pentagon":{let t=Math.cos(18*Math.PI/180)*i,r=-i,l=Math.sin(54*Math.PI/180)*i;return{x:e.x-t,y:e.y+r,width:2*t,height:l-r}}case"rounded-rect":case"blob":{let t=r??i,l=Math.abs(i)/2,s=Math.abs(t)/2;return{x:e.x-l,y:e.y-s,width:2*l,height:2*s}}case"ellipse":{let t=Math.abs(i),l=Math.abs(r??i);return{x:e.x-t,y:e.y-l,width:2*t,height:2*l}}case"circle":{let t=Math.abs(i);return{x:e.x-t,y:e.y-t,width:2*t,height:2*t}}}}var O='"Helvetica Neue", Helvetica, Arial, sans-serif';function H(t){return{aa:{size:.72*t,strokeWidth:5},sugar:{size:1.39*t,strokeWidth:5,cornerRadius:.3*t},base:{size:.88*t,strokeWidth:5},linker:{size:.63*t,strokeWidth:5},chem:{size:1.49*t,strokeWidth:5,cornerRadius:.5*t},blob:{size:1.64*t,strokeWidth:5,cornerRadius:.8*t},nucleotide:{size:.98*t,strokeWidth:5}}}var D={name:"light",background:"#ffffff",defaultStroke:"#202020",defaultFill:"#ffffff",selectionColor:"#FFC107",highlightColor:"#A4E2DC",errorColor:"#cc0000",fontSize:14,fontFamily:O,bondLength:28,textColor:"#000000",idColor:"#00aa00",annotationColor:"#FFA500",tagDotColor:"#dd2222",hbondColor:"#888888",nonCanonicalHbondColor:"#cc8800",crossPolymerBondColor:"#1f5fcd",colorTheme:T,palette:{softenCanvas:!1},shapes:H(14)};H(14);function z(t,e){switch(e){case r.AA:return t.shapes.aa;case r.SUGAR:return t.shapes.sugar;case r.BASE:return t.shapes.base;case r.LINKER:return t.shapes.linker;case r.CHEM:return t.shapes.chem;case r.BLOB:return t.shapes.blob;case r.NUCLEOTIDE:return t.shapes.nucleotide}}function U(t){switch(t){case r.AA:return"hexagon";case r.SUGAR:return"rounded-rect";case r.BASE:return"diamond";case r.LINKER:return"circle";case r.CHEM:return"rounded-rect";case r.BLOB:return"blob";case r.NUCLEOTIDE:return"pentagon"}}function G(t,e,i=0){let r=z(e,t.biotype);if("*"===t.symbol)return function(t,e){return I(t,e,e)}(t.p,r.size+i);switch(U(t.biotype)){case"hexagon":{let e=0===i?0:i/Math.cos(Math.PI/6);return function(t,e,i=-30){return L(R(t,6,e,i))}(t.p,r.size+e)}case"diamond":{let e=0===i?0:i/Math.cos(Math.PI/4);return function(t,e){return L([{x:t.x,y:t.y-e},{x:t.x+e,y:t.y},{x:t.x,y:t.y+e},{x:t.x-e,y:t.y}])}(t.p,r.size+e)}case"pentagon":{let e=0===i?0:i/Math.cos(Math.PI/5);return function(t,e,i=-90){return L(R(t,5,e,i))}(t.p,r.size+e)}case"rounded-rect":return P(t.p,r.size+2*i,r.size+2*i,(r.cornerRadius??0)+i);case"blob":return function(t,e,i,r){return P(t,e,i,r)}(t.p,r.size+2*i,r.size+2*i,(r.cornerRadius??0)+i);case"circle":return I(t.p,r.size+i,r.size+i)}}function q(t,e){let i,r=z(e,t.biotype),l="*"===t.symbol?"circle":U(t.biotype);switch(l){case"hexagon":case"diamond":case"pentagon":case"circle":i=N(l,t.p,r.size);break;case"rounded-rect":case"blob":i=N(l,t.p,r.size,r.size)}let s=r.strokeWidth/2;return{x:i.x-s,y:i.y-s,width:i.width+2*s,height:i.height+2*s}}function j(t,e){return z(e,t.biotype)}var K=/[&"'<>]/;function V(t){return K.test(t)?t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"):t}function W(t){if(Number.isInteger(t))return 0===t?"0":t.toString();if(!Number.isFinite(t)||Object.is(t,-0))return"0";let e=Math.round(1e3*t)/1e3;return 0===e?"0":e.toString()}function X(t,e,i){let r=`<${t}`;if(void 0!==e)for(let t in e){let i=e[t];if(void 0!==i&&!1!==i){if(!0===i){r+=` ${t}`;continue}r+="number"==typeof i?` ${t}="${W(i)}"`:` ${t}="${V(i)}"`}}return void 0===i?`${r}/>`:"string"==typeof i?`${r}>${i}</${t}>`:`${r}>${i.join("")}</${t}>`}function Y(t,e,i){if(0===i.size)return X("g",{class:"hw-layer hw-highlights"},"");let r=[];for(let l of t.atoms){if(!i.has(l.id))continue;let t=G(l,e,(j(l,e).strokeWidth+3)/2);r.push(X("path",{d:t,class:"hw-highlight",fill:"none",stroke:e.highlightColor,"stroke-width":3,"stroke-linejoin":"round","stroke-linecap":"round","data-symbol":l.symbol,"data-ring-atom-id":l.id,"data-testid":`highlight-ring-${l.id}`}))}return X("g",{class:"hw-layer hw-highlights"},r.join(""))}function Z(t,e,i){if(0===i.size)return X("g",{class:"hw-layer hw-selections"},"");let r=[];for(let l of t.atoms){if(!i.has(l.id))continue;let t=G(l,e,(j(l,e).strokeWidth+3)/2);r.push(X("path",{d:t,class:"hw-selection",fill:"none",stroke:e.selectionColor,"stroke-width":3,"stroke-linejoin":"round","stroke-linecap":"round","data-symbol":l.symbol,"data-ring-atom-id":l.id,"data-testid":`selection-ring-${l.id}`}))}return X("g",{class:"hw-layer hw-selections"},r.join(""))}new WeakMap;new Map;var J=class{constructor(t,e){this.atoms=t,this.bonds=e,this.isEmpty=0===t.size&&0===e.size,Object.freeze(this)}};new J(new Set,new Set);function Q(t){let e=t.ownerDocument;if(null!=e)return e;let i=globalThis;if(void 0!==i.document)return i.document;throw new Error("EditorView: no Document available (host.ownerDocument is null).")}function tt(t,e,i,r){let l=t.createElement(e);if(void 0!==i)for(let t of Object.keys(i)){let e=i[t];!1===e||void 0===e||l.setAttribute(t,!0===e?"":String(e))}if(void 0!==r)for(let e of r)"string"==typeof e?l.appendChild(t.createTextNode(e)):l.appendChild(e);return l}function et(t,e,i=220,r=140){if(null==t||""===e)return null;try{let l=t.get_mol(e);if(null===l)return null;let s=l.get_svg(i,r);return l.delete(),s}catch{return null}}function it(t,e,i){let r="data-testid";for(let i=0;i<t.body.children.length;i++){let l=t.body.children[i];if(void 0!==l&&l.getAttribute(r)===e)return l}let l=tt(t,"div",{class:i,[r]:e});return l.style.display="none",t.body.appendChild(l),l}function rt(t,e,i){for(;null!==e.firstChild;)e.removeChild(e.firstChild);if(e.appendChild(tt(t,"div",{class:"hw-tooltip__symbol"},[i.symbol])),void 0!==i.name&&""!==i.name&&i.name!==i.symbol&&e.appendChild(tt(t,"div",{class:"hw-tooltip__name"},[i.name])),void 0!==i.rdkitSvg&&null!==i.rdkitSvg&&""!==i.rdkitSvg){let r={class:"hw-tooltip__rdkit"};void 0!==i.rdkitTestid&&(r["data-testid"]=i.rdkitTestid);let l=tt(t,"div",r);l.innerHTML=i.rdkitSvg,e.appendChild(l)}void 0!==i.hint&&""!==i.hint&&e.appendChild(tt(t,"div",{class:"hw-tooltip__hint"},[i.hint]))}function lt(t,e,i){let r=t.style;r.display="block",r.left=`${e+12}px`,r.top=`${i+12}px`}function st(t){null!==t&&(t.style.display="none")}function ot(t){let e=t.body;if(null!=e)for(let t=0;t<e.children.length;t++){let i=e.children[t];if(void 0===i)continue;let r=void 0===i.getAttribute?null:i.getAttribute("data-testid");null!=r&&r.endsWith("-tooltip")&&st(i)}}var nt=class t{constructor(t,e,i){this._baseTransform="",this._viewport={scale:1,offset:{x:0,y:0}},this._pinnedBbox=null,this._tooltip=null,this._bondTooltip=null,this._rdkitSvgCache=new Map,this._unsubs=[],this._destroyed=!1,this.host=t,this._editor=e,this._doc=i?.documentImpl??Q(t),this._width=i?.width??400,this._height=i?.height??200,function(t){let e=Q(t);if(null!==e.querySelector("style[data-hw-editor-view-styles]"))return;let i=e.createElement("style");i.setAttribute("data-hw-editor-view-styles",""),i.textContent=".hw-editor-view{position:relative;display:block;overflow:hidden;outline:none;}.hw-editor-view svg{display:block;user-select:none;}.hw-editor-view.hw-view-only{cursor:default;}";let r=e.head??e.documentElement;null!==r&&r.appendChild(i)}(t);let r=this._doc.createElement("div");r.setAttribute("class","hw-editor-view"),t.appendChild(r),this._tooltip=it(this._doc,"atom-tooltip","hw-atom-tooltip"),this._bondTooltip=it(this._doc,"bond-tooltip","hw-bond-tooltip"),this._svgRoot=this._renderFresh(),this._unsubs.push(e.on("mol:changed",t=>{this._hideTooltip(),this._hideBondTooltip(),("setHelm"===t.reason||"cleanLayout"===t.reason||"initial"===t.reason)&&(this._pinnedBbox=null),this._renderFresh()})),this._unsubs.push(e.on("selection:change",t=>{this._refreshOverlays(t)})),this._unsubs.push(e.on("highlight:change",t=>{this._refreshOverlays(t)})),this._unsubs.push(e.on("theme:change",()=>{this._renderFresh()})),this._unsubs.push(e.on("view:resize",t=>{this._applyResize(t.width,t.height)})),this._unsubs.push(e.on("view:viewport-change",t=>{this._viewport=t.viewport,this._applyViewport(t.viewport)})),this._unsubs.push(e.on("view:fit-to-content",()=>{this._pinnedBbox=null,this._renderFresh()})),this._unsubs.push(e.on("monomer:hover",t=>{this._showTooltip(t.atom,t.clientX,t.clientY)})),this._unsubs.push(e.on("monomer:hover-end",()=>{this._hideTooltip()})),this._unsubs.push(e.on("bond:hover",t=>{this._showBondTooltip(t.bond,t.clientX,t.clientY)})),this._unsubs.push(e.on("bond:hover-end",()=>{this._hideBondTooltip()})),this._unsubs.push(e.on("bond:preview",t=>{this._paintBondPreview(t.start.p,t.cursor,null!==t.candidate)})),this._unsubs.push(e.on("bond:preview-end",()=>{this._clearBondPreview()})),this._unsubs.push(e.on("bond:cancel",()=>{this._clearBondPreview()})),this._unsubs.push(e.on("selection:rectangle-start",t=>{this._paintSelectionRect(t.origin,t.origin)})),this._unsubs.push(e.on("selection:rectangle-update",t=>{this._paintSelectionRectFromRect(t.rect)})),this._unsubs.push(e.on("selection:rectangle-end",()=>{this._clearSelectionRect()}))}get svgRoot(){return this._svgRoot}get width(){return this._width}get height(){return this._height}resize(t,e){this._destroyed||(this._width=t,this._height=e,this._renderFresh())}redraw(){this._destroyed||this._renderFresh()}destroy(){if(this._destroyed)return;this._destroyed=!0;for(let t of this._unsubs)t();this._unsubs.length=0;let t=this.host.querySelector(".hw-editor-view");null!==t&&null!==t.parentNode&&t.parentNode.removeChild(t),st(this._tooltip),st(this._bondTooltip),this._tooltip=null,this._bondTooltip=null}_renderFresh(){let t=this._editor.getService(),e=this._currentTheme(),i=this._editor.getMol();null===this._pinnedBbox&&(this._pinnedBbox=function(t,e=D){if(0===t.atoms.length)return{x:0,y:0,width:0,height:0};let i=q(t.atoms[0],e);for(let r=1;r<t.atoms.length;r++)i=B(i,q(t.atoms[r],e));return i}(i,e));let r=t.renderMol(i,{width:this._width,height:this._height,theme:e,fixedModelBbox:this._pinnedBbox});this._svgRoot=function(t,e){let i=Q(t),r=t.querySelector(".hw-editor-view");if(null===r)throw new Error("EditorView.replaceSvg: missing .hw-editor-view wrapper.");let l=i.createElement("div");l.innerHTML=e;let s=l.querySelector("svg");if(null===s)throw new Error("EditorView.replaceSvg: rendered output contained no <svg>.");for(;null!==r.firstChild;)r.removeChild(r.firstChild);return r.appendChild(s),s}(this.host,r);let l=this._svgRoot.querySelector(".hw-content");return this._baseTransform=null!==l?l.getAttribute("transform")??"":"",this._svgRoot.setAttribute("data-testid","editor-svg"),this._applyOverlaysToCurrent(),(1!==this._viewport.scale||0!==this._viewport.offset.x||0!==this._viewport.offset.y)&&this._applyViewport(this._viewport),this._svgRoot}_refreshOverlays(t){this._applyOverlaysToCurrent()}_applyOverlaysToCurrent(){let t=this._editor.getMol(),e=this._editor.getSelection(),i=function(t,e={}){let i=e.theme??D,r=e.selectedAtomIds??new Set;return{highlightLayer:Y(t,i,e.highlightedAtomIds??new Set),selectionLayer:Z(t,i,r)}}(t,{theme:this._currentTheme(),selectedAtomIds:e.atoms,highlightedAtomIds:this._editorHighlights()});this._spliceLayer("hw-highlights",i.highlightLayer),this._spliceLayer("hw-selections",i.selectionLayer)}_spliceLayer(t,e){let i=this._svgRoot.querySelector(`.${t}`);if(null===i||null===i.parentNode)return;let r=this._doc.createElementNS("http://www.w3.org/2000/svg","svg");r.innerHTML=e;let l=r.querySelector(`.${t}`);null!==l&&i.parentNode.replaceChild(l,i)}_editorHighlights(){let t=this._editor;return"function"==typeof t._currentHighlights?t._currentHighlights():new Set}_currentTheme(){let t=this._editor;return"function"==typeof t._currentTheme?t._currentTheme():this._editor.getService().theme}_applyResize(t,e){this._width=t,this._height=e,this._pinnedBbox=null,this._renderFresh()}_applyViewport(t){let e=this._svgRoot.querySelector(".hw-content");if(null===e)return;let i=`translate(${t.offset.x} ${t.offset.y}) scale(${t.scale})`,r=""===this._baseTransform?i:`${i} ${this._baseTransform}`;e.setAttribute("transform",r)}_showTooltip(t,e,i){let r=this._tooltip;if(null===r)return;let l=""===t.symbol?"?":t.symbol,s=t.monomer?.name??"",o=t.bio.positionInChain,n=""===t.bio.chainId?"?":t.bio.chainId,a=""!==s&&s!==l?`${s} @ ${n}:${o}`:`${l} @ ${n}:${o}`,h=this._renderRdkitTooltipSvg(t);rt(this._doc,r,{symbol:l,name:a,rdkitSvg:h,rdkitTestid:"atom-tooltip-rdkit-svg"});let d=""!==s&&s!==l?`${l} — ${s} @ ${n}:${o}`:`${l} @ ${n}:${o}`,u=this._doc.createElement("div");u.setAttribute("class","hw-atom-tooltip__text"),u.style.display="none",u.appendChild(this._doc.createTextNode(d)),r.appendChild(u),lt(r,e,i)}_renderRdkitTooltipSvg(e){let i=this._editor.getService().options.rdkitModule;if(null==i)return null;let r=e.monomer;if(null===r)return null;let l=r.smiles;if(void 0===l||""===l)return null;let s=`${r.polymerType}:${r.symbol}`;if(this._rdkitSvgCache.has(s))return this._rdkitSvgCache.get(s)??null;let o=et(i,l,220,140);if(this._rdkitSvgCache.size>=t._RDKIT_CACHE_LIMIT){let t=this._rdkitSvgCache.keys().next().value;void 0!==t&&this._rdkitSvgCache.delete(t)}return this._rdkitSvgCache.set(s,o),o}_hideTooltip(){st(this._tooltip)}_showBondTooltip(t,e,i){let r=this._bondTooltip;if(null===r)return;let l=at(t.r1),s=at(t.r2),o=`${t.a1.symbol}@${t.a1.bio.chainId}:${t.a1.bio.positionInChain}`,n=`${t.a2.symbol}@${t.a2.bio.chainId}:${t.a2.bio.positionInChain}`;rt(this._doc,r,{symbol:`${l}-${s} (${t.kind})`,name:`${o} ↔ ${n}`}),lt(r,e,i)}_hideBondTooltip(){st(this._bondTooltip)}_paintBondPreview(t,e,i){let r=this._svgRoot.querySelector(".hw-content");if(null===r)return;let l=r.querySelector(".hw-bond-preview");null===l&&(l=this._doc.createElementNS("http://www.w3.org/2000/svg","line"),l.setAttribute("class","hw-bond-preview"),l.setAttribute("data-testid","bond-preview"),l.setAttribute("stroke-dasharray","6 4"),l.setAttribute("stroke-width","2"),l.setAttribute("fill","none"),l.setAttribute("pointer-events","none"),r.appendChild(l)),l.setAttribute("x1",String(t.x)),l.setAttribute("y1",String(t.y)),l.setAttribute("x2",String(e.x)),l.setAttribute("y2",String(e.y)),l.setAttribute("stroke",i?"#1f5fcd":"#999999")}_clearBondPreview(){let t=this._svgRoot.querySelector(".hw-bond-preview");null!==t&&null!==t.parentNode&&t.parentNode.removeChild(t)}_paintSelectionRect(t,e){let i=Math.min(t.x,e.x),r=Math.min(t.y,e.y),l=Math.abs(t.x-e.x),s=Math.abs(t.y-e.y);this._paintSelectionRectAt(i,r,l,s)}_paintSelectionRectFromRect(t){this._paintSelectionRectAt(t.x,t.y,t.width,t.height)}_paintSelectionRectAt(t,e,i,r){let l=this._svgRoot.querySelector(".hw-content");if(null===l)return;let s=l.querySelector(".hw-selection-rect");null===s&&(s=this._doc.createElementNS("http://www.w3.org/2000/svg","rect"),s.setAttribute("class","hw-selection-rect"),s.setAttribute("data-testid","selection-rect"),s.setAttribute("fill","rgba(31, 95, 205, 0.08)"),s.setAttribute("stroke","#1f5fcd"),s.setAttribute("stroke-width","1"),s.setAttribute("stroke-dasharray","4 3"),s.setAttribute("pointer-events","none"),l.appendChild(s)),s.setAttribute("x",String(t)),s.setAttribute("y",String(e)),s.setAttribute("width",String(i)),s.setAttribute("height",String(r))}_clearSelectionRect(){let t=this._svgRoot.querySelector(".hw-selection-rect");null!==t&&null!==t.parentNode&&t.parentNode.removeChild(t)}};nt._RDKIT_CACHE_LIMIT=256;function at(t){switch(t.kind){case"numeric":return`R${t.r}`;case"unspecified":return"?";case"wildcard":return"*";case"pair":return"pair";case"positional":return`${t.position}pos:R${t.r}`}}var ht=class t{constructor(t,e){this._onClose=null,this._primaryAction=null,this._host=t,this._doc=e.documentImpl??Q(t);let i=this._doc,r={class:"hw-modal-backdrop",role:"presentation"};void 0!==e.testId&&(r["data-testid"]=`dialog-${e.testId}`);let l=tt(i,"div",r),s={class:"hw-modal",role:"dialog","aria-modal":"true","aria-label":e.title};void 0!==e.testId&&(s["data-testid"]=`dialog-${e.testId}-frame`);let o=tt(i,"div",s),n=tt(i,"div",{class:"hw-modal__header"},[e.title]),a=tt(i,"div",{class:"hw-modal__body"});o.appendChild(n),o.appendChild(a),l.appendChild(o);let h=t=>{t.stopPropagation()};for(let t of["mousedown","mousemove","mouseup","mouseover","mouseenter","mouseleave","wheel","contextmenu","dblclick","keydown","keyup","keypress"])l.addEventListener(t,h);o.addEventListener("keydown",t=>{let e=t;if("Enter"!==e.key||"TEXTAREA"===e.target?.tagName)return;let i=this._primaryAction;null!==i&&(e.preventDefault?.(),e.stopImmediatePropagation?.(),i())}),l.addEventListener("click",t=>{t.target!==l?t.stopPropagation():this.close()}),this.root=l,this.body=a}static anyOpen(){return t._openStack.length>0}static closeTopmost(){let e=t._openStack[t._openStack.length-1];return void 0!==e&&(e.close(),!0)}open(e){this._onClose=e??null,null===this.root.parentNode&&this._host.appendChild(this.root),t._openStack.includes(this)||t._openStack.push(this),ot(this._doc)}close(){let e=t._openStack.indexOf(this);e>=0&&t._openStack.splice(e,1),null!==this.root.parentNode&&this.root.parentNode.removeChild(this.root);let i=this._onClose;this._onClose=null,null!==i&&i()}setPrimaryAction(t){this._primaryAction=t}get isOpen(){return null!==this.root.parentNode}};ht._openStack=[];Object.freeze(new Set);function dt(t){return t.startsWith("[")&&t.endsWith("]")||1===t.length&&/^[A-Za-z]$/.test(t)?t:`[${t}]`}function ut(t,e,i){return`${dt(t)}(${dt(e)})${dt(i)}`}var pt="http://www.w3.org/2000/svg",ct={sugar:r.SUGAR,base:r.BASE,linker:r.LINKER},_t={sugar:["r","R"],base:["A"],linker:["p","P"]},bt={x:70,y:60},ft={x:140,y:60},vt={x:70,y:130},gt=class t{constructor(t,e,i){this.onValueSet=new s,this.onPickModeChange=new s,this._slots=new Map,this._favStar=null,this._pickMode=null,this._destroyed=!1,this._builderRdkitCache=new Map,this._editor=e,this._doc=i?.documentImpl??Q(t),this._hooks=i?.paletteHooks??null,this._favHooks=i?.favoriteHooks??null,this.element=tt(this._doc,"div",{class:"hw-rna-builder","data-testid":"rna-builder"});let r=tt(this._doc,"div",{class:"hw-rna-builder__header"});if(r.appendChild(tt(this._doc,"div",{class:"hw-rna-builder__title"},["RNA builder"])),null!==this._favHooks){let t=tt(this._doc,"span",{class:"hw-rna-builder__fav hw-rna-builder__fav--disabled",role:"button",tabindex:"0","data-testid":"rna-builder-fav-star",title:"Favorite this triplet","aria-pressed":"false","aria-disabled":"true"},["☆"]),e=t=>{t.stopPropagation();let e=this.getSelection();""===e.preview||null===this._favHooks||this._favHooks.toggleFavoriteTriplet(e.sugar,e.base,e.linker)};t.addEventListener("click",e),t.addEventListener("keydown",t=>{let i=t;("Enter"===i.key||" "===i.key)&&e(t)}),this._favStar=t,r.appendChild(t)}this.element.appendChild(r),this._hintEl=tt(this._doc,"div",{class:"hw-rna-builder__hint","data-testid":"rna-builder-hint",hidden:!0}),this.element.appendChild(this._hintEl);let l=this._buildSvg();this.element.appendChild(l),this._preview=tt(this._doc,"div",{class:"hw-rna-builder__preview","data-testid":"rna-builder-preview"}),this.element.appendChild(this._preview),this._addBtn=tt(this._doc,"button",{class:"hw-rna-builder__add",type:"button","data-testid":"rna-builder-add-btn"},["Add triplet"]),this._addBtn.addEventListener("click",()=>this._onAddClicked()),this.element.appendChild(this._addBtn),t.appendChild(this.element);let o=e.getService().monomerLib.onChanged.subscribe(()=>{this._destroyed||this.refresh()}),n=e.on("theme:change",()=>{this._destroyed||this._repaintSlotColors()});this._libUnsub=()=>{try{o()}catch{}try{n()}catch{}},this._populateDefaults(),this._updatePreview(),this._repaintSlotColors()}refresh(){this._populateDefaults(),this._updatePreview(),this._repaintSlotColors()}getSelection(){let t=this._slots.get("sugar")?.value??"",e=this._slots.get("base")?.value??"",i=this._slots.get("linker")?.value??"";return{sugar:t,base:e,linker:i,preview:""!==t&&""!==e&&""!==i?ut(t,e,i):""}}setField(t,e){let i=this._slots.get(t);void 0!==i&&(i.value=e,this._setLabelText(i.labelEl,e),this._repaintSlot(i),this._updatePreview(),this.onValueSet.next({field:t,symbol:e}))}startPickMode(t){this._pickMode!==t?(null!==this._pickMode&&this._setSlotPressed(this._pickMode,!1),this._pickMode=t,this._setSlotPressed(t,!0),this._setHintActive(t),this.onPickModeChange.next({field:t}),null!==this._hooks&&this._hooks.beginBiotypeFilter(ct[t],e=>{this.setField(t,e),this._exitPickMode()},()=>{this._exitPickMode()})):this.cancelPickMode()}cancelPickMode(){null!==this._pickMode&&(null!==this._hooks&&this._hooks.endBiotypeFilter(),this._exitPickMode())}getPickMode(){return this._pickMode}triggerAdd(){this._onAddClicked()}destroy(){this._destroyed||(this._destroyed=!0,null!==this._pickMode&&null!==this._hooks&&this._hooks.endBiotypeFilter(),this._libUnsub(),this.onValueSet.complete(),this.onPickModeChange.complete(),null!==this.element.parentNode&&this.element.parentNode.removeChild(this.element))}_buildSvg(){let t=this._doc.createElementNS(pt,"svg");t.setAttribute("class","hw-rna-builder__triplet"),t.setAttribute("viewBox","0 0 200 180"),t.setAttribute("data-testid","rna-builder-triplet-svg"),t.setAttribute("role","group"),t.setAttribute("aria-label","Triplet preview");let e=this._doc.createElementNS(pt,"line");e.setAttribute("class","hw-rna-builder__bond"),e.setAttribute("x1",String(bt.x+18)),e.setAttribute("y1",String(bt.y)),e.setAttribute("x2",String(ft.x-18)),e.setAttribute("y2",String(ft.y)),t.appendChild(e);let i=this._doc.createElementNS(pt,"line");i.setAttribute("class","hw-rna-builder__bond"),i.setAttribute("x1",String(bt.x)),i.setAttribute("y1",String(bt.y+18)),i.setAttribute("x2",String(vt.x)),i.setAttribute("y2",String(vt.y-22)),t.appendChild(i);let r=this._doc.createElementNS(pt,"rect");r.setAttribute("class","hw-rna-builder__slot-shape"),r.setAttribute("x",String(-18)),r.setAttribute("y",String(-18)),r.setAttribute("width",String(36)),r.setAttribute("height",String(36)),r.setAttribute("rx","8"),r.setAttribute("ry","8");let l=this._buildSlot("sugar","Pick sugar (backbone)",bt,r),s=this._doc.createElementNS(pt,"circle");s.setAttribute("class","hw-rna-builder__slot-shape"),s.setAttribute("cx","0"),s.setAttribute("cy","0"),s.setAttribute("r",String(18));let o=this._buildSlot("linker","Pick linker",ft,s),n=this._doc.createElementNS(pt,"path");n.setAttribute("class","hw-rna-builder__slot-shape"),n.setAttribute("d","M -22 0 L 0 -22 L 22 0 L 0 22 Z");let a=this._buildSlot("base","Pick base",vt,n);return t.appendChild(o.groupEl),t.appendChild(l.groupEl),t.appendChild(a.groupEl),this._slots.set("sugar",l),this._slots.set("linker",o),this._slots.set("base",a),t}_buildSlot(t,e,i,r){let l=this._doc.createElementNS(pt,"g");l.setAttribute("class","hw-rna-builder__slot"),l.setAttribute("data-slot",t),l.setAttribute("data-testid",`rna-builder-slot-${t}`),l.setAttribute("role","button"),l.setAttribute("tabindex","0"),l.setAttribute("aria-label",e),l.setAttribute("aria-pressed","false"),l.setAttribute("transform",`translate(${i.x} ${i.y})`),l.appendChild(r);let s=this._doc.createElementNS(pt,"text");s.setAttribute("class","hw-rna-builder__slot-label"),s.setAttribute("data-testid",`rna-builder-${t}-value`),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("text-anchor","middle"),s.setAttribute("dominant-baseline","central"),l.appendChild(s);let o=e=>{e.stopPropagation(),this.startPickMode(t)};return l.addEventListener("click",o),l.addEventListener("keydown",t=>{let e=t;("Enter"===e.key||" "===e.key)&&o(t)}),l.addEventListener("mouseenter",e=>this._showSlotTooltip(t,e)),l.addEventListener("mouseleave",()=>this._hideSlotTooltip()),l.addEventListener("focus",()=>this._showSlotTooltip(t,null)),l.addEventListener("blur",()=>this._hideSlotTooltip()),{id:t,biotype:ct[t],groupEl:l,shapeEl:r,labelEl:s,value:""}}_setLabelText(t,e){let i=[];for(let e=t.firstChild;null!==e;e=e.nextSibling)"title"===e.nodeName||"TITLE"===e.nodeName||i.push(e);for(let e of i)t.removeChild(e);let r=function(t){let e=t.length;return e<=2?16:e<=4?11:e<=7?8:e<=10?6:5}(e);t.setAttribute("font-size",String(r)),t.setAttribute("text-anchor","middle"),t.setAttribute("dominant-baseline","central");let l=e.length>10?`${e.slice(0,9)}…`:e;t.appendChild(this._doc.createTextNode(l));let s=t.parentNode;if(null!==s){let t=null;for(let e=s.firstChild;null!==e;e=e.nextSibling)if("title"===e.nodeName||"TITLE"===e.nodeName){t=e;break}for(null===t&&(t=this._doc.createElementNS(pt,"title"),s.insertBefore(t,s.firstChild));null!==t.firstChild;)t.removeChild(t.firstChild);t.appendChild(this._doc.createTextNode(e))}}_repaintSlotColors(){for(let t of this._slots.values())this._repaintSlot(t)}_repaintSlot(t){let e=this._editor.getService().monomerLib,i=this._theme(),r=""===t.value?null:function(t,e,i){return t.getMonomerSet(e).get(i)??null}(e,t.biotype,t.value),l=M(r,t.biotype,i.colorTheme);t.shapeEl.style.fill=l.background,t.shapeEl.style.stroke=l.line,t.labelEl.style.fill=l.text}_populateDefaults(){let t=this._editor.getService().monomerLib;for(let[e,i]of this._slots.entries()){let r=yt(t,i.biotype),l=wt(r,_t[e]),s=""!==i.value&&r.some(t=>t.symbol===i.value)?i.value:l??r[0]?.symbol??"";i.value=s,this._setLabelText(i.labelEl,s)}}_updatePreview(){let t=this.getSelection();for(;null!==this._preview.firstChild;)this._preview.removeChild(this._preview.firstChild);this._preview.appendChild(this._doc.createTextNode(""===t.preview?"-":t.preview)),this._updateFavStar(t)}_updateFavStar(t){if(null===this._favStar||null===this._favHooks)return;let e=""!==t.preview,i=e&&this._favHooks.isFavoriteTriplet(t.sugar,t.base,t.linker);for(;null!==this._favStar.firstChild;)this._favStar.removeChild(this._favStar.firstChild);this._favStar.appendChild(this._doc.createTextNode(i?"★":"☆")),this._favStar.setAttribute("aria-pressed",i?"true":"false"),e?this._favStar.removeAttribute("aria-disabled"):this._favStar.setAttribute("aria-disabled","true");let r="hw-rna-builder__fav"+(i?" hw-rna-builder__fav--active":"")+(e?"":" hw-rna-builder__fav--disabled");this._favStar.setAttribute("class",r)}_onAddClicked(){let t=this.getSelection();""!==t.preview&&this._editor.placeRnaTriplet(t.sugar,t.base,t.linker)}_exitPickMode(){if(null===this._pickMode)return;let t=this._pickMode;this._setSlotPressed(t,!1),this._pickMode=null,this._setHintActive(null),this.onPickModeChange.next({field:null})}_setHintActive(t){let e=this._hintEl;for(;null!==e.firstChild;)e.removeChild(e.firstChild);if(null===t)return void e.setAttribute("hidden","");e.removeAttribute("hidden");let i="sugar"===t?"sugar":"base"===t?"base":"linker";e.appendChild(this._doc.createTextNode(`Pick ${i} from palette`))}_setSlotPressed(t,e){let i=this._slots.get(t);if(void 0===i)return;i.groupEl.setAttribute("aria-pressed",e?"true":"false");let r=(i.groupEl.getAttribute("class")??"").split(/\s+/).filter(t=>"hw-rna-builder__slot--active"!==t).join(" ");i.groupEl.setAttribute("class",e?`${r} hw-rna-builder__slot--active`:r)}_theme(){let t=this._editor;return"function"==typeof t._currentTheme?t._currentTheme():this._editor.getService().theme}_rdkit(){let t=this._editor.getService().options?.rdkitModule;return t??null}_builderRdkitSvgFor(e){if(null===e)return null;let i=e.smiles;if(void 0===i||""===i)return null;let r=this._rdkit();if(null===r)return null;let l=`${e.polymerType}:${e.symbol}`;if(this._builderRdkitCache.has(l))return this._builderRdkitCache.get(l)??null;let s=et(r,i,220,140);if(this._builderRdkitCache.size>=t._BUILDER_RDKIT_CACHE_LIMIT){let t=this._builderRdkitCache.keys().next().value;void 0!==t&&this._builderRdkitCache.delete(t)}return this._builderRdkitCache.set(l,s),s}_slotHint(t){switch(t){case"sugar":return"Click to choose a different sugar";case"base":return"Click to choose a different base";case"linker":return"Click to choose a different linker"}}_slotTitle(t,e){let i=""===e?"?":e;switch(t){case"sugar":return`Sugar: ${i}`;case"base":return`Base: ${i}`;case"linker":return`Linker: ${i}`}}_showSlotTooltip(t,e){let i=this._slots.get(t);if(void 0===i)return;let r=this._editor.getService().monomerLib.getMonomerSet(i.biotype),l=""===i.value?null:r.get(i.value)??null,s=it(this._doc,"builder-tooltip","hw-builder-tooltip");rt(this._doc,s,{symbol:this._slotTitle(t,i.value),name:l?.name??"",rdkitSvg:this._builderRdkitSvgFor(l),rdkitTestid:"builder-tooltip-rdkit-svg",hint:this._slotHint(t)});let o=e;if(null!==o&&"number"==typeof o.clientX&&"number"==typeof o.clientY)lt(s,o.clientX,o.clientY);else{let t=i.groupEl,e="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():null;null!==e?lt(s,e.left+e.width/2,e.top+e.height/2):lt(s,0,0)}}_hideSlotTooltip(){st(this._doc.body.querySelector('[data-testid="builder-tooltip"]'))}};gt._BUILDER_RDKIT_CACHE_LIMIT=256;var mt=gt;function yt(t,e){let i=t.getMonomerSet(e),r=[];for(let t of i.values())r.push(t);return r.sort((t,e)=>t.symbol.localeCompare(e.symbol)),r}function wt(t,e){let i=new Set;for(let e of t)i.add(e.symbol);for(let t of e)if(i.has(t))return t;return null}var kt="Favorites",At={[kt]:"★ Favorites",[l.PEPTIDE]:"Peptides",[l.RNA]:"RNA",[l.CHEM]:"CHEM",[l.BLOB]:"BLOB",G:"G"},St=[kt,l.PEPTIDE,l.RNA,l.CHEM,l.BLOB,"G"],Ct="hwe:palette:favorites",Tt="hwe:palette:active-tab";function Et(t){return`${t.sugar}|${t.base}|${t.linker}`}var xt=class t{constructor(t,e,i){this.favoritesChanged=new s,this._nextAddUnsub=()=>{},this._favorites=new Set,this._favoriteTriplets=[],this._pendingRnaSelection=null,this._visibleTabs=[kt],this._activeTab=kt,this._searchInput=null,this._filter="",this._destroyed=!1,this._rnaBuilder=null,this._activeBiotypeFilter=null,this._pickResolver=null,this._pickCanceller=null,this._pickEscapeListener=null,this._pickOutsideClickListener=null,this._paletteRdkitCache=new Map,this._editor=e,this._doc=i?.documentImpl??Q(t),this._opts={documentImpl:this._doc,groupByNaturalAnalog:i?.groupByNaturalAnalog??!0,allowFavorites:i?.allowFavorites??!0},this._loadFavorites(),this._activeTab=this._resolveInitialTab(i?.initialTab),this.element=tt(this._doc,"div",{class:"hw-palette","data-testid":"palette"}),t.appendChild(this.element),this._render(),this._libUnsub=e.getService().monomerLib.onChanged.subscribe(()=>{this._destroyed||this.refresh()}),this._themeUnsub=e.on("theme:change",()=>{this._destroyed||this.refresh()}),this._nextAddUnsub=e.on("option:change",t=>{this._destroyed||"nextAdd"===t.key&&this._updatePrimedClasses()})}refresh(){this._render()}setFilter(t){this._filter=t.trim().toLowerCase(),null!==this._searchInput&&this._searchInput.value!==t&&(this._searchInput.value=t),this._applyFilter()}setActiveTab(t){this._visibleTabs.includes(t)&&(this._activeTab=t,this._persistActiveTab(),this._applyActiveTabClasses(),this._applyFilter())}getActiveTab(){return this._activeTab}getFavorites(){let t=this._editor.getService().monomerLib,e=[];for(let i of this._favorites)null!==this._findMonomer(t,i)&&e.push(i);return e}setFavorite(t,e){e!==this._favorites.has(t)&&(e?this._favorites.add(t):this._favorites.delete(t),this._saveFavorites(),this._hidePaletteTooltips(),this._render(),this._emitFavoritesChanged())}clearFavorites(){0===this._favorites.size&&0===this._favoriteTriplets.length||(this._favorites.clear(),this._favoriteTriplets.length=0,this._saveFavorites(),this._render(),this._emitFavoritesChanged())}getFavoriteTriplets(){return this._favoriteTriplets.map(t=>({...t}))}isFavoriteTriplet(t,e,i){let r=Et({sugar:t,base:e,linker:i});return this._favoriteTriplets.some(t=>Et(t)===r)}setFavoriteTriplet(t,e,i,r){let l=Et({sugar:t,base:e,linker:i}),s=this._favoriteTriplets.findIndex(t=>Et(t)===l);r!==s>=0&&(r?this._favoriteTriplets.push({sugar:t,base:e,linker:i}):this._favoriteTriplets.splice(s,1),this._saveFavorites(),this._hidePaletteTooltips(),this._render(),this._emitFavoritesChanged())}_hidePaletteTooltips(){let t=this._doc.body;st(t.querySelector('[data-testid="palette-tooltip"]')),st(t.querySelector('[data-testid="palette-triplet-tooltip"]'))}_emitFavoritesChanged(){this.favoritesChanged.next({favorites:this.getFavorites(),triplets:this.getFavoriteTriplets()})}destroy(){this._destroyed||(this._destroyed=!0,null!==this._rnaBuilder&&(this._rnaBuilder.destroy(),this._rnaBuilder=null),this._libUnsub(),this._themeUnsub(),this._nextAddUnsub(),null!==this.element.parentNode&&this.element.parentNode.removeChild(this.element))}getRnaBuilder(){return this._rnaBuilder}hasActiveBiotypeFilter(){return null!==this._activeBiotypeFilter}getActiveBiotypeFilter(){return this._activeBiotypeFilter}cancelBiotypeFilter(){if(null===this._activeBiotypeFilter)return;let t=this._pickCanceller;this._teardownPickMode(),t?.()}_buildPaletteFilterHooks(){return{beginBiotypeFilter:(t,e,i)=>{null!==this._activeBiotypeFilter&&this._teardownPickMode(),this._activeBiotypeFilter=t,this._pickResolver=e,this._pickCanceller=i,this._applyFilter();let r=t=>{"Escape"===t.key&&this.cancelBiotypeFilter()};this._pickEscapeListener=r,this._doc.defaultView?.addEventListener("keydown",r);let l=t=>{if(null===this._activeBiotypeFilter)return;let e=t.target;if(null==e)return;let i=this._activeBiotypeFilter,r=e;for(;null!==r;){let t=void 0===r.getAttribute?null:r.getAttribute("class");if(null!==t){let e=t.split(/\s+/);if(e.includes("hw-palette__tile")){if((r.getAttribute("data-biotype")??"")===i)return;break}if(e.includes("hw-rna-builder__slot")){if(this._isInsideOwnPalette(r))return;break}}r=r.parentElement}this.cancelBiotypeFilter()};this._pickOutsideClickListener=l,this._doc.addEventListener("mousedown",l,!0)},endBiotypeFilter:()=>this._teardownPickMode()}}_scrollActivePaneToTop(){let t=this.element.querySelector(`.hw-palette__pane[data-tab="${this._activeTab}"]`);if(null===t)return;let e=t;try{if("function"==typeof e.scrollTo)return void e.scrollTo({top:0,behavior:"smooth"})}catch{}"number"==typeof e.scrollTop&&(e.scrollTop=0)}_isInsideOwnPalette(t){let e=t;for(;null!==e;){if(e===this.element)return!0;e=e.parentElement}return!1}_teardownPickMode(){null!==this._activeBiotypeFilter&&(this._activeBiotypeFilter=null,this._pickResolver=null,this._pickCanceller=null,null!==this._pickEscapeListener&&(this._doc.defaultView?.removeEventListener("keydown",this._pickEscapeListener),this._pickEscapeListener=null),null!==this._pickOutsideClickListener&&(this._doc.removeEventListener("mousedown",this._pickOutsideClickListener,!0),this._pickOutsideClickListener=null),this._applyFilter())}_render(){for(null!==this._rnaBuilder&&(this._pendingRnaSelection=this._rnaBuilder.getSelection(),this._rnaBuilder.destroy(),this._rnaBuilder=null);null!==this.element.firstChild;)this.element.removeChild(this.element.firstChild);let t=this._doc.createElement("input");t.setAttribute("type","search"),t.setAttribute("class","hw-palette__search"),t.setAttribute("placeholder","Search monomers..."),t.setAttribute("data-testid","palette-search"),""!==this._filter&&(t.value=this._filter),t.addEventListener("input",()=>this.setFilter(t.value)),this._searchInput=t,this.element.appendChild(t),this._visibleTabs=this._computeVisibleTabs(),this._visibleTabs.includes(this._activeTab)||(this._activeTab=kt);let e=tt(this._doc,"div",{class:"hw-palette__tabs",role:"tablist","data-testid":"palette-tabs"});for(let t of this._visibleTabs){let i=t===this._activeTab,r=tt(this._doc,"button",{class:"hw-palette__tab",type:"button",role:"tab","aria-controls":`hw-palette-pane-${t}`,"aria-selected":i?"true":"false","data-testid":`palette-tab-${t}`,"data-tab":t,title:At[t]},[At[t]]);r.addEventListener("click",()=>this.setActiveTab(t)),e.appendChild(r)}this.element.appendChild(e);let i=tt(this._doc,"div",{class:"hw-palette__panes"}),r=this._theme(),l=this._editor.getService().monomerLib;for(let t of this._visibleTabs){let e=t===this._activeTab,s=tt(this._doc,"div",{class:"hw-palette__pane",id:`hw-palette-pane-${t}`,role:"tabpanel","data-testid":`palette-pane-${t}`,"data-tab":t,hidden:!e});t===kt?this._buildFavoritesPane(s,l,r):this._buildPolymerPane(s,t,l,r),i.appendChild(s)}this.element.appendChild(i),this._applyFilter()}_computeVisibleTabs(){let t=this._editor.getService().monomerLib,e=new Set;for(let i of t.getPolymerTypes())e.add(i);let i=[];i.push(kt);for(let t of St)t!==kt&&e.has(t)&&i.push(t);return i}_buildFavoritesPane(t,e,i){let r=this._resolveFavoriteMonomers(e),l=this._favoriteTriplets;if(0===r.length&&0===l.length){let e=tt(this._doc,"div",{class:"hw-palette__placeholder","data-testid":"palette-favorites-empty"},["No favorites yet — click the ☆ on any tile to add one."]);return void t.appendChild(e)}for(let[e,i]of this._groupByPolymerAndType(r))t.appendChild(this._renderGroup(e,i));l.length>0&&t.appendChild(this._renderTripletGroup("RNA · Triplets",l,e))}_groupByPolymerAndType(t){let e=new Map;for(let i of t){let t=i.polymerType,r=i.monomerType??"Undefined",l=`${t}|${r}`,s=e.get(l);void 0===s&&(s={pt:t,mt:r,list:[]},e.set(l,s)),s.list.push(i)}let i=t=>{let e=St.indexOf(t);return e<0?99:e},r={Backbone:0,Branch:1,Terminal:2,Undefined:3};return Array.from(e.values()).sort((t,e)=>i(t.pt)-i(e.pt)||(r[t.mt]??9)-(r[e.mt]??9)||t.mt.localeCompare(e.mt)).map(t=>[`${this._polymerLabel(t.pt)} · ${t.mt}`,t.list])}_polymerLabel(t){return At[t]??t}_renderTripletGroup(t,e,i){let r=tt(this._doc,"div",{class:"hw-palette__group","data-natural-analog":t}),l=tt(this._doc,"div",{class:"hw-palette__group-header","data-testid":`palette-group-${t}`},[t]),s=tt(this._doc,"div",{class:"hw-triplet-chips","data-testid":"palette-triplet-favorites"});for(let t of e)s.appendChild(this._renderTripletChip(t,i));return r.appendChild(l),r.appendChild(s),r}_renderTripletChip(t,e){let i=ut(t.sugar,t.base,t.linker),l=e.getMonomerSet(r.BASE).get(t.base)??null,s=M(l,r.BASE,this._theme().colorTheme),o=this.isFavoriteTriplet(t.sugar,t.base,t.linker),n=void 0!==l?.name&&""!==l.name?`${i} — ${l.name}`:i,{root:a}=function(t,e){let i=!1!==e.showStar,r=tt(t,"span",{class:"hw-triplet-chip__star"},[e.favorite?"★":"☆"]),l=tt(t,"span",{class:"hw-triplet-chip__label"},[e.label]),s=["hw-triplet-chip"];e.favorite&&s.push("hw-triplet-chip--favorite");let o=i?[r,l]:[l];return{root:tt(t,"div",{class:s.join(" "),role:"button",tabindex:"0","aria-label":e.title,"data-sugar":e.sugar,"data-base":e.base,"data-linker":e.linker,"data-triplet":e.label,"data-testid":`palette-triplet-${e.label}`,title:e.title,style:`background:${e.background};color:${e.textColor};`},o),star:r}}(this._doc,{sugar:t.sugar,base:t.base,linker:t.linker,label:i,title:n,background:_(s.background),textColor:s.text,favorite:o,showStar:this._opts.allowFavorites});return this._wireTripletChip(a,t),a}_wireTripletChip(t,e){t.addEventListener("mouseenter",t=>{let i=t,r=it(this._doc,"palette-triplet-tooltip","hw-palette-tooltip hw-triplet-tooltip");(function(t,e,i){for(;null!==e.firstChild;)e.removeChild(e.firstChild);e.appendChild(tt(t,"div",{class:"hw-tooltip__symbol"},[i.title]));let r=tt(t,"div",{class:"hw-tooltip__triplet"});for(let e of i.parts){let l=tt(t,"div",{class:"hw-tooltip__triplet-part"});if(l.appendChild(tt(t,"div",{class:"hw-tooltip__triplet-role"},[`${e.role}: ${e.symbol}`])),void 0!==e.name&&""!==e.name&&e.name!==e.symbol&&l.appendChild(tt(t,"div",{class:"hw-tooltip__name"},[e.name])),void 0!==e.rdkitSvg&&null!==e.rdkitSvg&&""!==e.rdkitSvg){let r={class:"hw-tooltip__rdkit"};void 0!==i.rdkitTestid&&(r["data-testid"]=i.rdkitTestid);let s=tt(t,"div",r);s.innerHTML=e.rdkitSvg,l.appendChild(s)}r.appendChild(l)}e.appendChild(r),void 0!==i.hint&&""!==i.hint&&e.appendChild(tt(t,"div",{class:"hw-tooltip__hint"},[i.hint]))})(this._doc,r,{title:ut(e.sugar,e.base,e.linker),parts:this._tripletTooltipParts(e),hint:"Click to add this triplet",rdkitTestid:"palette-triplet-tooltip-rdkit-svg"}),lt(r,"number"==typeof i.clientX?i.clientX:0,"number"==typeof i.clientY?i.clientY:0)}),t.addEventListener("mouseleave",()=>{st(this._doc.body.querySelector('[data-testid="palette-triplet-tooltip"]'))}),t.addEventListener("click",t=>{let i=t.target;if(this._opts.allowFavorites&&!0===i?.classList?.contains("hw-triplet-chip__star"))return this.setFavoriteTriplet(e.sugar,e.base,e.linker,!this.isFavoriteTriplet(e.sugar,e.base,e.linker)),void t.stopPropagation();this._editor.placeRnaTriplet(e.sugar,e.base,e.linker)}),t.addEventListener("keydown",t=>{let i=t;("Enter"===i.key||" "===i.key)&&this._editor.placeRnaTriplet(e.sugar,e.base,e.linker)})}_buildRnaDefaultChips(e){let i=this._pickSymbol(e.getMonomerSet(r.SUGAR),["r","R"]),l=this._pickSymbol(e.getMonomerSet(r.LINKER),["p","P"]),s=e.getMonomerSet(r.BASE);if(null===i||null===l)return null;let o=t._DEFAULT_TRIPLET_BASES.filter(t=>s.has(t));if(0===o.length)return null;let n=tt(this._doc,"div",{class:"hw-triplet-chips hw-triplet-chips--defaults","data-testid":"rna-default-triplets"});for(let t of o)n.appendChild(this._renderTripletChip({sugar:i,base:t,linker:l},e));return n}_tripletTooltipParts(t){let e=this._editor.getService().monomerLib,i=(t,i,r)=>{let l=e.getMonomerSet(i).get(r)??null;return{role:t,symbol:r,...void 0!==l?.name?{name:l.name}:{},rdkitSvg:null===l?null:this._paletteRdkitSvg(l)}};return[i("Sugar",r.SUGAR,t.sugar),i("Base",r.BASE,t.base),i("Linker",r.LINKER,t.linker)]}_pickSymbol(t,e){for(let i of e)if(t.has(i))return i;let i=t.keys().next();return!0===i.done?null:i.value}_restoreRnaSelection(){let t=this._pendingRnaSelection;if(this._pendingRnaSelection=null,null===t||null===this._rnaBuilder)return;let e=this._editor.getService().monomerLib;""!==t.sugar&&e.getMonomerSet(r.SUGAR).has(t.sugar)&&this._rnaBuilder.setField("sugar",t.sugar),""!==t.base&&e.getMonomerSet(r.BASE).has(t.base)&&this._rnaBuilder.setField("base",t.base),""!==t.linker&&e.getMonomerSet(r.LINKER).has(t.linker)&&this._rnaBuilder.setField("linker",t.linker)}_resolveFavoriteMonomers(t){let e=[];for(let i of this._favorites){let r=this._findMonomer(t,i);null!==r&&e.push(r)}return e}_findMonomer(t,e){for(let i of t.getPolymerTypes()){let r=t.getMonomer(i,e);if(null!==r)return r}return null}_buildPolymerPane(t,e,i,r){let s=e,o=this._monomersForPolymer(s,i);if(0===o.length)return;if(s===l.RNA){this._rnaBuilder=new mt(t,this._editor,{documentImpl:this._doc,paletteHooks:this._buildPaletteFilterHooks(),favoriteHooks:this._opts.allowFavorites?{isFavoriteTriplet:(t,e,i)=>this.isFavoriteTriplet(t,e,i),toggleFavoriteTriplet:(t,e,i)=>this.setFavoriteTriplet(t,e,i,!this.isFavoriteTriplet(t,e,i))}:null}),this._restoreRnaSelection();let e=this._buildRnaDefaultChips(i);null!==e&&t.appendChild(e);let r=this._groupRna(o);for(let[e,i]of r)0!==i.length&&t.appendChild(this._renderGroup(e,i));return}if(s===l.PEPTIDE&&this._opts.groupByNaturalAnalog){let e=this._groupByAnalog(o);for(let[i,r]of e){let e=""===i?"Other":i;t.appendChild(this._renderGroup(e,r))}return}let n=tt(this._doc,"div",{class:"hw-palette__group-tiles"}),a=this._editor.getNextAddSymbol(),h=this._sortByColor(o);for(let t of h){let e=this._biotype(t,s);n.appendChild(this._renderTile(t,e,a))}t.appendChild(n)}_renderGroup(t,e){let i=tt(this._doc,"div",{class:"hw-palette__group","data-natural-analog":t}),r=tt(this._doc,"div",{class:"hw-palette__group-header","data-testid":`palette-group-${t}`},[t]),l=tt(this._doc,"div",{class:"hw-palette__group-tiles"}),s=this._editor.getNextAddSymbol(),o=this._sortByColor(e);for(let t of o){let e=this._biotype(t,t.polymerType);l.appendChild(this._renderTile(t,e,s))}return i.appendChild(r),i.appendChild(l),i}_sortByColor(t){let e=this._theme(),i=t.map((t,i)=>{let r=function(t){let e=a(t);if(null===e)return{h:0,s:0,l:0};let[i,r,l]=u(e[0],e[1],e[2]);return{h:i,s:r,l}}(M(t,this._biotype(t,t.polymerType),e.colorTheme).background),l=0===r.s?1:0;return{m:t,idx:i,h:r.h,s:r.s,l:r.l,isGrey:l}});return i.sort((t,e)=>t.isGrey!==e.isGrey?t.isGrey-e.isGrey:t.h!==e.h?t.h-e.h:t.s!==e.s?t.s-e.s:t.l!==e.l?t.l-e.l:t.idx-e.idx),i.map(t=>t.m)}_monomersForPolymer(t,e){let i=e.getMonomerSymbolsByType(t),r=[];for(let l of i){let i=e.getMonomer(t,l);null!==i&&r.push(i)}return r.sort((t,e)=>t.symbol.localeCompare(e.symbol)),r}_groupByAnalog(t){let e=new Map;for(let i of t){let t=i.naturalAnalog??"",r=e.get(t);void 0===r&&(r=[],e.set(t,r)),r.push(i)}let i=[],r=Array.from(e.keys()).sort((t,e)=>""===t&&""!==e?1:""===e&&""!==t?-1:t.localeCompare(e));for(let t of r)i.push([t,e.get(t)]);return new Map(i)}_groupRna(t){let e=[],i=[],l=[],s=[];for(let o of t){let t=$(o);t===r.SUGAR?e.push(o):t===r.BASE?i.push(o):t===r.LINKER?l.push(o):s.push(o)}let o=new Map;return o.set("Backbones",e),o.set("Bases",i),o.set("Linkers",l),s.length>0&&o.set("Other",s),o}_renderTile(t,e,i){let r=this._favorites.has(t.symbol),l=null!==i&&i.symbol===t.symbol&&i.biotype===e,{root:s,star:o}=function(t,e){let i=M(e.monomer,e.biotype,e.theme.colorTheme),r=_(i.background),l=i.text,s=function(t,e){let i=b(t),r=b(e);return(Math.max(i,r)+.05)/(Math.min(i,r)+.05)}(l,r)<5,o=e.monomer.symbol,n=function(t){return t<=3?14:t<=6?11:t<=9?9:8}(o.length),a=`font-size:${n}px;${o.length>=10?"line-height:1.1;letter-spacing:-0.02em;":""}white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:80px;display:inline-block;`,h=tt(t,"span",{class:"hw-palette__star"},[e.favorite?"★":"☆"]),d=tt(t,"span",{class:"hw-palette__label",style:a},[o]),u=["hw-palette__tile"];e.primed&&u.push("hw-palette__tile--primed"),e.favorite&&u.push("hw-palette__tile--favorite"),s&&u.push("hw-palette__tile--low-contrast");let p=void 0!==e.monomer.name?`${o} — ${e.monomer.name}`:o,c=`background:${r};color:${l};width:100%;min-width:48px;padding:4px 6px;height:40px;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis;`;return{root:tt(t,"div",{class:u.join(" "),draggable:"true",role:"button","aria-pressed":e.primed?"true":"false","aria-label":p,"data-symbol":o,"data-biotype":e.biotype,"data-bg":r,"data-raw-bg":i.background,"data-testid":`palette-tile-${o}`,title:p,style:c},[h,d]),star:h}}(this._doc,{monomer:t,biotype:e,theme:this._theme(),favorite:r,primed:l});return this._wireTile(s,o,t,e),s}_rdkit(){let t=this._editor.getService().options?.rdkitModule;return t??null}_paletteRdkitSvg(e){let i=e.smiles;if(void 0===i||""===i)return null;let r=this._rdkit();if(null===r)return null;let l=`${e.polymerType}:${e.symbol}`;if(this._paletteRdkitCache.has(l))return this._paletteRdkitCache.get(l)??null;let s=et(r,i,220,140);if(this._paletteRdkitCache.size>=t._PALETTE_RDKIT_CACHE_LIMIT){let t=this._paletteRdkitCache.keys().next().value;void 0!==t&&this._paletteRdkitCache.delete(t)}return this._paletteRdkitCache.set(l,s),s}_wireTile(t,e,i,r){t.addEventListener("mouseenter",t=>{let e=t,r=it(this._doc,"palette-tooltip","hw-palette-tooltip");rt(this._doc,r,{symbol:i.symbol,name:i.name??"",rdkitSvg:this._paletteRdkitSvg(i),rdkitTestid:"palette-tooltip-rdkit-svg"}),lt(r,"number"==typeof e.clientX?e.clientX:0,"number"==typeof e.clientY?e.clientY:0)}),t.addEventListener("mouseleave",()=>{st(this._doc.body.querySelector('[data-testid="palette-tooltip"]'))}),t.addEventListener("click",t=>{let e=t.target;if(this._opts.allowFavorites&&void 0!==e&&!0===e?.classList?.contains("hw-palette__star"))return this.setFavorite(i.symbol,!this._favorites.has(i.symbol)),void t.stopPropagation();if(null!==this._activeBiotypeFilter&&this._activeBiotypeFilter===r){let e=this._pickResolver;return this._teardownPickMode(),e?.(i.symbol),this._scrollActivePaneToTop(),void t.stopPropagation()}let l=this._editor.getSelection();if(l.atoms.size>0){let e=this._editor.getMol(),s=[];for(let t of l.atoms){let i=e.atoms.find(e=>e.id===t);void 0!==i&&s.push(i)}return s.length>0&&s.every(t=>t.biotype===r)?(this._editor.replaceMonomers(s,i.symbol),void t.stopPropagation()):(this._editor.fire("editor:status",{message:`Cannot bulk-replace ${s.length} selected atom(s) with ${i.symbol}: selection contains incompatible biotypes for ${r}.`,severity:"warn",durationMs:3e3}),void t.stopPropagation())}let s=this._editor.getNextAddSymbol();if(null!==s&&s.symbol===i.symbol&&s.biotype===r)return this._editor.setNextAddSymbol(null),void this._updatePrimedClasses();this._editor.setNextAddSymbol(i.symbol,r),this._updatePrimedClasses()}),t.addEventListener("dragstart",t=>{let e=t.dataTransfer;if(null!=e)try{e.setData("application/x-hwe-monomer",JSON.stringify({symbol:i.symbol,biotype:r})),e.effectAllowed="copy"}catch{}st(this._doc.body.querySelector('[data-testid="palette-tooltip"]')),this._editor.startPaletteDrag(i.symbol,r)})}_biotype(t,e){let i=$(t);if(null!==i)return i;switch(e){case l.PEPTIDE:return r.AA;case l.RNA:return r.SUGAR;case l.CHEM:return r.CHEM;case l.BLOB:return r.BLOB;default:return r.CHEM}}_theme(){let t=this._editor;return"function"==typeof t._currentTheme?t._currentTheme():this._editor.getService().theme}_applyFilter(){let t=this._filter,e=this._activeBiotypeFilter,i=this.element.querySelector(`.hw-palette__pane[data-tab="${this._activeTab}"]`),r=(i??this.element).querySelectorAll(".hw-palette__tile");for(let i=0;i<r.length;i++){let l=r[i],s=(l.getAttribute("data-symbol")??"").toLowerCase(),o=(l.getAttribute("title")??"").toLowerCase(),n=l.getAttribute("data-biotype")??"",a=(""===t||s.indexOf(t)>=0||o.indexOf(t)>=0)&&(null===e||n===e);l.style.display=a?"":"none"}let l=(i??this.element).querySelectorAll(".hw-triplet-chip");for(let i=0;i<l.length;i++){let r=l[i],s=[r.getAttribute("data-triplet")??"",r.getAttribute("data-sugar")??"",r.getAttribute("data-base")??"",r.getAttribute("data-linker")??""].join(" ").toLowerCase(),o=(""===t||s.indexOf(t)>=0)&&null===e;r.style.display=o?"":"none"}let s=(i??this.element).querySelectorAll(".hw-palette__group");for(let t=0;t<s.length;t++){let e=s[t],i=e.querySelectorAll(".hw-palette__tile, .hw-triplet-chip"),r=!1;for(let t=0;t<i.length;t++)if("none"!==i[t].style.display){r=!0;break}r?(e.removeAttribute("hidden"),e.removeAttribute("data-section-empty")):(e.setAttribute("hidden",""),e.setAttribute("data-section-empty","true"))}}_updatePrimedClasses(){let t=this._editor.getNextAddSymbol(),e=this.element.querySelectorAll(".hw-palette__tile");for(let i=0;i<e.length;i++){let r=e[i],l=r.getAttribute("data-symbol")??"",s=r.getAttribute("data-biotype")??"",o=null!==t&&t.symbol===l&&t.biotype===s,n=(r.getAttribute("class")??"").split(/\s+/).filter(t=>"hw-palette__tile--primed"!==t).join(" ");r.setAttribute("class",o?`${n} hw-palette__tile--primed`:n),r.setAttribute("aria-pressed",o?"true":"false")}}_applyActiveTabClasses(){let t=this.element.querySelectorAll(".hw-palette__tab");for(let e=0;e<t.length;e++){let i=t[e],r=i.getAttribute("data-tab")??"";i.setAttribute("aria-selected",r===this._activeTab?"true":"false")}let e=this.element.querySelectorAll(".hw-palette__pane");for(let t=0;t<e.length;t++){let i=e[t];(i.getAttribute("data-tab")??"")===this._activeTab?i.removeAttribute("hidden"):i.setAttribute("hidden","")}}_localStorage(){if(!this._opts.allowFavorites)return null;let t=this._doc.defaultView;if(null==t)return null;try{return t.localStorage??null}catch{return null}}_resolveInitialTab(t){if(void 0!==t&&St.includes(t))return t;let e=this._localStorage();if(null!==e)try{let t=e.getItem(Tt);if(null!==t&&St.includes(t))return t}catch{}return kt}_persistActiveTab(){let t=this._localStorage();if(null!==t)try{t.setItem(Tt,this._activeTab)}catch{}}_loadFavorites(){let t=this._localStorage();if(null!==t){try{let e=t.getItem(Ct);if(null!==e&&""!==e){let t=JSON.parse(e),i=this._extractSymbols(t);for(let t of i)this._favorites.add(t);for(let e of this._extractTriplets(t))this._favoriteTriplets.push(e);return}}catch{}try{let e=t.getItem("hwe.palette.favorites");if(null===e||""===e)return;let i=JSON.parse(e);if(Array.isArray(i)){for(let t of i){if("string"!=typeof t)continue;let e=t.indexOf("|"),i=e>=0?t.slice(e+1):t;""!==i&&this._favorites.add(i)}this._saveFavorites()}}catch{}}}_extractSymbols(t){if(Array.isArray(t)){let e=[];for(let i of t)"string"==typeof i&&e.push(i);return e}if(null!==t&&"object"==typeof t){let e=t;if(Array.isArray(e.symbols)){let t=[];for(let i of e.symbols)"string"==typeof i&&t.push(i);return t}}return[]}_extractTriplets(t){if(null===t||"object"!=typeof t)return[];let e=t;if(!Array.isArray(e.triplets))return[];let i=[];for(let t of e.triplets){if(null===t||"object"!=typeof t)continue;let e=t;"string"==typeof e.sugar&&"string"==typeof e.base&&"string"==typeof e.linker&&i.push({sugar:e.sugar,base:e.base,linker:e.linker})}return i}_saveFavorites(){let t=this._localStorage();if(null!==t)try{let e={symbols:Array.from(this._favorites)};this._favoriteTriplets.length>0&&(e.triplets=this._favoriteTriplets.map(t=>({...t}))),t.setItem(Ct,JSON.stringify(e))}catch{}}};xt._DEFAULT_TRIPLET_BASES=["A","C","G","U","T"],xt._PALETTE_RDKIT_CACHE_LIMIT=256;new Set([l.PEPTIDE,l.RNA,l.CHEM,l.BLOB]),new Set(["Backbone","Branch","Terminal","Undefined"])}},r={};function l(t){var e=r[t];if(void 0!==e)return e.exports;var s=r[t]={exports:{}};return i[t](s,s.exports,l),s.exports}l.m=i,l.x=()=>{var t=l.O(void 0,[137],()=>l(330));return l.O(t)},t=[],l.O=(e,i,r,s)=>{if(!i){var o=1/0;for(d=0;d<t.length;d++){for(var[i,r,s]=t[d],n=!0,a=0;a<i.length;a++)(!1&s||o>=s)&&Object.keys(l.O).every(t=>l.O[t](i[a]))?i.splice(a--,1):(n=!1,s<o&&(o=s));if(n){t.splice(d--,1);var h=r();void 0!==h&&(e=h)}}return e}s=s||0;for(var d=t.length;d>0&&t[d-1][2]>s;d--)t[d]=t[d-1];t[d]=[i,r,s]},l.d=(t,e)=>{for(var i in e)l.o(e,i)&&!l.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},l.f={},l.e=t=>Promise.all(Object.keys(l.f).reduce((e,i)=>(l.f[i](t,e),e),[])),l.u=t=>t+".js",l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),l.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{var t;l.g.importScripts&&(t=l.g.location+"");var e=l.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var i=e.getElementsByTagName("script");if(i.length)for(var r=i.length-1;r>-1&&(!t||!/^http(s?):/.test(t));)t=i[r--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),l.p=t})(),(()=>{var t={94:1};l.f.i=(e,i)=>{t[e]||importScripts(l.p+l.u(e))};var e=self.webpackChunkhelm=self.webpackChunkhelm||[],i=e.push.bind(e);e.push=e=>{var[r,s,o]=e;for(var n in s)l.o(s,n)&&(l.m[n]=s[n]);for(o&&o(l);r.length;)t[r.pop()]=1;i(e)}})(),e=l.x,l.x=()=>l.e(137).then(e);var s=l.x();helm=s})();
2
- //# sourceMappingURL=94.js.map