/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../core/dist/index.js"),e=require("../../../linkifyjs/dist/linkify.js"),o=require("../../../prosemirror-state/dist/index.js");var n="[\0-   ᠎ -\u2029 　]",i=new RegExp(n),s=new RegExp(`${n}$`),r=new RegExp(n,"g");function l(t,e){const o=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(t=>{const e="string"==typeof t?t:t.scheme;e&&o.push(e)}),!t||t.replace(r,"").match(new RegExp(`^(?:(?:${o.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var a=t.Mark.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(t=>{"string"!=typeof t?e.registerCustomProtocol(t.scheme,t.optionalSlashes):e.registerCustomProtocol(t)})},onDestroy(){e.reset()},inclusive(){return this.options.autolink},addOptions:()=>({openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(t,e)=>!!l(t,e.protocols),validate:t=>!!t,shouldAutoLink:t=>{const e=/^[a-z][a-z0-9+.-]*:\/\//i.test(t),o=/^[a-z][a-z0-9+.-]*:/i.test(t);if(e||o&&!t.includes("@"))return!0;const n=(t.includes("@")?t.split("@").pop():t).split(/[/?#:]/)[0];return!/^\d{1,3}(\.\d{1,3}){3}$/.test(n)&&!!/\./.test(n)}}),addAttributes(){return{href:{default:null,parseHTML:t=>t.getAttribute("href")},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:"a[href]",getAttrs:t=>{const e=t.getAttribute("href");return!(!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!l(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}))&&null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:t=>!!l(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",t.mergeAttributes(this.options.HTMLAttributes,e),0]:["a",t.mergeAttributes(this.options.HTMLAttributes,{...e,href:""}),0]},markdownTokenName:"link",parseMarkdown:(t,e)=>e.applyMark("link",e.parseInline(t.tokens||[]),{href:t.href,title:t.title||null}),renderMarkdown:(t,e)=>{var o,n,i,s;const r=null!=(n=null==(o=t.attrs)?void 0:o.href)?n:"",l=null!=(s=null==(i=t.attrs)?void 0:i.title)?s:"",a=e.renderChildren(t);return l?`[${a}](${r} "${l}")`:`[${a}](${r})`},addCommands(){return{setLink:t=>({chain:e})=>{const{href:o}=t;return!!this.options.isAllowedUri(o,{defaultValidate:t=>!!l(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&e().setMark(this.name,t).setMeta("preventAutolink",!0).run()},toggleLink:t=>({chain:e})=>{const{href:o}=t||{};return!(o&&!this.options.isAllowedUri(o,{defaultValidate:t=>!!l(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}))&&e().toggleMark(this.name,t,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:t})=>t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[t.markPasteRule({find:t=>{const o=[];if(t){const{protocols:n,defaultProtocol:i}=this.options,s=e.find(t).filter(t=>t.isLink&&this.options.isAllowedUri(t.value,{defaultValidate:t=>!!l(t,n),protocols:n,defaultProtocol:i}));s.length&&s.forEach(t=>{this.options.shouldAutoLink(t.value)&&o.push({text:t.value,data:{href:t.href},index:t.start})})}return o},type:this.type,getAttributes:t=>{var e;return{href:null==(e=t.data)?void 0:e.href}}})]},addProseMirrorPlugins(){const n=[],{protocols:r,defaultProtocol:a}=this.options;var u;return this.options.autolink&&n.push((u={type:this.type,defaultProtocol:this.options.defaultProtocol,validate:t=>this.options.isAllowedUri(t,{defaultValidate:t=>!!l(t,r),protocols:r,defaultProtocol:a}),shouldAutoLink:this.options.shouldAutoLink},new o.Plugin({key:new o.PluginKey("autolink"),appendTransaction:(o,n,r)=>{const l=o.some(t=>t.docChanged)&&!n.doc.eq(r.doc),a=o.some(t=>t.getMeta("preventAutolink"));if(!l||a)return;const{tr:d}=r,p=t.combineTransactionSteps(n.doc,[...o]);return t.getChangedRanges(p).forEach(({newRange:o})=>{const n=t.findChildrenInRange(r.doc,o,t=>t.isTextblock);let l,a;if(n.length>1)l=n[0],a=r.doc.textBetween(l.pos,l.pos+l.node.nodeSize,void 0," ");else if(n.length){const t=r.doc.textBetween(o.from,o.to," "," ");if(!s.test(t))return;l=n[0],a=r.doc.textBetween(l.pos,o.to,void 0," ")}if(l&&a){const o=a.split(i).filter(Boolean);if(o.length<=0)return!1;const n=o[o.length-1],s=l.pos+a.lastIndexOf(n);if(!n)return!1;const c=e.tokenize(n).map(t=>t.toObject(u.defaultProtocol));if(!(1===(p=c).length?p[0].isLink:3===p.length&&p[1].isLink&&["()","[]"].includes(p[0].value+p[2].value)))return!1;c.filter(t=>t.isLink).map(t=>({...t,from:s+t.start+1,to:s+t.end+1})).filter(t=>!r.schema.marks.code||!r.doc.rangeHasMark(t.from,t.to,r.schema.marks.code)).filter(t=>u.validate(t.value)).filter(t=>u.shouldAutoLink(t.value)).forEach(e=>{t.getMarksBetween(e.from,e.to,r.doc).some(t=>t.mark.type===u.type)||d.addMark(e.from,e.to,u.type.create({href:e.href}))})}var p}),d.steps.length?d:void 0}}))),n.push(function(e){return new o.Plugin({key:new o.PluginKey("handleClickLink"),props:{handleClick:(o,n,i)=>{var s,r;if(0!==i.button)return!1;if(!o.editable)return!1;let l=null;if(i.target instanceof HTMLAnchorElement)l=i.target;else{const t=i.target;if(!t)return!1;const o=e.editor.view.dom;l=t.closest("a"),l&&!o.contains(l)&&(l=null)}if(!l)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){const n=t.getAttributes(o.state,e.type.name),i=null!=(s=l.href)?s:n.href,u=null!=(r=l.target)?r:n.target;i&&(window.open(i,u),a=!0)}return a}}})}({type:this.type,editor:this.editor,openOnClick:"whenNotEditable"===this.options.openOnClick||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(function(t){return new o.Plugin({key:new o.PluginKey("handlePasteLink"),props:{handlePaste:(o,n,i)=>{const{shouldAutoLink:s}=t,{state:r}=o,{selection:l}=r,{empty:a}=l;if(a)return!1;let u="";i.content.forEach(t=>{u+=t.textContent});const d=e.find(u,{defaultProtocol:t.defaultProtocol}).find(t=>t.isLink&&t.value===u);return!(!u||!d||void 0!==s&&!s(d.value))&&t.editor.commands.setMark(t.type,{href:d.href})}}})}({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}});exports.Link=a,exports.isAllowedUri=l;