import './async-D55cHugf.js';
import { d as bind_props, e as ensure_array_like, g as attr_style, f as attr_class, a as attr, c as spread_props } from './index-u8mz_F03.js';
import './2-BLdXJizP.js';
import { o } from './Clear-D7Yjckqz.js';
import { G } from './Block-DZmzQwnI.js';
import { k } from './BlockLabel-bKYWnOzQ.js';
import { p } from './Empty-DGRbZO0a.js';
import { $ } from './utils.svelte-B2py64Fz.js';
import { y } from './IconButtonWrapper-CjFRPb3y.js';
import { W } from './index3-Df92vI-L.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './context-CBkBucIx.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import './index-Cg-Pg6j3.js';
import './clone-Yk88IHKV.js';
import './IconButton-BRnu7KaR.js';

function I(s){s.push('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--carbon" width="100%" height="100%" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path fill="currentColor" d="M12 15H5a3 3 0 0 1-3-3v-2a3 3 0 0 1 3-3h5V5a1 1 0 0 0-1-1H3V2h6a3 3 0 0 1 3 3zM5 9a1 1 0 0 0-1 1v2a1 1 0 0 0 1 1h5V9zm15 14v2a1 1 0 0 0 1 1h5v-4h-5a1 1 0 0 0-1 1z"></path><path fill="currentColor" d="M2 30h28V2Zm26-2h-7a3 3 0 0 1-3-3v-2a3 3 0 0 1 3-3h5v-2a1 1 0 0 0-1-1h-6v-2h6a3 3 0 0 1 3 3Z"></path></svg>');}function R(s){if(!s)return  true;const c=s.toLowerCase().trim();return c==="transparent"||c.length===9&&c.endsWith("00")}function P(s,c){if(s.length===0)return [];const p=[];let u=s[0].token,r=s[0].class_or_confidence;for(let o=1;o<s.length;o++){const{token:e,class_or_confidence:h}=s[o];r===h?u+=e:(p.push({token:u,class_or_confidence:r}),u=e,r=h);}return p.push({token:u,class_or_confidence:r}),p}function Q(s){return s===null?"":s<0?`rgba(128, 90, 213, ${-s})`:`rgba(239, 68, 60, ${s})`}function U(s,c){s.component(p=>{let{value:u=[],label_to_edit:r=-1,category:o,active_legend:e,color_map:h,label_index:_,token:m,onchange:w,is_scores_mode:d=false}=c,a=o?.toString()??"";function n(){if(d){const f=typeof o=="number"?o:parseFloat(o??"0");return Q(f)}return o===null||e&&e!==o?"":h[o]?.primary??""}p.push(`<input class="label-input svelte-14ic1z3" autofocus${attr("type",d?"number":"text")}${attr("step",d?"0.1":void 0)}${attr("placeholder",d?void 0:"label")}${attr("value",o)}${attr_style("",{"background-color":n(),width:d?"7ch":`${(a?.length||4)+4}ch`})}/>`),bind_props(c,{value:u,label_to_edit:r});});}function X(s,c){s.component(p=>{let {value:u=[],show_legend:r=false,show_inline_category:o$1=true,color_map:e={},show_whitespaces:h=false,interactive:_=false,onselect:m,onchange:w}=c,a="",n=-1,k={};function A(){w?.(u),n=-1;}function C(t){return t===null?"":k[t]?.secondary??""}function O(t){return t===null?"":k[t]?.primary??""}function T(t){const b=C(t);return R(b)?"":"black"}let y=true,M;function G(t){t.push('<div class="container svelte-1akrbo3">');{if(t.push("<!--[-->"),r){t.push("<!--[-->"),t.push('<div class="legend svelte-1akrbo3" data-testid="highlighted-text:category-legend"><!--[-->');const g=ensure_array_like(Object.entries(k));for(let v=0,x=g.length;v<x;v++){let[i,B]=g[v];t.push(`<button class="legend-item svelte-1akrbo3"${attr_style("",{"background-color":B.secondary})}>${escape_html(i)}</button>`);}t.push("<!--]--></div>");}else t.push("<!--[!-->");t.push('<!--]--> <div class="textfield svelte-1akrbo3"><!--[-->');const b=ensure_array_like(u);for(let g=0,v=b.length;g<v;g++){let{token:x,class_or_confidence:i}=b[g];const B=x.split(`
`);t.push("<!--[-->");const E=ensure_array_like(B);for(let L=0,W=E.length;L<W;L++){let S=E[L];if(h?S!=="":S.trim()){t.push("<!--[-->");const H=C(i);t.push(`<span class="token-container svelte-1akrbo3"><span${attr_class("token svelte-1akrbo3",void 0,{highlighted:i!==null,transparent:i!==null&&R(H),dimmed:a})}${attr("role",i!==null?"button":void 0)}${attr("tabindex",i!==null?0:void 0)}${attr_style("",{"background-color":H,color:T(i)})}><span${attr_class("text svelte-1akrbo3",void 0,{unlabeled:i===null})}>${escape_html(S)}</span> `),!r&&o$1&&i!==null&&n!==g?(t.push("<!--[-->"),t.push(`<span class="label svelte-1akrbo3"${attr_style("",{"background-color":O(i)})}>${escape_html(i)}</span>`)):t.push("<!--[!-->"),t.push("<!--]--> "),_&&n===g&&i!==null?(t.push("<!--[-->"),U(t,{category:i,active_legend:a,color_map:k,label_index:g,token:x,onchange:A,get value(){return u},set value(z){u=z,y=false;},get label_to_edit(){return n},set label_to_edit(z){n=z,y=false;}})):t.push("<!--[!-->"),t.push("<!--]--></span> "),_&&i!==null?(t.push("<!--[-->"),t.push('<button class="remove-btn svelte-1akrbo3" aria-label="Remove label">'),o(t),t.push("<!----></button>")):t.push("<!--[!-->"),t.push("<!--]--></span>");}else t.push("<!--[!-->");t.push("<!--]--> "),L<B.length-1?(t.push("<!--[-->"),t.push('<span class="line-break svelte-1akrbo3"></span>')):t.push("<!--[!-->"),t.push("<!--]-->");}t.push("<!--]-->");}t.push("<!--]--></div>");}t.push("<!--]--></div>");}do y=true,M=p.copy(),G(M);while(!y);p.subsume(M),bind_props(c,{value:u});});}function _t(s,c){s.component(p$1=>{const{$$slots:u,$$events:r,...o}=c,e=new $(o);e.props.value;let h=e.props.combine_adjacent?P(e.props.value||[]):e.props.value,_=true,m;function w(d){G(d,{variant:e.shared.interactive?"dashed":"solid",test_id:"highlighted-text",visible:e.shared.visible,elem_id:e.shared.elem_id,elem_classes:e.shared.elem_classes,padding:false,container:e.shared.container,scale:e.shared.scale,min_width:e.shared.min_width,rtl:e.props.rtl,children:a=>{W(a,spread_props([{autoscroll:e.shared.autoscroll,i18n:e.i18n},e.shared.loading_status,{onclearstatus:()=>e.dispatch("clear_status",e.shared.loading_status)}])),a.push("<!----> "),e.shared.interactive&&e.shared.label&&e.shared.show_label&&e.props.buttons?.length?(a.push("<!--[-->"),y(a,{buttons:e.props.buttons,on_custom_button_click:n=>e.dispatch("custom_button_click",{id:n})})):a.push("<!--[!-->"),a.push("<!--]--> "),e.shared.label&&e.shared.show_label?(a.push("<!--[-->"),k(a,{Icon:I,label:e.shared.label||e.i18n("highlighted_text.highlighted_text"),float:false,disable:e.shared.container===false,show_label:e.shared.show_label,rtl:e.props.rtl})):a.push("<!--[!-->"),a.push("<!--]--> "),h?(a.push("<!--[-->"),X(a,{interactive:e.shared.interactive,show_legend:e.props.show_legend,show_inline_category:e.props.show_inline_category,show_whitespaces:e.props.show_whitespaces,color_map:e.props.color_map,onselect:n=>e.dispatch("select",n),onchange:()=>{e.props.value=h,e.dispatch("change");},get value(){return h},set value(n){h=n,_=false;}})):(a.push("<!--[!-->"),p(a,{size:e.shared.interactive?"small":"large",unpadded_box:e.shared.interactive,children:n=>{I(n);},$$slots:{default:true}})),a.push("<!--]-->");},$$slots:{default:true}});}do _=true,m=p$1.copy(),w(m);while(!_);p$1.subsume(m);});}

export { X as BaseHighlightedText, _t as default };
//# sourceMappingURL=Index48-DXYf4HkK.js.map
