hexo-theme-linen 1.0.46 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/layout/post.ejs +298 -0
- package/package.json +1 -1
- package/source/linen-theme/css/linen.scss +37 -10
- package/source/linen-theme/js/hdr.js +0 -16
package/layout/post.ejs
CHANGED
|
@@ -315,11 +315,26 @@ const seriesInfo = getSeriesInfo(page?.series);
|
|
|
315
315
|
};
|
|
316
316
|
const isHDRScreen = typeof window.matchMedia === 'function' &&
|
|
317
317
|
window.matchMedia('(dynamic-range: high)').matches;
|
|
318
|
+
let pendingOpenPromise = null;
|
|
318
319
|
const lightbox = new PhotoSwipeLightbox({
|
|
319
320
|
gallery: '#post',
|
|
320
321
|
children: 'a.gallery-item',
|
|
321
322
|
bgOpacity: 1,
|
|
322
323
|
pswpModule: PhotoSwipe,
|
|
324
|
+
openPromise: () => {
|
|
325
|
+
if (pendingOpenPromise) {
|
|
326
|
+
const promise = pendingOpenPromise;
|
|
327
|
+
pendingOpenPromise = null;
|
|
328
|
+
return promise;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const currentIndex = lightbox.options && lightbox.options.index;
|
|
332
|
+
if (typeof currentIndex === 'number' && currentIndex >= 0 && typeof prepareGalleryItemOpenPromise === 'function') {
|
|
333
|
+
const itemData = lightbox.getItemData(currentIndex);
|
|
334
|
+
const target = itemData && itemData.element;
|
|
335
|
+
return prepareGalleryItemOpenPromise(target);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
323
338
|
paddingFn: (viewportSize) => {
|
|
324
339
|
return viewportSize.x < 700 ? smallScreenPadding : largeScreenPadding
|
|
325
340
|
},
|
|
@@ -574,6 +589,272 @@ const seriesInfo = getSeriesInfo(page?.series);
|
|
|
574
589
|
</div>`;
|
|
575
590
|
}
|
|
576
591
|
|
|
592
|
+
const isElementInImageGridItem = (element) => {
|
|
593
|
+
const gridItem = element && element.closest && element.closest('.grid-item');
|
|
594
|
+
return Boolean(gridItem && gridItem.closest && gridItem.closest('.image-grid'));
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
let headerWasHiddenByLightbox = false;
|
|
598
|
+
|
|
599
|
+
const isImageBlockedByFixedHeader = (element) => {
|
|
600
|
+
if (!element) return false;
|
|
601
|
+
const header = document.querySelector('.nav-header');
|
|
602
|
+
if (!header) return false;
|
|
603
|
+
const style = window.getComputedStyle(header);
|
|
604
|
+
if (style.position !== 'fixed' || header.classList.contains('hide')) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
const headerHeight = header.offsetHeight || 65;
|
|
608
|
+
const target = (typeof getScrollTarget === 'function' ? getScrollTarget(element) : null) || element;
|
|
609
|
+
const rect = target.getBoundingClientRect();
|
|
610
|
+
return rect.top < headerHeight && rect.bottom > 0;
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
const hideFixedHeaderOnGalleryClick = (target) => {
|
|
614
|
+
if (!isImageBlockedByFixedHeader(target)) {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
const header = document.querySelector('.nav-header');
|
|
618
|
+
if (!header) return false;
|
|
619
|
+
headerWasHiddenByLightbox = true;
|
|
620
|
+
header.classList.add('hide');
|
|
621
|
+
return true;
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const getFixedHeaderHeight = () => {
|
|
625
|
+
const header = document.querySelector('.nav-header');
|
|
626
|
+
if (!header) return 0;
|
|
627
|
+
const style = window.getComputedStyle(header);
|
|
628
|
+
if (style.position !== 'fixed' || header.classList.contains('hide')) {
|
|
629
|
+
return 0;
|
|
630
|
+
}
|
|
631
|
+
return header.offsetHeight || 65;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
const getScrollDelta = (element) => {
|
|
635
|
+
if (!element) {
|
|
636
|
+
return { deltaX: 0, deltaY: 0, scrollContainer: null, target: null };
|
|
637
|
+
}
|
|
638
|
+
const target = (typeof getScrollTarget === 'function' ? getScrollTarget(element) : null) || element;
|
|
639
|
+
const rect = target.getBoundingClientRect();
|
|
640
|
+
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
641
|
+
const windowWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
642
|
+
|
|
643
|
+
const scrollContainer = target.closest && target.closest('.image-grid.scroll, .image-grid.slider');
|
|
644
|
+
let deltaX = 0;
|
|
645
|
+
|
|
646
|
+
if (scrollContainer) {
|
|
647
|
+
const containerRect = scrollContainer.getBoundingClientRect();
|
|
648
|
+
const targetCenter = rect.left + rect.width / 2;
|
|
649
|
+
const containerCenter = containerRect.left + containerRect.width / 2;
|
|
650
|
+
deltaX = targetCenter - containerCenter;
|
|
651
|
+
} else {
|
|
652
|
+
if (rect.left < 0) {
|
|
653
|
+
deltaX = rect.left;
|
|
654
|
+
} else if (rect.right > windowWidth) {
|
|
655
|
+
deltaX = rect.right - windowWidth;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const headerHeight = getFixedHeaderHeight();
|
|
660
|
+
const topSafePadding = headerHeight > 0 ? headerHeight + 16 : 16;
|
|
661
|
+
let deltaY = 0;
|
|
662
|
+
|
|
663
|
+
if (rect.top < topSafePadding) {
|
|
664
|
+
deltaY = rect.top - topSafePadding;
|
|
665
|
+
} else if (rect.bottom > windowHeight) {
|
|
666
|
+
const desiredDeltaY = rect.bottom - windowHeight + 16;
|
|
667
|
+
const maxAllowedDeltaY = rect.top - topSafePadding;
|
|
668
|
+
deltaY = Math.min(desiredDeltaY, maxAllowedDeltaY);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return { deltaX, deltaY, scrollContainer, target };
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
const waitForScrollEnd = (scrollContainer, needsScrollX, needsScrollY) => {
|
|
675
|
+
return new Promise((resolve) => {
|
|
676
|
+
let resolved = false;
|
|
677
|
+
let rafId = null;
|
|
678
|
+
let startTimer = null;
|
|
679
|
+
let maxTimer = null;
|
|
680
|
+
|
|
681
|
+
let hasMoved = false;
|
|
682
|
+
let hasMovedX = false;
|
|
683
|
+
let hasMovedY = false;
|
|
684
|
+
let idleFrames = 0;
|
|
685
|
+
let lastX = scrollContainer ? scrollContainer.scrollLeft : 0;
|
|
686
|
+
let lastY = window.pageYOffset;
|
|
687
|
+
|
|
688
|
+
const finish = () => {
|
|
689
|
+
if (resolved) return;
|
|
690
|
+
resolved = true;
|
|
691
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
692
|
+
clearTimeout(startTimer);
|
|
693
|
+
clearTimeout(maxTimer);
|
|
694
|
+
if (scrollContainer) {
|
|
695
|
+
scrollContainer.removeEventListener('scrollend', onContainerScrollEnd);
|
|
696
|
+
}
|
|
697
|
+
window.removeEventListener('scrollend', onWindowScrollEnd);
|
|
698
|
+
|
|
699
|
+
window.requestAnimationFrame(() => {
|
|
700
|
+
window.requestAnimationFrame(resolve);
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
const onContainerScrollEnd = () => {
|
|
705
|
+
if (!needsScrollY || !hasMovedY) {
|
|
706
|
+
finish();
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
const onWindowScrollEnd = () => {
|
|
711
|
+
if (!needsScrollX || !hasMovedX) {
|
|
712
|
+
finish();
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
maxTimer = setTimeout(finish, 800);
|
|
717
|
+
|
|
718
|
+
startTimer = setTimeout(() => {
|
|
719
|
+
if (!hasMoved) {
|
|
720
|
+
finish();
|
|
721
|
+
}
|
|
722
|
+
}, 160);
|
|
723
|
+
|
|
724
|
+
const check = () => {
|
|
725
|
+
if (resolved) return;
|
|
726
|
+
|
|
727
|
+
const currX = scrollContainer ? scrollContainer.scrollLeft : 0;
|
|
728
|
+
const currY = window.pageYOffset;
|
|
729
|
+
|
|
730
|
+
const diffX = Math.abs(currX - lastX);
|
|
731
|
+
const diffY = Math.abs(currY - lastY);
|
|
732
|
+
|
|
733
|
+
if (needsScrollX && diffX > 0.5) {
|
|
734
|
+
hasMoved = true;
|
|
735
|
+
hasMovedX = true;
|
|
736
|
+
}
|
|
737
|
+
if (needsScrollY && diffY > 0.5) {
|
|
738
|
+
hasMoved = true;
|
|
739
|
+
hasMovedY = true;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (hasMoved) {
|
|
743
|
+
const isIdleX = !needsScrollX || diffX <= 0.5;
|
|
744
|
+
const isIdleY = !needsScrollY || diffY <= 0.5;
|
|
745
|
+
|
|
746
|
+
if (isIdleX && isIdleY) {
|
|
747
|
+
idleFrames++;
|
|
748
|
+
if (idleFrames >= 6) {
|
|
749
|
+
finish();
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
} else {
|
|
753
|
+
idleFrames = 0;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
lastX = currX;
|
|
758
|
+
lastY = currY;
|
|
759
|
+
|
|
760
|
+
rafId = requestAnimationFrame(check);
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
if (scrollContainer) {
|
|
764
|
+
scrollContainer.addEventListener('scrollend', onContainerScrollEnd, { once: true, passive: true });
|
|
765
|
+
}
|
|
766
|
+
window.addEventListener('scrollend', onWindowScrollEnd, { once: true, passive: true });
|
|
767
|
+
|
|
768
|
+
rafId = requestAnimationFrame(check);
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
const prepareGalleryItemOpenPromise = (target) => {
|
|
773
|
+
if (!target) {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const isBlocked = isImageBlockedByFixedHeader(target);
|
|
778
|
+
const inGrid = isElementInImageGridItem(target);
|
|
779
|
+
|
|
780
|
+
// Neither blocked by fixed nav-header nor inside an image-grid; open lightbox immediately
|
|
781
|
+
if (!isBlocked && !inGrid) {
|
|
782
|
+
return null;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// Hide nav-header early on click only when the item is blocked by it
|
|
786
|
+
const headerDidStartHiding = isBlocked ? hideFixedHeaderOnGalleryClick(target) : false;
|
|
787
|
+
|
|
788
|
+
let deltaX = 0;
|
|
789
|
+
let deltaY = 0;
|
|
790
|
+
let scrollContainer = null;
|
|
791
|
+
|
|
792
|
+
if (inGrid) {
|
|
793
|
+
const scrollInfo = getScrollDelta(target);
|
|
794
|
+
deltaX = scrollInfo.deltaX;
|
|
795
|
+
deltaY = scrollInfo.deltaY;
|
|
796
|
+
scrollContainer = scrollInfo.scrollContainer;
|
|
797
|
+
} else if (isBlocked) {
|
|
798
|
+
// Non-grid image blocked by header: smooth scroll down if top edge overflows above viewport (< 16px)
|
|
799
|
+
const scrollTarget = (typeof getScrollTarget === 'function' ? getScrollTarget(target) : null) || target;
|
|
800
|
+
const rect = scrollTarget.getBoundingClientRect();
|
|
801
|
+
if (rect.top < 16) {
|
|
802
|
+
deltaY = rect.top - 16;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const needsScrollX = Boolean(scrollContainer && Math.abs(deltaX) > 6);
|
|
807
|
+
const needsScrollY = Math.abs(deltaY) > 6;
|
|
808
|
+
const needsScroll = needsScrollX || needsScrollY;
|
|
809
|
+
|
|
810
|
+
if (!needsScroll) {
|
|
811
|
+
if (headerDidStartHiding) {
|
|
812
|
+
return new Promise((resolve) => {
|
|
813
|
+
setTimeout(resolve, 180);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const prefersReducedMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
820
|
+
const behavior = prefersReducedMotion ? 'instant' : 'smooth';
|
|
821
|
+
|
|
822
|
+
if (needsScrollX && scrollContainer) {
|
|
823
|
+
if (typeof scrollContainer.scrollBy === 'function') {
|
|
824
|
+
scrollContainer.scrollBy({ left: deltaX, behavior });
|
|
825
|
+
} else {
|
|
826
|
+
scrollContainer.scrollLeft += deltaX;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
if (needsScrollY) {
|
|
831
|
+
if (typeof window.scrollBy === 'function') {
|
|
832
|
+
window.scrollBy({ top: deltaY, behavior });
|
|
833
|
+
} else {
|
|
834
|
+
window.scroll(0, window.pageYOffset + deltaY);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (behavior === 'instant') {
|
|
839
|
+
return new Promise((resolve) => {
|
|
840
|
+
window.requestAnimationFrame(() => {
|
|
841
|
+
window.requestAnimationFrame(resolve);
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
return waitForScrollEnd(scrollContainer, needsScrollX, needsScrollY);
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
lightbox.addFilter('clickedIndex', (index, event) => {
|
|
850
|
+
if (index >= 0) {
|
|
851
|
+
const clickedEl = event && event.target && (event.target.closest ? event.target : event.target.parentElement);
|
|
852
|
+
const target = clickedEl && clickedEl.closest && (clickedEl.closest('a.gallery-item') || clickedEl.closest('.gallery-item'));
|
|
853
|
+
pendingOpenPromise = prepareGalleryItemOpenPromise(target);
|
|
854
|
+
}
|
|
855
|
+
return index;
|
|
856
|
+
});
|
|
857
|
+
|
|
577
858
|
lightbox.addFilter('itemData', (itemData) => {
|
|
578
859
|
const livePhotoSrc = itemData && itemData.element && itemData.element.dataset && itemData.element.dataset.livePhotoSrc;
|
|
579
860
|
if (!livePhotoSrc) {
|
|
@@ -658,6 +939,23 @@ const seriesInfo = getSeriesInfo(page?.series);
|
|
|
658
939
|
lightbox.on('closingAnimationEnd', () => {
|
|
659
940
|
setPswpLivePhotoClosing(false);
|
|
660
941
|
window.requestAnimationFrame(restorePageLivePhotoTriggers);
|
|
942
|
+
if (headerWasHiddenByLightbox) {
|
|
943
|
+
const header = document.querySelector('.nav-header');
|
|
944
|
+
if (header) {
|
|
945
|
+
header.classList.remove('hide');
|
|
946
|
+
}
|
|
947
|
+
headerWasHiddenByLightbox = false;
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
lightbox.on('destroy', () => {
|
|
952
|
+
if (headerWasHiddenByLightbox) {
|
|
953
|
+
const header = document.querySelector('.nav-header');
|
|
954
|
+
if (header) {
|
|
955
|
+
header.classList.remove('hide');
|
|
956
|
+
}
|
|
957
|
+
headerWasHiddenByLightbox = false;
|
|
958
|
+
}
|
|
661
959
|
});
|
|
662
960
|
|
|
663
961
|
lightbox.on('change', (e) => {
|
package/package.json
CHANGED
|
@@ -330,9 +330,31 @@ body {
|
|
|
330
330
|
}
|
|
331
331
|
&.hdr-switch {
|
|
332
332
|
background-image: url("../img/icons/hdr.svg");
|
|
333
|
-
background-size:
|
|
333
|
+
background-size: contain;
|
|
334
|
+
background-repeat: no-repeat;
|
|
335
|
+
background-position: center;
|
|
334
336
|
cursor: pointer;
|
|
335
337
|
position: relative;
|
|
338
|
+
transition: opacity 0.2s ease;
|
|
339
|
+
|
|
340
|
+
&:hover {
|
|
341
|
+
opacity: 0.75;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
&::before {
|
|
345
|
+
content: "";
|
|
346
|
+
position: absolute;
|
|
347
|
+
inset: 0;
|
|
348
|
+
background: linear-gradient(90deg, #ff6ec4, #7873f5, #4ade80);
|
|
349
|
+
-webkit-mask: url("../img/icons/hdr.svg") no-repeat center;
|
|
350
|
+
mask: url("../img/icons/hdr.svg") no-repeat center;
|
|
351
|
+
-webkit-mask-size: contain;
|
|
352
|
+
mask-size: contain;
|
|
353
|
+
opacity: 0;
|
|
354
|
+
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
355
|
+
pointer-events: none;
|
|
356
|
+
}
|
|
357
|
+
|
|
336
358
|
&::after {
|
|
337
359
|
content: "";
|
|
338
360
|
display: block;
|
|
@@ -340,22 +362,26 @@ body {
|
|
|
340
362
|
height: 2px;
|
|
341
363
|
position: absolute;
|
|
342
364
|
top: 50%;
|
|
343
|
-
|
|
344
|
-
|
|
365
|
+
margin-top: -1px;
|
|
366
|
+
left: 2%;
|
|
345
367
|
background-color: #232323;
|
|
346
|
-
transition: all ease-in-out 0.3s;
|
|
347
368
|
border-radius: 2px;
|
|
369
|
+
transform: rotate(37deg) scaleX(1);
|
|
370
|
+
transform-origin: center;
|
|
348
371
|
opacity: 1;
|
|
372
|
+
transition:
|
|
373
|
+
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
|
|
374
|
+
opacity 0.25s ease;
|
|
375
|
+
pointer-events: none;
|
|
349
376
|
}
|
|
377
|
+
|
|
350
378
|
&.hdr_on {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
-webkit-mask-size: contain;
|
|
355
|
-
mask-size: contain;
|
|
379
|
+
&::before {
|
|
380
|
+
opacity: 1;
|
|
381
|
+
}
|
|
356
382
|
&::after {
|
|
357
383
|
opacity: 0;
|
|
358
|
-
transform: rotate(0);
|
|
384
|
+
transform: rotate(37deg) scaleX(0);
|
|
359
385
|
}
|
|
360
386
|
}
|
|
361
387
|
}
|
|
@@ -3439,6 +3465,7 @@ html[lang="zh-CN"] {
|
|
|
3439
3465
|
width: 100%;
|
|
3440
3466
|
display: inline-block;
|
|
3441
3467
|
vertical-align: middle;
|
|
3468
|
+
scroll-margin-top: calc(#{$navbarMinHeight} + 16px);
|
|
3442
3469
|
}
|
|
3443
3470
|
}
|
|
3444
3471
|
|
|
@@ -100,30 +100,14 @@ function switchHDR() {
|
|
|
100
100
|
} else {
|
|
101
101
|
lazyloadItem.removeAttribute("data-hdr-active");
|
|
102
102
|
}
|
|
103
|
-
var innerWrap = lazyloadItem.querySelector(".inner-wrap");
|
|
104
|
-
var placeholder = lazyloadItem.querySelector(".placeholder");
|
|
105
103
|
var InnerImgs = lazyloadItem.querySelectorAll("img");
|
|
106
104
|
InnerImgs.forEach((img) => {
|
|
107
105
|
if (targetState) {
|
|
108
106
|
if (img.src && img.src.includes(SDRPath)) {
|
|
109
|
-
// Re-enter the lazyload visual state while the replacement image
|
|
110
|
-
// is loading. The placeholder remains underneath the image.
|
|
111
|
-
lazyloadItem.classList.remove("loaded");
|
|
112
|
-
if (innerWrap) {
|
|
113
|
-
innerWrap.classList.remove("loaded");
|
|
114
|
-
innerWrap.style.opacity = "0";
|
|
115
|
-
}
|
|
116
|
-
if (placeholder) placeholder.classList.remove("loaded");
|
|
117
107
|
img.src = img.src.replace(SDRPath, HDRPath);
|
|
118
108
|
}
|
|
119
109
|
} else {
|
|
120
110
|
if (img.src && img.src.includes(HDRPath)) {
|
|
121
|
-
lazyloadItem.classList.remove("loaded");
|
|
122
|
-
if (innerWrap) {
|
|
123
|
-
innerWrap.classList.remove("loaded");
|
|
124
|
-
innerWrap.style.opacity = "0";
|
|
125
|
-
}
|
|
126
|
-
if (placeholder) placeholder.classList.remove("loaded");
|
|
127
111
|
img.src = img.src.replace(HDRPath, SDRPath);
|
|
128
112
|
}
|
|
129
113
|
}
|