@lark-apaas/miaoda-presets 1.0.5 → 1.0.6

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.
@@ -124,6 +124,37 @@ function removeAllChildren(element, skip) {
124
124
  element.removeChild(childList[i]);
125
125
  }
126
126
  }
127
+ /**
128
+ * 降级复制方案(兼容旧浏览器)
129
+ * @param text 要复制的文本
130
+ * @returns boolean 复制是否成功
131
+ */
132
+ function fallbackCopyToClipboard(text) {
133
+ try {
134
+ // 创建临时的 textarea 元素
135
+ const textArea = document.createElement('textarea');
136
+ textArea.value = text;
137
+ // 设置样式,使其不可见
138
+ textArea.style.position = 'fixed';
139
+ textArea.style.left = '-999999px';
140
+ textArea.style.top = '-999999px';
141
+ textArea.setAttribute('readonly', '');
142
+ // 添加到 DOM
143
+ document.body.appendChild(textArea);
144
+ // 选中文本
145
+ textArea.focus();
146
+ textArea.select();
147
+ // 执行复制命令
148
+ const successful = document.execCommand('copy');
149
+ // 清理:移除临时元素
150
+ document.body.removeChild(textArea);
151
+ return successful;
152
+ }
153
+ catch (error) {
154
+ console.error('降级复制方案失败:', error);
155
+ return false;
156
+ }
157
+ }
127
158
  async function copyToClipboard(text) {
128
159
  try {
129
160
  // 优先使用现代的 Clipboard API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-presets",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "files": [
5
5
  "lib"
6
6
  ],