PageSourceSearch

https://astroknot.netlify.app/modules/richEditor/utils.js

js astroknot.netlify.app collected 2026-10-03 10:30:21 UTC 2,248 bytes, 78 lines download raw bytes

1import { state } from './shared-state.js';
2
3export function showSavedToast() {
4  const wrapper = document.getElementById('ckEditorContainer');
5  if (!wrapper) return;
6  const old = wrapper.querySelector('.save-toast');
7  if (old) old.remove();
8
9  const toast = document.createElement('div');
10  toast.className = 'save-toast';
11  toast.textContent = '笔记已保存';
12  toast.style.cssText = `
13    position: absolute; top: 0; left: 0; right: 0; height: 30px;
14    background: linear-gradient(90deg, #2c7a6e, transparent);
15    color: white; text-align: center; line-height: 30px;
16    font-size: 13px; z-index: 10;
17    animation: toastFade 2s ease forwards;
18    pointer-events: none;
19  `;
20
21  if (!document.getElementById('toast-style')) {
22    const style = document.createElement('style');
23    style.id = 'toast-style';
24    style.textContent = `
25      @keyframes toastFade {
26        0% { opacity: 0; transform: translateY(-10px); }
27        15% { opacity: 1; transform: translateY(0); }
28        70% { opacity: 1; transform: translateY(0); }
29        100% { opacity: 0; transform: translateY(-10px); }
30      }
31    `;
32    document.head.appendChild(style);
33  }
34  wrapper.appendChild(toast);
35  setTimeout(() => toast.remove(), 2000);
36}
37
38export function getCKEditorInstance() {
39  return state.tinyEditor;
40}
41
42export function isCKEditorActive() {
43  return true;
44}
45
46export function setEditingFormulaImg(img) {
47  state._tmceEditingFormulaImg = img;
48}
49
50export function getEditingFormulaImg() {
51  return state._tmceEditingFormulaImg;
52}
53
54export function clearEditingFormulaImg() {
55  state._tmceEditingFormulaImg = null;
56}
57
58export function rgbToHex(rgb) {
59  if (!rgb) return '#eef';
60  if (rgb.startsWith('#')) return rgb;
61  const match = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
62  if (!match) return '#eef';
63  return '#' + [1, 2, 3].map(i => parseInt(match[i]).toString(16).padStart(2, '0')).join('');
64}
65
66export function getCurrentTinyFontColor() {
67  if (!state.tinyEditor) return '#eef';
68  const color = state.tinyEditor.formatter.get('color');
69  if (color) {
70    return rgbToHex(color);
71  }
72  const body = state.tinyEditor.getBody();
73  if (body) {
74    const computed = window.getComputedStyle(body);
75    return rgbToHex(computed.color);
76  }
77  return '#eef';
78}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.