初版:上传接口(从线上实例导出,适配容器端口)
@@ -0,0 +1,111 @@
|
||||
/* 基础 CSS 变量 - 所有页面共用 */
|
||||
|
||||
/* ========== 浅色模式 ========== */
|
||||
:root {
|
||||
/* 背景 */
|
||||
--bg-primary: #fafafa;
|
||||
--bg-secondary: #ffffff;
|
||||
|
||||
/* 文字 */
|
||||
--text-primary: #171717;
|
||||
--text-secondary: #525252;
|
||||
--text-muted: #737373;
|
||||
|
||||
/* 边框 */
|
||||
--border-color: #e5e5e5;
|
||||
--border-focus: #171717;
|
||||
|
||||
/* 输入框 */
|
||||
--input-bg: #fafafa;
|
||||
--input-border: #d4d4d4;
|
||||
--input-text: #171717;
|
||||
|
||||
/* 强调色 */
|
||||
--accent-bg: #171717;
|
||||
--accent-text: #ffffff;
|
||||
|
||||
/* 毛玻璃 */
|
||||
--glass-bg: rgba(255, 255, 255, 0.7);
|
||||
--glass-border: rgba(255, 255, 255, 0.5);
|
||||
--glass-hover: rgba(255, 255, 255, 0.9);
|
||||
|
||||
/* 阴影 */
|
||||
--shadow-color: rgba(0, 0, 0, 0.05);
|
||||
|
||||
/* 状态色 - Success */
|
||||
--success-bg: #f0fdf4;
|
||||
--success-border: #dcfce7;
|
||||
--success-text: #16a34a;
|
||||
|
||||
/* 状态色 - Error */
|
||||
--error-bg: #fef2f2;
|
||||
--error-border: #fee2e2;
|
||||
--error-text: #dc2626;
|
||||
|
||||
/* 状态色 - Warning */
|
||||
--warning-bg: #fffbeb;
|
||||
--warning-border: #fef3c7;
|
||||
--warning-text: #d97706;
|
||||
|
||||
/* 状态色 - Info */
|
||||
--info-bg: #eff6ff;
|
||||
--info-border: #dbeafe;
|
||||
--info-text: #2563eb;
|
||||
--progress-green: #4ade80;
|
||||
--progress-red: #ef4444;
|
||||
}
|
||||
|
||||
/* ========== 深色模式 ========== */
|
||||
.dark {
|
||||
/* 背景 */
|
||||
--bg-primary: #0a0a0a;
|
||||
--bg-secondary: #171717;
|
||||
|
||||
/* 文字 */
|
||||
--text-primary: #fafafa;
|
||||
--text-secondary: #a3a3a3;
|
||||
--text-muted: #737373;
|
||||
|
||||
/* 边框 */
|
||||
--border-color: #262626;
|
||||
--border-focus: #fafafa;
|
||||
|
||||
/* 输入框 */
|
||||
--input-bg: #262626;
|
||||
--input-border: #404040;
|
||||
--input-text: #fafafa;
|
||||
|
||||
/* 强调色 */
|
||||
--accent-bg: #fafafa;
|
||||
--accent-text: #171717;
|
||||
|
||||
/* 毛玻璃 */
|
||||
--glass-bg: rgba(23, 23, 23, 0.8);
|
||||
--glass-border: rgba(255, 255, 255, 0.1);
|
||||
--glass-hover: rgba(38, 38, 38, 0.9);
|
||||
|
||||
/* 阴影 */
|
||||
--shadow-color: rgba(0, 0, 0, 0.5);
|
||||
|
||||
/* 状态色 - Success */
|
||||
--success-bg: rgba(22, 163, 74, 0.1);
|
||||
--success-border: rgba(22, 163, 74, 0.2);
|
||||
--success-text: #4ade80;
|
||||
|
||||
/* 状态色 - Error */
|
||||
--error-bg: rgba(220, 38, 38, 0.1);
|
||||
--error-border: rgba(220, 38, 38, 0.2);
|
||||
--error-text: #ef4444;
|
||||
|
||||
/* 状态色 - Warning */
|
||||
--warning-bg: rgba(217, 119, 6, 0.1);
|
||||
--warning-border: rgba(217, 119, 6, 0.2);
|
||||
--warning-text: #fbbf24;
|
||||
|
||||
/* 状态色 - Info */
|
||||
--info-bg: rgba(37, 99, 235, 0.1);
|
||||
--info-border: rgba(37, 99, 235, 0.2);
|
||||
--info-text: #60a5fa;
|
||||
--progress-green: #4ade80;
|
||||
--progress-red: #ef4444;
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
/* ============================================================
|
||||
common.css — 全站公共样式
|
||||
依赖: basic.css(CSS 变量定义)
|
||||
============================================================ */
|
||||
|
||||
/* ── 全局重置 ────────────────────────────────────────────── */
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: rgba(128, 128, 128, 0.2);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* ── 字体导入 ─────────────────────────────────────────────── */
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,600;1,400&display=swap');
|
||||
@import url('/static/toast.css');
|
||||
|
||||
/* ── Body 基础 ────────────────────────────────────────────── */
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
background-color: var(--bg-primary);
|
||||
background-image:
|
||||
radial-gradient(at 0% 0%, rgba(128, 128, 128, 0.03) 0px, transparent 50%),
|
||||
radial-gradient(at 100% 100%, rgba(128, 128, 128, 0.03) 0px, transparent 50%);
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
overflow-x: hidden;
|
||||
transition: background-color 0.5s ease, color 0.5s ease;
|
||||
}
|
||||
|
||||
.dark body {
|
||||
background-image:
|
||||
radial-gradient(at 0% 0%, rgba(255, 255, 255, 0.02) 0px, transparent 50%),
|
||||
radial-gradient(at 100% 100%, rgba(255, 255, 255, 0.02) 0px, transparent 50%);
|
||||
}
|
||||
|
||||
/* ── 滚动条 ───────────────────────────────────────────────── */
|
||||
body::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
body::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
body::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
body::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
/* ── 字体辅助类 ───────────────────────────────────────────── */
|
||||
.font-serif {
|
||||
font-family: 'Playfair Display', serif;
|
||||
}
|
||||
|
||||
/* ── 毛玻璃效果 ───────────────────────────────────────────── */
|
||||
.glass {
|
||||
background: var(--glass-bg);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
border: 1px solid var(--glass-border);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.glass:hover {
|
||||
background: var(--glass-hover);
|
||||
}
|
||||
|
||||
/* ── 主题过渡 ─────────────────────────────────────────────── */
|
||||
.theme-transition {
|
||||
transition: background-color 0.5s ease, color 0.5s ease,
|
||||
border-color 0.5s ease, box-shadow 0.5s ease;
|
||||
}
|
||||
|
||||
/* ── 按钮系统 ─────────────────────────────────────────────── */
|
||||
.btn {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
|
||||
font-family: 'Inter', sans-serif;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -100%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, transparent, rgba(128, 128, 128, 0.1), transparent);
|
||||
transition: left 0.5s;
|
||||
}
|
||||
|
||||
.btn:hover::before {
|
||||
left: 100%;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--accent-bg);
|
||||
color: var(--accent-text);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 20px -5px var(--shadow-color);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: var(--bg-secondary);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: var(--error-bg);
|
||||
color: var(--error-text);
|
||||
border: 1px solid var(--error-border);
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
opacity: 0.8;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
/* ── 滚动进度条 ───────────────────────────────────────────── */
|
||||
#scrollProgress {
|
||||
background: linear-gradient(90deg, var(--text-muted), var(--text-primary));
|
||||
}
|
||||
|
||||
/* ── 加载动画 ─────────────────────────────────────────────── */
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 3px solid var(--border-color);
|
||||
border-top-color: var(--text-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* 小尺寸 spinner(用于按钮内联)*/
|
||||
.loading-spinner-sm {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid currentColor;
|
||||
border-top-color: transparent;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
display: inline-block;
|
||||
margin-left: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* ── Modal 对话框 ─────────────────────────────────────────── */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-overlay.show {
|
||||
display: flex;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--glass-border);
|
||||
border-radius: 24px;
|
||||
padding: 40px;
|
||||
width: 90%;
|
||||
max-width: 480px;
|
||||
transform: scale(0.95) translateY(20px);
|
||||
transition: transform 0.4s cubic-bezier(0.2, 0, 0, 1);
|
||||
}
|
||||
|
||||
.modal-overlay.show .modal-content {
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
|
||||
/* ── GSAP 入场动画初始状态 ────────────────────────────────── */
|
||||
.stagger-item {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
|
||||
/* ── 输入框样式(create/edit 共用)────────────────────────── */
|
||||
.input-underline {
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
font-size: 15px;
|
||||
color: var(--text-primary);
|
||||
outline: none;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
.input-underline:focus {
|
||||
border-color: var(--border-focus);
|
||||
box-shadow: 0 0 0 3px var(--shadow-color);
|
||||
}
|
||||
|
||||
.input-underline::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
select.input-underline {
|
||||
cursor: pointer;
|
||||
appearance: none;
|
||||
background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23737373' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 12px center;
|
||||
padding-right: 34px;
|
||||
}
|
||||
|
||||
/* ── 卡片字段(create/edit 共用)──────────────────────────── */
|
||||
.field-card {
|
||||
background: var(--glass-bg);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
border: 1px solid var(--glass-border);
|
||||
border-radius: 16px;
|
||||
padding: 16px;
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
transition: all 0.4s cubic-bezier(0.2, 0, 0, 1);
|
||||
overflow: hidden;
|
||||
touch-action: pan-y;
|
||||
}
|
||||
|
||||
.field-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 20px 40px -15px var(--shadow-color);
|
||||
border-color: rgba(128, 128, 128, 0.3);
|
||||
background: var(--glass-hover);
|
||||
}
|
||||
|
||||
.field-edit-input {
|
||||
width: 100%;
|
||||
min-height: 40px;
|
||||
padding: 9px 11px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
|
||||
}
|
||||
|
||||
.field-edit-input::placeholder { color: var(--text-muted); }
|
||||
|
||||
.field-edit-input:focus {
|
||||
border-color: var(--border-focus);
|
||||
box-shadow: 0 0 0 3px var(--shadow-color);
|
||||
}
|
||||
|
||||
.field-condition-button {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 52px;
|
||||
width: 28px !important;
|
||||
height: 28px;
|
||||
padding: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
.field-condition-button span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.field-card.sortable-ghost {
|
||||
opacity: 0.3;
|
||||
background: linear-gradient(135deg, var(--info-bg) 0%, transparent 100%);
|
||||
border: 2px dashed var(--info-text);
|
||||
transform: scale(0.98);
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.field-card.sortable-drag {
|
||||
opacity: 0.95;
|
||||
transform: scale(1.03) rotate(1deg);
|
||||
box-shadow:
|
||||
0 25px 50px -12px var(--shadow-color),
|
||||
0 0 0 1px rgba(128, 128, 128, 0.1);
|
||||
cursor: grabbing;
|
||||
z-index: 1000;
|
||||
animation: dragPulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.field-card.sortable-drag::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 20px;
|
||||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@keyframes dragPulse {
|
||||
0%, 100% { box-shadow: 0 25px 50px -12px var(--shadow-color); }
|
||||
50% { box-shadow: 0 30px 60px -15px var(--shadow-color), 0 0 20px rgba(128, 128, 128, 0.1); }
|
||||
}
|
||||
|
||||
@media (hover: none) and (pointer: coarse) {
|
||||
.field-card.sortable-drag {
|
||||
opacity: 0.98;
|
||||
transform: scale(1.02);
|
||||
box-shadow: 0 20px 40px -10px var(--shadow-color);
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 拖拽手柄 ─────────────────────────────────────────────── */
|
||||
.drag-handle {
|
||||
cursor: grab;
|
||||
padding: 8px;
|
||||
margin: -8px;
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
touch-action: none;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.drag-handle:hover {
|
||||
background: var(--bg-primary);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.drag-handle:active {
|
||||
cursor: grabbing;
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
@media (hover: none) and (pointer: coarse) {
|
||||
.drag-handle {
|
||||
padding: 12px;
|
||||
margin: -12px;
|
||||
}
|
||||
|
||||
.drag-handle svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 自定义 Checkbox ──────────────────────────────────────── */
|
||||
.checkbox-custom {
|
||||
appearance: none;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: all 0.2s ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.checkbox-custom:checked {
|
||||
background-color: var(--accent-bg);
|
||||
border-color: var(--accent-bg);
|
||||
}
|
||||
|
||||
.checkbox-custom:checked::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
top: 1px;
|
||||
width: 6px;
|
||||
height: 10px;
|
||||
border: 2px solid var(--accent-text);
|
||||
border-top: none;
|
||||
border-left: none;
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
/* ── 导航栏链接(面包屑风格)──────────────────────────────── */
|
||||
.nav-link {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
transition: color 0.2s;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
@@ -0,0 +1,678 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,600;1,400&display=swap');
|
||||
|
||||
/* 表单工作台与填写页:冷调蓝灰、清晰层级和克制的状态动效。 */
|
||||
.submission-page .field-wrapper[data-url-hidden="true"] { display: none !important; }
|
||||
.submission-page .url-prefilled input:disabled,
|
||||
.submission-page .url-prefilled textarea:disabled,
|
||||
.submission-page .url-prefilled select:disabled { cursor: not-allowed; opacity: .8; }
|
||||
.submission-page .url-prefilled label,
|
||||
.submission-page .url-prefilled .rating-stars { cursor: not-allowed; }
|
||||
.submission-page .url-prefilled .rating-stars[aria-disabled="true"] { pointer-events: none; }
|
||||
|
||||
.builder-page .stagger-item,
|
||||
.submission-page .stagger-item {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
.builder-page,
|
||||
.submission-page {
|
||||
--bg-primary: #edf2f8;
|
||||
--bg-secondary: #fbfdff;
|
||||
--text-primary: #17253a;
|
||||
--text-secondary: #465973;
|
||||
--text-muted: #5f7189;
|
||||
--border-color: #cfdaea;
|
||||
--border-focus: #285bd4;
|
||||
--input-bg: #f5f8fc;
|
||||
--input-border: #c5d3e6;
|
||||
--input-text: #17253a;
|
||||
--accent-bg: #285bd4;
|
||||
--accent-text: #fff;
|
||||
--glass-bg: rgba(251, 253, 255, .88);
|
||||
--glass-border: rgba(37, 74, 128, .14);
|
||||
--glass-hover: rgba(251, 253, 255, .97);
|
||||
--shadow-color: rgba(24, 54, 103, .13);
|
||||
--studio-side: #f4f8fd;
|
||||
--studio-ink-soft: #e3ebf7;
|
||||
--studio-glow: rgba(63, 115, 223, .16);
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-primary);
|
||||
background-image:
|
||||
radial-gradient(circle at 74% 0%, rgba(75, 132, 235, .14), transparent 32%),
|
||||
linear-gradient(180deg, #f5f8fd 0%, #edf2f8 48%, #e8eef6 100%);
|
||||
}
|
||||
|
||||
.dark body.builder-page,
|
||||
.dark body.submission-page {
|
||||
--bg-primary: #0b1524;
|
||||
--bg-secondary: #142338;
|
||||
--text-primary: #f0f5ff;
|
||||
--text-secondary: #b6c5da;
|
||||
--text-muted: #92a7c1;
|
||||
--border-color: #324763;
|
||||
--border-focus: #91b2ff;
|
||||
--input-bg: #102036;
|
||||
--input-border: #39516f;
|
||||
--input-text: #f0f5ff;
|
||||
--accent-bg: #91b2ff;
|
||||
--accent-text: #0d1b30;
|
||||
--glass-bg: rgba(20, 35, 56, .89);
|
||||
--glass-border: rgba(179, 204, 239, .17);
|
||||
--glass-hover: rgba(29, 48, 74, .97);
|
||||
--shadow-color: rgba(0, 5, 15, .45);
|
||||
--studio-side: #102035;
|
||||
--studio-ink-soft: #243b59;
|
||||
--studio-glow: rgba(100, 148, 255, .15);
|
||||
background-color: var(--bg-primary);
|
||||
background-image:
|
||||
radial-gradient(circle at 75% -8%, rgba(68, 112, 190, .22), transparent 33%),
|
||||
linear-gradient(180deg, #0e1c30 0%, #0b1524 46%, #09111f 100%);
|
||||
}
|
||||
|
||||
.builder-page::before,
|
||||
.submission-page::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
pointer-events: none;
|
||||
opacity: .24;
|
||||
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' opacity='.11' filter='url(%23n)'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
.builder-page > header,
|
||||
.submission-page > header {
|
||||
background: color-mix(in srgb, var(--bg-secondary) 91%, transparent) !important;
|
||||
border-color: var(--glass-border) !important;
|
||||
box-shadow: 0 9px 28px -24px var(--text-primary);
|
||||
backdrop-filter: blur(20px) saturate(135%);
|
||||
-webkit-backdrop-filter: blur(20px) saturate(135%);
|
||||
}
|
||||
|
||||
.builder-page #scrollProgress,
|
||||
.submission-page #scrollProgress {
|
||||
background: var(--accent-bg) !important;
|
||||
box-shadow: 0 0 16px var(--studio-glow);
|
||||
}
|
||||
|
||||
.builder-page main { padding-top: 126px; }
|
||||
.submission-page main { padding-top: 136px; }
|
||||
|
||||
.studio-kicker {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
margin: 0 0 16px;
|
||||
color: var(--accent-bg) !important;
|
||||
font: 700 11px/1.3 Inter, system-ui, sans-serif !important;
|
||||
letter-spacing: .15em !important;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.studio-kicker__dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
flex: none;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-bg);
|
||||
box-shadow: 0 0 0 5px var(--studio-glow);
|
||||
}
|
||||
|
||||
.builder-page #headerSection,
|
||||
.submission-page #headerSection {
|
||||
position: relative;
|
||||
margin-bottom: 28px;
|
||||
padding-left: 2px;
|
||||
}
|
||||
|
||||
.builder-page #headerSection h2,
|
||||
.submission-page #headerSection h1 {
|
||||
margin-bottom: 10px;
|
||||
color: var(--text-primary);
|
||||
font-family: Inter, 'Microsoft YaHei', system-ui, sans-serif;
|
||||
font-size: clamp(32px, 3vw, 46px);
|
||||
font-weight: 750;
|
||||
line-height: 1.12;
|
||||
letter-spacing: -.045em;
|
||||
text-wrap: balance;
|
||||
}
|
||||
|
||||
.builder-page #headerSection p:not(.studio-kicker),
|
||||
.submission-page #headerSection p:not(.studio-kicker) {
|
||||
max-width: 650px;
|
||||
color: var(--text-secondary) !important;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.builder-page #mobileTabbar > .glass {
|
||||
padding: 5px;
|
||||
background: var(--studio-side);
|
||||
border: 1px solid var(--border-color) !important;
|
||||
box-shadow: 0 14px 28px -24px var(--text-primary);
|
||||
}
|
||||
|
||||
.builder-page #mobileTabbar button {
|
||||
min-height: 42px;
|
||||
border-radius: 999px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.builder-page #mobileTabbar button.active {
|
||||
background: var(--accent-bg);
|
||||
color: var(--accent-text);
|
||||
box-shadow: 0 8px 22px -13px var(--accent-bg);
|
||||
}
|
||||
|
||||
.builder-page #palettePane > .glass,
|
||||
.builder-page #settingsPane > .glass {
|
||||
background: var(--studio-side);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 22px;
|
||||
box-shadow: 0 18px 42px -34px var(--text-primary);
|
||||
backdrop-filter: none;
|
||||
-webkit-backdrop-filter: none;
|
||||
animation: studio-enter .65s cubic-bezier(.16, 1, .3, 1) both;
|
||||
}
|
||||
|
||||
.builder-page #settingsPane > .glass { animation-delay: .11s; }
|
||||
|
||||
.builder-page #palettePane h2,
|
||||
.builder-page #settingsPane h2,
|
||||
.builder-page #fieldsSection h3 {
|
||||
color: var(--text-primary) !important;
|
||||
font-family: Inter, 'Microsoft YaHei', system-ui, sans-serif;
|
||||
font-weight: 700;
|
||||
letter-spacing: -.03em;
|
||||
}
|
||||
|
||||
.builder-page #palettePane .fc-tile {
|
||||
min-height: 48px;
|
||||
padding: 10px 11px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 3px 9px -8px var(--text-primary);
|
||||
transition: transform .25s cubic-bezier(.16, 1, .3, 1),
|
||||
border-color .25s ease, box-shadow .25s ease, background-color .25s ease;
|
||||
}
|
||||
|
||||
.builder-page #palettePane .fc-tile:hover,
|
||||
.builder-page #palettePane .fc-tile:focus-visible {
|
||||
background: color-mix(in srgb, var(--accent-bg) 9%, var(--bg-secondary));
|
||||
border-color: var(--accent-bg);
|
||||
box-shadow: 0 10px 19px -15px var(--accent-bg);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.builder-page #palettePane .fc-tile:active {
|
||||
transform: translateY(-1px) scale(.98);
|
||||
transition-duration: .1s;
|
||||
}
|
||||
|
||||
.builder-page #palettePane .fc-tile svg,
|
||||
.builder-page #palettePane .fc-tile:hover svg {
|
||||
stroke: var(--accent-bg);
|
||||
}
|
||||
|
||||
.builder-page #palettePane .fc-label { color: var(--text-primary); font-weight: 600; }
|
||||
|
||||
.builder-page #editorPane > .glass,
|
||||
.builder-page #editorPane > #formContainer,
|
||||
.submission-page #formContainer {
|
||||
position: relative;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 24px;
|
||||
box-shadow: 0 24px 68px -48px var(--text-primary) !important;
|
||||
backdrop-filter: none;
|
||||
-webkit-backdrop-filter: none;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.builder-page #editorPane > .glass,
|
||||
.builder-page #editorPane > #formContainer:not(.hidden) {
|
||||
animation: studio-enter .75s cubic-bezier(.16, 1, .3, 1) .08s both;
|
||||
}
|
||||
|
||||
.builder-page #fieldsSection {
|
||||
padding-top: 30px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.builder-page #fieldsSection > div:first-child {
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.builder-page #emptyFieldsState {
|
||||
padding: 42px 24px;
|
||||
background: var(--input-bg);
|
||||
border-color: var(--input-border) !important;
|
||||
border-style: dashed;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.builder-page .field-card {
|
||||
background: var(--input-bg);
|
||||
border-color: var(--border-color);
|
||||
border-radius: 16px;
|
||||
backdrop-filter: none;
|
||||
-webkit-backdrop-filter: none;
|
||||
transition: border-color .24s ease, box-shadow .24s ease, transform .24s cubic-bezier(.16, 1, .3, 1);
|
||||
}
|
||||
|
||||
.builder-page .field-card:hover,
|
||||
.builder-page .field-card:focus-within {
|
||||
background: var(--input-bg);
|
||||
border-color: var(--accent-bg);
|
||||
box-shadow: 0 14px 30px -25px var(--accent-bg);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.builder-page .page-break-card {
|
||||
background: color-mix(in srgb, var(--accent-bg) 6%, var(--bg-secondary));
|
||||
border-style: dashed;
|
||||
border-color: color-mix(in srgb, var(--accent-bg) 36%, var(--border-color));
|
||||
}
|
||||
.builder-page .page-break-card:focus-within {
|
||||
border-style: solid;
|
||||
}
|
||||
.builder-page .page-break-card .page-break-label {
|
||||
color: var(--accent-bg);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
}
|
||||
|
||||
.builder-page .preset-option {
|
||||
background: var(--bg-secondary);
|
||||
border-color: var(--border-color);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.builder-page .preset-option:hover { border-color: var(--accent-bg); }
|
||||
.builder-page .preset-option.selected {
|
||||
background: color-mix(in srgb, var(--accent-bg) 9%, var(--bg-secondary));
|
||||
border-color: var(--accent-bg);
|
||||
box-shadow: inset 3px 0 0 var(--accent-bg);
|
||||
}
|
||||
|
||||
.builder-page .input-underline,
|
||||
.builder-page .field-edit-input,
|
||||
.submission-page .form-entry-box,
|
||||
.submission-page #upForm :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='file']):not([type='range']) {
|
||||
background-color: var(--input-bg);
|
||||
border-color: var(--input-border);
|
||||
border-radius: 12px;
|
||||
color: var(--input-text);
|
||||
}
|
||||
|
||||
.builder-page :is(.input-underline, .field-edit-input):focus,
|
||||
.submission-page #upForm :is(input, select, textarea):focus {
|
||||
border-color: var(--border-focus) !important;
|
||||
box-shadow: 0 0 0 4px var(--studio-glow) !important;
|
||||
}
|
||||
.submission-page #upForm .field-wrapper :is(input, select, textarea):focus {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
.submission-page #upForm .field-wrapper :is(input, select, textarea):focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.builder-page :is(button, a, input, select, textarea, summary):focus-visible,
|
||||
.submission-page :is(button, a, input, select, textarea):focus-visible {
|
||||
outline: 2px solid var(--border-focus);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.builder-page .btn-primary,
|
||||
.submission-page #submitBtn {
|
||||
background: var(--accent-bg) !important;
|
||||
color: var(--accent-text) !important;
|
||||
box-shadow: 0 14px 28px -18px var(--accent-bg) !important;
|
||||
transition: transform .25s cubic-bezier(.16, 1, .3, 1), box-shadow .25s ease;
|
||||
}
|
||||
.builder-page .btn-primary { border-radius: 12px; }
|
||||
.submission-page #submitBtn { border-radius: 999px; }
|
||||
|
||||
.builder-page .btn-primary:hover,
|
||||
.submission-page #submitBtn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 19px 32px -17px var(--accent-bg) !important;
|
||||
}
|
||||
|
||||
.builder-page .btn-primary:active,
|
||||
.submission-page #submitBtn:active {
|
||||
transform: translateY(0) scale(.985);
|
||||
transition-duration: .1s;
|
||||
}
|
||||
|
||||
.submission-page main > div { max-width: 700px; }
|
||||
.submission-page #headerSection { margin-bottom: 32px; scroll-margin-top: 102px; }
|
||||
.submission-page #headerSection h1 { font-size: clamp(38px, 4vw, 54px); }
|
||||
.submission-page #formContainer { padding-top: 42px; }
|
||||
.submission-page #formContainer { scroll-margin-top: 96px; }
|
||||
.submission-page #announcementSection,
|
||||
.submission-page #progressSection {
|
||||
background: var(--studio-side);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 12px 26px -25px var(--text-primary);
|
||||
}
|
||||
|
||||
.submission-page #progressBar {
|
||||
background: var(--accent-bg) !important;
|
||||
}
|
||||
|
||||
.submission-page #progressPercent { color: var(--accent-bg) !important; }
|
||||
|
||||
.submission-page #upForm .field-wrapper {
|
||||
padding: 0 0 28px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
.submission-page #upForm .field-wrapper:hover,
|
||||
.submission-page #upForm .field-wrapper:focus-within {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
}
|
||||
.submission-page #upForm input[type='range']:focus-visible,
|
||||
.submission-page #upForm .rating-stars:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
.submission-page #upForm input[type='range']:focus-visible::-webkit-slider-thumb {
|
||||
box-shadow: 0 0 0 5px var(--studio-glow);
|
||||
}
|
||||
.submission-page #upForm .rating-stars:focus-visible .rating-star-item:first-child {
|
||||
filter: drop-shadow(0 0 6px rgba(251, 191, 36, .45));
|
||||
}
|
||||
|
||||
.submission-page #upForm .field-wrapper > label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
color: var(--text-primary) !important;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
.submission-page .field-label-content { min-width: 0; }
|
||||
.submission-page .field-optional-mark {
|
||||
margin-left: 4px;
|
||||
color: var(--text-muted);
|
||||
font-size: .88em;
|
||||
font-weight: 400;
|
||||
}
|
||||
.submission-page .field-required-mark {
|
||||
margin-left: 3px;
|
||||
color: #cf3d4c;
|
||||
font-size: 1.12em;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
}
|
||||
.dark .submission-page .field-required-mark { color: #ff7780; }
|
||||
|
||||
.submission-page .field-index {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 29px;
|
||||
height: 29px;
|
||||
flex: none;
|
||||
border-radius: 9px;
|
||||
background: color-mix(in srgb, var(--accent-bg) 12%, var(--bg-secondary));
|
||||
color: var(--accent-bg);
|
||||
font: 700 11px/1 Inter, system-ui, sans-serif;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.submission-page .slider-shell {
|
||||
--slider-progress: 0%;
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 30px;
|
||||
}
|
||||
.submission-page .slider-rail {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 10px;
|
||||
left: 10px;
|
||||
height: 6px;
|
||||
border-radius: 999px;
|
||||
background: var(--border-color);
|
||||
transform: translateY(-50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
.submission-page .slider-rail-fill {
|
||||
display: block;
|
||||
width: var(--slider-progress);
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background: var(--accent-bg);
|
||||
box-shadow: 0 0 12px var(--studio-glow);
|
||||
transition: width .28s cubic-bezier(.16, 1, .3, 1);
|
||||
}
|
||||
.submission-page .slider-thumb {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: var(--slider-progress);
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: 3px solid var(--accent-bg);
|
||||
border-radius: 50%;
|
||||
background: var(--bg-secondary);
|
||||
box-shadow: 0 3px 10px -5px var(--text-primary);
|
||||
transform: translate(-50%, -50%);
|
||||
transition: left .28s cubic-bezier(.16, 1, .3, 1),
|
||||
transform .2s ease, box-shadow .2s ease;
|
||||
}
|
||||
.submission-page .slider-shell.is-dragging .slider-rail-fill,
|
||||
.submission-page .slider-shell.is-dragging .slider-thumb {
|
||||
transition-duration: 0ms;
|
||||
}
|
||||
.submission-page .slider-shell:focus-within .slider-thumb {
|
||||
box-shadow: 0 0 0 5px var(--studio-glow), 0 3px 10px -5px var(--text-primary);
|
||||
}
|
||||
.submission-page #upForm .slider-shell .slider-native {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.submission-page #submitBtn { min-height: 54px; }
|
||||
.submission-page .form-page[hidden],
|
||||
.submission-page .form-page-status[hidden],
|
||||
.submission-page #pagePrevBtn[hidden],
|
||||
.submission-page #nextPageBtn[hidden],
|
||||
.submission-page #submitBtn[hidden] { display: none !important; }
|
||||
.submission-page .form-page-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18px;
|
||||
padding-bottom: 18px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
font-weight: 650;
|
||||
letter-spacing: .06em;
|
||||
}
|
||||
.submission-page .form-page-steps { display: flex; gap: 6px; position: relative; }
|
||||
.submission-page .form-page-step {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
width: 24px;
|
||||
height: 4px;
|
||||
border-radius: 999px;
|
||||
background: var(--border-color);
|
||||
}
|
||||
.submission-page .form-page-step::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: inherit;
|
||||
background: var(--accent-bg);
|
||||
transform: scaleX(0);
|
||||
transform-origin: left center;
|
||||
transition: transform .38s cubic-bezier(.16, 1, .3, 1);
|
||||
}
|
||||
.submission-page .form-page-step.complete::after { transform: scaleX(1); }
|
||||
.submission-page .form-page-active {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 24px;
|
||||
height: 4px;
|
||||
border-radius: 999px;
|
||||
background: var(--accent-bg);
|
||||
box-shadow: 0 0 12px color-mix(in srgb, var(--accent-bg) 55%, transparent);
|
||||
transform: translateX(var(--step-offset, 0px));
|
||||
transition: transform .46s cubic-bezier(.16, 1, .3, 1);
|
||||
pointer-events: none;
|
||||
}
|
||||
.submission-page .numeric-display {
|
||||
display: inline-block;
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
transition: transform .22s cubic-bezier(.16, 1, .3, 1), filter .22s ease;
|
||||
}
|
||||
.submission-page .number-spoken {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
.submission-page .number-visual {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
white-space: pre;
|
||||
}
|
||||
.submission-page .number-static-digit,
|
||||
.submission-page .number-reel {
|
||||
display: inline-block;
|
||||
width: .62em;
|
||||
flex: none;
|
||||
text-align: center;
|
||||
}
|
||||
.submission-page .number-reel {
|
||||
position: relative;
|
||||
height: 1.12em;
|
||||
overflow: hidden;
|
||||
vertical-align: -.08em;
|
||||
-webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 14%, #000 86%, transparent 100%);
|
||||
mask-image: linear-gradient(to bottom, transparent 0%, #000 14%, #000 86%, transparent 100%);
|
||||
}
|
||||
.submission-page .number-reel-track {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.12em;
|
||||
will-change: transform;
|
||||
}
|
||||
.submission-page .number-reel-face {
|
||||
display: block;
|
||||
height: 1.12em;
|
||||
flex: none;
|
||||
}
|
||||
.submission-page .numeric-display.number-changing {
|
||||
transform: translateY(-1px);
|
||||
filter: brightness(1.18) drop-shadow(0 0 7px var(--numeric-glow, var(--accent-bg)));
|
||||
}
|
||||
.submission-page .rating-value-display { --numeric-glow: #fbbf24; }
|
||||
.submission-page .form-nav {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
.submission-page #pagePrevBtn {
|
||||
min-width: 120px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 999px;
|
||||
color: var(--text-primary);
|
||||
background: var(--input-bg);
|
||||
font-weight: 600;
|
||||
transition: border-color .2s ease, background-color .2s ease, transform .2s ease;
|
||||
}
|
||||
.submission-page #pagePrevBtn:hover {
|
||||
border-color: var(--accent-bg);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
.submission-page .form-nav #submitBtn,
|
||||
.submission-page .form-nav #nextPageBtn { flex: 1; width: auto; }
|
||||
.submission-page input[type="file"].has-file + div,
|
||||
.submission-page input[type="file"][data-has-file="true"] + div,
|
||||
.dark .submission-page input[type="file"].has-file + div,
|
||||
.dark .submission-page input[type="file"][data-has-file="true"] + div {
|
||||
animation: fileSelected .35s cubic-bezier(.16, 1, .3, 1) both;
|
||||
}
|
||||
.submission-page #particleCanvas,
|
||||
.builder-page #particleCanvas { opacity: .22 !important; }
|
||||
|
||||
@keyframes studio-enter {
|
||||
from { opacity: 0; transform: translateY(18px) scale(.99); }
|
||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||
}
|
||||
|
||||
@media (max-width: 1279px) {
|
||||
.builder-page #mobileTabbar { top: 83px; }
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.builder-page main,
|
||||
.submission-page main { padding: 104px 16px 64px; }
|
||||
.builder-page #mobileTabbar { top: 73px; }
|
||||
.builder-page #editorPane > .glass,
|
||||
.builder-page #editorPane > #formContainer,
|
||||
.submission-page #formContainer { padding: 28px 20px; }
|
||||
.submission-page #pagePrevBtn { min-width: 98px; }
|
||||
.builder-page #headerSection h2 { font-size: 34px; }
|
||||
.submission-page #headerSection h1 { font-size: 38px; }
|
||||
.studio-kicker { margin-bottom: 12px; font-size: 10px !important; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.builder-page #headerSection,
|
||||
.submission-page #headerSection,
|
||||
.submission-page #mainHeader,
|
||||
.builder-page .stagger-item,
|
||||
.submission-page .stagger-item {
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
}
|
||||
.builder-page #palettePane > .glass,
|
||||
.builder-page #settingsPane > .glass,
|
||||
.builder-page #editorPane > .glass,
|
||||
.builder-page #editorPane > #formContainer:not(.hidden) {
|
||||
animation: none;
|
||||
}
|
||||
.builder-page #particleCanvas,
|
||||
.submission-page #particleCanvas { display: none; }
|
||||
.submission-page input[type="file"].has-file + div,
|
||||
.submission-page input[type="file"][data-has-file="true"] + div {
|
||||
animation: none !important;
|
||||
}
|
||||
.builder-page .fc-tile,
|
||||
.builder-page .field-card,
|
||||
.builder-page .btn-primary,
|
||||
.submission-page #submitBtn,
|
||||
.submission-page #pagePrevBtn { transition-duration: .01ms; }
|
||||
.submission-page .form-page-step::after,
|
||||
.submission-page .form-page-active,
|
||||
.submission-page .numeric-display { transition-duration: .01ms !important; }
|
||||
.submission-page .slider-rail-fill,
|
||||
.submission-page .slider-thumb { transition-duration: .01ms !important; }
|
||||
.submission-page .numeric-display.number-changing { transform: none; filter: none; }
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
/* Toast 容器 */
|
||||
#toast-stage {
|
||||
position: fixed;
|
||||
top: 80px;
|
||||
right: 24px;
|
||||
width: 320px;
|
||||
z-index: 9999;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#toast-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 400px;
|
||||
perspective: 1200px;
|
||||
transform-style: preserve-3d;
|
||||
}
|
||||
|
||||
/* Toast 基础 */
|
||||
.toast {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 18px 24px;
|
||||
border-radius: 16px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
backdrop-filter: blur(20px) saturate(180%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||
pointer-events: auto;
|
||||
transform-origin: center top;
|
||||
will-change: transform, opacity;
|
||||
}
|
||||
|
||||
/* ========== 进入动画状态 ========== */
|
||||
.toast.entering {
|
||||
opacity: 0;
|
||||
transform: translateX(-120px) translateZ(50px) rotateY(25deg);
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.toast.entering.show {
|
||||
opacity: 1;
|
||||
transform: translateX(0) translateZ(0) rotateY(0);
|
||||
transition:
|
||||
transform 0.6s cubic-bezier(0.23, 1, 0.32, 1),
|
||||
opacity 0.5s cubic-bezier(0.23, 1, 0.32, 1),
|
||||
filter 0.4s ease;
|
||||
}
|
||||
|
||||
/* ========== 堆叠层级系统 ========== */
|
||||
.toast:nth-child(1) {
|
||||
z-index: 5;
|
||||
transform: translateZ(0) translateY(0) scale(1);
|
||||
opacity: 1;
|
||||
filter: brightness(1);
|
||||
}
|
||||
|
||||
.toast:nth-child(2) {
|
||||
z-index: 4;
|
||||
transform: translateZ(-50px) translateY(24px) scale(0.94);
|
||||
opacity: 0.9;
|
||||
filter: brightness(0.97);
|
||||
}
|
||||
|
||||
.toast:nth-child(3) {
|
||||
z-index: 3;
|
||||
transform: translateZ(-100px) translateY(48px) scale(0.88);
|
||||
opacity: 0.75;
|
||||
filter: brightness(0.94);
|
||||
}
|
||||
|
||||
.toast:nth-child(4) {
|
||||
z-index: 2;
|
||||
transform: translateZ(-150px) translateY(72px) scale(0.82);
|
||||
opacity: 0.6;
|
||||
filter: brightness(0.91);
|
||||
}
|
||||
|
||||
.toast:nth-child(5) {
|
||||
z-index: 1;
|
||||
transform: translateZ(-200px) translateY(96px) scale(0.76);
|
||||
opacity: 0.45;
|
||||
filter: brightness(0.88);
|
||||
}
|
||||
|
||||
.toast:nth-child(n+6) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ========== 层级过渡 ========== */
|
||||
.toast.shift-down {
|
||||
transition:
|
||||
transform 0.5s cubic-bezier(0.23, 1, 0.32, 1),
|
||||
opacity 0.4s ease,
|
||||
filter 0.4s ease;
|
||||
}
|
||||
|
||||
/* ========== 悬停展开 ========== */
|
||||
#toast-stage:hover .toast {
|
||||
transition:
|
||||
transform 0.5s cubic-bezier(0.23, 1, 0.32, 1),
|
||||
opacity 0.4s ease,
|
||||
filter 0.4s ease;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast:nth-child(1) {
|
||||
transform: translateZ(0) translateY(0) scale(1) !important;
|
||||
opacity: 1 !important;
|
||||
filter: brightness(1) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast:nth-child(2) {
|
||||
transform: translateZ(0) translateY(80px) scale(1) !important;
|
||||
opacity: 1 !important;
|
||||
filter: brightness(1) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast:nth-child(3) {
|
||||
transform: translateZ(0) translateY(160px) scale(1) !important;
|
||||
opacity: 1 !important;
|
||||
filter: brightness(1) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast:nth-child(4) {
|
||||
transform: translateZ(0) translateY(240px) scale(1) !important;
|
||||
opacity: 1 !important;
|
||||
filter: brightness(1) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast:nth-child(5) {
|
||||
transform: translateZ(0) translateY(320px) scale(1) !important;
|
||||
opacity: 1 !important;
|
||||
filter: brightness(1) !important;
|
||||
}
|
||||
|
||||
/* ========== 退出动画 ========== */
|
||||
.toast.exiting {
|
||||
opacity: 0 !important;
|
||||
transform: translateX(100px) translateZ(-100px) scale(0.8) rotateY(-15deg) !important;
|
||||
transition:
|
||||
transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
opacity 0.3s ease !important;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting {
|
||||
opacity: 0 !important;
|
||||
transform: translateX(80px) scale(0.9) !important;
|
||||
transition:
|
||||
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
opacity 0.25s ease !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting:nth-child(1) {
|
||||
transform: translateX(80px) translateY(0) scale(0.9) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting:nth-child(2) {
|
||||
transform: translateX(80px) translateY(80px) scale(0.9) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting:nth-child(3) {
|
||||
transform: translateX(80px) translateY(160px) scale(0.9) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting:nth-child(4) {
|
||||
transform: translateX(80px) translateY(240px) scale(0.9) !important;
|
||||
}
|
||||
|
||||
#toast-stage:hover .toast.exiting:nth-child(5) {
|
||||
transform: translateX(80px) translateY(320px) scale(0.9) !important;
|
||||
}
|
||||
|
||||
/* ========== 补位动画 ========== */
|
||||
.toast.reordering {
|
||||
transition:
|
||||
transform 0.5s cubic-bezier(0.23, 1, 0.32, 1),
|
||||
opacity 0.4s ease,
|
||||
filter 0.4s ease;
|
||||
}
|
||||
|
||||
/* ========== 类型样式 ========== */
|
||||
.toast.success {
|
||||
background: rgba(240, 253, 244, 0.85);
|
||||
color: #166534;
|
||||
border-color: rgba(22, 163, 74, 0.2);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
background: rgba(254, 242, 242, 0.85);
|
||||
color: #991b1b;
|
||||
border-color: rgba(220, 38, 38, 0.2);
|
||||
}
|
||||
|
||||
.toast.info {
|
||||
background: rgba(239, 246, 255, 0.85);
|
||||
color: #1e40af;
|
||||
border-color: rgba(37, 99, 235, 0.2);
|
||||
}
|
||||
|
||||
.toast.warning {
|
||||
background: rgba(255, 251, 235, 0.85);
|
||||
color: #92400e;
|
||||
border-color: rgba(217, 119, 6, 0.2);
|
||||
}
|
||||
|
||||
/* ========== 深色模式 ========== */
|
||||
.dark .toast.success {
|
||||
background: rgba(22, 163, 74, 0.15);
|
||||
color: #86efac;
|
||||
border-color: rgba(22, 163, 74, 0.25);
|
||||
}
|
||||
|
||||
.dark .toast.error {
|
||||
background: rgba(220, 38, 38, 0.15);
|
||||
color: #fca5a5;
|
||||
border-color: rgba(220, 38, 38, 0.25);
|
||||
}
|
||||
|
||||
.dark .toast.info {
|
||||
background: rgba(37, 99, 235, 0.15);
|
||||
color: #93c5fd;
|
||||
border-color: rgba(37, 99, 235, 0.25);
|
||||
}
|
||||
|
||||
.dark .toast.warning {
|
||||
background: rgba(217, 119, 6, 0.15);
|
||||
color: #fcd34d;
|
||||
border-color: rgba(217, 119, 6, 0.25);
|
||||
}
|
||||
|
||||
/* ========== 手机端适配 ========== */
|
||||
@media (max-width: 640px) {
|
||||
#toast-stage {
|
||||
top: auto;
|
||||
bottom: 80px;
|
||||
left: 50%;
|
||||
right: auto;
|
||||
transform: translateX(-50%);
|
||||
width: calc(100% - 32px);
|
||||
max-width: 400px;
|
||||
padding-bottom: env(safe-area-inset-bottom, 0px);
|
||||
}
|
||||
|
||||
#toast-container {
|
||||
height: auto;
|
||||
min-height: 80px;
|
||||
perspective: none;
|
||||
transform-style: flat;
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
padding: 16px 20px;
|
||||
border-radius: 16px;
|
||||
font-size: 15px;
|
||||
box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
min-height: 56px;
|
||||
/* 默认最终状态 */
|
||||
transform: translateY(0) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 入场:从下方滑入(与出场方向相反,对称) */
|
||||
.toast.entering {
|
||||
transform: translateY(20px) scale(0.95);
|
||||
opacity: 0;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.toast.entering.show {
|
||||
transform: translateY(0) scale(1);
|
||||
opacity: 1;
|
||||
/* 与出场动画时间一致 */
|
||||
transition:
|
||||
transform 0.3s ease,
|
||||
opacity 0.25s ease;
|
||||
}
|
||||
|
||||
/* 只显示最新 */
|
||||
.toast:nth-child(n+2) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toast:nth-child(1) {
|
||||
transform: translateY(0) scale(1);
|
||||
opacity: 1;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* 出场:向下滑出 + 缩小(与入场对称) */
|
||||
.toast.exiting {
|
||||
transform: translateY(20px) scale(0.95) !important;
|
||||
opacity: 0 !important;
|
||||
transition:
|
||||
transform 0.3s ease,
|
||||
opacity 0.25s ease !important;
|
||||
}
|
||||
|
||||
.toast.swiping {
|
||||
transition: none !important;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.dark .toast {
|
||||
box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 380px) {
|
||||
#toast-stage {
|
||||
width: calc(100% - 24px);
|
||||
bottom: 70px;
|
||||
}
|
||||
|
||||
.toast {
|
||||
padding: 14px 16px;
|
||||
font-size: 14px;
|
||||
min-height: 52px;
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 731 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 607 B |
|
After Width: | Height: | Size: 592 KiB |
@@ -0,0 +1,107 @@
|
||||
/* ============================================================
|
||||
common.js — 全站公共脚本
|
||||
包含: 主题初始化、滚动进度条、退出登录、GSAP 入场动画、
|
||||
formatBytes 工具函数
|
||||
============================================================ */
|
||||
|
||||
/* ── 1. 主题初始化 & 切换(优先读 localStorage,否则跟随系统)── */
|
||||
(function initTheme() {
|
||||
const root = document.documentElement;
|
||||
const systemDark = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
|
||||
function applyTheme(isDark) {
|
||||
root.classList.toggle('dark', isDark);
|
||||
root.classList.toggle('light', !isDark);
|
||||
// 同步主题图标(如果页面有 #themeIcon)
|
||||
const icon = document.getElementById('themeIcon');
|
||||
if (icon) {
|
||||
icon.innerHTML = isDark
|
||||
? '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>' /* 月亮 */
|
||||
: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>'; /* 太阳 */
|
||||
}
|
||||
}
|
||||
|
||||
// 首次加载:localStorage > 系统偏好
|
||||
const saved = localStorage.getItem('theme');
|
||||
if (saved === 'dark' || saved === 'light') {
|
||||
applyTheme(saved === 'dark');
|
||||
} else {
|
||||
applyTheme(systemDark.matches);
|
||||
}
|
||||
|
||||
// 系统切换时,仅在没有手动记忆时跟随
|
||||
systemDark.addEventListener('change', function (e) {
|
||||
if (!localStorage.getItem('theme')) {
|
||||
applyTheme(e.matches);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
/* ── 全局主题切换(供所有页面 toggleTheme() 调用)──────────── */
|
||||
function toggleTheme() {
|
||||
const isDark = document.documentElement.classList.contains('dark');
|
||||
const next = !isDark;
|
||||
document.documentElement.classList.toggle('dark', next);
|
||||
document.documentElement.classList.toggle('light', !next);
|
||||
localStorage.setItem('theme', next ? 'dark' : 'light');
|
||||
// 同步图标
|
||||
const icon = document.getElementById('themeIcon');
|
||||
if (icon) {
|
||||
icon.innerHTML = next
|
||||
? '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>'
|
||||
: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>';
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 2. 滚动进度条(页面需要有 id="scrollProgress" 元素)──── */
|
||||
window.addEventListener('scroll', function () {
|
||||
const el = document.getElementById('scrollProgress');
|
||||
if (!el) return;
|
||||
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
|
||||
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
|
||||
const scrolled = height > 0 ? (winScroll / height) * 100 : 0;
|
||||
el.style.width = scrolled + '%';
|
||||
});
|
||||
|
||||
/* ── 3. 退出登录 ──────────────────────────────────────────── */
|
||||
async function logout() {
|
||||
try {
|
||||
await fetch('/api/logout', { method: 'POST' });
|
||||
window.location.href = '/login';
|
||||
} catch (err) {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('退出失败', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 4. GSAP 入场动画(页面需要有 id="headerSection" 和
|
||||
.stagger-item 元素,且 GSAP 已加载)──────────────── */
|
||||
function initPageAnimation() {
|
||||
if (typeof gsap === 'undefined') return;
|
||||
|
||||
const header = document.getElementById('headerSection');
|
||||
if (header) {
|
||||
gsap.to(header, { opacity: 1, y: 0, duration: 0.8, ease: 'power2.out', delay: 0.1 });
|
||||
}
|
||||
|
||||
const items = document.querySelectorAll('.stagger-item');
|
||||
if (items.length > 0) {
|
||||
gsap.to(items, { opacity: 1, y: 0, duration: 0.6, stagger: 0.1, ease: 'power2.out', delay: 0.3 });
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 5. formatBytes — 字节数格式化工具 ───────────────────── */
|
||||
function formatBytes(bytes, decimals) {
|
||||
decimals = decimals !== undefined ? decimals : 2;
|
||||
if (!bytes || bytes === 0) return '0 B';
|
||||
var k = 1024;
|
||||
var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
i = Math.min(i, sizes.length - 1);
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/* ── 6. Tailwind 统一配置(在 tailwind.config 未定义时注入)─ */
|
||||
/* 注意:各页面仍需自行在 tailwind.config 中声明 darkMode: 'class'
|
||||
本函数仅作为兼容性保底,不替代页面内的 tailwind.config 声明 */
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* FormComponents — 表单字段组件库(create/edit 左栏调色板)
|
||||
*
|
||||
* 用法:
|
||||
* <script src="/static/js/form-components.js"></script>
|
||||
* <script>
|
||||
* FormComponents.renderPalette(
|
||||
* document.getElementById('componentPalette'),
|
||||
* (type) => addField({ type }) // 点击组件时回调
|
||||
* );
|
||||
* </script>
|
||||
*
|
||||
* 组件瓦片可点击添加,也可拖拽:dragstart 写入
|
||||
* dataTransfer['application/x-field-type'] = type,
|
||||
* 由 create/edit 页面字段列表的 drop 事件读取(拖到指定位置插入)。
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
if (window.FormComponents) return;
|
||||
|
||||
const ICONS = {
|
||||
text: '<path d="M4 7V5h16v2M12 5v14M9 19h6"/>',
|
||||
textarea: '<path d="M4 6h16M4 10h16M4 14h10"/><rect x="3" y="3" width="18" height="18" rx="3" fill="none"/>',
|
||||
select: '<path d="M3 6h18M3 12h18M3 18h10"/><path d="M16 15l2 2 4-4"/>',
|
||||
radio: '<circle cx="12" cy="12" r="9" fill="none"/><circle cx="12" cy="12" r="4"/>',
|
||||
checkbox: '<rect x="3" y="3" width="18" height="18" rx="4" fill="none"/><path d="M8 12l3 3 5-6"/>',
|
||||
rating: '<path d="M12 3l2.7 5.5 6 .9-4.3 4.2 1 6-5.4-2.8L6.6 19.6l1-6L3.3 9.4l6-.9L12 3z"/>',
|
||||
number: '<path d="M6 5v14M18 5v14M6 12h12"/>',
|
||||
date: '<rect x="3" y="5" width="18" height="16" rx="2" fill="none"/><path d="M3 10h18M8 3v4M16 3v4"/>',
|
||||
time: '<circle cx="12" cy="12" r="9" fill="none"/><path d="M12 7v5l3 3"/>',
|
||||
file: '<path d="M12 16V4M12 4L8 8M12 4l4 4M4 17v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1"/>',
|
||||
slider: '<path d="M3 12h18"/><circle cx="9" cy="12" r="3" fill="none"/><circle cx="17" cy="12" r="3" fill="none"/>',
|
||||
page_break: '<rect x="3" y="4" width="18" height="6" rx="1.5"/><rect x="3" y="14" width="18" height="6" rx="1.5"/><path d="M12 10v4"/>',
|
||||
};
|
||||
|
||||
const CATALOG = [
|
||||
{ type: 'text', label: '文本', hint: '短文本输入' },
|
||||
{ type: 'textarea', label: '多行文本', hint: '长文本输入' },
|
||||
{ type: 'number', label: '数字', hint: '数字输入' },
|
||||
{ type: 'select', label: '下拉框', hint: '单选下拉' },
|
||||
{ type: 'radio', label: '单选', hint: '多个选项选一个' },
|
||||
{ type: 'checkbox', label: '多选', hint: '多个选项可多选' },
|
||||
{ type: 'date', label: '日期', hint: '日期选择' },
|
||||
{ type: 'time', label: '时间', hint: '时间选择' },
|
||||
{ type: 'rating', label: '评分', hint: '星级评分' },
|
||||
{ type: 'slider', label: '滑块', hint: '范围取值' },
|
||||
{ type: 'file', label: '文件上传', hint: '附件收集' },
|
||||
{ type: 'page_break', label: '分页', hint: '从这里开始新的一页' },
|
||||
];
|
||||
|
||||
const CSS = `
|
||||
.fc-palette { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
|
||||
@media (max-width: 480px) { .fc-palette { grid-template-columns: repeat(3, minmax(0,1fr)); } }
|
||||
.fc-tile {
|
||||
display: flex; flex-direction: column; align-items: center; gap: 6px;
|
||||
padding: 12px 6px 10px; border-radius: 12px; cursor: grab;
|
||||
border: 1px solid var(--border-color);
|
||||
background: transparent;
|
||||
width: 100%; color: var(--text-secondary); font: inherit; text-align: left;
|
||||
transition: border-color .18s ease, background-color .18s ease, transform .18s ease;
|
||||
user-select: none; -webkit-user-select: none;
|
||||
}
|
||||
.fc-tile:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
|
||||
.fc-tile:hover {
|
||||
border-color: var(--accent-bg, #6366f1);
|
||||
background: color-mix(in srgb, var(--accent-bg, #6366f1) 8%, transparent);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.fc-tile:active { cursor: grabbing; }
|
||||
.fc-tile svg { width: 20px; height: 20px; stroke: var(--text-secondary); fill: none;
|
||||
stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.fc-tile:hover svg { stroke: var(--accent-bg, #6366f1); }
|
||||
.fc-tile .fc-label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
|
||||
`;
|
||||
|
||||
function tileHtml(item) {
|
||||
return `
|
||||
<button type="button" class="fc-tile" draggable="true" data-field-type="${item.type}" title="${item.hint}"
|
||||
aria-label="${item.type === 'page_break' ? '插入分页控件' : `添加${item.label}字段`}">
|
||||
<svg viewBox="0 0 24 24">${ICONS[item.type] || ICONS.text}</svg>
|
||||
<span class="fc-label">${item.label}</span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
window.FormComponents = {
|
||||
CATALOG,
|
||||
|
||||
createPageBreakCard(fieldId, title, onRemove) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'field-card page-break-card';
|
||||
card.id = fieldId;
|
||||
card.innerHTML = `
|
||||
<div class="flex items-center justify-between gap-3 mb-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<button type="button" class="drag-handle" title="拖拽排序" aria-label="拖动以调整分页顺序">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<circle cx="9" cy="5" r="1"/><circle cx="9" cy="12" r="1"/><circle cx="9" cy="19" r="1"/>
|
||||
<circle cx="15" cy="5" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="19" r="1"/>
|
||||
</svg>
|
||||
</button>
|
||||
<span class="page-break-number page-break-label">分页</span>
|
||||
</div>
|
||||
<div class="field-card-actions flex items-center justify-end gap-2">
|
||||
<button type="button" class="page-break-remove btn-danger w-7 h-7 rounded-full flex items-center justify-center text-xs" aria-label="删除分页控件">×</button>
|
||||
</div>
|
||||
</div>
|
||||
<label class="block text-xs mb-2" style="color:var(--text-secondary)">下一页标题(可选)</label>
|
||||
<input type="text" class="field-edit-input page-title w-full" placeholder="例如:上传材料">
|
||||
<p class="text-xs mt-3" style="color:var(--text-muted)">填写者完成当前页后,点击“下一页”进入这里。</p>
|
||||
<input type="hidden" class="field-type" value="page_break">
|
||||
`;
|
||||
const input = card.querySelector('.page-title');
|
||||
input.id = `${fieldId}_page_title`;
|
||||
input.value = title || '';
|
||||
card.querySelector('label').htmlFor = input.id;
|
||||
card.querySelector('.page-break-remove').addEventListener('click', onRemove);
|
||||
return card;
|
||||
},
|
||||
|
||||
/* 渲染组件调色板。onAdd(type):点击组件回调;拖拽落位由字段列表处理。 */
|
||||
renderPalette(container, onAdd) {
|
||||
if (!container) return;
|
||||
if (!document.getElementById('fc-palette-style')) {
|
||||
const style = document.createElement('style');
|
||||
style.id = 'fc-palette-style';
|
||||
style.textContent = CSS;
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
container.classList.add('fc-palette');
|
||||
container.innerHTML = CATALOG.map(tileHtml).join('');
|
||||
|
||||
container.querySelectorAll('.fc-tile').forEach(tile => {
|
||||
const type = tile.dataset.fieldType;
|
||||
|
||||
tile.addEventListener('click', () => { if (onAdd) onAdd(type); });
|
||||
|
||||
tile.addEventListener('dragstart', (e) => {
|
||||
e.dataTransfer.setData('application/x-field-type', type);
|
||||
e.dataTransfer.setData('text/plain', 'fc:' + type);
|
||||
e.dataTransfer.effectAllowed = 'copy';
|
||||
tile.classList.add('fc-dragging');
|
||||
});
|
||||
tile.addEventListener('dragend', () => tile.classList.remove('fc-dragging'));
|
||||
});
|
||||
},
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,101 @@
|
||||
/* URL question numbers follow the displayed order; page breaks have no number. */
|
||||
(function () {
|
||||
'use strict';
|
||||
const supported = new Set(['text', 'textarea', 'number', 'select', 'radio', 'checkbox', 'date', 'time', 'rating', 'slider']);
|
||||
|
||||
function parse(fields, search) {
|
||||
const questions = fields.filter(field => field.type !== 'page_break');
|
||||
const params = new URLSearchParams(search);
|
||||
const locked = new Map();
|
||||
const hidden = new Set();
|
||||
const invalid = new Set();
|
||||
for (const key of new Set(params.keys())) {
|
||||
if (!/^[1-9]\d*$/.test(key)) continue;
|
||||
const field = questions[Number(key) - 1];
|
||||
if (!field || !supported.has(field.type)) continue;
|
||||
const values = params.getAll(key);
|
||||
let value = values[values.length - 1];
|
||||
if (['select', 'radio', 'checkbox'].includes(field.type)) {
|
||||
const options = (field.options || '').split(',').map(option => option.trim()).filter(Boolean);
|
||||
const selected = field.type === 'checkbox'
|
||||
? [...new Set(values.flatMap(item => item.split(',')).map(item => item.trim()).filter(Boolean))]
|
||||
: [value];
|
||||
if ((field.required && !selected.length) || selected.some(item => !options.includes(item))) {
|
||||
invalid.add(field.name);
|
||||
continue;
|
||||
}
|
||||
value = field.type === 'checkbox' ? selected : value;
|
||||
} else if (field.required && !value.trim()) {
|
||||
invalid.add(field.name);
|
||||
continue;
|
||||
}
|
||||
locked.set(field.name, { field, value });
|
||||
}
|
||||
for (const item of params.getAll('hidden').flatMap(value => value.split(','))) {
|
||||
const number = item.trim();
|
||||
if (!/^[1-9]\d*$/.test(number)) continue;
|
||||
const field = questions[Number(number) - 1];
|
||||
if (field) hidden.add(field.name);
|
||||
}
|
||||
return { locked, hidden, invalid };
|
||||
}
|
||||
|
||||
function apply(preset, getWrapper, hooks = {}) {
|
||||
const changed = [];
|
||||
for (const [name, entry] of preset.locked) {
|
||||
const { field } = entry;
|
||||
const wrapper = getWrapper(field);
|
||||
if (!wrapper) continue;
|
||||
const controls = [...wrapper.querySelectorAll('input, select, textarea')];
|
||||
const input = controls[0];
|
||||
let value = entry.value;
|
||||
if (hooks.normalize) value = hooks.normalize(field, value);
|
||||
let valid = input && value !== null;
|
||||
if (valid && ['radio', 'checkbox'].includes(field.type)) {
|
||||
for (const control of controls) {
|
||||
control.checked = field.type === 'checkbox' ? value.includes(control.value) : control.value === value;
|
||||
}
|
||||
} else if (valid) {
|
||||
const previous = input.value;
|
||||
input.value = value;
|
||||
valid = String(value) === input.value && input.validity.valid;
|
||||
if (field.type === 'rating') {
|
||||
const max = Number(field.ratingMax) === 10 ? 10 : 5;
|
||||
valid = value !== '' && Number.isInteger(Number(value)) && Number(value) >= (field.required ? 1 : 0) && Number(value) <= max;
|
||||
}
|
||||
if (!valid) input.value = previous;
|
||||
}
|
||||
if (!valid) {
|
||||
preset.locked.delete(name);
|
||||
preset.invalid.add(name);
|
||||
continue;
|
||||
}
|
||||
entry.value = value;
|
||||
wrapper.classList.add('url-prefilled');
|
||||
for (const control of controls) control.disabled = true;
|
||||
// Ratings are custom keyboard/pointer controls rather than native inputs.
|
||||
const rating = wrapper.querySelector('.rating-stars');
|
||||
if (rating) {
|
||||
rating.setAttribute('aria-disabled', 'true');
|
||||
rating.tabIndex = -1;
|
||||
hooks.rating?.(rating, value);
|
||||
}
|
||||
changed.push(...controls);
|
||||
}
|
||||
for (const name of preset.hidden) {
|
||||
const wrapper = getWrapper({ name });
|
||||
if (!wrapper) continue;
|
||||
wrapper.hidden = true;
|
||||
wrapper.dataset.urlHidden = 'true';
|
||||
for (const control of wrapper.querySelectorAll('input, select, textarea')) control.required = false;
|
||||
}
|
||||
// Apply all values before refreshing dependencies, identity and choice visuals.
|
||||
for (const control of changed) {
|
||||
if (control.type === 'radio' && !control.checked) continue;
|
||||
control.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
control.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
}
|
||||
|
||||
window.FormLinkPreset = { parse, apply };
|
||||
})();
|
||||
@@ -0,0 +1,709 @@
|
||||
/**
|
||||
* FormPreview v4 — 画布即编辑器(create/edit 右栏)
|
||||
*
|
||||
* 预览即真实填写页,且可直接在画布上编辑:
|
||||
* - 字段标题:点击直接改(同步到字段配置)
|
||||
* - 占位符:直接往输入框里打字,失焦后转为占位符
|
||||
* - 选项(单选/多选/下拉):就地增删改
|
||||
* - 字段工具条(悬停/选中出现):必填开关、条件显示、删除;左上角手柄拖拽排序
|
||||
* - 评分满分 / 滑块范围 / 文件格式:字段下方就地数值配置
|
||||
*
|
||||
* 数据仍存放在页面隐藏的 .field-card 编辑卡中(saveForm/populateForm 不变),
|
||||
* 画布与卡片双向同步;顺序以画布为权威(orderedFieldCards)。
|
||||
*
|
||||
* 用法:
|
||||
* FormPreview.init({
|
||||
* root, getMeta,
|
||||
* hooks: {
|
||||
* onDelete: (fieldId) => {}, // 画布删除字段
|
||||
* onCreateAt: (type, beforeId) => newId, // 调色板拖落创建,返回新卡 id
|
||||
* onConditional: (fieldId) => {}, // 打开条件显示配置
|
||||
* },
|
||||
* });
|
||||
* FormPreview.refresh(); / setSelected(id|null); / orderedFieldCards();
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
if (window.FormPreview) return;
|
||||
|
||||
let root = null;
|
||||
let getMeta = null;
|
||||
let hooks = null;
|
||||
let editable = false;
|
||||
let selectedId = null;
|
||||
let fieldOrder = null; // 画布权威字段顺序(id 数组)
|
||||
let debounceTimer = null;
|
||||
let dropLine = null;
|
||||
|
||||
function esc(s) {
|
||||
return String(s == null ? '' : s)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
/* ---------- 数据层:隐藏 field-card ↔ 画布 ---------- */
|
||||
|
||||
function rawFields() {
|
||||
const fields = [];
|
||||
document.querySelectorAll('.field-card').forEach(card => {
|
||||
const nameEl = card.querySelector('.field-name');
|
||||
const typeEl = card.querySelector('.field-type');
|
||||
if (!nameEl || !typeEl) return;
|
||||
const type = typeEl.value;
|
||||
const field = {
|
||||
id: card.id,
|
||||
type: type,
|
||||
name: nameEl.value.trim() || '未命名字段',
|
||||
placeholder: (card.querySelector('.field-placeholder') || {}).value || '',
|
||||
required: !!(card.querySelector('.field-required') || { checked: true }).checked,
|
||||
conditional: !!(card.querySelector('.field-show-when-field') || { value: '' }).value,
|
||||
};
|
||||
|
||||
if (['select', 'radio', 'checkbox'].includes(type)) {
|
||||
let options = (card.querySelector('.field-options-input') || {}).value || '';
|
||||
if (!options) {
|
||||
const optionInputs = card.querySelectorAll('.option-input');
|
||||
options = Array.from(optionInputs).map(i => i.value.trim()).filter(v => v).join(',');
|
||||
}
|
||||
field.options = options;
|
||||
}
|
||||
if (type === 'file') {
|
||||
let exts = (card.querySelector('.field-file-exts-combined') || {}).value || '';
|
||||
if (!exts) exts = (card.querySelector('.field-file-exts-input') || {}).value || '';
|
||||
field.exts = String(exts).split(/[,,\s]+/).map(s => s.replace(/^\./, '').trim())
|
||||
.filter(v => v && v !== '全部');
|
||||
}
|
||||
if (type === 'rating') {
|
||||
const rm = card.querySelector('.field-rating-max');
|
||||
field.ratingMax = Number(rm && rm.value) === 10 ? 10 : 5;
|
||||
}
|
||||
if (type === 'slider') {
|
||||
const g = cls => (card.querySelector(cls) || {}).value;
|
||||
field.sliderMin = g('.field-slider-min') || '0';
|
||||
field.sliderMax = g('.field-slider-max') || '100';
|
||||
field.sliderStep = g('.field-slider-step') || '1';
|
||||
}
|
||||
fields.push(field);
|
||||
});
|
||||
return fields;
|
||||
}
|
||||
|
||||
function collectFields() {
|
||||
const raw = rawFields();
|
||||
if (!fieldOrder) return raw;
|
||||
const byId = {};
|
||||
raw.forEach(f => { byId[f.id] = f; });
|
||||
const ordered = fieldOrder.map(id => byId[id]).filter(Boolean);
|
||||
raw.forEach(f => { if (!fieldOrder.includes(f.id)) ordered.push(f); });
|
||||
return ordered;
|
||||
}
|
||||
|
||||
function reconcileOrder() {
|
||||
const ids = rawFields().map(f => f.id);
|
||||
if (!fieldOrder) { fieldOrder = ids.slice(); return; }
|
||||
const kept = fieldOrder.filter(id => ids.includes(id));
|
||||
ids.forEach(id => { if (!kept.includes(id)) kept.push(id); });
|
||||
fieldOrder = kept;
|
||||
}
|
||||
|
||||
function insertIntoOrder(id, beforeId) {
|
||||
reconcileOrder();
|
||||
fieldOrder = fieldOrder.filter(x => x !== id);
|
||||
const idx = beforeId ? fieldOrder.indexOf(beforeId) : -1;
|
||||
if (idx >= 0) fieldOrder.splice(idx, 0, id);
|
||||
else fieldOrder.push(id);
|
||||
}
|
||||
|
||||
/* 写回隐藏编辑卡 */
|
||||
function writeCard(id, fn) {
|
||||
const card = document.getElementById(id);
|
||||
if (card) fn(card);
|
||||
}
|
||||
function setName(id, v) { writeCard(id, c => { c.querySelector('.field-name').value = v; }); }
|
||||
function setPlaceholder(id, v) { writeCard(id, c => { const el = c.querySelector('.field-placeholder'); if (el) el.value = v; }); }
|
||||
function setRequired(id, v) { writeCard(id, c => { const el = c.querySelector('.field-required'); if (el) el.checked = v; }); }
|
||||
function setOptions(id, v) { writeCard(id, c => { const el = c.querySelector('.field-options-input'); if (el) el.value = v; }); }
|
||||
function setExts(id, v) { writeCard(id, c => { const el = c.querySelector('.field-file-exts-combined'); if (el) el.value = v; }); }
|
||||
|
||||
/* ---------- 渲染层 ---------- */
|
||||
|
||||
const INPUT_CLS = 'w-full bg-transparent border-b py-3 text-sm';
|
||||
|
||||
function renderControl(field, meta) {
|
||||
switch (field.type) {
|
||||
case 'select': {
|
||||
const opts = (field.options || '').split(',').map(o => o.trim()).filter(Boolean);
|
||||
return `
|
||||
<select disabled class="${INPUT_CLS} appearance-none" style="color: var(--text-primary); border-bottom: 1px solid var(--border-color);">
|
||||
<option>请选择...</option>
|
||||
${opts.map(o => `<option>${esc(o)}</option>`).join('')}
|
||||
</select>
|
||||
${optionsEditor(field)}`;
|
||||
}
|
||||
case 'textarea':
|
||||
return `<textarea data-fp-ph rows="3" class="w-full border rounded-xl p-4 resize-none text-sm leading-relaxed" style="background: var(--input-bg, var(--bg-primary)); color: var(--text-primary); border-color: var(--border-color);" placeholder="${esc(field.placeholder || '点击输入占位提示...')}">${esc(field.__typed || '')}</textarea>`;
|
||||
case 'radio':
|
||||
case 'checkbox':
|
||||
return optionsAsPreview(field);
|
||||
case 'file': {
|
||||
const exts = field.exts && field.exts.length ? field.exts.join(', ') : '';
|
||||
const sizeHint = meta.maxSizeMB ? `单个不超过 ${meta.maxSizeMB}MB` : '';
|
||||
return `<div class="border-2 border-dashed rounded-xl p-6 text-center" style="border-color: var(--border-color); pointer-events: none;">
|
||||
<div class="mb-2" style="color: var(--text-muted);">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" class="mx-auto">
|
||||
<path d="M12 16V4M12 4L8 8M12 4L16 8M4 17V18C4 19.1046 4.89543 20 6 20H18C19.1046 20 20 19.1046 20 18V17"/>
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-xs" style="color: var(--text-secondary);">点击或拖拽上传文件</p>
|
||||
<p class="text-[10px] mt-1" style="color: var(--text-muted);">支持格式: ${esc(exts || '所有文件')}${sizeHint ? ' · ' + esc(sizeHint) : ''}</p>
|
||||
</div>
|
||||
<div class="fp-config-row">
|
||||
<span class="fp-config-lb">格式</span>
|
||||
<input type="text" data-fp-exts class="fp-config-input" value="${esc(exts)}" placeholder="如 jpg, png, pdf(留空不限制)">
|
||||
</div>`;
|
||||
}
|
||||
case 'rating': {
|
||||
const max = Number(field.ratingMax) === 10 ? 10 : 5;
|
||||
return `<div class="flex items-center gap-4 flex-wrap">
|
||||
<div class="flex gap-1.5" style="pointer-events: none;">
|
||||
${Array.from({ length: 5 }, () => `<svg width="26" height="26" viewBox="0 0 24 24" fill="none" style="color: var(--text-muted); opacity:.55;"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
<div class="fp-config-row">
|
||||
<span class="fp-config-lb">满分</span>
|
||||
<select data-fp-rmax class="fp-config-input" style="max-width:100px;">
|
||||
<option value="5" ${max === 5 ? 'selected' : ''}>5 分</option>
|
||||
<option value="10" ${max === 10 ? 'selected' : ''}>10 分</option>
|
||||
</select>
|
||||
<span class="text-xs" style="color: var(--text-muted);">分(点星评分)</span>
|
||||
</div>`;
|
||||
}
|
||||
case 'slider': {
|
||||
const min = parseFloat(field.sliderMin) || 0;
|
||||
const max = parseFloat(field.sliderMax) || 100;
|
||||
const mid = (min + max) / 2;
|
||||
const pct = (mid - min) / (max - min || 1) * 50;
|
||||
return `<div class="flex items-center gap-4" style="pointer-events: none;">
|
||||
<div class="flex-1 h-1.5 rounded-full relative" style="background: var(--border-color);">
|
||||
<div class="absolute h-1.5 rounded-full left-0" style="width:${pct}%; background: var(--accent-bg, #6366f1);"></div>
|
||||
<div class="absolute w-4 h-4 rounded-full -top-[5px] shadow" style="left:calc(${pct}% - 8px); background: var(--accent-bg, #6366f1);"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fp-config-row">
|
||||
<span class="fp-config-lb">范围</span>
|
||||
<input type="number" data-fp-smin class="fp-config-input" style="max-width:76px;" value="${min}">
|
||||
<span class="text-xs" style="color: var(--text-muted);">至</span>
|
||||
<input type="number" data-fp-smax class="fp-config-input" style="max-width:76px;" value="${max}">
|
||||
<span class="text-xs" style="color: var(--text-muted);">步长</span>
|
||||
<input type="number" data-fp-sstep class="fp-config-input" style="max-width:76px;" value="${esc(field.sliderStep || '1')}">
|
||||
</div>`;
|
||||
}
|
||||
case 'date':
|
||||
return `<input type="date" disabled class="${INPUT_CLS}" style="color: var(--text-primary); border-bottom: 1px solid var(--border-color);">`;
|
||||
case 'time':
|
||||
return `<input type="time" disabled class="${INPUT_CLS}" style="color: var(--text-primary); border-bottom: 1px solid var(--border-color);">`;
|
||||
default:
|
||||
// 文本/数字:直接打字编辑占位符
|
||||
return `<input type="text" data-fp-ph inputmode="${field.type === 'number' ? 'numeric' : 'text'}" class="${INPUT_CLS}" style="color: var(--text-primary); border-bottom: 1px solid var(--border-color);" placeholder="${esc(field.placeholder || '点击输入占位提示...')}">`;
|
||||
}
|
||||
}
|
||||
|
||||
/* 选项就地编辑:radio/checkbox 直接以选项预览形态呈现 */
|
||||
function optionsAsPreview(field) {
|
||||
const opts = (field.options || '').split(',').map(o => o.trim()).filter(Boolean);
|
||||
const row = (o) => {
|
||||
const mark = field.type === 'checkbox'
|
||||
? `<span class="fp-opt-mark" style="border-radius:6px;"></span>`
|
||||
: `<span class="fp-opt-mark" style="border-radius:50%;"></span>`;
|
||||
return `<label class="inline-flex items-center gap-2.5 text-sm fp-opt" style="color: var(--text-primary); position:relative; padding:8px; margin:-8px; border-radius:8px;">
|
||||
${mark}<span class="fp-opt-text" contenteditable="true" data-fp-opt>${esc(o)}</span>
|
||||
<button type="button" class="fp-opt-del" data-fp-opt-del title="删除选项">
|
||||
<svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.4" stroke-linecap="round"><path d="M18 6L6 18M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</label>`;
|
||||
};
|
||||
return `<div class="flex flex-wrap gap-3 mt-1" data-fp-opts>${opts.map(row).join('') || '<span class="text-xs" style="color: var(--text-muted);">暂无选项</span>'}
|
||||
<button type="button" class="fp-opt-add" data-fp-opt-add>+ 选项</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
/* 下拉的选项编辑行 */
|
||||
function optionsEditor(field) {
|
||||
const opts = (field.options || '').split(',').map(o => o.trim()).filter(Boolean);
|
||||
return `<div class="flex flex-wrap gap-2 mt-3" data-fp-opts>
|
||||
${opts.map(o => `<span class="fp-opt-chip">
|
||||
<span class="fp-opt-text" contenteditable="true" data-fp-opt>${esc(o)}</span>
|
||||
<button type="button" class="fp-opt-del" data-fp-opt-del title="删除选项">
|
||||
<svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.4" stroke-linecap="round"><path d="M18 6L6 18M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</span>`).join('')}
|
||||
<button type="button" class="fp-opt-add" data-fp-opt-add>+ 选项</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderField(field, meta, index) {
|
||||
const onCanvas = editable && !!field.id;
|
||||
let chrome = '';
|
||||
if (onCanvas) {
|
||||
chrome = `
|
||||
<span class="fp-num">${index + 1}</span>
|
||||
<span class="fp-handle" title="拖拽排序" draggable="true">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<circle cx="9" cy="5" r="1.6"/><circle cx="15" cy="5" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="19" r="1.6"/><circle cx="15" cy="19" r="1.6"/>
|
||||
</svg>
|
||||
</span>
|
||||
<div class="fp-toolbar">
|
||||
<button type="button" class="fp-chip ${field.required ? 'fp-chip-on' : ''}" data-fp-act="required" title="切换必填">✱ 必填</button>
|
||||
<button type="button" class="fp-chip ${field.conditional ? 'fp-chip-on' : ''}" data-fp-act="conditional" title="条件显示">◇ 条件</button>
|
||||
<button type="button" class="fp-chip fp-chip-danger" data-fp-act="delete" title="删除字段">✕</button>
|
||||
</div>`;
|
||||
}
|
||||
const selCls = onCanvas && field.id === selectedId ? ' fp-selected' : '';
|
||||
const optionalTag = (!field.required) ? ' <span class="fp-tag-optional">(选填)</span>' : '';
|
||||
return `<div class="fp-field${selCls}" ${onCanvas ? `data-fp-id="${field.id}"` : ''}>
|
||||
${chrome}
|
||||
<div class="fp-label-line">
|
||||
<label class="block text-[15px] font-semibold tracking-[0.12em] uppercase mb-2" style="color: var(--text-primary);">
|
||||
<span class="fp-label-text" ${onCanvas ? 'contenteditable="true" data-fp-name' : ''}>${esc(field.name)}</span>${optionalTag}
|
||||
</label>
|
||||
</div>
|
||||
<div class="fp-control">${renderControl(field, meta)}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderProgress(meta) {
|
||||
if (!meta.showProgress) return '';
|
||||
const body = meta.anonymous
|
||||
? `<p class="text-sm" style="color: var(--text-secondary);">已收集 <span style="color: var(--text-primary); font-weight:600;">0</span> 份提交</p>`
|
||||
: `<p class="text-sm" style="color: var(--text-secondary);">等待大家提交…</p>`;
|
||||
return `<div class="rounded-2xl p-4 mb-6" style="background: var(--bg-primary, transparent); border: 1px solid var(--border-color);">
|
||||
<p class="text-[11px] font-semibold tracking-[0.2em] uppercase mb-2" style="color: var(--text-muted);">完成情况</p>
|
||||
<div class="h-1.5 rounded-full overflow-hidden mb-2" style="background: var(--border-color);">
|
||||
<div style="width:0%; height:100%; background: var(--accent-bg, #6366f1);"></div>
|
||||
</div>
|
||||
${body}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function render(meta) {
|
||||
if (!root) return;
|
||||
const fields = collectFields();
|
||||
|
||||
const rosterFields = [];
|
||||
if (!meta.anonymous) {
|
||||
const digits = meta.verifyDigits || '2';
|
||||
rosterFields.push({ id: null, name: 'tail', type: 'number', required: true, placeholder: `学号后${digits}位` });
|
||||
rosterFields.push({ id: null, name: 'name', type: 'text', required: true, placeholder: '请输入学号自动获取姓名' });
|
||||
}
|
||||
|
||||
const onceHint = meta.once
|
||||
? `<p class="text-xs text-center mb-3" style="color: var(--warning-text, #b45309);">⚠ 此表单仅允许提交一次,提交后不能再修改,请确认填写无误后再提交。</p>`
|
||||
: '';
|
||||
|
||||
let fieldIndex = 0;
|
||||
const fieldHtml = (list) => list.map(f => renderField(f, meta, f.id ? fieldIndex++ : 0)).join('');
|
||||
|
||||
root.innerHTML = `
|
||||
<div class="fp-head px-7 pt-7 pb-5">
|
||||
<h1 class="text-2xl font-bold tracking-wide" style="color: var(--text-primary);">${esc(meta.title || '未命名表单')}</h1>
|
||||
<p class="text-xs mt-2" style="color: var(--text-muted);">请填写以下信息完成提交。所有字段经过加密处理。</p>
|
||||
</div>
|
||||
<div class="fp-body px-7 pb-8">
|
||||
${(meta.subtitle || meta.announcementText) ? `
|
||||
<div class="rounded-2xl p-4 mb-6" style="background: var(--bg-primary, transparent); border: 1px solid var(--border-color);">
|
||||
${meta.subtitle ? `<p class="text-sm font-semibold mb-1" style="color: var(--text-primary);">${esc(meta.subtitle)}</p>` : ''}
|
||||
${meta.announcementText ? `<p class="text-xs leading-relaxed whitespace-pre-wrap" style="color: var(--text-secondary);">${esc(meta.announcementText)}</p>` : ''}
|
||||
</div>` : ''}
|
||||
${renderProgress(meta)}
|
||||
<div class="space-y-7 fp-fields">
|
||||
${fieldHtml(rosterFields)}
|
||||
${fieldHtml(fields)}
|
||||
${fields.length === 0 && meta.anonymous ? '<p class="text-xs text-center py-6" style="color: var(--text-muted);">从左侧组件库添加字段,或直接把组件拖到这里</p>' : ''}
|
||||
</div>
|
||||
<div class="pt-8 fp-tail">
|
||||
${onceHint}
|
||||
<button type="button" disabled class="w-full py-4 px-8 rounded-full font-medium text-sm opacity-90" style="background: var(--accent-bg); color: var(--accent-text);">
|
||||
提交表单
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (editable) wireCanvas();
|
||||
}
|
||||
|
||||
/* ---------- 画布交互 ---------- */
|
||||
|
||||
const CANVAS_CSS = `
|
||||
.fp-field {
|
||||
position: relative; border: 1px dashed transparent; border-radius: 14px;
|
||||
padding: 14px 14px 10px; margin: -1px;
|
||||
transition: border-color .15s ease, background-color .15s ease;
|
||||
}
|
||||
.fp-field:hover { border-color: var(--border-color); }
|
||||
.fp-field.fp-selected {
|
||||
border-color: var(--accent-bg, #6366f1);
|
||||
background: color-mix(in srgb, var(--accent-bg, #6366f1) 6%, transparent);
|
||||
}
|
||||
.fp-field .fp-handle {
|
||||
position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
|
||||
width: 32px; height: 32px; border-radius: 10px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: var(--bg-primary, #fff); border: 1px solid var(--border-color);
|
||||
color: var(--text-secondary); box-shadow: 0 2px 10px rgba(0,0,0,.14);
|
||||
opacity: 0; cursor: grab; transition: opacity .15s ease, border-color .15s ease, color .15s ease;
|
||||
z-index: 3;
|
||||
}
|
||||
.fp-handle svg { width: 18px; height: 18px; }
|
||||
.fp-handle:hover { border-color: var(--accent-bg, #6366f1); color: var(--accent-bg, #6366f1); }
|
||||
.fp-field:hover .fp-handle, .fp-field.fp-selected .fp-handle { opacity: 1; }
|
||||
/* 手柄出现时内容右移让位,不遮标题 */
|
||||
.fp-field { padding-left: 14px; }
|
||||
.fp-field:hover, .fp-field.fp-selected { padding-left: 50px; }
|
||||
.fp-field .fp-num {
|
||||
position: absolute; right: 12px; top: 10px; font-size: 10px; font-weight: 600;
|
||||
color: var(--text-muted); opacity: 0; transition: opacity .15s ease;
|
||||
min-width: 18px; text-align: center;
|
||||
}
|
||||
.fp-field:hover .fp-num, .fp-field.fp-selected .fp-num { opacity: .7; }
|
||||
.fp-field.fp-dragging { opacity: .45; }
|
||||
|
||||
.fp-toolbar {
|
||||
position: absolute; right: 8px; top: -12px; display: flex; gap: 4px;
|
||||
opacity: 0; transition: opacity .15s ease; z-index: 3;
|
||||
}
|
||||
.fp-field:hover .fp-toolbar, .fp-field.fp-selected .fp-toolbar { opacity: 1; }
|
||||
.fp-chip {
|
||||
font-size: 10px; padding: 3px 8px; border-radius: 999px; cursor: pointer;
|
||||
border: 1px solid var(--border-color); background: var(--bg-primary, #fff);
|
||||
color: var(--text-secondary); line-height: 1.2;
|
||||
box-shadow: 0 1px 6px rgba(0,0,0,.08);
|
||||
transition: all .15s ease;
|
||||
}
|
||||
.fp-chip:hover { border-color: var(--accent-bg, #6366f1); color: var(--accent-bg, #6366f1); }
|
||||
.fp-chip-on { background: var(--accent-bg, #6366f1); border-color: var(--accent-bg, #6366f1); color: #fff; }
|
||||
.fp-chip-danger:hover { border-color: #dc2626; color: #dc2626; }
|
||||
|
||||
.fp-label-text { outline: none; border-bottom: 1px dashed transparent; min-width: 30px; display: inline-block; }
|
||||
.fp-field:hover .fp-label-text, .fp-field.fp-selected .fp-label-text { border-bottom-color: var(--border-color); }
|
||||
.fp-label-text:focus { border-bottom-color: var(--accent-bg, #6366f1); }
|
||||
.fp-label-text:empty::before { content: '未命名字段'; color: var(--text-muted); }
|
||||
.fp-tag-optional { color: var(--text-muted); font-weight: 400; }
|
||||
|
||||
.fp-config-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
|
||||
.fp-config-lb { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
|
||||
.fp-config-input {
|
||||
font-size: 12px; padding: 4px 8px; border-radius: 8px; outline: none;
|
||||
border: 1px solid var(--border-color); background: var(--input-bg, transparent);
|
||||
color: var(--text-primary); width: 220px; max-width: 60%;
|
||||
}
|
||||
.fp-config-input:focus { border-color: var(--accent-bg, #6366f1); }
|
||||
|
||||
.fp-opt { position: relative; }
|
||||
.fp-opt-mark { width: 22px; height: 22px; border: 2px solid var(--border-color); flex-shrink: 0;
|
||||
display: inline-flex; align-items: center; justify-content: center; }
|
||||
.fp-opt-text { outline: none; border-bottom: 1px dashed transparent; min-width: 16px; }
|
||||
.fp-opt-text:focus { border-bottom-color: var(--accent-bg, #6366f1); }
|
||||
.fp-opt .fp-opt-del {
|
||||
position: absolute; right: -4px; top: -2px; width: 16px; height: 16px; border-radius: 50%;
|
||||
background: rgba(220,38,38,.9); color: #fff; display: none;
|
||||
align-items: center; justify-content: center; cursor: pointer;
|
||||
}
|
||||
.fp-opt:hover .fp-opt-del { display: flex; }
|
||||
.fp-opt-chip {
|
||||
display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
|
||||
padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border-color);
|
||||
color: var(--text-primary); position: relative;
|
||||
}
|
||||
.fp-opt-chip .fp-opt-del {
|
||||
width: 14px; height: 14px; border-radius: 50%; background: rgba(220,38,38,.9);
|
||||
color: #fff; display: none; align-items: center; justify-content: center; cursor: pointer;
|
||||
}
|
||||
.fp-opt-chip:hover .fp-opt-del { display: flex; }
|
||||
.fp-opt-add {
|
||||
align-self: center; font-size: 11px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
|
||||
border: 1px dashed var(--border-color); color: var(--text-muted); background: transparent;
|
||||
transition: all .15s ease;
|
||||
}
|
||||
.fp-opt-add:hover { border-color: var(--accent-bg, #6366f1); color: var(--accent-bg, #6366f1); }
|
||||
|
||||
.fp-field.fp-drop-target { border-color: var(--accent-bg, #6366f1); }
|
||||
.fp-drop-line {
|
||||
height: 3px; border-radius: 3px; background: var(--accent-bg, #6366f1);
|
||||
box-shadow: 0 0 10px color-mix(in srgb, var(--accent-bg, #6366f1) 60%, transparent);
|
||||
margin: 6px 0; position: relative;
|
||||
}
|
||||
.fp-drop-line::before {
|
||||
content: ''; position: absolute; left: -5px; top: -3.5px; width: 10px; height: 10px;
|
||||
border-radius: 50%; background: var(--accent-bg, #6366f1);
|
||||
}
|
||||
`;
|
||||
|
||||
function wireCanvas() {
|
||||
if (root.__fpWired) return;
|
||||
root.__fpWired = true;
|
||||
|
||||
/* 点击:工具条动作 / 选中 / 空白取消 */
|
||||
root.addEventListener('click', (e) => {
|
||||
const act = e.target.closest('[data-fp-act]');
|
||||
if (act) {
|
||||
const fieldEl = act.closest('.fp-field[data-fp-id]');
|
||||
const id = fieldEl && fieldEl.dataset.fpId;
|
||||
const action = act.dataset.fpAct;
|
||||
if (action === 'delete') {
|
||||
if (selectedId === id) setSelected(null);
|
||||
if (hooks.onDelete) hooks.onDelete(id);
|
||||
return;
|
||||
}
|
||||
if (action === 'required') {
|
||||
const card = document.getElementById(id);
|
||||
const cb = card && card.querySelector('.field-required');
|
||||
const next = cb ? !cb.checked : false;
|
||||
setRequired(id, next);
|
||||
act.classList.toggle('fp-chip-on', next);
|
||||
const tag = fieldEl.querySelector('.fp-tag-optional');
|
||||
if (tag) tag.style.display = next ? 'none' : '';
|
||||
return;
|
||||
}
|
||||
if (action === 'conditional') {
|
||||
if (hooks.onConditional) hooks.onConditional(id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.target.closest('.fp-drawer, .fp-toolbar, .fp-config-row, [data-fp-opts], [contenteditable]')) return;
|
||||
const fieldEl = e.target.closest('.fp-field[data-fp-id]');
|
||||
if (fieldEl) {
|
||||
setSelected(fieldEl.dataset.fpId);
|
||||
if (hooks.onSelect) hooks.onSelect(fieldEl.dataset.fpId);
|
||||
} else if (selectedId) {
|
||||
setSelected(null);
|
||||
if (hooks.onSelect) hooks.onSelect(null);
|
||||
}
|
||||
});
|
||||
|
||||
/* 输入:标题 / 占位符 / 选项 / 数值配置 → 写回隐藏编辑卡 */
|
||||
root.addEventListener('input', (e) => {
|
||||
const fieldEl = e.target.closest('.fp-field[data-fp-id]');
|
||||
if (!fieldEl) return;
|
||||
const id = fieldEl.dataset.fpId;
|
||||
const t = e.target;
|
||||
|
||||
if (t.matches('[data-fp-name]')) {
|
||||
setName(id, t.textContent.replace(/\n/g, ''));
|
||||
} else if (t.matches('[data-fp-ph]')) {
|
||||
setPlaceholder(id, t.value);
|
||||
t.placeholder = t.value || '点击输入占位提示...';
|
||||
} else if (t.matches('[data-fp-opt]')) {
|
||||
syncOptions(fieldEl, id);
|
||||
} else if (t.matches('[data-fp-exts]')) {
|
||||
setExts(id, t.value);
|
||||
const p = fieldEl.querySelector('.fp-control p.text-\\[10px\\]');
|
||||
if (p) p.textContent = '支持格式: ' + (t.value.trim() || '所有文件');
|
||||
} else if (t.matches('[data-fp-rmax]')) {
|
||||
writeCard(id, c => { const el = c.querySelector('.field-rating-max'); if (el) el.value = t.value; });
|
||||
} else if (t.matches('[data-fp-smin]')) {
|
||||
writeCard(id, c => { const el = c.querySelector('.field-slider-min'); if (el) el.value = t.value; });
|
||||
} else if (t.matches('[data-fp-smax]')) {
|
||||
writeCard(id, c => { const el = c.querySelector('.field-slider-max'); if (el) el.value = t.value; });
|
||||
} else if (t.matches('[data-fp-sstep]')) {
|
||||
writeCard(id, c => { const el = c.querySelector('.field-slider-step'); if (el) el.value = t.value; });
|
||||
}
|
||||
});
|
||||
|
||||
/* 占位符失焦:把输入值转为占位符展示(预览即真实效果) */
|
||||
root.addEventListener('focusout', (e) => {
|
||||
if (e.target.matches && e.target.matches('[data-fp-ph]')) {
|
||||
e.target.placeholder = e.target.value || '点击输入占位提示...';
|
||||
e.target.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
/* contenteditable 回车提交、粘贴纯文本 */
|
||||
root.addEventListener('keydown', (e) => {
|
||||
if (e.target.matches && (e.target.matches('[data-fp-name], [data-fp-opt]')) && e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
e.target.blur();
|
||||
}
|
||||
});
|
||||
root.addEventListener('paste', (e) => {
|
||||
const t = e.target;
|
||||
if (t.matches && t.matches('[data-fp-name], [data-fp-opt]')) {
|
||||
e.preventDefault();
|
||||
const text = (e.clipboardData || window.clipboardData).getData('text').replace(/\n+/g, ' ');
|
||||
document.execCommand('insertText', false, text);
|
||||
}
|
||||
});
|
||||
|
||||
/* 选项增删 */
|
||||
root.addEventListener('click', (e) => {
|
||||
const add = e.target.closest('[data-fp-opt-add]');
|
||||
if (add) {
|
||||
const box = add.closest('[data-fp-opts]');
|
||||
const fieldEl = add.closest('.fp-field[data-fp-id]');
|
||||
const chip = document.createElement('span');
|
||||
chip.className = box.classList.contains('flex-wrap') && box.querySelector('.fp-opt-mark') ? 'inline-flex items-center gap-2.5 text-sm fp-opt' : 'fp-opt-chip';
|
||||
if (box.querySelector('.fp-opt-mark')) {
|
||||
const mark = document.createElement('span');
|
||||
mark.className = 'fp-opt-mark';
|
||||
mark.style.cssText = box.querySelector('.fp-opt-mark').style.cssText;
|
||||
chip.appendChild(mark);
|
||||
}
|
||||
const txt = document.createElement('span');
|
||||
txt.className = 'fp-opt-text';
|
||||
txt.setAttribute('contenteditable', 'true');
|
||||
txt.setAttribute('data-fp-opt', '');
|
||||
chip.appendChild(txt);
|
||||
chip.insertAdjacentHTML('beforeend', '<button type="button" class="fp-opt-del" data-fp-opt-del title="删除选项"><svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3.4" stroke-linecap="round"><path d="M18 6L6 18M6 6l12 12"/></svg></button>');
|
||||
box.insertBefore(chip, add);
|
||||
txt.focus();
|
||||
syncOptions(fieldEl, fieldEl.dataset.fpId);
|
||||
return;
|
||||
}
|
||||
const del = e.target.closest('[data-fp-opt-del]');
|
||||
if (del) {
|
||||
e.stopPropagation();
|
||||
const fieldEl = del.closest('.fp-field[data-fp-id]');
|
||||
const chip = del.closest('.fp-opt, .fp-opt-chip');
|
||||
if (chip) chip.remove();
|
||||
if (fieldEl) syncOptions(fieldEl, fieldEl.dataset.fpId);
|
||||
}
|
||||
});
|
||||
|
||||
/* 拖拽:手柄拖动排序 + 调色板落位 */
|
||||
root.addEventListener('dragstart', (e) => {
|
||||
const handle = e.target.closest('.fp-handle');
|
||||
if (!handle) { e.preventDefault(); return; }
|
||||
const fieldEl = handle.closest('.fp-field[data-fp-id]');
|
||||
if (!fieldEl) return;
|
||||
e.dataTransfer.setData('application/x-fp-field', fieldEl.dataset.fpId);
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
fieldEl.classList.add('fp-dragging');
|
||||
});
|
||||
root.addEventListener('dragend', (e) => {
|
||||
const fieldEl = e.target.closest && e.target.closest('.fp-field[data-fp-id]');
|
||||
if (fieldEl) fieldEl.classList.remove('fp-dragging');
|
||||
removeDropLine();
|
||||
});
|
||||
|
||||
root.addEventListener('dragover', (e) => {
|
||||
if (!isRelevantDrag(e)) return;
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = isMoveDrag(e) ? 'move' : 'copy';
|
||||
showDropLine(computeBeforeId(e.clientY));
|
||||
});
|
||||
root.addEventListener('dragleave', (e) => {
|
||||
if (e.target === root || !root.contains(e.relatedTarget)) removeDropLine();
|
||||
});
|
||||
root.addEventListener('drop', (e) => {
|
||||
if (!isRelevantDrag(e)) return;
|
||||
e.preventDefault();
|
||||
const beforeId = computeBeforeId(e.clientY);
|
||||
removeDropLine();
|
||||
|
||||
const newType = e.dataTransfer.getData('application/x-field-type');
|
||||
if (newType) {
|
||||
const newId = hooks.onCreateAt ? hooks.onCreateAt(newType, beforeId) : null;
|
||||
if (newId) insertIntoOrder(newId, beforeId);
|
||||
window.FormPreview.refresh();
|
||||
return;
|
||||
}
|
||||
const movedId = e.dataTransfer.getData('application/x-fp-field');
|
||||
if (movedId) {
|
||||
insertIntoOrder(movedId, beforeId);
|
||||
window.FormPreview.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function syncOptions(fieldEl, id) {
|
||||
const chips = Array.from(fieldEl.querySelectorAll('[data-fp-opt]'))
|
||||
.map(s => s.textContent.trim()).filter(Boolean);
|
||||
setOptions(id, chips.join(','));
|
||||
}
|
||||
|
||||
function isMoveDrag(e) { return Array.from(e.dataTransfer.types || []).includes('application/x-fp-field'); }
|
||||
function isRelevantDrag(e) {
|
||||
const t = Array.from(e.dataTransfer.types || []);
|
||||
return t.includes('application/x-field-type') || t.includes('application/x-fp-field');
|
||||
}
|
||||
|
||||
function computeBeforeId(clientY) {
|
||||
const els = Array.from(root.querySelectorAll('.fp-field[data-fp-id]'))
|
||||
.filter(el => el !== root.querySelector('.fp-field.fp-dragging'));
|
||||
for (const el of els) {
|
||||
const r = el.getBoundingClientRect();
|
||||
if (clientY < r.top + r.height / 2) return el.dataset.fpId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function showDropLine(beforeId) {
|
||||
removeDropLine();
|
||||
dropLine = document.createElement('div');
|
||||
dropLine.className = 'fp-drop-line';
|
||||
const anchor = beforeId ? root.querySelector(`.fp-field[data-fp-id="${beforeId}"]`) : null;
|
||||
const fieldsBox = root.querySelector('.fp-fields');
|
||||
const tailBox = root.querySelector('.fp-tail');
|
||||
if (anchor) fieldsBox.insertBefore(dropLine, anchor);
|
||||
else if (tailBox) tailBox.insertBefore(dropLine, tailBox.firstChild);
|
||||
else fieldsBox.appendChild(dropLine);
|
||||
}
|
||||
function removeDropLine() {
|
||||
if (dropLine && dropLine.parentNode) dropLine.parentNode.removeChild(dropLine);
|
||||
dropLine = null;
|
||||
}
|
||||
|
||||
/* ---------- 对外 API ---------- */
|
||||
|
||||
window.FormPreview = {
|
||||
init(options) {
|
||||
root = options.root;
|
||||
getMeta = options.getMeta || (() => ({}));
|
||||
hooks = options.hooks || null;
|
||||
editable = !!(hooks && (hooks.onDelete || hooks.onCreateAt || hooks.onConditional));
|
||||
if (editable && !document.getElementById('fp-canvas-style')) {
|
||||
const style = document.createElement('style');
|
||||
style.id = 'fp-canvas-style';
|
||||
style.textContent = CANVAS_CSS;
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
// 左栏基础配置变化 → 整画布刷新(标题/公告/名单模式/策略等)
|
||||
const debouncedFull = () => {
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => this.refresh(), 150);
|
||||
};
|
||||
document.addEventListener('input', (e) => {
|
||||
if (e.target.closest('.field-card')) return; // 卡片数据由画布编辑直接写回,不触发整刷
|
||||
if (e.target.closest('#formTitle, #announcementSubtitle, #announcementText, #verifyDigits, #maxSize')) debouncedFull();
|
||||
});
|
||||
document.addEventListener('change', (e) => {
|
||||
if (e.target.closest('.field-card')) return;
|
||||
if (e.target.closest('#showProgress, #verifyDigits, #maxSize')) debouncedFull();
|
||||
});
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
refresh() {
|
||||
if (!root || !getMeta) return;
|
||||
if (selectedId && !document.getElementById(selectedId)) selectedId = null; // 字段已删
|
||||
reconcileOrder();
|
||||
render(getMeta());
|
||||
},
|
||||
|
||||
setSelected(id) {
|
||||
selectedId = id || null;
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
/* 按画布顺序返回 .field-card 元素(保存/枚举的权威顺序) */
|
||||
orderedFieldCards() {
|
||||
const all = Array.from(document.querySelectorAll('.field-card'));
|
||||
if (!root || !editable) return all;
|
||||
const ids = Array.from(root.querySelectorAll('.fp-field[data-fp-id]')).map(el => el.dataset.fpId);
|
||||
const ordered = ids.map(id => document.getElementById(id)).filter(Boolean);
|
||||
all.forEach(c => { if (!ids.includes(c.id)) ordered.push(c); });
|
||||
return ordered;
|
||||
},
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,45 @@
|
||||
// CDN unavailable: keep form controls functional and show the final motion state.
|
||||
(function () {
|
||||
if (window.gsap) return;
|
||||
|
||||
function elements(target) {
|
||||
if (typeof target === 'string') return document.querySelectorAll(target);
|
||||
if (!target) return [];
|
||||
if (target.nodeType === 1) return [target];
|
||||
return typeof target.length === 'number' ? target : [];
|
||||
}
|
||||
|
||||
function apply(target, vars = {}) {
|
||||
for (const element of elements(target)) {
|
||||
if (!element.style) continue;
|
||||
for (const [key, value] of Object.entries(vars)) {
|
||||
if (key in element.style && value !== null) element.style[key] = String(value);
|
||||
}
|
||||
if ('x' in vars || 'y' in vars || 'scale' in vars || 'scaleX' in vars || 'scaleY' in vars) {
|
||||
const x = Number(vars.x || 0);
|
||||
const y = Number(vars.y || 0);
|
||||
const sx = Number(vars.scaleX ?? vars.scale ?? 1);
|
||||
const sy = Number(vars.scaleY ?? vars.scale ?? 1);
|
||||
element.style.transform = `translate(${x}px, ${y}px) scale(${sx}, ${sy})`;
|
||||
}
|
||||
}
|
||||
if (typeof vars.onComplete === 'function') vars.onComplete();
|
||||
return { kill() {} };
|
||||
}
|
||||
|
||||
function timeline() {
|
||||
const chain = {
|
||||
to(target, vars) { apply(target, vars); return chain; },
|
||||
fromTo(target, _from, vars) { apply(target, vars); return chain; }
|
||||
};
|
||||
return chain;
|
||||
}
|
||||
|
||||
window.gsap = {
|
||||
to: apply,
|
||||
fromTo(target, _from, vars) { return apply(target, vars); },
|
||||
set: apply,
|
||||
killTweensOf() {},
|
||||
timeline
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* markdown.js — 原生轻量 Markdown 渲染器(零依赖、无外部 CDN)
|
||||
*
|
||||
* 供 index 页「公告 / 表单说明」等富文本内容使用。
|
||||
* 安全策略:先对全部输入做 HTML 转义再解析 Markdown,杜绝 XSS。
|
||||
*
|
||||
* 支持语法:
|
||||
* - 标题 # ~ ######
|
||||
* - 段落、行内换行
|
||||
* - 加粗 **bold** 、斜体 *italic* / _italic_ 、删除线 ~~del~~
|
||||
* - 行内代码 `code` 、围栏代码块 ```lang
|
||||
* - 链接 [text](url) 、裸链接自动转可点击、图片 
|
||||
* - 无序列表 -/+/* 、有序列表 1. 、任务列表 - [x]
|
||||
* - 引用 > 、水平线 --- / *** / ___
|
||||
* - 表格 | a | b |
|
||||
*
|
||||
* 对外接口:window.Markdown.render(markdown) -> 安全 HTML 字符串
|
||||
*/
|
||||
window.Markdown = (function () {
|
||||
'use strict';
|
||||
|
||||
// 文本内容转义:仅转义 & < >(引号在文本节点中无需转义,
|
||||
// 若过早转义会破坏「带提示文字链接」中引号的匹配)
|
||||
function escapeHtml(s) {
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
// 属性值转义:在 escapeHtml 基础上再转义引号与反引号,防属性注入
|
||||
function escapeAttr(s) {
|
||||
return escapeHtml(s)
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/`/g, '`');
|
||||
}
|
||||
|
||||
// 只允许安全协议;其余一律丢弃,防止 javascript: 等注入
|
||||
function sanitizeUrl(url) {
|
||||
var u = (url || '').trim();
|
||||
if (/^(https?:|mailto:|tel:|ftp:|\/|\.\/|\.\.\/|#)/i.test(u)) return escapeAttr(u);
|
||||
return '#';
|
||||
}
|
||||
|
||||
// ===== 行内解析 =====
|
||||
function inline(text) {
|
||||
var t = escapeHtml(text || '');
|
||||
|
||||
// 行内代码
|
||||
t = t.replace(/`([^`]+)`/g, '<code>$1</code>');
|
||||
|
||||
// 图片(必须在链接之前处理,避免  被误判为链接)
|
||||
t = t.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, function (m, alt, url, title) {
|
||||
var ttl = title ? ' title="' + escapeAttr(title) + '"' : '';
|
||||
return '<img src="' + sanitizeUrl(url) + '" alt="' + escapeAttr(alt) + '" loading="lazy"' + ttl + '>';
|
||||
});
|
||||
|
||||
// 链接 [text](url "title")
|
||||
t = t.replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, function (m, label, url, title) {
|
||||
var ttl = title ? ' title="' + escapeAttr(title) + '"' : '';
|
||||
return '<a href="' + sanitizeUrl(url) + '" target="_blank" rel="noopener noreferrer"' + ttl + '>' + label + '</a>';
|
||||
});
|
||||
|
||||
// 加粗
|
||||
t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
||||
// 斜体(单星)
|
||||
t = t.replace(/(^|[^*])\*([^*\s][^*]*)\*(?!\*)/g, '$1<em>$2</em>');
|
||||
t = t.replace(/(^|[^_])_([^_\s][^_]*)_(?![_])/g, '$1<em>$2</em>');
|
||||
// 删除线
|
||||
t = t.replace(/~~([^~]+)~~/g, '<del>$1</del>');
|
||||
|
||||
// 裸链接自动转可点击(排除已转义的 href 属性与常见标点结尾)
|
||||
t = t.replace(/(^|\s)((?:https?:\/\/)[^\s<>"'`,。;:、()【】!?]+[^\s<>"'`,。;:、()【】!?,.;:!?)\]}])/g,
|
||||
function (m, pre, url) {
|
||||
return pre + '<a href="' + sanitizeUrl(url) + '" target="_blank" rel="noopener noreferrer">' + url + '</a>';
|
||||
});
|
||||
|
||||
// 单行换行保留为 <br>(段落内多个来源行 => 硬换行,尊重用户输入的换行符)
|
||||
t = t.replace(/\n/g, '<br>');
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
// 拆分表格行,去除首尾多余的 | 与空白
|
||||
function splitRow(row) {
|
||||
return row.replace(/^\s*\|?/, '').replace(/\|?\s*$/, '').split('|').map(function (c) {
|
||||
return c.trim();
|
||||
});
|
||||
}
|
||||
|
||||
function isDelimiterRow(line) {
|
||||
var t = (line || '').trim().replace(/^\|/, '').replace(/\|$/, '');
|
||||
return /^[\s:|-]+$/.test(t) && /-/.test(t);
|
||||
}
|
||||
|
||||
// ===== 块级解析 =====
|
||||
function render(src) {
|
||||
if (!src) return '';
|
||||
var lines = String(src).replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
|
||||
var html = '';
|
||||
var i = 0;
|
||||
var listStack = [];
|
||||
|
||||
function closeLists() {
|
||||
while (listStack.length) {
|
||||
var l = listStack.pop();
|
||||
html += l === 'ol' ? '</ol>\n' : '</ul>\n';
|
||||
}
|
||||
}
|
||||
|
||||
while (i < lines.length) {
|
||||
var line = lines[i];
|
||||
var trimmed = line.trim();
|
||||
|
||||
// 空行
|
||||
if (!trimmed) { i++; continue; }
|
||||
|
||||
// 围栏代码块
|
||||
var fence = trimmed.match(/^```([\w-]*)\s*$/);
|
||||
if (fence) {
|
||||
closeLists();
|
||||
var code = [];
|
||||
i++;
|
||||
while (i < lines.length && !/^```\s*$/.test(lines[i].trim())) {
|
||||
code.push(lines[i]);
|
||||
i++;
|
||||
}
|
||||
i++; // 跳过结束围栏
|
||||
html += '<pre><code' + (fence[1] ? ' class="language-' + escapeAttr(fence[1]) + '"' : '') + '>' +
|
||||
escapeHtml(code.join('\n')) + '</code></pre>\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
// 标题
|
||||
var heading = trimmed.match(/^(#{1,6})\s+(.*)$/);
|
||||
if (heading) {
|
||||
closeLists();
|
||||
var level = heading[1].length;
|
||||
html += '<h' + level + '>' + inline(heading[2]) + '</h' + level + '>\n';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 水平线
|
||||
if (/^(\s*[-*_]\s*){3,}$/.test(trimmed)) {
|
||||
closeLists();
|
||||
html += '<hr>\n';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 引用
|
||||
if (trimmed.charAt(0) === '>') {
|
||||
closeLists();
|
||||
var quote = [];
|
||||
while (i < lines.length && lines[i].trim().charAt(0) === '>') {
|
||||
quote.push(lines[i].trim().replace(/^>\s?/, ''));
|
||||
i++;
|
||||
}
|
||||
html += '<blockquote>' + inline(quote.join('\n')) + '</blockquote>\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
// 任务列表
|
||||
var task = trimmed.match(/^[-*+]\s+\[([ xX])\]\s+(.*)$/);
|
||||
if (task) {
|
||||
if (listStack.length === 0 || listStack[listStack.length - 1] !== 'ul') {
|
||||
closeLists();
|
||||
html += '<ul class="task-list">\n';
|
||||
listStack.push('ul');
|
||||
}
|
||||
var checked = /[xX]/.test(task[1]);
|
||||
html += '<li class="task-list-item"><input type="checkbox" disabled' + (checked ? ' checked' : '') + '> ' +
|
||||
inline(task[2]) + '</li>\n';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 无序列表
|
||||
var ul = trimmed.match(/^[-*+]\s+(.*)$/);
|
||||
if (ul) {
|
||||
if (listStack.length === 0 || listStack[listStack.length - 1] !== 'ul') {
|
||||
closeLists();
|
||||
html += '<ul>\n';
|
||||
listStack.push('ul');
|
||||
}
|
||||
html += '<li>' + inline(ul[1]) + '</li>\n';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 有序列表
|
||||
var ol = trimmed.match(/^\d+[.)]\s+(.*)$/);
|
||||
if (ol) {
|
||||
if (listStack.length === 0 || listStack[listStack.length - 1] !== 'ol') {
|
||||
closeLists();
|
||||
html += '<ol>\n';
|
||||
listStack.push('ol');
|
||||
}
|
||||
html += '<li>' + inline(ol[1]) + '</li>\n';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 表格(当前行含 | 且下一行为分隔行)
|
||||
if (trimmed.indexOf('|') !== -1 && i + 1 < lines.length && isDelimiterRow(lines[i + 1])) {
|
||||
closeLists();
|
||||
var header = splitRow(trimmed);
|
||||
var rows = [];
|
||||
i += 2; // 跳过表头与分隔行
|
||||
while (i < lines.length && lines[i].trim().indexOf('|') !== -1 && !isDelimiterRow(lines[i].trim())) {
|
||||
rows.push(splitRow(lines[i].trim()));
|
||||
i++;
|
||||
}
|
||||
html += '<table><thead><tr>' + header.map(function (c) {
|
||||
return '<th>' + inline(c) + '</th>';
|
||||
}).join('') + '</tr></thead><tbody>';
|
||||
html += rows.map(function (r) {
|
||||
return '<tr>' + r.map(function (c) {
|
||||
return '<td>' + inline(c) + '</td>';
|
||||
}).join('') + '</tr>';
|
||||
}).join('');
|
||||
html += '</tbody></table>\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
// 普通段落(收集连续的非空、非块级起始行)
|
||||
closeLists();
|
||||
var para = [trimmed];
|
||||
i++;
|
||||
while (i < lines.length &&
|
||||
lines[i].trim() &&
|
||||
!/^(#{1,6}\s|```|[-*+]\s|\d+[.)]\s|>\s?|\[[ xX]\]\s)/.test(lines[i].trim()) &&
|
||||
lines[i].trim().indexOf('|') === -1) {
|
||||
para.push(lines[i].trim());
|
||||
i++;
|
||||
}
|
||||
html += '<p>' + inline(para.join('\n')) + '</p>\n';
|
||||
}
|
||||
|
||||
closeLists();
|
||||
return html;
|
||||
}
|
||||
|
||||
return { render: render, inline: inline };
|
||||
})();
|
||||
@@ -0,0 +1,970 @@
|
||||
/**
|
||||
* MorphCard — 胶囊按钮 → 卡片 多状态形变组件(公共库)
|
||||
*
|
||||
* v6:临界阻尼流体弹簧引擎。
|
||||
* 容器位置/尺寸/底色/圆角不再走 CSS transition,而是由一组 ζ=1.0(临界阻尼、无过冲)
|
||||
* 的二阶弹簧逐帧驱动;border-radius 每帧由当前宽高推导:
|
||||
* radius = min( min(w,h)/2, lerp(min(w,h)/2 → 28, 圆角揭示进度) )
|
||||
* 胶囊阶段天然等于高度一半(完整圆端),随轮廓长大连续收敛到卡片圆角,
|
||||
* 与宽高/位置共享同一组弹簧,全程同步、无跳变。
|
||||
* 内容面的透明度/位移/模糊/级联也由面弹簧的当前值推导,可中断、无定时器硬切。
|
||||
*
|
||||
* 用法(任何页面):
|
||||
* <script src="/static/js/morph-card.js"></script>
|
||||
* <script>
|
||||
* const card = MorphCard.init({
|
||||
* // 可选配置(以下为默认值)
|
||||
* successTitle: '提交成功',
|
||||
* successDesc: '您填写的数据已保存。',
|
||||
* doneText: '确定',
|
||||
* errorTitle: '无法提交',
|
||||
* errorDefault: '提交失败,请稍后重试',
|
||||
* backText: '返回修改',
|
||||
* progressLabel: '正在上传',
|
||||
* onExpand: (sourceEl) => {}, // 卡片从来源元素展开时回调
|
||||
* onCollapse: (sourceEl) => {}, // 卡片收回、来源元素交还时回调
|
||||
* });
|
||||
*
|
||||
* card.open('progress', { sourceEl: btn }); // 从某元素形变展开(verify/confirm/progress/success/error)
|
||||
* card.setState('success'); // 已展开时切换内容面(宽高随弹簧平滑过渡)
|
||||
* card.progress({ percent: 68, text: '2.3 MB/s · 剩余 00:04' });
|
||||
* card.success(); // 成功面(对勾笔画 + 粒子)
|
||||
* card.error('具体的错误信息'); // 错误面(不自动收起,用户点"返回修改"关闭)
|
||||
* card.close(); // 收回来源位置
|
||||
*
|
||||
* // 确认卡片:无输入框的二次确认(如"仅可提交一次"提示)。
|
||||
* // onConfirm 返回 true=确认(keepOpen=true 时卡片保持展开由调用方切下一面);
|
||||
* // 返回字符串=错误提示显示在卡片内;取消/backdrop/Esc resolve false。
|
||||
* const ok = await card.confirm({
|
||||
* title: '仅可提交一次', desc: '提交后不能再修改。',
|
||||
* okText: '确认提交', cancelText: '再检查一下',
|
||||
* sourceEl: btn, keepOpen: true,
|
||||
* onConfirm: async () => true,
|
||||
* });
|
||||
*
|
||||
* // 验证卡片:尾号/验证码输入,resolve 输入值;取消 resolve null;
|
||||
* // onSubmit 返回 true=通过;返回字符串=错误提示(卡片内显示并抖动)
|
||||
* const value = await card.verify({
|
||||
* title: '加载上次提交', desc: '输入学号后 2 位…',
|
||||
* maxlength: 2, placeholder: '••', okText: '验证并加载',
|
||||
* inputFilter: v => v.replace(/\D/g, ''),
|
||||
* sourceEl: btn, keepOpen: false,
|
||||
* onSubmit: async (value) => true,
|
||||
* });
|
||||
* </script>
|
||||
*
|
||||
* 依赖:页面主题变量(--accent-bg、--bg-secondary、--text-primary、--border-color 等,
|
||||
* 由 basic.css 提供),缺失时使用内置深色兜底值。
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
if (window.MorphCard) return; // 单例
|
||||
|
||||
/* ---------- 弹簧参数 ---------- */
|
||||
/* 质量=1 二阶弹簧:ω = 2π/response,k = ω²,c = 2ζω。
|
||||
ζ = 1 临界阻尼(高阻尼、无过冲、平滑收敛);
|
||||
response 是"到达目标的特征时间"(秒),不是固定时长。 */
|
||||
const RESPONSE = 0.45;
|
||||
const ZETA = 1.0;
|
||||
const RESPONSE_REVEAL = RESPONSE + 0.12; // 圆角揭示略滞后于轮廓,更像液体
|
||||
const RESPONSE_BG = RESPONSE + 0.08;
|
||||
const RESPONSE_BG_COLLAPSE = 0.16; // 收起时先回到按钮主色,再完成轮廓收缩
|
||||
const FACE_IN = 0.55, FACE_OUT = 0.22; // 内容面弹簧(入/出)
|
||||
const GATE_AT = 0.45; // 展开时轮廓揭示超过该比例后内容才开始入场
|
||||
const CARD_R = 28;
|
||||
const SETTLE_GUARD_MS = 1000; // busy 兜底(约等于弹簧收敛时间)
|
||||
const COLLAPSE_SAFETY_MS = 2000; // 收起兜底(后台标签页 rAF 暂停时也能收尾)
|
||||
|
||||
const FACE_WIDTH = { verify: 300, confirm: 300, progress: 250, success: 320, error: 320 };
|
||||
const CARD_PAD_X = 44;
|
||||
const CARD_PAD_Y = 48;
|
||||
const ACCENT = [23, 23, 23]; // 兜底胶囊底色(正常被 --accent-bg 覆盖读取)
|
||||
const CARD_BG = [255, 255, 255]; // 兜底卡片底色(正常被 --bg-secondary 覆盖读取)
|
||||
|
||||
const reduceMotion = window.matchMedia && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
/* ---------- 弹簧引擎 ---------- */
|
||||
const spring = v => ({ x: v, v: 0, t: v });
|
||||
function stepSpring(s, dt, response, zeta) {
|
||||
if (dt <= 0) return;
|
||||
const w = 2 * Math.PI / response, k = w * w, c = 2 * (zeta == null ? ZETA : zeta) * w;
|
||||
const n = Math.max(1, Math.ceil(dt / (1 / 240))); // 固定子步长,保证数值稳定
|
||||
const h = dt / n;
|
||||
for (let i = 0; i < n; i++) {
|
||||
s.v += (-k * (s.x - s.t) - c * s.v) * h;
|
||||
s.x += s.v * h;
|
||||
}
|
||||
}
|
||||
const settledS = s => Math.abs(s.x - s.t) < 0.05 && Math.abs(s.v) < 0.05;
|
||||
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
|
||||
const lerp = (a, b, t) => a + (b - a) * t;
|
||||
const easeOutCubic = t => 1 - Math.pow(1 - t, 3);
|
||||
|
||||
/* ---------- 样式注入 ----------
|
||||
说明:--um-ease-* / --um-morph-ms 变量保留为外部兼容钩子(页面级 CSS 可引用),
|
||||
组件本体已不再使用 CSS 过渡做形变。 */
|
||||
const CSS = `
|
||||
:root {
|
||||
--um-morph-ms: 560ms;
|
||||
--um-ease-morph: cubic-bezier(0.32, 0.72, 0, 1);
|
||||
--um-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
|
||||
--um-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
|
||||
}
|
||||
body.um-locked { overflow: hidden; }
|
||||
|
||||
.um-backdrop {
|
||||
position: fixed; inset: 0; z-index: 90;
|
||||
background: rgba(8, 10, 14, 0.45);
|
||||
backdrop-filter: blur(10px) saturate(1.1);
|
||||
-webkit-backdrop-filter: blur(10px) saturate(1.1);
|
||||
opacity: 0; pointer-events: none;
|
||||
}
|
||||
.um-backdrop.show { pointer-events: auto; }
|
||||
|
||||
.um-morpher {
|
||||
position: fixed; left: 0; top: 0; z-index: 95; display: none;
|
||||
border: none; border-radius: 999px;
|
||||
background: var(--accent-bg, #171717);
|
||||
overflow: hidden; user-select: none; -webkit-tap-highlight-color: transparent;
|
||||
will-change: transform, width, height;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* 胶囊面的 spinner:随圆角揭示进度淡出(JS 逐帧写 opacity) */
|
||||
.um-spinner {
|
||||
position: absolute; left: 50%; top: 50%; width: 22px; height: 22px;
|
||||
margin: -11px 0 0 -11px; border-radius: 50%;
|
||||
border: 2.5px solid color-mix(in srgb, var(--accent-text, #fff) 30%, transparent);
|
||||
border-top-color: var(--accent-text, #fff);
|
||||
animation: um-spin 0.7s linear infinite;
|
||||
pointer-events: none;
|
||||
}
|
||||
@keyframes um-spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* 多状态面:verify / confirm / progress / success / error
|
||||
透明度/模糊由面弹簧逐帧写入,子元素级联亦由弹簧值推导 */
|
||||
.um-face {
|
||||
position: absolute; inset: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
overflow-y: auto;
|
||||
opacity: 0; pointer-events: none;
|
||||
}
|
||||
|
||||
.um-card-inner {
|
||||
display: flex; flex-direction: column; align-items: center;
|
||||
width: 320px; max-width: 100%; margin: auto;
|
||||
text-align: center;
|
||||
color: var(--text-primary, #171717);
|
||||
}
|
||||
|
||||
.um-badge-wrap { position: relative; width: 76px; height: 76px; }
|
||||
.um-badge {
|
||||
position: absolute; inset: 0; border-radius: 50%;
|
||||
background: linear-gradient(135deg, #34d399, #059669);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
box-shadow: 0 10px 28px -8px rgba(16, 185, 129, 0.55);
|
||||
transform: scale(0.4); opacity: 0;
|
||||
transition: transform 0.4s var(--um-spring), opacity 0.2s ease;
|
||||
}
|
||||
.um-morpher.um-badge-in .um-badge { transform: scale(1); opacity: 1; }
|
||||
.um-badge-error {
|
||||
background: linear-gradient(135deg, #f87171, #dc2626);
|
||||
box-shadow: 0 10px 28px -8px rgba(220, 38, 38, 0.5);
|
||||
}
|
||||
.um-badge svg { width: 34px; height: 34px; }
|
||||
.um-check {
|
||||
fill: none; stroke: #fff; stroke-width: 2.6;
|
||||
stroke-linecap: round; stroke-linejoin: round;
|
||||
stroke-dasharray: 1; stroke-dashoffset: 1;
|
||||
}
|
||||
.um-morpher.is-done .um-check {
|
||||
stroke-dashoffset: 0;
|
||||
transition: stroke-dashoffset 0.42s cubic-bezier(0.65, 0, 0.35, 1);
|
||||
}
|
||||
.um-ring-pulse {
|
||||
position: absolute; inset: -2px; border-radius: 50%;
|
||||
border: 2px solid #10b981; opacity: 0; pointer-events: none;
|
||||
}
|
||||
.um-morpher.is-done .um-ring-pulse { animation: um-ripple 0.65s ease-out 0.15s both; }
|
||||
@keyframes um-ripple {
|
||||
0% { transform: scale(1); opacity: 0.55; }
|
||||
100% { transform: scale(1.75); opacity: 0; }
|
||||
}
|
||||
|
||||
.um-title {
|
||||
font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
|
||||
font-size: 24px; font-weight: 500; margin-top: 22px;
|
||||
color: inherit;
|
||||
}
|
||||
.um-desc {
|
||||
font-size: 13.5px; color: var(--text-secondary, #525252);
|
||||
line-height: 1.75; margin-top: 10px;
|
||||
}
|
||||
.um-btn {
|
||||
width: 100%; height: 48px; margin-top: 26px;
|
||||
border: none; border-radius: 999px; cursor: pointer;
|
||||
background: var(--accent-bg, #171717); color: var(--accent-text, #ffffff);
|
||||
font: 600 14px/1 inherit; letter-spacing: 0.02em;
|
||||
transition: transform 0.16s ease-out, opacity 0.15s ease;
|
||||
}
|
||||
.um-btn:active { transform: scale(0.97); }
|
||||
|
||||
/* 验证面 */
|
||||
.um-verify-inner { width: 300px; max-width: 100%; }
|
||||
.um-verify-input {
|
||||
display: block; width: 170px; margin: 22px auto 0; padding: 10px 6px;
|
||||
border: none; border-bottom: 2px solid var(--border-color, #e5e5e5);
|
||||
border-radius: 0; background: transparent; outline: none;
|
||||
text-align: center; letter-spacing: 0.35em; text-indent: 0.35em;
|
||||
font-size: 26px; font-weight: 600; line-height: 1.4;
|
||||
color: var(--text-primary, #171717); font-family: inherit;
|
||||
caret-color: var(--accent-bg, #171717);
|
||||
transition: border-color 0.2s ease;
|
||||
}
|
||||
.um-verify-input:focus { border-color: var(--text-primary, #171717); }
|
||||
.um-verify-input.um-input-error { border-color: var(--error-text, #ef4444); }
|
||||
.um-verify-err {
|
||||
min-height: 20px; margin-top: 10px;
|
||||
font-size: 12px; color: var(--error-text, #ef4444);
|
||||
}
|
||||
.um-verify-actions { display: flex; gap: 10px; width: 100%; margin-top: 8px; }
|
||||
.um-verify-actions .um-btn { flex: 1; width: auto; margin-top: 0; }
|
||||
.um-btn-ghost {
|
||||
background: transparent; color: var(--text-secondary, #525252);
|
||||
border: 1px solid var(--border-color, #e5e5e5);
|
||||
}
|
||||
|
||||
/* 进度面 */
|
||||
.um-progress-inner { width: 250px; max-width: 100%; }
|
||||
.um-progress-label {
|
||||
font-size: 11px; letter-spacing: 0.4em; text-transform: uppercase;
|
||||
color: var(--text-muted, #737373);
|
||||
}
|
||||
.um-progress-ring { position: relative; width: 132px; height: 132px; margin-top: 28px; }
|
||||
.um-progress-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
|
||||
.um-ring-track { fill: none; stroke: var(--border-color, #e5e5e5); stroke-width: 5; }
|
||||
.um-ring-fill {
|
||||
fill: none; stroke: var(--text-primary, #171717); stroke-width: 5; stroke-linecap: round;
|
||||
stroke-dasharray: 100; stroke-dashoffset: 100;
|
||||
transition: stroke-dashoffset 0.25s linear;
|
||||
}
|
||||
.um-progress-percent {
|
||||
position: absolute; inset: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 26px; font-weight: 600; color: var(--text-primary, #171717);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.um-progress-sub {
|
||||
margin-top: 24px; font-size: 12.5px; color: var(--text-muted, #737373);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.um-error-inner .um-desc { color: var(--error-text, #ef4444); }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.um-spinner, .um-badge, .um-ring-pulse, .um-btn, .um-check {
|
||||
transition-duration: 1ms !important;
|
||||
animation-duration: 1ms !important;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/* ---------- DOM ---------- */
|
||||
function buildDom(opts) {
|
||||
const style = document.createElement('style');
|
||||
style.textContent = CSS;
|
||||
document.head.appendChild(style);
|
||||
|
||||
const backdrop = document.createElement('div');
|
||||
backdrop.className = 'um-backdrop';
|
||||
backdrop.id = 'umBackdrop';
|
||||
|
||||
const morpher = document.createElement('div');
|
||||
morpher.className = 'um-morpher';
|
||||
morpher.id = 'uploadMorpher';
|
||||
morpher.setAttribute('role', 'dialog');
|
||||
morpher.setAttribute('aria-modal', 'true');
|
||||
morpher.innerHTML = `
|
||||
<span class="um-spinner" aria-hidden="true"></span>
|
||||
|
||||
<div class="um-face um-face-verify">
|
||||
<div class="um-card-inner um-verify-inner">
|
||||
<h3 class="um-title" id="umVerifyTitle">身份验证</h3>
|
||||
<p class="um-desc" id="umVerifyDesc"></p>
|
||||
<input type="text" class="um-verify-input" id="umVerifyInput" autocomplete="off" />
|
||||
<p class="um-verify-err" id="umVerifyError"></p>
|
||||
<div class="um-verify-actions">
|
||||
<button type="button" class="um-btn um-btn-ghost" id="umVerifyCancel">取消</button>
|
||||
<button type="button" class="um-btn" id="umVerifyOk">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="um-face um-face-confirm">
|
||||
<div class="um-card-inner um-confirm-inner">
|
||||
<h3 class="um-title" id="umConfirmTitle">确认提交</h3>
|
||||
<p class="um-desc" id="umConfirmDesc"></p>
|
||||
<p class="um-verify-err" id="umConfirmError"></p>
|
||||
<div class="um-verify-actions">
|
||||
<button type="button" class="um-btn um-btn-ghost" id="umConfirmCancel">取消</button>
|
||||
<button type="button" class="um-btn" id="umConfirmOk">确认提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="um-face um-face-progress">
|
||||
<div class="um-card-inner um-progress-inner">
|
||||
<p class="um-progress-label">${opts.progressLabel}</p>
|
||||
<div class="um-progress-ring">
|
||||
<svg viewBox="0 0 120 120">
|
||||
<circle class="um-ring-track" cx="60" cy="60" r="52" pathLength="100"/>
|
||||
<circle class="um-ring-fill" id="umProgressRing" cx="60" cy="60" r="52" pathLength="100"/>
|
||||
</svg>
|
||||
<span class="um-progress-percent" id="umProgressPercent">0%</span>
|
||||
</div>
|
||||
<p class="um-progress-sub" id="umProgressSub">准备中…</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="um-face um-face-success">
|
||||
<div class="um-card-inner">
|
||||
<span class="um-badge-wrap">
|
||||
<span class="um-ring-pulse"></span>
|
||||
<span class="um-badge">
|
||||
<svg viewBox="0 0 24 24"><path class="um-check" d="M5 13l4 4L19 7" pathLength="1"/></svg>
|
||||
</span>
|
||||
</span>
|
||||
<h3 class="um-title">${opts.successTitle}</h3>
|
||||
<p class="um-desc">${opts.successDesc}</p>
|
||||
<button type="button" class="um-btn" id="umDoneBtn">${opts.doneText}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="um-face um-face-error">
|
||||
<div class="um-card-inner um-error-inner">
|
||||
<span class="um-badge-wrap">
|
||||
<span class="um-badge um-badge-error">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round">
|
||||
<path d="M12 6v7"/><path d="M12 16.5v.01"/>
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
<h3 class="um-title">${opts.errorTitle}</h3>
|
||||
<p class="um-desc" id="umErrorText">${opts.errorDefault}</p>
|
||||
<button type="button" class="um-btn" id="umErrorBack">${opts.backText}</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(backdrop);
|
||||
document.body.appendChild(morpher);
|
||||
|
||||
const faces = {}, inners = {};
|
||||
morpher.querySelectorAll('.um-face').forEach(f => {
|
||||
const name = /um-face-(\w+)/.exec(f.className)[1];
|
||||
faces[name] = f;
|
||||
inners[name] = f.querySelector('.um-card-inner');
|
||||
});
|
||||
return { backdrop, morpher, faces, inners, spinner: morpher.querySelector('.um-spinner') };
|
||||
}
|
||||
|
||||
/* ---------- 组件 ---------- */
|
||||
const state = {
|
||||
open: false, busy: false, collapsing: false,
|
||||
savedRect: null, sourceEl: null, verifyActive: false,
|
||||
activeFace: null, gateOpen: false, fxStage: 0
|
||||
};
|
||||
let dom = null;
|
||||
let opts = null;
|
||||
let measurer = null;
|
||||
|
||||
/* ---------- 弹簧组 ---------- */
|
||||
const box = { x: spring(0), y: spring(0), w: spring(0), h: spring(0), reveal: spring(0), bg: spring(0), op: spring(1) };
|
||||
const backdropS = spring(0);
|
||||
const faceS = {};
|
||||
for (const k of Object.keys(FACE_WIDTH)) faceS[k] = spring(0);
|
||||
|
||||
/* 底色读取:优先页面主题变量,读不到用兜底值。按次缓存,主题切换/下次展开时刷新 */
|
||||
function parseColor(varName, fallback, themeEl) {
|
||||
const v = getComputedStyle(themeEl).getPropertyValue(varName).trim();
|
||||
if (!v) return fallback;
|
||||
const m = v.match(/^#([0-9a-f]{6})$/i) || v.match(/^rgb\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)\s*\)$/i);
|
||||
if (m) {
|
||||
return m.length === 2
|
||||
? [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16)]
|
||||
: [+m[1], +m[2], +m[3]];
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
let cachedAccent = null, cachedCard = null, cachedBorder = null;
|
||||
function refreshTheme() {
|
||||
// 页面可在 body 或按钮上覆盖主题变量;从形变来源读取,颜色才能与按钮一致。
|
||||
const themeEl = state.sourceEl?.isConnected ? state.sourceEl : document.body;
|
||||
cachedAccent = parseColor('--accent-bg', ACCENT, themeEl);
|
||||
cachedCard = parseColor('--bg-secondary', CARD_BG, themeEl);
|
||||
cachedBorder = parseColor('--border-color', [229, 229, 229], themeEl);
|
||||
}
|
||||
|
||||
let rafId = null;
|
||||
let lastT = 0;
|
||||
let collapseSafety = null;
|
||||
|
||||
function ensureLoop() {
|
||||
if (rafId == null) { lastT = performance.now(); rafId = requestAnimationFrame(tick); }
|
||||
}
|
||||
|
||||
function allContainerSettled() {
|
||||
return [box.x, box.y, box.w, box.h, box.reveal, box.bg, box.op, backdropS].every(settledS);
|
||||
}
|
||||
function allFacesSettled() {
|
||||
for (const k in faceS) if (!settledS(faceS[k])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function visibleViewport() {
|
||||
const vv = window.visualViewport;
|
||||
if (vv) {
|
||||
return { top: vv.offsetTop, left: vv.offsetLeft, width: vv.width, height: vv.height };
|
||||
}
|
||||
return { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight };
|
||||
}
|
||||
|
||||
function targetRectFallback() {
|
||||
const w = Math.min(440, window.innerWidth - 32);
|
||||
const h = Math.min(560, window.innerHeight - 48);
|
||||
return { left: (window.innerWidth - w) / 2, top: (window.innerHeight - h) / 2, width: w, height: h };
|
||||
}
|
||||
|
||||
/* 离屏克隆目标状态面,测量其自然内容尺寸,返回在给定视口内居中的目标矩形 */
|
||||
function measureState(stateName, vp) {
|
||||
const face = dom.faces[stateName];
|
||||
if (!face) return targetRectFallback();
|
||||
vp = vp || visibleViewport();
|
||||
|
||||
if (!measurer) {
|
||||
measurer = document.createElement('div');
|
||||
measurer.style.cssText =
|
||||
'position:fixed;left:-10000px;top:0;visibility:hidden;pointer-events:none;' +
|
||||
'display:flex;align-items:center;justify-content:center;';
|
||||
document.body.appendChild(measurer);
|
||||
}
|
||||
|
||||
const clone = dom.inners[stateName].cloneNode(true);
|
||||
clone.removeAttribute('style');
|
||||
clone.querySelectorAll('*').forEach(el => el.removeAttribute('style'));
|
||||
const designWidth = FACE_WIDTH[stateName] || 320;
|
||||
const maxW = Math.min(440, vp.width - 32) - CARD_PAD_X * 2;
|
||||
measurer.style.width = Math.min(designWidth, maxW) + 'px';
|
||||
measurer.innerHTML = '';
|
||||
measurer.appendChild(clone);
|
||||
|
||||
const w = Math.min(measurer.offsetWidth + CARD_PAD_X * 2, vp.width - 32);
|
||||
const h = Math.min(measurer.offsetHeight + CARD_PAD_Y * 2, vp.height - 32);
|
||||
return {
|
||||
left: vp.left + (vp.width - w) / 2,
|
||||
top: vp.top + (vp.height - h) / 2,
|
||||
width: w, height: h
|
||||
};
|
||||
}
|
||||
|
||||
/* 把当前面的目标矩形写入弹簧(软键盘弹起/收起、切面、展开共用) */
|
||||
function retargetTo(stateName) {
|
||||
const t = measureState(stateName, visibleViewport());
|
||||
box.x.t = t.left; box.y.t = t.top; box.w.t = t.width; box.h.t = t.height;
|
||||
}
|
||||
|
||||
/* 软键盘弹起/收起时,让卡片平滑避让到可视区域内(弹簧自然滑移) */
|
||||
if (window.visualViewport) {
|
||||
window.visualViewport.addEventListener('resize', () => {
|
||||
if (!state.open || state.collapsing || !dom) return;
|
||||
if (dom.morpher.style.display !== 'block') return;
|
||||
retargetTo(state.activeFace || 'verify');
|
||||
ensureLoop();
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 逐帧写入 ---------- */
|
||||
/* 关键:border-radius 不独立过渡,由当前宽高与揭示进度推导,见文件头注释 */
|
||||
function applyBox() {
|
||||
const el = dom.morpher;
|
||||
const a = cachedAccent, c = cachedCard, bc = cachedBorder;
|
||||
const m = clamp(box.bg.x, 0, 1);
|
||||
el.style.transform = `translate3d(${box.x.x}px, ${box.y.x}px, 0)`;
|
||||
el.style.width = box.w.x + 'px';
|
||||
el.style.height = box.h.x + 'px';
|
||||
const half = Math.min(box.w.x, box.h.x) / 2;
|
||||
const radius = Math.min(half, lerp(half, CARD_R, clamp(box.reveal.x, 0, 1)));
|
||||
el.style.borderRadius = radius + 'px';
|
||||
el.style.backgroundColor =
|
||||
`rgb(${Math.round(lerp(a[0], c[0], m))},${Math.round(lerp(a[1], c[1], m))},${Math.round(lerp(a[2], c[2], m))})`;
|
||||
el.style.boxShadow = m < 0.01 ? 'none' :
|
||||
`0 ${(32 * m).toFixed(1)}px ${(90 * m).toFixed(1)}px ${(-20 * m).toFixed(1)}px rgba(8,10,14,${(0.35 * m).toFixed(3)}), ` +
|
||||
`0 0 0 1px rgba(${bc[0]},${bc[1]},${bc[2]},${m.toFixed(3)})`;
|
||||
el.style.opacity = clamp(box.op.x, 0, 1).toFixed(3);
|
||||
}
|
||||
|
||||
/* 内容面:透明度/模糊/子元素级联全部由面弹簧当前值推导(可中断、无定时器硬切) */
|
||||
function applyFace(name) {
|
||||
const s = faceS[name];
|
||||
const el = dom.faces[name], inner = dom.inners[name];
|
||||
if (!el) return;
|
||||
const r = clamp(s.x, 0, 1);
|
||||
el.style.opacity = r.toFixed(3);
|
||||
el.style.pointerEvents = r > 0.6 ? 'auto' : 'none';
|
||||
inner.style.filter = r < 0.999 ? `blur(${((1 - r) * 6).toFixed(2)}px)` : 'none';
|
||||
const kids = inner.children;
|
||||
for (let i = 0; i < kids.length; i++) {
|
||||
const d = i * 0.09;
|
||||
const e = easeOutCubic(clamp((r - d) / (1 - d), 0, 1));
|
||||
kids[i].style.opacity = e.toFixed(3);
|
||||
kids[i].style.transform = e < 0.999 ? `translateY(${((1 - e) * 14).toFixed(2)}px)` : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function burst() {
|
||||
const badge = dom.morpher.querySelector('.um-badge-wrap');
|
||||
if (!badge) return;
|
||||
const r = badge.getBoundingClientRect();
|
||||
const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
|
||||
const colors = ['#10b981', '#3b82f6', '#f59e0b', '#ec4899', '#8b5cf6'];
|
||||
for (let i = 0; i < 14; i++) {
|
||||
const dot = document.createElement('span');
|
||||
const size = 4 + Math.random() * 3;
|
||||
const angle = (Math.PI * 2 * i) / 14 + (Math.random() - 0.5) * 0.6;
|
||||
const dist = 46 + Math.random() * 52;
|
||||
dot.style.cssText =
|
||||
'position:fixed;z-index:96;pointer-events:none;border-radius:50%;' +
|
||||
'left:' + (cx - size / 2) + 'px;top:' + (cy - size / 2) + 'px;' +
|
||||
'width:' + size + 'px;height:' + size + 'px;background:' + colors[i % colors.length] + ';';
|
||||
document.body.appendChild(dot);
|
||||
const anim = dot.animate([
|
||||
{ transform: 'translate(0,0) scale(1)', opacity: 1 },
|
||||
{ transform: `translate(${Math.cos(angle) * dist}px, ${Math.sin(angle) * dist}px) scale(0.5)`, opacity: 0 }
|
||||
], { duration: 650 + Math.random() * 300, easing: 'cubic-bezier(0.16, 1, 0.3, 1)', fill: 'forwards' });
|
||||
anim.onfinish = () => dot.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/* 成功/错误徽章与对勾:由面弹簧阈值触发(is-done 同时驱动描画与涟漪) */
|
||||
function tickSuccessFx() {
|
||||
const name = state.activeFace;
|
||||
if ((name !== 'success' && name !== 'error') || state.collapsing) return;
|
||||
const r = faceS[name].x;
|
||||
if (state.fxStage < 1 && r > 0.55) {
|
||||
state.fxStage = 1;
|
||||
dom.morpher.classList.add('um-badge-in');
|
||||
if (name === 'success') dom.morpher.classList.add('is-done');
|
||||
}
|
||||
if (state.fxStage < 2 && name === 'success' && r > 0.85) {
|
||||
state.fxStage = 2;
|
||||
burst();
|
||||
}
|
||||
}
|
||||
function resetFx() {
|
||||
state.fxStage = 0;
|
||||
dom.morpher.classList.remove('is-done', 'um-badge-in');
|
||||
}
|
||||
|
||||
/* ---------- 主循环 ---------- */
|
||||
function tick(now) {
|
||||
const dt = Math.min((now - lastT) / 1000, 0.05);
|
||||
lastT = now;
|
||||
|
||||
/* 展开 Choreography:轮廓揭示超过阈值后内容才开始入场 */
|
||||
if (state.open && !state.gateOpen && box.reveal.x > GATE_AT) {
|
||||
state.gateOpen = true;
|
||||
if (state.activeFace) faceS[state.activeFace].t = 1;
|
||||
}
|
||||
|
||||
stepSpring(box.x, dt, RESPONSE);
|
||||
stepSpring(box.y, dt, RESPONSE);
|
||||
stepSpring(box.w, dt, RESPONSE);
|
||||
stepSpring(box.h, dt, RESPONSE);
|
||||
stepSpring(box.reveal, dt, RESPONSE_REVEAL);
|
||||
stepSpring(box.bg, dt, state.collapsing ? RESPONSE_BG_COLLAPSE : RESPONSE_BG);
|
||||
stepSpring(box.op, dt, 0.3);
|
||||
stepSpring(backdropS, dt, 0.5, 1);
|
||||
for (const k in faceS) stepSpring(faceS[k], dt, faceS[k].t === 1 ? FACE_IN : FACE_OUT);
|
||||
|
||||
applyBox();
|
||||
for (const k in faceS) applyFace(k);
|
||||
dom.backdrop.style.opacity = clamp(backdropS.x, 0, 1).toFixed(3);
|
||||
dom.spinner.style.opacity =
|
||||
(state.collapsing ? 0 : clamp(1 - box.reveal.x * 2.2, 0, 1)).toFixed(3);
|
||||
tickSuccessFx();
|
||||
|
||||
if (state.collapsing && allContainerSettled() && allFacesSettled()) {
|
||||
finishCollapse();
|
||||
}
|
||||
|
||||
const idle = !state.open && !state.collapsing && allContainerSettled() && allFacesSettled();
|
||||
if (idle) { rafId = null; return; } // 停表:完全静止时不再占用 rAF
|
||||
rafId = requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
/* ---------- 展开 / 切面 / 收起 ---------- */
|
||||
|
||||
/* 从来源元素锁定并展开为卡片 */
|
||||
function expandFrom(sourceEl, stateName) {
|
||||
// 防重入护栏:收起未完成时先强制瞬间完成收起;展开中/已展开时忽略
|
||||
if (state.collapsing) finishCollapse();
|
||||
if (state.open || state.busy) return;
|
||||
|
||||
state.sourceEl = sourceEl || null;
|
||||
const rect = sourceEl ? sourceEl.getBoundingClientRect() : targetRectFallback();
|
||||
state.savedRect = rect;
|
||||
|
||||
if (opts.onExpand) opts.onExpand(sourceEl);
|
||||
if (sourceEl) sourceEl.style.visibility = 'hidden'; // 原位留白,由胶囊接管
|
||||
|
||||
resetFx();
|
||||
dom.morpher.removeAttribute('data-um-state');
|
||||
refreshTheme();
|
||||
box.x.x = box.x.t = rect.left; box.y.x = box.y.t = rect.top;
|
||||
box.w.x = box.w.t = rect.width; box.h.x = box.h.t = rect.height;
|
||||
box.x.v = box.y.v = box.w.v = box.h.v = 0;
|
||||
box.reveal.x = box.reveal.t = 0; box.reveal.v = 0;
|
||||
box.bg.x = box.bg.t = 0; box.bg.v = 0;
|
||||
box.op.x = box.op.t = 1; box.op.v = 0;
|
||||
backdropS.x = backdropS.t = 0; backdropS.v = 0;
|
||||
for (const k in faceS) { faceS[k].x = faceS[k].t = 0; faceS[k].v = 0; }
|
||||
|
||||
dom.morpher.style.display = 'block';
|
||||
applyBox(); // 首帧即胶囊形态
|
||||
dom.backdrop.classList.add('show');
|
||||
document.body.classList.add('um-locked');
|
||||
|
||||
state.gateOpen = reduceMotion;
|
||||
state.open = true;
|
||||
setStateInternal(stateName);
|
||||
|
||||
box.reveal.t = 1; box.bg.t = 1; backdropS.t = 1;
|
||||
if (reduceMotion) snapAll();
|
||||
state.busy = true;
|
||||
setTimeout(() => { state.busy = false; }, SETTLE_GUARD_MS);
|
||||
ensureLoop();
|
||||
}
|
||||
|
||||
/* 切换内容面:面弹簧交叉淡入,宽高随同一组弹簧滑到新内容尺寸 */
|
||||
function setStateInternal(stateName) {
|
||||
state.activeFace = stateName;
|
||||
refreshTheme();
|
||||
dom.morpher.setAttribute('data-um-state', stateName);
|
||||
if (stateName !== 'success') resetFx(); else state.fxStage = 0;
|
||||
for (const k in faceS) {
|
||||
if (k === stateName) {
|
||||
if (state.gateOpen) faceS[k].t = 1; // 展开途中由 gate 统一点火
|
||||
} else {
|
||||
faceS[k].t = 0;
|
||||
}
|
||||
}
|
||||
if (state.open && dom.morpher.style.display === 'block') {
|
||||
retargetTo(stateName);
|
||||
ensureLoop();
|
||||
}
|
||||
}
|
||||
|
||||
/* 收起:内容快速退场 → 弹簧缩回来源位置 → 交还原位 */
|
||||
function collapse(onDone) {
|
||||
const tryStart = () => {
|
||||
if (state.busy || state.collapsing) { setTimeout(tryStart, 100); return; }
|
||||
state.collapsing = true;
|
||||
state.open = false;
|
||||
state.pendingCollapseDone = onDone || null;
|
||||
|
||||
const sourceEl = state.sourceEl;
|
||||
resetFx();
|
||||
dom.morpher.removeAttribute('data-um-state'); // 内容快速退场
|
||||
for (const k in faceS) faceS[k].t = 0;
|
||||
|
||||
if (!sourceEl) {
|
||||
// 无来源元素(如居中展开的错误卡):原位收缩淡出,避免变形为巨型胶囊盖住页面
|
||||
const cx = box.x.x + box.w.x / 2, cy = box.y.x + box.h.x / 2;
|
||||
box.w.t = box.w.x * 0.88; box.h.t = box.h.x * 0.88;
|
||||
box.x.t = cx - box.w.t / 2; box.y.t = cy - box.h.t / 2;
|
||||
box.op.t = 0;
|
||||
backdropS.t = 0;
|
||||
} else {
|
||||
const r = sourceEl.getBoundingClientRect();
|
||||
box.x.t = r.left; box.y.t = r.top; box.w.t = r.width; box.h.t = r.height;
|
||||
box.reveal.t = 0; // 圆角沿同一组弹簧连续回到完整圆端
|
||||
box.bg.t = 0;
|
||||
backdropS.t = 0;
|
||||
}
|
||||
|
||||
clearTimeout(collapseSafety);
|
||||
collapseSafety = setTimeout(() => { if (state.collapsing) finishCollapse(); }, COLLAPSE_SAFETY_MS);
|
||||
ensureLoop();
|
||||
};
|
||||
tryStart();
|
||||
}
|
||||
|
||||
function finishCollapse() {
|
||||
clearTimeout(collapseSafety);
|
||||
collapseSafety = null;
|
||||
const sourceEl = state.sourceEl;
|
||||
dom.morpher.style.cssText = ''; // 回到 CSS 基础形态(display:none)
|
||||
dom.morpher.removeAttribute('data-um-state');
|
||||
resetFx();
|
||||
dom.backdrop.classList.remove('show');
|
||||
dom.backdrop.style.opacity = '';
|
||||
// 弹簧全部归位,供下次展开使用
|
||||
box.op.x = box.op.t = 1; box.op.v = 0;
|
||||
for (const k in faceS) { faceS[k].x = faceS[k].t = 0; faceS[k].v = 0; }
|
||||
backdropS.x = backdropS.t = 0; backdropS.v = 0;
|
||||
if (sourceEl) {
|
||||
if (opts.onCollapse) opts.onCollapse(sourceEl);
|
||||
sourceEl.style.visibility = ''; // 交还原位
|
||||
}
|
||||
state.sourceEl = null;
|
||||
document.body.classList.remove('um-locked');
|
||||
state.collapsing = false;
|
||||
state.gateOpen = false;
|
||||
state.activeFace = null;
|
||||
const done = state.pendingCollapseDone;
|
||||
state.pendingCollapseDone = null;
|
||||
if (done) done();
|
||||
}
|
||||
|
||||
function snapAll() {
|
||||
for (const s of [box.x, box.y, box.w, box.h, box.reveal, box.bg, box.op, backdropS]) { s.x = s.t; s.v = 0; }
|
||||
for (const k in faceS) { faceS[k].x = faceS[k].t; faceS[k].v = 0; }
|
||||
}
|
||||
|
||||
/* ---------- 公开 API ---------- */
|
||||
const api = {
|
||||
isOpen: () => state.open,
|
||||
|
||||
/* 从某元素形变展开为卡片;state: verify / progress / success / error */
|
||||
open(stateName, options) {
|
||||
if (state.open || state.busy || state.collapsing) return;
|
||||
expandFrom(options && options.sourceEl, stateName);
|
||||
},
|
||||
|
||||
/* 已展开时切换内容面(宽高随弹簧平滑过渡) */
|
||||
setState: setStateInternal,
|
||||
|
||||
/* 收回来源位置并交还原元素 */
|
||||
close() {
|
||||
if (!state.open || state.collapsing) return;
|
||||
collapse();
|
||||
},
|
||||
|
||||
/* 进度面:未展开时从提交按钮展开;openProgress 由页面在提交时调用 */
|
||||
openProgress(sourceEl) {
|
||||
if (state.open) { setStateInternal('progress'); return; }
|
||||
expandFrom(sourceEl || null, 'progress');
|
||||
api.progress({ percent: 0, text: '准备中…' });
|
||||
},
|
||||
|
||||
progress(p) {
|
||||
const ring = document.getElementById('umProgressRing');
|
||||
const pct = document.getElementById('umProgressPercent');
|
||||
const sub = document.getElementById('umProgressSub');
|
||||
if (!ring || !pct) return;
|
||||
if (p.percent != null) {
|
||||
const clamped = Math.max(0, Math.min(100, p.percent));
|
||||
ring.style.strokeDashoffset = String(100 - clamped);
|
||||
pct.textContent = Math.round(clamped) + '%';
|
||||
}
|
||||
if (p.text && sub) sub.textContent = p.text;
|
||||
},
|
||||
|
||||
/* 成功面:已展开则原位切换,否则展开 */
|
||||
success(sourceEl) {
|
||||
if (!state.open) {
|
||||
expandFrom(sourceEl || null, 'success');
|
||||
} else {
|
||||
setStateInternal('success');
|
||||
}
|
||||
},
|
||||
|
||||
/* 错误面:已展开则原位切换(不自动收起),否则展开 */
|
||||
error(message, sourceEl) {
|
||||
document.getElementById('umErrorText').textContent = message || opts.errorDefault;
|
||||
if (state.open) {
|
||||
setStateInternal('error');
|
||||
} else {
|
||||
expandFrom(sourceEl || null, 'error');
|
||||
}
|
||||
},
|
||||
|
||||
/* 验证卡片:从来源元素展开,onSubmit 返回 true 关闭(keepOpen=true 时保持展开)
|
||||
并 resolve 输入值;返回字符串则作为错误显示在卡片内;取消 resolve(null)。 */
|
||||
verify({ title, desc, maxlength = 2, placeholder = '••', okText = '确认',
|
||||
inputFilter = null, sourceEl = null, keepOpen = false, onSubmit }) {
|
||||
return new Promise((resolve) => {
|
||||
const input = document.getElementById('umVerifyInput');
|
||||
const errEl = document.getElementById('umVerifyError');
|
||||
const okBtn = document.getElementById('umVerifyOk');
|
||||
const cancelBtn = document.getElementById('umVerifyCancel');
|
||||
|
||||
document.getElementById('umVerifyTitle').textContent = title;
|
||||
document.getElementById('umVerifyDesc').textContent = desc;
|
||||
okBtn.textContent = okText;
|
||||
input.setAttribute('maxlength', maxlength);
|
||||
input.placeholder = placeholder;
|
||||
input.value = '';
|
||||
errEl.textContent = '';
|
||||
input.classList.remove('um-input-error');
|
||||
okBtn.disabled = false; cancelBtn.disabled = false;
|
||||
|
||||
state.verifyActive = true;
|
||||
let settled = false;
|
||||
|
||||
const cleanup = () => {
|
||||
okBtn.onclick = null; cancelBtn.onclick = null; input.onkeydown = null;
|
||||
dom.backdrop.removeEventListener('click', onBackdrop);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
state.verifyActive = false;
|
||||
};
|
||||
const finish = (value) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
cleanup();
|
||||
if (value !== null && keepOpen && state.open) {
|
||||
resolve(value); // 卡片保持展开,由调用方切换到下一状态
|
||||
} else {
|
||||
collapse(() => resolve(value));
|
||||
}
|
||||
};
|
||||
const submit = async () => {
|
||||
if (settled) return;
|
||||
const value = input.value.trim();
|
||||
if (!value || value.length !== maxlength) {
|
||||
errEl.textContent = `请输入 ${maxlength} 位`;
|
||||
input.classList.add('um-input-error');
|
||||
input.focus();
|
||||
return;
|
||||
}
|
||||
okBtn.disabled = true; cancelBtn.disabled = true;
|
||||
let result;
|
||||
try { result = await onSubmit(value); }
|
||||
catch (e) { result = (e && e.message) || '操作失败,请稍后重试'; }
|
||||
if (result === true) { finish(value); }
|
||||
else {
|
||||
errEl.textContent = result || '验证失败';
|
||||
input.classList.add('um-input-error');
|
||||
okBtn.disabled = false; cancelBtn.disabled = false;
|
||||
/* 抖动写在当前内容面上,避免与容器弹簧逐帧写入的 transform 冲突 */
|
||||
const face = dom.faces[state.activeFace] || dom.faces.verify;
|
||||
if (window.gsap) {
|
||||
gsap.to(face, { x: [-5, 5, -5, 5, 0], duration: 0.4, ease: 'power2.inOut', clearProps: 'x' });
|
||||
} else {
|
||||
face.animate(
|
||||
[{ transform: 'translateX(0)' }, { transform: 'translateX(-5px)' }, { transform: 'translateX(5px)' },
|
||||
{ transform: 'translateX(-5px)' }, { transform: 'translateX(5px)' }, { transform: 'translateX(0)' }],
|
||||
{ duration: 400, easing: 'ease-in-out' });
|
||||
}
|
||||
input.focus(); input.select();
|
||||
}
|
||||
};
|
||||
|
||||
const onBackdrop = () => finish(null);
|
||||
const onKey = (e) => { if (e.key === 'Escape') finish(null); };
|
||||
|
||||
okBtn.onclick = submit;
|
||||
cancelBtn.onclick = () => finish(null);
|
||||
input.onkeydown = (e) => { if (e.key === 'Enter') submit(); };
|
||||
input.oninput = inputFilter ? function () { this.value = inputFilter(this.value); } : null;
|
||||
dom.backdrop.addEventListener('click', onBackdrop);
|
||||
document.addEventListener('keydown', onKey);
|
||||
|
||||
expandFrom(sourceEl, 'verify');
|
||||
setTimeout(() => input.focus(), 500);
|
||||
});
|
||||
},
|
||||
|
||||
/* 确认卡片(如"仅可提交一次"提示):从来源元素展开,无输入框。
|
||||
onConfirm 返回 true 关闭(keepOpen=true 保持展开)并 resolve true;
|
||||
返回字符串则在卡片内显示为错误;取消/backdrop/Esc resolve false。 */
|
||||
confirm({ title = '确认提交', desc = '', okText = '确认提交', cancelText = '取消',
|
||||
sourceEl = null, keepOpen = false, onConfirm }) {
|
||||
return new Promise((resolve) => {
|
||||
const errEl = document.getElementById('umConfirmError');
|
||||
const okBtn = document.getElementById('umConfirmOk');
|
||||
const cancelBtn = document.getElementById('umConfirmCancel');
|
||||
|
||||
document.getElementById('umConfirmTitle').textContent = title;
|
||||
document.getElementById('umConfirmDesc').textContent = desc;
|
||||
okBtn.textContent = okText;
|
||||
cancelBtn.textContent = cancelText;
|
||||
errEl.textContent = '';
|
||||
okBtn.disabled = false; cancelBtn.disabled = false;
|
||||
|
||||
let settled = false;
|
||||
|
||||
const cleanup = () => {
|
||||
okBtn.onclick = null; cancelBtn.onclick = null;
|
||||
dom.backdrop.removeEventListener('click', onBackdrop);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
const finish = (value) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
cleanup();
|
||||
if (value === true && keepOpen && state.open) {
|
||||
resolve(true); // 卡片保持展开,由调用方切换到下一状态
|
||||
} else {
|
||||
collapse(() => resolve(value));
|
||||
}
|
||||
};
|
||||
const submit = async () => {
|
||||
if (settled) return;
|
||||
okBtn.disabled = true; cancelBtn.disabled = true;
|
||||
let result;
|
||||
try { result = onConfirm ? await onConfirm() : true; }
|
||||
catch (e) { result = (e && e.message) || '操作失败,请稍后重试'; }
|
||||
if (result === true) { finish(true); }
|
||||
else {
|
||||
errEl.textContent = result || '操作失败';
|
||||
okBtn.disabled = false; cancelBtn.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onBackdrop = () => finish(false);
|
||||
const onKey = (e) => { if (e.key === 'Escape') finish(false); };
|
||||
|
||||
okBtn.onclick = submit;
|
||||
cancelBtn.onclick = () => finish(false);
|
||||
dom.backdrop.addEventListener('click', onBackdrop);
|
||||
document.addEventListener('keydown', onKey);
|
||||
|
||||
expandFrom(sourceEl, 'confirm');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.MorphCard = {
|
||||
/* 初始化:注入样式与 DOM,返回 API(单例,重复调用返回同一实例) */
|
||||
init(options) {
|
||||
if (dom) return api;
|
||||
opts = Object.assign({
|
||||
successTitle: '提交成功',
|
||||
successDesc: '您填写的数据已保存。',
|
||||
doneText: '确定',
|
||||
errorTitle: '无法提交',
|
||||
errorDefault: '提交失败,请稍后重试',
|
||||
backText: '返回修改',
|
||||
progressLabel: '正在上传',
|
||||
onExpand: null,
|
||||
onCollapse: null
|
||||
}, options || {});
|
||||
|
||||
dom = buildDom(opts);
|
||||
|
||||
document.getElementById('umDoneBtn').addEventListener('click', () => api.close());
|
||||
document.getElementById('umErrorBack').addEventListener('click', () => api.close());
|
||||
dom.backdrop.addEventListener('click', () => {
|
||||
if (state.verifyActive) return; // 验证中由 verify 的取消逻辑处理
|
||||
api.close();
|
||||
});
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && !state.verifyActive) api.close();
|
||||
});
|
||||
|
||||
return api;
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,297 @@
|
||||
// particles.js - CSDN 风格柔和粒子网格背景
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
class ParticleSystem {
|
||||
constructor(options = {}) {
|
||||
this.canvas = null;
|
||||
this.ctx = null;
|
||||
this.particles = [];
|
||||
this.animationId = null;
|
||||
|
||||
// CSDN 风格配置:极其 subtle
|
||||
this.config = {
|
||||
particleCount: options.particleCount || null, // 默认根据屏幕计算
|
||||
connectionDistance: options.connectionDistance || 100, // 连线距离短
|
||||
mouseDistance: options.mouseDistance || 120, // 鼠标影响范围
|
||||
attractStrength: options.attractStrength || 0.04, // 极弱的吸引力
|
||||
speed: options.speed || 0.4, // 缓慢的漂移速度
|
||||
size: { min: 2, max: 4 }, // 极小的粒子
|
||||
opacity: { min: 0.3, max: 0.6 }, // 很淡的透明度
|
||||
zIndex: options.zIndex || -1, // 放在内容后面
|
||||
colorLight: '100, 100, 100', // 浅灰色(亮色模式)
|
||||
colorDark: '150, 150, 150', // 中灰色(暗色模式)
|
||||
lineOpacity: 0.2, // 极淡的连线
|
||||
maxConnections: 5, // 限制连线数量避免杂乱
|
||||
bgColor: options.bgColor || null // 背景色(可选)
|
||||
};
|
||||
|
||||
this.mouse = { x: null, y: null, active: false };
|
||||
this.isDark = false;
|
||||
this.dpr = window.devicePixelRatio || 1;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
if (document.getElementById('particleCanvas')) return;
|
||||
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.canvas.id = 'particleCanvas';
|
||||
this.canvas.style.cssText = `
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: ${this.config.zIndex};
|
||||
pointer-events: none;
|
||||
touch-action: none;
|
||||
opacity: 0.6; /* 整体再淡一点 */
|
||||
`;
|
||||
|
||||
document.body.insertBefore(this.canvas, document.body.firstChild);
|
||||
this.ctx = this.canvas.getContext('2d', { alpha: true });
|
||||
|
||||
this.resize();
|
||||
window.addEventListener('resize', () => this.resize(), { passive: true });
|
||||
|
||||
this.initEvents();
|
||||
this.initThemeListener();
|
||||
this.createParticles();
|
||||
this.visibilityHandler = () => {
|
||||
if (document.hidden) {
|
||||
if (this.animationId) cancelAnimationFrame(this.animationId);
|
||||
this.animationId = null;
|
||||
} else if (!this.animationId) {
|
||||
this.animate();
|
||||
}
|
||||
};
|
||||
document.addEventListener('visibilitychange', this.visibilityHandler);
|
||||
this.animate();
|
||||
}
|
||||
|
||||
initEvents() {
|
||||
// 鼠标移动(极其平滑的跟随)
|
||||
const updateMouse = (x, y) => {
|
||||
this.mouse.x = x;
|
||||
this.mouse.y = y;
|
||||
this.mouse.active = true;
|
||||
|
||||
// 延迟取消 active 状态,避免闪烁
|
||||
clearTimeout(this.mouseTimer);
|
||||
this.mouseTimer = setTimeout(() => {
|
||||
this.mouse.active = false;
|
||||
}, 100);
|
||||
};
|
||||
|
||||
window.addEventListener('mousemove', (e) => {
|
||||
updateMouse(e.clientX, e.clientY);
|
||||
}, { passive: true });
|
||||
|
||||
// 触摸支持
|
||||
window.addEventListener('touchstart', (e) => {
|
||||
if (e.touches[0]) updateMouse(e.touches[0].clientX, e.touches[0].clientY);
|
||||
}, { passive: true });
|
||||
|
||||
window.addEventListener('touchmove', (e) => {
|
||||
if (e.touches[0]) updateMouse(e.touches[0].clientX, e.touches[0].clientY);
|
||||
}, { passive: true });
|
||||
|
||||
window.addEventListener('touchend', () => {
|
||||
this.mouse.active = false;
|
||||
});
|
||||
}
|
||||
|
||||
resize() {
|
||||
this.width = window.innerWidth;
|
||||
this.height = window.innerHeight;
|
||||
|
||||
this.canvas.width = this.width * this.dpr;
|
||||
this.canvas.height = this.height * this.dpr;
|
||||
this.canvas.style.width = this.width + 'px';
|
||||
this.canvas.style.height = this.height + 'px';
|
||||
this.ctx.scale(this.dpr, this.dpr);
|
||||
|
||||
// 根据屏幕面积计算粒子数:每 20000 像素一个粒子,最少 40,最多 100
|
||||
if (!this.config.particleCount) {
|
||||
const area = this.width * this.height;
|
||||
this.targetCount = Math.min(Math.max(Math.floor(area / 20000), 40), 100);
|
||||
}
|
||||
}
|
||||
|
||||
initThemeListener() {
|
||||
this.checkTheme();
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
mediaQuery.addEventListener('change', () => this.checkTheme());
|
||||
|
||||
const observer = new MutationObserver(() => this.checkTheme());
|
||||
observer.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class', 'data-theme']
|
||||
});
|
||||
}
|
||||
|
||||
checkTheme() {
|
||||
const html = document.documentElement;
|
||||
this.isDark = html.classList.contains('dark') ||
|
||||
html.getAttribute('data-theme') === 'dark' ||
|
||||
(!html.classList.contains('light') &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
}
|
||||
|
||||
createParticles() {
|
||||
const count = this.config.particleCount || this.targetCount || 60;
|
||||
this.particles = []; // 清空已有
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.particles.push({
|
||||
x: Math.random() * this.width,
|
||||
y: Math.random() * this.height,
|
||||
// 基础速度:极小的随机漂移
|
||||
vx: (Math.random() - 0.75) * this.config.speed,
|
||||
vy: (Math.random() - 0.75) * this.config.speed,
|
||||
size: Math.random() * (this.config.size.max - this.config.size.min) + this.config.size.min,
|
||||
opacity: Math.random() * (this.config.opacity.max - this.config.opacity.min) + this.config.opacity.min,
|
||||
// 每个粒子有独立的相位,用于正弦波动,让运动更自然
|
||||
phase: Math.random() * Math.PI * 2,
|
||||
phaseSpeed: 0.02 + Math.random() * 0.02
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateParticle(p) {
|
||||
// 正弦波动:让漂移更柔和自然
|
||||
p.phase += p.phaseSpeed;
|
||||
const waveX = Math.sin(p.phase) * 0.1;
|
||||
const waveY = Math.cos(p.phase * 0.7) * 0.1;
|
||||
|
||||
// 基础漂移
|
||||
p.x += p.vx + waveX;
|
||||
p.y += p.vy + waveY;
|
||||
|
||||
// 鼠标吸引效果(极其柔和)
|
||||
if (this.mouse.active && this.mouse.x !== null) {
|
||||
const dx = this.mouse.x - p.x;
|
||||
const dy = this.mouse.y - p.y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < this.config.mouseDistance) {
|
||||
// 距离越近吸引越弱(避免聚集太紧),越远吸引越强但总体很弱
|
||||
const force = (1 - dist / this.config.mouseDistance) * this.config.attractStrength;
|
||||
p.vx += dx * force * 0.01;
|
||||
p.vy += dy * force * 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
// 速度限制和阻尼(保持柔和感)
|
||||
const maxSpeed = this.config.speed * 1.5;
|
||||
p.vx = Math.max(-maxSpeed, Math.min(maxSpeed, p.vx));
|
||||
p.vy = Math.max(-maxSpeed, Math.min(maxSpeed, p.vy));
|
||||
|
||||
// 极小的阻尼,让速度慢慢回归基础值
|
||||
p.vx *= 0.995;
|
||||
p.vy *= 0.995;
|
||||
|
||||
// 软边界:不是硬反弹,而是慢慢转向
|
||||
const margin = 50;
|
||||
if (p.x < -margin) p.x = this.width + margin;
|
||||
if (p.x > this.width + margin) p.x = -margin;
|
||||
if (p.y < -margin) p.y = this.height + margin;
|
||||
if (p.y > this.height + margin) p.y = -margin;
|
||||
}
|
||||
|
||||
draw() {
|
||||
const color = this.isDark ? this.config.colorDark : this.config.colorLight;
|
||||
|
||||
// 绘制连线(在粒子下层)
|
||||
this.drawConnections(color);
|
||||
|
||||
// 绘制粒子
|
||||
this.particles.forEach(p => {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
||||
this.ctx.fillStyle = `rgba(${color}, ${p.opacity})`;
|
||||
this.ctx.fill();
|
||||
});
|
||||
}
|
||||
|
||||
drawConnections(color) {
|
||||
// 只检查部分粒子对,优化性能
|
||||
for (let i = 0; i < this.particles.length; i++) {
|
||||
let connections = 0;
|
||||
const p1 = this.particles[i];
|
||||
|
||||
// 只检查附近的粒子(简单空间分割思想:只检查索引接近的)
|
||||
for (let j = i + 1; j < Math.min(i + 20, this.particles.length); j++) {
|
||||
if (connections >= this.config.maxConnections) break;
|
||||
|
||||
const p2 = this.particles[j];
|
||||
const dx = p1.x - p2.x;
|
||||
const dy = p1.y - p2.y;
|
||||
const distSq = dx * dx + dy * dy;
|
||||
|
||||
if (distSq < this.config.connectionDistance * this.config.connectionDistance) {
|
||||
const dist = Math.sqrt(distSq);
|
||||
const opacity = this.config.lineOpacity * (1 - dist / this.config.connectionDistance);
|
||||
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(p1.x, p1.y);
|
||||
this.ctx.lineTo(p2.x, p2.y);
|
||||
this.ctx.strokeStyle = `rgba(${color}, ${opacity})`;
|
||||
this.ctx.lineWidth = 0.5;
|
||||
this.ctx.stroke();
|
||||
|
||||
connections++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
animate() {
|
||||
this.ctx.clearRect(0, 0, this.width, this.height);
|
||||
|
||||
this.particles.forEach(p => this.updateParticle(p));
|
||||
this.draw();
|
||||
|
||||
this.animationId = requestAnimationFrame(() => this.animate());
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.animationId) cancelAnimationFrame(this.animationId);
|
||||
if (this.visibilityHandler) document.removeEventListener('visibilitychange', this.visibilityHandler);
|
||||
if (this.canvas && this.canvas.parentNode) {
|
||||
this.canvas.parentNode.removeChild(this.canvas);
|
||||
}
|
||||
window.particleSystem = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 自动初始化
|
||||
function autoInit() {
|
||||
if (document.body?.hasAttribute('data-no-particles')) return;
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
if (window.particleSystem) return;
|
||||
if (!document.body) {
|
||||
setTimeout(autoInit, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
const options = {};
|
||||
if (document.body.dataset.particleCount) {
|
||||
options.particleCount = parseInt(document.body.dataset.particleCount);
|
||||
}
|
||||
|
||||
window.particleSystem = new ParticleSystem(options);
|
||||
}
|
||||
|
||||
window.ParticleSystem = ParticleSystem;
|
||||
window.initParticles = (opts) => new ParticleSystem(opts);
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', autoInit);
|
||||
} else {
|
||||
setTimeout(autoInit, 0);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,250 @@
|
||||
/**
|
||||
* Toast 3D Stack - 健壮版本
|
||||
*/
|
||||
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
const icons = {
|
||||
success: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>`,
|
||||
error: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>`,
|
||||
info: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>`,
|
||||
warning: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`
|
||||
};
|
||||
|
||||
let toastId = 0;
|
||||
const MAX_STACK = 5;
|
||||
const DISPLAY_TIME = 4000;
|
||||
let isReady = false;
|
||||
const pendingQueue = [];
|
||||
const isMobile = window.matchMedia('(max-width: 640px)').matches;
|
||||
|
||||
let touchStartY = 0;
|
||||
let isDragging = false;
|
||||
let currentToast = null;
|
||||
|
||||
function checkReady() {
|
||||
return document.readyState === 'complete' || document.readyState === 'interactive';
|
||||
}
|
||||
|
||||
function ensureReady(callback) {
|
||||
if (isReady || checkReady()) {
|
||||
isReady = true;
|
||||
callback();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
isReady = true;
|
||||
callback();
|
||||
}, { once: true });
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer() {
|
||||
let stage = document.getElementById('toast-stage');
|
||||
if (!stage) {
|
||||
stage = document.createElement('div');
|
||||
stage.id = 'toast-stage';
|
||||
const container = document.createElement('div');
|
||||
container.id = 'toast-container';
|
||||
stage.appendChild(container);
|
||||
|
||||
if (document.body) {
|
||||
document.body.appendChild(stage);
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.body.appendChild(stage);
|
||||
}, { once: true });
|
||||
}
|
||||
}
|
||||
return stage.querySelector('#toast-container');
|
||||
}
|
||||
|
||||
function createToast(message, type) {
|
||||
const el = document.createElement('div');
|
||||
el.className = `toast ${type} entering`;
|
||||
el.dataset.id = ++toastId;
|
||||
|
||||
el.innerHTML = `
|
||||
<div style="flex-shrink:0;width:20px;height:20px;">${icons[type] || icons.info}</div>
|
||||
<div style="flex:1;min-width:0;">${escapeHtml(message)}</div>
|
||||
`;
|
||||
|
||||
if (isMobile) {
|
||||
attachTouchEvents(el);
|
||||
}
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
function attachTouchEvents(el) {
|
||||
el.addEventListener('touchstart', handleTouchStart, { passive: true });
|
||||
el.addEventListener('touchmove', handleTouchMove, { passive: true });
|
||||
el.addEventListener('touchend', handleTouchEnd, { passive: true });
|
||||
el.addEventListener('click', () => removeToast(el));
|
||||
}
|
||||
|
||||
function handleTouchStart(e) {
|
||||
const touch = e.touches[0];
|
||||
touchStartY = touch.clientY;
|
||||
isDragging = true;
|
||||
currentToast = e.currentTarget;
|
||||
currentToast.classList.add('swiping');
|
||||
}
|
||||
|
||||
function handleTouchMove(e) {
|
||||
if (!isDragging || !currentToast) return;
|
||||
const touch = e.touches[0];
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
if (deltaY > 0) {
|
||||
const opacity = Math.max(0.3, 1 - deltaY / 200);
|
||||
currentToast.style.transform = `translateY(${deltaY}px) scale(${Math.max(0.95, 1 - deltaY / 1000)})`;
|
||||
currentToast.style.opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
function handleTouchEnd(e) {
|
||||
if (!isDragging || !currentToast) return;
|
||||
const touch = e.changedTouches[0];
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
currentToast.classList.remove('swiping');
|
||||
if (deltaY > 80) {
|
||||
removeToast(currentToast);
|
||||
} else {
|
||||
currentToast.style.transform = '';
|
||||
currentToast.style.opacity = '';
|
||||
}
|
||||
isDragging = false;
|
||||
currentToast = null;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function removeToast(el, immediate = false) {
|
||||
if (!el || el.classList.contains('exiting')) return;
|
||||
if (immediate) {
|
||||
el.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
el.classList.add('exiting');
|
||||
if (isMobile) {
|
||||
// 移动端出场:向下滑出 + 缩小,与入场对称
|
||||
el.style.transform = 'translateY(20px) scale(0.95)';
|
||||
el.style.opacity = '0';
|
||||
el.style.transition = 'transform 0.3s ease, opacity 0.25s ease';
|
||||
} else {
|
||||
el.style.transform = 'translateX(100px) translateZ(-100px) scale(0.8) rotateY(-15deg)';
|
||||
el.style.opacity = '0';
|
||||
el.style.transition = 'transform 0.35s ease, opacity 0.3s ease';
|
||||
}
|
||||
el.style.pointerEvents = 'none';
|
||||
|
||||
setTimeout(() => {
|
||||
if (el.parentNode) el.remove();
|
||||
}, isMobile ? 300 : 350);
|
||||
}
|
||||
|
||||
function processShow(message, type) {
|
||||
const container = getContainer();
|
||||
if (!container) {
|
||||
pendingQueue.push({ message, type });
|
||||
return;
|
||||
}
|
||||
|
||||
if (isMobile && container.children.length > 0) {
|
||||
Array.from(container.children).forEach(oldToast => removeToast(oldToast, true));
|
||||
}
|
||||
|
||||
const existingToasts = Array.from(container.children);
|
||||
if (!isMobile) {
|
||||
existingToasts.forEach(toast => toast.classList.add('shift-down'));
|
||||
}
|
||||
|
||||
const el = createToast(message, type);
|
||||
container.prepend(el);
|
||||
|
||||
// 强制同步重排
|
||||
void el.offsetHeight;
|
||||
|
||||
// 桌面端:强制设置初始状态
|
||||
if (!isMobile) {
|
||||
el.style.transform = 'translateX(-120px) translateZ(50px) rotateY(25deg)';
|
||||
el.style.opacity = '0';
|
||||
el.style.transition = 'none';
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
void el.offsetHeight;
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
el.classList.add('show');
|
||||
|
||||
if (!isMobile) {
|
||||
el.style.transform = '';
|
||||
el.style.opacity = '';
|
||||
el.style.transition = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
el.classList.remove('entering', 'show');
|
||||
if (!isMobile) {
|
||||
el.style.cssText = '';
|
||||
existingToasts.forEach(toast => {
|
||||
if (toast.parentNode) toast.classList.remove('shift-down');
|
||||
});
|
||||
}
|
||||
}, 600);
|
||||
|
||||
if (!isMobile && container.children.length > MAX_STACK) {
|
||||
const oldest = container.lastElementChild;
|
||||
if (oldest) {
|
||||
oldest.style.transition = 'all 0.3s ease';
|
||||
oldest.style.opacity = '0';
|
||||
oldest.style.transform = 'translateZ(-250px) scale(0.7)';
|
||||
setTimeout(() => oldest.remove(), 300);
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => removeToast(el), DISPLAY_TIME);
|
||||
}
|
||||
|
||||
function show(message, type = 'info') {
|
||||
ensureReady(() => processShow(message, type));
|
||||
}
|
||||
|
||||
function processQueue() {
|
||||
while (pendingQueue.length > 0) {
|
||||
const { message, type } = pendingQueue.shift();
|
||||
processShow(message, type);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkReady()) {
|
||||
processQueue();
|
||||
} else {
|
||||
window.addEventListener('load', processQueue);
|
||||
}
|
||||
|
||||
global.Toast = {
|
||||
show,
|
||||
success: (msg) => show(msg, 'success'),
|
||||
error: (msg) => show(msg, 'error'),
|
||||
info: (msg) => show(msg, 'info'),
|
||||
warning: (msg) => show(msg, 'warning'),
|
||||
clear: () => {
|
||||
const container = getContainer();
|
||||
if (container) {
|
||||
Array.from(container.children).forEach(el => removeToast(el, true));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
global.showToast = (msg, type = 'success') => show(msg, type);
|
||||
|
||||
})(window);
|
||||
@@ -0,0 +1,10 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
function load(config = {}) {
|
||||
document.getElementById('enableWebhook').checked = config.enabled === true;
|
||||
}
|
||||
function read() {
|
||||
return { enabled: document.getElementById('enableWebhook').checked };
|
||||
}
|
||||
window.FormWebhookSettings = { load, read };
|
||||
})();
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Robert Wildling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE WITH OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||