{"id":61733,"date":"2026-01-18T13:50:27","date_gmt":"2026-01-18T05:50:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/61733.html"},"modified":"2026-01-18T13:50:27","modified_gmt":"2026-01-18T05:50:27","slug":"%e3%80%90%e7%bb%84%e4%bb%b6%e5%b0%81%e8%a3%85%e3%80%91%e5%ae%9e%e7%8e%b0%e4%b8%80%e4%b8%aa%e7%9b%b8%e5%af%b9%e5%ae%89%e5%85%a8%e6%80%a7%e9%ab%98%e7%9a%84%e9%98%b2%e7%af%a1%e6%94%b9%e6%b0%b4%e5%8d%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/61733.html","title":{"rendered":"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E7%AC%AC%E4%B8%80%E7%AB%A0%20%E5%89%8D%E8%A8%80-toc\" style=\"margin-left:0px\">\u7b2c\u4e00\u7ae0 \u524d\u8a00<\/p>\n<p id=\"%E7%AC%AC%E4%BA%8C%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E6%A0%88%E6%8B%86%E8%A7%A3-toc\" style=\"margin-left:0px\">\u7b2c\u4e8c\u7ae0\u00a0\u7ec4\u4ef6\u6838\u5fc3\u6280\u672f\u6808\u62c6\u89e3<\/p>\n<p id=\"2.1%20%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:40px\">2.1 \u57fa\u672c\u914d\u7f6e<\/p>\n<p id=\"2.1.1%20props-toc\" style=\"margin-left:80px\">2.1.1 props<\/p>\n<p id=\"2.1.2%C2%A0%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86%E4%B8%8E%E6%96%B9%E6%B3%95%E6%9A%B4%E9%9C%B2-toc\" style=\"margin-left:80px\">2.1.2\u00a0\u751f\u547d\u5468\u671f\u7ba1\u7406\u4e0e\u65b9\u6cd5\u66b4\u9732<\/p>\n<p id=\"2.2%C2%A0Canvas%20%E7%BB%98%E5%9B%BE%E6%8A%80%E6%9C%AF%EF%BC%88%E7%94%9F%E6%88%90%E6%B0%B4%E5%8D%B0%E5%BA%95%E5%9B%BE%EF%BC%89-toc\" style=\"margin-left:40px\">2.2\u00a0Canvas \u7ed8\u56fe\u6280\u672f&#xff08;\u751f\u6210\u6c34\u5370\u5e95\u56fe&#xff09;<\/p>\n<p id=\"2.2.1%C2%A0%E6%96%87%E5%AD%97%E6%8B%86%E5%88%86%EF%BC%88%E8%A7%A3%E5%86%B3%E8%BF%87%E9%95%BF%E6%96%87%E5%AD%97%E6%8D%A2%E8%A1%8C%E9%97%AE%E9%A2%98%EF%BC%89-toc\" style=\"margin-left:80px\">2.2.1\u00a0\u6587\u5b57\u62c6\u5206&#xff08;\u89e3\u51b3\u8fc7\u957f\u6587\u5b57\u6362\u884c\u95ee\u9898&#xff09;<\/p>\n<p id=\"2.2.2%C2%A0Canvas%20%E7%BB%98%E5%88%B6%E5%A4%9A%E5%8D%95%E5%85%83%E6%B0%B4%E5%8D%B0%E5%B9%B6%E8%BD%AC%E6%8D%A2%E4%B8%BA%20base64-toc\" style=\"margin-left:80px\">2.2.2\u00a0Canvas \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370\u5e76\u8f6c\u6362\u4e3a base64<\/p>\n<p id=\"2.3%C2%A0MutationObserver%20DOM%20%E7%AF%A1%E6%94%B9%E7%9B%91%E6%B5%8B%EF%BC%88%E9%98%B2%E7%AF%A1%E6%94%B9%E6%A0%B8%E5%BF%83%EF%BC%89-toc\" style=\"margin-left:40px\">2.3\u00a0MutationObserver DOM \u7be1\u6539\u76d1\u6d4b&#xff08;\u9632\u7be1\u6539\u6838\u5fc3&#xff09;<\/p>\n<p id=\"2.3.1%C2%A0MutationObserver%20API%20%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:80px\">2.3.1\u00a0MutationObserver API \u539f\u7406<\/p>\n<p id=\"2.3.12%20DOM%20%E7%AF%A1%E6%94%B9%E7%9B%91%E6%B5%8B%E4%B8%8E%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D-toc\" style=\"margin-left:80px\">2.3.2 DOM \u7be1\u6539\u76d1\u6d4b\u4e0e\u81ea\u52a8\u6062\u590d<\/p>\n<p id=\"2.4%C2%A0%E9%98%B2%E6%8A%96%EF%BC%88Debounce%EF%BC%89%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:40px\">2.4\u00a0\u9632\u6296&#xff08;Debounce&#xff09;\u6027\u80fd\u4f18\u5316<\/p>\n<p id=\"2.4.1%C2%A0%E9%98%B2%E6%8A%96%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:80px\">2.4.1\u00a0\u9632\u6296\u51fd\u6570\u5b9e\u73b0<\/p>\n<p id=\"2.4.2%C2%A0%E9%98%B2%E6%8A%96%E5%87%BD%E6%95%B0%E7%9A%84%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:80px\">2.4.2\u00a0\u9632\u6296\u51fd\u6570\u7684\u4f7f\u7528<\/p>\n<p id=\"2.5%C2%A0%E5%8E%9F%E7%94%9F%20DOM%20%E6%93%8D%E4%BD%9C%E4%B8%8E%E6%A0%B7%E5%BC%8F%E9%80%82%E9%85%8D-toc\" style=\"margin-left:40px\">2.5\u00a0\u539f\u751f DOM \u64cd\u4f5c\u4e0e\u6837\u5f0f\u9002\u914d<\/p>\n<p id=\"2.5.1%C2%A0%E8%8E%B7%E5%8F%96%E7%9B%AE%E6%A0%87%E5%AE%B9%E5%99%A8%EF%BC%88%E6%B0%B4%E5%8D%B0%E7%BB%91%E5%AE%9A%E5%8F%AF%E5%8A%A8%E6%80%81%E9%85%8D%E7%BD%AE%EF%BC%89-toc\" style=\"margin-left:80px\">2.5.1\u00a0\u83b7\u53d6\u76ee\u6807\u5bb9\u5668&#xff08;\u6c34\u5370\u7ed1\u5b9a\u53ef\u52a8\u6001\u914d\u7f6e&#xff09;<\/p>\n<p id=\"2.5.2%C2%A0%E5%AE%B9%E5%99%A8%E6%A0%B7%E5%BC%8F%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E8%BF%98%E5%8E%9F-toc\" style=\"margin-left:80px\">2.5.2\u00a0\u5bb9\u5668\u6837\u5f0f\u521d\u59cb\u5316\u4e0e\u8fd8\u539f<\/p>\n<p id=\"%E7%AC%AC%E4%B8%89%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E5%AE%9E%E7%8E%B0%E9%9A%BE%E7%82%B9%E4%B8%8E%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:0px\">\u7b2c\u4e09\u7ae0\u00a0\u7ec4\u4ef6\u5b9e\u73b0\u96be\u70b9\u4e0e\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"3.1%C2%A0%E6%B0%B4%E5%8D%B0%20DOM%20%E6%A0%B7%E5%BC%8F%E9%80%82%E9%85%8D-toc\" style=\"margin-left:40px\">3.1\u00a0\u6c34\u5370 DOM \u6837\u5f0f\u9002\u914d<\/p>\n<p id=\"3.2%C2%A0%E5%A4%9A%E8%A1%8C%E6%96%87%E5%AD%97%E6%B0%B4%E5%8D%B0%E7%9A%84%E5%B1%85%E4%B8%AD%E6%8E%92%E7%89%88%E4%B8%8E%E6%97%8B%E8%BD%AC%E9%80%82%E9%85%8D-toc\" style=\"margin-left:40px\">3.2\u00a0\u591a\u884c\u6587\u5b57\u6c34\u5370\u7684\u5c45\u4e2d\u6392\u7248\u4e0e\u65cb\u8f6c\u9002\u914d<\/p>\n<p id=\"3.3%C2%A0%E9%98%B2%E7%AF%A1%E6%94%B9%E7%9A%84%E5%85%A8%E9%9D%A2%E6%80%A7%E4%B8%8E%E5%AE%89%E5%85%A8%E6%80%A7%E4%BF%9D%E9%9A%9C-toc\" style=\"margin-left:40px\">3.3\u00a0\u9632\u7be1\u6539\u7684\u5168\u9762\u6027\u4e0e\u5b89\u5168\u6027\u4fdd\u969c<\/p>\n<p id=\"3.4%C2%A0%E6%80%A7%E8%83%BD%E4%B8%8E%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E7%9A%84%E5%B9%B3%E8%A1%A1-toc\" style=\"margin-left:40px\">3.4\u00a0\u6027\u80fd\u4e0e\u8d44\u6e90\u7ba1\u7406\u7684\u5e73\u8861<\/p>\n<p id=\"%E7%AC%AC%E5%9B%9B%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:0px\">\u7b2c\u56db\u7ae0\u00a0\u7ec4\u4ef6\u4f7f\u7528\u793a\u4f8b<\/p>\n<p id=\"%E7%AC%AC%E4%BA%94%E7%AB%A0%C2%A0%E6%80%BB%E7%BB%93%E4%B8%8E%E6%8B%93%E5%B1%95%E6%96%B9%E5%90%91-toc\" style=\"margin-left:0px\">\u7b2c\u4e94\u7ae0\u00a0\u603b\u7ed3\u4e0e\u62d3\u5c55\u65b9\u5411<\/p>\n<p id=\"%E7%AC%AC%E5%85%AD%E7%AB%A0%20%E6%BA%90%E7%A0%81%EF%BC%88%E5%BC%80%E7%AE%B1%E5%8D%B3%E7%94%A8%EF%BC%89-toc\" style=\"margin-left:0px\">\u7b2c\u516d\u7ae0 \u6e90\u7801&#xff08;\u5f00\u7bb1\u5373\u7528&#xff09;<\/p>\n<hr id=\"hr-toc\" \/>\n<\/p>\n<h2 id=\"%E7%AC%AC%E4%B8%80%E7%AB%A0%20%E5%89%8D%E8%A8%80\">\u7b2c\u4e00\u7ae0 \u524d\u8a00<\/h2>\n<p>\u5728\u4f01\u4e1a\u7ea7\u5e94\u7528\u4e2d&#xff0c;\u6c34\u5370\u662f\u4fdd\u62a4\u654f\u611f\u6570\u636e\u3001\u9632\u6b62\u6587\u6863\u5916\u6cc4\u7684\u91cd\u8981\u624b\u6bb5\u3002\u666e\u901a\u6c34\u5370\u5f80\u5f80\u5b58\u5728\u6613\u88ab\u7be1\u6539\u3001\u6392\u7248\u9519\u4f4d\u3001\u6027\u80fd\u4e0d\u4f73\u7b49\u95ee\u9898&#xff0c;\u7ecf\u8fc7\u5c0f\u7f16\u5b9e\u8df5&#xff0c;\u672c\u6587\u5c31\u662f\u8981\u5b9e\u73b0\u8fd9\u4e48\u4e00\u4e2a\u6c34\u5370\u7ec4\u4ef6&#xff0c;\u4e0d\u4ec5\u5b9e\u73b0\u4e86\u76f8\u5bf9\u5b89\u5168\u6027\u9632\u7be1\u6539&#xff0c;\u8fd8\u5177\u5907\u826f\u597d\u7684\u53ef\u914d\u7f6e\u6027\u548c\u6027\u80fd\u8868\u73b0\u3002\u63a5\u4e0b\u6765&#xff0c;\u5c0f\u7f16\u5c06\u4ece\u6838\u5fc3\u6280\u672f\u3001\u5b9e\u73b0\u96be\u70b9\u3001\u8bbe\u8ba1\u4eae\u70b9\u4e09\u4e2a\u7ef4\u5ea6&#xff0c;\u7ed3\u5408\u5177\u4f53\u4ee3\u7801\u7247\u6bb5\u62c6\u89e3&#xff0c;\u8ba9\u6bcf\u4e00\u4e2a\u6280\u672f\u70b9\u90fd\u6e05\u6670\u53ef\u843d\u5730\u3002<\/p>\n<h2 id=\"%E7%AC%AC%E4%BA%8C%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E6%A0%88%E6%8B%86%E8%A7%A3\">\u7b2c\u4e8c\u7ae0\u00a0\u7ec4\u4ef6\u6838\u5fc3\u6280\u672f\u6808\u62c6\u89e3<\/h2>\n<h3 id=\"2.1%20%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE\">2.1 \u57fa\u672c\u914d\u7f6e<\/h3>\n<h4 id=\"2.1.1%20props\">2.1.1 props<\/h4>\n<p> const props &#061; defineProps({<br \/>\n    text: { type: String, default: &#039;\u5185\u90e8\u6587\u6863 \u00b7 \u7981\u6b62\u5916\u4f20&#039; },<br \/>\n    fontSize: { type: [Number, String], default: 14 },<br \/>\n    fontFamily: { type: String, default: &#039;Microsoft Yahei, sans-serif&#039; },<br \/>\n    color: { type: String, default: &#039;rgba(180, 180, 180, 0.3)&#039; },<br \/>\n    rotate: { type: [Number, String], default: -15 },<br \/>\n    spacing: { type: [Number, String], default: 50 },<br \/>\n    zIndex: { type: [Number, String], default: 999999 },<br \/>\n    debounceTime: { type: [Number, String], default: 300 },<br \/>\n    container: { type: [String, Object], default: &#039;body&#039; },<br \/>\n    lineHeight: { type: [Number, String], default: 1.5 },<br \/>\n    \/\/ \u65b0\u589e&#xff1a;\u6c34\u5370\u5355\u5143\u91cd\u590d\u6570\u91cf&#xff08;\u63a7\u5236\u80cc\u666f\u56fe\u5305\u542b\u7684\u6c34\u5370\u5355\u5143\u6570&#xff09;<br \/>\n    repeatCount: { type: [Number, String], default: 2 }<br \/>\n  }) <\/p>\n<h4 id=\"2.1.2%C2%A0%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86%E4%B8%8E%E6%96%B9%E6%B3%95%E6%9A%B4%E9%9C%B2\">2.1.2\u00a0\u751f\u547d\u5468\u671f\u7ba1\u7406\u4e0e\u65b9\u6cd5\u66b4\u9732<\/h4>\n<p>\/\/ \u66b4\u9732\u65b9\u6cd5\u7ed9\u7236\u7ec4\u4ef6\u8c03\u7528<br \/>\ndefineExpose({ renderWatermark, resetWatermark, destroyWatermark })<\/p>\n<p>\/\/ \u7ec4\u4ef6\u6302\u8f7d\u540e\u6e32\u67d3\u6c34\u5370<br \/>\nonMounted(() &#061;&gt; renderWatermark())<br \/>\n\/\/ \u7ec4\u4ef6\u5378\u8f7d\u540e\u9500\u6bc1\u6c34\u5370&#xff0c;\u91ca\u653e\u8d44\u6e90<br \/>\nonUnmounted(() &#061;&gt; destroyWatermark()) <\/p>\n<ul>\n<li>defineProps\u5b9a\u4e49\u4e86\u4e30\u5bcc\u7684\u914d\u7f6e\u9879&#xff0c;\u652f\u6301Number\/String\u591a\u7c7b\u578b\u4f20\u5165&#xff0c;\u4e14\u90fd\u8bbe\u7f6e\u4e86\u5408\u7406\u9ed8\u8ba4\u503c&#xff0c;\u964d\u4f4e\u4f7f\u7528\u95e8\u69db&#xff1b;<\/li>\n<li>onMounted\/onUnmounted\u5bf9\u5e94 Vue3 \u751f\u547d\u5468\u671f&#xff0c;\u786e\u4fdd\u6c34\u5370\u5728\u7ec4\u4ef6\u6302\u8f7d\u65f6\u521b\u5efa\u3001\u5378\u8f7d\u65f6\u9500\u6bc1&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f&#xff1b;<\/li>\n<li>defineExpose\u66b4\u9732\u6838\u5fc3\u65b9\u6cd5&#xff0c;\u652f\u6301\u5927\u90e8\u5206\u540e\u53f0\u4e1a\u52a1\u4fa7\u8fb9\u624b\u52a8\u63a7\u5236\u6c34\u5370\u751f\u547d\u5468\u671f&#xff0c;\u63d0\u5347\u7ec4\u4ef6\u7075\u6d3b\u6027\u3002<\/li>\n<\/ul>\n<h3 id=\"2.2%C2%A0Canvas%20%E7%BB%98%E5%9B%BE%E6%8A%80%E6%9C%AF%EF%BC%88%E7%94%9F%E6%88%90%E6%B0%B4%E5%8D%B0%E5%BA%95%E5%9B%BE%EF%BC%89\">2.2\u00a0Canvas \u7ed8\u56fe\u6280\u672f&#xff08;\u751f\u6210\u6c34\u5370\u5e95\u56fe&#xff09;<\/h3>\n<ul>\n<li>\u7ec4\u4ef6\u7684\u6c34\u5370\u53ef\u89c6\u5316<span style=\"color:#fe2c24\">\u6838\u5fc3\u4f9d\u8d56 Canvas API<\/span>&#xff0c;\u5c06<span style=\"color:#fe2c24\">\u6587\u5b57\u6c34\u5370\u8f6c\u6362\u4e3a base64 \u683c\u5f0f\u56fe\u7247<\/span>&#xff0c;\u65e2\u63d0\u5347\u6e32\u67d3\u6027\u80fd&#xff0c;\u53c8\u589e\u52a0\u7be1\u6539\u96be\u5ea6\u3002<\/li>\n<\/ul>\n<p>HTML5 &lt;canvas&gt; \u53c2\u8003\u624b\u518c<\/p>\n<p>HTML5 Canvas<\/p>\n<h4 id=\"2.2.1%C2%A0%E6%96%87%E5%AD%97%E6%8B%86%E5%88%86%EF%BC%88%E8%A7%A3%E5%86%B3%E8%BF%87%E9%95%BF%E6%96%87%E5%AD%97%E6%8D%A2%E8%A1%8C%E9%97%AE%E9%A2%98%EF%BC%89\">2.2.1\u00a0\u6587\u5b57\u62c6\u5206&#xff08;\u89e3\u51b3\u8fc7\u957f\u6587\u5b57\u6362\u884c\u95ee\u9898&#xff09;<\/h4>\n<p>\/**<br \/>\n * \u62c6\u5206\u8fc7\u957f\u6587\u5b57\u4e3a\u591a\u884c<br \/>\n *\/<br \/>\nconst _splitTextToLines &#061; (ctx, text, maxWidth) &#061;&gt; {<br \/>\n  if (!text) return []<br \/>\n  const lines &#061; []<br \/>\n  let currentLine &#061; &#039;&#039;<br \/>\n  const chars &#061; text.split(&#039;&#039;)<br \/>\n  for (const char of chars) {<br \/>\n    const testLine &#061; currentLine &#043; char<br \/>\n    const testWidth &#061; ctx.measureText(testLine).width \/\/ \u6d4b\u91cf\u6587\u5b57\u5bbd\u5ea6<br \/>\n    if (testWidth &gt; maxWidth &amp;&amp; currentLine) {<br \/>\n      lines.push(currentLine)<br \/>\n      currentLine &#061; char<br \/>\n    } else {<br \/>\n      currentLine &#061; testLine<br \/>\n    }<br \/>\n  }<br \/>\n  if (currentLine) lines.push(currentLine)<br \/>\n  return lines<br \/>\n} <\/p>\n<h4 id=\"2.2.2%C2%A0Canvas%20%E7%BB%98%E5%88%B6%E5%A4%9A%E5%8D%95%E5%85%83%E6%B0%B4%E5%8D%B0%E5%B9%B6%E8%BD%AC%E6%8D%A2%E4%B8%BA%20base64\">2.2.2\u00a0Canvas \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370\u5e76\u8f6c\u6362\u4e3a base64<\/h4>\n<p>\/**<br \/>\n * \u751f\u6210\u591a\u5355\u5143\u6c34\u5370\u80cc\u666f\u56fe&#xff08;\u6838\u5fc3\u4f18\u5316&#xff09;<br \/>\n *\/<br \/>\nconst _createCanvasBase64 &#061; () &#061;&gt; {<br \/>\n  const { text, fontSize, fontFamily, color, rotate, spacing, lineHeight, repeatCount } &#061; props<br \/>\n  const fontSizeNum &#061; Number(fontSize)<br \/>\n  const lineHeightNum &#061; Number(lineHeight) || 1.5<br \/>\n  const spacingNum &#061; Number(spacing)<br \/>\n  const repeatCountNum &#061; Number(repeatCount) || 2<\/p>\n<p>  \/\/ \u5355\u4e2a\u6c34\u5370\u5355\u5143\u7684\u5c3a\u5bf8<br \/>\n  const singleWidth &#061; spacingNum * 2<br \/>\n  const singleMaxTextWidth &#061; singleWidth * 0.8<br \/>\n  const canvas &#061; document.createElement(&#039;canvas&#039;) \/\/ \u521b\u5efa\u79bb\u7ebfCanvas<br \/>\n  const ctx &#061; canvas.getContext(&#039;2d&#039;) \/\/ \u83b7\u53d62D\u7ed8\u56fe\u4e0a\u4e0b\u6587<\/p>\n<p>  \/\/ \u521d\u59cb\u5316\u753b\u5e03\u4e0a\u4e0b\u6587\u914d\u7f6e<br \/>\n  ctx.fillStyle &#061; color<br \/>\n  ctx.font &#061; &#096;${fontSizeNum}px ${fontFamily}&#096;<br \/>\n  ctx.textAlign &#061; &#039;center&#039;<br \/>\n  ctx.textBaseline &#061; &#039;middle&#039;<\/p>\n<p>  \/\/ \u62c6\u5206\u6587\u5b57\u5e76\u8ba1\u7b97\u5355\u4e2a\u5355\u5143\u9ad8\u5ea6<br \/>\n  const textLines &#061; _splitTextToLines(ctx, text, singleMaxTextWidth)<br \/>\n  const singleHeight &#061; Math.max(spacingNum * 2, textLines.length * fontSizeNum * lineHeightNum)<\/p>\n<p>  \/\/ \u751f\u6210\u5305\u542b\u591a\u4e2a\u5355\u5143\u7684\u80cc\u666f\u56fe&#xff08;\u59822&#215;2&#xff09;<br \/>\n  const canvasWidth &#061; singleWidth * repeatCountNum<br \/>\n  const canvasHeight &#061; singleHeight * repeatCountNum<br \/>\n  canvas.width &#061; canvasWidth<br \/>\n  canvas.height &#061; canvasHeight<br \/>\n  ctx.clearRect(0, 0, canvasWidth, canvasHeight)<\/p>\n<p>  \/\/ \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370&#xff08;\u53cc\u91cd\u5faa\u73af\u5b9e\u73b0\u7f51\u683c\u5e03\u5c40&#xff09;<br \/>\n  for (let x &#061; 0; x &lt; repeatCountNum; x&#043;&#043;) {<br \/>\n    for (let y &#061; 0; y &lt; repeatCountNum; y&#043;&#043;) {<br \/>\n      const unitX &#061; singleWidth * x &#043; singleWidth \/ 2<br \/>\n      const unitY &#061; singleHeight * y &#043; singleHeight \/ 2<\/p>\n<p>      \/\/ \u4fdd\u5b58\/\u6062\u590d\u4e0a\u4e0b\u6587\u72b6\u6001&#xff0c;\u907f\u514d\u5355\u5143\u95f4\u7ed8\u5236\u76f8\u4e92\u5e72\u6270<br \/>\n      ctx.save()<br \/>\n      ctx.translate(unitX, unitY) \/\/ \u5e73\u79fb\u5230\u5f53\u524d\u5355\u5143\u4e2d\u5fc3<br \/>\n      ctx.rotate((Number(rotate) * Math.PI) \/ 180) \/\/ \u89d2\u5ea6\u8f6c\u5f27\u5ea6\u5b9e\u73b0\u65cb\u8f6c<\/p>\n<p>      \/\/ \u7ed8\u5236\u591a\u884c\u6587\u5b57&#xff0c;\u5b9e\u73b0\u5782\u76f4\u5c45\u4e2d<br \/>\n      const totalTextHeight &#061; (textLines.length &#8211; 1) * fontSizeNum * lineHeightNum<br \/>\n      textLines.forEach((line, index) &#061;&gt; {<br \/>\n        const yOffset &#061; (index &#8211; (textLines.length &#8211; 1) \/ 2) * fontSizeNum * lineHeightNum<br \/>\n        ctx.fillText(line, 0, yOffset)<br \/>\n      })<\/p>\n<p>      ctx.restore()<br \/>\n    }<br \/>\n  }<\/p>\n<p>  return canvas.toDataURL(&#039;image\/png&#039;) \/\/ \u8f6c\u6362\u4e3abase64\u683c\u5f0f\u56fe\u7247<br \/>\n} <\/p>\n<ul>\n<li>document.createElement(&#039;canvas&#039;)\u521b\u5efa\u79bb\u7ebf Canvas&#xff0c;\u4e0d\u76f4\u63a5\u63d2\u5165 DOM&#xff0c;\u4ec5\u7528\u4e8e\u751f\u6210\u56fe\u7247&#xff1b;<\/li>\n<li>ctx.measureText()\u6d4b\u91cf\u6587\u5b57\u5bbd\u5ea6&#xff0c;\u662f\u5b9e\u73b0\u6587\u5b57\u81ea\u52a8\u6362\u884c\u7684\u6838\u5fc3&#xff1b;<\/li>\n<li>ctx.rotate()\u63a5\u6536\u5f27\u5ea6\u503c&#xff0c;\u56e0\u6b64\u9700\u8981\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a(\u89d2\u5ea6 * Math.PI) \/ 180&#xff1b;<\/li>\n<li>ctx.save()\/ctx.restore()\u4fdd\u8bc1\u6bcf\u4e2a\u6c34\u5370\u5355\u5143\u7684\u7ed8\u5236\u72b6\u6001\u72ec\u7acb&#xff0c;\u907f\u514d\u65cb\u8f6c\u3001\u5e73\u79fb\u64cd\u4f5c\u76f8\u4e92\u5e72\u6270&#xff1b;<\/li>\n<li>canvas.toDataURL(&#039;image\/png&#039;)\u5c06 Canvas \u5185\u5bb9\u8f6c\u6362\u4e3a base64 \u56fe\u7247&#xff0c;\u7528\u4e8e\u540e\u7eed\u6c34\u5370 DOM \u7684\u80cc\u666f\u56fe\u3002<\/li>\n<\/ul>\n<h3 id=\"2.3%C2%A0MutationObserver%20DOM%20%E7%AF%A1%E6%94%B9%E7%9B%91%E6%B5%8B%EF%BC%88%E9%98%B2%E7%AF%A1%E6%94%B9%E6%A0%B8%E5%BF%83%EF%BC%89\">2.3\u00a0MutationObserver DOM \u7be1\u6539\u76d1\u6d4b&#xff08;\u9632\u7be1\u6539\u6838\u5fc3&#xff09;<\/h3>\n<ul>\n<li>\u7ec4\u4ef6\u7684\u9ad8\u5b89\u5168\u6027\u6838\u5fc3\u4f9d\u8d56<span style=\"color:#fe2c24\">MutationObserver API<\/span>&#xff0c;\u80fd\u591f\u7cbe\u51c6\u76d1\u542c DOM \u6811\u53d8\u5316&#xff0c;\u6355\u83b7\u6076\u610f\u7be1\u6539\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<h4 id=\"2.3.1%C2%A0MutationObserver%20API%20%E5%8E%9F%E7%90%86\">2.3.1\u00a0MutationObserver API \u539f\u7406<\/h4>\n<p>MutationObserver &#8211; Web API | MDN<\/p>\n<p>const observerOptions &#061; {<br \/>\n  childList: true, \/\/ \u76d1\u542c\u5b50\u8282\u70b9\u7684\u589e\u3001\u5220\u64cd\u4f5c<br \/>\n  attributes: true, \/\/ \u76d1\u542c\u5143\u7d20\u5c5e\u6027\u7684\u4fee\u6539&#xff08;\u5982style\u3001class\u3001dataset&#xff09;<br \/>\n  subtree: true, \/\/ \u76d1\u542c\u76ee\u6807\u8282\u70b9\u7684\u6240\u6709\u5b50\u6811&#xff08;\u540e\u4ee3\u8282\u70b9&#xff09;\u7684\u53d8\u5316<br \/>\n  attributeFilter: [&#039;style&#039;, &#039;class&#039;, &#039;dataset&#039;] \/\/ \u4ec5\u76d1\u542c\u6307\u5b9a\u5c5e\u6027\u7684\u4fee\u6539&#xff0c;\u8fdb\u4e00\u6b65\u7f29\u5c0f\u8303\u56f4<br \/>\n} <\/p>\n<ul>\n<li>MutationObserver \u662f<span style=\"color:#fe2c24\">\u6d4f\u89c8\u5668\u539f\u751f\u63d0\u4f9b\u7684\u5f02\u6b65 DOM \u53d8\u5316\u76d1\u6d4b API<\/span>&#xff0c;\u7528\u4e8e\u76d1\u542c DOM \u6811\u7684\u7ed3\u6784\u6216\u5185\u5bb9\u53d1\u751f\u7684\u4efb\u4f55\u6539\u53d8&#xff0c;\u5e76\u5728\u53d8\u5316\u53d1\u751f\u540e\u89e6\u53d1\u6307\u5b9a\u56de\u8c03\u51fd\u6570\u3002\u5b83\u662f\u66ff\u4ee3\u5df2\u5e9f\u5f03\u7684 DOMSubtreeModified \u7b49\u540c\u6b65 DOM \u4e8b\u4ef6\u7684\u9ad8\u6027\u80fd\u65b9\u6848&#xff0c;\u4e5f\u662f\u5b9e\u73b0\u6c34\u5370\u9632\u7be1\u6539\u3001\u52a8\u6001 DOM \u76d1\u63a7\u7b49\u529f\u80fd\u7684\u6838\u5fc3\u6280\u672f\u3002<\/li>\n<li>\u6838\u5fc3\u7279\u70b9&#xff1a;<\/li>\n<\/ul>\n<li>\u5f02\u6b65\u6267\u884c&#xff1a;\u4e0d\u4f1a\u540c\u6b65\u963b\u585e DOM \u6e32\u67d3\u548c\u5176\u4ed6 JavaScript \u6267\u884c&#xff1b;<\/li>\n<li>\u6279\u91cf\u5904\u7406&#xff1a;\u5c06\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u591a\u4e2a DOM \u53d8\u5316\u6536\u96c6\u8d77\u6765&#xff0c;\u6279\u91cf\u89e6\u53d1\u56de\u8c03&#xff1b;<\/li>\n<li>\u7cbe\u51c6\u914d\u7f6e&#xff1a;\u53ef\u6307\u5b9a\u76d1\u542c\u7684\u53d8\u5316\u7c7b\u578b&#xff0c;\u907f\u514d\u65e0\u610f\u4e49\u7684\u5197\u4f59\u56de\u8c03&#xff1b;<\/li>\n<li>\u65e0\u4fb5\u5165\u6027&#xff1a;\u76d1\u542c\u8fc7\u7a0b\u4e0d\u4fee\u6539\u539f\u6709 DOM \u7ed3\u6784\u548c\u903b\u8f91&#xff0c;\u4ec5\u505a\u89c2\u5bdf\u3002<\/li>\n<ul>\n<li>\u76d1\u542c\u673a\u5236&#xff1a;MutationObserver \u6700\u5173\u952e\u7684\u539f\u7406\u662f\u5f02\u6b65\u975e\u963b\u585e\u76d1\u542c&#xff0c;\u5b83\u4e0e onclick\u3001onchange \u7b49\u540c\u6b65 DOM \u4e8b\u4ef6\u6709\u672c\u8d28\u533a\u522b&#xff1a;<\/li>\n<\/ul>\n<li>\u540c\u6b65 DOM \u4e8b\u4ef6&#xff1a;DOM \u53d8\u5316\u53d1\u751f\u65f6&#xff0c;\u7acb\u5373\u89e6\u53d1\u5bf9\u5e94\u7684\u4e8b\u4ef6\u56de\u8c03&#xff0c;\u56de\u8c03\u6267\u884c\u5b8c\u6210\u540e&#xff0c;\u624d\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u7684 JavaScript \u4ee3\u7801\u548c DOM \u6e32\u67d3&#xff0c;\u9891\u7e41\u89e6\u53d1\u53ef\u80fd\u963b\u585e\u9875\u9762&#xff1b;<\/li>\n<li>MutationObserver&#xff1a;DOM \u53d8\u5316\u53d1\u751f\u65f6&#xff0c;\u6d4f\u89c8\u5668\u4e0d\u4f1a\u7acb\u5373\u89e6\u53d1\u56de\u8c03&#xff0c;\u800c\u662f\u5c06\u8be5\u53d8\u5316\u5c01\u88c5\u4e3a MutationRecord&#xff08;\u53d8\u5316\u8bb0\u5f55&#xff09;\u5b58\u5165\u4e00\u4e2a\u5f02\u6b65\u961f\u5217\u4e2d\u3002<\/li>\n<li>\u5f53\u5f53\u524d\u4e3b\u7ebf\u7a0b\u4efb\u52a1\u961f\u5217\u6267\u884c\u5b8c\u6bd5&#xff08;\u5305\u62ec\u540c\u6b65 JS \u4ee3\u7801\u3001\u5b8f\u4efb\u52a1&#xff09;&#xff0c;\u4e14\u5fae\u4efb\u52a1\u961f\u5217\u6e05\u7a7a\u540e&#xff0c;\u6d4f\u89c8\u5668\u624d\u4f1a\u5c06\u961f\u5217\u4e2d\u7684\u6240\u6709 MutationRecord \u6279\u91cf\u53d6\u51fa&#xff0c;\u4f20\u9012\u7ed9 MutationObserver \u7684\u56de\u8c03\u51fd\u6570\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<ul>\n<li>\u4f7f\u7528&#xff1a;<\/li>\n<\/ul>\n<p>\/\/ \u5b9e\u4f8b\u5316&#xff1a;\u56de\u8c03\u51fd\u6570\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\u2014\u2014\u53d8\u5316\u8bb0\u5f55\u6570\u7ec4\u3001\u76d1\u542c\u5668\u5b9e\u4f8b<br \/>\nconst observer &#061; new MutationObserver((mutations, observerInstance) &#061;&gt; {<br \/>\n  \/\/ mutations&#xff1a;\u6279\u91cf\u6536\u96c6\u7684 MutationRecord \u53d8\u5316\u8bb0\u5f55\u6570\u7ec4<br \/>\n  \/\/ observerInstance&#xff1a;\u5f53\u524d MutationObserver \u5b9e\u4f8b&#xff08;\u53ef\u7528\u4e8e\u65ad\u5f00\u76d1\u542c\u7b49\u64cd\u4f5c&#xff09;<br \/>\n  mutations.forEach(mutation &#061;&gt; {<br \/>\n    \/\/ \u5904\u7406\u5355\u4e2a DOM \u53d8\u5316\u8bb0\u5f55<br \/>\n  })<br \/>\n})<\/p>\n<p>\/\/ \u76ee\u6807\u8282\u70b9&#xff08;\u6c34\u5370\u7ec4\u4ef6\u4e2d\u7684\u76ee\u6807\u5bb9\u5668&#xff09;<br \/>\nconst targetContainer &#061; document.querySelector(&#039;#container&#039;)<\/p>\n<p>\/\/ \u542f\u52a8\u76d1\u542c<br \/>\nobserver.observe(targetContainer, observerOptions) <\/p>\n<h4 id=\"2.3.12%20DOM%20%E7%AF%A1%E6%94%B9%E7%9B%91%E6%B5%8B%E4%B8%8E%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D\">2.3.2 DOM \u7be1\u6539\u76d1\u6d4b\u4e0e\u81ea\u52a8\u6062\u590d<\/h4>\n<p>\/**<br \/>\n * \u521d\u59cb\u5316DOM\u7be1\u6539\u76d1\u6d4b<br \/>\n *\/<br \/>\nconst _initMutationObserver &#061; () &#061;&gt; {<br \/>\n  if (observer.value) observer.value.disconnect() \/\/ \u65ad\u5f00\u5df2\u6709\u76d1\u542c&#xff0c;\u907f\u514d\u91cd\u590d\u76d1\u542c<br \/>\n  const observerOptions &#061; {<br \/>\n    childList: true, \/\/ \u76d1\u542c\u5b50\u8282\u70b9\u7684\u589e\u5220\u64cd\u4f5c<br \/>\n    attributes: true, \/\/ \u76d1\u542c\u5143\u7d20\u5c5e\u6027\u7684\u4fee\u6539<br \/>\n    subtree: true, \/\/ \u76d1\u542c\u5b50\u6811&#xff08;\u540e\u4ee3\u8282\u70b9&#xff09;\u7684\u53d8\u5316<br \/>\n    attributeFilter: [&#039;style&#039;, &#039;class&#039;, &#039;dataset&#039;] \/\/ \u53ea\u76d1\u542c\u6307\u5b9a\u5c5e\u6027&#xff0c;\u63d0\u5347\u6027\u80fd<br \/>\n  }<\/p>\n<p>  \/\/ \u5b9e\u4f8b\u5316MutationObserver&#xff0c;\u4f20\u5165\u7be1\u6539\u56de\u8c03\u51fd\u6570<br \/>\n  observer.value &#061; new MutationObserver((mutations) &#061;&gt; {<br \/>\n    let needReRender &#061; false<br \/>\n    mutations.forEach((mutation) &#061;&gt; {<br \/>\n      \/\/ \u573a\u666f1&#xff1a;\u6c34\u5370DOM\u88ab\u5220\u9664<br \/>\n      if (mutation.type &#061;&#061;&#061; &#039;childList&#039; &amp;&amp; mutation.removedNodes.length) {<br \/>\n        const isWatermarkRemoved &#061; Array.from(mutation.removedNodes).some(<br \/>\n          (node) &#061;&gt; node.dataset?.watermarkId &#061;&#061;&#061; watermarkId.value<br \/>\n        )<br \/>\n        if (isWatermarkRemoved) needReRender &#061; true<br \/>\n      }<\/p>\n<p>      \/\/ \u573a\u666f2&#xff1a;\u6c34\u5370DOM\u7684\u6837\u5f0f\/\u7c7b\u540d\/\u5c5e\u6027\u88ab\u4fee\u6539<br \/>\n      if (<br \/>\n        mutation.type &#061;&#061;&#061; &#039;attributes&#039; &amp;&amp;<br \/>\n        mutation.target.dataset?.watermarkId &#061;&#061;&#061; watermarkId.value<br \/>\n      ) {<br \/>\n        needReRender &#061; true<br \/>\n      }<br \/>\n    })<\/p>\n<p>    \/\/ \u4e00\u65e6\u68c0\u6d4b\u5230\u7be1\u6539&#xff0c;\u81ea\u52a8\u91cd\u7f6e\u6c34\u5370<br \/>\n    if (needReRender) resetWatermark()<br \/>\n  })<\/p>\n<p>  \/\/ \u5f00\u59cb\u76d1\u542c\u76ee\u6807\u5bb9\u5668\u7684DOM\u53d8\u5316<br \/>\n  observer.value.observe(targetContainer.value, observerOptions)<br \/>\n} <\/p>\n<ul>\n<li>observerOptions\u914d\u7f6e\u76d1\u542c\u89c4\u5219&#xff0c;\u7cbe\u51c6\u7b5b\u9009\u9700\u8981\u76d1\u542c\u7684 DOM \u53d8\u5316\u7c7b\u578b&#xff0c;\u907f\u514d\u65e0\u610f\u4e49\u7684\u56de\u8c03\u89e6\u53d1&#xff1b;<\/li>\n<li>new MutationObserver((mutations) &#061;&gt; {})\u5b9e\u4f8b\u5316\u76d1\u542c\u5668&#xff0c;mutations\u53c2\u6570\u5305\u542b\u6240\u6709\u89e6\u53d1\u7684 DOM \u53d8\u5316&#xff1b;<\/li>\n<li>\u5206\u522b\u5224\u65adchildList&#xff08;\u8282\u70b9\u5220\u9664&#xff09;\u548cattributes&#xff08;\u5c5e\u6027\u4fee\u6539&#xff09;\u4e24\u79cd\u7be1\u6539\u573a\u666f&#xff0c;\u786e\u4fdd\u5168\u8986\u76d6&#xff1b;<\/li>\n<li>\u7ec4\u4ef6\u9500\u6bc1\u524d\u9700\u8c03\u7528observer.disconnect()\u65ad\u5f00\u76d1\u542c&#xff0c;\u91ca\u653e\u6d4f\u89c8\u5668\u8d44\u6e90&#xff0c;\u4e5f\u5c31\u662f\u9500\u6bc1\u94a9\u5b50\u91cc\u6267\u884c\u3002<\/li>\n<\/ul>\n<h3 id=\"2.4%C2%A0%E9%98%B2%E6%8A%96%EF%BC%88Debounce%EF%BC%89%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96\">2.4\u00a0\u9632\u6296&#xff08;Debounce&#xff09;\u6027\u80fd\u4f18\u5316<\/h3>\n<h4 id=\"2.4.1%C2%A0%E9%98%B2%E6%8A%96%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0\">2.4.1\u00a0\u9632\u6296\u51fd\u6570\u5b9e\u73b0<\/h4>\n<p>\/**<br \/>\n * \u9632\u6296\u51fd\u6570&#xff1a;\u6307\u5b9a\u65f6\u95f4\u5185\u591a\u6b21\u89e6\u53d1&#xff0c;\u4ec5\u6267\u884c\u6700\u540e\u4e00\u6b21<br \/>\n *\/<br \/>\nconst _debounce &#061; (fn, delay) &#061;&gt; {<br \/>\n  let timer &#061; null \/\/ \u5b9a\u65f6\u5668\u7f13\u5b58<br \/>\n  return function () {<br \/>\n    clearTimeout(timer) \/\/ \u6e05\u9664\u4e0a\u4e00\u6b21\u672a\u6267\u884c\u7684\u5b9a\u65f6\u5668<br \/>\n    timer &#061; setTimeout(() &#061;&gt; fn.apply(this, arguments), delay) \/\/ \u91cd\u65b0\u8bbe\u7f6e\u5b9a\u65f6\u5668&#xff0c;\u5ef6\u8fdf\u6267\u884c<br \/>\n  }<br \/>\n} <\/p>\n<p>\u5f88\u7ecf\u5178\u7684\u4e86&#xff0c;\u4e0d\u6e05\u695a\u53ef\u4ee5\u770b\u5c0f\u7f16\u4e0b\u9762\u7684\u6587\u7ae0&#xff1a;<\/p>\n<p>\u524d\u7aef\u5e38\u7528\u7b97\u6cd5&#xff08;\u4e00&#xff09;&#xff1a;\u9632\u6296&#043;\u8282\u6d41<\/p>\n<h4 id=\"2.4.2%C2%A0%E9%98%B2%E6%8A%96%E5%87%BD%E6%95%B0%E7%9A%84%E4%BD%BF%E7%94%A8\">2.4.2\u00a0\u9632\u6296\u51fd\u6570\u7684\u4f7f\u7528<\/h4>\n<p>\/**<br \/>\n * \u76d1\u542c\u7528\u6237\u64cd\u4f5c<br \/>\n *\/<br \/>\nconst _initUserOperationListener &#061; () &#061;&gt; {<br \/>\n  const { debounceTime } &#061; props<br \/>\n  \/\/ \u7ed9\u6c34\u5370\u91cd\u7f6e\u65b9\u6cd5\u6dfb\u52a0\u9632\u6296\u5305\u88c5<br \/>\n  operationHandler.value &#061; _debounce(() &#061;&gt; resetWatermark(), Number(debounceTime))<br \/>\n  const userEvents &#061; [&#039;click&#039;, &#039;input&#039;, &#039;scroll&#039;, &#039;dragend&#039;, &#039;keydown&#039;, &#039;mouseup&#039;, &#039;touchend&#039;]<\/p>\n<p>  \/\/ \u7ed1\u5b9a\u591a\u4e2a\u7528\u6237\u4e8b\u4ef6&#xff0c;\u9632\u6296\u89e6\u53d1\u6c34\u5370\u91cd\u7f6e<br \/>\n  userEvents.forEach((event) &#061;&gt; {<br \/>\n    targetContainer.value.addEventListener(event, operationHandler.value, { passive: true })<br \/>\n  })<br \/>\n} <\/p>\n<ul>\n<li>\u9632\u6296\u7684\u6838\u5fc3\u662fsetTimeout\u548cclearTimeout&#xff0c;\u901a\u8fc7\u7f13\u5b58\u5b9a\u65f6\u5668\u5b9e\u73b0 \u201c\u53d6\u6d88\u4e0a\u4e00\u6b21&#xff0c;\u6267\u884c\u4e0b\u4e00\u6b21\u201d&#xff1b;<\/li>\n<li>fn.apply(this, arguments)\u4fdd\u8bc1\u88ab\u5305\u88c5\u51fd\u6570\u7684this\u6307\u5411\u548c\u53c2\u6570\u4f20\u9012\u4e0d\u4e22\u5931&#xff1b;<\/li>\n<li>\u7ed9\u7528\u6237\u9ad8\u9891\u64cd\u4f5c&#xff08;scroll\/click\u7b49&#xff09;\u7ed1\u5b9a\u9632\u6296\u540e\u7684\u6c34\u5370\u91cd\u7f6e\u65b9\u6cd5&#xff0c;\u907f\u514d\u9891\u7e41\u6267\u884c DOM \u64cd\u4f5c\u548c Canvas \u7ed8\u56fe\u5bfc\u81f4\u9875\u9762\u5361\u987f\u3002<\/li>\n<\/ul>\n<h3 id=\"2.5%C2%A0%E5%8E%9F%E7%94%9F%20DOM%20%E6%93%8D%E4%BD%9C%E4%B8%8E%E6%A0%B7%E5%BC%8F%E9%80%82%E9%85%8D\">2.5\u00a0\u539f\u751f DOM \u64cd\u4f5c\u4e0e\u6837\u5f0f\u9002\u914d<\/h3>\n<h4 id=\"2.5.1%C2%A0%E8%8E%B7%E5%8F%96%E7%9B%AE%E6%A0%87%E5%AE%B9%E5%99%A8%EF%BC%88%E6%B0%B4%E5%8D%B0%E7%BB%91%E5%AE%9A%E5%8F%AF%E5%8A%A8%E6%80%81%E9%85%8D%E7%BD%AE%EF%BC%89\">2.5.1\u00a0\u83b7\u53d6\u76ee\u6807\u5bb9\u5668&#xff08;\u6c34\u5370\u7ed1\u5b9a\u53ef\u52a8\u6001\u914d\u7f6e&#xff09;<\/h4>\n<p>\/**<br \/>\n * \u83b7\u53d6\u76ee\u6807\u5bb9\u5668\u5b9e\u4f8b<br \/>\n *\/<br \/>\nconst _getTargetContainer &#061; () &#061;&gt; {<br \/>\n  let container &#061; null<br \/>\n  if (typeof props.container &#061;&#061;&#061; &#039;string&#039;) {<br \/>\n    \/\/ \u5b57\u7b26\u4e32\u9009\u62e9\u5668&#xff1a;\u901a\u8fc7querySelector\u83b7\u53d6DOM<br \/>\n    container &#061; document.querySelector(props.container)<br \/>\n  } else if (props.container instanceof HTMLElement) {<br \/>\n    \/\/ \u76f4\u63a5\u4f20\u5165HTMLElement\u5b9e\u4f8b&#xff0c;\u76f4\u63a5\u4f7f\u7528<br \/>\n    container &#061; props.container<br \/>\n  }<\/p>\n<p>  \/\/ \u5bb9\u9519\u5904\u7406&#xff1a;\u5bb9\u5668\u4e0d\u5b58\u5728\u65f6&#xff0c;\u9ed8\u8ba4\u4f7f\u7528body<br \/>\n  if (!container || !(container instanceof HTMLElement)) {<br \/>\n    console.warn(&#039;\u6c34\u5370\u76ee\u6807\u5bb9\u5668\u4e0d\u5b58\u5728&#xff0c;\u9ed8\u8ba4\u4f7f\u7528body&#039;)<br \/>\n    container &#061; document.body<br \/>\n  }<br \/>\n  return container<br \/>\n} <\/p>\n<h4 id=\"2.5.2%C2%A0%E5%AE%B9%E5%99%A8%E6%A0%B7%E5%BC%8F%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E8%BF%98%E5%8E%9F\">2.5.2\u00a0\u5bb9\u5668\u6837\u5f0f\u521d\u59cb\u5316\u4e0e\u8fd8\u539f<\/h4>\n<p>\/**<br \/>\n * \u521d\u59cb\u5316\u5bb9\u5668\u6837\u5f0f&#xff08;\u6dfb\u52a0\u6ea2\u51fa\u9690\u85cf\u548c\u5b9a\u4f4d&#xff09;<br \/>\n *\/<br \/>\nconst _initContainerStyle &#061; () &#061;&gt; {<br \/>\n  const container &#061; targetContainer.value<br \/>\n  if (container !&#061;&#061; document.body) {<br \/>\n    const computedStyle &#061; window.getComputedStyle(container)<br \/>\n    \/\/ \u4fdd\u5b58\u5bb9\u5668\u539f\u6709\u6837\u5f0f&#xff0c;\u7528\u4e8e\u540e\u7eed\u8fd8\u539f<br \/>\n    originContainerStyle.value &#061; {<br \/>\n      position: computedStyle.position,<br \/>\n      overflow: computedStyle.overflow<br \/>\n    }<\/p>\n<p>    \/\/ \u786e\u4fdd\u5bb9\u5668\u6709\u5b9a\u4f4d&#xff0c;\u8ba9\u6c34\u5370\u7684absolute\u5b9a\u4f4d\u751f\u6548<br \/>\n    if (<br \/>\n      ![&#039;relative&#039;, &#039;absolute&#039;, &#039;fixed&#039;, &#039;sticky&#039;].includes(originContainerStyle.value.position)<br \/>\n    ) {<br \/>\n      container.style.position &#061; &#039;relative !important&#039;<br \/>\n    }<br \/>\n    \/\/ \u786e\u4fdd\u5bb9\u5668\u6ea2\u51fa\u9690\u85cf&#xff0c;\u907f\u514d\u6c34\u5370\u8d85\u51fa\u5bb9\u5668\u8303\u56f4<br \/>\n    container.style.overflow &#061; &#039;hidden !important&#039;<br \/>\n  }<br \/>\n}<\/p>\n<p>\/\/ \u9500\u6bc1\u6c34\u5370\u65f6\u8fd8\u539f\u5bb9\u5668\u6837\u5f0f&#xff08;\u5bf9\u5e94destroyWatermark\u65b9\u6cd5\u7247\u6bb5&#xff09;<br \/>\nif (targetContainer.value &amp;&amp; targetContainer.value !&#061;&#061; document.body) {<br \/>\n  targetContainer.value.style.position &#061; originContainerStyle.value.position<br \/>\n  targetContainer.value.style.overflow &#061; originContainerStyle.value.overflow<br \/>\n  originContainerStyle.value &#061; { position: &#039;&#039;, overflow: &#039;&#039; }<br \/>\n} <\/p>\n<ul>\n<li>\u652f\u6301\u4e24\u79cd\u5bb9\u5668\u4f20\u5165\u65b9\u5f0f&#xff08;\u5b57\u7b26\u4e32\u9009\u62e9\u5668 \/ HTMLElement \u5b9e\u4f8b&#xff09;&#xff0c;\u63d0\u5347\u7ec4\u4ef6\u7075\u6d3b\u6027&#xff1b;<\/li>\n<li>\u4fdd\u5b58\u5bb9\u5668\u539f\u6709\u6837\u5f0f&#xff0c;\u6302\u8f7d\u6c34\u5370\u65f6\u4e34\u65f6\u4fee\u6539&#xff0c;\u9500\u6bc1\u65f6\u8fd8\u539f&#xff0c;\u907f\u514d\u5f71\u54cd\u9875\u9762\u539f\u6709\u5e03\u5c40&#xff1b;<\/li>\n<li>\u7ed9\u975ebody\u5bb9\u5668\u6dfb\u52a0relative\u5b9a\u4f4d&#xff0c;\u786e\u4fdd\u6c34\u5370\u7684absolute\u5b9a\u4f4d\u76f8\u5bf9\u4e8e\u5bb9\u5668\u751f\u6548&#xff0c;\u800c\u4e0d\u662f\u6574\u4e2a\u6587\u6863\u3002<\/li>\n<\/ul>\n<h2 id=\"%E7%AC%AC%E4%B8%89%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E5%AE%9E%E7%8E%B0%E9%9A%BE%E7%82%B9%E4%B8%8E%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\">\u7b2c\u4e09\u7ae0\u00a0\u7ec4\u4ef6\u5b9e\u73b0\u96be\u70b9\u4e0e\u89e3\u51b3\u65b9\u6848<\/h2>\n<h3 id=\"3.1%C2%A0%E6%B0%B4%E5%8D%B0%20DOM%20%E6%A0%B7%E5%BC%8F%E9%80%82%E9%85%8D\">3.1\u00a0\u6c34\u5370 DOM \u6837\u5f0f\u9002\u914d<\/h3>\n<ul>\n<li>\u9700\u6c42&#xff1a;\u6c34\u5370\u5b8c\u6574\u5e73\u94fa\u65e0\u9519\u4f4d&#xff0c;\u9002\u914d\u4e0d\u540c\u5bb9\u5668&#xff1b;\u4e0d\u540c\u5bb9\u5668&#xff08;body\/ \u666e\u901a\u5b9a\u5bbd\u9ad8\u5143\u7d20&#xff09;\u3001\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b&#xff0c;\u5982\u4f55\u4fdd\u8bc1\u6c34\u5370\u5e73\u94fa\u5b8c\u6574\u3001\u65e0\u8fb9\u7f18\u9519\u4f4d\u3001\u4e0d\u5f71\u54cd\u539f\u6709\u9875\u9762\u5e03\u5c40&#xff1f;<\/li>\n<\/ul>\n<p>\/**<br \/>\n * \u521b\u5efa\u6c34\u5370DOM\u5143\u7d20&#xff08;\u9002\u914d\u5b8c\u6574\u5e73\u94fa&#xff09;<br \/>\n *\/<br \/>\nconst _createWatermarkDom &#061; () &#061;&gt; {<br \/>\n  const { zIndex, spacing, repeatCount } &#061; props<br \/>\n  const base64Url &#061; _createCanvasBase64()<br \/>\n  const container &#061; targetContainer.value<br \/>\n  const spacingNum &#061; Number(spacing)<br \/>\n  const repeatCountNum &#061; Number(repeatCount) || 2<br \/>\n  const singleWidth &#061; spacingNum * 2<br \/>\n  const singleHeight &#061; spacingNum * 2<\/p>\n<p>  \/\/ \u533a\u5206\u5bb9\u5668\u7c7b\u578b&#xff0c;\u914d\u7f6e\u4e0d\u540c\u7684\u5bbd\u9ad8\u548c\u5b9a\u4f4d\u65b9\u5f0f<br \/>\n  const containerWidth &#061; container &#061;&#061;&#061; document.body ? &#039;100vw&#039; : &#096;${container.offsetWidth}px&#096;<br \/>\n  const containerHeight &#061; container &#061;&#061;&#061; document.body ? &#039;100vh&#039; : &#096;${container.offsetHeight}px&#096;<br \/>\n  const positionType &#061; container &#061;&#061;&#061; document.body ? &#039;fixed&#039; : &#039;absolute&#039;<\/p>\n<p>  \/\/ \u80cc\u666f\u56fe\u5c3a\u5bf8&#xff08;\u591a\u5355\u5143\u6574\u4f53\u5c3a\u5bf8&#xff09;&#xff0c;\u786e\u4fdd\u5e73\u94fa\u65e0\u9519\u4f4d<br \/>\n  const bgSize &#061; &#096;${singleWidth * repeatCountNum}px ${singleHeight * repeatCountNum}px&#096;<br \/>\n  const bgPosition &#061; &#096;0 0&#096;<\/p>\n<p>  const watermark &#061; document.createElement(&#039;div&#039;)<br \/>\n  \/\/ \u7528!important\u9501\u5b9a\u6838\u5fc3\u6837\u5f0f&#xff0c;\u9632\u6b62\u88ab\u9875\u9762\u5176\u4ed6\u6837\u5f0f\u8986\u76d6<br \/>\n  watermark.style.cssText &#061; &#096;<br \/>\n    position: ${positionType} !important;<br \/>\n    top: 0 !important;<br \/>\n    left: 0 !important;<br \/>\n    width: ${containerWidth} !important;<br \/>\n    height: ${containerHeight} !important;<br \/>\n    z-index: ${zIndex} !important;<br \/>\n    pointer-events: none !important; \/* \u7a7f\u900f\u6c34\u5370&#xff0c;\u4e0d\u5f71\u54cd\u4e0b\u65b9\u5143\u7d20\u4ea4\u4e92 *\/<br \/>\n    background-image: url(${base64Url}) !important;<br \/>\n    background-repeat: repeat !important; \/* \u80cc\u666f\u56fe\u5e73\u94fa&#xff0c;\u5b9e\u73b0\u5168\u5c4f\/\u5168\u5bb9\u5668\u8986\u76d6 *\/<br \/>\n    background-position: ${bgPosition} !important;<br \/>\n    background-size: ${bgSize} !important;<br \/>\n    user-select: none !important; \/* \u7981\u6b62\u9009\u4e2d\u6c34\u5370&#xff0c;\u63d0\u5347\u9632\u7be1\u6539\u80fd\u529b *\/<br \/>\n  &#096;<br \/>\n  watermarkId.value &#061; &#039;unique-watermark-&#039; &#043; Date.now() \/\/ \u751f\u6210\u552f\u4e00\u6c34\u5370ID<br \/>\n  watermark.dataset.watermarkId &#061; watermarkId.value \/\/ \u7ed1\u5b9a\u5230dataset&#xff0c;\u7528\u4e8e\u7be1\u6539\u8bc6\u522b<\/p>\n<p>  return watermark<br \/>\n} <\/p>\n<ul>\n<li>\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul>\n<li>\u5bb9\u5668\u7c7b\u578b\u533a\u5206&#xff1a;body\u5bb9\u5668\u4f7f\u7528100vw\/100vh\u5bbd\u9ad8 &#043;fixed\u5b9a\u4f4d&#xff0c;\u5b9e\u73b0\u5168\u5c4f\u5e73\u94fa&#xff1b;\u666e\u901a\u5bb9\u5668\u4f7f\u7528offsetWidth\/offsetHeight\u5bbd\u9ad8 &#043;absolute\u5b9a\u4f4d&#xff0c;\u5b9e\u73b0\u5bb9\u5668\u5185\u5e73\u94fa&#xff1b;<\/li>\n<li>\u591a\u5355\u5143\u6c34\u5370\u4f18\u5316&#xff1a;\u751f\u6210repeatCount\u00d7repeatCount\u7684\u591a\u5355\u5143\u6c34\u5370\u56fe&#xff0c;\u901a\u8fc7background-repeat: repeat\u5e73\u94fa&#xff0c;\u51cf\u5c11\u80cc\u666f\u56fe\u6e32\u67d3\u6b21\u6570&#xff0c;\u907f\u514d\u8fb9\u7f18\u9519\u4f4d&#xff1b;<\/li>\n<li>\u6837\u5f0f\u9501\u5b9a&#xff1a;\u4f7f\u7528!important\u9501\u5b9a\u6838\u5fc3\u6837\u5f0f&#xff0c;\u9632\u6b62\u88ab\u9875\u9762\u5176\u4ed6\u6837\u5f0f\u8986\u76d6&#xff1b;pointer-events: none\u5b9e\u73b0\u6c34\u5370\u7a7f\u900f&#xff0c;\u4e0d\u5f71\u54cd\u4e0b\u65b9\u5143\u7d20\u7684\u4ea4\u4e92&#xff1b;<\/li>\n<li>\u552f\u4e00 ID \u6807\u8bc6&#xff1a;\u751f\u6210unique-watermark-&#043;Date.now()\u552f\u4e00 ID&#xff0c;\u7ed1\u5b9a\u5230dataset.watermarkId&#xff0c;\u7528\u4e8e\u7cbe\u51c6\u8bc6\u522b\u6c34\u5370 DOM&#xff0c;\u907f\u514d\u8bef\u5224\u3002<\/li>\n<h3 id=\"3.2%C2%A0%E5%A4%9A%E8%A1%8C%E6%96%87%E5%AD%97%E6%B0%B4%E5%8D%B0%E7%9A%84%E5%B1%85%E4%B8%AD%E6%8E%92%E7%89%88%E4%B8%8E%E6%97%8B%E8%BD%AC%E9%80%82%E9%85%8D\">3.2\u00a0\u591a\u884c\u6587\u5b57\u6c34\u5370\u7684\u5c45\u4e2d\u6392\u7248\u4e0e\u65cb\u8f6c\u9002\u914d<\/h3>\n<ul>\n<li>\u9700\u6c42&#xff1a;\u5f53\u6c34\u5370\u6587\u5b57\u8fc7\u957f\u65f6&#xff0c;\u76f4\u63a5\u6e32\u67d3\u4f1a\u8d85\u51fa\u5bb9\u5668\u8303\u56f4&#xff0c;\u65cb\u8f6c\u540e\u66f4\u96be\u4fdd\u8bc1\u5c45\u4e2d\u5bf9\u9f50&#xff0c;\u5982\u4f55\u5b9e\u73b0\u4f18\u96c5\u7684\u591a\u884c\u6392\u7248\u4e0e\u5782\u76f4\u5c45\u4e2d&#xff1f;<\/li>\n<\/ul>\n<p>\/\/ 1. \u62c6\u5206\u6587\u5b57&#xff08;\u5df2\u5728\u6838\u5fc3\u6280\u672f\u90e8\u5206\u5c55\u793a&#xff0c;\u6b64\u5904\u805a\u7126\u7ed8\u5236\u903b\u8f91&#xff09;<br \/>\nconst textLines &#061; _splitTextToLines(ctx, text, singleMaxTextWidth)<\/p>\n<p>\/\/ 2. \u8ba1\u7b97\u591a\u884c\u6587\u5b57\u603b\u9ad8\u5ea6\u4e0e\u5355\u4e2a\u6c34\u5370\u5355\u5143\u9ad8\u5ea6<br \/>\nconst totalTextHeight &#061; (textLines.length &#8211; 1) * fontSizeNum * lineHeightNum<br \/>\nconst singleHeight &#061; Math.max(spacingNum * 2, textLines.length * fontSizeNum * lineHeightNum)<\/p>\n<p>\/\/ 3. \u5e73\u79fb\u5230\u5355\u5143\u4e2d\u5fc3&#xff0c;\u51c6\u5907\u65cb\u8f6c<br \/>\nctx.translate(unitX, unitY)<br \/>\nctx.rotate((Number(rotate) * Math.PI) \/ 180)<\/p>\n<p>\/\/ 4. \u7ed8\u5236\u591a\u884c\u6587\u5b57&#xff0c;\u5b9e\u73b0\u5782\u76f4\u5c45\u4e2d<br \/>\ntextLines.forEach((line, index) &#061;&gt; {<br \/>\n  \/\/ \u8ba1\u7b97\u6bcf\u884c\u6587\u5b57\u7684\u5782\u76f4\u504f\u79fb\u91cf&#xff0c;\u786e\u4fdd\u6574\u4f53\u5c45\u4e2d<br \/>\n  const yOffset &#061; (index &#8211; (textLines.length &#8211; 1) \/ 2) * fontSizeNum * lineHeightNum<br \/>\n  ctx.fillText(line, 0, yOffset)<br \/>\n}) <\/p>\n<ul>\n<li>\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul>\n<li>\u6587\u5b57\u62c6\u5206&#xff1a;\u901a\u8fc7_splitTextToLines\u65b9\u6cd5\u5c06\u8fc7\u957f\u6587\u5b57\u62c6\u5206\u4e3a\u591a\u884c&#xff0c;\u907f\u514d\u8d85\u51fa\u6c34\u5370\u5355\u5143\u8303\u56f4&#xff1b;<\/li>\n<li>\u9ad8\u5ea6\u8ba1\u7b97&#xff1a;\u57fa\u4e8efontSize\u548clineHeight\u8ba1\u7b97\u591a\u884c\u6587\u5b57\u603b\u9ad8\u5ea6&#xff0c;\u786e\u4fdd\u6c34\u5370\u5355\u5143\u9ad8\u5ea6\u8db3\u591f\u5bb9\u7eb3\u6240\u6709\u6587\u5b57&#xff1b;<\/li>\n<li>\u5782\u76f4\u504f\u79fb\u8ba1\u7b97&#xff1a;(index &#8211; (textLines.length &#8211; 1) \/ 2) * fontSizeNum * lineHeightNum\u662f\u5c45\u4e2d\u6838\u5fc3&#xff0c;\u901a\u8fc7\u7d22\u5f15\u504f\u79fb\u8ba9\u591a\u884c\u6587\u5b57\u6574\u4f53\u5782\u76f4\u5c45\u4e2d&#xff1b;<\/li>\n<li>\u4e0a\u4e0b\u6587\u72b6\u6001\u7ba1\u7406&#xff1a;ctx.save()\/ctx.restore()\u786e\u4fdd\u65cb\u8f6c\u64cd\u4f5c\u4ec5\u4f5c\u7528\u4e8e\u5f53\u524d\u6c34\u5370\u5355\u5143&#xff0c;\u4e0d\u5f71\u54cd\u5176\u4ed6\u5355\u5143\u7684\u7ed8\u5236\u3002<\/li>\n<h3 id=\"3.3%C2%A0%E9%98%B2%E7%AF%A1%E6%94%B9%E7%9A%84%E5%85%A8%E9%9D%A2%E6%80%A7%E4%B8%8E%E5%AE%89%E5%85%A8%E6%80%A7%E4%BF%9D%E9%9A%9C\">3.3\u00a0\u9632\u7be1\u6539\u7684\u5168\u9762\u6027\u4e0e\u5b89\u5168\u6027\u4fdd\u969c<\/h3>\n<ul>\n<li>\u95ee\u9898\u63cf\u8ff0&#xff1a;\u6076\u610f\u7528\u6237\u53ef\u80fd\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u7be1\u6539\u6c34\u5370&#xff08;\u5220\u9664 DOM\u3001\u4fee\u6539\u6837\u5f0f\u3001\u4fee\u6539\u5c5e\u6027&#xff09;&#xff0c;\u5982\u4f55\u5b9e\u73b0\u5168\u65b9\u4f4d\u7684\u9632\u7be1\u6539\u8986\u76d6&#xff0c;\u8ba9\u7be1\u6539\u64cd\u4f5c\u65e0\u6548&#xff1f;<\/li>\n<\/ul>\n<p>\/\/ \u673a\u52361&#xff1a;\u9ad8\u4f18\u5148\u7ea7\u6837\u5f0f\u9501&#xff0c;\u9632\u6b62\u666e\u901a\u6837\u5f0f\u8986\u76d6<br \/>\nwatermark.style.cssText &#061; &#096;<br \/>\n  position: ${positionType} !important;<br \/>\n  background-image: url(${base64Url}) !important;<br \/>\n  z-index: ${zIndex} !important;<br \/>\n&#096;<\/p>\n<p>\/\/ \u673a\u52362&#xff1a;MutationObserver\u7cbe\u51c6\u76d1\u6d4b\u7be1\u6539\u884c\u4e3a&#xff08;\u5df2\u5728\u6838\u5fc3\u6280\u672f\u90e8\u5206\u5c55\u793a&#xff09;<br \/>\nconst isWatermarkRemoved &#061; Array.from(mutation.removedNodes).some(<br \/>\n  (node) &#061;&gt; node.dataset?.watermarkId &#061;&#061;&#061; watermarkId.value<br \/>\n)<\/p>\n<p>\/\/ \u673a\u52363&#xff1a;\u7be1\u6539\u540e\u81ea\u52a8\u91cd\u7f6e\u6c34\u5370&#xff0c;\u8ba9\u7be1\u6539\u65e0\u6548<br \/>\nif (needReRender) resetWatermark()<\/p>\n<p>\/\/ \u673a\u52364&#xff1a;\u7528\u6237\u64cd\u4f5c\u515c\u5e95&#xff0c;\u9632\u6296\u76d1\u542c\u9ad8\u9891\u64cd\u4f5c&#xff0c;\u5f02\u5e38\u65f6\u91cd\u7f6e\u6c34\u5370<br \/>\noperationHandler.value &#061; _debounce(() &#061;&gt; resetWatermark(), Number(debounceTime)) <\/p>\n<ul>\n<li>\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul>\n<li>\u6837\u5f0f\u9501&#xff1a;\u4f7f\u7528!important\u9501\u5b9a\u6838\u5fc3\u6837\u5f0f&#xff0c;\u62b5\u5fa1\u666e\u901a CSS \u6837\u5f0f\u8986\u76d6&#xff1b;<\/li>\n<li>\u7cbe\u51c6\u76d1\u6d4b&#xff1a;\u901a\u8fc7MutationObserver\u76d1\u542c\u6c34\u5370 DOM \u7684\u5220\u9664\u548c\u5c5e\u6027\u4fee\u6539&#xff0c;\u65e0\u6b7b\u89d2\u6355\u83b7\u7be1\u6539\u884c\u4e3a&#xff1b;<\/li>\n<li>\u81ea\u52a8\u6062\u590d&#xff1a;\u4e00\u65e6\u68c0\u6d4b\u5230\u7be1\u6539&#xff0c;\u7acb\u5373\u8c03\u7528resetWatermark\u91cd\u65b0\u6e32\u67d3\u6c34\u5370&#xff0c;\u8ba9\u6076\u610f\u7be1\u6539\u64cd\u4f5c\u65e0\u6548&#xff1b;<\/li>\n<li>\u515c\u5e95\u4fdd\u969c&#xff1a;\u76d1\u542c\u7528\u6237\u9ad8\u9891\u64cd\u4f5c&#xff0c;\u9632\u6296\u540e\u89e6\u53d1\u6c34\u5370\u91cd\u7f6e&#xff0c;\u5e94\u5bf9\u7279\u6b8a\u573a\u666f\u4e0b\u7684\u7be1\u6539\u884c\u4e3a\u3002<\/li>\n<h3 id=\"3.4%C2%A0%E6%80%A7%E8%83%BD%E4%B8%8E%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E7%9A%84%E5%B9%B3%E8%A1%A1\">3.4\u00a0\u6027\u80fd\u4e0e\u8d44\u6e90\u7ba1\u7406\u7684\u5e73\u8861<\/h3>\n<ul>\n<li>\u95ee\u9898\u63cf\u8ff0&#xff1a;\u6c34\u5370\u7684\u76d1\u6d4b\u3001\u6e32\u67d3\u3001\u91cd\u7f6e\u53ef\u80fd\u4ea7\u751f\u6027\u80fd\u5f00\u9500&#xff0c;\u5982\u4f55\u907f\u514d\u9875\u9762\u5361\u987f\u548c\u5185\u5b58\u6cc4\u6f0f&#xff1f;<\/li>\n<\/ul>\n<p>\/**<br \/>\n * \u9500\u6bc1\u6c34\u5370&#xff08;\u8fd8\u539f\u5bb9\u5668\u6837\u5f0f&#xff0c;\u91ca\u653e\u6240\u6709\u8d44\u6e90&#xff09;<br \/>\n *\/<br \/>\nconst destroyWatermark &#061; (isClearOperationListener &#061; true) &#061;&gt; {<br \/>\n  \/\/ 1. \u79fb\u9664\u6c34\u5370DOM<br \/>\n  if (watermarkDom.value &amp;&amp; watermarkDom.value.parentNode) {<br \/>\n    watermarkDom.value.parentNode.removeChild(watermarkDom.value)<br \/>\n    watermarkDom.value &#061; null<br \/>\n  }<\/p>\n<p>  \/\/ 2. \u65ad\u5f00MutationObserver\u76d1\u542c&#xff0c;\u91ca\u653e\u6d4f\u89c8\u5668\u8d44\u6e90<br \/>\n  if (observer.value) {<br \/>\n    observer.value.disconnect()<br \/>\n    observer.value &#061; null<br \/>\n  }<\/p>\n<p>  \/\/ 3. \u79fb\u9664\u7528\u6237\u4e8b\u4ef6\u76d1\u542c&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f<br \/>\n  if (isClearOperationListener &amp;&amp; operationHandler.value) {<br \/>\n    const userEvents &#061; [&#039;click&#039;, &#039;input&#039;, &#039;scroll&#039;, &#039;dragend&#039;, &#039;keydown&#039;, &#039;mouseup&#039;, &#039;touchend&#039;]<br \/>\n    userEvents.forEach((event) &#061;&gt; {<br \/>\n      targetContainer.value.removeEventListener(event, operationHandler.value)<br \/>\n    })<br \/>\n    operationHandler.value &#061; null<br \/>\n  }<\/p>\n<p>  \/\/ 4. \u8fd8\u539f\u5bb9\u5668\u539f\u6709\u6837\u5f0f&#xff0c;\u4e0d\u5f71\u54cd\u9875\u9762\u5e03\u5c40<br \/>\n  if (targetContainer.value &amp;&amp; targetContainer.value !&#061;&#061; document.body) {<br \/>\n    targetContainer.value.style.position &#061; originContainerStyle.value.position<br \/>\n    targetContainer.value.style.overflow &#061; originContainerStyle.value.overflow<br \/>\n    originContainerStyle.value &#061; { position: &#039;&#039;, overflow: &#039;&#039; }<br \/>\n  }<br \/>\n} <\/p>\n<ul>\n<li>\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul>\n<li>\u9632\u6296\u4f18\u5316&#xff1a;\u7528\u6237\u64cd\u4f5c\u89e6\u53d1\u7684\u6c34\u5370\u91cd\u7f6e\u6dfb\u52a0\u9632\u6296&#xff0c;\u907f\u514d\u9891\u7e41\u6267\u884c DOM \u64cd\u4f5c\u548c Canvas \u7ed8\u56fe&#xff1b;<\/li>\n<li>\u8d44\u6e90\u91ca\u653e&#xff1a;\u7ec4\u4ef6\u5378\u8f7d\u65f6&#xff0c;\u79fb\u9664\u6c34\u5370 DOM\u3001\u65ad\u5f00MutationObserver\u76d1\u542c\u3001\u79fb\u9664\u7528\u6237\u4e8b\u4ef6\u76d1\u542c&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f&#xff1b;<\/li>\n<li>\u6837\u5f0f\u8fd8\u539f&#xff1a;\u8fd8\u539f\u5bb9\u5668\u539f\u6709\u6837\u5f0f&#xff0c;\u4e0d\u5f71\u54cd\u9875\u9762\u539f\u6709\u5e03\u5c40&#xff0c;\u63d0\u5347\u7ec4\u4ef6\u517c\u5bb9\u6027&#xff1b;<\/li>\n<li>\u65e0\u5197\u4f59 DOM&#xff1a;\u6c34\u5370\u4ec5\u751f\u6210\u4e00\u4e2a DOM \u8282\u70b9&#xff0c;\u901a\u8fc7\u80cc\u666f\u56fe\u5e73\u94fa\u5b9e\u73b0\u8986\u76d6&#xff0c;\u4e0d\u4ea7\u751f\u5927\u91cf\u5197\u4f59 DOM&#xff0c;\u964d\u4f4e\u9875\u9762\u6e32\u67d3\u538b\u529b\u3002<\/li>\n<h2 id=\"%E7%AC%AC%E5%9B%9B%E7%AB%A0%C2%A0%E7%BB%84%E4%BB%B6%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B\">\u7b2c\u56db\u7ae0\u00a0\u7ec4\u4ef6\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>&lt;GeneralWatermark<br \/>\n    ref&#061;&#034;watermarkRef&#034;<br \/>\n    :text&#061;&#034;&#039;\u5185\u90e8\u6587\u6863 \u00b7 \u7981\u6b62\u5916\u4f20&#039;&#034;<br \/>\n    color&#061;&#034;rgba(90, 153, 212, 0.2)&#034;<br \/>\n    rotate&#061;&#034;-15&#034;<br \/>\n    spacing&#061;&#034;120&#034;<br \/>\n    repeatCount&#061;&#034;2&#034;<br \/>\n\/&gt; <\/p>\n<h2 id=\"%E7%AC%AC%E4%BA%94%E7%AB%A0%C2%A0%E6%80%BB%E7%BB%93%E4%B8%8E%E6%8B%93%E5%B1%95%E6%96%B9%E5%90%91\">\u7b2c\u4e94\u7ae0\u00a0\u603b\u7ed3\u4e0e\u62d3\u5c55\u65b9\u5411<\/h2>\n<p>\u8fd9\u4efd Vue3 \u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6&#xff0c;\u662f\u524d\u7aef\u6280\u672f\u5728\u5b9e\u9645\u4e1a\u52a1\u573a\u666f\u4e2d\u7684\u4f18\u79c0\u843d\u5730\u5b9e\u8df5&#xff0c;\u6bcf\u4e2a\u6280\u672f\u70b9\u90fd\u6709\u6e05\u6670\u7684\u4ee3\u7801\u652f\u6491&#xff0c;\u89e3\u51b3\u4e86\u6c34\u5370\u5e73\u94fa\u3001\u591a\u884c\u6392\u7248\u3001\u9632\u7be1\u6539\u3001\u6027\u80fd\u4f18\u5316\u7b49\u6838\u5fc3\u95ee\u9898&#xff0c;\u5177\u5907\u9ad8\u5b89\u5168\u6027\u3001\u9ad8\u53ef\u914d\u7f6e\u6027\u548c\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>&#8212; \u6269\u5c55\u7a7a\u95f4&#xff1a;<\/p>\n<ul>\n<li>\u652f\u6301\u52a8\u6001\u66f4\u65b0&#xff1a;\u6dfb\u52a0watch\u76d1\u542c props \u53d8\u5316&#xff0c;\u5b9e\u73b0\u6c34\u5370\u914d\u7f6e\u52a8\u6001\u66f4\u65b0&#xff0c;\u65e0\u9700\u624b\u52a8\u8c03\u7528resetWatermark\/\u5237\u65b0\u9875\u9762&#xff1a;<\/li>\n<\/ul>\n<p>watch(props, () &#061;&gt; {<br \/>\n  resetWatermark()<br \/>\n}, { deep: true }) <\/p>\n<ul>\n<li>\u652f\u6301\u56fe\u7247\u6c34\u5370&#xff1a;\u589e\u52a0image\u914d\u7f6e\u9879&#xff0c;\u652f\u6301\u4e0a\u4f20\u56fe\u7247\u4f5c\u4e3a\u6c34\u5370\u5e95\u56fe&#xff0c;\u6269\u5c55 Canvas \u7ed8\u56fe\u903b\u8f91&#xff1b;<\/li>\n<li>\u517c\u5bb9\u4f4e\u7248\u672c\u6d4f\u89c8\u5668&#xff1a;\u6dfb\u52a0MutationObserver\u548c Canvas \u7684\u964d\u7ea7\u65b9\u6848&#xff0c;\u652f\u6301 IE11 \u7b49\u4f4e\u7248\u672c\u6d4f\u89c8\u5668&#xff1b;<\/li>\n<li>\u589e\u52a0\u6e10\u53d8\u6587\u5b57&#xff1a;\u901a\u8fc7ctx.createLinearGradient()\u5b9e\u73b0\u6e10\u53d8\u6c34\u5370\u6587\u5b57&#xff0c;\u63d0\u5347\u6c34\u5370\u7f8e\u89c2\u5ea6\u3002<\/li>\n<\/ul>\n<h2 id=\"%E7%AC%AC%E5%85%AD%E7%AB%A0%20%E6%BA%90%E7%A0%81%EF%BC%88%E5%BC%80%E7%AE%B1%E5%8D%B3%E7%94%A8%EF%BC%89\">\u7b2c\u516d\u7ae0 \u6e90\u7801&#xff08;\u5f00\u7bb1\u5373\u7528&#xff09;<\/h2>\n<p>&lt;template&gt;<br \/>\n  &lt;!&#8211; \u65e0\u9700\u663e\u6027 DOM \u8282\u70b9&#xff0c;\u6c34\u5370\u901a\u8fc7 JS \u52a8\u6001\u521b\u5efa\u6302\u8f7d\u5230\u76ee\u6807\u5bb9\u5668 &#8211;&gt;<br \/>\n&lt;\/template&gt;<\/p>\n<p>&lt;script setup&gt;<br \/>\n  import { onMounted, onUnmounted, ref } from &#039;vue&#039;<\/p>\n<p>  const props &#061; defineProps({<br \/>\n    text: { type: String, default: &#039;\u5185\u90e8\u6587\u6863 \u00b7 \u7981\u6b62\u5916\u4f20&#039; },<br \/>\n    fontSize: { type: [Number, String], default: 14 },<br \/>\n    fontFamily: { type: String, default: &#039;Microsoft Yahei, sans-serif&#039; },<br \/>\n    color: { type: String, default: &#039;rgba(180, 180, 180, 0.3)&#039; },<br \/>\n    rotate: { type: [Number, String], default: -15 },<br \/>\n    spacing: { type: [Number, String], default: 50 },<br \/>\n    zIndex: { type: [Number, String], default: 999999 },<br \/>\n    debounceTime: { type: [Number, String], default: 300 },<br \/>\n    container: { type: [String, Object], default: &#039;body&#039; },<br \/>\n    lineHeight: { type: [Number, String], default: 1.5 },<br \/>\n    \/\/ \u65b0\u589e&#xff1a;\u6c34\u5370\u5355\u5143\u91cd\u590d\u6570\u91cf&#xff08;\u63a7\u5236\u80cc\u666f\u56fe\u5305\u542b\u7684\u6c34\u5370\u5355\u5143\u6570&#xff09;<br \/>\n    repeatCount: { type: [Number, String], default: 2 }<br \/>\n  })<\/p>\n<p>  \/\/ \u4fdd\u5b58\u6838\u5fc3\u5b9e\u4f8b\u5f15\u7528<br \/>\n  const watermarkDom &#061; ref(null)<br \/>\n  const observer &#061; ref(null)<br \/>\n  const operationHandler &#061; ref(null)<br \/>\n  const watermarkId &#061; ref(&#039;&#039;)<br \/>\n  const targetContainer &#061; ref(null)<br \/>\n  const originContainerStyle &#061; ref({ position: &#039;&#039;, overflow: &#039;&#039; })<\/p>\n<p>  \/**<br \/>\n   * \u83b7\u53d6\u76ee\u6807\u5bb9\u5668\u5b9e\u4f8b<br \/>\n   *\/<br \/>\n  const _getTargetContainer &#061; () &#061;&gt; {<br \/>\n    let container &#061; null<br \/>\n    if (typeof props.container &#061;&#061;&#061; &#039;string&#039;) {<br \/>\n      container &#061; document.querySelector(props.container)<br \/>\n    } else if (props.container instanceof HTMLElement) {<br \/>\n      container &#061; props.container<br \/>\n    }<br \/>\n    if (!container || !(container instanceof HTMLElement)) {<br \/>\n      console.warn(&#039;\u6c34\u5370\u76ee\u6807\u5bb9\u5668\u4e0d\u5b58\u5728&#xff0c;\u9ed8\u8ba4\u4f7f\u7528body&#039;)<br \/>\n      container &#061; document.body<br \/>\n    }<br \/>\n    return container<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u62c6\u5206\u8fc7\u957f\u6587\u5b57\u4e3a\u591a\u884c<br \/>\n   *\/<br \/>\n  const _splitTextToLines &#061; (ctx, text, maxWidth) &#061;&gt; {<br \/>\n    if (!text) return []<br \/>\n    const lines &#061; []<br \/>\n    let currentLine &#061; &#039;&#039;<br \/>\n    const chars &#061; text.split(&#039;&#039;)<br \/>\n    for (const char of chars) {<br \/>\n      const testLine &#061; currentLine &#043; char<br \/>\n      const testWidth &#061; ctx.measureText(testLine).width<br \/>\n      if (testWidth &gt; maxWidth &amp;&amp; currentLine) {<br \/>\n        lines.push(currentLine)<br \/>\n        currentLine &#061; char<br \/>\n      } else {<br \/>\n        currentLine &#061; testLine<br \/>\n      }<br \/>\n    }<br \/>\n    if (currentLine) lines.push(currentLine)<br \/>\n    return lines<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u751f\u6210\u591a\u5355\u5143\u6c34\u5370\u80cc\u666f\u56fe&#xff08;\u6838\u5fc3\u4f18\u5316&#xff09;<br \/>\n   *\/<br \/>\n  const _createCanvasBase64 &#061; () &#061;&gt; {<br \/>\n    const { text, fontSize, fontFamily, color, rotate, spacing, lineHeight, repeatCount } &#061; props<br \/>\n    const fontSizeNum &#061; Number(fontSize)<br \/>\n    const lineHeightNum &#061; Number(lineHeight) || 1.5<br \/>\n    const spacingNum &#061; Number(spacing)<br \/>\n    const repeatCountNum &#061; Number(repeatCount) || 2<\/p>\n<p>    \/\/ \u5355\u4e2a\u6c34\u5370\u5355\u5143\u7684\u5c3a\u5bf8<br \/>\n    const singleWidth &#061; spacingNum * 2<br \/>\n    const singleMaxTextWidth &#061; singleWidth * 0.8<br \/>\n    const canvas &#061; document.createElement(&#039;canvas&#039;)<br \/>\n    const ctx &#061; canvas.getContext(&#039;2d&#039;)<\/p>\n<p>    \/\/ \u521d\u59cb\u5316\u753b\u5e03\u4e0a\u4e0b\u6587<br \/>\n    ctx.fillStyle &#061; color<br \/>\n    ctx.font &#061; &#096;${fontSizeNum}px ${fontFamily}&#096;<br \/>\n    ctx.textAlign &#061; &#039;center&#039;<br \/>\n    ctx.textBaseline &#061; &#039;middle&#039;<\/p>\n<p>    \/\/ \u62c6\u5206\u6587\u5b57\u5e76\u8ba1\u7b97\u5355\u4e2a\u5355\u5143\u9ad8\u5ea6<br \/>\n    const textLines &#061; _splitTextToLines(ctx, text, singleMaxTextWidth)<br \/>\n    const singleHeight &#061; Math.max(spacingNum * 2, textLines.length * fontSizeNum * lineHeightNum)<\/p>\n<p>    \/\/ \u751f\u6210\u5305\u542b\u591a\u4e2a\u5355\u5143\u7684\u80cc\u666f\u56fe&#xff08;\u59822&#215;2&#xff09;<br \/>\n    const canvasWidth &#061; singleWidth * repeatCountNum<br \/>\n    const canvasHeight &#061; singleHeight * repeatCountNum<br \/>\n    canvas.width &#061; canvasWidth<br \/>\n    canvas.height &#061; canvasHeight<br \/>\n    ctx.clearRect(0, 0, canvasWidth, canvasHeight)<\/p>\n<p>    \/\/ \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370<br \/>\n    for (let x &#061; 0; x &lt; repeatCountNum; x&#043;&#043;) {<br \/>\n      for (let y &#061; 0; y &lt; repeatCountNum; y&#043;&#043;) {<br \/>\n        const unitX &#061; singleWidth * x &#043; singleWidth \/ 2<br \/>\n        const unitY &#061; singleHeight * y &#043; singleHeight \/ 2<\/p>\n<p>        \/\/ \u4fdd\u5b58\u5f53\u524d\u4e0a\u4e0b\u6587\u72b6\u6001<br \/>\n        ctx.save()<br \/>\n        \/\/ \u5e73\u79fb\u5230\u5f53\u524d\u5355\u5143\u4e2d\u5fc3<br \/>\n        ctx.translate(unitX, unitY)<br \/>\n        \/\/ \u65cb\u8f6c<br \/>\n        ctx.rotate((Number(rotate) * Math.PI) \/ 180)<\/p>\n<p>        \/\/ \u7ed8\u5236\u591a\u884c\u6587\u5b57<br \/>\n        const totalTextHeight &#061; (textLines.length &#8211; 1) * fontSizeNum * lineHeightNum<br \/>\n        textLines.forEach((line, index) &#061;&gt; {<br \/>\n          const yOffset &#061; (index &#8211; (textLines.length &#8211; 1) \/ 2) * fontSizeNum * lineHeightNum<br \/>\n          ctx.fillText(line, 0, yOffset)<br \/>\n        })<\/p>\n<p>        \/\/ \u6062\u590d\u4e0a\u4e0b\u6587\u72b6\u6001<br \/>\n        ctx.restore()<br \/>\n      }<br \/>\n    }<\/p>\n<p>    return canvas.toDataURL(&#039;image\/png&#039;)<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u521b\u5efa\u6c34\u5370DOM\u5143\u7d20&#xff08;\u9002\u914d\u5b8c\u6574\u5e73\u94fa&#xff09;<br \/>\n   *\/<br \/>\n  const _createWatermarkDom &#061; () &#061;&gt; {<br \/>\n    const { zIndex, spacing, repeatCount } &#061; props<br \/>\n    const base64Url &#061; _createCanvasBase64()<br \/>\n    const container &#061; targetContainer.value<br \/>\n    const spacingNum &#061; Number(spacing)<br \/>\n    const repeatCountNum &#061; Number(repeatCount) || 2<br \/>\n    const singleWidth &#061; spacingNum * 2<br \/>\n    const singleHeight &#061; spacingNum * 2<\/p>\n<p>    \/\/ \u5bb9\u5668\u5c3a\u5bf8\u548c\u5b9a\u4f4d\u65b9\u5f0f<br \/>\n    const containerWidth &#061; container &#061;&#061;&#061; document.body ? &#039;100vw&#039; : &#096;${container.offsetWidth}px&#096;<br \/>\n    const containerHeight &#061; container &#061;&#061;&#061; document.body ? &#039;100vh&#039; : &#096;${container.offsetHeight}px&#096;<br \/>\n    const positionType &#061; container &#061;&#061;&#061; document.body ? &#039;fixed&#039; : &#039;absolute&#039;<\/p>\n<p>    \/\/ \u80cc\u666f\u56fe\u5c3a\u5bf8&#xff08;\u591a\u5355\u5143\u6574\u4f53\u5c3a\u5bf8&#xff09;<br \/>\n    const bgSize &#061; &#096;${singleWidth * repeatCountNum}px ${singleHeight * repeatCountNum}px&#096;<br \/>\n    \/\/ \u80cc\u666f\u56fe\u5b9a\u4f4d&#xff08;\u786e\u4fdd\u5de6\u4e0a\u89d2\u5bf9\u9f50&#xff09;<br \/>\n    const bgPosition &#061; &#096;0 0&#096;<\/p>\n<p>    const watermark &#061; document.createElement(&#039;div&#039;)<br \/>\n    watermark.style.cssText &#061; &#096;<br \/>\n    position: ${positionType} !important;<br \/>\n    top: 0 !important;<br \/>\n    left: 0 !important;<br \/>\n    width: ${containerWidth} !important;<br \/>\n    height: ${containerHeight} !important;<br \/>\n    z-index: ${zIndex} !important;<br \/>\n    pointer-events: none !important;<br \/>\n    background-image: url(${base64Url}) !important;<br \/>\n    background-repeat: repeat !important;<br \/>\n    background-position: ${bgPosition} !important;<br \/>\n    background-size: ${bgSize} !important;<br \/>\n    user-select: none !important;<br \/>\n    border: none !important;<br \/>\n    margin: 0 !important;<br \/>\n    padding: 0 !important;<br \/>\n    opacity: 1 !important;<br \/>\n    display: block !important;<br \/>\n  &#096;<br \/>\n    watermarkId.value &#061; &#039;unique-watermark-&#039; &#043; Date.now()<br \/>\n    watermark.dataset.watermarkId &#061; watermarkId.value<\/p>\n<p>    return watermark<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u521d\u59cb\u5316\u5bb9\u5668\u6837\u5f0f&#xff08;\u6dfb\u52a0\u6ea2\u51fa\u9690\u85cf&#xff09;<br \/>\n   *\/<br \/>\n  const _initContainerStyle &#061; () &#061;&gt; {<br \/>\n    const container &#061; targetContainer.value<br \/>\n    if (container !&#061;&#061; document.body) {<br \/>\n      const computedStyle &#061; window.getComputedStyle(container)<br \/>\n      originContainerStyle.value &#061; {<br \/>\n        position: computedStyle.position,<br \/>\n        overflow: computedStyle.overflow<br \/>\n      }<\/p>\n<p>      \/\/ \u786e\u4fdd\u5bb9\u5668\u6709\u5b9a\u4f4d\u4e14\u6ea2\u51fa\u9690\u85cf<br \/>\n      if (<br \/>\n        ![&#039;relative&#039;, &#039;absolute&#039;, &#039;fixed&#039;, &#039;sticky&#039;].includes(originContainerStyle.value.position)<br \/>\n      ) {<br \/>\n        container.style.position &#061; &#039;relative !important&#039;<br \/>\n      }<br \/>\n      container.style.overflow &#061; &#039;hidden !important&#039;<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u521d\u59cb\u5316DOM\u7be1\u6539\u76d1\u6d4b<br \/>\n   *\/<br \/>\n  const _initMutationObserver &#061; () &#061;&gt; {<br \/>\n    if (observer.value) observer.value.disconnect()<br \/>\n    const observerOptions &#061; {<br \/>\n      childList: true,<br \/>\n      attributes: true,<br \/>\n      subtree: true,<br \/>\n      attributeFilter: [&#039;style&#039;, &#039;class&#039;, &#039;dataset&#039;]<br \/>\n    }<br \/>\n    observer.value &#061; new MutationObserver((mutations) &#061;&gt; {<br \/>\n      console.log(&#039;mutations&#039;, mutations)<br \/>\n      let needReRender &#061; false<br \/>\n      mutations.forEach((mutation) &#061;&gt; {<br \/>\n        if (mutation.type &#061;&#061;&#061; &#039;childList&#039; &amp;&amp; mutation.removedNodes.length) {<br \/>\n          const isWatermarkRemoved &#061; Array.from(mutation.removedNodes).some(<br \/>\n            (node) &#061;&gt; node.dataset?.watermarkId &#061;&#061;&#061; watermarkId.value<br \/>\n          )<br \/>\n          if (isWatermarkRemoved) needReRender &#061; true<br \/>\n        }<br \/>\n        if (<br \/>\n          mutation.type &#061;&#061;&#061; &#039;attributes&#039; &amp;&amp;<br \/>\n          mutation.target.dataset?.watermarkId &#061;&#061;&#061; watermarkId.value<br \/>\n        ) {<br \/>\n          needReRender &#061; true<br \/>\n        }<br \/>\n      })<br \/>\n      if (needReRender) resetWatermark()<br \/>\n    })<br \/>\n    observer.value.observe(targetContainer.value, observerOptions)<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u9632\u6296\u51fd\u6570<br \/>\n   *\/<br \/>\n  const _debounce &#061; (fn, delay) &#061;&gt; {<br \/>\n    let timer &#061; null<br \/>\n    return function () {<br \/>\n      clearTimeout(timer)<br \/>\n      timer &#061; setTimeout(() &#061;&gt; fn.apply(this, arguments), delay)<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u76d1\u542c\u7528\u6237\u64cd\u4f5c<br \/>\n   *\/<br \/>\n  const _initUserOperationListener &#061; () &#061;&gt; {<br \/>\n    const { debounceTime } &#061; props<br \/>\n    operationHandler.value &#061; _debounce(() &#061;&gt; resetWatermark(), Number(debounceTime))<br \/>\n    const userEvents &#061; [&#039;click&#039;, &#039;input&#039;, &#039;scroll&#039;, &#039;dragend&#039;, &#039;keydown&#039;, &#039;mouseup&#039;, &#039;touchend&#039;]<br \/>\n    userEvents.forEach((event) &#061;&gt; {<br \/>\n      targetContainer.value.addEventListener(event, operationHandler.value, { passive: true })<br \/>\n    })<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u6e32\u67d3\u6c34\u5370<br \/>\n   *\/<br \/>\n  const renderWatermark &#061; () &#061;&gt; {<br \/>\n    destroyWatermark(false)<br \/>\n    targetContainer.value &#061; _getTargetContainer()<br \/>\n    _initContainerStyle()<br \/>\n    watermarkDom.value &#061; _createWatermarkDom()<br \/>\n    targetContainer.value.appendChild(watermarkDom.value)<br \/>\n    _initMutationObserver()<br \/>\n    _initUserOperationListener()<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u91cd\u7f6e\u6c34\u5370<br \/>\n   *\/<br \/>\n  const resetWatermark &#061; () &#061;&gt; {<br \/>\n    destroyWatermark(false)<br \/>\n    watermarkDom.value &#061; _createWatermarkDom()<br \/>\n    targetContainer.value.appendChild(watermarkDom.value)<br \/>\n    _initMutationObserver()<br \/>\n  }<\/p>\n<p>  \/**<br \/>\n   * \u9500\u6bc1\u6c34\u5370&#xff08;\u8fd8\u539f\u5bb9\u5668\u6837\u5f0f&#xff09;<br \/>\n   *\/<br \/>\n  const destroyWatermark &#061; (isClearOperationListener &#061; true) &#061;&gt; {<br \/>\n    if (watermarkDom.value &amp;&amp; watermarkDom.value.parentNode) {<br \/>\n      watermarkDom.value.parentNode.removeChild(watermarkDom.value)<br \/>\n      watermarkDom.value &#061; null<br \/>\n    }<br \/>\n    if (observer.value) {<br \/>\n      observer.value.disconnect()<br \/>\n      observer.value &#061; null<br \/>\n    }<br \/>\n    if (isClearOperationListener &amp;&amp; operationHandler.value) {<br \/>\n      const userEvents &#061; [&#039;click&#039;, &#039;input&#039;, &#039;scroll&#039;, &#039;dragend&#039;, &#039;keydown&#039;, &#039;mouseup&#039;, &#039;touchend&#039;]<br \/>\n      userEvents.forEach((event) &#061;&gt; {<br \/>\n        targetContainer.value.removeEventListener(event, operationHandler.value)<br \/>\n      })<br \/>\n      operationHandler.value &#061; null<br \/>\n    }<br \/>\n    \/\/ \u8fd8\u539f\u5bb9\u5668\u539f\u6709\u6837\u5f0f<br \/>\n    if (targetContainer.value &amp;&amp; targetContainer.value !&#061;&#061; document.body) {<br \/>\n      targetContainer.value.style.position &#061; originContainerStyle.value.position<br \/>\n      targetContainer.value.style.overflow &#061; originContainerStyle.value.overflow<br \/>\n      originContainerStyle.value &#061; { position: &#039;&#039;, overflow: &#039;&#039; }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/\/ \u66b4\u9732\u65b9\u6cd5<br \/>\n  defineExpose({ renderWatermark, resetWatermark, destroyWatermark })<\/p>\n<p>  \/\/ \u751f\u547d\u5468\u671f<br \/>\n  onMounted(() &#061;&gt; renderWatermark())<br \/>\n  onUnmounted(() &#061;&gt; destroyWatermark())<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;style scoped&gt;<br \/>\n  \/* \u65e0\u989d\u5916\u6837\u5f0f *\/<br \/>\n&lt;\/style&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u7b2c\u4e00\u7ae0 \u524d\u8a00<br \/>\n\u7b2c\u4e8c\u7ae0\u00a0\u7ec4\u4ef6\u6838\u5fc3\u6280\u672f\u6808\u62c6\u89e3<br \/>\n2.1 \u57fa\u672c\u914d\u7f6e<br \/>\n2.1.1 props<br \/>\n2.1.2\u00a0\u751f\u547d\u5468\u671f\u7ba1\u7406\u4e0e\u65b9\u6cd5\u66b4\u9732<br \/>\n2.2\u00a0Canvas \u7ed8\u56fe\u6280\u672f&#xff08;\u751f\u6210\u6c34\u5370\u5e95\u56fe&#xff09;<br \/>\n2.2.1\u00a0\u6587\u5b57\u62c6\u5206&#xff08;\u89e3\u51b3\u8fc7\u957f\u6587\u5b57\u6362\u884c\u95ee\u9898&#xff09;<br \/>\n2.2.2\u00a0Canvas \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370\u5e76\u8f6c\u6362\u4e3a base64<br \/>\n2.3\u00a0MutationObserver DOM \u7be1\u6539\u76d1\u6d4b&#xff08;\u9632\u7be1\u6539\u6838\u5fc3&#xff09;<br \/>\n2.3.1\u00a0Mut<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6543,6544,187,458,87,575],"topic":[],"class_list":["post-61733","post","type-post","status-publish","format-standard","hentry","category-server","tag-6543","tag-6544","tag-javascript","tag-vue","tag-87","tag-575"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/61733.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u7b2c\u4e00\u7ae0 \u524d\u8a00 \u7b2c\u4e8c\u7ae0\u00a0\u7ec4\u4ef6\u6838\u5fc3\u6280\u672f\u6808\u62c6\u89e3 2.1 \u57fa\u672c\u914d\u7f6e 2.1.1 props 2.1.2\u00a0\u751f\u547d\u5468\u671f\u7ba1\u7406\u4e0e\u65b9\u6cd5\u66b4\u9732 2.2\u00a0Canvas \u7ed8\u56fe\u6280\u672f&#xff08;\u751f\u6210\u6c34\u5370\u5e95\u56fe&#xff09; 2.2.1\u00a0\u6587\u5b57\u62c6\u5206&#xff08;\u89e3\u51b3\u8fc7\u957f\u6587\u5b57\u6362\u884c\u95ee\u9898&#xff09; 2.2.2\u00a0Canvas \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370\u5e76\u8f6c\u6362\u4e3a base64 2.3\u00a0MutationObserver DOM \u7be1\u6539\u76d1\u6d4b&#xff08;\u9632\u7be1\u6539\u6838\u5fc3&#xff09; 2.3.1\u00a0Mut\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/61733.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-18T05:50:27+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61733.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/61733.html\",\"name\":\"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-18T05:50:27+00:00\",\"dateModified\":\"2026-01-18T05:50:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/61733.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/61733.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61733.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/61733.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u7b2c\u4e00\u7ae0 \u524d\u8a00 \u7b2c\u4e8c\u7ae0\u00a0\u7ec4\u4ef6\u6838\u5fc3\u6280\u672f\u6808\u62c6\u89e3 2.1 \u57fa\u672c\u914d\u7f6e 2.1.1 props 2.1.2\u00a0\u751f\u547d\u5468\u671f\u7ba1\u7406\u4e0e\u65b9\u6cd5\u66b4\u9732 2.2\u00a0Canvas \u7ed8\u56fe\u6280\u672f&#xff08;\u751f\u6210\u6c34\u5370\u5e95\u56fe&#xff09; 2.2.1\u00a0\u6587\u5b57\u62c6\u5206&#xff08;\u89e3\u51b3\u8fc7\u957f\u6587\u5b57\u6362\u884c\u95ee\u9898&#xff09; 2.2.2\u00a0Canvas \u7ed8\u5236\u591a\u5355\u5143\u6c34\u5370\u5e76\u8f6c\u6362\u4e3a base64 2.3\u00a0MutationObserver DOM \u7be1\u6539\u76d1\u6d4b&#xff08;\u9632\u7be1\u6539\u6838\u5fc3&#xff09; 2.3.1\u00a0Mut","og_url":"https:\/\/www.wsisp.com\/helps\/61733.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-18T05:50:27+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"12 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/61733.html","url":"https:\/\/www.wsisp.com\/helps\/61733.html","name":"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-18T05:50:27+00:00","dateModified":"2026-01-18T05:50:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/61733.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/61733.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/61733.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u7ec4\u4ef6\u5c01\u88c5\u3011\u5b9e\u73b0\u4e00\u4e2a\u76f8\u5bf9\u5b89\u5168\u6027\u9ad8\u7684\u9632\u7be1\u6539\u6c34\u5370\u7ec4\u4ef6\uff1a\u5e26\u4ee3\u7801\u7247\u6bb5\u7684\u6838\u5fc3\u539f\u7406\u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=61733"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61733\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=61733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=61733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=61733"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=61733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}