|
|
<!DOCTYPE html> |
|
|
<html lang="en"> |
|
|
<head> |
|
|
<meta charset="UTF-8"> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<title>hf_kernels_rotary</title> |
|
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com"> |
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
|
|
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet"> |
|
|
|
|
|
<script> |
|
|
|
|
|
(function() { |
|
|
const isIframe = window.self !== window.top; |
|
|
if (!isIframe) return; |
|
|
|
|
|
|
|
|
const hash = window.location.hash; |
|
|
if (hash && hash.startsWith('#/')) { |
|
|
const targetPath = hash.slice(2); |
|
|
const currentPath = window.location.pathname.split('/').pop(); |
|
|
|
|
|
|
|
|
if (targetPath !== currentPath) { |
|
|
window.location.href = targetPath; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('click', function(e) { |
|
|
const link = e.target.closest('a'); |
|
|
if (!link) return; |
|
|
|
|
|
const href = link.getAttribute('href'); |
|
|
|
|
|
|
|
|
if (!href || href.startsWith('#') || href.startsWith('http') || href.startsWith('javascript:')) { |
|
|
return; |
|
|
} |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
const url = new URL(href, window.location.href); |
|
|
let fullPath = url.pathname; |
|
|
|
|
|
|
|
|
if (fullPath.startsWith('/')) { |
|
|
fullPath = fullPath.slice(1); |
|
|
} |
|
|
|
|
|
|
|
|
window.location.hash = '#/' + fullPath; |
|
|
|
|
|
|
|
|
if (fullPath.endsWith('.html') || fullPath.endsWith('/')) { |
|
|
const pathParts = fullPath.split('/').filter(p => p); |
|
|
const targetFile = pathParts[pathParts.length - 1] || 'index.html'; |
|
|
window.location.href = targetFile; |
|
|
} else { |
|
|
|
|
|
window.open(href, '_blank'); |
|
|
} |
|
|
}); |
|
|
})(); |
|
|
|
|
|
|
|
|
(function() { |
|
|
const configTheme = 'dark'; |
|
|
const hasConfigUi = false; |
|
|
const configUi = hasConfigUi ? 'None' : null; |
|
|
const hasWidgetsConfig = false; |
|
|
const widgetsOn = hasWidgetsConfig ? false : true; |
|
|
let theme; |
|
|
if (configTheme === 'auto') { |
|
|
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; |
|
|
} else { |
|
|
theme = localStorage.getItem('uvnote-theme') || configTheme; |
|
|
} |
|
|
document.documentElement.setAttribute('data-theme', theme); |
|
|
|
|
|
|
|
|
let ui = hasConfigUi ? configUi : (localStorage.getItem('uvnote-ui') || 'default'); |
|
|
if (ui !== 'default' && ui !== 'none' && ui !== 'monocolor') { ui = 'default'; } |
|
|
document.documentElement.setAttribute('data-ui', ui); |
|
|
|
|
|
|
|
|
document.documentElement.setAttribute('data-widgets', widgetsOn ? 'on' : 'off'); |
|
|
})(); |
|
|
</script> |
|
|
<style> |
|
|
:root[data-theme="light"] { |
|
|
--bg-primary: #ffffff; |
|
|
--bg-secondary: #f6f8fa; |
|
|
--bg-tertiary: #f8f9fa; |
|
|
--bg-code: #f8f9fa; |
|
|
--bg-error: #fdf2f2; |
|
|
--bg-artifact: #e6f3ff; |
|
|
--bg-artifact-hover: #d0e7ff; |
|
|
|
|
|
--text-primary: #333; |
|
|
--text-secondary: #656d76; |
|
|
--text-error: #c53030; |
|
|
--text-link: #0969da; |
|
|
|
|
|
--border-primary: #e1e5e9; |
|
|
--border-error: #e53e3e; |
|
|
--border-cell-failed: #d73a49; |
|
|
|
|
|
--shadow: rgba(0, 0, 0, 0.1); |
|
|
} |
|
|
|
|
|
:root[data-theme="dark"] { |
|
|
--bg-primary: #0a0a0a; |
|
|
--bg-secondary: #121212; |
|
|
--bg-tertiary: #181818; |
|
|
--bg-code: #0d0d0d; |
|
|
--bg-error: #1a0f0f; |
|
|
--bg-artifact: #151515; |
|
|
--bg-artifact-hover: #1a1a1a; |
|
|
|
|
|
--text-primary: #e0e0e0; |
|
|
--text-secondary: #888888; |
|
|
--text-error: #ff6b6b; |
|
|
--text-link: #64b5f6; |
|
|
|
|
|
--border-primary: #2a2a2a; |
|
|
--border-error: #ff6b6b; |
|
|
--border-cell-failed: #ff6b6b; |
|
|
|
|
|
--shadow: rgba(255, 255, 255, 0.05); |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="monocolor"] { |
|
|
--mono-color: #0a66ff; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"][data-theme="light"] { |
|
|
--bg-primary: #ffffff; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"][data-theme="dark"] { |
|
|
--bg-primary: #000000; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] { |
|
|
--bg-secondary: var(--bg-primary); |
|
|
--bg-tertiary: var(--bg-primary); |
|
|
--bg-code: var(--bg-primary); |
|
|
--bg-error: var(--bg-primary); |
|
|
--bg-artifact: var(--bg-primary); |
|
|
--bg-artifact-hover: var(--bg-primary); |
|
|
|
|
|
--text-primary: var(--mono-color); |
|
|
--text-secondary: var(--mono-color); |
|
|
--text-error: var(--mono-color); |
|
|
--text-link: var(--mono-color); |
|
|
|
|
|
--border-primary: var(--mono-color); |
|
|
--border-error: var(--mono-color); |
|
|
--border-cell-failed: var(--mono-color); |
|
|
|
|
|
--shadow: none; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] a { |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .menu-button, |
|
|
:root[data-ui="monocolor"] .theme-toggle, |
|
|
:root[data-ui="monocolor"] .reset-toggle, |
|
|
:root[data-ui="monocolor"] .back-button { |
|
|
background: var(--bg-primary); |
|
|
color: var(--mono-color); |
|
|
border-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .menu-button:hover, |
|
|
:root[data-ui="monocolor"] .theme-toggle:hover, |
|
|
:root[data-ui="monocolor"] .reset-toggle:hover, |
|
|
:root[data-ui="monocolor"] .back-button:hover { |
|
|
background: var(--bg-primary); |
|
|
color: var(--mono-color); |
|
|
border-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .menu-dropdown { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
box-shadow: none; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .menu-item { |
|
|
color: var(--mono-color); |
|
|
border-bottom-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .system-info { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .cell { |
|
|
border-color: var(--mono-color); |
|
|
background: var(--bg-primary); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .cell-header { |
|
|
background: var(--bg-primary); |
|
|
border-bottom-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .artifact { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .artifact:hover { |
|
|
background: var(--bg-primary); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .artifact-preview img, |
|
|
:root[data-ui="monocolor"] .artifact-preview svg { |
|
|
border-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .status-widget { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .minimap, |
|
|
:root[data-ui="monocolor"] .file-explorer, |
|
|
:root[data-ui="monocolor"] .tools-widget { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .cell-code { |
|
|
background: var(--bg-primary); |
|
|
border-bottom-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .tools-title, |
|
|
:root[data-ui="monocolor"] .file-explorer-section-title, |
|
|
:root[data-ui="monocolor"] .minimap-title { |
|
|
color: var(--mono-color); |
|
|
border-bottom-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .tool-button { |
|
|
background: var(--bg-primary); |
|
|
border-color: var(--mono-color); |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .tool-button.active { |
|
|
border-color: var(--mono-color); |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .file-explorer-item, |
|
|
:root[data-ui="monocolor"] .minimap-item { |
|
|
color: var(--mono-color); |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="monocolor"] .highlight { |
|
|
background: var(--bg-primary) !important; |
|
|
color: var(--mono-color) !important; |
|
|
} |
|
|
|
|
|
:root[data-ui="monocolor"] .highlight *, |
|
|
:root[data-ui="monocolor"] .highlight .hll { |
|
|
color: var(--mono-color) !important; |
|
|
background: transparent !important; |
|
|
border-color: var(--mono-color) !important; |
|
|
} |
|
|
|
|
|
|
|
|
:root { |
|
|
--code-font-size: 0.95rem; |
|
|
--code-line-height: 1.5; |
|
|
--code-pad-y: 0.75rem; |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="none"] { |
|
|
--bg-primary: #ffffff; |
|
|
--bg-secondary: transparent; |
|
|
--bg-tertiary: transparent; |
|
|
--bg-code: #f9f9f9; |
|
|
--bg-error: #fff0f0; |
|
|
--bg-artifact: #f0f7ff; |
|
|
--bg-artifact-hover: #e5f1ff; |
|
|
|
|
|
--text-primary: #000000; |
|
|
--text-secondary: #222222; |
|
|
--text-error: #a00000; |
|
|
--text-link: #0000ee; |
|
|
|
|
|
--border-primary: #cccccc; |
|
|
--border-error: #cc0000; |
|
|
--border-cell-failed: #cc0000; |
|
|
|
|
|
--shadow: none; |
|
|
} |
|
|
|
|
|
html { |
|
|
overscroll-behavior: none; |
|
|
} |
|
|
|
|
|
body { |
|
|
font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace; |
|
|
line-height: 1.4; |
|
|
max-width: 1000px; |
|
|
margin: 0 auto; |
|
|
padding: 15px; |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
transition: background-color 0.2s ease, color 0.2s ease; |
|
|
overscroll-behavior: none; |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="none"] body { |
|
|
font-family: 'Times New Roman', Times, serif; |
|
|
line-height: 1.5; |
|
|
max-width: 860px; |
|
|
padding: 12px; |
|
|
background: #ffffff; |
|
|
color: #000000; |
|
|
transition: none; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.controls { |
|
|
position: fixed; |
|
|
top: 20px; |
|
|
right: 20px; |
|
|
display: flex; |
|
|
flex-direction: column; |
|
|
align-items: flex-end; |
|
|
gap: 0.25rem; |
|
|
z-index: 1000; |
|
|
} |
|
|
|
|
|
.controls-buttons { |
|
|
display: flex; |
|
|
gap: 0.5rem; |
|
|
} |
|
|
|
|
|
.menu-button { |
|
|
position: relative; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 8px 12px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-family: inherit; |
|
|
font-size: 0.9rem; |
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="none"][data-widgets="on"] .menu-button, |
|
|
:root[data-ui="none"][data-widgets="on"] .theme-toggle, |
|
|
:root[data-ui="none"][data-widgets="on"] .reset-toggle, |
|
|
:root[data-ui="none"][data-widgets="on"] .back-button { |
|
|
background: #f6f6f6; |
|
|
border: 1px solid #cccccc; |
|
|
color: #222222; |
|
|
} |
|
|
|
|
|
.menu-button:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-tertiary); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.status-widget { |
|
|
position: fixed; |
|
|
right: 20px; |
|
|
bottom: 20px; |
|
|
width: auto; |
|
|
max-width: 260px; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
padding: 6px 8px; |
|
|
font-size: 0.8rem; |
|
|
color: var(--text-secondary); |
|
|
z-index: 100; |
|
|
} |
|
|
|
|
|
.status-widget strong { |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
:root[data-ui="none"][data-widgets="on"] .status-widget { |
|
|
background: #f6f6f6; |
|
|
border-color: #ccc; |
|
|
color: #222; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"][data-widgets="on"] .menu-button:hover, |
|
|
:root[data-ui="none"][data-widgets="on"] .theme-toggle:hover, |
|
|
:root[data-ui="none"][data-widgets="on"] .reset-toggle:hover, |
|
|
:root[data-ui="none"][data-widgets="on"] .back-button:hover { |
|
|
background: #ededed; |
|
|
border-color: #bbbbbb; |
|
|
color: #000000; |
|
|
} |
|
|
|
|
|
.menu-dropdown { |
|
|
position: absolute; |
|
|
top: 100%; |
|
|
right: 0; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 4px; |
|
|
box-shadow: 0 4px 12px var(--shadow); |
|
|
min-width: 160px; |
|
|
opacity: 0; |
|
|
visibility: hidden; |
|
|
transform: translateY(-8px); |
|
|
transition: all 0.2s ease; |
|
|
z-index: 1001; |
|
|
margin-top: 4px; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"][data-widgets="on"] .menu-dropdown { |
|
|
background: #ffffff; |
|
|
border: 1px solid #cccccc; |
|
|
box-shadow: none; |
|
|
} |
|
|
|
|
|
.menu-button.active .menu-dropdown { |
|
|
opacity: 1; |
|
|
visibility: visible; |
|
|
transform: translateY(0); |
|
|
} |
|
|
|
|
|
.menu-item { |
|
|
display: block; |
|
|
padding: 8px 12px; |
|
|
color: var(--text-secondary); |
|
|
text-decoration: none; |
|
|
font-size: 0.85rem; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
cursor: pointer; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .menu-item { |
|
|
color: #000; |
|
|
border-bottom: 1px solid #eee; |
|
|
} |
|
|
|
|
|
.menu-item:last-child { |
|
|
border-bottom: none; |
|
|
} |
|
|
|
|
|
.menu-item:hover { |
|
|
background: var(--bg-tertiary); |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.menu-checkbox { |
|
|
display: inline-block; |
|
|
width: 16px; |
|
|
font-family: monospace; |
|
|
color: var(--text-link); |
|
|
} |
|
|
|
|
|
.theme-toggle, |
|
|
.reset-toggle, |
|
|
.back-button { |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 8px 12px; |
|
|
border-radius: 4px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-family: inherit; |
|
|
font-size: 0.9rem; |
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.back-button { |
|
|
text-decoration: none; |
|
|
display: inline-block; |
|
|
} |
|
|
|
|
|
.theme-toggle:hover, |
|
|
.reset-toggle:hover, |
|
|
.back-button:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-tertiary); |
|
|
} |
|
|
|
|
|
.system-info { |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 4px; |
|
|
padding: 8px 12px; |
|
|
margin-bottom: 16px; |
|
|
font-size: 0.85em; |
|
|
color: var(--text-secondary); |
|
|
} |
|
|
|
|
|
.system-info-header { |
|
|
font-weight: 600; |
|
|
color: var(--text-primary); |
|
|
margin-bottom: 2px; |
|
|
} |
|
|
|
|
|
.system-info-content { |
|
|
font-family: monospace; |
|
|
} |
|
|
|
|
|
.theme-toggle, |
|
|
.reset-toggle { |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
|
|
|
cursor: pointer; |
|
|
font-family: inherit; |
|
|
font-size: 0.8rem; |
|
|
color: var(--text-secondary); |
|
|
user-select: none; |
|
|
transition: all 0.2s ease; |
|
|
text-transform: lowercase; |
|
|
letter-spacing: 0; |
|
|
} |
|
|
|
|
|
.theme-toggle:hover, |
|
|
.reset-toggle:hover { |
|
|
background: var(--bg-tertiary); |
|
|
border-color: var(--text-secondary); |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.minimap { |
|
|
position: fixed; |
|
|
bottom: 20px; |
|
|
right: 20px; |
|
|
width: 220px; |
|
|
max-height: 400px; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
padding: 0.5rem; |
|
|
font-size: 0.7rem; |
|
|
overflow-y: auto; |
|
|
z-index: 100; |
|
|
opacity: 0.9; |
|
|
transition: opacity 0.2s ease; |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-widgets="off"] .controls, |
|
|
:root[data-widgets="off"] .minimap, |
|
|
:root[data-widgets="off"] .file-explorer, |
|
|
:root[data-widgets="off"] .tools-widget, |
|
|
:root[data-widgets="off"] .status-widget { |
|
|
display: none !important; |
|
|
} |
|
|
|
|
|
.file-explorer { |
|
|
position: fixed; |
|
|
bottom: 20px; |
|
|
|
|
|
right: 20px; |
|
|
left: auto; |
|
|
top: auto; |
|
|
width: 220px; |
|
|
max-height: 400px; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
padding: 0.5rem; |
|
|
font-size: 0.7rem; |
|
|
overflow-y: auto; |
|
|
z-index: 100; |
|
|
opacity: 0.9; |
|
|
transition: opacity 0.2s ease; |
|
|
} |
|
|
|
|
|
|
|
|
.draw-overlay { |
|
|
position: fixed; |
|
|
top: 0; |
|
|
left: 0; |
|
|
width: 100vw; |
|
|
height: 100vh; |
|
|
z-index: 80; |
|
|
|
|
|
display: block; |
|
|
pointer-events: none; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
.tools-widget { |
|
|
position: fixed; |
|
|
bottom: 20px; |
|
|
|
|
|
right: 20px; |
|
|
left: auto; |
|
|
top: auto; |
|
|
width: 220px; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
padding: 0.5rem; |
|
|
font-size: 0.7rem; |
|
|
z-index: 100; |
|
|
opacity: 0.95; |
|
|
} |
|
|
|
|
|
.tools-title { |
|
|
font-weight: bold; |
|
|
color: var(--text-secondary); |
|
|
margin-bottom: 0.5rem; |
|
|
padding-bottom: 0.25rem; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
cursor: grab; |
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.tools-row { |
|
|
display: flex; |
|
|
gap: 0.4rem; |
|
|
flex-wrap: wrap; |
|
|
} |
|
|
|
|
|
.tool-button { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
padding: 0.25rem 0.4rem; |
|
|
cursor: pointer; |
|
|
color: var(--text-secondary); |
|
|
font-family: inherit; |
|
|
font-size: 0.75rem; |
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.tool-button:hover { |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.tool-button.active { |
|
|
color: var(--text-primary); |
|
|
border-color: var(--text-secondary); |
|
|
background: var(--bg-secondary); |
|
|
} |
|
|
|
|
|
.minimap:hover, |
|
|
.file-explorer:hover { |
|
|
opacity: 1; |
|
|
} |
|
|
|
|
|
.minimap-title { |
|
|
font-weight: bold; |
|
|
color: var(--text-secondary); |
|
|
margin-bottom: 0.5rem; |
|
|
padding-bottom: 0.25rem; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
cursor: grab; |
|
|
|
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.minimap-item { |
|
|
display: block; |
|
|
color: var(--text-secondary); |
|
|
text-decoration: none; |
|
|
padding: 0.15rem 0; |
|
|
border-left: 2px solid transparent; |
|
|
padding-left: 0.5rem; |
|
|
transition: all 0.2s ease; |
|
|
cursor: pointer; |
|
|
} |
|
|
|
|
|
.minimap-item:hover { |
|
|
color: var(--text-primary); |
|
|
border-left-color: var(--text-secondary); |
|
|
} |
|
|
|
|
|
.minimap-item.active { |
|
|
color: var(--text-primary); |
|
|
border-left-color: var(--text-link); |
|
|
} |
|
|
|
|
|
.minimap-heading { |
|
|
font-weight: normal; |
|
|
} |
|
|
|
|
|
.minimap-heading.h1 { |
|
|
padding-left: 0.5rem; |
|
|
} |
|
|
|
|
|
.minimap-heading.h2 { |
|
|
padding-left: 1rem; |
|
|
} |
|
|
|
|
|
.minimap-heading.h3 { |
|
|
padding-left: 1.5rem; |
|
|
} |
|
|
|
|
|
.minimap-heading.h4 { |
|
|
padding-left: 2rem; |
|
|
} |
|
|
|
|
|
.minimap-heading.h5 { |
|
|
padding-left: 2.5rem; |
|
|
} |
|
|
|
|
|
.minimap-heading.h6 { |
|
|
padding-left: 3rem; |
|
|
} |
|
|
|
|
|
.minimap-cell { |
|
|
color: var(--text-link); |
|
|
opacity: 0.8; |
|
|
font-style: italic; |
|
|
} |
|
|
|
|
|
.minimap-cell:hover { |
|
|
opacity: 1; |
|
|
} |
|
|
|
|
|
.file-explorer-title { |
|
|
font-weight: bold; |
|
|
color: var(--text-secondary); |
|
|
margin-bottom: 0.5rem; |
|
|
padding-bottom: 0.25rem; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
cursor: grab; |
|
|
|
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.file-explorer-section { |
|
|
margin-bottom: 0.75rem; |
|
|
} |
|
|
|
|
|
.file-explorer-section-title { |
|
|
font-weight: bold; |
|
|
color: var(--text-secondary); |
|
|
font-size: 0.65rem; |
|
|
margin-bottom: 0.25rem; |
|
|
text-transform: uppercase; |
|
|
letter-spacing: 0.5px; |
|
|
} |
|
|
|
|
|
.file-explorer-item { |
|
|
display: block; |
|
|
color: var(--text-secondary); |
|
|
text-decoration: none; |
|
|
padding: 0.1rem 0; |
|
|
margin-left: 0.5rem; |
|
|
transition: color 0.2s ease; |
|
|
cursor: pointer; |
|
|
font-family: monospace; |
|
|
} |
|
|
|
|
|
.file-explorer-item:hover { |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.file-explorer-item.script { |
|
|
color: var(--text-link); |
|
|
} |
|
|
|
|
|
.file-explorer-item.artifact { |
|
|
color: var(--text-secondary); |
|
|
opacity: 0.8; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 768px) { |
|
|
|
|
|
.minimap, |
|
|
.file-explorer, |
|
|
.tools-widget { |
|
|
display: none; |
|
|
} |
|
|
} |
|
|
|
|
|
.cell { |
|
|
margin: 1rem 0; |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 2px; |
|
|
overflow: hidden; |
|
|
background: var(--bg-secondary); |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .cell { |
|
|
margin: 1em 0; |
|
|
border: none; |
|
|
background: transparent; |
|
|
} |
|
|
|
|
|
.cell-header { |
|
|
background: var(--bg-secondary); |
|
|
padding: 0.5rem 1rem; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
font-family: inherit; |
|
|
font-size: 0.85rem; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .cell-header { |
|
|
background: transparent; |
|
|
border: none; |
|
|
padding: 0; |
|
|
font-weight: bold; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .cell-content { |
|
|
padding: 0; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .copy-button, |
|
|
:root[data-ui="none"] .collapse-indicators, |
|
|
:root[data-ui="none"] .cell-meta, |
|
|
:root[data-ui="none"] .cell-outputs-header { |
|
|
display: none !important; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] pre, |
|
|
:root[data-ui="none"] code { |
|
|
font-family: Menlo, Monaco, 'Courier New', monospace; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .code-content pre { |
|
|
background: #f9f9f9; |
|
|
border: 1px solid #ddd; |
|
|
padding: 8px; |
|
|
} |
|
|
|
|
|
:root[data-ui="none"] .output { |
|
|
background: transparent; |
|
|
border: none; |
|
|
padding: 0.25em 0; |
|
|
} |
|
|
|
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
user-select: none; |
|
|
transition: background-color 0.2s ease; |
|
|
} |
|
|
|
|
|
.cell-header:hover { |
|
|
background: var(--bg-tertiary); |
|
|
} |
|
|
|
|
|
.collapse-indicators { |
|
|
color: var(--text-secondary); |
|
|
font-size: 0.8rem; |
|
|
opacity: 0.7; |
|
|
} |
|
|
|
|
|
.collapse-indicators span:hover { |
|
|
color: var(--text-primary); |
|
|
opacity: 1; |
|
|
} |
|
|
|
|
|
.cell-code { |
|
|
display: block; |
|
|
background: var(--bg-code); |
|
|
} |
|
|
|
|
|
.cell-code.collapsed { |
|
|
display: none; |
|
|
} |
|
|
|
|
|
.cell-code pre { |
|
|
margin: 0; |
|
|
padding: 0.75rem; |
|
|
background: var(--bg-code); |
|
|
overflow-x: auto; |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.cell-output { |
|
|
padding: 0.75rem; |
|
|
|
|
|
background: var(--bg-secondary); |
|
|
} |
|
|
|
|
|
.cell-output.collapsed { |
|
|
display: none; |
|
|
} |
|
|
|
|
|
.cell-stdout { |
|
|
background: var(--bg-tertiary); |
|
|
padding: 0.75rem; |
|
|
border-radius: 1px; |
|
|
|
|
|
font-family: inherit; |
|
|
font-size: 0.9rem; |
|
|
white-space: pre-wrap; |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.cell-stdout { |
|
|
background: var(--bg-tertiary); |
|
|
padding: 0.75rem; |
|
|
border-radius: 1px; |
|
|
font-family: inherit; |
|
|
font-size: 0.9rem; |
|
|
color: var(--text-primary); |
|
|
|
|
|
|
|
|
overflow: auto; |
|
|
|
|
|
max-width: 100%; |
|
|
|
|
|
} |
|
|
|
|
|
.cell-stdout .stdout-text { |
|
|
margin: 0; |
|
|
|
|
|
white-space: pre; |
|
|
|
|
|
display: inline-block; |
|
|
|
|
|
min-width: max-content; |
|
|
|
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; |
|
|
tab-size: 2; |
|
|
} |
|
|
|
|
|
.cell-stderr { |
|
|
background: var(--bg-error); |
|
|
border-left: 2px solid var(--border-error); |
|
|
padding: 1rem; |
|
|
margin: 0.5rem 0; |
|
|
font-family: inherit; |
|
|
font-size: 0.9rem; |
|
|
color: var(--text-error); |
|
|
white-space: pre-wrap; |
|
|
} |
|
|
|
|
|
.uv-install-logs { |
|
|
margin: 0.5rem 0; |
|
|
} |
|
|
|
|
|
.uv-logs-header { |
|
|
cursor: pointer; |
|
|
padding: 0.75rem; |
|
|
border-left: 3px solid var(--border-color); |
|
|
font-family: inherit; |
|
|
font-size: 0.85rem; |
|
|
color: var(--text-secondary); |
|
|
user-select: none; |
|
|
} |
|
|
|
|
|
.uv-logs-content { |
|
|
background: var(--bg-secondary); |
|
|
padding: 1rem; |
|
|
border-left: 3px solid var(--border-color); |
|
|
white-space: pre-wrap; |
|
|
font-family: monospace; |
|
|
font-size: 0.85rem; |
|
|
color: var(--text-secondary); |
|
|
overflow-x: auto; |
|
|
} |
|
|
|
|
|
.cell-artifacts { |
|
|
margin: 1rem 0; |
|
|
} |
|
|
|
|
|
.cell-artifacts h4 { |
|
|
margin: 0 0 0.5rem 0; |
|
|
color: var(--text-secondary); |
|
|
font-size: 0.9rem; |
|
|
} |
|
|
|
|
|
.artifact { |
|
|
display: inline-block; |
|
|
background: var(--bg-artifact); |
|
|
padding: 0.25rem 0.5rem; |
|
|
border-radius: 1px; |
|
|
margin: 0.25rem 0.5rem 0.25rem 0; |
|
|
font-family: inherit; |
|
|
font-size: 0.8rem; |
|
|
color: var(--text-link); |
|
|
text-decoration: none; |
|
|
transition: background-color 0.2s ease; |
|
|
border: 1px solid var(--border-primary); |
|
|
} |
|
|
|
|
|
.artifact:hover { |
|
|
background: var(--bg-artifact-hover); |
|
|
} |
|
|
|
|
|
.artifact-preview { |
|
|
margin-top: 1rem; |
|
|
} |
|
|
|
|
|
.artifact-preview img { |
|
|
max-width: 100%; |
|
|
height: auto; |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 1px; |
|
|
} |
|
|
|
|
|
.artifact-preview svg { |
|
|
max-width: 100%; |
|
|
height: auto; |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 1px; |
|
|
display: block; |
|
|
} |
|
|
|
|
|
|
|
|
.artifact-preview svg g { |
|
|
fill: var(--text-primary) !important; |
|
|
} |
|
|
|
|
|
|
|
|
.artifact-preview svg { |
|
|
background: transparent; |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-theme="dark"] .artifact-preview img[src$=".svg"] { |
|
|
filter: invert(0.9) hue-rotate(180deg); |
|
|
} |
|
|
|
|
|
|
|
|
:root[data-ui="monocolor"] .artifact-preview img[src$=".svg"] { |
|
|
filter: none; |
|
|
} |
|
|
|
|
|
|
|
|
.artifact-csv { |
|
|
margin-top: 1rem; |
|
|
overflow-x: auto; |
|
|
} |
|
|
|
|
|
.csv-table { |
|
|
width: 100%; |
|
|
border-collapse: collapse; |
|
|
font-size: 0.9rem; |
|
|
background: var(--bg-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
border-radius: 1px; |
|
|
} |
|
|
|
|
|
.csv-table th, |
|
|
.csv-table td { |
|
|
padding: 0.5rem 0.75rem; |
|
|
text-align: left; |
|
|
border: 1px solid var(--border-primary); |
|
|
} |
|
|
|
|
|
.csv-table th { |
|
|
background: var(--bg-tertiary); |
|
|
font-weight: 600; |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
.csv-table tbody tr:hover { |
|
|
background: var(--bg-artifact-hover); |
|
|
} |
|
|
|
|
|
.artifact-csv-error { |
|
|
margin-top: 1rem; |
|
|
padding: 1rem; |
|
|
background: var(--bg-error); |
|
|
color: var(--text-error); |
|
|
border: 1px solid var(--border-error); |
|
|
border-radius: 1px; |
|
|
} |
|
|
|
|
|
.cell-failed { |
|
|
border-color: var(--border-cell-failed); |
|
|
} |
|
|
|
|
|
.cell-failed .cell-header { |
|
|
background: var(--bg-error); |
|
|
color: var(--text-error); |
|
|
} |
|
|
|
|
|
.cell-commented { |
|
|
opacity: 0.6; |
|
|
border-style: dashed; |
|
|
} |
|
|
|
|
|
.cell-commented .cell-header { |
|
|
background: var(--bg-secondary); |
|
|
color: var(--text-secondary); |
|
|
font-style: italic; |
|
|
} |
|
|
|
|
|
.run-btn { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 2px 6px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-size: 0.75em; |
|
|
font-family: inherit; |
|
|
margin-left: 4px; |
|
|
} |
|
|
|
|
|
.run-btn:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
} |
|
|
|
|
|
.run-btn:disabled { |
|
|
opacity: 0.6; |
|
|
cursor: not-allowed; |
|
|
} |
|
|
|
|
|
.copy-btn { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 2px 6px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-size: 0.75em; |
|
|
font-family: inherit; |
|
|
margin-left: 4px; |
|
|
} |
|
|
|
|
|
.copy-btn:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
} |
|
|
|
|
|
.copy-btn:disabled { |
|
|
opacity: 0.6; |
|
|
cursor: not-allowed; |
|
|
} |
|
|
|
|
|
.copy-btn.copied { |
|
|
color: #4caf50; |
|
|
background: var(--bg-primary); |
|
|
border-color: #4caf50; |
|
|
transition: all 0.2s ease; |
|
|
} |
|
|
|
|
|
.raw-btn { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 2px 6px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-size: 0.75em; |
|
|
font-family: inherit; |
|
|
margin-left: 4px; |
|
|
text-decoration: none; |
|
|
display: inline-block; |
|
|
} |
|
|
|
|
|
.raw-btn:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
text-decoration: none; |
|
|
} |
|
|
|
|
|
.github-btn { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 2px 6px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-size: 0.75em; |
|
|
font-family: inherit; |
|
|
margin-left: 4px; |
|
|
text-decoration: none; |
|
|
display: inline-block; |
|
|
} |
|
|
|
|
|
.github-btn:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
text-decoration: none; |
|
|
} |
|
|
|
|
|
.hf-btn { |
|
|
background: var(--bg-tertiary); |
|
|
border: 1px solid var(--border-primary); |
|
|
padding: 2px 6px; |
|
|
border-radius: 2px; |
|
|
color: var(--text-secondary); |
|
|
cursor: pointer; |
|
|
font-size: 0.75em; |
|
|
font-family: inherit; |
|
|
margin-left: 4px; |
|
|
text-decoration: none; |
|
|
display: inline-block; |
|
|
} |
|
|
|
|
|
.hf-btn:hover { |
|
|
color: var(--text-primary); |
|
|
background: var(--bg-primary); |
|
|
text-decoration: none; |
|
|
} |
|
|
|
|
|
.output-stale { |
|
|
opacity: 0.5; |
|
|
position: relative; |
|
|
} |
|
|
|
|
|
.output-stale::after { |
|
|
content: '⏳ updating...'; |
|
|
position: absolute; |
|
|
top: 8px; |
|
|
right: 8px; |
|
|
background: var(--bg-secondary); |
|
|
padding: 4px 8px; |
|
|
border-radius: 2px; |
|
|
font-size: 0.75em; |
|
|
color: var(--text-secondary); |
|
|
border: 1px solid var(--border-primary); |
|
|
} |
|
|
|
|
|
h1, |
|
|
h2, |
|
|
h3, |
|
|
h4, |
|
|
h5, |
|
|
h6 { |
|
|
margin-top: 1.5rem; |
|
|
margin-bottom: 0.75rem; |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
h1 { |
|
|
margin-top: 0; |
|
|
margin-bottom: 1rem; |
|
|
} |
|
|
|
|
|
p { |
|
|
margin: 0.75rem 0; |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
a { |
|
|
color: var(--text-link); |
|
|
} |
|
|
|
|
|
img { |
|
|
max-width: 100%; |
|
|
height: auto; |
|
|
border-radius: 1px; |
|
|
box-shadow: none; |
|
|
} |
|
|
|
|
|
pre, |
|
|
code { |
|
|
font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace; |
|
|
font-size: var(--code-font-size); |
|
|
} |
|
|
|
|
|
.code-wrap { |
|
|
position: relative; |
|
|
} |
|
|
|
|
|
.code-line-highlight { |
|
|
display: none; |
|
|
position: absolute; |
|
|
left: 0; |
|
|
right: 0; |
|
|
height: 1.5em; |
|
|
background: rgba(255, 235, 170, 0.35); |
|
|
pointer-events: none; |
|
|
border-left: 3px solid #f4c542; |
|
|
} |
|
|
|
|
|
.line-number { |
|
|
cursor: pointer; |
|
|
text-decoration: none; |
|
|
color: var(--text-secondary); |
|
|
padding: 0 0.25rem; |
|
|
} |
|
|
|
|
|
.line-number.selected { |
|
|
background: rgba(255, 235, 170, 0.4); |
|
|
color: var(--text-primary); |
|
|
} |
|
|
|
|
|
|
|
|
.highlight-with-lines { |
|
|
display: flex; |
|
|
} |
|
|
|
|
|
.line-numbers { |
|
|
background: var(--bg-tertiary); |
|
|
padding: var(--code-pad-y) 0.5rem; |
|
|
font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace; |
|
|
font-size: var(--code-font-size); |
|
|
line-height: var(--code-line-height); |
|
|
color: var(--text-secondary); |
|
|
user-select: none; |
|
|
text-align: right; |
|
|
border-right: 1px solid var(--border-primary); |
|
|
} |
|
|
|
|
|
.line-numbers .line-number { |
|
|
display: block; |
|
|
line-height: var(--code-line-height); |
|
|
} |
|
|
|
|
|
.highlight-with-lines .highlight { |
|
|
flex: 1; |
|
|
} |
|
|
|
|
|
.highlight .hll { |
|
|
background-color: transparent; |
|
|
} |
|
|
|
|
|
|
|
|
.highlight pre { |
|
|
white-space: pre; |
|
|
margin: 0; |
|
|
padding: var(--code-pad-y) 0.75rem; |
|
|
line-height: var(--code-line-height); |
|
|
} |
|
|
|
|
|
|
|
|
.cell-code.collapsed { |
|
|
display: none; |
|
|
} |
|
|
|
|
|
.cell-code.expanded { |
|
|
display: block; |
|
|
} |
|
|
|
|
|
{ |
|
|
% if config.collapse_code % |
|
|
} |
|
|
|
|
|
.cell-code { |
|
|
display: none; |
|
|
} |
|
|
|
|
|
{ |
|
|
% else % |
|
|
} |
|
|
|
|
|
.cell-code { |
|
|
display: block; |
|
|
border-bottom: 1px solid var(--border-primary); |
|
|
} |
|
|
|
|
|
{ |
|
|
% endif % |
|
|
} |
|
|
|
|
|
{ |
|
|
{ |
|
|
pygments_css |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.highlight pre { |
|
|
white-space: pre; |
|
|
margin: 0; |
|
|
padding: var(--code-pad-y) 0.75rem !important; |
|
|
line-height: var(--code-line-height) !important; |
|
|
font-size: var(--code-font-size) !important; |
|
|
font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace !important; |
|
|
border: none; |
|
|
} |
|
|
|
|
|
.line-numbers { |
|
|
line-height: var(--code-line-height) !important; |
|
|
} |
|
|
|
|
|
.line-numbers .line-number { |
|
|
line-height: var(--code-line-height) !important; |
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
config.custom_css |
|
|
} |
|
|
} |
|
|
|
|
|
{ |
|
|
# Override code font size from frontmatter (accept number as px) # |
|
|
} |
|
|
|
|
|
{ |
|
|
% if config.code_font_size is not none % |
|
|
} |
|
|
|
|
|
{ |
|
|
% if config.code_font_size is string % |
|
|
} |
|
|
|
|
|
:root { |
|
|
--code-font-size: { |
|
|
{ |
|
|
config.code_font_size |
|
|
} |
|
|
} |
|
|
|
|
|
; |
|
|
} |
|
|
|
|
|
{ |
|
|
% else % |
|
|
} |
|
|
|
|
|
:root { |
|
|
--code-font-size: { |
|
|
{ |
|
|
config.code_font_size |
|
|
} |
|
|
} |
|
|
|
|
|
px; |
|
|
} |
|
|
|
|
|
{ |
|
|
% endif % |
|
|
} |
|
|
|
|
|
{ |
|
|
% endif % |
|
|
} |
|
|
|
|
|
|
|
|
body[data-tool="arrow"] .main-content { |
|
|
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><path d="M2 2l7.586 7.586"/><circle cx="11" cy="11" r="2"/></svg>') 12 12, crosshair; |
|
|
} |
|
|
|
|
|
body[data-tool="pen"] .main-content { |
|
|
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><circle cx="4" cy="20" r="2" fill="%23e53935"/></svg>') 4 20, pointer; |
|
|
} |
|
|
|
|
|
body[data-tool="eraser"] .main-content { |
|
|
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M20 20H7l-7-7 7-7h13v14z"/><path d="M13 13l7-7"/><path d="M13 13L9 9"/></svg>') 12 12, auto; |
|
|
} |
|
|
|
|
|
|
|
|
.tools-section-title { |
|
|
font-weight: bold; |
|
|
color: var(--text-secondary); |
|
|
font-size: 0.65rem; |
|
|
margin: 0.75rem 0 0.5rem 0; |
|
|
text-transform: uppercase; |
|
|
letter-spacing: 0.5px; |
|
|
} |
|
|
|
|
|
.color-row { |
|
|
display: grid; |
|
|
grid-template-columns: repeat(6, 1fr); |
|
|
gap: 0.25rem; |
|
|
margin-bottom: 0.5rem; |
|
|
} |
|
|
|
|
|
.color-swatch { |
|
|
width: 18px; |
|
|
height: 18px; |
|
|
border: 2px solid var(--border-primary); |
|
|
border-radius: 3px; |
|
|
cursor: pointer; |
|
|
transition: all 0.2s ease; |
|
|
position: relative; |
|
|
} |
|
|
|
|
|
.color-swatch:hover { |
|
|
transform: scale(1.1); |
|
|
border-color: var(--text-secondary); |
|
|
} |
|
|
|
|
|
.color-swatch.selected { |
|
|
border-color: var(--text-primary); |
|
|
box-shadow: 0 0 0 2px var(--text-link); |
|
|
} |
|
|
|
|
|
.color-swatch.selected::after { |
|
|
content: '✓'; |
|
|
position: absolute; |
|
|
top: 50%; |
|
|
left: 50%; |
|
|
transform: translate(-50%, -50%); |
|
|
color: white; |
|
|
font-size: 10px; |
|
|
font-weight: bold; |
|
|
text-shadow: 1px 1px 1px black; |
|
|
} |
|
|
|
|
|
.color-input { |
|
|
width: 24px; |
|
|
height: 24px; |
|
|
border: 2px solid var(--border-primary); |
|
|
border-radius: 3px; |
|
|
cursor: pointer; |
|
|
background: none; |
|
|
padding: 0; |
|
|
grid-column: span 2; |
|
|
justify-self: center; |
|
|
} |
|
|
|
|
|
.color-input:hover { |
|
|
border-color: var(--text-secondary); |
|
|
} |
|
|
|
|
|
|
|
|
.thickness-row { |
|
|
display: flex; |
|
|
align-items: center; |
|
|
gap: 0.5rem; |
|
|
margin-top: 0.75rem; |
|
|
} |
|
|
|
|
|
.thickness-slider { |
|
|
flex: 1; |
|
|
-webkit-appearance: none; |
|
|
appearance: none; |
|
|
height: 4px; |
|
|
background: var(--border-primary); |
|
|
border-radius: 2px; |
|
|
outline: none; |
|
|
opacity: 0.7; |
|
|
transition: opacity 0.2s; |
|
|
} |
|
|
|
|
|
.thickness-slider:hover { |
|
|
opacity: 1; |
|
|
} |
|
|
|
|
|
.thickness-slider::-webkit-slider-thumb { |
|
|
-webkit-appearance: none; |
|
|
appearance: none; |
|
|
width: 12px; |
|
|
height: 12px; |
|
|
background: var(--text-link); |
|
|
border-radius: 50%; |
|
|
cursor: pointer; |
|
|
} |
|
|
|
|
|
.thickness-slider::-moz-range-thumb { |
|
|
width: 12px; |
|
|
height: 12px; |
|
|
background: var(--text-link); |
|
|
border-radius: 50%; |
|
|
cursor: pointer; |
|
|
border: none; |
|
|
} |
|
|
|
|
|
.thickness-value { |
|
|
font-size: 0.7rem; |
|
|
color: var(--text-secondary); |
|
|
min-width: 20px; |
|
|
text-align: right; |
|
|
} |
|
|
|
|
|
.highlight { |
|
|
background: none !important; |
|
|
} |
|
|
|
|
|
|
|
|
.loading-spinner { |
|
|
display: inline-block; |
|
|
width: 16px; |
|
|
height: 16px; |
|
|
border: 2px solid var(--border-primary); |
|
|
border-radius: 50%; |
|
|
border-top-color: var(--text-link); |
|
|
animation: spin 1s linear infinite; |
|
|
margin-right: 8px; |
|
|
vertical-align: middle; |
|
|
} |
|
|
|
|
|
@keyframes spin { |
|
|
to { |
|
|
transform: rotate(360deg); |
|
|
} |
|
|
} |
|
|
|
|
|
.loading-skeleton { |
|
|
display: inline-block; |
|
|
background: var(--bg-tertiary); |
|
|
background: linear-gradient(90deg, |
|
|
var(--bg-tertiary) 25%, |
|
|
var(--bg-secondary) 50%, |
|
|
var(--bg-tertiary) 75%); |
|
|
background-size: 200% 100%; |
|
|
animation: loading-shimmer 2s ease-in-out infinite; |
|
|
border-radius: 2px; |
|
|
height: 1em; |
|
|
width: 80px; |
|
|
vertical-align: middle; |
|
|
} |
|
|
|
|
|
@keyframes loading-shimmer { |
|
|
0% { |
|
|
background-position: -200% 0; |
|
|
} |
|
|
|
|
|
100% { |
|
|
background-position: 200% 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.cell-output:has(.loading-spinner) { |
|
|
opacity: 0.7; |
|
|
background: var(--bg-secondary); |
|
|
|
|
|
} |
|
|
</style> |
|
|
<script> |
|
|
|
|
|
function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } |
|
|
|
|
|
function restorePosition(el, storageKey) { |
|
|
try { |
|
|
const raw = localStorage.getItem(storageKey); |
|
|
if (!raw) return; |
|
|
const pos = JSON.parse(raw); |
|
|
if (typeof pos.left === 'number' && typeof pos.top === 'number') { |
|
|
el.style.left = pos.left + 'px'; |
|
|
el.style.top = pos.top + 'px'; |
|
|
el.style.right = 'auto'; |
|
|
el.style.bottom = 'auto'; |
|
|
} |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
function savePosition(el, storageKey) { |
|
|
try { |
|
|
const left = parseFloat(el.style.left || 'NaN'); |
|
|
const top = parseFloat(el.style.top || 'NaN'); |
|
|
if (!Number.isNaN(left) && !Number.isNaN(top)) { |
|
|
localStorage.setItem(storageKey, JSON.stringify({ left, top })); |
|
|
} |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
|
|
|
function makeDraggable(el, storageKey, handleEl) { |
|
|
let dragging = false; |
|
|
let startX = 0, startY = 0; |
|
|
let origLeft = 0, origTop = 0; |
|
|
|
|
|
const onMove = (e) => { |
|
|
if (!dragging) return; |
|
|
const clientX = e.touches ? e.touches[0].clientX : e.clientX; |
|
|
const clientY = e.touches ? e.touches[0].clientY : e.clientY; |
|
|
const dx = clientX - startX; |
|
|
const dy = clientY - startY; |
|
|
const w = el.offsetWidth; |
|
|
const h = el.offsetHeight; |
|
|
const maxX = window.innerWidth - w; |
|
|
const maxY = window.innerHeight - h; |
|
|
const newLeft = clamp(origLeft + dx, 0, maxX); |
|
|
const newTop = clamp(origTop + dy, 0, maxY); |
|
|
el.style.left = newLeft + 'px'; |
|
|
el.style.top = newTop + 'px'; |
|
|
el.style.right = 'auto'; |
|
|
el.style.bottom = 'auto'; |
|
|
}; |
|
|
|
|
|
const endDrag = () => { |
|
|
if (!dragging) return; |
|
|
dragging = false; |
|
|
document.removeEventListener('mousemove', onMove); |
|
|
document.removeEventListener('mouseup', endDrag); |
|
|
document.removeEventListener('touchmove', onMove); |
|
|
document.removeEventListener('touchend', endDrag); |
|
|
handleEl && (handleEl.style.cursor = 'grab'); |
|
|
savePosition(el, storageKey); |
|
|
|
|
|
try { layoutWidgetsStackedBottomRight(); } catch (_) {} |
|
|
}; |
|
|
|
|
|
const startDrag = (e) => { |
|
|
|
|
|
const elRect = el.getBoundingClientRect(); |
|
|
el.style.left = elRect.left + 'px'; |
|
|
el.style.top = elRect.top + 'px'; |
|
|
el.style.right = 'auto'; |
|
|
el.style.bottom = 'auto'; |
|
|
|
|
|
dragging = true; |
|
|
startX = e.touches ? e.touches[0].clientX : e.clientX; |
|
|
startY = e.touches ? e.touches[0].clientY : e.clientY; |
|
|
origLeft = elRect.left; |
|
|
origTop = elRect.top; |
|
|
|
|
|
document.addEventListener('mousemove', onMove); |
|
|
document.addEventListener('mouseup', endDrag); |
|
|
document.addEventListener('touchmove', onMove, { passive: false }); |
|
|
document.addEventListener('touchend', endDrag); |
|
|
handleEl && (handleEl.style.cursor = 'grabbing'); |
|
|
e.preventDefault(); |
|
|
}; |
|
|
|
|
|
(handleEl || el).addEventListener('mousedown', startDrag); |
|
|
(handleEl || el).addEventListener('touchstart', startDrag, { passive: false }); |
|
|
|
|
|
|
|
|
restorePosition(el, storageKey); |
|
|
} |
|
|
function toggleCell(cellId) { |
|
|
const codeElement = document.getElementById('code-' + cellId); |
|
|
const outputElement = document.getElementById('output-' + cellId); |
|
|
|
|
|
if (codeElement) { |
|
|
codeElement.classList.toggle('collapsed'); |
|
|
} |
|
|
if (outputElement) { |
|
|
outputElement.classList.toggle('collapsed'); |
|
|
} |
|
|
|
|
|
updateIndicators(cellId); |
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
|
|
|
function toggleCode(cellId) { |
|
|
const codeElement = document.getElementById('code-' + cellId); |
|
|
if (codeElement) { |
|
|
codeElement.classList.toggle('collapsed'); |
|
|
updateIndicators(cellId); |
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleOutput(cellId) { |
|
|
const outputElement = document.getElementById('output-' + cellId); |
|
|
if (outputElement) { |
|
|
outputElement.classList.toggle('collapsed'); |
|
|
updateIndicators(cellId); |
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleUvLogs(headerElement) { |
|
|
const contentElement = headerElement.nextElementSibling; |
|
|
if (contentElement) { |
|
|
const isCollapsed = contentElement.style.display === 'none'; |
|
|
contentElement.style.display = isCollapsed ? 'block' : 'none'; |
|
|
headerElement.textContent = isCollapsed ? '▼ UV Install Logs' : '▶ UV Install Logs'; |
|
|
|
|
|
|
|
|
const uvLogsDiv = headerElement.parentElement; |
|
|
if (uvLogsDiv && uvLogsDiv.id && uvLogsDiv.id.startsWith('uv-logs-')) { |
|
|
const cellId = uvLogsDiv.id.replace('uv-logs-', ''); |
|
|
const indicatorElement = document.getElementById('uv-indicator-' + cellId); |
|
|
if (indicatorElement) { |
|
|
indicatorElement.textContent = isCollapsed ? '▼ uv-logs' : '▶ uv-logs'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleUvLogsFromHeader(cellId) { |
|
|
const uvLogsElement = document.getElementById('uv-logs-' + cellId); |
|
|
const indicatorElement = document.getElementById('uv-indicator-' + cellId); |
|
|
if (uvLogsElement) { |
|
|
const headerElement = uvLogsElement.querySelector('.uv-logs-header'); |
|
|
const contentElement = uvLogsElement.querySelector('.uv-logs-content'); |
|
|
if (contentElement && headerElement) { |
|
|
const isCollapsed = contentElement.style.display === 'none'; |
|
|
contentElement.style.display = isCollapsed ? 'block' : 'none'; |
|
|
headerElement.textContent = isCollapsed ? '▼ UV Install Logs' : '▶ UV Install Logs'; |
|
|
if (indicatorElement) { |
|
|
indicatorElement.textContent = isCollapsed ? '▼ uv-logs' : '▶ uv-logs'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
function updateIndicators(cellId) { |
|
|
const codeElement = document.getElementById('code-' + cellId); |
|
|
const outputElement = document.getElementById('output-' + cellId); |
|
|
const indicators = document.querySelector(`[onclick*="${cellId}"]`)?.closest('.cell-header')?.querySelector('.collapse-indicators'); |
|
|
|
|
|
if (indicators) { |
|
|
const codeCollapsed = codeElement && codeElement.classList.contains('collapsed'); |
|
|
const outputCollapsed = outputElement && outputElement.classList.contains('collapsed'); |
|
|
|
|
|
const codeIcon = codeCollapsed ? '▶' : '▼'; |
|
|
const outputIcon = outputCollapsed ? '▶' : '▼'; |
|
|
|
|
|
const codeSpan = indicators.querySelector('[onclick*="toggleCode"]'); |
|
|
const outputSpan = indicators.querySelector('[onclick*="toggleOutput"]'); |
|
|
|
|
|
if (codeSpan) codeSpan.innerHTML = `${codeIcon} code`; |
|
|
if (outputSpan) outputSpan.innerHTML = `${outputIcon} output`; |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleTheme() { |
|
|
const html = document.documentElement; |
|
|
const currentTheme = html.getAttribute('data-theme'); |
|
|
const newTheme = currentTheme === 'dark' ? 'light' : 'dark'; |
|
|
html.setAttribute('data-theme', newTheme); |
|
|
localStorage.setItem('uvnote-theme', newTheme); |
|
|
updateThemeIcon(); |
|
|
updateUiDebug(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updateThemeIcon() { |
|
|
const theme = document.documentElement.getAttribute('data-theme'); |
|
|
const toggle = document.querySelector('.theme-toggle'); |
|
|
if (toggle) { |
|
|
toggle.textContent = theme === 'dark' ? 'light' : 'dark'; |
|
|
} |
|
|
} |
|
|
function setUiTheme(newUi) { |
|
|
if (newUi !== 'default' && newUi !== 'none' && newUi !== 'monocolor') return; |
|
|
const html = document.documentElement; |
|
|
html.setAttribute('data-ui', newUi); |
|
|
try { localStorage.setItem('uvnote-ui', newUi); } catch (_) {} |
|
|
updateUiMenu(); |
|
|
updateUiDebug(); |
|
|
} |
|
|
function updateUiMenu() { |
|
|
const ui = document.documentElement.getAttribute('data-ui') || 'default'; |
|
|
const checks = { |
|
|
default: document.getElementById('checkbox-ui-default'), |
|
|
none: document.getElementById('checkbox-ui-none'), |
|
|
monocolor: document.getElementById('checkbox-ui-monocolor') |
|
|
}; |
|
|
if (checks.default) checks.default.textContent = ui === 'default' ? '☑' : '☐'; |
|
|
if (checks.none) checks.none.textContent = ui === 'none' ? '☑' : '☐'; |
|
|
if (checks.monocolor) checks.monocolor.textContent = ui === 'monocolor' ? '☑' : '☐'; |
|
|
} |
|
|
|
|
|
function updateUiDebug() { |
|
|
const ui = document.documentElement.getAttribute('data-ui') || 'default'; |
|
|
const color = document.documentElement.getAttribute('data-theme') || 'light'; |
|
|
const el = document.getElementById('ui-debug'); |
|
|
if (el) { |
|
|
el.textContent = `UI: ${ui} | Color: ${color}`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function clearLineSelections() { |
|
|
try { |
|
|
document.querySelectorAll('.code-line-highlight').forEach(el => { el.style.display = 'none'; }); |
|
|
document.querySelectorAll('.line-number.selected').forEach(el => el.classList.remove('selected')); |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
let _selection = null; |
|
|
|
|
|
function clearSelection(updateUrl) { |
|
|
clearLineSelections(); |
|
|
_selection = null; |
|
|
if (updateUrl) { |
|
|
try { |
|
|
const url = new URL(window.location.href); |
|
|
url.searchParams.delete('cell'); |
|
|
url.searchParams.delete('line'); |
|
|
history.replaceState(null, '', url.toString()); |
|
|
} catch (_) {} |
|
|
} |
|
|
updateStateIndicator(); |
|
|
} |
|
|
|
|
|
function selectCellLine(cellId, line, updateUrl) { |
|
|
try { |
|
|
|
|
|
clearLineSelections(); |
|
|
const codeBox = document.getElementById(`code-${cellId}`); |
|
|
if (!codeBox) return; |
|
|
const pre = codeBox.querySelector('.highlight pre'); |
|
|
const overlay = document.getElementById(`line-highlight-${cellId}`); |
|
|
const numbers = document.getElementById(`lines-${cellId}`); |
|
|
if (!pre || !overlay) return; |
|
|
|
|
|
|
|
|
const preStyle = getComputedStyle(pre); |
|
|
const padTop = parseFloat(preStyle.paddingTop || '0'); |
|
|
const lh = parseFloat(preStyle.lineHeight || '20'); |
|
|
|
|
|
|
|
|
overlay.style.display = 'block'; |
|
|
overlay.style.height = `${lh}px`; |
|
|
overlay.style.top = `${pre.offsetTop + padTop + (line - 1) * lh}px`; |
|
|
|
|
|
|
|
|
if (numbers) { |
|
|
numbers.querySelectorAll('.line-number').forEach(a => a.classList.remove('selected')); |
|
|
const sel = numbers.querySelector(`.line-number[data-line="${line}"]`); |
|
|
if (sel) sel.classList.add('selected'); |
|
|
} |
|
|
|
|
|
if (updateUrl) { |
|
|
const url = new URL(window.location.href); |
|
|
url.searchParams.set('cell', cellId); |
|
|
url.searchParams.set('line', String(line)); |
|
|
history.replaceState(null, '', url.toString()); |
|
|
} |
|
|
_selection = { cellId, a: line, b: line }; |
|
|
updateStateIndicator(); |
|
|
} catch (e) { console.warn('selectCellLine error', e); } |
|
|
} |
|
|
|
|
|
function selectCellLines(cellId, startLine, endLine, updateUrl) { |
|
|
try { |
|
|
|
|
|
const a = Math.min(startLine, endLine); |
|
|
const b = Math.max(startLine, endLine); |
|
|
clearLineSelections(); |
|
|
const codeBox = document.getElementById(`code-${cellId}`); |
|
|
if (!codeBox) return; |
|
|
const pre = codeBox.querySelector('.highlight pre'); |
|
|
const overlay = document.getElementById(`line-highlight-${cellId}`); |
|
|
const numbers = document.getElementById(`lines-${cellId}`); |
|
|
if (!pre || !overlay) return; |
|
|
|
|
|
const preStyle = getComputedStyle(pre); |
|
|
const padTop = parseFloat(preStyle.paddingTop || '0'); |
|
|
const lh = parseFloat(preStyle.lineHeight || '20'); |
|
|
|
|
|
overlay.style.display = 'block'; |
|
|
overlay.style.top = `${pre.offsetTop + padTop + (a - 1) * lh}px`; |
|
|
overlay.style.height = `${(b - a + 1) * lh}px`; |
|
|
|
|
|
if (numbers) { |
|
|
numbers.querySelectorAll('.line-number').forEach(a => a.classList.remove('selected')); |
|
|
for (let i = a; i <= b; i++) { |
|
|
const el = numbers.querySelector(`.line-number[data-line="${i}"]`); |
|
|
if (el) el.classList.add('selected'); |
|
|
} |
|
|
} |
|
|
|
|
|
if (updateUrl) { |
|
|
const url = new URL(window.location.href); |
|
|
url.searchParams.set('cell', cellId); |
|
|
if (a === b) url.searchParams.set('line', String(a)); |
|
|
else url.searchParams.set('line', `${a}-${b}`); |
|
|
history.replaceState(null, '', url.toString()); |
|
|
} |
|
|
_selection = { cellId, a, b }; |
|
|
updateStateIndicator(); |
|
|
} catch (e) { console.warn('selectCellLines error', e); } |
|
|
} |
|
|
|
|
|
|
|
|
let _lineDrag = { active: false, cellId: null, start: 0 }; |
|
|
function onLineNumberMouseDown(e) { |
|
|
const a = e.target.closest('.line-number'); |
|
|
if (!a) return; |
|
|
e.preventDefault(); |
|
|
const cellId = a.dataset.cell; |
|
|
const line = parseInt(a.dataset.line || '1', 10) || 1; |
|
|
|
|
|
const numbers = document.getElementById(`lines-${cellId}`); |
|
|
if (numbers) { |
|
|
const selected = Array.from(numbers.querySelectorAll('.line-number.selected')).map(n => parseInt(n.dataset.line||'0',10)).filter(Boolean); |
|
|
if (selected.length === 1 && selected[0] === line) { |
|
|
clearSelection(true); |
|
|
return; |
|
|
} |
|
|
} |
|
|
_lineDrag.active = true; |
|
|
_lineDrag.cellId = cellId; |
|
|
_lineDrag.start = line; |
|
|
selectCellLines(_lineDrag.cellId, _lineDrag.start, _lineDrag.start, false); |
|
|
} |
|
|
function onDocMouseMove(e) { |
|
|
if (!_lineDrag.active) return; |
|
|
const el = document.elementFromPoint(e.clientX, e.clientY); |
|
|
if (!el) return; |
|
|
const a = el.closest && el.closest('.line-number'); |
|
|
if (!a) return; |
|
|
if (a.dataset.cell !== _lineDrag.cellId) return; |
|
|
const cur = parseInt(a.dataset.line || '1', 10) || 1; |
|
|
selectCellLines(_lineDrag.cellId, _lineDrag.start, cur, false); |
|
|
} |
|
|
function onDocMouseUp(e) { |
|
|
if (!_lineDrag.active) return; |
|
|
const last = document.querySelector('.line-number.selected:last-of-type'); |
|
|
|
|
|
const numbers = document.getElementById(`lines-${_lineDrag.cellId}`); |
|
|
if (numbers) { |
|
|
const selected = Array.from(numbers.querySelectorAll('.line-number.selected')).map(n => parseInt(n.dataset.line||'0',10)).filter(Boolean); |
|
|
if (selected.length) { |
|
|
const a = Math.min(...selected); const b = Math.max(...selected); |
|
|
selectCellLines(_lineDrag.cellId, a, b, true); |
|
|
} |
|
|
} |
|
|
_lineDrag.active = false; _lineDrag.cellId = null; _lineDrag.start = 0; |
|
|
} |
|
|
|
|
|
function applyLocationFromUrl() { |
|
|
try { |
|
|
const url = new URL(window.location.href); |
|
|
const cell = url.searchParams.get('cell'); |
|
|
const lineParam = url.searchParams.get('line'); |
|
|
if (cell && lineParam) { |
|
|
if (lineParam.includes('-')) { |
|
|
const [a, b] = lineParam.split('-').map(x => parseInt(x, 10)); |
|
|
if (!Number.isNaN(a) && !Number.isNaN(b)) selectCellLines(cell, a, b, false); |
|
|
} else { |
|
|
const l = parseInt(lineParam, 10); |
|
|
if (!Number.isNaN(l)) selectCellLine(cell, l, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
applyToolsFromUrl(url.searchParams); |
|
|
|
|
|
|
|
|
const encodedCellStates = url.searchParams.get('cells'); |
|
|
console.log('Encoded cell states from URL:', encodedCellStates); |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
function applyToolsFromUrl(params) { |
|
|
try { |
|
|
|
|
|
const showTools = params.get('tools'); |
|
|
if (showTools === '1') { |
|
|
|
|
|
_urlLoadedTool = true; |
|
|
|
|
|
|
|
|
const color = params.get('color'); |
|
|
if (color && /^[0-9a-fA-F]{6}$/.test(color)) { |
|
|
setStoredArrowColor('#' + color); |
|
|
} |
|
|
|
|
|
|
|
|
const thickness = params.get('thickness'); |
|
|
if (thickness) { |
|
|
const value = parseInt(thickness, 10); |
|
|
if (value >= 1 && value <= 10) { |
|
|
setStoredLineThickness(value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const encodedShapes = params.get('shapes'); |
|
|
if (encodedShapes) { |
|
|
const decodedShapes = decodeShapesFromUrl(encodedShapes); |
|
|
if (decodedShapes.length > 0) { |
|
|
_shapes = decodedShapes; |
|
|
saveShapes(); |
|
|
|
|
|
setTimeout(() => { |
|
|
renderOverlay(); |
|
|
}, 300); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
const toolsWidget = document.querySelector('.tools-widget'); |
|
|
const checkbox = document.getElementById('checkbox-tools'); |
|
|
if (toolsWidget && checkbox) { |
|
|
toolsWidget.style.display = 'block'; |
|
|
checkbox.textContent = '☑'; |
|
|
localStorage.setItem('uvnote-widget-tools', 'visible'); |
|
|
} |
|
|
|
|
|
|
|
|
const activeTool = params.get('tool'); |
|
|
if (activeTool && ['arrow', 'pen', 'eraser', 'spotlight'].includes(activeTool)) { |
|
|
const toolBtn = Array.from(document.querySelectorAll('.tool-button')).find(btn => btn.textContent === activeTool); |
|
|
if (toolBtn) { |
|
|
toolBtn.click(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
layoutWidgetsStackedBottomRight(); |
|
|
}, 200); |
|
|
} |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
function captureInitialCellStates() { |
|
|
const cells = document.querySelectorAll('.cell'); |
|
|
cells.forEach(cell => { |
|
|
const cellId = cell.id.replace('cell-', ''); |
|
|
const codeEl = document.getElementById('code-' + cellId); |
|
|
const outputEl = document.getElementById('output-' + cellId); |
|
|
|
|
|
if (codeEl || outputEl) { |
|
|
const state = {}; |
|
|
if (codeEl) { |
|
|
state.c = codeEl.classList.contains('collapsed') ? 0 : 1; |
|
|
} |
|
|
if (outputEl) { |
|
|
state.o = outputEl.classList.contains('collapsed') ? 0 : 1; |
|
|
} |
|
|
_initialCellStates[cellId] = state; |
|
|
} |
|
|
}); |
|
|
console.log('Captured initial cell states:', _initialCellStates); |
|
|
} |
|
|
|
|
|
function encodeCellStatesToUrl() { |
|
|
|
|
|
const cells = document.querySelectorAll('.cell'); |
|
|
const cellStates = {}; |
|
|
|
|
|
console.log('Found cells:', cells.length); |
|
|
|
|
|
cells.forEach(cell => { |
|
|
const cellId = cell.id.replace('cell-', ''); |
|
|
const codeEl = document.getElementById('code-' + cellId); |
|
|
const outputEl = document.getElementById('output-' + cellId); |
|
|
const initialState = _initialCellStates[cellId] || {}; |
|
|
|
|
|
console.log(`Encoding cell ${cellId}:`, { |
|
|
codeEl: !!codeEl, |
|
|
outputEl: !!outputEl, |
|
|
codeCollapsed: codeEl ? codeEl.classList.contains('collapsed') : 'N/A', |
|
|
outputCollapsed: outputEl ? outputEl.classList.contains('collapsed') : 'N/A', |
|
|
initialState: initialState |
|
|
}); |
|
|
|
|
|
if (codeEl || outputEl) { |
|
|
const state = {}; |
|
|
let hasChanges = false; |
|
|
|
|
|
if (codeEl) { |
|
|
const currentCodeState = codeEl.classList.contains('collapsed') ? 0 : 1; |
|
|
const initialCodeState = initialState.c; |
|
|
|
|
|
if (initialCodeState !== undefined && currentCodeState !== initialCodeState) { |
|
|
state.c = currentCodeState; |
|
|
hasChanges = true; |
|
|
} |
|
|
} |
|
|
|
|
|
if (outputEl) { |
|
|
const currentOutputState = outputEl.classList.contains('collapsed') ? 0 : 1; |
|
|
const initialOutputState = initialState.o; |
|
|
|
|
|
if (initialOutputState !== undefined && currentOutputState !== initialOutputState) { |
|
|
state.o = currentOutputState; |
|
|
hasChanges = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (hasChanges) { |
|
|
cellStates[cellId] = state; |
|
|
console.log(`Added cell ${cellId}:`, state); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
console.log('Final cell states to encode:', cellStates); |
|
|
|
|
|
|
|
|
if (Object.keys(cellStates).length === 0) return ''; |
|
|
|
|
|
|
|
|
const encoded = btoa(JSON.stringify(cellStates)); |
|
|
console.log('Encoded cell states:', encoded); |
|
|
return encoded; |
|
|
} |
|
|
|
|
|
function decodeCellStatesFromUrl(encodedStates) { |
|
|
if (!encodedStates) return {}; |
|
|
|
|
|
try { |
|
|
return JSON.parse(atob(encodedStates)); |
|
|
} catch (e) { |
|
|
console.error('Failed to decode cell states:', e); |
|
|
return {}; |
|
|
} |
|
|
} |
|
|
|
|
|
function applyCellStatesFromUrl(cellStates) { |
|
|
console.log('Applying cell states from URL:', cellStates); |
|
|
Object.entries(cellStates).forEach(([cellId, state]) => { |
|
|
const codeEl = document.getElementById('code-' + cellId); |
|
|
const outputEl = document.getElementById('output-' + cellId); |
|
|
|
|
|
console.log(`Cell ${cellId}:`, { |
|
|
codeEl: !!codeEl, |
|
|
outputEl: !!outputEl, |
|
|
state: state |
|
|
}); |
|
|
|
|
|
if (codeEl && state.c !== undefined) { |
|
|
if (state.c === 0) { |
|
|
codeEl.classList.add('collapsed'); |
|
|
console.log(`Collapsed code for cell ${cellId}`, { |
|
|
hasCollapsedClass: codeEl.classList.contains('collapsed'), |
|
|
computedDisplay: getComputedStyle(codeEl).display, |
|
|
classList: Array.from(codeEl.classList), |
|
|
elementId: codeEl.id |
|
|
}); |
|
|
} else { |
|
|
codeEl.classList.remove('collapsed'); |
|
|
codeEl.classList.add('expanded'); |
|
|
console.log(`Expanded code for cell ${cellId}`, { |
|
|
hasCollapsedClass: codeEl.classList.contains('collapsed'), |
|
|
hasExpandedClass: codeEl.classList.contains('expanded'), |
|
|
computedDisplay: getComputedStyle(codeEl).display, |
|
|
classList: Array.from(codeEl.classList), |
|
|
elementId: codeEl.id |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
if (outputEl && state.o !== undefined) { |
|
|
if (state.o === 0) { |
|
|
outputEl.classList.add('collapsed'); |
|
|
console.log(`Collapsed output for cell ${cellId}`); |
|
|
} else { |
|
|
outputEl.classList.remove('collapsed'); |
|
|
console.log(`Expanded output for cell ${cellId}`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
updateIndicators(cellId); |
|
|
|
|
|
if (codeEl) { |
|
|
codeEl.offsetHeight; |
|
|
console.log(`After indicators update - code visible: ${getComputedStyle(codeEl).display !== 'none'}`); |
|
|
} |
|
|
if (outputEl) { |
|
|
outputEl.offsetHeight; |
|
|
console.log(`After indicators update - output visible: ${getComputedStyle(outputEl).display !== 'none'}`); |
|
|
} |
|
|
} catch (e) { |
|
|
console.error(`Error updating indicators for cell ${cellId}:`, e); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
function encodeShapesToUrl() { |
|
|
|
|
|
if (_shapes.length === 0) return ''; |
|
|
|
|
|
const shapeData = _shapes.map(shape => { |
|
|
const baseData = { |
|
|
ct: shape.createdAt, |
|
|
fo: shape.fadeoutTime || getFadeoutTime() |
|
|
}; |
|
|
|
|
|
if (shape.type === 'arrow') { |
|
|
return { |
|
|
...baseData, |
|
|
t: 'a', |
|
|
x1: Math.round(shape.x1), |
|
|
y1: Math.round(shape.y1), |
|
|
x2: Math.round(shape.x2), |
|
|
y2: Math.round(shape.y2), |
|
|
c: shape.color.substring(1), |
|
|
w: shape.width |
|
|
}; |
|
|
} else if (shape.type === 'pen') { |
|
|
return { |
|
|
...baseData, |
|
|
t: 'p', |
|
|
pts: shape.points.map(p => [Math.round(p.x), Math.round(p.y)]), |
|
|
c: shape.color.substring(1), |
|
|
w: shape.width |
|
|
}; |
|
|
} else if (shape.type === 'spotlight') { |
|
|
return { |
|
|
...baseData, |
|
|
t: 's', |
|
|
x: Math.round(shape.x), |
|
|
y: Math.round(shape.y), |
|
|
r: Math.round(shape.radius) |
|
|
}; |
|
|
} |
|
|
}).filter(Boolean); |
|
|
|
|
|
return btoa(JSON.stringify(shapeData)); |
|
|
} |
|
|
|
|
|
function decodeShapesFromUrl(encodedShapes) { |
|
|
if (!encodedShapes) return []; |
|
|
|
|
|
try { |
|
|
const shapeData = JSON.parse(atob(encodedShapes)); |
|
|
return shapeData.map(data => { |
|
|
const base = { |
|
|
createdAt: data.ct || Date.now(), |
|
|
fadeoutTime: data.fo || 0, |
|
|
opacity: 1.0 |
|
|
}; |
|
|
|
|
|
if (data.t === 'a') { |
|
|
return { |
|
|
...base, |
|
|
type: 'arrow', |
|
|
x1: data.x1, |
|
|
y1: data.y1, |
|
|
x2: data.x2, |
|
|
y2: data.y2, |
|
|
color: '#' + data.c, |
|
|
width: data.w |
|
|
}; |
|
|
} else if (data.t === 'p') { |
|
|
return { |
|
|
...base, |
|
|
type: 'pen', |
|
|
points: data.pts.map(([x, y]) => ({ x, y })), |
|
|
color: '#' + data.c, |
|
|
width: data.w |
|
|
}; |
|
|
} else if (data.t === 's') { |
|
|
return { |
|
|
...base, |
|
|
type: 'spotlight', |
|
|
x: data.x, |
|
|
y: data.y, |
|
|
radius: data.r, |
|
|
color: '#000000' |
|
|
}; |
|
|
} |
|
|
}).filter(Boolean); |
|
|
} catch (e) { |
|
|
console.error('Failed to decode shapes:', e); |
|
|
return []; |
|
|
} |
|
|
} |
|
|
|
|
|
function encodeToolStateToUrl() { |
|
|
|
|
|
if (_isInitializing) { |
|
|
return window.location.href; |
|
|
} |
|
|
|
|
|
const params = new URLSearchParams(window.location.search); |
|
|
|
|
|
|
|
|
const toolsWidget = document.querySelector('.tools-widget'); |
|
|
const activeTool = document.body.dataset.tool; |
|
|
const hasActiveTool = activeTool && activeTool !== 'none'; |
|
|
const toolsWidgetVisible = toolsWidget && getComputedStyle(toolsWidget).display !== 'none'; |
|
|
|
|
|
|
|
|
const encodedShapes = encodeShapesToUrl(); |
|
|
if (encodedShapes) { |
|
|
params.set('shapes', encodedShapes); |
|
|
} else { |
|
|
params.delete('shapes'); |
|
|
} |
|
|
|
|
|
|
|
|
const existingCellStates = params.get('cells'); |
|
|
if (existingCellStates) { |
|
|
|
|
|
params.set('cells', existingCellStates); |
|
|
} else { |
|
|
|
|
|
const encodedCellStates = encodeCellStatesToUrl(); |
|
|
if (encodedCellStates) { |
|
|
params.set('cells', encodedCellStates); |
|
|
} |
|
|
} |
|
|
|
|
|
if (toolsWidgetVisible && hasActiveTool) { |
|
|
|
|
|
params.set('tools', '1'); |
|
|
params.set('tool', activeTool); |
|
|
|
|
|
|
|
|
const color = getArrowColor(); |
|
|
if (color && color.startsWith('#')) { |
|
|
params.set('color', color.substring(1)); |
|
|
} |
|
|
|
|
|
|
|
|
const thickness = getLineThickness(); |
|
|
params.set('thickness', thickness.toString()); |
|
|
} else { |
|
|
|
|
|
params.delete('tools'); |
|
|
params.delete('tool'); |
|
|
params.delete('color'); |
|
|
params.delete('thickness'); |
|
|
params.delete('fadeout'); |
|
|
} |
|
|
|
|
|
|
|
|
const newUrl = window.location.pathname + (params.toString() ? '?' + params.toString() : '') + window.location.hash; |
|
|
window.history.replaceState(null, '', newUrl); |
|
|
|
|
|
return window.location.href; |
|
|
} |
|
|
|
|
|
function resetLayout() { |
|
|
try { |
|
|
|
|
|
const allKeys = Object.keys(localStorage); |
|
|
const uvnoteKeys = allKeys.filter(key => key.startsWith('uvnote-')); |
|
|
uvnoteKeys.forEach(k => localStorage.removeItem(k)); |
|
|
} catch (_) {} |
|
|
|
|
|
|
|
|
try { clearSelection(true); } catch(_) {} |
|
|
|
|
|
try { window.setActiveTool('none'); } catch(_) {} |
|
|
|
|
|
try { _shapes = []; saveShapes(); } catch(_) {} |
|
|
|
|
|
try { _urlLoadedTool = false; } catch(_) {} |
|
|
|
|
|
try { |
|
|
const cells = document.querySelectorAll('.cell'); |
|
|
cells.forEach(cell => { |
|
|
const cellId = cell.id.replace('cell-', ''); |
|
|
const codeEl = document.getElementById('code-' + cellId); |
|
|
const outputEl = document.getElementById('output-' + cellId); |
|
|
if (codeEl) codeEl.classList.remove('collapsed'); |
|
|
if (outputEl) outputEl.classList.remove('collapsed'); |
|
|
updateIndicators(cellId); |
|
|
}); |
|
|
} catch(_) {} |
|
|
|
|
|
|
|
|
try { |
|
|
const cleanUrl = window.location.pathname + window.location.hash; |
|
|
window.location.href = cleanUrl; |
|
|
} catch (_) { |
|
|
|
|
|
location.reload(); |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleMenu() { |
|
|
const menuButton = document.querySelector('.menu-button'); |
|
|
if (menuButton) { |
|
|
menuButton.classList.toggle('active'); |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleWidget(widgetName) { |
|
|
let widget; |
|
|
let checkbox; |
|
|
|
|
|
|
|
|
const menuButton = document.querySelector('.menu-button'); |
|
|
if (menuButton) { |
|
|
menuButton.classList.remove('active'); |
|
|
} |
|
|
|
|
|
switch(widgetName) { |
|
|
case 'tools': |
|
|
widget = document.querySelector('.tools-widget'); |
|
|
checkbox = document.getElementById('checkbox-tools'); |
|
|
break; |
|
|
case 'file-explorer': |
|
|
widget = document.querySelector('.file-explorer'); |
|
|
checkbox = document.getElementById('checkbox-file-explorer'); |
|
|
break; |
|
|
case 'minimap': |
|
|
widget = document.querySelector('.minimap'); |
|
|
checkbox = document.getElementById('checkbox-minimap'); |
|
|
break; |
|
|
case 'status': |
|
|
widget = document.querySelector('.status-widget'); |
|
|
checkbox = document.getElementById('checkbox-status'); |
|
|
break; |
|
|
default: |
|
|
return; |
|
|
} |
|
|
|
|
|
if (widget && checkbox) { |
|
|
const isVisible = getComputedStyle(widget).display !== 'none'; |
|
|
widget.style.display = isVisible ? 'none' : 'block'; |
|
|
checkbox.textContent = isVisible ? '☐' : '☑'; |
|
|
|
|
|
|
|
|
try { |
|
|
localStorage.setItem(`uvnote-widget-${widgetName}`, isVisible ? 'hidden' : 'visible'); |
|
|
} catch (_) {} |
|
|
|
|
|
|
|
|
try { |
|
|
layoutWidgetsStackedBottomRight(); |
|
|
} catch (_) {} |
|
|
|
|
|
|
|
|
if (widgetName === 'tools') { |
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
function initializeWidgetVisibility() { |
|
|
const widgets = [ |
|
|
{ name: 'tools', selector: '.tools-widget' }, |
|
|
{ name: 'file-explorer', selector: '.file-explorer' }, |
|
|
{ name: 'minimap', selector: '.minimap' }, |
|
|
{ name: 'status', selector: '.status-widget' } |
|
|
]; |
|
|
|
|
|
widgets.forEach(({ name, selector }) => { |
|
|
const defaultState = name === 'status' ? 'visible' : 'hidden'; |
|
|
const savedState = localStorage.getItem(`uvnote-widget-${name}`) || defaultState; |
|
|
const widget = document.querySelector(selector); |
|
|
const checkbox = document.getElementById(`checkbox-${name}`); |
|
|
|
|
|
if (widget && checkbox) { |
|
|
const isVisible = savedState === 'visible'; |
|
|
widget.style.display = isVisible ? 'block' : 'none'; |
|
|
checkbox.textContent = isVisible ? '☑' : '☐'; |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('click', function(event) { |
|
|
const menuButton = document.querySelector('.menu-button'); |
|
|
|
|
|
if (menuButton && !menuButton.contains(event.target)) { |
|
|
menuButton.classList.remove('active'); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
function hasCustomWidgetPositions() { |
|
|
try { |
|
|
return ( |
|
|
localStorage.getItem('uvnote-minimap-pos') || |
|
|
localStorage.getItem('uvnote-file-explorer-pos') || |
|
|
localStorage.getItem('uvnote-tools-pos') |
|
|
); |
|
|
} catch (_) { return false; } |
|
|
} |
|
|
|
|
|
function rectsOverlap(r1, r2) { |
|
|
return !(r1.right <= r2.left || r2.right <= r1.left || r1.bottom <= r2.top || r2.bottom <= r1.top); |
|
|
} |
|
|
|
|
|
function widgetsOverlap(widgets) { |
|
|
for (let i = 0; i < widgets.length; i++) { |
|
|
const a = widgets[i]; |
|
|
const ra = a.getBoundingClientRect(); |
|
|
for (let j = i + 1; j < widgets.length; j++) { |
|
|
const b = widgets[j]; |
|
|
const rb = b.getBoundingClientRect(); |
|
|
if (rectsOverlap(ra, rb)) return true; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
function applyStackLayout(widgets, order) { |
|
|
if (!widgets.length) return; |
|
|
|
|
|
const fixedWidth = 220; |
|
|
widgets.forEach(el => { el.style.width = fixedWidth + 'px'; }); |
|
|
|
|
|
|
|
|
const gap = 12; |
|
|
const available = Math.max(0, window.innerHeight - 40 - gap * (order.length - 1)); |
|
|
const eachMax = Math.floor(available / order.length); |
|
|
order.forEach(el => { |
|
|
el.style.maxHeight = eachMax + 'px'; |
|
|
el.style.overflowY = 'auto'; |
|
|
}); |
|
|
|
|
|
|
|
|
let bottomOffset = 20; |
|
|
order.forEach(el => { |
|
|
el.style.left = 'auto'; |
|
|
el.style.top = 'auto'; |
|
|
el.style.right = '20px'; |
|
|
el.style.bottom = bottomOffset + 'px'; |
|
|
bottomOffset += el.offsetHeight + gap; |
|
|
}); |
|
|
} |
|
|
|
|
|
function layoutWidgetsStackedBottomRight() { |
|
|
const minimap = document.querySelector('.minimap'); |
|
|
const fileExplorer = document.querySelector('.file-explorer'); |
|
|
const tools = document.querySelector('.tools-widget'); |
|
|
const status = document.querySelector('.status-widget'); |
|
|
const widgets = [minimap, fileExplorer, tools, status].filter(el => el && getComputedStyle(el).display !== 'none'); |
|
|
if (!widgets.length) return; |
|
|
|
|
|
const order = [minimap, fileExplorer, tools, status].filter(Boolean).filter(el => getComputedStyle(el).display !== 'none'); |
|
|
|
|
|
|
|
|
if (hasCustomWidgetPositions() && !widgetsOverlap(widgets)) return; |
|
|
|
|
|
applyStackLayout(widgets, order); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let _minimapScrollContainer = null; |
|
|
let _minimapScrollHandler = null; |
|
|
function initMinimap() { |
|
|
|
|
|
const minimap = createMinimap(); |
|
|
document.body.appendChild(minimap); |
|
|
|
|
|
const mTitle = minimap.querySelector('.minimap-title'); |
|
|
makeDraggable(minimap, 'uvnote-minimap-pos', mTitle); |
|
|
|
|
|
|
|
|
_minimapScrollContainer = window; |
|
|
|
|
|
if (_minimapScrollContainer) { |
|
|
_minimapScrollHandler = () => updateMinimapActive(); |
|
|
if (_minimapScrollContainer === window) { |
|
|
window.addEventListener('scroll', _minimapScrollHandler); |
|
|
} else { |
|
|
_minimapScrollContainer.addEventListener('scroll', _minimapScrollHandler); |
|
|
} |
|
|
} |
|
|
updateMinimapActive(); |
|
|
} |
|
|
|
|
|
function teardownMinimap() { |
|
|
const minimap = document.querySelector('.minimap'); |
|
|
if (minimap && minimap.parentNode) minimap.parentNode.removeChild(minimap); |
|
|
if (_minimapScrollContainer && _minimapScrollHandler) { |
|
|
if (_minimapScrollContainer === window) { |
|
|
window.removeEventListener('scroll', _minimapScrollHandler); |
|
|
} else { |
|
|
_minimapScrollContainer.removeEventListener('scroll', _minimapScrollHandler); |
|
|
} |
|
|
} |
|
|
_minimapScrollContainer = null; |
|
|
_minimapScrollHandler = null; |
|
|
} |
|
|
|
|
|
function initFileExplorer() { |
|
|
|
|
|
const fileExplorer = createFileExplorer(); |
|
|
document.body.appendChild(fileExplorer); |
|
|
} |
|
|
|
|
|
function createMinimap() { |
|
|
const minimap = document.createElement('div'); |
|
|
minimap.className = 'minimap'; |
|
|
|
|
|
const title = document.createElement('div'); |
|
|
title.className = 'minimap-title'; |
|
|
title.textContent = 'navigation'; |
|
|
minimap.appendChild(title); |
|
|
|
|
|
|
|
|
const root = document.querySelector('.main-content') || document; |
|
|
const headings = root.querySelectorAll('h1, h2, h3, h4, h5, h6'); |
|
|
const cells = root.querySelectorAll('.cell'); |
|
|
|
|
|
|
|
|
const items = []; |
|
|
|
|
|
headings.forEach(heading => { |
|
|
const id = heading.id || generateId(heading.textContent); |
|
|
if (!heading.id) heading.id = id; |
|
|
|
|
|
items.push({ |
|
|
element: heading, |
|
|
type: 'heading', |
|
|
level: parseInt(heading.tagName.charAt(1)), |
|
|
text: heading.textContent.trim(), |
|
|
id: id, |
|
|
position: heading.getBoundingClientRect().top + window.scrollY |
|
|
}); |
|
|
}); |
|
|
|
|
|
cells.forEach(cell => { |
|
|
const header = cell.querySelector('.cell-header'); |
|
|
if (header) { |
|
|
const id = cell.id || `cell-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; |
|
|
if (!cell.id) cell.id = id; |
|
|
|
|
|
items.push({ |
|
|
element: cell, |
|
|
type: 'cell', |
|
|
text: header.textContent.trim(), |
|
|
id: id, |
|
|
position: cell.getBoundingClientRect().top + window.scrollY |
|
|
}); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
items.sort((a, b) => a.position - b.position); |
|
|
|
|
|
|
|
|
items.forEach(item => { |
|
|
const link = document.createElement('a'); |
|
|
link.className = `minimap-item ${item.type === 'heading' ? 'minimap-heading' : 'minimap-cell'}`; |
|
|
if (item.type === 'heading') { |
|
|
link.classList.add(`h${item.level}`); |
|
|
} |
|
|
link.textContent = item.text.length > 25 ? item.text.substring(0, 22) + '...' : item.text; |
|
|
link.href = `#${item.id}`; |
|
|
link.onclick = function(e) { |
|
|
e.preventDefault(); |
|
|
item.element.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
|
|
}; |
|
|
minimap.appendChild(link); |
|
|
}); |
|
|
|
|
|
return minimap; |
|
|
} |
|
|
|
|
|
function generateId(text) { |
|
|
return text.toLowerCase() |
|
|
.replace(/[^a-z0-9]+/g, '-') |
|
|
.replace(/^-+|-+$/g, '') |
|
|
.substring(0, 20); |
|
|
} |
|
|
|
|
|
function updateMinimapActive() { |
|
|
const minimapItems = document.querySelectorAll('.minimap-item'); |
|
|
const container = _minimapScrollContainer || window; |
|
|
const containerRect = container === window ? null : container.getBoundingClientRect(); |
|
|
const scrollPos = (container === window ? window.scrollY : container.scrollTop) + 100; |
|
|
|
|
|
let activeItem = null; |
|
|
minimapItems.forEach(item => { |
|
|
const targetId = item.getAttribute('href').substring(1); |
|
|
const target = document.getElementById(targetId); |
|
|
|
|
|
if (target) { |
|
|
const rectTop = target.getBoundingClientRect().top; |
|
|
const targetPos = (container === window) |
|
|
? rectTop + window.scrollY |
|
|
: rectTop - containerRect.top + container.scrollTop; |
|
|
if (targetPos <= scrollPos) { |
|
|
activeItem = item; |
|
|
} |
|
|
} |
|
|
|
|
|
item.classList.remove('active'); |
|
|
}); |
|
|
|
|
|
if (activeItem) { |
|
|
activeItem.classList.add('active'); |
|
|
} |
|
|
} |
|
|
|
|
|
function createFileExplorer() { |
|
|
const fileExplorer = document.createElement('div'); |
|
|
fileExplorer.className = 'file-explorer'; |
|
|
|
|
|
const title = document.createElement('div'); |
|
|
title.className = 'file-explorer-title'; |
|
|
title.textContent = 'files'; |
|
|
fileExplorer.appendChild(title); |
|
|
|
|
|
makeDraggable(fileExplorer, 'uvnote-file-explorer-pos', title); |
|
|
|
|
|
|
|
|
const scriptsSection = document.createElement('div'); |
|
|
scriptsSection.className = 'file-explorer-section'; |
|
|
|
|
|
const scriptsTitle = document.createElement('div'); |
|
|
scriptsTitle.className = 'file-explorer-section-title'; |
|
|
scriptsTitle.textContent = 'scripts'; |
|
|
scriptsSection.appendChild(scriptsTitle); |
|
|
|
|
|
|
|
|
const root = document.querySelector('.main-content') || document; |
|
|
const cells = root.querySelectorAll('.cell'); |
|
|
cells.forEach(cell => { |
|
|
const header = cell.querySelector('.cell-header'); |
|
|
if (header) { |
|
|
const cellText = header.textContent.trim(); |
|
|
const cellMatch = cellText.match(/Cell: ([a-zA-Z_][a-zA-Z0-9_]*)/); |
|
|
if (cellMatch) { |
|
|
const cellId = cellMatch[1]; |
|
|
const scriptItem = document.createElement('div'); |
|
|
scriptItem.className = 'file-explorer-item script'; |
|
|
scriptItem.textContent = `${cellId}.py`; |
|
|
scriptItem.onclick = function() { |
|
|
cell.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
|
|
}; |
|
|
scriptsSection.appendChild(scriptItem); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
fileExplorer.appendChild(scriptsSection); |
|
|
|
|
|
|
|
|
const artifactsSection = document.createElement('div'); |
|
|
artifactsSection.className = 'file-explorer-section'; |
|
|
|
|
|
const artifactsTitle = document.createElement('div'); |
|
|
artifactsTitle.className = 'file-explorer-section-title'; |
|
|
artifactsTitle.textContent = 'artifacts'; |
|
|
artifactsSection.appendChild(artifactsTitle); |
|
|
|
|
|
|
|
|
const artifactsRoot = document.querySelector('.main-content') || document; |
|
|
const artifacts = artifactsRoot.querySelectorAll('.artifact'); |
|
|
if (artifacts.length === 0) { |
|
|
const noArtifacts = document.createElement('div'); |
|
|
noArtifacts.className = 'file-explorer-item artifact'; |
|
|
noArtifacts.textContent = '(none)'; |
|
|
noArtifacts.style.opacity = '0.5'; |
|
|
artifactsSection.appendChild(noArtifacts); |
|
|
} else { |
|
|
artifacts.forEach(artifact => { |
|
|
const artifactItem = document.createElement('div'); |
|
|
artifactItem.className = 'file-explorer-item artifact'; |
|
|
artifactItem.textContent = artifact.textContent; |
|
|
artifactItem.onclick = function() { |
|
|
artifact.click(); |
|
|
}; |
|
|
artifactsSection.appendChild(artifactItem); |
|
|
}); |
|
|
} |
|
|
|
|
|
fileExplorer.appendChild(artifactsSection); |
|
|
|
|
|
return fileExplorer; |
|
|
} |
|
|
|
|
|
function initStatusWidget() { |
|
|
let el = document.querySelector('.status-widget'); |
|
|
if (!el) { |
|
|
el = document.createElement('div'); |
|
|
el.className = 'status-widget'; |
|
|
el.id = 'status-widget'; |
|
|
el.textContent = 'ready — Esc'; |
|
|
document.body.appendChild(el); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let _cursorX = 0; |
|
|
let _cursorY = 0; |
|
|
let _cursorVisible = false; |
|
|
|
|
|
function setActiveTool(tool) { |
|
|
if (!tool || tool === 'none') { |
|
|
document.body.dataset.tool = 'none'; |
|
|
localStorage.setItem('uvnote-active-tool', 'none'); |
|
|
setOverlayActive(false); |
|
|
_cursorVisible = false; |
|
|
|
|
|
const toolButtons = document.querySelectorAll('.tools-widget .tool-button'); |
|
|
toolButtons.forEach(btn => btn.classList.remove('active')); |
|
|
updateStateIndicator(); |
|
|
encodeToolStateToUrl(); |
|
|
return; |
|
|
} |
|
|
document.body.dataset.tool = tool; |
|
|
localStorage.setItem('uvnote-active-tool', tool); |
|
|
setOverlayActive(true); |
|
|
_cursorVisible = true; |
|
|
updateStateIndicator(); |
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
|
|
|
|
|
|
window.setActiveTool = setActiveTool; |
|
|
|
|
|
|
|
|
function getArrowColor() { |
|
|
const saved = localStorage.getItem('uvnote-arrow-color'); |
|
|
if (saved) return saved; |
|
|
return '#e53935'; |
|
|
} |
|
|
|
|
|
function setStoredArrowColor(color) { |
|
|
try { localStorage.setItem('uvnote-arrow-color', color); } catch (_) {} |
|
|
} |
|
|
|
|
|
function getLineThickness() { |
|
|
const saved = localStorage.getItem('uvnote-line-thickness'); |
|
|
if (saved) return parseInt(saved, 10); |
|
|
return 6; |
|
|
} |
|
|
|
|
|
function setStoredLineThickness(thickness) { |
|
|
try { localStorage.setItem('uvnote-line-thickness', thickness); } catch (_) {} |
|
|
} |
|
|
|
|
|
function getFadeoutTime() { |
|
|
const saved = localStorage.getItem('uvnote-fadeout-time'); |
|
|
if (saved) return parseInt(saved, 10); |
|
|
return 5; |
|
|
} |
|
|
|
|
|
function setStoredFadeoutTime(seconds) { |
|
|
try { localStorage.setItem('uvnote-fadeout-time', seconds); } catch (_) {} |
|
|
} |
|
|
|
|
|
function createToolsWidget() { |
|
|
const tools = document.createElement('div'); |
|
|
tools.className = 'tools-widget'; |
|
|
|
|
|
const title = document.createElement('div'); |
|
|
title.className = 'tools-title'; |
|
|
title.textContent = 'tools'; |
|
|
tools.appendChild(title); |
|
|
|
|
|
const row = document.createElement('div'); |
|
|
row.className = 'tools-row'; |
|
|
tools.appendChild(row); |
|
|
|
|
|
|
|
|
const arrowBtn = document.createElement('div'); |
|
|
arrowBtn.className = 'tool-button'; |
|
|
arrowBtn.textContent = 'arrow'; |
|
|
arrowBtn.onclick = function() { |
|
|
const isActive = arrowBtn.classList.contains('active'); |
|
|
if (isActive) { |
|
|
arrowBtn.classList.remove('active'); |
|
|
setActiveTool('none'); |
|
|
} else { |
|
|
tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active')); |
|
|
arrowBtn.classList.add('active'); |
|
|
setActiveTool('arrow'); |
|
|
} |
|
|
}; |
|
|
row.appendChild(arrowBtn); |
|
|
|
|
|
|
|
|
const penBtn = document.createElement('div'); |
|
|
penBtn.className = 'tool-button'; |
|
|
penBtn.textContent = 'pen'; |
|
|
penBtn.onclick = function() { |
|
|
const isActive = penBtn.classList.contains('active'); |
|
|
if (isActive) { |
|
|
penBtn.classList.remove('active'); |
|
|
setActiveTool('none'); |
|
|
} else { |
|
|
tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active')); |
|
|
penBtn.classList.add('active'); |
|
|
setActiveTool('pen'); |
|
|
} |
|
|
}; |
|
|
row.appendChild(penBtn); |
|
|
|
|
|
|
|
|
const eraseBtn = document.createElement('div'); |
|
|
eraseBtn.className = 'tool-button'; |
|
|
eraseBtn.textContent = 'eraser'; |
|
|
eraseBtn.onclick = function() { |
|
|
const isActive = eraseBtn.classList.contains('active'); |
|
|
if (isActive) { |
|
|
eraseBtn.classList.remove('active'); |
|
|
setActiveTool('none'); |
|
|
} else { |
|
|
tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active')); |
|
|
eraseBtn.classList.add('active'); |
|
|
setActiveTool('eraser'); |
|
|
} |
|
|
}; |
|
|
row.appendChild(eraseBtn); |
|
|
|
|
|
|
|
|
const spotlightBtn = document.createElement('div'); |
|
|
spotlightBtn.className = 'tool-button'; |
|
|
spotlightBtn.textContent = 'spotlight'; |
|
|
spotlightBtn.onclick = function() { |
|
|
const isActive = spotlightBtn.classList.contains('active'); |
|
|
if (isActive) { |
|
|
spotlightBtn.classList.remove('active'); |
|
|
setActiveTool('none'); |
|
|
} else { |
|
|
tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active')); |
|
|
spotlightBtn.classList.add('active'); |
|
|
setActiveTool('spotlight'); |
|
|
} |
|
|
}; |
|
|
row.appendChild(spotlightBtn); |
|
|
|
|
|
|
|
|
const clearBtn = document.createElement('div'); |
|
|
clearBtn.className = 'tool-button'; |
|
|
clearBtn.textContent = 'clear'; |
|
|
clearBtn.onclick = function() { |
|
|
_shapes = []; |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
}; |
|
|
row.appendChild(clearBtn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const saved = localStorage.getItem('uvnote-active-tool') || 'none'; |
|
|
if (saved === 'arrow') { |
|
|
arrowBtn.classList.add('active'); |
|
|
setActiveTool('arrow'); |
|
|
} else if (saved === 'pen') { |
|
|
penBtn.classList.add('active'); |
|
|
setActiveTool('pen'); |
|
|
} else if (saved === 'eraser') { |
|
|
eraseBtn.classList.add('active'); |
|
|
setActiveTool('eraser'); |
|
|
} else if (saved === 'spotlight') { |
|
|
spotlightBtn.classList.add('active'); |
|
|
setActiveTool('spotlight'); |
|
|
} |
|
|
|
|
|
|
|
|
const colorTitle = document.createElement('div'); |
|
|
colorTitle.className = 'tools-section-title'; |
|
|
colorTitle.textContent = 'color'; |
|
|
tools.appendChild(colorTitle); |
|
|
|
|
|
const colorRow = document.createElement('div'); |
|
|
colorRow.className = 'tools-row color-row'; |
|
|
tools.appendChild(colorRow); |
|
|
|
|
|
const swatchColors = [ |
|
|
|
|
|
'#e53935', '#fb8c00', '#fdd835', '#43a047', '#1e88e5', '#8e24aa', |
|
|
|
|
|
'#ff5722', '#795548', '#607d8b', '#9c27b0', |
|
|
|
|
|
'#000000', '#424242', '#9e9e9e', '#ffffff' |
|
|
]; |
|
|
const swatches = []; |
|
|
swatchColors.forEach(c => { |
|
|
const s = document.createElement('div'); |
|
|
s.className = 'color-swatch'; |
|
|
s.style.backgroundColor = c; |
|
|
s.title = c; |
|
|
s.onclick = () => { |
|
|
setStoredArrowColor(c); |
|
|
refreshColorUI(c); |
|
|
if (_cursorVisible) renderOverlay(); |
|
|
encodeToolStateToUrl(); |
|
|
}; |
|
|
colorRow.appendChild(s); |
|
|
swatches.push(s); |
|
|
}); |
|
|
|
|
|
const colorInput = document.createElement('input'); |
|
|
colorInput.type = 'color'; |
|
|
colorInput.className = 'color-input'; |
|
|
colorInput.oninput = () => { |
|
|
setStoredArrowColor(colorInput.value); |
|
|
refreshColorUI(colorInput.value); |
|
|
if (_cursorVisible) renderOverlay(); |
|
|
encodeToolStateToUrl(); |
|
|
}; |
|
|
colorRow.appendChild(colorInput); |
|
|
|
|
|
function refreshColorUI(selected) { |
|
|
const selectedHex = selected.startsWith('#') ? selected.toLowerCase() : rgbToHex(selected); |
|
|
|
|
|
swatches.forEach((s, i) => { |
|
|
const swatchHex = swatchColors[i].toLowerCase(); |
|
|
if (swatchHex === selectedHex) { |
|
|
s.classList.add('selected'); |
|
|
} else { |
|
|
s.classList.remove('selected'); |
|
|
} |
|
|
}); |
|
|
|
|
|
try { |
|
|
colorInput.value = selectedHex; |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
function rgbToHex(rgb) { |
|
|
const m = rgb.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)\)/i); |
|
|
if (!m) return '#000000'; |
|
|
const r = parseInt(m[1]).toString(16).padStart(2, '0'); |
|
|
const g = parseInt(m[2]).toString(16).padStart(2, '0'); |
|
|
const b = parseInt(m[3]).toString(16).padStart(2, '0'); |
|
|
return `#${r}${g}${b}`; |
|
|
} |
|
|
|
|
|
|
|
|
refreshColorUI(getArrowColor()); |
|
|
|
|
|
|
|
|
const thicknessTitle = document.createElement('div'); |
|
|
thicknessTitle.className = 'tools-section-title'; |
|
|
thicknessTitle.textContent = 'thickness'; |
|
|
tools.appendChild(thicknessTitle); |
|
|
|
|
|
const thicknessRow = document.createElement('div'); |
|
|
thicknessRow.className = 'thickness-row'; |
|
|
tools.appendChild(thicknessRow); |
|
|
|
|
|
const thicknessSlider = document.createElement('input'); |
|
|
thicknessSlider.type = 'range'; |
|
|
thicknessSlider.className = 'thickness-slider'; |
|
|
thicknessSlider.min = '1'; |
|
|
thicknessSlider.max = '10'; |
|
|
thicknessSlider.value = getLineThickness(); |
|
|
|
|
|
const thicknessValue = document.createElement('span'); |
|
|
thicknessValue.className = 'thickness-value'; |
|
|
thicknessValue.textContent = thicknessSlider.value + 'px'; |
|
|
|
|
|
thicknessSlider.oninput = function() { |
|
|
const value = parseInt(thicknessSlider.value, 10); |
|
|
setStoredLineThickness(value); |
|
|
thicknessValue.textContent = value + 'px'; |
|
|
if (_cursorVisible) renderOverlay(); |
|
|
encodeToolStateToUrl(); |
|
|
}; |
|
|
|
|
|
thicknessRow.appendChild(thicknessSlider); |
|
|
thicknessRow.appendChild(thicknessValue); |
|
|
|
|
|
|
|
|
const fadeoutTitle = document.createElement('div'); |
|
|
fadeoutTitle.className = 'tools-section-title'; |
|
|
fadeoutTitle.textContent = 'fadeout time'; |
|
|
tools.appendChild(fadeoutTitle); |
|
|
|
|
|
const fadeoutRow = document.createElement('div'); |
|
|
fadeoutRow.className = 'thickness-row'; |
|
|
tools.appendChild(fadeoutRow); |
|
|
|
|
|
const fadeoutSlider = document.createElement('input'); |
|
|
fadeoutSlider.type = 'range'; |
|
|
fadeoutSlider.className = 'thickness-slider'; |
|
|
fadeoutSlider.min = '0'; |
|
|
fadeoutSlider.max = '30'; |
|
|
fadeoutSlider.value = getFadeoutTime(); |
|
|
|
|
|
const fadeoutValue = document.createElement('span'); |
|
|
fadeoutValue.className = 'thickness-value'; |
|
|
fadeoutValue.textContent = fadeoutSlider.value === '0' ? 'never' : fadeoutSlider.value + 's'; |
|
|
|
|
|
fadeoutSlider.oninput = function() { |
|
|
const value = parseInt(fadeoutSlider.value, 10); |
|
|
setStoredFadeoutTime(value); |
|
|
fadeoutValue.textContent = value === 0 ? 'never' : value + 's'; |
|
|
encodeToolStateToUrl(); |
|
|
}; |
|
|
|
|
|
fadeoutRow.appendChild(fadeoutSlider); |
|
|
fadeoutRow.appendChild(fadeoutValue); |
|
|
|
|
|
|
|
|
makeDraggable(tools, 'uvnote-tools-pos', title); |
|
|
|
|
|
return tools; |
|
|
} |
|
|
|
|
|
function initTools() { |
|
|
const widget = createToolsWidget(); |
|
|
document.body.appendChild(widget); |
|
|
} |
|
|
|
|
|
function teardownTools() { |
|
|
const w = document.querySelector('.tools-widget'); |
|
|
if (w && w.parentNode) w.parentNode.removeChild(w); |
|
|
} |
|
|
|
|
|
|
|
|
let _overlay = null; |
|
|
let _overlayCtx = null; |
|
|
let _overlayContainer = null; |
|
|
let _overlayMode = 'single'; |
|
|
let _overlayResizeHandler = null; |
|
|
let _overlayScrollHandler = null; |
|
|
let _drawing = null; |
|
|
let _shapes = []; |
|
|
let _fadeTimer = null; |
|
|
let _urlLoadedTool = false; |
|
|
let _isInitializing = true; |
|
|
let _initialCellStates = {}; |
|
|
|
|
|
function getOverlayStorageKey() { return 'uvnote-shapes'; } |
|
|
|
|
|
function loadShapes() { |
|
|
try { |
|
|
const raw = localStorage.getItem(getOverlayStorageKey()); |
|
|
_shapes = raw ? JSON.parse(raw) : []; |
|
|
} catch (_) { _shapes = []; } |
|
|
} |
|
|
|
|
|
function saveShapes() { |
|
|
try { |
|
|
localStorage.setItem(getOverlayStorageKey(), JSON.stringify(_shapes)); |
|
|
|
|
|
encodeToolStateToUrl(); |
|
|
} catch (_) {} |
|
|
} |
|
|
|
|
|
function updateShapesFade() { |
|
|
const now = Date.now(); |
|
|
let needsUpdate = false; |
|
|
|
|
|
for (let i = _shapes.length - 1; i >= 0; i--) { |
|
|
const shape = _shapes[i]; |
|
|
if (!shape.createdAt) continue; |
|
|
|
|
|
|
|
|
const shapesFadeoutSeconds = shape.fadeoutTime !== undefined ? shape.fadeoutTime : getFadeoutTime(); |
|
|
|
|
|
|
|
|
if (shapesFadeoutSeconds === 0) continue; |
|
|
|
|
|
const fadeStartTime = Math.max(0, (shapesFadeoutSeconds - 2) * 1000); |
|
|
const fadeEndTime = shapesFadeoutSeconds * 1000; |
|
|
const age = now - shape.createdAt; |
|
|
|
|
|
if (age >= fadeEndTime) { |
|
|
|
|
|
_shapes.splice(i, 1); |
|
|
needsUpdate = true; |
|
|
} else if (age >= fadeStartTime) { |
|
|
|
|
|
const fadeProgress = (age - fadeStartTime) / (fadeEndTime - fadeStartTime); |
|
|
const newOpacity = 1 - fadeProgress; |
|
|
if (Math.abs(shape.opacity - newOpacity) > 0.01) { |
|
|
shape.opacity = newOpacity; |
|
|
needsUpdate = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (needsUpdate) { |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
|
|
|
encodeToolStateToUrl(); |
|
|
} |
|
|
} |
|
|
|
|
|
function getContentContainer() { return window; } |
|
|
|
|
|
function updateOverlayModeAndContainer() { |
|
|
_overlayContainer = window; |
|
|
_overlayMode = 'single'; |
|
|
} |
|
|
|
|
|
function updateOverlayBounds() { |
|
|
if (!_overlay) return; |
|
|
if (_overlayContainer === window) { |
|
|
_overlay.style.position = 'fixed'; |
|
|
_overlay.style.left = '0px'; |
|
|
_overlay.style.top = '0px'; |
|
|
_overlay.width = window.innerWidth; |
|
|
_overlay.height = window.innerHeight; |
|
|
} else { |
|
|
const rect = _overlayContainer.getBoundingClientRect(); |
|
|
_overlay.style.position = 'fixed'; |
|
|
_overlay.style.left = rect.left + 'px'; |
|
|
_overlay.style.top = rect.top + 'px'; |
|
|
_overlay.width = Math.max(0, Math.floor(rect.width)); |
|
|
_overlay.height = Math.max(0, Math.floor(rect.height)); |
|
|
} |
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function containerScrollLeft() { |
|
|
return (_overlayContainer === window) ? (window.scrollX || 0) : (_overlayContainer.scrollLeft || 0); |
|
|
} |
|
|
function containerScrollTop() { |
|
|
return (_overlayContainer === window) ? (window.scrollY || 0) : (_overlayContainer.scrollTop || 0); |
|
|
} |
|
|
|
|
|
function toCanvasCoords(clientX, clientY) { |
|
|
const rect = _overlay.getBoundingClientRect(); |
|
|
return { x: clientX - rect.left, y: clientY - rect.top }; |
|
|
} |
|
|
|
|
|
function onPointerDown(e) { |
|
|
const tool = document.body.dataset.tool; |
|
|
if (tool === 'arrow') { |
|
|
startDrawArrow(e); |
|
|
} else if (tool === 'pen') { |
|
|
startDrawPen(e); |
|
|
} else if (tool === 'eraser') { |
|
|
eraseAt(e); |
|
|
} else if (tool === 'spotlight') { |
|
|
startDrawSpotlight(e); |
|
|
} |
|
|
} |
|
|
|
|
|
function onPointerMove(e) { |
|
|
|
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_cursorX = pt.x; |
|
|
_cursorY = pt.y; |
|
|
|
|
|
if (!_drawing) { |
|
|
|
|
|
if (_cursorVisible) { |
|
|
renderOverlay(); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
if (_drawing.type === 'pen') { |
|
|
moveDrawPen(e); |
|
|
} else if (_drawing.type === 'spotlight') { |
|
|
moveDrawSpotlight(e); |
|
|
} else { |
|
|
moveDrawArrow(e); |
|
|
} |
|
|
} |
|
|
|
|
|
function onPointerEnter(e) { |
|
|
_cursorVisible = document.body.dataset.tool !== 'none'; |
|
|
if (_cursorVisible) { |
|
|
renderOverlay(); |
|
|
} |
|
|
} |
|
|
|
|
|
function onPointerLeave(e) { |
|
|
_cursorVisible = false; |
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function onPointerUp(e) { |
|
|
if (!_drawing) return; |
|
|
if (_drawing.type === 'pen') { |
|
|
endDrawPen(); |
|
|
} else if (_drawing.type === 'spotlight') { |
|
|
endDrawSpotlight(); |
|
|
} else { |
|
|
endDrawArrow(); |
|
|
} |
|
|
} |
|
|
|
|
|
function startDrawArrow(e) { |
|
|
if (document.body.dataset.tool !== 'arrow') return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_drawing = { |
|
|
x1: pt.x + containerScrollLeft(), |
|
|
y1: pt.y + containerScrollTop(), |
|
|
x2: pt.x + containerScrollLeft(), |
|
|
y2: pt.y + containerScrollTop(), |
|
|
color: getArrowColor(), |
|
|
width: getLineThickness() |
|
|
}; |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function moveDrawArrow(e) { |
|
|
if (!_drawing) return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_drawing.x2 = pt.x + containerScrollLeft(); |
|
|
_drawing.y2 = pt.y + containerScrollTop(); |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function endDrawArrow() { |
|
|
if (!_drawing) return; |
|
|
_shapes.push({ |
|
|
type: 'arrow', |
|
|
..._drawing, |
|
|
createdAt: Date.now(), |
|
|
fadeoutTime: getFadeoutTime(), |
|
|
opacity: 1.0 |
|
|
}); |
|
|
_drawing = null; |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function startDrawPen(e) { |
|
|
if (document.body.dataset.tool !== 'pen') return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_drawing = { |
|
|
type: 'pen', |
|
|
points: [{ |
|
|
x: pt.x + containerScrollLeft(), |
|
|
y: pt.y + containerScrollTop() |
|
|
}], |
|
|
color: getArrowColor(), |
|
|
width: getLineThickness() |
|
|
}; |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function moveDrawPen(e) { |
|
|
if (!_drawing || _drawing.type !== 'pen') return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_drawing.points.push({ |
|
|
x: pt.x + containerScrollLeft(), |
|
|
y: pt.y + containerScrollTop() |
|
|
}); |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function endDrawPen() { |
|
|
if (!_drawing || _drawing.type !== 'pen') return; |
|
|
if (_drawing.points.length > 1) { |
|
|
_shapes.push({ |
|
|
..._drawing, |
|
|
createdAt: Date.now(), |
|
|
fadeoutTime: getFadeoutTime(), |
|
|
opacity: 1.0 |
|
|
}); |
|
|
} |
|
|
_drawing = null; |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function startDrawSpotlight(e) { |
|
|
if (document.body.dataset.tool !== 'spotlight') return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
_drawing = { |
|
|
type: 'spotlight', |
|
|
x: pt.x + containerScrollLeft(), |
|
|
y: pt.y + containerScrollTop(), |
|
|
radius: getLineThickness() * 20, |
|
|
color: getArrowColor() |
|
|
}; |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function moveDrawSpotlight(e) { |
|
|
if (!_drawing || _drawing.type !== 'spotlight') return; |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
const dx = pt.x + containerScrollLeft() - _drawing.x; |
|
|
const dy = pt.y + containerScrollTop() - _drawing.y; |
|
|
_drawing.radius = Math.max(20, Math.sqrt(dx * dx + dy * dy)); |
|
|
renderOverlay(); |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function endDrawSpotlight() { |
|
|
if (!_drawing || _drawing.type !== 'spotlight') return; |
|
|
_shapes.push({ |
|
|
..._drawing, |
|
|
createdAt: Date.now(), |
|
|
fadeoutTime: getFadeoutTime(), |
|
|
opacity: 1.0 |
|
|
}); |
|
|
_drawing = null; |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function distPointToSegment(px, py, x1, y1, x2, y2) { |
|
|
const dx = x2 - x1, dy = y2 - y1; |
|
|
if (dx === 0 && dy === 0) return Math.hypot(px - x1, py - y1); |
|
|
const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx*dx + dy*dy))); |
|
|
const cx = x1 + t * dx, cy = y1 + t * dy; |
|
|
return Math.hypot(px - cx, py - cy); |
|
|
} |
|
|
|
|
|
function eraseAt(e) { |
|
|
const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY); |
|
|
const x = pt.x + containerScrollLeft(); |
|
|
const y = pt.y + containerScrollTop(); |
|
|
const threshold = 10; |
|
|
for (let i = _shapes.length - 1; i >= 0; i--) { |
|
|
const s = _shapes[i]; |
|
|
if (s.type === 'arrow') { |
|
|
const d = distPointToSegment(x, y, s.x1, s.y1, s.x2, s.y2); |
|
|
if (d <= threshold) { |
|
|
_shapes.splice(i, 1); |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
break; |
|
|
} |
|
|
} else if (s.type === 'pen' && s.points) { |
|
|
|
|
|
let minDist = Infinity; |
|
|
for (let j = 1; j < s.points.length; j++) { |
|
|
const d = distPointToSegment(x, y, s.points[j-1].x, s.points[j-1].y, s.points[j].x, s.points[j].y); |
|
|
minDist = Math.min(minDist, d); |
|
|
} |
|
|
if (minDist <= threshold) { |
|
|
_shapes.splice(i, 1); |
|
|
saveShapes(); |
|
|
renderOverlay(); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
e.preventDefault(); |
|
|
} |
|
|
|
|
|
function drawArrow(ctx, x1, y1, x2, y2, color, width, opacity = 1.0) { |
|
|
|
|
|
const oldAlpha = ctx.globalAlpha; |
|
|
ctx.globalAlpha = opacity; |
|
|
|
|
|
ctx.strokeStyle = color; |
|
|
ctx.fillStyle = color; |
|
|
ctx.lineWidth = width; |
|
|
ctx.lineCap = 'round'; |
|
|
ctx.lineJoin = 'round'; |
|
|
|
|
|
|
|
|
const dx = x2 - x1; |
|
|
const dy = y2 - y1; |
|
|
const distance = Math.sqrt(dx * dx + dy * dy); |
|
|
|
|
|
if (distance < 5) { |
|
|
|
|
|
const defaultAngle = Math.PI / 4; |
|
|
const headLength = Math.min(15 + width * 1.5, 25); |
|
|
const headAngle = Math.PI / 6; |
|
|
|
|
|
|
|
|
const hx1 = x1 + headLength * Math.cos(defaultAngle - headAngle); |
|
|
const hy1 = y1 + headLength * Math.sin(defaultAngle - headAngle); |
|
|
const hx2 = x1 + headLength * Math.cos(defaultAngle + headAngle); |
|
|
const hy2 = y1 + headLength * Math.sin(defaultAngle + headAngle); |
|
|
|
|
|
|
|
|
ctx.beginPath(); |
|
|
ctx.moveTo(x1, y1); |
|
|
ctx.lineTo(hx1, hy1); |
|
|
ctx.lineTo(hx2, hy2); |
|
|
ctx.closePath(); |
|
|
ctx.fill(); |
|
|
} else { |
|
|
|
|
|
const angle = Math.atan2(y1 - y2, x1 - x2); |
|
|
const headLength = Math.min(15 + width * 1.5, 25); |
|
|
const headAngle = Math.PI / 6; |
|
|
|
|
|
|
|
|
const lineEndX = x1 - headLength * 0.8 * Math.cos(angle); |
|
|
const lineEndY = y1 - headLength * 0.8 * Math.sin(angle); |
|
|
|
|
|
|
|
|
ctx.beginPath(); |
|
|
ctx.moveTo(x2, y2); |
|
|
ctx.lineTo(lineEndX, lineEndY); |
|
|
ctx.stroke(); |
|
|
|
|
|
|
|
|
const hx1 = x1 - headLength * Math.cos(angle - headAngle); |
|
|
const hy1 = y1 - headLength * Math.sin(angle - headAngle); |
|
|
const hx2 = x1 - headLength * Math.cos(angle + headAngle); |
|
|
const hy2 = y1 - headLength * Math.sin(angle + headAngle); |
|
|
|
|
|
|
|
|
ctx.beginPath(); |
|
|
ctx.moveTo(x1, y1); |
|
|
ctx.lineTo(hx1, hy1); |
|
|
ctx.lineTo(hx2, hy2); |
|
|
ctx.closePath(); |
|
|
ctx.fill(); |
|
|
} |
|
|
|
|
|
|
|
|
ctx.globalAlpha = oldAlpha; |
|
|
} |
|
|
|
|
|
function drawPen(ctx, points, color, width, offX, offY, opacity = 1.0) { |
|
|
if (!points || points.length < 2) return; |
|
|
|
|
|
|
|
|
const oldAlpha = ctx.globalAlpha; |
|
|
ctx.globalAlpha = opacity; |
|
|
|
|
|
ctx.strokeStyle = color; |
|
|
ctx.lineWidth = width; |
|
|
ctx.lineCap = 'round'; |
|
|
ctx.lineJoin = 'round'; |
|
|
ctx.beginPath(); |
|
|
ctx.moveTo(points[0].x - offX, points[0].y - offY); |
|
|
for (let i = 1; i < points.length; i++) { |
|
|
ctx.lineTo(points[i].x - offX, points[i].y - offY); |
|
|
} |
|
|
ctx.stroke(); |
|
|
|
|
|
|
|
|
ctx.globalAlpha = oldAlpha; |
|
|
} |
|
|
|
|
|
function drawAllSpotlights(ctx, spotlights, offX, offY) { |
|
|
if (!spotlights || spotlights.length === 0) return; |
|
|
|
|
|
ctx.save(); |
|
|
|
|
|
|
|
|
const maxOpacity = Math.max(...spotlights.map(s => s.opacity || 1.0)); |
|
|
|
|
|
|
|
|
ctx.fillStyle = `rgba(0, 0, 0, ${0.7 * maxOpacity})`; |
|
|
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); |
|
|
|
|
|
|
|
|
ctx.globalCompositeOperation = 'destination-out'; |
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 1)'; |
|
|
for (const spotlight of spotlights) { |
|
|
ctx.beginPath(); |
|
|
ctx.arc(spotlight.x - offX, spotlight.y - offY, spotlight.radius, 0, 2 * Math.PI); |
|
|
ctx.fill(); |
|
|
} |
|
|
|
|
|
ctx.restore(); |
|
|
} |
|
|
|
|
|
function renderOverlay() { |
|
|
if (!_overlay || !_overlayCtx) return; |
|
|
_overlayCtx.clearRect(0, 0, _overlay.width, _overlay.height); |
|
|
const offX = containerScrollLeft(); |
|
|
const offY = containerScrollTop(); |
|
|
|
|
|
for (const s of _shapes) { |
|
|
const opacity = s.opacity !== undefined ? s.opacity : 1.0; |
|
|
if (s.type === 'arrow') { |
|
|
drawArrow(_overlayCtx, s.x1 - offX, s.y1 - offY, s.x2 - offX, s.y2 - offY, s.color || '#f00', s.width || 2, opacity); |
|
|
} else if (s.type === 'pen') { |
|
|
drawPen(_overlayCtx, s.points, s.color || '#f00', s.width || 2, offX, offY, opacity); |
|
|
} |
|
|
} |
|
|
|
|
|
if (_drawing) { |
|
|
if (_drawing.type === 'pen') { |
|
|
drawPen(_overlayCtx, _drawing.points, _drawing.color, _drawing.width, offX, offY); |
|
|
} else if (_drawing.type !== 'spotlight') { |
|
|
drawArrow(_overlayCtx, _drawing.x1 - offX, _drawing.y1 - offY, _drawing.x2 - offX, _drawing.y2 - offY, _drawing.color, _drawing.width); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const spotlights = []; |
|
|
|
|
|
|
|
|
for (const s of _shapes) { |
|
|
if (s.type === 'spotlight') { |
|
|
spotlights.push({ |
|
|
x: s.x, |
|
|
y: s.y, |
|
|
radius: s.radius, |
|
|
opacity: s.opacity !== undefined ? s.opacity : 1.0 |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_drawing && _drawing.type === 'spotlight') { |
|
|
spotlights.push({ |
|
|
x: _drawing.x, |
|
|
y: _drawing.y, |
|
|
radius: _drawing.radius, |
|
|
opacity: 1.0 |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
if (_cursorVisible && !_drawing) { |
|
|
const tool = document.body.dataset.tool; |
|
|
if (tool === 'spotlight') { |
|
|
const thickness = getLineThickness(); |
|
|
const radius = thickness * 20; |
|
|
const cursorWorldX = _cursorX + containerScrollLeft(); |
|
|
const cursorWorldY = _cursorY + containerScrollTop(); |
|
|
spotlights.push({ |
|
|
x: cursorWorldX, |
|
|
y: cursorWorldY, |
|
|
radius: radius, |
|
|
opacity: 0.8 |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
drawAllSpotlights(_overlayCtx, spotlights, offX, offY); |
|
|
|
|
|
|
|
|
if (_cursorVisible && !_drawing) { |
|
|
const tool = document.body.dataset.tool; |
|
|
const color = getArrowColor(); |
|
|
const thickness = getLineThickness(); |
|
|
|
|
|
if (tool !== 'spotlight') { |
|
|
_overlayCtx.save(); |
|
|
_overlayCtx.fillStyle = color; |
|
|
_overlayCtx.globalAlpha = 0.7; |
|
|
|
|
|
if (tool === 'eraser') { |
|
|
|
|
|
_overlayCtx.strokeStyle = color; |
|
|
_overlayCtx.lineWidth = 2; |
|
|
_overlayCtx.beginPath(); |
|
|
_overlayCtx.arc(_cursorX, _cursorY, 10, 0, 2 * Math.PI); |
|
|
_overlayCtx.stroke(); |
|
|
} else { |
|
|
|
|
|
_overlayCtx.beginPath(); |
|
|
_overlayCtx.arc(_cursorX, _cursorY, thickness / 2, 0, 2 * Math.PI); |
|
|
_overlayCtx.fill(); |
|
|
} |
|
|
|
|
|
_overlayCtx.restore(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
function setOverlayActive(active) { |
|
|
if (!_overlay) initOverlay(); |
|
|
_overlay.style.pointerEvents = active ? 'auto' : 'none'; |
|
|
_overlay.style.cursor = active ? 'none' : 'auto'; |
|
|
|
|
|
renderOverlay(); |
|
|
} |
|
|
|
|
|
function initOverlay() { |
|
|
if (_overlay) return; |
|
|
updateOverlayModeAndContainer(); |
|
|
_overlay = document.createElement('canvas'); |
|
|
_overlay.className = 'draw-overlay'; |
|
|
_overlayCtx = _overlay.getContext('2d'); |
|
|
document.body.appendChild(_overlay); |
|
|
updateOverlayBounds(); |
|
|
loadShapes(); |
|
|
renderOverlay(); |
|
|
|
|
|
|
|
|
_overlay.addEventListener('mousedown', onPointerDown); |
|
|
_overlay.addEventListener('mousemove', onPointerMove); |
|
|
_overlay.addEventListener('mouseenter', onPointerEnter); |
|
|
_overlay.addEventListener('mouseleave', onPointerLeave); |
|
|
document.addEventListener('mouseup', onPointerUp); |
|
|
_overlay.addEventListener('touchstart', onPointerDown, { passive: false }); |
|
|
_overlay.addEventListener('touchmove', onPointerMove, { passive: false }); |
|
|
document.addEventListener('touchend', onPointerUp); |
|
|
|
|
|
_overlayResizeHandler = () => updateOverlayBounds(); |
|
|
window.addEventListener('resize', _overlayResizeHandler); |
|
|
|
|
|
_overlayScrollHandler = () => renderOverlay(); |
|
|
window.addEventListener('scroll', _overlayScrollHandler); |
|
|
|
|
|
|
|
|
_fadeTimer = setInterval(updateShapesFade, 100); |
|
|
} |
|
|
|
|
|
function rebindOverlayContainer() { |
|
|
if (!_overlay) return; |
|
|
|
|
|
if (_overlayScrollHandler) { window.removeEventListener('scroll', _overlayScrollHandler); } |
|
|
updateOverlayModeAndContainer(); |
|
|
updateOverlayBounds(); |
|
|
loadShapes(); |
|
|
renderOverlay(); |
|
|
_overlayScrollHandler = () => renderOverlay(); |
|
|
window.addEventListener('scroll', _overlayScrollHandler); |
|
|
} |
|
|
|
|
|
function teardownOverlay() { |
|
|
if (!_overlay) return; |
|
|
_overlay.removeEventListener('mousedown', onPointerDown); |
|
|
_overlay.removeEventListener('mousemove', onPointerMove); |
|
|
_overlay.removeEventListener('mouseenter', onPointerEnter); |
|
|
_overlay.removeEventListener('mouseleave', onPointerLeave); |
|
|
document.removeEventListener('mouseup', onPointerUp); |
|
|
_overlay.removeEventListener('touchstart', onPointerDown); |
|
|
_overlay.removeEventListener('touchmove', onPointerMove); |
|
|
document.removeEventListener('touchend', onPointerUp); |
|
|
if (_overlayResizeHandler) window.removeEventListener('resize', _overlayResizeHandler); |
|
|
if (_overlayScrollHandler) { |
|
|
if (_overlayContainer === window) { |
|
|
window.removeEventListener('scroll', _overlayScrollHandler); |
|
|
} else if (_overlayContainer) { |
|
|
_overlayContainer.removeEventListener('scroll', _overlayScrollHandler); |
|
|
} |
|
|
} |
|
|
if (_fadeTimer) { |
|
|
clearInterval(_fadeTimer); |
|
|
_fadeTimer = null; |
|
|
} |
|
|
if (_overlay.parentNode) _overlay.parentNode.removeChild(_overlay); |
|
|
_overlay = null; _overlayCtx = null; _overlayContainer = null; _overlayResizeHandler = null; _overlayScrollHandler = null; _drawing = null; |
|
|
} |
|
|
|
|
|
function teardownFileExplorer() { |
|
|
const fe = document.querySelector('.file-explorer'); |
|
|
if (fe && fe.parentNode) fe.parentNode.removeChild(fe); |
|
|
} |
|
|
|
|
|
function escapeHtml(text) { |
|
|
const div = document.createElement('div'); |
|
|
div.textContent = text; |
|
|
return div.innerHTML; |
|
|
} |
|
|
|
|
|
function runCell(cellId){ |
|
|
const btn=document.querySelector('.run-btn[onclick*="'+cellId+'"]'); |
|
|
const output=document.getElementById('output-'+cellId); |
|
|
if(btn){btn.textContent='⏳ running...';btn.disabled=true;} |
|
|
if(output){output.classList.add('output-stale');} |
|
|
fetch('/run/'+cellId,{method:'POST'}).then(r=>r.json()).then(data=>{ |
|
|
if(output){ |
|
|
output.classList.remove('output-stale'); |
|
|
let html=''; |
|
|
if (data.stdout) { |
|
|
html += '<div class="cell-stdout"><pre class="stdout-text">' |
|
|
+ escapeHtml(data.stdout) |
|
|
+ '</pre></div>'; |
|
|
} |
|
|
|
|
|
console.log('UV Logs:', data); |
|
|
if(data.stderr) { |
|
|
|
|
|
const lines = data.stderr.split('\\n'); |
|
|
let uvLogs = []; |
|
|
let regularLogs = []; |
|
|
let inUvSection = true; |
|
|
|
|
|
for (const line of lines) { |
|
|
if (inUvSection) { |
|
|
uvLogs.push(line); |
|
|
if (line.startsWith('Installed ')) { |
|
|
inUvSection = false; |
|
|
} |
|
|
} else { |
|
|
regularLogs.push(line); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (inUvSection) { |
|
|
html+='<div class="cell-stderr">'+escapeHtml(data.stderr)+'</div>'; |
|
|
} else { |
|
|
const uvLogsStr = uvLogs.join('\\n'); |
|
|
const regularLogsStr = regularLogs.join('\\n').trim(); |
|
|
|
|
|
if (uvLogsStr) { |
|
|
html+='<div class="uv-install-logs">'; |
|
|
html+='<div class="uv-logs-header" onclick="toggleUvLogs(this)">▶ UV Install Logs</div>'; |
|
|
html+='<div class="uv-logs-content" style="display: none;">'+escapeHtml(uvLogsStr)+'</div>'; |
|
|
html+='</div>'; |
|
|
} |
|
|
if (regularLogsStr) { |
|
|
html+='<div class="cell-stderr">'+escapeHtml(regularLogsStr)+'</div>'; |
|
|
} |
|
|
} |
|
|
} |
|
|
output.innerHTML=html; |
|
|
} |
|
|
if(btn){btn.textContent='▶ run';btn.disabled=false;} |
|
|
}).catch(e=>{ |
|
|
console.error('Run failed:',e); |
|
|
if(output){output.classList.remove('output-stale');} |
|
|
if(btn){btn.textContent='▶ run';btn.disabled=false;} |
|
|
}); |
|
|
} |
|
|
|
|
|
function copyCell(cellId){ |
|
|
|
|
|
|
|
|
let codeElement = document.querySelector('#code-'+cellId+' .highlight pre'); |
|
|
if (!codeElement) { |
|
|
codeElement = document.querySelector('#code-'+cellId+' pre'); |
|
|
} |
|
|
if (!codeElement) { |
|
|
codeElement = document.querySelector('#code-'+cellId+' code'); |
|
|
} |
|
|
if (!codeElement) { |
|
|
|
|
|
codeElement = document.getElementById('code-'+cellId); |
|
|
} |
|
|
|
|
|
const btn = document.querySelector('.copy-btn[onclick*="'+cellId+'"]'); |
|
|
|
|
|
if (!codeElement) { |
|
|
console.error('Code element not found for cell:', cellId); |
|
|
return; |
|
|
} |
|
|
if (!btn) { |
|
|
console.error('Copy button not found for cell:', cellId); |
|
|
return; |
|
|
} |
|
|
|
|
|
const codeText = codeElement.textContent; |
|
|
|
|
|
if (navigator.clipboard && navigator.clipboard.writeText) { |
|
|
navigator.clipboard.writeText(codeText).then(function() { |
|
|
console.log('Clipboard copy successful'); |
|
|
btn.textContent = '✓ Copied!'; |
|
|
btn.classList.add('copied'); |
|
|
setTimeout(function() { |
|
|
btn.textContent = 'Copy'; |
|
|
btn.classList.remove('copied'); |
|
|
}, 2000); |
|
|
}).catch(function(err) { |
|
|
console.warn('Clipboard copy failed:', err); |
|
|
fallbackCopy(); |
|
|
}); |
|
|
} else { |
|
|
console.log('Using fallback copy method'); |
|
|
fallbackCopy(); |
|
|
} |
|
|
|
|
|
function fallbackCopy() { |
|
|
const textarea = document.createElement('textarea'); |
|
|
textarea.value = codeText; |
|
|
textarea.style.position = 'absolute'; |
|
|
textarea.style.left = '-9999px'; |
|
|
document.body.appendChild(textarea); |
|
|
textarea.select(); |
|
|
try { |
|
|
const success = document.execCommand('copy'); |
|
|
console.log('Fallback copy success:', success); |
|
|
btn.textContent = '✓ Copied!'; |
|
|
btn.classList.add('copied'); |
|
|
setTimeout(function() { |
|
|
btn.textContent = 'Copy'; |
|
|
btn.classList.remove('copied'); |
|
|
}, 2000); |
|
|
} catch (err) { |
|
|
console.error('Fallback copy failed:', err); |
|
|
btn.textContent = 'Copy failed'; |
|
|
setTimeout(function() { |
|
|
btn.textContent = 'Copy'; |
|
|
}, 2000); |
|
|
} |
|
|
document.body.removeChild(textarea); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
|
captureInitialCellStates(); |
|
|
|
|
|
updateThemeIcon(); |
|
|
updateUiMenu(); |
|
|
updateUiDebug(); |
|
|
const widgetsEnabled = (document.documentElement.getAttribute('data-widgets') || 'on') === 'on'; |
|
|
if (widgetsEnabled) { |
|
|
initMinimap(); |
|
|
initFileExplorer(); |
|
|
initTools(); |
|
|
initOverlay(); |
|
|
initStatusWidget(); |
|
|
initializeWidgetVisibility(); |
|
|
layoutWidgetsStackedBottomRight(); |
|
|
window.addEventListener('resize', layoutWidgetsStackedBottomRight); |
|
|
} |
|
|
|
|
|
|
|
|
applyLocationFromUrl(); |
|
|
updateStateIndicator(); |
|
|
|
|
|
|
|
|
const url = new URL(window.location.href); |
|
|
const encodedCellStates = url.searchParams.get('cells'); |
|
|
if (encodedCellStates) { |
|
|
console.log('Applying cell states from URL...'); |
|
|
const cellStates = decodeCellStatesFromUrl(encodedCellStates); |
|
|
|
|
|
|
|
|
requestAnimationFrame(() => { |
|
|
applyCellStatesFromUrl(cellStates); |
|
|
|
|
|
|
|
|
if (typeof _isInitializing !== 'undefined') { |
|
|
_isInitializing = false; |
|
|
} |
|
|
}); |
|
|
} else { |
|
|
|
|
|
if (typeof _isInitializing !== 'undefined') { |
|
|
requestAnimationFrame(() => { |
|
|
_isInitializing = false; |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('mousedown', onLineNumberMouseDown); |
|
|
document.addEventListener('mousemove', onDocMouseMove); |
|
|
document.addEventListener('mouseup', onDocMouseUp); |
|
|
|
|
|
|
|
|
document.addEventListener('keydown', function(e) { |
|
|
if (e.key === 'Escape' || e.keyCode === 27) { |
|
|
const currentTool = document.body.dataset.tool; |
|
|
if (currentTool && currentTool !== 'none') { |
|
|
|
|
|
window.setActiveTool('none'); |
|
|
} |
|
|
|
|
|
clearSelection(true); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
function updateStateIndicator() { |
|
|
try { |
|
|
const el = document.getElementById('status-widget'); |
|
|
if (!el) return; |
|
|
const tool = document.body.dataset.tool || 'none'; |
|
|
if (tool && tool !== 'none') { |
|
|
el.textContent = `tool: ${tool} — Esc`; |
|
|
return; |
|
|
} |
|
|
if (_selection) { |
|
|
const t = _selection.a === _selection.b ? `L${_selection.a}` : `L${_selection.a}-${_selection.b}`; |
|
|
el.textContent = `selected: ${t} — Esc`; |
|
|
return; |
|
|
} |
|
|
el.textContent = 'ready — Esc'; |
|
|
} catch (_) {} |
|
|
} |
|
|
</script> |
|
|
</head> |
|
|
|
|
|
|
|
|
<body> |
|
|
<div class="controls"> |
|
|
<div class="controls-buttons"> |
|
|
|
|
|
<a href="index.html" class="back-button">← back</a> |
|
|
|
|
|
<div class="theme-toggle" onclick="toggleTheme()">light</div> |
|
|
<div class="reset-toggle" onclick="resetLayout()">reset</div> |
|
|
<div class="menu-button" onclick="toggleMenu()"> |
|
|
menu ▼ |
|
|
<div class="menu-dropdown"> |
|
|
<div class="menu-item" onclick="setUiTheme('default')"> |
|
|
<span class="menu-checkbox" id="checkbox-ui-default">☑</span> Theme: default |
|
|
</div> |
|
|
<div class="menu-item" onclick="setUiTheme('none')"> |
|
|
<span class="menu-checkbox" id="checkbox-ui-none">☐</span> Theme: none |
|
|
</div> |
|
|
<div class="menu-item" onclick="setUiTheme('monocolor')"> |
|
|
<span class="menu-checkbox" id="checkbox-ui-monocolor">☐</span> Theme: monocolor |
|
|
</div> |
|
|
<div class="menu-item" onclick="toggleWidget('tools')"> |
|
|
<span class="menu-checkbox" id="checkbox-tools">☐</span> Tools |
|
|
</div> |
|
|
<div class="menu-item" onclick="toggleWidget('file-explorer')"> |
|
|
<span class="menu-checkbox" id="checkbox-file-explorer">☐</span> File Explorer |
|
|
</div> |
|
|
<div class="menu-item" onclick="toggleWidget('minimap')"> |
|
|
<span class="menu-checkbox" id="checkbox-minimap">☐</span> Table of Contents |
|
|
</div> |
|
|
<div class="menu-item" onclick="toggleWidget('status')"> |
|
|
<span class="menu-checkbox" id="checkbox-status">☑</span> Status Indicator |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<div class="system-info"> |
|
|
<div class="system-info-header">Generated on:</div> |
|
|
<div class="system-info-content"> |
|
|
Linux x86_64 | Linux-5.10.244-240.970.amzn2.x86_64-x86_64-with-glibc2.35 |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<div class="main-content"> |
|
|
<h1>HF Kernels - Rotary Position Embeddings</h1> |
|
|
<h2>GPU Info</h2> |
|
|
<div class="cell" id="cell-nv"> |
|
|
<div class="cell-header"> |
|
|
<span class="collapse-indicators"> |
|
|
<span onclick="toggleCode('nv')" style="cursor: pointer;">▼ code</span> |
|
|
<span onclick="toggleOutput('nv')" style="cursor: pointer;">▼ output</span> |
|
|
<span id="uv-indicator-nv" style="cursor: default; opacity: 0.3;">▶ uv-logs</span> |
|
|
</span> | |
|
|
Cell: nv | 0.21s |
|
|
| <button class="run-btn" onclick="runCell('nv')">▶ run</button> |
|
|
<button class="copy-btn" onclick="copyCell('nv')">Copy</button> |
|
|
<a href="cells/nv.py" target="_blank" class="raw-btn">Raw</a> |
|
|
<a href="https://github.com/huggingface/kernels-uvnotes/blob/main/rotary/impls/hf_kernels_rotary.md" target="_blank" class="github-btn">GitHub</a> |
|
|
</div> |
|
|
<div id="code-nv" class="cell-code" data-lines="2"> |
|
|
<div class="code-wrap"> |
|
|
<div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">subprocess</span> |
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">"nvidia-smi"</span><span class="p">],</span> <span class="n">capture_output</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span> |
|
|
</pre></div> |
|
|
|
|
|
<div class="code-line-highlight" id="line-highlight-nv"></div> |
|
|
</div> |
|
|
</div> |
|
|
<div id="output-nv" class="cell-output"> |
|
|
<div class="cell-stdout"><pre class="stdout-text">Thu Oct 30 15:52:23 2025 |
|
|
+-----------------------------------------------------------------------------------------+ |
|
|
| NVIDIA-SMI 570.195.03 Driver Version: 570.195.03 CUDA Version: 12.8 | |
|
|
|-----------------------------------------+------------------------+----------------------+ |
|
|
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | |
|
|
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | |
|
|
| | | MIG M. | |
|
|
|=========================================+========================+======================| |
|
|
| 0 NVIDIA L40S On | 00000000:4D:00.0 Off | 0 | |
|
|
| N/A 30C P0 76W / 350W | 0MiB / 46068MiB | 11% Default | |
|
|
| | | N/A | |
|
|
+-----------------------------------------+------------------------+----------------------+ |
|
|
|
|
|
+-----------------------------------------------------------------------------------------+ |
|
|
| Processes: | |
|
|
| GPU GI CI PID Type Process name GPU Memory | |
|
|
| ID ID Usage | |
|
|
|=========================================================================================| |
|
|
| No running processes found | |
|
|
+-----------------------------------------------------------------------------------------+ |
|
|
|
|
|
</pre></div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<h2>Rotary Embeddings Benchmark</h2> |
|
|
<div class="cell" id="cell-benchmark"> |
|
|
<div class="cell-header"> |
|
|
<span class="collapse-indicators"> |
|
|
<span onclick="toggleCode('benchmark')" style="cursor: pointer;">▼ code</span> |
|
|
<span onclick="toggleOutput('benchmark')" style="cursor: pointer;">▼ output</span> |
|
|
<span id="uv-indicator-benchmark" onclick="toggleUvLogsFromHeader('benchmark')" style="cursor: pointer;">▶ uv-logs</span> |
|
|
</span> | |
|
|
Cell: benchmark | 8.39s |
|
|
| <button class="run-btn" onclick="runCell('benchmark')">▶ run</button> |
|
|
<button class="copy-btn" onclick="copyCell('benchmark')">Copy</button> |
|
|
<a href="cells/benchmark.py" target="_blank" class="raw-btn">Raw</a> |
|
|
<a href="https://github.com/huggingface/kernels-uvnotes/blob/main/rotary/impls/hf_kernels_rotary.md" target="_blank" class="github-btn">GitHub</a> |
|
|
</div> |
|
|
<div id="code-benchmark" class="cell-code" data-lines="48"> |
|
|
<div class="code-wrap"> |
|
|
<div class="highlight"><pre><span></span><span class="c1"># /// script</span> |
|
|
<span class="c1"># requires-python = ">=3.10"</span> |
|
|
<span class="c1"># dependencies = [</span> |
|
|
<span class="c1"># "numpy",</span> |
|
|
<span class="c1"># "torch==2.8.0",</span> |
|
|
<span class="c1"># "kernels-benchmark-tools",</span> |
|
|
<span class="c1"># "kernels",</span> |
|
|
<span class="c1"># ]</span> |
|
|
<span class="c1">#</span> |
|
|
<span class="c1"># [tool.uv.sources]</span> |
|
|
<span class="c1"># kernels-benchmark-tools = { path = "../../../../../tools", editable = true }</span> |
|
|
<span class="c1"># ///</span> |
|
|
<span class="kn">import</span><span class="w"> </span><span class="nn">torch</span> |
|
|
<span class="kn">import</span><span class="w"> </span><span class="nn">sys</span> |
|
|
<span class="kn">from</span><span class="w"> </span><span class="nn">kernels_benchmark_tools</span><span class="w"> </span><span class="kn">import</span> <span class="n">KernelTypeEnum</span><span class="p">,</span> <span class="n">run_benchmark</span> |
|
|
<span class="kn">from</span><span class="w"> </span><span class="nn">kernels</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_kernel</span> |
|
|
|
|
|
<span class="c1"># Load the rotary kernel</span> |
|
|
<span class="n">rotary</span> <span class="o">=</span> <span class="n">get_kernel</span><span class="p">(</span><span class="s2">"kernels-community/rotary"</span><span class="p">)</span> |
|
|
|
|
|
|
|
|
<span class="k">def</span><span class="w"> </span><span class="nf">hf_kernels_rotary</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">conj</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span> |
|
|
<span class="n">rotary_dim</span> <span class="o">=</span> <span class="n">cos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> |
|
|
|
|
|
<span class="c1"># Clone to avoid modifying inputs</span> |
|
|
<span class="n">q_out</span> <span class="o">=</span> <span class="n">query</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span> |
|
|
<span class="n">k_out</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span> |
|
|
|
|
|
<span class="c1"># Apply rotation to query</span> |
|
|
<span class="n">q1</span> <span class="o">=</span> <span class="n">q_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="p">:</span><span class="n">rotary_dim</span><span class="p">]</span> |
|
|
<span class="n">q2</span> <span class="o">=</span> <span class="n">q_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="n">rotary_dim</span> <span class="p">:</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">rotary_dim</span><span class="p">]</span> |
|
|
<span class="n">rotary</span><span class="o">.</span><span class="n">apply_rotary</span><span class="p">(</span><span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">conj</span><span class="p">)</span> |
|
|
|
|
|
<span class="c1"># Apply rotation to key</span> |
|
|
<span class="n">k1</span> <span class="o">=</span> <span class="n">k_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="p">:</span><span class="n">rotary_dim</span><span class="p">]</span> |
|
|
<span class="n">k2</span> <span class="o">=</span> <span class="n">k_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="n">rotary_dim</span> <span class="p">:</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">rotary_dim</span><span class="p">]</span> |
|
|
<span class="n">rotary</span><span class="o">.</span><span class="n">apply_rotary</span><span class="p">(</span><span class="n">k1</span><span class="p">,</span> <span class="n">k2</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">k1</span><span class="p">,</span> <span class="n">k2</span><span class="p">,</span> <span class="n">conj</span><span class="p">)</span> |
|
|
|
|
|
<span class="k">return</span> <span class="n">q_out</span><span class="p">,</span> <span class="n">k_out</span> |
|
|
|
|
|
|
|
|
<span class="n">run_benchmark</span><span class="p">(</span> |
|
|
<span class="n">kernel_type</span><span class="o">=</span><span class="n">KernelTypeEnum</span><span class="o">.</span><span class="n">ROTARY</span><span class="p">,</span> |
|
|
<span class="n">impl_name</span><span class="o">=</span><span class="s2">"hf_kernels_rotary"</span><span class="p">,</span> |
|
|
<span class="n">impl_tags</span><span class="o">=</span><span class="p">{</span><span class="s2">"family"</span><span class="p">:</span> <span class="s2">"hf-kernels"</span><span class="p">,</span> <span class="s2">"backend"</span><span class="p">:</span> <span class="s2">"cuda"</span><span class="p">},</span> |
|
|
<span class="n">impl_func</span><span class="o">=</span><span class="n">hf_kernels_rotary</span><span class="p">,</span> |
|
|
<span class="n">dtype</span><span class="o">=</span><span class="s2">"float32"</span><span class="p">,</span> |
|
|
<span class="p">)</span> |
|
|
</pre></div> |
|
|
|
|
|
<div class="code-line-highlight" id="line-highlight-benchmark"></div> |
|
|
</div> |
|
|
</div> |
|
|
<div id="output-benchmark" class="cell-output"> |
|
|
<div class="cell-stdout"><pre class="stdout-text">Running rotary benchmark on cuda with 24 workloads. |
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 437.951us 1890.33% 437.951us 437.951us 1 |
|
|
hf_kernels_rotary 12.22% 256.435us 99.67% 2.092ms 2.092ms 0.000us 0.00% 24.448us 24.448us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.70% 56.773us 5.22% 109.533us 18.255us 16.128us 69.61% 16.128us 2.688us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 16.128us 69.61% 16.128us 2.688us 6 |
|
|
aten::clone 2.06% 43.312us 79.20% 1.663ms 277.110us 0.000us 0.00% 8.320us 1.387us 6 |
|
|
aten::copy_ 2.16% 45.349us 74.16% 1.557ms 259.469us 7.040us 30.39% 8.320us 1.387us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.040us 30.39% 7.040us 1.173us 6 |
|
|
Activity Buffer Request 68.35% 1.435ms 68.35% 1.435ms 1.435ms 1.280us 5.52% 1.280us 1.280us 1 |
|
|
aten::empty_strided 2.98% 62.532us 2.98% 62.532us 10.422us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 3.65% 76.672us 3.65% 76.672us 12.779us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 2.33% 48.990us 3.04% 63.719us 5.310us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.70% 14.729us 0.70% 14.729us 1.227us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.51% 52.760us 2.51% 52.760us 8.793us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.33% 6.840us 0.33% 6.840us 6.840us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.099ms |
|
|
Self CUDA time total: 23.168us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 347.903us 1449.48% 347.903us 347.903us 1 |
|
|
hf_kernels_rotary 8.54% 161.773us 99.74% 1.890ms 1.890ms 0.000us 0.00% 25.314us 25.314us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.18% 41.260us 4.61% 87.431us 14.572us 16.194us 67.47% 16.194us 2.699us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 16.194us 67.47% 16.194us 2.699us 6 |
|
|
aten::clone 1.21% 22.941us 84.30% 1.597ms 266.206us 0.000us 0.00% 9.120us 1.520us 6 |
|
|
aten::copy_ 2.05% 38.809us 81.33% 1.541ms 256.844us 7.808us 32.53% 9.120us 1.520us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.808us 32.53% 7.808us 1.301us 6 |
|
|
Activity Buffer Request 76.43% 1.448ms 76.43% 1.448ms 1.448ms 1.312us 5.47% 1.312us 1.312us 1 |
|
|
aten::empty_strided 1.75% 33.230us 1.75% 33.230us 5.538us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 2.85% 54.092us 2.85% 54.092us 9.015us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.79% 33.972us 2.29% 43.382us 3.615us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.50% 9.410us 0.50% 9.410us 0.784us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.44% 46.171us 2.44% 46.171us 7.695us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.26% 4.990us 0.26% 4.990us 4.990us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 1.895ms |
|
|
Self CUDA time total: 24.002us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 344.799us 1421.56% 344.799us 344.799us 1 |
|
|
hf_kernels_rotary 8.36% 157.652us 99.72% 1.880ms 1.880ms 0.000us 0.00% 25.535us 25.535us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.20% 41.393us 4.58% 86.433us 14.405us 16.479us 67.94% 16.479us 2.747us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 16.479us 67.94% 16.479us 2.747us 6 |
|
|
aten::clone 1.19% 22.449us 84.54% 1.594ms 265.688us 0.000us 0.00% 9.056us 1.509us 6 |
|
|
aten::copy_ 1.98% 37.391us 81.51% 1.537ms 256.168us 7.776us 32.06% 9.056us 1.509us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.776us 32.06% 7.776us 1.296us 6 |
|
|
Activity Buffer Request 76.55% 1.443ms 76.55% 1.443ms 1.443ms 1.280us 5.28% 1.280us 1.280us 1 |
|
|
aten::empty_strided 1.84% 34.673us 1.84% 34.673us 5.779us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 2.98% 56.200us 2.98% 56.200us 9.367us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.75% 32.991us 2.23% 42.120us 3.510us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.48% 9.129us 0.48% 9.129us 0.761us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.39% 45.040us 2.39% 45.040us 7.507us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.28% 5.250us 0.28% 5.250us 5.250us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 1.886ms |
|
|
Self CUDA time total: 24.255us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 344.221us 1225.16% 344.221us 344.221us 1 |
|
|
hf_kernels_rotary 7.87% 162.633us 99.75% 2.060ms 2.060ms 0.000us 0.00% 29.824us 29.824us 1 |
|
|
_rotary_dba7d1e::apply_rotary 1.96% 40.432us 4.15% 85.752us 14.292us 17.728us 63.10% 17.728us 2.955us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 17.728us 63.10% 17.728us 2.955us 6 |
|
|
aten::clone 1.05% 21.772us 85.59% 1.768ms 294.674us 0.000us 0.00% 12.096us 2.016us 6 |
|
|
aten::copy_ 1.75% 36.131us 82.94% 1.713ms 285.533us 10.368us 36.90% 12.096us 2.016us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 10.368us 36.90% 10.368us 1.728us 6 |
|
|
Activity Buffer Request 69.12% 1.428ms 69.12% 1.428ms 1.428ms 1.728us 6.15% 1.728us 1.728us 1 |
|
|
aten::empty_strided 1.60% 33.071us 1.60% 33.071us 5.512us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 12.07% 249.233us 12.07% 249.233us 41.539us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.63% 33.600us 2.13% 43.960us 3.663us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.50% 10.360us 0.50% 10.360us 0.863us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.19% 45.320us 2.19% 45.320us 7.553us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.25% 5.220us 0.25% 5.220us 5.220us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.066ms |
|
|
Self CUDA time total: 28.096us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 345.758us 1419.83% 345.758us 345.758us 1 |
|
|
hf_kernels_rotary 7.72% 159.843us 99.76% 2.064ms 2.064ms 0.000us 0.00% 25.664us 25.664us 1 |
|
|
_rotary_dba7d1e::apply_rotary 1.98% 40.892us 4.09% 84.633us 14.106us 16.544us 67.94% 16.544us 2.757us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 16.544us 67.94% 16.544us 2.757us 6 |
|
|
aten::clone 1.14% 23.531us 85.80% 1.775ms 295.882us 0.000us 0.00% 9.120us 1.520us 6 |
|
|
aten::copy_ 1.76% 36.431us 83.03% 1.718ms 286.337us 7.808us 32.06% 9.120us 1.520us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.808us 32.06% 7.808us 1.301us 6 |
|
|
Activity Buffer Request 69.77% 1.444ms 69.77% 1.444ms 1.444ms 1.312us 5.39% 1.312us 1.312us 1 |
|
|
aten::empty_strided 1.63% 33.740us 1.63% 33.740us 5.623us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 11.50% 237.923us 11.50% 237.923us 39.654us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.68% 34.750us 2.15% 44.540us 3.712us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.47% 9.790us 0.47% 9.790us 0.816us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.11% 43.741us 2.11% 43.741us 7.290us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.24% 4.890us 0.24% 4.890us 4.890us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.069ms |
|
|
Self CUDA time total: 24.352us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 375.259us 1340.31% 375.259us 375.259us 1 |
|
|
hf_kernels_rotary 7.92% 165.422us 99.76% 2.085ms 2.085ms 0.000us 0.00% 29.790us 29.790us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.01% 42.019us 4.24% 88.630us 14.772us 17.566us 62.74% 17.566us 2.928us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 17.566us 62.74% 17.566us 2.928us 6 |
|
|
aten::clone 1.13% 23.560us 85.51% 1.787ms 297.810us 0.000us 0.00% 12.224us 2.037us 6 |
|
|
aten::copy_ 1.86% 38.872us 82.84% 1.731ms 288.508us 10.432us 37.26% 12.224us 2.037us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 10.432us 37.26% 10.432us 1.739us 6 |
|
|
Activity Buffer Request 68.75% 1.437ms 68.75% 1.437ms 1.437ms 1.792us 6.40% 1.792us 1.792us 1 |
|
|
aten::empty_strided 1.54% 32.252us 1.54% 32.252us 5.375us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 12.23% 255.474us 12.23% 255.474us 42.579us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.66% 34.672us 2.10% 43.902us 3.658us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.44% 9.230us 0.44% 9.230us 0.769us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.23% 46.611us 2.23% 46.611us 7.769us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.24% 4.930us 0.24% 4.930us 4.930us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.090ms |
|
|
Self CUDA time total: 27.998us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 346.557us 858.83% 346.557us 346.557us 1 |
|
|
hf_kernels_rotary 7.80% 160.642us 99.76% 2.055ms 2.055ms 0.000us 0.00% 43.200us 43.200us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.00% 41.122us 4.23% 87.123us 14.521us 23.424us 58.05% 23.424us 3.904us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 23.424us 58.05% 23.424us 3.904us 6 |
|
|
aten::clone 1.11% 22.900us 85.69% 1.765ms 294.130us 0.000us 0.00% 19.776us 3.296us 6 |
|
|
aten::copy_ 1.80% 37.091us 82.95% 1.708ms 284.737us 16.928us 41.95% 19.776us 3.296us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 16.928us 41.95% 16.928us 2.821us 6 |
|
|
Activity Buffer Request 70.02% 1.442ms 70.02% 1.442ms 1.442ms 2.848us 7.06% 2.848us 2.848us 1 |
|
|
aten::empty_strided 1.62% 33.460us 1.62% 33.460us 5.577us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 11.13% 229.194us 11.13% 229.194us 38.199us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.60% 33.049us 2.04% 42.051us 3.504us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.44% 9.002us 0.44% 9.002us 0.750us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.23% 46.001us 2.23% 46.001us 7.667us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.24% 4.950us 0.24% 4.950us 4.950us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.060ms |
|
|
Self CUDA time total: 40.352us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 349.374us 446.91% 349.374us 349.374us 1 |
|
|
hf_kernels_rotary 8.00% 163.391us 99.76% 2.039ms 2.039ms 0.000us 0.00% 90.720us 90.720us 1 |
|
|
aten::clone 1.09% 22.181us 85.39% 1.745ms 290.833us 0.000us 0.00% 52.224us 8.704us 6 |
|
|
aten::copy_ 1.85% 37.761us 82.69% 1.690ms 281.650us 39.680us 50.76% 52.224us 8.704us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 39.680us 50.76% 39.680us 6.613us 6 |
|
|
_rotary_dba7d1e::apply_rotary 2.10% 42.834us 4.25% 86.883us 14.481us 38.496us 49.24% 38.496us 6.416us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 38.496us 49.24% 38.496us 6.416us 6 |
|
|
Activity Buffer Request 69.78% 1.426ms 69.78% 1.426ms 1.426ms 12.544us 16.05% 12.544us 12.544us 1 |
|
|
aten::empty_strided 1.61% 32.920us 1.61% 32.920us 5.487us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 11.06% 226.094us 11.06% 226.094us 37.682us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.62% 33.171us 2.12% 43.331us 3.611us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.50% 10.160us 0.50% 10.160us 0.847us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.16% 44.049us 2.16% 44.049us 7.341us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.24% 4.951us 0.24% 4.951us 4.951us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.044ms |
|
|
Self CUDA time total: 78.176us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 333.879us 824.19% 333.879us 333.879us 1 |
|
|
hf_kernels_rotary 18.73% 154.483us 99.41% 820.134us 820.134us 0.000us 0.00% 43.327us 43.327us 1 |
|
|
_rotary_dba7d1e::apply_rotary 4.89% 40.361us 10.02% 82.702us 13.784us 23.422us 57.82% 23.422us 3.904us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 23.422us 57.82% 23.422us 3.904us 6 |
|
|
aten::clone 2.46% 20.259us 65.56% 540.868us 90.145us 0.000us 0.00% 19.905us 3.317us 6 |
|
|
aten::copy_ 4.70% 38.811us 59.16% 488.099us 81.350us 17.088us 42.18% 19.905us 3.317us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 17.088us 42.18% 17.088us 2.848us 6 |
|
|
Activity Buffer Request 27.39% 225.944us 27.39% 225.944us 225.944us 2.817us 6.95% 2.817us 2.817us 1 |
|
|
aten::empty_strided 3.94% 32.510us 3.94% 32.510us 5.418us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 27.07% 223.344us 27.07% 223.344us 37.224us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.93% 32.394us 5.10% 42.081us 3.507us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.17% 9.687us 1.17% 9.687us 0.807us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.13% 42.341us 5.13% 42.341us 7.057us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.59% 4.860us 0.59% 4.860us 4.860us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 824.994us |
|
|
Self CUDA time total: 40.510us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 338.778us 450.33% 338.778us 338.778us 1 |
|
|
hf_kernels_rotary 18.40% 151.937us 99.39% 820.824us 820.824us 0.000us 0.00% 85.723us 85.723us 1 |
|
|
aten::clone 2.47% 20.430us 65.45% 540.538us 90.090us 0.000us 0.00% 47.293us 7.882us 6 |
|
|
aten::copy_ 4.41% 36.400us 59.08% 487.928us 81.321us 36.798us 48.92% 47.293us 7.882us 6 |
|
|
_rotary_dba7d1e::apply_rotary 4.89% 40.390us 10.51% 86.760us 14.460us 38.430us 51.08% 38.430us 6.405us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 38.430us 51.08% 38.430us 6.405us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 36.798us 48.92% 36.798us 6.133us 6 |
|
|
Activity Buffer Request 27.74% 229.134us 27.74% 229.134us 229.134us 10.495us 13.95% 10.495us 10.495us 1 |
|
|
aten::empty_strided 3.90% 32.180us 3.90% 32.180us 5.363us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 26.93% 222.394us 26.93% 222.394us 37.066us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.90% 32.180us 5.04% 41.589us 3.466us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.14% 9.409us 1.14% 9.409us 0.784us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.61% 46.370us 5.61% 46.370us 7.728us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.61% 5.040us 0.61% 5.040us 5.040us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 825.864us |
|
|
Self CUDA time total: 75.228us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 338.815us 244.98% 338.815us 338.815us 1 |
|
|
hf_kernels_rotary 17.96% 152.299us 99.45% 843.474us 843.474us 0.000us 0.00% 161.823us 161.823us 1 |
|
|
aten::clone 2.40% 20.339us 66.32% 562.460us 93.743us 0.000us 0.00% 102.176us 17.029us 6 |
|
|
aten::copy_ 4.27% 36.251us 60.21% 510.629us 85.105us 78.656us 56.87% 102.176us 17.029us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 78.656us 56.87% 78.656us 13.109us 6 |
|
|
_rotary_dba7d1e::apply_rotary 4.86% 41.202us 10.23% 86.763us 14.460us 59.647us 43.13% 59.647us 9.941us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 59.647us 43.13% 59.647us 9.941us 6 |
|
|
Activity Buffer Request 30.37% 257.584us 30.37% 257.584us 257.584us 23.520us 17.01% 23.520us 23.520us 1 |
|
|
aten::empty_strided 3.71% 31.492us 3.71% 31.492us 5.249us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 25.56% 216.794us 25.56% 216.794us 36.132us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.89% 32.951us 4.95% 41.952us 3.496us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.06% 9.001us 1.06% 9.001us 0.750us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.37% 45.561us 5.37% 45.561us 7.594us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.55% 4.640us 0.55% 4.640us 4.640us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 848.114us |
|
|
Self CUDA time total: 138.303us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 12.84% 152.812us 71.89% 855.575us 855.575us 0.000us 0.00% 769.625us 769.625us 1 |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 710.234us 101.16% 710.234us 710.234us 1 |
|
|
aten::clone 1.76% 21.001us 48.07% 572.021us 95.337us 0.000us 0.00% 572.987us 95.498us 6 |
|
|
aten::copy_ 3.15% 37.471us 43.65% 519.450us 86.575us 505.436us 71.99% 572.987us 95.498us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 505.436us 71.99% 505.436us 84.239us 6 |
|
|
_rotary_dba7d1e::apply_rotary 3.42% 40.722us 7.33% 87.262us 14.544us 196.638us 28.01% 196.638us 32.773us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 196.638us 28.01% 196.638us 32.773us 6 |
|
|
Activity Buffer Request 21.90% 260.665us 21.90% 260.665us 260.665us 67.551us 9.62% 67.551us 67.551us 1 |
|
|
aten::empty_strided 2.65% 31.570us 2.65% 31.570us 5.262us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 18.60% 221.314us 18.60% 221.314us 36.886us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 2.82% 33.601us 3.65% 43.480us 3.623us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.83% 9.879us 0.83% 9.879us 0.823us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 3.91% 46.540us 3.91% 46.540us 7.757us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 28.11% 334.485us 28.11% 334.485us 334.485us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 1.190ms |
|
|
Self CUDA time total: 702.074us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 340.957us 1280.69% 340.957us 340.957us 1 |
|
|
hf_kernels_rotary 17.85% 154.192us 99.45% 858.915us 858.915us 0.000us 0.00% 27.935us 27.935us 1 |
|
|
_rotary_dba7d1e::apply_rotary 4.82% 41.593us 10.09% 87.173us 14.529us 18.719us 70.31% 18.719us 3.120us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 18.719us 70.31% 18.719us 3.120us 6 |
|
|
aten::clone 2.51% 21.701us 66.67% 575.779us 95.963us 0.000us 0.00% 9.216us 1.536us 6 |
|
|
aten::copy_ 4.05% 34.978us 60.54% 522.828us 87.138us 7.904us 29.69% 9.216us 1.536us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.904us 29.69% 7.904us 1.317us 6 |
|
|
Activity Buffer Request 30.68% 265.004us 30.68% 265.004us 265.004us 1.312us 4.93% 1.312us 1.312us 1 |
|
|
aten::empty_strided 3.62% 31.250us 3.62% 31.250us 5.208us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 25.80% 222.846us 25.80% 222.846us 37.141us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.77% 32.522us 4.84% 41.771us 3.481us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.07% 9.249us 1.07% 9.249us 0.771us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.28% 45.580us 5.28% 45.580us 7.597us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.55% 4.760us 0.55% 4.760us 4.760us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 863.675us |
|
|
Self CUDA time total: 26.623us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 331.838us 1247.93% 331.838us 331.838us 1 |
|
|
hf_kernels_rotary 18.40% 149.763us 99.33% 808.424us 808.424us 0.000us 0.00% 27.871us 27.871us 1 |
|
|
_rotary_dba7d1e::apply_rotary 5.12% 41.640us 10.68% 86.941us 14.490us 18.879us 71.00% 18.879us 3.147us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 18.879us 71.00% 18.879us 3.147us 6 |
|
|
aten::clone 2.56% 20.830us 65.24% 531.000us 88.500us 0.000us 0.00% 8.992us 1.499us 6 |
|
|
aten::copy_ 4.49% 36.550us 58.98% 480.009us 80.001us 7.712us 29.00% 8.992us 1.499us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 7.712us 29.00% 7.712us 1.285us 6 |
|
|
Activity Buffer Request 28.18% 229.375us 28.18% 229.375us 229.375us 1.280us 4.81% 1.280us 1.280us 1 |
|
|
aten::empty_strided 3.71% 30.161us 3.71% 30.161us 5.027us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 26.30% 214.084us 26.30% 214.084us 35.681us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.92% 31.890us 5.00% 40.720us 3.393us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.08% 8.830us 1.08% 8.830us 0.736us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.57% 45.301us 5.57% 45.301us 7.550us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.67% 5.440us 0.67% 5.440us 5.440us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 813.864us |
|
|
Self CUDA time total: 26.591us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 353.852us 1157.89% 353.852us 353.852us 1 |
|
|
hf_kernels_rotary 7.66% 156.034us 99.77% 2.033ms 2.033ms 0.000us 0.00% 32.320us 32.320us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.04% 41.512us 4.26% 86.762us 14.460us 20.159us 65.97% 20.159us 3.360us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 20.159us 65.97% 20.159us 3.360us 6 |
|
|
aten::clone 1.10% 22.431us 85.66% 1.746ms 290.955us 0.000us 0.00% 12.161us 2.027us 6 |
|
|
aten::copy_ 2.23% 45.431us 82.85% 1.688ms 281.408us 10.401us 34.03% 12.161us 2.027us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 10.401us 34.03% 10.401us 1.734us 6 |
|
|
Activity Buffer Request 70.07% 1.428ms 70.07% 1.428ms 1.428ms 1.760us 5.76% 1.760us 1.760us 1 |
|
|
aten::empty_strided 1.71% 34.849us 1.71% 34.849us 5.808us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 10.54% 214.913us 10.54% 214.913us 35.819us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.68% 34.241us 2.20% 44.770us 3.731us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.52% 10.529us 0.52% 10.529us 0.877us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.22% 45.250us 2.22% 45.250us 7.542us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.23% 4.770us 0.23% 4.770us 4.770us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.038ms |
|
|
Self CUDA time total: 30.560us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 367.612us 860.51% 367.612us 367.612us 1 |
|
|
hf_kernels_rotary 7.69% 158.003us 99.76% 2.050ms 2.050ms 0.000us 0.00% 45.568us 45.568us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.04% 41.961us 4.25% 87.391us 14.565us 25.759us 60.30% 25.759us 4.293us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 25.759us 60.30% 25.759us 4.293us 6 |
|
|
aten::clone 1.11% 22.799us 84.82% 1.743ms 290.528us 0.000us 0.00% 19.809us 3.301us 6 |
|
|
aten::copy_ 1.88% 38.712us 82.12% 1.688ms 281.267us 16.961us 39.70% 19.809us 3.301us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 16.961us 39.70% 16.961us 2.827us 6 |
|
|
Activity Buffer Request 69.69% 1.432ms 69.69% 1.432ms 1.432ms 2.848us 6.67% 2.848us 2.848us 1 |
|
|
aten::empty_strided 1.59% 32.771us 1.59% 32.771us 5.462us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 10.54% 216.613us 10.54% 216.613us 36.102us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 2.51% 51.572us 3.00% 61.672us 5.139us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.49% 10.100us 0.49% 10.100us 0.842us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.21% 45.430us 2.21% 45.430us 7.572us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.24% 4.849us 0.24% 4.849us 4.849us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.055ms |
|
|
Self CUDA time total: 42.720us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 347.614us 1135.14% 347.614us 347.614us 1 |
|
|
hf_kernels_rotary 7.64% 156.781us 99.77% 2.046ms 2.046ms 0.000us 0.00% 32.383us 32.383us 1 |
|
|
_rotary_dba7d1e::apply_rotary 2.01% 41.122us 4.16% 85.392us 14.232us 20.223us 66.04% 20.223us 3.370us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 20.223us 66.04% 20.223us 3.370us 6 |
|
|
aten::clone 1.11% 22.841us 85.79% 1.759ms 293.223us 0.000us 0.00% 12.160us 2.027us 6 |
|
|
aten::copy_ 1.81% 37.030us 83.06% 1.703ms 283.910us 10.400us 33.96% 12.160us 2.027us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 10.400us 33.96% 10.400us 1.733us 6 |
|
|
Activity Buffer Request 70.68% 1.449ms 70.68% 1.449ms 1.449ms 1.760us 5.75% 1.760us 1.760us 1 |
|
|
aten::empty_strided 1.61% 33.040us 1.61% 33.040us 5.507us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 10.58% 216.984us 10.58% 216.984us 36.164us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.70% 34.784us 2.17% 44.532us 3.711us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.48% 9.748us 0.48% 9.748us 0.812us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 2.16% 44.270us 2.16% 44.270us 7.378us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.23% 4.760us 0.23% 4.760us 4.760us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.051ms |
|
|
Self CUDA time total: 30.623us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 328.444us 771.23% 328.444us 328.444us 1 |
|
|
hf_kernels_rotary 18.84% 150.934us 99.38% 796.084us 796.084us 0.000us 0.00% 45.403us 45.403us 1 |
|
|
_rotary_dba7d1e::apply_rotary 5.06% 40.529us 10.59% 84.811us 14.135us 25.693us 60.33% 25.693us 4.282us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 25.693us 60.33% 25.693us 4.282us 6 |
|
|
aten::clone 2.49% 19.929us 64.90% 519.868us 86.645us 0.000us 0.00% 19.710us 3.285us 6 |
|
|
aten::copy_ 4.41% 35.321us 58.57% 469.148us 78.191us 16.894us 39.67% 19.710us 3.285us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 16.894us 39.67% 16.894us 2.816us 6 |
|
|
Activity Buffer Request 27.59% 221.013us 27.59% 221.013us 221.013us 2.816us 6.61% 2.816us 2.816us 1 |
|
|
aten::empty_strided 3.84% 30.791us 3.84% 30.791us 5.132us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 26.57% 212.814us 26.57% 212.814us 35.469us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.92% 31.361us 5.05% 40.471us 3.373us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.14% 9.110us 1.14% 9.110us 0.759us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.53% 44.282us 5.53% 44.282us 7.380us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.62% 4.951us 0.62% 4.951us 4.951us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 801.035us |
|
|
Self CUDA time total: 42.587us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 338.910us 380.70% 338.910us 338.910us 1 |
|
|
hf_kernels_rotary 14.14% 150.935us 99.54% 1.062ms 1.062ms 0.000us 0.00% 104.734us 104.734us 1 |
|
|
aten::clone 2.00% 21.371us 73.53% 784.703us 130.784us 0.000us 0.00% 63.775us 10.629us 6 |
|
|
aten::copy_ 3.58% 38.219us 68.59% 731.952us 121.992us 48.063us 53.99% 63.775us 10.629us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 48.063us 53.99% 48.063us 8.010us 6 |
|
|
_rotary_dba7d1e::apply_rotary 3.85% 41.059us 8.05% 85.950us 14.325us 40.959us 46.01% 40.959us 6.826us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 40.959us 46.01% 40.959us 6.826us 6 |
|
|
Activity Buffer Request 44.86% 478.699us 44.86% 478.699us 478.699us 15.712us 17.65% 15.712us 15.712us 1 |
|
|
aten::empty_strided 2.94% 31.380us 2.94% 31.380us 5.230us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 20.15% 215.034us 20.15% 215.034us 35.839us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 2.96% 31.591us 3.81% 40.690us 3.391us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.85% 9.099us 0.85% 9.099us 0.758us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 4.21% 44.891us 4.21% 44.891us 7.482us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.46% 4.900us 0.46% 4.900us 4.900us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 1.067ms |
|
|
Self CUDA time total: 89.022us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 336.057us 230.21% 336.057us 336.057us 1 |
|
|
hf_kernels_rotary 18.72% 149.775us 99.40% 795.224us 795.224us 0.000us 0.00% 169.949us 169.949us 1 |
|
|
aten::clone 2.52% 20.180us 65.04% 520.348us 86.725us 0.000us 0.00% 106.527us 17.755us 6 |
|
|
aten::copy_ 4.49% 35.890us 58.61% 468.868us 78.145us 82.559us 56.55% 106.527us 17.755us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 82.559us 56.55% 82.559us 13.760us 6 |
|
|
_rotary_dba7d1e::apply_rotary 5.12% 40.981us 10.49% 83.942us 13.990us 63.422us 43.45% 63.422us 10.570us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 63.422us 43.45% 63.422us 10.570us 6 |
|
|
Activity Buffer Request 27.82% 222.544us 27.82% 222.544us 222.544us 23.968us 16.42% 23.968us 23.968us 1 |
|
|
aten::empty_strided 3.91% 31.300us 3.91% 31.300us 5.217us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 26.30% 210.434us 26.30% 210.434us 35.072us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.94% 31.518us 5.14% 41.159us 3.430us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.21% 9.641us 1.21% 9.641us 0.803us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.37% 42.961us 5.37% 42.961us 7.160us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.60% 4.790us 0.60% 4.790us 4.790us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 800.014us |
|
|
Self CUDA time total: 145.981us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H8_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 339.836us 451.90% 339.836us 339.836us 1 |
|
|
hf_kernels_rotary 18.57% 150.269us 99.38% 804.154us 804.154us 0.000us 0.00% 81.986us 81.986us 1 |
|
|
_rotary_dba7d1e::apply_rotary 4.99% 40.401us 10.49% 84.862us 14.144us 41.601us 55.32% 41.601us 6.933us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 41.601us 55.32% 41.601us 6.933us 6 |
|
|
aten::clone 2.54% 20.532us 64.81% 524.439us 87.406us 0.000us 0.00% 40.385us 6.731us 6 |
|
|
aten::copy_ 4.41% 35.708us 58.24% 471.217us 78.536us 33.601us 44.68% 40.385us 6.731us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 33.601us 44.68% 33.601us 5.600us 6 |
|
|
Activity Buffer Request 27.71% 224.174us 27.71% 224.174us 224.174us 6.784us 9.02% 6.784us 6.784us 1 |
|
|
aten::empty_strided 4.04% 32.690us 4.04% 32.690us 5.448us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 26.12% 211.335us 26.12% 211.335us 35.223us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 4.32% 34.924us 5.51% 44.584us 3.715us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.19% 9.660us 1.19% 9.660us 0.805us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 5.49% 44.461us 5.49% 44.461us 7.410us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.62% 4.981us 0.62% 4.981us 4.981us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 809.135us |
|
|
Self CUDA time total: 75.202us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H8_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 372.859us 256.14% 372.859us 372.859us 1 |
|
|
hf_kernels_rotary 18.64% 161.451us 99.43% 861.125us 861.125us 0.000us 0.00% 169.279us 169.279us 1 |
|
|
aten::clone 2.47% 21.401us 63.58% 550.631us 91.772us 0.000us 0.00% 105.373us 17.562us 6 |
|
|
aten::copy_ 4.30% 37.239us 57.31% 496.359us 82.727us 81.662us 56.10% 105.373us 17.562us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 81.662us 56.10% 81.662us 13.610us 6 |
|
|
_rotary_dba7d1e::apply_rotary 5.12% 44.341us 12.24% 106.023us 17.671us 63.906us 43.90% 63.906us 10.651us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 63.906us 43.90% 63.906us 10.651us 6 |
|
|
Activity Buffer Request 28.62% 247.854us 28.62% 247.854us 247.854us 23.711us 16.29% 23.711us 23.711us 1 |
|
|
aten::empty_strided 3.80% 32.871us 3.80% 32.871us 5.479us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 24.39% 211.266us 24.39% 211.266us 35.211us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 3.88% 33.609us 4.97% 43.020us 3.585us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 1.09% 9.411us 1.09% 9.411us 0.784us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 7.12% 61.682us 7.12% 61.682us 10.280us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 0.57% 4.969us 0.57% 4.969us 4.969us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 866.094us |
|
|
Self CUDA time total: 145.568us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H32_D64_R32 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 13.02% 148.583us 72.32% 825.404us 825.404us 0.000us 0.00% 745.510us 745.510us 1 |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 687.015us 101.19% 687.015us 687.015us 1 |
|
|
aten::clone 1.76% 20.130us 47.96% 547.368us 91.228us 0.000us 0.00% 556.292us 92.715us 6 |
|
|
aten::copy_ 3.18% 36.280us 43.26% 493.818us 82.303us 489.699us 72.13% 556.292us 92.715us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 489.699us 72.13% 489.699us 81.617us 6 |
|
|
_rotary_dba7d1e::apply_rotary 3.57% 40.732us 7.58% 86.552us 14.425us 189.218us 27.87% 189.218us 31.536us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 189.218us 27.87% 189.218us 31.536us 6 |
|
|
Activity Buffer Request 21.89% 249.905us 21.89% 249.905us 249.905us 66.593us 9.81% 66.593us 66.593us 1 |
|
|
aten::empty_strided 2.93% 33.420us 2.93% 33.420us 5.570us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 18.19% 207.633us 18.19% 207.633us 34.606us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 2.92% 33.351us 3.76% 42.901us 3.575us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.84% 9.550us 0.84% 9.550us 0.796us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 4.01% 45.820us 4.01% 45.820us 7.637us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 27.68% 315.986us 27.68% 315.986us 315.986us 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 1.141ms |
|
|
Self CUDA time total: 678.917us |
|
|
|
|
|
|
|
|
|
|
|
====================================================================== |
|
|
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H32_D128_R64 |
|
|
====================================================================== |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
hf_kernels_rotary 5.26% 153.062us 28.60% 832.074us 832.074us 0.000us 0.00% 2.627ms 2.627ms 1 |
|
|
hf_kernels_rotary 0.00% 0.000us 0.00% 0.000us 0.000us 2.451ms 100.32% 2.451ms 2.451ms 1 |
|
|
aten::clone 0.71% 20.751us 18.92% 550.432us 91.739us 0.000us 0.00% 1.403ms 233.752us 6 |
|
|
aten::copy_ 1.33% 38.628us 17.10% 497.389us 82.898us 1.219ms 49.87% 1.403ms 233.752us 6 |
|
|
_rotary_dba7d1e::apply_rotary 1.42% 41.449us 2.89% 84.050us 14.008us 1.225ms 50.13% 1.225ms 204.141us 6 |
|
|
void at::native::(anonymous namespace)::unrolled_ele... 0.00% 0.000us 0.00% 0.000us 0.000us 1.225ms 50.13% 1.225ms 204.141us 6 |
|
|
Memcpy DtoD (Device -> Device) 0.00% 0.000us 0.00% 0.000us 0.000us 1.219ms 49.87% 1.219ms 203.112us 6 |
|
|
Activity Buffer Request 8.62% 250.725us 8.62% 250.725us 250.725us 183.838us 7.52% 183.838us 183.838us 1 |
|
|
aten::empty_strided 1.11% 32.292us 1.11% 32.292us 5.382us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaMemcpyAsync 7.15% 208.036us 7.15% 208.036us 34.673us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
aten::slice 1.18% 34.219us 1.53% 44.530us 3.711us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
aten::as_strided 0.35% 10.311us 0.35% 10.311us 0.859us 0.000us 0.00% 0.000us 0.000us 12 |
|
|
cudaLaunchKernel 1.46% 42.601us 1.46% 42.601us 7.100us 0.000us 0.00% 0.000us 0.000us 6 |
|
|
cudaDeviceSynchronize 71.40% 2.077ms 71.40% 2.077ms 2.077ms 0.000us 0.00% 0.000us 0.000us 1 |
|
|
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ |
|
|
Self CPU time total: 2.909ms |
|
|
Self CUDA time total: 2.444ms |
|
|
|
|
|
|
|
|
impl wl p50(ms) ok |
|
|
hf_kernels_rotary cuda_B1_S128_H32_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S128_H32_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S128_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S128_H8_D64_R32 0.08 True |
|
|
hf_kernels_rotary cuda_B1_S2048_H32_D128_R64 0.26 True |
|
|
hf_kernels_rotary cuda_B1_S2048_H32_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S2048_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S2048_H8_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S512_H32_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S512_H32_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S512_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B1_S512_H8_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S128_H32_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S128_H32_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S128_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S128_H8_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S2048_H32_D128_R64 0.85 True |
|
|
hf_kernels_rotary cuda_B2_S2048_H32_D64_R32 0.26 True |
|
|
hf_kernels_rotary cuda_B2_S2048_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S2048_H8_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S512_H32_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S512_H32_D64_R32 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S512_H8_D128_R64 0.09 True |
|
|
hf_kernels_rotary cuda_B2_S512_H8_D64_R32 0.09 True |
|
|
</pre></div> |
|
|
<div class="uv-install-logs" id="uv-logs-benchmark"> |
|
|
<div class="uv-logs-header" onclick="toggleUvLogs(this)">▶ UV Install Logs</div> |
|
|
<div class="uv-logs-content" style="display: none;"> |
|
|
Downloading hf-xet (3.2MiB) |
|
|
Downloading hf-xet |
|
|
Installed 52 packages in 244ms |
|
|
</div> |
|
|
</div> |
|
|
<div class="cell-stderr">Fetching 5 files: 0%| | 0/5 [00:00<?, ?it/s] |
|
|
Fetching 5 files: 100%|██████████| 5/5 [00:00<00:00, 15.33it/s] |
|
|
Fetching 5 files: 100%|██████████| 5/5 [00:00<00:00, 15.31it/s]</div> |
|
|
<div class="cell-artifacts"> |
|
|
<h4>Artifacts:</h4> |
|
|
<a href="artifacts/benchmark/rotary.jsonl" class="artifact" target="_blank">rotary.jsonl</a> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
</body> |
|
|
</html> |