cwd-widget 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ <div align="center">
2
+
3
+ <img src="https://cwd.js.org/icon.png" width="111" />
4
+
5
+ # CWD (Cloudflare Workers Discuss)
6
+
7
+ [![GitHub release](https://img.shields.io/github/v/release/anghunk/cwd?display_name=tag&style=flat-square)](https://github.com/anghunk/cwd/releases)
8
+ [![GitHub stars](https://img.shields.io/github/stars/anghunk/cwd?style=flat-square)](https://github.com/anghunk/cwd)
9
+ [![License](https://img.shields.io/github/license/anghunk/cwd?style=flat-square)](./LICENSE)
10
+ [![Docs](https://img.shields.io/badge/Docs-cwd.js.org-brightgreen?style=flat-square)](https://cwd.js.org)
11
+ [![Discord](https://img.shields.io/badge/discord-join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/n2pErsD7Kg)
12
+
13
+ ![Cloudflare Workers](https://img.shields.io/badge/Cloudflare-Workers-F38020?logo=cloudflare&logoColor=white&style=flat-square)
14
+ ![Cloudflare D1](https://img.shields.io/badge/Cloudflare-D1-F38020?logo=cloudflare&logoColor=white&style=flat-square)
15
+ ![Node.js](https://img.shields.io/badge/node-%3E=20.0.0-339933?logo=node.js&logoColor=white&style=flat-square)
16
+
17
+ 基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。
18
+
19
+ 数据存储在 Cloudflare D1 数据库中,通过 Worker 与数据库交互。
20
+
21
+ [使用文档](https://cwd.js.org) · [Discord](https://discord.gg/n2pErsD7Kg)
22
+
23
+ </div>
package/dist/cwd.js ADDED
@@ -0,0 +1,3 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CWDComments={})}(this,function(e){"use strict";var t,n=Object.defineProperty,r=(e,t,r)=>((e,t,r)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);function i(e){const t=e.apiBaseUrl.replace(/\/$/,"");function n(){try{const e="cwd_like_uid";let t=localStorage.getItem(e);return t||(t="undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}_${Math.random().toString(16).slice(2)}`,localStorage.setItem(e,t)),t}catch(e){return"anonymous"}}return{fetchComments:async function(n=1,r=20){const i=new URLSearchParams({post_slug:e.postSlug,page:n.toString(),limit:r.toString(),nested:"true"});e.avatarPrefix&&i.set("avatar_prefix",e.avatarPrefix);const o=await fetch(`${t}/api/comments?${i}`);if(!o.ok)throw new Error(`获取评论失败:${o.status} ${o.statusText}`);return o.json()},submitComment:async function(n){const r=await fetch(`${t}/api/comments`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({post_slug:e.postSlug,post_title:e.postTitle,post_url:e.postUrl,name:n.name,email:n.email,url:n.url||void 0,content:n.content,parent_id:n.parentId,adminToken:n.adminToken})});if(!r.ok){let e=r.statusText;try{const t=await r.json();t.message&&(e=t.message)}catch(i){}throw new Error(e)}return r.json()},verifyAdminKey:async function(e){const n=await fetch(`${t}/api/verify-admin`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({adminToken:e})});if(!n.ok){let e=n.statusText;try{const t=await n.json();t.message&&(e=t.message)}catch(r){}throw new Error(e)}return n.json()},trackVisit:async function(){try{await fetch(`${t}/api/analytics/visit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({postSlug:e.postSlug,postTitle:e.postTitle,postUrl:e.postUrl})})}catch(n){}},getLikeStatus:async function(){const r=new URLSearchParams({post_slug:e.postSlug}),i={"X-CWD-Like-User":n()},o=await fetch(`${t}/api/like?${r.toString()}`,{method:"GET",headers:i});return o.ok?o.json():{liked:!1,alreadyLiked:!1,totalLikes:0}},likePage:async function(){const r={"Content-Type":"application/json","X-CWD-Like-User":n()},i=await fetch(`${t}/api/like`,{method:"POST",headers:r,body:JSON.stringify({postSlug:e.postSlug,postTitle:e.postTitle,postUrl:e.postUrl})});if(!i.ok){let e=i.statusText;try{const t=await i.json();t.message&&(e=t.message)}catch(o){}throw new Error(e)}return i.json()},likeComment:async function(e,n=!0){const r="number"==typeof e?e:"string"==typeof e&&e.trim()?Number.parseInt(e.trim(),10):NaN;if(!Number.isFinite(r)||r<=0)throw new Error("Invalid comment id");const i=n?"POST":"DELETE",o=await fetch(`${t}/api/comments/like`,{method:i,headers:{"Content-Type":"application/json"},body:JSON.stringify({id:r})});if(!o.ok){let e=o.statusText;try{const t=await o.json();t.message&&(e=t.message)}catch(s){}throw new Error(e)}return o.json()}}}const o="cwd_admin_auth",s="cwd-salt";function a(e){try{const t=e=>e.split("").map(e=>e.charCodeAt(0)),n=e=>("0"+Number(e).toString(16)).substr(-2),r=e=>t(s).reduce((e,t)=>e^t,e);return e.split("").map(t).map(r).map(n).join("")}catch(t){return btoa(e)}}const l={saveToken(e){const t={adminToken:a(e),timestamp:Date.now()};localStorage.setItem(o,JSON.stringify(t))},getToken(){try{const e=localStorage.getItem(o);if(!e)return null;const t=JSON.parse(e);return Date.now()-t.timestamp>2592e5?(this.clearToken(),null):function(e){try{const t=e=>e.split("").map(e=>e.charCodeAt(0)),n=e=>t(s).reduce((e,t)=>e^t,e);return e.match(/.{1,2}/g).map(e=>parseInt(e,16)).map(n).map(e=>String.fromCharCode(e)).join("")}catch(t){return atob(e)}}(t.adminToken)}catch(e){return this.clearToken(),null}},clearToken(){localStorage.removeItem(o)},hasToken(){return!!this.getToken()}},c="cwd_user_info";class d{constructor(e){this.state={...e},this.listeners=[]}getState(){return{...this.state}}setState(e){const t={...this.state};this.state={...this.state,...e},this.listeners.forEach(e=>{e(this.state,t)})}subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}}function p(e,t,n,r){const i=function(){try{const e=localStorage.getItem(c);if(e){const t=JSON.parse(e);return{name:t.name||"",email:t.email||"",url:t.url||""}}}catch(e){}return{name:"",email:"",url:""}}(),o=new d({comments:[],loading:!0,error:null,successMessage:"",pagination:{page:1,limit:e.pageSize||20,total:0,totalCount:0},form:{name:i.name||"",email:i.email||"",url:i.url||"",content:""},formErrors:{},submitting:!1,replyingTo:null,replyContent:"",replyError:null,likeCount:0,liked:!1,commentLikeLoadingId:null});async function s(e=1){o.setState({loading:!0,error:null});try{const n=await t(e,o.getState().pagination.limit);o.setState({comments:n.data,pagination:{page:n.pagination.page,limit:n.pagination.limit,total:n.pagination.total,totalCount:n.pagination.totalCount},loading:!1})}catch(n){o.setState({error:n instanceof Error?n.message:"加载评论失败",loading:!1})}}return o.subscribe(e=>{(e.form.name||e.form.email||e.form.url)&&function(e,t,n){try{const r={name:e,email:t,url:n};localStorage.setItem(c,JSON.stringify(r))}catch(r){}}(e.form.name,e.form.email,e.form.url)}),{store:o,getTotalPages:()=>o.getState().pagination.total,loadComments:s,submitNewComment:async function(){const t=o.getState(),r=t.form,{validateCommentForm:i}=await Promise.resolve().then(()=>Gt),a=i(r);if(!a.valid)return o.setState({formErrors:a.errors}),!1;o.setState({formErrors:{},submitting:!0,error:null,successMessage:""});try{const i=await n({name:r.name,email:r.email,url:r.url,content:r.content,adminToken:l.getToken()}),a=i&&"string"==typeof i.message?i.message:e.requireReview?"已提交评论,待管理员审核后显示":"评论已提交";return o.setState({form:{...r,content:""},submitting:!1,successMessage:a}),await s(t.pagination.page),!0}catch(c){return o.setState({error:c instanceof Error?c.message:"提交评论失败",submitting:!1,successMessage:""}),!1}},submitReply:async function(e){const t=o.getState();if(!t.replyContent.trim())return!1;const{validateReplyUserInfo:r}=await Promise.resolve().then(()=>Gt),i=r(t.form);if(!i.valid){const e=Object.values(i.errors).join(";");return o.setState({replyError:e}),!1}o.setState({formErrors:{},submitting:!0,replyError:null});try{return await n({name:t.form.name,email:t.form.email,url:t.form.url,content:t.replyContent,parentId:e,adminToken:l.getToken()}),o.setState({replyContent:"",replyingTo:null,submitting:!1}),await s(t.pagination.page),!0}catch(a){return o.setState({error:a instanceof Error?a.message:"提交回复失败",submitting:!1}),!1}},startReply:function(e){o.setState({replyingTo:e,replyContent:"",replyError:null})},cancelReply:function(){o.setState({replyingTo:null,replyContent:"",replyError:null})},updateFormField:function(e,t){const n={...o.getState().form};n[e]=t,o.setState({form:n})},updateReplyContent:function(e){o.setState({replyContent:e})},clearReplyError:function(){o.setState({replyError:null})},clearError:function(){o.setState({error:null})},clearSuccess:function(){o.setState({successMessage:""})},goToPage:function(e){const t=o.getState().pagination.total;e>=1&&e<=t&&s(e)},setLikeState:function(e,t){const n="number"==typeof e&&Number.isFinite(e)&&e>=0?e:0;o.setState({likeCount:n,liked:!!t})},likeComment:async function(e,t=!0){const n=o.getState();if(!r||n.commentLikeLoadingId===e)return;const i="number"==typeof e?e:"string"==typeof e&&e.trim()?Number.parseInt(e.trim(),10):NaN;if(Number.isFinite(i)&&!(i<=0)){o.setState({commentLikeLoadingId:i});try{const e=Array.isArray(n.comments)?n.comments:[],s=t?1:-1,a=e.map(e=>{if(!e||"number"!=typeof e.id)return e;if(e.id===i){const t="number"==typeof e.likes&&Number.isFinite(e.likes)&&e.likes>=0?e.likes:0,n=Math.max(0,t+s);return{...e,likes:n}}if(Array.isArray(e.replies)&&e.replies.length>0){const t=e.replies.map(e=>{if(!e||"number"!=typeof e.id)return e;if(e.id===i){const t="number"==typeof e.likes&&Number.isFinite(e.likes)&&e.likes>=0?e.likes:0,n=Math.max(0,t+s);return{...e,likes:n}}return e});return{...e,replies:t}}return e});o.setState({comments:a}),await r(i,t)}catch(s){}finally{o.getState().commentLikeLoadingId===i&&o.setState({commentLikeLoadingId:null})}}}}}class h{constructor(e,t={}){this.container="string"==typeof e?document.querySelector(e):e,this.props=t,this.state={},this.elements={},this.destroyed=!1}setState(e){if(this.destroyed)return;const t={...this.state};this.state="function"==typeof e?{...this.state,...e(t)}:{...this.state,...e},this.update(t)}setProps(e){if(this.destroyed)return;const t={...this.props};this.props={...this.props,...e},this.updateProps(t)}render(){}update(e){this.render()}updateProps(e){}destroy(){this.destroyed=!0,this.container&&this.elements.root&&this.elements.root.parentNode&&this.elements.root.parentNode.removeChild(this.elements.root),this.elements={}}createElement(e,t={}){const n=new Set(["svg","path","circle","rect","line","polyline","polygon","ellipse","g","defs","clipPath","mask","pattern","text","tspan","use","symbol","linearGradient","radialGradient","stop","filter"]).has(String(e).toLowerCase()),r=n?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);if(t.className&&(n?r.setAttribute("class",t.className):r.className=t.className),t.attributes&&Object.entries(t.attributes).forEach(([e,t])=>{if(e.startsWith("on")){const n=e.slice(2).toLowerCase();r.addEventListener(n,t)}else"dataset"===e?Object.entries(t).forEach(([e,t])=>{r.dataset[e]=t}):["disabled","checked","readonly","required","autofocus"].includes(e)?t&&r.setAttribute(e,""):r.setAttribute(e,t)}),void 0!==t.text&&(r.textContent=t.text),void 0!==t.html&&(r.innerHTML=t.html),t.children){(Array.isArray(t.children)?t.children:[t.children]).forEach(e=>{e instanceof Node&&r.appendChild(e)})}return r}createTextElement(e,t,n=""){return this.createElement(e,{className:n,text:t})}empty(e){for(;e.firstChild;)e.removeChild(e.firstChild)}}class u extends h{constructor(e,t={}){super(e,t),this.state={key:"",error:"",loading:!1},this.elements={input:null,error:null,submitBtn:null}}render(){const{key:e,error:t,loading:n}=this.state,r=this.createElement("div",{className:"cwd-modal-overlay",children:[this.createElement("div",{className:"cwd-modal",children:[this.createTextElement("h3","管理员身份验证","cwd-modal-title"),this.createElement("div",{className:"cwd-modal-body",children:[this.createTextElement("p","检测到管理员邮箱,请输入密钥以继续。","cwd-modal-desc"),this.createElement("input",{className:"cwd-form-input "+(t?"cwd-input-error":""),attributes:{type:"password",placeholder:"请输入管理员密钥",value:e,disabled:n,onInput:e=>this.setState({key:e.target.value,error:""}),onKeydown:e=>{"Enter"===e.key&&this.handleSubmit()}}}),t?this.createTextElement("div",t,"cwd-error-text"):null]}),this.createElement("div",{className:"cwd-modal-actions",children:[this.createElement("button",{className:"cwd-btn cwd-btn-secondary",text:"取消",attributes:{type:"button",disabled:n,onClick:()=>this.props.onCancel&&this.props.onCancel()}}),this.createElement("button",{className:"cwd-btn cwd-btn-primary",text:n?"验证中...":"验证",attributes:{type:"button",disabled:n||!e,onClick:()=>this.handleSubmit()}})]})]})]});this.empty(this.container),this.container.appendChild(r),this.elements.input=r.querySelector("input"),this.elements.error=r.querySelector(".cwd-error-text"),this.elements.submitBtn=r.querySelector(".cwd-btn-primary"),this.update();const i=this.elements.input;i&&setTimeout(()=>i.focus(),50)}setState(e){this.state={...this.state,...e},this.update()}update(){const{key:e,error:t,loading:n}=this.state;this.elements.input&&(this.elements.input.value=e,this.elements.input.disabled=n,t?this.elements.input.classList.add("cwd-input-error"):this.elements.input.classList.remove("cwd-input-error")),this.elements.error&&(t?(this.elements.error.textContent=t,this.elements.error.style.display=""):(this.elements.error.textContent="",this.elements.error.style.display="none")),this.elements.submitBtn&&(this.elements.submitBtn.disabled=n||!e,this.elements.submitBtn.textContent=n?"验证中...":"验证")}handleSubmit(){this.state.key&&this.props.onSubmit&&(this.setState({loading:!0}),this.props.onSubmit(this.state.key).catch(e=>{this.setState({error:e.message||"验证失败",loading:!1})}))}destroy(){this.empty(this.container)}}function m(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var f={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function g(e){f=e}var b={exec:()=>null};function w(e,t=""){let n="string"==typeof e?e:e.source,r={replace:(e,t)=>{let i="string"==typeof t?t:t.source;return i=i.replace(y.caret,"$1"),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var k=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),y={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},x=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,v=/(?:[*+-]|\d{1,9}[.)])/,S=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,E=w(S).replace(/bull/g,v).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),C=w(S).replace(/bull/g,v).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),T=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,R=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,_=w(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",R).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),N=w(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,v).getRegex(),A="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",L=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,P=w("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",L).replace("tag",A).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),I=w(T).replace("hr",x).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),z={blockquote:w(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",I).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:_,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:x,html:P,lheading:E,list:N,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:I,table:b,text:/^[^\n]+/},M=w("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",x).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),D={...z,lheading:C,table:M,paragraph:w(T).replace("hr",x).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",M).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex()},U={...z,html:w("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",L).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:b,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:w(T).replace("hr",x).replace("heading"," *#{1,6} *[^\n]").replace("lheading",E).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},$=/^( {2,}|\\)\n(?!\s*$)/,O=/[\p{P}\p{S}]/u,F=/[\s\p{P}\p{S}]/u,B=/[^\s\p{P}\p{S}]/u,q=w(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,F).getRegex(),j=/(?!~)[\p{P}\p{S}]/u,H=w(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",k?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),G=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,W=w(G,"u").replace(/punct/g,O).getRegex(),Z=w(G,"u").replace(/punct/g,j).getRegex(),Y="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",V=w(Y,"gu").replace(/notPunctSpace/g,B).replace(/punctSpace/g,F).replace(/punct/g,O).getRegex(),X=w(Y,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,j).getRegex(),Q=w("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,B).replace(/punctSpace/g,F).replace(/punct/g,O).getRegex(),J=w(/\\(punct)/,"gu").replace(/punct/g,O).getRegex(),K=w(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),ee=w(L).replace("(?:--\x3e|$)","--\x3e").getRegex(),te=w("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",ee).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ne=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,re=w(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",ne).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ie=w(/^!?\[(label)\]\[(ref)\]/).replace("label",ne).replace("ref",R).getRegex(),oe=w(/^!?\[(ref)\](?:\[\])?/).replace("ref",R).getRegex(),se=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ae={_backpedal:b,anyPunctuation:J,autolink:K,blockSkip:H,br:$,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:b,emStrongLDelim:W,emStrongRDelimAst:V,emStrongRDelimUnd:Q,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:re,nolink:oe,punctuation:q,reflink:ie,reflinkSearch:w("reflink|nolink(?!\\()","g").replace("reflink",ie).replace("nolink",oe).getRegex(),tag:te,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:b},le={...ae,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",ne).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ne).getRegex()},ce={...ae,emStrongRDelimAst:X,emStrongLDelim:Z,url:w(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",se).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:w(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",se).getRegex()},de={...ce,br:w($).replace("{2,}","*").getRegex(),text:w(ce.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},pe={normal:z,gfm:D,pedantic:U},he={normal:ae,gfm:ce,breaks:de,pedantic:le},ue={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},me=e=>ue[e];function fe(e,t){if(t){if(y.escapeTest.test(e))return e.replace(y.escapeReplace,me)}else if(y.escapeTestNoEncode.test(e))return e.replace(y.escapeReplaceNoEncode,me);return e}function ge(e){try{e=encodeURI(e).replace(y.percentDecode,"%")}catch{return null}return e}function be(e,t){var n;let r=e.replace(y.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&"\\"===n[i];)r=!r;return r?"|":" |"}).split(y.splitPipe),i=0;if(r[0].trim()||r.shift(),r.length>0&&!(null==(n=r.at(-1))?void 0:n.trim())&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;i<r.length;i++)r[i]=r[i].trim().replace(y.slashPipe,"|");return r}function we(e,t,n){let r=e.length;if(0===r)return"";let i=0;for(;i<r;){if(e.charAt(r-i-1)!==t)break;i++}return e.slice(0,r-i)}function ke(e,t,n,r,i){let o=t.href,s=t.title||null,a=e[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:o,title:s,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}var ye=class{constructor(e){r(this,"options"),r(this,"rules"),r(this,"lexer"),this.options=e||f}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:we(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(null===r)return t;let i=r[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=we(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:we(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=we(t[0],"\n").split("\n"),n="",r="",i=[];for(;e.length>0;){let t,o=!1,s=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))s.push(e[t]),o=!0;else{if(o)break;s.push(e[t])}e=e.slice(t);let a=s.join("\n"),l=a.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${a}`:a,r=r?`${r}\n${l}`:l;let c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=c,0===e.length)break;let d=i.at(-1);if("code"===(null==d?void 0:d.type))break;if("blockquote"===(null==d?void 0:d.type)){let t=d,o=t.raw+"\n"+e.join("\n"),s=this.blockquote(o);i[i.length-1]=s,n=n.substring(0,n.length-t.raw.length)+s.raw,r=r.substring(0,r.length-t.text.length)+s.text;break}if("list"===(null==d?void 0:d.type)){let t=d,o=t.raw+"\n"+e.join("\n"),s=this.list(o);i[i.length-1]=s,n=n.substring(0,n.length-d.raw.length)+s.raw,r=r.substring(0,r.length-t.raw.length)+s.raw,e=o.substring(i.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:i,text:r}}}list(e){var t,n;let r=this.rules.block.list.exec(e);if(r){let i=r[1].trim(),o=i.length>1,s={type:"list",raw:"",ordered:o,start:o?+i.slice(0,-1):"",loose:!1,items:[]};i=o?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=o?i:"[*+-]");let a=this.rules.other.listItemRegex(i),l=!1;for(;e;){let t=!1,n="",i="";if(!(r=a.exec(e))||this.rules.block.hr.test(e))break;n=r[0],e=e.substring(n.length);let o=r[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],d=!o.trim(),p=0;if(this.options.pedantic?(p=2,i=o.trimStart()):d?p=r[1].length+1:(p=r[2].search(this.rules.other.nonSpaceChar),p=p>4?1:p,i=o.slice(p),p+=r[1].length),d&&this.rules.other.blankLine.test(c)&&(n+=c+"\n",e=e.substring(c.length+1),t=!0),!t){let t=this.rules.other.nextBulletRegex(p),r=this.rules.other.hrRegex(p),s=this.rules.other.fencesBeginRegex(p),a=this.rules.other.headingBeginRegex(p),l=this.rules.other.htmlBeginRegex(p);for(;e;){let h,u=e.split("\n",1)[0];if(c=u,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),h=c):h=c.replace(this.rules.other.tabCharGlobal," "),s.test(c)||a.test(c)||l.test(c)||t.test(c)||r.test(c))break;if(h.search(this.rules.other.nonSpaceChar)>=p||!c.trim())i+="\n"+h.slice(p);else{if(d||o.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||s.test(o)||a.test(o)||r.test(o))break;i+="\n"+c}!d&&!c.trim()&&(d=!0),n+=u+"\n",e=e.substring(u.length+1),o=h.slice(p)}}s.loose||(l?s.loose=!0:this.rules.other.doubleBlankLine.test(n)&&(l=!0)),s.items.push({type:"list_item",raw:n,task:!!this.options.gfm&&this.rules.other.listIsTask.test(i),loose:!1,text:i,tokens:[]}),s.raw+=n}let c=s.items.at(-1);if(!c)return;c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd(),s.raw=s.raw.trimEnd();for(let e of s.items){if(this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]),e.task){if(e.text=e.text.replace(this.rules.other.listReplaceTask,""),"text"===(null==(t=e.tokens[0])?void 0:t.type)||"paragraph"===(null==(n=e.tokens[0])?void 0:n.type)){e.tokens[0].raw=e.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),e.tokens[0].text=e.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,"");break}}let r=this.rules.other.listTaskCheckbox.exec(e.raw);if(r){let t={type:"checkbox",raw:r[0]+" ",checked:"[ ]"!==r[0]};e.checked=t.checked,s.loose?e.tokens[0]&&["paragraph","text"].includes(e.tokens[0].type)&&"tokens"in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=t.raw+e.tokens[0].raw,e.tokens[0].text=t.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(t)):e.tokens.unshift({type:"paragraph",raw:t.raw,text:t.raw,tokens:[t]}):e.tokens.unshift(t)}}if(!s.loose){let t=e.tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw));s.loose=n}}if(s.loose)for(let e of s.items){e.loose=!0;for(let t of e.tokens)"text"===t.type&&(t.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}table(e){var t;let n=this.rules.block.table.exec(e);if(!n||!this.rules.other.tableDelimiter.test(n[2]))return;let r=be(n[1]),i=n[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=(null==(t=n[3])?void 0:t.trim())?n[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],s={type:"table",raw:n[0],header:[],align:[],rows:[]};if(r.length===i.length){for(let e of i)this.rules.other.tableAlignRight.test(e)?s.align.push("right"):this.rules.other.tableAlignCenter.test(e)?s.align.push("center"):this.rules.other.tableAlignLeft.test(e)?s.align.push("left"):s.align.push(null);for(let e=0;e<r.length;e++)s.header.push({text:r[e],tokens:this.lexer.inline(r[e]),header:!0,align:s.align[e]});for(let e of o)s.rows.push(be(e,s.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:s.align[t]})));return s}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=we(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let r=0;r<e.length;r++)if("\\"===e[r])r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),ke(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return ke(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!r[1]&&!r[2]||!n||this.rules.inline.punctuation.exec(n))){let n,i,o=[...r[0]].length-1,s=o,a=0,l="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+o);null!=(r=l.exec(t));){if(n=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!n)continue;if(i=[...n].length,r[3]||r[4]){s+=i;continue}if((r[5]||r[6])&&o%3&&!((o+i)%3)){a+=i;continue}if(s-=i,s>0)continue;i=Math.min(i,i+s+a);let t=[...r[0]][0].length,l=e.slice(0,o+r.index+t+i);if(Math.min(o,i)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=t[1],n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){var t;let n;if(n=this.rules.inline.url.exec(e)){let e,r;if("@"===n[2])e=n[0],r="mailto:"+e;else{let i;do{i=n[0],n[0]=(null==(t=this.rules.inline._backpedal.exec(n[0]))?void 0:t[0])??""}while(i!==n[0]);e=n[0],r="www."===n[1]?"http://"+n[0]:n[0]}return{type:"link",raw:n[0],text:e,href:r,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},xe=class e{constructor(e){r(this,"tokens"),r(this,"options"),r(this,"state"),r(this,"inlineQueue"),r(this,"tokenizer"),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||f,this.options.tokenizer=this.options.tokenizer||new ye,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:y,block:pe.normal,inline:he.normal};this.options.pedantic?(t.block=pe.pedantic,t.inline=he.pedantic):this.options.gfm&&(t.block=pe.gfm,this.options.breaks?t.inline=he.breaks:t.inline=he.gfm),this.tokenizer.rules=t}static get rules(){return{block:pe,inline:he}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(y.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let e=this.inlineQueue[t];this.inlineTokens(e.src,e.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){var r,i,o;for(this.options.pedantic&&(e=e.replace(y.tabCharGlobal," ").replace(y.spaceLine,""));e;){let s;if(null==(i=null==(r=this.options.extensions)?void 0:r.block)?void 0:i.some(n=>!!(s=n.call({lexer:this},e,t))&&(e=e.substring(s.raw.length),t.push(s),!0)))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let n=t.at(-1);1===s.raw.length&&void 0!==n?n.raw+="\n":t.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===(null==n?void 0:n.type)||"text"===(null==n?void 0:n.type)?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);let n=t.at(-1);"paragraph"===(null==n?void 0:n.type)||"text"===(null==n?void 0:n.type)?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},t.push(s));continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),t.push(s);continue}let a=e;if(null==(o=this.options.extensions)?void 0:o.startBlock){let t,n=1/0,r=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},r),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(a=e.substring(0,n+1))}if(this.state.top&&(s=this.tokenizer.paragraph(a))){let r=t.at(-1);n&&"paragraph"===(null==r?void 0:r.type)?(r.raw+=(r.raw.endsWith("\n")?"":"\n")+s.raw,r.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(s),n=a.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);let n=t.at(-1);"text"===(null==n?void 0:n.type)?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+s.raw,n.text+="\n"+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(s);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){var n,r,i,o,s;let a,l=e,c=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(c=this.tokenizer.rules.inline.reflinkSearch.exec(l));)e.includes(c[0].slice(c[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,c.index)+"["+"a".repeat(c[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(c=this.tokenizer.rules.inline.anyPunctuation.exec(l));)l=l.slice(0,c.index)+"++"+l.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(c=this.tokenizer.rules.inline.blockSkip.exec(l));)a=c[2]?c[2].length:0,l=l.slice(0,c.index+a)+"["+"a".repeat(c[0].length-a-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);l=(null==(r=null==(n=this.options.hooks)?void 0:n.emStrongMask)?void 0:r.call({lexer:this},l))??l;let d=!1,p="";for(;e;){let n;if(d||(p=""),d=!1,null==(o=null==(i=this.options.extensions)?void 0:i.inline)?void 0:o.some(r=>!!(n=r.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))continue;if(n=this.tokenizer.escape(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.tag(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.link(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(n.raw.length);let r=t.at(-1);"text"===n.type&&"text"===(null==r?void 0:r.type)?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(n=this.tokenizer.emStrong(e,l,p)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.codespan(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.br(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.del(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.autolink(e)){e=e.substring(n.raw.length),t.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(e))){e=e.substring(n.raw.length),t.push(n);continue}let r=e;if(null==(s=this.options.extensions)?void 0:s.startInline){let t,n=1/0,i=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},i),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(r=e.substring(0,n+1))}if(n=this.tokenizer.inlineText(r)){e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(p=n.raw.slice(-1)),d=!0;let r=t.at(-1);"text"===(null==r?void 0:r.type)?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},ve=class{constructor(e){r(this,"options"),r(this,"parser"),this.options=e||f}space(e){return""}code({text:e,lang:t,escaped:n}){var r;let i=null==(r=(t||"").match(y.notSpaceStart))?void 0:r[0],o=e.replace(y.endingNewline,"")+"\n";return i?'<pre><code class="language-'+fe(i)+'">'+(n?o:fe(o,!0))+"</code></pre>\n":"<pre><code>"+(n?o:fe(o,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,r="";for(let o=0;o<e.items.length;o++){let t=e.items[o];r+=this.listitem(t)}let i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+r+"</"+i+">\n"}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let i=0;i<e.header.length;i++)n+=this.tablecell(e.header[i]);t+=this.tablerow({text:n});let r="";for(let i=0;i<e.rows.length;i++){let t=e.rows[i];n="";for(let e=0;e<t.length;e++)n+=this.tablecell(t[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+r+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${fe(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=ge(e);if(null===i)return r;let o='<a href="'+(e=i)+'"';return t&&(o+=' title="'+fe(t)+'"'),o+=">"+r+"</a>",o}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=ge(e);if(null===i)return fe(n);let o=`<img src="${e=i}" alt="${n}"`;return t&&(o+=` title="${fe(t)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:fe(e.text)}},Se=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},Ee=class e{constructor(e){r(this,"options"),r(this,"renderer"),r(this,"textRenderer"),this.options=e||f,this.options.renderer=this.options.renderer||new ve,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Se}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){var t,n;let r="";for(let i=0;i<e.length;i++){let o=e[i];if(null==(n=null==(t=this.options.extensions)?void 0:t.renderers)?void 0:n[o.type]){let e=o,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){r+=t||"";continue}}let s=o;switch(s.type){case"space":r+=this.renderer.space(s);break;case"hr":r+=this.renderer.hr(s);break;case"heading":r+=this.renderer.heading(s);break;case"code":r+=this.renderer.code(s);break;case"table":r+=this.renderer.table(s);break;case"blockquote":r+=this.renderer.blockquote(s);break;case"list":r+=this.renderer.list(s);break;case"checkbox":r+=this.renderer.checkbox(s);break;case"html":r+=this.renderer.html(s);break;case"def":r+=this.renderer.def(s);break;case"paragraph":r+=this.renderer.paragraph(s);break;case"text":r+=this.renderer.text(s);break;default:{let e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return r}parseInline(e,t=this.renderer){var n,r;let i="";for(let o=0;o<e.length;o++){let s=e[o];if(null==(r=null==(n=this.options.extensions)?void 0:n.renderers)?void 0:r[s.type]){let e=this.options.extensions.renderers[s.type].call({parser:this},s);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){i+=e||"";continue}}let a=s;switch(a.type){case"escape":case"text":i+=t.text(a);break;case"html":i+=t.html(a);break;case"link":i+=t.link(a);break;case"image":i+=t.image(a);break;case"checkbox":i+=t.checkbox(a);break;case"strong":i+=t.strong(a);break;case"em":i+=t.em(a);break;case"codespan":i+=t.codespan(a);break;case"br":i+=t.br(a);break;case"del":i+=t.del(a);break;default:{let e='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return i}},Ce=(t=class{constructor(e){r(this,"options"),r(this,"block"),this.options=e||f}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?xe.lex:xe.lexInline}provideParser(){return this.block?Ee.parse:Ee.parseInline}},r(t,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),r(t,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),t),Te=new class{constructor(...e){r(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),r(this,"options",this.setOptions),r(this,"parse",this.parseMarkdown(!0)),r(this,"parseInline",this.parseMarkdown(!1)),r(this,"Parser",Ee),r(this,"Renderer",ve),r(this,"TextRenderer",Se),r(this,"Lexer",xe),r(this,"Tokenizer",ye),r(this,"Hooks",Ce),this.use(...e)}walkTokens(e,t){var n,r;let i=[];for(let o of e)switch(i=i.concat(t.call(this,o)),o.type){case"table":{let e=o;for(let n of e.header)i=i.concat(this.walkTokens(n.tokens,t));for(let n of e.rows)for(let e of n)i=i.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=o;i=i.concat(this.walkTokens(e.items,t));break}default:{let e=o;(null==(r=null==(n=this.defaults.extensions)?void 0:n.childTokens)?void 0:r[e.type])?this.defaults.extensions.childTokens[e.type].forEach(n=>{let r=e[n].flat(1/0);i=i.concat(this.walkTokens(r,t))}):e.tokens&&(i=i.concat(this.walkTokens(e.tokens,t)))}}return i}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new ve(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let r=n,i=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new ye(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let r=n,i=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new Ce;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let r=n,i=e.hooks[r],o=t[r];Ce.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&Ce.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return o.call(t,n)})();let r=i.call(t,e);return o.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return!1===n&&(n=await o.apply(t,e)),n})();let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return xe.lex(e,t??this.defaults)}parser(e,t){return Ee.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},o=this.onError(!!i.silent,!!i.async);if(!0===this.defaults.async&&!1===r.async)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?xe.lex:xe.lexInline)(n,i),o=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(o,i.walkTokens));let s=await(i.hooks?await i.hooks.provideParser():e?Ee.parse:Ee.parseInline)(o,i);return i.hooks?await i.hooks.postprocess(s):s})().catch(o);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?xe.lex:xe.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?Ee.parse:Ee.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(s){return o(s)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+fe(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function Re(e,t){return Te.parse(e,t)}Re.options=Re.setOptions=function(e){return Te.setOptions(e),Re.defaults=Te.defaults,g(Re.defaults),Re},Re.getDefaults=m,Re.defaults=f,Re.use=function(...e){return Te.use(...e),Re.defaults=Te.defaults,g(Re.defaults),Re},Re.walkTokens=function(e,t){return Te.walkTokens(e,t)},Re.parseInline=Te.parseInline,Re.Parser=Ee,Re.parser=Ee.parse,Re.Renderer=ve,Re.TextRenderer=Se,Re.Lexer=xe,Re.lexer=xe.lex,Re.Tokenizer=ye,Re.Hooks=Ce,Re.parse=Re,Re.options,Re.setOptions,Re.use,Re.walkTokens,Re.parseInline,Ee.parse,xe.lex;
2
+ /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
3
+ const{entries:_e,setPrototypeOf:Ne,isFrozen:Ae,getPrototypeOf:Le,getOwnPropertyDescriptor:Pe}=Object;let{freeze:Ie,seal:ze,create:Me}=Object,{apply:De,construct:Ue}="undefined"!=typeof Reflect&&Reflect;Ie||(Ie=function(e){return e}),ze||(ze=function(e){return e}),De||(De=function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return e.apply(t,r)}),Ue||(Ue=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return new e(...n)});const $e=Ke(Array.prototype.forEach),Oe=Ke(Array.prototype.lastIndexOf),Fe=Ke(Array.prototype.pop),Be=Ke(Array.prototype.push),qe=Ke(Array.prototype.splice),je=Ke(String.prototype.toLowerCase),He=Ke(String.prototype.toString),Ge=Ke(String.prototype.match),We=Ke(String.prototype.replace),Ze=Ke(String.prototype.indexOf),Ye=Ke(String.prototype.trim),Ve=Ke(Object.prototype.hasOwnProperty),Xe=Ke(RegExp.prototype.test),Qe=(Je=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ue(Je,t)});var Je;function Ke(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return De(e,t,r)}}function et(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:je;Ne&&Ne(e,null);let r=t.length;for(;r--;){let i=t[r];if("string"==typeof i){const e=n(i);e!==i&&(Ae(t)||(t[r]=e),i=e)}e[i]=!0}return e}function tt(e){for(let t=0;t<e.length;t++){Ve(e,t)||(e[t]=null)}return e}function nt(e){const t=Me(null);for(const[n,r]of _e(e)){Ve(e,n)&&(Array.isArray(r)?t[n]=tt(r):r&&"object"==typeof r&&r.constructor===Object?t[n]=nt(r):t[n]=r)}return t}function rt(e,t){for(;null!==e;){const n=Pe(e,t);if(n){if(n.get)return Ke(n.get);if("function"==typeof n.value)return Ke(n.value)}e=Le(e)}return function(){return null}}const it=Ie(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),ot=Ie(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),st=Ie(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),at=Ie(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),lt=Ie(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),ct=Ie(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),dt=Ie(["#text"]),pt=Ie(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),ht=Ie(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),ut=Ie(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),mt=Ie(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),ft=ze(/\{\{[\w\W]*|[\w\W]*\}\}/gm),gt=ze(/<%[\w\W]*|[\w\W]*%>/gm),bt=ze(/\$\{[\w\W]*/gm),wt=ze(/^data-[\-\w.\u00B7-\uFFFF]+$/),kt=ze(/^aria-[\-\w]+$/),yt=ze(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),xt=ze(/^(?:\w+script|data):/i),vt=ze(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),St=ze(/^html$/i),Et=ze(/^[a-z][.\w]*(-[.\w]+)+$/i);var Ct=Object.freeze({__proto__:null,ARIA_ATTR:kt,ATTR_WHITESPACE:vt,CUSTOM_ELEMENT:Et,DATA_ATTR:wt,DOCTYPE_NAME:St,ERB_EXPR:gt,IS_ALLOWED_URI:yt,IS_SCRIPT_OR_DATA:xt,MUSTACHE_EXPR:ft,TMPLIT_EXPR:bt});const Tt=1,Rt=3,_t=7,Nt=8,At=9;var Lt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"undefined"==typeof window?null:window;const n=t=>e(t);if(n.version="3.3.1",n.removed=[],!t||!t.document||t.document.nodeType!==At||!t.Element)return n.isSupported=!1,n;let{document:r}=t;const i=r,o=i.currentScript,{DocumentFragment:s,HTMLTemplateElement:a,Node:l,Element:c,NodeFilter:d,NamedNodeMap:p=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:h,DOMParser:u,trustedTypes:m}=t,f=c.prototype,g=rt(f,"cloneNode"),b=rt(f,"remove"),w=rt(f,"nextSibling"),k=rt(f,"childNodes"),y=rt(f,"parentNode");if("function"==typeof a){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let x,v="";const{implementation:S,createNodeIterator:E,createDocumentFragment:C,getElementsByTagName:T}=r,{importNode:R}=i;let _={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};n.isSupported="function"==typeof _e&&"function"==typeof y&&S&&void 0!==S.createHTMLDocument;const{MUSTACHE_EXPR:N,ERB_EXPR:A,TMPLIT_EXPR:L,DATA_ATTR:P,ARIA_ATTR:I,IS_SCRIPT_OR_DATA:z,ATTR_WHITESPACE:M,CUSTOM_ELEMENT:D}=Ct;let{IS_ALLOWED_URI:U}=Ct,$=null;const O=et({},[...it,...ot,...st,...lt,...dt]);let F=null;const B=et({},[...pt,...ht,...ut,...mt]);let q=Object.seal(Me(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}})),j=null,H=null;const G=Object.seal(Me(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let W=!0,Z=!0,Y=!1,V=!0,X=!1,Q=!0,J=!1,K=!1,ee=!1,te=!1,ne=!1,re=!1,ie=!0,oe=!1,se=!0,ae=!1,le={},ce=null;const de=et({},["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 pe=null;const he=et({},["audio","video","img","source","image","track"]);let ue=null;const me=et({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),fe="http://www.w3.org/1998/Math/MathML",ge="http://www.w3.org/2000/svg",be="http://www.w3.org/1999/xhtml";let we=be,ke=!1,ye=null;const xe=et({},[fe,ge,be],He);let ve=et({},["mi","mo","mn","ms","mtext"]),Se=et({},["annotation-xml"]);const Ee=et({},["title","style","font","a","script"]);let Ce=null;const Te=["application/xhtml+xml","text/html"];let Re=null,Ne=null;const Ae=r.createElement("form"),Le=function(e){return e instanceof RegExp||e instanceof Function},Pe=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!Ne||Ne!==e){if(e&&"object"==typeof e||(e={}),e=nt(e),Ce=-1===Te.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Re="application/xhtml+xml"===Ce?He:je,$=Ve(e,"ALLOWED_TAGS")?et({},e.ALLOWED_TAGS,Re):O,F=Ve(e,"ALLOWED_ATTR")?et({},e.ALLOWED_ATTR,Re):B,ye=Ve(e,"ALLOWED_NAMESPACES")?et({},e.ALLOWED_NAMESPACES,He):xe,ue=Ve(e,"ADD_URI_SAFE_ATTR")?et(nt(me),e.ADD_URI_SAFE_ATTR,Re):me,pe=Ve(e,"ADD_DATA_URI_TAGS")?et(nt(he),e.ADD_DATA_URI_TAGS,Re):he,ce=Ve(e,"FORBID_CONTENTS")?et({},e.FORBID_CONTENTS,Re):de,j=Ve(e,"FORBID_TAGS")?et({},e.FORBID_TAGS,Re):nt({}),H=Ve(e,"FORBID_ATTR")?et({},e.FORBID_ATTR,Re):nt({}),le=!!Ve(e,"USE_PROFILES")&&e.USE_PROFILES,W=!1!==e.ALLOW_ARIA_ATTR,Z=!1!==e.ALLOW_DATA_ATTR,Y=e.ALLOW_UNKNOWN_PROTOCOLS||!1,V=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,X=e.SAFE_FOR_TEMPLATES||!1,Q=!1!==e.SAFE_FOR_XML,J=e.WHOLE_DOCUMENT||!1,te=e.RETURN_DOM||!1,ne=e.RETURN_DOM_FRAGMENT||!1,re=e.RETURN_TRUSTED_TYPE||!1,ee=e.FORCE_BODY||!1,ie=!1!==e.SANITIZE_DOM,oe=e.SANITIZE_NAMED_PROPS||!1,se=!1!==e.KEEP_CONTENT,ae=e.IN_PLACE||!1,U=e.ALLOWED_URI_REGEXP||yt,we=e.NAMESPACE||be,ve=e.MATHML_TEXT_INTEGRATION_POINTS||ve,Se=e.HTML_INTEGRATION_POINTS||Se,q=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&Le(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(q.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&Le(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(q.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(q.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),X&&(Z=!1),ne&&(te=!0),le&&($=et({},dt),F=[],!0===le.html&&(et($,it),et(F,pt)),!0===le.svg&&(et($,ot),et(F,ht),et(F,mt)),!0===le.svgFilters&&(et($,st),et(F,ht),et(F,mt)),!0===le.mathMl&&(et($,lt),et(F,ut),et(F,mt))),e.ADD_TAGS&&("function"==typeof e.ADD_TAGS?G.tagCheck=e.ADD_TAGS:($===O&&($=nt($)),et($,e.ADD_TAGS,Re))),e.ADD_ATTR&&("function"==typeof e.ADD_ATTR?G.attributeCheck=e.ADD_ATTR:(F===B&&(F=nt(F)),et(F,e.ADD_ATTR,Re))),e.ADD_URI_SAFE_ATTR&&et(ue,e.ADD_URI_SAFE_ATTR,Re),e.FORBID_CONTENTS&&(ce===de&&(ce=nt(ce)),et(ce,e.FORBID_CONTENTS,Re)),e.ADD_FORBID_CONTENTS&&(ce===de&&(ce=nt(ce)),et(ce,e.ADD_FORBID_CONTENTS,Re)),se&&($["#text"]=!0),J&&et($,["html","head","body"]),$.table&&(et($,["tbody"]),delete j.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw Qe('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw Qe('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');x=e.TRUSTED_TYPES_POLICY,v=x.createHTML("")}else void 0===x&&(x=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(n=t.getAttribute(r));const i="dompurify"+(n?"#"+n:"");try{return e.createPolicy(i,{createHTML:e=>e,createScriptURL:e=>e})}catch(o){return console.warn("TrustedTypes policy "+i+" could not be created."),null}}(m,o)),null!==x&&"string"==typeof v&&(v=x.createHTML(""));Ie&&Ie(e),Ne=e}},ze=et({},[...ot,...st,...at]),De=et({},[...lt,...ct]),Ue=function(e){Be(n.removed,{element:e});try{y(e).removeChild(e)}catch(t){b(e)}},Je=function(e,t){try{Be(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(r){Be(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(te||ne)try{Ue(t)}catch(r){}else try{t.setAttribute(e,"")}catch(r){}},Ke=function(e){let t=null,n=null;if(ee)e="<remove></remove>"+e;else{const t=Ge(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===Ce&&we===be&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const i=x?x.createHTML(e):e;if(we===be)try{t=(new u).parseFromString(i,Ce)}catch(s){}if(!t||!t.documentElement){t=S.createDocument(we,"template",null);try{t.documentElement.innerHTML=ke?v:i}catch(s){}}const o=t.body||t.documentElement;return e&&n&&o.insertBefore(r.createTextNode(n),o.childNodes[0]||null),we===be?T.call(t,J?"html":"body")[0]:J?t.documentElement:o},tt=function(e){return E.call(e.ownerDocument||e,e,d.SHOW_ELEMENT|d.SHOW_COMMENT|d.SHOW_TEXT|d.SHOW_PROCESSING_INSTRUCTION|d.SHOW_CDATA_SECTION,null)},ft=function(e){return e instanceof h&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof p)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},gt=function(e){return"function"==typeof l&&e instanceof l};function bt(e,t,r){$e(e,e=>{e.call(n,t,r,Ne)})}const wt=function(e){let t=null;if(bt(_.beforeSanitizeElements,e,null),ft(e))return Ue(e),!0;const r=Re(e.nodeName);if(bt(_.uponSanitizeElement,e,{tagName:r,allowedTags:$}),Q&&e.hasChildNodes()&&!gt(e.firstElementChild)&&Xe(/<[/\w!]/g,e.innerHTML)&&Xe(/<[/\w!]/g,e.textContent))return Ue(e),!0;if(e.nodeType===_t)return Ue(e),!0;if(Q&&e.nodeType===Nt&&Xe(/<[/\w]/g,e.data))return Ue(e),!0;if(!(G.tagCheck instanceof Function&&G.tagCheck(r))&&(!$[r]||j[r])){if(!j[r]&&xt(r)){if(q.tagNameCheck instanceof RegExp&&Xe(q.tagNameCheck,r))return!1;if(q.tagNameCheck instanceof Function&&q.tagNameCheck(r))return!1}if(se&&!ce[r]){const t=y(e)||e.parentNode,n=k(e)||e.childNodes;if(n&&t){for(let r=n.length-1;r>=0;--r){const i=g(n[r],!0);i.__removalCount=(e.__removalCount||0)+1,t.insertBefore(i,w(e))}}}return Ue(e),!0}return e instanceof c&&!function(e){let t=y(e);t&&t.tagName||(t={namespaceURI:we,tagName:"template"});const n=je(e.tagName),r=je(t.tagName);return!!ye[e.namespaceURI]&&(e.namespaceURI===ge?t.namespaceURI===be?"svg"===n:t.namespaceURI===fe?"svg"===n&&("annotation-xml"===r||ve[r]):Boolean(ze[n]):e.namespaceURI===fe?t.namespaceURI===be?"math"===n:t.namespaceURI===ge?"math"===n&&Se[r]:Boolean(De[n]):e.namespaceURI===be?!(t.namespaceURI===ge&&!Se[r])&&!(t.namespaceURI===fe&&!ve[r])&&!De[n]&&(Ee[n]||!ze[n]):!("application/xhtml+xml"!==Ce||!ye[e.namespaceURI]))}(e)?(Ue(e),!0):"noscript"!==r&&"noembed"!==r&&"noframes"!==r||!Xe(/<\/no(script|embed|frames)/i,e.innerHTML)?(X&&e.nodeType===Rt&&(t=e.textContent,$e([N,A,L],e=>{t=We(t,e," ")}),e.textContent!==t&&(Be(n.removed,{element:e.cloneNode()}),e.textContent=t)),bt(_.afterSanitizeElements,e,null),!1):(Ue(e),!0)},kt=function(e,t,n){if(ie&&("id"===t||"name"===t)&&(n in r||n in Ae))return!1;if(Z&&!H[t]&&Xe(P,t));else if(W&&Xe(I,t));else if(G.attributeCheck instanceof Function&&G.attributeCheck(t,e));else if(!F[t]||H[t]){if(!(xt(e)&&(q.tagNameCheck instanceof RegExp&&Xe(q.tagNameCheck,e)||q.tagNameCheck instanceof Function&&q.tagNameCheck(e))&&(q.attributeNameCheck instanceof RegExp&&Xe(q.attributeNameCheck,t)||q.attributeNameCheck instanceof Function&&q.attributeNameCheck(t,e))||"is"===t&&q.allowCustomizedBuiltInElements&&(q.tagNameCheck instanceof RegExp&&Xe(q.tagNameCheck,n)||q.tagNameCheck instanceof Function&&q.tagNameCheck(n))))return!1}else if(ue[t]);else if(Xe(U,We(n,M,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==Ze(n,"data:")||!pe[e]){if(Y&&!Xe(z,We(n,M,"")));else if(n)return!1}else;return!0},xt=function(e){return"annotation-xml"!==e&&Ge(e,D)},vt=function(e){bt(_.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||ft(e))return;const r={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:F,forceKeepAttr:void 0};let i=t.length;for(;i--;){const s=t[i],{name:a,namespaceURI:l,value:c}=s,d=Re(a),p=c;let h="value"===a?p:Ye(p);if(r.attrName=d,r.attrValue=h,r.keepAttr=!0,r.forceKeepAttr=void 0,bt(_.uponSanitizeAttribute,e,r),h=r.attrValue,!oe||"id"!==d&&"name"!==d||(Je(a,e),h="user-content-"+h),Q&&Xe(/((--!?|])>)|<\/(style|title|textarea)/i,h)){Je(a,e);continue}if("attributename"===d&&Ge(h,"href")){Je(a,e);continue}if(r.forceKeepAttr)continue;if(!r.keepAttr){Je(a,e);continue}if(!V&&Xe(/\/>/i,h)){Je(a,e);continue}X&&$e([N,A,L],e=>{h=We(h,e," ")});const u=Re(e.nodeName);if(kt(u,d,h)){if(x&&"object"==typeof m&&"function"==typeof m.getAttributeType)if(l);else switch(m.getAttributeType(u,d)){case"TrustedHTML":h=x.createHTML(h);break;case"TrustedScriptURL":h=x.createScriptURL(h)}if(h!==p)try{l?e.setAttributeNS(l,a,h):e.setAttribute(a,h),ft(e)?Ue(e):Fe(n.removed)}catch(o){Je(a,e)}}else Je(a,e)}bt(_.afterSanitizeAttributes,e,null)},Et=function e(t){let n=null;const r=tt(t);for(bt(_.beforeSanitizeShadowDOM,t,null);n=r.nextNode();)bt(_.uponSanitizeShadowNode,n,null),wt(n),vt(n),n.content instanceof s&&e(n.content);bt(_.afterSanitizeShadowDOM,t,null)};return n.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=null,o=null,a=null,c=null;if(ke=!e,ke&&(e="\x3c!--\x3e"),"string"!=typeof e&&!gt(e)){if("function"!=typeof e.toString)throw Qe("toString is not a function");if("string"!=typeof(e=e.toString()))throw Qe("dirty is not a string, aborting")}if(!n.isSupported)return e;if(K||Pe(t),n.removed=[],"string"==typeof e&&(ae=!1),ae){if(e.nodeName){const t=Re(e.nodeName);if(!$[t]||j[t])throw Qe("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof l)r=Ke("\x3c!----\x3e"),o=r.ownerDocument.importNode(e,!0),o.nodeType===Tt&&"BODY"===o.nodeName||"HTML"===o.nodeName?r=o:r.appendChild(o);else{if(!te&&!X&&!J&&-1===e.indexOf("<"))return x&&re?x.createHTML(e):e;if(r=Ke(e),!r)return te?null:re?v:""}r&&ee&&Ue(r.firstChild);const d=tt(ae?e:r);for(;a=d.nextNode();)wt(a),vt(a),a.content instanceof s&&Et(a.content);if(ae)return e;if(te){if(ne)for(c=C.call(r.ownerDocument);r.firstChild;)c.appendChild(r.firstChild);else c=r;return(F.shadowroot||F.shadowrootmode)&&(c=R.call(i,c,!0)),c}let p=J?r.outerHTML:r.innerHTML;return J&&$["!doctype"]&&r.ownerDocument&&r.ownerDocument.doctype&&r.ownerDocument.doctype.name&&Xe(St,r.ownerDocument.doctype.name)&&(p="<!DOCTYPE "+r.ownerDocument.doctype.name+">\n"+p),X&&$e([N,A,L],e=>{p=We(p,e," ")}),x&&re?x.createHTML(p):p},n.setConfig=function(){Pe(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),K=!0},n.clearConfig=function(){Ne=null,K=!1},n.isValidAttribute=function(e,t,n){Ne||Pe({});const r=Re(e),i=Re(t);return kt(r,i,n)},n.addHook=function(e,t){"function"==typeof t&&Be(_[e],t)},n.removeHook=function(e,t){if(void 0!==t){const n=Oe(_[e],t);return-1===n?void 0:qe(_[e],n,1)[0]}return Fe(_[e])},n.removeHooks=function(e){_[e]=[]},n.removeAllHooks=function(){_={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},n}();try{Re.setOptions({gfm:!0,breaks:!0})}catch(Wt){console.error("Failed to configure marked:",Wt)}function Pt(e){if(!e)return"";try{const t=Re.parse(e);return t instanceof Promise?(console.warn("marked.parse returned a Promise. Async markdown rendering is not fully supported in this sync flow."),""):Lt.sanitize(t)}catch(t){return console.error("Markdown rendering error:",t),Lt.sanitize(e)}}class It extends h{constructor(e,t={}){super(e,t);const n=t.form||{};this.state={localForm:{name:n.name||"",email:n.email||"",url:n.url||"",content:n.content||""},activeTab:"write",showPreview:!1},this.modal=null}render(){var e,t;const{formErrors:n,submitting:r}=this.props,{localForm:i}=this.state,o=i.name.trim()&&i.email.trim()&&i.content.trim(),s=this.props.adminEmail&&i.email.trim()===this.props.adminEmail&&l.hasToken(),a=this.createElement("form",{className:"cwd-comment-form",attributes:{novalidate:!0,onSubmit:e=>this.handleSubmit(e)},children:[this.createTextElement("h3","发表评论","cwd-form-title"),this.createElement("div",{className:"cwd-form-fields",children:[this.createElement("div",{className:"cwd-form-row",children:[this.createFormField("昵称 *","text","name",i.name,n.name),this.createElement("div",{className:"cwd-form-field-wrapper",children:[this.createFormField("邮箱 *","email","email",i.email,n.email),s?this.createElement("div",{className:"cwd-admin-controls",children:[this.createElement("button",{className:"cwd-btn-text",text:"退出验证",attributes:{type:"button",title:"清除管理员凭证",onClick:()=>{l.clearToken(),this.render()}}})]}):null]}),this.createFormField("网址","url","url",i.url,n.url)]}),this.createElement("div",{className:"cwd-form-field",children:[this.createTextElement("label","写下你的评论...","cwd-form-label"),this.createElement("textarea",{className:"cwd-form-textarea "+(n.content?"cwd-input-error":""),attributes:{rows:4,disabled:r,onInput:e=>this.handleFieldChange("content",e.target.value)}}),...n.content?[this.createTextElement("span",n.content,"cwd-error-text")]:[]]})]}),this.createElement("div",{className:"cwd-form-actions",children:[this.createElement("button",{className:"cwd-btn cwd-btn-secondary cwd-btn-preview "+(this.state.showPreview?"cwd-btn-active":""),attributes:{type:"button",disabled:r||!(null==(e=i.content)?void 0:e.trim()),style:(null==(t=i.content)?void 0:t.trim())?"":"display:none;",onClick:()=>this.togglePreview()},text:this.state.showPreview?"关闭":"预览"}),this.createElement("button",{className:"cwd-btn cwd-btn-primary",attributes:{type:"submit",disabled:r||!o},text:r?"提交中...":"提交评论"})]}),...this.state.showPreview&&i.content?[this.createElement("div",{className:"cwd-preview-container",children:[this.createElement("div",{className:"cwd-preview-content cwd-comment-content",html:Pt(i.content)})]})]:[]]});this.setInputValues(a,i),this.elements.root=a,this.empty(this.container),this.container.appendChild(a)}updateProps(e){if(!this.props.submitting&&this.props.form!==e.form){const e=this.state.localForm.name||"",t=this.state.localForm.email||"",n=this.state.localForm.url||"",r=this.state.localForm.content||"";this.state.localForm={name:this.props.form.name||e,email:this.props.form.email||t,url:this.props.form.url||n,content:void 0!==this.props.form.content?this.props.form.content:r},this.elements.root&&this.setInputValues(this.elements.root,this.state.localForm)}this.elements.root&&this.updateFormState()}updateFormState(){var e;const{formErrors:t,submitting:n}=this.props,{localForm:r}=this.state,i=r.name.trim()&&r.email.trim()&&r.content.trim(),o=this.elements.root.querySelector('button[type="submit"]');o&&(o.disabled=n||!i,o.textContent=n?"提交中...":"提交评论");const s=this.elements.root.querySelector(".cwd-btn-preview");if(s){const t=!!(null==(e=r.content)?void 0:e.trim());if(s.disabled=n||!t,s.style.display=t?"":"none",t)s.textContent=this.state.showPreview?"关闭":"预览";else{this.state.showPreview=!1;const e=this.elements.root.querySelector(".cwd-preview-container");e&&e.remove(),s.textContent="预览"}}this.elements.root.querySelectorAll("input, textarea").forEach(e=>{e.disabled=n}),this.updateErrors(t)}updateErrors(e){if(!this.elements.root)return;const t=this.elements.root.querySelector('input[name="name"]');this.updateFieldError(t,null==e?void 0:e.name);const n=this.elements.root.querySelector('input[name="email"]');this.updateFieldError(n,null==e?void 0:e.email);const r=this.elements.root.querySelector('input[name="url"]');this.updateFieldError(r,null==e?void 0:e.url);const i=this.elements.root.querySelector("textarea");this.updateFieldError(i,null==e?void 0:e.content)}updateFieldError(e,t){if(!e)return;t?e.classList.add("cwd-input-error"):e.classList.remove("cwd-input-error");const n=e.parentElement;let r=n.querySelector(".cwd-error-text");t?(r||(r=document.createElement("span"),r.className="cwd-error-text",n.appendChild(r)),r.textContent=t):r&&r.remove()}createFormField(e,t,n,r,i,o=""){return this.createElement("div",{className:"cwd-form-field",children:[this.createTextElement("label",e,"cwd-form-label"),this.createElement("input",{className:"cwd-form-input "+(i?"cwd-input-error":""),attributes:{type:t,name:n,value:r||"",disabled:this.props.submitting,onInput:e=>this.handleFieldChange(n,e.target.value),onBlur:e=>{"email"===n&&this.handleEmailBlur(e.target.value)}}}),...i?[this.createTextElement("span",i,"cwd-error-text")]:[]]})}setInputValues(e,t){const n=e.querySelector('input[name="name"]'),r=e.querySelector('input[name="email"]'),i=e.querySelector('input[name="url"]'),o=e.querySelector("textarea");n&&(n.value=t.name||""),r&&(r.value=t.email||""),i&&(i.value=t.url||""),o&&(o.value=t.content||"")}togglePreview(){this.state.showPreview=!this.state.showPreview,this.render()}handleFieldChange(e,t){this.state.localForm[e]=t,this.props.onFieldChange&&this.props.onFieldChange(e,t),this.elements.root&&(this.updateFormState(),"content"===e&&this.state.showPreview&&this.updatePreviewContent(t))}updatePreviewContent(e){const t=this.elements.root.querySelector(".cwd-preview-content");t&&(t.innerHTML=Pt(e))}handleSubmit(e){var t;e.preventDefault();const n=null==(t=this.state.localForm.email)?void 0:t.trim(),r=this.props.adminEmail;r&&n&&n===r&&!l.hasToken()?this.showAuthModal():this.props.onSubmit&&this.props.onSubmit(this.state.localForm)}async handleEmailBlur(e){if(e&&this.props.adminEmail&&e.trim()===this.props.adminEmail){if(l.hasToken())return;this.showAuthModal()}}showAuthModal(){let e=this.elements.root.querySelector(".cwd-modal-container");e||(e=document.createElement("div"),e.className="cwd-modal-container",this.elements.root.appendChild(e)),this.modal=new u(e,{onCancel:()=>{this.modal.destroy(),this.modal=null},onSubmit:async e=>{this.props.onVerifyAdmin&&(await this.props.onVerifyAdmin(e),l.saveToken(e),this.modal.destroy(),this.modal=null)}}),this.modal.render()}}class zt extends h{constructor(e,t={}){super(e,t);const{currentUser:n}=t;this.state={content:t.content||"",showUserInfo:!n||!n.name||!n.email,showPreview:!1}}render(){const{currentUser:e}=this.props,{showUserInfo:t}=this.state,n=this.createElement("div",{className:"cwd-reply-editor",children:[this.createElement("div",{className:"cwd-reply-header",children:[this.createTextElement("span",`回复 @${this.props.replyToAuthor}`,"cwd-reply-to"),this.createElement("button",{className:"cwd-btn-close",attributes:{type:"button",onClick:()=>this.handleCancel()},text:"✕"})]}),...t?[this.createElement("div",{className:"cwd-form-row",attributes:{style:"margin-bottom: 12px;"},children:[this.createFormField("昵称 *","text","name",null==e?void 0:e.name),this.createFormField("邮箱 *","email","email",null==e?void 0:e.email),this.createFormField("网址","url","url",null==e?void 0:e.url)]})]:[],this.createElement("textarea",{className:"cwd-reply-textarea",attributes:{rows:3,placeholder:"支持 Markdown 格式",disabled:this.props.submitting,onInput:e=>this.handleInput(e)}}),...this.props.error?[this.createElement("div",{className:"cwd-error-inline cwd-error-small",children:[this.createTextElement("span",this.props.error),this.createElement("button",{className:"cwd-error-close",attributes:{type:"button",onClick:()=>this.handleClearError()},text:"✕"})]})]:[],this.createElement("div",{className:"cwd-reply-actions",children:[this.createElement("button",{className:"cwd-btn cwd-btn-secondary cwd-btn-small cwd-btn-preview "+(this.state.showPreview?"cwd-btn-active":""),attributes:{type:"button",disabled:this.props.submitting||!this.state.content.trim(),onClick:()=>this.togglePreview()},text:this.state.showPreview?"关闭":"预览"}),this.createElement("button",{className:"cwd-btn cwd-btn-primary cwd-btn-small",attributes:{type:"button",disabled:this.props.submitting||!this.state.content.trim(),onClick:()=>this.handleSubmit()},text:this.props.submitting?"提交中...":"提交回复"}),this.createElement("button",{className:"cwd-btn cwd-btn-secondary cwd-btn-small",attributes:{type:"button",disabled:this.props.submitting,onClick:()=>this.handleCancel()},text:"取消"})]}),...this.state.showPreview&&this.state.content?[this.createElement("div",{className:"cwd-preview-container",children:[this.createElement("div",{className:"cwd-preview-content cwd-comment-content",html:Pt(this.state.content)})]})]:[]]}),r=n.querySelector("textarea");r&&(r.value=this.state.content),this.elements.root=n,this.empty(this.container),this.container.appendChild(n)}updateProps(e){if(this.props.content!==this.state.content&&this.props.content!==(null==e?void 0:e.content))return this.state.content=this.props.content,void this.render();JSON.stringify(this.props.currentUser)===JSON.stringify(null==e?void 0:e.currentUser)&&this.props.error===(null==e?void 0:e.error)&&this.props.submitting===(null==e?void 0:e.submitting)||this.render()}togglePreview(){this.state.showPreview=!this.state.showPreview,this.render()}handleInput(e){var t,n;this.state.content=e.target.value;const r=null==(t=this.elements.root)?void 0:t.querySelector(".cwd-btn-primary");r&&(r.disabled=this.props.submitting||!this.state.content.trim());const i=null==(n=this.elements.root)?void 0:n.querySelector(".cwd-btn-preview");i&&(i.disabled=this.props.submitting||!this.state.content.trim()),this.props.onUpdate&&this.props.onUpdate(this.state.content),this.state.showPreview&&this.updatePreviewContent(this.state.content)}updatePreviewContent(e){var t;const n=null==(t=this.elements.root)?void 0:t.querySelector(".cwd-preview-content");n&&(n.innerHTML=Pt(e))}handleSubmit(){this.props.onSubmit&&this.props.onSubmit()}handleCancel(){this.props.onCancel&&this.props.onCancel()}handleClearError(){this.props.onClearError&&this.props.onClearError()}setContent(e){var t;this.state.content=e;const n=null==(t=this.elements.root)?void 0:t.querySelector("textarea");n&&(n.value=e)}getContent(){return this.state.content}focus(){var e;const t=null==(e=this.elements.root)?void 0:e.querySelector("textarea");t&&t.focus()}handleUserInfoChange(e,t){this.props.onUpdateUserInfo&&this.props.onUpdateUserInfo(e,t)}createFormField(e,t,n,r){return this.createElement("div",{className:"cwd-form-field",children:[this.createElement("input",{className:"cwd-form-input",attributes:{type:t,placeholder:e,value:r||"",disabled:this.props.submitting,onInput:e=>this.handleUserInfoChange(n,e.target.value)}})]})}}function Mt(e){const t=new Date(e),n=(new Date).getTime()-t.getTime(),r=Math.floor(n/1e3),i=Math.floor(r/60),o=Math.floor(i/60),s=Math.floor(o/24);return s<3?s>0?1===s?"昨天":`${s}天前`:o>0?`${o}小时前`:i>0?`${i}分钟前`:"刚刚":function(e){const t=new Date(e),n=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),s=String(t.getMinutes()).padStart(2,"0"),a=String(t.getSeconds()).padStart(2,"0");return`${n}/${r}/${i} ${o}:${s}:${a}`}(e)}const Dt=class e extends h{constructor(e,t={}){super(e,t),this.replyEditor=null,this.childCommentItems=[]}render(){const{comment:t,isReply:n,adminEmail:r,adminBadge:i}=this.props,o="number"==typeof t.priority&&t.priority>1,s=this.props.replyingTo===t.id,a=!!t.isAdmin,l=this.createElement("div",{className:"cwd-comment-item "+(n?"cwd-comment-reply":""),children:[this.createElement("div",{className:"cwd-comment-avatar",children:[this.createElement("img",{attributes:{src:t.avatar,alt:t.name,loading:"lazy"}})]}),this.createElement("div",{className:"cwd-comment-body",children:[this.createElement("div",{className:"cwd-comment-header",children:[this.createElement("div",{className:"cwd-comment-author",children:[t.url?this.createElement("span",{className:"cwd-author-name",children:[this.createElement("a",{attributes:{href:t.url,target:"_blank",rel:"noopener noreferrer"},text:t.name})]}):this.createTextElement("span",t.name,"cwd-author-name"),...a?[i?this.createTextElement("span",`${i}`,"cwd-admin-badge"):this.createElement("span",{className:"cwd-admin-badge cwd-admin-badge-icon",attributes:{title:"网站管理员"},html:'<svg viewBox="0 0 22 22" aria-label="网站管理员" role="img" class="cwd-admin-icon" style="width:15px;height:15px;fill:currentColor;vertical-align:-0.15em;"><g><path d="M20.396 11c-.018-.646-.215-1.275-.57-1.816-.354-.54-.852-.972-1.438-1.246.223-.607.27-1.264.14-1.897-.131-.634-.437-1.218-.882-1.687-.47-.445-1.053-.75-1.687-.882-.633-.13-1.29-.083-1.897.14-.273-.587-.704-1.086-1.245-1.44S11.647 1.62 11 1.604c-.646.017-1.273.213-1.813.568s-.969.854-1.24 1.44c-.608-.223-1.267-.272-1.902-.14-.635.13-1.22.436-1.69.882-.445.47-.749 1.055-.878 1.688-.13.633-.08 1.29.144 1.896-.587.274-1.087.705-1.443 1.245-.356.54-.555 1.17-.574 1.817.02.647.218 1.276.574 1.817.356.54.856.972 1.443 1.245-.224.606-.274 1.263-.144 1.896.13.634.433 1.218.877 1.688.47.443 1.054.747 1.687.878.633.132 1.29.084 1.897-.136.274.586.705 1.084 1.246 1.439.54.354 1.17.551 1.816.569.647-.016 1.276-.213 1.817-.567s.972-.854 1.245-1.44c.604.239 1.266.296 1.903.164.636-.132 1.22-.447 1.68-.907.46-.46.776-1.044.908-1.681s.075-1.299-.165-1.903c.586-.274 1.084-.705 1.439-1.246.354-.54.551-1.17.569-1.816zM9.662 14.85l-3.429-3.428 1.293-1.302 2.072 2.072 4.4-4.794 1.347 1.246z"></path></g></svg>'})]:[],...o?[this.createTextElement("span","置顶","cwd-pin-badge")]:[],...t.replyToAuthor?[this.createTextElement("span"," 回复 ","cwd-reply-to-separator"),this.createTextElement("span",t.replyToAuthor,"cwd-reply-to-author")]:[]]}),this.createElement("div",{className:"cwd-comment-actions",children:[this.createElement("span",{className:"cwd-action-btn",attributes:{onClick:()=>this.handleReply()},text:"回复"}),...!1!==this.props.enableCommentLike?[this.createElement("div",{className:"cwd-comment-like",children:[this.createElement("button",{className:"cwd-comment-like-button"+(this.hasLiked(t.id)?" cwd-comment-like-button-liked":""),attributes:{type:"button","aria-label":this.hasLiked(t.id)?"取消点赞":"点赞",onClick:()=>this.handleLikeComment()},children:[this.createElement("span",{className:"cwd-comment-like-icon-wrapper",children:[this.createElement("svg",{className:"cwd-comment-like-icon",attributes:{viewBox:"0 0 24 24","aria-hidden":"true",fill:this.hasLiked(t.id)?"currentColor":"none"},children:[this.createElement("path",{attributes:{d:"M2 21h4V9H2v12zm20-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L13 1 7.59 6.41C7.22 6.78 7 7.3 7 7.83V19c0 1.1.9 2 2 2h8c.78 0 1.48-.45 1.82-1.11l3.02-7.05c.11-.23.16-.48.16-.74v-2z"}})]})]}),...(()=>{const e="number"==typeof t.likes&&Number.isFinite(t.likes)&&t.likes>=0?t.likes:0;return e>=1?[this.createTextElement("span",String(e),"cwd-comment-like-count")]:[]})()]})]})]:[],this.createTextElement("span",Mt(t.created),"cwd-comment-time")]})]}),this.createElement("div",{className:"cwd-comment-content"}),this.createElement("div",{className:"cwd-reply-editor-container"}),...t.replies&&t.replies.length>0?[this.createElement("div",{className:"cwd-replies"})]:[]]})]}),c=l.querySelector(".cwd-comment-content");if(c&&(c.innerHTML=t.contentHtml),s){const e=l.querySelector(".cwd-reply-editor-container");e&&(this.replyEditor=new zt(e,{replyToAuthor:t.name,content:this.props.replyContent,error:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,onUpdateUserInfo:this.props.onUpdateUserInfo,onUpdate:e=>this.handleUpdateReplyContent(e),onSubmit:()=>this.handleSubmitReply(),onCancel:()=>this.handleCancelReply(),onClearError:()=>this.handleClearReplyError()}),this.replyEditor.render(),this.replyEditor.focus())}else this.replyEditor=null;if(this.childCommentItems=[],t.replies&&t.replies.length>0){const n=l.querySelector(".cwd-replies");n&&t.replies.forEach(t=>{const r=new e(n,{comment:t,isReply:!0,replyingTo:this.props.replyingTo,replyContent:this.props.replyContent,replyError:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,onUpdateUserInfo:this.props.onUpdateUserInfo,adminBadge:this.props.adminBadge,enableCommentLike:this.props.enableCommentLike,onReply:this.props.onReply,onLikeComment:this.props.onLikeComment,onSubmitReply:this.props.onSubmitReply,onCancelReply:this.props.onCancelReply,onUpdateReplyContent:this.props.onUpdateReplyContent,onClearReplyError:this.props.onClearReplyError});r.render(),this.childCommentItems.push(r)})}this.elements.root=l,this.container.contains(l)?this.container.replaceChild(l,this.elements.root):this.container.appendChild(l)}updateProps(e){var t;const{comment:n}=this.props,r=e.replyingTo===n.id,i=this.props.replyingTo===n.id;if(this.props.comment===e.comment){if(i!==r){const e=null==(t=this.elements.root)?void 0:t.querySelector(":scope > .cwd-comment-body > .cwd-reply-editor-container");i&&e?(this.replyEditor=new zt(e,{replyToAuthor:n.name,content:this.props.replyContent,error:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,onUpdateUserInfo:this.props.onUpdateUserInfo,onUpdate:e=>this.handleUpdateReplyContent(e),onSubmit:()=>this.handleSubmitReply(),onCancel:()=>this.handleCancelReply(),onClearError:()=>this.handleClearReplyError()}),this.replyEditor.render(),this.replyEditor.focus()):!i&&e&&(e.innerHTML="",this.replyEditor=null)}else i&&this.replyEditor&&this.replyEditor.setProps({content:this.props.replyContent,error:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser});this.childCommentItems&&this.childCommentItems.length>0&&this.childCommentItems.forEach(e=>{e.setProps({replyingTo:this.props.replyingTo,replyContent:this.props.replyContent,replyError:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,enableCommentLike:this.props.enableCommentLike,onLikeComment:this.props.onLikeComment})})}else this.render()}handleReply(){this.props.onReply&&this.props.onReply(this.props.comment.id)}handleLikeComment(){if(!this.props.onLikeComment)return;const t=String(this.props.comment.id),n=Date.now(),r=`${this.getUserId()}_${t}`,i=e._likeDebounce.get(r);if(i&&n-i<1e3)return;e._likeDebounce.set(r,n);const o=this.getLikedComments();o.has(t)||(o.add(t),this.saveLikedComments(o),this.props.onLikeComment(t,!0))}getUserId(){if(e._userId)return e._userId;const t="cwd_comment_user_id";let n=localStorage.getItem(t);return n||(n="u_"+Date.now()+"_"+Math.random().toString(36).substring(2,12),localStorage.setItem(t,n)),e._userId=n,n}getLikedComments(){const e=`cwd_comment_liked_${this.getUserId()}`,t=localStorage.getItem(e),n=new Set;if(t)try{const e=JSON.parse(t);Array.isArray(e)&&e.forEach(e=>n.add(String(e)))}catch(Wt){}return n}saveLikedComments(e){const t=`cwd_comment_liked_${this.getUserId()}`;localStorage.setItem(t,JSON.stringify(Array.from(e)))}hasLiked(e){return this.getLikedComments().has(String(e))}handleSubmitReply(){this.props.onSubmitReply&&this.props.onSubmitReply(this.props.comment.id)}handleCancelReply(){this.props.onCancelReply&&this.props.onCancelReply()}handleUpdateReplyContent(e){this.props.onUpdateReplyContent&&this.props.onUpdateReplyContent(e)}handleClearReplyError(){this.props.onClearReplyError&&this.props.onClearReplyError()}};r(Dt,"_likeDebounce",new Map),r(Dt,"_userId",null);let Ut=Dt;class $t extends h{constructor(e,t={}){super(e,{text:"加载中...",...t})}render(){const e=this.createElement("div",{className:"cwd-loading",children:[this.createElement("div",{className:"cwd-spinner"}),this.createTextElement("span",this.props.text,"cwd-loading-text")]});this.elements.root=e,this.empty(this.container),this.container.appendChild(e)}setText(e){this.props.text=e;const t=this.elements.root.querySelector(".cwd-loading-text");t&&(t.textContent=e)}}class Ot extends h{constructor(e,t={}){super(e,t),this.state={currentPage:t.currentPage||1,totalPages:t.totalPages||1}}getDisplayedPages(){const{currentPage:e,totalPages:t}=this.state,n=[],r=Math.max(1,e-Math.floor(2.5)),i=Math.min(t,r+5-1);for(let o=i-5+1;o<=i;o++)o>=1&&n.push(o);return n.slice(0,5)}render(){if(this.state.totalPages<=1)return void this.empty(this.container);const e=this.getDisplayedPages(),t=this.createElement("div",{className:"cwd-pagination",children:[this.createElement("button",{className:"cwd-page-btn",attributes:{type:"button",disabled:1===this.state.currentPage,onClick:()=>this.handlePrev()},text:"上一页"}),this.createElement("div",{className:"cwd-page-numbers",children:e.map(e=>this.createElement("button",{className:"cwd-page-num "+(e===this.state.currentPage?"cwd-page-num-active":""),attributes:{type:"button",onClick:()=>this.handleGoTo(e)},text:e.toString()}))}),this.createElement("button",{className:"cwd-page-btn",attributes:{type:"button",disabled:this.state.currentPage===this.state.totalPages,onClick:()=>this.handleNext()},text:"下一页"})]});this.elements.root=t,this.empty(this.container),this.container.appendChild(t)}updateProps(){this.state.currentPage=this.props.currentPage,this.state.totalPages=this.props.totalPages,this.render()}handlePrev(){this.props.onPrev&&this.props.onPrev()}handleNext(){this.props.onNext&&this.props.onNext()}handleGoTo(e){this.props.onGoTo&&this.props.onGoTo(e)}}class Ft extends h{constructor(e,t={}){super(e,t),this.loadingComponent=null,this.paginationComponent=null,this.commentItems=new Map}render(){const{comments:e,loading:t,error:n,currentPage:r,totalPages:i}=this.props;if(this.empty(this.container),t&&0===e.length)return this.loadingComponent=new $t(this.container,{text:"加载评论中..."}),this.loadingComponent.render(),void(this.elements.root=this.loadingComponent.elements.root);if(n&&0===e.length){const e=this.createElement("div",{className:"cwd-error",children:[this.createTextElement("span",n),this.createElement("button",{className:"cwd-error-retry",attributes:{type:"button",onClick:()=>this.handleRetry()},text:"重试"})]});return this.elements.root=e,void this.container.appendChild(e)}const o=this.createElement("div",{className:"cwd-comment-list"});if(e.length>0){const t=this.createElement("div",{className:"cwd-comments"});this.commentItems.clear(),e.forEach((e,n)=>{const r=new Ut(t,{comment:e,replyingTo:this.props.replyingTo,replyContent:this.props.replyContent,replyError:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,onUpdateUserInfo:this.props.onUpdateUserInfo,adminBadge:this.props.adminBadge,enableCommentLike:this.props.enableCommentLike,onReply:e=>this.handleReply(e),onSubmitReply:e=>this.handleSubmitReply(e),onCancelReply:()=>this.handleCancelReply(),onUpdateReplyContent:e=>this.handleUpdateReplyContent(e),onClearReplyError:()=>this.handleClearReplyError(),onLikeComment:(e,t)=>this.handleLikeComment(e,t)});r.render(),this.commentItems.set(e.id,r)}),o.appendChild(t)}else{const e=this.createElement("div",{className:"cwd-empty",children:[this.createTextElement("p","暂无评论,快来抢沙发吧!","cwd-empty-text")]});o.appendChild(e)}if(i>1){const e=this.createElement("div");o.appendChild(e),this.paginationComponent=new Ot(e,{currentPage:r,totalPages:i,onPrev:()=>this.handlePrevPage(),onNext:()=>this.handleNextPage(),onGoTo:e=>this.handleGoToPage(e)}),this.paginationComponent.render()}else this.paginationComponent=null;this.elements.root=o,this.container.appendChild(o)}updateProps(e){if(this.props.loading===e.loading||this.props.loading)if(this.props.comments===e.comments)if(this.props.replyingTo===e.replyingTo&&this.props.replyError===e.replyError&&this.props.submitting===e.submitting&&this.props.currentUser===e.currentUser){if(this.paginationComponent){(this.props.currentPage!==e.currentPage||this.props.totalPages!==e.totalPages)&&(this.paginationComponent.props.currentPage=this.props.currentPage,this.paginationComponent.props.totalPages=this.props.totalPages,this.paginationComponent.updateProps())}}else this.commentItems.forEach(e=>{e.setProps({replyingTo:this.props.replyingTo,replyContent:this.props.replyContent,replyError:this.props.replyError,submitting:this.props.submitting,currentUser:this.props.currentUser,enableCommentLike:this.props.enableCommentLike,onLikeComment:(e,t)=>this.handleLikeComment(e,t)})});else this.render();else this.render()}handleRetry(){this.props.onRetry&&this.props.onRetry()}handleReply(e){this.props.onReply&&this.props.onReply(e)}handleSubmitReply(e){this.props.onSubmitReply&&this.props.onSubmitReply(e)}handleCancelReply(){this.props.onCancelReply&&this.props.onCancelReply()}handleUpdateReplyContent(e){this.props.onUpdateReplyContent&&this.props.onUpdateReplyContent(e)}handleClearReplyError(){this.props.onClearReplyError&&this.props.onClearReplyError()}handleLikeComment(e,t){this.props.onLikeComment&&this.props.onLikeComment(e,t)}handlePrevPage(){this.props.onPrevPage&&this.props.onPrevPage()}handleNextPage(){this.props.onNextPage&&this.props.onNextPage()}handleGoToPage(e){this.props.onGoToPage&&this.props.onGoToPage(e)}}class Bt{constructor(e){this.config={...e},"undefined"!=typeof window&&(this.config.postSlug=window.location.origin+window.location.pathname),"undefined"!=typeof document&&(this.config.postTitle=document.title||this.config.postSlug),"undefined"!=typeof window&&(this.config.postUrl=window.location.origin+window.location.pathname),this.hostElement=this._resolveElement(e.el),this.shadowRoot=null,this.mountPoint=null,this.commentForm=null,this.commentList=null,this.formContainer=null,this.customStyleElement=null,this.store=null,this.unsubscribe=null,this.likeState={count:0,liked:!1,loading:!1},this._likeButtonEl=null,this._likeCountEl=null,this._mounted=!1}_resolveElement(e){if("undefined"==typeof document)return null;if(!e)return null;if("string"==typeof e){const t=document.querySelector(e);return t&&t instanceof HTMLElement?t:null}return e instanceof HTMLElement?e:null}async _loadServerConfig(){try{const e=this.config.apiBaseUrl;if(!e)return{};const t=e.replace(/\/$/,""),n=await fetch(`${t}/api/config/comments`);if(!n.ok)return{};const r=await n.json();return{adminEmail:r.adminEmail||"",adminBadge:r.adminBadge||"",adminEnabled:!!r.adminEnabled,avatarPrefix:r.avatarPrefix||"",allowedDomains:Array.isArray(r.allowedDomains)?r.allowedDomains:[],enableCommentLike:"boolean"!=typeof r.enableCommentLike||r.enableCommentLike,enableArticleLike:"boolean"!=typeof r.enableArticleLike||r.enableArticleLike}}catch(Wt){return{}}}mount(){if(!this._mounted){if(this.hostElement){this.shadowRoot=this.hostElement.attachShadow({mode:"open"});const e=document.createElement("style");e.textContent='.cwd-comments-container,[data-theme=light]{--cwd-primary: #0969da;--cwd-primary-hover: #0864ca;--cwd-text: #24292f;--cwd-text-secondary: #6e7781;--cwd-bg: #ffffff;--cwd-bg-input: #ffffff;--cwd-bg-secondary: #f6f8fa;--cwd-bg-reply: #f6f8fa;--cwd-bg-hover: #f6f8fa;--cwd-bg-disabled: #f6f8fa;--cwd-bg-avatar: #f6f8fa;--cwd-border: #d0d7de;--cwd-border-light: #eaeef2;--cwd-error: #cf222e;--cwd-bg-error: #ffebe9;--cwd-border-error: #fd8c73;--cwd-radius: 6px}[data-theme=dark]{--cwd-primary: #58a6ff;--cwd-primary-hover: #4094ff;--cwd-text: #c9d1d9;--cwd-text-secondary: #8b949e;--cwd-bg: #0d1117;--cwd-bg-input: #0d1117;--cwd-bg-secondary: #161b22;--cwd-bg-reply: #161b22;--cwd-bg-hover: #161b22;--cwd-bg-disabled: #161b22;--cwd-bg-avatar: #161b22;--cwd-border: #30363d;--cwd-border-light: #21262d;--cwd-error: #f85149;--cwd-bg-error: #3d1614;--cwd-border-error: #f85149}*{box-sizing:border-box;margin:0;padding:0}.cwd-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Noto Sans,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;line-height:1.5;color:var(--cwd-text);background:var(--cwd-bg);word-wrap:break-word}.cwd-header{display:flex;align-items:center;justify-content:space-between;padding:16px 0;margin-bottom:16px;border-bottom:1px solid var(--cwd-border)}.cwd-count{font-size:16px;font-weight:600;color:var(--cwd-text)}.cwd-comments-header{padding:16px 0}.cwd-comments-count{font-size:16px;font-weight:600;color:var(--cwd-text)}.cwd-loading{display:flex;align-items:center;justify-content:center;gap:12px;padding:40px 20px;color:var(--cwd-text-secondary, #6e7781)}.cwd-spinner{width:20px;height:20px;border:2px solid var(--cwd-border, #d0d7de);border-top-color:var(--cwd-primary, #0969da);border-radius:50%;animation:cwd-spin .6s linear infinite}@keyframes cwd-spin{to{transform:rotate(360deg)}}.cwd-loading-text{font-size:14px}.cwd-comment-form{background:var(--cwd-bg, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);padding:20px;margin-bottom:24px}.cwd-form-title{margin:0 0 16px;font-size:16px;font-weight:600;color:var(--cwd-text, #24292f)}.cwd-preview-container{margin-top:16px;border-top:1px solid var(--cwd-border, #d0d7de);padding-top:16px}.cwd-preview-title{font-size:13px;font-weight:600;color:var(--cwd-text-secondary, #6e7781);margin-bottom:8px}.cwd-preview-content{padding:12px;min-height:80px;background:var(--cwd-bg, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px)}.cwd-btn-active{background:var(--cwd-bg-hover, #eaeef2);color:var(--cwd-text, #24292f);border-color:var(--cwd-border-active, #8c959f)}.cwd-form-fields{display:flex;flex-direction:column;gap:12px}.cwd-form-row{display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px}@media(max-width:640px){.cwd-form-row{grid-template-columns:1fr}}.cwd-form-field{display:flex;flex-direction:column;gap:4px}.cwd-form-label{font-size:13px;font-weight:500;color:var(--cwd-text, #24292f)}.cwd-form-field input,.cwd-form-field textarea{width:100%;padding:8px 12px;font-size:14px;line-height:1.5;color:var(--cwd-text, #24292f);background:var(--cwd-bg-input, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);transition:border-color .2s,box-shadow .2s;font-family:inherit}.cwd-form-field input:focus,.cwd-form-field textarea:focus{outline:none;border-color:var(--cwd-primary, #0969da);box-shadow:0 0 0 3px #0969da1a}.cwd-form-field input:disabled,.cwd-form-field textarea:disabled{background:var(--cwd-bg-disabled, #f6f8fa);cursor:not-allowed}.cwd-form-field input.cwd-input-error,.cwd-form-field textarea.cwd-input-error{border-color:var(--cwd-error, #cf222e)}.cwd-form-field textarea{resize:vertical;min-height:80px}.cwd-error-text{font-size:12px;color:var(--cwd-error, #cf222e)}.cwd-form-actions{display:flex;justify-content:flex-end;margin-top:16px;gap:10px}.cwd-btn{padding:8px 16px;font-size:14px;font-weight:500;line-height:1.5;border:none;border-radius:var(--cwd-radius, 6px);cursor:pointer;transition:background-color .2s;font-family:inherit}.cwd-btn-primary{color:#fff;background:var(--cwd-primary, #0969da)}.cwd-btn-primary:hover:not(:disabled){background:var(--cwd-primary-hover, #0864ca)}.cwd-btn:disabled{opacity:.6;cursor:not-allowed}.cwd-reply-editor{margin-top:12px;padding:12px;background:var(--cwd-bg-reply, #f6f8fa);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px)}.cwd-reply-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.cwd-reply-to{font-size:13px;font-weight:500;color:var(--cwd-text-secondary, #6e7781)}.cwd-btn-close{width:20px;height:20px;padding:0;font-size:14px;color:var(--cwd-text-secondary, #6e7781);background:transparent;border:none;border-radius:4px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background-color .2s}.cwd-btn-close:hover{background:var(--cwd-bg-hover, rgba(0, 0, 0, .05))}.cwd-reply-textarea{width:100%;padding:8px 12px;font-size:14px;line-height:1.5;color:var(--cwd-text, #24292f);background:var(--cwd-bg-input, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);resize:vertical;font-family:inherit;margin-bottom:8px}.cwd-reply-textarea:focus{outline:none;border-color:var(--cwd-primary, #0969da);box-shadow:0 0 0 3px #0969da1a}.cwd-reply-actions{display:flex;gap:8px;justify-content:flex-end}.cwd-btn-small{padding:4px 10px;font-size:12px}.cwd-btn-secondary{color:var(--cwd-text, #24292f);background:var(--cwd-bg-secondary, #f6f8fa);border:1px solid var(--cwd-border, #d0d7de)}.cwd-btn-secondary:hover:not(:disabled){background:var(--cwd-bg-hover, #eaeef2)}.cwd-comment-item{display:flex;gap:12px;padding:20px 0;border-bottom:1px solid var(--cwd-border-light, #eaeef2)}.cwd-comment-body:hover .cwd-action-btn{display:inline-flex!important}.cwd-comment-item:last-child{border-bottom:none}.cwd-comment-reply{padding-top:12px;padding-bottom:12px}.cwd-comment-avatar{flex-shrink:0;width:40px;height:40px;border-radius:5px;overflow:hidden;background:var(--cwd-bg-avatar, #f6f8fa)}.cwd-comment-avatar img{width:100%;height:100%;object-fit:cover}.cwd-comment-reply .cwd-comment-avatar{width:32px;height:32px}.cwd-comment-body{flex:1;min-width:0}.cwd-comment-header{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;margin-bottom:4px}.cwd-author-name{font-size:16px;font-weight:600;color:var(--cwd-text, #24292f)}.cwd-author-name a{color:inherit;text-decoration:none}.cwd-author-name a:hover{color:var(--cwd-primary, #0969da);text-decoration:underline}.cwd-comment-author{display:inline-flex;flex-wrap:wrap;align-items:center}.cwd-admin-badge{background:#db850d;color:#fff;border-radius:3px;padding:1px 4px;font-size:12px;margin:0 4px}.cwd-pin-badge{background:#fff8c5;color:#9a6700;border-radius:3px;padding:0 6px;font-size:12px;margin:0 4px;border:1px solid #9a6700}.cwd-reply-to-separator{font-size:14px;margin:0 4px}.cwd-reply-to-author{font-size:14px;font-style:italic;color:var(--cwd-text-secondary, #6e7781)}.cwd-comment-time{font-size:12px;color:var(--cwd-text-secondary, #6e7781)}.cwd-comment-content{font-size:14px;line-height:1.6;color:var(--cwd-text, #24292f);word-wrap:break-word;white-space:pre-wrap;margin-top:10px}.cwd-comment-content p{margin:0 0 8px}.cwd-comment-content p:last-child{margin-bottom:0}.cwd-comment-content a{color:var(--cwd-primary, #0969da);text-decoration:none}.cwd-comment-content a:hover{text-decoration:underline}.cwd-comment-content h1,.cwd-comment-content h2,.cwd-comment-content h3,.cwd-comment-content h4,.cwd-comment-content h5,.cwd-comment-content h6{margin-top:16px;margin-bottom:8px;font-weight:600;line-height:1.25}.cwd-comment-content h1{font-size:1.5em}.cwd-comment-content h2{font-size:1.3em}.cwd-comment-content h3{font-size:1.1em}.cwd-comment-content ul,.cwd-comment-content ol{padding-left:1.7em;margin:0 0 8px}.cwd-comment-content li+li{margin-top:4px}.cwd-comment-content code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:.9em;background:var(--cwd-bg-secondary, #f6f8fa);padding:.2em .4em;border-radius:4px}.cwd-comment-content pre{padding:12px;margin:12px 0;overflow-x:auto;background:var(--cwd-bg-secondary, #f6f8fa);border-radius:6px;font-size:.9em}.cwd-comment-content pre code{padding:0;background:transparent;border-radius:0;display:block}.cwd-comment-content blockquote{margin:8px 0;padding:0 12px;border-left:4px solid var(--cwd-border, #d0d7de);color:var(--cwd-text-secondary, #6e7781)}.cwd-comment-content hr{border:0;border-top:1px solid var(--cwd-border-light, #eaeef2);margin:16px 0}.cwd-comment-content table{border-collapse:collapse;border-spacing:0;width:100%;font-size:13px;margin:12px 0}.cwd-comment-content th,.cwd-comment-content td{border:1px solid var(--cwd-border, #d0d7de);padding:6px 12px;text-align:left}.cwd-comment-content th{background:var(--cwd-bg-secondary, #f6f8fa)}.cwd-comment-content img{max-width:100%;height:auto}.cwd-like{display:flex;align-items:center;justify-content:center;padding:30px 15px}.cwd-like-button{display:inline-flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;gap:6px;padding:4px 10px;border-radius:999px;border:1px solid var(--cwd-border-light, #eaeef2);border:none;background:var(--cwd-bg-secondary, #f6f8fa);background:none;color:var(--cwd-text-secondary, #6e7781);cursor:pointer;font-size:13px;font-family:inherit;transition:background-color .2s ease,border-color .2s ease,color .2s ease,transform .15s ease}.cwd-like-button[data-liked=true]{color:var(--cwd-primary, #0969da)}.cwd-like-button[data-loading=true]{opacity:.6;cursor:default;pointer-events:none}.cwd-like-icon-wrapper{display:inline-flex;align-items:center;justify-content:center}.cwd-like-icon{width:32px;height:32px;fill:currentColor}.cwd-like-count{text-align:center}.cwd-like-animate .cwd-like-icon{animation:cwd-like-bounce .3s ease}@keyframes cwd-like-bounce{0%{transform:scale(1)}50%{transform:scale(1.2)}to{transform:scale(1.05)}}.cwd-comment-actions{display:flex;align-items:center;gap:12px}.cwd-comment-like{display:flex;align-items:center}.cwd-comment-like-button{display:inline-flex;align-items:center;border:1px solid var(--cwd-border-light, #eaeef2);border:1px solid transparent;background:var(--cwd-bg-secondary, #f6f8fa);background:none;color:var(--cwd-text-secondary, #6e7781);cursor:pointer;font-size:12px;font-family:inherit;transition:background-color .2s ease,border-color .2s ease,color .2s ease,transform .15s ease}.cwd-comment-like-button:hover{color:var(--cwd-primary, #0969da)}.cwd-comment-like-icon-wrapper{display:inline-flex;align-items:center;justify-content:center}.cwd-comment-like-icon{width:14px;height:14px;fill:currentColor}.cwd-comment-like-count{white-space:nowrap;padding-left:5px;text-align:right}.cwd-action-btn{display:inline-flex;align-items:center;font-size:12px;color:var(--cwd-text-secondary, #6e7781);background:transparent;border:none;border-radius:4px;cursor:pointer;transition:background-color .2s;font-family:inherit;display:none}.cwd-action-btn:hover{color:var(--cwd-primary, #0969da)}.cwd-replies{margin-top:12px;padding-left:12px;border-left:2px solid var(--cwd-border-light, #eaeef2)}.cwd-comment-list{min-height:100px}.cwd{display:flex;flex-direction:column}.cwd-error{padding:20px;text-align:center;color:var(--cwd-error, #cf222e);background:var(--cwd-bg-error, #ffebe9);border:1px solid var(--cwd-border-error, #fd8c73);border-radius:var(--cwd-radius, 6px)}.cwd-error-retry{margin-left:12px;padding:4px 12px;font-size:13px;color:#fff;background:var(--cwd-primary, #0969da);border:none;border-radius:4px;cursor:pointer;font-family:inherit}.cwd-error-retry:hover{background:var(--cwd-primary-hover, #0864ca)}.cwd-empty{padding:40px 20px;text-align:center}.cwd-empty-icon{font-size:48px;margin-bottom:12px}.cwd-empty-text{margin:0;font-size:14px;color:var(--cwd-text-secondary, #6e7781)}.cwd-pagination{display:flex;align-items:center;justify-content:center;gap:8px;padding:20px 0}.cwd-page-btn{padding:6px 12px;font-size:13px;color:var(--cwd-text, #24292f);background:var(--cwd-bg, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);cursor:pointer;transition:background-color .2s;font-family:inherit}.cwd-page-btn:hover:not(:disabled){background:var(--cwd-bg-hover, #f6f8fa)}.cwd-page-btn:disabled{opacity:.5;cursor:not-allowed}.cwd-page-numbers{display:flex;gap:4px}.cwd-page-num{min-width:32px;padding:6px 8px;font-size:13px;color:var(--cwd-text, #24292f);background:var(--cwd-bg, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);cursor:pointer;transition:background-color .2s;font-family:inherit}.cwd-page-num-active{color:#fff;background:var(--cwd-primary, #0969da);border-color:var(--cwd-primary, #0969da)}.cwd-error-inline{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;margin-bottom:16px;font-size:14px;color:var(--cwd-error, #cf222e);background:var(--cwd-bg-error, #ffebe9);border:1px solid var(--cwd-border-error, #fd8c73);border-radius:var(--cwd-radius, 6px)}.cwd-error-close{width:20px;height:20px;padding:0;font-size:14px;color:inherit;background:transparent;border:none;border-radius:4px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background-color .2s}.cwd-error-close:hover{background:#0000001a}.cwd-success-inline{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;margin-bottom:16px;font-size:14px;color:#1a7f37;background:#dafbe1;border:1px solid #54ae65;border-radius:var(--cwd-radius, 6px)}.cwd-load-more{display:block;width:100%;padding:12px;margin:16px 0;font-size:14px;color:var(--cwd-primary);background:var(--cwd-bg-secondary);border:1px solid var(--cwd-border);border-radius:var(--cwd-radius);cursor:pointer;transition:background-color .2s;font-family:inherit}.cwd-load-more:hover{background:var(--cwd-bg-hover)}.fade-enter-active,.fade-leave-active{transition:opacity .2s ease}.fade-enter-from,.fade-leave-to{opacity:0}.cwd-container::-webkit-scrollbar{width:8px;height:8px}.cwd-container::-webkit-scrollbar-track{background:transparent}.cwd-container::-webkit-scrollbar-thumb{background:var(--cwd-border);border-radius:4px}.cwd-container::-webkit-scrollbar-thumb:hover{background:var(--cwd-text-secondary)}.cwd-modal-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background:#00000080;display:flex;align-items:center;justify-content:center;z-index:10000;-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px)}.cwd-modal{background:var(--cwd-bg, #ffffff);border-radius:var(--cwd-radius, 6px);width:90%;max-width:400px;box-shadow:0 8px 24px #0003;border:1px solid var(--cwd-border, #d0d7de);overflow:hidden;animation:cwd-modal-in .2s ease-out}@keyframes cwd-modal-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.cwd-modal-title{margin:0;padding:16px 20px;border-bottom:1px solid var(--cwd-border, #d0d7de);font-size:16px;font-weight:600;color:var(--cwd-text, #24292f)}.cwd-modal-body{padding:20px}.cwd-modal-desc{margin:0 0 16px;font-size:14px;color:var(--cwd-text-secondary, #6e7781)}.cwd-form-input{width:100%;padding:8px 12px;font-size:14px;line-height:1.5;color:var(--cwd-text, #24292f);background:var(--cwd-bg-input, #ffffff);border:1px solid var(--cwd-border, #d0d7de);border-radius:var(--cwd-radius, 6px);transition:border-color .2s,box-shadow .2s;font-family:inherit}.cwd-modal-actions{padding:16px 20px;background:var(--cwd-bg-secondary, #f6f8fa);border-top:1px solid var(--cwd-border, #d0d7de);display:flex;justify-content:flex-end;gap:12px}.cwd-form-field-wrapper{display:flex;flex-direction:column;gap:4px;position:relative}.cwd-admin-controls{position:absolute;top:0;right:0;display:flex;align-items:center;gap:8px;font-size:12px}.cwd-admin-verified{color:#1a7f37;font-weight:500}.cwd-btn-text{background:none;border:none;padding:0;color:var(--cwd-text-secondary);font-size:12px;cursor:pointer;text-decoration:underline}.cwd-btn-text:hover{color:var(--cwd-primary)}.cwd-admin-badge.cwd-admin-badge-icon{background:transparent;padding:0;color:#db850d}.cwd-comment-content .tk-owo-emotion{display:inline-block;vertical-align:bottom;max-width:40px}',this.shadowRoot.appendChild(e),this.mountPoint=document.createElement("div"),this.mountPoint.className="cwd-comments-container",this.shadowRoot.appendChild(this.mountPoint);const t=this.config.theme||"light";this.mountPoint.setAttribute("data-theme",t),this._applyCustomCss()}(async()=>{const e=await this._loadServerConfig();if(!this._mounted)return;if(e.allowedDomains&&e.allowedDomains.length>0&&"undefined"!=typeof window){const t=window.location.hostname;if(!e.allowedDomains.some(e=>t===e||t.endsWith("."+e)))return void(this.mountPoint&&(this.mountPoint.innerHTML=`\n <div style="padding: 20px; text-align: center; color: #666; font-size: 14px; border: 1px solid #eee; border-radius: 8px; background: #f9f9f9;">\n 当前域名 (${t}) 未获得评论组件调用授权\n </div>\n `))}e.avatarPrefix&&(this.config.avatarPrefix=e.avatarPrefix),e.adminEmail&&(this.config.adminEmail=e.adminEmail),e.adminEnabled&&(this.config.adminBadge=e.adminBadge),this.config.requireReview=!!e.requireReview,this.config.enableCommentLike=e.enableCommentLike,this.config.enableArticleLike=e.enableArticleLike;const t=i(this.config);if(this.api=t,this.hostElement&&this.mountPoint&&(this.store=p(this.config,t.fetchComments.bind(t),t.submitComment.bind(t),"function"==typeof t.likeComment?t.likeComment.bind(t):void 0),this.unsubscribe=this.store.store.subscribe((e,t)=>{this._onStateChange(e,t)}),this._render(),this.store.loadComments()),this.api&&"function"==typeof this.api.trackVisit&&this.api.trackVisit(),this.api&&"function"==typeof this.api.getLikeStatus)try{const e=await this.api.getLikeStatus(),t=e&&"number"==typeof e.totalLikes?e.totalLikes:0,n=!(!e||!e.liked);this.likeState.count=t,this.likeState.liked=n,this.store&&"function"==typeof this.store.setLikeState&&this.store.setLikeState(t,n),this._updateLikeButton()}catch(Wt){}})(),this._mounted=!0}}unmount(){if(this._mounted){if(this.commentForm&&(this.commentForm.destroy(),this.commentForm=null),this.commentList&&(this.commentList.destroy(),this.commentList=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.hostElement)for(;this.hostElement.firstChild;)this.hostElement.removeChild(this.hostElement.firstChild);this.shadowRoot=null,this.mountPoint=null,this.store=null,this._mounted=!1}}_render(){if(!this.mountPoint)return;const e=this.store.store.getState(),t=this.mountPoint.querySelector(".cwd-error-inline");if(e.error){if(!t){const t=document.createElement("div");t.className="cwd-error-inline",t.innerHTML=`\n <span>${e.error}</span>\n <button type="button" class="cwd-error-close" data-action="clear-error">✕</button>\n `,t.querySelector('[data-action="clear-error"]').addEventListener("click",()=>{this.store.clearError()}),this.mountPoint.insertBefore(t,this.mountPoint.firstChild)}}else t&&t.remove();const n=this.mountPoint.querySelector(".cwd-success-inline");if(e.successMessage)if(n){const t=n.querySelector("span");t&&(t.textContent=e.successMessage)}else{const t=document.createElement("div");t.className="cwd-success-inline",t.innerHTML=`\n <span>${e.successMessage}</span>\n <button type="button" class="cwd-error-close" data-action="clear-success">✕</button>\n `,t.querySelector('[data-action="clear-success"]').addEventListener("click",()=>{this.store.clearSuccess()}),this.mountPoint.insertBefore(t,this.mountPoint.firstChild)}else n&&n.remove();let r=this.mountPoint.querySelector(".cwd-comments-header");if(!r){r=document.createElement("div"),r.className="cwd-comments-header";const e=!1!==this.config.enableArticleLike;r.innerHTML=`\n\t\t\t\t<div class="cwd-like" ${e?"":'style="display: none;"'}>\n <button type="button" class="cwd-like-button" data-liked="false">\n <span class="cwd-like-icon-wrapper">\n <svg class="cwd-like-icon" viewBox="0 0 24 24" aria-hidden="true">\n <path d="M12 21c-.4 0-.8-.1-1.1-.4L4.5 15C3 13.6 2 11.7 2 9.6 2 6.5 4.5 4 7.6 4c1.7 0 3.3.8 4.4 2.1C13.1 4.8 14.7 4 16.4 4 19.5 4 22 6.5 22 9.6c0 2.1-1 4-2.5 5.4l-6.4 5.6c-.3.3-.7.4-1.1.4z"></path>\n </svg>\n </span>\n\t\t\t\t\t\t<div>已有 <span class="cwd-like-count">0</span>人喜欢~ </div>\n </button>\n </div>\n `,this.mountPoint.appendChild(r)}this._initLikeButton(r),this.formContainer||(this.formContainer=document.createElement("div"),this.mountPoint.appendChild(this.formContainer)),this.commentForm||(this.commentForm=new It(this.formContainer,{form:e.form,formErrors:e.formErrors,submitting:e.submitting,onSubmit:()=>this._handleSubmit(),onFieldChange:(e,t)=>this.store.updateFormField(e,t),adminEmail:this.config.adminEmail,onVerifyAdmin:e=>this.api.verifyAdminKey(e)}),this.commentForm.render());let i=this.mountPoint.querySelector(".cwd-comments-count");i||(i=document.createElement("h3"),i.className="cwd-comments-count",i.innerHTML='\n 共 <span class="cwd-comments-count-number">0</span> 条评论\n ',this.formContainer&&this.formContainer.parentNode===this.mountPoint?this.mountPoint.insertBefore(i,this.formContainer.nextSibling):this.mountPoint.appendChild(i));const o=this.mountPoint.querySelector(".cwd-comments-count-number");if(o&&(o.textContent=e.pagination.totalCount),!this.commentList){const t=document.createElement("div");this.mountPoint.appendChild(t),this.commentList=new Ft(t,{comments:e.comments,loading:e.loading,error:null,currentPage:e.pagination.page,totalPages:this.store.getTotalPages(),replyingTo:e.replyingTo,replyContent:e.replyContent,replyError:e.replyError,submitting:e.submitting,currentUser:e.form,onUpdateUserInfo:(e,t)=>this.store.updateFormField(e,t),adminBadge:this.config.adminBadge,enableCommentLike:!1!==this.config.enableCommentLike,onRetry:()=>this.store.loadComments(),onReply:e=>this.store.startReply(e),onSubmitReply:e=>this.store.submitReply(e),onCancelReply:()=>this.store.cancelReply(),onUpdateReplyContent:e=>this.store.updateReplyContent(e),onClearReplyError:()=>this.store.clearReplyError(),onPrevPage:()=>this.store.goToPage(e.pagination.page-1),onNextPage:()=>this.store.goToPage(e.pagination.page+1),onGoToPage:e=>this.store.goToPage(e),onLikeComment:(e,t)=>{this.store&&"function"==typeof this.store.likeComment&&this.store.likeComment(e,t)}}),this.commentList.render()}}_onStateChange(e,t){var n,r,i,o,s,a,l,c;if(!this._mounted)return;if(null==(r=null==(n=this.commentForm)?void 0:n.elements)?void 0:r.root){const t=this.commentForm.elements.root;null!==e.replyingTo?t.style.display="none":t.style.display=""}this.commentForm&&this.commentForm.setProps({form:e.form,formErrors:e.formErrors,submitting:e.submitting,adminEmail:this.config.adminEmail});const d=null==(i=this.mountPoint)?void 0:i.querySelector(".cwd-error-inline");if(e.error){if(!d){const t=document.createElement("div");t.className="cwd-error-inline",t.innerHTML=`\n <span>${e.error}</span>\n <button type="button" class="cwd-error-close" data-action="clear-error">✕</button>\n `,t.querySelector('[data-action="clear-error"]').addEventListener("click",()=>{this.store.clearError()}),null==(o=this.mountPoint)||o.insertBefore(t,this.mountPoint.firstChild)}}else d&&d.remove();const p=null==(s=this.mountPoint)?void 0:s.querySelector(".cwd-success-inline");if(e.successMessage)if(p){const t=p.querySelector("span");t&&(t.textContent=e.successMessage)}else{const t=document.createElement("div");t.className="cwd-success-inline",t.innerHTML=`\n <span>${e.successMessage}</span>\n <button type="button" class="cwd-error-close" data-action="clear-success">✕</button>\n `,t.querySelector('[data-action="clear-success"]').addEventListener("click",()=>{this.store.clearSuccess()}),null==(a=this.mountPoint)||a.insertBefore(t,this.mountPoint.firstChild)}else p&&p.remove();const h=null==(l=this.mountPoint)?void 0:l.querySelector(".cwd-comments-header"),u=null==(c=this.mountPoint)?void 0:c.querySelector(".cwd-comments-count-number");u&&(u.textContent=e.pagination.totalCount),"number"!=typeof e.likeCount&&"boolean"!=typeof e.liked||("number"==typeof e.likeCount&&(this.likeState.count=e.likeCount),"boolean"==typeof e.liked&&(this.likeState.liked=e.liked),h&&(this._likeButtonEl&&this._likeCountEl||this._initLikeButton(h),this._updateLikeButton())),this.commentList&&this.commentList.setProps({comments:e.comments,loading:e.loading,currentPage:e.pagination.page,totalPages:this.store.getTotalPages(),replyingTo:e.replyingTo,replyContent:e.replyContent,replyError:e.replyError,submitting:e.submitting,currentUser:e.form});t&&t.pagination&&e&&e.pagination&&e.pagination.page!==t.pagination.page&&this._scrollToCommentsTop()}async _handleSubmit(){await this.store.submitNewComment()&&this.commentForm&&(this.commentForm.state.localForm={...this.store.store.getState().form},this.commentForm.state.showPreview=!1,this.commentForm.render())}updateConfig(e){const t={...this.config};Object.assign(this.config,e),"undefined"!=typeof window&&(this.config.postSlug=window.location.origin+window.location.pathname),"undefined"!=typeof document&&(this.config.postTitle=document.title||this.config.postSlug),"undefined"!=typeof window&&(this.config.postUrl=window.location.origin+window.location.pathname),e.theme&&this.mountPoint&&this.mountPoint.setAttribute("data-theme",e.theme);if(this.config.apiBaseUrl!==t.apiBaseUrl||this.config.pageSize!==t.pageSize||this.config.postSlug!==t.postSlug){const e=i(this.config);this.api=e,this.unsubscribe&&this.unsubscribe(),this.store=p(this.config,e.fetchComments.bind(e),e.submitComment.bind(e)),this.unsubscribe=this.store.store.subscribe((e,t)=>{this._onStateChange(e,t)}),this.store.loadComments()}this._applyCustomCss()}_scrollToCommentsTop(){if("undefined"==typeof window)return;const e=this.hostElement||this.mountPoint;e&&"function"==typeof e.scrollIntoView&&e.scrollIntoView({behavior:"smooth",block:"start"})}_applyCustomCss(){if(!this.shadowRoot)return;const e=(this.config&&"string"==typeof this.config.customCssUrl?this.config.customCssUrl:"").trim();if(!e)return this.customStyleElement&&this.customStyleElement.parentNode&&this.customStyleElement.parentNode.removeChild(this.customStyleElement),void(this.customStyleElement=null);if(!this.customStyleElement){const t=document.createElement("link");return t.rel="stylesheet",t.href=e,this.shadowRoot.appendChild(t),void(this.customStyleElement=t)}this.customStyleElement.href=e,this.customStyleElement.parentNode!==this.shadowRoot&&this.shadowRoot.appendChild(this.customStyleElement)}_initLikeButton(e){e&&(this._likeButtonEl||(this._likeButtonEl=e.querySelector(".cwd-like-button"),this._likeButtonEl&&this._likeButtonEl.addEventListener("click",()=>{this._handleLikeClick()})),this._likeCountEl||(this._likeCountEl=e.querySelector(".cwd-like-count")),this._updateLikeButton())}_updateLikeButton(e=!1){var t,n;if(!this._likeButtonEl){if(!this.mountPoint)return;const e=this.mountPoint.querySelector(".cwd-comments-header");if(!e)return;this._initLikeButton(e)}if(!this._likeButtonEl)return;const r=null==(n=null==(t=this.store)?void 0:t.store)?void 0:n.getState(),i=r?!!r.liked:this.likeState.liked,o=r&&"number"==typeof r.likeCount?r.likeCount:this.likeState.count;this.likeState.count=o,this.likeState.liked=i,this._likeButtonEl.dataset.liked=i?"true":"false",this._likeButtonEl.dataset.loading=this.likeState.loading?"true":"false",this._likeCountEl&&(this._likeCountEl.textContent=String(o)),e&&this._likeButtonEl&&(this._likeButtonEl.classList.remove("cwd-like-animate"),this._likeButtonEl.offsetWidth,this._likeButtonEl.classList.add("cwd-like-animate"))}_handleLikeClick(){var e,t;if(!this.api||"function"!=typeof this.api.likePage)return;if(this.likeState.loading)return;const n=null==(t=null==(e=this.store)?void 0:e.store)?void 0:t.getState(),r=n&&"number"==typeof n.likeCount?n.likeCount:this.likeState.count,i=n?!!n.liked:this.likeState.liked;if(i)return;const o=r+1;this.likeState.loading=!0,this.likeState.count=o,this.likeState.liked=!0,this.store&&"function"==typeof this.store.setLikeState&&this.store.setLikeState(o,!0),this._updateLikeButton(!0),this.api.likePage().then(e=>{const t=e&&"number"==typeof e.totalLikes?e.totalLikes:o,n=!(!e||!e.liked);this.likeState.count=t,this.likeState.liked=n,this.store&&"function"==typeof this.store.setLikeState&&this.store.setLikeState(t,n),this._updateLikeButton()}).catch(()=>{this.likeState.count=r,this.likeState.liked=i,this.store&&"function"==typeof this.store.setLikeState&&this.store.setLikeState(r,i),this._updateLikeButton()}).finally(()=>{this.likeState.loading=!1,this._updateLikeButton()})}getConfig(){return{...this.config}}}function qt(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function jt(e){if(!e)return!0;try{return new URL(e),!0}catch{return!1}}function Ht(e){return e&&0!==e.trim().length?e.length>1e3?{valid:!1,error:"评论内容不能超过 1000 字"}:{valid:!0}:{valid:!1,error:"请输入评论内容"}}"undefined"!=typeof window&&(window.CWDComments=Bt);const Gt=Object.freeze(Object.defineProperty({__proto__:null,isValidEmail:qt,isValidUrl:jt,validateCommentContent:Ht,validateCommentForm:function(e){const t={};e.name&&0!==e.name.trim().length?e.name.length>50&&(t.name="昵称不能超过 50 字"):t.name="请输入昵称",e.email&&0!==e.email.trim().length?qt(e.email)||(t.email="邮箱格式不正确"):t.email="请输入邮箱",e.url&&!jt(e.url)&&(t.url="网址格式不正确");const n=Ht(e.content);return n.valid||(t.content=n.error),{valid:0===Object.keys(t).length,errors:t}},validateReplyUserInfo:function(e){const t={};return e.name&&0!==e.name.trim().length?e.name.length>50&&(t.name="昵称不能超过 50 字"):t.name="请输入昵称",e.email&&0!==e.email.trim().length?qt(e.email)||(t.email="邮箱格式不正确"):t.email="请输入邮箱",e.url&&!jt(e.url)&&(t.url="网址格式不正确"),{valid:0===Object.keys(t).length,errors:t}}},Symbol.toStringTag,{value:"Module"}));e.CWDComments=Bt,e.default=Bt,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});