比较提交
5 次代码提交
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "theme-terminal",
|
||||
"private": true,
|
||||
"version": "1.1.8",
|
||||
"version": "1.1.9",
|
||||
"description": "A terminal like theme for Halo.",
|
||||
"scripts": {
|
||||
"dev": "vite build --watch",
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
// 非文字元素列表
|
||||
const NON_TEXT_ELEMENTS = ['img', 'hr', 'table', 'figure', 'video', 'audio', 'canvas', 'svg', 'iframe'];
|
||||
|
||||
// 默认行高倍数
|
||||
const DEFAULT_LINE_HEIGHT_RATIO = 1.54;
|
||||
|
||||
// 工具函数:创建行号元素
|
||||
function createLineSpan(lineNum: number, top: number, height: number, isGap = false): HTMLSpanElement {
|
||||
const span = document.createElement('span');
|
||||
span.className = isGap ? 'line-number line-number--gap' : 'line-number';
|
||||
span.style.top = `${top}px`;
|
||||
span.style.height = `${height}px`;
|
||||
span.style.lineHeight = `${height}px`;
|
||||
span.textContent = String(lineNum);
|
||||
return span;
|
||||
}
|
||||
|
||||
// 工具函数:获取元素的 padding
|
||||
function getElementPadding(style: CSSStyleDeclaration): { top: number; bottom: number } {
|
||||
return {
|
||||
top: parseFloat(style.paddingTop) || 0,
|
||||
bottom: parseFloat(style.paddingBottom) || 0
|
||||
};
|
||||
}
|
||||
|
||||
// 工具函数:计算默认行高
|
||||
function getDefaultLineHeight(element: HTMLElement): number {
|
||||
const style = getComputedStyle(element);
|
||||
const fontSize = parseFloat(style.fontSize);
|
||||
return parseFloat(style.lineHeight) || fontSize * DEFAULT_LINE_HEIGHT_RATIO;
|
||||
}
|
||||
|
||||
// 工具函数:判断是否为非文��元素
|
||||
function isNonTextElement(tagName: string): boolean {
|
||||
return NON_TEXT_ELEMENTS.includes(tagName.toLowerCase());
|
||||
}
|
||||
|
||||
// 工具函数:计算元素占用的行数
|
||||
function calculateElementLines(element: HTMLElement, defaultLineHeight: number): number {
|
||||
const tagName = element.tagName.toLowerCase();
|
||||
const style = getComputedStyle(element);
|
||||
const padding = getElementPadding(style);
|
||||
const contentHeight = element.offsetHeight - padding.top - padding.bottom;
|
||||
|
||||
// 非文字元素整体算作一行
|
||||
if (isNonTextElement(tagName)) return 1;
|
||||
|
||||
// 获取行高
|
||||
const lineHeight = parseFloat(style.lineHeight) || defaultLineHeight;
|
||||
|
||||
return Math.max(1, Math.round(contentHeight / lineHeight));
|
||||
}
|
||||
|
||||
// 填充空白间隙的行号
|
||||
function appendGapLines(
|
||||
fragment: DocumentFragment,
|
||||
gapStart: number,
|
||||
gapEnd: number,
|
||||
lineHeight: number,
|
||||
startLine: number
|
||||
): number {
|
||||
const gapLines = Math.round((gapEnd - gapStart) / lineHeight);
|
||||
for (let i = 0; i < gapLines; i++) {
|
||||
fragment.appendChild(
|
||||
createLineSpan(startLine + i, gapStart + i * lineHeight, lineHeight, true)
|
||||
);
|
||||
}
|
||||
return startLine + gapLines;
|
||||
}
|
||||
|
||||
// 生成元素内容的行号
|
||||
function appendElementLines(
|
||||
fragment: DocumentFragment,
|
||||
element: HTMLElement,
|
||||
defaultLineHeight: number,
|
||||
startLine: number
|
||||
): number {
|
||||
const style = getComputedStyle(element);
|
||||
const padding = getElementPadding(style);
|
||||
const elementTop = element.offsetTop;
|
||||
const elementHeight = element.offsetHeight;
|
||||
|
||||
const lines = calculateElementLines(element, defaultLineHeight);
|
||||
const contentHeight = elementHeight - padding.top - padding.bottom;
|
||||
const lineHeight = contentHeight / lines;
|
||||
const startTop = elementTop + padding.top;
|
||||
|
||||
for (let i = 0; i < lines; i++) {
|
||||
fragment.appendChild(
|
||||
createLineSpan(startLine + i, startTop + i * lineHeight, lineHeight)
|
||||
);
|
||||
}
|
||||
|
||||
return startLine + lines;
|
||||
}
|
||||
|
||||
interface LineNumbersState {
|
||||
$el?: HTMLElement;
|
||||
totalLines: number;
|
||||
resizeObserver: ResizeObserver | null;
|
||||
init(): void;
|
||||
calculateLineNumbers(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
export const lineNumbers = (): LineNumbersState => ({
|
||||
totalLines: 0,
|
||||
resizeObserver: null,
|
||||
|
||||
init() {
|
||||
const content = (this.$el as HTMLElement).querySelector('.post-content') as HTMLElement;
|
||||
|
||||
if (!content) return;
|
||||
|
||||
// 延迟计算确保 DOM 渲染完成
|
||||
requestAnimationFrame(() => {
|
||||
setTimeout(() => this.calculateLineNumbers(), 50);
|
||||
});
|
||||
|
||||
// 监听内容区域大小变化
|
||||
if (typeof ResizeObserver !== 'undefined') {
|
||||
this.resizeObserver = new ResizeObserver(() => this.calculateLineNumbers());
|
||||
this.resizeObserver.observe(content);
|
||||
}
|
||||
|
||||
// 窗口大小变化时重新计算(备用)
|
||||
let resizeTimer: number;
|
||||
window.addEventListener('resize', () => {
|
||||
clearTimeout(resizeTimer);
|
||||
resizeTimer = window.setTimeout(() => this.calculateLineNumbers(), 200);
|
||||
});
|
||||
|
||||
// 监听图片加载
|
||||
content.querySelectorAll('img').forEach((img: HTMLImageElement) => {
|
||||
if (!img.complete) {
|
||||
img.addEventListener('load', () => this.calculateLineNumbers());
|
||||
img.addEventListener('error', () => this.calculateLineNumbers());
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.resizeObserver?.disconnect();
|
||||
},
|
||||
|
||||
calculateLineNumbers() {
|
||||
const content = this.$el?.querySelector('.post-content') as HTMLElement;
|
||||
const gutter = this.$el?.querySelector('.post-line-gutter') as HTMLElement;
|
||||
|
||||
if (!content || !gutter) return;
|
||||
|
||||
const defaultLineHeight = getDefaultLineHeight(content);
|
||||
const container = content.querySelector(':scope > div') || content;
|
||||
const blockElements = container.querySelectorAll(':scope > *');
|
||||
|
||||
gutter.innerHTML = '';
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
let currentLine = 1;
|
||||
let lastBottom = 0;
|
||||
|
||||
blockElements.forEach((el: Element) => {
|
||||
const element = el as HTMLElement;
|
||||
const elementTop = element.offsetTop;
|
||||
|
||||
// 填充空白间隙
|
||||
if (lastBottom > 0 && elementTop > lastBottom) {
|
||||
currentLine = appendGapLines(fragment, lastBottom, elementTop, defaultLineHeight, currentLine);
|
||||
}
|
||||
|
||||
// 生成元素行号
|
||||
currentLine = appendElementLines(fragment, element, defaultLineHeight, currentLine);
|
||||
lastBottom = elementTop + element.offsetHeight;
|
||||
});
|
||||
|
||||
this.totalLines = currentLine - 1;
|
||||
gutter.appendChild(fragment);
|
||||
gutter.style.height = `${container.scrollHeight}px`;
|
||||
}
|
||||
});
|
||||
+2
@@ -6,6 +6,7 @@ import Alpine from 'alpinejs'
|
||||
import {upvote} from './alpine/upvote'
|
||||
import {themeMode} from './alpine/themeMode'
|
||||
import {menu} from './alpine/menu'
|
||||
import {lineNumbers} from './alpine/lineNumbers'
|
||||
import {typewriterEffect} from './utils'
|
||||
|
||||
window.Alpine = Alpine
|
||||
@@ -13,6 +14,7 @@ window.Alpine = Alpine
|
||||
Alpine.data('upvote', upvote)
|
||||
Alpine.data('themeMode', themeMode)
|
||||
Alpine.data('menu', menu)
|
||||
Alpine.data('lineNumbers', lineNumbers)
|
||||
|
||||
Alpine.start()
|
||||
|
||||
|
||||
+6
-9
@@ -158,7 +158,7 @@
|
||||
|
||||
&.open {
|
||||
display: block;
|
||||
animation: terminal-frame 0.2s ease-out;
|
||||
animation: terminal-frame-reveal 0.3s ease-out forwards;
|
||||
|
||||
// 逐行渲染效果 - 为每个子项添加延迟动画
|
||||
li {
|
||||
@@ -182,17 +182,14 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
// 菜单框架渲染动画 - 模拟终端窗口从上到下打开
|
||||
@keyframes terminal-frame {
|
||||
// 菜单框架渲染动画 - 从上到下逐层渲染边框和内容
|
||||
@keyframes terminal-frame-reveal {
|
||||
0% {
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
clip-path: inset(-10px -10px calc(100% + 10px) -10px);
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
max-height: 800px;
|
||||
clip-path: inset(-10px -10px -10px -10px);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +198,7 @@
|
||||
@keyframes terminal-line {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateX(-10px);
|
||||
transform: translateX(-2px);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
|
||||
@@ -173,15 +173,6 @@ blockquote {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
&:before {
|
||||
content: '”';
|
||||
font-family: Georgia, serif;
|
||||
font-size: 3.875rem;
|
||||
position: absolute;
|
||||
left: -40px;
|
||||
top: -20px;
|
||||
}
|
||||
|
||||
p:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
+92
-2
@@ -38,6 +38,8 @@
|
||||
}
|
||||
|
||||
%meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 1rem;
|
||||
margin-bottom: 10px;
|
||||
color: var(--brightBlue);
|
||||
@@ -53,6 +55,30 @@
|
||||
display: inline;
|
||||
}
|
||||
|
||||
&-separator {
|
||||
position: relative;
|
||||
top: 1px;
|
||||
display: inline-grid;
|
||||
grid-template-columns: repeat(2, 3px);
|
||||
grid-template-rows: repeat(2, 3px);
|
||||
gap: 2px;
|
||||
margin: 0 6px;
|
||||
|
||||
span {
|
||||
width: 2px;
|
||||
height: 2px;
|
||||
background-color: var(--brightBlue);
|
||||
border-radius: 50%;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
// 每个点使用不同动画和时长,形成随机效果
|
||||
span:nth-child(1) { animation: dot-blink-1 2.8s ease-in-out infinite; }
|
||||
span:nth-child(2) { animation: dot-blink-2 2.2s ease-in-out infinite 0.4s; }
|
||||
span:nth-child(3) { animation: dot-blink-3 3.4s ease-in-out infinite 1s; }
|
||||
span:nth-child(4) { animation: dot-blink-4 2.6s ease-in-out infinite 0.2s; }
|
||||
}
|
||||
|
||||
&-title {
|
||||
--border: 3px dotted var(--blue);
|
||||
|
||||
@@ -102,9 +128,43 @@
|
||||
}
|
||||
}
|
||||
|
||||
&-content {
|
||||
&-body {
|
||||
position: relative;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
&-line-gutter {
|
||||
position: absolute;
|
||||
left: -60px;
|
||||
top: 0;
|
||||
width: 40px;
|
||||
user-select: none;
|
||||
opacity: 0.5;
|
||||
border-right: 1px solid var(--foreground);
|
||||
|
||||
@media (max-width: $tablet-max-width) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.line-number {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
font-size: 0.75rem;
|
||||
color: var(--foreground);
|
||||
font-family: Hack, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.line-number--gap {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
&-content {
|
||||
font-family: Hack, Monaco, Consolas, 'Ubuntu Mono', PingHei, 'PingFang SC', 'Microsoft YaHei', monospace;
|
||||
line-height: 1.54;
|
||||
}
|
||||
|
||||
&-cover {
|
||||
@@ -172,4 +232,34 @@
|
||||
.comment-wrap {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 4个不同的随机动画模式
|
||||
@keyframes dot-blink-1 {
|
||||
0%, 100% { opacity: 0.2; }
|
||||
25% { opacity: 1; }
|
||||
50% { opacity: 0.3; }
|
||||
75% { opacity: 0.8; }
|
||||
}
|
||||
|
||||
@keyframes dot-blink-2 {
|
||||
0%, 100% { opacity: 0.3; }
|
||||
30% { opacity: 0.9; }
|
||||
60% { opacity: 0.2; }
|
||||
85% { opacity: 0.7; }
|
||||
}
|
||||
|
||||
@keyframes dot-blink-3 {
|
||||
0%, 100% { opacity: 0.2; }
|
||||
20% { opacity: 0.6; }
|
||||
45% { opacity: 1; }
|
||||
70% { opacity: 0.4; }
|
||||
}
|
||||
|
||||
@keyframes dot-blink-4 {
|
||||
0%, 100% { opacity: 0.4; }
|
||||
15% { opacity: 0.2; }
|
||||
40% { opacity: 0.8; }
|
||||
65% { opacity: 1; }
|
||||
90% { opacity: 0.3; }
|
||||
}
|
||||
|
||||
+10
-7
@@ -12,18 +12,21 @@
|
||||
<div class="posts">
|
||||
<div class="post on-list" th:each="post : ${posts.items}">
|
||||
<h1 class="post-title">
|
||||
<a th:text="${post.spec.title}" th:href="${post.status.permalink}">Post Title</a>
|
||||
<a th:text="'< ' + ${post.spec.title} + ' >'" th:href="${post.status.permalink}">Post Title</a>
|
||||
</h1>
|
||||
<div class="post-meta">
|
||||
<span class="post-date" th:text="${#dates.format(post.spec.publishTime,'yyyy-MM-dd')}">
|
||||
Post CreateTime
|
||||
</span>
|
||||
<span
|
||||
class="post-author"
|
||||
th:with="contributor = ${post.contributors[0]}"
|
||||
th:text="${':: '+contributor.displayName}"
|
||||
>:: Author</span
|
||||
>
|
||||
<span class="post-separator">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</span>
|
||||
<span class="post-author" th:with="contributor = ${post.contributors[0]}" th:text="${contributor.displayName}">
|
||||
Author
|
||||
</span>
|
||||
</div>
|
||||
<span class="post-tags-inline" th:each="tag : ${post.tags}">
|
||||
<a
|
||||
|
||||
+14
-5
@@ -4,11 +4,17 @@
|
||||
th:replace="~{modules/layout :: html(title = |${post.spec.title} - ${site.title}|, header = null, content = ~{::content}, footer = null)}"
|
||||
>
|
||||
<th:block th:fragment="content">
|
||||
<div class="post">
|
||||
<h1 class="post-title" th:text="${post.spec.title}">Post Title</h1>
|
||||
<div class="post" x-data="lineNumbers" x-init="init()">
|
||||
<h1 class="post-title" th:text="'< ' + ${post.spec.title} + ' >'">Post Title</h1>
|
||||
<div class="post-meta">
|
||||
<span class="post-date" th:text="${#dates.format(post.spec.publishTime,'yyyy-MM-dd')}"> publishTime </span>
|
||||
<span class="post-author" th:text="${':: '+post.owner.displayName}">:: Author</span>
|
||||
<span class="post-separator">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</span>
|
||||
<span class="post-author" th:text="${post.owner.displayName}">Author</span>
|
||||
</div>
|
||||
<span class="post-tags-inline" th:each="tag : ${post.tags}">
|
||||
<a
|
||||
@@ -19,8 +25,11 @@
|
||||
>#Tag</a
|
||||
>
|
||||
</span>
|
||||
<div class="post-content">
|
||||
<div th:utext="${post.content.content}">Post Content</div>
|
||||
<div class="post-body">
|
||||
<div class="post-line-gutter"></div>
|
||||
<div class="post-content">
|
||||
<div th:utext="${post.content.content}">Post Content</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="comment-wrap" th:if="${haloCommentEnabled}">
|
||||
|
||||
+1
-1
@@ -13,5 +13,5 @@ spec:
|
||||
repo: https://git.dev.cm/theme-terminal
|
||||
settingName: "theme-terminal-setting"
|
||||
configMapName: "theme-terminal-configMap"
|
||||
version: 1.1.8
|
||||
version: 1.1.9
|
||||
require: ">=2.22.0"
|
||||
|
||||
在新议题中引用
屏蔽一个用户