From 2613673f9e48a30d89236597d8ce3d64c3b21d4f Mon Sep 17 00:00:00 2001 From: Mattias Bodlund Date: Thu, 15 May 2025 09:17:53 +0200 Subject: [PATCH] na --- Gemfile.lock | 6 +- app/assets/images/ikea-foundation-203x22.svg | 6 ++ app/assets/stylesheets/application.css | 19 ++++- app/controllers/questions_controller.rb | 1 + app/helpers/questions_helper.rb | 85 ++++++++++++++++++++ app/views/languages/index.html.erb | 11 +-- app/views/layouts/application.html.erb | 2 +- app/views/questions/show.html.erb | 9 ++- config/importmap.rb | 2 +- vendor/javascript/trix.js | 6 +- 10 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 app/assets/images/ikea-foundation-203x22.svg diff --git a/Gemfile.lock b/Gemfile.lock index 10ee345..ff2bf84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,7 +84,7 @@ GEM benchmark (0.4.0) bigdecimal (3.1.9) bindex (0.8.1) - bootsnap (1.18.4) + bootsnap (1.18.5) msgpack (~> 1.2) builder (3.3.0) concurrent-ruby (1.3.5) @@ -156,7 +156,7 @@ GEM benchmark logger mini_mime (1.1.5) - mini_portile2 (2.8.8) + mini_portile2 (2.8.9) minitest (5.25.5) mobility (1.3.2) i18n (>= 0.6.10, < 2) @@ -205,7 +205,7 @@ GEM activesupport (>= 7.0.0) rack railties (>= 7.0.0) - psych (5.2.5) + psych (5.2.6) date stringio public_suffix (6.0.2) diff --git a/app/assets/images/ikea-foundation-203x22.svg b/app/assets/images/ikea-foundation-203x22.svg new file mode 100644 index 0000000..563d008 --- /dev/null +++ b/app/assets/images/ikea-foundation-203x22.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f9e6150..88f50bb 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -128,11 +128,24 @@ header { flex-grow: 0; & svg { - width: 70px; + width: 203px; height: auto; + max-width: 60vw; } } +path.logo-text { + fill: var(--clr-black); +} + +:has(main .background-container) { + & header path.logo-text { + fill: var(--clr-white); + } + & footer { + color: var(--clr-white); + } +} footer { position: fixed; @@ -480,9 +493,7 @@ label { top: 2rem; left: 3rem; - & svg { - width: 80px; - } + } main { diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 09d4cc6..a256ba9 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -7,6 +7,7 @@ class QuestionsController < ApplicationController not_found unless question @answer = Answer.new(player_id: current_player.id, node_id: question.id) + end diff --git a/app/helpers/questions_helper.rb b/app/helpers/questions_helper.rb index 2eaab4a..30dc0d2 100644 --- a/app/helpers/questions_helper.rb +++ b/app/helpers/questions_helper.rb @@ -1,2 +1,87 @@ module QuestionsHelper + + def image_orientation(file_attachment) + return nil unless file_attachment&.attached? + + metadata = file_attachment.blob.metadata + width = metadata[:width] || 0 + height = metadata[:height] || 0 + + if width > height + :landscape + elsif height > width + :portrait + else + :square + end + end + + def responsive_picture_tag_for_question(question) + # assets = question.assets.includes(file_attachment: :blob).to_a + assets = question.assets.includes(file_attachment: :blob).select{ |asset| asset.file.image? }.to_a + + # Find one landscape and one portrait image + landscape_asset = assets.find { |asset| image_orientation(asset.file) == :landscape } + portrait_asset = assets.find { |asset| image_orientation(asset.file) == :portrait } + + # Fall back to any image if specific orientation not found + landscape_asset ||= portrait_asset + portrait_asset ||= landscape_asset + + # If we have at least one image + if landscape_asset || portrait_asset + primary_asset = landscape_asset || portrait_asset + + # If we have both orientations, create a responsive picture tag + if landscape_asset && portrait_asset && landscape_asset != portrait_asset + render_responsive_picture(landscape_asset, portrait_asset) + else + # Just one orientation available, create a simple picture tag + render_simple_picture(primary_asset) + end + else + # No images available + + content_tag(:div, "No images available", class: "no-images") + end + end + +private + + def render_responsive_picture(landscape_asset, portrait_asset) + content_tag(:picture) do + concat( + content_tag(:source, "", + media: "(orientation: portrait)", + srcset: rails_storage_proxy_path(portrait_asset.file.variant(resize_to_limit: [800, nil])) + " 800w, " + + rails_storage_proxy_path(portrait_asset.file.variant(resize_to_limit: [1600, nil])) + " 1600w, " + + rails_storage_proxy_path(portrait_asset.file.variant(resize_to_limit: [2400, nil])) + " 2400w", + sizes: "100vw" + ) + ) + + concat( + image_tag( + rails_storage_proxy_path(landscape_asset.file.variant(resize_to_limit: [800, nil])), + srcset: rails_storage_proxy_path(landscape_asset.file.variant(resize_to_limit: [800, nil])) + " 800w, " + + rails_storage_proxy_path(landscape_asset.file.variant(resize_to_limit: [1600, nil])) + " 1600w, " + + rails_storage_proxy_path(landscape_asset.file.variant(resize_to_limit: [2400, nil])) + " 2400w", + sizes: "100vw" + ) + ) + end + end + + def render_simple_picture(asset) + content_tag(:picture) do + image_tag( + rails_storage_proxy_path(asset.file.variant(resize_to_limit: [800, nil])), + srcset: rails_storage_proxy_path(asset.file.variant(resize_to_limit: [800, nil])) + " 800w, " + + rails_storage_proxy_path(asset.file.variant(resize_to_limit: [1600, nil])) + " 1600w, " + + rails_storage_proxy_path(asset.file.variant(resize_to_limit: [2400, nil])) + " 2400w", + sizes: "100vw" + ) + end + end + end diff --git a/app/views/languages/index.html.erb b/app/views/languages/index.html.erb index f919140..b1f7e01 100644 --- a/app/views/languages/index.html.erb +++ b/app/views/languages/index.html.erb @@ -1,15 +1,10 @@ <%- content_for :title, t('project_name') %> -<% Array(@node.assets.select{ |asset| asset.file.image? }.first).each do |asset| %> +
- <%= image_tag rails_storage_proxy_path(asset.file.representation(resize_to_limit: [800,nil], format: :jpg)), - srcset: "#{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [800,nil], format: :jpg))} 800w, - #{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [1600,nil], format: :jpg))} 1600w, - #{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [2400,nil], format: :jpg))} 2400w", - sizes: "100vw" - %> + <%= responsive_picture_tag_for_question(@node) %>
-<% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3f88365..4f6ad37 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -25,7 +25,7 @@
- <%= link_to svg('ikea-foundation-logo'), root_url %> + <%= link_to svg('ikea-foundation-203x22'), root_url %>
diff --git a/app/views/questions/show.html.erb b/app/views/questions/show.html.erb index a72120f..fd204d7 100644 --- a/app/views/questions/show.html.erb +++ b/app/views/questions/show.html.erb @@ -3,16 +3,17 @@ content_for :meta_description, question.page_description %> -<% Array(question.assets.select{ |asset| asset.file.image? }.first).each do |asset| %> +<%# Array(question.assets.select{ |asset| asset.file.image? }.first).each do |asset| %>
- <%= image_tag rails_storage_proxy_path(asset.file.representation(resize_to_limit: [800,nil], format: :jpg)), + <%# image_tag rails_storage_proxy_path(asset.file.representation(resize_to_limit: [800,nil], format: :jpg)), srcset: "#{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [800,nil], format: :jpg))} 800w, #{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [1600,nil], format: :jpg))} 1600w, #{rails_storage_proxy_path(asset.file.representation(resize_to_limit: [2400,nil], format: :jpg))} 2400w", sizes: "100vw" - %> + %> + <%= responsive_picture_tag_for_question(question) %>
-<% end %> +<%# end %> <%= form_with model: @answer, url: url_for(controller: 'answers', action: 'create') do |form| %> diff --git a/config/importmap.rb b/config/importmap.rb index ea2c433..b3a72c3 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -10,7 +10,7 @@ pin "stimulus-use" # @0.52.3 pin "@rails/request.js", to: "@rails--request.js.js" # @0.0.12 pin "@rails/activestorage", to: "@rails--activestorage.js" # @8.0.200 pin "tom-select", to: "tom-select--dist--js--tom-select.base.min.js.js" # @2.4.3 -pin "trix" # @2.1.14 +pin "trix" # @2.1.15 # site_helper pin "application", preload: false diff --git a/vendor/javascript/trix.js b/vendor/javascript/trix.js index b40de45..5809a45 100644 --- a/vendor/javascript/trix.js +++ b/vendor/javascript/trix.js @@ -1,5 +1,5 @@ -// trix@2.1.14 downloaded from https://ga.jspm.io/npm:trix@2.1.14/dist/trix.esm.min.js +// trix@2.1.15 downloaded from https://ga.jspm.io/npm:trix@2.1.15/dist/trix.esm.min.js -var o="2.1.14";const s="[data-trix-attachment]",a={preview:{presentation:"gallery",caption:{name:!0,size:!0}},file:{caption:{size:!0}}},l={default:{tagName:"div",parse:!1},quote:{tagName:"blockquote",nestable:!0},heading1:{tagName:"h1",terminal:!0,breakOnReturn:!0,group:!1},code:{tagName:"pre",terminal:!0,htmlAttributes:["language"],text:{plaintext:!0}},bulletList:{tagName:"ul",parse:!1},bullet:{tagName:"li",listAttribute:"bulletList",group:!1,nestable:!0,test(o){return r(o.parentNode)===l[this.listAttribute].tagName}},numberList:{tagName:"ol",parse:!1},number:{tagName:"li",listAttribute:"numberList",group:!1,nestable:!0,test(o){return r(o.parentNode)===l[this.listAttribute].tagName}},attachmentGallery:{tagName:"div",exclusive:!0,terminal:!0,parse:!1,group:!1}},r=o=>{var s;return null==o||null===(s=o.tagName)||void 0===s?void 0:s.toLowerCase()},c=navigator.userAgent.match(/android\s([0-9]+.*Chrome)/i),h=c&&parseInt(c[1]);var d={composesExistingText:/Android.*Chrome/.test(navigator.userAgent),recentAndroid:h&&h>12,samsungAndroid:h&&navigator.userAgent.match(/Android.*SM-/),forcesObjectResizing:/Trident.*rv:11/.test(navigator.userAgent),supportsInputEvents:"undefined"!=typeof InputEvent&&["data","getTargetRanges","inputType"].every((o=>o in InputEvent.prototype))},g={ADD_ATTR:["language"],SAFE_FOR_XML:!1,RETURN_DOM:!0},p={attachFiles:"Attach Files",bold:"Bold",bullets:"Bullets",byte:"Byte",bytes:"Bytes",captionPlaceholder:"Add a caption…",code:"Code",heading1:"Heading",indent:"Increase Level",italic:"Italic",link:"Link",numbers:"Numbers",outdent:"Decrease Level",quote:"Quote",redo:"Redo",remove:"Remove",strike:"Strikethrough",undo:"Undo",unlink:"Unlink",url:"URL",urlPlaceholder:"Enter a URL…",GB:"GB",KB:"KB",MB:"MB",PB:"PB",TB:"TB"};const f=[p.bytes,p.KB,p.MB,p.GB,p.TB,p.PB];var w={prefix:"IEC",precision:2,formatter(o){switch(o){case 0:return"0 ".concat(p.bytes);case 1:return"1 ".concat(p.byte);default:let s;"SI"===this.prefix?s=1e3:"IEC"===this.prefix&&(s=1024);const a=Math.floor(Math.log(o)/Math.log(s)),l=(o/Math.pow(s,a)).toFixed(this.precision).replace(/0*$/,"").replace(/\.$/,"");return"".concat(l," ").concat(f[a])}}};const _="\ufeff",j=" ",m=function(o){for(const s in o){const a=o[s];this[s]=a}return this},W=document.documentElement,U=W.matches,b=function(o){let{onElement:s,matchingSelector:a,withCallback:l,inPhase:c,preventDefault:h,times:d}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const g=s||W,p=a,f="capturing"===c,u=function(o){null!=d&&0==--d&&u.destroy();const s=y(o.target,{matchingSelector:p});null!=s&&(null==l||l.call(s,o,s),h&&o.preventDefault())};return u.destroy=()=>g.removeEventListener(o,u,f),g.addEventListener(o,u,f),u},v=function(o){let{onElement:s,bubbles:a,cancelable:l,attributes:c}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const h=null!=s?s:W;a=!1!==a,l=!1!==l;const d=document.createEvent("Events");return d.initEvent(o,a,l),null!=c&&m.call(d,c),h.dispatchEvent(d)},A=function(o,s){if(1===(null==o?void 0:o.nodeType))return U.call(o,s)},y=function(o){let{matchingSelector:s,untilNode:a}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(;o&&o.nodeType!==Node.ELEMENT_NODE;)o=o.parentNode;if(null!=o){if(null==s)return o;if(o.closest&&null==a)return o.closest(s);for(;o&&o!==a;){if(A(o,s))return o;o=o.parentNode}}},x=o=>document.activeElement!==o&&C(o,document.activeElement),C=function(o,s){if(o&&s)for(;s;){if(s===o)return!0;s=s.parentNode}},E=function(o){var s;if(null===(s=o)||void 0===s||!s.parentNode)return;let a=0;for(o=o.previousSibling;o;)a++,o=o.previousSibling;return a},S=o=>{var s;return null==o||null===(s=o.parentNode)||void 0===s?void 0:s.removeChild(o)},R=function(o){let{onlyNodesOfType:s,usingFilter:a,expandEntityReferences:l}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const c=(()=>{switch(s){case"element":return NodeFilter.SHOW_ELEMENT;case"text":return NodeFilter.SHOW_TEXT;case"comment":return NodeFilter.SHOW_COMMENT;default:return NodeFilter.SHOW_ALL}})();return document.createTreeWalker(o,c,null!=a?a:null,!0===l)},k=o=>{var s;return null==o||null===(s=o.tagName)||void 0===s?void 0:s.toLowerCase()},T=function(o){let s,a,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"==typeof o?(l=o,o=l.tagName):l={attributes:l};const c=document.createElement(o);if(null!=l.editable&&(null==l.attributes&&(l.attributes={}),l.attributes.contenteditable=l.editable),l.attributes)for(s in l.attributes)a=l.attributes[s],c.setAttribute(s,a);if(l.style)for(s in l.style)a=l.style[s],c.style[s]=a;if(l.data)for(s in l.data)a=l.data[s],c.dataset[s]=a;return l.className&&l.className.split(" ").forEach((o=>{c.classList.add(o)})),l.textContent&&(c.textContent=l.textContent),l.childNodes&&[].concat(l.childNodes).forEach((o=>{c.appendChild(o)})),c};let V;const L=function(){if(null!=V)return V;V=[];for(const o in l){const s=l[o];s.tagName&&V.push(s.tagName)}return V},D=o=>I(null==o?void 0:o.firstChild),N=function(o){let{strict:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{strict:!0};return s?I(o):I(o)||!I(o.firstChild)&&function(o){return L().includes(k(o))&&!L().includes(k(o.firstChild))}(o)},I=o=>O(o)&&"block"===(null==o?void 0:o.data),O=o=>(null==o?void 0:o.nodeType)===Node.COMMENT_NODE,F=function(o){let{name:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(o)return B(o)?o.data===_?!s||o.parentNode.dataset.trixCursorTarget===s:void 0:F(o.firstChild)},P=o=>A(o,s),M=o=>B(o)&&""===(null==o?void 0:o.data),B=o=>(null==o?void 0:o.nodeType)===Node.TEXT_NODE,z={level2Enabled:!0,getLevel(){return this.level2Enabled&&d.supportsInputEvents?2:0},pickFiles(o){const s=T("input",{type:"file",multiple:!0,hidden:!0,id:this.fileInputId});s.addEventListener("change",(()=>{o(s.files),S(s)})),S(document.getElementById(this.fileInputId)),document.body.appendChild(s),s.click()}};var J={removeBlankTableCells:!1,tableCellSeparator:" | ",tableRowSeparator:"\n"},K={bold:{tagName:"strong",inheritable:!0,parser(o){const s=window.getComputedStyle(o);return"bold"===s.fontWeight||s.fontWeight>=600}},italic:{tagName:"em",inheritable:!0,parser:o=>"italic"===window.getComputedStyle(o).fontStyle},href:{groupTagName:"a",parser(o){const a="a:not(".concat(s,")"),l=o.closest(a);if(l)return l.getAttribute("href")}},strike:{tagName:"del",inheritable:!0},frozen:{style:{backgroundColor:"highlight"}}},G={getDefaultHTML:()=>'
\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n\n \n \n \n \n
\n\n
\n \n
')};const Y={interval:5e3};var $=Object.freeze({__proto__:null,attachments:a,blockAttributes:l,browser:d,css:{attachment:"attachment",attachmentCaption:"attachment__caption",attachmentCaptionEditor:"attachment__caption-editor",attachmentMetadata:"attachment__metadata",attachmentMetadataContainer:"attachment__metadata-container",attachmentName:"attachment__name",attachmentProgress:"attachment__progress",attachmentSize:"attachment__size",attachmentToolbar:"attachment__toolbar",attachmentGallery:"attachment-gallery"},dompurify:g,fileSize:w,input:z,keyNames:{8:"backspace",9:"tab",13:"return",27:"escape",37:"left",39:"right",46:"delete",68:"d",72:"h",79:"o"},lang:p,parser:J,textAttributes:K,toolbar:G,undo:Y});class q{static proxyMethod(o){const{name:s,toMethod:a,toProperty:l,optional:c}=H(o);this.prototype[s]=function(){let o,h;var d,g;a?h=c?null===(d=this[a])||void 0===d?void 0:d.call(this):this[a]():l&&(h=this[l]);return c?(o=null===(g=h)||void 0===g?void 0:g[s],o?Z.call(o,h,arguments):void 0):(o=h[s],Z.call(o,h,arguments))}}}const H=function(o){const s=o.match(Q);if(!s)throw new Error("can't parse @proxyMethod expression: ".concat(o));const a={name:s[4]};return null!=s[2]?a.toMethod=s[1]:a.toProperty=s[1],null!=s[3]&&(a.optional=!0),a},{apply:Z}=Function.prototype,Q=new RegExp("^(.+?)(\\(\\))?(\\?)?\\.(.+?)$");var tt,et,it;class X extends q{static box(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return o instanceof this?o:this.fromUCS2String(null==o?void 0:o.toString())}static fromUCS2String(o){return new this(o,ct(o))}static fromCodepoints(o){return new this(ut(o),o)}constructor(o,s){super(...arguments),this.ucs2String=o,this.codepoints=s,this.length=this.codepoints.length,this.ucs2Length=this.ucs2String.length}offsetToUCS2Offset(o){return ut(this.codepoints.slice(0,Math.max(0,o))).length}offsetFromUCS2Offset(o){return ct(this.ucs2String.slice(0,Math.max(0,o))).length}slice(){return this.constructor.fromCodepoints(this.codepoints.slice(...arguments))}charAt(o){return this.slice(o,o+1)}isEqualTo(o){return this.constructor.box(o).ucs2String===this.ucs2String}toJSON(){return this.ucs2String}getCacheKey(){return this.ucs2String}toString(){return this.ucs2String}}const nt=1===(null===(tt=Array.from)||void 0===tt?void 0:tt.call(Array,"👼").length),at=null!=(null===(et=" ".codePointAt)||void 0===et?void 0:et.call(" ",0)),lt=" 👼"===(null===(it=String.fromCodePoint)||void 0===it?void 0:it.call(String,32,128124));let ct,ut;ct=nt&&at?o=>Array.from(o).map((o=>o.codePointAt(0))):function(o){const s=[];let a=0;const{length:l}=o;for(;aString.fromCodePoint(...Array.from(o||[])):function(o){return(()=>{const s=[];return Array.from(o).forEach((o=>{let a="";o>65535&&(o-=65536,a+=String.fromCharCode(o>>>10&1023|55296),o=56320|1023&o),s.push(a+String.fromCharCode(o))})),s})().join("")};let ht=0;class rt extends q{static fromJSONString(o){return this.fromJSON(JSON.parse(o))}constructor(){super(...arguments),this.id=++ht}hasSameConstructorAs(o){return this.constructor===(null==o?void 0:o.constructor)}isEqualTo(o){return this===o}inspect(){const o=[],s=this.contentsForInspection()||{};for(const a in s){const l=s[a];o.push("".concat(a,"=").concat(l))}return"#<".concat(this.constructor.name,":").concat(this.id).concat(o.length?" ".concat(o.join(", ")):"",">")}contentsForInspection(){}toJSONString(){return JSON.stringify(this)}toUTF16String(){return X.box(this)}getCacheKey(){return this.id.toString()}}const ot=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(o.length!==s.length)return!1;for(let a=0;a1?a-1:0),c=1;c(St||(St=bt().concat(pt())),St),mt=o=>l[o],pt=()=>(re||(re=Object.keys(l)),re),ft=o=>K[o],bt=()=>(oe||(oe=Object.keys(K)),oe),vt=function(o,s){At(o).textContent=s.replace(/%t/g,o)},At=function(o){const s=document.createElement("style");s.setAttribute("type","text/css"),s.setAttribute("data-tag-name",o.toLowerCase());const a=yt();return a&&s.setAttribute("nonce",a),document.head.insertBefore(s,document.head.firstChild),s},yt=function(){const o=xt("trix-csp-nonce")||xt("csp-nonce");if(o){const{nonce:s,content:a}=o;return""==s?a:s}},xt=o=>document.head.querySelector("meta[name=".concat(o,"]")),ae={"application/x-trix-feature-detection":"test"},Et=function(o){const s=o.getData("text/plain"),a=o.getData("text/html");if(!s||!a)return null==s?void 0:s.length;{const{body:o}=(new DOMParser).parseFromString(a,"text/html");if(o.textContent===s)return!o.querySelector("*")}},le=/Mac|^iP/.test(navigator.platform)?o=>o.metaKey:o=>o.ctrlKey;const Rt=o=>setTimeout(o,1),kt=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s={};for(const a in o){const l=o[a];s[a]=l}return s},Tt=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Object.keys(o).length!==Object.keys(s).length)return!1;for(const a in o)if(o[a]!==s[a])return!1;return!0},wt=function(o){if(null!=o)return Array.isArray(o)||(o=[o,o]),[Nt(o[0]),Nt(null!=o[1]?o[1]:o[0])]},Lt=function(o){if(null==o)return;const[s,a]=wt(o);return It(s,a)},Dt=function(o,s){if(null==o||null==s)return;const[a,l]=wt(o),[c,h]=wt(s);return It(a,c)&&It(l,h)},Nt=function(o){return"number"==typeof o?o:kt(o)},It=function(o,s){return"number"==typeof o?o===s:Tt(o,s)};class Ot extends q{constructor(){super(...arguments),this.update=this.update.bind(this),this.selectionManagers=[]}start(){this.started||(this.started=!0,document.addEventListener("selectionchange",this.update,!0))}stop(){if(this.started)return this.started=!1,document.removeEventListener("selectionchange",this.update,!0)}registerSelectionManager(o){if(!this.selectionManagers.includes(o))return this.selectionManagers.push(o),this.start()}unregisterSelectionManager(o){if(this.selectionManagers=this.selectionManagers.filter((s=>s!==o)),0===this.selectionManagers.length)return this.stop()}notifySelectionManagersOfSelectionChange(){return this.selectionManagers.map((o=>o.selectionDidChange()))}update(){this.notifySelectionManagersOfSelectionChange()}reset(){this.update()}}const ce=new Ot,Pt=function(){const o=window.getSelection();if(o.rangeCount>0)return o},Mt=function(){var o;const s=null===(o=Pt())||void 0===o?void 0:o.getRangeAt(0);if(s&&!_t(s))return s},Bt=function(o){const s=window.getSelection();return s.removeAllRanges(),s.addRange(o),ce.update()},_t=o=>jt(o.startContainer)||jt(o.endContainer),jt=o=>!Object.getPrototypeOf(o),Wt=o=>o.replace(new RegExp("".concat(_),"g"),"").replace(new RegExp("".concat(j),"g")," "),ue=new RegExp("[^\\S".concat(j,"]")),Vt=o=>o.replace(new RegExp("".concat(ue.source),"g")," ").replace(/\ {2,}/g," "),zt=function(o,s){if(o.isEqualTo(s))return["",""];const a=qt(o,s),{length:l}=a.utf16String;let c;if(l){const{offset:h}=a,d=o.codepoints.slice(0,h).concat(o.codepoints.slice(h+l));c=qt(s,X.fromCodepoints(d))}else c=qt(s,o);return[a.utf16String.toString(),c.utf16String.toString()]},qt=function(o,s){let a=0,l=o.length,c=s.length;for(;aa+1&&o.charAt(l-1).isEqualTo(s.charAt(c-1));)l--,c--;return{utf16String:o.slice(a,l),offset:a}};class Ht extends rt{static fromCommonAttributesOfObjects(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!o.length)return new this;let s=Yt(o[0]),a=s.getKeys();return o.slice(1).forEach((o=>{a=s.getKeysCommonToHash(Yt(o)),s=s.slice(a)})),s}static box(o){return Yt(o)}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(...arguments),this.values=Gt(o)}add(o,s){return this.merge(Jt(o,s))}remove(o){return new Ht(Gt(this.values,o))}get(o){return this.values[o]}has(o){return o in this.values}merge(o){return new Ht(Kt(this.values,$t(o)))}slice(o){const s={};return Array.from(o).forEach((o=>{this.has(o)&&(s[o]=this.values[o])})),new Ht(s)}getKeys(){return Object.keys(this.values)}getKeysCommonToHash(o){return o=Yt(o),this.getKeys().filter((s=>this.values[s]===o.values[s]))}isEqualTo(o){return ot(this.toArray(),Yt(o).toArray())}isEmpty(){return 0===this.getKeys().length}toArray(){if(!this.array){const o=[];for(const s in this.values){const a=this.values[s];o.push(o.push(s,a))}this.array=o.slice(0)}return this.array}toObject(){return Gt(this.values)}toJSON(){return this.toObject()}contentsForInspection(){return{values:JSON.stringify(this.values)}}}const Jt=function(o,s){const a={};return a[o]=s,a},Kt=function(o,s){const a=Gt(o);for(const o in s){const l=s[o];a[o]=l}return a},Gt=function(o,s){const a={};return Object.keys(o).sort().forEach((l=>{l!==s&&(a[l]=o[l])})),a},Yt=function(o){return o instanceof Ht?o:new Ht(o)},$t=function(o){return o instanceof Ht?o.values:o};class Xt{static groupObjects(){let o,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],{depth:a,asTree:l}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l&&null==a&&(a=0);const c=[];return Array.from(s).forEach((s=>{var h;if(o){var d,g,p;if(null!==(d=s.canBeGrouped)&&void 0!==d&&d.call(s,a)&&null!==(g=(p=o[o.length-1]).canBeGroupedWith)&&void 0!==g&&g.call(p,s,a))return void o.push(s);c.push(new this(o,{depth:a,asTree:l})),o=null}null!==(h=s.canBeGrouped)&&void 0!==h&&h.call(s,a)?o=[s]:c.push(s)})),o&&c.push(new this(o,{depth:a,asTree:l})),c}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],{depth:s,asTree:a}=arguments.length>1?arguments[1]:void 0;this.objects=o,a&&(this.depth=s,this.objects=this.constructor.groupObjects(this.objects,{asTree:a,depth:this.depth+1}))}getObjects(){return this.objects}getDepth(){return this.depth}getCacheKey(){const o=["objectGroup"];return Array.from(this.getObjects()).forEach((s=>{o.push(s.getCacheKey())})),o.join("/")}}class Zt extends q{constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.objects={},Array.from(o).forEach((o=>{const s=JSON.stringify(o);null==this.objects[s]&&(this.objects[s]=o)}))}find(o){const s=JSON.stringify(o);return this.objects[s]}}class Qt{constructor(o){this.reset(o)}add(o){const s=te(o);this.elements[s]=o}remove(o){const s=te(o),a=this.elements[s];if(a)return delete this.elements[s],a}reset(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return this.elements={},Array.from(o).forEach((o=>{this.add(o)})),o}}const te=o=>o.dataset.trixStoreKey;class ee extends q{isPerforming(){return!0===this.performing}hasPerformed(){return!0===this.performed}hasSucceeded(){return this.performed&&this.succeeded}hasFailed(){return this.performed&&!this.succeeded}getPromise(){return this.promise||(this.promise=new Promise(((o,s)=>(this.performing=!0,this.perform(((a,l)=>{this.succeeded=a,this.performing=!1,this.performed=!0,this.succeeded?o(l):s(l)})))))),this.promise}perform(o){return o(!1)}release(){var o,s;null===(o=this.promise)||void 0===o||null===(s=o.cancel)||void 0===s||s.call(o),this.promise=null,this.performing=null,this.performed=null,this.succeeded=null}}ee.proxyMethod("getPromise().then"),ee.proxyMethod("getPromise().catch");class ie extends q{constructor(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.object=o,this.options=s,this.childViews=[],this.rootView=this}getNodes(){return this.nodes||(this.nodes=this.createNodes()),this.nodes.map((o=>o.cloneNode(!0)))}invalidate(){var o;return this.nodes=null,this.childViews=[],null===(o=this.parentView)||void 0===o?void 0:o.invalidate()}invalidateViewForObject(o){var s;return null===(s=this.findViewForObject(o))||void 0===s?void 0:s.invalidate()}findOrCreateCachedChildView(o,s,a){let l=this.getCachedViewForObject(s);return l?this.recordChildView(l):(l=this.createChildView(...arguments),this.cacheViewForObject(l,s)),l}createChildView(o,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};s instanceof Xt&&(a.viewClass=o,o=ne);const l=new o(s,a);return this.recordChildView(l)}recordChildView(o){return o.parentView=this,o.rootView=this.rootView,this.childViews.push(o),o}getAllChildViews(){let o=[];return this.childViews.forEach((s=>{o.push(s),o=o.concat(s.getAllChildViews())})),o}findElement(){return this.findElementForObject(this.object)}findElementForObject(o){const s=null==o?void 0:o.id;if(s)return this.rootView.element.querySelector("[data-trix-id='".concat(s,"']"))}findViewForObject(o){for(const s of this.getAllChildViews())if(s.object===o)return s}getViewCache(){return this.rootView!==this?this.rootView.getViewCache():this.isViewCachingEnabled()?(this.viewCache||(this.viewCache={}),this.viewCache):void 0}isViewCachingEnabled(){return!1!==this.shouldCacheViews}enableViewCaching(){this.shouldCacheViews=!0}disableViewCaching(){this.shouldCacheViews=!1}getCachedViewForObject(o){var s;return null===(s=this.getViewCache())||void 0===s?void 0:s[o.getCacheKey()]}cacheViewForObject(o,s){const a=this.getViewCache();a&&(a[s.getCacheKey()]=o)}garbageCollectCachedViews(){const o=this.getViewCache();if(o){const s=this.getAllChildViews().concat(this).map((o=>o.object.getCacheKey()));for(const a in o)s.includes(a)||delete o[a]}}}class ne extends ie{constructor(){super(...arguments),this.objectGroup=this.object,this.viewClass=this.options.viewClass,delete this.options.viewClass}getChildViews(){return this.childViews.length||Array.from(this.objectGroup.getObjects()).forEach((o=>{this.findOrCreateCachedChildView(this.viewClass,o,this.options)})),this.childViews}createNodes(){const o=this.createContainerElement();return this.getChildViews().forEach((s=>{Array.from(s.getNodes()).forEach((s=>{o.appendChild(s)}))})),[o]}createContainerElement(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.objectGroup.getDepth();return this.getChildViews()[0].createContainerElement(o)}} -/*! @license DOMPurify 3.2.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.5/LICENSE */const{entries:he,setPrototypeOf:de,isFrozen:ge,getPrototypeOf:me,getOwnPropertyDescriptor:pe}=Object;let{freeze:fe,seal:be,create:ve}=Object,{apply:Ae,construct:ye}="undefined"!=typeof Reflect&&Reflect;fe||(fe=function(o){return o}),be||(be=function(o){return o}),Ae||(Ae=function(o,s,a){return o.apply(s,a)}),ye||(ye=function(o,s){return new o(...s)});const xe=Le(Array.prototype.forEach),Ce=Le(Array.prototype.lastIndexOf),Ee=Le(Array.prototype.pop),Se=Le(Array.prototype.push),Re=Le(Array.prototype.splice),ke=Le(String.prototype.toLowerCase),Te=Le(String.prototype.toString),we=Le(String.prototype.match),Pe=Le(String.prototype.replace),Fe=Le(String.prototype.indexOf),Me=Le(String.prototype.trim),Be=Le(Object.prototype.hasOwnProperty),_e=Le(RegExp.prototype.test),je=(We=TypeError,function(){for(var o=arguments.length,s=new Array(o),a=0;a1?a-1:0),c=1;c2&&void 0!==arguments[2]?arguments[2]:ke;de&&de(o,null);let l=s.length;for(;l--;){let c=s[l];if("string"==typeof c){const o=a(c);o!==c&&(ge(s)||(s[l]=o),c=o)}o[c]=!0}return o}function Ne(o){for(let s=0;s/gm),ti=be(/\$\{[\w\W]*/gm),ei=be(/^data-[\-\w.\u00B7-\uFFFF]+$/),ii=be(/^aria-[\-\w]+$/),ni=be(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ri=be(/^(?:\w+script|data):/i),oi=be(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),si=be(/^html$/i),li=be(/^[a-z][.\w]*(-[.\w]+)+$/i);var ci=Object.freeze({__proto__:null,ARIA_ATTR:ii,ATTR_WHITESPACE:oi,CUSTOM_ELEMENT:li,DATA_ATTR:ei,DOCTYPE_NAME:si,ERB_EXPR:Qe,IS_ALLOWED_URI:ni,IS_SCRIPT_OR_DATA:ri,MUSTACHE_EXPR:Ze,TMPLIT_EXPR:ti});const ui=1,hi=3,mi=7,Ci=8,Qi=9,ai=function(){return"undefined"==typeof window?null:window};var An=function t(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ai();const i=o=>t(o);if(i.version="3.2.5",i.removed=[],!o||!o.document||o.document.nodeType!==Qi||!o.Element)return i.isSupported=!1,i;let{document:s}=o;const a=s,l=a.currentScript,{DocumentFragment:c,HTMLTemplateElement:h,Node:d,Element:g,NodeFilter:p,NamedNodeMap:f=o.NamedNodeMap||o.MozNamedAttrMap,HTMLFormElement:w,DOMParser:_,trustedTypes:j}=o,W=g.prototype,U=Oe(W,"cloneNode"),V=Oe(W,"remove"),z=Oe(W,"nextSibling"),J=Oe(W,"childNodes"),K=Oe(W,"parentNode");if("function"==typeof h){const o=s.createElement("template");o.content&&o.content.ownerDocument&&(s=o.content.ownerDocument)}let G,Y="";const{implementation:$,createNodeIterator:Z,createDocumentFragment:Q,getElementsByTagName:tt}=s,{importNode:et}=a;let it={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};i.isSupported="function"==typeof he&&"function"==typeof K&&$&&void 0!==$.createHTMLDocument;const{MUSTACHE_EXPR:nt,ERB_EXPR:at,TMPLIT_EXPR:lt,DATA_ATTR:ct,ARIA_ATTR:ut,IS_SCRIPT_OR_DATA:ht,ATTR_WHITESPACE:dt,CUSTOM_ELEMENT:Ct}=ci;let{IS_ALLOWED_URI:St}=ci,re=null;const oe=De({},[...Ue,...Ve,...qe,...ze,...Ke]);let se=null;const ae=De({},[...Ge,...Ye,...Xe,...$e]);let le=Object.seal(ve(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ce=null,ue=null,de=!0,ge=!0,me=!1,pe=!0,be=!1,Ae=!0,ye=!1,We=!1,Ze=!1,Qe=!1,ti=!1,ei=!1,ii=!0,ri=!1,oi=!0,li=!1,An={},yn=null;const xn=De({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Cn=null;const En=De({},["audio","video","img","source","image","track"]);let Sn=null;const Nn=De({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Fn="http://www.w3.org/1998/Math/MathML",qn="http://www.w3.org/2000/svg",Hn="http://www.w3.org/1999/xhtml";let zn=Hn,Jn=!1,Kn=null;const Zn=De({},[Fn,qn,Hn],Te);let Qn=De({},["mi","mo","mn","ms","mtext"]),tr=De({},["annotation-xml"]);const sr=De({},["title","style","font","a","script"]);let cr=null;const ur=["application/xhtml+xml","text/html"];let hr=null,dr=null;const pr=s.createElement("form"),Lt=function(o){return o instanceof RegExp||o instanceof Function},Dt=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!dr||dr!==o){if(o&&"object"==typeof o||(o={}),o=Ie(o),cr=-1===ur.indexOf(o.PARSER_MEDIA_TYPE)?"text/html":o.PARSER_MEDIA_TYPE,hr="application/xhtml+xml"===cr?Te:ke,re=Be(o,"ALLOWED_TAGS")?De({},o.ALLOWED_TAGS,hr):oe,se=Be(o,"ALLOWED_ATTR")?De({},o.ALLOWED_ATTR,hr):ae,Kn=Be(o,"ALLOWED_NAMESPACES")?De({},o.ALLOWED_NAMESPACES,Te):Zn,Sn=Be(o,"ADD_URI_SAFE_ATTR")?De(Ie(Nn),o.ADD_URI_SAFE_ATTR,hr):Nn,Cn=Be(o,"ADD_DATA_URI_TAGS")?De(Ie(En),o.ADD_DATA_URI_TAGS,hr):En,yn=Be(o,"FORBID_CONTENTS")?De({},o.FORBID_CONTENTS,hr):xn,ce=Be(o,"FORBID_TAGS")?De({},o.FORBID_TAGS,hr):{},ue=Be(o,"FORBID_ATTR")?De({},o.FORBID_ATTR,hr):{},An=!!Be(o,"USE_PROFILES")&&o.USE_PROFILES,de=!1!==o.ALLOW_ARIA_ATTR,ge=!1!==o.ALLOW_DATA_ATTR,me=o.ALLOW_UNKNOWN_PROTOCOLS||!1,pe=!1!==o.ALLOW_SELF_CLOSE_IN_ATTR,be=o.SAFE_FOR_TEMPLATES||!1,Ae=!1!==o.SAFE_FOR_XML,ye=o.WHOLE_DOCUMENT||!1,Qe=o.RETURN_DOM||!1,ti=o.RETURN_DOM_FRAGMENT||!1,ei=o.RETURN_TRUSTED_TYPE||!1,Ze=o.FORCE_BODY||!1,ii=!1!==o.SANITIZE_DOM,ri=o.SANITIZE_NAMED_PROPS||!1,oi=!1!==o.KEEP_CONTENT,li=o.IN_PLACE||!1,St=o.ALLOWED_URI_REGEXP||ni,zn=o.NAMESPACE||Hn,Qn=o.MATHML_TEXT_INTEGRATION_POINTS||Qn,tr=o.HTML_INTEGRATION_POINTS||tr,le=o.CUSTOM_ELEMENT_HANDLING||{},o.CUSTOM_ELEMENT_HANDLING&&Lt(o.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(le.tagNameCheck=o.CUSTOM_ELEMENT_HANDLING.tagNameCheck),o.CUSTOM_ELEMENT_HANDLING&&Lt(o.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(le.attributeNameCheck=o.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),o.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof o.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(le.allowCustomizedBuiltInElements=o.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),be&&(ge=!1),ti&&(Qe=!0),An&&(re=De({},Ke),se=[],!0===An.html&&(De(re,Ue),De(se,Ge)),!0===An.svg&&(De(re,Ve),De(se,Ye),De(se,$e)),!0===An.svgFilters&&(De(re,qe),De(se,Ye),De(se,$e)),!0===An.mathMl&&(De(re,ze),De(se,Xe),De(se,$e))),o.ADD_TAGS&&(re===oe&&(re=Ie(re)),De(re,o.ADD_TAGS,hr)),o.ADD_ATTR&&(se===ae&&(se=Ie(se)),De(se,o.ADD_ATTR,hr)),o.ADD_URI_SAFE_ATTR&&De(Sn,o.ADD_URI_SAFE_ATTR,hr),o.FORBID_CONTENTS&&(yn===xn&&(yn=Ie(yn)),De(yn,o.FORBID_CONTENTS,hr)),oi&&(re["#text"]=!0),ye&&De(re,["html","head","body"]),re.table&&(De(re,["tbody"]),delete ce.tbody),o.TRUSTED_TYPES_POLICY){if("function"!=typeof o.TRUSTED_TYPES_POLICY.createHTML)throw je('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof o.TRUSTED_TYPES_POLICY.createScriptURL)throw je('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');G=o.TRUSTED_TYPES_POLICY,Y=G.createHTML("")}else void 0===G&&(G=function(o,s){if("object"!=typeof o||"function"!=typeof o.createPolicy)return null;let a=null;const l="data-tt-policy-suffix";s&&s.hasAttribute(l)&&(a=s.getAttribute(l));const c="dompurify"+(a?"#"+a:"");try{return o.createPolicy(c,{createHTML:o=>o,createScriptURL:o=>o})}catch(o){return console.warn("TrustedTypes policy "+c+" could not be created."),null}}(j,l)),null!==G&&"string"==typeof Y&&(Y=G.createHTML(""));fe&&fe(o),dr=o}},Dr=De({},[...Ve,...qe,...He]),Tr=De({},[...ze,...Je]),Ot=function(o){Se(i.removed,{element:o});try{K(o).removeChild(o)}catch(s){V(o)}},Ft=function(o,s){try{Se(i.removed,{attribute:s.getAttributeNode(o),from:s})}catch(o){Se(i.removed,{attribute:null,from:s})}if(s.removeAttribute(o),"is"===o)if(Qe||ti)try{Ot(s)}catch(o){}else try{s.setAttribute(o,"")}catch(o){}},Pt=function(o){let a=null,l=null;if(Ze)o=""+o;else{const s=we(o,/^[\r\n\t ]+/);l=s&&s[0]}"application/xhtml+xml"===cr&&zn===Hn&&(o=''+o+"");const c=G?G.createHTML(o):o;if(zn===Hn)try{a=(new _).parseFromString(c,cr)}catch(o){}if(!a||!a.documentElement){a=$.createDocument(zn,"template",null);try{a.documentElement.innerHTML=Jn?Y:c}catch(o){}}const h=a.body||a.documentElement;return o&&l&&h.insertBefore(s.createTextNode(l),h.childNodes[0]||null),zn===Hn?tt.call(a,ye?"html":"body")[0]:ye?a.documentElement:h},Mt=function(o){return Z.call(o.ownerDocument||o,o,p.SHOW_ELEMENT|p.SHOW_COMMENT|p.SHOW_TEXT|p.SHOW_PROCESSING_INSTRUCTION|p.SHOW_CDATA_SECTION,null)},Bt=function(o){return o instanceof w&&("string"!=typeof o.nodeName||"string"!=typeof o.textContent||"function"!=typeof o.removeChild||!(o.attributes instanceof f)||"function"!=typeof o.removeAttribute||"function"!=typeof o.setAttribute||"string"!=typeof o.namespaceURI||"function"!=typeof o.insertBefore||"function"!=typeof o.hasChildNodes)},_t=function(o){return"function"==typeof d&&o instanceof d};function jt(o,s,a){xe(o,(o=>{o.call(i,s,a,dr)}))}const Wt=function(o){let s=null;if(jt(it.beforeSanitizeElements,o,null),Bt(o))return Ot(o),!0;const a=hr(o.nodeName);if(jt(it.uponSanitizeElement,o,{tagName:a,allowedTags:re}),o.hasChildNodes()&&!_t(o.firstElementChild)&&_e(/<[/\w!]/g,o.innerHTML)&&_e(/<[/\w!]/g,o.textContent))return Ot(o),!0;if(o.nodeType===mi)return Ot(o),!0;if(Ae&&o.nodeType===Ci&&_e(/<[/\w]/g,o.data))return Ot(o),!0;if(!re[a]||ce[a]){if(!ce[a]&&Vt(a)){if(le.tagNameCheck instanceof RegExp&&_e(le.tagNameCheck,a))return!1;if(le.tagNameCheck instanceof Function&&le.tagNameCheck(a))return!1}if(oi&&!yn[a]){const s=K(o)||o.parentNode,a=J(o)||o.childNodes;if(a&&s)for(let l=a.length-1;l>=0;--l){const c=U(a[l],!0);c.__removalCount=(o.__removalCount||0)+1,s.insertBefore(c,z(o))}}return Ot(o),!0}return o instanceof g&&!function(o){let s=K(o);s&&s.tagName||(s={namespaceURI:zn,tagName:"template"});const a=ke(o.tagName),l=ke(s.tagName);return!!Kn[o.namespaceURI]&&(o.namespaceURI===qn?s.namespaceURI===Hn?"svg"===a:s.namespaceURI===Fn?"svg"===a&&("annotation-xml"===l||Qn[l]):Boolean(Dr[a]):o.namespaceURI===Fn?s.namespaceURI===Hn?"math"===a:s.namespaceURI===qn?"math"===a&&tr[l]:Boolean(Tr[a]):o.namespaceURI===Hn?!(s.namespaceURI===qn&&!tr[l])&&!(s.namespaceURI===Fn&&!Qn[l])&&!Tr[a]&&(sr[a]||!Dr[a]):!("application/xhtml+xml"!==cr||!Kn[o.namespaceURI]))}(o)?(Ot(o),!0):"noscript"!==a&&"noembed"!==a&&"noframes"!==a||!_e(/<\/no(script|embed|frames)/i,o.innerHTML)?(be&&o.nodeType===hi&&(s=o.textContent,xe([nt,at,lt],(o=>{s=Pe(s,o," ")})),o.textContent!==s&&(Se(i.removed,{element:o.cloneNode()}),o.textContent=s)),jt(it.afterSanitizeElements,o,null),!1):(Ot(o),!0)},Ut=function(o,a,l){if(ii&&("id"===a||"name"===a)&&(l in s||l in pr))return!1;if(ge&&!ue[a]&&_e(ct,a));else if(de&&_e(ut,a));else if(!se[a]||ue[a]){if(!(Vt(o)&&(le.tagNameCheck instanceof RegExp&&_e(le.tagNameCheck,o)||le.tagNameCheck instanceof Function&&le.tagNameCheck(o))&&(le.attributeNameCheck instanceof RegExp&&_e(le.attributeNameCheck,a)||le.attributeNameCheck instanceof Function&&le.attributeNameCheck(a))||"is"===a&&le.allowCustomizedBuiltInElements&&(le.tagNameCheck instanceof RegExp&&_e(le.tagNameCheck,l)||le.tagNameCheck instanceof Function&&le.tagNameCheck(l))))return!1}else if(Sn[a]);else if(_e(St,Pe(l,dt,"")));else if("src"!==a&&"xlink:href"!==a&&"href"!==a||"script"===o||0!==Fe(l,"data:")||!Cn[o])if(me&&!_e(ht,Pe(l,dt,"")));else if(l)return!1;return!0},Vt=function(o){return"annotation-xml"!==o&&we(o,Ct)},zt=function(o){jt(it.beforeSanitizeAttributes,o,null);const{attributes:s}=o;if(!s||Bt(o))return;const a={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:se,forceKeepAttr:void 0};let l=s.length;for(;l--;){const c=s[l],{name:h,namespaceURI:d,value:g}=c,p=hr(h);let f="value"===h?g:Me(g);if(a.attrName=p,a.attrValue=f,a.keepAttr=!0,a.forceKeepAttr=void 0,jt(it.uponSanitizeAttribute,o,a),f=a.attrValue,!ri||"id"!==p&&"name"!==p||(Ft(h,o),f="user-content-"+f),Ae&&_e(/((--!?|])>)|<\/(style|title)/i,f)){Ft(h,o);continue}if(a.forceKeepAttr)continue;if(Ft(h,o),!a.keepAttr)continue;if(!pe&&_e(/\/>/i,f)){Ft(h,o);continue}be&&xe([nt,at,lt],(o=>{f=Pe(f,o," ")}));const w=hr(o.nodeName);if(Ut(w,p,f)){if(G&&"object"==typeof j&&"function"==typeof j.getAttributeType)if(d);else switch(j.getAttributeType(w,p)){case"TrustedHTML":f=G.createHTML(f);break;case"TrustedScriptURL":f=G.createScriptURL(f)}try{d?o.setAttributeNS(d,h,f):o.setAttribute(h,f),Bt(o)?Ot(o):Ee(i.removed)}catch(o){}}}jt(it.afterSanitizeAttributes,o,null)},wr=function t(o){let s=null;const a=Mt(o);for(jt(it.beforeSanitizeShadowDOM,o,null);s=a.nextNode();)jt(it.uponSanitizeShadowNode,s,null),Wt(s),zt(s),s.content instanceof c&&t(s.content);jt(it.afterSanitizeShadowDOM,o,null)};return i.sanitize=function(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},l=null,h=null,g=null,p=null;if(Jn=!o,Jn&&(o="\x3c!--\x3e"),"string"!=typeof o&&!_t(o)){if("function"!=typeof o.toString)throw je("toString is not a function");if("string"!=typeof(o=o.toString()))throw je("dirty is not a string, aborting")}if(!i.isSupported)return o;if(We||Dt(s),i.removed=[],"string"==typeof o&&(li=!1),li){if(o.nodeName){const s=hr(o.nodeName);if(!re[s]||ce[s])throw je("root node is forbidden and cannot be sanitized in-place")}}else if(o instanceof d)l=Pt("\x3c!----\x3e"),h=l.ownerDocument.importNode(o,!0),h.nodeType===ui&&"BODY"===h.nodeName||"HTML"===h.nodeName?l=h:l.appendChild(h);else{if(!Qe&&!be&&!ye&&-1===o.indexOf("<"))return G&&ei?G.createHTML(o):o;if(l=Pt(o),!l)return Qe?null:ei?Y:""}l&&Ze&&Ot(l.firstChild);const f=Mt(li?o:l);for(;g=f.nextNode();)Wt(g),zt(g),g.content instanceof c&&wr(g.content);if(li)return o;if(Qe){if(ti)for(p=Q.call(l.ownerDocument);l.firstChild;)p.appendChild(l.firstChild);else p=l;return(se.shadowroot||se.shadowrootmode)&&(p=et.call(a,p,!0)),p}let w=ye?l.outerHTML:l.innerHTML;return ye&&re["!doctype"]&&l.ownerDocument&&l.ownerDocument.doctype&&l.ownerDocument.doctype.name&&_e(si,l.ownerDocument.doctype.name)&&(w="\n"+w),be&&xe([nt,at,lt],(o=>{w=Pe(w,o," ")})),G&&ei?G.createHTML(w):w},i.setConfig=function(){Dt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),We=!0},i.clearConfig=function(){dr=null,We=!1},i.isValidAttribute=function(o,s,a){dr||Dt({});const l=hr(o),c=hr(s);return Ut(l,c,a)},i.addHook=function(o,s){"function"==typeof s&&Se(it[o],s)},i.removeHook=function(o,s){if(void 0!==s){const a=Ce(it[o],s);return-1===a?void 0:Re(it[o],a,1)[0]}return Ee(it[o])},i.removeHooks=function(o){it[o]=[]},i.removeAllHooks=function(){it={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},i}();An.addHook("uponSanitizeAttribute",(function(o,s){/^data-trix-/.test(s.attrName)&&(s.forceKeepAttr=!0)}));const yn="style href src width height language class".split(" "),xn="javascript:".split(" "),Cn="script iframe form noscript".split(" ");class di extends q{static setHTML(o,s){const a=new this(s).sanitize(),l=a.getHTML?a.getHTML():a.outerHTML;o.innerHTML=l}static sanitize(o,s){const a=new this(o,s);return a.sanitize(),a}constructor(o){let{allowedAttributes:s,forbiddenProtocols:a,forbiddenElements:l}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.allowedAttributes=s||yn,this.forbiddenProtocols=a||xn,this.forbiddenElements=l||Cn,this.body=gi(o)}sanitize(){return this.sanitizeElements(),this.normalizeListElementNesting(),An.setConfig(g),this.body=An.sanitize(this.body),this.body}getHTML(){return this.body.innerHTML}getBody(){return this.body}sanitizeElements(){const o=R(this.body),s=[];for(;o.nextNode();){const a=o.currentNode;switch(a.nodeType){case Node.ELEMENT_NODE:this.elementIsRemovable(a)?s.push(a):this.sanitizeElement(a);break;case Node.COMMENT_NODE:s.push(a)}}return s.forEach((o=>S(o))),this.body}sanitizeElement(o){return o.hasAttribute("href")&&this.forbiddenProtocols.includes(o.protocol)&&o.removeAttribute("href"),Array.from(o.attributes).forEach((s=>{let{name:a}=s;this.allowedAttributes.includes(a)||0===a.indexOf("data-trix")||o.removeAttribute(a)})),o}normalizeListElementNesting(){return Array.from(this.body.querySelectorAll("ul,ol")).forEach((o=>{const s=o.previousElementSibling;s&&"li"===k(s)&&s.appendChild(o)})),this.body}elementIsRemovable(o){if((null==o?void 0:o.nodeType)===Node.ELEMENT_NODE)return this.elementIsForbidden(o)||this.elementIsntSerializable(o)}elementIsForbidden(o){return this.forbiddenElements.includes(k(o))}elementIsntSerializable(o){return"false"===o.getAttribute("data-trix-serialize")&&!P(o)}}const gi=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";o=o.replace(/<\/html[^>]*>[^]*$/i,"");const s=document.implementation.createHTMLDocument("");return s.documentElement.innerHTML=o,Array.from(s.head.querySelectorAll("style")).forEach((o=>{s.body.appendChild(o)})),s.body},{css:En}=$;class pi extends ie{constructor(){super(...arguments),this.attachment=this.object,this.attachment.uploadProgressDelegate=this,this.attachmentPiece=this.options.piece}createContentNodes(){return[]}createNodes(){let o;const s=o=T({tagName:"figure",className:this.getClassName(),data:this.getData(),editable:!1}),a=this.getHref();return a&&(o=T({tagName:"a",editable:!1,attributes:{href:a,tabindex:-1}}),s.appendChild(o)),this.attachment.hasContent()?di.setHTML(o,this.attachment.getContent()):this.createContentNodes().forEach((s=>{o.appendChild(s)})),o.appendChild(this.createCaptionElement()),this.attachment.isPending()&&(this.progressElement=T({tagName:"progress",attributes:{class:En.attachmentProgress,value:this.attachment.getUploadProgress(),max:100},data:{trixMutable:!0,trixStoreKey:["progressElement",this.attachment.id].join("/")}}),s.appendChild(this.progressElement)),[fi("left"),s,fi("right")]}createCaptionElement(){const o=T({tagName:"figcaption",className:En.attachmentCaption}),s=this.attachmentPiece.getCaption();if(s)o.classList.add("".concat(En.attachmentCaption,"--edited")),o.textContent=s;else{let s,a;const l=this.getCaptionConfig();if(l.name&&(s=this.attachment.getFilename()),l.size&&(a=this.attachment.getFormattedFilesize()),s){const a=T({tagName:"span",className:En.attachmentName,textContent:s});o.appendChild(a)}if(a){s&&o.appendChild(document.createTextNode(" "));const l=T({tagName:"span",className:En.attachmentSize,textContent:a});o.appendChild(l)}}return o}getClassName(){const o=[En.attachment,"".concat(En.attachment,"--").concat(this.attachment.getType())],s=this.attachment.getExtension();return s&&o.push("".concat(En.attachment,"--").concat(s)),o.join(" ")}getData(){const o={trixAttachment:JSON.stringify(this.attachment),trixContentType:this.attachment.getContentType(),trixId:this.attachment.id},{attributes:s}=this.attachmentPiece;return s.isEmpty()||(o.trixAttributes=JSON.stringify(s)),this.attachment.isPending()&&(o.trixSerialize=!1),o}getHref(){if(!bi(this.attachment.getContent(),"a"))return this.attachment.getHref()}getCaptionConfig(){var o;const s=this.attachment.getType(),l=kt(null===(o=a[s])||void 0===o?void 0:o.caption);return"file"===s&&(l.name=!0),l}findProgressElement(){var o;return null===(o=this.findElement())||void 0===o?void 0:o.querySelector("progress")}attachmentDidChangeUploadProgress(){const o=this.attachment.getUploadProgress(),s=this.findProgressElement();s&&(s.value=o)}}const fi=o=>T({tagName:"span",textContent:_,data:{trixCursorTarget:o,trixSerialize:!1}}),bi=function(o,s){const a=T("div");return di.setHTML(a,o||""),a.querySelector(s)};class vi extends pi{constructor(){super(...arguments),this.attachment.previewDelegate=this}createContentNodes(){return this.image=T({tagName:"img",attributes:{src:""},data:{trixMutable:!0}}),this.refresh(this.image),[this.image]}createCaptionElement(){const o=super.createCaptionElement(...arguments);return o.textContent||o.setAttribute("data-trix-placeholder",p.captionPlaceholder),o}refresh(o){var s;o||(o=null===(s=this.findElement())||void 0===s?void 0:s.querySelector("img"));if(o)return this.updateAttributesForImage(o)}updateAttributesForImage(o){const s=this.attachment.getURL(),a=this.attachment.getPreviewURL();if(o.src=a||s,a===s)o.removeAttribute("data-trix-serialized-attributes");else{const a=JSON.stringify({src:s});o.setAttribute("data-trix-serialized-attributes",a)}const l=this.attachment.getWidth(),c=this.attachment.getHeight();null!=l&&(o.width=l),null!=c&&(o.height=c);const h=["imageElement",this.attachment.id,o.src,o.width,o.height].join("/");o.dataset.trixStoreKey=h}attachmentDidChangeAttributes(){return this.refresh(this.image),this.refresh()}}class Ai extends ie{constructor(){super(...arguments),this.piece=this.object,this.attributes=this.piece.getAttributes(),this.textConfig=this.options.textConfig,this.context=this.options.context,this.piece.attachment?this.attachment=this.piece.attachment:this.string=this.piece.toString()}createNodes(){let o=this.attachment?this.createAttachmentNodes():this.createStringNodes();const s=this.createElement();if(s){const a=function(o){for(;null!==(s=o)&&void 0!==s&&s.firstElementChild;){var s;o=o.firstElementChild}return o}(s);Array.from(o).forEach((o=>{a.appendChild(o)})),o=[s]}return o}createAttachmentNodes(){const o=this.attachment.isPreviewable()?vi:pi;return this.createChildView(o,this.piece.attachment,{piece:this.piece}).getNodes()}createStringNodes(){var o;if(null!==(o=this.textConfig)&&void 0!==o&&o.plaintext)return[document.createTextNode(this.string)];{const o=[],s=this.string.split("\n");for(let a=0;a0){const s=T("br");o.push(s)}if(l.length){const s=document.createTextNode(this.preserveSpaces(l));o.push(s)}}return o}}createElement(){let o,s,a;const l={};for(s in this.attributes){a=this.attributes[s];const h=ft(s);if(h){if(h.tagName){var c;const s=T(h.tagName);c?(c.appendChild(s),c=s):o=c=s}if(h.styleProperty&&(l[h.styleProperty]=a),h.style)for(s in h.style)a=h.style[s],l[s]=a}}if(Object.keys(l).length)for(s in o||(o=T("span")),l)a=l[s],o.style[s]=a;return o}createContainerElement(){for(const o in this.attributes){const s=this.attributes[o],a=ft(o);if(a&&a.groupTagName){const l={};return l[o]=s,T(a.groupTagName,l)}}}preserveSpaces(o){return this.context.isLast&&(o=o.replace(/\ $/,j)),o=o.replace(/(\S)\ {3}(\S)/g,"$1 ".concat(j," $2")).replace(/\ {2}/g,"".concat(j," ")).replace(/\ {2}/g," ".concat(j)),(this.context.isFirst||this.context.followsWhitespace)&&(o=o.replace(/^\ /,j)),o}}class yi extends ie{constructor(){super(...arguments),this.text=this.object,this.textConfig=this.options.textConfig}createNodes(){const o=[],s=Xt.groupObjects(this.getPieces()),a=s.length-1;for(let c=0;c!o.hasAttribute("blockBreak")))}}const xi=o=>/\s$/.test(null==o?void 0:o.toString()),{css:Sn}=$;class Ei extends ie{constructor(){super(...arguments),this.block=this.object,this.attributes=this.block.getAttributes()}createNodes(){const o=[document.createComment("block")];if(this.block.isEmpty())o.push(T("br"));else{var s;const a=null===(s=mt(this.block.getLastAttribute()))||void 0===s?void 0:s.text,l=this.findOrCreateCachedChildView(yi,this.block.text,{textConfig:a});o.push(...Array.from(l.getNodes()||[])),this.shouldAddExtraNewlineElement()&&o.push(T("br"))}if(this.attributes.length)return o;{let s;const{tagName:a}=l.default;this.block.isRTL()&&(s={dir:"rtl"});const c=T({tagName:a,attributes:s});return o.forEach((o=>c.appendChild(o))),[c]}}createContainerElement(o){const s={};let a;const l=this.attributes[o],{tagName:c,htmlAttributes:h=[]}=mt(l);if(0===o&&this.block.isRTL()&&Object.assign(s,{dir:"rtl"}),"attachmentGallery"===l){const o=this.block.getBlockBreakPosition();a="".concat(Sn.attachmentGallery," ").concat(Sn.attachmentGallery,"--").concat(o)}return Object.entries(this.block.htmlAttributes).forEach((o=>{let[a,l]=o;h.includes(a)&&(s[a]=l)})),T({tagName:c,className:a,attributes:s})}shouldAddExtraNewlineElement(){return/\n\n$/.test(this.block.toString())}}class Si extends ie{static render(o){const s=T("div"),a=new this(o,{element:s});return a.render(),a.sync(),s}constructor(){super(...arguments),this.element=this.options.element,this.elementStore=new Qt,this.setDocument(this.object)}setDocument(o){o.isEqualTo(this.document)||(this.document=this.object=o)}render(){if(this.childViews=[],this.shadowElement=T("div"),!this.document.isEmpty()){const o=Xt.groupObjects(this.document.getBlocks(),{asTree:!0});Array.from(o).forEach((o=>{const s=this.findOrCreateCachedChildView(Ei,o);Array.from(s.getNodes()).map((o=>this.shadowElement.appendChild(o)))}))}}isSynced(){return ki(this.shadowElement,this.element)}sync(){const o=this.createDocumentFragmentForSync();for(;this.element.lastChild;)this.element.removeChild(this.element.lastChild);return this.element.appendChild(o),this.didSync()}didSync(){return this.elementStore.reset(Ri(this.element)),Rt((()=>this.garbageCollectCachedViews()))}createDocumentFragmentForSync(){const o=document.createDocumentFragment();return Array.from(this.shadowElement.childNodes).forEach((s=>{o.appendChild(s.cloneNode(!0))})),Array.from(Ri(o)).forEach((o=>{const s=this.elementStore.remove(o);s&&o.parentNode.replaceChild(s,o)})),o}}const Ri=o=>o.querySelectorAll("[data-trix-store-key]"),ki=(o,s)=>Ti(o.innerHTML)===Ti(s.innerHTML),Ti=o=>o.replace(/ /g," ");function wi(o){var s,a;function n(s,a){try{var l=o[s](a),c=l.value,h=c instanceof Li;Promise.resolve(h?c.v:c).then((function(a){if(h){var d="return"===s?"return":"next";if(!c.k||a.done)return n(d,a);a=o[d](a).value}r(l.done?"return":"normal",a)}),(function(o){n("throw",o)}))}catch(o){r("throw",o)}}function r(o,l){switch(o){case"return":s.resolve({value:l,done:!0});break;case"throw":s.reject(l);break;default:s.resolve({value:l,done:!1})}(s=s.next)?n(s.key,s.arg):a=null}this._invoke=function(o,l){return new Promise((function(c,h){var d={key:o,arg:l,resolve:c,reject:h,next:null};a?a=a.next=d:(s=a=d,n(o,l))}))},"function"!=typeof o.return&&(this.return=void 0)}function Li(o,s){this.v=o,this.k=s}function Di(o,s,a){return(s=Ni(s))in o?Object.defineProperty(o,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):o[s]=a,o}function Ni(o){var s=function(o,s){if("object"!=typeof o||null===o)return o;var a=o[Symbol.toPrimitive];if(void 0!==a){var l=a.call(o,s||"default");if("object"!=typeof l)return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===s?String:Number)(o)}(o,"string");return"symbol"==typeof s?s:String(s)}wi.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},wi.prototype.next=function(o){return this._invoke("next",o)},wi.prototype.throw=function(o){return this._invoke("throw",o)},wi.prototype.return=function(o){return this._invoke("return",o)};function Ii(o,s){return Pi(o,Fi(o,s,"get"))}function Oi(o,s,a){return Mi(o,Fi(o,s,"set"),a),a}function Fi(o,s,a){if(!s.has(o))throw new TypeError("attempted to "+a+" private field on non-instance");return s.get(o)}function Pi(o,s){return s.get?s.get.call(o):s.value}function Mi(o,s,a){if(s.set)s.set.call(o,a);else{if(!s.writable)throw new TypeError("attempted to set read only private field");s.value=a}}function Bi(o,s,a){if(!s.has(o))throw new TypeError("attempted to get private field on non-instance");return a}function _i(o,s){if(s.has(o))throw new TypeError("Cannot initialize the same private elements twice on an object")}function ji(o,s,a){_i(o,s),s.set(o,a)}class Wi extends rt{static registerType(o,s){s.type=o,this.types[o]=s}static fromJSON(o){const s=this.types[o.type];if(s)return s.fromJSON(o)}constructor(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.attributes=Ht.box(s)}copyWithAttributes(o){return new this.constructor(this.getValue(),o)}copyWithAdditionalAttributes(o){return this.copyWithAttributes(this.attributes.merge(o))}copyWithoutAttribute(o){return this.copyWithAttributes(this.attributes.remove(o))}copy(){return this.copyWithAttributes(this.attributes)}getAttribute(o){return this.attributes.get(o)}getAttributesHash(){return this.attributes}getAttributes(){return this.attributes.toObject()}hasAttribute(o){return this.attributes.has(o)}hasSameStringValueAsPiece(o){return o&&this.toString()===o.toString()}hasSameAttributesAsPiece(o){return o&&(this.attributes===o.attributes||this.attributes.isEqualTo(o.attributes))}isBlockBreak(){return!1}isEqualTo(o){return super.isEqualTo(...arguments)||this.hasSameConstructorAs(o)&&this.hasSameStringValueAsPiece(o)&&this.hasSameAttributesAsPiece(o)}isEmpty(){return 0===this.length}isSerializable(){return!0}toJSON(){return{type:this.constructor.type,attributes:this.getAttributes()}}contentsForInspection(){return{type:this.constructor.type,attributes:this.attributes.inspect()}}canBeGrouped(){return this.hasAttribute("href")}canBeGroupedWith(o){return this.getAttribute("href")===o.getAttribute("href")}getLength(){return this.length}canBeConsolidatedWith(o){return!1}}Di(Wi,"types",{});class Ui extends ee{constructor(o){super(...arguments),this.url=o}perform(o){const s=new Image;s.onload=()=>(s.width=this.width=s.naturalWidth,s.height=this.height=s.naturalHeight,o(!0,s)),s.onerror=()=>o(!1),s.src=this.url}}class Vi extends rt{static attachmentForFile(o){const s=new this(this.attributesForFile(o));return s.setFile(o),s}static attributesForFile(o){return new Ht({filename:o.name,filesize:o.size,contentType:o.type})}static fromJSON(o){return new this(o)}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(o),this.releaseFile=this.releaseFile.bind(this),this.attributes=Ht.box(o),this.didChangeAttributes()}getAttribute(o){return this.attributes.get(o)}hasAttribute(o){return this.attributes.has(o)}getAttributes(){return this.attributes.toObject()}setAttributes(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s=this.attributes.merge(o);var a,l,c,h;if(!this.attributes.isEqualTo(s))return this.attributes=s,this.didChangeAttributes(),null===(a=this.previewDelegate)||void 0===a||null===(l=a.attachmentDidChangeAttributes)||void 0===l||l.call(a,this),null===(c=this.delegate)||void 0===c||null===(h=c.attachmentDidChangeAttributes)||void 0===h?void 0:h.call(c,this)}didChangeAttributes(){if(this.isPreviewable())return this.preloadURL()}isPending(){return null!=this.file&&!(this.getURL()||this.getHref())}isPreviewable(){return this.attributes.has("previewable")?this.attributes.get("previewable"):Vi.previewablePattern.test(this.getContentType())}getType(){return this.hasContent()?"content":this.isPreviewable()?"preview":"file"}getURL(){return this.attributes.get("url")}getHref(){return this.attributes.get("href")}getFilename(){return this.attributes.get("filename")||""}getFilesize(){return this.attributes.get("filesize")}getFormattedFilesize(){const o=this.attributes.get("filesize");return"number"==typeof o?w.formatter(o):""}getExtension(){var o;return null===(o=this.getFilename().match(/\.(\w+)$/))||void 0===o?void 0:o[1].toLowerCase()}getContentType(){return this.attributes.get("contentType")}hasContent(){return this.attributes.has("content")}getContent(){return this.attributes.get("content")}getWidth(){return this.attributes.get("width")}getHeight(){return this.attributes.get("height")}getFile(){return this.file}setFile(o){if(this.file=o,this.isPreviewable())return this.preloadFile()}releaseFile(){this.releasePreloadedFile(),this.file=null}getUploadProgress(){return null!=this.uploadProgress?this.uploadProgress:0}setUploadProgress(o){var s,a;if(this.uploadProgress!==o)return this.uploadProgress=o,null===(s=this.uploadProgressDelegate)||void 0===s||null===(a=s.attachmentDidChangeUploadProgress)||void 0===a?void 0:a.call(s,this)}toJSON(){return this.getAttributes()}getCacheKey(){return[super.getCacheKey(...arguments),this.attributes.getCacheKey(),this.getPreviewURL()].join("/")}getPreviewURL(){return this.previewURL||this.preloadingURL}setPreviewURL(o){var s,a,l,c;if(o!==this.getPreviewURL())return this.previewURL=o,null===(s=this.previewDelegate)||void 0===s||null===(a=s.attachmentDidChangeAttributes)||void 0===a||a.call(s,this),null===(l=this.delegate)||void 0===l||null===(c=l.attachmentDidChangePreviewURL)||void 0===c?void 0:c.call(l,this)}preloadURL(){return this.preload(this.getURL(),this.releaseFile)}preloadFile(){if(this.file)return this.fileObjectURL=URL.createObjectURL(this.file),this.preload(this.fileObjectURL)}releasePreloadedFile(){this.fileObjectURL&&(URL.revokeObjectURL(this.fileObjectURL),this.fileObjectURL=null)}preload(o,s){if(o&&o!==this.getPreviewURL()){this.preloadingURL=o;return new Ui(o).then((a=>{let{width:l,height:c}=a;return this.getWidth()&&this.getHeight()||this.setAttributes({width:l,height:c}),this.preloadingURL=null,this.setPreviewURL(o),null==s?void 0:s()})).catch((()=>(this.preloadingURL=null,null==s?void 0:s())))}}}Di(Vi,"previewablePattern",/^image(\/(gif|png|webp|jpe?g)|$)/);class zi extends Wi{static fromJSON(o){return new this(Vi.fromJSON(o.attachment),o.attributes)}constructor(o){super(...arguments),this.attachment=o,this.length=1,this.ensureAttachmentExclusivelyHasAttribute("href"),this.attachment.hasContent()||this.removeProhibitedAttributes()}ensureAttachmentExclusivelyHasAttribute(o){this.hasAttribute(o)&&(this.attachment.hasAttribute(o)||this.attachment.setAttributes(this.attributes.slice([o])),this.attributes=this.attributes.remove(o))}removeProhibitedAttributes(){const o=this.attributes.slice(zi.permittedAttributes);o.isEqualTo(this.attributes)||(this.attributes=o)}getValue(){return this.attachment}isSerializable(){return!this.attachment.isPending()}getCaption(){return this.attributes.get("caption")||""}isEqualTo(o){var s;return super.isEqualTo(o)&&this.attachment.id===(null==o||null===(s=o.attachment)||void 0===s?void 0:s.id)}toString(){return""}toJSON(){const o=super.toJSON(...arguments);return o.attachment=this.attachment,o}getCacheKey(){return[super.getCacheKey(...arguments),this.attachment.getCacheKey()].join("/")}toConsole(){return JSON.stringify(this.toString())}}Di(zi,"permittedAttributes",["caption","presentation"]),Wi.registerType("attachment",zi);class qi extends Wi{static fromJSON(o){return new this(o.string,o.attributes)}constructor(o){super(...arguments),this.string=(o=>o.replace(/\r\n?/g,"\n"))(o),this.length=this.string.length}getValue(){return this.string}toString(){return this.string.toString()}isBlockBreak(){return"\n"===this.toString()&&!0===this.getAttribute("blockBreak")}toJSON(){const o=super.toJSON(...arguments);return o.string=this.string,o}canBeConsolidatedWith(o){return o&&this.hasSameConstructorAs(o)&&this.hasSameAttributesAsPiece(o)}consolidateWith(o){return new this.constructor(this.toString()+o.toString(),this.attributes)}splitAtOffset(o){let s,a;return 0===o?(s=null,a=this):o===this.length?(s=this,a=null):(s=new this.constructor(this.string.slice(0,o),this.attributes),a=new this.constructor(this.string.slice(o),this.attributes)),[s,a]}toConsole(){let{string:o}=this;return o.length>15&&(o=o.slice(0,14)+"…"),JSON.stringify(o.toString())}}Wi.registerType("string",qi);class Hi extends rt{static box(o){return o instanceof this?o:new this(o)}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.objects=o.slice(0),this.length=this.objects.length}indexOf(o){return this.objects.indexOf(o)}splice(){for(var o=arguments.length,s=new Array(o),a=0;ao(s,a)))}insertObjectAtIndex(o,s){return this.splice(s,0,o)}insertSplittableListAtIndex(o,s){return this.splice(s,0,...o.objects)}insertSplittableListAtPosition(o,s){const[a,l]=this.splitObjectAtPosition(s);return new this.constructor(a).insertSplittableListAtIndex(o,l)}editObjectAtIndex(o,s){return this.replaceObjectAtIndex(s(this.objects[o]),o)}replaceObjectAtIndex(o,s){return this.splice(s,1,o)}removeObjectAtIndex(o){return this.splice(o,1)}getObjectAtIndex(o){return this.objects[o]}getSplittableListInRange(o){const[s,a,l]=this.splitObjectsAtRange(o);return new this.constructor(s.slice(a,l+1))}selectSplittableList(o){const s=this.objects.filter((s=>o(s)));return new this.constructor(s)}removeObjectsInRange(o){const[s,a,l]=this.splitObjectsAtRange(o);return new this.constructor(s).splice(a,l-a+1)}transformObjectsInRange(o,s){const[a,l,c]=this.splitObjectsAtRange(o),h=a.map(((o,a)=>l<=a&&a<=c?s(o):o));return new this.constructor(h)}splitObjectsAtRange(o){let s,[a,l,c]=this.splitObjectAtPosition(Ki(o));return[a,s]=new this.constructor(a).splitObjectAtPosition(Gi(o)+c),[a,l,s-1]}getObjectAtPosition(o){const{index:s}=this.findIndexAndOffsetAtPosition(o);return this.objects[s]}splitObjectAtPosition(o){let s,a;const{index:l,offset:c}=this.findIndexAndOffsetAtPosition(o),h=this.objects.slice(0);if(null!=l)if(0===c)s=l,a=0;else{const o=this.getObjectAtIndex(l),[d,g]=o.splitAtOffset(c);h.splice(l,1,d,g),s=l+1,a=d.getLength()-c}else s=h.length,a=0;return[h,s,a]}consolidate(){const o=[];let s=this.objects[0];return this.objects.slice(1).forEach((a=>{var l,c;null!==(l=(c=s).canBeConsolidatedWith)&&void 0!==l&&l.call(c,a)?s=s.consolidateWith(a):(o.push(s),s=a)})),s&&o.push(s),new this.constructor(o)}consolidateFromIndexToIndex(o,s){const a=this.objects.slice(0).slice(o,s+1),l=new this.constructor(a).consolidate().toArray();return this.splice(o,a.length,...l)}findIndexAndOffsetAtPosition(o){let s,a=0;for(s=0;sthis.endPosition+=o.getLength()))),this.endPosition}toString(){return this.objects.join("")}toArray(){return this.objects.slice(0)}toJSON(){return this.toArray()}isEqualTo(o){return super.isEqualTo(...arguments)||Ji(this.objects,null==o?void 0:o.objects)}contentsForInspection(){return{objects:"[".concat(this.objects.map((o=>o.inspect())).join(", "),"]")}}}const Ji=function(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(o.length!==s.length)return!1;let a=!0;for(let l=0;lo[0],Gi=o=>o[1];class Yi extends rt{static textForAttachmentWithAttributes(o,s){return new this([new zi(o,s)])}static textForStringWithAttributes(o,s){return new this([new qi(o,s)])}static fromJSON(o){return new this(Array.from(o).map((o=>Wi.fromJSON(o))))}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments);const s=o.filter((o=>!o.isEmpty()));this.pieceList=new Hi(s)}copy(){return this.copyWithPieceList(this.pieceList)}copyWithPieceList(o){return new this.constructor(o.consolidate().toArray())}copyUsingObjectMap(o){const s=this.getPieces().map((s=>o.find(s)||s));return new this.constructor(s)}appendText(o){return this.insertTextAtPosition(o,this.getLength())}insertTextAtPosition(o,s){return this.copyWithPieceList(this.pieceList.insertSplittableListAtPosition(o.pieceList,s))}removeTextAtRange(o){return this.copyWithPieceList(this.pieceList.removeObjectsInRange(o))}replaceTextAtRange(o,s){return this.removeTextAtRange(s).insertTextAtPosition(o,s[0])}moveTextFromRangeToPosition(o,s){if(o[0]<=s&&s<=o[1])return;const a=this.getTextAtRange(o),l=a.getLength();return o[0]s.copyWithAdditionalAttributes(o))))}removeAttributeAtRange(o,s){return this.copyWithPieceList(this.pieceList.transformObjectsInRange(s,(s=>s.copyWithoutAttribute(o))))}setAttributesAtRange(o,s){return this.copyWithPieceList(this.pieceList.transformObjectsInRange(s,(s=>s.copyWithAttributes(o))))}getAttributesAtPosition(o){var s;return(null===(s=this.pieceList.getObjectAtPosition(o))||void 0===s?void 0:s.getAttributes())||{}}getCommonAttributes(){const o=Array.from(this.pieceList.toArray()).map((o=>o.getAttributes()));return Ht.fromCommonAttributesOfObjects(o).toObject()}getCommonAttributesAtRange(o){return this.getTextAtRange(o).getCommonAttributes()||{}}getExpandedRangeForAttributeAtOffset(o,s){let a,l=a=s;const c=this.getLength();for(;l>0&&this.getCommonAttributesAtRange([l-1,a])[o];)l--;for(;a!!o.attachment))}getAttachments(){return this.getAttachmentPieces().map((o=>o.attachment))}getAttachmentAndPositionById(o){let s=0;for(const l of this.pieceList.toArray()){var a;if((null===(a=l.attachment)||void 0===a?void 0:a.id)===o)return{attachment:l.attachment,position:s};s+=l.length}return{attachment:null,position:null}}getAttachmentById(o){const{attachment:s}=this.getAttachmentAndPositionById(o);return s}getRangeOfAttachment(o){const s=this.getAttachmentAndPositionById(o.id),a=s.position;if(o=s.attachment)return[a,a+1]}updateAttributesForAttachment(o,s){const a=this.getRangeOfAttachment(s);return a?this.addAttributesAtRange(o,a):this}getLength(){return this.pieceList.getEndPosition()}isEmpty(){return 0===this.getLength()}isEqualTo(o){var s;return super.isEqualTo(o)||(null==o||null===(s=o.pieceList)||void 0===s?void 0:s.isEqualTo(this.pieceList))}isBlockBreak(){return 1===this.getLength()&&this.pieceList.getObjectAtIndex(0).isBlockBreak()}eachPiece(o){return this.pieceList.eachObject(o)}getPieces(){return this.pieceList.toArray()}getPieceAtPosition(o){return this.pieceList.getObjectAtPosition(o)}contentsForInspection(){return{pieceList:this.pieceList.inspect()}}toSerializableText(){const o=this.pieceList.selectSplittableList((o=>o.isSerializable()));return this.copyWithPieceList(o)}toString(){return this.pieceList.toString()}toJSON(){return this.pieceList.toJSON()}toConsole(){return JSON.stringify(this.pieceList.toArray().map((o=>JSON.parse(o.toConsole()))))}getDirection(){return Ct(this.toString())}isRTL(){return"rtl"===this.getDirection()}}class $i extends rt{static fromJSON(o){return new this(Yi.fromJSON(o.text),o.attributes,o.htmlAttributes)}constructor(o,s,a){super(...arguments),this.text=Xi(o||new Yi),this.attributes=s||[],this.htmlAttributes=a||{}}isEmpty(){return this.text.isBlockBreak()}isEqualTo(o){return!!super.isEqualTo(o)||this.text.isEqualTo(null==o?void 0:o.text)&&ot(this.attributes,null==o?void 0:o.attributes)&&Tt(this.htmlAttributes,null==o?void 0:o.htmlAttributes)}copyWithText(o){return new $i(o,this.attributes,this.htmlAttributes)}copyWithoutText(){return this.copyWithText(null)}copyWithAttributes(o){return new $i(this.text,o,this.htmlAttributes)}copyWithoutAttributes(){return this.copyWithAttributes(null)}copyUsingObjectMap(o){const s=o.find(this.text);return s?this.copyWithText(s):this.copyWithText(this.text.copyUsingObjectMap(o))}addAttribute(o){const s=this.attributes.concat(rn(o));return this.copyWithAttributes(s)}addHTMLAttribute(o,s){const a=Object.assign({},this.htmlAttributes,{[o]:s});return new $i(this.text,this.attributes,a)}removeAttribute(o){const{listAttribute:s}=mt(o),a=sn(sn(this.attributes,o),s);return this.copyWithAttributes(a)}removeLastAttribute(){return this.removeAttribute(this.getLastAttribute())}getLastAttribute(){return on(this.attributes)}getAttributes(){return this.attributes.slice(0)}getAttributeLevel(){return this.attributes.length}getAttributeAtLevel(o){return this.attributes[o-1]}hasAttribute(o){return this.attributes.includes(o)}hasAttributes(){return this.getAttributeLevel()>0}getLastNestableAttribute(){return on(this.getNestableAttributes())}getNestableAttributes(){return this.attributes.filter((o=>mt(o).nestable))}getNestingLevel(){return this.getNestableAttributes().length}decreaseNestingLevel(){const o=this.getLastNestableAttribute();return o?this.removeAttribute(o):this}increaseNestingLevel(){const o=this.getLastNestableAttribute();if(o){const s=this.attributes.lastIndexOf(o),a=st(this.attributes,s+1,0,...rn(o));return this.copyWithAttributes(a)}return this}getListItemAttributes(){return this.attributes.filter((o=>mt(o).listAttribute))}isListItem(){var o;return null===(o=mt(this.getLastAttribute()))||void 0===o?void 0:o.listAttribute}isTerminalBlock(){var o;return null===(o=mt(this.getLastAttribute()))||void 0===o?void 0:o.terminal}breaksOnReturn(){var o;return null===(o=mt(this.getLastAttribute()))||void 0===o?void 0:o.breakOnReturn}findLineBreakInDirectionFromPosition(o,s){const a=this.toString();let l;switch(o){case"forward":l=a.indexOf("\n",s);break;case"backward":l=a.slice(0,s).lastIndexOf("\n")}if(-1!==l)return l}contentsForInspection(){return{text:this.text.inspect(),attributes:this.attributes}}toString(){return this.text.toString()}toJSON(){return{text:this.text,attributes:this.attributes,htmlAttributes:this.htmlAttributes}}getDirection(){return this.text.getDirection()}isRTL(){return this.text.isRTL()}getLength(){return this.text.getLength()}canBeConsolidatedWith(o){return!this.hasAttributes()&&!o.hasAttributes()&&this.getDirection()===o.getDirection()}consolidateWith(o){const s=Yi.textForStringWithAttributes("\n"),a=this.getTextWithoutBlockBreak().appendText(s);return this.copyWithText(a.appendText(o.text))}splitAtOffset(o){let s,a;return 0===o?(s=null,a=this):o===this.getLength()?(s=this,a=null):(s=this.copyWithText(this.text.getTextAtRange([0,o])),a=this.copyWithText(this.text.getTextAtRange([o,this.getLength()]))),[s,a]}getBlockBreakPosition(){return this.text.getLength()-1}getTextWithoutBlockBreak(){return en(this.text)?this.text.getTextAtRange([0,this.getBlockBreakPosition()]):this.text.copy()}canBeGrouped(o){return this.attributes[o]}canBeGroupedWith(o,s){const a=o.getAttributes(),c=a[s],h=this.attributes[s];return h===c&&!(!1===mt(h).group&&!(()=>{if(!se){se=[];for(const o in l){const{listAttribute:s}=l[o];null!=s&&se.push(s)}}return se})().includes(a[s+1]))&&(this.getDirection()===o.getDirection()||o.isEmpty())}}const Xi=function(o){return o=Zi(o),tn(o)},Zi=function(o){let s=!1;const a=o.getPieces();let l=a.slice(0,a.length-1);const c=a[a.length-1];return c?(l=l.map((o=>o.isBlockBreak()?(s=!0,nn(o)):o)),s?new Yi([...l,c]):o):o},Nn=Yi.textForStringWithAttributes("\n",{blockBreak:!0}),tn=function(o){return en(o)?o:o.appendText(Nn)},en=function(o){const s=o.getLength();return 0!==s&&o.getTextAtRange([s-1,s]).isBlockBreak()},nn=o=>o.copyWithoutAttribute("blockBreak"),rn=function(o){const{listAttribute:s}=mt(o);return s?[s,o]:[o]},on=o=>o.slice(-1)[0],sn=function(o,s){const a=o.lastIndexOf(s);return-1===a?o:st(o,a,1)};class an extends rt{static fromJSON(o){return new this(Array.from(o).map((o=>$i.fromJSON(o))))}static fromString(o,s){const a=Yi.textForStringWithAttributes(o,s);return new this([new $i(a)])}constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),0===o.length&&(o=[new $i]),this.blockList=Hi.box(o)}isEmpty(){const o=this.getBlockAtIndex(0);return 1===this.blockList.length&&o.isEmpty()&&!o.hasAttributes()}copy(){const o=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).consolidateBlocks?this.blockList.consolidate().toArray():this.blockList.toArray();return new this.constructor(o)}copyUsingObjectsFromDocument(o){const s=new Zt(o.getObjects());return this.copyUsingObjectMap(s)}copyUsingObjectMap(o){const s=this.getBlocks().map((s=>o.find(s)||s.copyUsingObjectMap(o)));return new this.constructor(s)}copyWithBaseBlockAttributes(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const s=this.getBlocks().map((s=>{const a=o.concat(s.getAttributes());return s.copyWithAttributes(a)}));return new this.constructor(s)}replaceBlock(o,s){const a=this.blockList.indexOf(o);return-1===a?this:new this.constructor(this.blockList.replaceObjectAtIndex(s,a))}insertDocumentAtRange(o,s){const{blockList:a}=o;s=wt(s);let[l]=s;const{index:c,offset:h}=this.locationFromPosition(l);let d=this;const g=this.getBlockAtPosition(l);return Lt(s)&&g.isEmpty()&&!g.hasAttributes()?d=new this.constructor(d.blockList.removeObjectAtIndex(c)):g.getBlockBreakPosition()===h&&l++,d=d.removeTextAtRange(s),new this.constructor(d.blockList.insertSplittableListAtPosition(a,l))}mergeDocumentAtRange(o,s){let a,l;s=wt(s);const[c]=s,h=this.locationFromPosition(c),d=this.getBlockAtIndex(h.index).getAttributes(),g=o.getBaseBlockAttributes(),p=d.slice(-g.length);if(ot(g,p)){const s=d.slice(0,-g.length);a=o.copyWithBaseBlockAttributes(s)}else a=o.copy({consolidateBlocks:!0}).copyWithBaseBlockAttributes(d);const f=a.getBlockCount(),w=a.getBlockAtIndex(0);if(ot(d,w.getAttributes())){const o=w.getTextWithoutBlockBreak();if(l=this.insertTextAtRange(o,s),f>1){a=new this.constructor(a.getBlocks().slice(1));const s=c+o.getLength();l=l.insertDocumentAtRange(a,s)}}else l=this.insertDocumentAtRange(a,s);return l}insertTextAtRange(o,s){s=wt(s);const[a]=s,{index:l,offset:c}=this.locationFromPosition(a),h=this.removeTextAtRange(s);return new this.constructor(h.blockList.editObjectAtIndex(l,(s=>s.copyWithText(s.text.insertTextAtPosition(o,c)))))}removeTextAtRange(o){let s;o=wt(o);const[a,l]=o;if(Lt(o))return this;const[c,h]=Array.from(this.locationRangeFromRange(o)),d=c.index,g=c.offset,p=this.getBlockAtIndex(d),f=h.index,w=h.offset,_=this.getBlockAtIndex(f);if(l-a==1&&p.getBlockBreakPosition()===g&&_.getBlockBreakPosition()!==w&&"\n"===_.text.getStringAtPosition(w))s=this.blockList.editObjectAtIndex(f,(o=>o.copyWithText(o.text.removeTextAtRange([w,w+1]))));else{let o;const a=p.text.getTextAtRange([0,g]),l=_.text.getTextAtRange([w,_.getLength()]),c=a.appendText(l);o=d!==f&&0===g&&p.getAttributeLevel()>=_.getAttributeLevel()?_.copyWithText(c):p.copyWithText(c);const h=f+1-d;s=this.blockList.splice(d,h,o)}return new this.constructor(s)}moveTextFromRangeToPosition(o,s){let a;o=wt(o);const[l,c]=o;if(l<=s&&s<=c)return this;let h=this.getDocumentAtRange(o),d=this.removeTextAtRange(o);const g=ll=l.editObjectAtIndex(h,(function(){return mt(o)?a.addAttribute(o,s):c[0]===c[1]?a:a.copyWithText(a.text.addAttributeAtRange(o,s,c))})))),new this.constructor(l)}addAttribute(o,s){let{blockList:a}=this;return this.eachBlock(((l,c)=>a=a.editObjectAtIndex(c,(()=>l.addAttribute(o,s))))),new this.constructor(a)}removeAttributeAtRange(o,s){let{blockList:a}=this;return this.eachBlockAtRange(s,(function(s,l,c){mt(o)?a=a.editObjectAtIndex(c,(()=>s.removeAttribute(o))):l[0]!==l[1]&&(a=a.editObjectAtIndex(c,(()=>s.copyWithText(s.text.removeAttributeAtRange(o,l)))))})),new this.constructor(a)}updateAttributesForAttachment(o,s){const a=this.getRangeOfAttachment(s),[l]=Array.from(a),{index:c}=this.locationFromPosition(l),h=this.getTextAtIndex(c);return new this.constructor(this.blockList.editObjectAtIndex(c,(a=>a.copyWithText(h.updateAttributesForAttachment(o,s)))))}removeAttributeForAttachment(o,s){const a=this.getRangeOfAttachment(s);return this.removeAttributeAtRange(o,a)}setHTMLAttributeAtPosition(o,s,a){const l=this.getBlockAtPosition(o),c=l.addHTMLAttribute(s,a);return this.replaceBlock(l,c)}insertBlockBreakAtRange(o){let s;o=wt(o);const[a]=o,{offset:l}=this.locationFromPosition(a),c=this.removeTextAtRange(o);return 0===l&&(s=[new $i]),new this.constructor(c.blockList.insertSplittableListAtPosition(new Hi(s),a))}applyBlockAttributeAtRange(o,s,a){const l=this.expandRangeToLineBreaksAndSplitBlocks(a);let c=l.document;a=l.range;const h=mt(o);if(h.listAttribute){c=c.removeLastListAttributeAtRange(a,{exceptAttributeName:o});const s=c.convertLineBreaksToBlockBreaksInRange(a);c=s.document,a=s.range}else c=h.exclusive?c.removeBlockAttributesAtRange(a):h.terminal?c.removeLastTerminalAttributeAtRange(a):c.consolidateBlocksAtRange(a);return c.addAttributeAtRange(o,s,a)}removeLastListAttributeAtRange(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{blockList:a}=this;return this.eachBlockAtRange(o,(function(o,l,c){const h=o.getLastAttribute();h&&mt(h).listAttribute&&h!==s.exceptAttributeName&&(a=a.editObjectAtIndex(c,(()=>o.removeAttribute(h))))})),new this.constructor(a)}removeLastTerminalAttributeAtRange(o){let{blockList:s}=this;return this.eachBlockAtRange(o,(function(o,a,l){const c=o.getLastAttribute();c&&mt(c).terminal&&(s=s.editObjectAtIndex(l,(()=>o.removeAttribute(c))))})),new this.constructor(s)}removeBlockAttributesAtRange(o){let{blockList:s}=this;return this.eachBlockAtRange(o,(function(o,a,l){o.hasAttributes()&&(s=s.editObjectAtIndex(l,(()=>o.copyWithoutAttributes())))})),new this.constructor(s)}expandRangeToLineBreaksAndSplitBlocks(o){let s;o=wt(o);let[a,l]=o;const c=this.locationFromPosition(a),h=this.locationFromPosition(l);let d=this;const g=d.getBlockAtIndex(c.index);if(c.offset=g.findLineBreakInDirectionFromPosition("backward",c.offset),null!=c.offset&&(s=d.positionFromLocation(c),d=d.insertBlockBreakAtRange([s,s+1]),h.index+=1,h.offset-=d.getBlockAtIndex(c.index).getLength(),c.index+=1),c.offset=0,0===h.offset&&h.index>c.index)h.index-=1,h.offset=d.getBlockAtIndex(h.index).getBlockBreakPosition();else{const o=d.getBlockAtIndex(h.index);"\n"===o.text.getStringAtRange([h.offset-1,h.offset])?h.offset-=1:h.offset=o.findLineBreakInDirectionFromPosition("forward",h.offset),h.offset!==o.getBlockBreakPosition()&&(s=d.positionFromLocation(h),d=d.insertBlockBreakAtRange([s,s+1]))}return a=d.positionFromLocation(c),l=d.positionFromLocation(h),{document:d,range:o=wt([a,l])}}convertLineBreaksToBlockBreaksInRange(o){o=wt(o);let[s]=o;const a=this.getStringAtRange(o).slice(0,-1);let l=this;return a.replace(/.*?\n/g,(function(o){s+=o.length,l=l.insertBlockBreakAtRange([s-1,s])})),{document:l,range:o}}consolidateBlocksAtRange(o){o=wt(o);const[s,a]=o,l=this.locationFromPosition(s).index,c=this.locationFromPosition(a).index;return new this.constructor(this.blockList.consolidateFromIndexToIndex(l,c))}getDocumentAtRange(o){o=wt(o);const s=this.blockList.getSplittableListInRange(o).toArray();return new this.constructor(s)}getStringAtRange(o){let s;const a=o=wt(o);return a[a.length-1]!==this.getLength()&&(s=-1),this.getDocumentAtRange(o).toString().slice(0,s)}getBlockAtIndex(o){return this.blockList.getObjectAtIndex(o)}getBlockAtPosition(o){const{index:s}=this.locationFromPosition(o);return this.getBlockAtIndex(s)}getTextAtIndex(o){var s;return null===(s=this.getBlockAtIndex(o))||void 0===s?void 0:s.text}getTextAtPosition(o){const{index:s}=this.locationFromPosition(o);return this.getTextAtIndex(s)}getPieceAtPosition(o){const{index:s,offset:a}=this.locationFromPosition(o);return this.getTextAtIndex(s).getPieceAtPosition(a)}getCharacterAtPosition(o){const{index:s,offset:a}=this.locationFromPosition(o);return this.getTextAtIndex(s).getStringAtRange([a,a+1])}getLength(){return this.blockList.getEndPosition()}getBlocks(){return this.blockList.toArray()}getBlockCount(){return this.blockList.length}getEditCount(){return this.editCount}eachBlock(o){return this.blockList.eachObject(o)}eachBlockAtRange(o,s){let a,l;o=wt(o);const[c,h]=o,d=this.locationFromPosition(c),g=this.locationFromPosition(h);if(d.index===g.index)return a=this.getBlockAtIndex(d.index),l=[d.offset,g.offset],s(a,l,d.index);for(let o=d.index;o<=g.index;o++)if(a=this.getBlockAtIndex(o),a){switch(o){case d.index:l=[d.offset,a.text.getLength()];break;case g.index:l=[0,g.offset];break;default:l=[0,a.text.getLength()]}s(a,l,o)}}getCommonAttributesAtRange(o){o=wt(o);const[s]=o;if(Lt(o))return this.getCommonAttributesAtPosition(s);{const s=[],a=[];return this.eachBlockAtRange(o,(function(o,l){if(l[0]!==l[1])return s.push(o.text.getCommonAttributesAtRange(l)),a.push(ln(o))})),Ht.fromCommonAttributesOfObjects(s).merge(Ht.fromCommonAttributesOfObjects(a)).toObject()}}getCommonAttributesAtPosition(o){let s,a;const{index:l,offset:c}=this.locationFromPosition(o),h=this.getBlockAtIndex(l);if(!h)return{};const d=ln(h),g=h.text.getAttributesAtPosition(c),p=h.text.getAttributesAtPosition(c-1),f=Object.keys(K).filter((o=>K[o].inheritable));for(s in p)a=p[s],(a===g[s]||f.includes(s))&&(d[s]=a);return d}getRangeOfCommonAttributeAtPosition(o,s){const{index:a,offset:l}=this.locationFromPosition(s),c=this.getTextAtIndex(a),[h,d]=Array.from(c.getExpandedRangeForAttributeAtOffset(o,l)),g=this.positionFromLocation({index:a,offset:h}),p=this.positionFromLocation({index:a,offset:d});return wt([g,p])}getBaseBlockAttributes(){let o=this.getBlockAtIndex(0).getAttributes();for(let s=1;s{const s=[];for(let c=0;c{let{text:a}=s;return o=o.concat(a.getAttachmentPieces())})),o}getAttachments(){return this.getAttachmentPieces().map((o=>o.attachment))}getRangeOfAttachment(o){let s=0;const a=this.blockList.toArray();for(let l=0;l{const c=l.getLength();l.hasAttribute(o)&&a.push([s,s+c]),s+=c})),a}findRangesForTextAttribute(o){let{withValue:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=0,l=[];const c=[];return this.getPieces().forEach((h=>{const d=h.getLength();(function(a){return s?a.getAttribute(o)===s:a.hasAttribute(o)})(h)&&(l[1]===a?l[1]=a+d:c.push(l=[a,a+d])),a+=d})),c}locationFromPosition(o){const s=this.blockList.findIndexAndOffsetAtPosition(Math.max(0,o));if(null!=s.index)return s;{const o=this.getBlocks();return{index:o.length-1,offset:o[o.length-1].getLength()}}}positionFromLocation(o){return this.blockList.findPositionAtIndexAndOffset(o.index,o.offset)}locationRangeFromPosition(o){return wt(this.locationFromPosition(o))}locationRangeFromRange(o){if(!(o=wt(o)))return;const[s,a]=Array.from(o),l=this.locationFromPosition(s),c=this.locationFromPosition(a);return wt([l,c])}rangeFromLocationRange(o){let s;o=wt(o);const a=this.positionFromLocation(o[0]);return Lt(o)||(s=this.positionFromLocation(o[1])),wt([a,s])}isEqualTo(o){return this.blockList.isEqualTo(null==o?void 0:o.blockList)}getTexts(){return this.getBlocks().map((o=>o.text))}getPieces(){const o=[];return Array.from(this.getTexts()).forEach((s=>{o.push(...Array.from(s.getPieces()||[]))})),o}getObjects(){return this.getBlocks().concat(this.getTexts()).concat(this.getPieces())}toSerializableDocument(){const o=[];return this.blockList.eachObject((s=>o.push(s.copyWithText(s.text.toSerializableText())))),new this.constructor(o)}toString(){return this.blockList.toString()}toJSON(){return this.blockList.toJSON()}toConsole(){return JSON.stringify(this.blockList.toArray().map((o=>JSON.parse(o.text.toConsole()))))}}const ln=function(o){const s={},a=o.getLastAttribute();return a&&(s[a]=!0),s},cn=function(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{string:o=Wt(o),attributes:s,type:"string"}},un=(o,s)=>{try{return JSON.parse(o.getAttribute("data-trix-".concat(s)))}catch(o){return{}}};class hn extends q{static parse(o,s){const a=new this(o,s);return a.parse(),a}constructor(o){let{referenceElement:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.html=o,this.referenceElement=s,this.blocks=[],this.blockElements=[],this.processedElements=[]}getDocument(){return an.fromJSON(this.blocks)}parse(){try{this.createHiddenContainer(),di.setHTML(this.containerElement,this.html);const o=R(this.containerElement,{usingFilter:pn});for(;o.nextNode();)this.processNode(o.currentNode);return this.translateBlockElementMarginsToNewlines()}finally{this.removeHiddenContainer()}}createHiddenContainer(){return this.referenceElement?(this.containerElement=this.referenceElement.cloneNode(!1),this.containerElement.removeAttribute("id"),this.containerElement.setAttribute("data-trix-internal",""),this.containerElement.style.display="none",this.referenceElement.parentNode.insertBefore(this.containerElement,this.referenceElement.nextSibling)):(this.containerElement=T({tagName:"div",style:{display:"none"}}),document.body.appendChild(this.containerElement))}removeHiddenContainer(){return S(this.containerElement)}processNode(o){switch(o.nodeType){case Node.TEXT_NODE:if(!this.isInsignificantTextNode(o))return this.appendBlockForTextNode(o),this.processTextNode(o);break;case Node.ELEMENT_NODE:return this.appendBlockForElement(o),this.processElement(o)}}appendBlockForTextNode(o){const s=o.parentNode;if(s===this.currentBlockElement&&this.isBlockElement(o.previousSibling))return this.appendStringWithAttributes("\n");if(s===this.containerElement||this.isBlockElement(s)){var a;const o=this.getBlockAttributes(s),l=this.getBlockHTMLAttributes(s);ot(o,null===(a=this.currentBlock)||void 0===a?void 0:a.attributes)||(this.currentBlock=this.appendBlockForAttributesWithElement(o,s,l),this.currentBlockElement=s)}}appendBlockForElement(o){const s=this.isBlockElement(o),a=C(this.currentBlockElement,o);if(s&&!this.isBlockElement(o.firstChild)){if(!this.isInsignificantTextNode(o.firstChild)||!this.isBlockElement(o.firstElementChild)){const s=this.getBlockAttributes(o),l=this.getBlockHTMLAttributes(o);if(o.firstChild){if(a&&ot(s,this.currentBlock.attributes))return this.appendStringWithAttributes("\n");this.currentBlock=this.appendBlockForAttributesWithElement(s,o,l),this.currentBlockElement=o}}}else if(this.currentBlockElement&&!a&&!s){const s=this.findParentBlockElement(o);if(s)return this.appendBlockForElement(s);this.currentBlock=this.appendEmptyBlock(),this.currentBlockElement=null}}findParentBlockElement(o){let{parentElement:s}=o;for(;s&&s!==this.containerElement;){if(this.isBlockElement(s)&&this.blockElements.includes(s))return s;s=s.parentElement}return null}processTextNode(o){let s=o.data;var a;dn(o.parentNode)||(s=Vt(s),vn(null===(a=o.previousSibling)||void 0===a?void 0:a.textContent)&&(s=fn(s)));return this.appendStringWithAttributes(s,this.getTextAttributes(o.parentNode))}processElement(o){let s;if(P(o)){if(s=un(o,"attachment"),Object.keys(s).length){const a=this.getTextAttributes(o);this.appendAttachmentWithAttributes(s,a),o.innerHTML=""}return this.processedElements.push(o)}switch(k(o)){case"br":return this.isExtraBR(o)||this.isBlockElement(o.nextSibling)||this.appendStringWithAttributes("\n",this.getTextAttributes(o)),this.processedElements.push(o);case"img":s={url:o.getAttribute("src"),contentType:"image"};const a=(o=>{const s=o.getAttribute("width"),a=o.getAttribute("height"),l={};return s&&(l.width=parseInt(s,10)),a&&(l.height=parseInt(a,10)),l})(o);for(const o in a){const l=a[o];s[o]=l}return this.appendAttachmentWithAttributes(s,this.getTextAttributes(o)),this.processedElements.push(o);case"tr":if(this.needsTableSeparator(o))return this.appendStringWithAttributes(J.tableRowSeparator);break;case"td":if(this.needsTableSeparator(o))return this.appendStringWithAttributes(J.tableCellSeparator)}}appendBlockForAttributesWithElement(o,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.blockElements.push(s);const l=function(){return{text:[],attributes:arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},htmlAttributes:arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}}}(o,a);return this.blocks.push(l),l}appendEmptyBlock(){return this.appendBlockForAttributesWithElement([],null)}appendStringWithAttributes(o,s){return this.appendPiece(cn(o,s))}appendAttachmentWithAttributes(o,s){return this.appendPiece(function(o){return{attachment:o,attributes:arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},type:"attachment"}}(o,s))}appendPiece(o){return 0===this.blocks.length&&this.appendEmptyBlock(),this.blocks[this.blocks.length-1].text.push(o)}appendStringToTextAtIndex(o,s){const{text:a}=this.blocks[s],l=a[a.length-1];if("string"!==(null==l?void 0:l.type))return a.push(cn(o));l.string+=o}prependStringToTextAtIndex(o,s){const{text:a}=this.blocks[s],l=a[0];if("string"!==(null==l?void 0:l.type))return a.unshift(cn(o));l.string=o+l.string}getTextAttributes(o){let s;const a={};for(const l in K){const c=K[l];if(c.tagName&&y(o,{matchingSelector:c.tagName,untilNode:this.containerElement}))a[l]=!0;else if(c.parser){if(s=c.parser(o),s){let h=!1;for(const a of this.findBlockElementAncestors(o))if(c.parser(a)===s){h=!0;break}h||(a[l]=s)}}else c.styleProperty&&(s=o.style[c.styleProperty],s&&(a[l]=s))}if(P(o)){const l=un(o,"attributes");for(const o in l)s=l[o],a[o]=s}return a}getBlockAttributes(o){const s=[];for(;o&&o!==this.containerElement;){for(const c in l){const h=l[c];var a;!1!==h.parse&&k(o)===h.tagName&&(null!==(a=h.test)&&void 0!==a&&a.call(h,o)||!h.test)&&(s.push(c),h.listAttribute&&s.push(h.listAttribute))}o=o.parentNode}return s.reverse()}getBlockHTMLAttributes(o){const s={},a=Object.values(l).find((s=>s.tagName===k(o)));return((null==a?void 0:a.htmlAttributes)||[]).forEach((a=>{o.hasAttribute(a)&&(s[a]=o.getAttribute(a))})),s}findBlockElementAncestors(o){const s=[];for(;o&&o!==this.containerElement;){const a=k(o);L().includes(a)&&s.push(o),o=o.parentNode}return s}isBlockElement(o){if((null==o?void 0:o.nodeType)===Node.ELEMENT_NODE&&!P(o)&&!y(o,{matchingSelector:"td",untilNode:this.containerElement}))return L().includes(k(o))||"block"===window.getComputedStyle(o).display}isInsignificantTextNode(o){if((null==o?void 0:o.nodeType)!==Node.TEXT_NODE)return;if(!bn(o.data))return;const{parentNode:s,previousSibling:a,nextSibling:l}=o;return gn(s.previousSibling)&&!this.isBlockElement(s.previousSibling)||dn(s)?void 0:!a||this.isBlockElement(a)||!l||this.isBlockElement(l)}isExtraBR(o){return"br"===k(o)&&this.isBlockElement(o.parentNode)&&o.parentNode.lastChild===o}needsTableSeparator(o){if(J.removeBlankTableCells){var s;const a=null===(s=o.previousSibling)||void 0===s?void 0:s.textContent;return a&&/\S/.test(a)}return o.previousSibling}translateBlockElementMarginsToNewlines(){const o=this.getMarginOfDefaultBlockElement();for(let s=0;s2*o.top&&this.prependStringToTextAtIndex("\n",s),a.bottom>2*o.bottom&&this.appendStringToTextAtIndex("\n",s))}}getMarginOfBlockElementAtIndex(o){const s=this.blockElements[o];if(s&&s.textContent&&!L().includes(k(s))&&!this.processedElements.includes(s))return mn(s)}getMarginOfDefaultBlockElement(){const o=T(l.default.tagName);return this.containerElement.appendChild(o),mn(o)}}const dn=function(o){const{whiteSpace:s}=window.getComputedStyle(o);return["pre","pre-wrap","pre-line"].includes(s)},gn=o=>o&&!vn(o.textContent),mn=function(o){const s=window.getComputedStyle(o);if("block"===s.display)return{top:parseInt(s.marginTop),bottom:parseInt(s.marginBottom)}},pn=function(o){return"style"===k(o)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},fn=o=>o.replace(new RegExp("^".concat(ue.source,"+")),""),bn=o=>new RegExp("^".concat(ue.source,"*$")).test(o),vn=o=>/\s$/.test(o),Fn=["contenteditable","data-trix-id","data-trix-store-key","data-trix-mutable","data-trix-placeholder","tabindex"],qn="data-trix-serialized-attributes",Hn="[".concat(qn,"]"),zn=new RegExp("\x3c!--block--\x3e","g"),Jn={"application/json":function(o){let s;if(o instanceof an)s=o;else{if(!(o instanceof HTMLElement))throw new Error("unserializable object");s=hn.parse(o.innerHTML).getDocument()}return s.toSerializableDocument().toJSONString()},"text/html":function(o){let s;if(o instanceof an)s=Si.render(o);else{if(!(o instanceof HTMLElement))throw new Error("unserializable object");s=o.cloneNode(!0)}return Array.from(s.querySelectorAll("[data-trix-serialize=false]")).forEach((o=>{S(o)})),Fn.forEach((o=>{Array.from(s.querySelectorAll("[".concat(o,"]"))).forEach((s=>{s.removeAttribute(o)}))})),Array.from(s.querySelectorAll(Hn)).forEach((o=>{try{const s=JSON.parse(o.getAttribute(qn));o.removeAttribute(qn);for(const a in s){const l=s[a];o.setAttribute(a,l)}}catch(o){}})),s.innerHTML.replace(zn,"")}};var Kn=Object.freeze({__proto__:null});class Rn extends q{constructor(o,s){super(...arguments),this.attachmentManager=o,this.attachment=s,this.id=this.attachment.id,this.file=this.attachment.file}remove(){return this.attachmentManager.requestRemovalOfAttachment(this.attachment)}}Rn.proxyMethod("attachment.getAttribute"),Rn.proxyMethod("attachment.hasAttribute"),Rn.proxyMethod("attachment.setAttribute"),Rn.proxyMethod("attachment.getAttributes"),Rn.proxyMethod("attachment.setAttributes"),Rn.proxyMethod("attachment.isPending"),Rn.proxyMethod("attachment.isPreviewable"),Rn.proxyMethod("attachment.getURL"),Rn.proxyMethod("attachment.getHref"),Rn.proxyMethod("attachment.getFilename"),Rn.proxyMethod("attachment.getFilesize"),Rn.proxyMethod("attachment.getFormattedFilesize"),Rn.proxyMethod("attachment.getExtension"),Rn.proxyMethod("attachment.getContentType"),Rn.proxyMethod("attachment.getFile"),Rn.proxyMethod("attachment.setFile"),Rn.proxyMethod("attachment.releaseFile"),Rn.proxyMethod("attachment.getUploadProgress"),Rn.proxyMethod("attachment.setUploadProgress");class kn extends q{constructor(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.managedAttachments={},Array.from(o).forEach((o=>{this.manageAttachment(o)}))}getAttachments(){const o=[];for(const s in this.managedAttachments){const a=this.managedAttachments[s];o.push(a)}return o}manageAttachment(o){return this.managedAttachments[o.id]||(this.managedAttachments[o.id]=new Rn(this,o)),this.managedAttachments[o.id]}attachmentIsManaged(o){return o.id in this.managedAttachments}requestRemovalOfAttachment(o){var s,a;if(this.attachmentIsManaged(o))return null===(s=this.delegate)||void 0===s||null===(a=s.attachmentManagerDidRequestRemovalOfAttachment)||void 0===a?void 0:a.call(s,o)}unmanageAttachment(o){const s=this.managedAttachments[o.id];return delete this.managedAttachments[o.id],s}}class Tn{constructor(o){this.composition=o,this.document=this.composition.document;const s=this.composition.getSelectedRange();this.startPosition=s[0],this.endPosition=s[1],this.startLocation=this.document.locationFromPosition(this.startPosition),this.endLocation=this.document.locationFromPosition(this.endPosition),this.block=this.document.getBlockAtIndex(this.endLocation.index),this.breaksOnReturn=this.block.breaksOnReturn(),this.previousCharacter=this.block.text.getStringAtPosition(this.endLocation.offset-1),this.nextCharacter=this.block.text.getStringAtPosition(this.endLocation.offset)}shouldInsertBlockBreak(){return this.block.hasAttributes()&&this.block.isListItem()&&!this.block.isEmpty()?0!==this.startLocation.offset:this.breaksOnReturn&&"\n"!==this.nextCharacter}shouldBreakFormattedBlock(){return this.block.hasAttributes()&&!this.block.isListItem()&&(this.breaksOnReturn&&"\n"===this.nextCharacter||"\n"===this.previousCharacter)}shouldDecreaseListLevel(){return this.block.hasAttributes()&&this.block.isListItem()&&this.block.isEmpty()}shouldPrependListItem(){return this.block.isListItem()&&0===this.startLocation.offset&&!this.block.isEmpty()}shouldRemoveLastBlockAttribute(){return this.block.hasAttributes()&&!this.block.isListItem()&&this.block.isEmpty()}}class wn extends q{constructor(){super(...arguments),this.document=new an,this.attachments=[],this.currentAttributes={},this.revision=0}setDocument(o){var s,a;if(!o.isEqualTo(this.document))return this.document=o,this.refreshAttachments(),this.revision++,null===(s=this.delegate)||void 0===s||null===(a=s.compositionDidChangeDocument)||void 0===a?void 0:a.call(s,o)}getSnapshot(){return{document:this.document,selectedRange:this.getSelectedRange()}}loadSnapshot(o){var s,a,l,c;let{document:h,selectedRange:d}=o;return null===(s=this.delegate)||void 0===s||null===(a=s.compositionWillLoadSnapshot)||void 0===a||a.call(s),this.setDocument(null!=h?h:new an),this.setSelection(null!=d?d:[0,0]),null===(l=this.delegate)||void 0===l||null===(c=l.compositionDidLoadSnapshot)||void 0===c?void 0:c.call(l)}insertText(o){let{updatePosition:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{updatePosition:!0};const a=this.getSelectedRange();this.setDocument(this.document.insertTextAtRange(o,a));const l=a[0],c=l+o.getLength();return s&&this.setSelection(c),this.notifyDelegateOfInsertionAtRange([l,c])}insertBlock(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new $i;const s=new an([o]);return this.insertDocument(s)}insertDocument(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new an;const s=this.getSelectedRange();this.setDocument(this.document.insertDocumentAtRange(o,s));const a=s[0],l=a+o.getLength();return this.setSelection(l),this.notifyDelegateOfInsertionAtRange([a,l])}insertString(o,s){const a=this.getCurrentTextAttributes(),l=Yi.textForStringWithAttributes(o,a);return this.insertText(l,s)}insertBlockBreak(){const o=this.getSelectedRange();this.setDocument(this.document.insertBlockBreakAtRange(o));const s=o[0],a=s+1;return this.setSelection(a),this.notifyDelegateOfInsertionAtRange([s,a])}insertLineBreak(){const o=new Tn(this);if(o.shouldDecreaseListLevel())return this.decreaseListLevel(),this.setSelection(o.startPosition);if(o.shouldPrependListItem()){const s=new an([o.block.copyWithoutText()]);return this.insertDocument(s)}return o.shouldInsertBlockBreak()?this.insertBlockBreak():o.shouldRemoveLastBlockAttribute()?this.removeLastBlockAttribute():o.shouldBreakFormattedBlock()?this.breakFormattedBlock(o):this.insertString("\n")}insertHTML(o){const s=hn.parse(o).getDocument(),a=this.getSelectedRange();this.setDocument(this.document.mergeDocumentAtRange(s,a));const l=a[0],c=l+s.getLength()-1;return this.setSelection(c),this.notifyDelegateOfInsertionAtRange([l,c])}replaceHTML(o){const s=hn.parse(o).getDocument().copyUsingObjectsFromDocument(this.document),a=this.getLocationRange({strict:!1}),l=this.document.rangeFromLocationRange(a);return this.setDocument(s),this.setSelection(l)}insertFile(o){return this.insertFiles([o])}insertFiles(o){const s=[];return Array.from(o).forEach((o=>{var a;if(null!==(a=this.delegate)&&void 0!==a&&a.compositionShouldAcceptFile(o)){const a=Vi.attachmentForFile(o);s.push(a)}})),this.insertAttachments(s)}insertAttachment(o){return this.insertAttachments([o])}insertAttachments(o){let s=new Yi;return Array.from(o).forEach((o=>{var l;const c=o.getType(),h=null===(l=a[c])||void 0===l?void 0:l.presentation,d=this.getCurrentTextAttributes();h&&(d.presentation=h);const g=Yi.textForAttachmentWithAttributes(o,d);s=s.appendText(g)})),this.insertText(s)}shouldManageDeletingInDirection(o){const s=this.getLocationRange();if(Lt(s)){if("backward"===o&&0===s[0].offset)return!0;if(this.shouldManageMovingCursorInDirection(o))return!0}else if(s[0].index!==s[1].index)return!0;return!1}deleteInDirection(o){let s,a,l,{length:c}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const h=this.getLocationRange();let d=this.getSelectedRange();const g=Lt(d);if(g?a="backward"===o&&0===h[0].offset:l=h[0].index!==h[1].index,a&&this.canDecreaseBlockAttributeLevel()){const o=this.getBlock();if(o.isListItem()?this.decreaseListLevel():this.decreaseBlockAttributeLevel(),this.setSelection(d[0]),o.isEmpty())return!1}return g&&(d=this.getExpandedRangeInDirection(o,{length:c}),"backward"===o&&(s=this.getAttachmentAtRange(d))),s?(this.editAttachment(s),!1):(this.setDocument(this.document.removeTextAtRange(d)),this.setSelection(d[0]),!a&&!l&&void 0)}moveTextFromRange(o){const[s]=Array.from(this.getSelectedRange());return this.setDocument(this.document.moveTextFromRangeToPosition(o,s)),this.setSelection(s)}removeAttachment(o){const s=this.document.getRangeOfAttachment(o);if(s)return this.stopEditingAttachment(),this.setDocument(this.document.removeTextAtRange(s)),this.setSelection(s[0])}removeLastBlockAttribute(){const[o,s]=Array.from(this.getSelectedRange()),a=this.document.getBlockAtPosition(s);return this.removeCurrentAttribute(a.getLastAttribute()),this.setSelection(o)}insertPlaceholder(){return this.placeholderPosition=this.getPosition(),this.insertString(" ")}selectPlaceholder(){if(null!=this.placeholderPosition)return this.setSelectedRange([this.placeholderPosition,this.placeholderPosition+1]),this.getSelectedRange()}forgetPlaceholder(){this.placeholderPosition=null}hasCurrentAttribute(o){const s=this.currentAttributes[o];return null!=s&&!1!==s}toggleCurrentAttribute(o){const s=!this.currentAttributes[o];return s?this.setCurrentAttribute(o,s):this.removeCurrentAttribute(o)}canSetCurrentAttribute(o){return mt(o)?this.canSetCurrentBlockAttribute(o):this.canSetCurrentTextAttribute(o)}canSetCurrentTextAttribute(o){const s=this.getSelectedDocument();if(s){for(const o of Array.from(s.getAttachments()))if(!o.hasContent())return!1;return!0}}canSetCurrentBlockAttribute(o){const s=this.getBlock();if(s)return!s.isTerminalBlock()}setCurrentAttribute(o,s){return mt(o)?this.setBlockAttribute(o,s):(this.setTextAttribute(o,s),this.currentAttributes[o]=s,this.notifyDelegateOfCurrentAttributesChange())}setHTMLAtributeAtPosition(o,s,a){var l;const c=this.document.getBlockAtPosition(o),h=null===(l=mt(c.getLastAttribute()))||void 0===l?void 0:l.htmlAttributes;if(c&&null!=h&&h.includes(s)){const l=this.document.setHTMLAttributeAtPosition(o,s,a);this.setDocument(l)}}setTextAttribute(o,s){const a=this.getSelectedRange();if(!a)return;const[l,c]=Array.from(a);if(l!==c)return this.setDocument(this.document.addAttributeAtRange(o,s,a));if("href"===o){const o=Yi.textForStringWithAttributes(s,{href:s});return this.insertText(o)}}setBlockAttribute(o,s){const a=this.getSelectedRange();if(this.canSetCurrentAttribute(o))return this.setDocument(this.document.applyBlockAttributeAtRange(o,s,a)),this.setSelection(a)}removeCurrentAttribute(o){return mt(o)?(this.removeBlockAttribute(o),this.updateCurrentAttributes()):(this.removeTextAttribute(o),delete this.currentAttributes[o],this.notifyDelegateOfCurrentAttributesChange())}removeTextAttribute(o){const s=this.getSelectedRange();if(s)return this.setDocument(this.document.removeAttributeAtRange(o,s))}removeBlockAttribute(o){const s=this.getSelectedRange();if(s)return this.setDocument(this.document.removeAttributeAtRange(o,s))}canDecreaseNestingLevel(){var o;return(null===(o=this.getBlock())||void 0===o?void 0:o.getNestingLevel())>0}canIncreaseNestingLevel(){var o;const s=this.getBlock();if(s){if(null===(o=mt(s.getLastNestableAttribute()))||void 0===o||!o.listAttribute)return s.getNestingLevel()>0;{const o=this.getPreviousBlock();if(o)return function(){let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return ot((arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).slice(0,o.length),o)}(o.getListItemAttributes(),s.getListItemAttributes())}}}decreaseNestingLevel(){const o=this.getBlock();if(o)return this.setDocument(this.document.replaceBlock(o,o.decreaseNestingLevel()))}increaseNestingLevel(){const o=this.getBlock();if(o)return this.setDocument(this.document.replaceBlock(o,o.increaseNestingLevel()))}canDecreaseBlockAttributeLevel(){var o;return(null===(o=this.getBlock())||void 0===o?void 0:o.getAttributeLevel())>0}decreaseBlockAttributeLevel(){var o;const s=null===(o=this.getBlock())||void 0===o?void 0:o.getLastAttribute();if(s)return this.removeCurrentAttribute(s)}decreaseListLevel(){let[o]=Array.from(this.getSelectedRange());const{index:s}=this.document.locationFromPosition(o);let a=s;const l=this.getBlock().getAttributeLevel();let c=this.document.getBlockAtIndex(a+1);for(;c&&c.isListItem()&&!(c.getAttributeLevel()<=l);)a++,c=this.document.getBlockAtIndex(a+1);o=this.document.positionFromLocation({index:s,offset:0});const h=this.document.positionFromLocation({index:a,offset:0});return this.setDocument(this.document.removeLastListAttributeAtRange([o,h]))}updateCurrentAttributes(){const o=this.getSelectedRange({ignoreLock:!0});if(o){const s=this.document.getCommonAttributesAtRange(o);if(Array.from(gt()).forEach((o=>{s[o]||this.canSetCurrentAttribute(o)||(s[o]=!1)})),!Tt(s,this.currentAttributes))return this.currentAttributes=s,this.notifyDelegateOfCurrentAttributesChange()}}getCurrentAttributes(){return m.call({},this.currentAttributes)}getCurrentTextAttributes(){const o={};for(const s in this.currentAttributes){const a=this.currentAttributes[s];!1!==a&&ft(s)&&(o[s]=a)}return o}freezeSelection(){return this.setCurrentAttribute("frozen",!0)}thawSelection(){return this.removeCurrentAttribute("frozen")}hasFrozenSelection(){return this.hasCurrentAttribute("frozen")}setSelection(o){var s;const a=this.document.locationRangeFromRange(o);return null===(s=this.delegate)||void 0===s?void 0:s.compositionDidRequestChangingSelectionToLocationRange(a)}getSelectedRange(){const o=this.getLocationRange();if(o)return this.document.rangeFromLocationRange(o)}setSelectedRange(o){const s=this.document.locationRangeFromRange(o);return this.getSelectionManager().setLocationRange(s)}getPosition(){const o=this.getLocationRange();if(o)return this.document.positionFromLocation(o[0])}getLocationRange(o){return this.targetLocationRange?this.targetLocationRange:this.getSelectionManager().getLocationRange(o)||wt({index:0,offset:0})}withTargetLocationRange(o,s){let a;this.targetLocationRange=o;try{a=s()}finally{this.targetLocationRange=null}return a}withTargetRange(o,s){const a=this.document.locationRangeFromRange(o);return this.withTargetLocationRange(a,s)}withTargetDOMRange(o,s){const a=this.createLocationRangeFromDOMRange(o,{strict:!1});return this.withTargetLocationRange(a,s)}getExpandedRangeInDirection(o){let{length:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[a,l]=Array.from(this.getSelectedRange());return"backward"===o?s?a-=s:a=this.translateUTF16PositionFromOffset(a,-1):s?l+=s:l=this.translateUTF16PositionFromOffset(l,1),wt([a,l])}shouldManageMovingCursorInDirection(o){if(this.editingAttachment)return!0;const s=this.getExpandedRangeInDirection(o);return null!=this.getAttachmentAtRange(s)}moveCursorInDirection(o){let s,a;if(this.editingAttachment)a=this.document.getRangeOfAttachment(this.editingAttachment);else{const l=this.getSelectedRange();a=this.getExpandedRangeInDirection(o),s=!Dt(l,a)}if("backward"===o?this.setSelectedRange(a[0]):this.setSelectedRange(a[1]),s){const o=this.getAttachmentAtRange(a);if(o)return this.editAttachment(o)}}expandSelectionInDirection(o){let{length:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const a=this.getExpandedRangeInDirection(o,{length:s});return this.setSelectedRange(a)}expandSelectionForEditing(){if(this.hasCurrentAttribute("href"))return this.expandSelectionAroundCommonAttribute("href")}expandSelectionAroundCommonAttribute(o){const s=this.getPosition(),a=this.document.getRangeOfCommonAttributeAtPosition(o,s);return this.setSelectedRange(a)}selectionContainsAttachments(){var o;return(null===(o=this.getSelectedAttachments())||void 0===o?void 0:o.length)>0}selectionIsInCursorTarget(){return this.editingAttachment||this.positionIsCursorTarget(this.getPosition())}positionIsCursorTarget(o){const s=this.document.locationFromPosition(o);if(s)return this.locationIsCursorTarget(s)}positionIsBlockBreak(o){var s;return null===(s=this.document.getPieceAtPosition(o))||void 0===s?void 0:s.isBlockBreak()}getSelectedDocument(){const o=this.getSelectedRange();if(o)return this.document.getDocumentAtRange(o)}getSelectedAttachments(){var o;return null===(o=this.getSelectedDocument())||void 0===o?void 0:o.getAttachments()}getAttachments(){return this.attachments.slice(0)}refreshAttachments(){const o=this.document.getAttachments(),{added:s,removed:a}=function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const a=[],l=[],c=new Set;o.forEach((o=>{c.add(o)}));const h=new Set;return s.forEach((o=>{h.add(o),c.has(o)||a.push(o)})),o.forEach((o=>{h.has(o)||l.push(o)})),{added:a,removed:l}}(this.attachments,o);return this.attachments=o,Array.from(a).forEach((o=>{var s,a;o.delegate=null,null===(s=this.delegate)||void 0===s||null===(a=s.compositionDidRemoveAttachment)||void 0===a||a.call(s,o)})),(()=>{const o=[];return Array.from(s).forEach((s=>{var a,l;s.delegate=this,o.push(null===(a=this.delegate)||void 0===a||null===(l=a.compositionDidAddAttachment)||void 0===l?void 0:l.call(a,s))})),o})()}attachmentDidChangeAttributes(o){var s,a;return this.revision++,null===(s=this.delegate)||void 0===s||null===(a=s.compositionDidEditAttachment)||void 0===a?void 0:a.call(s,o)}attachmentDidChangePreviewURL(o){var s,a;return this.revision++,null===(s=this.delegate)||void 0===s||null===(a=s.compositionDidChangeAttachmentPreviewURL)||void 0===a?void 0:a.call(s,o)}editAttachment(o,s){var a,l;if(o!==this.editingAttachment)return this.stopEditingAttachment(),this.editingAttachment=o,null===(a=this.delegate)||void 0===a||null===(l=a.compositionDidStartEditingAttachment)||void 0===l?void 0:l.call(a,this.editingAttachment,s)}stopEditingAttachment(){var o,s;this.editingAttachment&&(null===(o=this.delegate)||void 0===o||null===(s=o.compositionDidStopEditingAttachment)||void 0===s||s.call(o,this.editingAttachment),this.editingAttachment=null)}updateAttributesForAttachment(o,s){return this.setDocument(this.document.updateAttributesForAttachment(o,s))}removeAttributeForAttachment(o,s){return this.setDocument(this.document.removeAttributeForAttachment(o,s))}breakFormattedBlock(o){let{document:s}=o;const{block:a}=o;let l=o.startPosition,c=[l-1,l];a.getBlockBreakPosition()===o.startLocation.offset?(a.breaksOnReturn()&&"\n"===o.nextCharacter?l+=1:s=s.removeTextAtRange(c),c=[l,l]):"\n"===o.nextCharacter?"\n"===o.previousCharacter?c=[l-1,l+1]:(c=[l,l+1],l+=1):o.startLocation.offset-1!=0&&(l+=1);const h=new an([a.removeLastAttribute().copyWithoutText()]);return this.setDocument(s.insertDocumentAtRange(h,c)),this.setSelection(l)}getPreviousBlock(){const o=this.getLocationRange();if(o){const{index:s}=o[0];if(s>0)return this.document.getBlockAtIndex(s-1)}}getBlock(){const o=this.getLocationRange();if(o)return this.document.getBlockAtIndex(o[0].index)}getAttachmentAtRange(o){const s=this.document.getDocumentAtRange(o);if(s.toString()==="".concat("","\n"))return s.getAttachments()[0]}notifyDelegateOfCurrentAttributesChange(){var o,s;return null===(o=this.delegate)||void 0===o||null===(s=o.compositionDidChangeCurrentAttributes)||void 0===s?void 0:s.call(o,this.currentAttributes)}notifyDelegateOfInsertionAtRange(o){var s,a;return null===(s=this.delegate)||void 0===s||null===(a=s.compositionDidPerformInsertionAtRange)||void 0===a?void 0:a.call(s,o)}translateUTF16PositionFromOffset(o,s){const a=this.document.toUTF16String(),l=a.offsetFromUCS2Offset(o);return a.offsetToUCS2Offset(l+s)}}wn.proxyMethod("getSelectionManager().getPointRange"),wn.proxyMethod("getSelectionManager().setLocationRangeFromPointRange"),wn.proxyMethod("getSelectionManager().createLocationRangeFromDOMRange"),wn.proxyMethod("getSelectionManager().locationIsCursorTarget"),wn.proxyMethod("getSelectionManager().selectionIsExpanded"),wn.proxyMethod("delegate?.getSelectionManager");class Ln extends q{constructor(o){super(...arguments),this.composition=o,this.undoEntries=[],this.redoEntries=[]}recordUndoEntry(o){let{context:s,consolidatable:a}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const l=this.undoEntries.slice(-1)[0];if(!a||!Dn(l,o,s)){const a=this.createEntry({description:o,context:s});this.undoEntries.push(a),this.redoEntries=[]}}undo(){const o=this.undoEntries.pop();if(o){const s=this.createEntry(o);return this.redoEntries.push(s),this.composition.loadSnapshot(o.snapshot)}}redo(){const o=this.redoEntries.pop();if(o){const s=this.createEntry(o);return this.undoEntries.push(s),this.composition.loadSnapshot(o.snapshot)}}canUndo(){return this.undoEntries.length>0}canRedo(){return this.redoEntries.length>0}createEntry(){let{description:o,context:s}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{description:null==o?void 0:o.toString(),context:JSON.stringify(s),snapshot:this.composition.getSnapshot()}}}const Dn=(o,s,a)=>(null==o?void 0:o.description)===(null==s?void 0:s.toString())&&(null==o?void 0:o.context)===JSON.stringify(a),Zn="attachmentGallery";class In{constructor(o){this.document=o.document,this.selectedRange=o.selectedRange}perform(){return this.removeBlockAttribute(),this.applyBlockAttribute()}getSnapshot(){return{document:this.document,selectedRange:this.selectedRange}}removeBlockAttribute(){return this.findRangesOfBlocks().map((o=>this.document=this.document.removeAttributeAtRange(Zn,o)))}applyBlockAttribute(){let o=0;this.findRangesOfPieces().forEach((s=>{s[1]-s[0]>1&&(s[0]+=o,s[1]+=o,"\n"!==this.document.getCharacterAtPosition(s[1])&&(this.document=this.document.insertBlockBreakAtRange(s[1]),s[1]0&&void 0!==arguments[0]?arguments[0]:"";const s=hn.parse(o,{referenceElement:this.element}).getDocument();return this.loadDocument(s)}loadJSON(o){let{document:s,selectedRange:a}=o;return s=an.fromJSON(s),this.loadSnapshot({document:s,selectedRange:a})}loadSnapshot(o){return this.undoManager=new Ln(this.composition),this.composition.loadSnapshot(o)}getDocument(){return this.composition.document}getSelectedDocument(){return this.composition.getSelectedDocument()}getSnapshot(){return this.composition.getSnapshot()}toJSON(){return this.getSnapshot()}deleteInDirection(o){return this.composition.deleteInDirection(o)}insertAttachment(o){return this.composition.insertAttachment(o)}insertAttachments(o){return this.composition.insertAttachments(o)}insertDocument(o){return this.composition.insertDocument(o)}insertFile(o){return this.composition.insertFile(o)}insertFiles(o){return this.composition.insertFiles(o)}insertHTML(o){return this.composition.insertHTML(o)}insertString(o){return this.composition.insertString(o)}insertText(o){return this.composition.insertText(o)}insertLineBreak(){return this.composition.insertLineBreak()}getSelectedRange(){return this.composition.getSelectedRange()}getPosition(){return this.composition.getPosition()}getClientRectAtPosition(o){const s=this.getDocument().locationRangeFromRange([o,o+1]);return this.selectionManager.getClientRectAtLocationRange(s)}expandSelectionInDirection(o){return this.composition.expandSelectionInDirection(o)}moveCursorInDirection(o){return this.composition.moveCursorInDirection(o)}setSelectedRange(o){return this.composition.setSelectedRange(o)}activateAttribute(o){let s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.composition.setCurrentAttribute(o,s)}attributeIsActive(o){return this.composition.hasCurrentAttribute(o)}canActivateAttribute(o){return this.composition.canSetCurrentAttribute(o)}deactivateAttribute(o){return this.composition.removeCurrentAttribute(o)}setHTMLAtributeAtPosition(o,s,a){this.composition.setHTMLAtributeAtPosition(o,s,a)}canDecreaseNestingLevel(){return this.composition.canDecreaseNestingLevel()}canIncreaseNestingLevel(){return this.composition.canIncreaseNestingLevel()}decreaseNestingLevel(){if(this.canDecreaseNestingLevel())return this.composition.decreaseNestingLevel()}increaseNestingLevel(){if(this.canIncreaseNestingLevel())return this.composition.increaseNestingLevel()}canRedo(){return this.undoManager.canRedo()}canUndo(){return this.undoManager.canUndo()}recordUndoEntry(o){let{context:s,consolidatable:a}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.undoManager.recordUndoEntry(o,{context:s,consolidatable:a})}redo(){if(this.canRedo())return this.undoManager.redo()}undo(){if(this.canUndo())return this.undoManager.undo()}}class Mn{constructor(o){this.element=o}findLocationFromContainerAndOffset(o,s){let{strict:a}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{strict:!0},l=0,c=!1;const h={index:0,offset:0},d=this.findAttachmentElementParentForNode(o);d&&(o=d.parentNode,s=E(d));const g=R(this.element,{usingFilter:Wn});for(;g.nextNode();){const d=g.currentNode;if(d===o&&B(o)){F(d)||(h.offset+=s);break}if(d.parentNode===o){if(l++===s)break}else if(!C(o,d)&&l>0)break;N(d,{strict:a})?(c&&h.index++,h.offset=0,c=!0):h.offset+=Bn(d)}return h}findContainerAndOffsetFromLocation(o){let s,a;if(0===o.index&&0===o.offset){for(s=this.element,a=0;s.firstChild;)if(s=s.firstChild,D(s)){a=1;break}return[s,a]}let[l,c]=this.findNodeAndOffsetFromLocation(o);if(l){if(B(l))0===Bn(l)?(s=l.parentNode.parentNode,a=E(l.parentNode),F(l,{name:"right"})&&a++):(s=l,a=o.offset-c);else{if(s=l.parentNode,!N(l.previousSibling)&&!D(s))for(;l===s.lastChild&&(l=s,s=s.parentNode,!D(s)););a=E(l),0!==o.offset&&a++}return[s,a]}}findNodeAndOffsetFromLocation(o){let s,a,l=0;for(const c of this.getSignificantNodesForIndex(o.index)){const h=Bn(c);if(o.offset<=l+h)if(B(c)){if(s=c,a=l,o.offset===a&&F(s))break}else s||(s=c,a=l);if(l+=h,l>o.offset)break}return[s,a]}findAttachmentElementParentForNode(o){for(;o&&o!==this.element;){if(P(o))return o;o=o.parentNode}}getSignificantNodesForIndex(o){const s=[],a=R(this.element,{usingFilter:_n});let l=!1;for(;a.nextNode();){const h=a.currentNode;var c;if(I(h)){if(null!=c?c++:c=0,c===o)l=!0;else if(l)break}else l&&s.push(h)}return s}}const Bn=function(o){return o.nodeType===Node.TEXT_NODE?F(o)?0:o.textContent.length:"br"===k(o)||P(o)?1:0},_n=function(o){return jn(o)===NodeFilter.FILTER_ACCEPT?Wn(o):NodeFilter.FILTER_REJECT},jn=function(o){return M(o)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},Wn=function(o){return P(o.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT};class Un{createDOMRangeFromPoint(o){let s,{x:a,y:l}=o;if(document.caretPositionFromPoint){const{offsetNode:o,offset:c}=document.caretPositionFromPoint(a,l);return s=document.createRange(),s.setStart(o,c),s}if(document.caretRangeFromPoint)return document.caretRangeFromPoint(a,l);if(document.body.createTextRange){const c=Mt();try{const o=document.body.createTextRange();o.moveToPoint(a,l),o.select()}catch(o){}return s=Mt(),Bt(c),s}}getClientRectsForDOMRange(o){const s=Array.from(o.getClientRects());return[s[0],s[s.length-1]]}}class Vn extends q{constructor(o){super(...arguments),this.didMouseDown=this.didMouseDown.bind(this),this.selectionDidChange=this.selectionDidChange.bind(this),this.element=o,this.locationMapper=new Mn(this.element),this.pointMapper=new Un,this.lockCount=0,b("mousedown",{onElement:this.element,withCallback:this.didMouseDown})}getLocationRange(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return!1===o.strict?this.createLocationRangeFromDOMRange(Mt()):o.ignoreLock?this.currentLocationRange:this.lockedLocationRange?this.lockedLocationRange:this.currentLocationRange}setLocationRange(o){if(this.lockedLocationRange)return;o=wt(o);const s=this.createDOMRangeFromLocationRange(o);s&&(Bt(s),this.updateCurrentLocationRange(o))}setLocationRangeFromPointRange(o){o=wt(o);const s=this.getLocationAtPoint(o[0]),a=this.getLocationAtPoint(o[1]);this.setLocationRange([s,a])}getClientRectAtLocationRange(o){const s=this.createDOMRangeFromLocationRange(o);if(s)return this.getClientRectsForDOMRange(s)[1]}locationIsCursorTarget(o){const s=Array.from(this.findNodeAndOffsetFromLocation(o))[0];return F(s)}lock(){0==this.lockCount++&&(this.updateCurrentLocationRange(),this.lockedLocationRange=this.getLocationRange())}unlock(){if(0==--this.lockCount){const{lockedLocationRange:o}=this;if(this.lockedLocationRange=null,null!=o)return this.setLocationRange(o)}}clearSelection(){var o;return null===(o=Pt())||void 0===o?void 0:o.removeAllRanges()}selectionIsCollapsed(){var o;return!0===(null===(o=Mt())||void 0===o?void 0:o.collapsed)}selectionIsExpanded(){return!this.selectionIsCollapsed()}createLocationRangeFromDOMRange(o,s){if(null==o||!this.domRangeWithinElement(o))return;const a=this.findLocationFromContainerAndOffset(o.startContainer,o.startOffset,s);if(!a)return;const l=o.collapsed?void 0:this.findLocationFromContainerAndOffset(o.endContainer,o.endOffset,s);return wt([a,l])}didMouseDown(){return this.pauseTemporarily()}pauseTemporarily(){let o;this.paused=!0;const e=()=>{if(this.paused=!1,clearTimeout(s),Array.from(o).forEach((o=>{o.destroy()})),C(document,this.element))return this.selectionDidChange()},s=setTimeout(e,200);o=["mousemove","keydown"].map((o=>b(o,{onElement:document,withCallback:e})))}selectionDidChange(){if(!this.paused&&!x(this.element))return this.updateCurrentLocationRange()}updateCurrentLocationRange(o){var s,a;if((null!=o?o:o=this.createLocationRangeFromDOMRange(Mt()))&&!Dt(o,this.currentLocationRange))return this.currentLocationRange=o,null===(s=this.delegate)||void 0===s||null===(a=s.locationRangeDidChange)||void 0===a?void 0:a.call(s,this.currentLocationRange.slice(0))}createDOMRangeFromLocationRange(o){const s=this.findContainerAndOffsetFromLocation(o[0]),a=Lt(o)?s:this.findContainerAndOffsetFromLocation(o[1])||s;if(null!=s&&null!=a){const o=document.createRange();return o.setStart(...Array.from(s||[])),o.setEnd(...Array.from(a||[])),o}}getLocationAtPoint(o){const s=this.createDOMRangeFromPoint(o);var a;if(s)return null===(a=this.createLocationRangeFromDOMRange(s))||void 0===a?void 0:a[0]}domRangeWithinElement(o){return o.collapsed?C(this.element,o.startContainer):C(this.element,o.startContainer)&&C(this.element,o.endContainer)}}Vn.proxyMethod("locationMapper.findLocationFromContainerAndOffset"),Vn.proxyMethod("locationMapper.findContainerAndOffsetFromLocation"),Vn.proxyMethod("locationMapper.findNodeAndOffsetFromLocation"),Vn.proxyMethod("pointMapper.createDOMRangeFromPoint"),Vn.proxyMethod("pointMapper.getClientRectsForDOMRange");var tr=Object.freeze({__proto__:null,Attachment:Vi,AttachmentManager:kn,AttachmentPiece:zi,Block:$i,Composition:wn,Document:an,Editor:Pn,HTMLParser:hn,HTMLSanitizer:di,LineBreakInsertion:Tn,LocationMapper:Mn,ManagedAttachment:Rn,Piece:Wi,PointMapper:Un,SelectionManager:Vn,SplittableList:Hi,StringPiece:qi,Text:Yi,UndoManager:Ln}),sr=Object.freeze({__proto__:null,ObjectView:ie,AttachmentView:pi,BlockView:Ei,DocumentView:Si,PieceView:Ai,PreviewableAttachmentView:vi,TextView:yi});const{lang:cr,css:ur,keyNames:hr}=$,Gn=function(o){return function(){const s=o.apply(this,arguments);s.do(),this.undos||(this.undos=[]),this.undos.push(s.undo)}};class Yn extends q{constructor(o,s,a){let l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};super(...arguments),Di(this,"makeElementMutable",Gn((()=>({do:()=>{this.element.dataset.trixMutable=!0},undo:()=>delete this.element.dataset.trixMutable})))),Di(this,"addToolbar",Gn((()=>{const o=T({tagName:"div",className:ur.attachmentToolbar,data:{trixMutable:!0},childNodes:T({tagName:"div",className:"trix-button-row",childNodes:T({tagName:"span",className:"trix-button-group trix-button-group--actions",childNodes:T({tagName:"button",className:"trix-button trix-button--remove",textContent:cr.remove,attributes:{title:cr.remove},data:{trixAction:"remove"}})})})});return this.attachment.isPreviewable()&&o.appendChild(T({tagName:"div",className:ur.attachmentMetadataContainer,childNodes:T({tagName:"span",className:ur.attachmentMetadata,childNodes:[T({tagName:"span",className:ur.attachmentName,textContent:this.attachment.getFilename(),attributes:{title:this.attachment.getFilename()}}),T({tagName:"span",className:ur.attachmentSize,textContent:this.attachment.getFormattedFilesize()})]})})),b("click",{onElement:o,withCallback:this.didClickToolbar}),b("click",{onElement:o,matchingSelector:"[data-trix-action]",withCallback:this.didClickActionButton}),v("trix-attachment-before-toolbar",{onElement:this.element,attributes:{toolbar:o,attachment:this.attachment}}),{do:()=>this.element.appendChild(o),undo:()=>S(o)}}))),Di(this,"installCaptionEditor",Gn((()=>{const o=T({tagName:"textarea",className:ur.attachmentCaptionEditor,attributes:{placeholder:cr.captionPlaceholder},data:{trixMutable:!0}});o.value=this.attachmentPiece.getCaption();const s=o.cloneNode();s.classList.add("trix-autoresize-clone"),s.tabIndex=-1;const i=function(){s.value=o.value,o.style.height=s.scrollHeight+"px"};b("input",{onElement:o,withCallback:i}),b("input",{onElement:o,withCallback:this.didInputCaption}),b("keydown",{onElement:o,withCallback:this.didKeyDownCaption}),b("change",{onElement:o,withCallback:this.didChangeCaption}),b("blur",{onElement:o,withCallback:this.didBlurCaption});const a=this.element.querySelector("figcaption"),l=a.cloneNode();return{do:()=>{if(a.style.display="none",l.appendChild(o),l.appendChild(s),l.classList.add("".concat(ur.attachmentCaption,"--editing")),a.parentElement.insertBefore(l,a),i(),this.options.editCaption)return Rt((()=>o.focus()))},undo(){S(l),a.style.display=null}}}))),this.didClickToolbar=this.didClickToolbar.bind(this),this.didClickActionButton=this.didClickActionButton.bind(this),this.didKeyDownCaption=this.didKeyDownCaption.bind(this),this.didInputCaption=this.didInputCaption.bind(this),this.didChangeCaption=this.didChangeCaption.bind(this),this.didBlurCaption=this.didBlurCaption.bind(this),this.attachmentPiece=o,this.element=s,this.container=a,this.options=l,this.attachment=this.attachmentPiece.attachment,"a"===k(this.element)&&(this.element=this.element.firstChild),this.install()}install(){this.makeElementMutable(),this.addToolbar(),this.attachment.isPreviewable()&&this.installCaptionEditor()}uninstall(){var o;let s=this.undos.pop();for(this.savePendingCaption();s;)s(),s=this.undos.pop();null===(o=this.delegate)||void 0===o||o.didUninstallAttachmentEditor(this)}savePendingCaption(){if(null!=this.pendingCaption){const c=this.pendingCaption;var o,s,a,l;this.pendingCaption=null,c?null===(o=this.delegate)||void 0===o||null===(s=o.attachmentEditorDidRequestUpdatingAttributesForAttachment)||void 0===s||s.call(o,{caption:c},this.attachment):null===(a=this.delegate)||void 0===a||null===(l=a.attachmentEditorDidRequestRemovingAttributeForAttachment)||void 0===l||l.call(a,"caption",this.attachment)}}didClickToolbar(o){return o.preventDefault(),o.stopPropagation()}didClickActionButton(o){var s;if("remove"===o.target.getAttribute("data-trix-action"))return null===(s=this.delegate)||void 0===s?void 0:s.attachmentEditorDidRequestRemovalOfAttachment(this.attachment)}didKeyDownCaption(o){var s,a;if("return"===hr[o.keyCode])return o.preventDefault(),this.savePendingCaption(),null===(s=this.delegate)||void 0===s||null===(a=s.attachmentEditorDidRequestDeselectingAttachment)||void 0===a?void 0:a.call(s,this.attachment)}didInputCaption(o){this.pendingCaption=o.target.value.replace(/\s/g," ").trim()}didChangeCaption(o){return this.savePendingCaption()}didBlurCaption(o){return this.savePendingCaption()}}class $n extends q{constructor(o,a){super(...arguments),this.didFocus=this.didFocus.bind(this),this.didBlur=this.didBlur.bind(this),this.didClickAttachment=this.didClickAttachment.bind(this),this.element=o,this.composition=a,this.documentView=new Si(this.composition.document,{element:this.element}),b("focus",{onElement:this.element,withCallback:this.didFocus}),b("blur",{onElement:this.element,withCallback:this.didBlur}),b("click",{onElement:this.element,matchingSelector:"a[contenteditable=false]",preventDefault:!0}),b("mousedown",{onElement:this.element,matchingSelector:s,withCallback:this.didClickAttachment}),b("click",{onElement:this.element,matchingSelector:"a".concat(s),preventDefault:!0})}didFocus(o){var s;const i=()=>{var o,s;if(!this.focused)return this.focused=!0,null===(o=this.delegate)||void 0===o||null===(s=o.compositionControllerDidFocus)||void 0===s?void 0:s.call(o)};return(null===(s=this.blurPromise)||void 0===s?void 0:s.then(i))||i()}didBlur(o){this.blurPromise=new Promise((o=>Rt((()=>{var s,a;x(this.element)||(this.focused=null,null===(s=this.delegate)||void 0===s||null===(a=s.compositionControllerDidBlur)||void 0===a||a.call(s));return this.blurPromise=null,o()}))))}didClickAttachment(o,s){var a,l;const c=this.findAttachmentForElement(s),h=!!y(o.target,{matchingSelector:"figcaption"});return null===(a=this.delegate)||void 0===a||null===(l=a.compositionControllerDidSelectAttachment)||void 0===l?void 0:l.call(a,c,{editCaption:h})}getSerializableElement(){return this.isEditingAttachment()?this.documentView.shadowElement:this.element}render(){var o,s,a,l,c,h;(this.revision!==this.composition.revision&&(this.documentView.setDocument(this.composition.document),this.documentView.render(),this.revision=this.composition.revision),this.canSyncDocumentView()&&!this.documentView.isSynced())&&(null===(a=this.delegate)||void 0===a||null===(l=a.compositionControllerWillSyncDocumentView)||void 0===l||l.call(a),this.documentView.sync(),null===(c=this.delegate)||void 0===c||null===(h=c.compositionControllerDidSyncDocumentView)||void 0===h||h.call(c));return null===(o=this.delegate)||void 0===o||null===(s=o.compositionControllerDidRender)||void 0===s?void 0:s.call(o)}rerenderViewForObject(o){return this.invalidateViewForObject(o),this.render()}invalidateViewForObject(o){return this.documentView.invalidateViewForObject(o)}isViewCachingEnabled(){return this.documentView.isViewCachingEnabled()}enableViewCaching(){return this.documentView.enableViewCaching()}disableViewCaching(){return this.documentView.disableViewCaching()}refreshViewCache(){return this.documentView.garbageCollectCachedViews()}isEditingAttachment(){return!!this.attachmentEditor}installAttachmentEditorForAttachment(o,s){var a;if((null===(a=this.attachmentEditor)||void 0===a?void 0:a.attachment)===o)return;const l=this.documentView.findElementForObject(o);if(!l)return;this.uninstallAttachmentEditor();const c=this.composition.document.getAttachmentPieceForAttachment(o);this.attachmentEditor=new Yn(c,l,this.element,s),this.attachmentEditor.delegate=this}uninstallAttachmentEditor(){var o;return null===(o=this.attachmentEditor)||void 0===o?void 0:o.uninstall()}didUninstallAttachmentEditor(){return this.attachmentEditor=null,this.render()}attachmentEditorDidRequestUpdatingAttributesForAttachment(o,s){var a,l;return null===(a=this.delegate)||void 0===a||null===(l=a.compositionControllerWillUpdateAttachment)||void 0===l||l.call(a,s),this.composition.updateAttributesForAttachment(o,s)}attachmentEditorDidRequestRemovingAttributeForAttachment(o,s){var a,l;return null===(a=this.delegate)||void 0===a||null===(l=a.compositionControllerWillUpdateAttachment)||void 0===l||l.call(a,s),this.composition.removeAttributeForAttachment(o,s)}attachmentEditorDidRequestRemovalOfAttachment(o){var s,a;return null===(s=this.delegate)||void 0===s||null===(a=s.compositionControllerDidRequestRemovalOfAttachment)||void 0===a?void 0:a.call(s,o)}attachmentEditorDidRequestDeselectingAttachment(o){var s,a;return null===(s=this.delegate)||void 0===s||null===(a=s.compositionControllerDidRequestDeselectingAttachment)||void 0===a?void 0:a.call(s,o)}canSyncDocumentView(){return!this.isEditingAttachment()}findAttachmentForElement(o){return this.composition.document.getAttachmentById(parseInt(o.dataset.trixId,10))}}class Xn extends q{}const dr="data-trix-mutable",pr="[".concat(dr,"]"),Dr={attributes:!0,childList:!0,characterData:!0,characterDataOldValue:!0,subtree:!0};class er extends q{constructor(o){super(o),this.didMutate=this.didMutate.bind(this),this.element=o,this.observer=new window.MutationObserver(this.didMutate),this.start()}start(){return this.reset(),this.observer.observe(this.element,Dr)}stop(){return this.observer.disconnect()}didMutate(o){var s,a;if(this.mutations.push(...Array.from(this.findSignificantMutations(o)||[])),this.mutations.length)return null===(s=this.delegate)||void 0===s||null===(a=s.elementDidMutate)||void 0===a||a.call(s,this.getMutationSummary()),this.reset()}reset(){this.mutations=[]}findSignificantMutations(o){return o.filter((o=>this.mutationIsSignificant(o)))}mutationIsSignificant(o){if(this.nodeIsMutable(o.target))return!1;for(const s of Array.from(this.nodesModifiedByMutation(o)))if(this.nodeIsSignificant(s))return!0;return!1}nodeIsSignificant(o){return o!==this.element&&!this.nodeIsMutable(o)&&!M(o)}nodeIsMutable(o){return y(o,{matchingSelector:pr})}nodesModifiedByMutation(o){const s=[];switch(o.type){case"attributes":o.attributeName!==dr&&s.push(o.target);break;case"characterData":s.push(o.target.parentNode),s.push(o.target);break;case"childList":s.push(...Array.from(o.addedNodes||[])),s.push(...Array.from(o.removedNodes||[]))}return s}getMutationSummary(){return this.getTextMutationSummary()}getTextMutationSummary(){const{additions:o,deletions:s}=this.getTextChangesFromCharacterData(),a=this.getTextChangesFromChildList();Array.from(a.additions).forEach((s=>{Array.from(o).includes(s)||o.push(s)})),s.push(...Array.from(a.deletions||[]));const l={},c=o.join("");c&&(l.textAdded=c);const h=s.join("");return h&&(l.textDeleted=h),l}getMutationsByType(o){return Array.from(this.mutations).filter((s=>s.type===o))}getTextChangesFromChildList(){let o,s;const a=[],l=[];Array.from(this.getMutationsByType("childList")).forEach((o=>{a.push(...Array.from(o.addedNodes||[])),l.push(...Array.from(o.removedNodes||[]))}));0===a.length&&1===l.length&&I(l[0])?(o=[],s=["\n"]):(o=ir(a),s=ir(l));const c=o.filter(((o,a)=>o!==s[a])).map(Wt),h=s.filter(((s,a)=>s!==o[a])).map(Wt);return{additions:c,deletions:h}}getTextChangesFromCharacterData(){let o,s;const a=this.getMutationsByType("characterData");if(a.length){const l=a[0],c=a[a.length-1],h=function(o,s){let a,l;return o=X.box(o),(s=X.box(s)).length0&&void 0!==arguments[0]?arguments[0]:[];const s=[];for(const a of Array.from(o))switch(a.nodeType){case Node.TEXT_NODE:s.push(a.data);break;case Node.ELEMENT_NODE:"br"===k(a)?s.push("\n"):s.push(...Array.from(ir(a.childNodes)||[]))}return s};class nr extends ee{constructor(o){super(...arguments),this.file=o}perform(o){const s=new FileReader;return s.onerror=()=>o(!1),s.onload=()=>{s.onerror=null;try{s.abort()}catch(o){}return o(!0,this.file)},s.readAsArrayBuffer(this.file)}}class rr{constructor(o){this.element=o}shouldIgnore(o){return!!d.samsungAndroid&&(this.previousEvent=this.event,this.event=o,this.checkSamsungKeyboardBuggyModeStart(),this.checkSamsungKeyboardBuggyModeEnd(),this.buggyMode)}checkSamsungKeyboardBuggyModeStart(){this.insertingLongTextAfterUnidentifiedChar()&&or(this.element.innerText,this.event.data)&&(this.buggyMode=!0,this.event.preventDefault())}checkSamsungKeyboardBuggyModeEnd(){this.buggyMode&&"insertText"!==this.event.inputType&&(this.buggyMode=!1)}insertingLongTextAfterUnidentifiedChar(){var o;return this.isBeforeInputInsertText()&&this.previousEventWasUnidentifiedKeydown()&&(null===(o=this.event.data)||void 0===o?void 0:o.length)>50}isBeforeInputInsertText(){return"beforeinput"===this.event.type&&"insertText"===this.event.inputType}previousEventWasUnidentifiedKeydown(){var o,s;return"keydown"===(null===(o=this.previousEvent)||void 0===o?void 0:o.type)&&"Unidentified"===(null===(s=this.previousEvent)||void 0===s?void 0:s.key)}}const or=(o,s)=>ar(o)===ar(s),Tr=new RegExp("(".concat("","|").concat(_,"|").concat(j,"|\\s)+"),"g"),ar=o=>o.replace(Tr," ").trim();class lr extends q{constructor(o){super(...arguments),this.element=o,this.mutationObserver=new er(this.element),this.mutationObserver.delegate=this,this.flakyKeyboardDetector=new rr(this.element);for(const o in this.constructor.events)b(o,{onElement:this.element,withCallback:this.handlerFor(o)})}elementDidMutate(o){}editorWillSyncDocumentView(){return this.mutationObserver.stop()}editorDidSyncDocumentView(){return this.mutationObserver.start()}requestRender(){var o,s;return null===(o=this.delegate)||void 0===o||null===(s=o.inputControllerDidRequestRender)||void 0===s?void 0:s.call(o)}requestReparse(){var o,s;return null===(o=this.delegate)||void 0===o||null===(s=o.inputControllerDidRequestReparse)||void 0===s||s.call(o),this.requestRender()}attachFiles(o){const s=Array.from(o).map((o=>new nr(o)));return Promise.all(s).then((o=>{this.handleInput((function(){var s,a;return null===(s=this.delegate)||void 0===s||s.inputControllerWillAttachFiles(),null===(a=this.responder)||void 0===a||a.insertFiles(o),this.requestRender()}))}))}handlerFor(o){return s=>{s.defaultPrevented||this.handleInput((()=>{if(!x(this.element)){if(this.flakyKeyboardDetector.shouldIgnore(s))return;this.eventName=o,this.constructor.events[o].call(this,s)}}))}}handleInput(o){try{var s;null===(s=this.delegate)||void 0===s||s.inputControllerWillHandleInput(),o.call(this)}finally{var a;null===(a=this.delegate)||void 0===a||a.inputControllerDidHandleInput()}}createLinkHTML(o,s){const a=document.createElement("a");return a.href=o,a.textContent=s||o,a.outerHTML}}var wr;Di(lr,"events",{});const{browser:Lr,keyNames:Ir}=$;let Nr=0;class gr extends lr{constructor(){super(...arguments),this.resetInputSummary()}setInputSummary(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.inputSummary.eventName=this.eventName;for(const s in o){const a=o[s];this.inputSummary[s]=a}return this.inputSummary}resetInputSummary(){this.inputSummary={}}reset(){return this.resetInputSummary(),ce.reset()}elementDidMutate(o){var s,a;return this.isComposing()?null===(s=this.delegate)||void 0===s||null===(a=s.inputControllerDidAllowUnhandledInput)||void 0===a?void 0:a.call(s):this.handleInput((function(){return this.mutationIsSignificant(o)&&(this.mutationIsExpected(o)?this.requestRender():this.requestReparse()),this.reset()}))}mutationIsExpected(o){let{textAdded:s,textDeleted:a}=o;if(this.inputSummary.preferDocument)return!0;const l=null!=s?s===this.inputSummary.textAdded:!this.inputSummary.textAdded,c=null!=a?this.inputSummary.didDelete:!this.inputSummary.didDelete,h=["\n"," \n"].includes(s)&&!l,d="\n"===a&&!c;if(h&&!d||d&&!h){const o=this.getSelectedRange();if(o){var g;const a=h?s.replace(/\n$/,"").length||-1:(null==s?void 0:s.length)||1;if(null!==(g=this.responder)&&void 0!==g&&g.positionIsBlockBreak(o[1]+a))return!0}}return l&&c}mutationIsSignificant(o){var s;const a=Object.keys(o).length>0,l=""===(null===(s=this.compositionInput)||void 0===s?void 0:s.getEndData());return a||!l}getCompositionInput(){if(this.isComposing())return this.compositionInput;this.compositionInput=new vr(this)}isComposing(){return this.compositionInput&&!this.compositionInput.isEnded()}deleteInDirection(o,s){var a;return!1!==(null===(a=this.responder)||void 0===a?void 0:a.deleteInDirection(o))?this.setInputSummary({didDelete:!0}):s?(s.preventDefault(),this.requestRender()):void 0}serializeSelectionToDataTransfer(o){var s;if(!function(o){if(null==o||!o.setData)return!1;for(const s in ae){const a=ae[s];try{if(o.setData(s,a),!o.getData(s)===a)return!1}catch(o){return!1}}return!0}(o))return;const a=null===(s=this.responder)||void 0===s?void 0:s.getSelectedDocument().toSerializableDocument();return o.setData("application/x-trix-document",JSON.stringify(a)),o.setData("text/html",Si.render(a).innerHTML),o.setData("text/plain",a.toString().replace(/\n$/,"")),!0}canAcceptDataTransfer(o){const s={};return Array.from((null==o?void 0:o.types)||[]).forEach((o=>{s[o]=!0})),s.Files||s["application/x-trix-document"]||s["text/html"]||s["text/plain"]}getPastedHTMLUsingHiddenElement(o){const s=this.getSelectedRange(),a={position:"absolute",left:"".concat(window.pageXOffset,"px"),top:"".concat(window.pageYOffset,"px"),opacity:0},l=T({style:a,tagName:"div",editable:!0});return document.body.appendChild(l),l.focus(),requestAnimationFrame((()=>{const a=l.innerHTML;return S(l),this.setSelectedRange(s),o(a)}))}}Di(gr,"events",{keydown(o){this.isComposing()||this.resetInputSummary(),this.inputSummary.didInput=!0;const s=Ir[o.keyCode];if(s){var a;let l=this.keys;["ctrl","alt","shift","meta"].forEach((s=>{var a;o["".concat(s,"Key")]&&("ctrl"===s&&(s="control"),l=null===(a=l)||void 0===a?void 0:a[s])})),null!=(null===(a=l)||void 0===a?void 0:a[s])&&(this.setInputSummary({keyName:s}),ce.reset(),l[s].call(this,o))}if(le(o)){const s=String.fromCharCode(o.keyCode).toLowerCase();if(s){var l;const a=["alt","shift"].map((s=>{if(o["".concat(s,"Key")])return s})).filter((o=>o));a.push(s),null!==(l=this.delegate)&&void 0!==l&&l.inputControllerDidReceiveKeyboardCommand(a)&&o.preventDefault()}}},keypress(o){if(null!=this.inputSummary.eventName)return;if(o.metaKey)return;if(o.ctrlKey&&!o.altKey)return;const s=fr(o);var a,l;return s?(null===(a=this.delegate)||void 0===a||a.inputControllerWillPerformTyping(),null===(l=this.responder)||void 0===l||l.insertString(s),this.setInputSummary({textAdded:s,didDelete:this.selectionIsExpanded()})):void 0},textInput(o){const{data:s}=o,{textAdded:a}=this.inputSummary;if(a&&a!==s&&a.toUpperCase()===s){var l;const o=this.getSelectedRange();return this.setSelectedRange([o[0],o[1]+a.length]),null===(l=this.responder)||void 0===l||l.insertString(s),this.setInputSummary({textAdded:s}),this.setSelectedRange(o)}},dragenter(o){o.preventDefault()},dragstart(o){var s,a;return this.serializeSelectionToDataTransfer(o.dataTransfer),this.draggedRange=this.getSelectedRange(),null===(s=this.delegate)||void 0===s||null===(a=s.inputControllerDidStartDrag)||void 0===a?void 0:a.call(s)},dragover(o){if(this.draggedRange||this.canAcceptDataTransfer(o.dataTransfer)){o.preventDefault();const l={x:o.clientX,y:o.clientY};var s,a;if(!Tt(l,this.draggingPoint))return this.draggingPoint=l,null===(s=this.delegate)||void 0===s||null===(a=s.inputControllerDidReceiveDragOverPoint)||void 0===a?void 0:a.call(s,this.draggingPoint)}},dragend(o){var s,a;null===(s=this.delegate)||void 0===s||null===(a=s.inputControllerDidCancelDrag)||void 0===a||a.call(s),this.draggedRange=null,this.draggingPoint=null},drop(o){var s,a;o.preventDefault();const l=null===(s=o.dataTransfer)||void 0===s?void 0:s.files,c=o.dataTransfer.getData("application/x-trix-document"),h={x:o.clientX,y:o.clientY};if(null===(a=this.responder)||void 0===a||a.setLocationRangeFromPointRange(h),null!=l&&l.length)this.attachFiles(l);else if(this.draggedRange){var d,g;null===(d=this.delegate)||void 0===d||d.inputControllerWillMoveText(),null===(g=this.responder)||void 0===g||g.moveTextFromRange(this.draggedRange),this.draggedRange=null,this.requestRender()}else if(c){var p;const o=an.fromJSONString(c);null===(p=this.responder)||void 0===p||p.insertDocument(o),this.requestRender()}this.draggedRange=null,this.draggingPoint=null},cut(o){var s,a;if(null!==(s=this.responder)&&void 0!==s&&s.selectionIsExpanded()&&(this.serializeSelectionToDataTransfer(o.clipboardData)&&o.preventDefault(),null===(a=this.delegate)||void 0===a||a.inputControllerWillCutText(),this.deleteInDirection("backward"),o.defaultPrevented))return this.requestRender()},copy(o){var s;null!==(s=this.responder)&&void 0!==s&&s.selectionIsExpanded()&&this.serializeSelectionToDataTransfer(o.clipboardData)&&o.preventDefault()},paste(o){const s=o.clipboardData||o.testClipboardData,a={clipboard:s};if(!s||br(o))return void this.getPastedHTMLUsingHiddenElement((o=>{var s,l,c;return a.type="text/html",a.html=o,null===(s=this.delegate)||void 0===s||s.inputControllerWillPaste(a),null===(l=this.responder)||void 0===l||l.insertHTML(a.html),this.requestRender(),null===(c=this.delegate)||void 0===c?void 0:c.inputControllerDidPaste(a)}));const l=s.getData("URL"),c=s.getData("text/html"),h=s.getData("public.url-name");if(l){var d,g,p;let o;a.type="text/html",o=h?Vt(h).trim():l,a.html=this.createLinkHTML(l,o),null===(d=this.delegate)||void 0===d||d.inputControllerWillPaste(a),this.setInputSummary({textAdded:o,didDelete:this.selectionIsExpanded()}),null===(g=this.responder)||void 0===g||g.insertHTML(a.html),this.requestRender(),null===(p=this.delegate)||void 0===p||p.inputControllerDidPaste(a)}else if(Et(s)){var f,w,_;a.type="text/plain",a.string=s.getData("text/plain"),null===(f=this.delegate)||void 0===f||f.inputControllerWillPaste(a),this.setInputSummary({textAdded:a.string,didDelete:this.selectionIsExpanded()}),null===(w=this.responder)||void 0===w||w.insertString(a.string),this.requestRender(),null===(_=this.delegate)||void 0===_||_.inputControllerDidPaste(a)}else if(c){var j,W,U;a.type="text/html",a.html=c,null===(j=this.delegate)||void 0===j||j.inputControllerWillPaste(a),null===(W=this.responder)||void 0===W||W.insertHTML(a.html),this.requestRender(),null===(U=this.delegate)||void 0===U||U.inputControllerDidPaste(a)}else if(Array.from(s.types).includes("Files")){var V,z;const o=null===(V=s.items)||void 0===V||null===(V=V[0])||void 0===V||null===(z=V.getAsFile)||void 0===z?void 0:z.call(V);if(o){var J,K,G;const s=mr(o);!o.name&&s&&(o.name="pasted-file-".concat(++Nr,".").concat(s)),a.type="File",a.file=o,null===(J=this.delegate)||void 0===J||J.inputControllerWillAttachFiles(),null===(K=this.responder)||void 0===K||K.insertFile(a.file),this.requestRender(),null===(G=this.delegate)||void 0===G||G.inputControllerDidPaste(a)}}o.preventDefault()},compositionstart(o){return this.getCompositionInput().start(o.data)},compositionupdate(o){return this.getCompositionInput().update(o.data)},compositionend(o){return this.getCompositionInput().end(o.data)},beforeinput(o){this.inputSummary.didInput=!0},input(o){return this.inputSummary.didInput=!0,o.stopPropagation()}}),Di(gr,"keys",{backspace(o){var s;return null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),this.deleteInDirection("backward",o)},delete(o){var s;return null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),this.deleteInDirection("forward",o)},return(o){var s,a;return this.setInputSummary({preferDocument:!0}),null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),null===(a=this.responder)||void 0===a?void 0:a.insertLineBreak()},tab(o){var s,a;null!==(s=this.responder)&&void 0!==s&&s.canIncreaseNestingLevel()&&(null===(a=this.responder)||void 0===a||a.increaseNestingLevel(),this.requestRender(),o.preventDefault())},left(o){var s;if(this.selectionIsInCursorTarget())return o.preventDefault(),null===(s=this.responder)||void 0===s?void 0:s.moveCursorInDirection("backward")},right(o){var s;if(this.selectionIsInCursorTarget())return o.preventDefault(),null===(s=this.responder)||void 0===s?void 0:s.moveCursorInDirection("forward")},control:{d(o){var s;return null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),this.deleteInDirection("forward",o)},h(o){var s;return null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),this.deleteInDirection("backward",o)},o(o){var s,a;return o.preventDefault(),null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),null===(a=this.responder)||void 0===a||a.insertString("\n",{updatePosition:!1}),this.requestRender()}},shift:{return(o){var s,a;null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),null===(a=this.responder)||void 0===a||a.insertString("\n"),this.requestRender(),o.preventDefault()},tab(o){var s,a;null!==(s=this.responder)&&void 0!==s&&s.canDecreaseNestingLevel()&&(null===(a=this.responder)||void 0===a||a.decreaseNestingLevel(),this.requestRender(),o.preventDefault())},left(o){if(this.selectionIsInCursorTarget())return o.preventDefault(),this.expandSelectionInDirection("backward")},right(o){if(this.selectionIsInCursorTarget())return o.preventDefault(),this.expandSelectionInDirection("forward")}},alt:{backspace(o){var s;return this.setInputSummary({preferDocument:!1}),null===(s=this.delegate)||void 0===s?void 0:s.inputControllerWillPerformTyping()}},meta:{backspace(o){var s;return this.setInputSummary({preferDocument:!1}),null===(s=this.delegate)||void 0===s?void 0:s.inputControllerWillPerformTyping()}}}),gr.proxyMethod("responder?.getSelectedRange"),gr.proxyMethod("responder?.setSelectedRange"),gr.proxyMethod("responder?.expandSelectionInDirection"),gr.proxyMethod("responder?.selectionIsInCursorTarget"),gr.proxyMethod("responder?.selectionIsExpanded");const mr=o=>{var s;return null===(s=o.type)||void 0===s||null===(s=s.match(/\/(\w+)$/))||void 0===s?void 0:s[1]},Or=!(null===(wr=" ".codePointAt)||void 0===wr||!wr.call(" ",0)),fr=function(o){if(o.key&&Or&&o.key.codePointAt(0)===o.keyCode)return o.key;{let s;if(null===o.which?s=o.keyCode:0!==o.which&&0!==o.charCode&&(s=o.charCode),null!=s&&"escape"!==Ir[s])return X.fromCodepoints([s]).toString()}},br=function(o){const s=o.clipboardData;if(s){if(s.types.includes("text/html")){for(const o of s.types){const a=/^CorePasteboardFlavorType/.test(o),l=/^dyn\./.test(o)&&s.getData(o);if(a||l)return!0}return!1}{const o=s.types.includes("com.apple.webarchive"),a=s.types.includes("com.apple.flat-rtfd");return o||a}}};class vr extends q{constructor(o){super(...arguments),this.inputController=o,this.responder=this.inputController.responder,this.delegate=this.inputController.delegate,this.inputSummary=this.inputController.inputSummary,this.data={}}start(o){if(this.data.start=o,this.isSignificant()){var s,a;"keypress"===this.inputSummary.eventName&&this.inputSummary.textAdded&&(null===(a=this.responder)||void 0===a||a.deleteInDirection("left"));this.selectionIsExpanded()||(this.insertPlaceholder(),this.requestRender()),this.range=null===(s=this.responder)||void 0===s?void 0:s.getSelectedRange()}}update(o){if(this.data.update=o,this.isSignificant()){const o=this.selectPlaceholder();o&&(this.forgetPlaceholder(),this.range=o)}}end(o){return this.data.end=o,this.isSignificant()?(this.forgetPlaceholder(),this.canApplyToDocument()?(this.setInputSummary({preferDocument:!0,didInput:!1}),null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),null===(a=this.responder)||void 0===a||a.setSelectedRange(this.range),null===(l=this.responder)||void 0===l||l.insertString(this.data.end),null===(c=this.responder)||void 0===c?void 0:c.setSelectedRange(this.range[0]+this.data.end.length)):null!=this.data.start||null!=this.data.update?(this.requestReparse(),this.inputController.reset()):void 0):this.inputController.reset();var s,a,l,c}getEndData(){return this.data.end}isEnded(){return null!=this.getEndData()}isSignificant(){return!Lr.composesExistingText||this.inputSummary.didInput}canApplyToDocument(){var o,s;return 0===(null===(o=this.data.start)||void 0===o?void 0:o.length)&&(null===(s=this.data.end)||void 0===s?void 0:s.length)>0&&this.range}}vr.proxyMethod("inputController.setInputSummary"),vr.proxyMethod("inputController.requestRender"),vr.proxyMethod("inputController.requestReparse"),vr.proxyMethod("responder?.selectionIsExpanded"),vr.proxyMethod("responder?.insertPlaceholder"),vr.proxyMethod("responder?.selectPlaceholder"),vr.proxyMethod("responder?.forgetPlaceholder");class Ar extends lr{constructor(){super(...arguments),this.render=this.render.bind(this)}elementDidMutate(){return this.scheduledRender?this.composing?null===(o=this.delegate)||void 0===o||null===(s=o.inputControllerDidAllowUnhandledInput)||void 0===s?void 0:s.call(o):void 0:this.reparse();var o,s}scheduleRender(){return this.scheduledRender?this.scheduledRender:this.scheduledRender=requestAnimationFrame(this.render)}render(){var o,s;(cancelAnimationFrame(this.scheduledRender),this.scheduledRender=null,this.composing)||null===(s=this.delegate)||void 0===s||s.render();null===(o=this.afterRender)||void 0===o||o.call(this),this.afterRender=null}reparse(){var o;return null===(o=this.delegate)||void 0===o?void 0:o.reparse()}insertString(){var o;let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",a=arguments.length>1?arguments[1]:void 0;return null===(o=this.delegate)||void 0===o||o.inputControllerWillPerformTyping(),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertString(s,a)}))}toggleAttributeIfSupported(o){var s;if(gt().includes(o))return null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformFormatting(o),this.withTargetDOMRange((function(){var s;return null===(s=this.responder)||void 0===s?void 0:s.toggleCurrentAttribute(o)}))}activateAttributeIfSupported(o,s){var a;if(gt().includes(o))return null===(a=this.delegate)||void 0===a||a.inputControllerWillPerformFormatting(o),this.withTargetDOMRange((function(){var a;return null===(a=this.responder)||void 0===a?void 0:a.setCurrentAttribute(o,s)}))}deleteInDirection(o){let{recordUndoEntry:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{recordUndoEntry:!0};var a;s&&(null===(a=this.delegate)||void 0===a||a.inputControllerWillPerformTyping());const n=()=>{var s;return null===(s=this.responder)||void 0===s?void 0:s.deleteInDirection(o)},l=this.getTargetDOMRange({minLength:this.composing?1:2});return l?this.withTargetDOMRange(l,n):n()}withTargetDOMRange(o,s){var a;return"function"==typeof o&&(s=o,o=this.getTargetDOMRange()),o?null===(a=this.responder)||void 0===a?void 0:a.withTargetDOMRange(o,s.bind(this)):(ce.reset(),s.call(this))}getTargetDOMRange(){var o,s;let{minLength:a}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{minLength:0};const l=null===(o=(s=this.event).getTargetRanges)||void 0===o?void 0:o.call(s);if(l&&l.length){const o=yr(l[0]);if(0===a||o.toString().length>=a)return o}}withEvent(o,s){let a;this.event=o;try{a=s.call(this)}finally{this.event=null}return a}}Di(Ar,"events",{keydown(o){if(le(o)){var s;const a=Rr(o);null!==(s=this.delegate)&&void 0!==s&&s.inputControllerDidReceiveKeyboardCommand(a)&&o.preventDefault()}else{let s=o.key;o.altKey&&(s+="+Alt"),o.shiftKey&&(s+="+Shift");const a=this.constructor.keys[s];if(a)return this.withEvent(o,a)}},paste(o){var s;let a;const l=null===(s=o.clipboardData)||void 0===s?void 0:s.getData("URL");return Er(o)?(o.preventDefault(),this.attachFiles(o.clipboardData.files)):Sr(o)?(o.preventDefault(),a={type:"text/plain",string:o.clipboardData.getData("text/plain")},null===(c=this.delegate)||void 0===c||c.inputControllerWillPaste(a),null===(h=this.responder)||void 0===h||h.insertString(a.string),this.render(),null===(d=this.delegate)||void 0===d?void 0:d.inputControllerDidPaste(a)):l?(o.preventDefault(),a={type:"text/html",html:this.createLinkHTML(l)},null===(g=this.delegate)||void 0===g||g.inputControllerWillPaste(a),null===(p=this.responder)||void 0===p||p.insertHTML(a.html),this.render(),null===(f=this.delegate)||void 0===f?void 0:f.inputControllerDidPaste(a)):void 0;var c,h,d,g,p,f},beforeinput(o){const s=this.constructor.inputTypes[o.inputType],a=(l=o,!(!/iPhone|iPad/.test(navigator.userAgent)||l.inputType&&"insertParagraph"!==l.inputType));var l;s&&(this.withEvent(o,s),a||this.scheduleRender()),a&&this.render()},input(o){ce.reset()},dragstart(o){var s,a;null!==(s=this.responder)&&void 0!==s&&s.selectionContainsAttachments()&&(o.dataTransfer.setData("application/x-trix-dragging",!0),this.dragging={range:null===(a=this.responder)||void 0===a?void 0:a.getSelectedRange(),point:kr(o)})},dragenter(o){xr(o)&&o.preventDefault()},dragover(o){if(this.dragging){o.preventDefault();const a=kr(o);var s;if(!Tt(a,this.dragging.point))return this.dragging.point=a,null===(s=this.responder)||void 0===s?void 0:s.setLocationRangeFromPointRange(a)}else xr(o)&&o.preventDefault()},drop(o){var s,a;if(this.dragging)return o.preventDefault(),null===(s=this.delegate)||void 0===s||s.inputControllerWillMoveText(),null===(a=this.responder)||void 0===a||a.moveTextFromRange(this.dragging.range),this.dragging=null,this.scheduleRender();if(xr(o)){var l;o.preventDefault();const s=kr(o);return null===(l=this.responder)||void 0===l||l.setLocationRangeFromPointRange(s),this.attachFiles(o.dataTransfer.files)}},dragend(){var o;this.dragging&&(null===(o=this.responder)||void 0===o||o.setSelectedRange(this.dragging.range),this.dragging=null)},compositionend(o){this.composing&&(this.composing=!1,d.recentAndroid||this.scheduleRender())}}),Di(Ar,"keys",{ArrowLeft(){var o,s;if(null!==(o=this.responder)&&void 0!==o&&o.shouldManageMovingCursorInDirection("backward"))return this.event.preventDefault(),null===(s=this.responder)||void 0===s?void 0:s.moveCursorInDirection("backward")},ArrowRight(){var o,s;if(null!==(o=this.responder)&&void 0!==o&&o.shouldManageMovingCursorInDirection("forward"))return this.event.preventDefault(),null===(s=this.responder)||void 0===s?void 0:s.moveCursorInDirection("forward")},Backspace(){var o,s,a;if(null!==(o=this.responder)&&void 0!==o&&o.shouldManageDeletingInDirection("backward"))return this.event.preventDefault(),null===(s=this.delegate)||void 0===s||s.inputControllerWillPerformTyping(),null===(a=this.responder)||void 0===a||a.deleteInDirection("backward"),this.render()},Tab(){var o,s;if(null!==(o=this.responder)&&void 0!==o&&o.canIncreaseNestingLevel())return this.event.preventDefault(),null===(s=this.responder)||void 0===s||s.increaseNestingLevel(),this.render()},"Tab+Shift"(){var o,s;if(null!==(o=this.responder)&&void 0!==o&&o.canDecreaseNestingLevel())return this.event.preventDefault(),null===(s=this.responder)||void 0===s||s.decreaseNestingLevel(),this.render()}}),Di(Ar,"inputTypes",{deleteByComposition(){return this.deleteInDirection("backward",{recordUndoEntry:!1})},deleteByCut(){return this.deleteInDirection("backward")},deleteByDrag(){return this.event.preventDefault(),this.withTargetDOMRange((function(){var o;this.deleteByDragRange=null===(o=this.responder)||void 0===o?void 0:o.getSelectedRange()}))},deleteCompositionText(){return this.deleteInDirection("backward",{recordUndoEntry:!1})},deleteContent(){return this.deleteInDirection("backward")},deleteContentBackward(){return this.deleteInDirection("backward")},deleteContentForward(){return this.deleteInDirection("forward")},deleteEntireSoftLine(){return this.deleteInDirection("forward")},deleteHardLineBackward(){return this.deleteInDirection("backward")},deleteHardLineForward(){return this.deleteInDirection("forward")},deleteSoftLineBackward(){return this.deleteInDirection("backward")},deleteSoftLineForward(){return this.deleteInDirection("forward")},deleteWordBackward(){return this.deleteInDirection("backward")},deleteWordForward(){return this.deleteInDirection("forward")},formatBackColor(){return this.activateAttributeIfSupported("backgroundColor",this.event.data)},formatBold(){return this.toggleAttributeIfSupported("bold")},formatFontColor(){return this.activateAttributeIfSupported("color",this.event.data)},formatFontName(){return this.activateAttributeIfSupported("font",this.event.data)},formatIndent(){var o;if(null!==(o=this.responder)&&void 0!==o&&o.canIncreaseNestingLevel())return this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.increaseNestingLevel()}))},formatItalic(){return this.toggleAttributeIfSupported("italic")},formatJustifyCenter(){return this.toggleAttributeIfSupported("justifyCenter")},formatJustifyFull(){return this.toggleAttributeIfSupported("justifyFull")},formatJustifyLeft(){return this.toggleAttributeIfSupported("justifyLeft")},formatJustifyRight(){return this.toggleAttributeIfSupported("justifyRight")},formatOutdent(){var o;if(null!==(o=this.responder)&&void 0!==o&&o.canDecreaseNestingLevel())return this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.decreaseNestingLevel()}))},formatRemove(){this.withTargetDOMRange((function(){for(const a in null===(o=this.responder)||void 0===o?void 0:o.getCurrentAttributes()){var o,s;null===(s=this.responder)||void 0===s||s.removeCurrentAttribute(a)}}))},formatSetBlockTextDirection(){return this.activateAttributeIfSupported("blockDir",this.event.data)},formatSetInlineTextDirection(){return this.activateAttributeIfSupported("textDir",this.event.data)},formatStrikeThrough(){return this.toggleAttributeIfSupported("strike")},formatSubscript(){return this.toggleAttributeIfSupported("sub")},formatSuperscript(){return this.toggleAttributeIfSupported("sup")},formatUnderline(){return this.toggleAttributeIfSupported("underline")},historyRedo(){var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerWillPerformRedo()},historyUndo(){var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerWillPerformUndo()},insertCompositionText(){return this.composing=!0,this.insertString(this.event.data)},insertFromComposition(){return this.composing=!1,this.insertString(this.event.data)},insertFromDrop(){const o=this.deleteByDragRange;var s;if(o)return this.deleteByDragRange=null,null===(s=this.delegate)||void 0===s||s.inputControllerWillMoveText(),this.withTargetDOMRange((function(){var s;return null===(s=this.responder)||void 0===s?void 0:s.moveTextFromRange(o)}))},insertFromPaste(){const{dataTransfer:o}=this.event,s={dataTransfer:o},a=o.getData("URL"),l=o.getData("text/html");if(a){var c;let l;this.event.preventDefault(),s.type="text/html";const h=o.getData("public.url-name");l=h?Vt(h).trim():a,s.html=this.createLinkHTML(a,l),null===(c=this.delegate)||void 0===c||c.inputControllerWillPaste(s),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertHTML(s.html)})),this.afterRender=()=>{var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerDidPaste(s)}}else if(Et(o)){var h;s.type="text/plain",s.string=o.getData("text/plain"),null===(h=this.delegate)||void 0===h||h.inputControllerWillPaste(s),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertString(s.string)})),this.afterRender=()=>{var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerDidPaste(s)}}else if(Cr(this.event)){var d;s.type="File",s.file=o.files[0],null===(d=this.delegate)||void 0===d||d.inputControllerWillPaste(s),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertFile(s.file)})),this.afterRender=()=>{var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerDidPaste(s)}}else if(l){var g;this.event.preventDefault(),s.type="text/html",s.html=l,null===(g=this.delegate)||void 0===g||g.inputControllerWillPaste(s),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertHTML(s.html)})),this.afterRender=()=>{var o;return null===(o=this.delegate)||void 0===o?void 0:o.inputControllerDidPaste(s)}}},insertFromYank(){return this.insertString(this.event.data)},insertLineBreak(){return this.insertString("\n")},insertLink(){return this.activateAttributeIfSupported("href",this.event.data)},insertOrderedList(){return this.toggleAttributeIfSupported("number")},insertParagraph(){var o;return null===(o=this.delegate)||void 0===o||o.inputControllerWillPerformTyping(),this.withTargetDOMRange((function(){var o;return null===(o=this.responder)||void 0===o?void 0:o.insertLineBreak()}))},insertReplacementText(){const o=this.event.dataTransfer.getData("text/plain"),s=this.event.getTargetRanges()[0];this.withTargetDOMRange(s,(()=>{this.insertString(o,{updatePosition:!1})}))},insertText(){var o;return this.insertString(this.event.data||(null===(o=this.event.dataTransfer)||void 0===o?void 0:o.getData("text/plain")))},insertTranspose(){return this.insertString(this.event.data)},insertUnorderedList(){return this.toggleAttributeIfSupported("bullet")}});const yr=function(o){const s=document.createRange();return s.setStart(o.startContainer,o.startOffset),s.setEnd(o.endContainer,o.endOffset),s},xr=o=>{var s;return Array.from((null===(s=o.dataTransfer)||void 0===s?void 0:s.types)||[]).includes("Files")},Cr=o=>{var s;return(null===(s=o.dataTransfer.files)||void 0===s?void 0:s[0])&&!Er(o)&&!(o=>{let{dataTransfer:s}=o;return s.types.includes("Files")&&s.types.includes("text/html")&&s.getData("text/html").includes("urn:schemas-microsoft-com:office:office")})(o)},Er=function(o){const s=o.clipboardData;if(s)return Array.from(s.types).filter((o=>o.match(/file/i))).length===s.types.length&&s.files.length>=1},Sr=function(o){const s=o.clipboardData;if(s)return s.types.includes("text/plain")&&1===s.types.length},Rr=function(o){const s=[];return o.altKey&&s.push("alt"),o.shiftKey&&s.push("shift"),s.push(o.key),s},kr=o=>({x:o.clientX,y:o.clientY}),jr="[data-trix-attribute]",Wr="[data-trix-action]",Ur="".concat(jr,", ").concat(Wr),zr="[data-trix-dialog]",Gr="".concat(zr,"[data-trix-active]"),Yr="".concat(zr," [data-trix-method]"),$r="".concat(zr," [data-trix-input]"),Fr=(o,s)=>(s||(s=Mr(o)),o.querySelector("[data-trix-input][name='".concat(s,"']"))),Pr=o=>o.getAttribute("data-trix-action"),Mr=o=>o.getAttribute("data-trix-attribute")||o.getAttribute("data-trix-dialog-attribute");class Br extends q{constructor(o){super(o),this.didClickActionButton=this.didClickActionButton.bind(this),this.didClickAttributeButton=this.didClickAttributeButton.bind(this),this.didClickDialogButton=this.didClickDialogButton.bind(this),this.didKeyDownDialogInput=this.didKeyDownDialogInput.bind(this),this.element=o,this.attributes={},this.actions={},this.resetDialogInputs(),b("mousedown",{onElement:this.element,matchingSelector:Wr,withCallback:this.didClickActionButton}),b("mousedown",{onElement:this.element,matchingSelector:jr,withCallback:this.didClickAttributeButton}),b("click",{onElement:this.element,matchingSelector:Ur,preventDefault:!0}),b("click",{onElement:this.element,matchingSelector:Yr,withCallback:this.didClickDialogButton}),b("keydown",{onElement:this.element,matchingSelector:$r,withCallback:this.didKeyDownDialogInput})}didClickActionButton(o,s){var a;null===(a=this.delegate)||void 0===a||a.toolbarDidClickButton(),o.preventDefault();const l=Pr(s);return this.getDialog(l)?this.toggleDialog(l):null===(c=this.delegate)||void 0===c?void 0:c.toolbarDidInvokeAction(l,s);var c}didClickAttributeButton(o,s){var a;null===(a=this.delegate)||void 0===a||a.toolbarDidClickButton(),o.preventDefault();const l=Mr(s);var c;this.getDialog(l)?this.toggleDialog(l):null===(c=this.delegate)||void 0===c||c.toolbarDidToggleAttribute(l);return this.refreshAttributeButtons()}didClickDialogButton(o,s){const a=y(s,{matchingSelector:zr});return this[s.getAttribute("data-trix-method")].call(this,a)}didKeyDownDialogInput(o,s){if(13===o.keyCode){o.preventDefault();const a=s.getAttribute("name"),l=this.getDialog(a);this.setAttribute(l)}if(27===o.keyCode)return o.preventDefault(),this.hideDialog()}updateActions(o){return this.actions=o,this.refreshActionButtons()}refreshActionButtons(){return this.eachActionButton(((o,s)=>{o.disabled=!1===this.actions[s]}))}eachActionButton(o){return Array.from(this.element.querySelectorAll(Wr)).map((s=>o(s,Pr(s))))}updateAttributes(o){return this.attributes=o,this.refreshAttributeButtons()}refreshAttributeButtons(){return this.eachAttributeButton(((o,s)=>(o.disabled=!1===this.attributes[s],this.attributes[s]||this.dialogIsVisible(s)?(o.setAttribute("data-trix-active",""),o.classList.add("trix-active")):(o.removeAttribute("data-trix-active"),o.classList.remove("trix-active")))))}eachAttributeButton(o){return Array.from(this.element.querySelectorAll(jr)).map((s=>o(s,Mr(s))))}applyKeyboardCommand(o){const s=JSON.stringify(o.sort());for(const o of Array.from(this.element.querySelectorAll("[data-trix-key]"))){const a=o.getAttribute("data-trix-key").split("+");if(JSON.stringify(a.sort())===s)return v("mousedown",{onElement:o}),!0}return!1}dialogIsVisible(o){const s=this.getDialog(o);if(s)return s.hasAttribute("data-trix-active")}toggleDialog(o){return this.dialogIsVisible(o)?this.hideDialog():this.showDialog(o)}showDialog(o){var s,a;this.hideDialog(),null===(s=this.delegate)||void 0===s||s.toolbarWillShowDialog();const l=this.getDialog(o);l.setAttribute("data-trix-active",""),l.classList.add("trix-active"),Array.from(l.querySelectorAll("input[disabled]")).forEach((o=>{o.removeAttribute("disabled")}));const c=Mr(l);if(c){const s=Fr(l,o);s&&(s.value=this.attributes[c]||"",s.select())}return null===(a=this.delegate)||void 0===a?void 0:a.toolbarDidShowDialog(o)}setAttribute(o){var s;const a=Mr(o),l=Fr(o,a);return!l.willValidate||(l.setCustomValidity(""),l.checkValidity()&&this.isSafeAttribute(l))?(null===(s=this.delegate)||void 0===s||s.toolbarDidUpdateAttribute(a,l.value),this.hideDialog()):(l.setCustomValidity("Invalid value"),l.setAttribute("data-trix-validate",""),l.classList.add("trix-validate"),l.focus())}isSafeAttribute(o){return!o.hasAttribute("data-trix-validate-href")||An.isValidAttribute("a","href",o.value)}removeAttribute(o){var s;const a=Mr(o);return null===(s=this.delegate)||void 0===s||s.toolbarDidRemoveAttribute(a),this.hideDialog()}hideDialog(){const o=this.element.querySelector(Gr);var s;if(o)return o.removeAttribute("data-trix-active"),o.classList.remove("trix-active"),this.resetDialogInputs(),null===(s=this.delegate)||void 0===s?void 0:s.toolbarDidHideDialog((o=>o.getAttribute("data-trix-dialog"))(o))}resetDialogInputs(){Array.from(this.element.querySelectorAll($r)).forEach((o=>{o.setAttribute("disabled","disabled"),o.removeAttribute("data-trix-validate"),o.classList.remove("trix-validate")}))}getDialog(o){return this.element.querySelector("[data-trix-dialog=".concat(o,"]"))}}class _r extends Xn{constructor(o){let{editorElement:s,document:a,html:l}=o;super(...arguments),this.editorElement=s,this.selectionManager=new Vn(this.editorElement),this.selectionManager.delegate=this,this.composition=new wn,this.composition.delegate=this,this.attachmentManager=new kn(this.composition.getAttachments()),this.attachmentManager.delegate=this,this.inputController=2===z.getLevel()?new Ar(this.editorElement):new gr(this.editorElement),this.inputController.delegate=this,this.inputController.responder=this.composition,this.compositionController=new $n(this.editorElement,this.composition),this.compositionController.delegate=this,this.toolbarController=new Br(this.editorElement.toolbarElement),this.toolbarController.delegate=this,this.editor=new Pn(this.composition,this.selectionManager,this.editorElement),a?this.editor.loadDocument(a):this.editor.loadHTML(l)}registerSelectionManager(){return ce.registerSelectionManager(this.selectionManager)}unregisterSelectionManager(){return ce.unregisterSelectionManager(this.selectionManager)}render(){return this.compositionController.render()}reparse(){return this.composition.replaceHTML(this.editorElement.innerHTML)}compositionDidChangeDocument(o){if(this.notifyEditorElement("document-change"),!this.handlingInput)return this.render()}compositionDidChangeCurrentAttributes(o){return this.currentAttributes=o,this.toolbarController.updateAttributes(this.currentAttributes),this.updateCurrentActions(),this.notifyEditorElement("attributes-change",{attributes:this.currentAttributes})}compositionDidPerformInsertionAtRange(o){this.pasting&&(this.pastedRange=o)}compositionShouldAcceptFile(o){return this.notifyEditorElement("file-accept",{file:o})}compositionDidAddAttachment(o){const s=this.attachmentManager.manageAttachment(o);return this.notifyEditorElement("attachment-add",{attachment:s})}compositionDidEditAttachment(o){this.compositionController.rerenderViewForObject(o);const s=this.attachmentManager.manageAttachment(o);return this.notifyEditorElement("attachment-edit",{attachment:s}),this.notifyEditorElement("change")}compositionDidChangeAttachmentPreviewURL(o){return this.compositionController.invalidateViewForObject(o),this.notifyEditorElement("change")}compositionDidRemoveAttachment(o){const s=this.attachmentManager.unmanageAttachment(o);return this.notifyEditorElement("attachment-remove",{attachment:s})}compositionDidStartEditingAttachment(o,s){return this.attachmentLocationRange=this.composition.document.getLocationRangeOfAttachment(o),this.compositionController.installAttachmentEditorForAttachment(o,s),this.selectionManager.setLocationRange(this.attachmentLocationRange)}compositionDidStopEditingAttachment(o){this.compositionController.uninstallAttachmentEditor(),this.attachmentLocationRange=null}compositionDidRequestChangingSelectionToLocationRange(o){if(!this.loadingSnapshot||this.isFocused())return this.requestedLocationRange=o,this.compositionRevisionWhenLocationRangeRequested=this.composition.revision,this.handlingInput?void 0:this.render()}compositionWillLoadSnapshot(){this.loadingSnapshot=!0}compositionDidLoadSnapshot(){this.compositionController.refreshViewCache(),this.render(),this.loadingSnapshot=!1}getSelectionManager(){return this.selectionManager}attachmentManagerDidRequestRemovalOfAttachment(o){return this.removeAttachment(o)}compositionControllerWillSyncDocumentView(){return this.inputController.editorWillSyncDocumentView(),this.selectionManager.lock(),this.selectionManager.clearSelection()}compositionControllerDidSyncDocumentView(){return this.inputController.editorDidSyncDocumentView(),this.selectionManager.unlock(),this.updateCurrentActions(),this.notifyEditorElement("sync")}compositionControllerDidRender(){this.requestedLocationRange&&(this.compositionRevisionWhenLocationRangeRequested===this.composition.revision&&this.selectionManager.setLocationRange(this.requestedLocationRange),this.requestedLocationRange=null,this.compositionRevisionWhenLocationRangeRequested=null),this.renderedCompositionRevision!==this.composition.revision&&(this.runEditorFilters(),this.composition.updateCurrentAttributes(),this.notifyEditorElement("render")),this.renderedCompositionRevision=this.composition.revision}compositionControllerDidFocus(){return this.isFocusedInvisibly()&&this.setLocationRange({index:0,offset:0}),this.toolbarController.hideDialog(),this.notifyEditorElement("focus")}compositionControllerDidBlur(){return this.notifyEditorElement("blur")}compositionControllerDidSelectAttachment(o,s){return this.toolbarController.hideDialog(),this.composition.editAttachment(o,s)}compositionControllerDidRequestDeselectingAttachment(o){const s=this.attachmentLocationRange||this.composition.document.getLocationRangeOfAttachment(o);return this.selectionManager.setLocationRange(s[1])}compositionControllerWillUpdateAttachment(o){return this.editor.recordUndoEntry("Edit Attachment",{context:o.id,consolidatable:!0})}compositionControllerDidRequestRemovalOfAttachment(o){return this.removeAttachment(o)}inputControllerWillHandleInput(){this.handlingInput=!0,this.requestedRender=!1}inputControllerDidRequestRender(){this.requestedRender=!0}inputControllerDidHandleInput(){if(this.handlingInput=!1,this.requestedRender)return this.requestedRender=!1,this.render()}inputControllerDidAllowUnhandledInput(){return this.notifyEditorElement("change")}inputControllerDidRequestReparse(){return this.reparse()}inputControllerWillPerformTyping(){return this.recordTypingUndoEntry()}inputControllerWillPerformFormatting(o){return this.recordFormattingUndoEntry(o)}inputControllerWillCutText(){return this.editor.recordUndoEntry("Cut")}inputControllerWillPaste(o){return this.editor.recordUndoEntry("Paste"),this.pasting=!0,this.notifyEditorElement("before-paste",{paste:o})}inputControllerDidPaste(o){return o.range=this.pastedRange,this.pastedRange=null,this.pasting=null,this.notifyEditorElement("paste",{paste:o})}inputControllerWillMoveText(){return this.editor.recordUndoEntry("Move")}inputControllerWillAttachFiles(){return this.editor.recordUndoEntry("Drop Files")}inputControllerWillPerformUndo(){return this.editor.undo()}inputControllerWillPerformRedo(){return this.editor.redo()}inputControllerDidReceiveKeyboardCommand(o){return this.toolbarController.applyKeyboardCommand(o)}inputControllerDidStartDrag(){this.locationRangeBeforeDrag=this.selectionManager.getLocationRange()}inputControllerDidReceiveDragOverPoint(o){return this.selectionManager.setLocationRangeFromPointRange(o)}inputControllerDidCancelDrag(){this.selectionManager.setLocationRange(this.locationRangeBeforeDrag),this.locationRangeBeforeDrag=null}locationRangeDidChange(o){return this.composition.updateCurrentAttributes(),this.updateCurrentActions(),this.attachmentLocationRange&&!Dt(this.attachmentLocationRange,o)&&this.composition.stopEditingAttachment(),this.notifyEditorElement("selection-change")}toolbarDidClickButton(){if(!this.getLocationRange())return this.setLocationRange({index:0,offset:0})}toolbarDidInvokeAction(o,s){return this.invokeAction(o,s)}toolbarDidToggleAttribute(o){if(this.recordFormattingUndoEntry(o),this.composition.toggleCurrentAttribute(o),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarDidUpdateAttribute(o,s){if(this.recordFormattingUndoEntry(o),this.composition.setCurrentAttribute(o,s),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarDidRemoveAttribute(o){if(this.recordFormattingUndoEntry(o),this.composition.removeCurrentAttribute(o),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarWillShowDialog(o){return this.composition.expandSelectionForEditing(),this.freezeSelection()}toolbarDidShowDialog(o){return this.notifyEditorElement("toolbar-dialog-show",{dialogName:o})}toolbarDidHideDialog(o){return this.thawSelection(),this.editorElement.focus(),this.notifyEditorElement("toolbar-dialog-hide",{dialogName:o})}freezeSelection(){if(!this.selectionFrozen)return this.selectionManager.lock(),this.composition.freezeSelection(),this.selectionFrozen=!0,this.render()}thawSelection(){if(this.selectionFrozen)return this.composition.thawSelection(),this.selectionManager.unlock(),this.selectionFrozen=!1,this.render()}canInvokeAction(o){return!!this.actionIsExternal(o)||!(null===(s=this.actions[o])||void 0===s||null===(s=s.test)||void 0===s||!s.call(this));var s}invokeAction(o,s){return this.actionIsExternal(o)?this.notifyEditorElement("action-invoke",{actionName:o,invokingElement:s}):null===(a=this.actions[o])||void 0===a||null===(a=a.perform)||void 0===a?void 0:a.call(this);var a}actionIsExternal(o){return/^x-./.test(o)}getCurrentActions(){const o={};for(const s in this.actions)o[s]=this.canInvokeAction(s);return o}updateCurrentActions(){const o=this.getCurrentActions();if(!Tt(o,this.currentActions))return this.currentActions=o,this.toolbarController.updateActions(this.currentActions),this.notifyEditorElement("actions-change",{actions:this.currentActions})}runEditorFilters(){let o=this.composition.getSnapshot();if(Array.from(this.editor.filters).forEach((s=>{const{document:a,selectedRange:l}=o;o=s.call(this.editor,o)||{},o.document||(o.document=a),o.selectedRange||(o.selectedRange=l)})),s=o,a=this.composition.getSnapshot(),!Dt(s.selectedRange,a.selectedRange)||!s.document.isEqualTo(a.document))return this.composition.loadSnapshot(o);var s,a}updateInputElement(){const o=function(o,s){const a=Jn[s];if(a)return a(o);throw new Error("unknown content type: ".concat(s))}(this.compositionController.getSerializableElement(),"text/html");return this.editorElement.setFormValue(o)}notifyEditorElement(o,s){switch(o){case"document-change":this.documentChangedSinceLastRender=!0;break;case"render":this.documentChangedSinceLastRender&&(this.documentChangedSinceLastRender=!1,this.notifyEditorElement("change"));break;case"change":case"attachment-add":case"attachment-edit":case"attachment-remove":this.updateInputElement()}return this.editorElement.notify(o,s)}removeAttachment(o){return this.editor.recordUndoEntry("Delete Attachment"),this.composition.removeAttachment(o),this.render()}recordFormattingUndoEntry(o){const s=mt(o),a=this.selectionManager.getLocationRange();if(s||!Lt(a))return this.editor.recordUndoEntry("Formatting",{context:this.getUndoContext(),consolidatable:!0})}recordTypingUndoEntry(){return this.editor.recordUndoEntry("Typing",{context:this.getUndoContext(this.currentAttributes),consolidatable:!0})}getUndoContext(){for(var o=arguments.length,s=new Array(o),a=0;a0?Math.floor((new Date).getTime()/Y.interval):0}isFocused(){var o;return this.editorElement===(null===(o=this.editorElement.ownerDocument)||void 0===o?void 0:o.activeElement)}isFocusedInvisibly(){return this.isFocused()&&!this.getLocationRange()}get actions(){return this.constructor.actions}}Di(_r,"actions",{undo:{test(){return this.editor.canUndo()},perform(){return this.editor.undo()}},redo:{test(){return this.editor.canRedo()},perform(){return this.editor.redo()}},link:{test(){return this.editor.canActivateAttribute("href")}},increaseNestingLevel:{test(){return this.editor.canIncreaseNestingLevel()},perform(){return this.editor.increaseNestingLevel()&&this.render()}},decreaseNestingLevel:{test(){return this.editor.canDecreaseNestingLevel()},perform(){return this.editor.decreaseNestingLevel()&&this.render()}},attachFiles:{test:()=>!0,perform(){return z.pickFiles(this.editor.insertFiles)}}}),_r.proxyMethod("getSelectionManager().setLocationRange"),_r.proxyMethod("getSelectionManager().getLocationRange");var Qr=Object.freeze({__proto__:null,AttachmentEditorController:Yn,CompositionController:$n,Controller:Xn,EditorController:_r,InputController:lr,Level0InputController:gr,Level2InputController:Ar,ToolbarController:Br}),to=Object.freeze({__proto__:null,MutationObserver:er,SelectionChangeObserver:Ot}),eo=Object.freeze({__proto__:null,FileVerificationOperation:nr,ImagePreloadOperation:Ui});vt("trix-toolbar","%t {\n display: block;\n}\n\n%t {\n white-space: nowrap;\n}\n\n%t [data-trix-dialog] {\n display: none;\n}\n\n%t [data-trix-dialog][data-trix-active] {\n display: block;\n}\n\n%t [data-trix-dialog] [data-trix-validate]:invalid {\n background-color: #ffdddd;\n}");class Vr extends HTMLElement{connectedCallback(){""===this.innerHTML&&(this.innerHTML=G.getDefaultHTML())}}let no=0;const qr=function(o){if(!o.hasAttribute("contenteditable"))return o.setAttribute("contenteditable",""),function(o){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return s.times=1,b(o,s)}("focus",{onElement:o,withCallback:()=>Hr(o)})},Hr=function(o){return Jr(o),Kr(o)},Jr=function(o){var s,a;if(null!==(s=(a=document).queryCommandSupported)&&void 0!==s&&s.call(a,"enableObjectResizing"))return document.execCommand("enableObjectResizing",!1,!1),b("mscontrolselect",{onElement:o,preventDefault:!0})},Kr=function(o){var s,a;if(null!==(s=(a=document).queryCommandSupported)&&void 0!==s&&s.call(a,"DefaultParagraphSeparator")){const{tagName:o}=l.default;if(["div","p"].includes(o))return document.execCommand("DefaultParagraphSeparator",!1,o)}},oo=d.forcesObjectResizing?{display:"inline",width:"auto"}:{display:"inline-block",width:"1px"};vt("trix-editor","%t {\n display: block;\n}\n\n%t:empty::before {\n content: attr(placeholder);\n color: graytext;\n cursor: text;\n pointer-events: none;\n white-space: pre-line;\n}\n\n%t a[contenteditable=false] {\n cursor: text;\n}\n\n%t img {\n max-width: 100%;\n height: auto;\n}\n\n%t ".concat(s," figcaption textarea {\n resize: none;\n}\n\n%t ").concat(s," figcaption textarea.trix-autoresize-clone {\n position: absolute;\n left: -9999px;\n max-height: 0px;\n}\n\n%t ").concat(s," figcaption[data-trix-placeholder]:empty::before {\n content: attr(data-trix-placeholder);\n color: graytext;\n}\n\n%t [data-trix-cursor-target] {\n display: ").concat(oo.display," !important;\n width: ").concat(oo.width," !important;\n padding: 0 !important;\n margin: 0 !important;\n border: none !important;\n}\n\n%t [data-trix-cursor-target=left] {\n vertical-align: top !important;\n margin-left: -1px !important;\n}\n\n%t [data-trix-cursor-target=right] {\n vertical-align: bottom !important;\n margin-right: -1px !important;\n}"));var so=new WeakMap,ao=new WeakSet;class Xr{constructor(o){var s,a;_i(s=this,a=ao),a.add(s),ji(this,so,{writable:!0,value:void 0}),this.element=o,Oi(this,so,o.attachInternals())}connectedCallback(){Bi(this,ao,Zr).call(this)}disconnectedCallback(){}get labels(){return Ii(this,so).labels}get disabled(){var o;return null===(o=this.element.inputElement)||void 0===o?void 0:o.disabled}set disabled(o){this.element.toggleAttribute("disabled",o)}get required(){return this.element.hasAttribute("required")}set required(o){this.element.toggleAttribute("required",o),Bi(this,ao,Zr).call(this)}get validity(){return Ii(this,so).validity}get validationMessage(){return Ii(this,so).validationMessage}get willValidate(){return Ii(this,so).willValidate}setFormValue(o){Bi(this,ao,Zr).call(this)}checkValidity(){return Ii(this,so).checkValidity()}reportValidity(){return Ii(this,so).reportValidity()}setCustomValidity(o){Bi(this,ao,Zr).call(this,o)}}function Zr(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const{required:s,value:a}=this.element,l=s&&!a,c=!!o,h=T("input",{required:s}),d=o||h.validationMessage;Ii(this,so).setValidity({valueMissing:l,customError:c},d)}var lo=new WeakMap,co=new WeakMap,uo=new WeakMap;class io{constructor(o){ji(this,lo,{writable:!0,value:void 0}),ji(this,co,{writable:!0,value:o=>{o.defaultPrevented||o.target===this.element.form&&this.element.reset()}}),ji(this,uo,{writable:!0,value:o=>{if(o.defaultPrevented)return;if(this.element.contains(o.target))return;const s=y(o.target,{matchingSelector:"label"});s&&Array.from(this.labels).includes(s)&&this.element.focus()}}),this.element=o}connectedCallback(){Oi(this,lo,function(o){if(o.hasAttribute("aria-label")||o.hasAttribute("aria-labelledby"))return;const e=function(){const s=Array.from(o.labels).map((s=>{if(!s.contains(o))return s.textContent})).filter((o=>o)),a=s.join(" ");return a?o.setAttribute("aria-label",a):o.removeAttribute("aria-label")};return e(),b("focus",{onElement:o,withCallback:e})}(this.element)),window.addEventListener("reset",Ii(this,co),!1),window.addEventListener("click",Ii(this,uo),!1)}disconnectedCallback(){var o;null===(o=Ii(this,lo))||void 0===o||o.destroy(),window.removeEventListener("reset",Ii(this,co),!1),window.removeEventListener("click",Ii(this,uo),!1)}get labels(){const o=[];this.element.id&&this.element.ownerDocument&&o.push(...Array.from(this.element.ownerDocument.querySelectorAll("label[for='".concat(this.element.id,"']"))||[]));const s=y(this.element,{matchingSelector:"label"});return s&&[this.element,null].includes(s.control)&&o.push(s),o}get disabled(){return console.warn("This browser does not support the [disabled] attribute for trix-editor elements."),!1}set disabled(o){console.warn("This browser does not support the [disabled] attribute for trix-editor elements.")}get required(){return console.warn("This browser does not support the [required] attribute for trix-editor elements."),!1}set required(o){console.warn("This browser does not support the [required] attribute for trix-editor elements.")}get validity(){return console.warn("This browser does not support the validity property for trix-editor elements."),null}get validationMessage(){return console.warn("This browser does not support the validationMessage property for trix-editor elements."),""}get willValidate(){return console.warn("This browser does not support the willValidate property for trix-editor elements."),!1}setFormValue(o){}checkValidity(){return console.warn("This browser does not support checkValidity() for trix-editor elements."),!0}reportValidity(){return console.warn("This browser does not support reportValidity() for trix-editor elements."),!0}setCustomValidity(o){console.warn("This browser does not support setCustomValidity(validationMessage) for trix-editor elements.")}}var ho=new WeakMap;class ro extends HTMLElement{constructor(){super(),ji(this,ho,{writable:!0,value:void 0}),Oi(this,ho,this.constructor.formAssociated?new Xr(this):new io(this))}get trixId(){return this.hasAttribute("trix-id")?this.getAttribute("trix-id"):(this.setAttribute("trix-id",++no),this.trixId)}get labels(){return Ii(this,ho).labels}get disabled(){return Ii(this,ho).disabled}set disabled(o){Ii(this,ho).disabled=o}get required(){return Ii(this,ho).required}set required(o){Ii(this,ho).required=o}get validity(){return Ii(this,ho).validity}get validationMessage(){return Ii(this,ho).validationMessage}get willValidate(){return Ii(this,ho).willValidate}get type(){return this.localName}get toolbarElement(){var o;if(this.hasAttribute("toolbar"))return null===(o=this.ownerDocument)||void 0===o?void 0:o.getElementById(this.getAttribute("toolbar"));if(this.parentNode){const o="trix-toolbar-".concat(this.trixId);return this.setAttribute("toolbar",o),this.internalToolbar=T("trix-toolbar",{id:o}),this.parentNode.insertBefore(this.internalToolbar,this),this.internalToolbar}}get form(){var o;return null===(o=this.inputElement)||void 0===o?void 0:o.form}get inputElement(){var o;if(this.hasAttribute("input"))return null===(o=this.ownerDocument)||void 0===o?void 0:o.getElementById(this.getAttribute("input"));if(this.parentNode){const o="trix-input-".concat(this.trixId);this.setAttribute("input",o);const s=T("input",{type:"hidden",id:o});return this.parentNode.insertBefore(s,this.nextElementSibling),s}}get editor(){var o;return null===(o=this.editorController)||void 0===o?void 0:o.editor}get name(){var o;return null===(o=this.inputElement)||void 0===o?void 0:o.name}get value(){var o;return null===(o=this.inputElement)||void 0===o?void 0:o.value}set value(o){var s;this.defaultValue=o,null===(s=this.editor)||void 0===s||s.loadHTML(this.defaultValue)}attributeChangedCallback(o,s,a){"connected"===o&&this.isConnected&&null!=s&&s!==a&&requestAnimationFrame((()=>this.reconnect()))}notify(o,s){if(this.editorController)return v("trix-".concat(o),{onElement:this,attributes:s})}setFormValue(o){this.inputElement&&(this.inputElement.value=o,Ii(this,ho).setFormValue(o))}connectedCallback(){this.hasAttribute("data-trix-internal")||(qr(this),function(o){o.hasAttribute("role")||o.setAttribute("role","textbox")}(this),this.editorController||(v("trix-before-initialize",{onElement:this}),this.editorController=new _r({editorElement:this,html:this.defaultValue=this.value}),requestAnimationFrame((()=>v("trix-initialize",{onElement:this})))),this.editorController.registerSelectionManager(),Ii(this,ho).connectedCallback(),this.toggleAttribute("connected",!0),function(o){!document.querySelector(":focus")&&o.hasAttribute("autofocus")&&document.querySelector("[autofocus]")===o&&o.focus()}(this))}disconnectedCallback(){var o;null===(o=this.editorController)||void 0===o||o.unregisterSelectionManager(),Ii(this,ho).disconnectedCallback(),this.toggleAttribute("connected",!1)}reconnect(){this.removeInternalToolbar(),this.disconnectedCallback(),this.connectedCallback()}removeInternalToolbar(){var o;null===(o=this.internalToolbar)||void 0===o||o.remove(),this.internalToolbar=null}checkValidity(){return Ii(this,ho).checkValidity()}reportValidity(){return Ii(this,ho).reportValidity()}setCustomValidity(o){Ii(this,ho).setCustomValidity(o)}formDisabledCallback(o){this.inputElement&&(this.inputElement.disabled=o),this.toggleAttribute("contenteditable",!o)}formResetCallback(){this.reset()}reset(){this.value=this.defaultValue}}Di(ro,"formAssociated","ElementInternals"in window),Di(ro,"observedAttributes",["connected"]);const go={VERSION:o,config:$,core:Kn,models:tr,views:sr,controllers:Qr,observers:to,operations:eo,elements:Object.freeze({__proto__:null,TrixEditorElement:ro,TrixToolbarElement:Vr}),filters:Object.freeze({__proto__:null,Filter:In,attachmentGalleryFilter:On})};Object.assign(go,tr),window.Trix=go,setTimeout((function(){customElements.get("trix-toolbar")||customElements.define("trix-toolbar",Vr),customElements.get("trix-editor")||customElements.define("trix-editor",ro)}),0);export{go as default}; +var t="2.1.15";const e="[data-trix-attachment]",i={preview:{presentation:"gallery",caption:{name:!0,size:!0}},file:{caption:{size:!0}}},n={default:{tagName:"div",parse:!1},quote:{tagName:"blockquote",nestable:!0},heading1:{tagName:"h1",terminal:!0,breakOnReturn:!0,group:!1},code:{tagName:"pre",terminal:!0,htmlAttributes:["language"],text:{plaintext:!0}},bulletList:{tagName:"ul",parse:!1},bullet:{tagName:"li",listAttribute:"bulletList",group:!1,nestable:!0,test(t){return r(t.parentNode)===n[this.listAttribute].tagName}},numberList:{tagName:"ol",parse:!1},number:{tagName:"li",listAttribute:"numberList",group:!1,nestable:!0,test(t){return r(t.parentNode)===n[this.listAttribute].tagName}},attachmentGallery:{tagName:"div",exclusive:!0,terminal:!0,parse:!1,group:!1}},r=t=>{var e;return null==t||null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase()},o=navigator.userAgent.match(/android\s([0-9]+.*Chrome)/i),s=o&&parseInt(o[1]);var a={composesExistingText:/Android.*Chrome/.test(navigator.userAgent),recentAndroid:s&&s>12,samsungAndroid:s&&navigator.userAgent.match(/Android.*SM-/),forcesObjectResizing:/Trident.*rv:11/.test(navigator.userAgent),supportsInputEvents:"undefined"!=typeof InputEvent&&["data","getTargetRanges","inputType"].every((t=>t in InputEvent.prototype))},l={ADD_ATTR:["language"],SAFE_FOR_XML:!1,RETURN_DOM:!0},c={attachFiles:"Attach Files",bold:"Bold",bullets:"Bullets",byte:"Byte",bytes:"Bytes",captionPlaceholder:"Add a caption…",code:"Code",heading1:"Heading",indent:"Increase Level",italic:"Italic",link:"Link",numbers:"Numbers",outdent:"Decrease Level",quote:"Quote",redo:"Redo",remove:"Remove",strike:"Strikethrough",undo:"Undo",unlink:"Unlink",url:"URL",urlPlaceholder:"Enter a URL…",GB:"GB",KB:"KB",MB:"MB",PB:"PB",TB:"TB"};const u=[c.bytes,c.KB,c.MB,c.GB,c.TB,c.PB];var h={prefix:"IEC",precision:2,formatter(t){switch(t){case 0:return"0 ".concat(c.bytes);case 1:return"1 ".concat(c.byte);default:let e;"SI"===this.prefix?e=1e3:"IEC"===this.prefix&&(e=1024);const i=Math.floor(Math.log(t)/Math.log(e)),n=(t/Math.pow(e,i)).toFixed(this.precision).replace(/0*$/,"").replace(/\.$/,"");return"".concat(n," ").concat(u[i])}}};const d="\ufeff",g=" ",m=function(t){for(const e in t){const i=t[e];this[e]=i}return this},p=document.documentElement,f=p.matches,b=function(t){let{onElement:e,matchingSelector:i,withCallback:n,inPhase:r,preventDefault:o,times:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const a=e||p,l=i,c="capturing"===r,u=function(t){null!=s&&0==--s&&u.destroy();const e=y(t.target,{matchingSelector:l});null!=e&&(null==n||n.call(e,t,e),o&&t.preventDefault())};return u.destroy=()=>a.removeEventListener(t,u,c),a.addEventListener(t,u,c),u},v=function(t){let{onElement:e,bubbles:i,cancelable:n,attributes:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=null!=e?e:p;i=!1!==i,n=!1!==n;const s=document.createEvent("Events");return s.initEvent(t,i,n),null!=r&&m.call(s,r),o.dispatchEvent(s)},A=function(t,e){if(1===(null==t?void 0:t.nodeType))return f.call(t,e)},y=function(t){let{matchingSelector:e,untilNode:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(;t&&t.nodeType!==Node.ELEMENT_NODE;)t=t.parentNode;if(null!=t){if(null==e)return t;if(t.closest&&null==i)return t.closest(e);for(;t&&t!==i;){if(A(t,e))return t;t=t.parentNode}}},x=t=>document.activeElement!==t&&C(t,document.activeElement),C=function(t,e){if(t&&e)for(;e;){if(e===t)return!0;e=e.parentNode}},E=function(t){var e;if(null===(e=t)||void 0===e||!e.parentNode)return;let i=0;for(t=t.previousSibling;t;)i++,t=t.previousSibling;return i},S=t=>{var e;return null==t||null===(e=t.parentNode)||void 0===e?void 0:e.removeChild(t)},R=function(t){let{onlyNodesOfType:e,usingFilter:i,expandEntityReferences:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=(()=>{switch(e){case"element":return NodeFilter.SHOW_ELEMENT;case"text":return NodeFilter.SHOW_TEXT;case"comment":return NodeFilter.SHOW_COMMENT;default:return NodeFilter.SHOW_ALL}})();return document.createTreeWalker(t,r,null!=i?i:null,!0===n)},k=t=>{var e;return null==t||null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase()},T=function(t){let e,i,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"==typeof t?(n=t,t=n.tagName):n={attributes:n};const r=document.createElement(t);if(null!=n.editable&&(null==n.attributes&&(n.attributes={}),n.attributes.contenteditable=n.editable),n.attributes)for(e in n.attributes)i=n.attributes[e],r.setAttribute(e,i);if(n.style)for(e in n.style)i=n.style[e],r.style[e]=i;if(n.data)for(e in n.data)i=n.data[e],r.dataset[e]=i;return n.className&&n.className.split(" ").forEach((t=>{r.classList.add(t)})),n.textContent&&(r.textContent=n.textContent),n.childNodes&&[].concat(n.childNodes).forEach((t=>{r.appendChild(t)})),r};let w;const L=function(){if(null!=w)return w;w=[];for(const t in n){const e=n[t];e.tagName&&w.push(e.tagName)}return w},D=t=>I(null==t?void 0:t.firstChild),N=function(t){let{strict:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{strict:!0};return e?I(t):I(t)||!I(t.firstChild)&&function(t){return L().includes(k(t))&&!L().includes(k(t.firstChild))}(t)},I=t=>O(t)&&"block"===(null==t?void 0:t.data),O=t=>(null==t?void 0:t.nodeType)===Node.COMMENT_NODE,F=function(t){let{name:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t)return B(t)?t.data===d?!e||t.parentNode.dataset.trixCursorTarget===e:void 0:F(t.firstChild)},P=t=>A(t,e),M=t=>B(t)&&""===(null==t?void 0:t.data),B=t=>(null==t?void 0:t.nodeType)===Node.TEXT_NODE,_={level2Enabled:!0,getLevel(){return this.level2Enabled&&a.supportsInputEvents?2:0},pickFiles(t){const e=T("input",{type:"file",multiple:!0,hidden:!0,id:this.fileInputId});e.addEventListener("change",(()=>{t(e.files),S(e)})),S(document.getElementById(this.fileInputId)),document.body.appendChild(e),e.click()}};var j={removeBlankTableCells:!1,tableCellSeparator:" | ",tableRowSeparator:"\n"},W={bold:{tagName:"strong",inheritable:!0,parser(t){const e=window.getComputedStyle(t);return"bold"===e.fontWeight||e.fontWeight>=600}},italic:{tagName:"em",inheritable:!0,parser:t=>"italic"===window.getComputedStyle(t).fontStyle},href:{groupTagName:"a",parser(t){const i="a:not(".concat(e,")"),n=t.closest(i);if(n)return n.getAttribute("href")}},strike:{tagName:"del",inheritable:!0},frozen:{style:{backgroundColor:"highlight"}}},U={getDefaultHTML:()=>'
\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n\n \n \n \n \n
\n\n
\n \n
')};const V={interval:5e3};var H=Object.freeze({__proto__:null,attachments:i,blockAttributes:n,browser:a,css:{attachment:"attachment",attachmentCaption:"attachment__caption",attachmentCaptionEditor:"attachment__caption-editor",attachmentMetadata:"attachment__metadata",attachmentMetadataContainer:"attachment__metadata-container",attachmentName:"attachment__name",attachmentProgress:"attachment__progress",attachmentSize:"attachment__size",attachmentToolbar:"attachment__toolbar",attachmentGallery:"attachment-gallery"},dompurify:l,fileSize:h,input:_,keyNames:{8:"backspace",9:"tab",13:"return",27:"escape",37:"left",39:"right",46:"delete",68:"d",72:"h",79:"o"},lang:c,parser:j,textAttributes:W,toolbar:U,undo:V});class q{static proxyMethod(t){const{name:e,toMethod:i,toProperty:n,optional:r}=z(t);this.prototype[e]=function(){let t,o;var s,a;i?o=r?null===(s=this[i])||void 0===s?void 0:s.call(this):this[i]():n&&(o=this[n]);return r?(t=null===(a=o)||void 0===a?void 0:a[e],t?J.call(t,o,arguments):void 0):(t=o[e],J.call(t,o,arguments))}}}const z=function(t){const e=t.match(K);if(!e)throw new Error("can't parse @proxyMethod expression: ".concat(t));const i={name:e[4]};return null!=e[2]?i.toMethod=e[1]:i.toProperty=e[1],null!=e[3]&&(i.optional=!0),i},{apply:J}=Function.prototype,K=new RegExp("^(.+?)(\\(\\))?(\\?)?\\.(.+?)$");var G,Y,X;class $ extends q{static box(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return t instanceof this?t:this.fromUCS2String(null==t?void 0:t.toString())}static fromUCS2String(t){return new this(t,et(t))}static fromCodepoints(t){return new this(it(t),t)}constructor(t,e){super(...arguments),this.ucs2String=t,this.codepoints=e,this.length=this.codepoints.length,this.ucs2Length=this.ucs2String.length}offsetToUCS2Offset(t){return it(this.codepoints.slice(0,Math.max(0,t))).length}offsetFromUCS2Offset(t){return et(this.ucs2String.slice(0,Math.max(0,t))).length}slice(){return this.constructor.fromCodepoints(this.codepoints.slice(...arguments))}charAt(t){return this.slice(t,t+1)}isEqualTo(t){return this.constructor.box(t).ucs2String===this.ucs2String}toJSON(){return this.ucs2String}getCacheKey(){return this.ucs2String}toString(){return this.ucs2String}}const Z=1===(null===(G=Array.from)||void 0===G?void 0:G.call(Array,"👼").length),Q=null!=(null===(Y=" ".codePointAt)||void 0===Y?void 0:Y.call(" ",0)),tt=" 👼"===(null===(X=String.fromCodePoint)||void 0===X?void 0:X.call(String,32,128124));let et,it;et=Z&&Q?t=>Array.from(t).map((t=>t.codePointAt(0))):function(t){const e=[];let i=0;const{length:n}=t;for(;iString.fromCodePoint(...Array.from(t||[])):function(t){return(()=>{const e=[];return Array.from(t).forEach((t=>{let i="";t>65535&&(t-=65536,i+=String.fromCharCode(t>>>10&1023|55296),t=56320|1023&t),e.push(i+String.fromCharCode(t))})),e})().join("")};let nt=0;class rt extends q{static fromJSONString(t){return this.fromJSON(JSON.parse(t))}constructor(){super(...arguments),this.id=++nt}hasSameConstructorAs(t){return this.constructor===(null==t?void 0:t.constructor)}isEqualTo(t){return this===t}inspect(){const t=[],e=this.contentsForInspection()||{};for(const i in e){const n=e[i];t.push("".concat(i,"=").concat(n))}return"#<".concat(this.constructor.name,":").concat(this.id).concat(t.length?" ".concat(t.join(", ")):"",">")}contentsForInspection(){}toJSONString(){return JSON.stringify(this)}toUTF16String(){return $.box(this)}getCacheKey(){return this.id.toString()}}const ot=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(t.length!==e.length)return!1;for(let i=0;i1?i-1:0),r=1;r(ct||(ct=bt().concat(pt())),ct),mt=t=>n[t],pt=()=>(ut||(ut=Object.keys(n)),ut),ft=t=>W[t],bt=()=>(ht||(ht=Object.keys(W)),ht),vt=function(t,e){At(t).textContent=e.replace(/%t/g,t)},At=function(t){const e=document.createElement("style");e.setAttribute("type","text/css"),e.setAttribute("data-tag-name",t.toLowerCase());const i=yt();return i&&e.setAttribute("nonce",i),document.head.insertBefore(e,document.head.firstChild),e},yt=function(){const t=xt("trix-csp-nonce")||xt("csp-nonce");if(t){const{nonce:e,content:i}=t;return""==e?i:e}},xt=t=>document.head.querySelector("meta[name=".concat(t,"]")),Ct={"application/x-trix-feature-detection":"test"},Et=function(t){const e=t.getData("text/plain"),i=t.getData("text/html");if(!e||!i)return null==e?void 0:e.length;{const{body:t}=(new DOMParser).parseFromString(i,"text/html");if(t.textContent===e)return!t.querySelector("*")}},St=/Mac|^iP/.test(navigator.platform)?t=>t.metaKey:t=>t.ctrlKey;const Rt=t=>setTimeout(t,1),kt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e={};for(const i in t){const n=t[i];e[i]=n}return e},Tt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const i in t)if(t[i]!==e[i])return!1;return!0},wt=function(t){if(null!=t)return Array.isArray(t)||(t=[t,t]),[Nt(t[0]),Nt(null!=t[1]?t[1]:t[0])]},Lt=function(t){if(null==t)return;const[e,i]=wt(t);return It(e,i)},Dt=function(t,e){if(null==t||null==e)return;const[i,n]=wt(t),[r,o]=wt(e);return It(i,r)&&It(n,o)},Nt=function(t){return"number"==typeof t?t:kt(t)},It=function(t,e){return"number"==typeof t?t===e:Tt(t,e)};class Ot extends q{constructor(){super(...arguments),this.update=this.update.bind(this),this.selectionManagers=[]}start(){this.started||(this.started=!0,document.addEventListener("selectionchange",this.update,!0))}stop(){if(this.started)return this.started=!1,document.removeEventListener("selectionchange",this.update,!0)}registerSelectionManager(t){if(!this.selectionManagers.includes(t))return this.selectionManagers.push(t),this.start()}unregisterSelectionManager(t){if(this.selectionManagers=this.selectionManagers.filter((e=>e!==t)),0===this.selectionManagers.length)return this.stop()}notifySelectionManagersOfSelectionChange(){return this.selectionManagers.map((t=>t.selectionDidChange()))}update(){this.notifySelectionManagersOfSelectionChange()}reset(){this.update()}}const Ft=new Ot,Pt=function(){const t=window.getSelection();if(t.rangeCount>0)return t},Mt=function(){var t;const e=null===(t=Pt())||void 0===t?void 0:t.getRangeAt(0);if(e&&!_t(e))return e},Bt=function(t){const e=window.getSelection();return e.removeAllRanges(),e.addRange(t),Ft.update()},_t=t=>jt(t.startContainer)||jt(t.endContainer),jt=t=>!Object.getPrototypeOf(t),Wt=t=>t.replace(new RegExp("".concat(d),"g"),"").replace(new RegExp("".concat(g),"g")," "),Ut=new RegExp("[^\\S".concat(g,"]")),Vt=t=>t.replace(new RegExp("".concat(Ut.source),"g")," ").replace(/\ {2,}/g," "),qt=function(t,e){if(t.isEqualTo(e))return["",""];const i=zt(t,e),{length:n}=i.utf16String;let r;if(n){const{offset:o}=i,s=t.codepoints.slice(0,o).concat(t.codepoints.slice(o+n));r=zt(e,$.fromCodepoints(s))}else r=zt(e,t);return[i.utf16String.toString(),r.utf16String.toString()]},zt=function(t,e){let i=0,n=t.length,r=e.length;for(;ii+1&&t.charAt(n-1).isEqualTo(e.charAt(r-1));)n--,r--;return{utf16String:t.slice(i,n),offset:i}};class Ht extends rt{static fromCommonAttributesOfObjects(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!t.length)return new this;let e=Yt(t[0]),i=e.getKeys();return t.slice(1).forEach((t=>{i=e.getKeysCommonToHash(Yt(t)),e=e.slice(i)})),e}static box(t){return Yt(t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(...arguments),this.values=Gt(t)}add(t,e){return this.merge(Jt(t,e))}remove(t){return new Ht(Gt(this.values,t))}get(t){return this.values[t]}has(t){return t in this.values}merge(t){return new Ht(Kt(this.values,Xt(t)))}slice(t){const e={};return Array.from(t).forEach((t=>{this.has(t)&&(e[t]=this.values[t])})),new Ht(e)}getKeys(){return Object.keys(this.values)}getKeysCommonToHash(t){return t=Yt(t),this.getKeys().filter((e=>this.values[e]===t.values[e]))}isEqualTo(t){return ot(this.toArray(),Yt(t).toArray())}isEmpty(){return 0===this.getKeys().length}toArray(){if(!this.array){const t=[];for(const e in this.values){const i=this.values[e];t.push(t.push(e,i))}this.array=t.slice(0)}return this.array}toObject(){return Gt(this.values)}toJSON(){return this.toObject()}contentsForInspection(){return{values:JSON.stringify(this.values)}}}const Jt=function(t,e){const i={};return i[t]=e,i},Kt=function(t,e){const i=Gt(t);for(const t in e){const n=e[t];i[t]=n}return i},Gt=function(t,e){const i={};return Object.keys(t).sort().forEach((n=>{n!==e&&(i[n]=t[n])})),i},Yt=function(t){return t instanceof Ht?t:new Ht(t)},Xt=function(t){return t instanceof Ht?t.values:t};class $t{static groupObjects(){let t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],{depth:i,asTree:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n&&null==i&&(i=0);const r=[];return Array.from(e).forEach((e=>{var o;if(t){var s,a,l;if(null!==(s=e.canBeGrouped)&&void 0!==s&&s.call(e,i)&&null!==(a=(l=t[t.length-1]).canBeGroupedWith)&&void 0!==a&&a.call(l,e,i))return void t.push(e);r.push(new this(t,{depth:i,asTree:n})),t=null}null!==(o=e.canBeGrouped)&&void 0!==o&&o.call(e,i)?t=[e]:r.push(e)})),t&&r.push(new this(t,{depth:i,asTree:n})),r}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],{depth:e,asTree:i}=arguments.length>1?arguments[1]:void 0;this.objects=t,i&&(this.depth=e,this.objects=this.constructor.groupObjects(this.objects,{asTree:i,depth:this.depth+1}))}getObjects(){return this.objects}getDepth(){return this.depth}getCacheKey(){const t=["objectGroup"];return Array.from(this.getObjects()).forEach((e=>{t.push(e.getCacheKey())})),t.join("/")}}class Zt extends q{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.objects={},Array.from(t).forEach((t=>{const e=JSON.stringify(t);null==this.objects[e]&&(this.objects[e]=t)}))}find(t){const e=JSON.stringify(t);return this.objects[e]}}class Qt{constructor(t){this.reset(t)}add(t){const e=te(t);this.elements[e]=t}remove(t){const e=te(t),i=this.elements[e];if(i)return delete this.elements[e],i}reset(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return this.elements={},Array.from(t).forEach((t=>{this.add(t)})),t}}const te=t=>t.dataset.trixStoreKey;class ee extends q{isPerforming(){return!0===this.performing}hasPerformed(){return!0===this.performed}hasSucceeded(){return this.performed&&this.succeeded}hasFailed(){return this.performed&&!this.succeeded}getPromise(){return this.promise||(this.promise=new Promise(((t,e)=>(this.performing=!0,this.perform(((i,n)=>{this.succeeded=i,this.performing=!1,this.performed=!0,this.succeeded?t(n):e(n)})))))),this.promise}perform(t){return t(!1)}release(){var t,e;null===(t=this.promise)||void 0===t||null===(e=t.cancel)||void 0===e||e.call(t),this.promise=null,this.performing=null,this.performed=null,this.succeeded=null}}ee.proxyMethod("getPromise().then"),ee.proxyMethod("getPromise().catch");class ie extends q{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.object=t,this.options=e,this.childViews=[],this.rootView=this}getNodes(){return this.nodes||(this.nodes=this.createNodes()),this.nodes.map((t=>t.cloneNode(!0)))}invalidate(){var t;return this.nodes=null,this.childViews=[],null===(t=this.parentView)||void 0===t?void 0:t.invalidate()}invalidateViewForObject(t){var e;return null===(e=this.findViewForObject(t))||void 0===e?void 0:e.invalidate()}findOrCreateCachedChildView(t,e,i){let n=this.getCachedViewForObject(e);return n?this.recordChildView(n):(n=this.createChildView(...arguments),this.cacheViewForObject(n,e)),n}createChildView(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e instanceof $t&&(i.viewClass=t,t=ne);const n=new t(e,i);return this.recordChildView(n)}recordChildView(t){return t.parentView=this,t.rootView=this.rootView,this.childViews.push(t),t}getAllChildViews(){let t=[];return this.childViews.forEach((e=>{t.push(e),t=t.concat(e.getAllChildViews())})),t}findElement(){return this.findElementForObject(this.object)}findElementForObject(t){const e=null==t?void 0:t.id;if(e)return this.rootView.element.querySelector("[data-trix-id='".concat(e,"']"))}findViewForObject(t){for(const e of this.getAllChildViews())if(e.object===t)return e}getViewCache(){return this.rootView!==this?this.rootView.getViewCache():this.isViewCachingEnabled()?(this.viewCache||(this.viewCache={}),this.viewCache):void 0}isViewCachingEnabled(){return!1!==this.shouldCacheViews}enableViewCaching(){this.shouldCacheViews=!0}disableViewCaching(){this.shouldCacheViews=!1}getCachedViewForObject(t){var e;return null===(e=this.getViewCache())||void 0===e?void 0:e[t.getCacheKey()]}cacheViewForObject(t,e){const i=this.getViewCache();i&&(i[e.getCacheKey()]=t)}garbageCollectCachedViews(){const t=this.getViewCache();if(t){const e=this.getAllChildViews().concat(this).map((t=>t.object.getCacheKey()));for(const i in t)e.includes(i)||delete t[i]}}}class ne extends ie{constructor(){super(...arguments),this.objectGroup=this.object,this.viewClass=this.options.viewClass,delete this.options.viewClass}getChildViews(){return this.childViews.length||Array.from(this.objectGroup.getObjects()).forEach((t=>{this.findOrCreateCachedChildView(this.viewClass,t,this.options)})),this.childViews}createNodes(){const t=this.createContainerElement();return this.getChildViews().forEach((e=>{Array.from(e.getNodes()).forEach((e=>{t.appendChild(e)}))})),[t]}createContainerElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.objectGroup.getDepth();return this.getChildViews()[0].createContainerElement(t)}} +/*! @license DOMPurify 3.2.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.5/LICENSE */const{entries:re,setPrototypeOf:oe,isFrozen:se,getPrototypeOf:ae,getOwnPropertyDescriptor:le}=Object;let{freeze:ce,seal:ue,create:he}=Object,{apply:de,construct:ge}="undefined"!=typeof Reflect&&Reflect;ce||(ce=function(t){return t}),ue||(ue=function(t){return t}),de||(de=function(t,e,i){return t.apply(e,i)}),ge||(ge=function(t,e){return new t(...e)});const me=Le(Array.prototype.forEach),pe=Le(Array.prototype.lastIndexOf),fe=Le(Array.prototype.pop),be=Le(Array.prototype.push),ve=Le(Array.prototype.splice),Ae=Le(String.prototype.toLowerCase),ye=Le(String.prototype.toString),xe=Le(String.prototype.match),Ce=Le(String.prototype.replace),Ee=Le(String.prototype.indexOf),Se=Le(String.prototype.trim),Re=Le(Object.prototype.hasOwnProperty),ke=Le(RegExp.prototype.test),Te=(we=TypeError,function(){for(var t=arguments.length,e=new Array(t),i=0;i1?i-1:0),r=1;r2&&void 0!==arguments[2]?arguments[2]:Ae;oe&&oe(t,null);let n=e.length;for(;n--;){let r=e[n];if("string"==typeof r){const t=i(r);t!==r&&(se(e)||(e[n]=t),r=t)}t[r]=!0}return t}function Ne(t){for(let e=0;e/gm),Ke=ue(/\$\{[\w\W]*/gm),Ge=ue(/^data-[\-\w.\u00B7-\uFFFF]+$/),Ye=ue(/^aria-[\-\w]+$/),$e=ue(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Xe=ue(/^(?:\w+script|data):/i),Ze=ue(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Qe=ue(/^html$/i),ti=ue(/^[a-z][.\w]*(-[.\w]+)+$/i);var ei=Object.freeze({__proto__:null,ARIA_ATTR:Ye,ATTR_WHITESPACE:Ze,CUSTOM_ELEMENT:ti,DATA_ATTR:Ge,DOCTYPE_NAME:Qe,ERB_EXPR:Je,IS_ALLOWED_URI:$e,IS_SCRIPT_OR_DATA:Xe,MUSTACHE_EXPR:ze,TMPLIT_EXPR:Ke});const ii=1,ni=3,ri=7,oi=8,si=9,ai=function(){return"undefined"==typeof window?null:window};var li=function t(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ai();const i=e=>t(e);if(i.version="3.2.5",i.removed=[],!e||!e.document||e.document.nodeType!==si||!e.Element)return i.isSupported=!1,i;let{document:n}=e;const r=n,o=r.currentScript,{DocumentFragment:s,HTMLTemplateElement:a,Node:l,Element:c,NodeFilter:u,NamedNodeMap:h=e.NamedNodeMap||e.MozNamedAttrMap,HTMLFormElement:d,DOMParser:g,trustedTypes:m}=e,p=c.prototype,f=Oe(p,"cloneNode"),b=Oe(p,"remove"),v=Oe(p,"nextSibling"),A=Oe(p,"childNodes"),y=Oe(p,"parentNode");if("function"==typeof a){const t=n.createElement("template");t.content&&t.content.ownerDocument&&(n=t.content.ownerDocument)}let x,C="";const{implementation:E,createNodeIterator:S,createDocumentFragment:R,getElementsByTagName:k}=n,{importNode:T}=r;let w={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};i.isSupported="function"==typeof re&&"function"==typeof y&&E&&void 0!==E.createHTMLDocument;const{MUSTACHE_EXPR:L,ERB_EXPR:D,TMPLIT_EXPR:N,DATA_ATTR:I,ARIA_ATTR:O,IS_SCRIPT_OR_DATA:F,ATTR_WHITESPACE:P,CUSTOM_ELEMENT:M}=ei;let{IS_ALLOWED_URI:B}=ei,_=null;const j=De({},[...Fe,...Pe,...Me,..._e,...We]);let W=null;const U=De({},[...Ue,...Ve,...qe,...He]);let V=Object.seal(he(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),H=null,z=null,J=!0,K=!0,G=!1,Y=!0,X=!1,Z=!0,Q=!1,tt=!1,et=!1,it=!1,nt=!1,ot=!1,st=!0,at=!1,lt=!0,ct=!1,ut={},ht=null;const dt=De({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let gt=null;const mt=De({},["audio","video","img","source","image","track"]);let pt=null;const ft=De({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),bt="http://www.w3.org/1998/Math/MathML",vt="http://www.w3.org/2000/svg",At="http://www.w3.org/1999/xhtml";let yt=At,xt=!1,Ct=null;const Et=De({},[bt,vt,At],ye);let St=De({},["mi","mo","mn","ms","mtext"]),Rt=De({},["annotation-xml"]);const kt=De({},["title","style","font","a","script"]);let Tt=null;const wt=["application/xhtml+xml","text/html"];let Lt=null,Dt=null;const Nt=n.createElement("form"),It=function(t){return t instanceof RegExp||t instanceof Function},Ft=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!Dt||Dt!==t){if(t&&"object"==typeof t||(t={}),t=Ie(t),Tt=-1===wt.indexOf(t.PARSER_MEDIA_TYPE)?"text/html":t.PARSER_MEDIA_TYPE,Lt="application/xhtml+xml"===Tt?ye:Ae,_=Re(t,"ALLOWED_TAGS")?De({},t.ALLOWED_TAGS,Lt):j,W=Re(t,"ALLOWED_ATTR")?De({},t.ALLOWED_ATTR,Lt):U,Ct=Re(t,"ALLOWED_NAMESPACES")?De({},t.ALLOWED_NAMESPACES,ye):Et,pt=Re(t,"ADD_URI_SAFE_ATTR")?De(Ie(ft),t.ADD_URI_SAFE_ATTR,Lt):ft,gt=Re(t,"ADD_DATA_URI_TAGS")?De(Ie(mt),t.ADD_DATA_URI_TAGS,Lt):mt,ht=Re(t,"FORBID_CONTENTS")?De({},t.FORBID_CONTENTS,Lt):dt,H=Re(t,"FORBID_TAGS")?De({},t.FORBID_TAGS,Lt):{},z=Re(t,"FORBID_ATTR")?De({},t.FORBID_ATTR,Lt):{},ut=!!Re(t,"USE_PROFILES")&&t.USE_PROFILES,J=!1!==t.ALLOW_ARIA_ATTR,K=!1!==t.ALLOW_DATA_ATTR,G=t.ALLOW_UNKNOWN_PROTOCOLS||!1,Y=!1!==t.ALLOW_SELF_CLOSE_IN_ATTR,X=t.SAFE_FOR_TEMPLATES||!1,Z=!1!==t.SAFE_FOR_XML,Q=t.WHOLE_DOCUMENT||!1,it=t.RETURN_DOM||!1,nt=t.RETURN_DOM_FRAGMENT||!1,ot=t.RETURN_TRUSTED_TYPE||!1,et=t.FORCE_BODY||!1,st=!1!==t.SANITIZE_DOM,at=t.SANITIZE_NAMED_PROPS||!1,lt=!1!==t.KEEP_CONTENT,ct=t.IN_PLACE||!1,B=t.ALLOWED_URI_REGEXP||$e,yt=t.NAMESPACE||At,St=t.MATHML_TEXT_INTEGRATION_POINTS||St,Rt=t.HTML_INTEGRATION_POINTS||Rt,V=t.CUSTOM_ELEMENT_HANDLING||{},t.CUSTOM_ELEMENT_HANDLING&&It(t.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(V.tagNameCheck=t.CUSTOM_ELEMENT_HANDLING.tagNameCheck),t.CUSTOM_ELEMENT_HANDLING&&It(t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(V.attributeNameCheck=t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),t.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(V.allowCustomizedBuiltInElements=t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),X&&(K=!1),nt&&(it=!0),ut&&(_=De({},We),W=[],!0===ut.html&&(De(_,Fe),De(W,Ue)),!0===ut.svg&&(De(_,Pe),De(W,Ve),De(W,He)),!0===ut.svgFilters&&(De(_,Me),De(W,Ve),De(W,He)),!0===ut.mathMl&&(De(_,_e),De(W,qe),De(W,He))),t.ADD_TAGS&&(_===j&&(_=Ie(_)),De(_,t.ADD_TAGS,Lt)),t.ADD_ATTR&&(W===U&&(W=Ie(W)),De(W,t.ADD_ATTR,Lt)),t.ADD_URI_SAFE_ATTR&&De(pt,t.ADD_URI_SAFE_ATTR,Lt),t.FORBID_CONTENTS&&(ht===dt&&(ht=Ie(ht)),De(ht,t.FORBID_CONTENTS,Lt)),lt&&(_["#text"]=!0),Q&&De(_,["html","head","body"]),_.table&&(De(_,["tbody"]),delete H.tbody),t.TRUSTED_TYPES_POLICY){if("function"!=typeof t.TRUSTED_TYPES_POLICY.createHTML)throw Te('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof t.TRUSTED_TYPES_POLICY.createScriptURL)throw Te('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');x=t.TRUSTED_TYPES_POLICY,C=x.createHTML("")}else void 0===x&&(x=function(t,e){if("object"!=typeof t||"function"!=typeof t.createPolicy)return null;let i=null;const n="data-tt-policy-suffix";e&&e.hasAttribute(n)&&(i=e.getAttribute(n));const r="dompurify"+(i?"#"+i:"");try{return t.createPolicy(r,{createHTML:t=>t,createScriptURL:t=>t})}catch(t){return console.warn("TrustedTypes policy "+r+" could not be created."),null}}(m,o)),null!==x&&"string"==typeof C&&(C=x.createHTML(""));ce&&ce(t),Dt=t}},Pt=De({},[...Pe,...Me,...Be]),Mt=De({},[..._e,...je]),Bt=function(t){be(i.removed,{element:t});try{y(t).removeChild(t)}catch(e){b(t)}},_t=function(t,e){try{be(i.removed,{attribute:e.getAttributeNode(t),from:e})}catch(t){be(i.removed,{attribute:null,from:e})}if(e.removeAttribute(t),"is"===t)if(it||nt)try{Bt(e)}catch(t){}else try{e.setAttribute(t,"")}catch(t){}},jt=function(t){let e=null,i=null;if(et)t=""+t;else{const e=xe(t,/^[\r\n\t ]+/);i=e&&e[0]}"application/xhtml+xml"===Tt&&yt===At&&(t=''+t+"");const r=x?x.createHTML(t):t;if(yt===At)try{e=(new g).parseFromString(r,Tt)}catch(t){}if(!e||!e.documentElement){e=E.createDocument(yt,"template",null);try{e.documentElement.innerHTML=xt?C:r}catch(t){}}const o=e.body||e.documentElement;return t&&i&&o.insertBefore(n.createTextNode(i),o.childNodes[0]||null),yt===At?k.call(e,Q?"html":"body")[0]:Q?e.documentElement:o},Wt=function(t){return S.call(t.ownerDocument||t,t,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT|u.SHOW_PROCESSING_INSTRUCTION|u.SHOW_CDATA_SECTION,null)},Ut=function(t){return t instanceof d&&("string"!=typeof t.nodeName||"string"!=typeof t.textContent||"function"!=typeof t.removeChild||!(t.attributes instanceof h)||"function"!=typeof t.removeAttribute||"function"!=typeof t.setAttribute||"string"!=typeof t.namespaceURI||"function"!=typeof t.insertBefore||"function"!=typeof t.hasChildNodes)},Vt=function(t){return"function"==typeof l&&t instanceof l};function qt(t,e,n){me(t,(t=>{t.call(i,e,n,Dt)}))}const zt=function(t){let e=null;if(qt(w.beforeSanitizeElements,t,null),Ut(t))return Bt(t),!0;const n=Lt(t.nodeName);if(qt(w.uponSanitizeElement,t,{tagName:n,allowedTags:_}),t.hasChildNodes()&&!Vt(t.firstElementChild)&&ke(/<[/\w!]/g,t.innerHTML)&&ke(/<[/\w!]/g,t.textContent))return Bt(t),!0;if(t.nodeType===ri)return Bt(t),!0;if(Z&&t.nodeType===oi&&ke(/<[/\w]/g,t.data))return Bt(t),!0;if(!_[n]||H[n]){if(!H[n]&&Kt(n)){if(V.tagNameCheck instanceof RegExp&&ke(V.tagNameCheck,n))return!1;if(V.tagNameCheck instanceof Function&&V.tagNameCheck(n))return!1}if(lt&&!ht[n]){const e=y(t)||t.parentNode,i=A(t)||t.childNodes;if(i&&e)for(let n=i.length-1;n>=0;--n){const r=f(i[n],!0);r.__removalCount=(t.__removalCount||0)+1,e.insertBefore(r,v(t))}}return Bt(t),!0}return t instanceof c&&!function(t){let e=y(t);e&&e.tagName||(e={namespaceURI:yt,tagName:"template"});const i=Ae(t.tagName),n=Ae(e.tagName);return!!Ct[t.namespaceURI]&&(t.namespaceURI===vt?e.namespaceURI===At?"svg"===i:e.namespaceURI===bt?"svg"===i&&("annotation-xml"===n||St[n]):Boolean(Pt[i]):t.namespaceURI===bt?e.namespaceURI===At?"math"===i:e.namespaceURI===vt?"math"===i&&Rt[n]:Boolean(Mt[i]):t.namespaceURI===At?!(e.namespaceURI===vt&&!Rt[n])&&!(e.namespaceURI===bt&&!St[n])&&!Mt[i]&&(kt[i]||!Pt[i]):!("application/xhtml+xml"!==Tt||!Ct[t.namespaceURI]))}(t)?(Bt(t),!0):"noscript"!==n&&"noembed"!==n&&"noframes"!==n||!ke(/<\/no(script|embed|frames)/i,t.innerHTML)?(X&&t.nodeType===ni&&(e=t.textContent,me([L,D,N],(t=>{e=Ce(e,t," ")})),t.textContent!==e&&(be(i.removed,{element:t.cloneNode()}),t.textContent=e)),qt(w.afterSanitizeElements,t,null),!1):(Bt(t),!0)},Jt=function(t,e,i){if(st&&("id"===e||"name"===e)&&(i in n||i in Nt))return!1;if(K&&!z[e]&&ke(I,e));else if(J&&ke(O,e));else if(!W[e]||z[e]){if(!(Kt(t)&&(V.tagNameCheck instanceof RegExp&&ke(V.tagNameCheck,t)||V.tagNameCheck instanceof Function&&V.tagNameCheck(t))&&(V.attributeNameCheck instanceof RegExp&&ke(V.attributeNameCheck,e)||V.attributeNameCheck instanceof Function&&V.attributeNameCheck(e))||"is"===e&&V.allowCustomizedBuiltInElements&&(V.tagNameCheck instanceof RegExp&&ke(V.tagNameCheck,i)||V.tagNameCheck instanceof Function&&V.tagNameCheck(i))))return!1}else if(pt[e]);else if(ke(B,Ce(i,P,"")));else if("src"!==e&&"xlink:href"!==e&&"href"!==e||"script"===t||0!==Ee(i,"data:")||!gt[t])if(G&&!ke(F,Ce(i,P,"")));else if(i)return!1;return!0},Kt=function(t){return"annotation-xml"!==t&&xe(t,M)},Gt=function(t){qt(w.beforeSanitizeAttributes,t,null);const{attributes:e}=t;if(!e||Ut(t))return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:W,forceKeepAttr:void 0};let r=e.length;for(;r--;){const o=e[r],{name:s,namespaceURI:a,value:l}=o,c=Lt(s);let u="value"===s?l:Se(l);if(n.attrName=c,n.attrValue=u,n.keepAttr=!0,n.forceKeepAttr=void 0,qt(w.uponSanitizeAttribute,t,n),u=n.attrValue,!at||"id"!==c&&"name"!==c||(_t(s,t),u="user-content-"+u),Z&&ke(/((--!?|])>)|<\/(style|title)/i,u)){_t(s,t);continue}if(n.forceKeepAttr)continue;if(_t(s,t),!n.keepAttr)continue;if(!Y&&ke(/\/>/i,u)){_t(s,t);continue}X&&me([L,D,N],(t=>{u=Ce(u,t," ")}));const h=Lt(t.nodeName);if(Jt(h,c,u)){if(x&&"object"==typeof m&&"function"==typeof m.getAttributeType)if(a);else switch(m.getAttributeType(h,c)){case"TrustedHTML":u=x.createHTML(u);break;case"TrustedScriptURL":u=x.createScriptURL(u)}try{a?t.setAttributeNS(a,s,u):t.setAttribute(s,u),Ut(t)?Bt(t):fe(i.removed)}catch(t){}}}qt(w.afterSanitizeAttributes,t,null)},Yt=function t(e){let i=null;const n=Wt(e);for(qt(w.beforeSanitizeShadowDOM,e,null);i=n.nextNode();)qt(w.uponSanitizeShadowNode,i,null),zt(i),Gt(i),i.content instanceof s&&t(i.content);qt(w.afterSanitizeShadowDOM,e,null)};return i.sanitize=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,o=null,a=null,c=null;if(xt=!t,xt&&(t="\x3c!--\x3e"),"string"!=typeof t&&!Vt(t)){if("function"!=typeof t.toString)throw Te("toString is not a function");if("string"!=typeof(t=t.toString()))throw Te("dirty is not a string, aborting")}if(!i.isSupported)return t;if(tt||Ft(e),i.removed=[],"string"==typeof t&&(ct=!1),ct){if(t.nodeName){const e=Lt(t.nodeName);if(!_[e]||H[e])throw Te("root node is forbidden and cannot be sanitized in-place")}}else if(t instanceof l)n=jt("\x3c!----\x3e"),o=n.ownerDocument.importNode(t,!0),o.nodeType===ii&&"BODY"===o.nodeName||"HTML"===o.nodeName?n=o:n.appendChild(o);else{if(!it&&!X&&!Q&&-1===t.indexOf("<"))return x&&ot?x.createHTML(t):t;if(n=jt(t),!n)return it?null:ot?C:""}n&&et&&Bt(n.firstChild);const u=Wt(ct?t:n);for(;a=u.nextNode();)zt(a),Gt(a),a.content instanceof s&&Yt(a.content);if(ct)return t;if(it){if(nt)for(c=R.call(n.ownerDocument);n.firstChild;)c.appendChild(n.firstChild);else c=n;return(W.shadowroot||W.shadowrootmode)&&(c=T.call(r,c,!0)),c}let h=Q?n.outerHTML:n.innerHTML;return Q&&_["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&ke(Qe,n.ownerDocument.doctype.name)&&(h="\n"+h),X&&me([L,D,N],(t=>{h=Ce(h,t," ")})),x&&ot?x.createHTML(h):h},i.setConfig=function(){Ft(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),tt=!0},i.clearConfig=function(){Dt=null,tt=!1},i.isValidAttribute=function(t,e,i){Dt||Ft({});const n=Lt(t),r=Lt(e);return Jt(n,r,i)},i.addHook=function(t,e){"function"==typeof e&&be(w[t],e)},i.removeHook=function(t,e){if(void 0!==e){const i=pe(w[t],e);return-1===i?void 0:ve(w[t],i,1)[0]}return fe(w[t])},i.removeHooks=function(t){w[t]=[]},i.removeAllHooks=function(){w={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},i}();li.addHook("uponSanitizeAttribute",(function(t,e){/^data-trix-/.test(e.attrName)&&(e.forceKeepAttr=!0)}));const ci="style href src width height language class".split(" "),ui="javascript:".split(" "),hi="script iframe form noscript".split(" ");class di extends q{static setHTML(t,e,i){const n=new this(e,i).sanitize(),r=n.getHTML?n.getHTML():n.outerHTML;t.innerHTML=r}static sanitize(t,e){const i=new this(t,e);return i.sanitize(),i}constructor(t){let{allowedAttributes:e,forbiddenProtocols:i,forbiddenElements:n,purifyOptions:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.allowedAttributes=e||ci,this.forbiddenProtocols=i||ui,this.forbiddenElements=n||hi,this.purifyOptions=r||{},this.body=gi(t)}sanitize(){this.sanitizeElements(),this.normalizeListElementNesting();const t=Object.assign({},l,this.purifyOptions);return li.setConfig(t),this.body=li.sanitize(this.body),this.body}getHTML(){return this.body.innerHTML}getBody(){return this.body}sanitizeElements(){const t=R(this.body),e=[];for(;t.nextNode();){const i=t.currentNode;switch(i.nodeType){case Node.ELEMENT_NODE:this.elementIsRemovable(i)?e.push(i):this.sanitizeElement(i);break;case Node.COMMENT_NODE:e.push(i)}}return e.forEach((t=>S(t))),this.body}sanitizeElement(t){return t.hasAttribute("href")&&this.forbiddenProtocols.includes(t.protocol)&&t.removeAttribute("href"),Array.from(t.attributes).forEach((e=>{let{name:i}=e;this.allowedAttributes.includes(i)||0===i.indexOf("data-trix")||t.removeAttribute(i)})),t}normalizeListElementNesting(){return Array.from(this.body.querySelectorAll("ul,ol")).forEach((t=>{const e=t.previousElementSibling;e&&"li"===k(e)&&e.appendChild(t)})),this.body}elementIsRemovable(t){if((null==t?void 0:t.nodeType)===Node.ELEMENT_NODE)return this.elementIsForbidden(t)||this.elementIsntSerializable(t)}elementIsForbidden(t){return this.forbiddenElements.includes(k(t))}elementIsntSerializable(t){return"false"===t.getAttribute("data-trix-serialize")&&!P(t)}}const gi=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";t=t.replace(/<\/html[^>]*>[^]*$/i,"");const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t,Array.from(e.head.querySelectorAll("style")).forEach((t=>{e.body.appendChild(t)})),e.body},{css:mi}=H;class pi extends ie{constructor(){super(...arguments),this.attachment=this.object,this.attachment.uploadProgressDelegate=this,this.attachmentPiece=this.options.piece}createContentNodes(){return[]}createNodes(){let t;const e=t=T({tagName:"figure",className:this.getClassName(),data:this.getData(),editable:!1}),i=this.getHref();return i&&(t=T({tagName:"a",editable:!1,attributes:{href:i,tabindex:-1}}),e.appendChild(t)),this.attachment.hasContent()?di.setHTML(t,this.attachment.getContent()):this.createContentNodes().forEach((e=>{t.appendChild(e)})),t.appendChild(this.createCaptionElement()),this.attachment.isPending()&&(this.progressElement=T({tagName:"progress",attributes:{class:mi.attachmentProgress,value:this.attachment.getUploadProgress(),max:100},data:{trixMutable:!0,trixStoreKey:["progressElement",this.attachment.id].join("/")}}),e.appendChild(this.progressElement)),[fi("left"),e,fi("right")]}createCaptionElement(){const t=T({tagName:"figcaption",className:mi.attachmentCaption}),e=this.attachmentPiece.getCaption();if(e)t.classList.add("".concat(mi.attachmentCaption,"--edited")),t.textContent=e;else{let e,i;const n=this.getCaptionConfig();if(n.name&&(e=this.attachment.getFilename()),n.size&&(i=this.attachment.getFormattedFilesize()),e){const i=T({tagName:"span",className:mi.attachmentName,textContent:e});t.appendChild(i)}if(i){e&&t.appendChild(document.createTextNode(" "));const n=T({tagName:"span",className:mi.attachmentSize,textContent:i});t.appendChild(n)}}return t}getClassName(){const t=[mi.attachment,"".concat(mi.attachment,"--").concat(this.attachment.getType())],e=this.attachment.getExtension();return e&&t.push("".concat(mi.attachment,"--").concat(e)),t.join(" ")}getData(){const t={trixAttachment:JSON.stringify(this.attachment),trixContentType:this.attachment.getContentType(),trixId:this.attachment.id},{attributes:e}=this.attachmentPiece;return e.isEmpty()||(t.trixAttributes=JSON.stringify(e)),this.attachment.isPending()&&(t.trixSerialize=!1),t}getHref(){if(!bi(this.attachment.getContent(),"a"))return this.attachment.getHref()}getCaptionConfig(){var t;const e=this.attachment.getType(),n=kt(null===(t=i[e])||void 0===t?void 0:t.caption);return"file"===e&&(n.name=!0),n}findProgressElement(){var t;return null===(t=this.findElement())||void 0===t?void 0:t.querySelector("progress")}attachmentDidChangeUploadProgress(){const t=this.attachment.getUploadProgress(),e=this.findProgressElement();e&&(e.value=t)}}const fi=t=>T({tagName:"span",textContent:d,data:{trixCursorTarget:t,trixSerialize:!1}}),bi=function(t,e){const i=T("div");return di.setHTML(i,t||""),i.querySelector(e)};class vi extends pi{constructor(){super(...arguments),this.attachment.previewDelegate=this}createContentNodes(){return this.image=T({tagName:"img",attributes:{src:""},data:{trixMutable:!0}}),this.refresh(this.image),[this.image]}createCaptionElement(){const t=super.createCaptionElement(...arguments);return t.textContent||t.setAttribute("data-trix-placeholder",c.captionPlaceholder),t}refresh(t){var e;t||(t=null===(e=this.findElement())||void 0===e?void 0:e.querySelector("img"));if(t)return this.updateAttributesForImage(t)}updateAttributesForImage(t){const e=this.attachment.getURL(),i=this.attachment.getPreviewURL();if(t.src=i||e,i===e)t.removeAttribute("data-trix-serialized-attributes");else{const i=JSON.stringify({src:e});t.setAttribute("data-trix-serialized-attributes",i)}const n=this.attachment.getWidth(),r=this.attachment.getHeight();null!=n&&(t.width=n),null!=r&&(t.height=r);const o=["imageElement",this.attachment.id,t.src,t.width,t.height].join("/");t.dataset.trixStoreKey=o}attachmentDidChangeAttributes(){return this.refresh(this.image),this.refresh()}}class Ai extends ie{constructor(){super(...arguments),this.piece=this.object,this.attributes=this.piece.getAttributes(),this.textConfig=this.options.textConfig,this.context=this.options.context,this.piece.attachment?this.attachment=this.piece.attachment:this.string=this.piece.toString()}createNodes(){let t=this.attachment?this.createAttachmentNodes():this.createStringNodes();const e=this.createElement();if(e){const i=function(t){for(;null!==(e=t)&&void 0!==e&&e.firstElementChild;){var e;t=t.firstElementChild}return t}(e);Array.from(t).forEach((t=>{i.appendChild(t)})),t=[e]}return t}createAttachmentNodes(){const t=this.attachment.isPreviewable()?vi:pi;return this.createChildView(t,this.piece.attachment,{piece:this.piece}).getNodes()}createStringNodes(){var t;if(null!==(t=this.textConfig)&&void 0!==t&&t.plaintext)return[document.createTextNode(this.string)];{const t=[],e=this.string.split("\n");for(let i=0;i0){const e=T("br");t.push(e)}if(n.length){const e=document.createTextNode(this.preserveSpaces(n));t.push(e)}}return t}}createElement(){let t,e,i;const n={};for(e in this.attributes){i=this.attributes[e];const o=ft(e);if(o){if(o.tagName){var r;const e=T(o.tagName);r?(r.appendChild(e),r=e):t=r=e}if(o.styleProperty&&(n[o.styleProperty]=i),o.style)for(e in o.style)i=o.style[e],n[e]=i}}if(Object.keys(n).length)for(e in t||(t=T("span")),n)i=n[e],t.style[e]=i;return t}createContainerElement(){for(const t in this.attributes){const e=this.attributes[t],i=ft(t);if(i&&i.groupTagName){const n={};return n[t]=e,T(i.groupTagName,n)}}}preserveSpaces(t){return this.context.isLast&&(t=t.replace(/\ $/,g)),t=t.replace(/(\S)\ {3}(\S)/g,"$1 ".concat(g," $2")).replace(/\ {2}/g,"".concat(g," ")).replace(/\ {2}/g," ".concat(g)),(this.context.isFirst||this.context.followsWhitespace)&&(t=t.replace(/^\ /,g)),t}}class yi extends ie{constructor(){super(...arguments),this.text=this.object,this.textConfig=this.options.textConfig}createNodes(){const t=[],e=$t.groupObjects(this.getPieces()),i=e.length-1;for(let r=0;r!t.hasAttribute("blockBreak")))}}const xi=t=>/\s$/.test(null==t?void 0:t.toString()),{css:Ci}=H;class Ei extends ie{constructor(){super(...arguments),this.block=this.object,this.attributes=this.block.getAttributes()}createNodes(){const t=[document.createComment("block")];if(this.block.isEmpty())t.push(T("br"));else{var e;const i=null===(e=mt(this.block.getLastAttribute()))||void 0===e?void 0:e.text,n=this.findOrCreateCachedChildView(yi,this.block.text,{textConfig:i});t.push(...Array.from(n.getNodes()||[])),this.shouldAddExtraNewlineElement()&&t.push(T("br"))}if(this.attributes.length)return t;{let e;const{tagName:i}=n.default;this.block.isRTL()&&(e={dir:"rtl"});const r=T({tagName:i,attributes:e});return t.forEach((t=>r.appendChild(t))),[r]}}createContainerElement(t){const e={};let i;const n=this.attributes[t],{tagName:r,htmlAttributes:o=[]}=mt(n);if(0===t&&this.block.isRTL()&&Object.assign(e,{dir:"rtl"}),"attachmentGallery"===n){const t=this.block.getBlockBreakPosition();i="".concat(Ci.attachmentGallery," ").concat(Ci.attachmentGallery,"--").concat(t)}return Object.entries(this.block.htmlAttributes).forEach((t=>{let[i,n]=t;o.includes(i)&&(e[i]=n)})),T({tagName:r,className:i,attributes:e})}shouldAddExtraNewlineElement(){return/\n\n$/.test(this.block.toString())}}class Si extends ie{static render(t){const e=T("div"),i=new this(t,{element:e});return i.render(),i.sync(),e}constructor(){super(...arguments),this.element=this.options.element,this.elementStore=new Qt,this.setDocument(this.object)}setDocument(t){t.isEqualTo(this.document)||(this.document=this.object=t)}render(){if(this.childViews=[],this.shadowElement=T("div"),!this.document.isEmpty()){const t=$t.groupObjects(this.document.getBlocks(),{asTree:!0});Array.from(t).forEach((t=>{const e=this.findOrCreateCachedChildView(Ei,t);Array.from(e.getNodes()).map((t=>this.shadowElement.appendChild(t)))}))}}isSynced(){return ki(this.shadowElement,this.element)}sync(){const t=this.createDocumentFragmentForSync();for(;this.element.lastChild;)this.element.removeChild(this.element.lastChild);return this.element.appendChild(t),this.didSync()}didSync(){return this.elementStore.reset(Ri(this.element)),Rt((()=>this.garbageCollectCachedViews()))}createDocumentFragmentForSync(){const t=document.createDocumentFragment();return Array.from(this.shadowElement.childNodes).forEach((e=>{t.appendChild(e.cloneNode(!0))})),Array.from(Ri(t)).forEach((t=>{const e=this.elementStore.remove(t);e&&t.parentNode.replaceChild(e,t)})),t}}const Ri=t=>t.querySelectorAll("[data-trix-store-key]"),ki=(t,e)=>Ti(t.innerHTML)===Ti(e.innerHTML),Ti=t=>t.replace(/ /g," ");function wi(t){var e,i;function n(e,i){try{var o=t[e](i),s=o.value,a=s instanceof Li;Promise.resolve(a?s.v:s).then((function(i){if(a){var l="return"===e?"return":"next";if(!s.k||i.done)return n(l,i);i=t[l](i).value}r(o.done?"return":"normal",i)}),(function(t){n("throw",t)}))}catch(t){r("throw",t)}}function r(t,r){switch(t){case"return":e.resolve({value:r,done:!0});break;case"throw":e.reject(r);break;default:e.resolve({value:r,done:!1})}(e=e.next)?n(e.key,e.arg):i=null}this._invoke=function(t,r){return new Promise((function(o,s){var a={key:t,arg:r,resolve:o,reject:s,next:null};i?i=i.next=a:(e=i=a,n(t,r))}))},"function"!=typeof t.return&&(this.return=void 0)}function Li(t,e){this.v=t,this.k=e}function Di(t,e,i){return(e=Ni(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function Ni(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}wi.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},wi.prototype.next=function(t){return this._invoke("next",t)},wi.prototype.throw=function(t){return this._invoke("throw",t)},wi.prototype.return=function(t){return this._invoke("return",t)};function Ii(t,e){return Pi(t,Fi(t,e,"get"))}function Oi(t,e,i){return Mi(t,Fi(t,e,"set"),i),i}function Fi(t,e,i){if(!e.has(t))throw new TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function Pi(t,e){return e.get?e.get.call(t):e.value}function Mi(t,e,i){if(e.set)e.set.call(t,i);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=i}}function Bi(t,e,i){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return i}function _i(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function ji(t,e,i){_i(t,e),e.set(t,i)}class Wi extends rt{static registerType(t,e){e.type=t,this.types[t]=e}static fromJSON(t){const e=this.types[t.type];if(e)return e.fromJSON(t)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.attributes=Ht.box(e)}copyWithAttributes(t){return new this.constructor(this.getValue(),t)}copyWithAdditionalAttributes(t){return this.copyWithAttributes(this.attributes.merge(t))}copyWithoutAttribute(t){return this.copyWithAttributes(this.attributes.remove(t))}copy(){return this.copyWithAttributes(this.attributes)}getAttribute(t){return this.attributes.get(t)}getAttributesHash(){return this.attributes}getAttributes(){return this.attributes.toObject()}hasAttribute(t){return this.attributes.has(t)}hasSameStringValueAsPiece(t){return t&&this.toString()===t.toString()}hasSameAttributesAsPiece(t){return t&&(this.attributes===t.attributes||this.attributes.isEqualTo(t.attributes))}isBlockBreak(){return!1}isEqualTo(t){return super.isEqualTo(...arguments)||this.hasSameConstructorAs(t)&&this.hasSameStringValueAsPiece(t)&&this.hasSameAttributesAsPiece(t)}isEmpty(){return 0===this.length}isSerializable(){return!0}toJSON(){return{type:this.constructor.type,attributes:this.getAttributes()}}contentsForInspection(){return{type:this.constructor.type,attributes:this.attributes.inspect()}}canBeGrouped(){return this.hasAttribute("href")}canBeGroupedWith(t){return this.getAttribute("href")===t.getAttribute("href")}getLength(){return this.length}canBeConsolidatedWith(t){return!1}}Di(Wi,"types",{});class Ui extends ee{constructor(t){super(...arguments),this.url=t}perform(t){const e=new Image;e.onload=()=>(e.width=this.width=e.naturalWidth,e.height=this.height=e.naturalHeight,t(!0,e)),e.onerror=()=>t(!1),e.src=this.url}}class Vi extends rt{static attachmentForFile(t){const e=new this(this.attributesForFile(t));return e.setFile(t),e}static attributesForFile(t){return new Ht({filename:t.name,filesize:t.size,contentType:t.type})}static fromJSON(t){return new this(t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.releaseFile=this.releaseFile.bind(this),this.attributes=Ht.box(t),this.didChangeAttributes()}getAttribute(t){return this.attributes.get(t)}hasAttribute(t){return this.attributes.has(t)}getAttributes(){return this.attributes.toObject()}setAttributes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=this.attributes.merge(t);var i,n,r,o;if(!this.attributes.isEqualTo(e))return this.attributes=e,this.didChangeAttributes(),null===(i=this.previewDelegate)||void 0===i||null===(n=i.attachmentDidChangeAttributes)||void 0===n||n.call(i,this),null===(r=this.delegate)||void 0===r||null===(o=r.attachmentDidChangeAttributes)||void 0===o?void 0:o.call(r,this)}didChangeAttributes(){if(this.isPreviewable())return this.preloadURL()}isPending(){return null!=this.file&&!(this.getURL()||this.getHref())}isPreviewable(){return this.attributes.has("previewable")?this.attributes.get("previewable"):Vi.previewablePattern.test(this.getContentType())}getType(){return this.hasContent()?"content":this.isPreviewable()?"preview":"file"}getURL(){return this.attributes.get("url")}getHref(){return this.attributes.get("href")}getFilename(){return this.attributes.get("filename")||""}getFilesize(){return this.attributes.get("filesize")}getFormattedFilesize(){const t=this.attributes.get("filesize");return"number"==typeof t?h.formatter(t):""}getExtension(){var t;return null===(t=this.getFilename().match(/\.(\w+)$/))||void 0===t?void 0:t[1].toLowerCase()}getContentType(){return this.attributes.get("contentType")}hasContent(){return this.attributes.has("content")}getContent(){return this.attributes.get("content")}getWidth(){return this.attributes.get("width")}getHeight(){return this.attributes.get("height")}getFile(){return this.file}setFile(t){if(this.file=t,this.isPreviewable())return this.preloadFile()}releaseFile(){this.releasePreloadedFile(),this.file=null}getUploadProgress(){return null!=this.uploadProgress?this.uploadProgress:0}setUploadProgress(t){var e,i;if(this.uploadProgress!==t)return this.uploadProgress=t,null===(e=this.uploadProgressDelegate)||void 0===e||null===(i=e.attachmentDidChangeUploadProgress)||void 0===i?void 0:i.call(e,this)}toJSON(){return this.getAttributes()}getCacheKey(){return[super.getCacheKey(...arguments),this.attributes.getCacheKey(),this.getPreviewURL()].join("/")}getPreviewURL(){return this.previewURL||this.preloadingURL}setPreviewURL(t){var e,i,n,r;if(t!==this.getPreviewURL())return this.previewURL=t,null===(e=this.previewDelegate)||void 0===e||null===(i=e.attachmentDidChangeAttributes)||void 0===i||i.call(e,this),null===(n=this.delegate)||void 0===n||null===(r=n.attachmentDidChangePreviewURL)||void 0===r?void 0:r.call(n,this)}preloadURL(){return this.preload(this.getURL(),this.releaseFile)}preloadFile(){if(this.file)return this.fileObjectURL=URL.createObjectURL(this.file),this.preload(this.fileObjectURL)}releasePreloadedFile(){this.fileObjectURL&&(URL.revokeObjectURL(this.fileObjectURL),this.fileObjectURL=null)}preload(t,e){if(t&&t!==this.getPreviewURL()){this.preloadingURL=t;return new Ui(t).then((i=>{let{width:n,height:r}=i;return this.getWidth()&&this.getHeight()||this.setAttributes({width:n,height:r}),this.preloadingURL=null,this.setPreviewURL(t),null==e?void 0:e()})).catch((()=>(this.preloadingURL=null,null==e?void 0:e())))}}}Di(Vi,"previewablePattern",/^image(\/(gif|png|webp|jpe?g)|$)/);class zi extends Wi{static fromJSON(t){return new this(Vi.fromJSON(t.attachment),t.attributes)}constructor(t){super(...arguments),this.attachment=t,this.length=1,this.ensureAttachmentExclusivelyHasAttribute("href"),this.attachment.hasContent()||this.removeProhibitedAttributes()}ensureAttachmentExclusivelyHasAttribute(t){this.hasAttribute(t)&&(this.attachment.hasAttribute(t)||this.attachment.setAttributes(this.attributes.slice([t])),this.attributes=this.attributes.remove(t))}removeProhibitedAttributes(){const t=this.attributes.slice(zi.permittedAttributes);t.isEqualTo(this.attributes)||(this.attributes=t)}getValue(){return this.attachment}isSerializable(){return!this.attachment.isPending()}getCaption(){return this.attributes.get("caption")||""}isEqualTo(t){var e;return super.isEqualTo(t)&&this.attachment.id===(null==t||null===(e=t.attachment)||void 0===e?void 0:e.id)}toString(){return""}toJSON(){const t=super.toJSON(...arguments);return t.attachment=this.attachment,t}getCacheKey(){return[super.getCacheKey(...arguments),this.attachment.getCacheKey()].join("/")}toConsole(){return JSON.stringify(this.toString())}}Di(zi,"permittedAttributes",["caption","presentation"]),Wi.registerType("attachment",zi);class qi extends Wi{static fromJSON(t){return new this(t.string,t.attributes)}constructor(t){super(...arguments),this.string=(t=>t.replace(/\r\n?/g,"\n"))(t),this.length=this.string.length}getValue(){return this.string}toString(){return this.string.toString()}isBlockBreak(){return"\n"===this.toString()&&!0===this.getAttribute("blockBreak")}toJSON(){const t=super.toJSON(...arguments);return t.string=this.string,t}canBeConsolidatedWith(t){return t&&this.hasSameConstructorAs(t)&&this.hasSameAttributesAsPiece(t)}consolidateWith(t){return new this.constructor(this.toString()+t.toString(),this.attributes)}splitAtOffset(t){let e,i;return 0===t?(e=null,i=this):t===this.length?(e=this,i=null):(e=new this.constructor(this.string.slice(0,t),this.attributes),i=new this.constructor(this.string.slice(t),this.attributes)),[e,i]}toConsole(){let{string:t}=this;return t.length>15&&(t=t.slice(0,14)+"…"),JSON.stringify(t.toString())}}Wi.registerType("string",qi);class Hi extends rt{static box(t){return t instanceof this?t:new this(t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.objects=t.slice(0),this.length=this.objects.length}indexOf(t){return this.objects.indexOf(t)}splice(){for(var t=arguments.length,e=new Array(t),i=0;it(e,i)))}insertObjectAtIndex(t,e){return this.splice(e,0,t)}insertSplittableListAtIndex(t,e){return this.splice(e,0,...t.objects)}insertSplittableListAtPosition(t,e){const[i,n]=this.splitObjectAtPosition(e);return new this.constructor(i).insertSplittableListAtIndex(t,n)}editObjectAtIndex(t,e){return this.replaceObjectAtIndex(e(this.objects[t]),t)}replaceObjectAtIndex(t,e){return this.splice(e,1,t)}removeObjectAtIndex(t){return this.splice(t,1)}getObjectAtIndex(t){return this.objects[t]}getSplittableListInRange(t){const[e,i,n]=this.splitObjectsAtRange(t);return new this.constructor(e.slice(i,n+1))}selectSplittableList(t){const e=this.objects.filter((e=>t(e)));return new this.constructor(e)}removeObjectsInRange(t){const[e,i,n]=this.splitObjectsAtRange(t);return new this.constructor(e).splice(i,n-i+1)}transformObjectsInRange(t,e){const[i,n,r]=this.splitObjectsAtRange(t),o=i.map(((t,i)=>n<=i&&i<=r?e(t):t));return new this.constructor(o)}splitObjectsAtRange(t){let e,[i,n,r]=this.splitObjectAtPosition(Ki(t));return[i,e]=new this.constructor(i).splitObjectAtPosition(Gi(t)+r),[i,n,e-1]}getObjectAtPosition(t){const{index:e}=this.findIndexAndOffsetAtPosition(t);return this.objects[e]}splitObjectAtPosition(t){let e,i;const{index:n,offset:r}=this.findIndexAndOffsetAtPosition(t),o=this.objects.slice(0);if(null!=n)if(0===r)e=n,i=0;else{const t=this.getObjectAtIndex(n),[s,a]=t.splitAtOffset(r);o.splice(n,1,s,a),e=n+1,i=s.getLength()-r}else e=o.length,i=0;return[o,e,i]}consolidate(){const t=[];let e=this.objects[0];return this.objects.slice(1).forEach((i=>{var n,r;null!==(n=(r=e).canBeConsolidatedWith)&&void 0!==n&&n.call(r,i)?e=e.consolidateWith(i):(t.push(e),e=i)})),e&&t.push(e),new this.constructor(t)}consolidateFromIndexToIndex(t,e){const i=this.objects.slice(0).slice(t,e+1),n=new this.constructor(i).consolidate().toArray();return this.splice(t,i.length,...n)}findIndexAndOffsetAtPosition(t){let e,i=0;for(e=0;ethis.endPosition+=t.getLength()))),this.endPosition}toString(){return this.objects.join("")}toArray(){return this.objects.slice(0)}toJSON(){return this.toArray()}isEqualTo(t){return super.isEqualTo(...arguments)||Ji(this.objects,null==t?void 0:t.objects)}contentsForInspection(){return{objects:"[".concat(this.objects.map((t=>t.inspect())).join(", "),"]")}}}const Ji=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(t.length!==e.length)return!1;let i=!0;for(let n=0;nt[0],Gi=t=>t[1];class Yi extends rt{static textForAttachmentWithAttributes(t,e){return new this([new zi(t,e)])}static textForStringWithAttributes(t,e){return new this([new qi(t,e)])}static fromJSON(t){return new this(Array.from(t).map((t=>Wi.fromJSON(t))))}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments);const e=t.filter((t=>!t.isEmpty()));this.pieceList=new Hi(e)}copy(){return this.copyWithPieceList(this.pieceList)}copyWithPieceList(t){return new this.constructor(t.consolidate().toArray())}copyUsingObjectMap(t){const e=this.getPieces().map((e=>t.find(e)||e));return new this.constructor(e)}appendText(t){return this.insertTextAtPosition(t,this.getLength())}insertTextAtPosition(t,e){return this.copyWithPieceList(this.pieceList.insertSplittableListAtPosition(t.pieceList,e))}removeTextAtRange(t){return this.copyWithPieceList(this.pieceList.removeObjectsInRange(t))}replaceTextAtRange(t,e){return this.removeTextAtRange(e).insertTextAtPosition(t,e[0])}moveTextFromRangeToPosition(t,e){if(t[0]<=e&&e<=t[1])return;const i=this.getTextAtRange(t),n=i.getLength();return t[0]e.copyWithAdditionalAttributes(t))))}removeAttributeAtRange(t,e){return this.copyWithPieceList(this.pieceList.transformObjectsInRange(e,(e=>e.copyWithoutAttribute(t))))}setAttributesAtRange(t,e){return this.copyWithPieceList(this.pieceList.transformObjectsInRange(e,(e=>e.copyWithAttributes(t))))}getAttributesAtPosition(t){var e;return(null===(e=this.pieceList.getObjectAtPosition(t))||void 0===e?void 0:e.getAttributes())||{}}getCommonAttributes(){const t=Array.from(this.pieceList.toArray()).map((t=>t.getAttributes()));return Ht.fromCommonAttributesOfObjects(t).toObject()}getCommonAttributesAtRange(t){return this.getTextAtRange(t).getCommonAttributes()||{}}getExpandedRangeForAttributeAtOffset(t,e){let i,n=i=e;const r=this.getLength();for(;n>0&&this.getCommonAttributesAtRange([n-1,i])[t];)n--;for(;i!!t.attachment))}getAttachments(){return this.getAttachmentPieces().map((t=>t.attachment))}getAttachmentAndPositionById(t){let e=0;for(const n of this.pieceList.toArray()){var i;if((null===(i=n.attachment)||void 0===i?void 0:i.id)===t)return{attachment:n.attachment,position:e};e+=n.length}return{attachment:null,position:null}}getAttachmentById(t){const{attachment:e}=this.getAttachmentAndPositionById(t);return e}getRangeOfAttachment(t){const e=this.getAttachmentAndPositionById(t.id),i=e.position;if(t=e.attachment)return[i,i+1]}updateAttributesForAttachment(t,e){const i=this.getRangeOfAttachment(e);return i?this.addAttributesAtRange(t,i):this}getLength(){return this.pieceList.getEndPosition()}isEmpty(){return 0===this.getLength()}isEqualTo(t){var e;return super.isEqualTo(t)||(null==t||null===(e=t.pieceList)||void 0===e?void 0:e.isEqualTo(this.pieceList))}isBlockBreak(){return 1===this.getLength()&&this.pieceList.getObjectAtIndex(0).isBlockBreak()}eachPiece(t){return this.pieceList.eachObject(t)}getPieces(){return this.pieceList.toArray()}getPieceAtPosition(t){return this.pieceList.getObjectAtPosition(t)}contentsForInspection(){return{pieceList:this.pieceList.inspect()}}toSerializableText(){const t=this.pieceList.selectSplittableList((t=>t.isSerializable()));return this.copyWithPieceList(t)}toString(){return this.pieceList.toString()}toJSON(){return this.pieceList.toJSON()}toConsole(){return JSON.stringify(this.pieceList.toArray().map((t=>JSON.parse(t.toConsole()))))}getDirection(){return lt(this.toString())}isRTL(){return"rtl"===this.getDirection()}}class Xi extends rt{static fromJSON(t){return new this(Yi.fromJSON(t.text),t.attributes,t.htmlAttributes)}constructor(t,e,i){super(...arguments),this.text=$i(t||new Yi),this.attributes=e||[],this.htmlAttributes=i||{}}isEmpty(){return this.text.isBlockBreak()}isEqualTo(t){return!!super.isEqualTo(t)||this.text.isEqualTo(null==t?void 0:t.text)&&ot(this.attributes,null==t?void 0:t.attributes)&&Tt(this.htmlAttributes,null==t?void 0:t.htmlAttributes)}copyWithText(t){return new Xi(t,this.attributes,this.htmlAttributes)}copyWithoutText(){return this.copyWithText(null)}copyWithAttributes(t){return new Xi(this.text,t,this.htmlAttributes)}copyWithoutAttributes(){return this.copyWithAttributes(null)}copyUsingObjectMap(t){const e=t.find(this.text);return e?this.copyWithText(e):this.copyWithText(this.text.copyUsingObjectMap(t))}addAttribute(t){const e=this.attributes.concat(rn(t));return this.copyWithAttributes(e)}addHTMLAttribute(t,e){const i=Object.assign({},this.htmlAttributes,{[t]:e});return new Xi(this.text,this.attributes,i)}removeAttribute(t){const{listAttribute:e}=mt(t),i=sn(sn(this.attributes,t),e);return this.copyWithAttributes(i)}removeLastAttribute(){return this.removeAttribute(this.getLastAttribute())}getLastAttribute(){return on(this.attributes)}getAttributes(){return this.attributes.slice(0)}getAttributeLevel(){return this.attributes.length}getAttributeAtLevel(t){return this.attributes[t-1]}hasAttribute(t){return this.attributes.includes(t)}hasAttributes(){return this.getAttributeLevel()>0}getLastNestableAttribute(){return on(this.getNestableAttributes())}getNestableAttributes(){return this.attributes.filter((t=>mt(t).nestable))}getNestingLevel(){return this.getNestableAttributes().length}decreaseNestingLevel(){const t=this.getLastNestableAttribute();return t?this.removeAttribute(t):this}increaseNestingLevel(){const t=this.getLastNestableAttribute();if(t){const e=this.attributes.lastIndexOf(t),i=st(this.attributes,e+1,0,...rn(t));return this.copyWithAttributes(i)}return this}getListItemAttributes(){return this.attributes.filter((t=>mt(t).listAttribute))}isListItem(){var t;return null===(t=mt(this.getLastAttribute()))||void 0===t?void 0:t.listAttribute}isTerminalBlock(){var t;return null===(t=mt(this.getLastAttribute()))||void 0===t?void 0:t.terminal}breaksOnReturn(){var t;return null===(t=mt(this.getLastAttribute()))||void 0===t?void 0:t.breakOnReturn}findLineBreakInDirectionFromPosition(t,e){const i=this.toString();let n;switch(t){case"forward":n=i.indexOf("\n",e);break;case"backward":n=i.slice(0,e).lastIndexOf("\n")}if(-1!==n)return n}contentsForInspection(){return{text:this.text.inspect(),attributes:this.attributes}}toString(){return this.text.toString()}toJSON(){return{text:this.text,attributes:this.attributes,htmlAttributes:this.htmlAttributes}}getDirection(){return this.text.getDirection()}isRTL(){return this.text.isRTL()}getLength(){return this.text.getLength()}canBeConsolidatedWith(t){return!this.hasAttributes()&&!t.hasAttributes()&&this.getDirection()===t.getDirection()}consolidateWith(t){const e=Yi.textForStringWithAttributes("\n"),i=this.getTextWithoutBlockBreak().appendText(e);return this.copyWithText(i.appendText(t.text))}splitAtOffset(t){let e,i;return 0===t?(e=null,i=this):t===this.getLength()?(e=this,i=null):(e=this.copyWithText(this.text.getTextAtRange([0,t])),i=this.copyWithText(this.text.getTextAtRange([t,this.getLength()]))),[e,i]}getBlockBreakPosition(){return this.text.getLength()-1}getTextWithoutBlockBreak(){return en(this.text)?this.text.getTextAtRange([0,this.getBlockBreakPosition()]):this.text.copy()}canBeGrouped(t){return this.attributes[t]}canBeGroupedWith(t,e){const i=t.getAttributes(),r=i[e],o=this.attributes[e];return o===r&&!(!1===mt(o).group&&!(()=>{if(!dt){dt=[];for(const t in n){const{listAttribute:e}=n[t];null!=e&&dt.push(e)}}return dt})().includes(i[e+1]))&&(this.getDirection()===t.getDirection()||t.isEmpty())}}const $i=function(t){return t=Zi(t),tn(t)},Zi=function(t){let e=!1;const i=t.getPieces();let n=i.slice(0,i.length-1);const r=i[i.length-1];return r?(n=n.map((t=>t.isBlockBreak()?(e=!0,nn(t)):t)),e?new Yi([...n,r]):t):t},Qi=Yi.textForStringWithAttributes("\n",{blockBreak:!0}),tn=function(t){return en(t)?t:t.appendText(Qi)},en=function(t){const e=t.getLength();return 0!==e&&t.getTextAtRange([e-1,e]).isBlockBreak()},nn=t=>t.copyWithoutAttribute("blockBreak"),rn=function(t){const{listAttribute:e}=mt(t);return e?[e,t]:[t]},on=t=>t.slice(-1)[0],sn=function(t,e){const i=t.lastIndexOf(e);return-1===i?t:st(t,i,1)};class an extends rt{static fromJSON(t){return new this(Array.from(t).map((t=>Xi.fromJSON(t))))}static fromString(t,e){const i=Yi.textForStringWithAttributes(t,e);return new this([new Xi(i)])}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),0===t.length&&(t=[new Xi]),this.blockList=Hi.box(t)}isEmpty(){const t=this.getBlockAtIndex(0);return 1===this.blockList.length&&t.isEmpty()&&!t.hasAttributes()}copy(){const t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).consolidateBlocks?this.blockList.consolidate().toArray():this.blockList.toArray();return new this.constructor(t)}copyUsingObjectsFromDocument(t){const e=new Zt(t.getObjects());return this.copyUsingObjectMap(e)}copyUsingObjectMap(t){const e=this.getBlocks().map((e=>t.find(e)||e.copyUsingObjectMap(t)));return new this.constructor(e)}copyWithBaseBlockAttributes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.getBlocks().map((e=>{const i=t.concat(e.getAttributes());return e.copyWithAttributes(i)}));return new this.constructor(e)}replaceBlock(t,e){const i=this.blockList.indexOf(t);return-1===i?this:new this.constructor(this.blockList.replaceObjectAtIndex(e,i))}insertDocumentAtRange(t,e){const{blockList:i}=t;e=wt(e);let[n]=e;const{index:r,offset:o}=this.locationFromPosition(n);let s=this;const a=this.getBlockAtPosition(n);return Lt(e)&&a.isEmpty()&&!a.hasAttributes()?s=new this.constructor(s.blockList.removeObjectAtIndex(r)):a.getBlockBreakPosition()===o&&n++,s=s.removeTextAtRange(e),new this.constructor(s.blockList.insertSplittableListAtPosition(i,n))}mergeDocumentAtRange(t,e){let i,n;e=wt(e);const[r]=e,o=this.locationFromPosition(r),s=this.getBlockAtIndex(o.index).getAttributes(),a=t.getBaseBlockAttributes(),l=s.slice(-a.length);if(ot(a,l)){const e=s.slice(0,-a.length);i=t.copyWithBaseBlockAttributes(e)}else i=t.copy({consolidateBlocks:!0}).copyWithBaseBlockAttributes(s);const c=i.getBlockCount(),u=i.getBlockAtIndex(0);if(ot(s,u.getAttributes())){const t=u.getTextWithoutBlockBreak();if(n=this.insertTextAtRange(t,e),c>1){i=new this.constructor(i.getBlocks().slice(1));const e=r+t.getLength();n=n.insertDocumentAtRange(i,e)}}else n=this.insertDocumentAtRange(i,e);return n}insertTextAtRange(t,e){e=wt(e);const[i]=e,{index:n,offset:r}=this.locationFromPosition(i),o=this.removeTextAtRange(e);return new this.constructor(o.blockList.editObjectAtIndex(n,(e=>e.copyWithText(e.text.insertTextAtPosition(t,r)))))}removeTextAtRange(t){let e;t=wt(t);const[i,n]=t;if(Lt(t))return this;const[r,o]=Array.from(this.locationRangeFromRange(t)),s=r.index,a=r.offset,l=this.getBlockAtIndex(s),c=o.index,u=o.offset,h=this.getBlockAtIndex(c);if(n-i==1&&l.getBlockBreakPosition()===a&&h.getBlockBreakPosition()!==u&&"\n"===h.text.getStringAtPosition(u))e=this.blockList.editObjectAtIndex(c,(t=>t.copyWithText(t.text.removeTextAtRange([u,u+1]))));else{let t;const i=l.text.getTextAtRange([0,a]),n=h.text.getTextAtRange([u,h.getLength()]),r=i.appendText(n);t=s!==c&&0===a&&l.getAttributeLevel()>=h.getAttributeLevel()?h.copyWithText(r):l.copyWithText(r);const o=c+1-s;e=this.blockList.splice(s,o,t)}return new this.constructor(e)}moveTextFromRangeToPosition(t,e){let i;t=wt(t);const[n,r]=t;if(n<=e&&e<=r)return this;let o=this.getDocumentAtRange(t),s=this.removeTextAtRange(t);const a=nn=n.editObjectAtIndex(o,(function(){return mt(t)?i.addAttribute(t,e):r[0]===r[1]?i:i.copyWithText(i.text.addAttributeAtRange(t,e,r))})))),new this.constructor(n)}addAttribute(t,e){let{blockList:i}=this;return this.eachBlock(((n,r)=>i=i.editObjectAtIndex(r,(()=>n.addAttribute(t,e))))),new this.constructor(i)}removeAttributeAtRange(t,e){let{blockList:i}=this;return this.eachBlockAtRange(e,(function(e,n,r){mt(t)?i=i.editObjectAtIndex(r,(()=>e.removeAttribute(t))):n[0]!==n[1]&&(i=i.editObjectAtIndex(r,(()=>e.copyWithText(e.text.removeAttributeAtRange(t,n)))))})),new this.constructor(i)}updateAttributesForAttachment(t,e){const i=this.getRangeOfAttachment(e),[n]=Array.from(i),{index:r}=this.locationFromPosition(n),o=this.getTextAtIndex(r);return new this.constructor(this.blockList.editObjectAtIndex(r,(i=>i.copyWithText(o.updateAttributesForAttachment(t,e)))))}removeAttributeForAttachment(t,e){const i=this.getRangeOfAttachment(e);return this.removeAttributeAtRange(t,i)}setHTMLAttributeAtPosition(t,e,i){const n=this.getBlockAtPosition(t),r=n.addHTMLAttribute(e,i);return this.replaceBlock(n,r)}insertBlockBreakAtRange(t){let e;t=wt(t);const[i]=t,{offset:n}=this.locationFromPosition(i),r=this.removeTextAtRange(t);return 0===n&&(e=[new Xi]),new this.constructor(r.blockList.insertSplittableListAtPosition(new Hi(e),i))}applyBlockAttributeAtRange(t,e,i){const n=this.expandRangeToLineBreaksAndSplitBlocks(i);let r=n.document;i=n.range;const o=mt(t);if(o.listAttribute){r=r.removeLastListAttributeAtRange(i,{exceptAttributeName:t});const e=r.convertLineBreaksToBlockBreaksInRange(i);r=e.document,i=e.range}else r=o.exclusive?r.removeBlockAttributesAtRange(i):o.terminal?r.removeLastTerminalAttributeAtRange(i):r.consolidateBlocksAtRange(i);return r.addAttributeAtRange(t,e,i)}removeLastListAttributeAtRange(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{blockList:i}=this;return this.eachBlockAtRange(t,(function(t,n,r){const o=t.getLastAttribute();o&&mt(o).listAttribute&&o!==e.exceptAttributeName&&(i=i.editObjectAtIndex(r,(()=>t.removeAttribute(o))))})),new this.constructor(i)}removeLastTerminalAttributeAtRange(t){let{blockList:e}=this;return this.eachBlockAtRange(t,(function(t,i,n){const r=t.getLastAttribute();r&&mt(r).terminal&&(e=e.editObjectAtIndex(n,(()=>t.removeAttribute(r))))})),new this.constructor(e)}removeBlockAttributesAtRange(t){let{blockList:e}=this;return this.eachBlockAtRange(t,(function(t,i,n){t.hasAttributes()&&(e=e.editObjectAtIndex(n,(()=>t.copyWithoutAttributes())))})),new this.constructor(e)}expandRangeToLineBreaksAndSplitBlocks(t){let e;t=wt(t);let[i,n]=t;const r=this.locationFromPosition(i),o=this.locationFromPosition(n);let s=this;const a=s.getBlockAtIndex(r.index);if(r.offset=a.findLineBreakInDirectionFromPosition("backward",r.offset),null!=r.offset&&(e=s.positionFromLocation(r),s=s.insertBlockBreakAtRange([e,e+1]),o.index+=1,o.offset-=s.getBlockAtIndex(r.index).getLength(),r.index+=1),r.offset=0,0===o.offset&&o.index>r.index)o.index-=1,o.offset=s.getBlockAtIndex(o.index).getBlockBreakPosition();else{const t=s.getBlockAtIndex(o.index);"\n"===t.text.getStringAtRange([o.offset-1,o.offset])?o.offset-=1:o.offset=t.findLineBreakInDirectionFromPosition("forward",o.offset),o.offset!==t.getBlockBreakPosition()&&(e=s.positionFromLocation(o),s=s.insertBlockBreakAtRange([e,e+1]))}return i=s.positionFromLocation(r),n=s.positionFromLocation(o),{document:s,range:t=wt([i,n])}}convertLineBreaksToBlockBreaksInRange(t){t=wt(t);let[e]=t;const i=this.getStringAtRange(t).slice(0,-1);let n=this;return i.replace(/.*?\n/g,(function(t){e+=t.length,n=n.insertBlockBreakAtRange([e-1,e])})),{document:n,range:t}}consolidateBlocksAtRange(t){t=wt(t);const[e,i]=t,n=this.locationFromPosition(e).index,r=this.locationFromPosition(i).index;return new this.constructor(this.blockList.consolidateFromIndexToIndex(n,r))}getDocumentAtRange(t){t=wt(t);const e=this.blockList.getSplittableListInRange(t).toArray();return new this.constructor(e)}getStringAtRange(t){let e;const i=t=wt(t);return i[i.length-1]!==this.getLength()&&(e=-1),this.getDocumentAtRange(t).toString().slice(0,e)}getBlockAtIndex(t){return this.blockList.getObjectAtIndex(t)}getBlockAtPosition(t){const{index:e}=this.locationFromPosition(t);return this.getBlockAtIndex(e)}getTextAtIndex(t){var e;return null===(e=this.getBlockAtIndex(t))||void 0===e?void 0:e.text}getTextAtPosition(t){const{index:e}=this.locationFromPosition(t);return this.getTextAtIndex(e)}getPieceAtPosition(t){const{index:e,offset:i}=this.locationFromPosition(t);return this.getTextAtIndex(e).getPieceAtPosition(i)}getCharacterAtPosition(t){const{index:e,offset:i}=this.locationFromPosition(t);return this.getTextAtIndex(e).getStringAtRange([i,i+1])}getLength(){return this.blockList.getEndPosition()}getBlocks(){return this.blockList.toArray()}getBlockCount(){return this.blockList.length}getEditCount(){return this.editCount}eachBlock(t){return this.blockList.eachObject(t)}eachBlockAtRange(t,e){let i,n;t=wt(t);const[r,o]=t,s=this.locationFromPosition(r),a=this.locationFromPosition(o);if(s.index===a.index)return i=this.getBlockAtIndex(s.index),n=[s.offset,a.offset],e(i,n,s.index);for(let t=s.index;t<=a.index;t++)if(i=this.getBlockAtIndex(t),i){switch(t){case s.index:n=[s.offset,i.text.getLength()];break;case a.index:n=[0,a.offset];break;default:n=[0,i.text.getLength()]}e(i,n,t)}}getCommonAttributesAtRange(t){t=wt(t);const[e]=t;if(Lt(t))return this.getCommonAttributesAtPosition(e);{const e=[],i=[];return this.eachBlockAtRange(t,(function(t,n){if(n[0]!==n[1])return e.push(t.text.getCommonAttributesAtRange(n)),i.push(ln(t))})),Ht.fromCommonAttributesOfObjects(e).merge(Ht.fromCommonAttributesOfObjects(i)).toObject()}}getCommonAttributesAtPosition(t){let e,i;const{index:n,offset:r}=this.locationFromPosition(t),o=this.getBlockAtIndex(n);if(!o)return{};const s=ln(o),a=o.text.getAttributesAtPosition(r),l=o.text.getAttributesAtPosition(r-1),c=Object.keys(W).filter((t=>W[t].inheritable));for(e in l)i=l[e],(i===a[e]||c.includes(e))&&(s[e]=i);return s}getRangeOfCommonAttributeAtPosition(t,e){const{index:i,offset:n}=this.locationFromPosition(e),r=this.getTextAtIndex(i),[o,s]=Array.from(r.getExpandedRangeForAttributeAtOffset(t,n)),a=this.positionFromLocation({index:i,offset:o}),l=this.positionFromLocation({index:i,offset:s});return wt([a,l])}getBaseBlockAttributes(){let t=this.getBlockAtIndex(0).getAttributes();for(let e=1;e{const e=[];for(let r=0;r{let{text:i}=e;return t=t.concat(i.getAttachmentPieces())})),t}getAttachments(){return this.getAttachmentPieces().map((t=>t.attachment))}getRangeOfAttachment(t){let e=0;const i=this.blockList.toArray();for(let n=0;n{const r=n.getLength();n.hasAttribute(t)&&i.push([e,e+r]),e+=r})),i}findRangesForTextAttribute(t){let{withValue:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=0,n=[];const r=[];return this.getPieces().forEach((o=>{const s=o.getLength();(function(i){return e?i.getAttribute(t)===e:i.hasAttribute(t)})(o)&&(n[1]===i?n[1]=i+s:r.push(n=[i,i+s])),i+=s})),r}locationFromPosition(t){const e=this.blockList.findIndexAndOffsetAtPosition(Math.max(0,t));if(null!=e.index)return e;{const t=this.getBlocks();return{index:t.length-1,offset:t[t.length-1].getLength()}}}positionFromLocation(t){return this.blockList.findPositionAtIndexAndOffset(t.index,t.offset)}locationRangeFromPosition(t){return wt(this.locationFromPosition(t))}locationRangeFromRange(t){if(!(t=wt(t)))return;const[e,i]=Array.from(t),n=this.locationFromPosition(e),r=this.locationFromPosition(i);return wt([n,r])}rangeFromLocationRange(t){let e;t=wt(t);const i=this.positionFromLocation(t[0]);return Lt(t)||(e=this.positionFromLocation(t[1])),wt([i,e])}isEqualTo(t){return this.blockList.isEqualTo(null==t?void 0:t.blockList)}getTexts(){return this.getBlocks().map((t=>t.text))}getPieces(){const t=[];return Array.from(this.getTexts()).forEach((e=>{t.push(...Array.from(e.getPieces()||[]))})),t}getObjects(){return this.getBlocks().concat(this.getTexts()).concat(this.getPieces())}toSerializableDocument(){const t=[];return this.blockList.eachObject((e=>t.push(e.copyWithText(e.text.toSerializableText())))),new this.constructor(t)}toString(){return this.blockList.toString()}toJSON(){return this.blockList.toJSON()}toConsole(){return JSON.stringify(this.blockList.toArray().map((t=>JSON.parse(t.text.toConsole()))))}}const ln=function(t){const e={},i=t.getLastAttribute();return i&&(e[i]=!0),e},cn=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{string:t=Wt(t),attributes:e,type:"string"}},un=(t,e)=>{try{return JSON.parse(t.getAttribute("data-trix-".concat(e)))}catch(t){return{}}};class hn extends q{static parse(t,e){const i=new this(t,e);return i.parse(),i}constructor(t){let{referenceElement:e,purifyOptions:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(...arguments),this.html=t,this.referenceElement=e,this.purifyOptions=i,this.blocks=[],this.blockElements=[],this.processedElements=[]}getDocument(){return an.fromJSON(this.blocks)}parse(){try{this.createHiddenContainer(),di.setHTML(this.containerElement,this.html,{purifyOptions:this.purifyOptions});const t=R(this.containerElement,{usingFilter:pn});for(;t.nextNode();)this.processNode(t.currentNode);return this.translateBlockElementMarginsToNewlines()}finally{this.removeHiddenContainer()}}createHiddenContainer(){return this.referenceElement?(this.containerElement=this.referenceElement.cloneNode(!1),this.containerElement.removeAttribute("id"),this.containerElement.setAttribute("data-trix-internal",""),this.containerElement.style.display="none",this.referenceElement.parentNode.insertBefore(this.containerElement,this.referenceElement.nextSibling)):(this.containerElement=T({tagName:"div",style:{display:"none"}}),document.body.appendChild(this.containerElement))}removeHiddenContainer(){return S(this.containerElement)}processNode(t){switch(t.nodeType){case Node.TEXT_NODE:if(!this.isInsignificantTextNode(t))return this.appendBlockForTextNode(t),this.processTextNode(t);break;case Node.ELEMENT_NODE:return this.appendBlockForElement(t),this.processElement(t)}}appendBlockForTextNode(t){const e=t.parentNode;if(e===this.currentBlockElement&&this.isBlockElement(t.previousSibling))return this.appendStringWithAttributes("\n");if(e===this.containerElement||this.isBlockElement(e)){var i;const t=this.getBlockAttributes(e),n=this.getBlockHTMLAttributes(e);ot(t,null===(i=this.currentBlock)||void 0===i?void 0:i.attributes)||(this.currentBlock=this.appendBlockForAttributesWithElement(t,e,n),this.currentBlockElement=e)}}appendBlockForElement(t){const e=this.isBlockElement(t),i=C(this.currentBlockElement,t);if(e&&!this.isBlockElement(t.firstChild)){if(!this.isInsignificantTextNode(t.firstChild)||!this.isBlockElement(t.firstElementChild)){const e=this.getBlockAttributes(t),n=this.getBlockHTMLAttributes(t);if(t.firstChild){if(i&&ot(e,this.currentBlock.attributes))return this.appendStringWithAttributes("\n");this.currentBlock=this.appendBlockForAttributesWithElement(e,t,n),this.currentBlockElement=t}}}else if(this.currentBlockElement&&!i&&!e){const e=this.findParentBlockElement(t);if(e)return this.appendBlockForElement(e);this.currentBlock=this.appendEmptyBlock(),this.currentBlockElement=null}}findParentBlockElement(t){let{parentElement:e}=t;for(;e&&e!==this.containerElement;){if(this.isBlockElement(e)&&this.blockElements.includes(e))return e;e=e.parentElement}return null}processTextNode(t){let e=t.data;var i;dn(t.parentNode)||(e=Vt(e),vn(null===(i=t.previousSibling)||void 0===i?void 0:i.textContent)&&(e=fn(e)));return this.appendStringWithAttributes(e,this.getTextAttributes(t.parentNode))}processElement(t){let e;if(P(t)){if(e=un(t,"attachment"),Object.keys(e).length){const i=this.getTextAttributes(t);this.appendAttachmentWithAttributes(e,i),t.innerHTML=""}return this.processedElements.push(t)}switch(k(t)){case"br":return this.isExtraBR(t)||this.isBlockElement(t.nextSibling)||this.appendStringWithAttributes("\n",this.getTextAttributes(t)),this.processedElements.push(t);case"img":e={url:t.getAttribute("src"),contentType:"image"};const i=(t=>{const e=t.getAttribute("width"),i=t.getAttribute("height"),n={};return e&&(n.width=parseInt(e,10)),i&&(n.height=parseInt(i,10)),n})(t);for(const t in i){const n=i[t];e[t]=n}return this.appendAttachmentWithAttributes(e,this.getTextAttributes(t)),this.processedElements.push(t);case"tr":if(this.needsTableSeparator(t))return this.appendStringWithAttributes(j.tableRowSeparator);break;case"td":if(this.needsTableSeparator(t))return this.appendStringWithAttributes(j.tableCellSeparator)}}appendBlockForAttributesWithElement(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.blockElements.push(e);const n=function(){return{text:[],attributes:arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},htmlAttributes:arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}}}(t,i);return this.blocks.push(n),n}appendEmptyBlock(){return this.appendBlockForAttributesWithElement([],null)}appendStringWithAttributes(t,e){return this.appendPiece(cn(t,e))}appendAttachmentWithAttributes(t,e){return this.appendPiece(function(t){return{attachment:t,attributes:arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},type:"attachment"}}(t,e))}appendPiece(t){return 0===this.blocks.length&&this.appendEmptyBlock(),this.blocks[this.blocks.length-1].text.push(t)}appendStringToTextAtIndex(t,e){const{text:i}=this.blocks[e],n=i[i.length-1];if("string"!==(null==n?void 0:n.type))return i.push(cn(t));n.string+=t}prependStringToTextAtIndex(t,e){const{text:i}=this.blocks[e],n=i[0];if("string"!==(null==n?void 0:n.type))return i.unshift(cn(t));n.string=t+n.string}getTextAttributes(t){let e;const i={};for(const n in W){const r=W[n];if(r.tagName&&y(t,{matchingSelector:r.tagName,untilNode:this.containerElement}))i[n]=!0;else if(r.parser){if(e=r.parser(t),e){let o=!1;for(const i of this.findBlockElementAncestors(t))if(r.parser(i)===e){o=!0;break}o||(i[n]=e)}}else r.styleProperty&&(e=t.style[r.styleProperty],e&&(i[n]=e))}if(P(t)){const n=un(t,"attributes");for(const t in n)e=n[t],i[t]=e}return i}getBlockAttributes(t){const e=[];for(;t&&t!==this.containerElement;){for(const r in n){const o=n[r];var i;!1!==o.parse&&k(t)===o.tagName&&(null!==(i=o.test)&&void 0!==i&&i.call(o,t)||!o.test)&&(e.push(r),o.listAttribute&&e.push(o.listAttribute))}t=t.parentNode}return e.reverse()}getBlockHTMLAttributes(t){const e={},i=Object.values(n).find((e=>e.tagName===k(t)));return((null==i?void 0:i.htmlAttributes)||[]).forEach((i=>{t.hasAttribute(i)&&(e[i]=t.getAttribute(i))})),e}findBlockElementAncestors(t){const e=[];for(;t&&t!==this.containerElement;){const i=k(t);L().includes(i)&&e.push(t),t=t.parentNode}return e}isBlockElement(t){if((null==t?void 0:t.nodeType)===Node.ELEMENT_NODE&&!P(t)&&!y(t,{matchingSelector:"td",untilNode:this.containerElement}))return L().includes(k(t))||"block"===window.getComputedStyle(t).display}isInsignificantTextNode(t){if((null==t?void 0:t.nodeType)!==Node.TEXT_NODE)return;if(!bn(t.data))return;const{parentNode:e,previousSibling:i,nextSibling:n}=t;return gn(e.previousSibling)&&!this.isBlockElement(e.previousSibling)||dn(e)?void 0:!i||this.isBlockElement(i)||!n||this.isBlockElement(n)}isExtraBR(t){return"br"===k(t)&&this.isBlockElement(t.parentNode)&&t.parentNode.lastChild===t}needsTableSeparator(t){if(j.removeBlankTableCells){var e;const i=null===(e=t.previousSibling)||void 0===e?void 0:e.textContent;return i&&/\S/.test(i)}return t.previousSibling}translateBlockElementMarginsToNewlines(){const t=this.getMarginOfDefaultBlockElement();for(let e=0;e2*t.top&&this.prependStringToTextAtIndex("\n",e),i.bottom>2*t.bottom&&this.appendStringToTextAtIndex("\n",e))}}getMarginOfBlockElementAtIndex(t){const e=this.blockElements[t];if(e&&e.textContent&&!L().includes(k(e))&&!this.processedElements.includes(e))return mn(e)}getMarginOfDefaultBlockElement(){const t=T(n.default.tagName);return this.containerElement.appendChild(t),mn(t)}}const dn=function(t){const{whiteSpace:e}=window.getComputedStyle(t);return["pre","pre-wrap","pre-line"].includes(e)},gn=t=>t&&!vn(t.textContent),mn=function(t){const e=window.getComputedStyle(t);if("block"===e.display)return{top:parseInt(e.marginTop),bottom:parseInt(e.marginBottom)}},pn=function(t){return"style"===k(t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},fn=t=>t.replace(new RegExp("^".concat(Ut.source,"+")),""),bn=t=>new RegExp("^".concat(Ut.source,"*$")).test(t),vn=t=>/\s$/.test(t),An=["contenteditable","data-trix-id","data-trix-store-key","data-trix-mutable","data-trix-placeholder","tabindex"],yn="data-trix-serialized-attributes",xn="[".concat(yn,"]"),Cn=new RegExp("\x3c!--block--\x3e","g"),En={"application/json":function(t){let e;if(t instanceof an)e=t;else{if(!(t instanceof HTMLElement))throw new Error("unserializable object");e=hn.parse(t.innerHTML).getDocument()}return e.toSerializableDocument().toJSONString()},"text/html":function(t){let e;if(t instanceof an)e=Si.render(t);else{if(!(t instanceof HTMLElement))throw new Error("unserializable object");e=t.cloneNode(!0)}return Array.from(e.querySelectorAll("[data-trix-serialize=false]")).forEach((t=>{S(t)})),An.forEach((t=>{Array.from(e.querySelectorAll("[".concat(t,"]"))).forEach((e=>{e.removeAttribute(t)}))})),Array.from(e.querySelectorAll(xn)).forEach((t=>{try{const e=JSON.parse(t.getAttribute(yn));t.removeAttribute(yn);for(const i in e){const n=e[i];t.setAttribute(i,n)}}catch(t){}})),e.innerHTML.replace(Cn,"")}};var Sn=Object.freeze({__proto__:null});class Rn extends q{constructor(t,e){super(...arguments),this.attachmentManager=t,this.attachment=e,this.id=this.attachment.id,this.file=this.attachment.file}remove(){return this.attachmentManager.requestRemovalOfAttachment(this.attachment)}}Rn.proxyMethod("attachment.getAttribute"),Rn.proxyMethod("attachment.hasAttribute"),Rn.proxyMethod("attachment.setAttribute"),Rn.proxyMethod("attachment.getAttributes"),Rn.proxyMethod("attachment.setAttributes"),Rn.proxyMethod("attachment.isPending"),Rn.proxyMethod("attachment.isPreviewable"),Rn.proxyMethod("attachment.getURL"),Rn.proxyMethod("attachment.getHref"),Rn.proxyMethod("attachment.getFilename"),Rn.proxyMethod("attachment.getFilesize"),Rn.proxyMethod("attachment.getFormattedFilesize"),Rn.proxyMethod("attachment.getExtension"),Rn.proxyMethod("attachment.getContentType"),Rn.proxyMethod("attachment.getFile"),Rn.proxyMethod("attachment.setFile"),Rn.proxyMethod("attachment.releaseFile"),Rn.proxyMethod("attachment.getUploadProgress"),Rn.proxyMethod("attachment.setUploadProgress");class kn extends q{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];super(...arguments),this.managedAttachments={},Array.from(t).forEach((t=>{this.manageAttachment(t)}))}getAttachments(){const t=[];for(const e in this.managedAttachments){const i=this.managedAttachments[e];t.push(i)}return t}manageAttachment(t){return this.managedAttachments[t.id]||(this.managedAttachments[t.id]=new Rn(this,t)),this.managedAttachments[t.id]}attachmentIsManaged(t){return t.id in this.managedAttachments}requestRemovalOfAttachment(t){var e,i;if(this.attachmentIsManaged(t))return null===(e=this.delegate)||void 0===e||null===(i=e.attachmentManagerDidRequestRemovalOfAttachment)||void 0===i?void 0:i.call(e,t)}unmanageAttachment(t){const e=this.managedAttachments[t.id];return delete this.managedAttachments[t.id],e}}class Tn{constructor(t){this.composition=t,this.document=this.composition.document;const e=this.composition.getSelectedRange();this.startPosition=e[0],this.endPosition=e[1],this.startLocation=this.document.locationFromPosition(this.startPosition),this.endLocation=this.document.locationFromPosition(this.endPosition),this.block=this.document.getBlockAtIndex(this.endLocation.index),this.breaksOnReturn=this.block.breaksOnReturn(),this.previousCharacter=this.block.text.getStringAtPosition(this.endLocation.offset-1),this.nextCharacter=this.block.text.getStringAtPosition(this.endLocation.offset)}shouldInsertBlockBreak(){return this.block.hasAttributes()&&this.block.isListItem()&&!this.block.isEmpty()?0!==this.startLocation.offset:this.breaksOnReturn&&"\n"!==this.nextCharacter}shouldBreakFormattedBlock(){return this.block.hasAttributes()&&!this.block.isListItem()&&(this.breaksOnReturn&&"\n"===this.nextCharacter||"\n"===this.previousCharacter)}shouldDecreaseListLevel(){return this.block.hasAttributes()&&this.block.isListItem()&&this.block.isEmpty()}shouldPrependListItem(){return this.block.isListItem()&&0===this.startLocation.offset&&!this.block.isEmpty()}shouldRemoveLastBlockAttribute(){return this.block.hasAttributes()&&!this.block.isListItem()&&this.block.isEmpty()}}class wn extends q{constructor(){super(...arguments),this.document=new an,this.attachments=[],this.currentAttributes={},this.revision=0}setDocument(t){var e,i;if(!t.isEqualTo(this.document))return this.document=t,this.refreshAttachments(),this.revision++,null===(e=this.delegate)||void 0===e||null===(i=e.compositionDidChangeDocument)||void 0===i?void 0:i.call(e,t)}getSnapshot(){return{document:this.document,selectedRange:this.getSelectedRange()}}loadSnapshot(t){var e,i,n,r;let{document:o,selectedRange:s}=t;return null===(e=this.delegate)||void 0===e||null===(i=e.compositionWillLoadSnapshot)||void 0===i||i.call(e),this.setDocument(null!=o?o:new an),this.setSelection(null!=s?s:[0,0]),null===(n=this.delegate)||void 0===n||null===(r=n.compositionDidLoadSnapshot)||void 0===r?void 0:r.call(n)}insertText(t){let{updatePosition:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{updatePosition:!0};const i=this.getSelectedRange();this.setDocument(this.document.insertTextAtRange(t,i));const n=i[0],r=n+t.getLength();return e&&this.setSelection(r),this.notifyDelegateOfInsertionAtRange([n,r])}insertBlock(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Xi;const e=new an([t]);return this.insertDocument(e)}insertDocument(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new an;const e=this.getSelectedRange();this.setDocument(this.document.insertDocumentAtRange(t,e));const i=e[0],n=i+t.getLength();return this.setSelection(n),this.notifyDelegateOfInsertionAtRange([i,n])}insertString(t,e){const i=this.getCurrentTextAttributes(),n=Yi.textForStringWithAttributes(t,i);return this.insertText(n,e)}insertBlockBreak(){const t=this.getSelectedRange();this.setDocument(this.document.insertBlockBreakAtRange(t));const e=t[0],i=e+1;return this.setSelection(i),this.notifyDelegateOfInsertionAtRange([e,i])}insertLineBreak(){const t=new Tn(this);if(t.shouldDecreaseListLevel())return this.decreaseListLevel(),this.setSelection(t.startPosition);if(t.shouldPrependListItem()){const e=new an([t.block.copyWithoutText()]);return this.insertDocument(e)}return t.shouldInsertBlockBreak()?this.insertBlockBreak():t.shouldRemoveLastBlockAttribute()?this.removeLastBlockAttribute():t.shouldBreakFormattedBlock()?this.breakFormattedBlock(t):this.insertString("\n")}insertHTML(t){const e=hn.parse(t,{purifyOptions:{SAFE_FOR_XML:!0}}).getDocument(),i=this.getSelectedRange();this.setDocument(this.document.mergeDocumentAtRange(e,i));const n=i[0],r=n+e.getLength()-1;return this.setSelection(r),this.notifyDelegateOfInsertionAtRange([n,r])}replaceHTML(t){const e=hn.parse(t).getDocument().copyUsingObjectsFromDocument(this.document),i=this.getLocationRange({strict:!1}),n=this.document.rangeFromLocationRange(i);return this.setDocument(e),this.setSelection(n)}insertFile(t){return this.insertFiles([t])}insertFiles(t){const e=[];return Array.from(t).forEach((t=>{var i;if(null!==(i=this.delegate)&&void 0!==i&&i.compositionShouldAcceptFile(t)){const i=Vi.attachmentForFile(t);e.push(i)}})),this.insertAttachments(e)}insertAttachment(t){return this.insertAttachments([t])}insertAttachments(t){let e=new Yi;return Array.from(t).forEach((t=>{var n;const r=t.getType(),o=null===(n=i[r])||void 0===n?void 0:n.presentation,s=this.getCurrentTextAttributes();o&&(s.presentation=o);const a=Yi.textForAttachmentWithAttributes(t,s);e=e.appendText(a)})),this.insertText(e)}shouldManageDeletingInDirection(t){const e=this.getLocationRange();if(Lt(e)){if("backward"===t&&0===e[0].offset)return!0;if(this.shouldManageMovingCursorInDirection(t))return!0}else if(e[0].index!==e[1].index)return!0;return!1}deleteInDirection(t){let e,i,n,{length:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=this.getLocationRange();let s=this.getSelectedRange();const a=Lt(s);if(a?i="backward"===t&&0===o[0].offset:n=o[0].index!==o[1].index,i&&this.canDecreaseBlockAttributeLevel()){const t=this.getBlock();if(t.isListItem()?this.decreaseListLevel():this.decreaseBlockAttributeLevel(),this.setSelection(s[0]),t.isEmpty())return!1}return a&&(s=this.getExpandedRangeInDirection(t,{length:r}),"backward"===t&&(e=this.getAttachmentAtRange(s))),e?(this.editAttachment(e),!1):(this.setDocument(this.document.removeTextAtRange(s)),this.setSelection(s[0]),!i&&!n&&void 0)}moveTextFromRange(t){const[e]=Array.from(this.getSelectedRange());return this.setDocument(this.document.moveTextFromRangeToPosition(t,e)),this.setSelection(e)}removeAttachment(t){const e=this.document.getRangeOfAttachment(t);if(e)return this.stopEditingAttachment(),this.setDocument(this.document.removeTextAtRange(e)),this.setSelection(e[0])}removeLastBlockAttribute(){const[t,e]=Array.from(this.getSelectedRange()),i=this.document.getBlockAtPosition(e);return this.removeCurrentAttribute(i.getLastAttribute()),this.setSelection(t)}insertPlaceholder(){return this.placeholderPosition=this.getPosition(),this.insertString(" ")}selectPlaceholder(){if(null!=this.placeholderPosition)return this.setSelectedRange([this.placeholderPosition,this.placeholderPosition+1]),this.getSelectedRange()}forgetPlaceholder(){this.placeholderPosition=null}hasCurrentAttribute(t){const e=this.currentAttributes[t];return null!=e&&!1!==e}toggleCurrentAttribute(t){const e=!this.currentAttributes[t];return e?this.setCurrentAttribute(t,e):this.removeCurrentAttribute(t)}canSetCurrentAttribute(t){return mt(t)?this.canSetCurrentBlockAttribute(t):this.canSetCurrentTextAttribute(t)}canSetCurrentTextAttribute(t){const e=this.getSelectedDocument();if(e){for(const t of Array.from(e.getAttachments()))if(!t.hasContent())return!1;return!0}}canSetCurrentBlockAttribute(t){const e=this.getBlock();if(e)return!e.isTerminalBlock()}setCurrentAttribute(t,e){return mt(t)?this.setBlockAttribute(t,e):(this.setTextAttribute(t,e),this.currentAttributes[t]=e,this.notifyDelegateOfCurrentAttributesChange())}setHTMLAtributeAtPosition(t,e,i){var n;const r=this.document.getBlockAtPosition(t),o=null===(n=mt(r.getLastAttribute()))||void 0===n?void 0:n.htmlAttributes;if(r&&null!=o&&o.includes(e)){const n=this.document.setHTMLAttributeAtPosition(t,e,i);this.setDocument(n)}}setTextAttribute(t,e){const i=this.getSelectedRange();if(!i)return;const[n,r]=Array.from(i);if(n!==r)return this.setDocument(this.document.addAttributeAtRange(t,e,i));if("href"===t){const t=Yi.textForStringWithAttributes(e,{href:e});return this.insertText(t)}}setBlockAttribute(t,e){const i=this.getSelectedRange();if(this.canSetCurrentAttribute(t))return this.setDocument(this.document.applyBlockAttributeAtRange(t,e,i)),this.setSelection(i)}removeCurrentAttribute(t){return mt(t)?(this.removeBlockAttribute(t),this.updateCurrentAttributes()):(this.removeTextAttribute(t),delete this.currentAttributes[t],this.notifyDelegateOfCurrentAttributesChange())}removeTextAttribute(t){const e=this.getSelectedRange();if(e)return this.setDocument(this.document.removeAttributeAtRange(t,e))}removeBlockAttribute(t){const e=this.getSelectedRange();if(e)return this.setDocument(this.document.removeAttributeAtRange(t,e))}canDecreaseNestingLevel(){var t;return(null===(t=this.getBlock())||void 0===t?void 0:t.getNestingLevel())>0}canIncreaseNestingLevel(){var t;const e=this.getBlock();if(e){if(null===(t=mt(e.getLastNestableAttribute()))||void 0===t||!t.listAttribute)return e.getNestingLevel()>0;{const t=this.getPreviousBlock();if(t)return function(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return ot((arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).slice(0,t.length),t)}(t.getListItemAttributes(),e.getListItemAttributes())}}}decreaseNestingLevel(){const t=this.getBlock();if(t)return this.setDocument(this.document.replaceBlock(t,t.decreaseNestingLevel()))}increaseNestingLevel(){const t=this.getBlock();if(t)return this.setDocument(this.document.replaceBlock(t,t.increaseNestingLevel()))}canDecreaseBlockAttributeLevel(){var t;return(null===(t=this.getBlock())||void 0===t?void 0:t.getAttributeLevel())>0}decreaseBlockAttributeLevel(){var t;const e=null===(t=this.getBlock())||void 0===t?void 0:t.getLastAttribute();if(e)return this.removeCurrentAttribute(e)}decreaseListLevel(){let[t]=Array.from(this.getSelectedRange());const{index:e}=this.document.locationFromPosition(t);let i=e;const n=this.getBlock().getAttributeLevel();let r=this.document.getBlockAtIndex(i+1);for(;r&&r.isListItem()&&!(r.getAttributeLevel()<=n);)i++,r=this.document.getBlockAtIndex(i+1);t=this.document.positionFromLocation({index:e,offset:0});const o=this.document.positionFromLocation({index:i,offset:0});return this.setDocument(this.document.removeLastListAttributeAtRange([t,o]))}updateCurrentAttributes(){const t=this.getSelectedRange({ignoreLock:!0});if(t){const e=this.document.getCommonAttributesAtRange(t);if(Array.from(gt()).forEach((t=>{e[t]||this.canSetCurrentAttribute(t)||(e[t]=!1)})),!Tt(e,this.currentAttributes))return this.currentAttributes=e,this.notifyDelegateOfCurrentAttributesChange()}}getCurrentAttributes(){return m.call({},this.currentAttributes)}getCurrentTextAttributes(){const t={};for(const e in this.currentAttributes){const i=this.currentAttributes[e];!1!==i&&ft(e)&&(t[e]=i)}return t}freezeSelection(){return this.setCurrentAttribute("frozen",!0)}thawSelection(){return this.removeCurrentAttribute("frozen")}hasFrozenSelection(){return this.hasCurrentAttribute("frozen")}setSelection(t){var e;const i=this.document.locationRangeFromRange(t);return null===(e=this.delegate)||void 0===e?void 0:e.compositionDidRequestChangingSelectionToLocationRange(i)}getSelectedRange(){const t=this.getLocationRange();if(t)return this.document.rangeFromLocationRange(t)}setSelectedRange(t){const e=this.document.locationRangeFromRange(t);return this.getSelectionManager().setLocationRange(e)}getPosition(){const t=this.getLocationRange();if(t)return this.document.positionFromLocation(t[0])}getLocationRange(t){return this.targetLocationRange?this.targetLocationRange:this.getSelectionManager().getLocationRange(t)||wt({index:0,offset:0})}withTargetLocationRange(t,e){let i;this.targetLocationRange=t;try{i=e()}finally{this.targetLocationRange=null}return i}withTargetRange(t,e){const i=this.document.locationRangeFromRange(t);return this.withTargetLocationRange(i,e)}withTargetDOMRange(t,e){const i=this.createLocationRangeFromDOMRange(t,{strict:!1});return this.withTargetLocationRange(i,e)}getExpandedRangeInDirection(t){let{length:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[i,n]=Array.from(this.getSelectedRange());return"backward"===t?e?i-=e:i=this.translateUTF16PositionFromOffset(i,-1):e?n+=e:n=this.translateUTF16PositionFromOffset(n,1),wt([i,n])}shouldManageMovingCursorInDirection(t){if(this.editingAttachment)return!0;const e=this.getExpandedRangeInDirection(t);return null!=this.getAttachmentAtRange(e)}moveCursorInDirection(t){let e,i;if(this.editingAttachment)i=this.document.getRangeOfAttachment(this.editingAttachment);else{const n=this.getSelectedRange();i=this.getExpandedRangeInDirection(t),e=!Dt(n,i)}if("backward"===t?this.setSelectedRange(i[0]):this.setSelectedRange(i[1]),e){const t=this.getAttachmentAtRange(i);if(t)return this.editAttachment(t)}}expandSelectionInDirection(t){let{length:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getExpandedRangeInDirection(t,{length:e});return this.setSelectedRange(i)}expandSelectionForEditing(){if(this.hasCurrentAttribute("href"))return this.expandSelectionAroundCommonAttribute("href")}expandSelectionAroundCommonAttribute(t){const e=this.getPosition(),i=this.document.getRangeOfCommonAttributeAtPosition(t,e);return this.setSelectedRange(i)}selectionContainsAttachments(){var t;return(null===(t=this.getSelectedAttachments())||void 0===t?void 0:t.length)>0}selectionIsInCursorTarget(){return this.editingAttachment||this.positionIsCursorTarget(this.getPosition())}positionIsCursorTarget(t){const e=this.document.locationFromPosition(t);if(e)return this.locationIsCursorTarget(e)}positionIsBlockBreak(t){var e;return null===(e=this.document.getPieceAtPosition(t))||void 0===e?void 0:e.isBlockBreak()}getSelectedDocument(){const t=this.getSelectedRange();if(t)return this.document.getDocumentAtRange(t)}getSelectedAttachments(){var t;return null===(t=this.getSelectedDocument())||void 0===t?void 0:t.getAttachments()}getAttachments(){return this.attachments.slice(0)}refreshAttachments(){const t=this.document.getAttachments(),{added:e,removed:i}=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const i=[],n=[],r=new Set;t.forEach((t=>{r.add(t)}));const o=new Set;return e.forEach((t=>{o.add(t),r.has(t)||i.push(t)})),t.forEach((t=>{o.has(t)||n.push(t)})),{added:i,removed:n}}(this.attachments,t);return this.attachments=t,Array.from(i).forEach((t=>{var e,i;t.delegate=null,null===(e=this.delegate)||void 0===e||null===(i=e.compositionDidRemoveAttachment)||void 0===i||i.call(e,t)})),(()=>{const t=[];return Array.from(e).forEach((e=>{var i,n;e.delegate=this,t.push(null===(i=this.delegate)||void 0===i||null===(n=i.compositionDidAddAttachment)||void 0===n?void 0:n.call(i,e))})),t})()}attachmentDidChangeAttributes(t){var e,i;return this.revision++,null===(e=this.delegate)||void 0===e||null===(i=e.compositionDidEditAttachment)||void 0===i?void 0:i.call(e,t)}attachmentDidChangePreviewURL(t){var e,i;return this.revision++,null===(e=this.delegate)||void 0===e||null===(i=e.compositionDidChangeAttachmentPreviewURL)||void 0===i?void 0:i.call(e,t)}editAttachment(t,e){var i,n;if(t!==this.editingAttachment)return this.stopEditingAttachment(),this.editingAttachment=t,null===(i=this.delegate)||void 0===i||null===(n=i.compositionDidStartEditingAttachment)||void 0===n?void 0:n.call(i,this.editingAttachment,e)}stopEditingAttachment(){var t,e;this.editingAttachment&&(null===(t=this.delegate)||void 0===t||null===(e=t.compositionDidStopEditingAttachment)||void 0===e||e.call(t,this.editingAttachment),this.editingAttachment=null)}updateAttributesForAttachment(t,e){return this.setDocument(this.document.updateAttributesForAttachment(t,e))}removeAttributeForAttachment(t,e){return this.setDocument(this.document.removeAttributeForAttachment(t,e))}breakFormattedBlock(t){let{document:e}=t;const{block:i}=t;let n=t.startPosition,r=[n-1,n];i.getBlockBreakPosition()===t.startLocation.offset?(i.breaksOnReturn()&&"\n"===t.nextCharacter?n+=1:e=e.removeTextAtRange(r),r=[n,n]):"\n"===t.nextCharacter?"\n"===t.previousCharacter?r=[n-1,n+1]:(r=[n,n+1],n+=1):t.startLocation.offset-1!=0&&(n+=1);const o=new an([i.removeLastAttribute().copyWithoutText()]);return this.setDocument(e.insertDocumentAtRange(o,r)),this.setSelection(n)}getPreviousBlock(){const t=this.getLocationRange();if(t){const{index:e}=t[0];if(e>0)return this.document.getBlockAtIndex(e-1)}}getBlock(){const t=this.getLocationRange();if(t)return this.document.getBlockAtIndex(t[0].index)}getAttachmentAtRange(t){const e=this.document.getDocumentAtRange(t);if(e.toString()==="".concat("","\n"))return e.getAttachments()[0]}notifyDelegateOfCurrentAttributesChange(){var t,e;return null===(t=this.delegate)||void 0===t||null===(e=t.compositionDidChangeCurrentAttributes)||void 0===e?void 0:e.call(t,this.currentAttributes)}notifyDelegateOfInsertionAtRange(t){var e,i;return null===(e=this.delegate)||void 0===e||null===(i=e.compositionDidPerformInsertionAtRange)||void 0===i?void 0:i.call(e,t)}translateUTF16PositionFromOffset(t,e){const i=this.document.toUTF16String(),n=i.offsetFromUCS2Offset(t);return i.offsetToUCS2Offset(n+e)}}wn.proxyMethod("getSelectionManager().getPointRange"),wn.proxyMethod("getSelectionManager().setLocationRangeFromPointRange"),wn.proxyMethod("getSelectionManager().createLocationRangeFromDOMRange"),wn.proxyMethod("getSelectionManager().locationIsCursorTarget"),wn.proxyMethod("getSelectionManager().selectionIsExpanded"),wn.proxyMethod("delegate?.getSelectionManager");class Ln extends q{constructor(t){super(...arguments),this.composition=t,this.undoEntries=[],this.redoEntries=[]}recordUndoEntry(t){let{context:e,consolidatable:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=this.undoEntries.slice(-1)[0];if(!i||!Dn(n,t,e)){const i=this.createEntry({description:t,context:e});this.undoEntries.push(i),this.redoEntries=[]}}undo(){const t=this.undoEntries.pop();if(t){const e=this.createEntry(t);return this.redoEntries.push(e),this.composition.loadSnapshot(t.snapshot)}}redo(){const t=this.redoEntries.pop();if(t){const e=this.createEntry(t);return this.undoEntries.push(e),this.composition.loadSnapshot(t.snapshot)}}canUndo(){return this.undoEntries.length>0}canRedo(){return this.redoEntries.length>0}createEntry(){let{description:t,context:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{description:null==t?void 0:t.toString(),context:JSON.stringify(e),snapshot:this.composition.getSnapshot()}}}const Dn=(t,e,i)=>(null==t?void 0:t.description)===(null==e?void 0:e.toString())&&(null==t?void 0:t.context)===JSON.stringify(i),Nn="attachmentGallery";class In{constructor(t){this.document=t.document,this.selectedRange=t.selectedRange}perform(){return this.removeBlockAttribute(),this.applyBlockAttribute()}getSnapshot(){return{document:this.document,selectedRange:this.selectedRange}}removeBlockAttribute(){return this.findRangesOfBlocks().map((t=>this.document=this.document.removeAttributeAtRange(Nn,t)))}applyBlockAttribute(){let t=0;this.findRangesOfPieces().forEach((e=>{e[1]-e[0]>1&&(e[0]+=t,e[1]+=t,"\n"!==this.document.getCharacterAtPosition(e[1])&&(this.document=this.document.insertBlockBreakAtRange(e[1]),e[1]0&&void 0!==arguments[0]?arguments[0]:"";const e=hn.parse(t,{referenceElement:this.element}).getDocument();return this.loadDocument(e)}loadJSON(t){let{document:e,selectedRange:i}=t;return e=an.fromJSON(e),this.loadSnapshot({document:e,selectedRange:i})}loadSnapshot(t){return this.undoManager=new Ln(this.composition),this.composition.loadSnapshot(t)}getDocument(){return this.composition.document}getSelectedDocument(){return this.composition.getSelectedDocument()}getSnapshot(){return this.composition.getSnapshot()}toJSON(){return this.getSnapshot()}deleteInDirection(t){return this.composition.deleteInDirection(t)}insertAttachment(t){return this.composition.insertAttachment(t)}insertAttachments(t){return this.composition.insertAttachments(t)}insertDocument(t){return this.composition.insertDocument(t)}insertFile(t){return this.composition.insertFile(t)}insertFiles(t){return this.composition.insertFiles(t)}insertHTML(t){return this.composition.insertHTML(t)}insertString(t){return this.composition.insertString(t)}insertText(t){return this.composition.insertText(t)}insertLineBreak(){return this.composition.insertLineBreak()}getSelectedRange(){return this.composition.getSelectedRange()}getPosition(){return this.composition.getPosition()}getClientRectAtPosition(t){const e=this.getDocument().locationRangeFromRange([t,t+1]);return this.selectionManager.getClientRectAtLocationRange(e)}expandSelectionInDirection(t){return this.composition.expandSelectionInDirection(t)}moveCursorInDirection(t){return this.composition.moveCursorInDirection(t)}setSelectedRange(t){return this.composition.setSelectedRange(t)}activateAttribute(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.composition.setCurrentAttribute(t,e)}attributeIsActive(t){return this.composition.hasCurrentAttribute(t)}canActivateAttribute(t){return this.composition.canSetCurrentAttribute(t)}deactivateAttribute(t){return this.composition.removeCurrentAttribute(t)}setHTMLAtributeAtPosition(t,e,i){this.composition.setHTMLAtributeAtPosition(t,e,i)}canDecreaseNestingLevel(){return this.composition.canDecreaseNestingLevel()}canIncreaseNestingLevel(){return this.composition.canIncreaseNestingLevel()}decreaseNestingLevel(){if(this.canDecreaseNestingLevel())return this.composition.decreaseNestingLevel()}increaseNestingLevel(){if(this.canIncreaseNestingLevel())return this.composition.increaseNestingLevel()}canRedo(){return this.undoManager.canRedo()}canUndo(){return this.undoManager.canUndo()}recordUndoEntry(t){let{context:e,consolidatable:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.undoManager.recordUndoEntry(t,{context:e,consolidatable:i})}redo(){if(this.canRedo())return this.undoManager.redo()}undo(){if(this.canUndo())return this.undoManager.undo()}}class Mn{constructor(t){this.element=t}findLocationFromContainerAndOffset(t,e){let{strict:i}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{strict:!0},n=0,r=!1;const o={index:0,offset:0},s=this.findAttachmentElementParentForNode(t);s&&(t=s.parentNode,e=E(s));const a=R(this.element,{usingFilter:Wn});for(;a.nextNode();){const s=a.currentNode;if(s===t&&B(t)){F(s)||(o.offset+=e);break}if(s.parentNode===t){if(n++===e)break}else if(!C(t,s)&&n>0)break;N(s,{strict:i})?(r&&o.index++,o.offset=0,r=!0):o.offset+=Bn(s)}return o}findContainerAndOffsetFromLocation(t){let e,i;if(0===t.index&&0===t.offset){for(e=this.element,i=0;e.firstChild;)if(e=e.firstChild,D(e)){i=1;break}return[e,i]}let[n,r]=this.findNodeAndOffsetFromLocation(t);if(n){if(B(n))0===Bn(n)?(e=n.parentNode.parentNode,i=E(n.parentNode),F(n,{name:"right"})&&i++):(e=n,i=t.offset-r);else{if(e=n.parentNode,!N(n.previousSibling)&&!D(e))for(;n===e.lastChild&&(n=e,e=e.parentNode,!D(e)););i=E(n),0!==t.offset&&i++}return[e,i]}}findNodeAndOffsetFromLocation(t){let e,i,n=0;for(const r of this.getSignificantNodesForIndex(t.index)){const o=Bn(r);if(t.offset<=n+o)if(B(r)){if(e=r,i=n,t.offset===i&&F(e))break}else e||(e=r,i=n);if(n+=o,n>t.offset)break}return[e,i]}findAttachmentElementParentForNode(t){for(;t&&t!==this.element;){if(P(t))return t;t=t.parentNode}}getSignificantNodesForIndex(t){const e=[],i=R(this.element,{usingFilter:_n});let n=!1;for(;i.nextNode();){const o=i.currentNode;var r;if(I(o)){if(null!=r?r++:r=0,r===t)n=!0;else if(n)break}else n&&e.push(o)}return e}}const Bn=function(t){return t.nodeType===Node.TEXT_NODE?F(t)?0:t.textContent.length:"br"===k(t)||P(t)?1:0},_n=function(t){return jn(t)===NodeFilter.FILTER_ACCEPT?Wn(t):NodeFilter.FILTER_REJECT},jn=function(t){return M(t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},Wn=function(t){return P(t.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT};class Un{createDOMRangeFromPoint(t){let e,{x:i,y:n}=t;if(document.caretPositionFromPoint){const{offsetNode:t,offset:r}=document.caretPositionFromPoint(i,n);return e=document.createRange(),e.setStart(t,r),e}if(document.caretRangeFromPoint)return document.caretRangeFromPoint(i,n);if(document.body.createTextRange){const r=Mt();try{const t=document.body.createTextRange();t.moveToPoint(i,n),t.select()}catch(t){}return e=Mt(),Bt(r),e}}getClientRectsForDOMRange(t){const e=Array.from(t.getClientRects());return[e[0],e[e.length-1]]}}class Vn extends q{constructor(t){super(...arguments),this.didMouseDown=this.didMouseDown.bind(this),this.selectionDidChange=this.selectionDidChange.bind(this),this.element=t,this.locationMapper=new Mn(this.element),this.pointMapper=new Un,this.lockCount=0,b("mousedown",{onElement:this.element,withCallback:this.didMouseDown})}getLocationRange(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return!1===t.strict?this.createLocationRangeFromDOMRange(Mt()):t.ignoreLock?this.currentLocationRange:this.lockedLocationRange?this.lockedLocationRange:this.currentLocationRange}setLocationRange(t){if(this.lockedLocationRange)return;t=wt(t);const e=this.createDOMRangeFromLocationRange(t);e&&(Bt(e),this.updateCurrentLocationRange(t))}setLocationRangeFromPointRange(t){t=wt(t);const e=this.getLocationAtPoint(t[0]),i=this.getLocationAtPoint(t[1]);this.setLocationRange([e,i])}getClientRectAtLocationRange(t){const e=this.createDOMRangeFromLocationRange(t);if(e)return this.getClientRectsForDOMRange(e)[1]}locationIsCursorTarget(t){const e=Array.from(this.findNodeAndOffsetFromLocation(t))[0];return F(e)}lock(){0==this.lockCount++&&(this.updateCurrentLocationRange(),this.lockedLocationRange=this.getLocationRange())}unlock(){if(0==--this.lockCount){const{lockedLocationRange:t}=this;if(this.lockedLocationRange=null,null!=t)return this.setLocationRange(t)}}clearSelection(){var t;return null===(t=Pt())||void 0===t?void 0:t.removeAllRanges()}selectionIsCollapsed(){var t;return!0===(null===(t=Mt())||void 0===t?void 0:t.collapsed)}selectionIsExpanded(){return!this.selectionIsCollapsed()}createLocationRangeFromDOMRange(t,e){if(null==t||!this.domRangeWithinElement(t))return;const i=this.findLocationFromContainerAndOffset(t.startContainer,t.startOffset,e);if(!i)return;const n=t.collapsed?void 0:this.findLocationFromContainerAndOffset(t.endContainer,t.endOffset,e);return wt([i,n])}didMouseDown(){return this.pauseTemporarily()}pauseTemporarily(){let t;this.paused=!0;const e=()=>{if(this.paused=!1,clearTimeout(i),Array.from(t).forEach((t=>{t.destroy()})),C(document,this.element))return this.selectionDidChange()},i=setTimeout(e,200);t=["mousemove","keydown"].map((t=>b(t,{onElement:document,withCallback:e})))}selectionDidChange(){if(!this.paused&&!x(this.element))return this.updateCurrentLocationRange()}updateCurrentLocationRange(t){var e,i;if((null!=t?t:t=this.createLocationRangeFromDOMRange(Mt()))&&!Dt(t,this.currentLocationRange))return this.currentLocationRange=t,null===(e=this.delegate)||void 0===e||null===(i=e.locationRangeDidChange)||void 0===i?void 0:i.call(e,this.currentLocationRange.slice(0))}createDOMRangeFromLocationRange(t){const e=this.findContainerAndOffsetFromLocation(t[0]),i=Lt(t)?e:this.findContainerAndOffsetFromLocation(t[1])||e;if(null!=e&&null!=i){const t=document.createRange();return t.setStart(...Array.from(e||[])),t.setEnd(...Array.from(i||[])),t}}getLocationAtPoint(t){const e=this.createDOMRangeFromPoint(t);var i;if(e)return null===(i=this.createLocationRangeFromDOMRange(e))||void 0===i?void 0:i[0]}domRangeWithinElement(t){return t.collapsed?C(this.element,t.startContainer):C(this.element,t.startContainer)&&C(this.element,t.endContainer)}}Vn.proxyMethod("locationMapper.findLocationFromContainerAndOffset"),Vn.proxyMethod("locationMapper.findContainerAndOffsetFromLocation"),Vn.proxyMethod("locationMapper.findNodeAndOffsetFromLocation"),Vn.proxyMethod("pointMapper.createDOMRangeFromPoint"),Vn.proxyMethod("pointMapper.getClientRectsForDOMRange");var qn=Object.freeze({__proto__:null,Attachment:Vi,AttachmentManager:kn,AttachmentPiece:zi,Block:Xi,Composition:wn,Document:an,Editor:Pn,HTMLParser:hn,HTMLSanitizer:di,LineBreakInsertion:Tn,LocationMapper:Mn,ManagedAttachment:Rn,Piece:Wi,PointMapper:Un,SelectionManager:Vn,SplittableList:Hi,StringPiece:qi,Text:Yi,UndoManager:Ln}),Hn=Object.freeze({__proto__:null,ObjectView:ie,AttachmentView:pi,BlockView:Ei,DocumentView:Si,PieceView:Ai,PreviewableAttachmentView:vi,TextView:yi});const{lang:zn,css:Jn,keyNames:Kn}=H,Gn=function(t){return function(){const e=t.apply(this,arguments);e.do(),this.undos||(this.undos=[]),this.undos.push(e.undo)}};class Yn extends q{constructor(t,e,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};super(...arguments),Di(this,"makeElementMutable",Gn((()=>({do:()=>{this.element.dataset.trixMutable=!0},undo:()=>delete this.element.dataset.trixMutable})))),Di(this,"addToolbar",Gn((()=>{const t=T({tagName:"div",className:Jn.attachmentToolbar,data:{trixMutable:!0},childNodes:T({tagName:"div",className:"trix-button-row",childNodes:T({tagName:"span",className:"trix-button-group trix-button-group--actions",childNodes:T({tagName:"button",className:"trix-button trix-button--remove",textContent:zn.remove,attributes:{title:zn.remove},data:{trixAction:"remove"}})})})});return this.attachment.isPreviewable()&&t.appendChild(T({tagName:"div",className:Jn.attachmentMetadataContainer,childNodes:T({tagName:"span",className:Jn.attachmentMetadata,childNodes:[T({tagName:"span",className:Jn.attachmentName,textContent:this.attachment.getFilename(),attributes:{title:this.attachment.getFilename()}}),T({tagName:"span",className:Jn.attachmentSize,textContent:this.attachment.getFormattedFilesize()})]})})),b("click",{onElement:t,withCallback:this.didClickToolbar}),b("click",{onElement:t,matchingSelector:"[data-trix-action]",withCallback:this.didClickActionButton}),v("trix-attachment-before-toolbar",{onElement:this.element,attributes:{toolbar:t,attachment:this.attachment}}),{do:()=>this.element.appendChild(t),undo:()=>S(t)}}))),Di(this,"installCaptionEditor",Gn((()=>{const t=T({tagName:"textarea",className:Jn.attachmentCaptionEditor,attributes:{placeholder:zn.captionPlaceholder},data:{trixMutable:!0}});t.value=this.attachmentPiece.getCaption();const e=t.cloneNode();e.classList.add("trix-autoresize-clone"),e.tabIndex=-1;const i=function(){e.value=t.value,t.style.height=e.scrollHeight+"px"};b("input",{onElement:t,withCallback:i}),b("input",{onElement:t,withCallback:this.didInputCaption}),b("keydown",{onElement:t,withCallback:this.didKeyDownCaption}),b("change",{onElement:t,withCallback:this.didChangeCaption}),b("blur",{onElement:t,withCallback:this.didBlurCaption});const n=this.element.querySelector("figcaption"),r=n.cloneNode();return{do:()=>{if(n.style.display="none",r.appendChild(t),r.appendChild(e),r.classList.add("".concat(Jn.attachmentCaption,"--editing")),n.parentElement.insertBefore(r,n),i(),this.options.editCaption)return Rt((()=>t.focus()))},undo(){S(r),n.style.display=null}}}))),this.didClickToolbar=this.didClickToolbar.bind(this),this.didClickActionButton=this.didClickActionButton.bind(this),this.didKeyDownCaption=this.didKeyDownCaption.bind(this),this.didInputCaption=this.didInputCaption.bind(this),this.didChangeCaption=this.didChangeCaption.bind(this),this.didBlurCaption=this.didBlurCaption.bind(this),this.attachmentPiece=t,this.element=e,this.container=i,this.options=n,this.attachment=this.attachmentPiece.attachment,"a"===k(this.element)&&(this.element=this.element.firstChild),this.install()}install(){this.makeElementMutable(),this.addToolbar(),this.attachment.isPreviewable()&&this.installCaptionEditor()}uninstall(){var t;let e=this.undos.pop();for(this.savePendingCaption();e;)e(),e=this.undos.pop();null===(t=this.delegate)||void 0===t||t.didUninstallAttachmentEditor(this)}savePendingCaption(){if(null!=this.pendingCaption){const r=this.pendingCaption;var t,e,i,n;this.pendingCaption=null,r?null===(t=this.delegate)||void 0===t||null===(e=t.attachmentEditorDidRequestUpdatingAttributesForAttachment)||void 0===e||e.call(t,{caption:r},this.attachment):null===(i=this.delegate)||void 0===i||null===(n=i.attachmentEditorDidRequestRemovingAttributeForAttachment)||void 0===n||n.call(i,"caption",this.attachment)}}didClickToolbar(t){return t.preventDefault(),t.stopPropagation()}didClickActionButton(t){var e;if("remove"===t.target.getAttribute("data-trix-action"))return null===(e=this.delegate)||void 0===e?void 0:e.attachmentEditorDidRequestRemovalOfAttachment(this.attachment)}didKeyDownCaption(t){var e,i;if("return"===Kn[t.keyCode])return t.preventDefault(),this.savePendingCaption(),null===(e=this.delegate)||void 0===e||null===(i=e.attachmentEditorDidRequestDeselectingAttachment)||void 0===i?void 0:i.call(e,this.attachment)}didInputCaption(t){this.pendingCaption=t.target.value.replace(/\s/g," ").trim()}didChangeCaption(t){return this.savePendingCaption()}didBlurCaption(t){return this.savePendingCaption()}}class Xn extends q{constructor(t,i){super(...arguments),this.didFocus=this.didFocus.bind(this),this.didBlur=this.didBlur.bind(this),this.didClickAttachment=this.didClickAttachment.bind(this),this.element=t,this.composition=i,this.documentView=new Si(this.composition.document,{element:this.element}),b("focus",{onElement:this.element,withCallback:this.didFocus}),b("blur",{onElement:this.element,withCallback:this.didBlur}),b("click",{onElement:this.element,matchingSelector:"a[contenteditable=false]",preventDefault:!0}),b("mousedown",{onElement:this.element,matchingSelector:e,withCallback:this.didClickAttachment}),b("click",{onElement:this.element,matchingSelector:"a".concat(e),preventDefault:!0})}didFocus(t){var e;const i=()=>{var t,e;if(!this.focused)return this.focused=!0,null===(t=this.delegate)||void 0===t||null===(e=t.compositionControllerDidFocus)||void 0===e?void 0:e.call(t)};return(null===(e=this.blurPromise)||void 0===e?void 0:e.then(i))||i()}didBlur(t){this.blurPromise=new Promise((t=>Rt((()=>{var e,i;x(this.element)||(this.focused=null,null===(e=this.delegate)||void 0===e||null===(i=e.compositionControllerDidBlur)||void 0===i||i.call(e));return this.blurPromise=null,t()}))))}didClickAttachment(t,e){var i,n;const r=this.findAttachmentForElement(e),o=!!y(t.target,{matchingSelector:"figcaption"});return null===(i=this.delegate)||void 0===i||null===(n=i.compositionControllerDidSelectAttachment)||void 0===n?void 0:n.call(i,r,{editCaption:o})}getSerializableElement(){return this.isEditingAttachment()?this.documentView.shadowElement:this.element}render(){var t,e,i,n,r,o;(this.revision!==this.composition.revision&&(this.documentView.setDocument(this.composition.document),this.documentView.render(),this.revision=this.composition.revision),this.canSyncDocumentView()&&!this.documentView.isSynced())&&(null===(i=this.delegate)||void 0===i||null===(n=i.compositionControllerWillSyncDocumentView)||void 0===n||n.call(i),this.documentView.sync(),null===(r=this.delegate)||void 0===r||null===(o=r.compositionControllerDidSyncDocumentView)||void 0===o||o.call(r));return null===(t=this.delegate)||void 0===t||null===(e=t.compositionControllerDidRender)||void 0===e?void 0:e.call(t)}rerenderViewForObject(t){return this.invalidateViewForObject(t),this.render()}invalidateViewForObject(t){return this.documentView.invalidateViewForObject(t)}isViewCachingEnabled(){return this.documentView.isViewCachingEnabled()}enableViewCaching(){return this.documentView.enableViewCaching()}disableViewCaching(){return this.documentView.disableViewCaching()}refreshViewCache(){return this.documentView.garbageCollectCachedViews()}isEditingAttachment(){return!!this.attachmentEditor}installAttachmentEditorForAttachment(t,e){var i;if((null===(i=this.attachmentEditor)||void 0===i?void 0:i.attachment)===t)return;const n=this.documentView.findElementForObject(t);if(!n)return;this.uninstallAttachmentEditor();const r=this.composition.document.getAttachmentPieceForAttachment(t);this.attachmentEditor=new Yn(r,n,this.element,e),this.attachmentEditor.delegate=this}uninstallAttachmentEditor(){var t;return null===(t=this.attachmentEditor)||void 0===t?void 0:t.uninstall()}didUninstallAttachmentEditor(){return this.attachmentEditor=null,this.render()}attachmentEditorDidRequestUpdatingAttributesForAttachment(t,e){var i,n;return null===(i=this.delegate)||void 0===i||null===(n=i.compositionControllerWillUpdateAttachment)||void 0===n||n.call(i,e),this.composition.updateAttributesForAttachment(t,e)}attachmentEditorDidRequestRemovingAttributeForAttachment(t,e){var i,n;return null===(i=this.delegate)||void 0===i||null===(n=i.compositionControllerWillUpdateAttachment)||void 0===n||n.call(i,e),this.composition.removeAttributeForAttachment(t,e)}attachmentEditorDidRequestRemovalOfAttachment(t){var e,i;return null===(e=this.delegate)||void 0===e||null===(i=e.compositionControllerDidRequestRemovalOfAttachment)||void 0===i?void 0:i.call(e,t)}attachmentEditorDidRequestDeselectingAttachment(t){var e,i;return null===(e=this.delegate)||void 0===e||null===(i=e.compositionControllerDidRequestDeselectingAttachment)||void 0===i?void 0:i.call(e,t)}canSyncDocumentView(){return!this.isEditingAttachment()}findAttachmentForElement(t){return this.composition.document.getAttachmentById(parseInt(t.dataset.trixId,10))}}class $n extends q{}const Zn="data-trix-mutable",Qn="[".concat(Zn,"]"),tr={attributes:!0,childList:!0,characterData:!0,characterDataOldValue:!0,subtree:!0};class er extends q{constructor(t){super(t),this.didMutate=this.didMutate.bind(this),this.element=t,this.observer=new window.MutationObserver(this.didMutate),this.start()}start(){return this.reset(),this.observer.observe(this.element,tr)}stop(){return this.observer.disconnect()}didMutate(t){var e,i;if(this.mutations.push(...Array.from(this.findSignificantMutations(t)||[])),this.mutations.length)return null===(e=this.delegate)||void 0===e||null===(i=e.elementDidMutate)||void 0===i||i.call(e,this.getMutationSummary()),this.reset()}reset(){this.mutations=[]}findSignificantMutations(t){return t.filter((t=>this.mutationIsSignificant(t)))}mutationIsSignificant(t){if(this.nodeIsMutable(t.target))return!1;for(const e of Array.from(this.nodesModifiedByMutation(t)))if(this.nodeIsSignificant(e))return!0;return!1}nodeIsSignificant(t){return t!==this.element&&!this.nodeIsMutable(t)&&!M(t)}nodeIsMutable(t){return y(t,{matchingSelector:Qn})}nodesModifiedByMutation(t){const e=[];switch(t.type){case"attributes":t.attributeName!==Zn&&e.push(t.target);break;case"characterData":e.push(t.target.parentNode),e.push(t.target);break;case"childList":e.push(...Array.from(t.addedNodes||[])),e.push(...Array.from(t.removedNodes||[]))}return e}getMutationSummary(){return this.getTextMutationSummary()}getTextMutationSummary(){const{additions:t,deletions:e}=this.getTextChangesFromCharacterData(),i=this.getTextChangesFromChildList();Array.from(i.additions).forEach((e=>{Array.from(t).includes(e)||t.push(e)})),e.push(...Array.from(i.deletions||[]));const n={},r=t.join("");r&&(n.textAdded=r);const o=e.join("");return o&&(n.textDeleted=o),n}getMutationsByType(t){return Array.from(this.mutations).filter((e=>e.type===t))}getTextChangesFromChildList(){let t,e;const i=[],n=[];Array.from(this.getMutationsByType("childList")).forEach((t=>{i.push(...Array.from(t.addedNodes||[])),n.push(...Array.from(t.removedNodes||[]))}));0===i.length&&1===n.length&&I(n[0])?(t=[],e=["\n"]):(t=ir(i),e=ir(n));const r=t.filter(((t,i)=>t!==e[i])).map(Wt),o=e.filter(((e,i)=>e!==t[i])).map(Wt);return{additions:r,deletions:o}}getTextChangesFromCharacterData(){let t,e;const i=this.getMutationsByType("characterData");if(i.length){const n=i[0],r=i[i.length-1],o=function(t,e){let i,n;return t=$.box(t),(e=$.box(e)).length0&&void 0!==arguments[0]?arguments[0]:[];const e=[];for(const i of Array.from(t))switch(i.nodeType){case Node.TEXT_NODE:e.push(i.data);break;case Node.ELEMENT_NODE:"br"===k(i)?e.push("\n"):e.push(...Array.from(ir(i.childNodes)||[]))}return e};class nr extends ee{constructor(t){super(...arguments),this.file=t}perform(t){const e=new FileReader;return e.onerror=()=>t(!1),e.onload=()=>{e.onerror=null;try{e.abort()}catch(t){}return t(!0,this.file)},e.readAsArrayBuffer(this.file)}}class rr{constructor(t){this.element=t}shouldIgnore(t){return!!a.samsungAndroid&&(this.previousEvent=this.event,this.event=t,this.checkSamsungKeyboardBuggyModeStart(),this.checkSamsungKeyboardBuggyModeEnd(),this.buggyMode)}checkSamsungKeyboardBuggyModeStart(){this.insertingLongTextAfterUnidentifiedChar()&&or(this.element.innerText,this.event.data)&&(this.buggyMode=!0,this.event.preventDefault())}checkSamsungKeyboardBuggyModeEnd(){this.buggyMode&&"insertText"!==this.event.inputType&&(this.buggyMode=!1)}insertingLongTextAfterUnidentifiedChar(){var t;return this.isBeforeInputInsertText()&&this.previousEventWasUnidentifiedKeydown()&&(null===(t=this.event.data)||void 0===t?void 0:t.length)>50}isBeforeInputInsertText(){return"beforeinput"===this.event.type&&"insertText"===this.event.inputType}previousEventWasUnidentifiedKeydown(){var t,e;return"keydown"===(null===(t=this.previousEvent)||void 0===t?void 0:t.type)&&"Unidentified"===(null===(e=this.previousEvent)||void 0===e?void 0:e.key)}}const or=(t,e)=>ar(t)===ar(e),sr=new RegExp("(".concat("","|").concat(d,"|").concat(g,"|\\s)+"),"g"),ar=t=>t.replace(sr," ").trim();class lr extends q{constructor(t){super(...arguments),this.element=t,this.mutationObserver=new er(this.element),this.mutationObserver.delegate=this,this.flakyKeyboardDetector=new rr(this.element);for(const t in this.constructor.events)b(t,{onElement:this.element,withCallback:this.handlerFor(t)})}elementDidMutate(t){}editorWillSyncDocumentView(){return this.mutationObserver.stop()}editorDidSyncDocumentView(){return this.mutationObserver.start()}requestRender(){var t,e;return null===(t=this.delegate)||void 0===t||null===(e=t.inputControllerDidRequestRender)||void 0===e?void 0:e.call(t)}requestReparse(){var t,e;return null===(t=this.delegate)||void 0===t||null===(e=t.inputControllerDidRequestReparse)||void 0===e||e.call(t),this.requestRender()}attachFiles(t){const e=Array.from(t).map((t=>new nr(t)));return Promise.all(e).then((t=>{this.handleInput((function(){var e,i;return null===(e=this.delegate)||void 0===e||e.inputControllerWillAttachFiles(),null===(i=this.responder)||void 0===i||i.insertFiles(t),this.requestRender()}))}))}handlerFor(t){return e=>{e.defaultPrevented||this.handleInput((()=>{if(!x(this.element)){if(this.flakyKeyboardDetector.shouldIgnore(e))return;this.eventName=t,this.constructor.events[t].call(this,e)}}))}}handleInput(t){try{var e;null===(e=this.delegate)||void 0===e||e.inputControllerWillHandleInput(),t.call(this)}finally{var i;null===(i=this.delegate)||void 0===i||i.inputControllerDidHandleInput()}}createLinkHTML(t,e){const i=document.createElement("a");return i.href=t,i.textContent=e||t,i.outerHTML}}var cr;Di(lr,"events",{});const{browser:ur,keyNames:hr}=H;let dr=0;class gr extends lr{constructor(){super(...arguments),this.resetInputSummary()}setInputSummary(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.inputSummary.eventName=this.eventName;for(const e in t){const i=t[e];this.inputSummary[e]=i}return this.inputSummary}resetInputSummary(){this.inputSummary={}}reset(){return this.resetInputSummary(),Ft.reset()}elementDidMutate(t){var e,i;return this.isComposing()?null===(e=this.delegate)||void 0===e||null===(i=e.inputControllerDidAllowUnhandledInput)||void 0===i?void 0:i.call(e):this.handleInput((function(){return this.mutationIsSignificant(t)&&(this.mutationIsExpected(t)?this.requestRender():this.requestReparse()),this.reset()}))}mutationIsExpected(t){let{textAdded:e,textDeleted:i}=t;if(this.inputSummary.preferDocument)return!0;const n=null!=e?e===this.inputSummary.textAdded:!this.inputSummary.textAdded,r=null!=i?this.inputSummary.didDelete:!this.inputSummary.didDelete,o=["\n"," \n"].includes(e)&&!n,s="\n"===i&&!r;if(o&&!s||s&&!o){const t=this.getSelectedRange();if(t){var a;const i=o?e.replace(/\n$/,"").length||-1:(null==e?void 0:e.length)||1;if(null!==(a=this.responder)&&void 0!==a&&a.positionIsBlockBreak(t[1]+i))return!0}}return n&&r}mutationIsSignificant(t){var e;const i=Object.keys(t).length>0,n=""===(null===(e=this.compositionInput)||void 0===e?void 0:e.getEndData());return i||!n}getCompositionInput(){if(this.isComposing())return this.compositionInput;this.compositionInput=new vr(this)}isComposing(){return this.compositionInput&&!this.compositionInput.isEnded()}deleteInDirection(t,e){var i;return!1!==(null===(i=this.responder)||void 0===i?void 0:i.deleteInDirection(t))?this.setInputSummary({didDelete:!0}):e?(e.preventDefault(),this.requestRender()):void 0}serializeSelectionToDataTransfer(t){var e;if(!function(t){if(null==t||!t.setData)return!1;for(const e in Ct){const i=Ct[e];try{if(t.setData(e,i),!t.getData(e)===i)return!1}catch(t){return!1}}return!0}(t))return;const i=null===(e=this.responder)||void 0===e?void 0:e.getSelectedDocument().toSerializableDocument();return t.setData("application/x-trix-document",JSON.stringify(i)),t.setData("text/html",Si.render(i).innerHTML),t.setData("text/plain",i.toString().replace(/\n$/,"")),!0}canAcceptDataTransfer(t){const e={};return Array.from((null==t?void 0:t.types)||[]).forEach((t=>{e[t]=!0})),e.Files||e["application/x-trix-document"]||e["text/html"]||e["text/plain"]}getPastedHTMLUsingHiddenElement(t){const e=this.getSelectedRange(),i={position:"absolute",left:"".concat(window.pageXOffset,"px"),top:"".concat(window.pageYOffset,"px"),opacity:0},n=T({style:i,tagName:"div",editable:!0});return document.body.appendChild(n),n.focus(),requestAnimationFrame((()=>{const i=n.innerHTML;return S(n),this.setSelectedRange(e),t(i)}))}}Di(gr,"events",{keydown(t){this.isComposing()||this.resetInputSummary(),this.inputSummary.didInput=!0;const e=hr[t.keyCode];if(e){var i;let n=this.keys;["ctrl","alt","shift","meta"].forEach((e=>{var i;t["".concat(e,"Key")]&&("ctrl"===e&&(e="control"),n=null===(i=n)||void 0===i?void 0:i[e])})),null!=(null===(i=n)||void 0===i?void 0:i[e])&&(this.setInputSummary({keyName:e}),Ft.reset(),n[e].call(this,t))}if(St(t)){const e=String.fromCharCode(t.keyCode).toLowerCase();if(e){var n;const i=["alt","shift"].map((e=>{if(t["".concat(e,"Key")])return e})).filter((t=>t));i.push(e),null!==(n=this.delegate)&&void 0!==n&&n.inputControllerDidReceiveKeyboardCommand(i)&&t.preventDefault()}}},keypress(t){if(null!=this.inputSummary.eventName)return;if(t.metaKey)return;if(t.ctrlKey&&!t.altKey)return;const e=fr(t);var i,n;return e?(null===(i=this.delegate)||void 0===i||i.inputControllerWillPerformTyping(),null===(n=this.responder)||void 0===n||n.insertString(e),this.setInputSummary({textAdded:e,didDelete:this.selectionIsExpanded()})):void 0},textInput(t){const{data:e}=t,{textAdded:i}=this.inputSummary;if(i&&i!==e&&i.toUpperCase()===e){var n;const t=this.getSelectedRange();return this.setSelectedRange([t[0],t[1]+i.length]),null===(n=this.responder)||void 0===n||n.insertString(e),this.setInputSummary({textAdded:e}),this.setSelectedRange(t)}},dragenter(t){t.preventDefault()},dragstart(t){var e,i;return this.serializeSelectionToDataTransfer(t.dataTransfer),this.draggedRange=this.getSelectedRange(),null===(e=this.delegate)||void 0===e||null===(i=e.inputControllerDidStartDrag)||void 0===i?void 0:i.call(e)},dragover(t){if(this.draggedRange||this.canAcceptDataTransfer(t.dataTransfer)){t.preventDefault();const n={x:t.clientX,y:t.clientY};var e,i;if(!Tt(n,this.draggingPoint))return this.draggingPoint=n,null===(e=this.delegate)||void 0===e||null===(i=e.inputControllerDidReceiveDragOverPoint)||void 0===i?void 0:i.call(e,this.draggingPoint)}},dragend(t){var e,i;null===(e=this.delegate)||void 0===e||null===(i=e.inputControllerDidCancelDrag)||void 0===i||i.call(e),this.draggedRange=null,this.draggingPoint=null},drop(t){var e,i;t.preventDefault();const n=null===(e=t.dataTransfer)||void 0===e?void 0:e.files,r=t.dataTransfer.getData("application/x-trix-document"),o={x:t.clientX,y:t.clientY};if(null===(i=this.responder)||void 0===i||i.setLocationRangeFromPointRange(o),null!=n&&n.length)this.attachFiles(n);else if(this.draggedRange){var s,a;null===(s=this.delegate)||void 0===s||s.inputControllerWillMoveText(),null===(a=this.responder)||void 0===a||a.moveTextFromRange(this.draggedRange),this.draggedRange=null,this.requestRender()}else if(r){var l;const t=an.fromJSONString(r);null===(l=this.responder)||void 0===l||l.insertDocument(t),this.requestRender()}this.draggedRange=null,this.draggingPoint=null},cut(t){var e,i;if(null!==(e=this.responder)&&void 0!==e&&e.selectionIsExpanded()&&(this.serializeSelectionToDataTransfer(t.clipboardData)&&t.preventDefault(),null===(i=this.delegate)||void 0===i||i.inputControllerWillCutText(),this.deleteInDirection("backward"),t.defaultPrevented))return this.requestRender()},copy(t){var e;null!==(e=this.responder)&&void 0!==e&&e.selectionIsExpanded()&&this.serializeSelectionToDataTransfer(t.clipboardData)&&t.preventDefault()},paste(t){const e=t.clipboardData||t.testClipboardData,i={clipboard:e};if(!e||br(t))return void this.getPastedHTMLUsingHiddenElement((t=>{var e,n,r;return i.type="text/html",i.html=t,null===(e=this.delegate)||void 0===e||e.inputControllerWillPaste(i),null===(n=this.responder)||void 0===n||n.insertHTML(i.html),this.requestRender(),null===(r=this.delegate)||void 0===r?void 0:r.inputControllerDidPaste(i)}));const n=e.getData("URL"),r=e.getData("text/html"),o=e.getData("public.url-name");if(n){var s,a,l;let t;i.type="text/html",t=o?Vt(o).trim():n,i.html=this.createLinkHTML(n,t),null===(s=this.delegate)||void 0===s||s.inputControllerWillPaste(i),this.setInputSummary({textAdded:t,didDelete:this.selectionIsExpanded()}),null===(a=this.responder)||void 0===a||a.insertHTML(i.html),this.requestRender(),null===(l=this.delegate)||void 0===l||l.inputControllerDidPaste(i)}else if(Et(e)){var c,u,h;i.type="text/plain",i.string=e.getData("text/plain"),null===(c=this.delegate)||void 0===c||c.inputControllerWillPaste(i),this.setInputSummary({textAdded:i.string,didDelete:this.selectionIsExpanded()}),null===(u=this.responder)||void 0===u||u.insertString(i.string),this.requestRender(),null===(h=this.delegate)||void 0===h||h.inputControllerDidPaste(i)}else if(r){var d,g,m;i.type="text/html",i.html=r,null===(d=this.delegate)||void 0===d||d.inputControllerWillPaste(i),null===(g=this.responder)||void 0===g||g.insertHTML(i.html),this.requestRender(),null===(m=this.delegate)||void 0===m||m.inputControllerDidPaste(i)}else if(Array.from(e.types).includes("Files")){var p,f;const t=null===(p=e.items)||void 0===p||null===(p=p[0])||void 0===p||null===(f=p.getAsFile)||void 0===f?void 0:f.call(p);if(t){var b,v,A;const e=mr(t);!t.name&&e&&(t.name="pasted-file-".concat(++dr,".").concat(e)),i.type="File",i.file=t,null===(b=this.delegate)||void 0===b||b.inputControllerWillAttachFiles(),null===(v=this.responder)||void 0===v||v.insertFile(i.file),this.requestRender(),null===(A=this.delegate)||void 0===A||A.inputControllerDidPaste(i)}}t.preventDefault()},compositionstart(t){return this.getCompositionInput().start(t.data)},compositionupdate(t){return this.getCompositionInput().update(t.data)},compositionend(t){return this.getCompositionInput().end(t.data)},beforeinput(t){this.inputSummary.didInput=!0},input(t){return this.inputSummary.didInput=!0,t.stopPropagation()}}),Di(gr,"keys",{backspace(t){var e;return null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),this.deleteInDirection("backward",t)},delete(t){var e;return null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),this.deleteInDirection("forward",t)},return(t){var e,i;return this.setInputSummary({preferDocument:!0}),null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),null===(i=this.responder)||void 0===i?void 0:i.insertLineBreak()},tab(t){var e,i;null!==(e=this.responder)&&void 0!==e&&e.canIncreaseNestingLevel()&&(null===(i=this.responder)||void 0===i||i.increaseNestingLevel(),this.requestRender(),t.preventDefault())},left(t){var e;if(this.selectionIsInCursorTarget())return t.preventDefault(),null===(e=this.responder)||void 0===e?void 0:e.moveCursorInDirection("backward")},right(t){var e;if(this.selectionIsInCursorTarget())return t.preventDefault(),null===(e=this.responder)||void 0===e?void 0:e.moveCursorInDirection("forward")},control:{d(t){var e;return null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),this.deleteInDirection("forward",t)},h(t){var e;return null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),this.deleteInDirection("backward",t)},o(t){var e,i;return t.preventDefault(),null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),null===(i=this.responder)||void 0===i||i.insertString("\n",{updatePosition:!1}),this.requestRender()}},shift:{return(t){var e,i;null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),null===(i=this.responder)||void 0===i||i.insertString("\n"),this.requestRender(),t.preventDefault()},tab(t){var e,i;null!==(e=this.responder)&&void 0!==e&&e.canDecreaseNestingLevel()&&(null===(i=this.responder)||void 0===i||i.decreaseNestingLevel(),this.requestRender(),t.preventDefault())},left(t){if(this.selectionIsInCursorTarget())return t.preventDefault(),this.expandSelectionInDirection("backward")},right(t){if(this.selectionIsInCursorTarget())return t.preventDefault(),this.expandSelectionInDirection("forward")}},alt:{backspace(t){var e;return this.setInputSummary({preferDocument:!1}),null===(e=this.delegate)||void 0===e?void 0:e.inputControllerWillPerformTyping()}},meta:{backspace(t){var e;return this.setInputSummary({preferDocument:!1}),null===(e=this.delegate)||void 0===e?void 0:e.inputControllerWillPerformTyping()}}}),gr.proxyMethod("responder?.getSelectedRange"),gr.proxyMethod("responder?.setSelectedRange"),gr.proxyMethod("responder?.expandSelectionInDirection"),gr.proxyMethod("responder?.selectionIsInCursorTarget"),gr.proxyMethod("responder?.selectionIsExpanded");const mr=t=>{var e;return null===(e=t.type)||void 0===e||null===(e=e.match(/\/(\w+)$/))||void 0===e?void 0:e[1]},pr=!(null===(cr=" ".codePointAt)||void 0===cr||!cr.call(" ",0)),fr=function(t){if(t.key&&pr&&t.key.codePointAt(0)===t.keyCode)return t.key;{let e;if(null===t.which?e=t.keyCode:0!==t.which&&0!==t.charCode&&(e=t.charCode),null!=e&&"escape"!==hr[e])return $.fromCodepoints([e]).toString()}},br=function(t){const e=t.clipboardData;if(e){if(e.types.includes("text/html")){for(const t of e.types){const i=/^CorePasteboardFlavorType/.test(t),n=/^dyn\./.test(t)&&e.getData(t);if(i||n)return!0}return!1}{const t=e.types.includes("com.apple.webarchive"),i=e.types.includes("com.apple.flat-rtfd");return t||i}}};class vr extends q{constructor(t){super(...arguments),this.inputController=t,this.responder=this.inputController.responder,this.delegate=this.inputController.delegate,this.inputSummary=this.inputController.inputSummary,this.data={}}start(t){if(this.data.start=t,this.isSignificant()){var e,i;"keypress"===this.inputSummary.eventName&&this.inputSummary.textAdded&&(null===(i=this.responder)||void 0===i||i.deleteInDirection("left"));this.selectionIsExpanded()||(this.insertPlaceholder(),this.requestRender()),this.range=null===(e=this.responder)||void 0===e?void 0:e.getSelectedRange()}}update(t){if(this.data.update=t,this.isSignificant()){const t=this.selectPlaceholder();t&&(this.forgetPlaceholder(),this.range=t)}}end(t){return this.data.end=t,this.isSignificant()?(this.forgetPlaceholder(),this.canApplyToDocument()?(this.setInputSummary({preferDocument:!0,didInput:!1}),null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),null===(i=this.responder)||void 0===i||i.setSelectedRange(this.range),null===(n=this.responder)||void 0===n||n.insertString(this.data.end),null===(r=this.responder)||void 0===r?void 0:r.setSelectedRange(this.range[0]+this.data.end.length)):null!=this.data.start||null!=this.data.update?(this.requestReparse(),this.inputController.reset()):void 0):this.inputController.reset();var e,i,n,r}getEndData(){return this.data.end}isEnded(){return null!=this.getEndData()}isSignificant(){return!ur.composesExistingText||this.inputSummary.didInput}canApplyToDocument(){var t,e;return 0===(null===(t=this.data.start)||void 0===t?void 0:t.length)&&(null===(e=this.data.end)||void 0===e?void 0:e.length)>0&&this.range}}vr.proxyMethod("inputController.setInputSummary"),vr.proxyMethod("inputController.requestRender"),vr.proxyMethod("inputController.requestReparse"),vr.proxyMethod("responder?.selectionIsExpanded"),vr.proxyMethod("responder?.insertPlaceholder"),vr.proxyMethod("responder?.selectPlaceholder"),vr.proxyMethod("responder?.forgetPlaceholder");class Ar extends lr{constructor(){super(...arguments),this.render=this.render.bind(this)}elementDidMutate(){return this.scheduledRender?this.composing?null===(t=this.delegate)||void 0===t||null===(e=t.inputControllerDidAllowUnhandledInput)||void 0===e?void 0:e.call(t):void 0:this.reparse();var t,e}scheduleRender(){return this.scheduledRender?this.scheduledRender:this.scheduledRender=requestAnimationFrame(this.render)}render(){var t,e;(cancelAnimationFrame(this.scheduledRender),this.scheduledRender=null,this.composing)||null===(e=this.delegate)||void 0===e||e.render();null===(t=this.afterRender)||void 0===t||t.call(this),this.afterRender=null}reparse(){var t;return null===(t=this.delegate)||void 0===t?void 0:t.reparse()}insertString(){var t;let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",i=arguments.length>1?arguments[1]:void 0;return null===(t=this.delegate)||void 0===t||t.inputControllerWillPerformTyping(),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertString(e,i)}))}toggleAttributeIfSupported(t){var e;if(gt().includes(t))return null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformFormatting(t),this.withTargetDOMRange((function(){var e;return null===(e=this.responder)||void 0===e?void 0:e.toggleCurrentAttribute(t)}))}activateAttributeIfSupported(t,e){var i;if(gt().includes(t))return null===(i=this.delegate)||void 0===i||i.inputControllerWillPerformFormatting(t),this.withTargetDOMRange((function(){var i;return null===(i=this.responder)||void 0===i?void 0:i.setCurrentAttribute(t,e)}))}deleteInDirection(t){let{recordUndoEntry:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{recordUndoEntry:!0};var i;e&&(null===(i=this.delegate)||void 0===i||i.inputControllerWillPerformTyping());const n=()=>{var e;return null===(e=this.responder)||void 0===e?void 0:e.deleteInDirection(t)},r=this.getTargetDOMRange({minLength:this.composing?1:2});return r?this.withTargetDOMRange(r,n):n()}withTargetDOMRange(t,e){var i;return"function"==typeof t&&(e=t,t=this.getTargetDOMRange()),t?null===(i=this.responder)||void 0===i?void 0:i.withTargetDOMRange(t,e.bind(this)):(Ft.reset(),e.call(this))}getTargetDOMRange(){var t,e;let{minLength:i}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{minLength:0};const n=null===(t=(e=this.event).getTargetRanges)||void 0===t?void 0:t.call(e);if(n&&n.length){const t=yr(n[0]);if(0===i||t.toString().length>=i)return t}}withEvent(t,e){let i;this.event=t;try{i=e.call(this)}finally{this.event=null}return i}}Di(Ar,"events",{keydown(t){if(St(t)){var e;const i=Rr(t);null!==(e=this.delegate)&&void 0!==e&&e.inputControllerDidReceiveKeyboardCommand(i)&&t.preventDefault()}else{let e=t.key;t.altKey&&(e+="+Alt"),t.shiftKey&&(e+="+Shift");const i=this.constructor.keys[e];if(i)return this.withEvent(t,i)}},paste(t){var e;let i;const n=null===(e=t.clipboardData)||void 0===e?void 0:e.getData("URL");return Er(t)?(t.preventDefault(),this.attachFiles(t.clipboardData.files)):Sr(t)?(t.preventDefault(),i={type:"text/plain",string:t.clipboardData.getData("text/plain")},null===(r=this.delegate)||void 0===r||r.inputControllerWillPaste(i),null===(o=this.responder)||void 0===o||o.insertString(i.string),this.render(),null===(s=this.delegate)||void 0===s?void 0:s.inputControllerDidPaste(i)):n?(t.preventDefault(),i={type:"text/html",html:this.createLinkHTML(n)},null===(a=this.delegate)||void 0===a||a.inputControllerWillPaste(i),null===(l=this.responder)||void 0===l||l.insertHTML(i.html),this.render(),null===(c=this.delegate)||void 0===c?void 0:c.inputControllerDidPaste(i)):void 0;var r,o,s,a,l,c},beforeinput(t){const e=this.constructor.inputTypes[t.inputType],i=(n=t,!(!/iPhone|iPad/.test(navigator.userAgent)||n.inputType&&"insertParagraph"!==n.inputType));var n;e&&(this.withEvent(t,e),i||this.scheduleRender()),i&&this.render()},input(t){Ft.reset()},dragstart(t){var e,i;null!==(e=this.responder)&&void 0!==e&&e.selectionContainsAttachments()&&(t.dataTransfer.setData("application/x-trix-dragging",!0),this.dragging={range:null===(i=this.responder)||void 0===i?void 0:i.getSelectedRange(),point:kr(t)})},dragenter(t){xr(t)&&t.preventDefault()},dragover(t){if(this.dragging){t.preventDefault();const i=kr(t);var e;if(!Tt(i,this.dragging.point))return this.dragging.point=i,null===(e=this.responder)||void 0===e?void 0:e.setLocationRangeFromPointRange(i)}else xr(t)&&t.preventDefault()},drop(t){var e,i;if(this.dragging)return t.preventDefault(),null===(e=this.delegate)||void 0===e||e.inputControllerWillMoveText(),null===(i=this.responder)||void 0===i||i.moveTextFromRange(this.dragging.range),this.dragging=null,this.scheduleRender();if(xr(t)){var n;t.preventDefault();const e=kr(t);return null===(n=this.responder)||void 0===n||n.setLocationRangeFromPointRange(e),this.attachFiles(t.dataTransfer.files)}},dragend(){var t;this.dragging&&(null===(t=this.responder)||void 0===t||t.setSelectedRange(this.dragging.range),this.dragging=null)},compositionend(t){this.composing&&(this.composing=!1,a.recentAndroid||this.scheduleRender())}}),Di(Ar,"keys",{ArrowLeft(){var t,e;if(null!==(t=this.responder)&&void 0!==t&&t.shouldManageMovingCursorInDirection("backward"))return this.event.preventDefault(),null===(e=this.responder)||void 0===e?void 0:e.moveCursorInDirection("backward")},ArrowRight(){var t,e;if(null!==(t=this.responder)&&void 0!==t&&t.shouldManageMovingCursorInDirection("forward"))return this.event.preventDefault(),null===(e=this.responder)||void 0===e?void 0:e.moveCursorInDirection("forward")},Backspace(){var t,e,i;if(null!==(t=this.responder)&&void 0!==t&&t.shouldManageDeletingInDirection("backward"))return this.event.preventDefault(),null===(e=this.delegate)||void 0===e||e.inputControllerWillPerformTyping(),null===(i=this.responder)||void 0===i||i.deleteInDirection("backward"),this.render()},Tab(){var t,e;if(null!==(t=this.responder)&&void 0!==t&&t.canIncreaseNestingLevel())return this.event.preventDefault(),null===(e=this.responder)||void 0===e||e.increaseNestingLevel(),this.render()},"Tab+Shift"(){var t,e;if(null!==(t=this.responder)&&void 0!==t&&t.canDecreaseNestingLevel())return this.event.preventDefault(),null===(e=this.responder)||void 0===e||e.decreaseNestingLevel(),this.render()}}),Di(Ar,"inputTypes",{deleteByComposition(){return this.deleteInDirection("backward",{recordUndoEntry:!1})},deleteByCut(){return this.deleteInDirection("backward")},deleteByDrag(){return this.event.preventDefault(),this.withTargetDOMRange((function(){var t;this.deleteByDragRange=null===(t=this.responder)||void 0===t?void 0:t.getSelectedRange()}))},deleteCompositionText(){return this.deleteInDirection("backward",{recordUndoEntry:!1})},deleteContent(){return this.deleteInDirection("backward")},deleteContentBackward(){return this.deleteInDirection("backward")},deleteContentForward(){return this.deleteInDirection("forward")},deleteEntireSoftLine(){return this.deleteInDirection("forward")},deleteHardLineBackward(){return this.deleteInDirection("backward")},deleteHardLineForward(){return this.deleteInDirection("forward")},deleteSoftLineBackward(){return this.deleteInDirection("backward")},deleteSoftLineForward(){return this.deleteInDirection("forward")},deleteWordBackward(){return this.deleteInDirection("backward")},deleteWordForward(){return this.deleteInDirection("forward")},formatBackColor(){return this.activateAttributeIfSupported("backgroundColor",this.event.data)},formatBold(){return this.toggleAttributeIfSupported("bold")},formatFontColor(){return this.activateAttributeIfSupported("color",this.event.data)},formatFontName(){return this.activateAttributeIfSupported("font",this.event.data)},formatIndent(){var t;if(null!==(t=this.responder)&&void 0!==t&&t.canIncreaseNestingLevel())return this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.increaseNestingLevel()}))},formatItalic(){return this.toggleAttributeIfSupported("italic")},formatJustifyCenter(){return this.toggleAttributeIfSupported("justifyCenter")},formatJustifyFull(){return this.toggleAttributeIfSupported("justifyFull")},formatJustifyLeft(){return this.toggleAttributeIfSupported("justifyLeft")},formatJustifyRight(){return this.toggleAttributeIfSupported("justifyRight")},formatOutdent(){var t;if(null!==(t=this.responder)&&void 0!==t&&t.canDecreaseNestingLevel())return this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.decreaseNestingLevel()}))},formatRemove(){this.withTargetDOMRange((function(){for(const i in null===(t=this.responder)||void 0===t?void 0:t.getCurrentAttributes()){var t,e;null===(e=this.responder)||void 0===e||e.removeCurrentAttribute(i)}}))},formatSetBlockTextDirection(){return this.activateAttributeIfSupported("blockDir",this.event.data)},formatSetInlineTextDirection(){return this.activateAttributeIfSupported("textDir",this.event.data)},formatStrikeThrough(){return this.toggleAttributeIfSupported("strike")},formatSubscript(){return this.toggleAttributeIfSupported("sub")},formatSuperscript(){return this.toggleAttributeIfSupported("sup")},formatUnderline(){return this.toggleAttributeIfSupported("underline")},historyRedo(){var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerWillPerformRedo()},historyUndo(){var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerWillPerformUndo()},insertCompositionText(){return this.composing=!0,this.insertString(this.event.data)},insertFromComposition(){return this.composing=!1,this.insertString(this.event.data)},insertFromDrop(){const t=this.deleteByDragRange;var e;if(t)return this.deleteByDragRange=null,null===(e=this.delegate)||void 0===e||e.inputControllerWillMoveText(),this.withTargetDOMRange((function(){var e;return null===(e=this.responder)||void 0===e?void 0:e.moveTextFromRange(t)}))},insertFromPaste(){const{dataTransfer:t}=this.event,e={dataTransfer:t},i=t.getData("URL"),n=t.getData("text/html");if(i){var r;let n;this.event.preventDefault(),e.type="text/html";const o=t.getData("public.url-name");n=o?Vt(o).trim():i,e.html=this.createLinkHTML(i,n),null===(r=this.delegate)||void 0===r||r.inputControllerWillPaste(e),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertHTML(e.html)})),this.afterRender=()=>{var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerDidPaste(e)}}else if(Et(t)){var o;e.type="text/plain",e.string=t.getData("text/plain"),null===(o=this.delegate)||void 0===o||o.inputControllerWillPaste(e),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertString(e.string)})),this.afterRender=()=>{var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerDidPaste(e)}}else if(Cr(this.event)){var s;e.type="File",e.file=t.files[0],null===(s=this.delegate)||void 0===s||s.inputControllerWillPaste(e),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertFile(e.file)})),this.afterRender=()=>{var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerDidPaste(e)}}else if(n){var a;this.event.preventDefault(),e.type="text/html",e.html=n,null===(a=this.delegate)||void 0===a||a.inputControllerWillPaste(e),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertHTML(e.html)})),this.afterRender=()=>{var t;return null===(t=this.delegate)||void 0===t?void 0:t.inputControllerDidPaste(e)}}},insertFromYank(){return this.insertString(this.event.data)},insertLineBreak(){return this.insertString("\n")},insertLink(){return this.activateAttributeIfSupported("href",this.event.data)},insertOrderedList(){return this.toggleAttributeIfSupported("number")},insertParagraph(){var t;return null===(t=this.delegate)||void 0===t||t.inputControllerWillPerformTyping(),this.withTargetDOMRange((function(){var t;return null===(t=this.responder)||void 0===t?void 0:t.insertLineBreak()}))},insertReplacementText(){const t=this.event.dataTransfer.getData("text/plain"),e=this.event.getTargetRanges()[0];this.withTargetDOMRange(e,(()=>{this.insertString(t,{updatePosition:!1})}))},insertText(){var t;return this.insertString(this.event.data||(null===(t=this.event.dataTransfer)||void 0===t?void 0:t.getData("text/plain")))},insertTranspose(){return this.insertString(this.event.data)},insertUnorderedList(){return this.toggleAttributeIfSupported("bullet")}});const yr=function(t){const e=document.createRange();return e.setStart(t.startContainer,t.startOffset),e.setEnd(t.endContainer,t.endOffset),e},xr=t=>{var e;return Array.from((null===(e=t.dataTransfer)||void 0===e?void 0:e.types)||[]).includes("Files")},Cr=t=>{var e;return(null===(e=t.dataTransfer.files)||void 0===e?void 0:e[0])&&!Er(t)&&!(t=>{let{dataTransfer:e}=t;return e.types.includes("Files")&&e.types.includes("text/html")&&e.getData("text/html").includes("urn:schemas-microsoft-com:office:office")})(t)},Er=function(t){const e=t.clipboardData;if(e)return Array.from(e.types).filter((t=>t.match(/file/i))).length===e.types.length&&e.files.length>=1},Sr=function(t){const e=t.clipboardData;if(e)return e.types.includes("text/plain")&&1===e.types.length},Rr=function(t){const e=[];return t.altKey&&e.push("alt"),t.shiftKey&&e.push("shift"),e.push(t.key),e},kr=t=>({x:t.clientX,y:t.clientY}),Tr="[data-trix-attribute]",wr="[data-trix-action]",Lr="".concat(Tr,", ").concat(wr),Dr="[data-trix-dialog]",Nr="".concat(Dr,"[data-trix-active]"),Ir="".concat(Dr," [data-trix-method]"),Or="".concat(Dr," [data-trix-input]"),Fr=(t,e)=>(e||(e=Mr(t)),t.querySelector("[data-trix-input][name='".concat(e,"']"))),Pr=t=>t.getAttribute("data-trix-action"),Mr=t=>t.getAttribute("data-trix-attribute")||t.getAttribute("data-trix-dialog-attribute");class Br extends q{constructor(t){super(t),this.didClickActionButton=this.didClickActionButton.bind(this),this.didClickAttributeButton=this.didClickAttributeButton.bind(this),this.didClickDialogButton=this.didClickDialogButton.bind(this),this.didKeyDownDialogInput=this.didKeyDownDialogInput.bind(this),this.element=t,this.attributes={},this.actions={},this.resetDialogInputs(),b("mousedown",{onElement:this.element,matchingSelector:wr,withCallback:this.didClickActionButton}),b("mousedown",{onElement:this.element,matchingSelector:Tr,withCallback:this.didClickAttributeButton}),b("click",{onElement:this.element,matchingSelector:Lr,preventDefault:!0}),b("click",{onElement:this.element,matchingSelector:Ir,withCallback:this.didClickDialogButton}),b("keydown",{onElement:this.element,matchingSelector:Or,withCallback:this.didKeyDownDialogInput})}didClickActionButton(t,e){var i;null===(i=this.delegate)||void 0===i||i.toolbarDidClickButton(),t.preventDefault();const n=Pr(e);return this.getDialog(n)?this.toggleDialog(n):null===(r=this.delegate)||void 0===r?void 0:r.toolbarDidInvokeAction(n,e);var r}didClickAttributeButton(t,e){var i;null===(i=this.delegate)||void 0===i||i.toolbarDidClickButton(),t.preventDefault();const n=Mr(e);var r;this.getDialog(n)?this.toggleDialog(n):null===(r=this.delegate)||void 0===r||r.toolbarDidToggleAttribute(n);return this.refreshAttributeButtons()}didClickDialogButton(t,e){const i=y(e,{matchingSelector:Dr});return this[e.getAttribute("data-trix-method")].call(this,i)}didKeyDownDialogInput(t,e){if(13===t.keyCode){t.preventDefault();const i=e.getAttribute("name"),n=this.getDialog(i);this.setAttribute(n)}if(27===t.keyCode)return t.preventDefault(),this.hideDialog()}updateActions(t){return this.actions=t,this.refreshActionButtons()}refreshActionButtons(){return this.eachActionButton(((t,e)=>{t.disabled=!1===this.actions[e]}))}eachActionButton(t){return Array.from(this.element.querySelectorAll(wr)).map((e=>t(e,Pr(e))))}updateAttributes(t){return this.attributes=t,this.refreshAttributeButtons()}refreshAttributeButtons(){return this.eachAttributeButton(((t,e)=>(t.disabled=!1===this.attributes[e],this.attributes[e]||this.dialogIsVisible(e)?(t.setAttribute("data-trix-active",""),t.classList.add("trix-active")):(t.removeAttribute("data-trix-active"),t.classList.remove("trix-active")))))}eachAttributeButton(t){return Array.from(this.element.querySelectorAll(Tr)).map((e=>t(e,Mr(e))))}applyKeyboardCommand(t){const e=JSON.stringify(t.sort());for(const t of Array.from(this.element.querySelectorAll("[data-trix-key]"))){const i=t.getAttribute("data-trix-key").split("+");if(JSON.stringify(i.sort())===e)return v("mousedown",{onElement:t}),!0}return!1}dialogIsVisible(t){const e=this.getDialog(t);if(e)return e.hasAttribute("data-trix-active")}toggleDialog(t){return this.dialogIsVisible(t)?this.hideDialog():this.showDialog(t)}showDialog(t){var e,i;this.hideDialog(),null===(e=this.delegate)||void 0===e||e.toolbarWillShowDialog();const n=this.getDialog(t);n.setAttribute("data-trix-active",""),n.classList.add("trix-active"),Array.from(n.querySelectorAll("input[disabled]")).forEach((t=>{t.removeAttribute("disabled")}));const r=Mr(n);if(r){const e=Fr(n,t);e&&(e.value=this.attributes[r]||"",e.select())}return null===(i=this.delegate)||void 0===i?void 0:i.toolbarDidShowDialog(t)}setAttribute(t){var e;const i=Mr(t),n=Fr(t,i);return!n.willValidate||(n.setCustomValidity(""),n.checkValidity()&&this.isSafeAttribute(n))?(null===(e=this.delegate)||void 0===e||e.toolbarDidUpdateAttribute(i,n.value),this.hideDialog()):(n.setCustomValidity("Invalid value"),n.setAttribute("data-trix-validate",""),n.classList.add("trix-validate"),n.focus())}isSafeAttribute(t){return!t.hasAttribute("data-trix-validate-href")||li.isValidAttribute("a","href",t.value)}removeAttribute(t){var e;const i=Mr(t);return null===(e=this.delegate)||void 0===e||e.toolbarDidRemoveAttribute(i),this.hideDialog()}hideDialog(){const t=this.element.querySelector(Nr);var e;if(t)return t.removeAttribute("data-trix-active"),t.classList.remove("trix-active"),this.resetDialogInputs(),null===(e=this.delegate)||void 0===e?void 0:e.toolbarDidHideDialog((t=>t.getAttribute("data-trix-dialog"))(t))}resetDialogInputs(){Array.from(this.element.querySelectorAll(Or)).forEach((t=>{t.setAttribute("disabled","disabled"),t.removeAttribute("data-trix-validate"),t.classList.remove("trix-validate")}))}getDialog(t){return this.element.querySelector("[data-trix-dialog=".concat(t,"]"))}}class _r extends $n{constructor(t){let{editorElement:e,document:i,html:n}=t;super(...arguments),this.editorElement=e,this.selectionManager=new Vn(this.editorElement),this.selectionManager.delegate=this,this.composition=new wn,this.composition.delegate=this,this.attachmentManager=new kn(this.composition.getAttachments()),this.attachmentManager.delegate=this,this.inputController=2===_.getLevel()?new Ar(this.editorElement):new gr(this.editorElement),this.inputController.delegate=this,this.inputController.responder=this.composition,this.compositionController=new Xn(this.editorElement,this.composition),this.compositionController.delegate=this,this.toolbarController=new Br(this.editorElement.toolbarElement),this.toolbarController.delegate=this,this.editor=new Pn(this.composition,this.selectionManager,this.editorElement),i?this.editor.loadDocument(i):this.editor.loadHTML(n)}registerSelectionManager(){return Ft.registerSelectionManager(this.selectionManager)}unregisterSelectionManager(){return Ft.unregisterSelectionManager(this.selectionManager)}render(){return this.compositionController.render()}reparse(){return this.composition.replaceHTML(this.editorElement.innerHTML)}compositionDidChangeDocument(t){if(this.notifyEditorElement("document-change"),!this.handlingInput)return this.render()}compositionDidChangeCurrentAttributes(t){return this.currentAttributes=t,this.toolbarController.updateAttributes(this.currentAttributes),this.updateCurrentActions(),this.notifyEditorElement("attributes-change",{attributes:this.currentAttributes})}compositionDidPerformInsertionAtRange(t){this.pasting&&(this.pastedRange=t)}compositionShouldAcceptFile(t){return this.notifyEditorElement("file-accept",{file:t})}compositionDidAddAttachment(t){const e=this.attachmentManager.manageAttachment(t);return this.notifyEditorElement("attachment-add",{attachment:e})}compositionDidEditAttachment(t){this.compositionController.rerenderViewForObject(t);const e=this.attachmentManager.manageAttachment(t);return this.notifyEditorElement("attachment-edit",{attachment:e}),this.notifyEditorElement("change")}compositionDidChangeAttachmentPreviewURL(t){return this.compositionController.invalidateViewForObject(t),this.notifyEditorElement("change")}compositionDidRemoveAttachment(t){const e=this.attachmentManager.unmanageAttachment(t);return this.notifyEditorElement("attachment-remove",{attachment:e})}compositionDidStartEditingAttachment(t,e){return this.attachmentLocationRange=this.composition.document.getLocationRangeOfAttachment(t),this.compositionController.installAttachmentEditorForAttachment(t,e),this.selectionManager.setLocationRange(this.attachmentLocationRange)}compositionDidStopEditingAttachment(t){this.compositionController.uninstallAttachmentEditor(),this.attachmentLocationRange=null}compositionDidRequestChangingSelectionToLocationRange(t){if(!this.loadingSnapshot||this.isFocused())return this.requestedLocationRange=t,this.compositionRevisionWhenLocationRangeRequested=this.composition.revision,this.handlingInput?void 0:this.render()}compositionWillLoadSnapshot(){this.loadingSnapshot=!0}compositionDidLoadSnapshot(){this.compositionController.refreshViewCache(),this.render(),this.loadingSnapshot=!1}getSelectionManager(){return this.selectionManager}attachmentManagerDidRequestRemovalOfAttachment(t){return this.removeAttachment(t)}compositionControllerWillSyncDocumentView(){return this.inputController.editorWillSyncDocumentView(),this.selectionManager.lock(),this.selectionManager.clearSelection()}compositionControllerDidSyncDocumentView(){return this.inputController.editorDidSyncDocumentView(),this.selectionManager.unlock(),this.updateCurrentActions(),this.notifyEditorElement("sync")}compositionControllerDidRender(){this.requestedLocationRange&&(this.compositionRevisionWhenLocationRangeRequested===this.composition.revision&&this.selectionManager.setLocationRange(this.requestedLocationRange),this.requestedLocationRange=null,this.compositionRevisionWhenLocationRangeRequested=null),this.renderedCompositionRevision!==this.composition.revision&&(this.runEditorFilters(),this.composition.updateCurrentAttributes(),this.notifyEditorElement("render")),this.renderedCompositionRevision=this.composition.revision}compositionControllerDidFocus(){return this.isFocusedInvisibly()&&this.setLocationRange({index:0,offset:0}),this.toolbarController.hideDialog(),this.notifyEditorElement("focus")}compositionControllerDidBlur(){return this.notifyEditorElement("blur")}compositionControllerDidSelectAttachment(t,e){return this.toolbarController.hideDialog(),this.composition.editAttachment(t,e)}compositionControllerDidRequestDeselectingAttachment(t){const e=this.attachmentLocationRange||this.composition.document.getLocationRangeOfAttachment(t);return this.selectionManager.setLocationRange(e[1])}compositionControllerWillUpdateAttachment(t){return this.editor.recordUndoEntry("Edit Attachment",{context:t.id,consolidatable:!0})}compositionControllerDidRequestRemovalOfAttachment(t){return this.removeAttachment(t)}inputControllerWillHandleInput(){this.handlingInput=!0,this.requestedRender=!1}inputControllerDidRequestRender(){this.requestedRender=!0}inputControllerDidHandleInput(){if(this.handlingInput=!1,this.requestedRender)return this.requestedRender=!1,this.render()}inputControllerDidAllowUnhandledInput(){return this.notifyEditorElement("change")}inputControllerDidRequestReparse(){return this.reparse()}inputControllerWillPerformTyping(){return this.recordTypingUndoEntry()}inputControllerWillPerformFormatting(t){return this.recordFormattingUndoEntry(t)}inputControllerWillCutText(){return this.editor.recordUndoEntry("Cut")}inputControllerWillPaste(t){return this.editor.recordUndoEntry("Paste"),this.pasting=!0,this.notifyEditorElement("before-paste",{paste:t})}inputControllerDidPaste(t){return t.range=this.pastedRange,this.pastedRange=null,this.pasting=null,this.notifyEditorElement("paste",{paste:t})}inputControllerWillMoveText(){return this.editor.recordUndoEntry("Move")}inputControllerWillAttachFiles(){return this.editor.recordUndoEntry("Drop Files")}inputControllerWillPerformUndo(){return this.editor.undo()}inputControllerWillPerformRedo(){return this.editor.redo()}inputControllerDidReceiveKeyboardCommand(t){return this.toolbarController.applyKeyboardCommand(t)}inputControllerDidStartDrag(){this.locationRangeBeforeDrag=this.selectionManager.getLocationRange()}inputControllerDidReceiveDragOverPoint(t){return this.selectionManager.setLocationRangeFromPointRange(t)}inputControllerDidCancelDrag(){this.selectionManager.setLocationRange(this.locationRangeBeforeDrag),this.locationRangeBeforeDrag=null}locationRangeDidChange(t){return this.composition.updateCurrentAttributes(),this.updateCurrentActions(),this.attachmentLocationRange&&!Dt(this.attachmentLocationRange,t)&&this.composition.stopEditingAttachment(),this.notifyEditorElement("selection-change")}toolbarDidClickButton(){if(!this.getLocationRange())return this.setLocationRange({index:0,offset:0})}toolbarDidInvokeAction(t,e){return this.invokeAction(t,e)}toolbarDidToggleAttribute(t){if(this.recordFormattingUndoEntry(t),this.composition.toggleCurrentAttribute(t),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarDidUpdateAttribute(t,e){if(this.recordFormattingUndoEntry(t),this.composition.setCurrentAttribute(t,e),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarDidRemoveAttribute(t){if(this.recordFormattingUndoEntry(t),this.composition.removeCurrentAttribute(t),this.render(),!this.selectionFrozen)return this.editorElement.focus()}toolbarWillShowDialog(t){return this.composition.expandSelectionForEditing(),this.freezeSelection()}toolbarDidShowDialog(t){return this.notifyEditorElement("toolbar-dialog-show",{dialogName:t})}toolbarDidHideDialog(t){return this.thawSelection(),this.editorElement.focus(),this.notifyEditorElement("toolbar-dialog-hide",{dialogName:t})}freezeSelection(){if(!this.selectionFrozen)return this.selectionManager.lock(),this.composition.freezeSelection(),this.selectionFrozen=!0,this.render()}thawSelection(){if(this.selectionFrozen)return this.composition.thawSelection(),this.selectionManager.unlock(),this.selectionFrozen=!1,this.render()}canInvokeAction(t){return!!this.actionIsExternal(t)||!(null===(e=this.actions[t])||void 0===e||null===(e=e.test)||void 0===e||!e.call(this));var e}invokeAction(t,e){return this.actionIsExternal(t)?this.notifyEditorElement("action-invoke",{actionName:t,invokingElement:e}):null===(i=this.actions[t])||void 0===i||null===(i=i.perform)||void 0===i?void 0:i.call(this);var i}actionIsExternal(t){return/^x-./.test(t)}getCurrentActions(){const t={};for(const e in this.actions)t[e]=this.canInvokeAction(e);return t}updateCurrentActions(){const t=this.getCurrentActions();if(!Tt(t,this.currentActions))return this.currentActions=t,this.toolbarController.updateActions(this.currentActions),this.notifyEditorElement("actions-change",{actions:this.currentActions})}runEditorFilters(){let t=this.composition.getSnapshot();if(Array.from(this.editor.filters).forEach((e=>{const{document:i,selectedRange:n}=t;t=e.call(this.editor,t)||{},t.document||(t.document=i),t.selectedRange||(t.selectedRange=n)})),e=t,i=this.composition.getSnapshot(),!Dt(e.selectedRange,i.selectedRange)||!e.document.isEqualTo(i.document))return this.composition.loadSnapshot(t);var e,i}updateInputElement(){const t=function(t,e){const i=En[e];if(i)return i(t);throw new Error("unknown content type: ".concat(e))}(this.compositionController.getSerializableElement(),"text/html");return this.editorElement.setFormValue(t)}notifyEditorElement(t,e){switch(t){case"document-change":this.documentChangedSinceLastRender=!0;break;case"render":this.documentChangedSinceLastRender&&(this.documentChangedSinceLastRender=!1,this.notifyEditorElement("change"));break;case"change":case"attachment-add":case"attachment-edit":case"attachment-remove":this.updateInputElement()}return this.editorElement.notify(t,e)}removeAttachment(t){return this.editor.recordUndoEntry("Delete Attachment"),this.composition.removeAttachment(t),this.render()}recordFormattingUndoEntry(t){const e=mt(t),i=this.selectionManager.getLocationRange();if(e||!Lt(i))return this.editor.recordUndoEntry("Formatting",{context:this.getUndoContext(),consolidatable:!0})}recordTypingUndoEntry(){return this.editor.recordUndoEntry("Typing",{context:this.getUndoContext(this.currentAttributes),consolidatable:!0})}getUndoContext(){for(var t=arguments.length,e=new Array(t),i=0;i0?Math.floor((new Date).getTime()/V.interval):0}isFocused(){var t;return this.editorElement===(null===(t=this.editorElement.ownerDocument)||void 0===t?void 0:t.activeElement)}isFocusedInvisibly(){return this.isFocused()&&!this.getLocationRange()}get actions(){return this.constructor.actions}}Di(_r,"actions",{undo:{test(){return this.editor.canUndo()},perform(){return this.editor.undo()}},redo:{test(){return this.editor.canRedo()},perform(){return this.editor.redo()}},link:{test(){return this.editor.canActivateAttribute("href")}},increaseNestingLevel:{test(){return this.editor.canIncreaseNestingLevel()},perform(){return this.editor.increaseNestingLevel()&&this.render()}},decreaseNestingLevel:{test(){return this.editor.canDecreaseNestingLevel()},perform(){return this.editor.decreaseNestingLevel()&&this.render()}},attachFiles:{test:()=>!0,perform(){return _.pickFiles(this.editor.insertFiles)}}}),_r.proxyMethod("getSelectionManager().setLocationRange"),_r.proxyMethod("getSelectionManager().getLocationRange");var jr=Object.freeze({__proto__:null,AttachmentEditorController:Yn,CompositionController:Xn,Controller:$n,EditorController:_r,InputController:lr,Level0InputController:gr,Level2InputController:Ar,ToolbarController:Br}),Wr=Object.freeze({__proto__:null,MutationObserver:er,SelectionChangeObserver:Ot}),Ur=Object.freeze({__proto__:null,FileVerificationOperation:nr,ImagePreloadOperation:Ui});vt("trix-toolbar","%t {\n display: block;\n}\n\n%t {\n white-space: nowrap;\n}\n\n%t [data-trix-dialog] {\n display: none;\n}\n\n%t [data-trix-dialog][data-trix-active] {\n display: block;\n}\n\n%t [data-trix-dialog] [data-trix-validate]:invalid {\n background-color: #ffdddd;\n}");class Vr extends HTMLElement{connectedCallback(){""===this.innerHTML&&(this.innerHTML=U.getDefaultHTML())}}let qr=0;const Hr=function(t){if(!t.hasAttribute("contenteditable"))return t.setAttribute("contenteditable",""),function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.times=1,b(t,e)}("focus",{onElement:t,withCallback:()=>zr(t)})},zr=function(t){return Jr(t),Kr(t)},Jr=function(t){var e,i;if(null!==(e=(i=document).queryCommandSupported)&&void 0!==e&&e.call(i,"enableObjectResizing"))return document.execCommand("enableObjectResizing",!1,!1),b("mscontrolselect",{onElement:t,preventDefault:!0})},Kr=function(t){var e,i;if(null!==(e=(i=document).queryCommandSupported)&&void 0!==e&&e.call(i,"DefaultParagraphSeparator")){const{tagName:t}=n.default;if(["div","p"].includes(t))return document.execCommand("DefaultParagraphSeparator",!1,t)}},Gr=a.forcesObjectResizing?{display:"inline",width:"auto"}:{display:"inline-block",width:"1px"};vt("trix-editor","%t {\n display: block;\n}\n\n%t:empty::before {\n content: attr(placeholder);\n color: graytext;\n cursor: text;\n pointer-events: none;\n white-space: pre-line;\n}\n\n%t a[contenteditable=false] {\n cursor: text;\n}\n\n%t img {\n max-width: 100%;\n height: auto;\n}\n\n%t ".concat(e," figcaption textarea {\n resize: none;\n}\n\n%t ").concat(e," figcaption textarea.trix-autoresize-clone {\n position: absolute;\n left: -9999px;\n max-height: 0px;\n}\n\n%t ").concat(e," figcaption[data-trix-placeholder]:empty::before {\n content: attr(data-trix-placeholder);\n color: graytext;\n}\n\n%t [data-trix-cursor-target] {\n display: ").concat(Gr.display," !important;\n width: ").concat(Gr.width," !important;\n padding: 0 !important;\n margin: 0 !important;\n border: none !important;\n}\n\n%t [data-trix-cursor-target=left] {\n vertical-align: top !important;\n margin-left: -1px !important;\n}\n\n%t [data-trix-cursor-target=right] {\n vertical-align: bottom !important;\n margin-right: -1px !important;\n}"));var Yr=new WeakMap,Xr=new WeakSet;class $r{constructor(t){var e,i;_i(e=this,i=Xr),i.add(e),ji(this,Yr,{writable:!0,value:void 0}),this.element=t,Oi(this,Yr,t.attachInternals())}connectedCallback(){Bi(this,Xr,Zr).call(this)}disconnectedCallback(){}get labels(){return Ii(this,Yr).labels}get disabled(){var t;return null===(t=this.element.inputElement)||void 0===t?void 0:t.disabled}set disabled(t){this.element.toggleAttribute("disabled",t)}get required(){return this.element.hasAttribute("required")}set required(t){this.element.toggleAttribute("required",t),Bi(this,Xr,Zr).call(this)}get validity(){return Ii(this,Yr).validity}get validationMessage(){return Ii(this,Yr).validationMessage}get willValidate(){return Ii(this,Yr).willValidate}setFormValue(t){Bi(this,Xr,Zr).call(this)}checkValidity(){return Ii(this,Yr).checkValidity()}reportValidity(){return Ii(this,Yr).reportValidity()}setCustomValidity(t){Bi(this,Xr,Zr).call(this,t)}}function Zr(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const{required:e,value:i}=this.element,n=e&&!i,r=!!t,o=T("input",{required:e}),s=t||o.validationMessage;Ii(this,Yr).setValidity({valueMissing:n,customError:r},s)}var Qr=new WeakMap,to=new WeakMap,eo=new WeakMap;class io{constructor(t){ji(this,Qr,{writable:!0,value:void 0}),ji(this,to,{writable:!0,value:t=>{t.defaultPrevented||t.target===this.element.form&&this.element.reset()}}),ji(this,eo,{writable:!0,value:t=>{if(t.defaultPrevented)return;if(this.element.contains(t.target))return;const e=y(t.target,{matchingSelector:"label"});e&&Array.from(this.labels).includes(e)&&this.element.focus()}}),this.element=t}connectedCallback(){Oi(this,Qr,function(t){if(t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"))return;const e=function(){const e=Array.from(t.labels).map((e=>{if(!e.contains(t))return e.textContent})).filter((t=>t)),i=e.join(" ");return i?t.setAttribute("aria-label",i):t.removeAttribute("aria-label")};return e(),b("focus",{onElement:t,withCallback:e})}(this.element)),window.addEventListener("reset",Ii(this,to),!1),window.addEventListener("click",Ii(this,eo),!1)}disconnectedCallback(){var t;null===(t=Ii(this,Qr))||void 0===t||t.destroy(),window.removeEventListener("reset",Ii(this,to),!1),window.removeEventListener("click",Ii(this,eo),!1)}get labels(){const t=[];this.element.id&&this.element.ownerDocument&&t.push(...Array.from(this.element.ownerDocument.querySelectorAll("label[for='".concat(this.element.id,"']"))||[]));const e=y(this.element,{matchingSelector:"label"});return e&&[this.element,null].includes(e.control)&&t.push(e),t}get disabled(){return console.warn("This browser does not support the [disabled] attribute for trix-editor elements."),!1}set disabled(t){console.warn("This browser does not support the [disabled] attribute for trix-editor elements.")}get required(){return console.warn("This browser does not support the [required] attribute for trix-editor elements."),!1}set required(t){console.warn("This browser does not support the [required] attribute for trix-editor elements.")}get validity(){return console.warn("This browser does not support the validity property for trix-editor elements."),null}get validationMessage(){return console.warn("This browser does not support the validationMessage property for trix-editor elements."),""}get willValidate(){return console.warn("This browser does not support the willValidate property for trix-editor elements."),!1}setFormValue(t){}checkValidity(){return console.warn("This browser does not support checkValidity() for trix-editor elements."),!0}reportValidity(){return console.warn("This browser does not support reportValidity() for trix-editor elements."),!0}setCustomValidity(t){console.warn("This browser does not support setCustomValidity(validationMessage) for trix-editor elements.")}}var no=new WeakMap;class ro extends HTMLElement{constructor(){super(),ji(this,no,{writable:!0,value:void 0}),Oi(this,no,this.constructor.formAssociated?new $r(this):new io(this))}get trixId(){return this.hasAttribute("trix-id")?this.getAttribute("trix-id"):(this.setAttribute("trix-id",++qr),this.trixId)}get labels(){return Ii(this,no).labels}get disabled(){return Ii(this,no).disabled}set disabled(t){Ii(this,no).disabled=t}get required(){return Ii(this,no).required}set required(t){Ii(this,no).required=t}get validity(){return Ii(this,no).validity}get validationMessage(){return Ii(this,no).validationMessage}get willValidate(){return Ii(this,no).willValidate}get type(){return this.localName}get toolbarElement(){var t;if(this.hasAttribute("toolbar"))return null===(t=this.ownerDocument)||void 0===t?void 0:t.getElementById(this.getAttribute("toolbar"));if(this.parentNode){const t="trix-toolbar-".concat(this.trixId);return this.setAttribute("toolbar",t),this.internalToolbar=T("trix-toolbar",{id:t}),this.parentNode.insertBefore(this.internalToolbar,this),this.internalToolbar}}get form(){var t;return null===(t=this.inputElement)||void 0===t?void 0:t.form}get inputElement(){var t;if(this.hasAttribute("input"))return null===(t=this.ownerDocument)||void 0===t?void 0:t.getElementById(this.getAttribute("input"));if(this.parentNode){const t="trix-input-".concat(this.trixId);this.setAttribute("input",t);const e=T("input",{type:"hidden",id:t});return this.parentNode.insertBefore(e,this.nextElementSibling),e}}get editor(){var t;return null===(t=this.editorController)||void 0===t?void 0:t.editor}get name(){var t;return null===(t=this.inputElement)||void 0===t?void 0:t.name}get value(){var t;return null===(t=this.inputElement)||void 0===t?void 0:t.value}set value(t){var e;this.defaultValue=t,null===(e=this.editor)||void 0===e||e.loadHTML(this.defaultValue)}attributeChangedCallback(t,e,i){"connected"===t&&this.isConnected&&null!=e&&e!==i&&requestAnimationFrame((()=>this.reconnect()))}notify(t,e){if(this.editorController)return v("trix-".concat(t),{onElement:this,attributes:e})}setFormValue(t){this.inputElement&&(this.inputElement.value=t,Ii(this,no).setFormValue(t))}connectedCallback(){this.hasAttribute("data-trix-internal")||(Hr(this),function(t){t.hasAttribute("role")||t.setAttribute("role","textbox")}(this),this.editorController||(v("trix-before-initialize",{onElement:this}),this.editorController=new _r({editorElement:this,html:this.defaultValue=this.value}),requestAnimationFrame((()=>v("trix-initialize",{onElement:this})))),this.editorController.registerSelectionManager(),Ii(this,no).connectedCallback(),this.toggleAttribute("connected",!0),function(t){!document.querySelector(":focus")&&t.hasAttribute("autofocus")&&document.querySelector("[autofocus]")===t&&t.focus()}(this))}disconnectedCallback(){var t;null===(t=this.editorController)||void 0===t||t.unregisterSelectionManager(),Ii(this,no).disconnectedCallback(),this.toggleAttribute("connected",!1)}reconnect(){this.removeInternalToolbar(),this.disconnectedCallback(),this.connectedCallback()}removeInternalToolbar(){var t;null===(t=this.internalToolbar)||void 0===t||t.remove(),this.internalToolbar=null}checkValidity(){return Ii(this,no).checkValidity()}reportValidity(){return Ii(this,no).reportValidity()}setCustomValidity(t){Ii(this,no).setCustomValidity(t)}formDisabledCallback(t){this.inputElement&&(this.inputElement.disabled=t),this.toggleAttribute("contenteditable",!t)}formResetCallback(){this.reset()}reset(){this.value=this.defaultValue}}Di(ro,"formAssociated","ElementInternals"in window),Di(ro,"observedAttributes",["connected"]);const oo={VERSION:t,config:H,core:Sn,models:qn,views:Hn,controllers:jr,observers:Wr,operations:Ur,elements:Object.freeze({__proto__:null,TrixEditorElement:ro,TrixToolbarElement:Vr}),filters:Object.freeze({__proto__:null,Filter:In,attachmentGalleryFilter:On})};Object.assign(oo,qn),window.Trix=oo,setTimeout((function(){customElements.get("trix-toolbar")||customElements.define("trix-toolbar",Vr),customElements.get("trix-editor")||customElements.define("trix-editor",ro)}),0);export{oo as default};